public UIColorField AddColorPicker(string name, Color defaultValue, OnColorChanged eventCallback, out UILabel title) { if (eventCallback != null && !string.IsNullOrEmpty(name)) { UIPanel panel = m_Root.AttachUIComponent(UITemplateManager.GetAsGameObject(UIHelperExtension.kDropdownTemplate)) as UIPanel; panel.name = "DropDownColorSelector"; title = panel.Find <UILabel>("Label"); title.text = name; panel.autoLayoutDirection = LayoutDirection.Horizontal; panel.wrapLayout = false; panel.autoFitChildrenVertically = true; GameObject.Destroy(panel.Find <UIDropDown>("Dropdown").gameObject); var colorField = KlyteUtils.CreateColorField(panel); colorField.eventSelectedColorReleased += (cp, value) => { eventCallback(value); }; return(colorField); } DebugOutputPanel.AddMessage(PluginManager.MessageType.Warning, "Cannot create colorPicker with no name or no event"); title = null; return(null); }
public DropDownColorSelector AddColorField(string name, Color defaultValue, OnColorChanged eventCallback, OnButtonClicked eventRemove) { if (eventCallback != null && !string.IsNullOrEmpty(name)) { UIPanel uIPanel = m_Root.AttachUIComponent(UITemplateManager.GetAsGameObject(UIHelperExtension.kDropdownTemplate)) as UIPanel; uIPanel.name = "DropDownColorSelector"; uIPanel.Find <UILabel>("Label").text = name; GameObject.Destroy(uIPanel.Find <UIDropDown>("Dropdown").gameObject); DropDownColorSelector ddcs = new DropDownColorSelector(uIPanel, defaultValue); ddcs.eventColorChanged += (Color32 value) => { eventCallback(value); }; ddcs.eventOnRemove += () => { if (eventRemove != null) { eventRemove(); } }; return(ddcs); } DebugOutputPanel.AddMessage(PluginManager.MessageType.Warning, "Cannot create colorPicker with no name or no event"); return(null); }
public void UpdatePicker(IColorable currentSelectable) { if (currentSelectable == null) { return; } if (currentSelectable.ColorFillArea) { _currentColor = currentSelectable.GetInlineAreaColor(); } else { _currentColor = currentSelectable.GetPathColor(); } _alpha.value = _currentColor.a; Color.RGBToHSV(_currentColor, out _currentHue, out _currentSaturation, out _currentValue); float hue = 360 * _currentHue; Vector2 direction = CurveMath.Rotate(Vector2.right, hue); _hueSelector.localPosition = direction.normalized * _hueRadius; _image.color = Color.HSVToRGB(_currentHue, 1, 1); Vector2 newPositon; newPositon.x = _currentSaturation * _svRectWidth - _saturationValueRectWidth; newPositon.y = _currentValue * _svRectWidth - _saturationValueRectWidth; _colorSelector.localPosition = newPositon; OnColorChanged?.Invoke(currentSelectable.GetInlineAreaColor(), currentSelectable.GetPathColor()); }
/// <summary> /// Called when the hex field updates /// </summary> /// <param name="evt"></param> private void UpdateColorFromHex(FocusOutEvent evt) { UpdatePrevColor(); // make sure the color string starts with a # string colorString = _hexField.value; if (!colorString.StartsWith("#")) { colorString = colorString.Insert(0, "#"); } // if the string is not valid, reset to the previous color if (!UnityEngine.ColorUtility.TryParseHtmlString(colorString, out Color colorFromHex)) { _hexField.SetValueWithoutNotify(UnityEngine.ColorUtility.ToHtmlStringRGB(_currentColor)); return; } // set color _currentColor = colorFromHex; // update display UpdateColorComparisionSwatch(); UpdateHslWheel(); UpdateSliders(); OnColorChanged?.Invoke(_currentColor); }
public DropDownColorSelector AddColorField(string name, Color defaultValue, OnColorChanged eventCallback, OnButtonClicked eventRemove) { bool flag = eventCallback != null && !string.IsNullOrEmpty(name); DropDownColorSelector result; if (flag) { UIPanel uIPanel = this.m_Root.AttachUIComponent(UITemplateManager.GetAsGameObject(UIHelperExtension.kDropdownTemplate)) as UIPanel; uIPanel.name = "DropDownColorSelector"; uIPanel.Find <UILabel>("Label").text = name; UnityEngine.Object.Destroy(uIPanel.Find <UIDropDown>("Dropdown").gameObject); DropDownColorSelector dropDownColorSelector = new DropDownColorSelector(uIPanel, defaultValue, 0); dropDownColorSelector.eventColorChanged += delegate(Color32 value) { eventCallback(value); }; dropDownColorSelector.eventOnRemove += delegate { bool flag2 = eventRemove != null; if (flag2) { eventRemove(); } }; result = dropDownColorSelector; } else { DebugOutputPanel.AddMessage(PluginManager.MessageType.Warning, "Cannot create colorPicker with no name or no event"); result = null; } return(result); }
void ChangeColor()//puts the first color of the queue in the last place and sets it as the "currentColor" { AgentType color = colors.Dequeue(); currentColor = color; colors.Enqueue(color); OnColorChanged.Invoke(); }
public void SetColor(Color color, OnColorChanged _onColorChanged) { originalAlpha = color.a; currentHSV = ColorUtil.HSV.RGB2HSV(color); currentHSV.h = 360.0f - currentHSV.h; onColorChanged = _onColorChanged; RedrawPicker(); }
// // Private Methods // private void UpdateColor(Color c) { Color = c; // Update color sample colorSample.color = c; OnColorChanged?.Invoke(c); }
/// <summary> /// Called when the alpha slider updates /// </summary> /// <param name="evt"></param> private void UpdateAlpha(ChangeEvent <float> evt) { _currentColor.a = evt.newValue; // update display UpdateColorComparisionSwatch(); OnColorChanged?.Invoke(_currentColor); }
/// <summary> /// All the common updating after a slider changed /// </summary> private void DoCommonUpdateFromSliders() { // update display UpdateColorComparisionSwatch(); UpdateHslWheel(); UpdateAlphaSlider(); UpdateHexColor(); OnColorChanged?.Invoke(_currentColor); }
public virtual void ChangeColor(MyColor newColor) { (PressColor = newColor.Duplicate()).AdjustLight(-0.6f); DefaultColor = newColor.Duplicate(); ColorChanger.SetColor(newColor); ScreenTexture.ColorChanger.ResetColor(newColor); OnColorChanged?.Invoke(newColor); }
private void ToggleClicked(ColorToggle toggle) { if (toggle == currentToggle) { return; } Select(toggle); OnColorChanged?.Invoke(currentToggle.color); }
private void UpdateColorFromHSB() { color = Color.HSVToRGB(hsb.x, hsb.y, hsb.z); // Calculate Luma var Y = 0.2126f * color.r + 0.7152f * color.g + 0.0722f * color.b; // Update selector's color (black or white) selector.color = Y > 0.5f? Color.black : Color.white; OnColorChanged?.Invoke(color); }
private void SetImageColor(Color value) { if (spriteRenderer != null) { spriteRenderer.color = value; } else if (image != null) { image.color = value; } OnColorChanged?.Invoke(value); }
/// <summary> /// Sets the current color and updates all displays /// </summary> /// <param name="newColor"></param> public void SetColor(Color newColor) { UpdatePrevColor(); _currentColor = newColor; // update display UpdateColorComparisionSwatch(); UpdateHslWheel(); UpdateSliders(); UpdateHexColor(); OnColorChanged?.Invoke(_currentColor); }
// ######################## FUNCTIONALITY ######################## // #region FUNCTIONALITY #region EVENT_HANDLING /// <summary> /// Called when the hsl wheel updates /// </summary> /// <param name="newColor"></param> private void UpdateColorFromHslWheel(Color newColor) { UpdatePrevColor(); // make sure alpha is kept and set the color newColor.a = _currentColor.a; _currentColor = newColor; // update display UpdateColorComparisionSwatch(); UpdateSliders(); UpdateHexColor(); OnColorChanged?.Invoke(_currentColor); }
private void Slider_ValueChanged(object sender, RoutedPropertyChangedEventArgs <double> e) { if (!isTextHex) { int red = (int)slRed.Value; int green = (int)slGreen.Value; int blue = (int)slBlue.Value; Color color = Color.FromArgb(red, green, blue); hexColor = ColorTranslator.ToHtml(color); tbHex.Text = hexColor; } OnColorChanged?.Invoke(sender, hexColor); }
/* Select Saturation : the intensity of the color and * Brightness (or Value) : the brightness of the color * Rectangle in the center of Texture */ void SetSaturationAndValue(Vector2 pickPosition) { // position SaturationAndValueSelector pickPosition.x = Mathf.Clamp(pickPosition.x, -_saturationValueRectWidth, _saturationValueRectWidth); pickPosition.y = Mathf.Clamp(pickPosition.y, -_saturationValueRectWidth, _saturationValueRectWidth); _colorSelector.localPosition = pickPosition; // Set ColorSelectorImage Color _currentSaturation = (pickPosition.x + _saturationValueRectWidth) / _svRectWidth; _currentValue = (pickPosition.y + _saturationValueRectWidth) / _svRectWidth; _currentColor = Color.HSVToRGB(_currentHue, _currentSaturation, _currentValue); OnColorChanged?.Invoke(_currentColor); }
public void SelectRandom() { if (colorToggles.Count == 0) { return; } ColorToggle toggle = colorToggles[Random.Range(0, colorToggles.Count)]; if (toggle == currentToggle) { return; } Select(toggle); OnColorChanged?.Invoke(currentToggle.color); }
private void Button_Click(object sender, EventArgs e) { var dialog = new ColorDialog() { Color = color }; if (dialog.ShowDialog(this) == DialogResult.OK) { color = dialog.Color; RefreshColor(); OnColorChanged?.Invoke(this, new ColorChangedEventArgs() { Color = color }); } }
// Select Hue : the color type; outer circle in Texture void SetHue(Vector2 pickPosition) { // position HueSelector _hueSelector.localPosition = pickPosition.normalized * _hueRadius; pickPosition = _hueSelector.localPosition; float angle = Vector2.Angle(pickPosition, Vector2.right); // Set ColorSelectorImage Color if (pickPosition.y < 0) { angle = 360 - angle; } _currentHue = angle / 360; _image.color = Color.HSVToRGB(_currentHue, 1, 1); _currentColor = Color.HSVToRGB(_currentHue, _currentSaturation, _currentValue); OnColorChanged?.Invoke(_currentColor); }
private void Grid_MouseDown(object sender, MouseButtonEventArgs e) { if (e.ClickCount > 1) { e.Handled = true; ColorPicker cp = new ColorPicker(System.Drawing.Color.FromArgb((int)(color.W * 255), (int)(color.X * 255), (int)(color.Y * 255), (int)(color.Z * 255))); cp.ShowDialog(); if (cp.DialogResult == true) { var c = cp.Selected; SetColor(c); if (OnColorChanged != null) { OnColorChanged.Invoke(); } } } }
public void NotifyColorChanged(Color c, int x, int y) { OnColorChanged?.Invoke(c, x, y); }
public static void AddColorField(UIHelperExtension helper, string text, out UIColorField m_colorEditor, OnColorChanged onSelectedColorChanged, out UILabel label) { m_colorEditor = helper.AddColorPicker(text, Color.white, onSelectedColorChanged); label = m_colorEditor.parent.GetComponentInChildren <UILabel>(); KlyteMonoUtils.LimitWidthAndBox(label, helper.Self.width / 2, true); }
public static void AddColorField(UIHelperExtension helper, string text, out UIColorField m_colorEditor, OnColorChanged onSelectedColorChanged) => AddColorField(helper, text, out m_colorEditor, onSelectedColorChanged, out _);
public UIColorField AddColorPicker(string name, Color defaultValue, OnColorChanged eventCallback) { return(AddColorPicker(name, defaultValue, eventCallback, out UILabel title)); }
public void SetColor(Color color, OnColorChanged _onColorChanged) { originalAlpha = color.a; currentHSV = ColorUtil.HSV.RGB2HSV(color); currentHSV.h = 360.0f - currentHSV.h; onColorChanged = _onColorChanged; RedrawPicker(); }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void SelectedIndexChanged(object sender, EventArgs e) { OnColorChanged?.Invoke(sender, e); }
public void SetAlpha() { _currentColor.a = _alpha.value; OnColorChanged?.Invoke(_currentColor); }
void OnValueChanged(int val) { colorDisplay.color = new Color32((byte)R.GetValue(), (byte)G.GetValue(), (byte)B.GetValue(), 255); OnColorChanged?.Invoke(colorDisplay.color); }