예제 #1
0
        public void Draw()
        {
            const int WM_SETREDRAW = 0x000B;

            SendMessage(Handle, WM_SETREDRAW, 0, IntPtr.Zero); // supress redrawing
            TransformParams tr     = new TransformParams(0, 0, m_scale_factor);
            int             width  = (int)Math.Ceiling(tr.Transform(m_canvas_size.Width));
            int             height = (int)Math.Ceiling(tr.Transform(m_canvas_size.Height));

            if (m_drawable_object == null)
            {
                PrepareBitmap(MAIN_LAYER, width, height);
                SetupCanvas(width, height);
                picBoxCanvas.Image = canvas_view.Bitmap;
            }
            else
            {
                BitmapInfo main_layer = PrepareBitmap(MAIN_LAYER, width, height);
                m_drawable_object.Draw(main_layer.Graphics, tr);
                SetupCanvas(width, height);
                picBoxCanvas.Image = canvas_view.Bitmap;
            }
            SendMessage(Handle, WM_SETREDRAW, 1, IntPtr.Zero); // resume redrawing
            AutoScroll = true;                                 // update scrollbars
            Refresh();                                         // repaint control
        }
예제 #2
0
 // *** IDrawableObject interface implementation ***
 public void Draw(Graphics gfx, TransformParams tr)
 {
     foreach (IDrawableObject drawable_object in m_drawable_objects)
     {
         drawable_object.Draw(gfx, tr);
     }
 }
예제 #3
0
파일: Picture.cs 프로젝트: 0000duck/latino
        public static void Draw(Image image, float x, float y, Graphics g, TransformParams t, BoundingArea.ReadOnly boundingArea)
        {
//#if !NO_PARTIAL_RENDERING
//            Utils.ThrowException(g == null ? new ArgumentNullException("g") : null);
//            Utils.ThrowException(t == null ? new ArgumentNullException("t") : null);
//            // TODO: throw other exceptions
//            float width = t.Transform(image.Width);
//            float height = t.Transform(image.Height);
//            Vector2DF pos = t.Transform(new Vector2DF(x, y));
//            BoundingArea inflatedArea = boundingArea.GetWritableCopy();
//            inflatedArea.Inflate(5f, 5f);
//            // *** the following code is using relatively slow GDI+ clipping :-/
//            GraphicsPath gPath = new GraphicsPath();
//            foreach (RectangleF rect in inflatedArea.Rectangles)
//            {
//                gPath.AddRectangle(rect);
//            }
//            g.SetClip(gPath, CombineMode.Union);
//            PixelOffsetMode pixelOffsetMode = g.PixelOffsetMode;
//            g.PixelOffsetMode = PixelOffsetMode.Half;
//            g.DrawImage(image, pos.X, pos.Y, width, height);
//            g.ResetClip();
//            g.PixelOffsetMode = pixelOffsetMode;
//#else
            Draw(image, x, y, g, t);
//#endif
        }
예제 #4
0
        // ***********************

        public void Draw(BoundingArea.ReadOnly bounding_area, params IDrawableObject[] drawable_objects)
        {
            Utils.ThrowException(bounding_area == null ? new ArgumentNullException("bounding_area") : null);
            Utils.ThrowException(drawable_objects == null ? new ArgumentNullException("drawable_objects") : null);
            DateTime     start_time    = DateTime.Now;
            BoundingArea extended_area = bounding_area.GetWritableCopy();

            ExtendBoundingArea(extended_area, drawable_objects);
#if !NO_BB_SIMPLIFICATION
            extended_area.Optimize();
#endif
            TransformParams       tr = new TransformParams(0, 0, m_scale_factor);
            Set <IDrawableObject> outdated_objects = new Set <IDrawableObject>(drawable_objects);
            drawable_objects = m_drawable_object.GetObjectsIn(extended_area, tr);

            Rectangle enclosing_rect = GetEnclosingRect(extended_area.BoundingBox);

            BitmapInfo      render_layer = PrepareBitmap(RENDER_LAYER, enclosing_rect.Width, enclosing_rect.Height);
            TransformParams render_tr    = new TransformParams(-enclosing_rect.X, -enclosing_rect.Y, m_scale_factor);

            BoundingArea extended_area_tr = extended_area.Clone();
            extended_area_tr.Transform(new TransformParams(-enclosing_rect.X, -enclosing_rect.Y, 1));

            for (int i = drawable_objects.Length - 1; i >= 0; i--)
            {
                if (outdated_objects.Contains(drawable_objects[i]))
                {
                    drawable_objects[i].Draw(render_layer.Graphics, render_tr);
                }
                else
                {
                    drawable_objects[i].Draw(render_layer.Graphics, render_tr, extended_area_tr);
                }
            }
            BitmapInfo main_layer = m_bmp_cache[MAIN_LAYER];
            Graphics   canvas_gfx = Graphics.FromHwnd(picBoxCanvas.Handle);
            foreach (RectangleF rect in extended_area.Rectangles)
            {
                Rectangle view_area = GetEnclosingRect(rect);
                view_area.X -= enclosing_rect.X;
                view_area.Y -= enclosing_rect.Y;
                view_area.Intersect(new Rectangle(0, 0, enclosing_rect.Width, enclosing_rect.Height));
                EditableBitmap view = render_layer.EditableBitmap.CreateView(view_area);
                main_layer.Graphics.DrawImageUnscaled(view.Bitmap, view_area.X + enclosing_rect.X, view_area.Y + enclosing_rect.Y);
                // clipping to visible area?!?
                canvas_gfx.DrawImageUnscaled(view.Bitmap, view_area.X + enclosing_rect.X, view_area.Y + enclosing_rect.Y);
                //view_on_view.Dispose();
                view.Dispose();
            }
            canvas_gfx.Dispose();

            TimeSpan draw_time = DateTime.Now - start_time;
            m_draw_time += draw_time;
            m_draw_count++;

            FpsInfo.Text = string.Format("{0:0.00} ms / draw", (double)m_draw_time.TotalMilliseconds / (double)m_draw_count);
            m_draw_info.Add(draw_time.TotalMilliseconds);
            FpsInfo.Refresh();
        }
예제 #5
0
파일: Line.cs 프로젝트: mgrcar/Detextive
        public static bool IsObjectAt(float pt_x, float pt_y, TransformParams tr, float x1, float y1, float x2, float y2, ref float dist)
        {
            Utils.ThrowException(tr.NotSet ? new ArgumentValueException("tr") : null);
            Vector2D pt1 = tr.Transform(new Vector2D(x1, y1));
            Vector2D pt2 = tr.Transform(new Vector2D(x2, y2));

            return(VisualizationUtils.TestLineHit(new Vector2D(pt_x, pt_y), pt1, pt2, m_hit_dist, ref dist));
        }
예제 #6
0
        public static bool IsObjectAt(float ptX, float ptY, TransformParams t, float x1, float y1, float x2, float y2, ref float dist)
        {
            Utils.ThrowException(t == null ? new ArgumentNullException("t") : null);
            Vector2DF pt1 = t.Transform(new Vector2DF(x1, y1));
            Vector2DF pt2 = t.Transform(new Vector2DF(x2, y2));

            return(VisualizationUtils.TestLineHit(new Vector2DF(ptX, ptY), pt1, pt2, mHitDist, ref dist));
        }
예제 #7
0
 public void Transform(TransformParams tr)
 {
     Utils.ThrowException(tr.NotSet ? new ArgumentValueException("tr") : null);
     for (int i = 0; i < m_rects.Count; i++)
     {
         m_rects[i] = tr.Transform(m_rects[i]);
     }
     m_bounding_box = tr.Transform(m_bounding_box);
 }
예제 #8
0
        public override IDrawableObject GetObjectAt(float x, float y, TransformParams t, ref float dist)
        {
            Utils.ThrowException(t == null ? new ArgumentNullException("t") : null);
            float     width  = t.Transform(mWidth);
            float     height = t.Transform(mHeight);
            Vector2DF pos    = t.Transform(new Vector2DF(mX - mWidth / 2f, mY - mHeight / 2f));

            return(VisualizationUtils.PointInsideRect(x, y, new RectangleF(pos.X, pos.Y, width, height)) ? this : null);
        }
예제 #9
0
 public void Transform(TransformParams tr)
 {
     Utils.ThrowException(tr == null ? new ArgumentNullException("tr") : null);
     for (int i = 0; i < mRects.Count; i++)
     {
         mRects[i] = tr.Transform(mRects[i]);
     }
     mBoundingBox = tr.Transform(mBoundingBox);
 }
예제 #10
0
        public IDrawableObject[] GetObjectsIn(BoundingArea.ReadOnly bounding_area, TransformParams tr)
        {
            ArrayList <IDrawableObject> result = new ArrayList <IDrawableObject>();

            for (int i = m_drawable_objects.Count - 1; i >= 0; i--)
            {
                result.AddRange(m_drawable_objects[i].GetObjectsIn(bounding_area, tr));
            }
            return(result.ToArray());
        }
예제 #11
0
 public void Draw(Graphics gfx, TransformParams tr, BoundingArea.ReadOnly bounding_area)
 {
     foreach (IDrawableObject drawable_object in m_drawable_objects)
     {
         if (drawable_object.GetBoundingArea(tr).IntersectsWith(bounding_area))
         {
             drawable_object.Draw(gfx, tr, bounding_area);
         }
     }
 }
예제 #12
0
        public void ExtendBoundingArea(BoundingArea bounding_area, params IDrawableObject[] drawable_objects)
        {
            Utils.ThrowException(bounding_area == null ? new ArgumentNullException("bounding_area") : null);
            Utils.ThrowException(drawable_objects == null ? new ArgumentNullException("drawable_objects") : null);
            TransformParams tr = new TransformParams(0, 0, m_scale_factor);

            foreach (IDrawableObject drawable_object in drawable_objects)
            {
                bounding_area.AddRectangles(drawable_object.GetBoundingArea(tr).Rectangles);
            }
        }
예제 #13
0
        public override void Draw(Graphics g, TransformParams t)
        {
            Utils.ThrowException(g == null ? new ArgumentNullException("g") : null);
            Utils.ThrowException(t == null ? new ArgumentNullException("t") : null);
            Vector2DF pos = t.Transform(new Vector2DF(mX - mWidth / 2f, mY - mHeight / 2f));

            using (Font font = new Font(mFont.FontFamily, t.Transform(mFont.Size), mFont.Style))
            {
                g.DrawString(mLabel, font, mBrush, pos.X, pos.Y, StringFormat.GenericTypographic);
            }
        }
예제 #14
0
        public BoundingArea GetBoundingArea(TransformParams tr)
        {
            BoundingArea bounding_area = new BoundingArea();

            foreach (IDrawableObject drawable_object in m_drawable_objects)
            {
                bounding_area.AddRectangles(drawable_object.GetBoundingArea(tr).Rectangles);
            }
            // bounding_area.OptimizeArea();
            return(bounding_area);
        }
예제 #15
0
 public virtual IDrawableObject[] GetObjectsIn(BoundingArea.ReadOnly area, TransformParams tr)
 {
     Utils.ThrowException(area == null ? new ArgumentNullException("area") : null);
     Utils.ThrowException(tr == null ? new ArgumentNullException("tr") : null);
     if (GetBoundingArea(tr).IntersectsWith(area))
     {
         return(new IDrawableObject[] { this });
     }
     else
     {
         return(new IDrawableObject[] { });
     }
 }
예제 #16
0
        public virtual BoundingArea GetBoundingArea(TransformParams tr)
        {
            Utils.ThrowException(tr.NotSet ? new ArgumentValueException("tr") : null);
            if (m_bounding_area == null)
            {
                m_bounding_area = GetBoundingArea();
            }
            BoundingArea bounding_area = m_bounding_area.Clone();

            bounding_area.Transform(tr);
            lock (m_pen) { bounding_area.Inflate(m_pen.Width / 2f + 5f, m_pen.Width / 2f + 5f); }
            return(bounding_area);
        }
예제 #17
0
        public virtual BoundingArea GetBoundingArea(TransformParams tr)
        {
            Utils.ThrowException(tr == null ? new ArgumentNullException("tr") : null);
            if (mBoundingArea == null)
            {
                mBoundingArea = GetBoundingArea();
            }
            BoundingArea boundingArea = mBoundingArea.Clone();

            boundingArea.Transform(tr);
            lock (mPen) { boundingArea.Inflate(mPen.Width / 2f + 5f, mPen.Width / 2f + 5f); }
            return(boundingArea);
        }
예제 #18
0
파일: Picture.cs 프로젝트: 0000duck/latino
        public static void Draw(Image image, float x, float y, Graphics g, TransformParams t)
        {
            Utils.ThrowException(g == null ? new ArgumentNullException("g") : null);
            Utils.ThrowException(t == null ? new ArgumentNullException("t") : null);
            // TODO: throw other exceptions
            float           width           = t.Transform(image.Width);
            float           height          = t.Transform(image.Height);
            Vector2DF       pos             = t.Transform(new Vector2DF(x, y));
            PixelOffsetMode pixelOffsetMode = g.PixelOffsetMode;

            g.PixelOffsetMode = PixelOffsetMode.Half;
            g.DrawImage(image, pos.X, pos.Y, width, height);
            g.PixelOffsetMode = pixelOffsetMode;
        }
예제 #19
0
        // *** IDrawableObject interface implementation ***
        public virtual IDrawableObject[] GetObjectsAt(float x, float y, TransformParams tr, ref float[] distArray)
        {
            Utils.ThrowException(tr == null ? new ArgumentNullException("tr") : null);
            float           dist           = 0;
            IDrawableObject drawableObject = GetObjectAt(x, y, tr, ref dist);

            if (drawableObject != null)
            {
                distArray = new float[] { dist };
                return(new IDrawableObject[] { drawableObject });
            }
            else
            {
                distArray = new float[] { };
                return(new IDrawableObject[] { });
            }
        }
예제 #20
0
파일: Ellipse.cs 프로젝트: 0000duck/latino
        public static bool IsObjectAt(float ptX, float ptY, TransformParams tr, float cX, float cY, float rX, float rY)
        {
            Utils.ThrowException(tr.NotSet ? new ArgumentValueException("tr") : null);
            VectorF center = tr.Transform(new VectorF(cX, cY));
            VectorF pt     = new VectorF(ptX, ptY);

            if (pt == center)
            {
                return(true);
            }
            float angle = (pt - center).GetAngle();
            float x     = (float)Math.Cos(angle) * tr.Transform(rX);
            float y     = (float)Math.Sin(angle) * tr.Transform(rY);
            float r     = new VectorF(x, y).GetLength();

            return((center - pt).GetLength() <= r);
        }
예제 #21
0
파일: Ellipse.cs 프로젝트: mgrcar/Detextive
        public static bool IsObjectAt(float pt_x, float pt_y, TransformParams tr, float c_x, float c_y, float r_x, float r_y)
        {
            Utils.ThrowException(tr.NotSet ? new ArgumentValueException("tr") : null);
            Vector2D center = tr.Transform(new Vector2D(c_x, c_y));
            Vector2D pt     = new Vector2D(pt_x, pt_y);

            if (pt == center)
            {
                return(true);
            }
            float angle = (pt - center).GetAngle();
            float x     = (float)Math.Cos(angle) * tr.Transform(r_x);
            float y     = (float)Math.Sin(angle) * tr.Transform(r_y);
            float r     = new Vector2D(x, y).GetLength();

            return((center - pt).GetLength() <= r);
        }
예제 #22
0
        public IDrawableObject[] GetObjectsAt(float x, float y, TransformParams tr, ref float[] dist_array)
        {
            ArrayList <ObjectInfo> aux = new ArrayList <ObjectInfo>();

            for (int i = m_drawable_objects.Count - 1; i >= 0; i--)
            {
                IDrawableObject[] objects_at_xy = m_drawable_objects[i].GetObjectsAt(x, y, tr, ref dist_array);
                for (int j = 0; j < objects_at_xy.Length; j++)
                {
                    aux.Add(new ObjectInfo(aux.Count, dist_array[j], objects_at_xy[j]));
                }
            }
            aux.Sort();
            IDrawableObject[] result = new IDrawableObject[aux.Count];
            dist_array = new float[aux.Count];
            int k = 0;

            foreach (ObjectInfo object_info in aux)
            {
                result[k]       = object_info.DrawableObject;
                dist_array[k++] = object_info.Dist;
            }
            return(result);
        }
예제 #23
0
        private void DrawableObjectViewer_MouseMove(object sender, MouseEventArgs args)
        {
            const int WM_ACTIVATE = 0x0006;

            if (m_drawable_object != null)
            {
                TransformParams             tr                 = new TransformParams(0, 0, m_scale_factor);
                float[]                     dist_array         = null;
                IDrawableObject[]           new_target_objs    = m_drawable_object.GetObjectsAt(args.X, args.Y, tr, ref dist_array);
                Set <IDrawableObject>       new_target_obj_set = new Set <IDrawableObject>(new_target_objs);
                ArrayList <IDrawableObject> exit_objs          = new ArrayList <IDrawableObject>();
                ArrayList <IDrawableObject> enter_objs         = new ArrayList <IDrawableObject>();
                if (DrawableObjectMouseLeave != null || DrawableObjectToolTipRequest != null)
                {
                    foreach (IDrawableObject obj in m_target_objs)
                    {
                        if (!new_target_obj_set.Contains(obj))
                        {
                            exit_objs.Add(obj);
                        }
                    }
                }
                if (DrawableObjectMouseEnter != null || DrawableObjectToolTipRequest != null)
                {
                    foreach (IDrawableObject obj in new_target_objs)
                    {
                        if (!m_target_obj_set.Contains(obj))
                        {
                            enter_objs.Add(obj);
                        }
                    }
                }
                if (DrawableObjectMouseLeave != null && exit_objs.Count > 0)
                {
                    DrawableObjectMouseLeave(this, new DrawableObjectEventArgs(args, exit_objs.ToArray()));
                }
                if (DrawableObjectMouseEnter != null && enter_objs.Count > 0)
                {
                    DrawableObjectMouseEnter(this, new DrawableObjectEventArgs(args, enter_objs.ToArray()));
                }
                if (DrawableObjectToolTipRequest != null && (enter_objs.Count > 0 || exit_objs.Count > 0))
                {
                    if (new_target_objs.Length > 0)
                    {
                        m_drawable_object_tip.SetToolTip(picBoxCanvas, null);
                        DrawableObjectEventArgs event_args = new DrawableObjectEventArgs(args, new_target_objs);
                        DrawableObjectToolTipRequest(this, event_args);
                        m_drawable_object_tip.SetToolTip(picBoxCanvas, event_args.ToolTipText);
                        SendMessage(picBoxCanvas.Handle, WM_ACTIVATE, 0, IntPtr.Zero); // *** I'm not sure why this is required but it is :)
                    }
                    else
                    {
                        m_drawable_object_tip.SetToolTip(picBoxCanvas, null);
                    }
                }
                m_target_obj_set = new_target_obj_set;
                m_target_objs    = new_target_objs;
            }
            if (m_target_objs.Length == 0)
            {
                if (CanvasMouseMove != null)
                {
                    CanvasMouseMove(this, args);
                }
            }
            else
            {
                if (DrawableObjectMouseMove != null)
                {
                    DrawableObjectMouseMove(this, new DrawableObjectEventArgs(args, m_target_objs));
                }
            }
        }
예제 #24
0
 public override IDrawableObject GetObjectAt(float x, float y, TransformParams t, ref float dist)
 {
     return(IsObjectAt(x, y, t, mX1, mY1, mX2, mY2, ref dist) ? this : null); // throws ArgumentNullException
 }
예제 #25
0
 public override void Draw(Graphics g, TransformParams t, BoundingArea.ReadOnly boundingArea)
 {
     Draw(mX1, mY1, mX2, mY2, g, mPen, t, boundingArea); // throws ArgumentNullException
 }
예제 #26
0
파일: Picture.cs 프로젝트: 0000duck/latino
        public static bool IsObjectAt(Image image, float x, float y, float ptX, float ptY, TransformParams t)
        {
            Utils.ThrowException(t == null ? new ArgumentNullException("t") : null);
            // TODO: other exceptions
            float     width  = t.Transform(image.Width);
            float     height = t.Transform(image.Height);
            Vector2DF pos    = t.Transform(new Vector2DF(x, y));

            return(VisualizationUtils.PointInsideRect(ptX, ptY, new RectangleF(pos.X, pos.Y, width, height)));
        }
예제 #27
0
        public static void Draw(float x1, float y1, float x2, float y2, Graphics g, Pen pen, TransformParams t)
        {
            Utils.ThrowException(g == null ? new ArgumentNullException("g") : null);
            Utils.ThrowException(pen == null ? new ArgumentNullException("pen") : null);
            Utils.ThrowException(t == null ? new ArgumentNullException("t") : null);
            Vector2DF pt1 = t.Transform(new Vector2DF(x1, y1));
            Vector2DF pt2 = t.Transform(new Vector2DF(x2, y2));

            g.DrawLine(pen, pt1, pt2);
        }
예제 #28
0
파일: Picture.cs 프로젝트: 0000duck/latino
        // TODO: Image

        public override void Draw(Graphics g, TransformParams t)
        {
            Draw(mImage, mX, mY, g, t); // throws ArgumentNullException
        }
예제 #29
0
파일: Picture.cs 프로젝트: 0000duck/latino
 public override IDrawableObject GetObjectAt(float x, float y, TransformParams t, ref float dist)
 {
     dist = 0;
     return(IsObjectAt(mImage, mX, mY, x, y, t) ? this : null); // throws ArgumentNullException
 }
예제 #30
0
파일: Picture.cs 프로젝트: 0000duck/latino
 public override void Draw(Graphics g, TransformParams t, BoundingArea.ReadOnly boundingArea)
 {
     Draw(mImage, mX, mY, g, t, boundingArea); // throws ArgumentNullException
 }