Mercurial > dwindows
comparison gtk/dw.c @ 372:3ef2cf70ee07
Code for drawing text with a background color on GTK 2.x.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Sun, 27 Apr 2003 19:21:24 +0000 |
parents | 39983df2b93d |
children | d04b0699fc28 |
comparison
equal
deleted
inserted
replaced
371:e856f80e0520 | 372:3ef2cf70ee07 |
---|---|
844 | 844 |
845 if(_dw_thread_list[z] == (DWTID)-1) | 845 if(_dw_thread_list[z] == (DWTID)-1) |
846 { | 846 { |
847 _dw_thread_list[z] = tid; | 847 _dw_thread_list[z] = tid; |
848 _foreground[z].pixel = _foreground[z].red =_foreground[z].green = _foreground[z].blue = 0; | 848 _foreground[z].pixel = _foreground[z].red =_foreground[z].green = _foreground[z].blue = 0; |
849 _background[z].pixel = 0; | 849 _background[z].pixel = 1; |
850 _background[z].red = 0xaaaa; | 850 _background[z].red = _background[z].green = _background[z].blue = 0; |
851 _background[z].green = 0xaaaa; | |
852 _background[z].blue = 0xaaaa; | |
853 return; | 851 return; |
854 } | 852 } |
855 } | 853 } |
856 } | 854 } |
857 | 855 |
5206 } | 5204 } |
5207 | 5205 |
5208 /* Returns a GdkColor from a DW color */ | 5206 /* Returns a GdkColor from a DW color */ |
5209 static GdkColor _internal_color(unsigned long value) | 5207 static GdkColor _internal_color(unsigned long value) |
5210 { | 5208 { |
5209 if(value == DW_CLR_DEFAULT) | |
5210 { | |
5211 GdkColor color = { 1, 0, 0, 0 }; | |
5212 return color; | |
5213 } | |
5211 if(DW_RGB_COLOR & value) | 5214 if(DW_RGB_COLOR & value) |
5212 { | 5215 { |
5213 GdkColor color = { 0, DW_RED_VALUE(value) << 8, DW_GREEN_VALUE(value) << 8, DW_BLUE_VALUE(value) << 8 }; | 5216 GdkColor color = { 0, DW_RED_VALUE(value) << 8, DW_GREEN_VALUE(value) << 8, DW_BLUE_VALUE(value) << 8 }; |
5214 return color; | 5217 return color; |
5215 } | 5218 } |
5216 else if (value < 16) | 5219 if (value < 16) |
5217 return _colors[value]; | 5220 return _colors[value]; |
5218 return _colors[0]; | 5221 return _colors[0]; |
5219 } | 5222 } |
5220 | 5223 |
5221 /* Sets the current foreground drawing color. | 5224 /* Sets the current foreground drawing color. |
5228 { | 5231 { |
5229 int _locked_by_me = FALSE, index = _find_thread_index(dw_thread_id()); | 5232 int _locked_by_me = FALSE, index = _find_thread_index(dw_thread_id()); |
5230 GdkColor color = _internal_color(value); | 5233 GdkColor color = _internal_color(value); |
5231 | 5234 |
5232 DW_MUTEX_LOCK; | 5235 DW_MUTEX_LOCK; |
5233 gdk_color_alloc(_dw_cmap, &color); | 5236 if(!color.pixel) |
5237 gdk_color_alloc(_dw_cmap, &color); | |
5234 _foreground[index] = color; | 5238 _foreground[index] = color; |
5235 DW_MUTEX_UNLOCK; | 5239 DW_MUTEX_UNLOCK; |
5236 } | 5240 } |
5237 | 5241 |
5238 /* Sets the current background drawing color. | 5242 /* Sets the current background drawing color. |
5245 { | 5249 { |
5246 int _locked_by_me = FALSE, index = _find_thread_index(dw_thread_id()); | 5250 int _locked_by_me = FALSE, index = _find_thread_index(dw_thread_id()); |
5247 GdkColor color = _internal_color(value); | 5251 GdkColor color = _internal_color(value); |
5248 | 5252 |
5249 DW_MUTEX_LOCK; | 5253 DW_MUTEX_LOCK; |
5250 gdk_color_alloc(_dw_cmap, &color); | 5254 if(!color.pixel) |
5255 gdk_color_alloc(_dw_cmap, &color); | |
5251 _background[index] = color; | 5256 _background[index] = color; |
5252 DW_MUTEX_UNLOCK; | 5257 DW_MUTEX_UNLOCK; |
5253 } | 5258 } |
5254 | 5259 |
5255 GdkGC *_set_colors(GdkWindow *window) | 5260 GdkGC *_set_colors(GdkWindow *window) |
5260 if(!window) | 5265 if(!window) |
5261 return NULL; | 5266 return NULL; |
5262 gc = gdk_gc_new(window); | 5267 gc = gdk_gc_new(window); |
5263 if(gc) | 5268 if(gc) |
5264 { | 5269 { |
5265 gdk_gc_set_foreground(gc, &_foreground[index]); | 5270 if(!_foreground[index].pixel) |
5266 gdk_gc_set_background(gc, &_background[index]); | 5271 gdk_gc_set_foreground(gc, &_foreground[index]); |
5272 if(!_background[index].pixel) | |
5273 gdk_gc_set_background(gc, &_background[index]); | |
5267 } | 5274 } |
5268 return gc; | 5275 return gc; |
5269 } | 5276 } |
5270 | 5277 |
5271 /* Draw a point on a window (preferably a render window). | 5278 /* Draw a point on a window (preferably a render window). |
5392 { | 5399 { |
5393 PangoLayout *layout = pango_layout_new(context); | 5400 PangoLayout *layout = pango_layout_new(context); |
5394 | 5401 |
5395 if(layout) | 5402 if(layout) |
5396 { | 5403 { |
5404 int index = _find_thread_index(dw_thread_id()); | |
5405 | |
5397 pango_layout_set_font_description(layout, font); | 5406 pango_layout_set_font_description(layout, font); |
5398 pango_layout_set_text(layout, text, strlen(text)); | 5407 pango_layout_set_text(layout, text, strlen(text)); |
5399 | 5408 |
5400 gdk_draw_layout(handle ? handle->window : pixmap->pixmap, gc, x, y + 2, layout); | 5409 if(_background[index].pixel) |
5410 gdk_draw_layout(handle ? handle->window : pixmap->pixmap, gc, x, y + 2, layout); | |
5411 else | |
5412 gdk_draw_layout_with_colors(handle ? handle->window : pixmap->pixmap, gc, x, y + 2, layout, &_foreground[index], &_background[index]); | |
5401 | 5413 |
5402 g_object_unref(layout); | 5414 g_object_unref(layout); |
5403 } | 5415 } |
5404 g_object_unref(context); | 5416 g_object_unref(context); |
5405 } | 5417 } |