⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gros2pm.c

📁 freetype库的应用demo,里面包含freetype的很多实例
💻 C
📖 第 1 页 / 共 2 页
字号:
                                     GPIA_ASSOC | GPIF_DEFAULT );    GpiSetBackMix( surface->image_ps, BM_OVERPAINT );    /* create the image's PM bitmap */    bit = (PBITMAPINFO2)grAlloc( sizeof(BITMAPINFO2) + 256*sizeof(RGB2) );    surface->bitmap_header = bit;    bit->cbFix   = sizeof( BITMAPINFOHEADER2 );    bit->cx      = surface->root.bitmap.width;    bit->cy      = surface->root.bitmap.rows;    bit->cPlanes = 1;    bit->argbColor[0].bBlue  = 255;    bit->argbColor[0].bGreen = 0;    bit->argbColor[0].bRed   = 0;    bit->argbColor[1].bBlue  = 0;    bit->argbColor[1].bGreen = 255;    bit->argbColor[1].bRed   = 0;    bit->cBitCount = (bitmap->mode == gr_pixel_mode_gray ? 8 : 1 );    if (bitmap->mode == gr_pixel_mode_gray)    {      RGB2*  color = bit->argbColor;      int    x, count;      count = bitmap->grays;      for ( x = 0; x < count; x++, color++ )      {        color->bBlue  =        color->bGreen =        color->bRed   = (((count-x)*255)/count);      }    }    else    {      RGB2*  color = bit->argbColor;      color[0].bBlue  =      color[0].bGreen =      color[0].bRed   = 0;      color[1].bBlue  =      color[1].bGreen =      color[1].bRed   = 255;    }    surface->os2_bitmap = GpiCreateBitmap( surface->image_ps,                                           (PBITMAPINFOHEADER2)bit,                                           0L, NULL, NULL );    GpiSetBitmap( surface->image_ps, surface->os2_bitmap );    bit->cbFix = sizeof( BITMAPINFOHEADER2 );    GpiQueryBitmapInfoHeader( surface->os2_bitmap,                              (PBITMAPINFOHEADER2)bit );    surface->bitmap_header = bit;    /* for gr_pixel_mode_gray, create a gray-levels logical palette */    if ( bitmap->mode == gr_pixel_mode_gray )    {      int     x, count;      count = bitmap->grays;      for ( x = 0; x < count; x++ )        palette[x] = (((count-x)*255)/count) * 0x010101;      /* create logical color table */      GpiCreateLogColorTable( surface->image_ps,                              (ULONG) LCOL_PURECOLOR,                              (LONG)  LCOLF_CONSECRGB,                              (LONG)  0L,                              (LONG)  count,                              (PLONG) palette );      /* now, copy the color indexes to surface->shades */      for ( x = 0; x < count; x++ )        surface->shades[x] = GpiQueryColorIndex( surface->image_ps,                                                 0, palette[x] );    }    /* set up the blit points array */    surface->blit_points[1].x = surface->root.bitmap.width;    surface->blit_points[1].y = surface->root.bitmap.rows;    surface->blit_points[3]   = surface->blit_points[1];    /* Finally, create the event handling thread for the surface's window */    DosCreateThread( &surface->message_thread,                     (PFNTHREAD) RunPMWindow,                     (ULONG)     surface,                     0UL,                     32920 );    /* wait for the window creation */    LOCK(surface->image_lock);    UNLOCK(surface->image_lock);    surface->root.done         = (grDoneSurfaceFunc) done_surface;    surface->root.refresh_rect = (grRefreshRectFunc) refresh_rectangle;    surface->root.set_title    = (grSetTitleFunc)    set_title;    surface->root.listen_event = (grListenEventFunc) listen_event;    /* convert_rectangle( surface, 0, 0, bitmap->width, bitmap->rows ); */    return surface;  }  MRESULT EXPENTRY  Message_Process( HWND    handle,                                     ULONG   mess,                                     MPARAM  parm1,                                     MPARAM  parm2 );  static  void  RunPMWindow( grPMSurface*  surface )  {    unsigned char   class_name[] = "DisplayClass";             ULONG  class_flags;    static   HMQ    queue;             QMSG   message;    /* store the current surface pointer in "the_surface". It is a static */    /* variable that is only used to retrieve the pointer in the client   */    /* window procedure the first time is is called..                     */    the_surface = surface;    /* try to prevent the program from going on without the setup of thread 2 */    LOCK( surface->image_lock );    LOG(( "Os2PM: RunPMWindow( %08lx )\n", (long)surface ));    /* create an anchor to allow this thread to use PM */    surface->anchor = WinInitialize(0);    if (!surface->anchor)    {      printf( "Error doing WinInitialize()\n" );      return;    }    /* create a message queue */    queue = WinCreateMsgQueue( surface->anchor, 0 );    if (!queue)    {      printf( "Error doing WinCreateMsgQueue()\n" );      return;    }    /* register the window class */    if ( !WinRegisterClass( surface->anchor,                            (PSZ)   class_name,                            (PFNWP) Message_Process,                            CS_SIZEREDRAW,                            0 ) )    {      printf( "Error doing WinRegisterClass()\n" );      return;    }    /* create the PM window */    class_flags = FCF_TITLEBAR | FCF_MINBUTTON | FCF_DLGBORDER |                  FCF_TASKLIST | FCF_SYSMENU;    LOG(( "Os2PM: RunPMWindow: Creating window\n" ));    surface->frame_window = WinCreateStdWindow(                                HWND_DESKTOP,                                WS_VISIBLE,                                &class_flags,                                (PSZ) class_name,                                (PSZ) "FreeType Viewer - press F1 for help",                                WS_VISIBLE,                                0, 0,                                &surface->client_window );    if (!surface->frame_window)    {      printf( "Error doing WinCreateStdWindow()\n" );      return;    }    /* find the title window handle */    surface->title_window = WinWindowFromID( surface->frame_window,                                             FID_TITLEBAR );    LOG (( "Os2PM: RunPMWIndow: Creation succeeded\n" ));    LOG (( "    -- frame  = %08lx\n", surface->frame_window ));    LOG (( "    -- client = %08lx\n", surface->client_window ));    /* set Window size and position */    WinSetWindowPos( surface->frame_window,                     0L,                     (SHORT) 60,                     (SHORT) WinQuerySysValue( HWND_DESKTOP, SV_CYSCREEN ) -                             (surface->root.bitmap.rows + 100),                     (SHORT) WinQuerySysValue( HWND_DESKTOP, SV_CYDLGFRAME )*2 +                             surface->root.bitmap.width,                     (SHORT) WinQuerySysValue( HWND_DESKTOP, SV_CYTITLEBAR ) +                             WinQuerySysValue( HWND_DESKTOP, SV_CYDLGFRAME )*2 +                             surface->root.bitmap.rows,                     SWP_SIZE | SWP_MOVE );#if 0    /* save the handle to the current surface within the window words */    WinSetWindowPtr( surface->client_window,QWL_USER, surface );#endif    /* Announcing window_created */    UNLOCK(surface->image_lock);    /* run the message queue till the end */    while ( WinGetMsg( surface->anchor, &message, (HWND)NULL, 0, 0 ) )    {      WinDispatchMsg( surface->anchor, &message );    }    /* clean-up */    WinDestroyWindow( surface->frame_window );    surface->frame_window = 0;    WinDestroyMsgQueue( queue );    WinTerminate( surface->anchor );    /* await death... */    while ( 1 )      DosSleep( 100 );  }  /* Message processing for our PM Window class */  MRESULT EXPENTRY  Message_Process( HWND    handle,                                     ULONG   mess,                                     MPARAM  parm1,                                     MPARAM  parm2 )  {     static HDC     screen_dc;     static HPS     screen_ps;     static BOOL    minimized;     SIZEL   sizl;     SWP     swp;     grPMSurface*  surface;    /* get the handle to the window's surface -- note that this */    /* value will be null when the window is created            */    surface = (grPMSurface*)WinQueryWindowPtr( handle, QWL_USER );    if (!surface)    {      surface = the_surface;      WinSetWindowPtr( handle, QWL_USER, surface );    }    switch( mess )    {    case WM_DESTROY:      /* warn the main thread to quit if it didn't know */      surface->event.type = gr_event_key;      surface->event.key  = grKeyEsc;      DosPostEventSem( surface->event_lock );      break;    case WM_CREATE:      /* set original magnification */      minimized = FALSE;      /* create Device Context and Presentation Space for screen. */      screen_dc = WinOpenWindowDC( handle );      screen_ps = GpiCreatePS( surface->anchor,                               screen_dc,                               &sizl,                               PU_PELS | GPIT_MICRO |                               GPIA_ASSOC | GPIF_DEFAULT );      /* take the input focus */      WinFocusChange( HWND_DESKTOP, handle, 0L );      LOG(( "screen_dc and screen_ps have been created\n" ));      /* To permit F9, F10 and others to pass through to the application */      if (TRUE != WinSetAccelTable (surface->anchor, 0, surface->frame_window))      {        printf( "Error - failed to clear accel table\n");      }      break;    case WM_MINMAXFRAME:      /* to update minimized if changed */      swp = *((PSWP) parm1);      if ( swp.fl & SWP_MINIMIZE )        minimized = TRUE;      if ( swp.fl & SWP_RESTORE )        minimized = FALSE;      return WinDefWindowProc( handle, mess, parm1, parm2 );      break;    case WM_ERASEBACKGROUND:    case WM_PAINT:      /* copy the memory image of the screen out to the real screen */      LOCK( surface->image_lock );      WinBeginPaint( handle, screen_ps, NULL );      /* main image and magnified picture */      GpiBitBlt( screen_ps,                 surface->image_ps,                 4L,                 surface->blit_points,                 ROP_SRCCOPY, BBO_AND );      WinEndPaint( screen_ps );      UNLOCK( surface->image_lock );      break;    case WM_HELP:  /* this really is a F1 Keypress !! */      surface->event.key = grKeyF1;      goto Do_Key_Event;    case WM_CHAR:      if ( CHARMSG( &mess )->fs & KC_KEYUP )        break;      /* look for a specific vkey */      {        int          count = sizeof( key_translators )/sizeof( key_translators[0] );        Translator*  trans = key_translators;        Translator*  limit = trans + count;        for ( ; trans < limit; trans++ )          if ( CHARMSG(&mess)->vkey == trans->os2key )          {            surface->event.key = trans->grkey;            goto Do_Key_Event;          }      }      /* otherwise, simply record the character code */      if ( (CHARMSG( &mess )->fs & KC_CHAR) == 0 )        break;      surface->event.key = CHARMSG(&mess)->chr;    Do_Key_Event:      surface->event.type = gr_event_key;      DosPostEventSem( surface->event_lock );      break;    default:      return WinDefWindowProc( handle, mess, parm1, parm2 );    }    return (MRESULT) FALSE;  }  grDevice  gr_os2pm_device =  {    sizeof( grPMSurface ),    "os2pm",    init_device,    done_device,    (grDeviceInitSurfaceFunc) init_surface,    0,    0  };

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -