public ScaleTransform ( float sx, float sy ) : void | ||
sx | float | |
sy | float | |
Результат | void |
public override void Draw(System.Drawing.Graphics g) { if (IsVisible) { g.TranslateTransform(Location.X + 50, Location.Y + 50); g.DrawArc(new System.Drawing.Pen(new SolidBrush(Color.FromArgb(Convert.ToInt32(255 * Animation), Color.Blue)), 8), new RectangleF(-50, -50, 100, 100), -90, Animation * 360); nearestItem = GetNearestItem(); for (int i = 0; i < actions.Count; i++) { g.RotateTransform(-360 * i / actions.Count); g.TranslateTransform(100, 0); g.RotateTransform(360 * i / actions.Count); if (i != nearestItem) { g.ScaleTransform(0.75f, 0.75f); } Actions[i].Draw(g, Animation); if (i != nearestItem) { g.ScaleTransform(1f / 0.75f, 1f / 0.75f); } g.RotateTransform(-360 * i / actions.Count); g.TranslateTransform(-100, 0); g.RotateTransform(360 * i / actions.Count); } float angle = Game.GetPointAngle(new Point(Convert.ToInt32(Location.X) + 50, Convert.ToInt32(Location.Y) + 50), Program.game.MousePosition); float length = Game.GetPointLength(new Point(Convert.ToInt32(Location.X) + 50, Convert.ToInt32(Location.Y) + 50), Program.game.MousePosition); PointF translateLength = Game.LengthDir(64, -angle); if (length > 50) { g.TranslateTransform(translateLength.X, translateLength.Y); g.RotateTransform(-angle); g.TranslateTransform(-16, -16); g.DrawImageUnscaledAndClipped(Properties.Resources.Arrow, new Rectangle(0, 0, Properties.Resources.Arrow.Width, Properties.Resources.Arrow.Height)); g.TranslateTransform(16, 16); g.RotateTransform(angle); g.TranslateTransform(-translateLength.X, -translateLength.Y); } //g.DrawImageUnscaledAndClipped() //g.DrawString(nearestItem.ToString(), new Font("Segoe UI", 14), Brushes.Blue, new PointF(0, 0)); g.TranslateTransform(-Location.X, -Location.Y); g.ResetTransform(); } }
/// <summary> /// Draw- simple draw of an entire page. Useful when printing or creating an image. /// </summary> /// <param name="g"></param> /// <param name="page"></param> /// <param name="clipRectangle"></param> public void Draw(Graphics g, int page, System.Drawing.Rectangle clipRectangle, bool drawBackground, PointF pageOffset) { DpiX = g.DpiX; // this can change (e.g. printing graphics context) DpiY = g.DpiY; // g.InterpolationMode = InterpolationMode.HighQualityBilinear; // try to unfuzz charts g.PageUnit = GraphicsUnit.Pixel; g.ScaleTransform(1, 1); if (!pageOffset.IsEmpty) // used when correcting for non-printable area on paper { g.TranslateTransform(pageOffset.X, pageOffset.Y); } _left = 0; _top = 0; _hScroll = 0; _vScroll = 0; RectangleF r = new RectangleF(clipRectangle.X, clipRectangle.Y, clipRectangle.Width, clipRectangle.Height); if (drawBackground) g.FillRectangle(Brushes.White, PixelsX(_left), PixelsY(_top), PixelsX(_pgs.PageWidth), PixelsY(_pgs.PageHeight)); ProcessPage(g, _pgs[page], r, false); }
private static void InitGraphics(Graphics g) { g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor; g.ScaleTransform(ValorEngine.Scale, ValorEngine.Scale); g.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.Half; g.PageUnit = GraphicsUnit.Pixel; }
public System.Drawing.Image ConvertPdfToImage() { try { Spire.Pdf.PdfDocument pdfDocument = new Spire.Pdf.PdfDocument(); pdfDocument.LoadFromFile(this.FilePath); System.Drawing.Image image1 = pdfDocument.SaveAsImage(0, PdfImageType.Metafile); Size size = image1.Size; int width = size.Width * 5; size = image1.Size; int height = size.Height * 5; System.Drawing.Image image2 = (System.Drawing.Image) new Bitmap(width, height); using (System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(image2)) { graphics.ScaleTransform(5f, 5f); graphics.DrawImage(image1, new System.Drawing.Rectangle(new Point(0, 0), image1.Size), new System.Drawing.Rectangle(new Point(0, 0), image1.Size), GraphicsUnit.Pixel); } MembercardService.logger.Debug("PDF conversion to image succeeded."); return(image2); } catch (Exception ex) { MembercardService.logger.Error("PDF conversion to image failed:" + ex.Message); return((System.Drawing.Image)null); } }
private void ApplyTransform(Graphics g) { scale = Math.Min(ClientRectangle.Width / clientSize, ClientRectangle.Height / clientSize); if (scale == 0f) return; g.ScaleTransform(scale, scale); g.TranslateTransform(offset, offset); }
public override void Paint(Graphics g) { g.ScaleTransform(this.zoomFactor, this.zoomFactor); var brushSwitcher = new BrushSwitcher(); foreach (var cluster in this.dataSource.CurrentValue.Clusters) { this.DrawClusterPoints(cluster, g, brushSwitcher.GetNext()); this.DrawCenter(cluster, g); } }
//рисует клетку поля field[i,j] private void cell(int i, int j) { int x = i * (cw + 2), y = j * (ch + 2); if (field[i, j] == 0) { //для этой клетки найдена пара, её нужно убрать с поля GraphicsContainer gr = g.BeginContainer(); float xs = (float)xscale / cw; float ys = (float)yscale / ch; g.ScaleTransform(xs, ys); g.FillRectangle(SystemBrushes.Control, x + Convert.ToInt32(r / xs * i), y + Convert.ToInt32(r / ys * j) + Convert.ToInt32(menuStrip1.Height / ys), cw + 2 + r, ch + 2 + r); g.EndContainer(gr); } else if ((field[i, j] == 1)) { //клетка открыта -вывести картинку GraphicsContainer gr = g.BeginContainer(); float xs = (float)xscale / cw; float ys = (float)yscale / ch; g.ScaleTransform(xs, ys); g.DrawImage(pics, new Rectangle(x + Convert.ToInt32(2 / ys + r / xs * i), y + Convert.ToInt32(2 / ys + r / ys * j) + Convert.ToInt32(menuStrip1.Height / ys), cw, ch), new Rectangle(picture[i, j] * cw, 0, cw, ch), GraphicsUnit.Pixel); g.DrawRectangle(Pens.Black, x + Convert.ToInt32(2 / ys + r / xs * i), y + Convert.ToInt32(2 / ys + r / ys * j) + menuStrip1.Height / ys, cw, ch); g.EndContainer(gr); } else if ((field[i, j] == 2)) { //клетка закрыта GraphicsContainer gr = g.BeginContainer(); float xs = (float)xscale / cw; float ys = (float)yscale / ch; g.ScaleTransform(xs, ys); Brush b = new SolidBrush(back); g.DrawRectangle(Pens.Black, x + Convert.ToInt32(2 / ys + r / xs * i), y + Convert.ToInt32(2 / ys + r / ys * j) + Convert.ToInt32(menuStrip1.Height / ys), cw, ch); g.FillRectangle(b, x + Convert.ToInt32(2 / ys + r / xs * i), y + Convert.ToInt32(2 / ys + 2 + r / ys * j) + Convert.ToInt32(menuStrip1.Height / ys), cw, ch); g.EndContainer(gr); } else { MessageBox.Show(field[i, j] + "? Што?"); } }
public virtual void DrawToGraphics (Graphics graphics, float x, float y, float scaleX, float scaleY) { if (graphics == null) return; GraphicsState state = graphics.Save(); graphics.TranslateTransform (x, y); graphics.ScaleTransform(scaleX, scaleY); Draw(graphics); //graphics.DrawRectangle(Pens.Magenta, 0, 0, ShapeWidth, ShapeHeight); graphics.Restore(state); }
private void DrawGeneral(Graphics g, LiveSplitState state, float width, float height) { var oldMatrix = g.Transform; if (Settings.FlipGraph) { g.ScaleTransform(1, -1); g.TranslateTransform(0, -height); } DrawGraph(g, state, width, height); g.Transform = oldMatrix; }
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e) { base.OnPaint(e); System.Drawing.Graphics g = e.Graphics; g.ScaleTransform(4, 4); g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor; g.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.Half; onMyPaint(g); }
public override void Draw(Graphics graphics) { if (graphics == null) return; CollapseShape.DrawButton(graphics); graphics.TranslateTransform(1, 23); graphics.ScaleTransform(1, -1); CollapseShape.DrawArrow(graphics); graphics.TranslateTransform(0, 6); CollapseShape.DrawArrow(graphics); }
public void ScaleTransform(float xscale, float yscale) { if (isD3D) { d3d.ScaleTransform(xscale, yscale); } else { gdi.ScaleTransform(xscale, yscale); } }
private void DrawElement(Graphics g, Act2DMapLayoutObject.Element e) { var bitmap = file.CreateBitmapForResource(e.resourceID); if (bitmap == null) return; g.TranslateTransform(e.x, e.y); g.TranslateTransform(bitmap.Width * 0.5f, bitmap.Height * 0.5f); g.RotateTransform(e.rotate); g.ScaleTransform(e.scale_x, e.scale_y); g.TranslateTransform(-bitmap.Width * 0.5f, -bitmap.Height * 0.5f); g.DrawImage(bitmap, new PointF(0.0f, 0.0f)); }
public void Draw(Graphics g) { g.ResetTransform(); g.ScaleTransform(1 + (float)Math.Cos(angle/200f)/1f, 1+ (float)Math.Cos(angle/200f)/1f); g.TranslateTransform(g.VisibleClipBounds.Width / 2f, g.VisibleClipBounds.Height / 2f); angle += 10; g.RotateTransform(angle); g.DrawPolygon(new Pen(new SolidBrush(Color.Black), 3), vertices); }
private void TestDraw(Graphics g, bool flip, bool rotate) { Matrix matrix = g.Transform; if (flip) g.ScaleTransform(1, -1); if (rotate) g.RotateTransform(90); g.DrawRectangle(Pens.Red, 16, 32, 100, 40); g.DrawString("Testing 1234567890", Font, Brushes.Red, 24, 48); g.Transform = matrix; }
public override void Draw(Graphics graphics) { if (graphics == null) return; GraphicsState state = graphics.Save(); graphics.TranslateTransform(17.0f, 0.0f); graphics.ScaleTransform(-1.0f, 1.0f); MethodShape.DrawBrick(graphics, brickBrush1, brickBrush2, brickBrush3); graphics.Restore(state); graphics.FillRectangle(Brushes.Gray, 1.0f, 4.5f, 3.5f, 0.5f); graphics.FillRectangle(Brushes.Gray, 0.0f, 6.5f, 3.5f, 0.5f); graphics.FillRectangle(Brushes.Gray, 2.0f, 8.5f, 3.5f, 0.5f); }
public FormMain() { InitializeComponent(); pictureBoxView.Image = new Bitmap(pictureBoxView.Width, pictureBoxView.Height); m_g = Graphics.FromImage(pictureBoxView.Image); m_g.TranslateTransform(0, pictureBoxView.Height); m_g.ScaleTransform(1, -1); pictureBoxView.Image.RotateFlip(RotateFlipType.Rotate180FlipX); pointGenerator = new UniformPointGenerator(); radioUniform.Checked = true; //start with this as the default m_pointList = new List<PointF>(); UniquePoints = new Dictionary<float, PointF>(); }
private void DoTheWork() { Size wSize = Size; if (wSize.Width < 1 || wSize.Height < 1) { return; } System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(wSize.Width, wSize.Height); using (System.Drawing.Graphics g = Graphics.FromImage(bmp)) { g.SmoothingMode = SmoothingMode.AntiAlias; g.InterpolationMode = InterpolationMode.HighQualityBicubic; g.PixelOffsetMode = PixelOffsetMode.HighQuality; g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit; g.ScaleTransform(1.0F, -1.0F); g.TranslateTransform(0.0F, -(float)wSize.Height); float scaleX = (float)(wSize.Width - 25 - 5) / (float)wSize.Width; float scaleY = (float)(wSize.Height - 15 - 5) / (float)wSize.Height; g.ScaleTransform(scaleX, scaleY); g.TranslateTransform(25, 15); g.DrawLines(GetPen(ColorScheme.PreviewText), new PointF[] { new PointF(0, wSize.Height), new PointF(0, 0), new PointF(wSize.Width, 0) }); if (Core != null && Core.HasProgram) { Core.LoadedFile.DrawOnGraphics(g, wSize); } mLastMatrix = g.Transform; } AssignBMP(bmp); }
public void RunPages(Pages pgs) // this does all the work { int pageNo = 1; // STEP: processing a page. foreach (Page p in pgs) { System.Drawing.Bitmap bm = CreateObjectBitmap(); System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bm); g.PageUnit = GraphicsUnit.Pixel; g.ScaleTransform(1, 1); DpiX = g.DpiX; DpiY = g.DpiY; // STEP: Fill backgroup g.FillRectangle(Brushes.White, 0F, 0F, (float)bm.Width, (float)bm.Height); // STEP: draw page to bitmap ProcessPage(g, p); // STEP: System.Drawing.Bitmap bm2 = ConvertToBitonal(bm); if (pageNo == 1) { _tif = bm2; } SaveBitmap(_tif, bm2, tw, pageNo); pageNo++; } if (_tif != null) { // STEP: prepare encoder parameters EncoderParameters encoderParams = new EncoderParameters(1); encoderParams.Param[0] = new EncoderParameter( System.Drawing.Imaging.Encoder.SaveFlag, (long)EncoderValue.Flush ); // STEP: _tif.SaveAdd(encoderParams); } return; }
public override void OnRender(Graphics g) { //g.DrawRectangle(Pen, new System.Drawing.Rectangle(LocalPosition.X, LocalPosition.Y, Size.Width, Size.Height)); { g.TranslateTransform(ToolTipPosition.X, ToolTipPosition.Y); var c = g.BeginContainer(); { g.RotateTransform(Bearing - Overlay.Control.Bearing); g.ScaleTransform(Scale, Scale); g.FillPolygon(Fill, Arrow); } g.EndContainer(c); g.TranslateTransform(-ToolTipPosition.X, -ToolTipPosition.Y); } }
public override void Draw(Graphics graphics) { if (graphics == null) return; GraphicsState state = graphics.Save(); CollapseExpandShape.DrawButton(graphics); if (collapsed) { graphics.TranslateTransform(0, 21); graphics.ScaleTransform(1, -1); } CollapseExpandShape.DrawArrow(graphics); graphics.TranslateTransform(0, 6); CollapseExpandShape.DrawArrow(graphics); graphics.Restore(state); }
private void PaintHand(Graphics g, HandData hand) { g.TranslateTransform(hand.Location.X * this.zoomFactor, hand.Location.Y * this.zoomFactor); g.ScaleTransform(this.zoomHandFactor, this.zoomHandFactor); g.TranslateTransform(-hand.Location.X * this.zoomFactor, -hand.Location.Y * this.zoomFactor); g.ScaleTransform(this.zoomFactor, this.zoomFactor); if (this.ShowConvexHull) { this.PaintCovexHull(hand, g); } if (this.ShowContour && hand.Contour != null) { this.PaintContour(hand, g); } DrawFingerPoints(hand, g); this.DrawCenter(hand, g); g.ResetTransform(); }
public override void Draw(Graphics gr, Point position, Range range) { foreach (Place p in range) { int time = (int)(DateTime.Now.TimeOfDay.TotalMilliseconds/2); int angle = (int)(time % 360L); int angle2 = (int)((time - (p.iChar - range.Start.iChar)*20) % 360L)*2; int x = position.X + (p.iChar - range.Start.iChar) * range.tb.CharWidth; Range r = range.tb.GetRange(p, new Place(p.iChar+1, p.iLine)); Point point = new Point(x, position.Y + (int)(5 + 5 * Math.Sin(Math.PI * angle2 / 180))); gr.ResetTransform(); gr.TranslateTransform(point.X + range.tb.CharWidth / 2, point.Y +range.tb.CharHeight / 2); gr.RotateTransform(angle); gr.ScaleTransform(0.8f, 0.8f); gr.TranslateTransform(- range.tb.CharWidth / 2, -range.tb.CharHeight / 2); base.Draw(gr, new Point(0, 0), r); } gr.ResetTransform(); }
protected System.Drawing.Bitmap CreateContentBitmap(float rate, System.Drawing.Color BmpBackColor) { SimpleRectangleTransform trans = this.myTransform as SimpleRectangleTransform; if (trans == null) { return(null); } System.Drawing.Size size = this.AutoScrollMinSize; size.Width = (int)(size.Width * rate); size.Height = (int)(size.Height * rate); if (size.Width <= 0 || size.Height <= 0) { return(null); } System.Drawing.Bitmap bmp = new Bitmap(size.Width, size.Height); float rate2 = rate; float rateback = this.fXZoomRate; try { using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmp)) { g.Clear(BmpBackColor); g.PageUnit = this.intGraphicsUnit; g.ScaleTransform(rate2, rate2); g.TranslateTransform(-trans.DescRectF.X, -trans.DescRectF.Y); System.Windows.Forms.PaintEventArgs e = new PaintEventArgs(g, trans.DescRect); this.fXZoomRate = rate; this.OnViewPaint(e, trans); this.fXZoomRate = rateback; } return(bmp); } catch (Exception ext) { this.fXZoomRate = rateback; throw ext; } }
protected override void PaintPanel(Graphics g) { if (g == null) throw new ArgumentNullException("g"); var scroll = Hexgrid.ScrollPosition; if (DesignMode) { g.FillRectangle(Brushes.Gray, ClientRectangle); return; } g.Clear(Color.Black); if (IsTransposed) { g.Transform = TransposeMatrix; } g.TranslateTransform(scroll.X, scroll.Y); g.ScaleTransform(MapScale, MapScale); var state = g.Save(); g.DrawImageUnscaled(MapBuffer, Point.Empty); g.Restore(state); state = g.Save(); Host.PaintUnits(g); g.Restore(state); state = g.Save(); Host.PaintHighlight(g); }
static void TestImage() { Hearthstone_Deck_Tracker.Hearthstone.Card card = new Hearthstone_Deck_Tracker.Hearthstone.Card(HearthDb.Cards.Collectible[HearthDb.CardIds.Collectible.Druid.AncientOfWar]); System.Windows.Media.Imaging.BitmapImage image = Hearthstone_Deck_Tracker.Utility.ImageCache.GetCardImage(card); System.Drawing.Bitmap bitmap = Hearthstone_Deck_Tracker.Utility.ImageCache.GetCardBitmap(card); System.Windows.Forms.Form pForm = new System.Windows.Forms.Form(); pForm.Show(); pForm.Size = new System.Drawing.Size(200, 200); System.Drawing.Graphics pGraphics = pForm.CreateGraphics(); pGraphics.ScaleTransform(1.0f, 0.5f); Font pFont = new Font("Arial", 16); SolidBrush pBrush = new SolidBrush(Color.Black); PointF pPoint = new PointF(0.0f, 0.0f); pGraphics.DrawImage(bitmap, 0, 0); pGraphics.DrawString(card.Name, pFont, pBrush, pPoint); System.Drawing.Size size = bitmap.Size; string opClass = Hearthstone_Deck_Tracker.API.Core.Game.Opponent.Class; pGraphics.Clear(System.Drawing.Color.Cyan); }
private void Graficar() { System.Drawing.Graphics Dibujo = this.picBox.CreateGraphics(); double[] valores = new double[20000]; double puntoX1 = 0, puntoY1 = 0, puntoX2 = 0, puntoY2 = 0; int con = 0; int xcentro = picBox.Width / 2; // centro de x int ycentro = picBox.Height / 2; // centro de y //var a = new Funcion(); string func = txtFunc.Text; Function e = new Function("f(x) = " + func); Dibujo.TranslateTransform(xcentro, ycentro); Dibujo.ScaleTransform(1, -1); for (int i = -xcentro; i < xcentro; i += 8) { Dibujo.DrawLine(mylapiz1, 5, i, -5, i); // eje y Dibujo.DrawLine(mylapiz1, i, 5, i, -5); // eje x } con = 0; for (double x = xcentro * -1; x < xcentro * 2; x += 0.1) { valores[con] = e.calculate(x); con = con + 1; } con = 1; for (double xx = xcentro * -1 + 0.1; xx < xcentro * 2; xx += 0.1) { puntoX1 = (xx - 0.1) * (picBox.Width / Convert.ToInt16(textBox2.Text) * 2); puntoY1 = valores[con - 1] * ycentro; puntoX2 = xx * (picBox.Width / Convert.ToInt16(textBox2.Text) * 2); puntoY2 = valores[con] * ycentro; Dibujo.DrawLine(mylapiz2, Convert.ToSingle(puntoX1), Convert.ToSingle(puntoY1), Convert.ToSingle(puntoX2), Convert.ToSingle(puntoY2)); con = con + 1; } }
/// <summary> /// Text to Image /// </summary> /// <param name="text">Set text</param> /// <param name="font">Set font</param> /// <param name="factor">Set factor</param> /// <returns></returns> public static System.Drawing.Bitmap TextToImage(this string text, Font font, float factor) { System.Drawing.Bitmap textBitmap = new System.Drawing.Bitmap(1, 1); System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(textBitmap); int width = (int)Math.Ceiling( graphics.MeasureString(text, font).Width * factor); int height = (int)Math.Ceiling( graphics.MeasureString(text, font).Height * factor); graphics.Dispose(); textBitmap = new System.Drawing.Bitmap(width, height, PixelFormat.Format32bppArgb); graphics = System.Drawing.Graphics.FromImage(textBitmap); graphics.Clear(Color.Black); graphics.CompositingQuality = CompositingQuality.HighQuality; graphics.InterpolationMode = InterpolationMode.HighQualityBicubic; graphics.PixelOffsetMode = PixelOffsetMode.HighQuality; graphics.SmoothingMode = SmoothingMode.HighQuality; graphics.TextRenderingHint = TextRenderingHint.AntiAliasGridFit; graphics.ScaleTransform(factor, factor); graphics.DrawString(text, font, Brushes.White, new PointF(0, 0)); graphics.Flush(); graphics.Dispose(); return(textBitmap); }
private static void DrawInk(GraphicsPath p, InkPressureFeedbackMode m, Size s, Graphics g) { RectangleF PathBounds = p.GetBounds(); //get the bounds of the path and compute the square scale transform float ds = 0.8f * Math.Min(s.Width / PathBounds.Width, s.Height / PathBounds.Height); GraphicsState OriginalGraphicsState = g.Save(); g.TranslateTransform(s.Width >> 1, s.Height >> 1); g.ScaleTransform(ds, -ds); switch (m) { case InkPressureFeedbackMode.Size: g.FillEllipse(Brushes.Black, new Rectangle(-800, -800, 1600, 1600)); break; case InkPressureFeedbackMode.Width: g.DrawLine(new Pen(Color.Black, 500f), new Point(-500, 0), new Point(500, 0)); break; case InkPressureFeedbackMode.None: case InkPressureFeedbackMode.Color: default: GraphicsPath InkRegion = new GraphicsPath(); //upper-left triangular clip region to fake "ink" InkRegion.AddPolygon(new Point[] { Point.Empty, new Point(s.Width, 0), new Point(0, s.Height) }); Matrix InverseTransform = g.Transform; InverseTransform.Invert(); InkRegion.Transform(InverseTransform); g.IntersectClip(new Region(InkRegion)); g.DrawPath(new Pen(Color.Blue, 4 / ds), p); break; } g.Restore(OriginalGraphicsState); }
/// <summary> /// Scale the Graphics so that this node's full bounds fit in displayRect and then /// render into the given Graphics context. /// </summary> /// <param name="g">The Graphics context to use when rendering the node.</param> /// <param name="displayRect">The imageable area.</param> protected virtual void ScaleAndDraw(Graphics g, RectangleF displayRect) { RectangleF bounds = FullBounds; g.TranslateTransform(displayRect.X, displayRect.Y); // scale the graphics so node's full bounds fit in the imageable bounds. float scale = displayRect.Width / bounds.Width; if (displayRect.Height / bounds.Height < scale) { scale = displayRect.Height / bounds.Height; } g.ScaleTransform(scale, scale); g.TranslateTransform(-bounds.X, -bounds.Y); PPaintContext pc = new PPaintContext(g, null); pc.RenderQuality = RenderQuality.HighQuality; FullPaint(pc); }
public override void Draw(Graphics gr, Point position, Range range) { //draw background if (BackgroundBrush != null) gr.FillRectangle(BackgroundBrush, position.X, position.Y, (range.End.iChar - range.Start.iChar) * range.tb.CharWidth, range.tb.CharHeight); //draw chars using (var f = new Font(range.tb.Font, FontStyle)) { Line line = range.tb[range.Start.iLine]; float dx = range.tb.CharWidth; float y = position.Y + range.tb.LineInterval / 2; float x = position.X - range.tb.CharWidth / 3; if (ForeBrush == null) ForeBrush = new SolidBrush(range.tb.ForeColor); if (range.tb.ImeAllowed) { //IME mode for (int i = range.Start.iChar; i < range.End.iChar; i++) { SizeF size = FastColoredTextBox.GetCharSize(f, line[i].c); var gs = gr.Save(); float k = size.Width > range.tb.CharWidth + 1 ? range.tb.CharWidth / size.Width : 1; gr.TranslateTransform(x, y + (1 - k) * range.tb.CharHeight / 2); gr.ScaleTransform(k, (float)Math.Sqrt(k)); gr.DrawString(line[i].c.ToString(), f, ForeBrush, 0, 0, stringFormat); gr.Restore(gs); x += dx; } } else { //classic mode for (int i = range.Start.iChar; i < range.End.iChar; i++) { //draw char gr.DrawString(line[i].c.ToString(), f, ForeBrush, x, y, stringFormat); x += dx; } } } }
// Current methods signature is temporary. Most of the parameters will temporary become class members or properties. private void DrawClockFore(Graphics graphics, string timeStringAbsPart, ref string timeStringDecPart, bool inaccuraciesDetected, int num8, ref Brush brush) { // Transforms the Graphics object in order to draw the clock time full-sized graphics.InterpolationMode = InterpolationMode.HighQualityBicubic; graphics.SmoothingMode = SmoothingMode.HighQuality; graphics.TextRenderingHint = TextRenderingHint.AntiAlias; //graphics.TranslateTransform(num8 + (((wsplit.clockRect.Width - (clockScale * 124f)) - num8) / 2f), wsplit.clockRect.Top + ((wsplit.clockRect.Height - (clockScale * 26f)) / 2f)); graphics.TranslateTransform(num8 + ((wsplit.clockRect.Width - (this.clockScale * this.clockTimeTotalSize.Width) - num8) / 2f), wsplit.clockRect.Top + ((wsplit.clockRect.Height - (this.clockScale * this.clockTimeTotalSize.Height)) / 2f)); graphics.ScaleTransform(clockScale, clockScale); // If using DigitalClock font if (Settings.Profile.DigitalClock) { // The drawing of the digital clock font could have been done dynamically, but since the result wasn't // exactly centered vertically, I decided to hardcode values that give the best looking result. // Since this option is used by many, I had to make sure it looked nice. graphics.DrawString(timeStringAbsPart, wsplit.digitLarge, brush, 0f, 0.15f); if (inaccuraciesDetected) { timeStringDecPart = "".PadRight(timeStringDecPart.Length, '?'); brush = new SolidBrush(ColorSettings.Profile.Flash); } if (Settings.Profile.ShowDecimalSeparator) { graphics.DrawString(wsplit.decimalChar, wsplit.digitMed, brush, clockTimeAbsSize.Width - 7, 4.5f); graphics.DrawString(timeStringDecPart, wsplit.digitMed, brush, clockTimeAbsSize.Width, 4.5f); /*graphics.DrawString(wsplit.decimalChar, wsplit.digitMed, brush, (112 - clockTimeDecSize.Width), 4.5f); graphics.DrawString(timeStringDecPart, wsplit.digitMed, brush, (119 - clockTimeDecSize.Width), 4.5f);*/ } else graphics.DrawString(timeStringDecPart, wsplit.digitMed, brush, (clockTimeAbsSize.Width), 4.5f); //graphics.DrawString(timeStringDecPart, wsplit.digitMed, brush, (117.5f - clockTimeDecSize.Width), 4.5f); } // If the font used for the clock is any font but the default digital clock font, the display is done dynamically, according to font measurements. else { // Calculates de relative baseline height of both fonts used in the display so that they can be aligned correctly float largeBaseline = wsplit.clockLarge.Size * wsplit.clockLarge.FontFamily.GetCellAscent(wsplit.clockLarge.Style) / wsplit.clockLarge.FontFamily.GetEmHeight(wsplit.clockLarge.Style); float mediumBaseline = wsplit.clockMed.Size * wsplit.clockMed.FontFamily.GetCellAscent(wsplit.clockMed.Style) / wsplit.clockMed.FontFamily.GetEmHeight(wsplit.clockMed.Style); RectangleF clockTimeAbsRectF = new RectangleF(0f, 0f, this.clockTimeAbsSize.Width, this.clockTimeAbsSize.Height); RectangleF clockTimeDecRectF; if (Settings.Profile.ShowDecimalSeparator) { clockTimeDecRectF = new RectangleF(clockTimeAbsRectF.Right - 7, clockTimeAbsRectF.Top + (largeBaseline - mediumBaseline), this.clockTimeDecSize.Width, this.clockTimeDecSize.Height); graphics.DrawString(wsplit.decimalChar, wsplit.clockMed, brush, clockTimeDecRectF); clockTimeDecRectF.X = clockTimeAbsRectF.Right; } else clockTimeDecRectF = new RectangleF(clockTimeAbsRectF.Right - 2, clockTimeAbsRectF.Top + (largeBaseline - mediumBaseline), this.clockTimeDecSize.Width, this.clockTimeDecSize.Height); StringFormat format = new StringFormat { Alignment = StringAlignment.Far }; graphics.DrawString(timeStringAbsPart, wsplit.clockLarge, brush, clockTimeAbsRectF, format); if (inaccuraciesDetected) { timeStringDecPart = "".PadRight(timeStringDecPart.Length, '?'); brush = new SolidBrush(ColorSettings.Profile.Flash); } format.Alignment = StringAlignment.Near; graphics.DrawString(timeStringDecPart, wsplit.clockMed, brush, clockTimeDecRectF, format); } graphics.ResetTransform(); }
private void DrawClockBack(float angle, int num8, Graphics bgGraphics) { if (!Settings.Profile.BackgroundBlack) { if (Settings.Profile.BackgroundPlain) bgGraphics.FillRectangle(new SolidBrush(this.clockPlainColor), wsplit.clockRect); else { bgGraphics.FillRectangle(new LinearGradientBrush(wsplit.clockRect, this.clockGrColor, this.clockGrColor2, angle), wsplit.clockRect); if ((angle == 0f) && Settings.Profile.ClockAccent) bgGraphics.FillRectangle(new SolidBrush(Color.FromArgb(0x56, this.clockGrColor2)), wsplit.clockRect.X, wsplit.clockRect.Y, wsplit.clockRect.Width, wsplit.clockRect.Height / 2); if (Settings.Profile.DigitalClock) { bgGraphics.InterpolationMode = InterpolationMode.HighQualityBicubic; bgGraphics.TextRenderingHint = TextRenderingHint.AntiAlias; bgGraphics.SmoothingMode = SmoothingMode.HighQuality; // Change according to what was done in that DrawClockFore method //bgGraphics.TranslateTransform(num8 + (((wsplit.clockRect.Width - (clockScale * 124f)) - num8) / 2f), wsplit.clockRect.Top + ((wsplit.clockRect.Height - (clockScale * 26f)) / 2f)); //bgGraphics.ScaleTransform(clockScale, clockScale); bgGraphics.TranslateTransform(num8 + ((wsplit.clockRect.Width - (this.clockScale * this.clockTimeTotalSize.Width) - num8) / 2f), wsplit.clockRect.Top + ((wsplit.clockRect.Height - (this.clockScale * this.clockTimeTotalSize.Height)) / 2f)); bgGraphics.ScaleTransform(clockScale, clockScale); Brush brush4 = new SolidBrush(Color.FromArgb(86, this.clockGrColor2)); bgGraphics.DrawString("88:88:88".PadLeft(timeStringAbsPart.Length, '8'), wsplit.digitLarge, brush4, 0f, 0.15f); if (Settings.Profile.ShowDecimalSeparator) { bgGraphics.DrawString(wsplit.decimalChar, wsplit.digitMed, brush4, (112 - clockTimeDecSize.Width), 4.5f); bgGraphics.DrawString("".PadRight(this.timeStringDecPart.Length, '8'), wsplit.digitMed, brush4, (119 - clockTimeDecSize.Width), 4.5f); } else bgGraphics.DrawString("".PadRight(this.timeStringDecPart.Length, '8'), wsplit.digitMed, brush4, (117.5f - clockTimeDecSize.Width), 4.5f); bgGraphics.ResetTransform(); } } } }
void PaintView1(Graphics g) { g.SmoothingMode = SmoothingMode.HighQuality; g.CompositingQuality = CompositingQuality.HighQuality; if (brush1==null) brush1=createCircularMetalBrush(); //Graphics g=e.Graphics; int cx=Width/2; int cy=Height/2; int r=cx; if (r>cy) r=cy; r-=20; // margin g.TranslateTransform(cx, cy); g.ScaleTransform(r, r); g.FillEllipse(brush1, new RectangleF(-1, -1, 2, 2)); var triangleCenter = ((PathGradientBrush)brush1).CenterPoint; g.FillEllipse(Brushes.Red, new RectangleF(triangleCenter.X + cx, triangleCenter.Y+cy, 2*r, 2*r)); title = "Metal Brush - not Working"; }
/// <summary> /// Draw: accounting for scrolling and zoom factors /// </summary> /// <param name="g"></param> /// <param name="zoom"></param> /// <param name="leftOffset"></param> /// <param name="pageGap"></param> /// <param name="hScroll"></param> /// <param name="vScroll"></param> /// <param name="clipRectangle"></param> public void Draw(Graphics g, float zoom, float leftOffset, float pageGap, float hScroll, float vScroll, System.Drawing.Rectangle clipRectangle, PageItem highLightItem, string highLight, bool highLightCaseSensitive, bool highLightAll) { // init for mouse handling _HitList.Clear(); // remove all items from list _LastZoom = zoom; _HighlightItem = highLightItem; _HighlightText = highLight; _HighlightCaseSensitive = highLightCaseSensitive; _HighlightAll = highLightAll; if (_pgs == null) { // No pages; means nothing to draw g.FillRectangle(Brushes.White, clipRectangle); return; } g.PageUnit = GraphicsUnit.Pixel; g.ScaleTransform(zoom, zoom); DpiX = g.DpiX; DpiY = g.DpiY; // Zoom affects how much will show on the screen. Adjust our perceived clipping rectangle // to account for it. RectangleF r; r = new RectangleF((clipRectangle.X) / zoom, (clipRectangle.Y) / zoom, (clipRectangle.Width) / zoom, (clipRectangle.Height) / zoom); // Calculate the top of the page int fpage = (int)(vScroll / (_pgs.PageHeight + pageGap)); int lpage = (int)((vScroll + r.Height) / (_pgs.PageHeight + pageGap)) + 1; if (fpage >= _pgs.PageCount) return; if (lpage >= _pgs.PageCount) lpage = _pgs.PageCount - 1; _hScroll = hScroll; _left = leftOffset; _top = pageGap; // Loop thru the visible pages for (int p = fpage; p <= lpage; p++) { _vScroll = vScroll - p * (_pgs.PageHeight + pageGap); System.Drawing.Rectangle pr = new System.Drawing.Rectangle((int)PixelsX(_left - _hScroll), (int)PixelsY(_top - _vScroll), (int)PixelsX(_pgs.PageWidth), (int)PixelsY(_pgs.PageHeight)); g.FillRectangle(Brushes.White, pr); ProcessPage(g, _pgs[p], r, true); // Draw the page outline using (Pen pn = new Pen(Brushes.Black, 1)) { int z3 = Math.Min((int)(3f / zoom), 3); if (z3 <= 0) z3 = 1; int z4 = Math.Min((int)(4f / zoom), 4); if (z4 <= 0) z4 = 1; g.DrawRectangle(pn, pr); // outline of page g.FillRectangle(Brushes.Black, pr.X + pr.Width, pr.Y + z3, z3, pr.Height); // right side of page g.FillRectangle(Brushes.Black, pr.X + z3, pr.Y + pr.Height, pr.Width, z4); // bottom of page } } }
private void dibujarVehiculo(Graphics grafico, Vehiculo vehiculo) { //El punto es el centro del vehiculo int xInicio = (int)vehiculo.X; int yInicio = (int)vehiculo.Y; int largo = vehiculo.Largo; int ancho = 12; //Coordenada del inicio del dibujo int x = xInicio-(ancho/2); int y = yInicio-largo; Random a = new Random (vehiculo.Id); Color colorVehiculo = Color.White; if (vehiculo.Tipo == Vehiculo.AUTOPERSONAL) { colorVehiculo = Color.FromArgb(a.Next(20, 105),a.Next(30, 160),125); } else if (vehiculo.Tipo == Vehiculo.CAMION) { colorVehiculo = Color.FromArgb(a.Next(0, 120),a.Next(0, 50),0); } else if (vehiculo.Tipo == Vehiculo.TRASPORTEPUBLICO) { colorVehiculo = Color.FromArgb(a.Next(230, 255),a.Next(50, 200),0); } if(Modificar.eliminarVehiculos && Modificar.estaSobre(vehiculo)) { colorVehiculo = Configuracion.COLORRESALTAR; } Color interDerecho = Color.Gray; Color interIzquierdo = Color.Gray; Color freno = Color.Gray; if (vehiculo.Intermitente == Vehiculo.INTERMITENTE_DERECHA) interDerecho = Color.Yellow; else if (vehiculo.Intermitente == Vehiculo.INTERMITENTE_IZQUIERDA) interIzquierdo = Color.Yellow; if (vehiculo.LuzFreno) freno = Color.Red; if (Configuracion.mostrarBezier) { Bezier b = vehiculo.Conductor.Bezier; if (b != null) grafico.DrawBezier (new Pen (colorVehiculo), b.X1, b.Y1, b.X2, b.Y2, b.X3, b.Y3, b.X4, b.Y4); } //Rota el vehiculo con el angulo de giro Matrix m = new Matrix (); m.Translate (Configuracion.origenX,Configuracion.origenY); m.Scale (Configuracion.tamañoMapa,Configuracion.tamañoMapa); m.RotateAt ((int)vehiculo.Angulo, new PointF (xInicio, yInicio)); grafico.Transform = m; grafico.FillRectangle (new SolidBrush (colorVehiculo), x, y, ancho, largo); grafico.FillRectangle (new SolidBrush (interIzquierdo), x, y+largo-2, 2, 2); grafico.FillRectangle (new SolidBrush (freno), x+4, y+largo-2, 4, 2); grafico.FillRectangle (new SolidBrush (interDerecho), x+10, y+largo-2, 2, 2); //grafico.FillRectangle (new SolidBrush (Color.Green), x+ancho/2, y+largo, 4, 4); //grafico.FillRectangle (new SolidBrush (Color.YellowGreen), x+ancho/2-4, y+largo, 4, 4); if (Configuracion.mostrarRadioPercepcion) { grafico.DrawEllipse (new Pen (colorVehiculo), xInicio - Configuracion.radioPercepcionVehiculo, yInicio-(largo/2) - Configuracion.radioPercepcionVehiculo, Configuracion.radioPercepcionVehiculo * 2, Configuracion.radioPercepcionVehiculo * 2); grafico.DrawEllipse (new Pen (colorVehiculo), xInicio - Configuracion.radioPercepcionSeñaletica, yInicio-(largo/2) - Configuracion.radioPercepcionSeñaletica, Configuracion.radioPercepcionSeñaletica * 2, Configuracion.radioPercepcionSeñaletica * 2); } this.dibujarID (grafico, vehiculo.Id, Elemento.VERTICAL, x+3, y); grafico.ResetTransform (); //Se reestablecen los ajustes del mapa grafico.TranslateTransform (Configuracion.origenX,Configuracion.origenY); grafico.ScaleTransform (Configuracion.tamañoMapa,Configuracion.tamañoMapa); }
//renders the vector map with depth filtering private void DrawLinesFiltered(Graphics g) { if (!m_showLines) return; float dx = (mapViewOffset.X + clientCenter.X) / -m_ratio + mapCenter.X; float dy = (mapViewOffset.Y + clientCenter.Y) / -m_ratio - mapCenter.Y; GraphicsState tState = g.Save(); g.ScaleTransform(m_ratio, -m_ratio); g.TranslateTransform(-dx, dy); float playerZ = m_game.Player.Location.Z; foreach (MapLine line in m_data.Lines) { if (line.Count > 1) { float curX, curY, curZ, lastX, lastY, lastZ; int alpha; lastX = line[0].X; lastY = line[0].Y; lastZ = line[0].Z; float lastZDist = Math.Max(playerZ, line[0].Z) - Math.Min(playerZ, line[0].Z); float curZDist = 0; float useZDist = 0; pCacheMapLine.Color = line.Color; for (int d = 1; d < line.Count; d++) { curX = line[d].X; curY = line[d].Y; curZ = line[d].Z; curZDist = Math.Max(playerZ, line[d].Z) - Math.Min(playerZ, line[d].Z); useZDist = Math.Min(lastZDist, curZDist); lastZDist = curZDist; if (useZDist > m_depthCutoff) { lastX = curX; lastY = curY; lastZ = curZ; continue; } else if (useZDist > m_depthDistance) { if (m_depthUseAlpha) { float aratio = m_depthCutoff / m_depthMaxAlpha; alpha = (int)((m_depthCutoff - useZDist) / aratio); if (alpha < m_depthMinAlpha) alpha = m_depthMinAlpha; pCacheMapLine.Color = Color.FromArgb(alpha, pCacheMapLine.Color); } else { pCacheMapLine.Color = Color.FromArgb(64, pCacheMapLine.Color); } } g.DrawLine(pCacheMapLine, lastX, lastY, curX, curY); lastX = curX; lastY = curY; lastZ = curZ; } } } g.Restore(tState); }
//renders the vector map with no depth filtering private void DrawLines(Graphics g) { if (!m_showLines) return; float dx = (mapViewOffset.X + clientCenter.X) / -m_ratio + mapCenter.X; float dy = (mapViewOffset.Y + clientCenter.Y) / -m_ratio - mapCenter.Y; GraphicsState tState = g.Save(); g.ScaleTransform(m_ratio, -m_ratio); g.TranslateTransform(-dx, dy); foreach (MapLine line in m_data.Lines) { if (line.Count > 1) { pCacheMapLine.Color = line.Color; g.DrawLines(pCacheMapLine, line.getPoints()); } } g.Restore(tState); }
partial void ScaleTransformImp(float x, float y) { g.ScaleTransform(x, y); }
/// <summary> /// /// </summary> /// <param name="pReflMark"></param> public unsafe uint[] ReflectBitmap() { if (this.mBitmapOriginal == null) { return(null); } // Create a canvas of the correct size and with Alpha Pixel format Bitmap finalBitmap = new Bitmap(this.mBitmapOriginal.Width, this.mBitmapOriginal.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb); // Locate bitmap System.Drawing.Graphics g = Graphics.FromImage(finalBitmap); if (mSettings.KeepTransparency) { g.Clear(System.Drawing.Color.Transparent); } else { g.Clear(this.panelViewport.BackColor); } float sx = (float)this.mSettings.NewWidth / (float)this.mBitmapOriginal.Width; float sy = (float)this.mSettings.NewHeight / (float)this.mBitmapOriginal.Height; g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; g.ScaleTransform(sx, sy); System.Drawing.Rectangle destRect = new System.Drawing.Rectangle(mSettings.NewLocation, finalBitmap.Size); System.Drawing.Rectangle srcRect = new System.Drawing.Rectangle(new System.Drawing.Point(), finalBitmap.Size); g.DrawImage(this.mBitmapOriginal, destRect, srcRect, GraphicsUnit.Pixel); System.Drawing.Imaging.BitmapData bmData = finalBitmap.LockBits(new System.Drawing.Rectangle(0, 0, finalBitmap.Width, finalBitmap.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); int pixelBytes = 4; byte *pointer = (byte *)(void *)bmData.Scan0; // Make the reflection uint[] result = new uint[finalBitmap.Width * finalBitmap.Height]; for (int x = 0; x < finalBitmap.Width; x++) { int pbX = (int)this.mXNAPictureBox.ImageToPictureBox(new Vector2(x, 0)).X; int initialy = (int)this.mReflectionMark.GetYAt(pbX); if (initialy == float.MinValue) { continue; } int initialy_onImage = (int)this.mXNAPictureBox.PictureBoxToImage(new Vector2(0, initialy)).Y; int address, adBytes; for (int y = 0; y < finalBitmap.Height; y++) { address = (y * finalBitmap.Width) + x; if (y <= initialy_onImage) { adBytes = (y * bmData.Stride) + (x * pixelBytes); // alpha << 24 | red << 16 | green << 8 | blue; result[address] = (uint)(pointer[adBytes + 3] << 24 | pointer[adBytes + 2] << 16 | pointer[adBytes + 1] << 8 | pointer[adBytes]); continue; } int disty = y - initialy_onImage; int reflectY = initialy_onImage - disty; if (reflectY >= 0 && reflectY < finalBitmap.Height) { adBytes = (reflectY * bmData.Stride) + (x * pixelBytes); // alpha << 24 | red << 16 | green << 8 | blue; if (mSettings.KeepTransparency) { int alpha = (int)((float)pointer[adBytes + 3] * this.GetAlphaGradient(disty)); result[address] = (uint)(alpha << 24 | pointer[adBytes + 2] << 16 | pointer[adBytes + 1] << 8 | pointer[adBytes]); } else { // Mix up backColor and reflection color float falpha = this.GetAlphaGradient(disty); byte red = (byte)(((float)pointer[adBytes + 2] * falpha) + ((float)panelViewport.BackColor.R * (1 - falpha))); byte green = (byte)(((float)pointer[adBytes + 1] * falpha) + ((float)panelViewport.BackColor.G * (1 - falpha))); byte blue = (byte)(((float)pointer[adBytes] * falpha) + ((float)panelViewport.BackColor.B * (1 - falpha))); result[address] = (uint)((byte)255 << 24 | red << 16 | green << 8 | blue); } } else if (!mSettings.KeepTransparency) { // Just copy backcolor result[address] = (uint)(panelViewport.BackColor.A << 24 | panelViewport.BackColor.R << 16 | panelViewport.BackColor.G << 8 | panelViewport.BackColor.B); } } } return(result); }
protected override void PaintClient(Graphics g, bool imageDataLost) { float z = Zoom; if (mPreviousClientSize != ClientSize) { if (!mNeedsPlayerRecenter && mCenterOnCoords == Coordinates.NO_COORDINATES) { if (CenterOnPlayer && IsCenteredOnPlayer(z, mPreviousClientSize)) mNeedsPlayerRecenter = true; else CenterOnPix(mPreviousClientSize.Width / 2, mPreviousClientSize.Height / 2, z); } mPreviousClientSize = ClientSize; } float zoomedSize = mMapSize * z; if (zoomedSize < ClientSize.Width || zoomedSize < ClientSize.Height) { z = Math.Max(ClientSize.Width / (float)mMapSize, ClientSize.Height / (float)mMapSize); if (z > 1) z = 1; Zoom = z; ActualZoom = z; zoomedSize = mMapSize * z; } // Paint Map Matrix origTransform = g.Transform; g.Clear(Clear); float coordPadX = 0, coordPadY = 0; if (mCenterOnCoords != Coordinates.NO_COORDINATES) { CenterOnCoords(mCenterOnCoords, z); mCenterOnCoords = Coordinates.NO_COORDINATES; mNeedsPlayerRecenter = false; } else if (mNeedsPlayerRecenter && (ClientMouseButtons & DragButton) == 0) { mNeedsPlayerRecenter = false; if (!PlayerInDungeon) CenterOnCoords(mPlayerCoords, z); } if (ClientSize.Width > zoomedSize) { // Center horizontally mOffset.X = (ClientSize.Width - zoomedSize) / (2 * z); coordPadX = mOffset.X * z; } else if (mOffset.X > 0) mOffset.X = 0; else if (mOffset.X < (ClientSize.Width - zoomedSize) / z) mOffset.X = (ClientSize.Width - zoomedSize) / z; if (ClientSize.Height > zoomedSize) { // Center vertically mOffset.Y = (ClientSize.Height - zoomedSize) / (2 * z); coordPadY = mOffset.Y * z; } else if (mOffset.Y > 0) mOffset.Y = 0; else if (mOffset.Y < (ClientSize.Height - zoomedSize) / z) mOffset.Y = (ClientSize.Height - zoomedSize) / z; #region Draw Map if (z < 1) { // Lazy load low res map if (mDerethMapLowRes == null) { mDerethMapLowRes = new Bitmap(mZipFile.GetInputStream(mZipFile.GetEntry("lowres.png"))); } float relSize = (float)mDerethMapLowRes.Width / mMapSize; if (z / relSize <= 0.5f) g.InterpolationMode = InterpolationMode.HighQualityBilinear; else g.InterpolationMode = InterpolationMode.Bilinear; RectangleF srcRect = new RectangleF(-mOffset.X * relSize, -mOffset.Y * relSize, ClientSize.Width * relSize / z, ClientSize.Height * relSize / z); RectangleF destRect = new RectangleF(0, 0, ClientSize.Width, ClientSize.Height); g.DrawImage(mDerethMapLowRes, destRect, srcRect, GraphicsUnit.Pixel); } else { float w = ClientSize.Width / z; int minTileX = Math.Max((int)(-mOffset.X / mTileSize), 0); int minTileY = Math.Max((int)(-mOffset.Y / mTileSize), 0); int maxTileX = Math.Min( (int)((-mOffset.X + ClientSize.Width / z) / mTileSize), mMaxTile); int maxTileY = Math.Min( (int)((-mOffset.Y + ClientSize.Height / z) / mTileSize), mMaxTile); if (z == 1) { int offX = (int)mOffset.X, offY = (int)mOffset.Y; int dX, dY; for (int i = minTileX; i <= maxTileX; i++) { dX = i * mTileSize + offX; for (int j = minTileY; j <= maxTileY; j++) { dY = j * mTileSize + offY; GraphicsUtil.BitBlt(GetTile(i, j), ClientImage, dX, dY); } } } else { g.InterpolationMode = InterpolationMode.NearestNeighbor; g.ScaleTransform(z, z); float dX, dY; for (int i = minTileX; i <= maxTileX; i++) { dX = i * mTileSize + mOffset.X; for (int j = minTileY; j <= maxTileY; j++) { dY = j * mTileSize + mOffset.Y; g.DrawImage(GetTile(i, j), dX, dY); } } } } #endregion g.Transform = origTransform; #region Draw Route-Finding Regions #if false float regionZoom = z * mPixPerClick; g.ScaleTransform(z, z); g.TranslateTransform(mOffset.X + mMapSize / 2.0f - 1.0f, mOffset.Y + mMapSize / 2.0f); g.ScaleTransform(mPixPerClick, -mPixPerClick); Brush regionFill = new SolidBrush(Color.FromArgb(0x77CC0000)); Brush innerRegionFill = new SolidBrush(Color.FromArgb(0x77AB10BC)); RouteFinder.DrawRegions(g, regionFill, innerRegionFill); g.Transform = origTransform; #endif #endregion Coordinates minCoords = PixToCoords(0, 0, z); Coordinates maxCoords = PixToCoords(ClientSize.Width, ClientSize.Height, z); #region Draw Coordinates (Part I: Gridlines) float lastTickNS = 0, firstTickEW = 0, lastTickEW = 0, firstTickNS = 0; RectangleF mapRect = new RectangleF(), insideGutter = new RectangleF(); Region coordGutter = null; string precision = ""; if (DrawCoords) { g.SmoothingMode = SmoothingMode.Default; if (mCoordTickDelta >= 1) precision = "0"; else if (mCoordTickDelta >= 0.1) precision = "0.0"; else precision = "0.00"; lastTickNS = (float)(Math.Floor(minCoords.NS / mCoordTickDelta) * mCoordTickDelta); firstTickEW = (float)(Math.Floor(minCoords.EW / mCoordTickDelta) * mCoordTickDelta); lastTickEW = (float)(Math.Ceiling(maxCoords.EW / mCoordTickDelta) * mCoordTickDelta); firstTickNS = (float)(Math.Ceiling(maxCoords.NS / mCoordTickDelta) * mCoordTickDelta); mapRect = new RectangleF(coordPadX, coordPadY, ClientSize.Width - 2 * coordPadX, ClientSize.Height - 2 * coordPadY); insideGutter = new RectangleF( coordPadX + CoordGutterSize, coordPadY + CoordGutterSize, ClientSize.Width - 2 * (CoordGutterSize + coordPadX), ClientSize.Height - 2 * (CoordGutterSize + coordPadY)); coordGutter = new Region(mapRect); coordGutter.Xor(insideGutter); g.FillRegion(CoordGutterFill, coordGutter); // Draw Gridlines for (float ns = firstTickNS, ew = firstTickEW; ns <= lastTickNS || ew <= lastTickEW; ns += mCoordTickDelta, ew += mCoordTickDelta) { PointF pos = CoordsToPix(ns, ew, z); if (pos.Y > insideGutter.Top && pos.Y < insideGutter.Bottom) { // Draw horizontal NS gridline g.DrawLine(CoordGridline, CoordGutterSize + coordPadX, pos.Y, ClientSize.Width - CoordGutterSize - coordPadX - 1, pos.Y); } if (pos.X > insideGutter.Left && pos.X < insideGutter.Right) { // Draw vertical EW gridline g.DrawLine(CoordGridline, pos.X, CoordGutterSize + coordPadY, pos.X, ClientSize.Height - CoordGutterSize - coordPadY - 1); } } } #endregion #region Draw Locations mHotspots.Clear(); float z2 = (float)(Math.Pow(z / ZoomBase, 0.25)); if (ShowLocations) { g.SmoothingMode = SmoothingMode.Default; g.InterpolationMode = InterpolationMode.HighQualityBilinear; Dictionary<LocationType, List<Location>> visibleLocations = new Dictionary<LocationType, List<Location>>(); foreach (Location loc in mLocDb.Locations.Values) { if (loc.Coords.NS <= minCoords.NS && loc.Coords.NS >= maxCoords.NS && loc.Coords.EW >= minCoords.EW && loc.Coords.EW <= maxCoords.EW) { List<Location> addTo; LocationType type = loc.Type; if ((type & LocationType.AnyPortal) != 0) { type = LocationType.AnyPortal; } if (!visibleLocations.TryGetValue(type, out addTo)) { addTo = new List<Location>(); visibleLocations.Add(type, addTo); } addTo.Add(loc); } } if (ShowLocationsAllZooms || ZoomFactor >= 5) { DrawLocationType(visibleLocations, LocationType.NPC, Icons.Map.NPC, g, z, z2); DrawLocationType(visibleLocations, LocationType.Vendor, Icons.Map.Store, g, z, z2); } if (ShowLocationsAllZooms || ZoomFactor >= 2) { DrawLocationType(visibleLocations, LocationType.Village, Icons.Map.Settlement, g, z, z2); DrawLocationType(visibleLocations, LocationType.Landmark, Icons.Map.PointOfInterest, g, z, z2); DrawLocationType(visibleLocations, LocationType.AllegianceHall, Icons.Map.Dungeon, g, z, z2); DrawLocationType(visibleLocations, LocationType.Bindstone, Icons.Map.Bindstone, g, z, z2); } if (ShowLocationsAllZooms || ZoomFactor >= -1) { DrawLocationType(visibleLocations, LocationType.Custom, Icons.Map.PointOfInterest, g, z, z2); DrawLocationType(visibleLocations, LocationType.Lifestone, Icons.Map.Lifestone, g, z, z2); DrawLocationType(visibleLocations, LocationType.Dungeon, Icons.Map.Dungeon, g, z, z2); DrawLocationType(visibleLocations, LocationType.AnyPortal, Icons.Map.Portal, g, z, z2); DrawLocationType(visibleLocations, LocationType.PortalHub, Icons.Map.PortalHub, g, z, z2); DrawLocationType(visibleLocations, LocationType.Outpost, Icons.Map.TownSmall, g, z, z2); } DrawLocationType(visibleLocations, LocationType.Town, Icons.Map.Town, g, z, z2); //DrawLocationType(visibleLocations, LocationType._StartPoint, Icons.Map.StartPoint, g, z, z2); //DrawLocationType(visibleLocations, LocationType._EndPoint, Icons.Map.EndPoint, g, z, z2); if (ShowLabels) { float z3 = (float)(Math.Pow(z / ZoomBase, 0.1)); Font f = new Font(FontFamily.GenericSerif, Math.Min(8 * z3, 10)); Font fTown = new Font(FontFamily.GenericSerif, Math.Min(9 * z3, 12), FontStyle.Bold); List<RectangleF> usedLabelRects = new List<RectangleF>(); if (ZoomFactor >= -4) { LabelLocationType(g, fTown, usedLabelRects, LocationType.Town); } if (ZoomFactor >= 1) { LabelLocationType(g, f, usedLabelRects, LocationType.Outpost); LabelLocationType(g, f, usedLabelRects, LocationType.PortalHub); LabelLocationType(g, f, usedLabelRects, LocationType.AnyPortal); LabelLocationType(g, f, usedLabelRects, LocationType.Dungeon); LabelLocationType(g, f, usedLabelRects, LocationType.Lifestone); LabelLocationType(g, f, usedLabelRects, LocationType.Custom); } if (ZoomFactor >= 4) { LabelLocationType(g, f, usedLabelRects, LocationType.Bindstone); LabelLocationType(g, f, usedLabelRects, LocationType.AllegianceHall); LabelLocationType(g, f, usedLabelRects, LocationType.Landmark); LabelLocationType(g, f, usedLabelRects, LocationType.Village); } //if (ZoomFactor >= 6) { // LabelLocation(g, f, usedLabelRects, LocationType.Vendor); // LabelLocation(g, f, usedLabelRects, LocationType.NPC); //} } } #endregion #region Draw Route if (ShowRoute && mRoute != null && mRoute.Count > 1) { g.SmoothingMode = SmoothingMode.AntiAlias; PointF lastPoint, curPoint = CoordsToPix(mRoute[0].Coords, z); for (int i = 1; i < mRoute.Count; i++) { // Running lastPoint = curPoint; curPoint = CoordsToPix(mRoute[i].Coords, z); double dX = lastPoint.X - curPoint.X; double dY = lastPoint.Y - curPoint.Y; double dist = Math.Sqrt(dX * dX + dY * dY); if (dist >= 5.0) { g.DrawLine(RouteLineBackground, lastPoint, curPoint); g.DrawLine(RouteLine, lastPoint, curPoint); } // Portals if (mRoute[i].HasExitCoords) { lastPoint = curPoint; curPoint = CoordsToPix(mRoute[i].ExitCoords, z); dX = lastPoint.X - curPoint.X; dY = lastPoint.Y - curPoint.Y; dist = Math.Sqrt(dX * dX + dY * dY); if (dist >= 5.0) { //g.DrawLine(RouteLineBackground, lastPoint, curPoint); g.DrawLine(RouteLinePortal, lastPoint, curPoint); } } } } #endregion #region Draw Arrow Destination PointF ptf = CoordsToPix(mPluginCore.mArrowHud.DestinationCoords, z); if (ptf.X >= 0 && ptf.Y >= 0 && ptf.X < ClientSize.Width && ptf.Y < ClientSize.Height) { float zw = z2 * Icons.Map.ArrowDest2.Width; float zh = z2 * Icons.Map.ArrowDest2.Height; RectangleF rectf = new RectangleF(ptf.X - zw / 2, ptf.Y - zh / 2, zw, zh); g.DrawImage(Icons.Map.ArrowDest2, rectf); Rectangle rect = new Rectangle(Point.Truncate(rectf.Location), Size.Ceiling(rectf.Size)); } #endregion #region Draw Coordinates (Part II: Labels) if (DrawCoords) { Region clipNS = new Region(new RectangleF(mapRect.X, mapRect.Y + CoordGutterSize, mapRect.Width, mapRect.Height - 2 * CoordGutterSize)); Region clipEW = new Region(new RectangleF(mapRect.X + CoordGutterSize, mapRect.Y, mapRect.Width - 2 * CoordGutterSize, mapRect.Height)); Region origClip = g.Clip; // Draw Labels for (float ns = firstTickNS, ew = firstTickEW; ns <= lastTickNS || ew <= lastTickEW; ns += mCoordTickDelta, ew += mCoordTickDelta) { PointF pos = CoordsToPix(ns, ew, z); string nsString = Math.Abs(ns).ToString(precision) + (ns >= 0 ? "N" : "S"); string ewString = Math.Abs(ew).ToString(precision) + (ew >= 0 ? "E" : "W"); SizeF nsSize = g.MeasureString(nsString, CoordTextFont); SizeF ewSize = g.MeasureString(ewString, CoordTextFont); g.Clip = clipNS; float nsY = pos.Y - nsSize.Width / 2; g.DrawString(nsString, CoordTextFont, Brushes.White, coordPadX, nsY, VerticalText); g.DrawString(nsString, CoordTextFont, Brushes.White, ClientSize.Width - coordPadX - nsSize.Height, nsY, VerticalText); g.Clip = coordGutter; float ewX = pos.X - ewSize.Width / 2; g.DrawString(ewString, CoordTextFont, Brushes.White, ewX, coordPadY); g.DrawString(ewString, CoordTextFont, Brushes.White, ewX, ClientSize.Height - ewSize.Height - coordPadY); } g.Clip = origClip; } #endregion PaintSprites(z); mPreviousZoomMultiplier = z; mLastPaintedPlayerCoords = PlayerCoords; }
private void DrawSelection(Graphics gdiG, PdnGraphicsPath outline) { if (outline == null) { return; } float ratio = (float)OwnerList.ScaleFactor.Ratio; gdiG.ScaleTransform(ratio, ratio); if (EnableSelectionTinting) { PdnGraphicsPath outline2; if (invertedTinting) { outline2 = (PdnGraphicsPath)outline.Clone(); outline2.AddRectangle(new Rectangle(-1, -1, this.SourceSize.Width + 1, this.SourceSize.Height + 1)); outline2.CloseAllFigures(); } else { outline2 = outline; } DrawSelectionTinting(gdiG, outline2); if (invertedTinting) { outline2.Dispose(); } } if (EnableSelectionOutline) { DrawSelectionOutline(gdiG, outline); } gdiG.ScaleTransform(1 / ratio, 1 / ratio); }
public void scale(float x, float y) { dg.ScaleTransform(x, y); }
public void Draw(Graphics g, int x, int y) { g.ResetTransform(); g.TranslateTransform(x, y); g.RotateTransform(useangle); // Debug.Print("Drawing at scale" + mScale); g.ScaleTransform(mScale, mScale); g.TranslateTransform(-textbitmap.Width / 2, -textbitmap.Height / 2); //should we draw a shadow? if (drawShadow) { //if so, translate to the shadow offset. g.TranslateTransform(ShadowOffset.X, ShadowOffset.Y); //draw the shadow //g.DrawImage(drawthis, new Rectangle((int)Location.X, (int)Location.Y, (int)ObjectSize.Width, (int)ObjectSize.Height), //0, 0, drawthis.Width, drawthis.Height, GraphicsUnit.Pixel, useattributes); g.DrawImage(textbitmap, new Rectangle(0, 0, (int)textbitmap.Width, (int)textbitmap.Height), 0, 0, textbitmap.Width, textbitmap.Height, GraphicsUnit.Pixel, drawshadowattributes); //go back... g.ResetTransform(); g.TranslateTransform(x, y); g.RotateTransform(useangle); // Debug.Print("Drawing at scale" + mScale); g.ScaleTransform(mScale, mScale); g.TranslateTransform(-textbitmap.Width / 2, -textbitmap.Height / 2); } g.DrawImage(textbitmap, 0, 0); //g.RotateTransform(30); }
private void graficar1() { System.Drawing.Graphics ent = this.pictureBox1.CreateGraphics(); int xcentro = pictureBox1.Width / 2; int ycentro = pictureBox1.Height / 2; ent.TranslateTransform(xcentro, ycentro); ent.ScaleTransform(1, -1); double a, b; a = Convert.ToDouble(txtix.Text); b = Convert.ToDouble(txtiy.Text); if (a < -40 || a > 40 || b < -40 || b > 40) { //PINTAR LAS RAYAS for (int c = -xcentro; c <= xcentro; c += 4) { ent.DrawLine(mylapiz1, -1 * 2, c * 2, 1 * 2, c * 2); ent.DrawLine(mylapiz1, c * 2, 1 * 2, c * 2, -1 * 2); } double x1, y1, punto1, c3, punto1a, x11, y11, c11, punto2, punto2a; x1 = Convert.ToDouble(txbA.Text); y1 = Convert.ToDouble(txbB.Text); c3 = Convert.ToDouble(txbC.Text); x11 = x1 * 2; y11 = y1 * 2; c11 = c3 * 2; //RESOLVER LA ECUACION CUANDO X TIENDE A -100 punto1 = (((x1 * -100) + c3) * -1); punto1a = ((punto1 / y1) * 2); //RESOLVER LA ECUACION CUANDO X TIENDE A 100 punto2 = (((x1 * 100) + c3) * -1); punto2a = ((punto1 / y1) * 2); double x22, x23; x22 = -100 * 2; x23 = 100 * 2; Point ucord1 = new Point((int)x22, (int)punto1a); Point ucord2 = new Point((int)x23, (int)punto2a); ent.DrawLine(mylapiz2, (int)x22, (int)punto1a, (int)x23, (int)punto2a); } else { if (a < -20 || a > 20 || b < -20 || b > 20) { for (int c = -xcentro; c <= xcentro; c += 2) { ent.DrawLine(mylapiz1, -1 * 5, c * 5, 1 * 5, c * 5); ent.DrawLine(mylapiz1, c * 5, 1 * 5, c * 5, -1 * 5); } double x1, y1, miau, c3, miau2, x11, y11, c11, miau11, miau22; x1 = Convert.ToDouble(txbA.Text); y1 = Convert.ToDouble(txbB.Text); c3 = Convert.ToDouble(txbC.Text); x11 = x1 * 5; y11 = y1 * 5; c11 = c3 * 5; miau = (((x1 * -100) + c3) * -1); miau2 = ((miau / y1) * 5); miau11 = (((x1 * 100) + c3) * -1); miau22 = ((miau11 / y1) * 5); double x22, x23; x22 = -100 * 5; x23 = 100 * 5; Point ucord1 = new Point((int)x22, (int)miau2); Point ucord2 = new Point((int)x22, (int)miau22); ent.DrawLine(mylapiz2, (int)x22, (int)miau2, (int)x23, (int)miau22); } else { for (int c = -xcentro; c <= xcentro; c += 1) { ent.DrawLine(mylapiz1, -1 * 20, c * 20, 1 * 20, c * 20); ent.DrawLine(mylapiz1, c * 20, 1 * 20, c * 20, -1 * 20); } double x1, y1, miau, c3, miau2, x11, y11, c11, miau11, miau22; x1 = Convert.ToDouble(txbA.Text); y1 = Convert.ToDouble(txbB.Text); c3 = Convert.ToDouble(txbC.Text); x11 = x1 * 20; y11 = y1 * 20; c11 = c3 * 20; miau = (((x1 * -100) + c3) * -1); miau2 = ((miau / y1) * 20); miau11 = (((x1 * 100) + c3) * -1); miau22 = ((miau11 / y1) * 20); double x22, x23; x22 = -100 * 20; x23 = 100 * 20; Point ucord1 = new Point((int)x22, (int)miau2); Point ucord2 = new Point((int)x22, (int)miau22); ent.DrawLine(mylapiz2, (int)x22, (int)miau2, (int)x23, (int)miau22); } } }