comparison gtk/dw.c @ 1261:61d0c5f84644

Initial attempt at adding dw_draw_arc() support on all platforms. This code doesn't yet work... will probably require a bunch of fixes... but I wanted to get the code committed while doing research on it.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Tue, 25 Oct 2011 10:51:59 +0000
parents 3df86772b625
children 6b605b0700e8
comparison
equal deleted inserted replaced
1260:3cbd8de0b50b 1261:61d0c5f84644
26 #include <dirent.h> 26 #include <dirent.h>
27 #include <sys/stat.h> 27 #include <sys/stat.h>
28 #include <signal.h> 28 #include <signal.h>
29 #include <fcntl.h> 29 #include <fcntl.h>
30 #include <unistd.h> 30 #include <unistd.h>
31 #include <math.h>
31 #include <gdk/gdkkeysyms.h> 32 #include <gdk/gdkkeysyms.h>
32 #ifdef USE_IMLIB 33 #ifdef USE_IMLIB
33 #include <gdk_imlib.h> 34 #include <gdk_imlib.h>
34 #endif 35 #endif
35 36
8050 gdk_gc_unref(gc); 8051 gdk_gc_unref(gc);
8051 } 8052 }
8052 DW_MUTEX_UNLOCK; 8053 DW_MUTEX_UNLOCK;
8053 } 8054 }
8054 8055
8056 /* Draw an arc on a window (preferably a render window).
8057 * Parameters:
8058 * handle: Handle to the window.
8059 * pixmap: Handle to the pixmap. (choose only one of these)
8060 * flags: For future use.
8061 * xorigin: X coordinate of center of arc.
8062 * yorigin: Y coordinate of center of arc.
8063 * x1: X coordinate of first segment of arc.
8064 * y1: Y coordinate of first segment of arc.
8065 * x2: X coordinate of second segment of arc.
8066 * y2: Y coordinate of second segment of arc.
8067 */
8068 void API dw_draw_arc(HWND handle, HPIXMAP pixmap, int flags, int xorigin, int yorigin, int x1, int y1, int x2, int y2)
8069 {
8070 int _locked_by_me = FALSE;
8071 GdkGC *gc = NULL;
8072 #if GTK_CHECK_VERSION(2,10,0)
8073 cairo_t *cr = NULL;
8074 #endif
8075 double dx = xorigin - x1;
8076 double dy = yorigin - y1;
8077 double r = sqrt(dx*dx + dy*dy);
8078
8079 DW_MUTEX_LOCK;
8080 if(handle)
8081 gc = _set_colors(handle->window);
8082 else if(pixmap && pixmap->pixmap)
8083 gc = _set_colors(pixmap->pixmap);
8084 #if GTK_CHECK_VERSION(2,10,0)
8085 else if(pixmap && pixmap->image)
8086 cr = cairo_create(pixmap->image);
8087 if(cr)
8088 {
8089 GdkColor *foreground = pthread_getspecific(_dw_fg_color_key);
8090 double a1 = 180/M_PI * arctan((y1-yorigin)/(x1-xorigin));
8091 double a2 = 180/M_PI * arctan((y2-yorigin)/(x2-xorigin));
8092
8093 gdk_cairo_set_source_color (cr, foreground);
8094 cairo_set_line_width(cr, 1);
8095 cairo_arc(cr, xorigin, yorigin, r, a1, a2);
8096 cairo_stroke(cr);
8097 cairo_destroy(cr);
8098 }
8099 #endif
8100 if(gc)
8101 {
8102 double radius1 = 0, radius2 = 0;
8103 int alpha1, alpha2;
8104
8105 if(x1 == x2 && y1 == y2)
8106 {
8107 radius1 = 0.0;
8108 radius2 = 360.0;
8109 }
8110 else
8111 {
8112 radius1 = (x1 - xorigin == 0) ? (y1 - yc < 0) ? 90.0 : -90.0 : -atan2((double)y1-yc, (double)x1-xc) * RAD2DEG;
8113 radius2 = (x2 - xorigin == 0) ? (y2 - yc < 0) ? 90.0 : -90.0 : -atan2((double)y2-yc, (double)x2-xc) * RAD2DEG;
8114 }
8115 alpha1 = (int)(radius1 * 64.0);
8116 alpha2 = (int)((radius2 - radius1) * 64.0);
8117 while (alpha2 <= 0) alpha2 += 360*64;
8118 while (alpha1 > 360*64) alpha1 -= 360*64;
8119
8120 gdk_draw_arc(handle ? handle->window : pixmap->pixmap, gc, TRUE, xorigin-r, yorigin-r, 2*r,2*r, alpha1, alpha2);
8121 gdk_gc_unref(gc);
8122 }
8123 DW_MUTEX_UNLOCK;
8124 }
8125
8055 /* Draw text on a window (preferably a render window). 8126 /* Draw text on a window (preferably a render window).
8056 * Parameters: 8127 * Parameters:
8057 * handle: Handle to the window. 8128 * handle: Handle to the window.
8058 * pixmap: Handle to the pixmap. (choose only one of these) 8129 * pixmap: Handle to the pixmap. (choose only one of these)
8059 * x: X coordinate. 8130 * x: X coordinate.