private BufferedColor PickColor1D(BufferedColor color, PickerType type, Vector2 v) { bool horizontal = IsHorizontal(pickerImages[(int)type]); float value = horizontal ? v.x : v.y; return(PickColor1D(color, type, value)); }
/// <summary>Initializes a new instance of the <see cref="VisualColorPicker" /> class.</summary> public VisualColorPicker() { SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.Selectable | ControlStyles.StandardClick | ControlStyles.StandardDoubleClick | ControlStyles.SupportsTransparentBackColor, true); styleManager = new StyleManager(DefaultConstants.DefaultStyle); _buttonColor = styleManager.Theme.ColorPalette.Enabled; _pickType = PickerType.Rectangle; Color = Color.Black; ColorStep = 4; SelectionSize = 10; SmallChange = 1; LargeChange = 5; _pickerVisible = true; _border = new Border(); _pickerBorder = new Border(); MinimumSize = new Size(130, 130); Size = new Size(130, 130); _pickerBorder.HoverVisible = false; Size = new Size(200, 100); UpdateLinearGradientBrushes(); UpdateGraphicsBuffer(); }
private BufferedColor PickColor2D(BufferedColor color, PickerType type1, float value1, PickerType type2, float value2) { color = PickColor1D(color, type1, value1); color = PickColor1D(color, type2, value2); return(color); }
private void UpdateTexture(PickerType type, bool standardized) { Image image = GetImage((int)type); if (!image || !image.gameObject.activeInHierarchy) { return; } Material m = image.materialForRendering; BufferedColor bc = this.bufferedColor; if (standardized) { switch (type) { case PickerType.S: bc = new BufferedColor(Color.red); break; case PickerType.Preview: case PickerType.PreviewAlpha: break; default: bc = new BufferedColor(Color.black); break; } } bool alpha = IsAlphaType(type); m.SetInt("_Mode", GetGradientMode(type)); Color c1 = PickColor(bc, type, Vector2.zero).color; Color c2 = PickColor(bc, type, Vector2.one).color; if (!alpha) { c1 = new Color(c1.r, c1.g, c1.b); c2 = new Color(c2.r, c2.g, c2.b); } m.SetColor("_Color1", c1); m.SetColor("_Color2", c2); if (type == PickerType.Main) { m.SetInt("_DoubleMode", (int)mode); } if (standardized) { m.SetVector("_HSV", new Vector4(0f, 1f, 1f, 1f)); } else { m.SetVector("_HSV", new Vector4(bc.h / HUE_LOOP, bc.s, bc.v, alpha ? bc.a : 1f)); } }
void ChangePicker(PickerType picker, List <string> source = null, int?index = null, bool?isVis = null) { var pick = pickers[(int)picker]; pick.index = index ?? pick.index; pick.source = source ?? pick.source; pick.isVisible = isVis ?? pick.isVisible; OnPickerChanged?.Invoke(null, pick); }
private static bool IsAlphaType(PickerType type) { switch (type) { case PickerType.A: return(true); case PickerType.PreviewAlpha: return(true); default: return(false); } }
/*---------------------------------------------------------- * -------------------- MARKER UPDATING --------------------- * ---------------------------------------------------------- * * Update positions of markers on each picking texture, * indicating the currently selected values. */ private void UpdateMarkers() { for (int i = 0; i < pickers.Length; i++) { if (IsPickerAvailable(i)) { PickerType type = (PickerType)i; Vector2 v = GetValue(type); UpdateMarker(pickers[i], type, v); } } }
/// <summary> /// Change picker that is being focused (and edited) using the pointer. /// </summary> /// <param name="i">Index of the picker image.</param> public void SetPointerFocus(int i) { if (i < 0 || i >= pickerImages.Length) { Debug.LogWarning("No picker image available of type " + (PickerType)i + ". Did you assign all the picker images in the editor?"); } else { focusedPicker = pickerImages[i]; } focusedPickerType = (PickerType)i; }
/*---------------------------------------------------------- * --------------------- COLOR PICKING ---------------------- * ---------------------------------------------------------- * * Get a new color that is the currently selected color but with * one or two values changed. This is the core functionality of * the picking images and the entire color picker script. */ /// <summary> /// Get a color that is the current color, but changed by the given picker and value. /// </summary> /// <param name="type">Picker type to base change on</param> /// <param name="v">normalized x and y values (both values may not be used)</param> private BufferedColor PickColor(BufferedColor color, PickerType type, Vector2 v) { switch (type) { case PickerType.Main: return(PickColorMain(color, v)); case PickerType.Preview: case PickerType.PreviewAlpha: return(color); default: return(PickColor1D(color, type, v)); } }
public PeopleParameter(string name, PickerType pickerType, LocalizedString noSelectionText) : base(name, LocalizedString.Empty, LocalizedString.Empty) { this.PickerType = pickerType.ToString(); if (string.IsNullOrEmpty(noSelectionText)) { this.noSelectionText = Strings.TransportRulePeopleParameterNoSelectionText; } else { this.noSelectionText = noSelectionText; } base.FormletType = typeof(PeoplePicker); }
private int GetGradientMode(PickerType type) { int o = IsHorizontal(pickerImages[(int)type]) ? 0 : 1; switch (type) { case PickerType.Main: return(2); case PickerType.H: return(3 + o); default: return(o); } }
void makeJNICall(PickerType type, string[] items, long selectedItem) { if (isMobileRuntime == false) { return; } #if UNITY_ANDROID //Debug.Log(String.Format("Selected item -> {0}", selectedItem)); _pluginObject.Call("showPicker", (int)type, items, selectedItem, "NativePicker"); #else return; #endif }
private BufferedColor GetDefaultColor(PickerType type) { switch (type) { case PickerType.Main: return(GetDefaultColor(this.mode)); case PickerType.H: return(new BufferedColor(Color.red)); case PickerType.S: return(new BufferedColor(Color.red)); case PickerType.A: return(new BufferedColor(Color.white)); default: return(new BufferedColor()); } }
/*---------------------------------------------------------- * -------------------- MARKER UPDATING --------------------- * ---------------------------------------------------------- * * Update positions of markers on each picking texture, * indicating the currently selected values. */ private void UpdateMarkers() { for (int i = 0; i < pickerImages.Length; i++) { Image image = GetImage(i); if (!image || !image.isActiveAndEnabled) { continue; } PickerType type = (PickerType)i; Vector2 v = GetValue(type); UpdateMarker(image, type, v); } }
/*---------------------------------------------------------- * -------------------- VALUE RETRIEVAL --------------------- * ---------------------------------------------------------- * * Get individual values associated with a picker image from the * currently selected color. * This is needed to properly update markers. */ private Vector2 GetValue(PickerType type) { switch (type) { case PickerType.Main: return(GetValue(mode)); case PickerType.Preview: case PickerType.PreviewAlpha: return(Vector2.zero); default: float value = GetValue1D(type); return(new Vector2(value, value)); } }
public void SetDrawableItems(IList <int> resIds, int?defaultPosition) { _resIdItems = resIds; _type = PickerType.Drawable; _editView.Visibility = _readOnlyView.Visibility = ViewStates.Gone; if (defaultPosition < 0 || defaultPosition >= _resIdItems.Count) { defaultPosition = null; } _currentValue = defaultPosition; DisplayValue(); }
public void SelectType(string name) { for (int i = 0; i < content.transform.childCount; i++) { Destroy(content.transform.GetChild(i).gameObject); } if (name == "kind") { foreach (GameObject item in PastaFeatures._kinds) { GameObject next = Instantiate(prefab, content.transform); GameObject image = next.transform.GetChild(0).gameObject; GameObject text = next.transform.GetChild(1).gameObject; Instantiate(item, next.transform); image.GetComponent <Image>().sprite = item.GetComponent <Kind>().icon; text.GetComponent <Text>().text = item.name; pickerType = PickerType.Kind; } } else if (name == "shape") { foreach (GameObject item in PastaFeatures._shapes) { GameObject next = Instantiate(prefab, content.transform); GameObject image = next.transform.GetChild(0).gameObject; GameObject text = next.transform.GetChild(1).gameObject; Instantiate(item, next.transform); image.GetComponent <Image>().sprite = item.GetComponent <Shape>().icon; text.GetComponent <Text>().text = item.name; pickerType = PickerType.Shape; } } else if (name == "flour") { foreach (GameObject item in PastaFeatures._flours) { GameObject next = Instantiate(prefab, content.transform); GameObject image = next.transform.GetChild(0).gameObject; GameObject text = next.transform.GetChild(1).gameObject; Instantiate(item, next.transform); image.GetComponent <Image>().sprite = item.GetComponent <FlourType>().icon; text.GetComponent <Text>().text = item.name; pickerType = PickerType.Flour; } } }
private void HandlePointerIn(object sender, PointerEventArgs e) { if (e.target.gameObject.GetComponent <PickableObject>() != null) { //Debug.Log(e.distance); type = PickerType.PickableObject; currentSelected = e.target.GetComponent <PickableObject>().moveParent; currentTarget = e.target.gameObject.GetComponent <PickableObject>(); isOnObject = true; } if (e.target.gameObject.GetComponent <LeverHandler>() != null) { type = PickerType.Lever; isOnObject = true; lever = e.target.gameObject.GetComponent <LeverHandler>(); } }
public void SetStringItems(IList <string> strings, int?defaultPosition) { _stringItems = strings; _type = PickerType.Strings; _readOnlyView.Visibility = ViewStates.Visible; _editView.Visibility = _imageView.Visibility = ViewStates.Gone; if (defaultPosition < 0 || defaultPosition >= _stringItems.Count) { defaultPosition = 0; } _currentValue = defaultPosition; DisplayValue(); }
private void UpdateTexture(PickerType type, bool standardized) { RawImage image = GetImage((int)type); if (!image || !image.gameObject.activeInHierarchy) { return; } Texture2D tex = (Texture2D)(image.texture); int width = tex.width; int height = tex.height; Color[] pixels = new Color[width * height]; for (int x = 0; x < width; x++) { float normX = (float)x / (width - 1); for (int y = 0; y < height; y++) { float normY = (float)y / (height - 1); Vector2 v = new Vector2(normX, normY); BufferedColor bc = this.bufferedColor; if (standardized) { bc = GetDefaultColor(type); } bc = PickColor(bc, type, v); Color c = bc.color; if (!IsAlphaType(type)) { c.a = 1f; } int pixelIndex = x + y * width; pixels[pixelIndex] = c; } } tex.SetPixels(pixels); tex.Apply(); }
private void UpdateMarker(Image picker, PickerType type, Vector2 v) { switch (type) { case PickerType.Main: SetMarker(picker, v, true, true); break; case PickerType.Preview: case PickerType.PreviewAlpha: break; default: bool horizontal = IsHorizontal(picker); SetMarker(picker, v, horizontal, !horizontal); break; } }
private void UpdateDynamic(PickerType type) { if (!IsPickerAvailable(type)) { return; } Picker p = pickers[(int)type]; if (p.dynamicMaterial == null) { return; } Material m = p.dynamicMaterial; p.image.material = m; p.image.color = Color.white; p.image.sprite = p.dynamicSprite; BufferedColor bc = this.bufferedColor; bool alpha = IsAlphaType(type); m.SetInt(SHADER_MODE, GetGradientMode(type)); Color c1 = PickColor(bc, type, Vector2.zero).color; Color c2 = PickColor(bc, type, Vector2.one).color; if (!alpha) { c1 = new Color(c1.r, c1.g, c1.b); c2 = new Color(c2.r, c2.g, c2.b); } m.SetColor(SHADER_C1, c1); m.SetColor(SHADER_C2, c2); if (type == PickerType.Main) { m.SetInt(SHADER_DOUBLE_MODE, (int)mode); } else { m.SetVector(SHADER_HSV, new Vector4(bc.h / HUE_LOOP, bc.s, bc.v, alpha ? bc.a : 1f)); } }
public void SetNumericValues(float max, uint precision, bool readOnly, float?defaultValue, float min = 0) { _maxValue = max; _minValue = min; _precision = precision; _type = readOnly ? PickerType.ReadOnly : PickerType.Editable; _imageView.Visibility = ViewStates.Gone; _editView.Visibility = readOnly ? ViewStates.Gone : ViewStates.Visible; _readOnlyView.Visibility = readOnly ? ViewStates.Visible : ViewStates.Gone; if (_precision == 0) { _editView.InputType = InputTypes.ClassNumber; } _editView.AfterTextChanged += (sender, args) => { var str = args.Editable.ToString(); var length = str.Length; if (!float.TryParse(str, NumberStyles.AllowDecimalPoint, CultureInfo.CurrentCulture, out var parsedResult) || parsedResult < min) { _currentValue = null; } else if (parsedResult > _maxValue) { _currentValue = _maxValue; args.Editable.Replace(0, length, _maxValue.ToString(CultureInfo.CurrentCulture)); } else { _currentValue = parsedResult; } }; _currentValue = defaultValue; DisplayValue(); }
//void PickupObject() //{ // try // { // currentSelected.transform.SetParent(parenter); // currentSelected.transform.localPosition = new Vector3(0, 0, 0.2f) + currentSelected.GetComponent<PickableObject>().offset; // pointer.enabled = false; // } // catch { } //} //public void ReleaseObject() //{ // try // { // currentSelected.transform.SetParent(FindObjectOfType<Snapper>().parentObject); // pointer.enabled = true; // } // catch { } //} private void HandlePointerIn(object sender, PointerEventArgs e) { //if (e.target.gameObject.GetComponent<PickableObject>() != null) //{ // currentSelected = e.target.GetComponent<PickableObject>().moveParent; // currentTarget = e.target.gameObject.GetComponent<PickableObject>(); // isOnObject = true; //} if (e.target.gameObject.GetComponent <LeverHandler>() != null) { type = PickerType.Lever; isOnObject = true; lever = e.target.gameObject.GetComponent <LeverHandler>(); } else { type = PickerType.PickableObject; } currentSelected = e.target.gameObject; }
private BufferedColor PickColor1D(BufferedColor color, PickerType type, float value) { switch (type) { case PickerType.R: return(color.PickR(value)); case PickerType.G: return(color.PickG(value)); case PickerType.B: return(color.PickB(value)); case PickerType.H: return(color.PickH(value * HUE_LOOP)); case PickerType.S: return(color.PickS(value)); case PickerType.V: return(color.PickV(value)); case PickerType.A: return(color.PickA(value)); default: throw new Exception("Picker type " + type + " is not associated with a single color value."); } }
private float GetValue1D(PickerType type) { switch (type) { case PickerType.R: return(this.bufferedColor.r); case PickerType.G: return(this.bufferedColor.g); case PickerType.B: return(this.bufferedColor.b); case PickerType.H: return(this.bufferedColor.h / HUE_LOOP); case PickerType.S: return(this.bufferedColor.s); case PickerType.V: return(this.bufferedColor.v); case PickerType.A: return(this.bufferedColor.a); default: throw new Exception("Picker type " + type + " is not associated with a single color value."); } }
void makeJNICall(PickerType type, string[] items, long selectedItem) { if (isMobileRuntime == false) { return; } #if UNITY_ANDROID AndroidJavaObject obj_ArrayListItems = new AndroidJavaObject("java.util.ArrayList"); IntPtr method_Add = AndroidJNIHelper.GetMethodID(obj_ArrayListItems.GetRawClass(), "add", "(Ljava/lang/Object;)Z"); foreach (string item in items) { AndroidJNI.CallBooleanMethod(obj_ArrayListItems.GetRawObject(), method_Add, AndroidJNIHelper.CreateJNIArgArray(new string[] {item})); } Debug.Log(String.Format("Selected item -> {0}", selectedItem)); _pluginObject.Call("showPicker", (int)type, obj_ArrayListItems, selectedItem, "NativePicker"); #else return; #endif }
private BufferedColor PickColor1D(BufferedColor color, PickerType type, float value) { switch (type) { case PickerType.R: return(color.PickR(Mathf.Lerp(AS.r.min, AS.r.max, value))); case PickerType.G: return(color.PickG(Mathf.Lerp(AS.g.min, AS.g.max, value))); case PickerType.B: return(color.PickB(Mathf.Lerp(AS.b.min, AS.b.max, value))); case PickerType.H: return(color.PickH(Mathf.Lerp(AS.h.min, AS.h.max, value) * HUE_LOOP)); case PickerType.S: return(color.PickS(Mathf.Lerp(AS.s.min, AS.s.max, value))); case PickerType.V: return(color.PickV(Mathf.Lerp(AS.v.min, AS.v.max, value))); case PickerType.A: return(color.PickA(Mathf.Lerp(AS.a.min, AS.a.max, value))); default: throw new Exception("Picker type " + type + " is not associated with a single color value."); } }
/// <summary> /// Get normalized value of the current color according to the given picker. /// This value can be used to adjust the position of the marker on a slider. /// </summary> private float GetValue1D(PickerType type) { switch (type) { case PickerType.R: return(Mathf.InverseLerp(AS.r.min, AS.r.max, bufferedColor.r)); case PickerType.G: return(Mathf.InverseLerp(AS.g.min, AS.g.max, bufferedColor.g)); case PickerType.B: return(Mathf.InverseLerp(AS.b.min, AS.b.max, bufferedColor.b)); case PickerType.H: return(Mathf.InverseLerp(AS.h.min, AS.h.max, bufferedColor.h / HUE_LOOP)); case PickerType.S: return(Mathf.InverseLerp(AS.s.min, AS.s.max, bufferedColor.s)); case PickerType.V: return(Mathf.InverseLerp(AS.v.min, AS.v.max, bufferedColor.v)); case PickerType.A: return(Mathf.InverseLerp(AS.a.min, AS.a.max, bufferedColor.a)); default: throw new Exception("Picker type " + type + " is not associated with a single color value."); } }
private void UpdateStatic(PickerType type) { if (!IsPickerAvailable(type)) { return; } Picker p = pickers[(int)type]; bool hor = IsHorizontal(p); Sprite s = hor ? p.staticSpriteHor : p.staticSpriteVer; if (s == null) { s = hor ? p.staticSpriteVer : p.staticSpriteHor; } p.image.sprite = s; p.image.material = null; p.image.color = Color.white; Color prvw = color; switch (type) { case PickerType.Main: p.image.sprite = staticSpriteMain[(int)mode]; break; case PickerType.Preview: prvw.a = 1f; p.image.color = prvw; break; case PickerType.PreviewAlpha: p.image.color = prvw; break; } }
void makeJNICall(PickerType type, string[] items, long selectedItem) { if (isMobileRuntime == false) { return; } #if UNITY_ANDROID AndroidJavaObject obj_ArrayListItems = new AndroidJavaObject("java.util.ArrayList"); IntPtr method_Add = AndroidJNIHelper.GetMethodID(obj_ArrayListItems.GetRawClass(), "add", "(Ljava/lang/Object;)Z"); foreach (string item in items) { AndroidJNI.CallBooleanMethod(obj_ArrayListItems.GetRawObject(), method_Add, AndroidJNIHelper.CreateJNIArgArray(new string[] { item })); } Debug.Log(String.Format("Selected item -> {0}", selectedItem)); _pluginObject.Call("showPicker", (int)type, obj_ArrayListItems, selectedItem, "NativePicker"); #else return; #endif }
private static extern void showPicker(PickerType type, string[] items, int numItems, long selectedItem, int x, int y, int w, int h, string gameObject);
/// <summary> /// Creates a picker with custom options in multiple columns. /// </summary> public PickerElement(string caption, IEnumerable<string[]> entries, params int[] selected) : base(caption) { pickerType = PickerType.Custom; if (pickerView == null) { pickerView = new UIPickerView(new RectangleF(0, 152, 320, 100)); pickerView.ShowSelectionIndicator = true; } if (toolBar == null) { toolBar = new UIToolbar(new RectangleF(0, 108, 320, 44)); toolBar.BarStyle = UIBarStyle.Black; } pickerData = new PickerData(entries); pickerData.ValueSelected += () => { for (int i = 0; i < selectedRows.Length; i++) selectedRows[i] = pickerView.SelectedRowInComponent(i); if (RowsSelected != null) RowsSelected(selectedRows); FormatValue(); }; int count = entries.Count(); selectedRows = new int[count]; string formatter = ""; for (int i = 0; i < count; i++) { // the default format string simply separates each string with a space formatter += " {" + i + "}"; if (selected.Length > i) selectedRows[i] = selected[i]; } FormatString = formatter.Trim(); }
/// <summary> /// Creates a date/time picker. /// </summary> public PickerElement(string caption, DateTime value, UIDatePickerMode mode) : base(caption, FormatDate(value)) { pickerType = PickerType.Date; dateTime = value; dateMode = mode; if (datePickerView == null) { datePickerView = new UIDatePicker(new RectangleF(0, 152, 320, 100)); } datePickerView.ValueChanged += delegate(object sender, EventArgs e) { if (activeCell == cell) { dateTime = datePickerView.Date; Value = FormatDate(dateTime); cell.DetailTextLabel.Text = Value; cell.SetNeedsLayout(); cell.SetNeedsDisplay(); } }; if (toolBar == null) { toolBar = new UIToolbar(new RectangleF(0, 108, 320, 44)); toolBar.BarStyle = UIBarStyle.Black; } }