private void PaintBehindWindow(IDeviceContext destDc, Rectangle screenBounds) { if (!DesktopWindowManager.IsAeroEnabled()) { TopLevelWindow desktopWindow = TopLevelWindow.DesktopWindow; IntPtr desktopDc = desktopWindow.GetHdc(); NativeMethods.BitBlt(destDc.GetHdc(), 0, 0, screenBounds.Width, screenBounds.Height, desktopDc, screenBounds.X, screenBounds.Y, CopyPixelOperation.SourceCopy); desktopWindow.ReleaseHdc(); return; } IntPtr dc = destDc.GetHdc(); for (int index = _visisbleWindows.Count - 1; index > -1; index--) { var window = _visisbleWindows[index]; if (window.Handle == ExcludeWindowBehindBlur) { continue; } Rectangle windowBounds = window.Bounds; var inter = Rectangle.Intersect(screenBounds, windowBounds); if (inter == Rectangle.Empty) { continue; } var localPoint = inter.Location; NativeMethods.ScreenToClient(window.Handle, ref localPoint); var myLocalPoint = new Point(Math.Abs(screenBounds.X - inter.X), Math.Abs(screenBounds.Y - inter.Y)); IntPtr windowDc = window.GetHdc(); if (index == _visisbleWindows.Count - 2) { NativeMethods.AlphaBlend(dc, myLocalPoint.X, myLocalPoint.Y, inter.Width, inter.Height, windowDc, localPoint.X, localPoint.Y, inter.Width, inter.Height, BlendFunction.Default); } else { NativeMethods.BitBlt(dc, myLocalPoint.X, myLocalPoint.Y, inter.Width, inter.Height, windowDc, localPoint.X, localPoint.Y, CopyPixelOperation.SourceCopy); } window.ReleaseHdc(); } destDc.ReleaseHdc(); }
public int UxThemeGetThemeTextMetrics(IntPtr hTheme, IDeviceContext dc, int iPartId, int iStateId, out TextMetrics result) { XplatUIWin32.TEXTMETRIC metrics; int hresult = UXTheme.GetThemeTextMetrics(hTheme, dc.GetHdc(), iPartId, iStateId, out metrics); dc.ReleaseHdc(); TextMetrics retval = new TextMetrics(); retval.Ascent = metrics.tmAscent; retval.AverageCharWidth = metrics.tmAveCharWidth; retval.BreakChar = (char)metrics.tmBreakChar; retval.CharSet = (TextMetricsCharacterSet)metrics.tmCharSet; retval.DefaultChar = (char)metrics.tmDefaultChar; retval.Descent = metrics.tmDescent; retval.DigitizedAspectX = metrics.tmDigitizedAspectX; retval.DigitizedAspectY = metrics.tmDigitizedAspectY; retval.ExternalLeading = metrics.tmExternalLeading; retval.FirstChar = (char)metrics.tmFirstChar; retval.Height = metrics.tmHeight; retval.InternalLeading = metrics.tmInternalLeading; retval.Italic = metrics.tmItalic == 0 ? false : true; retval.LastChar = (char)metrics.tmLastChar; retval.MaxCharWidth = metrics.tmMaxCharWidth; retval.Overhang = metrics.tmOverhang; retval.PitchAndFamily = (TextMetricsPitchAndFamilyValues)metrics.tmPitchAndFamily; retval.StruckOut = metrics.tmStruckOut == 0 ? false : true; retval.Underlined = metrics.tmUnderlined == 0 ? false : true; retval.Weight = metrics.tmWeight; result = retval; return(hresult); }
private Padding GetThemeMargins(IDeviceContext dc, MarginProperty marginType) { NativeMethods.MARGINS margins; try { var hDC = dc.GetHdc(); var rv = NativeMethods.GetThemeMargins( renderer.Handle, hDC, renderer.Part, renderer.State, (int)marginType, IntPtr.Zero, out margins); if (rv == 0) { return(new Padding( margins.cxLeftWidth, margins.cyTopHeight, margins.cxRightWidth, margins.cyBottomHeight)); } return(new Padding(0)); } catch (Exception) { return(renderer.GetMargins(dc, marginType)); } finally { dc.ReleaseHdc(); } }
public void DrawText(IDeviceContext dc, string text, Rectangle bounds, Color foreColor) { if (string.IsNullOrEmpty(text)) { return; } if (dc == null) { throw new ArgumentNullException("dc"); } IntPtr hDc = dc.GetHdc(); try { int clr = ColorTranslator.ToWin32(foreColor); RECT rect = new RECT(bounds); NativeMethods.DrawAlphaTextRect(hDc, text, hFont, clr, ref rect, 0); } finally { dc.ReleaseHdc(); } }
/*** CURENTLY NOT USED ***/ public static void RenderText(IDeviceContext hdc, string text, string fontFamily, Color color, Rectangle region, float size) { // create the handle of DC var h = new HandleRef(null, hdc.GetHdc()); // create the font int emsize = -gdiNative.MulDiv((int)size, gdiNative.GetDeviceCaps(h, gdiNative.LOGPIXELSY), 72); var p = new HandleRef(null, gdiNative.CreateFont(emsize, 0, 0, 0, 0, 0, 0, 0, 1 /*Ansi_encoding*/, 0, 0, 4, 0, fontFamily)); try { // use the font in the DC gdiNative.SelectObject(h, p.Handle); // set the background to transparent gdiNative.SetBkMode(h, 1); // set the color of the text gdiNative.SetTextColor(h, color); // draw the text to the region gdiNative.DrawText(h, text, region, 0x0100); } finally { // release the resources gdiNative.DeleteObject(p); hdc.ReleaseHdc( ); } }
public void DrawBlurFromScreen(Action <IDeviceContext, Rectangle> sourcePainterFunc, IDeviceContext destImage, Rectangle screenBounds, Point destLocation, int blurStrength) { if (screenBounds.Size.Width < 1 || screenBounds.Size.Height < 1) { return; } try { Rectangle srcRect = new Rectangle(Point.Empty, screenBounds.Size); Rectangle distRect = new Rectangle(0, 0, srcRect.Width / blurStrength, srcRect.Height / blurStrength); using (GraphicsImage stretchImage = new GraphicsImage(srcRect.Size)) { using (GraphicsImage shrinkImage = new GraphicsImage(distRect.Size)) { sourcePainterFunc(shrinkImage.Graphics, screenBounds); shrinkImage.Graphics.ReleaseHdc(); shrinkImage.Graphics.DrawImage(stretchImage.Image, distRect, srcRect, GraphicsUnit.Pixel); srcRect.Location = destLocation; Graphics g = Graphics.FromHdc(destImage.GetHdc()); g.DrawImage(shrinkImage.Image, srcRect, distRect, GraphicsUnit.Pixel); g.Dispose(); destImage.ReleaseHdc(); } } } catch { } }
public void DrawBlurFromScreen(Action <IDeviceContext, Rectangle> sourcePainterFunc, IDeviceContext destImage, Rectangle screenBounds, Point destLocation, int blurStrength) { if (screenBounds.Size.Width < 1 || screenBounds.Size.Height < 1) { return; } try { using (var blurImage = new Bitmap(screenBounds.Width, screenBounds.Height)) { using (var blurImageGraphics = Graphics.FromImage(blurImage)) { sourcePainterFunc(blurImageGraphics, screenBounds); } ImageTools.FastBlur(blurImage, blurStrength); using (Graphics destGraphics = Graphics.FromHdc(destImage.GetHdc())) { destGraphics.DrawImage(blurImage, new Rectangle(destLocation, screenBounds.Size), new Rectangle(Point.Empty, screenBounds.Size), GraphicsUnit.Pixel); } } } catch { } }
private static void RenderText(IDeviceContext hdc, string text, string fontFamily, Color color, Rectangle region, int size) { // create the handle of DC HandleRef h = new HandleRef(null, hdc.GetHdc()); // create the font HandleRef p = new HandleRef(null, NativeMethods.CreateFont (size, 0, 0, 0, 0, 0, 0, 0, 1 /*Ansi_encoding*/, 0, 0, 4, 0, fontFamily)); try { // use the font in the DC NativeMethods.SelectObject((IntPtr)h, p.Handle); // set the background to transparent NativeMethods.SetBkMode((IntPtr)h, 1); // set the color of the text NativeMethods.SetTextColor((IntPtr)h, ColorTranslator.ToWin32(color)); // draw the text to the region NativeMethods.DrawText(h, text, region, 0x0100); } finally { // release the resources NativeMethods.DeleteObject((IntPtr)p); hdc.ReleaseHdc(); } }
internal static void DrawText(string text, IDeviceContext destImage, Point location, Size size, byte opacity, SolidBrush textColorBrush, StringFormat stringFormat, Font font) { GraphicsImage textBuffer = new GraphicsImage(size.Width, size.Height); Rectangle drawBounds = new Rectangle(Point.Empty, size); SolidBrush brush = textColorBrush; Color oldColor = brush.Color; if (opacity != 255 && opacity < oldColor.A) { brush.Color = Color.FromArgb(opacity, brush.Color); } textBuffer.Graphics.DrawString(text, font, brush, drawBounds, stringFormat); drawBounds.Location = location; Graphics g = Graphics.FromHdc(destImage.GetHdc()); g.DrawImage(textBuffer.Image, drawBounds); g.Dispose(); destImage.ReleaseHdc(); brush.Color = oldColor; textBuffer.Dispose(); }
private Padding GetMargins(IDeviceContext ctxt, MarginProperty type, IntPtr hTheme, int iPartId, int iStateId) { int iPropId = 0; switch (type) { case MarginProperty.CaptionMargins: iPropId = 3603; break; case MarginProperty.SizingMargins: iPropId = 3601; break; case MarginProperty.ContentMargins: iPropId = 3602; break; } MARGINS margins; GetThemeMargins(hTheme, ctxt.GetHdc(), iPartId, iStateId, iPropId, IntPtr.Zero, out margins); ctxt.ReleaseHdc(); Padding padding = new Padding(); padding.Left = margins.Left; padding.Right = margins.Right; padding.Top = margins.Top; padding.Bottom = margins.Bottom; return(padding); }
public void DrawText(IDeviceContext dc, string text, Rectangle bounds, TextFormatFlags flags) { if (string.IsNullOrEmpty(text)) { return; } if (dc == null) { throw new ArgumentNullException("dc"); } IntPtr hDc = dc.GetHdc(); try { int param = GetIntTextFormatFlags(flags); RECT rect = new RECT(bounds); NativeMethods.DrawAlphaTextRect(hDc, text, hFont, Win32Color, ref rect, param); } finally { dc.ReleaseHdc(); } }
public void DirectDraw(IDeviceContext dc, string text, Point pt, Color foreColor, Color backColor) { if (string.IsNullOrEmpty(text)) { return; } if (dc == null) { throw new ArgumentNullException("dc"); } IntPtr hDc = dc.GetHdc(); try { int clr = ColorTranslator.ToWin32(foreColor); int back = ColorTranslator.ToWin32(backColor); NativeMethods.DrawTextDirectEx(hDc, text, hFont, clr, back, pt.X, pt.Y); } finally { dc.ReleaseHdc(); } }
public int UxThemeDrawThemeBackground (IntPtr hTheme, IDeviceContext dc, int iPartId, int iStateId, Rectangle bounds) { XplatUIWin32.RECT BoundsRect = XplatUIWin32.RECT.FromRectangle (bounds); int result = UXTheme.DrawThemeBackground(hTheme, dc.GetHdc (), iPartId, iStateId, ref BoundsRect, IntPtr.Zero); dc.ReleaseHdc (); return result; }
public int UxThemeDrawThemeText (IntPtr hTheme, IDeviceContext dc, int iPartId, int iStateId, string text, TextFormatFlags textFlags, Rectangle bounds) { XplatUIWin32.RECT BoundsRect = XplatUIWin32.RECT.FromRectangle (bounds); int result = UXTheme.DrawThemeText (hTheme, dc.GetHdc (), iPartId, iStateId, text, text.Length, (uint)textFlags, 0, ref BoundsRect); dc.ReleaseHdc (); return result; }
public SafeGDIHandle(IDeviceContext dc) : base(IntPtr.Zero, true) { if (dc != null) { idc = dc; base.SetHandle(idc.GetHdc()); } }
public int UxThemeDrawThemeBackground(IntPtr hTheme, IDeviceContext dc, int iPartId, int iStateId, Rectangle_ bounds) { XplatUIWin32.RECT BoundsRect = XplatUIWin32.RECT.FromRectangle(bounds); int result = UXTheme.DrawThemeBackground(hTheme, dc.GetHdc(), iPartId, iStateId, ref BoundsRect, IntPtr.Zero); dc.ReleaseHdc(); return(result); }
private Padding GetThemeMargins(IDeviceContext dc, MarginTypes marginType) { try { var ok = NativeMethods.GetThemeMargins(_renderer.Handle, dc.GetHdc(), _renderer.Part, _renderer.State, (int)marginType, IntPtr.Zero, out var margins) == 0; return(!ok ? new Padding(0) : new Padding(margins.cxLeftWidth, margins.cyTopHeight, margins.cxRightWidth, margins.cyBottomHeight)); } finally { dc.ReleaseHdc(); } }
/// <summary>Initializes a new instance of the <see cref="SafeDCHandle"/> class.</summary> /// <param name="dc">An <see cref="IDeviceContext"/> instance.</param> public SafeDCHandle(IDeviceContext dc) : base(true) { if (dc == null) { return; } idc = dc; SetHandle(dc.GetHdc()); }
public int UxThemeDrawThemeText(IntPtr hTheme, IDeviceContext dc, int iPartId, int iStateId, string text, TextFormatFlags textFlags, Rectangle_ bounds) { XplatUIWin32.RECT BoundsRect = XplatUIWin32.RECT.FromRectangle(bounds); int result = UXTheme.DrawThemeText(hTheme, dc.GetHdc(), iPartId, iStateId, text, text.Length, (uint)textFlags, 0, ref BoundsRect); dc.ReleaseHdc(); return(result); }
/// <summary>Initializes a new instance of the <see cref="SafeHDC"/> class.</summary> /// <param name="dc">An <see cref="IDeviceContext"/> instance.</param> public SafeHDC(IDeviceContext dc) : base(IntPtr.Zero) { if (dc == null) { return; } idc = dc; SetHandle(dc.GetHdc()); }
/// <summary> /// Draws composited text onto the glass area of a form. /// </summary> /// <param name="dc">The <see cref="IDeviceContext" /> onto which the composited text should be drawn.</param> /// <param name="text">The text to draw.</param> /// <param name="font">The <see cref="Font" /> to apply to the drawn text.</param> /// <param name="bounds">The <see cref="Rectangle" /> that represents the bounds of the text.</param> /// <param name="padding">The <see cref="Padding" /> around the text; necessary to allow space for the glow effect.</param> /// <param name="foreColor">The <see cref="Color" /> to apply to the drawn text.</param> /// <param name="textFormat">A bitwise combination of the <see cref="TextFormatFlags" /> values.</param> /// <param name="glowSize">Specifies the size of a glow that will be drawn on the background prior to any text being drawn.</param> /// <remarks> /// <para> /// Do not use this method to draw text on non-glass areas of a form. /// </para> /// </remarks> /// <exception cref="NotSupportedException"> /// The current operating system does not support glass, or the Desktop Window /// Manager is not enabled. /// </exception> /// <exception cref="ArgumentNullException"> /// <paramref name="dc" />, <paramref name="text" /> or <paramref name="font" /> is /// <see langword="null" />. /// </exception> public static void DrawCompositedText(IDeviceContext dc, string text, Font font, Rectangle bounds, Padding padding, Color foreColor, int glowSize, TextFormatFlags textFormat) { if (!IsDwmCompositionEnabled) { throw new NotSupportedException(Resources.GlassNotSupportedError); } if (dc == null) { throw new ArgumentNullException("dc"); } if (text == null) { throw new ArgumentNullException("text"); } if (font == null) { throw new ArgumentNullException("font"); } var primaryHdc = dc.GetHdc(); try { using (var memoryHdc = NativeMethods.CreateCompatibleDC(primaryHdc)) using (var fontHandle = new SafeGDIHandle(font.ToHfont(), true)) using (var dib = NativeMethods.CreateDib(bounds, primaryHdc, memoryHdc)) { NativeMethods.SelectObject(memoryHdc, fontHandle); // Draw glowing text var renderer = new VisualStyleRenderer(VisualStyleElement.Window.Caption.Active); var dttOpts = new NativeMethods.DTTOPTS(); dttOpts.dwSize = Marshal.SizeOf(typeof(NativeMethods.DTTOPTS)); dttOpts.dwFlags = NativeMethods.DrawThemeTextFlags.Composited | NativeMethods.DrawThemeTextFlags.GlowSize | NativeMethods.DrawThemeTextFlags.TextColor; dttOpts.crText = ColorTranslator.ToWin32(foreColor); dttOpts.iGlowSize = glowSize; var textBounds = new NativeMethods.RECT(padding.Left, padding.Top, bounds.Width - padding.Right, bounds.Height - padding.Bottom); NativeMethods.DrawThemeTextEx(renderer.Handle, memoryHdc, 0, 0, text, text.Length, (int)textFormat, ref textBounds, ref dttOpts); // Copy to foreground const int SRCCOPY = 0x00CC0020; NativeMethods.BitBlt(primaryHdc, bounds.Left, bounds.Top, bounds.Width, bounds.Height, memoryHdc, 0, 0, SRCCOPY); } } finally { dc.ReleaseHdc(); } }
public int UxThemeDrawThemeEdge (IntPtr hTheme, IDeviceContext dc, int iPartId, int iStateId, Rectangle bounds, Edges edges, EdgeStyle style, EdgeEffects effects, out Rectangle result) { XplatUIWin32.RECT BoundsRect = XplatUIWin32.RECT.FromRectangle (bounds); XplatUIWin32.RECT retval; int hresult = UXTheme.DrawThemeEdge (hTheme, dc.GetHdc (), iPartId, iStateId, ref BoundsRect, (uint)style, (uint)edges + (uint)effects, out retval); dc.ReleaseHdc (); result = retval.ToRectangle(); return hresult; }
/// <summary> /// Initializes a new instance of the <see cref="SafeDCHandle"/> class. /// </summary> /// <param name="dc">An <see cref="IDeviceContext"/> instance.</param> public SafeDCHandle(IDeviceContext dc) : base(IntPtr.Zero, true) { if (dc == null) { throw new ArgumentNullException(nameof(dc)); } idc = dc; SetHandle(dc.GetHdc()); }
public int UxThemeDrawThemeEdge(IntPtr hTheme, IDeviceContext dc, int iPartId, int iStateId, Rectangle_ bounds, Edges edges, EdgeStyle style, EdgeEffects effects, out Rectangle_ result) { XplatUIWin32.RECT BoundsRect = XplatUIWin32.RECT.FromRectangle(bounds); XplatUIWin32.RECT retval; int hresult = UXTheme.DrawThemeEdge(hTheme, dc.GetHdc(), iPartId, iStateId, ref BoundsRect, (uint)style, (uint)edges + (uint)effects, out retval); dc.ReleaseHdc(); result = retval.ToRectangle(); return(hresult); }
public int UxThemeGetThemeTextExtent(IntPtr hTheme, IDeviceContext dc, int iPartId, int iStateId, string textToDraw, TextFormatFlags flags, out Rectangle_ result) { XplatUIWin32.RECT retval; int hresult = UXTheme.GetThemeTextExtent(hTheme, dc.GetHdc(), iPartId, iStateId, textToDraw, textToDraw.Length, (int)flags, 0, out retval); dc.ReleaseHdc(); result = retval.ToRectangle(); return(hresult); }
public int UxThemeGetThemePartSize(IntPtr hTheme, IDeviceContext dc, int iPartId, int iStateId, ThemeSizeType type, out Size_ result) { UXTheme.SIZE retval; int hresult = UXTheme.GetThemePartSize(hTheme, dc.GetHdc(), iPartId, iStateId, IntPtr.Zero, (int)type, out retval); dc.ReleaseHdc(); result = retval.ToSize(); return(hresult); }
public int UxThemeGetThemeBackgroundContentRect(IntPtr hTheme, IDeviceContext dc, int iPartId, int iStateId, Rectangle_ bounds, out Rectangle_ result) { XplatUIWin32.RECT BoundsRect = XplatUIWin32.RECT.FromRectangle(bounds); XplatUIWin32.RECT retval; int hresult = UXTheme.GetThemeBackgroundContentRect(hTheme, dc.GetHdc(), iPartId, iStateId, ref BoundsRect, out retval); dc.ReleaseHdc(); result = retval.ToRectangle(); return(hresult); }
public int UxThemeGetThemeBackgroundRegion(IntPtr hTheme, IDeviceContext dc, int iPartId, int iStateId, Rectangle bounds, out Region result) { XplatUIWin32.RECT BoundsRect = XplatUIWin32.RECT.FromRectangle(bounds); IntPtr retval; int hresult = UXTheme.GetThemeBackgroundRegion(hTheme, dc.GetHdc(), iPartId, iStateId, ref BoundsRect, out retval); dc.ReleaseHdc(); result = Region.FromHrgn(retval); return(hresult); }
public static void DrawText(IDeviceContext dc, String text, Rectangle bounds, TextFormatFlags format) { try { var options = new DTTOPTS(); NativeMethods.DrawThemeTextEx(Renderer.Handle, dc.GetHdc(), 0, 0, text, text.Length, format, RECT.FromRectangle(bounds), options); } finally { dc.ReleaseHdc(); } }
public int UxThemeGetThemePartSize(IntPtr hTheme, IDeviceContext dc, int iPartId, int iStateId, Rectangle_ bounds, ThemeSizeType type, out Size_ result) { XplatUIWin32.RECT BoundsRect = XplatUIWin32.RECT.FromRectangle(bounds); UXTheme.SIZE retval; int hresult = UXTheme.GetThemePartSize(hTheme, dc.GetHdc(), iPartId, iStateId, ref BoundsRect, (int)type, out retval); dc.ReleaseHdc(); result = retval.ToSize(); return(hresult); }
public int UxThemeHitTestThemeBackground(IntPtr hTheme, IDeviceContext dc, int iPartId, int iStateId, HitTestOptions options, Rectangle_ backgroundRectangle, IntPtr hrgn, Point_ pt, out HitTestCode result) { XplatUIWin32.RECT BoundsRect = XplatUIWin32.RECT.FromRectangle(backgroundRectangle); HitTestCode retval; int hresult = UXTheme.HitTestThemeBackground(hTheme, dc.GetHdc(), iPartId, iStateId, (uint)options, ref BoundsRect, hrgn, new POINT(pt.X, pt.Y), out retval); dc.ReleaseHdc(); result = (HitTestCode)retval; return(hresult); }
public int UxThemeGetThemeMargins(IntPtr hTheme, IDeviceContext dc, int iPartId, int iStateId, MarginProperty prop, out Padding result) { UXTheme.MARGINS retval = new UXTheme.MARGINS(); XplatUIWin32.RECT BoundsRect; int hresult = UXTheme.GetThemeMargins(hTheme, dc.GetHdc(), iPartId, iStateId, (int)prop, out BoundsRect, out retval); dc.ReleaseHdc(); result = retval.ToPadding(); return(hresult); }
public void VisualStyleRendererDrawBackgroundExcludingArea(IntPtr theme, IDeviceContext dc, int part, int state, Rectangle_ bounds, Rectangle_ excludedArea) { XplatUIWin32.RECT bounds_rect = XplatUIWin32.RECT.FromRectangle(bounds); IntPtr hdc = dc.GetHdc(); XplatUIWin32.Win32ExcludeClipRect(hdc, excludedArea.Left, excludedArea.Top, excludedArea.Right, excludedArea.Bottom); UXTheme.DrawThemeBackground(theme, hdc, part, state, ref bounds_rect, IntPtr.Zero); IntPtr hrgn = XplatUIWin32.Win32CreateRectRgn(excludedArea.Left, excludedArea.Top, excludedArea.Right, excludedArea.Bottom); XplatUIWin32.Win32ExtSelectClipRgn(hdc, hrgn, (int)ClipCombineMode.RGN_OR); XplatUIWin32.Win32DeleteObject(hrgn); dc.ReleaseHdc(); }
Padding GetThemeMargins(IDeviceContext dc, MarginTypes marginType) { NativeMethods.Margins margins; try { IntPtr hDc = dc.GetHdc(); if (NativeMethods.GetThemeMargins(Renderer.Handle, hDc, Renderer.Part, Renderer.State, (int)marginType, IntPtr.Zero, out margins) == 0) { return new Padding(margins.cxLeftWidth, margins.cyTopHeight, margins.cxRightWidth, margins.cyBottomHeight); } return new Padding(0); } finally { dc.ReleaseHdc(); } }
public int UxThemeGetThemeTextMetrics (IntPtr hTheme, IDeviceContext dc, int iPartId, int iStateId, out TextMetrics result) { XplatUIWin32.TEXTMETRIC metrics; int hresult = UXTheme.GetThemeTextMetrics (hTheme, dc.GetHdc (), iPartId, iStateId, out metrics); dc.ReleaseHdc (); TextMetrics retval = new TextMetrics (); retval.Ascent = metrics.tmAscent; retval.AverageCharWidth = metrics.tmAveCharWidth; retval.BreakChar =(char)metrics.tmBreakChar; retval.CharSet = (TextMetricsCharacterSet)metrics.tmCharSet; retval.DefaultChar = (char)metrics.tmDefaultChar; retval.Descent = metrics.tmDescent; retval.DigitizedAspectX = metrics.tmDigitizedAspectX; retval.DigitizedAspectY = metrics.tmDigitizedAspectY; retval.ExternalLeading = metrics.tmExternalLeading; retval.FirstChar = (char)metrics.tmFirstChar; retval.Height = metrics.tmHeight; retval.InternalLeading = metrics.tmInternalLeading; retval.Italic = metrics.tmItalic == 0 ? false : true; retval.LastChar = (char)metrics.tmLastChar; retval.MaxCharWidth = metrics.tmMaxCharWidth; retval.Overhang = metrics.tmOverhang; retval.PitchAndFamily = (TextMetricsPitchAndFamilyValues)metrics.tmPitchAndFamily; retval.StruckOut = metrics.tmStruckOut == 0 ? false : true; retval.Underlined = metrics.tmUnderlined == 0 ? false : true; retval.Weight = metrics.tmWeight; result = retval; return hresult; }
public GraphicsHDC(IDeviceContext graphics) { this.graphics = graphics; this.h = graphics.GetHdc(); }
public int UxThemeGetThemeMargins (IntPtr hTheme, IDeviceContext dc, int iPartId, int iStateId, MarginProperty prop, out Padding result) { UXTheme.MARGINS retval = new UXTheme.MARGINS (); XplatUIWin32.RECT BoundsRect; int hresult = UXTheme.GetThemeMargins (hTheme, dc.GetHdc (), iPartId, iStateId, (int)prop, out BoundsRect, out retval); dc.ReleaseHdc (); result = retval.ToPadding(); return hresult; }
public int UxThemeGetThemePartSize (IntPtr hTheme, IDeviceContext dc, int iPartId, int iStateId, Rectangle bounds, ThemeSizeType type, out Size result) { XplatUIWin32.RECT BoundsRect = XplatUIWin32.RECT.FromRectangle (bounds); UXTheme.SIZE retval; int hresult = UXTheme.GetThemePartSize (hTheme, dc.GetHdc (), iPartId, iStateId, ref BoundsRect, (int)type, out retval); dc.ReleaseHdc (); result = retval.ToSize(); return hresult; }
public int UxThemeGetThemePartSize (IntPtr hTheme, IDeviceContext dc, int iPartId, int iStateId, ThemeSizeType type, out Size result) { UXTheme.SIZE retval; int hresult = UXTheme.GetThemePartSize (hTheme, dc.GetHdc (), iPartId, iStateId, IntPtr.Zero, (int)type, out retval); dc.ReleaseHdc (); result = retval.ToSize (); return hresult; }
public int UxThemeGetThemeTextExtent (IntPtr hTheme, IDeviceContext dc, int iPartId, int iStateId, string textToDraw, TextFormatFlags flags, out Rectangle result) { XplatUIWin32.RECT retval; int hresult = UXTheme.GetThemeTextExtent (hTheme, dc.GetHdc (), iPartId, iStateId, textToDraw, textToDraw.Length, (int)flags, 0, out retval); dc.ReleaseHdc (); result = retval.ToRectangle (); return hresult; }
public void VisualStyleRendererDrawBackgroundExcludingArea (IntPtr theme, IDeviceContext dc, int part, int state, Rectangle bounds, Rectangle excludedArea) { XplatUIWin32.RECT bounds_rect = XplatUIWin32.RECT.FromRectangle (bounds); IntPtr hdc = dc.GetHdc (); XplatUIWin32.Win32ExcludeClipRect (hdc, excludedArea.Left, excludedArea.Top, excludedArea.Right, excludedArea.Bottom); UXTheme.DrawThemeBackground (theme, hdc, part, state, ref bounds_rect, IntPtr.Zero); IntPtr hrgn = XplatUIWin32.Win32CreateRectRgn (excludedArea.Left, excludedArea.Top, excludedArea.Right, excludedArea.Bottom); XplatUIWin32.Win32ExtSelectClipRgn (hdc, hrgn, (int)ClipCombineMode.RGN_OR); XplatUIWin32.Win32DeleteObject (hrgn); dc.ReleaseHdc (); }
public int UxThemeGetThemeBackgroundContentRect (IntPtr hTheme, IDeviceContext dc, int iPartId, int iStateId, Rectangle bounds, out Rectangle result) { XplatUIWin32.RECT BoundsRect = XplatUIWin32.RECT.FromRectangle (bounds); XplatUIWin32.RECT retval; int hresult = UXTheme.GetThemeBackgroundContentRect (hTheme, dc.GetHdc (), iPartId, iStateId, ref BoundsRect, out retval); dc.ReleaseHdc (); result = retval.ToRectangle (); return hresult; }
void Paint (WidgetType widgetType, Rectangle bounds, IDeviceContext dc, TransparencyType transparencyType, Color background, DeviceContextType deviceContextType, Rectangle clippingArea, Painter painter, Rectangle excludedArea) { Rectangle painted_area = Rectangle.Intersect (bounds, clippingArea); if (painted_area.Width == 0 || painted_area.Height == 0) return; painted_area.Offset (-bounds.X, -bounds.Y); excludedArea.Offset (-bounds.X, -bounds.Y); GdkDrawablePointer drawable = gdk_pixmap_new (IntPtr.Zero, bounds.Width, bounds.Height, 24); painter.AttachStyle (widgetType, drawable, this); GdkPixbufPointer pixbuf; IntPtr pixel_data; int rowstride; GdkGCPointer gc = gdk_gc_new (drawable); GdkColor color = new GdkColor (background); gdk_gc_set_rgb_fg_color (gc, ref color); Paint (drawable, gc, bounds, widgetType, out pixbuf, out pixel_data, out rowstride, painted_area, painter, excludedArea); GdkPixbufPointer white_pixbuf = IntPtr.Zero; IntPtr white_pixel_data = IntPtr.Zero; int white_rowstride = 0; GdkColor white_color = new GdkColor(); if (transparencyType == TransparencyType.Alpha) { white_color.red = guint16.MaxValue; white_color.green = guint16.MaxValue; white_color.blue = guint16.MaxValue; gdk_gc_set_rgb_fg_color (gc, ref white_color); Paint (drawable, gc, bounds, widgetType, out white_pixbuf, out white_pixel_data, out white_rowstride, painted_area, painter, excludedArea); } g_object_unref (gc); unsafe { byte* row = (byte*)pixel_data; byte* pixel; byte* white_row = (byte*)white_pixel_data; byte* white_pixel; for (int row_index = 0; row_index < painted_area.Height; row_index++) { pixel = row; white_pixel = white_row; for (int pixel_index = 0; pixel_index < painted_area.Width; pixel_index++) { const int GdkRedOffset = 0; const int GdkGreenOffset = 1; const int GdkBlueOffset = 2; const int BitmapAlphaOffset = 3; const int BitmapRedOffset = 2; const int BitmapBlueOffset = 0; switch (transparencyType) { case TransparencyType.Alpha: pixel [BitmapAlphaOffset] = (byte)(pixel [GdkRedOffset] - white_pixel [GdkRedOffset] + byte.MaxValue); break; case TransparencyType.Color: if ( pixel [GdkRedOffset] == background.R && pixel [GdkGreenOffset] == background.G && pixel [GdkBlueOffset] == background.B) { const int AlphaFullyTransparent = 0; pixel [BitmapAlphaOffset] = AlphaFullyTransparent; } break; } byte temporary = pixel [GdkRedOffset]; pixel [BitmapBlueOffset] = pixel [GdkBlueOffset]; pixel [BitmapRedOffset] = temporary; const int PixelSize = 4; pixel += PixelSize; white_pixel += PixelSize; } row += rowstride; white_row += white_rowstride; } } if (transparencyType == TransparencyType.Alpha) g_object_unref (white_pixbuf); g_object_unref (drawable); Bitmap bitmap = new Bitmap (painted_area.Width, painted_area.Height, rowstride, PixelFormat.Format32bppPArgb, pixel_data); Graphics g; bool graphics_is_from_hdc = false; switch (deviceContextType) { case DeviceContextType.Graphics: g = (Graphics)dc; break; case DeviceContextType.Native: g = Graphics.FromHdc (dc.GetHdc ()); break; default: g = dc as Graphics; if (g == null) { graphics_is_from_hdc = true; g = Graphics.FromHdc (dc.GetHdc ()); } else graphics_is_from_hdc = false; break; } painted_area.Offset (bounds.X, bounds.Y); g.DrawImage (bitmap, painted_area.Location); switch (deviceContextType) { case DeviceContextType.Graphics: break; case DeviceContextType.Native: g.Dispose (); dc.ReleaseHdc (); break; default: if (graphics_is_from_hdc) { g.Dispose (); dc.ReleaseHdc (); } break; } bitmap.Dispose (); g_object_unref (pixbuf); }
public int UxThemeHitTestThemeBackground (IntPtr hTheme, IDeviceContext dc, int iPartId, int iStateId, HitTestOptions options, Rectangle backgroundRectangle, IntPtr hrgn, Point pt, out HitTestCode result) { XplatUIWin32.RECT BoundsRect = XplatUIWin32.RECT.FromRectangle (backgroundRectangle); int retval; int hresult = UXTheme.HitTestThemeBackground (hTheme, dc.GetHdc (), iPartId, iStateId, (uint)options, ref BoundsRect, hrgn, new POINT(pt.X, pt.Y), out retval); dc.ReleaseHdc (); result = (HitTestCode)retval; return hresult; }