Mercurial > dwindows
comparison gtk/dw.c @ 373:d04b0699fc28
Fixes for background color drawing on GTK 2.x.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Sun, 27 Apr 2003 19:53:29 +0000 |
parents | 3ef2cf70ee07 |
children | 47dc310e6d74 |
comparison
equal
deleted
inserted
replaced
372:3ef2cf70ee07 | 373:d04b0699fc28 |
---|---|
53 #define DW_THREAD_LIMIT 50 | 53 #define DW_THREAD_LIMIT 50 |
54 | 54 |
55 DWTID _dw_thread_list[DW_THREAD_LIMIT]; | 55 DWTID _dw_thread_list[DW_THREAD_LIMIT]; |
56 GdkColor _foreground[DW_THREAD_LIMIT]; | 56 GdkColor _foreground[DW_THREAD_LIMIT]; |
57 GdkColor _background[DW_THREAD_LIMIT]; | 57 GdkColor _background[DW_THREAD_LIMIT]; |
58 int _transparent[DW_THREAD_LIMIT]; | |
58 | 59 |
59 GtkWidget *last_window = NULL, *popup = NULL; | 60 GtkWidget *last_window = NULL, *popup = NULL; |
60 | 61 |
61 static int _dw_file_active = 0, _dw_ignore_click = 0; | 62 static int _dw_file_active = 0, _dw_ignore_click = 0; |
62 static pthread_t _dw_thread = (pthread_t)-1; | 63 static pthread_t _dw_thread = (pthread_t)-1; |
846 { | 847 { |
847 _dw_thread_list[z] = tid; | 848 _dw_thread_list[z] = tid; |
848 _foreground[z].pixel = _foreground[z].red =_foreground[z].green = _foreground[z].blue = 0; | 849 _foreground[z].pixel = _foreground[z].red =_foreground[z].green = _foreground[z].blue = 0; |
849 _background[z].pixel = 1; | 850 _background[z].pixel = 1; |
850 _background[z].red = _background[z].green = _background[z].blue = 0; | 851 _background[z].red = _background[z].green = _background[z].blue = 0; |
852 _transparent[z] = 1; | |
851 return; | 853 return; |
852 } | 854 } |
853 } | 855 } |
854 } | 856 } |
855 | 857 |
5204 } | 5206 } |
5205 | 5207 |
5206 /* Returns a GdkColor from a DW color */ | 5208 /* Returns a GdkColor from a DW color */ |
5207 static GdkColor _internal_color(unsigned long value) | 5209 static GdkColor _internal_color(unsigned long value) |
5208 { | 5210 { |
5209 if(value == DW_CLR_DEFAULT) | |
5210 { | |
5211 GdkColor color = { 1, 0, 0, 0 }; | |
5212 return color; | |
5213 } | |
5214 if(DW_RGB_COLOR & value) | 5211 if(DW_RGB_COLOR & value) |
5215 { | 5212 { |
5216 GdkColor color = { 0, DW_RED_VALUE(value) << 8, DW_GREEN_VALUE(value) << 8, DW_BLUE_VALUE(value) << 8 }; | 5213 GdkColor color = { 0, DW_RED_VALUE(value) << 8, DW_GREEN_VALUE(value) << 8, DW_BLUE_VALUE(value) << 8 }; |
5217 return color; | 5214 return color; |
5218 } | 5215 } |
5231 { | 5228 { |
5232 int _locked_by_me = FALSE, index = _find_thread_index(dw_thread_id()); | 5229 int _locked_by_me = FALSE, index = _find_thread_index(dw_thread_id()); |
5233 GdkColor color = _internal_color(value); | 5230 GdkColor color = _internal_color(value); |
5234 | 5231 |
5235 DW_MUTEX_LOCK; | 5232 DW_MUTEX_LOCK; |
5236 if(!color.pixel) | 5233 gdk_color_alloc(_dw_cmap, &color); |
5237 gdk_color_alloc(_dw_cmap, &color); | |
5238 _foreground[index] = color; | 5234 _foreground[index] = color; |
5239 DW_MUTEX_UNLOCK; | 5235 DW_MUTEX_UNLOCK; |
5240 } | 5236 } |
5241 | 5237 |
5242 /* Sets the current background drawing color. | 5238 /* Sets the current background drawing color. |
5249 { | 5245 { |
5250 int _locked_by_me = FALSE, index = _find_thread_index(dw_thread_id()); | 5246 int _locked_by_me = FALSE, index = _find_thread_index(dw_thread_id()); |
5251 GdkColor color = _internal_color(value); | 5247 GdkColor color = _internal_color(value); |
5252 | 5248 |
5253 DW_MUTEX_LOCK; | 5249 DW_MUTEX_LOCK; |
5254 if(!color.pixel) | 5250 gdk_color_alloc(_dw_cmap, &color); |
5255 gdk_color_alloc(_dw_cmap, &color); | 5251 if(value == DW_CLR_DEFAULT) |
5252 _transparent[index] = 1; | |
5253 else | |
5254 _transparent[index] = 0; | |
5255 | |
5256 _background[index] = color; | 5256 _background[index] = color; |
5257 DW_MUTEX_UNLOCK; | 5257 DW_MUTEX_UNLOCK; |
5258 } | 5258 } |
5259 | 5259 |
5260 GdkGC *_set_colors(GdkWindow *window) | 5260 GdkGC *_set_colors(GdkWindow *window) |
5265 if(!window) | 5265 if(!window) |
5266 return NULL; | 5266 return NULL; |
5267 gc = gdk_gc_new(window); | 5267 gc = gdk_gc_new(window); |
5268 if(gc) | 5268 if(gc) |
5269 { | 5269 { |
5270 if(!_foreground[index].pixel) | 5270 gdk_gc_set_foreground(gc, &_foreground[index]); |
5271 gdk_gc_set_foreground(gc, &_foreground[index]); | 5271 gdk_gc_set_background(gc, &_background[index]); |
5272 if(!_background[index].pixel) | 5272 gdk_gc_set_colormap(gc, _dw_cmap); |
5273 gdk_gc_set_background(gc, &_background[index]); | |
5274 } | 5273 } |
5275 return gc; | 5274 return gc; |
5276 } | 5275 } |
5277 | 5276 |
5278 /* Draw a point on a window (preferably a render window). | 5277 /* Draw a point on a window (preferably a render window). |
5401 | 5400 |
5402 if(layout) | 5401 if(layout) |
5403 { | 5402 { |
5404 int index = _find_thread_index(dw_thread_id()); | 5403 int index = _find_thread_index(dw_thread_id()); |
5405 | 5404 |
5405 gdk_pango_context_set_colormap(context, _dw_cmap); | |
5406 pango_layout_set_font_description(layout, font); | 5406 pango_layout_set_font_description(layout, font); |
5407 pango_layout_set_text(layout, text, strlen(text)); | 5407 pango_layout_set_text(layout, text, strlen(text)); |
5408 | 5408 |
5409 if(_background[index].pixel) | 5409 if(_transparent[index]) |
5410 gdk_draw_layout(handle ? handle->window : pixmap->pixmap, gc, x, y + 2, layout); | 5410 gdk_draw_layout(handle ? handle->window : pixmap->pixmap, gc, x, y + 2, layout); |
5411 else | 5411 else |
5412 gdk_draw_layout_with_colors(handle ? handle->window : pixmap->pixmap, gc, x, y + 2, layout, &_foreground[index], &_background[index]); | 5412 gdk_draw_layout_with_colors(handle ? handle->window : pixmap->pixmap, gc, x, y + 2, layout, &_foreground[index], &_background[index]); |
5413 | 5413 |
5414 g_object_unref(layout); | 5414 g_object_unref(layout); |