protected Control(int x, int y, int width, int height) { area = new Rect(x, y, width, height); children = new ControlCollection(this); //X = x; //Y = y; //Width = width; //Height = height; }
public DrawingContext(Bitmap bmp) { bitmap = bmp; clipRect = new Rect(0, 0, bitmap.Width, bitmap.Height); // in screen coords }
// in screen coordinates public void PushClippingRectangle(Rect ctrlScreenArea) { if (ctrlScreenArea.Width < 0 || ctrlScreenArea.Height < 0) throw new ArgumentException(); dx = ctrlScreenArea.X - translationX; dy = ctrlScreenArea.Y - translationY; translationX += dx; translationY += dy; Rect rect = ctrlScreenArea; if (clippingRectangles.Count > 0) { Rect previousRect = (Rect)clippingRectangles.Peek(); //Rect previousRect = (Rect)clippingRectangles[clippingRectangles.Count - 1]; rect = ctrlScreenArea.Intersection(previousRect); } clippingRectangles.Push(rect); //clippingRectangles.Add(rect); clipRect = rect; bitmap.SetClippingRectangle(rect.X, rect.Y, rect.Width, rect.Height); }
public void PopClippingRectangle() { if (clippingRectangles.Count > 0) { clippingRectangles.Pop(); //clippingRectangles.RemoveAt(clippingRectangles.Count - 1); Rect rect; if (clippingRectangles.Count == 0) rect = new Rect(0, 0, bitmap.Width, bitmap.Height); else rect = (Rect)clippingRectangles.Peek(); translationX -= dx; translationY -= dy; clipRect = rect; //bitmap.SetClippingRectangle(res.X, res.Y, res.Width, res.Height); } else { Rect rect = new Rect(0, 0, bitmap.Width, bitmap.Height); clipRect = rect; translationX -= dx; translationY -= dy; //bitmap.SetClippingRectangle(rect.X, rect.Y, rect.Width, rect.Height); } }
public RenderTask(Control sender, Rect dirtyArea) { Sender = sender; DirtyArea = dirtyArea; }
private void RenderTask(RenderTask task) { Rect contentRect = new Rect(0, 0, desktop.Width, desktop.Height); var dirtyRect = contentRect; if (task != null) dirtyRect = task.DirtyArea.Intersection(contentRect); if (dirtyRect.IsZero) return; //dt = DateTime.Now; var dc = new DrawingContext(bitmap); dc.PushClippingRectangle(dirtyRect); if (!dc.ClippingRectangle.IsZero) { desktop.RenderRecursive(dc); desktop.PostRenderRecursive(dc); } dc.PopClippingRectangle(); dc.Close(); //ts = DateTime.Now - dt; if (OnRenderRequest != null) OnRenderRequest(bitmap, dirtyRect); else bitmap.Flush(dirtyRect.X, dirtyRect.Y, dirtyRect.Width, dirtyRect.Height); //Rect dirtyRect2 = new Rect(0, 0, 300, 20); //dc = new DrawingContext(screen); //dc.PushClippingRectangle(dirtyRect2); //Font font = Resources.GetFont(Resources.FontResources.CourierNew_10); //dc.DrawRectangle(new SolidColorBrush(Color.White), null, 0, 0, 300, 20); //dc.DrawText(dirtyRect.ToString() + "; Render: " + ts.ToString(), font, Color.Red, 3, 3); //dc.PopClippingRectangle(); //dc.Close(); //screen.Flush(dirtyRect2.X, dirtyRect2.Y, dirtyRect2.Width, dirtyRect2.Height); //Debug.Print("Render task: " + ts.ToString()); }
public void Invalidate(Rect rect) { if (!isSuspended) { //scrollManager.Update(); Rect sa = ScreenArea; Rect r; if (!rect.IsZero) r = rect; else { r = dirtyArea; r.Combine(sa); } ProcessTask(new RenderTask(this, r)); if (rect.IsZero) dirtyArea = sa; } }
public bool IntersectsScreenRect(Rect r) { return ScreenArea.Intersects(r); }
protected override void OnRender(DrawingContext dc) { bool horizontal = orientation == Orientation.Horizontal; // background int trackRatio = 7; int a = horizontal ? Height / trackRatio : Width / trackRatio; if (horizontal) trackArea = new Rect(0, (Height - a) / 2, Width, a); else trackArea = new Rect((Width - a) / 2, 0, a, Height); Brush b = background ?? new SolidColorBrush(Color.DarkGray); Pen border = new Pen(Color.Gray, 0); dc.DrawRectangle(b, border, trackArea.X, trackArea.Y, trackArea.Width, trackArea.Height); // thumb int workarea = horizontal ? Width - thumbSize : Height - thumbSize; int x = horizontal ? workarea * value / 100 : 0; int y = horizontal ? 0 : Height - thumbSize - workarea * value / 100; if (horizontal) thumbArea = new Rect(x, y, thumbSize, Height); else thumbArea = new Rect(x, y, Width, thumbSize); Brush bb = foreground ?? new LinearGradientBrush(Color.LightGray, Color.Black); dc.DrawRectangle(bb, thumbBorder, thumbArea.X, thumbArea.Y, thumbArea.Width, thumbArea.Height); }