protected override void OnStartDemo(SampleViewport viewport) { var box1 = new LayoutFarm.CustomWidgets.SimpleBox(50, 50); box1.BackColor = Color.Red; box1.SetLocation(10, 10); viewport.AddContent(box1); //-------------------------------- var box2 = new LayoutFarm.CustomWidgets.SimpleBox(30, 30); box2.SetLocation(50, 50); viewport.AddContent(box2); //1. mouse down box1.MouseDown += (s, e) => { box1.BackColor = KnownColors.FromKnownColor(KnownColor.DeepSkyBlue); box2.Visible = false; }; box1.MouseUp += (s, e) => { box1.BackColor = Color.Red; box2.Visible = true; }; }
void SetupActiveBoxProperties(LayoutFarm.CustomWidgets.EaseBox box) { //1. mouse down box.MouseDown += (s, e) => { box.BackColor = KnownColors.FromKnownColor(KnownColor.DeepSkyBlue); e.MouseCursorStyle = MouseCursorStyle.Pointer; //-------------------------------------------- //move controller here controllerBox1.SetBounds(box.Left - 5, box.Top - 5, box.Width + 10, box.Height + 10); controllerBox1.Visible = true; controllerBox1.TargetBox = box; e.SetMouseCapture(controllerBox1); }; //2. mouse up box.MouseUp += (s, e) => { e.MouseCursorStyle = MouseCursorStyle.Default; box.BackColor = Color.LightGray; controllerBox1.Visible = false; controllerBox1.TargetBox = null; }; }
public static Color ConvertFromString(string colorString, IFormatProvider formatProvider) { var normalized = colorString.Trim(); if (normalized.StartsWith("#") && normalized.Length == 9) { if (normalized.Length == 9) { var a = byte.Parse(colorString.Substring(1, 2), NumberStyles.HexNumber, formatProvider); var r = byte.Parse(colorString.Substring(3, 2), NumberStyles.HexNumber, formatProvider); var g = byte.Parse(colorString.Substring(5, 2), NumberStyles.HexNumber, formatProvider); var b = byte.Parse(colorString.Substring(7, 2), NumberStyles.HexNumber, formatProvider); return(Color.FromArgb(a, r, g, b)); } if (normalized.Length == 7) { var r = byte.Parse(colorString.Substring(1, 2), NumberStyles.HexNumber, formatProvider); var g = byte.Parse(colorString.Substring(3, 2), NumberStyles.HexNumber, formatProvider); var b = byte.Parse(colorString.Substring(5, 2), NumberStyles.HexNumber, formatProvider); return(Color.FromArgb(0xFF, r, g, b)); } } Color color; return(KnownColors.TryGetColor(normalized, out color) ? color : Colors.Transparent); }
UIControllerBox GetFreeUserControllerBox() { if (userControllerPool.Count > 0) { var controlBox = userControllerPool.Dequeue(); //------------------------------------------- //register to working box list workingControllerBoxes.Add(controlBox); return(controlBox); } else { //create new one //controller box 1 (red corners) var controllerBox1 = new UIControllerBox(40, 40); Color c = KnownColors.FromKnownColor(KnownColor.Yellow); controllerBox1.BackColor = new Color(100, c.R, c.G, c.B); controllerBox1.SetLocation(200, 200); //controllerBox1.dbugTag = 3; controllerBox1.Visible = false; SetupControllerBoxProperties(controllerBox1); //------------------------------------------- //register to working box list workingControllerBoxes.Add(controllerBox1); return(controllerBox1); } }
public ColorSchemeController() { // force init color table byte unused = SystemColors.Window.R; var systemDrawingAssembly = typeof(Color).Assembly; _colorTableField = systemDrawingAssembly.GetType("System.Drawing.KnownColorTable") .GetField("colorTable", BindingFlags.Static | BindingFlags.NonPublic); _colorTable = readColorTable(); SystemEvents.UserPreferenceChanging += userPreferenceChanging; OriginalColors = _colorTable.ToArray(); KnownOriginalColors = KnownColors.Cast <int>() .ToDictionary(i => i, i => OriginalColors[i]) .AsReadOnlyDictionary(); _threadDataProperty = systemDrawingAssembly.GetType("System.Drawing.SafeNativeMethods") .GetNestedType("Gdip", BindingFlags.NonPublic) .GetProperty("ThreadData", BindingFlags.Static | BindingFlags.NonPublic); SystemBrushesKey = typeof(SystemBrushes) .GetField("SystemBrushesKey", BindingFlags.Static | BindingFlags.NonPublic) .GetValue(null); SystemPensKey = typeof(SystemPens) .GetField("SystemPensKey", BindingFlags.Static | BindingFlags.NonPublic) .GetValue(null); }
void SetupActiveBoxProperties(LayoutFarm.CustomWidgets.Box box) { //1. mouse down box.MouseDown += (s, e) => { box.BackColor = KnownColors.FromKnownColor(KnownColor.DeepSkyBlue); e.MouseCursorStyle = MouseCursorStyle.Pointer; //-------------------------------------------- //move controller here _controllerBox1.TargetBox = box; _controllerBox1.SetLocation(box.Left - 5, box.Top - 5); _controllerBox1.SetSize(box.Width + 10, box.Height + 10); _controllerBox1.Visible = true; //-------------------------------------------- e.CancelBubbling = true; //change mouse capture to another control e.SetMouseCapturedElement(_controllerBox1); }; //2. mouse up box.MouseUp += (s, e) => { e.MouseCursorStyle = MouseCursorStyle.Default; box.BackColor = KnownColors.LightGray; //hide controller _controllerBox1.Visible = false; _controllerBox1.TargetBox = null; e.CancelBubbling = true; }; }
private static bool SerializeOn(BinaryWriter writer, string stringValue) { if (writer == null) { throw new ArgumentNullException("writer"); } KnownColor knownColor = KnownColors.ColorStringToKnownColor(stringValue); if (knownColor != KnownColor.UnknownColor) { // Serialize values of the type "Red", "Blue" and other names writer.Write((byte)SerializationBrushType.KnownSolidColor); writer.Write((uint)knownColor); return(true); } else { // Serialize values of the type "#F00", "#0000FF" and other hex color values. // We don't have a good way to check if this is valid without running the // converter at this point, so just store the string if it has at least a // minimum length of 4. stringValue = stringValue.Trim(); if (stringValue.Length > 3) { writer.Write((byte)SerializationBrushType.OtherColor); writer.Write(stringValue); return(true); } } return(false); }
protected override void OnStartDemo(SampleViewport viewport) { //grid0 { var gridBox = new LayoutFarm.CustomWidgets.GridBox(100, 100); gridBox.SetLocation(50, 50); gridBox.BuildGrid(2, 4, CellSizeStyle.UniformCell); viewport.AddContent(gridBox); } //grid1 { var gridBox = new LayoutFarm.CustomWidgets.GridBox(100, 100); gridBox.SetLocation(200, 50); gridBox.BuildGrid(2, 4, CellSizeStyle.UniformCell); viewport.AddContent(gridBox); var simpleButton = new LayoutFarm.CustomWidgets.SimpleBox(20, 20); simpleButton.BackColor = KnownColors.FromKnownColor(KnownColor.OliveDrab); gridBox.AddUI(simpleButton, 1, 1); } //----- //grid2 { var gridBox = new LayoutFarm.CustomWidgets.GridBox(100, 100); gridBox.SetLocation(350, 50); gridBox.BuildGrid(3, 8, CellSizeStyle.UniformCell); viewport.AddContent(gridBox); } }
internal static object DeserializeFrom(BinaryReader reader, ITypeDescriptorContext context) { SerializationBrushType brushType = (SerializationBrushType)reader.ReadByte(); if (brushType == SerializationBrushType.KnownSolidColor) { uint knownColorUint = reader.ReadUInt32(); SolidColorBrush scp = KnownColors.SolidColorBrushFromUint(knownColorUint); #if !PBTCOMPILER lock (s_knownSolidColorBrushStringCache) { if (!s_knownSolidColorBrushStringCache.ContainsKey(scp)) { string strColor = scp.Color.ConvertToString(null, System.Windows.Markup.TypeConverterHelper.InvariantEnglishUS); s_knownSolidColorBrushStringCache[scp] = strColor; } } #endif return(scp); } else if (brushType == SerializationBrushType.OtherColor) { string colorValue = reader.ReadString(); BrushConverter converter = new BrushConverter(); return(converter.ConvertFromInvariantString(context, colorValue)); } else { throw new Exception(SR.Get(SRID.BrushUnknownBamlType)); } }
protected override void OnStart(AppHost host) { var box1 = new LayoutFarm.CustomWidgets.Box(50, 50); box1.BackColor = Color.Red; box1.SetLocation(10, 10); //box1.dbugTag = 1; SetupActiveBoxProperties(box1); host.AddChild(box1); var box2 = new LayoutFarm.CustomWidgets.Box(30, 30); box2.SetLocation(50, 50); //box2.dbugTag = 2; SetupActiveBoxProperties(box2); host.AddChild(box2); _controllerBox1 = new UIControllerBox(40, 40); Color c = KnownColors.FromKnownColor(KnownColor.Yellow); _controllerBox1.BackColor = new Color(100, c.R, c.G, c.B); _controllerBox1.SetLocation(200, 200); //controllerBox1.dbugTag = 3; _controllerBox1.Visible = false; SetupControllerBoxProperties(_controllerBox1); host.AddChild(_controllerBox1); }
public static string AsText(this Color c) { bool ColorEquals(KeyValuePair <string, Color> kv) { var c2 = kv.Value; return(c2.A == c.A && c2.R == c.R && c2.G == c.G && c2.B == c.B); } var l = KnownColors.Where(ColorEquals); using (var en = l.GetEnumerator()) { if (en.MoveNext()) { return(en.Current.Key); } } StringBuilder result = new StringBuilder(); result.Append("#"); if (c.A != 255) { result.Append($"{c.A:x2}"); } result.Append($"{c.R:x2}"); result.Append($"{c.G:x2}"); result.Append($"{c.B:x2}"); return(result.ToString()); }
public IEnumerable <Color> GetAvailableColors() { RecalculateProperty(KnownColors); return(KnownColors .Where(color => color.Value.GetValueOrDefault(true)) .Select(color => color.Key)); }
protected override void OnStart(AppHost host) { var listbox = new LayoutFarm.CustomWidgets.ListBox(300, 400); listbox.SetLocation(10, 10); listbox.BackColor = KnownColors.FromKnownColor(KnownColor.LightGray); //add list view to viewport host.AddChild(listbox); //add RequestFont listItemFont = new RequestFont("tahoma", 18); for (int i = 0; i < 10; ++i) { var listItem = new LayoutFarm.CustomWidgets.ListItem(400, 20); if ((i % 2) == 0) { listItem.BackColor = KnownColors.FromKnownColor(KnownColor.OrangeRed); } else { listItem.BackColor = KnownColors.FromKnownColor(KnownColor.Orange); } listItem.SetFont(listItemFont); listItem.Text = "A" + i; listbox.AddItem(listItem); } }
public override RenderElement GetPrimaryRenderElement(RootGraphic rootgfx) { if (_gridViewRenderE == null) { var myGridBox = new GridViewRenderElement(rootgfx, this.Width, this.Height); myGridBox.HasSpecificSize = true;//*** myGridBox.SetLocation(this.Left, this.Top); myGridBox.SetController(this); myGridBox.BackColor = KnownColors.FromKnownColor(KnownColor.LightGray); this.SetPrimaryRenderElement(myGridBox); this._gridViewRenderE = myGridBox; //create layers int nrows = this.gridTable.RowCount; int ncols = this.gridTable.ColumnCount; //---------------------------------------- myGridBox.BuildGrid(gridTable, this.CellSizeStyle); //add grid content for (int c = 0; c < ncols; ++c) { for (int r = 0; r < nrows; ++r) { var gridCell = gridTable.GetCell(r, c); var content = gridCell.ContentElement as UIElement; if (content != null) { myGridBox.SetContent(r, c, content); } } } } return(_gridViewRenderE); }
protected override void OnStartDemo(SampleViewport viewport) { var box1 = new LayoutFarm.CustomWidgets.SimpleBox(50, 50); box1.BackColor = Color.Red; box1.SetLocation(10, 10); //box1.dbugTag = 1; SetupActiveBoxProperties(box1); viewport.AddContent(box1); var box2 = new LayoutFarm.CustomWidgets.SimpleBox(30, 30); box2.SetLocation(50, 50); //box2.dbugTag = 2; SetupActiveBoxProperties(box2); viewport.AddContent(box2); controllerBox1 = new UIControllerBox(40, 40); Color c = KnownColors.FromKnownColor(KnownColor.Yellow); controllerBox1.BackColor = new Color(100, c.R, c.G, c.B); controllerBox1.SetLocation(200, 200); //controllerBox1.dbugTag = 3; controllerBox1.Visible = false; SetupControllerBoxProperties(controllerBox1); viewport.AddContent(controllerBox1); }
public static bool TryGetKnownColor(string color, out int rgb) { if (color == null) { throw new ArgumentNullException(nameof(color)); } return(KnownColors.TryGetValue(color, out rgb)); }
public int GetColor(KnownColor knownColor) { if (!KnownColors.Contains(knownColor)) { throw new ArgumentException(); } return(_colorTable[(int)knownColor]); }
[FriendAccessAllowed] // Built into Core, also used by Framework. internal static bool SerializeOn(BinaryWriter writer, string stringValue) { // ********* VERY IMPORTANT NOTE ***************** // If this method is changed, then XamlBrushSerilaizer.SerializeOn() needs // to be correspondingly changed as well. That code is linked into PBT.dll // and duplicates the code below to avoid pulling in SCB & base classes as well. // ********* VERY IMPORTANT NOTE ***************** if (writer == null) { throw new ArgumentNullException("writer"); } KnownColor knownColor = KnownColors.ColorStringToKnownColor(stringValue); #if !PBTCOMPILER // ***************** NOTE ***************** // This section under #if !PBTCOMPILER is not needed in XamlBrushSerializer.cs // because XamlBrushSerializer.SerializeOn() is only compiled when PBTCOMPILER is set. // If this code were tried to be compiled in XamlBrushSerializer.cs, it wouldn't compile // becuase of missing definition of s_knownSolidColorBrushStringCache. // This code is added in XamlBrushSerializer.cs nevertheless for maintaining consistency in the codebase // between XamlBrushSerializer.SerializeOn() and SolidColorBrush.SerializeOn(). // ***************** NOTE ***************** lock (s_knownSolidColorBrushStringCache) { if (s_knownSolidColorBrushStringCache.ContainsValue(stringValue)) { knownColor = KnownColors.ArgbStringToKnownColor(stringValue); } } #endif if (knownColor != KnownColor.UnknownColor) { // Serialize values of the type "Red", "Blue" and other names writer.Write((byte)SerializationBrushType.KnownSolidColor); writer.Write((uint)knownColor); return(true); } else { // Serialize values of the type "#F00", "#0000FF" and other hex color values. // We don't have a good way to check if this is valid without running the // converter at this point, so just store the string if it has at least a // minimum length of 4. stringValue = stringValue.Trim(); if (stringValue.Length > 3) { writer.Write((byte)SerializationBrushType.OtherColor); writer.Write(stringValue); return(true); } } return(false); }
void SetupCornerBoxController(PlotBox box) { Color c = KnownColors.FromKnownColor(KnownColor.Orange); box.BackColor = new Color(100, c.R, c.G, c.B); //controllerBox1.dbugTag = 3; box.Visible = true; SetupCornerProperties(box); // _controls.Add(box); }
void SetupHorizontalScrollButtonProperties(RenderElement container) { var scroll_button = new ScrollBarButton(10, this.Height, this); //create with default value scroll_button.BackColor = KnownColors.FromKnownColor(KnownColor.DarkBlue); int thumbPosX = CalculateThumbPosition() + minmax_boxHeight; scroll_button.SetLocation(thumbPosX, 0); container.AddChild(scroll_button); this.scrollButton = scroll_button; //---------------------------- EvaluateHorizontalScrollBarProperties(); //---------------------------- //3. drag scroll_button.MouseDrag += (s, e) => { //dragging ... //find x-diff Point pos = scroll_button.Position; //if vscroll bar then move only y axis int newXPos = (int)(pos.X + e.DiffCapturedX); //clamp! if (newXPos >= this.Width - (minmax_boxHeight + scrollButton.Width)) { newXPos = this.Width - (minmax_boxHeight + scrollButton.Width); } else if (newXPos < minmax_boxHeight) { newXPos = minmax_boxHeight; } //calculate value from position int currentMarkAt = (newXPos - minmax_boxHeight); this.scrollValue = (float)(onePixelFor * currentMarkAt); newXPos = CalculateThumbPosition() + minmax_boxHeight; scroll_button.SetLocation(newXPos, pos.Y); if (this.UserScroll != null) { this.UserScroll(this, EventArgs.Empty); } e.StopPropagation(); }; }
public static Color FindColorMatch(Color c) { uint argb = (uint)c.ToArgb(); for (int i = 0; i < KnownColors.ArgbValues.Length; i++) { if (argb == KnownColors.ArgbValues [i]) { return(KnownColors.FromKnownColor((KnownColor)i)); } } return(Color.Empty); }
public void GetNameReturnsName(KnownColor knownColor) { #if !NET_2_0 if ((short)knownColor > 167) { // can't assess these. return; } #endif var name = KnownColors.GetName(knownColor); Assert.False(string.IsNullOrWhiteSpace(name)); }
void SetupCornerBoxController(UIControllerBox box) { Color c = KnownColors.FromKnownColor(KnownColor.Orange); box.BackColor = new Color(100, c.R, c.G, c.B); box.SetLocation(200, 200); //controllerBox1.dbugTag = 3; box.Visible = false; SetupControllerBoxProperties2(box); //viewport.AddContent(box); // _controls.Add(box); }
void SetupEdge_Controller(UIControllerBox box) { Color c = KnownColors.FromKnownColor(KnownColor.Blue); box.BackColor = c;// new Color(200, c.R, c.G, c.B); box.SetLocation(200, 200); box.Visible = true; switch (box.MoveDirection) { case MoveDirection.XAxis: { box.MouseDrag += (s, e) => { Point pos = box.Position; box.SetLocation(pos.X + e.XDiff, pos.Y); //var targetBox = cornerBox.TargetBox; //if (targetBox != null) //{ // //move target box too // targetBox.SetLocation(newX + 5, newY + 5); //} e.CancelBubbling = true; }; } break; case MoveDirection.YAxis: { box.MouseDrag += (s, e) => { Point pos = box.Position; box.SetLocation(pos.X, pos.Y + e.YDiff); //var targetBox = cornerBox.TargetBox; //if (targetBox != null) //{ // //move target box too // targetBox.SetLocation(newX + 5, newY + 5); //} e.CancelBubbling = true; }; } break; } _controls.Add(box); }
void SetupMinButtonProperties(RenderElement container) { ScrollBarButton min_button; if (this.ScrollBarType == ScrollBarType.Horizontal) { min_button = new ScrollBarButton(minmax_boxHeight, this.Height, this); } else { min_button = new ScrollBarButton(this.Width, minmax_boxHeight, this); } min_button.BackColor = KnownColors.FromKnownColor(KnownColor.DarkGray); min_button.MouseUp += (s, e) => this.StepSmallToMin(); container.AddChild(min_button); this.minButton = min_button; }
protected override void OnStart(AppHost host) { var box_beh = new UIMouseBehaviour <Box>(); { box_beh.GuestMsg += (s, e) => { }; box_beh.MouseDown += (s, e) => { e.MouseCursorStyle = MouseCursorStyle.Pointer; }; box_beh.MouseUp += (s, e) => { e.MouseCursorStyle = MouseCursorStyle.Default; //box.BackColor = Color.LightGray; s.Source.BackColor = Color.FromArgb(50, KnownColors.FromKnownColor(KnownColor.DeepSkyBlue)); }; box_beh.MouseDrag += (s, e) => { Box box = s.Source; box.BackColor = Color.FromArgb(180, KnownColors.FromKnownColor(KnownColor.GreenYellow)); Point pos = box.Position; box.SetLocation(pos.X + e.XDiff, pos.Y + e.YDiff); e.MouseCursorStyle = MouseCursorStyle.Pointer; e.CancelBubbling = true; }; } //------------- { var box1 = new LayoutFarm.CustomWidgets.Box(50, 50); box1.BackColor = Color.Red; box1.SetLocation(10, 10); box_beh.AttachSharedBehaviorTo(box1); host.AddChild(box1); } //-------------------------------- { var box2 = new LayoutFarm.CustomWidgets.Box(30, 30); box2.SetLocation(50, 50); //box2.dbugTag = 2; box_beh.AttachSharedBehaviorTo(box2); host.AddChild(box2); } }
/// <summary> /// ParseBrush /// <param name="brush"> string with brush description </param> /// <param name="formatProvider">IFormatProvider for processing string</param> /// <param name="context">ITypeDescriptorContext</param> /// </summary> internal static Brush ParseBrush(string brush, IFormatProvider formatProvider, ITypeDescriptorContext context) { bool isPossibleKnownColor; bool isNumericColor; bool isScRgbColor; bool isContextColor; string trimmedColor = KnownColors.MatchColor(brush, out isPossibleKnownColor, out isNumericColor, out isContextColor, out isScRgbColor); if (trimmedColor.Length == 0) { throw new FormatException(SR.Get(SRID.Parser_Empty)); } // Note that because trimmedColor is exactly brush.Trim() we don't have to worry about // extra tokens as we do with TokenizerHelper. If we return one of the solid color // brushes then the ParseColor routine (or ColorStringToKnownColor) matched the entire // input. if (isNumericColor) { return(new SolidColorBrush(ParseHexColor(trimmedColor))); } if (isContextColor) { return(new SolidColorBrush(ParseContextColor(trimmedColor, formatProvider, context))); } if (isScRgbColor) { return(new SolidColorBrush(ParseScRgbColor(trimmedColor, formatProvider))); } if (isPossibleKnownColor) { SolidColorBrush scp = KnownColors.ColorStringToKnownBrush(trimmedColor); if (scp != null) { return(scp); } } // If it's not a color, so the content is illegal. throw new FormatException(SR.Get(SRID.Parsers_IllegalToken)); }
void SetupVerticalScrollButtonProperties(RenderElement container) { var scroll_button = new ScrollBarButton(this.Width, 10, this); //create with default value scroll_button.BackColor = KnownColors.FromKnownColor(KnownColor.DarkBlue); int thumbPosY = CalculateThumbPosition() + _minmax_boxHeight; scroll_button.SetLocation(0, thumbPosY); container.AddChild(scroll_button); _scrollButton = scroll_button; //---------------------------- EvaluateVerticalScrollBarProperties(); //---------------------------- //3. drag scroll_button.MouseDrag += (s, e) => { //dragging ... Point pos = scroll_button.Position; //if vscroll bar then move only y axis int newYPos = (int)(pos.Y + e.DiffCapturedY); //clamp! if (newYPos >= this.Height - (_minmax_boxHeight + _scrollButton.Height)) { newYPos = this.Height - (_minmax_boxHeight + _scrollButton.Height); } else if (newYPos < _minmax_boxHeight) { newYPos = _minmax_boxHeight; } //calculate value from position int currentMarkAt = (newYPos - _minmax_boxHeight); _scrollValue = (float)(_onePixelFor * currentMarkAt); newYPos = CalculateThumbPosition() + _minmax_boxHeight; scroll_button.SetLocation(pos.X, newYPos); if (this.UserScroll != null) { this.UserScroll(this, EventArgs.Empty); } e.StopPropagation(); }; }
// FIXME: Linear scan public static Color_ FindColorMatch(Color_ c) { uint argb = (uint)c.ToArgb(); // 1-based const int first_real_color_index = (int)KnownColor.AliceBlue; const int last_real_color_index = (int)KnownColor.YellowGreen; for (int i = first_real_color_index - 1; i < last_real_color_index; i++) { if (argb == KnownColors.ArgbValues [i]) { return(KnownColors.FromKnownColor((KnownColor)i)); } } return(Color_.Empty); }
/// <summary> /// Retrieve or create a name for the specified color. /// </summary> /// <param name="color">Color that may or may not have a associated name.</param> /// <returns>The color's name or a name created based upon the ARGB values.</returns> public static string GetName(this Color color) { if (color.IsEmpty) { return("Empty"); } if (color.A == 0) { return(Color.Transparent.Name); } if (color.IsNamedColor) { return(color.Name); } var result = KnownColors.FirstOrDefault(c => c.R == color.R && c.G == color.G && c.B == color.B); return(!result.IsEmpty ? (color.A != 255 ? $"({color.A},{result.Name})" : result.Name) : (color.A != 255 ? $"({color.A},{color.R},{color.G},{color.B})" : $"({color.R},{color.G},{color.B})")); }