comparison gtk/dw.c @ 633:87db549e79bc

Add dw_polygon_draw() to draw closed polygons. Fix bug in date items in container; date structure not initialised to zero. Add button_release as valid event in render box. Add support for transparency when bitblt'ing bitmaps from source bitmaps that have transparency. Fix off-by-one in dw_listbox_clear()
author mhessling@81767d24-ef19-dc11-ae90-00e081727c95
date Tue, 06 Jan 2009 11:00:15 +0000
parents a5deb87b26e4
children f6f887d2c5aa
comparison
equal deleted inserted replaced
632:bf3a6d596cd4 633:87db549e79bc
6421 else if(flag & DW_CFA_DATE) 6421 else if(flag & DW_CFA_DATE)
6422 { 6422 {
6423 struct tm curtm; 6423 struct tm curtm;
6424 CDATE cdate = *((CDATE *)data); 6424 CDATE cdate = *((CDATE *)data);
6425 6425
6426 memset( &curtm, 0, sizeof(curtm) );
6426 curtm.tm_mday = cdate.day; 6427 curtm.tm_mday = cdate.day;
6427 curtm.tm_mon = cdate.month - 1; 6428 curtm.tm_mon = cdate.month - 1;
6428 curtm.tm_year = cdate.year - 1900; 6429 curtm.tm_year = cdate.year - 1900;
6429 6430
6430 strftime(textbuffer, 100, "%x", &curtm); 6431 strftime(textbuffer, 100, "%x", &curtm);
6434 else if(flag & DW_CFA_TIME) 6435 else if(flag & DW_CFA_TIME)
6435 { 6436 {
6436 struct tm curtm; 6437 struct tm curtm;
6437 CTIME ctime = *((CTIME *)data); 6438 CTIME ctime = *((CTIME *)data);
6438 6439
6440 memset( &curtm, 0, sizeof(curtm) );
6439 curtm.tm_hour = ctime.hours; 6441 curtm.tm_hour = ctime.hours;
6440 curtm.tm_min = ctime.minutes; 6442 curtm.tm_min = ctime.minutes;
6441 curtm.tm_sec = ctime.seconds; 6443 curtm.tm_sec = ctime.seconds;
6442 6444
6443 strftime(textbuffer, 100, "%X", &curtm); 6445 strftime(textbuffer, 100, "%X", &curtm);
6997 DW_MUTEX_LOCK; 6999 DW_MUTEX_LOCK;
6998 tmp = gtk_drawing_area_new(); 7000 tmp = gtk_drawing_area_new();
6999 gtk_widget_set_events(tmp, GDK_EXPOSURE_MASK 7001 gtk_widget_set_events(tmp, GDK_EXPOSURE_MASK
7000 | GDK_LEAVE_NOTIFY_MASK 7002 | GDK_LEAVE_NOTIFY_MASK
7001 | GDK_BUTTON_PRESS_MASK 7003 | GDK_BUTTON_PRESS_MASK
7004 | GDK_BUTTON_RELEASE_MASK
7002 | GDK_KEY_PRESS_MASK 7005 | GDK_KEY_PRESS_MASK
7003 | GDK_POINTER_MOTION_MASK 7006 | GDK_POINTER_MOTION_MASK
7004 | GDK_POINTER_MOTION_HINT_MASK); 7007 | GDK_POINTER_MOTION_HINT_MASK);
7005 gtk_object_set_data(GTK_OBJECT(tmp), "_dw_id", GINT_TO_POINTER(id)); 7008 gtk_object_set_data(GTK_OBJECT(tmp), "_dw_id", GINT_TO_POINTER(id));
7006 GTK_WIDGET_SET_FLAGS(tmp, GTK_CAN_FOCUS); 7009 GTK_WIDGET_SET_FLAGS(tmp, GTK_CAN_FOCUS);
7234 gdk_gc_unref(gc); 7237 gdk_gc_unref(gc);
7235 } 7238 }
7236 DW_MUTEX_UNLOCK; 7239 DW_MUTEX_UNLOCK;
7237 } 7240 }
7238 7241
7239 /* Draw a rectangle on a window (preferably a render window). 7242 /* Draw a closed polygon on a window (preferably a render window).
7240 * Parameters: 7243 * Parameters:
7241 * handle: Handle to the window. 7244 * handle: Handle to the window.
7242 * pixmap: Handle to the pixmap. (choose only one of these) 7245 * pixmap: Handle to the pixmap. (choose only one of these)
7246 * fill: if true filled
7247 * number of points
7248 * x[]: X coordinates.
7249 * y[]: Y coordinates.
7250 */
7251 void dw_draw_polygon(HWND handle, HPIXMAP pixmap, int fill, int npoints, int *x, int *y)
7252 {
7253 int _locked_by_me = FALSE;
7254 int i;
7255 GdkGC *gc = NULL;
7256 GdkPoint *points;
7257
7258 DW_MUTEX_LOCK;
7259 if ( handle )
7260 gc = _set_colors( handle->window );
7261 else if ( pixmap )
7262 gc = _set_colors( pixmap->pixmap );
7263 if ( npoints )
7264 {
7265 points = alloca( npoints * sizeof(GdkPoint) );
7266 /*
7267 * should check for NULL pointer return!
7268 */
7269 for ( i = 0 ; i < npoints ; i++ )
7270 {
7271 points[i].x = x[i];
7272 points[i].y = y[i];
7273 }
7274 }
7275 if ( gc )
7276 {
7277 gdk_draw_polygon(handle ? handle->window : pixmap->pixmap, gc, fill, points, npoints );
7278 gdk_gc_unref( gc );
7279 }
7280 DW_MUTEX_UNLOCK;
7281 }
7282
7283 /* Draw a rectangle on a window (preferably a render window).
7284 * Parameters:
7285 * handle: Handle to the window.
7286 * pixmap: Handle to the pixmap. (choose only one of these)
7287 * fill: if true filled
7243 * x: X coordinate. 7288 * x: X coordinate.
7244 * y: Y coordinate. 7289 * y: Y coordinate.
7245 * width: Width of rectangle. 7290 * width: Width of rectangle.
7246 * height: Height of rectangle. 7291 * height: Height of rectangle.
7247 */ 7292 */
7481 */ 7526 */
7482 HPIXMAP dw_pixmap_new_from_file(HWND handle, char *filename) 7527 HPIXMAP dw_pixmap_new_from_file(HWND handle, char *filename)
7483 { 7528 {
7484 int _locked_by_me = FALSE; 7529 int _locked_by_me = FALSE;
7485 HPIXMAP pixmap; 7530 HPIXMAP pixmap;
7486 #ifndef USE_IMLIB
7487 GdkBitmap *bitmap = NULL;
7488 #endif
7489 #if GTK_MAJOR_VERSION > 1 7531 #if GTK_MAJOR_VERSION > 1
7490 GdkPixbuf *pixbuf; 7532 GdkPixbuf *pixbuf;
7491 #elif defined(USE_IMLIB) 7533 #elif defined(USE_IMLIB)
7492 GdkImlibImage *image; 7534 GdkImlibImage *image;
7493 #endif 7535 #endif
7513 DW_MUTEX_LOCK; 7555 DW_MUTEX_LOCK;
7514 #if GTK_MAJOR_VERSION > 1 7556 #if GTK_MAJOR_VERSION > 1
7515 pixbuf = gdk_pixbuf_new_from_file(file, NULL); 7557 pixbuf = gdk_pixbuf_new_from_file(file, NULL);
7516 pixmap->width = gdk_pixbuf_get_width(pixbuf); 7558 pixmap->width = gdk_pixbuf_get_width(pixbuf);
7517 pixmap->height = gdk_pixbuf_get_height(pixbuf); 7559 pixmap->height = gdk_pixbuf_get_height(pixbuf);
7518 gdk_pixbuf_render_pixmap_and_mask(pixbuf, &pixmap->pixmap, &bitmap, 1); 7560 gdk_pixbuf_render_pixmap_and_mask(pixbuf, &pixmap->pixmap, &pixmap->bitmap, 1);
7519 g_object_unref(pixbuf); 7561 g_object_unref(pixbuf);
7520 #elif defined(USE_IMLIB) 7562 #elif defined(USE_IMLIB)
7521 image = gdk_imlib_load_image(file); 7563 image = gdk_imlib_load_image(file);
7522 7564
7523 pixmap->width = image->rgb_width; 7565 pixmap->width = image->rgb_width;
7525 7567
7526 gdk_imlib_render(image, pixmap->width, pixmap->height); 7568 gdk_imlib_render(image, pixmap->width, pixmap->height);
7527 pixmap->pixmap = gdk_imlib_copy_image(image); 7569 pixmap->pixmap = gdk_imlib_copy_image(image);
7528 gdk_imlib_destroy_image(image); 7570 gdk_imlib_destroy_image(image);
7529 #else 7571 #else
7530 pixmap->pixmap = gdk_pixmap_create_from_xpm(handle->window, &bitmap, &_colors[DW_CLR_PALEGRAY], file); 7572 pixmap->pixmap = gdk_pixmap_create_from_xpm(handle->window, &pixmap->bitmap, &_colors[DW_CLR_PALEGRAY], file);
7531 #endif 7573 #endif
7532 pixmap->handle = handle; 7574 pixmap->handle = handle;
7533 DW_MUTEX_UNLOCK; 7575 DW_MUTEX_UNLOCK;
7534 return pixmap; 7576 return pixmap;
7535 } 7577 }
7548 { 7590 {
7549 int _locked_by_me = FALSE; 7591 int _locked_by_me = FALSE;
7550 char *file; 7592 char *file;
7551 FILE *fp; 7593 FILE *fp;
7552 HPIXMAP pixmap; 7594 HPIXMAP pixmap;
7553 #ifndef USE_IMLIB
7554 GdkBitmap *bitmap = NULL;
7555 #endif
7556 #if GTK_MAJOR_VERSION > 1 7595 #if GTK_MAJOR_VERSION > 1
7557 GdkPixbuf *pixbuf; 7596 GdkPixbuf *pixbuf;
7558 #elif defined(USE_IMLIB) 7597 #elif defined(USE_IMLIB)
7559 GdkImlibImage *image; 7598 GdkImlibImage *image;
7560 #endif 7599 #endif
7581 } 7620 }
7582 #if GTK_MAJOR_VERSION > 1 7621 #if GTK_MAJOR_VERSION > 1
7583 pixbuf = gdk_pixbuf_new_from_file(file, NULL); 7622 pixbuf = gdk_pixbuf_new_from_file(file, NULL);
7584 pixmap->width = gdk_pixbuf_get_width(pixbuf); 7623 pixmap->width = gdk_pixbuf_get_width(pixbuf);
7585 pixmap->height = gdk_pixbuf_get_height(pixbuf); 7624 pixmap->height = gdk_pixbuf_get_height(pixbuf);
7586 gdk_pixbuf_render_pixmap_and_mask(pixbuf, &pixmap->pixmap, &bitmap, 1); 7625 gdk_pixbuf_render_pixmap_and_mask(pixbuf, &pixmap->pixmap, &pixmap->bitmap, 1);
7587 g_object_unref(pixbuf); 7626 g_object_unref(pixbuf);
7588 #elif defined(USE_IMLIB) 7627 #elif defined(USE_IMLIB)
7589 image = gdk_imlib_load_image(file); 7628 image = gdk_imlib_load_image(file);
7590 7629
7591 pixmap->width = image->rgb_width; 7630 pixmap->width = image->rgb_width;
7593 7632
7594 gdk_imlib_render(image, pixmap->width, pixmap->height); 7633 gdk_imlib_render(image, pixmap->width, pixmap->height);
7595 pixmap->pixmap = gdk_imlib_copy_image(image); 7634 pixmap->pixmap = gdk_imlib_copy_image(image);
7596 gdk_imlib_destroy_image(image); 7635 gdk_imlib_destroy_image(image);
7597 #else 7636 #else
7598 pixmap->pixmap = gdk_pixmap_create_from_xpm_d(handle->window, &bitmap, &_colors[DW_CLR_PALEGRAY], data); 7637 pixmap->pixmap = gdk_pixmap_create_from_xpm_d(handle->window, &pixmap->bitmap, &_colors[DW_CLR_PALEGRAY], data);
7599 #endif 7638 #endif
7600 /* remove our temporary file */ 7639 /* remove our temporary file */
7601 unlink (file ); 7640 unlink (file );
7602 pixmap->handle = handle; 7641 pixmap->handle = handle;
7603 DW_MUTEX_UNLOCK; 7642 DW_MUTEX_UNLOCK;
7612 * Returns: 7651 * Returns:
7613 * A handle to a pixmap or NULL on failure. 7652 * A handle to a pixmap or NULL on failure.
7614 */ 7653 */
7615 HPIXMAP dw_pixmap_grab(HWND handle, ULONG id) 7654 HPIXMAP dw_pixmap_grab(HWND handle, ULONG id)
7616 { 7655 {
7617 GdkBitmap *bitmap = NULL;
7618 HPIXMAP pixmap; 7656 HPIXMAP pixmap;
7619 int _locked_by_me = FALSE; 7657 int _locked_by_me = FALSE;
7620 7658
7621 if (!(pixmap = calloc(1,sizeof(struct _hpixmap)))) 7659 if (!(pixmap = calloc(1,sizeof(struct _hpixmap))))
7622 return NULL; 7660 return NULL;
7623 7661
7624 7662
7625 DW_MUTEX_LOCK; 7663 DW_MUTEX_LOCK;
7626 pixmap->pixmap = _find_pixmap(&bitmap, id, handle, &pixmap->width, &pixmap->height); 7664 pixmap->pixmap = _find_pixmap(&pixmap->bitmap, id, handle, &pixmap->width, &pixmap->height);
7627 if(pixmap->pixmap) 7665 if(pixmap->pixmap)
7628 { 7666 {
7629 #if GTK_MAJOR_VERSION < 2 7667 #if GTK_MAJOR_VERSION < 2
7630 GdkPixmapPrivate *pvt = (GdkPixmapPrivate *)pixmap->pixmap; 7668 GdkPixmapPrivate *pvt = (GdkPixmapPrivate *)pixmap->pixmap;
7631 pixmap->width = pvt->width; pixmap->height = pvt->height; 7669 pixmap->width = pvt->width; pixmap->height = pvt->height;
7700 else if(destp) 7738 else if(destp)
7701 gc = gdk_gc_new(destp->pixmap); 7739 gc = gdk_gc_new(destp->pixmap);
7702 else if(srcp) 7740 else if(srcp)
7703 gc = gdk_gc_new(srcp->pixmap); 7741 gc = gdk_gc_new(srcp->pixmap);
7704 7742
7705 if(gc) 7743 if ( gc )
7706 { 7744 {
7707 gdk_draw_pixmap(dest ? dest->window : destp->pixmap, gc, src ? src->window : srcp->pixmap, xsrc, ysrc, xdest, ydest, width, height); 7745 /*
7708 gdk_gc_unref(gc); 7746 * If we have a bitmap (mask) in the source pixmap, then set the clipping region
7747 */
7748 if ( srcp->bitmap )
7749 {
7750 gdk_gc_set_clip_mask( gc, srcp->bitmap );
7751 gdk_gc_set_clip_origin( gc, xdest, ydest );
7752 }
7753 gdk_draw_pixmap( dest ? dest->window : destp->pixmap, gc, src ? src->window : srcp->pixmap, xsrc, ysrc, xdest, ydest, width, height );
7754 /*
7755 * Reset the clipping region
7756 */
7757 if ( srcp->bitmap )
7758 {
7759 gdk_gc_set_clip_mask( gc, NULL );
7760 gdk_gc_set_clip_origin( gc, 0, 0 );
7761 }
7762 gdk_gc_unref( gc );
7709 } 7763 }
7710 DW_MUTEX_UNLOCK; 7764 DW_MUTEX_UNLOCK;
7711 } 7765 }
7712 7766
7713 /* 7767 /*
8437 */ 8491 */
8438 DWTID dw_thread_new(void *func, void *data, int stack) 8492 DWTID dw_thread_new(void *func, void *data, int stack)
8439 { 8493 {
8440 DWTID gtkthread; 8494 DWTID gtkthread;
8441 void **tmp = malloc(sizeof(void *) * 2); 8495 void **tmp = malloc(sizeof(void *) * 2);
8496 int rc;
8442 8497
8443 tmp[0] = func; 8498 tmp[0] = func;
8444 tmp[1] = data; 8499 tmp[1] = data;
8445 8500
8446 pthread_create(&gtkthread, NULL, (void *)_dwthreadstart, (void *)tmp); 8501 rc = pthread_create(&gtkthread, NULL, (void *)_dwthreadstart, (void *)tmp);
8447 return gtkthread; 8502 if ( rc == 0 )
8503 return gtkthread;
8504 else
8505 return rc;
8448 } 8506 }
8449 8507
8450 /* 8508 /*
8451 * Ends execution of current thread immediately. 8509 * Ends execution of current thread immediately.
8452 */ 8510 */
9252 } 9310 }
9253 else if(GTK_IS_LIST(handle2)) 9311 else if(GTK_IS_LIST(handle2))
9254 { 9312 {
9255 int count = dw_listbox_count(handle); 9313 int count = dw_listbox_count(handle);
9256 9314
9257 gtk_list_clear_items(GTK_LIST(handle2), 0, count - 1); 9315 gtk_list_clear_items(GTK_LIST(handle2), 0, count);
9258 } 9316 }
9259 DW_MUTEX_UNLOCK; 9317 DW_MUTEX_UNLOCK;
9260 } 9318 }
9261 9319
9262 /* 9320 /*