comparison gtk/dw.c @ 49:bf42d08d72d7

Added font text extent querying code, and made it so winmain.c can be used without Dynamic Windows.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Fri, 09 Nov 2001 13:49:44 +0000
parents 16eac0f8b45f
children d97de82f0b6e
comparison
equal deleted inserted replaced
48:16eac0f8b45f 49:bf42d08d72d7
3476 int _locked_by_me = FALSE; 3476 int _locked_by_me = FALSE;
3477 GdkGC *gc = NULL; 3477 GdkGC *gc = NULL;
3478 GdkFont *font; 3478 GdkFont *font;
3479 char *fontname = "fixed"; 3479 char *fontname = "fixed";
3480 3480
3481 if(!text)
3482 return;
3483
3481 DW_MUTEX_LOCK; 3484 DW_MUTEX_LOCK;
3482 if(handle) 3485 if(handle)
3483 { 3486 {
3484 fontname = (char *)gtk_object_get_data(GTK_OBJECT(handle), "fontname"); 3487 fontname = (char *)gtk_object_get_data(GTK_OBJECT(handle), "fontname");
3485 gc = _set_colors(handle->window); 3488 gc = _set_colors(handle->window);
3499 gdk_text_extents(font, text, strlen(text), NULL, NULL, NULL, &ascent, NULL); 3502 gdk_text_extents(font, text, strlen(text), NULL, NULL, NULL, &ascent, NULL);
3500 gdk_draw_text(handle ? handle->window : pixmap->pixmap, font, gc, x, y + ascent + 2, text, strlen(text)); 3503 gdk_draw_text(handle ? handle->window : pixmap->pixmap, font, gc, x, y + ascent + 2, text, strlen(text));
3501 gdk_gc_unref(gc); 3504 gdk_gc_unref(gc);
3502 gdk_font_unref(font); 3505 gdk_font_unref(font);
3503 } 3506 }
3507 }
3508 DW_MUTEX_UNLOCK;
3509 }
3510
3511 /* Query the width and height of a text string.
3512 * Parameters:
3513 * handle: Handle to the window.
3514 * pixmap: Handle to the pixmap. (choose only one of these)
3515 * text: Text to be queried.
3516 * width: Pointer to a variable to be filled in with the width.
3517 * height Pointer to a variable to be filled in with the height.
3518 */
3519 void dw_font_text_extents(HWND handle, HPIXMAP pixmap, char *text, int *width, int *height)
3520 {
3521 int _locked_by_me = FALSE;
3522 GdkFont *font;
3523 char *fontname = NULL;
3524
3525 if(!text)
3526 return;
3527
3528 DW_MUTEX_LOCK;
3529 if(handle)
3530 fontname = (char *)gtk_object_get_data(GTK_OBJECT(handle), "fontname");
3531 else if(pixmap)
3532 fontname = (char *)gtk_object_get_data(GTK_OBJECT(pixmap->handle), "fontname");
3533
3534 font = gdk_font_load(fontname ? fontname : "fixed");
3535 if(font)
3536 {
3537 if(width)
3538 *width = gdk_string_width(font, text);
3539 if(height)
3540 *height = gdk_string_height(font, text);
3541 gdk_font_unref(font);
3504 } 3542 }
3505 DW_MUTEX_UNLOCK; 3543 DW_MUTEX_UNLOCK;
3506 } 3544 }
3507 3545
3508 /* 3546 /*