Bitmap Graphics Model - Device Context • Windows Does Not Retain a Copy of What the Application Drew • Windows 3.0 (1990)

Bitmap Graphics Model - Device Context • Windows Does Not Retain a Copy of What the Application Drew • Windows 3.0 (1990)

historie 08.11.2018 vjj 1 pravěk INPUT PROGRAM OUTPUT 08.11.2018 vjj 2 evoluce • dávkové zpracování • interaktivní práce • prompt • GUI 08.11.2018 vjj 3 evoluce INPUT PROGRAM OUTPUT 08.11.2018 vjj 4 evoluce Windows • bitmap graphics model - Device Context • Windows does not retain a copy of what the application drew • Windows 3.0 (1990) • bitmap graphics model - layered Device Context • Windows does retain a copy of the drawing as a bitmap • Windows 2000 (beta 1998) • .NET Framework (2001-2005) • vector graphics model – WPF (on DirectX) • tree of user-interface elements with objects representing graphical shapes • Windows Vista, .NET Framework 3.0 (2006) • Metro - deterioration • Windows 8, .NET Framework 4.5 (2012) 08.11.2018 vjj 5 1: Win32 API classique 08.11.2018 vjj 6 Uživatel Fronta zpráv GetMessage (mouse, keyboard) hardware interrupt DRIVER DispatchMessage System message queue WindowProc WindowProc RIT Raw Input Thread Fronta zpráv 8.11.18 vjj 7 WM_PAINT • každý ovládací prvek je samostatným oknem s vlastní procedurou na zpracovávání zpráv • celá stavba programu/algoritmu se točila kolem přípravy dat pro vykreslení obsahu okna vždy, když přišla zpráva WM_PAINT (a že chodila často) • během přímého kreslení se výstup do momentálně neviditelné části okna nikam nezapsal 08.11.2018 vjj 8 User Windows OS Invalidate... Program WM_PAINT GetDC Program Funkce GDI32 / GDI+ Graphics Card Frame Buffer for Screen Image data only retained as long as it remains visible on screen 08.11.2018 vjj 9 PROGRAM: direct Device Context OUTPUT PROGRAM PROGRAM PROGRAM PROGRAM PROGRAM WM_PAINT WM_PAINT WM_PAINT WM_PAINT WM_PAINT 08.11.2018 vjj 10 standardní funkce • TextOut • MoveToEx DrawText LineTo Rectangle Ellipse • DrawIcon Pie Arc Chord Polyline • BitBlt Polygon stretchBlt 08.11.2018 vjj 11 Device Context • standardní funkce pro kreslení do okna vyžadují hDC jako svůj první parametr • datová struktura popisující vlastnosti výstupu, např. • font – text • pero – čárová grafika • štětec – pozadí • Update Region • hDC z funkcí BeginPaint, GetDC, ... • CS_CLASSDC, CS_OWNDC 08.11.2018 vjj 12 bitmap graphics model • each UI element (HWND) has exclusive ownership of some region of the application's window • within each top-level window, any given pixel in that window is controlled completely by exactly one UI element • this prevents elements from being partially transparent • it also preludes the use of anti-aliasing around the edges of elements 08.11.2018 vjj 13 TextOut TextOut (hDC, x, y, "text", délka) ; SetTextAlign (hDC, TA_LEFT | TA_TOP) ; TA_RIGHT TA_BOTTOM TA_CENTER TA_NOUPDATECP TA_UPDATECP SetTextColor (hDC, dwColorRGB) ; RGB (255, 255, 255) dwColorRGB = GetTextColor (hDC) ; 08.11.2018 vjj 29 Čárová grafika • MoveToEx (hDC, doX, doY, NULL) ; • LineTo (hDC, doX, doY) ; • Rectangle (hDC, leftX, topY, rightX, bottomY) ; • Ellipse (hDC, leftX, topY, rightX, bottomY) ; • Pie (hDC, leftX, topY, rightX, bottomY, x3, y3, x4, y4) ; • Arc (hDC, leftX, topY, rightX, bottomY, x3, y3, x4, y4) ; • Chord(hDC, leftX, topY, rightX, bottomY, x3, y3, x4, y4); • Polyline (hDC, CONST POINT *lpPoints, int nPočet) ; • Polygon (hDC, CONST POINT *lpPoints, int nPočet) ; SetPolyFillMode (hDC, ALTERNATE nebo WINDING); 08.11.2018 vjj 34 Bitmap 08.11.2018 vjj 43 2: layered window Win32 API upgrade 08.11.2018 vjj 70 layered window Windows WM_PAINT Program Funkce GDI32 / GDI+ off-screen Layered Window Buffer Desktop Compositing Engine (DCE) Graphics Card Frame Buffer for Screen 08.11.2018 vjj 71 2½: Windows.Forms 1st generation of .NET 08.11.2018 vjj 77 .NET GDI Graphics Model Aplikace Drawing Objects Funkce GDI32 / GDI+ Buffer for the Window Windows .NET runtime Funkce GDI32 / GDI+ off-screen Layered Window Buffer Desktop Window Manager (DWM) Graphics Card Buffer 08.11.2018 vjj 78 3: DirectX 08.11.2018 vjj 86 3½: WPF 08.11.2018 vjj 88 Desktop Window Manager DWM.EXE http://en.wikipedia.org/wiki/Desktop_Window_Manager 08.11.2018 vjj 89 DWM • window undercoat • window with non-rectangular area • window chrome • window without title bar • window content • GDI, DirectX (WPF) • window composition • partial transparency, blur, outer glow, anti-aliasing 08.11.2018 vjj 90 DWM • It was originally created to enable portions of the "Windows Aero" user experience (Windows Vista, Windows 7), which allowed for effects such as • transparency, • 3D window switching • and more • it has been subsequently • severely reduced, blocked - with advent of Windows 8 • severely reduced, code removed – Windows 8, 8.1 • partially revived – several updates of Windows 10 08.11.2018 vjj 91 window chrome 08.11.2018 vjj 92 with UI chrome WindowStyle="ThreeDBorderWindow" 08.11.2018 vjj 93 without UI chrome WindowStyle="None" 08.11.2018 vjj 94 non-rectangular window 08.11.2018 vjj 95 Win32 API SetWindowRgn SetWindowPos (hMyMainWindow, 0, 100, 100, 800, 400, SWP_NOZORDER) ; rg1 = CreateEllipticRgn (0, -400, 800, 400) ; rg2 = CreateRectRgn (0, 0, 800, 400) ; CombineRgn (rg1, rg1, rg2, RGN_AND) ; rg2 = CreateEllipticRgn (500, 50, 700, 150) ; CombineRgn (rg1, rg1, rg2, RGN_DIFF) ; SetWindowRgn (hMyMainWindow, rg1, TRUE) ; 08.11.2018 vjj 96 Win32 API SetWindowRgn 08.11.2018 vjj 97 WPF VisualClip this.VisualClip = new EllipseGeometry (new Rect(new Point(0, 0), new Size(400, 400))); 08.11.2018 vjj 98 WPF VisualClip WindowStyle="ThreeDBorderWindow" 08.11.2018 vjj 99 WPF VisualClip WindowStyle="None" 08.11.2018 vjj 100 AllowsTransparency <Window x:Class="GlassW.Window1" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" AllowsTransparency="True" WindowStyle="None"> • requires WindowStyle="None“ • AllowsTransparency cannot be changed after a Window has been shown or WindowInteropHelper.EnsureHandle has been called 08.11.2018 vjj 101 WPF WindowStyle="None" AllowsTransparency="True" 08.11.2018 vjj 102 window opacity 08.11.2018 vjj 103 Opacity Opacity="0.4" 08.11.2018 vjj 104 Opacity WindowStyle="None" AllowsTransparency="True" Background="Transparent" 08.11.2018 vjj 105 Aero blur DwmIsCompositionEnabled DwmExtendFrameIntoClientArea DwmEnableBlurBehindWindow 08.11.2018 vjj 106 Aero blur <Window x:Class="GlassW.Window1" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" AllowsTransparency="False" WindowStyle="None" Background="Transparent"> • requires desktop Aero Theme 08.11.2018 vjj 107 DwmExtendFrameIntoClientArea 08.11.2018 vjj 108 DwmExtendFrameIntoClientArea 08.11.2018 vjj 109 DwmExtendFrameIntoClientArea 08.11.2018 vjj 110 DwmExtendFrameIntoClientArea public class GlassHelper { [StructLayout(LayoutKind.Sequential)] struct MARGINS { public MARGINS( Thickness t ) { Left = (int)t.Left; Right = (int)t.Right; Top = (int)t.Top; Bottom = (int)t.Bottom; } public int Left; public int Right; public int Top; public int Bottom; } // P/Invoke [DllImport("dwmapi.dll", PreserveSig = false)] static extern void DwmExtendFrameIntoClientArea( IntPtr hWnd, ref MARGINS pMarInset); [DllImport("dwmapi.dll", PreserveSig = false)] static extern bool DwmIsCompositionEnabled(); 08.11.2018 vjj 111 DwmExtendFrameIntoClientArea public static bool ExtendGlassFrame( System.Windows.Window window, Thickness margin) { IntPtr hwnd = new WindowInteropHelper( window ).Handle; if (hwnd == IntPtr.Zero) return false; if ( ! DwmIsCompositionEnabled() ) return false; MARGINS margins = new MARGINS( margin ); DwmExtendFrameIntoClientArea( hwnd, ref margins ); return true; } } // class GlassHelper 08.11.2018 vjj 112 DwmExtendFrameIntoClientArea private void myBackgroundVisibility_Unchecked( object sender, RoutedEventArgs e) { // Set the WPF background to transparent this.Background = Brushes.Transparent; // Set the Win32 background to transparent IntPtr hwnd = new WindowInteropHelper(this).Handle; if (hwnd == IntPtr.Zero) return; HwndSource.FromHwnd(hwnd).CompositionTarget.BackgroundColor = Colors.Transparent; } 08.11.2018 vjj 113 DwmEnableBlurBehindWindow 08.11.2018 vjj 114 DwmEnableBlurBehindWindow [DllImport("dwmapi.dll", PreserveSig = false)] static extern void DwmEnableBlurBehindWindow( IntPtr hWnd, ref DWM_BLURBEHIND pBlurBehind); [StructLayout(LayoutKind.Sequential)] struct DWM_BLURBEHIND { public DWM_BB dwFlags; public bool fEnable; public IntPtr hRgnBlur; public bool fTransitionOnMaximized; public DWM_BLURBEHIND(bool enabled) { fEnable = enabled ? true : false; hRgnBlur = IntPtr.Zero; fTransitionOnMaximized = false; dwFlags = DWM_BB.Enable; } DWM_BLURBEHIND bb = new DWM_BLURBEHIND(bbb); DwmEnableBlurBehindWindow(hwnd, ref bb); 08.11.2018 vjj 115 WPF 08.11.2018 vjj 116 WPF • zjednodušení stromové struktury oken, ze kterých se skládá UI aplikace • všechny ovládací prvky uvnitř okna už nejsou samostatnými okny, ale jen ilustracemi • o rozlišení událostí, které se jich týkají, se místo jádra Windows (vlákno RAW) stará .NET runtime (tj. DLL uvnitř Win32 API aplikace hostující .NET, která zpracovává Win32 API zprávy) • Metro šlo ve zjednodušení stromové struktury oken ještě dál - runtime + všechny apps = jediný Win32 API proces s jediným oknem (full screen) 08.11.2018 vjj 118 WPF Graphics Model • Windows Presentation Foundation (Avalon) • nadstavba nad DirectX • HW akcelerace • transformace jsou aplikovány na libovolnou část vizuálního stromu, tj. ne pouze na kompletní uživatelskou oblast okna jako u Win32 API • nezávislé na hardwaru a na rozlišení • vždy vektorové • jednotky: "device-independent pixels" = 1/96th of an inch • výpočty - float • WPF Windows are based on old fashioned Win32 window objects. • The

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    68 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us