// Select this brush into a graphics object. public override void Select(IToolkitGraphics _graphics) { DrawingGraphics graphics = (_graphics as DrawingGraphics); if (graphics != null) { Xsharp.Graphics g = graphics.graphics; Xsharp.Bitmap bitmap; lock (typeof(DrawingHatchBrush)) { bitmap = GetBitmap(style); } g.Function = GCFunction.GXcopy; g.SubwindowMode = SubwindowMode.ClipByChildren; if (bitmap != null) { // Use an opaque stipple to fill the region. g.Foreground = DrawingToolkit.DrawingToXColor(foreColor); g.Background = DrawingToolkit.DrawingToXColor(backColor); g.SetFillOpaqueStippled(bitmap, 0, 0); } else { // We don't recognize this hatch style, so use a // solid brush with the foreground color. g.Foreground = DrawingToolkit.DrawingToXColor(foreColor); g.SetFillSolid(); } graphics.Brush = this; } }
// Select this brush into a graphics object. public override void Select(IToolkitGraphics _graphics) { DrawingGraphics graphics = (_graphics as DrawingGraphics); if (graphics != null) { Xsharp.Graphics g = graphics.graphics; g.Function = GCFunction.GXcopy; g.SubwindowMode = SubwindowMode.ClipByChildren; g.SetFillSolid(); g.Foreground = DrawingToolkit.DrawingToXColor(Color); graphics.Brush = this; } }
// Draw a bitmap-based glyph to a "Graphics" object. "bits" must be // in the form of an xbm bitmap. public override void DrawGlyph(int x, int y, byte[] bits, int bitsWidth, int bitsHeight, System.Drawing.Color color) { Xsharp.Bitmap bitmap; bitmap = new Xsharp.Bitmap(bitsWidth, bitsHeight, bits); try { graphics.Foreground = DrawingToolkit.DrawingToXColor(color); graphics.SetFillStippled(bitmap, x, y); graphics.FillRectangle(x, y, bitsWidth, bitsHeight); graphics.SetFillSolid(); } finally { bitmap.Destroy(); } }
// Paint this widget in response to an "Expose" event. protected override void OnPaint(Graphics graphics) { // Draw the thick 3D border around the outside first. graphics.DrawEffect(0, 0, width, height, Effect.Raised); // Get the rectangle containing the caption area. Rectangle rect = new Rectangle (FrameBorderSize, FrameBorderSize, width - FrameBorderSize * 2, captionHeight - FrameBorderSize); // If the rectangle does not overlap the expose region, // then there is no point drawing the main caption area. if(!graphics.ExposeRegion.Overlaps(rect)) { return; } // Get the colors to use for the foreground and background. Color foreground, background, endBackground; if((flags & CaptionFlags.Active) != 0) { foreground = new Color(StandardColor.HighlightForeground); background = new Color(StandardColor.HighlightBackground); endBackground = new Color(StandardColor.HighlightEndBackground); } else { foreground = new Color(StandardColor.Background); background = new Color(StandardColor.BottomShadow); endBackground = new Color(StandardColor.EndBackground); } // Create a gradient for the title bar, if necessary. if(gradient != null && (gradient.Width != rect.width || gradient.Height != rect.height)) { // The size has changed and we need a new gradient. gradient.Dispose(); gradient = null; } if(gradient == null && screen.DefaultDepth >= 15) { DotGNU.Images.Image image = CreateGradient (rect.width, rect.height, background, endBackground); gradient = new Xsharp.Image(screen, image.GetFrame(0)); image.Dispose(); } // Clear the caption background. if(gradient == null) { graphics.Foreground = background; graphics.SetFillSolid(); graphics.FillRectangle(rect); } else { graphics.SetFillTiled(gradient.Pixmap, rect.x, rect.y); graphics.FillRectangle(rect); graphics.SetFillSolid(); } // Draw the caption buttons and then subtract that // region off the caption rectangle so we don't get // bleed through when we draw the caption text. rect.width -= DrawCaptionButtons (graphics, rect, flags, (CaptionFlags)(~0)); // Bail out if the rectangle is too small for the text. if(rect.width <= 2) { return; } // Position the caption text. Font font = GetCaptionFont(); FontExtents extents = font.GetFontExtents(graphics); int textY = (rect.height - extents.Ascent) / 2; textY += rect.y + extents.Ascent; // Draw the caption text, clipped to the caption area // so that it won't overwrite the buttons on the right. using(Region region = new Region(graphics.ExposeRegion)) { region.Intersect(rect); graphics.SetClipRegion(region); graphics.Foreground = foreground; graphics.DrawString(rect.x + 2, textY, child.Name, font); } }
// Select this pen into a graphics object. public override void Select(IToolkitGraphics _graphics) { if (_graphics == null) { return; } if (_graphics is DrawingGraphics) { DrawingGraphics graphics = _graphics as DrawingGraphics; Xsharp.Graphics g = graphics.graphics; int width = (int)(properties.Width); LineStyle style = MapLineStyle(properties.DashStyle); if (style == LineStyle.LineOnOffDash) { if (width == 1) { width = 0; } switch (properties.DashStyle) { case DashStyle.Dash: { g.DashPattern = dash; } break; case DashStyle.Dot: { g.DashPattern = dot; } break; case DashStyle.DashDot: { g.DashPattern = dashdot; } break; case DashStyle.DashDotDot: { g.DashPattern = dashdotdot; } break; case DashStyle.Custom: { float [] src = properties.DashPattern; int iLen = src.Length; byte [] ayCopy = new byte[iLen]; float fWidth = properties.Width; float tmp; for (int i = 0; i < iLen; i++) { tmp = src[i] * fWidth; if (tmp < 0) { tmp = 0; } else if (tmp > 0xFF) { tmp = 0xFF; } ayCopy[i] = (byte)(tmp); if (ayCopy[i] == 0) { ayCopy[i] = 1; // must not be zero } } g.DashPattern = ayCopy; } break; } } g.Function = GCFunction.GXcopy; g.SubwindowMode = SubwindowMode.ClipByChildren; g.LineWidth = width; g.LineStyle = style; g.CapStyle = MapCapStyle(properties.EndCap); g.JoinStyle = MapJoinStyle(properties.LineJoin); g.Foreground = DrawingToolkit.DrawingToXColor (properties.Color); g.SetFillSolid(); graphics.Pen = this; } else if (_graphics is DrawingGraphicsImage) { DrawingGraphicsImage graphics = _graphics as DrawingGraphicsImage; graphics.Pen = this; } }