void gdiViewer_InfoMessageSent(object sender, GDI.ViewerInfoEventArgs e) { if (e.InfoType.HasFlag(GDI.ViewerInfoType.InitDone)) { GeomInfoLabel.Text = e.GeometryInfo; PerfInitLabel.Text = string.Format("Init: {0} ms", e.InitTime); MouseCoordsLabel.Text = null; } else if (e.InfoType.HasFlag(GDI.ViewerInfoType.MouseMove)) { MouseCoordsLabel.Text = "Mouse move"; } else if (e.InfoType.HasFlag(GDI.ViewerInfoType.Draw)) { PerfDrawLabel.Text = string.Format("Draw: {0} ms", e.DrawTime); } }
static bool GdiOpenFace(string face, out byte[] buffer) { int weight = GDI.FW_REGULAR; uint fdwItalic = 0; //Get font data from GDI buffer = null; unsafe { var hfont = GDI.CreateFont(0, 0, 0, 0, weight, fdwItalic, 0, 0, GDI.DEFAULT_CHARSET, GDI.OUT_OUTLINE_PRECIS, GDI.CLIP_DEFAULT_PRECIS, GDI.DEFAULT_QUALITY, GDI.DEFAULT_PITCH, face); //get data var hdc = GDI.CreateCompatibleDC(IntPtr.Zero); GDI.SelectObject(hdc, hfont); var size = GDI.GetFontData(hdc, 0, 0, IntPtr.Zero, 0); if (size == GDI.GDI_ERROR) { FLLog.Warning("GDI", "GetFontData for " + face + " failed"); GDI.DeleteDC(hdc); GDI.DeleteObject(hfont); return(false); } buffer = new byte[size]; fixed(byte *ptr = buffer) { GDI.GetFontData(hdc, 0, 0, (IntPtr)ptr, size); } GDI.DeleteDC(hdc); //delete font GDI.DeleteObject(hfont); return(true); } }
public void Render(PlotDimensions dims, Bitmap bmp, bool lowQuality = false) { using (var gfx = Graphics.FromImage(bmp)) using (var font = GDI.Font(FontName, FontSize, FontBold)) using (var fontBrush = new SolidBrush(FontColor)) using (var shadowBrush = new SolidBrush(ShadowColor)) using (var backgroundBrush = new SolidBrush(BackgroundColor)) using (var borderPen = new Pen(BorderColor, BorderWidth)) { gfx.SmoothingMode = lowQuality ? SmoothingMode.HighSpeed : SmoothingMode.AntiAlias; gfx.TextRenderingHint = lowQuality ? TextRenderingHint.SingleBitPerPixelGridFit : TextRenderingHint.AntiAliasGridFit; SizeF size = GDI.MeasureString(gfx, label, font); double x = (xPixel >= 0) ? xPixel : dims.DataWidth + xPixel - size.Width; double y = (yPixel >= 0) ? yPixel : dims.DataHeight + yPixel - size.Height; PointF location = new PointF((float)x, (float)y); if (Background && Shadow) { gfx.FillRectangle(shadowBrush, location.X + 5, location.Y + 5, size.Width, size.Height); } if (Background) { gfx.FillRectangle(backgroundBrush, location.X, location.Y, size.Width, size.Height); } if (Border) { gfx.DrawRectangle(borderPen, location.X, location.Y, size.Width, size.Height); } gfx.DrawString(label, font, fontBrush, location); } }
internal void CreateFrom(Bitmap bmp, bool useGDI) { if (Bitmap != null) { throw new Exception(); } try { Bitmap = bmp; if (useGDI) { gdi = true; hBitmap = Bitmap.GetHbitmap(); g = Graphics.FromImage(Bitmap); GDIhDC = g.GetHdc(); hDefaultImg = GDI.SelectObject(GDIhDC, hBitmap); } } catch { return; } return; }
private HCLineObj GetLineObjAt(int x, int y) { HCLineObj Result = HCLineObj.cloNone; if (HC.PtInRect(new RECT(FStartPt.X - PointSize, FStartPt.Y - PointSize, FStartPt.X + PointSize, FStartPt.Y + PointSize), new POINT(x, y))) { Result = HCLineObj.cloLeftOrTop; } else if (HC.PtInRect(new RECT(FEndPt.X - PointSize, FEndPt.Y - PointSize, FEndPt.X + PointSize, FEndPt.Y + PointSize), new POINT(x, y))) { Result = HCLineObj.cloRightOrBottom; } else { POINT[] vPointArr = new POINT[4]; vPointArr[0] = new POINT(FStartPt.X - PointSize, FStartPt.Y); vPointArr[1] = new POINT(FStartPt.X + PointSize, FStartPt.Y); vPointArr[2] = new POINT(FEndPt.X + PointSize, FEndPt.Y); vPointArr[3] = new POINT(FEndPt.X - PointSize, FEndPt.Y); IntPtr vRgn = (IntPtr)GDI.CreatePolygonRgn(ref vPointArr[0], 4, GDI.WINDING); try { if (GDI.PtInRegion(vRgn, x, y) > 0) { Result = HCLineObj.cloLine; } } finally { GDI.DeleteObject(vRgn); } } return(Result); }
public static void Distribution(Settings settings, Population pop, Random rand, double popLeft, double popWidth, Color color, Position position, LineStyle lineStyle) { // adjust edges to accomodate special positions if (position == Position.Hide) { return; } if (position == Position.Left || position == Position.Right) { popWidth /= 2; } if (position == Position.Right) { popLeft += popWidth; } // contract edges slightly to encourage padding between elements double edgePaddingFrac = 0.2; popLeft += popWidth * edgePaddingFrac; popWidth -= (popWidth * edgePaddingFrac) * 2; Pen pen = GDI.Pen(color, 1, lineStyle, true); double[] ys = DataGen.Range(pop.minus3stDev, pop.plus3stDev, settings.yAxisUnitsPerPixel); double[] ysFrac = pop.GetDistribution(ys); PointF[] points = new PointF[ys.Length]; for (int i = 0; i < ys.Length; i++) { float x = (float)settings.GetPixelX(popLeft + popWidth * ysFrac[i]); float y = (float)settings.GetPixelY(ys[i]); points[i] = new PointF(x, y); } settings.gfxData.DrawLines(pen, points); }
public static void Box(PlotDimensions dims, Bitmap bmp, bool lowQuality, Population pop, Random rand, double popLeft, double popWidth, Color color, Position position, BoxFormat boxFormat, HorizontalAlignment errorAlignment = HorizontalAlignment.Right) { // adjust edges to accomodate special positions if (position == Position.Hide) { return; } if (position == Position.Left || position == Position.Right) { popWidth /= 2; } if (position == Position.Right) { popLeft += popWidth; } double errorMaxPx, errorMinPx; double yPxTop, yPxBase; double yPx; if (boxFormat == BoxFormat.StdevStderrMean) { errorMaxPx = dims.GetPixelY(pop.mean + pop.stDev); errorMinPx = dims.GetPixelY(pop.mean - pop.stDev); yPxTop = dims.GetPixelY(pop.mean + pop.stdErr); yPxBase = dims.GetPixelY(pop.mean - pop.stdErr); yPx = dims.GetPixelY(pop.mean); } else if (boxFormat == BoxFormat.OutlierQuartileMedian) { errorMaxPx = dims.GetPixelY(pop.maxNonOutlier); errorMinPx = dims.GetPixelY(pop.minNonOutlier); yPxTop = dims.GetPixelY(pop.Q3); yPxBase = dims.GetPixelY(pop.Q1); yPx = dims.GetPixelY(pop.median); } else { throw new NotImplementedException(); } // make cap width a fraction of available space double capWidthFrac = .38; double capWidth = popWidth * capWidthFrac; // contract edges slightly to encourage padding between elements double edgePaddingFrac = 0.2; popLeft += popWidth * edgePaddingFrac; popWidth -= (popWidth * edgePaddingFrac) * 2; double leftPx = dims.GetPixelX(popLeft); double rightPx = dims.GetPixelX(popLeft + popWidth); RectangleF rect = new RectangleF( x: (float)leftPx, y: (float)yPxTop, width: (float)(rightPx - leftPx), height: (float)(yPxBase - yPxTop)); // determine location of errorbars and caps double capPx1, capPx2, errorPxX; switch (errorAlignment) { case HorizontalAlignment.Center: double centerX = popLeft + popWidth / 2; errorPxX = dims.GetPixelX(centerX); capPx1 = dims.GetPixelX(centerX - capWidth / 2); capPx2 = dims.GetPixelX(centerX + capWidth / 2); break; case HorizontalAlignment.Right: errorPxX = dims.GetPixelX(popLeft + popWidth); capPx1 = dims.GetPixelX(popLeft + popWidth - capWidth / 2); capPx2 = dims.GetPixelX(popLeft + popWidth); break; case HorizontalAlignment.Left: errorPxX = dims.GetPixelX(popLeft); capPx1 = dims.GetPixelX(popLeft); capPx2 = dims.GetPixelX(popLeft + capWidth / 2); break; default: throw new NotImplementedException(); } using (Graphics gfx = GDI.Graphics(bmp, dims, lowQuality)) using (Pen pen = GDI.Pen(Color.Black)) using (Brush brush = GDI.Brush(color)) { // draw the box gfx.FillRectangle(brush, rect.X, rect.Y, rect.Width, rect.Height); gfx.DrawRectangle(pen, rect.X, rect.Y, rect.Width, rect.Height); // draw the line in the center gfx.DrawLine(pen, rect.X, (float)yPx, rect.X + rect.Width, (float)yPx); // draw errorbars and caps gfx.DrawLine(pen, (float)errorPxX, (float)errorMinPx, (float)errorPxX, rect.Y + rect.Height); gfx.DrawLine(pen, (float)errorPxX, (float)errorMaxPx, (float)errorPxX, rect.Y); gfx.DrawLine(pen, (float)capPx1, (float)errorMinPx, (float)capPx2, (float)errorMinPx); gfx.DrawLine(pen, (float)capPx1, (float)errorMaxPx, (float)capPx2, (float)errorMaxPx); } }
/// <summary> /// Сохраняет данные IImage в файл /// </summary> /// <param name="image"></param> /// <param name="file"></param> public static void SaveImageFromMemory(GDI.IImage image, string file) { GDI.ImageInfo newImageInfo; GDI.IBitmapImage newIBitmapImage; Bitmap newBitmap; image.GetImageInfo(out newImageInfo); ImagingFactory.CreateBitmapFromImage(image, newImageInfo.Width, newImageInfo.Height, PixelFormatID.PixelFormat24bppRGB, DefaultInterpolation, out newIBitmapImage); newBitmap = ImageUtils.IBitmapImageToBitmap((IBitmapImage)newIBitmapImage); newBitmap.Save(file, ImageFormat.Jpeg); Marshal.FinalReleaseComObject(newIBitmapImage); newBitmap.Dispose(); }
/// <summary> /// Загрузка IImage из файла /// </summary> /// <param name="file"></param> /// <param name="image"></param> public static void LoadImageFromFile(string file, out GDI.IImage image) { ImagingFactory.CreateImageFromFile(file, out image); }
/// <summary> /// Draws a check mark control in the specified state, on the specified graphics surface, and within the specified /// bounds. /// </summary> /// <param name="graphics">The graphics to draw on.</param> /// <param name="checkStyle">The check mark type.</param> /// <param name="rectangle">The rectangle that represents the dimensions of the check box.</param> /// <param name="enabled">The state to draw the check mark in.</param> public static void DrawCheckMark(Graphics graphics, CheckStyle checkStyle, Rectangle rectangle, bool enabled) { Size _characterSize = GDI.MeasureText(graphics, checkStyle.Character.ToString(), checkStyle.Font); int _styleCount = checkStyle.Style.Count(); var _defaultLocations = new Point[_styleCount]; _defaultLocations[0] = new Point((rectangle.X + (rectangle.Width / 2)) - (_characterSize.Width / 2), (rectangle.Y + (rectangle.Height / 2)) - (_characterSize.Height / 2)); _defaultLocations[1] = new Point((rectangle.X + (rectangle.Width / 2)) - (checkStyle.Bounds.Width / 2), (rectangle.Y + (rectangle.Height / 2)) - (checkStyle.Bounds.Height / 2)); _defaultLocations[2] = new Point((rectangle.X + (rectangle.Width / 2)) - (checkStyle.Bounds.Width / 2), (rectangle.Y + (rectangle.Height / 2)) - (checkStyle.Bounds.Height / 2)); Point _tempLocation; if (checkStyle.AutoSize) { int styleIndex; switch (checkStyle.Style) { case CheckStyle.CheckType.Character: { styleIndex = 0; break; } case CheckStyle.CheckType.Image: { styleIndex = 1; break; } case CheckStyle.CheckType.Shape: { styleIndex = 2; break; } default: { throw new ArgumentOutOfRangeException(); } } _tempLocation = _defaultLocations[styleIndex]; } else { _tempLocation = checkStyle.Bounds.Location; } switch (checkStyle.Style) { case CheckStyle.CheckType.Character: { graphics.DrawString(checkStyle.Character.ToString(), checkStyle.Font, new SolidBrush(checkStyle.CheckColor), _tempLocation); break; } case CheckStyle.CheckType.Image: { Rectangle _imageRectangle = new Rectangle(_tempLocation, checkStyle.Bounds.Size); graphics.DrawImage(checkStyle.Image, _imageRectangle); break; } case CheckStyle.CheckType.Shape: { Rectangle shapeRectangle = new Rectangle(_tempLocation, checkStyle.Bounds.Size); GraphicsPath shapePath = VisualBorderRenderer.CreateBorderTypePath(shapeRectangle, checkStyle.ShapeRounding, checkStyle.ShapeRounding, checkStyle.ShapeType); graphics.FillPath(new SolidBrush(checkStyle.CheckColor), shapePath); break; } default: { throw new ArgumentOutOfRangeException(); } } }
public PlottableScatter(double[] xs, double[] ys, Color color, double lineWidth, double markerSize, string label, double[] errorX, double[] errorY, double errorLineWidth, double errorCapSize, bool stepDisplay, MarkerShape markerShape, LineStyle lineStyle) { if ((xs == null) || (ys == null)) { throw new ArgumentException("X and Y data cannot be null"); } if ((xs.Length == 0) || (ys.Length == 0)) { throw new ArgumentException("xs and ys must have at least one element"); } if (xs.Length != ys.Length) { throw new ArgumentException("Xs and Ys must have same length"); } if (errorY != null) { for (int i = 0; i < errorY.Length; i++) { if (errorY[i] < 0) { errorY[i] = -errorY[i]; } } } if (errorX != null) { for (int i = 0; i < errorX.Length; i++) { if (errorX[i] < 0) { errorX[i] = -errorX[i]; } } } this.xs = xs; this.ys = ys; this.color = color; this.lineWidth = lineWidth; this.markerSize = (float)markerSize; this.label = label; this.errorX = errorX; this.errorY = errorY; this.errorLineWidth = (float)errorLineWidth; this.errorCapSize = (float)errorCapSize; this.stepDisplay = stepDisplay; this.markerShape = markerShape; this.lineStyle = lineStyle; if (xs.Length != ys.Length) { throw new ArgumentException("X and Y arrays must have the same length"); } if ((errorX != null) && (xs.Length != errorX.Length)) { throw new ArgumentException("errorX must be the same length as the original data"); } if ((errorY != null) && (xs.Length != errorY.Length)) { throw new ArgumentException("errorY must be the same length as the original data"); } penLine = GDI.Pen(color, lineWidth, lineStyle, true); penLineError = GDI.Pen(color, errorLineWidth, LineStyle.Solid, true); }
/// <summary>Draws the expander button.</summary> /// <param name="graphics">The graphics to draw on.</param> /// <param name="rectangle">The button rectangle.</param> /// <param name="color">The button color.</param> /// <param name="state">The expanded toggle.</param> public static void Draw(Graphics graphics, Rectangle rectangle, Color color, bool state) { GDI.DrawTriangle(graphics, rectangle, new SolidBrush(color), state); }
protected void DoFontChanged(object sender, EventArgs e) { GDI.SelectObject(FHandle, FFont.Handle); GDI.SetTextColor(FHandle, (int)Font.Color.ToRGB_UInt()); }
protected void DoPenChanged(object sender, EventArgs e) { GDI.SelectObject(FHandle, Pen.Handle); switch (FPen.Mode) { case HCPenMode.pmBlack: GDI.SetROP2(FHandle, GDI.R2_BLACK); break; case HCPenMode.pmWhite: GDI.SetROP2(FHandle, GDI.R2_WHITE); break; case HCPenMode.pmNop: GDI.SetROP2(FHandle, GDI.R2_NOP); break; case HCPenMode.pmNot: GDI.SetROP2(FHandle, GDI.R2_NOT); break; case HCPenMode.pmCopy: GDI.SetROP2(FHandle, GDI.R2_COPYPEN); break; case HCPenMode.pmNotCopy: GDI.SetROP2(FHandle, GDI.R2_NOTCOPYPEN); break; case HCPenMode.pmMergePenNot: GDI.SetROP2(FHandle, GDI.R2_MERGEPENNOT); break; case HCPenMode.pmMaskPenNot: GDI.SetROP2(FHandle, GDI.R2_MASKPENNOT); break; case HCPenMode.pmMergeNotPen: GDI.SetROP2(FHandle, GDI.R2_MERGENOTPEN); break; case HCPenMode.pmMaskNotPen: GDI.SetROP2(FHandle, GDI.R2_MASKNOTPEN); break; case HCPenMode.pmMerge: GDI.SetROP2(FHandle, GDI.R2_MERGEPEN); break; case HCPenMode.pmNotMerge: GDI.SetROP2(FHandle, GDI.R2_NOTMERGEPEN); break; case HCPenMode.pmMask: GDI.SetROP2(FHandle, GDI.R2_MASKPEN); break; case HCPenMode.pmNotMask: GDI.SetROP2(FHandle, GDI.R2_NOTMASKPEN); break; case HCPenMode.pmXor: GDI.SetROP2(FHandle, GDI.R2_XORPEN); break; case HCPenMode.pmNotXor: GDI.SetROP2(FHandle, GDI.R2_NOTXORPEN); break; } }
protected virtual void OnBackgroundChanged(ColorEventArgs e) { GDI.ApplyContainerBackColorChange(this, Background); BackgroundChanged?.Invoke(e); }
protected override void OnControlRemoved(ControlEventArgs e) { GDI.SetControlBackColor(e.Control, Background, true); }
public int Save() { return(GDI.SaveDC(FHandle)); }
private void RenderCandles(PlotDimensions dims, Bitmap bmp, bool lowQuality) { double fractionalTickWidth = .7; using Graphics gfx = GDI.Graphics(bmp, dims, lowQuality); using Pen pen = new Pen(Color.Magenta); using SolidBrush brush = new SolidBrush(Color.Magenta); for (int i = 0; i < OHLCs.Count; i++) { var ohlc = OHLCs[i]; bool closedHigher = ohlc.Close >= ohlc.Open; double highestOpenClose = Math.Max(ohlc.Open, ohlc.Close); double lowestOpenClose = Math.Min(ohlc.Open, ohlc.Close); var ohlcTime = Sequential ? i : ohlc.DateTime.ToOADate(); var ohlcSpan = Sequential ? 1 : ohlc.TimeSpan.TotalDays; float pixelX = dims.GetPixelX(ohlcTime); float boxWidth = (float)(ohlcSpan * dims.PxPerUnitX / 2 * fractionalTickWidth); Color priceChangeColor = closedHigher ? ColorUp : ColorDown; pen.Color = WickColor ?? priceChangeColor; pen.Width = (boxWidth >= 2) ? 2 : 1; // draw the wick below the box PointF wickLowBot = new PointF(pixelX, dims.GetPixelY(ohlc.Low)); PointF wickLowTop = new PointF(pixelX, dims.GetPixelY(lowestOpenClose)); gfx.DrawLine(pen, wickLowBot, wickLowTop); // draw the wick above the box PointF wickHighBot = new PointF(pixelX, dims.GetPixelY(highestOpenClose)); PointF wickHighTop = new PointF(pixelX, dims.GetPixelY(ohlc.High)); gfx.DrawLine(pen, wickHighBot, wickHighTop); // draw the candle body PointF boxLowerLeft = new PointF(pixelX, dims.GetPixelY(lowestOpenClose)); PointF boxUpperRight = new PointF(pixelX, dims.GetPixelY(highestOpenClose)); if (ohlc.Open == ohlc.Close) { // draw OHLC (non-filled) candle gfx.DrawLine(pen, boxLowerLeft.X - boxWidth, boxLowerLeft.Y, boxLowerLeft.X + boxWidth, boxLowerLeft.Y); } else { // draw a filled candle brush.Color = priceChangeColor; gfx.FillRectangle( brush: brush, x: boxLowerLeft.X - boxWidth, y: boxUpperRight.Y, width: boxWidth * 2, height: boxLowerLeft.Y - boxUpperRight.Y); if (WickColor != null) { gfx.DrawRectangle( pen: pen, x: boxLowerLeft.X - boxWidth, y: boxUpperRight.Y, width: boxWidth * 2, height: boxLowerLeft.Y - boxUpperRight.Y); } } } }
public int Restore(int aSavedDC) { return(GDI.RestoreDC(FHandle, aSavedDC)); }
//private MemoryStream ms; #region (Chat Screen) public Chat(Client client) { InitializeComponent(); UserListPanel.Controls.Add(UserListBox); UserListBox.Anchor = AnchorStyles.Right; UserListBox.BackColor = Theme.GetBackColor(); UserListBox.ForeColor = Theme.GetForeColor(); UserListBox.Dock = DockStyle.Fill; UserListBox.Visible = false; UserListBox.Font = new Font("Tahoma", 12, FontStyle.Regular); TalkingTolbl = new Label { Location = new Point(326, 14), Text = string.Empty, Font = new Font("Tahoma", 14, FontStyle.Regular) }; Controls.Add(TalkingTolbl); BubblePlaceHolder = new Panel() { Name = "BubblePlaceHolder", Anchor = (AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Bottom), AutoSize = false, Size = new Size(772, 447), Location = new Point(313, 52), Visible = true }; Controls.Add(BubblePlaceHolder); ConversationFLP = new FlowLayoutPanel() { BorderStyle = BorderStyle.FixedSingle, FlowDirection = FlowDirection.TopDown, WrapContents = false, AutoScroll = true, AutoSize = true, Enabled = true, Visible = true }; ConversationFLP.ControlAdded += ConversationFLP_ControlAdded; UserListPanel.Controls.Add(ConversationFLP); ConversationFLP.Dock = DockStyle.Fill; ConversationFLP.HorizontalScroll.Maximum = 0; ConversationFLP.HorizontalScroll.Visible = false; ConversationFLP.VerticalScroll.Visible = true; ConversationFLP.Refresh(); ContactsFLP = new FlowLayoutPanel() { BorderStyle = BorderStyle.FixedSingle, FlowDirection = FlowDirection.TopDown, WrapContents = false, AutoScroll = true, AutoSize = true, Enabled = true, Visible = false }; UserListPanel.Controls.Add(ContactsFLP); ContactsFLP.Dock = DockStyle.Fill; ContactsFLP.HorizontalScroll.Maximum = 0; ContactsFLP.HorizontalScroll.Visible = false; ContactsFLP.VerticalScroll.Visible = true; ContactsFLP.Refresh(); //NPanel NotificationsFLP = new FlowLayoutPanel() { BorderStyle = BorderStyle.FixedSingle, FlowDirection = FlowDirection.TopDown, WrapContents = false, AutoScroll = true, AutoSize = true, Enabled = true, Visible = true }; NotificationsFLP.ControlAdded += NotificationsFLP_ControlAdded; NotificationsFLP.ControlRemoved += NotificationsFLP_ControlRemoved; NPanel.Controls.Add(NotificationsFLP); NotificationsFLP.Dock = DockStyle.Fill; NotificationsFLP.HorizontalScroll.Maximum = 0; NotificationsFLP.HorizontalScroll.Visible = false; NotificationsFLP.VerticalScroll.Visible = true; NotificationsFLP.Refresh(); ThisPanel.HorizontalScroll.Visible = false; RolesPanel.Controls.Add(ContactLbl); RolesPanel.Controls.Add(ConversationsLbl); notifyTray.BalloonTipIcon = ToolTipIcon.Info; notifyTray.BalloonTipTitle = "Volupia Messenger"; //notifyTray.Icon = GetHiconForChat(); notifyTray.Icon = new Icon(Environment.CurrentDirectory + @"\VolupiaChat.ico"); notifyTray.BalloonTipClicked += NotifyTray_BalloonTipClicked; notifyTray.MouseDoubleClick += NotifyTray_MouseDoubleClick; //Button Fix MicRBtn.FlatStyle = FlatStyle.Flat; MicRBtn.BackColor = Color.Lavender; MicRBtn.FlatAppearance.BorderSize = 0; BarPanel.Region = Region.FromHrgn(GDI.CreateRoundRectRgn(0, 0, BarPanel.Width, BarPanel.Height, 60, 60)); //Arredonda caixa de texto SendRButton.FlatStyle = FlatStyle.Flat; SendRButton.BackColor = Color.Lavender; SendRButton.FlatAppearance.BorderSize = 0; ApplyTheme(); downTime = new System.Windows.Forms.Timer { Interval = 500 }; downTime.Tick += DownTime_Tick; waveOut.PlaybackStopped += (s, e) => { waveOut.Dispose(); }; _MyClient = client; myUserName = _MyClient.Username; myUserId = _MyClient.Id; NameLbl.Text = _MyClient.Name; notifyTray.Text = _MyClient.Name; downCount = 0; LoginForm.Server.Connected(); TakeInvites(); GetContacts(); }
public void DrawLine(int x1, int y1, int x2, int y2) { GDI.MoveToEx(FHandle, x1, y1, IntPtr.Zero); GDI.LineTo(FHandle, x2, y2); }
public void ApplyStyle(HCCanvas aCanvas, Single aScale = 1) { if (FBackColor == HC.HCTransparentColor) { aCanvas.Brush.Style = HCBrushStyle.bsClear; } else { aCanvas.Brush.Color = FBackColor; } aCanvas.Font.BeginUpdate(); try { aCanvas.Font.Color = FColor; aCanvas.Font.Family = FFamily; if ((FFontStyles.Contains((byte)HCFontStyle.tsSuperscript)) || (FFontStyles.Contains((byte)HCFontStyle.tsSubscript))) { aCanvas.Font.Size = FSize / 2; } else { aCanvas.Font.Size = FSize; } aCanvas.Font.FontStyles = FFontStyles; } finally { aCanvas.Font.EndUpdate(); } aCanvas.GetTextMetrics(ref FTextMetric); FONTSIGNATURE vFontSignature = new FONTSIGNATURE(); FFontHeight = aCanvas.TextHeight("H"); if ((GDI.GetTextCharsetInfo(aCanvas.Handle, ref vFontSignature, 0) != GDI.DEFAULT_CHARSET) && ((vFontSignature.fsCsb[0] & CJK_CODEPAGE_BITS) != 0)) { FCJKFont = true; } else { FCJKFont = false; } if (FOutMetSize > 0) { Marshal.FreeHGlobal(FOutlineTextmetricPtr); } FOutMetSize = GDI.GetOutlineTextMetrics(aCanvas.Handle, 0, IntPtr.Zero); if (FOutMetSize != 0) { //FOutMetSize = (uint)Marshal.SizeOf(FOutlineTextmetric); FOutlineTextmetricPtr = Marshal.AllocHGlobal((int)FOutMetSize); if (GDI.GetOutlineTextMetrics(aCanvas.Handle, FOutMetSize, FOutlineTextmetricPtr) != 0) { //FOutlineTextmetric = new OUTLINETEXTMETRICW(); //FOutlineTextmetric = (OUTLINETEXTMETRICW)Marshal.PtrToStructure(FOutlineTextmetricPtr, typeof(OUTLINETEXTMETRICW)); //string otmpFamilyName = Marshal.PtrToStringUni(new IntPtr((int)FOutlineTextmetricPtr + (int)FOutlineTextmetric.otmpFamilyName)); //string otmpFaceName = Marshal.PtrToStringUni(new IntPtr((int)FOutlineTextmetricPtr + (int)FOutlineTextmetric.otmpFaceName)); ; //string otmpStyleName = Marshal.PtrToStringUni(new IntPtr((int)FOutlineTextmetricPtr + (int)FOutlineTextmetric.otmpStyleName)); ; //string otmpFullName = Marshal.PtrToStringUni(new IntPtr((int)FOutlineTextmetricPtr + (int)FOutlineTextmetric.otmpFullName)); ; // 以上为参考代码 //Marshal.PtrToStructure(FOutlineTextmetricPtr, FOutlineTextmetric); FOutlineTextmetric = (OUTLINETEXTMETRICW)Marshal.PtrToStructure(FOutlineTextmetricPtr, typeof(OUTLINETEXTMETRICW)); } } if ((uint)GDI.GetFontData(aCanvas.Handle, MS_HHEA_TAG, 0, ref FFontHeader, Marshal.SizeOf(FFontHeader)) == GDI.GDI_ERROR) { return; } }
public void GetTextMetrics(ref TEXTMETRICW aTextMetric) { GDI.GetTextMetrics(FHandle, ref aTextMetric); }
/// <summary> /// Загрузка IImage из файла /// </summary> /// <param name="file"></param> /// <param name="image"></param> /// <param name="imageSize"></param> public static void LoadImageFromFile(string file, out GDI.IImage image, out Size imageSize) { GDI.ImageInfo newImageInfo; ImagingFactory.CreateImageFromFile(file, out image); image.GetImageInfo(out newImageInfo); imageSize = new Size((int)newImageInfo.Width, (int)newImageInfo.Height); }
public void GetTextExtentExPoint(string aText, int aLen, int[] alpDx, ref SIZE aSize) // 超过65535数组元素取不到值 { GDI.GetTextExtentExPoint(FHandle, aText, aLen, 0, IntPtr.Zero, alpDx, ref aSize); }
/// <summary> /// Загрузка IImage из файла в память (без привязки к файлу) /// </summary> /// <param name="file"></param> /// <param name="image"></param> public static void LoadImageFromFileIntoMemory(string file, out GDI.IImage image) { FileStream newFileStream = new FileStream(file, FileMode.Open); MemoryStream newMemoryStream = new MemoryStream((int)newFileStream.Length); CopyStream(newFileStream, newMemoryStream); byte[] buffer = newMemoryStream.GetBuffer(); IntPtr bytes = Marshal.AllocHGlobal(buffer.Length); Marshal.Copy(buffer, 0, bytes, buffer.Length); ImagingFactory.CreateImageFromBuffer(bytes, (uint)buffer.Length, GDI.BufferDisposalFlag.BufferDisposalFlagGlobalFree, out image); newFileStream.Close(); }
public void RoundRect(RECT aRect, int x, int y) { GDI.RoundRect(FHandle, aRect.Left, aRect.Top, aRect.Right, aRect.Bottom, x, y); }
public static void Bar(PlotDimensions dims, Bitmap bmp, bool lowQuality, Population pop, Random rand, double popLeft, double popWidth, Color color, Position position, bool useStdErr = false) { // adjust edges to accomodate special positions if (position == Position.Hide) { return; } if (position == Position.Left || position == Position.Right) { popWidth /= 2; } if (position == Position.Right) { popLeft += popWidth; } // determine the center point and calculate bounds double centerX = popLeft + popWidth / 2; double xPx = dims.GetPixelX(centerX); double yPxTop = dims.GetPixelY(pop.mean); double yPxBase = dims.GetPixelY(0); double errorMaxPx, errorMinPx; if (useStdErr) { errorMaxPx = dims.GetPixelY(pop.mean + pop.stdErr); errorMinPx = dims.GetPixelY(pop.mean - pop.stdErr); } else { errorMaxPx = dims.GetPixelY(pop.mean + pop.stDev); errorMinPx = dims.GetPixelY(pop.mean - pop.stDev); } // make cap width a fraction of available space double capWidthFrac = .38; double capWidth = popWidth * capWidthFrac; double capPx1 = dims.GetPixelX(centerX - capWidth / 2); double capPx2 = dims.GetPixelX(centerX + capWidth / 2); // contract edges slightly to encourage padding between elements double edgePaddingFrac = 0.2; popLeft += popWidth * edgePaddingFrac; popWidth -= (popWidth * edgePaddingFrac) * 2; double leftPx = dims.GetPixelX(popLeft); double rightPx = dims.GetPixelX(popLeft + popWidth); RectangleF rect = new RectangleF((float)leftPx, (float)yPxTop, (float)(rightPx - leftPx), (float)(yPxBase - yPxTop)); using (Graphics gfx = GDI.Graphics(bmp, dims, lowQuality)) using (Pen pen = GDI.Pen(Color.Black)) using (Brush brush = GDI.Brush(color)) { gfx.FillRectangle(brush, rect.X, rect.Y, rect.Width, rect.Height); gfx.DrawRectangle(pen, rect.X, rect.Y, rect.Width, rect.Height); gfx.DrawLine(pen, (float)xPx, (float)errorMinPx, (float)xPx, (float)errorMaxPx); gfx.DrawLine(pen, (float)capPx1, (float)errorMinPx, (float)capPx2, (float)errorMinPx); gfx.DrawLine(pen, (float)capPx1, (float)errorMaxPx, (float)capPx2, (float)errorMaxPx); } }
public void MoveTo(int x, int y) { GDI.MoveToEx(FHandle, x, y, IntPtr.Zero); }
private void RenderOnBitmap(Graphics gfx, LegendItem[] items, System.Drawing.Font font, float locationX, float locationY, float width, float height, float maxLabelHeight, bool shadow = true, bool outline = true) { using (var fillBrush = new SolidBrush(FillColor)) using (var shadowBrush = new SolidBrush(ShadowColor)) using (var textBrush = new SolidBrush(Font.Color)) using (var outlinePen = new Pen(OutlineColor)) { if (AntiAlias) { gfx.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; gfx.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias; } RectangleF rectShadow = new RectangleF(locationX + ShadowOffsetX, locationY + ShadowOffsetY, width, height); RectangleF rectFill = new RectangleF(locationX, locationY, width, height); if (shadow) { gfx.FillRectangle(shadowBrush, rectShadow); } gfx.FillRectangle(fillBrush, rectFill); if (outline) { gfx.DrawRectangle(outlinePen, Rectangle.Round(rectFill)); } for (int i = 0; i < items.Length; i++) { var item = items[i]; float verticalOffset = i * maxLabelHeight; // draw text gfx.DrawString(item.label, font, textBrush, locationX + SymbolWidth, locationY + verticalOffset); // prepare values for drawing a line outlinePen.Color = item.color; outlinePen.Width = 1; float lineY = locationY + verticalOffset + maxLabelHeight / 2; float lineX1 = locationX + SymbolPad; float lineX2 = lineX1 + SymbolWidth - SymbolPad * 2; // prepare values for drawing a rectangle PointF rectOrigin = new PointF(lineX1, (float)(lineY - item.lineWidth / 2)); SizeF rectSize = new SizeF(lineX2 - lineX1, (float)item.lineWidth); RectangleF rect = new RectangleF(rectOrigin, rectSize); if (item.IsRectangle) { // draw a rectangle using (var legendItemFillBrush = GDI.Brush(item.color, item.hatchColor, item.hatchStyle)) using (var legendItemOutlinePen = new Pen(item.borderColor, item.borderWith)) { gfx.FillRectangle(legendItemFillBrush, rect); gfx.DrawRectangle(legendItemOutlinePen, rect.X, rect.Y, rect.Width, rect.Height); } } else { // draw a line using (var linePen = GDI.Pen(item.color, item.lineWidth, item.lineStyle, false)) gfx.DrawLine(linePen, lineX1, lineY, lineX2, lineY); // and perhaps a marker in the middle of the line float lineXcenter = (lineX1 + lineX2) / 2; PointF markerPoint = new PointF(lineXcenter, lineY); if ((item.markerShape != MarkerShape.none) && (item.markerSize > 0)) { MarkerTools.DrawMarker(gfx, markerPoint, item.markerShape, MarkerWidth, item.color); } } } } }
public void LineTo(int x, int y) { GDI.LineTo(FHandle, x, y); }
protected override void OnControlAdded(ControlEventArgs e) { GDI.SetControlBackColor(e.Control, Background, false); }
public void TextOut(int x, int y, string text) { GDI.ExtTextOut(FHandle, x, y, FTextFlags, IntPtr.Zero, text, text.Length, IntPtr.Zero); MoveTo(x + TextWidth(text), y); }
public void ApplyStyle(HCCanvas aCanvas, Single aScale = 1) { if (FBackColor == HC.HCTransparentColor) { aCanvas.Brush.Style = HCBrushStyle.bsClear; } else { aCanvas.Brush.Color = FBackColor; } aCanvas.Font.BeginUpdate(); try { aCanvas.Font.Color = FColor; aCanvas.Font.Family = FFamily; if ((FFontStyles.Contains((byte)HCFontStyle.tsSuperscript)) || (FFontStyles.Contains((byte)HCFontStyle.tsSubscript))) { aCanvas.Font.Size = FSize / 2; } else { aCanvas.Font.Size = FSize; } aCanvas.Font.FontStyles.Value = FFontStyles.Value; // 防止后面其他地方修改canva的font时影响到原始的样式数据 } finally { aCanvas.Font.EndUpdate(); } TEXTMETRICW vTextMetric = new TEXTMETRICW(); aCanvas.GetTextMetrics(ref vTextMetric); FTextMetric_tmAveCharWidth = vTextMetric.tmAveCharWidth; FTextMetric_tmExternalLeading = vTextMetric.tmExternalLeading; FTextMetric_tmHeight = vTextMetric.tmHeight; FONTSIGNATURE vFontSignature = new FONTSIGNATURE(); FFontHeight = aCanvas.TextHeight("H"); if ((GDI.GetTextCharsetInfo(aCanvas.Handle, ref vFontSignature, 0) != GDI.DEFAULT_CHARSET) && ((vFontSignature.fsCsb[0] & CJK_CODEPAGE_BITS) != 0)) { FCJKFont = true; } else { FCJKFont = false; } FOutMetSize = GDI.GetOutlineTextMetrics(aCanvas.Handle, 0, IntPtr.Zero); if (FOutMetSize != 0) { //FOutMetSize = (uint)Marshal.SizeOf(FOutlineTextmetric); IntPtr vOutlineTextmetricPtr = Marshal.AllocHGlobal((int)FOutMetSize); try { if (GDI.GetOutlineTextMetrics(aCanvas.Handle, FOutMetSize, vOutlineTextmetricPtr) != 0) { //FOutlineTextmetric = new OUTLINETEXTMETRICW(); //FOutlineTextmetric = (OUTLINETEXTMETRICW)Marshal.PtrToStructure(FOutlineTextmetricPtr, typeof(OUTLINETEXTMETRICW)); //string otmpFamilyName = Marshal.PtrToStringUni(new IntPtr((int)FOutlineTextmetricPtr + (int)FOutlineTextmetric.otmpFamilyName)); //string otmpFaceName = Marshal.PtrToStringUni(new IntPtr((int)FOutlineTextmetricPtr + (int)FOutlineTextmetric.otmpFaceName)); ; //string otmpStyleName = Marshal.PtrToStringUni(new IntPtr((int)FOutlineTextmetricPtr + (int)FOutlineTextmetric.otmpStyleName)); ; //string otmpFullName = Marshal.PtrToStringUni(new IntPtr((int)FOutlineTextmetricPtr + (int)FOutlineTextmetric.otmpFullName)); ; // 以上为参考代码 //Marshal.PtrToStructure(FOutlineTextmetricPtr, FOutlineTextmetric); OUTLINETEXTMETRICW vOutlineTextmetric = (OUTLINETEXTMETRICW)Marshal.PtrToStructure(vOutlineTextmetricPtr, typeof(OUTLINETEXTMETRICW)); FOutlineTextmetric_otmfsSelection = vOutlineTextmetric.otmfsSelection; FOutlineTextmetric_otmAscent = vOutlineTextmetric.otmAscent; FOutlineTextmetric_otmDescent = vOutlineTextmetric.otmDescent; FOutlineTextmetric_otmEMSquare = vOutlineTextmetric.otmEMSquare; } } finally { Marshal.FreeHGlobal(vOutlineTextmetricPtr); } } TT_HHEA vFontHeader = new TT_HHEA(); if ((uint)GDI.GetFontData(aCanvas.Handle, MS_HHEA_TAG, 0, ref vFontHeader, Marshal.SizeOf(vFontHeader)) != GDI.GDI_ERROR) { FFontHeader_Ascender = vFontHeader.Ascender; FFontHeader_Descender = vFontHeader.Descender; } else { FFontHeader_Ascender = 0; FFontHeader_Descender = 0; } }
public void Rectangle(int aLeft, int aTop, int aRight, int aBottom) { GDI.Rectangle(FHandle, aLeft, aTop, aRight, aBottom); }