// Constructor. public DrawingWindowBuffer(IToolkitWindow windowToBuffer) { toolkit = windowToBuffer.Toolkit; widget = windowToBuffer as InputOutputWidget; buffer = null; graphics = null; }
// Begin a double buffer operation. public IToolkitGraphics BeginDoubleBuffer() { // Create the double buffer if necessary. if(buffer == null) { CreateBuffer(widget.Width, widget.Height); } // Create a graphics object for the buffer and return it. graphics = new DrawingGraphics (toolkit, new Xsharp.Graphics(buffer)); return graphics; }
// WM_PAINT Message internal void Paint() { Win32.Api.PAINTSTRUCT myPS = new System.Drawing.Win32.Api.PAINTSTRUCT(); hdc = Win32.Api.BeginPaint(hwnd, ref myPS); if (sink != null) { DrawingGraphics g = new DrawingGraphics(toolkit, hdc); Region clip = new Region(Rectangle.FromLTRB(myPS.rcPaintLeft, myPS.rcPaintTop, myPS.rcPaintRight, myPS.rcPaintBottom)); System.Drawing.Graphics gr = ToolkitManager.CreateGraphics(g, clip); try { sink.ToolkitExpose(gr); } finally { // EndPaint deletes the hdc but that doesnt matter. Win32.Api.EndPaint(hwnd, ref myPS); gr.Dispose(); } //Console.WriteLine( "DrawingWindow.Paint "+ sink +","+gr.ClipBounds.ToString()); } }
public DrawingHatchBrush(IToolkit toolkit, HatchStyle style, System.Drawing.Color foreColor, System.Drawing.Color backColor) : base(toolkit, backColor) { this.foreColor = DrawingGraphics.ColorToWin32(foreColor); this.backColor = DrawingGraphics.ColorToWin32(backColor); IntPtr hBi; lock (typeof(DrawingHatchBrush)) { hBi = GetBitmap(style); } if (hBi != IntPtr.Zero) { hBrush = Win32.Api.CreatePatternBrush(hBi); } else { //not one of the types we recognize, so make it a solid brush hBrush = DrawingSolidBrush.CreateSolidBrush(foreColor); } }
// Handle a paint event from Xsharp. protected override void OnPaint(Xsharp.Graphics graphics) { if(sink != null) { System.Drawing.Region clip = DrawingWindow.RegionToDrawingRegion (graphics.ExposeRegion); DrawingGraphics g = new DrawingGraphics(toolkit, graphics); using(System.Drawing.Graphics gr = ToolkitManager.CreateGraphics(g, clip)) { sink.ToolkitExpose(gr); } } }
// WM_PAINT Message internal void Paint() { Win32.Api.PAINTSTRUCT myPS = new System.Drawing.Win32.Api.PAINTSTRUCT(); hdc = Win32.Api.BeginPaint(hwnd, ref myPS ); if( sink != null ) { DrawingGraphics g = new DrawingGraphics(toolkit, hdc); Region clip = new Region(Rectangle.FromLTRB(myPS.rcPaintLeft, myPS.rcPaintTop, myPS.rcPaintRight, myPS.rcPaintBottom)); System.Drawing.Graphics gr = ToolkitManager.CreateGraphics(g, clip); try { sink.ToolkitExpose(gr); } finally { // EndPaint deletes the hdc but that doesnt matter. Win32.Api.EndPaint( hwnd, ref myPS); gr.Dispose(); } //Console.WriteLine( "DrawingWindow.Paint "+ sink +","+gr.ClipBounds.ToString()); } }
// End a double buffer operation, flusing the buffer back to the widget. public void EndDoubleBuffer() { if(graphics != null) { // Dispose of the IToolkitGraphics object and // the underlying double-buffered "Xsharp.Graphics" // object. Dispose that will update the screen. graphics.Dispose(); graphics = null; } }
// Set this window's minimum size. void IToolkitTopLevelWindow.SetMinimumSize(Size size) { SetMinimumSize(DrawingGraphics.RestrictXY(size.Width), DrawingGraphics.RestrictXY(size.Height)); }
// 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; } }