public static void DrawHandle(UI.Controls.Canvas canvas, XGraphics graphics, Palette palette, Rect bounds, DrawingContext context, bool alwaysAlpha, bool round) { if (bounds.Width <= 0 || bounds.Height <= 0) { return; } using (var quality = new Smoothing(graphics, XSmoothingMode.Default)) { XBrush brush; Pen pen; var alpha = 180; if (context.Selected) { if (!alwaysAlpha) { alpha = 255; } brush = palette.Gradient(bounds, Color.FromArgb(alpha, Color.LemonChiffon), Color.FromArgb(alpha, Color.DarkOrange)); pen = palette.Pen(Color.FromArgb(alpha, Color.Chocolate), 0); } else { brush = palette.Gradient(bounds, Color.FromArgb(alpha, Color.LightCyan), Color.FromArgb(alpha, Color.SteelBlue)); pen = palette.Pen(Color.FromArgb(alpha, Color.Navy), 0); } if (round) { graphics.DrawEllipse(brush, bounds.ToRectangleF()); // graphics.DrawRectangle(new XPen(Color.Red), bounds.ToRectangleF() ); graphics.DrawEllipse(pen, bounds.ToRectangleF()); } else { graphics.DrawRectangle(brush, bounds.ToRectangleF()); graphics.DrawRectangle(pen, bounds.ToRectangleF()); } } }
private void ColorListBox_DrawItem(object sender, DrawItemEventArgs e) { using (var palette = new Palette()) { e.DrawBackground(); var horizontalMargin = 2; var verticalMargin = 2; var width = 24; var colorBounds = new Rectangle(e.Bounds.Left + horizontalMargin, e.Bounds.Top + verticalMargin, width, e.Bounds.Height - verticalMargin * 2); var textBounds = new Rectangle(colorBounds.Right + horizontalMargin, e.Bounds.Top, e.Bounds.Width - colorBounds.Width - horizontalMargin * 2, e.Bounds.Height); e.Graphics.FillRectangle(palette.Brush(m_color[e.Index]), colorBounds); e.Graphics.DrawRectangle(palette.Pen(e.ForeColor, 0), colorBounds); e.Graphics.DrawString(m_colorListBox.Items[e.Index].ToString(), e.Font, palette.Brush(e.ForeColor), textBounds, StringFormats.Left); } }
private void RegionListBox_DrawItem(object sender, DrawItemEventArgs e) { using (var palette = new Palette()) { e.DrawBackground(); var colorBounds = new Rectangle(e.Bounds.Left + HORIZONTAL_MARGIN, e.Bounds.Top + VERTICAL_MARGIN, WIDTH, e.Bounds.Height - VERTICAL_MARGIN * 2); var textBounds = new Rectangle(colorBounds.Right + HORIZONTAL_MARGIN, e.Bounds.Top, e.Bounds.Width - colorBounds.Width - HORIZONTAL_MARGIN * 2, e.Bounds.Height); var firstOrDefault = Settings.Regions.FirstOrDefault(p => p.RegionName == cboRegion.Items[e.Index].ToString()); if (firstOrDefault != null) { e.Graphics.FillRectangle(palette.Brush(firstOrDefault.RColor), colorBounds); } e.Graphics.DrawRectangle(palette.Pen(e.ForeColor, 0), colorBounds); e.Graphics.DrawString(cboRegion.Items[e.Index].ToString(), e.Font, palette.Brush(e.ForeColor), textBounds, StringFormats.Left); } }
private void RegionListBox_DrawItem(object sender, DrawItemEventArgs e) { if (e.Index < 0) { return; } Font txtColorFont = new Font("Arial", 6); using (var palette = new Palette()) { e.DrawBackground(); var colorBounds = new Rectangle(e.Bounds.Left + HORIZONTAL_MARGIN, e.Bounds.Top + VERTICAL_MARGIN, WIDTH, e.Bounds.Height - VERTICAL_MARGIN * 2); var textBounds = new Rectangle(colorBounds.Right + HORIZONTAL_MARGIN, e.Bounds.Top, e.Bounds.Width - colorBounds.Width - HORIZONTAL_MARGIN * 2, e.Bounds.Height); var foundRegion = Regions.FirstOrDefault(p => p.RegionName == m_RegionListing.Items[e.Index].ToString()); if (foundRegion != null) { e.Graphics.FillRectangle(palette.Brush(foundRegion.RColor), colorBounds); e.Graphics.DrawRectangle(palette.Pen(e.ForeColor, 0), colorBounds); e.Graphics.DrawString(m_RegionListing.Items[e.Index].ToString(), e.Font, palette.Brush(e.ForeColor), textBounds, StringFormats.Left); e.Graphics.DrawString("123", txtColorFont, palette.Brush(foundRegion.TextColor), colorBounds, StringFormats.Center); } } }
protected override void OnPaint(PaintEventArgs e) { if (DesignMode) { e.Graphics.Clear(Settings.Color[Colors.Canvas]); return; } foreach (var element in Project.Current.Elements) { element.Flagged = false; } foreach (var element in Canvas.SelectedElements) { element.Flagged = true; } using (var nativeGraphics = Graphics.FromHdc(e.Graphics.GetHdc())) { using (var graphics = XGraphics.FromGraphics(nativeGraphics, new XSize(Width, Height))) { using (var palette = new Palette()) { var clientArea = new Rectangle(0, 0, Width, Height); ControlPaint.DrawBorder3D(nativeGraphics, clientArea, Border3DStyle.Raised); clientArea.Inflate(-OuterBorderSize, -OuterBorderSize); nativeGraphics.FillRectangle(SystemBrushes.Control, clientArea); clientArea.Inflate(-OuterPadding, -OuterPadding); ControlPaint.DrawBorder3D(nativeGraphics, clientArea, Border3DStyle.SunkenOuter); clientArea.Inflate(-InnerBorderSize, -InnerBorderSize); nativeGraphics.FillRectangle(palette.CanvasBrush, clientArea); clientArea.Inflate(-InnerPadding, -InnerPadding); //nativeGraphics.FillRectangle(Brushes.Cyan, clientArea); var canvasBounds = Canvas != null ? Canvas.ComputeCanvasBounds(false) : Rect.Empty; var borderPen = palette.Pen(Settings.Color[Colors.Border], 0); foreach (var element in Project.Current.Elements) { if (element is Room) { var room = (Room)element; var roomBounds = CanvasToClient(room.InnerBounds.ToRectangleF(), canvasBounds, clientArea); graphics.DrawRectangle(borderPen, room.Flagged ? palette.BorderBrush : palette.FillBrush, roomBounds); } } if (Canvas != null) { // draw the viewport area as a selectable "handle" var viewportBounds = CanvasToClient(Canvas.Viewport.ToRectangleF(), canvasBounds, clientArea); viewportBounds.Intersect(clientArea); if (Project.Current.Elements.Count > 0) { var context = new DrawingContext(1f); context.Selected = m_draggingViewport; Drawing.DrawHandle(Canvas, graphics, palette, new Rect(viewportBounds), context, true, false); } } } } } e.Graphics.ReleaseHdc(); base.OnPaint(e); }
private void RegionListBox_DrawItem(object sender, DrawItemEventArgs e) { using (var palette = new Palette()) { e.DrawBackground(); var colorBounds = new Rectangle(e.Bounds.Left + HORIZONTAL_MARGIN, e.Bounds.Top + VERTICAL_MARGIN, WIDTH, e.Bounds.Height - VERTICAL_MARGIN*2); var textBounds = new Rectangle(colorBounds.Right + HORIZONTAL_MARGIN, e.Bounds.Top, e.Bounds.Width - colorBounds.Width - HORIZONTAL_MARGIN*2, e.Bounds.Height); var firstOrDefault = Settings.Regions.FirstOrDefault(p => p.RegionName == cboRegion.Items[e.Index].ToString()); if (firstOrDefault != null) e.Graphics.FillRectangle(palette.Brush(firstOrDefault.RColor), colorBounds); e.Graphics.DrawRectangle(palette.Pen(e.ForeColor, 0), colorBounds); e.Graphics.DrawString(cboRegion.Items[e.Index].ToString(), e.Font, palette.Brush(e.ForeColor), textBounds, StringFormats.Left); } }
protected override void OnPaint(PaintEventArgs e) { if (DesignMode) { e.Graphics.Clear(Settings.Color[Colors.Canvas]); return; } foreach (var element in Project.Current.Elements) { element.Flagged = false; } foreach (var element in Canvas.SelectedElements) { element.Flagged = true; } using (var nativeGraphics = Graphics.FromHdc(e.Graphics.GetHdc())) { using (var graphics = XGraphics.FromGraphics(nativeGraphics, new XSize(Width, Height))) { using (var palette = new Palette()) { var clientArea = new Rectangle(0, 0, Width, Height); ControlPaint.DrawBorder3D(nativeGraphics, clientArea, Border3DStyle.Raised); clientArea.Inflate(-OuterBorderSize, -OuterBorderSize); nativeGraphics.FillRectangle(SystemBrushes.Control, clientArea); clientArea.Inflate(-OuterPadding, -OuterPadding); ControlPaint.DrawBorder3D(nativeGraphics, clientArea, Border3DStyle.SunkenOuter); clientArea.Inflate(-InnerBorderSize, -InnerBorderSize); nativeGraphics.FillRectangle(palette.CanvasBrush, clientArea); clientArea.Inflate(-InnerPadding, -InnerPadding); //nativeGraphics.FillRectangle(Brushes.Cyan, clientArea); var canvasBounds = Canvas != null?Canvas.ComputeCanvasBounds(false) : Rect.Empty; var borderPen = palette.Pen(Settings.Color[Colors.Border], 0); foreach (var element in Project.Current.Elements) { if (element is Room) { var room = (Room)element; var roomBounds = CanvasToClient(room.InnerBounds.ToRectangleF(), canvasBounds, clientArea); graphics.DrawRectangle(borderPen, room.Flagged ? palette.BorderBrush : palette.FillBrush, roomBounds); } } if (Canvas != null) { // draw the viewport area as a selectable "handle" var viewportBounds = CanvasToClient(Canvas.Viewport.ToRectangleF(), canvasBounds, clientArea); viewportBounds.Intersect(clientArea); if (Project.Current.Elements.Count > 0) { var context = new DrawingContext(1f); context.Selected = m_draggingViewport; Drawing.DrawHandle(Canvas, graphics, palette, new Rect(viewportBounds), context, true, false); } } } } } e.Graphics.ReleaseHdc(); base.OnPaint(e); }
private void RegionListBox_DrawItem(object sender, DrawItemEventArgs e) { if (e.Index < 0) return; Font txtColorFont = new Font("Arial", 6); using (var palette = new Palette()) { e.DrawBackground(); var colorBounds = new Rectangle(e.Bounds.Left + HORIZONTAL_MARGIN, e.Bounds.Top + VERTICAL_MARGIN, WIDTH, e.Bounds.Height - VERTICAL_MARGIN * 2); var textBounds = new Rectangle(colorBounds.Right + HORIZONTAL_MARGIN, e.Bounds.Top, e.Bounds.Width - colorBounds.Width - HORIZONTAL_MARGIN * 2, e.Bounds.Height); var foundRegion = Regions.FirstOrDefault(p => p.RegionName == m_RegionListing.Items[e.Index].ToString()); if (foundRegion != null) { e.Graphics.FillRectangle(palette.Brush(foundRegion.RColor), colorBounds); e.Graphics.DrawRectangle(palette.Pen(e.ForeColor, 0), colorBounds); e.Graphics.DrawString(m_RegionListing.Items[e.Index].ToString(), e.Font, palette.Brush(e.ForeColor), textBounds, StringFormats.Left); e.Graphics.DrawString("123", txtColorFont, palette.Brush(foundRegion.TextColor), colorBounds, StringFormats.Center); } } }
private void ColorListBox_DrawItem(object sender, DrawItemEventArgs e) { using (var palette = new Palette()) { e.DrawBackground(); const int horizontalMargin = 2; const int verticalMargin = 2; const int width = 24; var colorBounds = new Rectangle(e.Bounds.Left + horizontalMargin, e.Bounds.Top + verticalMargin, width, e.Bounds.Height - verticalMargin * 2); var textBounds = new Rectangle(colorBounds.Right + horizontalMargin, e.Bounds.Top, e.Bounds.Width - colorBounds.Width - horizontalMargin * 2, e.Bounds.Height); e.Graphics.FillRectangle(palette.Brush(Color[e.Index]), colorBounds); e.Graphics.DrawRectangle(palette.Pen(e.ForeColor, 0), colorBounds); StringFormat format = new StringFormat {Trimming = StringTrimming.EllipsisCharacter}; e.Graphics.DrawString(m_colorListBox.Items[e.Index].ToString(), e.Font, palette.Brush(e.ForeColor), textBounds, format); } }
public static void DrawHandle(Canvas canvas, XGraphics graphics, Palette palette, Rect bounds, DrawingContext context, bool alwaysAlpha, bool round) { if (bounds.Width <= 0 || bounds.Height <= 0) { return; } using (var quality = new Smoothing(graphics, XSmoothingMode.Default)) { XBrush brush; Pen pen; var alpha = 180; if (context.Selected) { if (!alwaysAlpha) { alpha = 255; } brush = palette.Gradient(bounds, Color.FromArgb(alpha, Color.LemonChiffon), Color.FromArgb(alpha, Color.DarkOrange)); pen = palette.Pen(Color.FromArgb(alpha, Color.Chocolate), 0); } else { brush = palette.Gradient(bounds, Color.FromArgb(alpha, Color.LightCyan), Color.FromArgb(alpha, Color.SteelBlue)); pen = palette.Pen(Color.FromArgb(alpha, Color.Navy), 0); } if (round) { graphics.DrawEllipse(brush, bounds.ToRectangleF()); graphics.DrawEllipse(pen, bounds.ToRectangleF()); } else { graphics.DrawRectangle(brush, bounds.ToRectangleF()); graphics.DrawRectangle(pen, bounds.ToRectangleF()); } } }