freetype-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[freetype2-demos] master 5a19151 3/4: [graph/win32] Icon support.


From: Alexei Podtelezhnikov
Subject: [freetype2-demos] master 5a19151 3/4: [graph/win32] Icon support.
Date: Thu, 15 Oct 2020 23:36:34 -0400 (EDT)

branch: master
commit 5a19151be9ea8813140244758f6243b091c0988c
Author: Alexei Podtelezhnikov <apodtele@gmail.com>
Commit: Alexei Podtelezhnikov <apodtele@gmail.com>

    [graph/win32] Icon support.
    
    * graph/win32/grwin32.c (gr_win32_surface_set_icon): Implement it.
    (gr_win32_surface_init): Initialize the driver backend.
    (gr_win32_surface_done): Destroy icons.
---
 ChangeLog             |  8 +++++++
 graph/win32/grwin32.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 71 insertions(+)

diff --git a/ChangeLog b/ChangeLog
index 65f8e7d..ee49e63 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
 2020-10-15  Alexei Podtelezhnikov  <apodtele@gmail.com>
 
+       [graph/win32] Icon support.
+
+       * graph/win32/grwin32.c (gr_win32_surface_set_icon): Implement it.
+       (gr_win32_surface_init): Initialize the driver backend.
+       (gr_win32_surface_done): Destroy icons.
+
+2020-10-15  Alexei Podtelezhnikov  <apodtele@gmail.com>
+
        [graph/x11] Icon support.
 
        * graph/x11/grx11.c (gr_x11_surface_set_icon): Implement it.
diff --git a/graph/win32/grwin32.c b/graph/win32/grwin32.c
index 585ba1f..4bc2cb9 100644
--- a/graph/win32/grwin32.c
+++ b/graph/win32/grwin32.c
@@ -106,6 +106,8 @@
   {
     grSurface     root;
     HWND          window;
+    HICON         sIcon;
+    HICON         bIcon;
     LPBITMAPINFO  pbmi;
     char          bmi[ sizeof(BITMAPINFO) + 256*sizeof(RGBQUAD) ];
     grBitmap      bgrBitmap;  /* windows wants data in BGR format !! */
@@ -125,6 +127,9 @@ gr_win32_surface_done( grWin32Surface*  surface )
     DestroyWindow ( surface->window );
     PostMessage( surface->window, WM_QUIT, 0, 0 );
   }
+
+  DestroyIcon( surface->sIcon );
+  DestroyIcon( surface->bIcon );
 #ifdef SWIZZLE
   grDoneBitmap( &surface->swizzle_bitmap );
 #endif
@@ -256,6 +261,63 @@ gr_win32_surface_set_title( grWin32Surface*  surface,
 }
 
 
+static int
+gr_win32_surface_set_icon( grWin32Surface*  surface,
+                           grBitmap*        icon )
+{
+  int       s[] = { GetSystemMetrics( SM_CYSMICON ),
+                    GetSystemMetrics( SM_CYICON ) };
+  WPARAM    wParam;
+  HDC       hDC;
+  VOID*     bts;
+  ICONINFO  ici = { TRUE };
+  HICON     hIcon;
+
+  BITMAPV4HEADER  hdr = { sizeof( BITMAPV4HEADER ),
+                          0, 0, 1, 32, BI_BITFIELDS, 0, 0, 0, 0, 0,
+                          0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000,
+                          LCS_sRGB };
+
+
+  if ( !icon )
+    return s[1];
+  else if ( icon->mode != gr_pixel_mode_rgb32 )
+    return 0;
+  else if ( icon->rows == s[0] )
+    wParam = ICON_SMALL;
+  else if ( icon->rows == s[1] )
+    wParam = ICON_BIG;
+  else
+    return 0;
+
+  ici.hbmMask  = CreateBitmap( icon->width, icon->rows, 1, 1, NULL);
+
+  hdr.bV4Width  =  icon->width;
+  hdr.bV4Height = -icon->rows;
+
+  hDC = GetDC( NULL );
+  ici.hbmColor = CreateDIBSection( hDC, (LPBITMAPINFO)&hdr,
+                                   DIB_RGB_COLORS, &bts, NULL, 0 );
+  ReleaseDC( NULL, hDC );
+
+  memcpy( bts, icon->buffer, icon->rows * icon->width * 4 );
+
+  hIcon = CreateIconIndirect( &ici );
+
+  PostMessage( surface->window, WM_SETICON, wParam, (LPARAM)hIcon );
+
+  switch( wParam )
+  {
+  case ICON_SMALL:
+    surface->sIcon = hIcon;
+    return 0;
+  case ICON_BIG:
+    surface->bIcon = hIcon;
+    return s[0];
+  }
+}
+
+
 /*
  * set graphics mode
  * and create the window class and the message handling.
@@ -508,6 +570,7 @@ gr_win32_surface_init( grWin32Surface*  surface,
   surface->root.done         = (grDoneSurfaceFunc) gr_win32_surface_done;
   surface->root.refresh_rect = (grRefreshRectFunc) 
gr_win32_surface_refresh_rectangle;
   surface->root.set_title    = (grSetTitleFunc)    gr_win32_surface_set_title;
+  surface->root.set_icon     = (grSetIconFunc)     gr_win32_surface_set_icon;
   surface->root.listen_event = (grListenEventFunc) 
gr_win32_surface_listen_event;
 
   return surface;



reply via email to

[Prev in Thread] Current Thread [Next in Thread]