public virtual void UpdateWithHSV(HSV hsv) { HSV hsvTemp; hsvTemp.S = 1; hsvTemp.H = hsv.H; hsvTemp.V = 1; RGBA rgb = CCControlUtils.RGBfromHSV(hsvTemp); Background.Color = new CCColor3B((byte)(rgb.R * 255.0f), (byte)(rgb.G * 255.0f), (byte)(rgb.B * 255.0f)); }
public void ColourSliderValueChanged(Object sender, CCControlEvent controlEvent) { Hsv.S = ((CCControlSaturationBrightnessPicker)sender).Saturation; Hsv.V = ((CCControlSaturationBrightnessPicker)sender).Brightness; RGBA rgb = CCControlUtils.RGBfromHSV(Hsv); // XXX fixed me if not correct base.Color = new CCColor3B((byte)(rgb.R * 255.0f), (byte)(rgb.G * 255.0f), (byte)(rgb.B * 255.0f)); // Send Control callback SendActionsForControlEvents(CCControlEvent.ValueChanged); }
public void HueSliderValueChanged(Object sender, CCControlEvent controlEvent) { Hsv.H = ((CCControlHuePicker)sender).Hue; RGBA rgb = CCControlUtils.RGBfromHSV(Hsv); // XXX fixed me if not correct base.Color = new CCColor3B((byte)(rgb.R * 255.0f), (byte)(rgb.G * 255.0f), (byte)(rgb.B * 255.0f)); // Send Control callback SendActionsForControlEvents(CCControlEvent.ValueChanged); UpdateControlPicker(); }
public CCControlColourPicker() { // Register Touch Event var touchListener = new CCEventListenerTouchOneByOne(); touchListener.IsSwallowTouches = true; touchListener.OnTouchBegan = OnTouchBegan; AddEventListener(touchListener); CCSpriteFrameCache.SharedSpriteFrameCache.AddSpriteFrames("extensions/CCControlColourPickerSpriteSheet.plist"); var spriteSheet = new CCSpriteBatchNode("extensions/CCControlColourPickerSpriteSheet.png"); AddChild(spriteSheet); 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; CCPoint huePickerPos = new CCPoint(backgroundPointZero.X + hueShift, backgroundPointZero.Y + hueShift); HuePicker = new CCControlHuePicker(spriteSheet, huePickerPos); CCPoint colourPickerPos = new CCPoint(backgroundPointZero.X + colourShift, backgroundPointZero.Y + colourShift); ColourPicker = new CCControlSaturationBrightnessPicker(spriteSheet, colourPickerPos); // Setup events HuePicker.AddTargetWithActionForControlEvents(this, HueSliderValueChanged, CCControlEvent.ValueChanged); ColourPicker.AddTargetWithActionForControlEvents(this, ColourSliderValueChanged, CCControlEvent.ValueChanged); UpdateHueAndControlPicker(); AddChild(HuePicker); AddChild(ColourPicker); ContentSize = Background.ContentSize; }
public CCControlStepper(CCSprite minusSprite, CCSprite plusSprite) { Debug.Assert(minusSprite != null, "Minus sprite must be not nil"); Debug.Assert(plusSprite != null, "Plus sprite must be not nil"); IsContinuous = true; IgnoreAnchorPointForPosition = false; autorepeat = true; minimumValue = 0; maximumValue = 100; value = 0; stepValue = 1; wraps = false; MinusSprite = minusSprite; MinusSprite.Position = new CCPoint(minusSprite.ContentSize.Width / 2, minusSprite.ContentSize.Height / 2); AddChild(MinusSprite); MinusLabel = new CCLabelTtf("-", ControlStepperLabelFont, 38); MinusLabel.Color = ControlStepperLabelColorDisabled; MinusLabel.Position = new CCPoint(MinusSprite.ContentSize.Width / 2, MinusSprite.ContentSize.Height / 2); MinusSprite.AddChild(MinusLabel); PlusSprite = plusSprite; PlusSprite.Position = new CCPoint(minusSprite.ContentSize.Width + plusSprite.ContentSize.Width / 2, minusSprite.ContentSize.Height / 2); AddChild(PlusSprite); PlusLabel = new CCLabelTtf("+", ControlStepperLabelFont, 38); PlusLabel.Color = ControlStepperLabelColorEnabled; PlusLabel.Position = PlusSprite.ContentSize.Center; PlusSprite.AddChild(PlusLabel); // Defines the content size CCRect maxRect = CCControlUtils.CCRectUnion(MinusSprite.BoundingBox, PlusSprite.BoundingBox); ContentSize = new CCSize(MinusSprite.ContentSize.Width + PlusSprite.ContentSize.Height, maxRect.Size.Height); // Register Touch Event var touchListener = new CCEventListenerTouchOneByOne(); touchListener.IsSwallowTouches = true; touchListener.OnTouchBegan = OnTouchBegan; touchListener.OnTouchMoved = OnTouchMoved; touchListener.OnTouchEnded = OnTouchEnded; AddEventListener(touchListener); }
public CCControlSlider(CCSprite backgroundSprite, CCSprite progressSprite, CCSprite thumbSprite) { Debug.Assert(backgroundSprite != null, "Background sprite can not be null"); Debug.Assert(progressSprite != null, "Progress sprite can not be null"); Debug.Assert(thumbSprite != null, "Thumb sprite can not be null"); BackgroundSprite = backgroundSprite; ProgressSprite = progressSprite; ThumbSprite = thumbSprite; minimumValue = 0.0f; maximumValue = 1.0f; Value = minimumValue; IgnoreAnchorPointForPosition = false; // Defines the content size CCRect maxRect = CCControlUtils.CCRectUnion(backgroundSprite.BoundingBox, thumbSprite.BoundingBox); ContentSize = new CCSize(maxRect.Size.Width, maxRect.Size.Height); // Add the slider background BackgroundSprite.AnchorPoint = CCPoint.AnchorMiddle; BackgroundSprite.Position = ContentSize.Center; AddChild(BackgroundSprite); // Add the progress bar ProgressSprite.AnchorPoint = CCPoint.AnchorMiddleLeft; ProgressSprite.PositionX = 0; ProgressSprite.PositionY = BackgroundSprite.PositionY; AddChild(ProgressSprite); // Add the slider thumb ThumbSprite.Position = new CCPoint(0, ContentSize.Height / 2); ThumbSprite.AnchorPoint = CCPoint.AnchorMiddle; ThumbSprite.PositionX = 0; ThumbSprite.PositionY = BackgroundSprite.PositionY; AddChild(ThumbSprite); // Register Touch Event var touchListener = new CCEventListenerTouchOneByOne(); touchListener.IsSwallowTouches = true; touchListener.OnTouchBegan = OnTouchBegan; touchListener.OnTouchMoved = OnTouchMoved; touchListener.OnTouchEnded = OnTouchEnded; AddEventListener(touchListener); }
public CCControlHuePicker(CCNode target, CCPoint pos) { var touchListener = new CCEventListenerTouchOneByOne(); touchListener.IsSwallowTouches = true; touchListener.OnTouchBegan = OnTouchBegan; touchListener.OnTouchMoved = OnTouchMoved; AddEventListener(touchListener); 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; }
public CCControlColourPicker() { // Register Touch Event var touchListener = new CCEventListenerTouchOneByOne(); touchListener.IsSwallowTouches = true; touchListener.OnTouchBegan = OnTouchBegan; AddEventListener(touchListener); CCSpriteFrameCache.SharedSpriteFrameCache.AddSpriteFrames("extensions/CCControlColourPickerSpriteSheet.plist"); Hsv.H = 0; Hsv.S = 0; Hsv.V = 0; // Add image Background = CCControlUtils.AddSpriteToTargetWithPosAndAnchor("menuColourPanelBackground.png", this, CCPoint.Zero, CCPoint.AnchorMiddle); CCPoint backgroundPointZero = Background.Position - Background.ContentSize.Center; // Setup panels float hueShift = 8; float colourShift = 28; CCPoint huePickerPos = new CCPoint(backgroundPointZero.X + hueShift, backgroundPointZero.Y + hueShift); HuePicker = new CCControlHuePicker(this, huePickerPos); CCPoint colourPickerPos = new CCPoint(backgroundPointZero.X + colourShift, backgroundPointZero.Y + colourShift); ColourPicker = new CCControlSaturationBrightnessPicker(this, colourPickerPos); // Setup events HuePicker.ValueChanged += HuePicker_ValueChanged; ColourPicker.ValueChanged += ColourPicker_ValueChanged; UpdateHueAndControlPicker(); AddChild(HuePicker); AddChild(ColourPicker); ContentSize = Background.ContentSize; }
public CCControlSaturationBrightnessPicker(CCNode target, CCPoint pos) { 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; 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 // Register Touch Event var touchListener = new CCEventListenerTouchOneByOne(); touchListener.IsSwallowTouches = true; touchListener.OnTouchBegan = OnTouchBegan; touchListener.OnTouchMoved = OnTouchMoved; AddEventListener(touchListener); }
public override void NeedsLayout() { if (!parentInited) { return; } // Hide the background and the label if (titleLabel != null) { titleLabel.Visible = false; } if (_backgroundSprite != null) { _backgroundSprite.Visible = false; } // Update anchor of all labels LabelAnchorPoint = labelAnchorPoint; // Update the label to match with the current state currentTitle = GetTitleForState(State); currentTitleColor = GetTitleColorForState(State); TitleLabel = GetTitleLabelForState(State); var label = (ICCTextContainer)titleLabel; if (label != null && !String.IsNullOrEmpty(currentTitle)) { label.Text = (currentTitle); } var rgbaLabel = titleLabel; if (rgbaLabel != null) { rgbaLabel.Color = currentTitleColor; } if (titleLabel != null) { titleLabel.Position = new CCPoint(ContentSize.Width / 2, ContentSize.Height / 2); } // Update the background sprite BackgroundSprite = GetBackgroundSpriteForState(State); if (_backgroundSprite != null) { _backgroundSprite.Position = new CCPoint(ContentSize.Width / 2, ContentSize.Height / 2); } // Get the title label size CCSize titleLabelSize = CCSize.Zero; if (titleLabel != null) { titleLabelSize = titleLabel.BoundingBox.Size; } // Adjust the background image if necessary if (isAdjustBackgroundImage) { // Add the margins if (_backgroundSprite != null) { _backgroundSprite.ContentSize = new CCSize(titleLabelSize.Width + _marginH * 2, titleLabelSize.Height + _marginV * 2); } } else { //TODO: should this also have margins if one of the preferred sizes is relaxed? if (_backgroundSprite != null && _backgroundSprite is CCScale9Sprite) { CCSize preferredSize = ((CCScale9Sprite)_backgroundSprite).PreferredSize; if (preferredSize.Width <= 0) { preferredSize.Width = titleLabelSize.Width; } if (preferredSize.Height <= 0) { preferredSize.Height = titleLabelSize.Height; } _backgroundSprite.ContentSize = preferredSize; } } // Set the content size CCRect rectTitle = CCRect.Zero; if (titleLabel != null) { rectTitle = titleLabel.BoundingBox; } CCRect rectBackground = CCRect.Zero; if (_backgroundSprite != null) { rectBackground = _backgroundSprite.BoundingBox; } CCRect maxRect = CCControlUtils.CCRectUnion(rectTitle, rectBackground); ContentSize = new CCSize(maxRect.Size.Width, maxRect.Size.Height); if (titleLabel != null) { titleLabel.Position = new CCPoint(ContentSize.Width / 2, ContentSize.Height / 2); // Make visible label titleLabel.Visible = true; } if (_backgroundSprite != null) { _backgroundSprite.Position = new CCPoint(ContentSize.Width / 2, ContentSize.Height / 2); // Make visible the background _backgroundSprite.Visible = true; } }