Пример #1
0
        public virtual bool InitWithTargetAndPos(CCNode target, CCPoint pos)
        {
            if (base.Init())
            {
                TouchEnabled = true;
                // Add background and slider sprites
                Background = CCControlUtils.AddSpriteToTargetWithPosAndAnchor("huePickerBackground.png", target,
                                                                              pos, CCPoint.Zero);
                Slider = CCControlUtils.AddSpriteToTargetWithPosAndAnchor("colourPicker.png", target, pos,
                                                                          new CCPoint(0.5f, 0.5f));

                _slider.Position = new CCPoint(pos.X, pos.Y + _background.BoundingBox.Size.Height * 0.5f);
                _startPos        = pos;

                // Sets the default value
                _hue           = 0.0f;
                _huePercentage = 0.0f;
                return(true);
            }
            return(false);
        }
        public virtual bool InitWithTargetAndPos(CCNode target, CCPoint pos)
        {
            if (base.Init())
            {
                TouchEnabled = true;
                // Add background and slider sprites
                _background = CCControlUtils.AddSpriteToTargetWithPosAndAnchor("colourPickerBackground.png", target, pos,
                                                                               CCPoint.Zero);
                _overlay = CCControlUtils.AddSpriteToTargetWithPosAndAnchor("colourPickerOverlay.png", target, pos,
                                                                            CCPoint.Zero);
                _shadow = CCControlUtils.AddSpriteToTargetWithPosAndAnchor("colourPickerShadow.png", target, pos,
                                                                           CCPoint.Zero);
                _slider = CCControlUtils.AddSpriteToTargetWithPosAndAnchor("colourPicker.png", target, pos,
                                                                           new CCPoint(0.5f, 0.5f));

                _startPos = pos; // starting position of the colour picker
                boxPos    = 35;  // starting position of the virtual box area for picking a colour
                boxSize   = (int)_background.ContentSize.Width / 2;
                // the size (width and height) of the virtual box for picking a colour from
                return(true);
            }

            return(false);
        }
        public override bool Init()
        {
            if (base.Init())
            {
                TouchEnabled = true;
                // Cache the sprites
                CCSpriteFrameCache.SharedSpriteFrameCache.AddSpriteFramesWithFile(
                    "extensions/CCControlColourPickerSpriteSheet.plist");

                // Create the sprite batch node
                var spriteSheet = new CCSpriteBatchNode("extensions/CCControlColourPickerSpriteSheet.png");
                AddChild(spriteSheet);

                // MIPMAP
//        ccTexParams params  = {GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT};

                /* Comment next line to avoid something like mosaic in 'ControlExtensionTest',
                 * especially the display of 'huePickerBackground.png' when in 800*480 window size with 480*320 design resolution and hd(960*640) resources.
                 */
//        spriteSheet->getTexture()->setAliasTexParameters();
//         spriteSheet->getTexture()->setTexParameters(&params);
//         spriteSheet->getTexture()->generateMipmap();

                // Init default color
                _hsv.h = 0;
                _hsv.s = 0;
                _hsv.v = 0;

                // Add image
                _background = CCControlUtils.AddSpriteToTargetWithPosAndAnchor("menuColourPanelBackground.png",
                                                                               spriteSheet, CCPoint.Zero,
                                                                               new CCPoint(0.5f, 0.5f));

                CCPoint backgroundPointZero = _background.Position -
                                              new CCPoint(_background.ContentSize.Width / 2,
                                                          _background.ContentSize.Height / 2);

                // Setup panels
                float hueShift    = 8;
                float colourShift = 28;

                _huePicker = new CCControlHuePicker();
                _huePicker.InitWithTargetAndPos(spriteSheet,
                                                new CCPoint(backgroundPointZero.X + hueShift,
                                                            backgroundPointZero.Y + hueShift));
                _colourPicker = new CCControlSaturationBrightnessPicker();
                _colourPicker.InitWithTargetAndPos(spriteSheet,
                                                   new CCPoint(backgroundPointZero.X + colourShift,
                                                               backgroundPointZero.Y + colourShift));

                // Setup events
                _huePicker.AddTargetWithActionForControlEvents(this, HueSliderValueChanged,
                                                               CCControlEvent.ValueChanged);
                _colourPicker.AddTargetWithActionForControlEvents(this, ColourSliderValueChanged,
                                                                  CCControlEvent.ValueChanged);

                // Set defaults
                UpdateHueAndControlPicker();
                AddChild(_huePicker);
                AddChild(_colourPicker);

                // Set content size
                ContentSize = _background.ContentSize;
                return(true);
            }
            return(false);
        }