예제 #1
0
        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;
        }
예제 #2
0
 public DrawingContext(Bitmap bmp)
 {
     bitmap = bmp;
     clipRect = new Rect(0, 0, bitmap.Width, bitmap.Height); // in screen coords
 }
예제 #3
0
        // 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);
        }
예제 #4
0
        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);
            }
        }
예제 #5
0
 public RenderTask(Control sender, Rect dirtyArea)
 {
     Sender = sender;
     DirtyArea = dirtyArea;
 }
예제 #6
0
        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());
        }
예제 #7
0
        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;
            }
        }
예제 #8
0
 public bool IntersectsScreenRect(Rect r)
 {
     return ScreenArea.Intersects(r);
 }
예제 #9
0
        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);
        }