public int GetBrushIndex(BrushType brush, Guid?customGuid = null) { Guid brushGuid = Guid.Empty; if (brush != BrushType.Custom) { brushGuid = GetBrushGuid(brush); } else { if (!customGuid.HasValue) { customGuid = Guid.Empty; } brushGuid = customGuid.Value; } //just perform a basic loop through the array to get the index, int index = -1; for (int i = 0; i < BrushIndex.Length; i++) { if (BrushIndex[i] == brushGuid) { index = i; break; } } if (index == -1) { //if no brush found then throw an exception to prevent corrupt files from being written. throw new BrushNotFoundException($"Brush: {brush.ToString()}, has not been added to the brush collection"); } return(index); }
/// <summary> /// Creates the brush. /// </summary> /// <returns>The new brush.</returns> /// <param name="stroke">Stroke.</param> /// <param name="name">Name.</param> /// <param name="options">Options.</param> public static IBrush CreateBrush(Stroke stroke, BrushType type, Dictionary <string, object> newOptions) { // if unable to instantiate, return LineBrush with default options by default // prerequisite: enum BrushType is constant with Brush class name IBrush o = (ScriptableObject.CreateInstance(type.ToString()) as IBrush) ?? ScriptableObject.CreateInstance <LineBrush> (); o.Initialize(stroke, newOptions); return(o); }
private Guid GetBrushGuid(BrushType brush) { Guid brushGuid = Guid.Empty; if (brush != BrushType.Custom) { //get the guid from the enum attribute var attr = typeof(BrushType).GetMember(brush.ToString())[0].GetCustomAttributes(typeof(BrushIdAttribute), false)[0] as BrushIdAttribute; if (attr != null) { brushGuid = attr.BrushGuid; } } return(brushGuid); }
protected override void OnDrawItem(DrawItemEventArgs e) { Graphics grfx = e.Graphics; Rectangle rectColor = new Rectangle(e.Bounds.Left, e.Bounds.Top, 2 * e.Bounds.Height, e.Bounds.Height); rectColor.Inflate(-1, -1); Rectangle rectText = new Rectangle(e.Bounds.Left + 2 * e.Bounds.Height, e.Bounds.Top, e.Bounds.Width - 2 * e.Bounds.Height, e.Bounds.Height); if (this.Enabled) { e.DrawBackground(); } BrushType item = e.Index >= 0 ? (BrushType)Items[e.Index] : BrushType.SolidBrush; SolidBrush foreColorBrush = new SolidBrush(e.ForeColor); Brush fillbrush = foreColorBrush; switch (item) { case BrushType.SolidBrush: fillbrush = new SolidBrush(e.ForeColor); break; case BrushType.HatchBrush: fillbrush = new HatchBrush(HatchStyle.Cross, e.BackColor, e.ForeColor); break; case BrushType.LinearGradientBrush: fillbrush = new LinearGradientBrush(rectColor, e.BackColor, e.ForeColor, LinearGradientMode.ForwardDiagonal); break; case BrushType.PathGradientBrush: GraphicsPath gp = new GraphicsPath(); gp.AddRectangle(rectColor); PathGradientBrush pgb = new PathGradientBrush(gp); pgb.CenterColor = e.ForeColor; fillbrush = pgb; break; } grfx.FillRectangle(fillbrush, rectColor); grfx.DrawString(item.ToString(), Font, foreColorBrush, rectText); }
/// <summary> /// Gets the default options. /// </summary> /// <returns>The default options.</returns> /// <param name="brushName">Brush name.</param> public static Dictionary <string, object> GetDefaultOptions(BrushType type) { // prerequisite: enum BrushType is constant with Brush class name string name = type.ToString(); // create temporary instance of brush object IBrush o = (ScriptableObject.CreateInstance(name) as IBrush); // TODO: try catch "could not create instance exception" if (o == null) { return(null); } // TODO: release temporary object o return(o.GetOptions()); }
/// <summary> /// 手柄输入 /// </summary> private void FixedUpdate() { if (ViveInput.GetPress(trackedObj.viveRole, ControllerButton.Trigger)) { Debug.Log("扳机按住"); tracker.transform.position = trackedObj.transform.position; ViveTexturePainter.Instance.VRTrackerSpary(trackedObj, tracker, color, brushType.ToString(), brushSize); } if (ViveInput.GetPressDown(trackedObj.viveRole, ControllerButton.Trigger)) { Debug.Log("扳机按下!"); } if (ViveInput.GetPressUp(trackedObj.viveRole, ControllerButton.Trigger)) { Debug.Log("扳机抬起!"); } }
private static SolidColorBrush GetBrush(IEditorFormatMap editorFormatMap, string propertyName, BrushType type, IWpfTextView textView) { var props = editorFormatMap.GetProperties(propertyName); var typeText = type.ToString(); object value = null; if (props.Contains(typeText)) { value = props[typeText]; } else { typeText += "Color"; if (props.Contains(typeText)) { value = props[typeText]; if (value is wpf.Color) { var color = (wpf.Color)value; var cb = new SolidColorBrush(color); cb.Freeze(); value = cb; } } else { //Background is often not found in editorFormatMap. Don't know why :( if (type == BrushType.Background) { value = textView.Background; } } } return((value as SolidColorBrush) ?? (type == BrushType.Background ? DefaultBackgroundBrush : DefaultForegroundBrush)); }
public override string ToString() { return(BrushType.ToString()); }