Mercurial > dwindows
comparison win/dw.c @ 1147:091ed7c20b3f
Implemented dw_pixmap_set_font() on Windows. Added to export files on Windows and OS/2.
Added the function to the template and fixed the comments on several platforms.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Sun, 11 Sep 2011 21:56:55 +0000 |
parents | b1b23de965d7 |
children | 58b5374355ab |
comparison
equal
deleted
inserted
replaced
1146:9d97610b2140 | 1147:091ed7c20b3f |
---|---|
8616 void API dw_draw_text(HWND handle, HPIXMAP pixmap, int x, int y, char *text) | 8616 void API dw_draw_text(HWND handle, HPIXMAP pixmap, int x, int y, char *text) |
8617 { | 8617 { |
8618 HDC hdc; | 8618 HDC hdc; |
8619 int mustdelete = 0; | 8619 int mustdelete = 0; |
8620 HFONT hFont = 0, oldFont = 0; | 8620 HFONT hFont = 0, oldFont = 0; |
8621 ColorInfo *cinfo; | 8621 ColorInfo *cinfo = NULL; |
8622 COLORREF background; | 8622 COLORREF background; |
8623 | 8623 |
8624 if(handle) | 8624 if(handle) |
8625 hdc = GetDC(handle); | 8625 hdc = GetDC(handle); |
8626 else if(pixmap) | 8626 else if(pixmap) |
8628 else | 8628 else |
8629 return; | 8629 return; |
8630 | 8630 |
8631 if(handle) | 8631 if(handle) |
8632 cinfo = (ColorInfo *)GetWindowLongPtr(handle, GWLP_USERDATA); | 8632 cinfo = (ColorInfo *)GetWindowLongPtr(handle, GWLP_USERDATA); |
8633 else | 8633 else if(pixmap->font) |
8634 hFont = pixmap->font; | |
8635 else if(pixmap->handle) | |
8634 cinfo = (ColorInfo *)GetWindowLongPtr(pixmap->handle, GWLP_USERDATA); | 8636 cinfo = (ColorInfo *)GetWindowLongPtr(pixmap->handle, GWLP_USERDATA); |
8635 | 8637 |
8636 if(cinfo) | 8638 if(cinfo) |
8637 { | 8639 { |
8638 hFont = _acquire_font(handle, cinfo->fontname); | 8640 hFont = _acquire_font(handle, cinfo->fontname); |
8986 | 8988 |
8987 return pixmap; | 8989 return pixmap; |
8988 } | 8990 } |
8989 | 8991 |
8990 /* | 8992 /* |
8993 * Sets the font used by a specified pixmap. | |
8994 * Normally the pixmap font is obtained from the associated window handle. | |
8995 * However this can be used to override that, or for pixmaps with no window. | |
8996 * Parameters: | |
8997 * pixmap: Handle to a pixmap returned by dw_pixmap_new() or | |
8998 * passed to the application via a callback. | |
8999 * fontname: Name and size of the font in the form "size.fontname" | |
9000 * Returns: | |
9001 * DW_ERROR_NONE on success and DW_ERROR_GENERAL on failure. | |
9002 */ | |
9003 int API dw_pixmap_set_font(HPIXMAP pixmap, char *fontname) | |
9004 { | |
9005 if(pixmap) | |
9006 { | |
9007 HFONT hfont = _acquire_font(pixmap->handle, fontname); | |
9008 | |
9009 if(hfont) | |
9010 { | |
9011 HFONT oldfont = pixmap->font; | |
9012 pixmap->font = hfont; | |
9013 if(oldfont) | |
9014 DeleteObject(oldfont); | |
9015 return DW_ERROR_NONE; | |
9016 } | |
9017 } | |
9018 return DW_ERROR_GENERAL; | |
9019 } | |
9020 | |
9021 /* | |
8991 * Destroys an allocated pixmap. | 9022 * Destroys an allocated pixmap. |
8992 * Parameters: | 9023 * Parameters: |
8993 * pixmap: Handle to a pixmap returned by | 9024 * pixmap: Handle to a pixmap returned by |
8994 * dw_pixmap_new.. | 9025 * dw_pixmap_new.. |
8995 */ | 9026 */ |
8996 void API dw_pixmap_destroy(HPIXMAP pixmap) | 9027 void API dw_pixmap_destroy(HPIXMAP pixmap) |
8997 { | 9028 { |
8998 if(pixmap) | 9029 if(pixmap) |
8999 { | 9030 { |
9000 DeleteDC( pixmap->hdc ); | 9031 DeleteDC(pixmap->hdc); |
9001 DeleteObject( pixmap->hbm ); | 9032 DeleteObject(pixmap->hbm); |
9002 free( pixmap ); | 9033 if(pixmap->font) |
9034 DeleteObject(pixmap->font); | |
9035 free(pixmap); | |
9003 } | 9036 } |
9004 } | 9037 } |
9005 | 9038 |
9006 /* | 9039 /* |
9007 * Copies from one item to another. | 9040 * Copies from one item to another. |
10056 return result; | 10089 return result; |
10057 | 10090 |
10058 if (!(pixmap = calloc(1,sizeof(struct _hpixmap)))) | 10091 if (!(pixmap = calloc(1,sizeof(struct _hpixmap)))) |
10059 return result; | 10092 return result; |
10060 | 10093 |
10061 pixmap->width = GetDeviceCaps(p->pd.hDC, PHYSICALWIDTH); | 10094 pixmap->width = GetDeviceCaps(p->pd.hDC, HORZRES); |
10062 pixmap->height = GetDeviceCaps(p->pd.hDC, PHYSICALHEIGHT); | 10095 pixmap->height = GetDeviceCaps(p->pd.hDC, VERTRES); |
10063 | 10096 |
10064 /*pixmap->handle = handle;*/ | 10097 /*pixmap->handle = handle;*/ |
10065 pixmap->hbm = CreateCompatibleBitmap(p->pd.hDC, pixmap->width, pixmap->height); | 10098 pixmap->hbm = CreateCompatibleBitmap(p->pd.hDC, pixmap->width, pixmap->height); |
10066 pixmap->hdc = p->pd.hDC; | 10099 pixmap->hdc = p->pd.hDC; |
10067 pixmap->transcolor = DW_RGB_TRANSPARENT; | 10100 pixmap->transcolor = DW_RGB_TRANSPARENT; |