public override void RenderObject() { int realLength; if (!SizeInPercent) { realLength = (int)Length; } else { realLength = (int)(((float)Length / 100.0F) * (float)(IsVertical ? Paper.Height : Paper.Width)); } Size lineDimentions = Zoom.Calculate(new Size(realLength, Thickness)); // Initialize the bitmap Bitmap b = new Bitmap(lineDimentions.Width, lineDimentions.Height); // Initialize the graphics and render settings Graphics g = Graphics.FromImage(b); g.ApplyGraphicsQuality(); Pen drawingPen = new Pen(LineColor, lineDimentions.Height); drawingPen.DashPattern = DashPattern.GetFloatList(' '); g.DrawLine(drawingPen, new Point(0, lineDimentions.Height / 2), new Point(lineDimentions.Width, lineDimentions.Height / 2)); if (IsVertical) { b.RotateFlip(RotateFlipType.Rotate90FlipNone); } // Set the image Holder.Image = b; Holder.Size = Holder.Image.Size; base.RenderObject(); }
public virtual void RenderObject() { Point p = Zoom.Calculate(RealLocation); if (IsCenter()) { p.X -= (int)((float)Holder.Width * 0.5); } if (IsRight()) { p.X -= (int)((float)Holder.Width); } if (IsMiddle()) { p.Y -= (int)((float)Holder.Height * 0.5); } if (IsDown()) { p.Y -= (int)((float)Holder.Height); } // Clamp Position to inside the document p.X = Funcs.Clamp(p.X, 0, Zoom.paperSize.Width - Holder.Width); p.Y = Funcs.Clamp(p.Y, 0, Zoom.paperSize.Height - Holder.Height); // Finally set theposition clamped and with zoom applied Holder.Location = p; RecalculateRealPosition(); // Set the BackColor Holder.BackColor = BackColor; #if DEBUG Console.WriteLine("Rendering : " + Name); #endif }
/* * public override void RenderObject() * { * Thread thread = new Thread(new ThreadStart(ExRenderObject)); * thread.Start(); * * } */ public override void RenderObject() { Size realObjectSize; double xOffset, yOffset; if (!SizeInPercent) { realObjectSize = new Size((int)Width, (int)Height); } else { realObjectSize = new Size((int)((float)Paper.Width * Width / 100.0f), (int)((float)Paper.Height * Height / 100.0f)); } // Limit Size to a minimum of 1 realObjectSize = realObjectSize.Max(1); Bitmap c = new Bitmap(realObjectSize.Width, realObjectSize.Height); Bitmap i = new Bitmap(Resources.Get(ResourceID)); Graphics g = Graphics.FromImage(c); if (IsVertical) { i.RotateFlip(RotateFlipType.Rotate90FlipNone); } if (IsTurned180) { i.RotateFlip(RotateFlipType.Rotate180FlipNone); } switch (drawingType) { case DrawingTypes.Tiles: using (TextureBrush brush = new TextureBrush(i, WrapMode.Tile)) { g.FillRectangle(brush, 0, 0, realObjectSize.Width, realObjectSize.Height); } break; case DrawingTypes.Stretch: g.DrawImage(i, 0, 0, realObjectSize.Width, realObjectSize.Height); break; case DrawingTypes.Center: xOffset = (double)(c.Width - i.Width) / 2.0d; yOffset = (double)(c.Height - i.Height) / 2.0d; g.DrawImage(i, (int)xOffset, (int)yOffset, i.Width, i.Height); break; case DrawingTypes.Zoom: Size newSize; double cRatio = (double)c.Width / c.Height; double iRatio = (double)i.Width / i.Height; if (cRatio > iRatio) { newSize = new Size((int)(i.Width * ((double)c.Height / i.Height)), c.Height); } else { newSize = new Size(c.Width, (int)(i.Height * ((double)c.Width / i.Width))); } xOffset = (double)(c.Width - newSize.Width) / 2.0d; yOffset = (double)(c.Height - newSize.Height) / 2.0d; g.DrawImage(i, (int)xOffset, (int)yOffset, newSize.Width, newSize.Height); break; default: break; } // To prevent bitmap-ception, anchors will be off when zooming in/out for ImageObjects // After thinking I left the anchors to be shown even if zoomed but they become blurry (whatever) :/ // Draw the anchor point for this label // Point anchor = new Point(0, 0); if (Config.ShowAnchorPoints /*&& Zoom.currentAppliedZoom == 100*/) { // Reset rotation for anchors (only if show [Optimisation :3]) g.ResetTransform(); if (IsCenter()) { anchor.X = (int)(c.Width * 0.5F); } if (IsRight()) { anchor.X = (int)c.Width - 1; } if (IsMiddle()) { anchor.Y = (int)(c.Height * 0.5F); } if (IsDown()) { anchor.Y = (int)c.Height - 1; } g.DrawLine(Config.AnchorPen, anchor.X - Config.ANCHOR_SIZE, anchor.Y, anchor.X + Config.ANCHOR_SIZE, anchor.Y); g.DrawLine(Config.AnchorPen, anchor.X, anchor.Y - Config.ANCHOR_SIZE, anchor.X, anchor.Y + Config.ANCHOR_SIZE); } // Release previous rendered bitmap (A lil bit of memore'h :3) if (Holder.Image != null) { Holder.Image.Dispose(); } // Dispose of the copy i.Dispose(); Holder.Image = c; Holder.Size = Zoom.Calculate(realObjectSize); base.RenderObject(); }