public override void OnEnter()
        {
            base.OnEnter();

            var screenSize = Layer.VisibleBoundsWorldspace.Size;

            var layer = new CCNode();

            layer.Position = screenSize.Center;
            AddChild(layer, 1);

            var layerWidth = 0.0f;

            // Add the black background for the text
            var background = new CCScale9SpriteFile("extensions/buttonBackground");

            background.ContentSize = new CCSize(80, 50);
            background.Position    = new CCPoint(layerWidth + background.ContentSize.Width / 2.0f, 0);
            layer.AddChild(background);

            layerWidth += background.ContentSize.Width;

            DisplayValueLabel = new CCLabel("#color", "Arial", 30, CCLabelFormat.SpriteFont);

            DisplayValueLabel.Position = background.Position;
            layer.AddChild(DisplayValueLabel);

            // Create the switch
            CCControlSwitch switchControl = new CCControlSwitch
                                            (
                new CCSprite("extensions/switch-mask"),
                new CCSprite("extensions/switch-on"),
                new CCSprite("extensions/switch-off"),
                new CCSprite("extensions/switch-thumb"),
                new CCLabel("On", "Arial", 16, CCLabelFormat.SpriteFont),
                new CCLabel("Off", "Arial", 16, CCLabelFormat.SpriteFont)
                                            );

            switchControl.Position = new CCPoint(layerWidth + 10 + switchControl.ContentSize.Width / 2, 0);
            layer.AddChild(switchControl);

            // Subscribe to the switches StateChanged event
            switchControl.StateChanged += SwitchControl_StateChanged;

            // --------------- OR ---------------------
            // we can subscribe to the ValueChanged event.
            //switchControl.ValueChanged += SwitchControl_ValueChanged;



            // Set the layer size
            layer.ContentSize = new CCSize(layerWidth, 0);
            layer.AnchorPoint = CCPoint.AnchorMiddle;

            // Update the value label
            ValueChanged(switchControl, CCControlEvent.ValueChanged);
        }
예제 #2
0
        public override bool Init()
        {
            if (base.Init())
            {
                // Get the sceensize
                CCSize screensize = CCDirector.SharedDirector.WinSize;

                var pBackItem = new CCMenuItemFont("Back", toExtensionsMainLayer);
                pBackItem.Position = new CCPoint(screensize.Width - 50, 25);
                var pBackMenu = new CCMenu(pBackItem);
                pBackMenu.Position = CCPoint.Zero;
                AddChild(pBackMenu, 10);

                // Add the generated background
                var background = new CCSprite("extensions/background");
                background.Position = new CCPoint(screensize.Width / 2, screensize.Height / 2);
                AddChild(background);

                // Add the ribbon
                var ribbon = new CCScale9SpriteFile("extensions/ribbon", new CCRect(1, 1, 48, 55));
                ribbon.ContentSize = new CCSize(screensize.Width, 57);
                ribbon.Position    = new CCPoint(screensize.Width / 2.0f, screensize.Height - ribbon.ContentSize.Height / 2.0f);
                AddChild(ribbon);

                // Add the title
                setSceneTitleLabel(new CCLabelTTF(" ", "Arial", 12));
                m_pSceneTitleLabel.Position = new CCPoint(screensize.Width / 2, screensize.Height - m_pSceneTitleLabel.ContentSize.Height / 2 - 5);
                AddChild(m_pSceneTitleLabel, 1);

                // Add the subtitle
                setSceneSubtitleLabel(new CCLabelTTF(" ", "Arial", 12));
                m_pSceneSubtitleLabel.Position = new CCPoint(screensize.Width / 2,
                                                             screensize.Height - m_pSceneTitleLabel.ContentSize.Height -
                                                             m_pSceneSubtitleLabel.ContentSize.Height / 2 - 10);
                AddChild(m_pSceneSubtitleLabel, 1);

                // Add the menu
                var item1 = new CCMenuItemImage("Images/b1", "Images/b2", previousCallback);
                var item2 = new CCMenuItemImage("Images/r1", "Images/r2", restartCallback);
                var item3 = new CCMenuItemImage("Images/f1", "Images/f2", nextCallback);

                var menu = new CCMenu(item1, item3, item2);
                menu.Position  = CCPoint.Zero;
                item1.Position = new CCPoint(screensize.Width / 2 - 100, 37);
                item2.Position = new CCPoint(screensize.Width / 2, 35);
                item3.Position = new CCPoint(screensize.Width / 2 + 100, 37);

                AddChild(menu, 1);

                return(true);
            }
            return(false);
        }
예제 #3
0
        public override bool Init()
        {
            if (base.Init())
            {
                CCSize screenSize = CCDirector.SharedDirector.WinSize;

                CCNode layer = new CCNode();
                layer.Position = new CCPoint(screenSize.Width / 2, screenSize.Height / 2);
                AddChild(layer, 1);

                float layer_width = 0.0f;

                // Add the black background for the text
                CCScale9Sprite background = new CCScale9SpriteFile("extensions/buttonBackground");
                background.ContentSize = new CCSize(80, 50);
                background.Position    = new CCPoint(layer_width + background.ContentSize.Width / 2.0f, 0);
                layer.AddChild(background);

                layer_width += background.ContentSize.Width;

                m_pDisplayValueLabel = new CCLabelTTF("#color", "Marker Felt", 30);

                m_pDisplayValueLabel.Position = background.Position;
                layer.AddChild(m_pDisplayValueLabel);

                // Create the switch
                CCControlSwitch switchControl = new CCControlSwitch
                                                (
                    new CCSprite("extensions/switch-mask"),
                    new CCSprite("extensions/switch-on"),
                    new CCSprite("extensions/switch-off"),
                    new CCSprite("extensions/switch-thumb"),
                    new CCLabelTTF("On", "Arial-BoldMT", 16),
                    new CCLabelTTF("Off", "Arial-BoldMT", 16)
                                                );
                switchControl.Position = new CCPoint(layer_width + 10 + switchControl.ContentSize.Width / 2, 0);
                layer.AddChild(switchControl);

                switchControl.AddTargetWithActionForControlEvents(this, valueChanged, CCControlEvent.ValueChanged);

                // Set the layer size
                layer.ContentSize = new CCSize(layer_width, 0);
                layer.AnchorPoint = new CCPoint(0.5f, 0.5f);

                // Update the value label
                valueChanged(switchControl, CCControlEvent.ValueChanged);
                return(true);
            }
            return(false);
        }
예제 #4
0
        public override bool Init()
        {
            if (base.Init())
            {
                CCSize screenSize = CCDirector.SharedDirector.WinSize;

                CCNode layer = new CCNode();
                layer.Position = new CCPoint(screenSize.Width / 2, screenSize.Height / 2);
                AddChild(layer, 1);

                float layer_width = 0;

                // Create the colour picker
                CCControlColourPicker colourPicker = new CCControlColourPicker();
                colourPicker.Color    = new CCColor3B(37, 46, 252);
                colourPicker.Position = new CCPoint(colourPicker.ContentSize.Width / 2, 0);

                // Add it to the layer
                layer.AddChild(colourPicker);

                // Add the target-action pair
                colourPicker.AddTargetWithActionForControlEvents(this, ColourValueChanged,
                                                                 CCControlEvent.ValueChanged);


                layer_width += colourPicker.ContentSize.Width;

                // Add the black background for the text
                CCScale9Sprite background = new CCScale9SpriteFile("extensions/buttonBackground.png");
                background.ContentSize = new CCSize(150, 50);
                background.Position    = new CCPoint(layer_width + background.ContentSize.Width / 2.0f, 0);
                layer.AddChild(background);

                layer_width += background.ContentSize.Width;

                _colorLabel = new CCLabelTTF("#color", "Arial", 26);

                _colorLabel.Position = background.Position;
                layer.AddChild(_colorLabel);

                // Set the layer size
                layer.ContentSize = new CCSize(layer_width, 0);
                layer.AnchorPoint = new CCPoint(0.5f, 0.5f);

                // Update the color text
                ColourValueChanged(colourPicker, CCControlEvent.ValueChanged);
                return(true);
            }
            return(false);
        }
        public override bool Init()
        {
            if (base.Init())
            {
                CCSize screenSize = CCDirector.SharedDirector.WinSize;

                var layer = new CCNode();
                layer.Position = new CCPoint(screenSize.Width / 2, screenSize.Height / 2);
                AddChild(layer, 1);

                double layer_width = 0;

                // Add the black background for the text
                CCScale9Sprite background = new CCScale9SpriteFile("extensions/buttonBackground.png");
                background.ContentSize = new CCSize(80, 50);
                background.Position    = new CCPoint((float)layer_width + background.ContentSize.Width / 2.0f, 0);
                layer.AddChild(background);

                layer_width += background.ContentSize.Width;

                DisplayValueLabel = new CCLabelTTF("", "Arial", 30);

                _displayValueLabel.Position = background.Position;
                layer.AddChild(_displayValueLabel);

                // Add the slider
                var potentiometer = new CCControlPotentiometer("extensions/potentiometerTrack.png"
                                                               ,
                                                               "extensions/potentiometerProgress.png"
                                                               , "extensions/potentiometerButton.png");
                potentiometer.Position = new CCPoint((float)layer_width + 10 + potentiometer.ContentSize.Width / 2, 0);

                // When the value of the slider will change, the given selector will be call
                potentiometer.AddTargetWithActionForControlEvents(this, ValueChanged, CCControlEvent.ValueChanged);

                layer.AddChild(potentiometer);

                layer_width += potentiometer.ContentSize.Width;

                // Set the layer size
                layer.ContentSize = new CCSize((float)layer_width, 0);
                layer.AnchorPoint = new CCPoint(0.5f, 0.5f);

                // Update the value label
                ValueChanged(potentiometer, CCControlEvent.ValueChanged);
                return(true);
            }
            return(false);
        }
        public override void OnEnter()
        {
            base.OnEnter();

            var screenSize = Layer.VisibleBoundsWorldspace.Size;

            var layer = new CCNode();

            layer.Position = screenSize.Center;
            AddChild(layer, 1);

            double layer_width = 0;

            // Add the black background for the text
            CCScale9Sprite background = new CCScale9SpriteFile("extensions/buttonBackground.png");

            background.ContentSize = new CCSize(80, 50);
            background.Position    = new CCPoint((float)layer_width + background.ContentSize.Width / 2.0f, 0);
            layer.AddChild(background);

            layer_width += background.ContentSize.Width;

            DisplayValueLabel = new CCLabel("", "Arial", 30);

            DisplayValueLabel.Position = background.Position;
            layer.AddChild(DisplayValueLabel);

            // Add the slider
            var potentiometer = new CCControlPotentiometer("extensions/potentiometerTrack.png"
                                                           ,
                                                           "extensions/potentiometerProgress.png"
                                                           , "extensions/potentiometerButton.png");

            potentiometer.Position = new CCPoint((float)layer_width + 10 + potentiometer.ContentSize.Width / 2, 0);

            // When the value of the slider will change, the given selector will be call
            potentiometer.ValueChanged += Potentiometer_ValueChanged;

            layer.AddChild(potentiometer);

            layer_width += potentiometer.ContentSize.Width;

            // Set the layer size
            layer.ContentSize = new CCSize((float)layer_width, 0);
            layer.AnchorPoint = CCPoint.AnchorMiddle;

            // Update the value label
            ValueChanged(potentiometer, CCControlEvent.ValueChanged);
        }
예제 #7
0
        public override void OnEnter()
        {
            base.OnEnter();

            CCSize screenSize = Layer.VisibleBoundsWorldspace.Size;

            // Add a label in which the button events will be displayed
            DisplayValueLabel             = new CCLabel("No Event", "Arial", 28, CCLabelFormat.SpriteFont);
            DisplayValueLabel.AnchorPoint = new CCPoint(0.5f, -0.5f);
            DisplayValueLabel.Position    = screenSize.Center;
            AddChild(DisplayValueLabel, 1);

            // Add the button
            var backgroundButton            = new CCScale9SpriteFile("extensions/button");
            var backgroundHighlightedButton = new CCScale9SpriteFile("extensions/buttonHighlighted");

            var titleButton = new CCLabel("Touch Me!", "Arial", 30, CCLabelFormat.SpriteFont);

            titleButton.Color = new CCColor3B(159, 168, 176);

            var controlButton = new CCControlButton(titleButton, backgroundButton);

            controlButton.SetBackgroundSpriteForState(backgroundHighlightedButton, CCControlState.Highlighted);
            controlButton.SetTitleColorForState(CCColor3B.White, CCControlState.Highlighted);

            controlButton.AnchorPoint = CCPoint.AnchorMiddleTop;
            controlButton.Position    = screenSize.Center;
            AddChild(controlButton, 1);

            // Add the black background
            var background = new CCScale9SpriteFile("extensions/buttonBackground");

            background.ContentSize = new CCSize(300, 170);
            background.Position    = screenSize.Center;
            AddChild(background);

            // Sets up event handlers
            controlButton.TouchDown        += ControlButton_TouchDown;
            controlButton.TouchDragInside  += ControlButton_TouchDragInside;
            controlButton.TouchDragOutside += ControlButton_TouchDragOutside;
            controlButton.TouchDragEnter   += ControlButton_TouchDragEnter;
            controlButton.TouchDragExit    += ControlButton_TouchDragExit;
            //controlButton.TouchUpInside += ControlButton_TouchUpInside;
            controlButton.TouchUpOutside += ControlButton_TouchUpOutside;
            controlButton.TouchCancel    += ControlButton_TouchCancel;

            // To see clicked events your will need comment out TouchUpInside events
            controlButton.Clicked += ControlButton_Clicked;
        }
        public CCControlColourPickerTest()
        {
            CCSize screenSize = Layer.VisibleBoundsWorldspace.Size;

            CCNode layer = new CCNode();

            layer.Position = new CCPoint(screenSize.Width / 2, screenSize.Height / 2);
            AddChild(layer, 1);

            float layer_width = 0;

            // Create the colour picker
            CCControlColourPicker colourPicker = new CCControlColourPicker();

            colourPicker.Color    = new CCColor3B(37, 46, 252);
            colourPicker.Position = new CCPoint(colourPicker.ContentSize.Width / 2, 0);

            // Add it to the layer
            layer.AddChild(colourPicker);

            // Add the target-action pair
            colourPicker.AddTargetWithActionForControlEvents(this, ColourValueChanged,
                                                             CCControlEvent.ValueChanged);


            layer_width += colourPicker.ContentSize.Width;

            // Add the black background for the text
            CCScale9Sprite background = new CCScale9SpriteFile("extensions/buttonBackground.png");

            background.ContentSize = new CCSize(150, 50);
            background.Position    = new CCPoint(layer_width + background.ContentSize.Width / 2.0f, 0);
            layer.AddChild(background);

            layer_width += background.ContentSize.Width;

            _colorLabel = new CCLabelTtf("#color", "Arial", 26);

            _colorLabel.Position = background.Position;
            layer.AddChild(_colorLabel);

            // Set the layer size
            layer.ContentSize = new CCSize(layer_width, 0);
            layer.AnchorPoint = new CCPoint(0.5f, 0.5f);

            // Update the color text
            ColourValueChanged(colourPicker, CCControlEvent.ValueChanged);
        }
        public override void OnEnter()
        {
            base.OnEnter();

            var screenSize = Layer.VisibleBoundsWorldspace.Size;

            CCNode layer = new CCNode();

            layer.Position = screenSize.Center;
            AddChild(layer, 1);

            float layer_width = 0;

            // Create the colour picker
            CCControlColourPicker colourPicker = new CCControlColourPicker();

            colourPicker.Color    = new CCColor3B(37, 46, 252);
            colourPicker.Position = new CCPoint(colourPicker.ContentSize.Width / 2, 0);

            // Add it to the layer
            layer.AddChild(colourPicker);

            // Add the target-action pair
            colourPicker.ValueChanged += ColourValueChanged;

            layer_width += colourPicker.ContentSize.Width;

            // Add the black background for the text
            CCScale9Sprite background = new CCScale9SpriteFile("extensions/buttonBackground.png");

            background.ContentSize = new CCSize(150, 50);
            background.Position    = new CCPoint(layer_width + background.ContentSize.Width / 2.0f, 0);
            layer.AddChild(background);

            layer_width += background.ContentSize.Width;

            ColorLabel = new CCLabel("#color", "Arial", 26, CCLabelFormat.SpriteFont);

            ColorLabel.Position = background.Position;
            layer.AddChild(ColorLabel);

            // Set the layer size
            layer.ContentSize = new CCSize(layer_width, 0);
            layer.AnchorPoint = new CCPoint(0.5f, 0.5f);

            // Update the color text
            ColourValueChanged(colourPicker, CCControlEvent.ValueChanged);
        }
예제 #10
0
        public CCControlSwitchTest()
        {
            CCSize screenSize = Layer.VisibleBoundsWorldspace.Size;

            CCNode layer = new CCNode();

            layer.Position = new CCPoint(screenSize.Width / 2, screenSize.Height / 2);
            AddChild(layer, 1);

            float layer_width = 0.0f;

            // Add the black background for the text
            CCScale9Sprite background = new CCScale9SpriteFile("extensions/buttonBackground");

            background.ContentSize = new CCSize(80, 50);
            background.Position    = new CCPoint(layer_width + background.ContentSize.Width / 2.0f, 0);
            layer.AddChild(background);

            layer_width += background.ContentSize.Width;

            m_pDisplayValueLabel = new CCLabelTtf("#color", "Arial", 30);

            m_pDisplayValueLabel.Position = background.Position;
            layer.AddChild(m_pDisplayValueLabel);

            // Create the switch
            CCControlSwitch switchControl = new CCControlSwitch
                                            (
                new CCSprite("extensions/switch-mask"),
                new CCSprite("extensions/switch-on"),
                new CCSprite("extensions/switch-off"),
                new CCSprite("extensions/switch-thumb"),
                new CCLabelTtf("On", "Arial", 16),
                new CCLabelTtf("Off", "Arial", 16)
                                            );

            switchControl.Position = new CCPoint(layer_width + 10 + switchControl.ContentSize.Width / 2, 0);
            layer.AddChild(switchControl);

            switchControl.AddTargetWithActionForControlEvents(this, valueChanged, CCControlEvent.ValueChanged);

            // Set the layer size
            layer.ContentSize = new CCSize(layer_width, 0);
            layer.AnchorPoint = new CCPoint(0.5f, 0.5f);

            // Update the value label
            valueChanged(switchControl, CCControlEvent.ValueChanged);
        }
예제 #11
0
        public override bool Init()
        {
            if (base.Init())
            {
                CCSize screenSize = CCDirector.SharedDirector.WinSize;

                // Add a label in which the button events will be displayed
                setDisplayValueLabel(new CCLabelTTF("No Event", "Arial", 32));
                m_pDisplayValueLabel.AnchorPoint = new CCPoint(0.5f, -1);
                m_pDisplayValueLabel.Position    = new CCPoint(screenSize.Width / 2.0f, screenSize.Height / 2.0f);
                AddChild(m_pDisplayValueLabel, 1);

                // Add the button
                var backgroundButton            = new CCScale9SpriteFile("extensions/button");
                var backgroundHighlightedButton = new CCScale9SpriteFile("extensions/buttonHighlighted");

                var titleButton = new CCLabelTTF("Touch Me!", "Arial", 30);

                titleButton.Color = new CCColor3B(159, 168, 176);

                var controlButton = new CCControlButton(titleButton, backgroundButton);
                controlButton.SetBackgroundSpriteForState(backgroundHighlightedButton, CCControlState.Highlighted);
                controlButton.SetTitleColorForState(CCTypes.CCWhite, CCControlState.Highlighted);

                controlButton.AnchorPoint = new CCPoint(0.5f, 1);
                controlButton.Position    = new CCPoint(screenSize.Width / 2.0f, screenSize.Height / 2.0f);
                AddChild(controlButton, 1);

                // Add the black background
                var background = new CCScale9SpriteFile("extensions/buttonBackground");
                background.ContentSize = new CCSize(300, 170);
                background.Position    = new CCPoint(screenSize.Width / 2.0f, screenSize.Height / 2.0f);
                AddChild(background);

                // Sets up event handlers
                controlButton.AddTargetWithActionForControlEvent(this, touchDownAction, CCControlEvent.TouchDown);
                controlButton.AddTargetWithActionForControlEvent(this, touchDragInsideAction, CCControlEvent.TouchDragInside);
                controlButton.AddTargetWithActionForControlEvent(this, touchDragOutsideAction, CCControlEvent.TouchDragOutside);
                controlButton.AddTargetWithActionForControlEvent(this, touchDragEnterAction, CCControlEvent.TouchDragEnter);
                controlButton.AddTargetWithActionForControlEvent(this, touchDragExitAction, CCControlEvent.TouchDragExit);
                controlButton.AddTargetWithActionForControlEvent(this, touchUpInsideAction, CCControlEvent.TouchUpInside);
                controlButton.AddTargetWithActionForControlEvent(this, touchUpOutsideAction, CCControlEvent.TouchUpOutside);
                controlButton.AddTargetWithActionForControlEvent(this, touchCancelAction, CCControlEvent.TouchCancel);
                return(true);
            }
            return(false);
        }
예제 #12
0
        /** Creates and return a button with a default background and title color. */
        public CCControlButton standardButtonWithTitle(string title)
        {
            /** Creates and return a button with a default background and title color. */
            var backgroundButton            = new CCScale9SpriteFile("extensions/button");
            var backgroundHighlightedButton = new CCScale9SpriteFile("extensions/buttonHighlighted");

            var titleButton = new CCLabelTtf(title, "Arial", 30);

            titleButton.Color = new CCColor3B(159, 168, 176);

            var button = new CCControlButton(titleButton, backgroundButton);

            button.SetBackgroundSpriteForState(backgroundHighlightedButton, CCControlState.Highlighted);
            button.SetTitleColorForState(CCColor3B.White, CCControlState.Highlighted);

            return(button);
        }
        public override bool Init()
        {
            if (base.Init())
            {
                CCSize screenSize = CCDirector.SharedDirector.WinSize;

                // Defines an array of title to create buttons dynamically
                var stringArray = new[] {
                    "Hello",
                    "Variable",
                    "Size",
                    "!"
                };

                CCNode layer = new CCNode();
                AddChild(layer, 1);

                float total_width = 0, height = 0;

                // For each title in the array
                object pObj = null;
                foreach (var title in stringArray)
                {
                    // Creates a button with this string as title
                    var button = standardButtonWithTitle(title);
                    button.Position = new CCPoint(total_width + button.ContentSize.Width / 2, button.ContentSize.Height / 2);
                    layer.AddChild(button);

                    // Compute the size of the layer
                    height       = button.ContentSize.Height;
                    total_width += button.ContentSize.Width;
                }

                layer.AnchorPoint = new CCPoint(0.5f, 0.5f);
                layer.ContentSize = new CCSize(total_width, height);
                layer.Position    = new CCPoint(screenSize.Width / 2.0f, screenSize.Height / 2.0f);

                // Add the black background
                var background = new CCScale9SpriteFile("extensions/buttonBackground");
                background.ContentSize = new CCSize(total_width + 14, height + 14);
                background.Position    = new CCPoint(screenSize.Width / 2.0f, screenSize.Height / 2.0f);
                AddChild(background);
                return(true);
            }
            return(false);
        }
예제 #14
0
        public override void OnEnter()
        {
            base.OnEnter();

            CCSize screenSize = Layer.VisibleBoundsWorldspace.Size;

            // Defines an array of title to create buttons dynamically
            var stringArray = new[] {
                "Inset",
                "Inset",
                "Inset"
            };

            CCNode layer = new CCNode();

            AddChild(layer, 1);

            float total_width = 0, height = 0;

            var insetRect = new CCRect(5, 5, 5, 5);

            // For each title in the array
            foreach (var title in stringArray)
            {
                // Creates a button with this string as title
                CCControlButton button = insetButtonWithTitle(title, insetRect);
                button.Position = new CCPoint(total_width + button.ContentSize.Width / 2, button.ContentSize.Height / 2);
                layer.AddChild(button);

                // Compute the size of the layer
                height       = button.ContentSize.Height;
                total_width += button.ContentSize.Width;
            }

            layer.AnchorPoint = CCPoint.AnchorMiddle;
            layer.ContentSize = new CCSize(total_width, height);
            layer.Position    = screenSize.Center;

            // Add the black background
            var background = new CCScale9SpriteFile("extensions/buttonBackground");

            background.ContentSize = new CCSize(total_width + 14, height + 14);
            background.Position    = screenSize.Center;
            AddChild(background);
        }
예제 #15
0
        public CCControlButtonTest_Inset()
        {
            CCSize screenSize = Layer.VisibleBoundsWorldspace.Size;

            // Defines an array of title to create buttons dynamically
            var stringArray = new[] {
                "Inset",
                "Inset",
                "Inset"
            };

            CCNode layer = new CCNode();

            AddChild(layer, 1);

            float total_width = 0, height = 0;

            // For each title in the array
            object pObj = null;

            foreach (var title in stringArray)
            {
                // Creates a button with this string as title
                CCControlButton button = insetButtonWithTitle(title, new CCRect(5, 5, 5, 5));
                button.Position = new CCPoint(total_width + button.ContentSize.Width / 2, button.ContentSize.Height / 2);
                layer.AddChild(button);

                // Compute the size of the layer
                height       = button.ContentSize.Height;
                total_width += button.ContentSize.Width;
            }

            layer.AnchorPoint = new CCPoint(0.5f, 0.5f);
            layer.ContentSize = new CCSize(total_width, height);
            layer.Position    = new CCPoint(screenSize.Width / 2.0f, screenSize.Height / 2.0f);

            // Add the black background
            var background = new CCScale9SpriteFile("extensions/buttonBackground");

            background.ContentSize = new CCSize(total_width + 14, height + 14);
            background.Position    = new CCPoint(screenSize.Width / 2.0f, screenSize.Height / 2.0f);
            AddChild(background);
        }
예제 #16
0
        public override bool Init()
        {
            if (base.Init())
            {
                CCSize screenSize = CCDirector.SharedDirector.WinSize;

                var layer = new CCNode();
                layer.Position = screenSize.Center;
                AddChild(layer, 1);

                float layer_width = 0;

                // Add the black background for the text
                CCScale9Sprite background = new CCScale9SpriteFile("extensions/buttonBackground.png");
                background.ContentSize = new CCSize(100, 50);
                background.Position    = new CCPoint(layer_width + background.ContentSize.Width / 2.0f, 0);
                layer.AddChild(background);

                DisplayValueLabel = new CCLabelTTF("0", "Arial", 26);

                _displayValueLabel.Position = background.Position;
                layer.AddChild(_displayValueLabel);

                layer_width += background.ContentSize.Width;

                CCControlStepper stepper = MakeControlStepper();
                stepper.Position = new CCPoint(layer_width + 10 + stepper.ContentSize.Width / 2, 0);
                stepper.AddTargetWithActionForControlEvents(this, ValueChanged,
                                                            CCControlEvent.ValueChanged);
                layer.AddChild(stepper);

                layer_width += stepper.ContentSize.Width;

                // Set the layer size
                layer.ContentSize = new CCSize(layer_width, 0);
                layer.AnchorPoint = new CCPoint(0.5f, 0.5f);

                // Update the value label
                ValueChanged(stepper, CCControlEvent.ValueChanged);
                return(true);
            }
            return(false);
        }
예제 #17
0
        public override void OnEnter()
        {
            base.OnEnter();

            CCSize screenSize = Layer.VisibleBoundsWorldspace.Size;

            var layer = new CCNode();

            AddChild(layer, 1);

            int space = 10; // px

            float max_w = 0, max_h = 0;

            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    // Add the buttons
                    var button = standardButtonWithTitle(CCRandom.Next(30).ToString());
                    button.IsAdjustBackgroundImage = false;  // Tells the button that the background image must not be adjust
                    // It'll use the prefered size of the background image
                    button.Position = new CCPoint(button.ContentSize.Width / 2 + (button.ContentSize.Width + space) * i,
                                                  button.ContentSize.Height / 2 + (button.ContentSize.Height + space) * j);
                    layer.AddChild(button);

                    max_w = Math.Max(button.ContentSize.Width * (i + 1) + space * i, max_w);
                    max_h = Math.Max(button.ContentSize.Height * (j + 1) + space * j, max_h);
                }
            }

            layer.AnchorPoint = CCPoint.AnchorMiddle;
            layer.ContentSize = new CCSize(max_w, max_h);
            layer.Position    = screenSize.Center;

            // Add the black background
            var backgroundButton = new CCScale9SpriteFile("extensions/buttonBackground");

            backgroundButton.ContentSize = new CCSize(max_w + 14, max_h + 14);
            backgroundButton.Position    = screenSize.Center;
            AddChild(backgroundButton);
        }
예제 #18
0
        public override bool Init()
        {
            if (base.Init())
            {
                CCSize screenSize = CCDirector.SharedDirector.WinSize;

                var layer = new CCNode();
                AddChild(layer, 1);

                int space = 10;                 // px

                float max_w = 0, max_h = 0;
                for (int i = 0; i < 3; i++)
                {
                    for (int j = 0; j < 3; j++)
                    {
                        // Add the buttons
                        var button = standardButtonWithTitle(CCRandom.Next(30).ToString());
                        button.SetAdjustBackgroundImage(false);                          // Tells the button that the background image must not be adjust
                        // It'll use the prefered size of the background image
                        button.Position = new CCPoint(button.ContentSize.Width / 2 + (button.ContentSize.Width + space) * i,
                                                      button.ContentSize.Height / 2 + (button.ContentSize.Height + space) * j);
                        layer.AddChild(button);

                        max_w = Math.Max(button.ContentSize.Width * (i + 1) + space * i, max_w);
                        max_h = Math.Max(button.ContentSize.Height * (j + 1) + space * j, max_h);
                    }
                }

                layer.AnchorPoint = new CCPoint(0.5f, 0.5f);
                layer.ContentSize = new CCSize(max_w, max_h);
                layer.Position    = new CCPoint(screenSize.Width / 2.0f, screenSize.Height / 2.0f);

                // Add the black background
                var backgroundButton = new CCScale9SpriteFile("extensions/buttonBackground");
                backgroundButton.ContentSize = new CCSize(max_w + 14, max_h + 14);
                backgroundButton.Position    = new CCPoint(screenSize.Width / 2.0f, screenSize.Height / 2.0f);
                AddChild(backgroundButton);
                return(true);
            }
            return(false);
        }
        public override void OnEnter()
        {
            base.OnEnter();

            CCSize screenSize = Layer.VisibleBoundsWorldspace.Size;

            var layer = new CCNode();

            layer.Position = screenSize.Center;
            AddChild(layer, 1);

            float layer_width = 0;

            // Add the black background for the text
            CCScale9Sprite background = new CCScale9SpriteFile("extensions/buttonBackground.png");

            background.ContentSize = new CCSize(100, 50);
            background.Position    = new CCPoint(layer_width + background.ContentSize.Width / 2.0f, 0);
            layer.AddChild(background);

            DisplayValueLabel = new CCLabel("0", "Arial", 26, CCLabelFormat.SpriteFont);

            DisplayValueLabel.Position = background.Position;
            layer.AddChild(DisplayValueLabel);

            layer_width += background.ContentSize.Width;

            CCControlStepper stepper = MakeControlStepper();

            stepper.Position      = new CCPoint(layer_width + 10 + stepper.ContentSize.Width / 2, 0);
            stepper.ValueChanged += Stepper_ValueChanged;
            layer.AddChild(stepper);

            layer_width += stepper.ContentSize.Width;

            // Set the layer size
            layer.ContentSize = new CCSize(layer_width, 0);
            layer.AnchorPoint = CCPoint.AnchorMiddle;

            // Update the value label
            ValueChanged(stepper, CCControlEvent.ValueChanged);
        }
        public CCControlButton insetButtonWithTitle(string title, CCRect inset)
        {
            /** Creates and return a button with a default background and title color. */
            var backgroundButton            = new CCScale9SpriteFile("extensions/button");
            var backgroundHighlightedButton = new CCScale9SpriteFile("extensions/buttonHighlighted");

            backgroundButton.CapInsets            = inset;
            backgroundHighlightedButton.CapInsets = inset;

            var titleButton = new CCLabelTTF(title, "Marker Felt", 30);

            titleButton.Color = new CCColor3B(159, 168, 176);

            var button = new CCControlButton(titleButton, backgroundButton);

            button.SetBackgroundSpriteForState(backgroundHighlightedButton, CCControlState.Highlighted);
            button.SetTitleColorForState(CCTypes.CCWhite, CCControlState.Highlighted);

            return(button);
        }
예제 #21
0
        public CCControlStepperTest()
        {
            CCSize screenSize = Layer.VisibleBoundsWorldspace.Size;

            var layer = new CCNode();

            layer.Position = screenSize.Center;
            AddChild(layer, 1);

            float layer_width = 0;

            // Add the black background for the text
            CCScale9Sprite background = new CCScale9SpriteFile("extensions/buttonBackground.png");

            background.ContentSize = new CCSize(100, 50);
            background.Position    = new CCPoint(layer_width + background.ContentSize.Width / 2.0f, 0);
            layer.AddChild(background);

            DisplayValueLabel = new CCLabelTtf("0", "Arial", 26);

            _displayValueLabel.Position = background.Position;
            layer.AddChild(_displayValueLabel);

            layer_width += background.ContentSize.Width;

            CCControlStepper stepper = MakeControlStepper();

            stepper.Position = new CCPoint(layer_width + 10 + stepper.ContentSize.Width / 2, 0);
            stepper.AddTargetWithActionForControlEvents(this, ValueChanged,
                                                        CCControlEvent.ValueChanged);
            layer.AddChild(stepper);

            layer_width += stepper.ContentSize.Width;

            // Set the layer size
            layer.ContentSize = new CCSize(layer_width, 0);
            layer.AnchorPoint = new CCPoint(0.5f, 0.5f);

            // Update the value label
            ValueChanged(stepper, CCControlEvent.ValueChanged);
        }
        public CCControlButton standardButtonWithTitle(string title)
        {
            /** Creates and return a button with a default background and title color. */
            var backgroundButton = new CCScale9SpriteFile("extensions/button");

            backgroundButton.PreferredSize = new CCSize(45, 45);              // Set the prefered size
            var backgroundHighlightedButton = new CCScale9SpriteFile("extensions/buttonHighlighted");

            backgroundHighlightedButton.PreferredSize = new CCSize(45, 45);              // Set the prefered size

            var titleButton = new CCLabelTTF(title, "Marker Felt", 30);

            titleButton.Color = new CCColor3B(159, 168, 176);

            var button = new CCControlButton(titleButton, backgroundButton);

            button.SetBackgroundSpriteForState(backgroundHighlightedButton, CCControlState.Highlighted);
            button.SetTitleColorForState(CCTypes.CCWhite, CCControlState.Highlighted);

            return(button);
        }
예제 #23
0
        /*
         * This is a test of the texture reinit on the control button.
         */
        public override bool Init()
        {
            if (base.Init())
            {
                CCSize screenSize = CCDirector.SharedDirector.WinSize;

                var layer = new CCNode();
                AddChild(layer, 1, kTheLayer);

                CreateTheButtons();

                layer.AnchorPoint = new CCPoint(0.5f, 0.5f);
                layer.ContentSize = new CCSize(max_w, max_h);
                layer.Position    = new CCPoint(screenSize.Width / 2.0f, screenSize.Height / 2.0f);

                // Add the black background
                var backgroundButton = new CCScale9SpriteFile("extensions/buttonBackground");
                backgroundButton.ContentSize = new CCSize(max_w + 14, max_h + 14);
                backgroundButton.Position    = new CCPoint(screenSize.Width / 2.0f, screenSize.Height / 2.0f);
                AddChild(backgroundButton);
                return(true);
            }
            return(false);
        }
예제 #24
0
        public CCControlButtonTest_HelloVariableSize()
        {
            CCSize screenSize = Layer.VisibleBoundsWorldspace.Size;

            // Defines an array of title to create buttons dynamically
            var stringArray = new[] {
                "Hello",
                "Variable",
                "Size",
                "!"
            };

            CCNode layer = new CCNode();

            AddChild(layer, 1);

            float total_width = 0, height = 0;

            // For each title in the array
            object pObj = null;
            int    i    = 0;

            foreach (var title in stringArray)
            {
                // Creates a button with this string as title
                var button = standardButtonWithTitle(title);
                if (i == 0)
                {
                    button.Opacity = 50;
                    button.Color   = new CCColor3B(0, 255, 0);
                }
                else if (i == 1)
                {
                    button.Opacity = 200;
                    button.Color   = new CCColor3B(0, 255, 0);
                }
                else if (i == 2)
                {
                    button.Opacity = 100;
                    button.Color   = new CCColor3B(0, 0, 255);
                }

                button.Position = new CCPoint(total_width + button.ContentSize.Width / 2, button.ContentSize.Height / 2);
                layer.AddChild(button);

                // Compute the size of the layer
                height       = button.ContentSize.Height;
                total_width += button.ContentSize.Width;
                i++;
            }

            layer.AnchorPoint = new CCPoint(0.5f, 0.5f);
            layer.ContentSize = new CCSize(total_width, height);
            layer.Position    = new CCPoint(screenSize.Width / 2.0f, screenSize.Height / 2.0f);

            // Add the black background
            var background = new CCScale9SpriteFile("extensions/buttonBackground");

            background.ContentSize = new CCSize(total_width + 14, height + 14);
            background.Position    = new CCPoint(screenSize.Width / 2.0f, screenSize.Height / 2.0f);
            AddChild(background);
        }