freetype-commit
[Top][All Lists]
Advanced

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

[Git][freetype/freetype-demos][master] 2 commits: [graph/win32] Implemen


From: Alexei Podtelezhnikov (@apodtele)
Subject: [Git][freetype/freetype-demos][master] 2 commits: [graph/win32] Implement smooth resizing.
Date: Fri, 31 Dec 2021 19:02:25 +0000

Alexei Podtelezhnikov pushed to branch master at FreeType / FreeType Demo Programs

Commits:

1 changed file:

Changes:

  • graph/win32/grwin32.c
    ... ... @@ -57,6 +57,7 @@
    57 57
     #endif
    
    58 58
     
    
    59 59
     /*  Custom messages. */
    
    60
    +#define WM_STATUS  WM_USER+512
    
    60 61
     #define WM_RESIZE  WM_USER+517
    
    61 62
     
    
    62 63
     
    
    ... ... @@ -99,6 +100,7 @@
    99 100
       typedef struct grWin32SurfaceRec_
    
    100 101
       {
    
    101 102
         grSurface     root;
    
    103
    +    DWORD         host;
    
    102 104
         HWND          window;
    
    103 105
         HICON         sIcon;
    
    104 106
         HICON         bIcon;
    
    ... ... @@ -148,7 +150,7 @@ gr_win32_surface_refresh_rectangle(
    148 150
       grBitmap*  bitmap = &surface->root.bitmap;
    
    149 151
     
    
    150 152
       LOG(( "gr_win32_surface_refresh_rectangle: ( %p, %d, %d, %d, %d )\n",
    
    151
    -        (long)surface, x, y, w, h ));
    
    153
    +        surface->root.bitmap.buffer, x, y, w, h ));
    
    152 154
     
    
    153 155
       /* clip update rectangle */
    
    154 156
     
    
    ... ... @@ -305,8 +307,6 @@ gr_win32_surface_set_icon( grWin32Surface* surface,
    305 307
         return 0;
    
    306 308
       case ICON_BIG:
    
    307 309
         surface->bIcon = hIcon;
    
    308
    -    SetClassLongPtr( surface->window, GCLP_HBRBACKGROUND,
    
    309
    -                     (LONG_PTR)CreatePatternBrush( ici.hbmColor ) );
    
    310 310
         return s[0];
    
    311 311
       default:
    
    312 312
         return 0;  /* should not happen */
    
    ... ... @@ -373,7 +373,7 @@ gr_win32_surface_listen_event( grWin32Surface* surface,
    373 373
     
    
    374 374
       event_mask=event_mask;  /* unused parameter */
    
    375 375
     
    
    376
    -  while ( GetMessage( &msg, NULL, 0, 0 ) > 0 )
    
    376
    +  while ( GetMessage( &msg, (HWND)-1, 0, 0 ) > 0 )
    
    377 377
       {
    
    378 378
         switch ( msg.message )
    
    379 379
         {
    
    ... ... @@ -423,16 +423,61 @@ gr_win32_surface_listen_event( grWin32Surface* surface,
    423 423
           }
    
    424 424
           break;
    
    425 425
         }
    
    426
    +  }
    
    427
    +}
    
    428
    +
    
    429
    +
    
    430
    +DWORD WINAPI Window_ThreadProc( LPVOID lpParameter )
    
    431
    +{
    
    432
    +  grWin32Surface*  surface = (grWin32Surface*)lpParameter;
    
    433
    +  DWORD            style   = WS_OVERLAPPEDWINDOW;
    
    434
    +  RECT             WndRect;
    
    435
    +  MSG              msg;
    
    436
    +
    
    437
    +  WndRect.left   = 0;
    
    438
    +  WndRect.top    = 0;
    
    439
    +  WndRect.right  = surface->root.bitmap.width;
    
    440
    +  WndRect.bottom = surface->root.bitmap.rows;
    
    441
    +
    
    442
    +  AdjustWindowRect( &WndRect, style, FALSE );
    
    443
    +
    
    444
    +  surface->window = CreateWindow(
    
    445
    +       /* LPCSTR lpszClassName;    */ "FreeTypeTestGraphicDriver",
    
    446
    +       /* LPCSTR lpszWindowName;   */ "FreeType Test Graphic Driver",
    
    447
    +       /* DWORD dwStyle;           */  style,
    
    448
    +       /* int x;                   */  CW_USEDEFAULT,
    
    449
    +       /* int y;                   */  CW_USEDEFAULT,
    
    450
    +       /* int nWidth;              */  WndRect.right - WndRect.left,
    
    451
    +       /* int nHeight;             */  WndRect.bottom - WndRect.top,
    
    452
    +       /* HWND hwndParent;         */  HWND_DESKTOP,
    
    453
    +       /* HMENU hmenu;             */  0,
    
    454
    +       /* HINSTANCE hinst;         */  GetModuleHandle( NULL ),
    
    455
    +       /* void FAR* lpvParam;      */  surface );
    
    456
    +
    
    457
    +  PostThreadMessage( surface->host, WM_STATUS, (WPARAM)surface->window, 0 );
    
    458
    +
    
    459
    +  if ( surface->window == 0 )
    
    460
    +    return -1;
    
    426 461
     
    
    462
    +  ShowWindow( surface->window, SW_SHOWNORMAL );
    
    463
    +
    
    464
    +  while ( GetMessage( &msg, surface->window, 0, 0 ) > 0 )
    
    465
    +  {
    
    427 466
         TranslateMessage( &msg );
    
    428 467
         DispatchMessage( &msg );
    
    429 468
       }
    
    469
    +
    
    470
    +  LOG(("Window thread done.\n"));
    
    471
    +  return 0;
    
    430 472
     }
    
    431 473
     
    
    474
    +
    
    432 475
     static grWin32Surface*
    
    433 476
     gr_win32_surface_init( grWin32Surface*  surface,
    
    434 477
                            grBitmap*        bitmap )
    
    435 478
     {
    
    479
    +  MSG  msg;
    
    480
    +
    
    436 481
       surface->root.bitmap.grays = bitmap->grays;
    
    437 482
     
    
    438 483
       /* Set default mode */
    
    ... ... @@ -464,14 +509,6 @@ gr_win32_surface_init( grWin32Surface* surface,
    464 509
       else
    
    465 510
         surface->root.bitmap.mode  = bitmap->mode;
    
    466 511
     
    
    467
    -
    
    468
    -  LOG(( "Win32: init_surface( %p, %p )\n", surface, bitmap ));
    
    469
    -
    
    470
    -  LOG(( "       --   mode   = %d\n", bitmap->mode ));
    
    471
    -  LOG(( "       --   grays  = %d\n", bitmap->grays ));
    
    472
    -  LOG(( "       --   width  = %d\n", bitmap->width ));
    
    473
    -  LOG(( "       --   height = %d\n", bitmap->rows ));
    
    474
    -
    
    475 512
       if ( !gr_win32_surface_resize( surface, bitmap->width, bitmap->rows ) )
    
    476 513
         return 0;
    
    477 514
     
    
    ... ... @@ -540,42 +577,28 @@ gr_win32_surface_init( grWin32Surface* surface,
    540 577
         return 0;         /* Unknown mode */
    
    541 578
       }
    
    542 579
     
    
    543
    -  {
    
    544
    -    DWORD  style = WS_OVERLAPPEDWINDOW;
    
    545
    -    RECT   WndRect;
    
    546
    -
    
    547
    -    WndRect.left   = 0;
    
    548
    -    WndRect.top    = 0;
    
    549
    -    WndRect.right  = bitmap->width;
    
    550
    -    WndRect.bottom = bitmap->rows;
    
    551
    -
    
    552
    -    AdjustWindowRect( &WndRect, style, FALSE );
    
    553
    -
    
    554
    -    surface->window = CreateWindow(
    
    555
    -            /* LPCSTR lpszClassName;    */ "FreeTypeTestGraphicDriver",
    
    556
    -            /* LPCSTR lpszWindowName;   */ "FreeType Test Graphic Driver",
    
    557
    -            /* DWORD dwStyle;           */  style,
    
    558
    -            /* int x;                   */  CW_USEDEFAULT,
    
    559
    -            /* int y;                   */  CW_USEDEFAULT,
    
    560
    -            /* int nWidth;              */  WndRect.right - WndRect.left,
    
    561
    -            /* int nHeight;             */  WndRect.bottom - WndRect.top,
    
    562
    -            /* HWND hwndParent;         */  HWND_DESKTOP,
    
    563
    -            /* HMENU hmenu;             */  0,
    
    564
    -            /* HINSTANCE hinst;         */  GetModuleHandle( NULL ),
    
    565
    -            /* void FAR* lpvParam;      */  surface );
    
    566
    -  }
    
    580
    +  /* set up the main message queue and spin off the window thread */
    
    581
    +  PeekMessage( &msg, (HWND)-1, WM_USER, WM_USER, PM_NOREMOVE );
    
    582
    +  surface->host = GetCurrentThreadId();
    
    567 583
     
    
    568
    -  if ( surface->window == 0 )
    
    569
    -    return  0;
    
    584
    +  CreateThread( NULL, 0, Window_ThreadProc, (LPVOID)surface, 0, NULL );
    
    570 585
     
    
    571
    -  ShowWindow( surface->window, SW_SHOWNORMAL );
    
    586
    +  /* listen if window is created */
    
    587
    +  if ( GetMessage ( &msg, (HWND)-1, WM_STATUS, WM_STATUS ) < 0 ||
    
    588
    +       !msg.wParam )
    
    589
    +    return 0;
    
    572 590
     
    
    591
    +  /* wrap up */
    
    573 592
       surface->root.done         = (grDoneSurfaceFunc) gr_win32_surface_done;
    
    574 593
       surface->root.refresh_rect = (grRefreshRectFunc) gr_win32_surface_refresh_rectangle;
    
    575 594
       surface->root.set_title    = (grSetTitleFunc)    gr_win32_surface_set_title;
    
    576 595
       surface->root.set_icon     = (grSetIconFunc)     gr_win32_surface_set_icon;
    
    577 596
       surface->root.listen_event = (grListenEventFunc) gr_win32_surface_listen_event;
    
    578 597
     
    
    598
    +  LOG(( "Surface initialized: %dx%dx%d\n",
    
    599
    +        surface->root.bitmap.width, surface->root.bitmap.rows,
    
    600
    +        surface->bmiHeader.biBitCount ));
    
    601
    +
    
    579 602
       return surface;
    
    580 603
     }
    
    581 604
     
    
    ... ... @@ -611,15 +634,14 @@ LRESULT CALLBACK Message_Process( HWND handle, UINT mess,
    611 634
         {
    
    612 635
         case WM_CLOSE:
    
    613 636
           /* warn the main thread to quit if it didn't know */
    
    614
    -      PostMessage( handle, WM_CHAR, (WPARAM)grKeyEsc, 0 );
    
    637
    +      PostThreadMessage( surface->host, WM_CHAR, (WPARAM)grKeyEsc, 0 );
    
    615 638
           break;
    
    616 639
     
    
    617 640
         case WM_SIZE:
    
    618 641
           if ( wParam == SIZE_RESTORED || wParam == SIZE_MAXIMIZED )
    
    619
    -        PostMessage( handle, WM_RESIZE, wParam, lParam );
    
    642
    +        PostThreadMessage( surface->host, WM_RESIZE, wParam, lParam );
    
    620 643
           break;
    
    621 644
     
    
    622
    -#ifdef DEBUG
    
    623 645
         case WM_SIZING:
    
    624 646
           {
    
    625 647
             PRECT  r = (PRECT)lParam;
    
    ... ... @@ -638,27 +660,34 @@ LRESULT CALLBACK Message_Process( HWND handle, UINT mess,
    638 660
                   y, x, r->left, r->top, r->right, r->bottom,
    
    639 661
                   WndRect.right, WndRect.bottom ));
    
    640 662
     
    
    641
    -        /* XXX: We cannot simply interrupt here and resize the image. */
    
    663
    +        PostThreadMessage( surface->host, WM_RESIZE, SIZE_RESTORED,
    
    664
    +                           MAKELPARAM( WndRect.right, WndRect.bottom ) );
    
    642 665
           }
    
    643 666
           break;
    
    644
    -#endif
    
    645 667
     
    
    646 668
         case WM_EXITSIZEMOVE:
    
    647 669
           {
    
    648 670
             RECT  WndRect;
    
    649 671
     
    
    650 672
             GetClientRect( handle, &WndRect );
    
    651
    -        PostMessage( handle, WM_RESIZE, SIZE_RESTORED,
    
    652
    -                     MAKELPARAM( WndRect.right, WndRect.bottom ) );
    
    673
    +        PostThreadMessage( surface->host, WM_RESIZE, SIZE_RESTORED,
    
    674
    +                           MAKELPARAM( WndRect.right, WndRect.bottom ) );
    
    653 675
           }
    
    654 676
           break;
    
    655 677
     
    
    678
    +    case WM_KEYDOWN:
    
    679
    +    case WM_SYSKEYDOWN:
    
    680
    +    case WM_CHAR:
    
    681
    +      /* repost to the main thread */
    
    682
    +      PostThreadMessage( surface->host, mess, wParam, lParam );
    
    683
    +      break;
    
    684
    +
    
    656 685
         case WM_PAINT:
    
    657 686
           {
    
    658
    -        HDC           hDC;
    
    659
    -        PAINTSTRUCT   ps;
    
    687
    +        HDC          hDC;
    
    688
    +        PAINTSTRUCT  ps;
    
    660 689
     
    
    661
    -        hDC   = BeginPaint ( handle, &ps );
    
    690
    +        hDC = BeginPaint ( handle, &ps );
    
    662 691
             SetDIBitsToDevice( hDC, 0, 0,
    
    663 692
                                surface->root.bitmap.width,
    
    664 693
                                surface->root.bitmap.rows,
    


  • reply via email to

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