void load_graph_set_color(LoadGraph * lg, LoadGraphColor color) { lg->color = color; gdk_rgb_gc_set_foreground(lg->trace, lg->color); gdk_rgb_gc_set_foreground(lg->fill, lg->color - 0x303030); gdk_rgb_gc_set_foreground(lg->grid, lg->color - 0xcdcdcd); }
gint wgra_configure(GtkWidget *widget,GdkEventConfigure *ee,gpointer data) { GdkGC *mygc; int x,y,cx,xs; int i,v; long max; float fac; GdkFont *fn; if (wcanvas!=NULL) gdk_pixmap_unref(wcanvas); mygc=gdk_gc_new(widget->window); wcanvas=gdk_pixmap_new(widget->window,x=widget->allocation.width, y=widget->allocation.height,-1); gdk_draw_rectangle(wcanvas,widget->style->white_gc,TRUE,0,0,x,y); gdk_draw_rectangle(wcanvas,widget->style->black_gc,FALSE,0,0,x-1,y-1); max=0; for(i=0;i<7;i++) if (weekly[i]>max) max=weekly[i]; if (!max) max=1; fac=((float)(y-18-16))/((float)max); cx=1; xs=(x-2)/7; fn=gdk_font_load("-*-helvetica-medium-r-*-*-8-*-*-*-*-*-*-*"); for (i=0;i<7;i++) { v=(int)(((float)weekly[i])*fac); gdk_rgb_gc_set_foreground(mygc,0xc0c0c0); gdk_draw_line(wcanvas,mygc,cx,1,cx,y-2); gdk_rgb_gc_set_foreground(mygc,0x004080); gdk_draw_rectangle(wcanvas,mygc,TRUE,cx,y-18-v,xs,v); gdk_rgb_gc_set_foreground(mygc,0x000000); gdk_draw_string(wcanvas,fn,mygc,cx,y-6,wdays[i]); cx+=xs; } gdk_draw_line(wcanvas,widget->style->black_gc,0,y-18,x-1,y-18); gdk_rgb_gc_set_foreground(mygc,0xffffff); gdk_draw_rectangle(wcanvas,mygc,TRUE,0,0,23*4,13); gdk_rgb_gc_set_foreground(mygc,0x000000); gdk_draw_rectangle(wcanvas,mygc,FALSE,0,0,23*4,13); gdk_font_unref(fn); fn=gdk_font_load("-*-helvetica-medium-r-*-*-10-*-*-*-*-*-*-*"); gdk_draw_string(wcanvas,fn,mygc,5,10,"weekday summary"); gdk_font_unref(fn); gdk_gc_destroy(mygc); return FALSE; }
void draw_swatch_color (GtkWidget * widget, HSV hsv) { GdkGC * black_gc, * color_gc; RGB rgb; guint32 rgb32 = 0; gint width, height, x, y; GdkPixbuf * brightness; GtkAllocation allocation; brightness = g_object_get_data(G_OBJECT (widget), DATA_V_PIXBUF); hsv_to_rgb(&hsv, &rgb); rgb32 = ((int) (rgb.R * 255.0)) << 16 | ((int) (rgb.G * 255.0)) << 8 | ((int) (rgb.B * 255.0)); black_gc = gdk_gc_new(gtk_widget_get_window(widget)); color_gc = gdk_gc_new(gtk_widget_get_window(widget)); gdk_rgb_gc_set_foreground(black_gc, 0); gdk_rgb_gc_set_foreground(color_gc, rgb32); width = gdk_pixbuf_get_width(brightness); gtk_widget_get_allocation(widget, &allocation); height = (allocation.height - 2*COLORWHEEL_SELECT) * COLORWHEEL_SWATCH_HEIGHT; x = allocation.width - width - COLORWHEEL_SELECT; y = allocation.height - COLORWHEEL_SELECT - height; gdk_draw_rectangle (gtk_widget_get_window(widget), black_gc, FALSE, x, y, width - 1, height - 1 ); gdk_draw_rectangle (gtk_widget_get_window(widget), color_gc, TRUE, x + 1, y + 1, width - 2, height - 2 ); gdk_gc_unref(black_gc); gdk_gc_unref(color_gc); }
void draw_selected_color (GtkWidget * widget, HSV hsv, GdkPixbuf **pixbufs) { GdkGC * gc; float angle, radius; GdkPixbuf * colorwheel, * brightness; gint xcenter, ycenter, x, y, width, height; GtkAllocation allocation; gc = gdk_gc_new(gtk_widget_get_window(widget)); gdk_rgb_gc_set_foreground(gc, 0); colorwheel = g_object_get_data(G_OBJECT (widget), DATA_HS_PIXBUF); brightness = g_object_get_data(G_OBJECT (widget), DATA_V_PIXBUF); width = gdk_pixbuf_get_width(brightness); height = gdk_pixbuf_get_height(brightness); gtk_widget_get_allocation(widget, &allocation); x = allocation.width - gdk_pixbuf_get_width(brightness) - 2*COLORWHEEL_SELECT; y = (1.0 - hsv.V) * (float) gdk_pixbuf_get_height(brightness); gdk_draw_line( gtk_widget_get_window(widget), gc, x, y + COLORWHEEL_SELECT, allocation.width, COLORWHEEL_SELECT + y); /* Hue is 0..6 */ angle = (hsv.H / 3) * (M_PI); radius = (hsv.S * gdk_pixbuf_get_width(colorwheel)) / 2.0; x = radius * cos (angle); y = radius * sin (angle); width = gdk_pixbuf_get_width(pixbufs[PM_COLOR_SEL]); height = gdk_pixbuf_get_height(pixbufs[PM_COLOR_SEL]); xcenter = allocation.height / 2.0; // Use height on purpose ycenter = allocation.height / 2.0; gdk_pixbuf_render_to_drawable_alpha( pixbufs[PM_COLOR_SEL], gtk_widget_get_window(widget), 0, 0, (xcenter + x) - width/2, (ycenter + y) - height/2, width, height, GDK_PIXBUF_ALPHA_FULL, 127, GDK_RGB_DITHER_NORMAL, 0, 0); gdk_gc_unref(gc); }
void load_graph_configure_expose(LoadGraph * lg) { /* creates the backing store pixmap */ gtk_widget_realize(lg->area); lg->buf = gdk_pixmap_new(lg->area->window, lg->width, lg->height, -1); /* create the graphic contexts */ lg->grid = gdk_gc_new(GDK_DRAWABLE(lg->buf)); lg->trace = gdk_gc_new(GDK_DRAWABLE(lg->buf)); lg->fill = gdk_gc_new(GDK_DRAWABLE(lg->buf)); /* the default color is green */ load_graph_set_color(lg, LG_COLOR_GREEN); /* init graphic contexts */ gdk_gc_set_line_attributes(lg->grid, 1, GDK_LINE_ON_OFF_DASH, GDK_CAP_NOT_LAST, GDK_JOIN_ROUND); gdk_gc_set_dashes(lg->grid, 0, (gint8*)"\2\2", 2); #if 0 /* old-style grid */ gdk_rgb_gc_set_foreground(lg->grid, 0x707070); #endif gdk_gc_set_line_attributes(lg->trace, 1, GDK_LINE_SOLID, GDK_CAP_PROJECTING, GDK_JOIN_ROUND); #if 0 /* old-style fill */ gdk_gc_set_line_attributes(lg->fill, 1, GDK_LINE_SOLID, GDK_CAP_BUTT, GDK_JOIN_BEVEL); #endif /* configures the expose event */ g_signal_connect(G_OBJECT(lg->area), "expose-event", (GCallback) _expose, lg); }