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 bool InitWithMinusSpriteAndPlusSprite(CCSprite minusSprite, CCSprite plusSprite) { if (base.Init()) { Debug.Assert(minusSprite != null, "Minus sprite must be not nil"); Debug.Assert(plusSprite != null, "Plus sprite must be not nil"); TouchEnabled = true; // Set the default values _autorepeat = true; _continuous = true; _minimumValue = 0; _maximumValue = 100; _value = 0; _stepValue = 1; _wraps = false; IgnoreAnchorPointForPosition = false; // Add the minus components 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); // Add the plus components 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); return(true); } return(false); }
//virtual ~ControlColourPicker(); public void HueSliderValueChanged(Object sender, CCControlEvent controlEvent) { _hsv.h = ((CCControlHuePicker)sender).Hue; // Update the value 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 void SetColor(CCColor3B colorValue) { // XXX fixed me if not correct base.Color = colorValue; RGBA rgba; rgba.r = colorValue.R / 255.0f; rgba.g = colorValue.G / 255.0f; rgba.b = colorValue.B / 255.0f; rgba.a = 1.0f; _hsv = CCControlUtils.HSVfromRGB(rgba); UpdateHueAndControlPicker(); }
public void ColourSliderValueChanged(Object sender, CCControlEvent controlEvent) { _hsv.s = ((CCControlSaturationBrightnessPicker)sender).Saturation; _hsv.v = ((CCControlSaturationBrightnessPicker)sender).Brightness; // Update the value 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); }
/** * Initializes a slider with a background sprite, a progress bar and a thumb * item. * * @param backgroundSprite CCSprite, that is used as a background. * @param progressSprite CCSprite, that is used as a progress bar. * @param thumbItem CCMenuItem, that is used as a thumb. */ public virtual bool InitWithSprites(CCSprite backgroundSprite, CCSprite progressSprite, CCSprite thumbSprite) { if (base.Init()) { Debug.Assert(backgroundSprite != null, "Background sprite must be not nil"); Debug.Assert(progressSprite != null, "Progress sprite must be not nil"); Debug.Assert(thumbSprite != null, "Thumb sprite must be not nil"); IgnoreAnchorPointForPosition = false; TouchEnabled = true; BackgroundSprite = backgroundSprite; ProgressSprite = progressSprite; ThumbSprite = thumbSprite; // Defines the content size CCRect maxRect = CCControlUtils.CCRectUnion(backgroundSprite.BoundingBox, thumbSprite.BoundingBox); ContentSize = new CCSize(maxRect.Size.Width, maxRect.Size.Height); //setContentSize(CCSizeMake(backgroundSprite->getContentSize().width, thumbItem->getContentSize().height)); // Add the slider background _backgroundSprite.AnchorPoint = new CCPoint(0.5f, 0.5f); _backgroundSprite.Position = new CCPoint(ContentSize.Width / 2, ContentSize.Height / 2); AddChild(_backgroundSprite); // Add the progress bar _progressSprite.AnchorPoint = new CCPoint(0.0f, 0.5f); _progressSprite.Position = new CCPoint(0.0f, ContentSize.Height / 2); AddChild(_progressSprite); // Add the slider thumb _thumbSprite.Position = new CCPoint(0, ContentSize.Height / 2); AddChild(_thumbSprite); // Init default values _minimumValue = 0.0f; _maximumValue = 1.0f; Value = _minimumValue; 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("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 void NeedsLayout() { if (!m_bParentInited) { return; } // Hide the background and the label if (m_titleLabel != null) { m_titleLabel.Visible = false; } if (m_backgroundSprite != null) { m_backgroundSprite.Visible = false; } // Update anchor of all labels LabelAnchorPoint = m_labelAnchorPoint; // Update the label to match with the current state m_currentTitle = GetTitleForState(m_eState); m_currentTitleColor = GetTitleColorForState(m_eState); TitleLabel = GetTitleLabelForState(m_eState); var label = (ICCLabelProtocol)m_titleLabel; if (label != null && !String.IsNullOrEmpty(m_currentTitle)) { label.Label = (m_currentTitle); } var rgbaLabel = (ICCRGBAProtocol)m_titleLabel; if (rgbaLabel != null) { rgbaLabel.Color = m_currentTitleColor; } if (m_titleLabel != null) { m_titleLabel.Position = new CCPoint(ContentSize.Width / 2, ContentSize.Height / 2); } // Update the background sprite BackgroundSprite = GetBackgroundSpriteForState(m_eState); if (m_backgroundSprite != null) { m_backgroundSprite.Position = new CCPoint(ContentSize.Width / 2, ContentSize.Height / 2); } // Get the title label size CCSize titleLabelSize = CCSize.Zero; if (m_titleLabel != null) { titleLabelSize = m_titleLabel.BoundingBox.Size; } // Adjust the background image if necessary if (m_doesAdjustBackgroundImage) { // Add the margins if (m_backgroundSprite != null) { m_backgroundSprite.ContentSize = new CCSize(titleLabelSize.Width + m_marginH * 2, titleLabelSize.Height + m_marginV * 2); } } else { //TODO: should this also have margins if one of the preferred sizes is relaxed? if (m_backgroundSprite != null) { CCSize preferredSize = m_backgroundSprite.PreferredSize; if (preferredSize.Width <= 0) { preferredSize.Width = titleLabelSize.Width; } if (preferredSize.Height <= 0) { preferredSize.Height = titleLabelSize.Height; } m_backgroundSprite.ContentSize = preferredSize; } } // Set the content size CCRect rectTitle = CCRect.Zero; if (m_titleLabel != null) { rectTitle = m_titleLabel.BoundingBox; } CCRect rectBackground = CCRect.Zero; if (m_backgroundSprite != null) { rectBackground = m_backgroundSprite.BoundingBox; } CCRect maxRect = CCControlUtils.CCRectUnion(rectTitle, rectBackground); ContentSize = new CCSize(maxRect.Size.Width, maxRect.Size.Height); if (m_titleLabel != null) { m_titleLabel.Position = new CCPoint(ContentSize.Width / 2, ContentSize.Height / 2); // Make visible label m_titleLabel.Visible = true; } if (m_backgroundSprite != null) { m_backgroundSprite.Position = new CCPoint(ContentSize.Width / 2, ContentSize.Height / 2); // Make visible the background m_backgroundSprite.Visible = true; } }
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(¶ms); // 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); }