// *********************** 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(); }
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()); }
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); } } }
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[] { }); } }
public bool IntersectsWith(BoundingArea.ReadOnly other) { Utils.ThrowException(other == null ? new ArgumentNullException("other") : null); if (mBoundingBox.IntersectsWith(other.BoundingBox)) { foreach (RectangleF rect in mRects) { foreach (RectangleF otherRect in other.Rectangles) { if (rect.IntersectsWith(otherRect)) { return(true); } } } } return(false); }
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 }
public override void Draw(Graphics g, TransformParams t, BoundingArea.ReadOnly boundingArea) { Draw(mImage, mX, mY, g, t, boundingArea); // throws ArgumentNullException }
public override void Draw(Graphics g, TransformParams t, BoundingArea.ReadOnly boundingArea) { Draw(mX1, mY1, mX2, mY2, g, mPen, t, boundingArea); // throws ArgumentNullException }
public static void Draw(float x1, float y1, float x2, float y2, Graphics g, Pen pen, TransformParams t, BoundingArea.ReadOnly boundingArea) { #if !NO_PARTIAL_RENDERING Utils.ThrowException(g == null ? new ArgumentNullException("g") : null); Utils.ThrowException(pen == null ? new ArgumentNullException("pen") : null); Utils.ThrowException(t == null ? new ArgumentNullException("t") : null); Utils.ThrowException(boundingArea == null ? new ArgumentNullException("boundingArea") : null); Vector2DF pt1 = t.Transform(new Vector2DF(x1, y1)); Vector2DF pt2 = t.Transform(new Vector2DF(x2, y2)); Vector2DF isectPt1 = new Vector2DF(); Vector2DF isectPt2 = new Vector2DF(); BoundingArea inflatedArea = boundingArea.GetWritableCopy(); inflatedArea.Inflate(pen.Width / 2f + 5f, pen.Width / 2f + 5f); ArrayList <KeyDat <float, PointInfo> > points = new ArrayList <KeyDat <float, PointInfo> >(); foreach (RectangleF rect in inflatedArea.Rectangles) { if (LineIntersectRectangle(pt1, pt2, rect, ref isectPt1, ref isectPt2)) { float distPt1 = (pt1 - isectPt1).GetLength(); float distPt2 = (pt1 - isectPt2).GetLength(); bool startPt1 = distPt1 < distPt2; points.Add(new KeyDat <float, PointInfo>(distPt1, new PointInfo(isectPt1, startPt1))); points.Add(new KeyDat <float, PointInfo>(distPt2, new PointInfo(isectPt2, !startPt1))); } } points.Sort(); int refCount = 0; int startIdx = 0; for (int i = 0; i < points.Count; i++) { PointInfo pointInfo = points[i].Dat; if (pointInfo.IsStartPoint) { refCount++; } else { refCount--; if (refCount == 0) { g.DrawLine(pen, points[startIdx].Dat.Point, pointInfo.Point); startIdx = i + 1; } } } #else Draw(x1, y1, x2, y2, g, pen, t); #endif }
public bool IntersectsWith(BoundingArea.ReadOnly other) { return(mBoundingArea.IntersectsWith(other)); }
public override void Draw(Graphics gfx, TransformParams tr, BoundingArea.ReadOnly bounding_area) { Draw(m_x1, m_y1, m_x2, m_y2, gfx, m_pen, tr, bounding_area); // throws ArgumentNullException, ArgumentValueException }
public virtual void Draw(Graphics gfx, TransformParams tr, BoundingArea.ReadOnly boundingArea) { Draw(gfx, tr); }