/*! Display a string at the image point \e ip location. To select the font used to display the string, use setFont(). \param ip : Upper left image point location of the string in the display. \param text : String to display in overlay. \param color : String color. \sa setFont() */ void vpDisplayGTK::displayCharString ( const vpImagePoint &ip, const char *text, const vpColor &color ) { if (displayHasBeenInitialized) { if (color.id < vpColor::id_unknown) gdk_gc_set_foreground(gc, col[color.id]); else { gdkcolor.red = 256 * color.R; gdkcolor.green = 256 * color.G; gdkcolor.blue = 256 * color.B; gdk_colormap_alloc_color(colormap,&gdkcolor,FALSE,TRUE); gdk_gc_set_foreground(gc, &gdkcolor); } if (font != NULL) gdk_draw_string(background, font, gc, vpMath::round( ip.get_u() ), vpMath::round( ip.get_v() ), (const gchar *)text); else std::cout << "Cannot draw string: no font is selected" << std::endl; } else { vpERROR_TRACE("GTK not initialized " ) ; throw(vpDisplayException(vpDisplayException::notInitializedError, "GTK not initialized")) ; } }
static void draw_polygon (DiaRenderer *object, Point *points, int num_points, Color *fill, Color *stroke) { DiaGdkRenderer *renderer = DIA_GDK_RENDERER (object); GdkGC *gc = renderer->gc; GdkColor color; GdkPoint *gdk_points; int i,x,y; gdk_points = g_new(GdkPoint, num_points); for (i=0;i<num_points;i++) { dia_transform_coords(renderer->transform, points[i].x, points[i].y, &x, &y); gdk_points[i].x = x; gdk_points[i].y = y; } if (fill && fill->alpha > 0.0) { renderer_color_convert(renderer, fill, &color); gdk_gc_set_foreground(gc, &color); gdk_draw_polygon(renderer->pixmap, gc, TRUE, gdk_points, num_points); } if (stroke && stroke->alpha > 0.0) { renderer_color_convert(renderer, stroke, &color); gdk_gc_set_foreground(gc, &color); gdk_draw_polygon(renderer->pixmap, gc, FALSE, gdk_points, num_points); } g_free(gdk_points); }
/*! Display a line from image point \e ip1 to image point \e ip2. \param ip1,ip2 : Initial and final image points. \param color : Line color. \param thickness : Line thickness. */ void vpDisplayGTK::displayLine ( const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness ) { if (displayHasBeenInitialized) { if ( thickness == 1 ) thickness = 0; if (color.id < vpColor::id_unknown) gdk_gc_set_foreground(gc, col[color.id]); else { gdkcolor.red = 256 * color.R; gdkcolor.green = 256 * color.G; gdkcolor.blue = 256 * color.B; gdk_colormap_alloc_color(colormap,&gdkcolor,FALSE,TRUE); gdk_gc_set_foreground(gc, &gdkcolor); } gdk_gc_set_line_attributes(gc, (gint)thickness, GDK_LINE_SOLID, GDK_CAP_BUTT, GDK_JOIN_BEVEL) ; gdk_draw_line(background, gc, vpMath::round( ip1.get_u() ), vpMath::round( ip1.get_v() ), vpMath::round( ip2.get_u() ), vpMath::round( ip2.get_v() ) ); } else { vpERROR_TRACE("GTK not initialized " ) ; throw(vpDisplayException(vpDisplayException::notInitializedError, "GTK not initialized")) ; } }
static void on_main_win_realize(GtkWidget * widget, gpointer user_data) { GtkStyle *style; // Get the current style style = gtk_widget_get_style(main_win); // Create the pix gc pix_gc = gdk_gc_new(main_win->window); g_object_ref(pix_gc); gdk_gc_set_fill(pix_gc, GDK_TILED); bg_gc = gdk_gc_new(main_win->window); gdk_gc_copy(bg_gc, style->mid_gc[3]); g_object_ref(bg_gc); gdk_gc_set_fill(bg_gc, GDK_SOLID); last_gc = gdk_gc_new(main_win->window); gdk_gc_copy(last_gc, style->light_gc[3]); g_object_ref(last_gc); gdk_gc_set_fill(last_gc, GDK_SOLID); /* Use configuration options. They've already been loaded. */ gdk_colormap_alloc_color(gtk_widget_get_colormap(main_win), last_color, TRUE, TRUE); gdk_colormap_alloc_color(gtk_widget_get_colormap(main_win), back_color, TRUE, TRUE); g_object_set_data(G_OBJECT(main_win), "last_color", last_color); g_object_set_data(G_OBJECT(main_win), "back_color", back_color); gdk_gc_set_foreground(bg_gc, back_color); gdk_gc_set_foreground(last_gc, last_color); board_resized(); }
/* Draw the marker that indicates where the black point is */ static void drawBlackMarker(GdkDrawable *drawable, GtkWidget *greyramp) { GreyrampProperties *properties = greyrampGetProperties(greyramp); DotterContext *dc = properties->dwc->dotterCtx; GdkRectangle markerRect; getBlackMarkerRect(properties, &markerRect); /* Draw a triangle. Line color is the 'selected' color if dragging */ GdkColor *fillColor = getGdkColor(DOTCOLOR_MARKER_FILL, dc->defaultColors, FALSE, properties->dwc->usePrintColors); GdkColor *lineColor = getGdkColor(DOTCOLOR_MARKER_LINE, dc->defaultColors, properties->draggingBlack, properties->dwc->usePrintColors); int numPoints = 3; GdkPoint points[numPoints]; points[0].x = markerRect.x + (markerRect.width / 2); points[0].y = markerRect.y; points[1].x = markerRect.x; points[1].y = markerRect.y + markerRect.height; points[2].x = markerRect.x + markerRect.width; points[2].y = markerRect.y + markerRect.height; /* Draw fill in white and line in black (or green if dragging) */ GdkGC *gc = gdk_gc_new(drawable); gdk_gc_set_foreground(gc, fillColor); gdk_draw_polygon(drawable, gc, TRUE, points, numPoints); gdk_gc_set_foreground(gc, lineColor); gdk_draw_polygon(drawable, gc, FALSE, points, numPoints); g_object_unref(gc); }
static gint configure_event (GtkWidget *widget, GdkEventConfigure *e, C2NetworkTraffic *nt) { if (!nt->blue) { GdkColor blue = { 0, 0, 0, 0xffff }; GdkColor red = { 0, 0xffff, 0, 0 }; gdk_color_alloc (gdk_colormap_get_system (), &blue); gdk_color_alloc (gdk_colormap_get_system (), &red); nt->blue = gdk_gc_new (GTK_WIDGET (nt)->window); nt->red = gdk_gc_new (GTK_WIDGET (nt)->window); gdk_gc_set_foreground (nt->blue, &blue); gdk_gc_set_foreground (nt->red, &red); } if (nt->pixmap) gdk_pixmap_unref (nt->pixmap); nt->pixmap = gdk_pixmap_new (widget->window, widget->allocation.width, widget->allocation.height, -1); return TRUE; }
GdkBitmap * arc_clip_mask(gint width, gint height) { GdkBitmap *result; GdkGC *gc; GdkColor color; result = (GdkBitmap *)gdk_pixmap_new(NULL, width, height, 1); gc = gdk_gc_new(result); color.pixel = 0; gdk_gc_set_foreground(gc, &color); gdk_draw_rectangle(result, gc, TRUE, 0, 0, width, height); gdk_draw_rectangle(result, gc, FALSE, 0, 0, width, height); color.pixel = 1; gdk_gc_set_foreground(gc, &color); gdk_draw_arc(result, gc, TRUE, 0, 0, width, height, 0, 360*64); gdk_draw_arc(result, gc, FALSE, 0, 0, width, height, 0, 360*64); gdk_gc_destroy(gc); return result; }
gint configure_event( GtkWidget *widget, GdkEvent *event, gpointer data ) { int i; if( pixmap ) { g_object_unref( pixmap ); for( i = bg; i <= vp_frame; i++ ) gdk_gc_unref( gc[i] ); } pixmap = gdk_pixmap_new( widget->window, width, height, -1 ); for( i = bg; i <= ws_divider; i++ ) gdk_gc_set_foreground( gc[i] = gdk_gc_new( pixmap ), &colors[i] ); /* wishing for a nicer line style, like 3 on, 5 off, making this alternate for neighbouring VPs */ gdk_gc_set_line_attributes( gc[vp_divider], 1, GDK_LINE_ON_OFF_DASH, GDK_CAP_ROUND, GDK_JOIN_ROUND ); gdk_gc_set_foreground( gc[vp_frame] = gdk_gc_new( pixmap ), &colors[vp_divider] ); gdk_gc_set_line_attributes( gc[vp_frame], 1, GDK_LINE_ON_OFF_DASH, GDK_CAP_ROUND, GDK_JOIN_ROUND ); /* wishing for Gimp-style functions -- GDK is just too primitive */ /* gdk_gc_set_function( gc[vp_frame], GDK_XOR ); */ make_background(); draw_pager( widget ); return TRUE; }
static void gnucash_grid_realize (GnomeCanvasItem *item) { GdkWindow *window; GnucashGrid *gnucash_grid; GdkGC *gc; if (GNOME_CANVAS_ITEM_CLASS (gnucash_grid_parent_class)->realize) (GNOME_CANVAS_ITEM_CLASS (gnucash_grid_parent_class)->realize)(item); gnucash_grid = GNUCASH_GRID (item); window = gtk_widget_get_window (GTK_WIDGET (item->canvas)); /* Configure the default grid gc */ gnucash_grid->grid_gc = gc = gdk_gc_new (window); gnucash_grid->fill_gc = gdk_gc_new (window); gnucash_grid->gc = gdk_gc_new (window); /* Allocate the default colors */ gnucash_grid->background = gn_white; gnucash_grid->grid_color = gn_black; gnucash_grid->default_color = gn_black; gdk_gc_set_foreground (gc, &gnucash_grid->grid_color); gdk_gc_set_background (gc, &gnucash_grid->background); gdk_gc_set_foreground (gnucash_grid->fill_gc, &gnucash_grid->background); gdk_gc_set_background (gnucash_grid->fill_gc, &gnucash_grid->grid_color); }
/*! Display a point at the image point \e ip location. \param ip : Point location. \param color : Point color. */ void vpDisplayGTK::displayPoint ( const vpImagePoint &ip, const vpColor &color ) { if (displayHasBeenInitialized) { if (color.id < vpColor::id_unknown) gdk_gc_set_foreground(gc, col[color.id]); else { gdkcolor.red = 256 * color.R; gdkcolor.green = 256 * color.G; gdkcolor.blue = 256 * color.B; gdk_colormap_alloc_color(colormap,&gdkcolor,FALSE,TRUE); gdk_gc_set_foreground(gc, &gdkcolor); } gdk_draw_point(background,gc, vpMath::round( ip.get_u() ), vpMath::round( ip.get_v() ) ); } else { vpERROR_TRACE("GTK not initialized " ) ; throw(vpDisplayException(vpDisplayException::notInitializedError, "GTK not initialized")) ; } }
void SetPenAttr( GdkGC *fgGc, GdkGC *bgGc, curs_attr_t *attr ) { if( attr == NULL ) return; GdkColor colorFg; GdkColor colorBg; CvColorRGB( &colorFg, attr->fg ); CvColorRGB( &colorBg, attr->bg ); if( (attr->attr) & A_REVERSE ){ if( fgGc != NULL ){ gdk_gc_set_foreground( fgGc, &colorBg ); gdk_gc_set_background( fgGc, &colorFg ); } if( bgGc != NULL ){ gdk_gc_set_foreground( bgGc, &colorFg ); gdk_gc_set_background( bgGc, &colorBg ); } } else { if( fgGc != NULL ){ gdk_gc_set_foreground( fgGc, &colorFg ); gdk_gc_set_background( fgGc, &colorBg ); } if( bgGc != NULL ){ gdk_gc_set_foreground( bgGc, &colorBg ); gdk_gc_set_background( bgGc, &colorFg ); } } }
void _HYPlatformGraphicPane::_ErasePolygon (Ptr rgn) { if (rgn) { gdk_gc_set_foreground (theContext,&saveBG); _FillPolygon (rgn); gdk_gc_set_foreground (theContext,&saveFG); } }
void UI_buildui(IBusHandwriteEngine * engine) { GdkPixmap * pxmp; GdkGC * gc; GdkColor black, white; GdkColormap* colormap = gdk_colormap_get_system(); gdk_color_black(colormap, &black); gdk_color_white(colormap, &white); g_object_unref(colormap); int R = 5; if (!engine->drawpanel) //建立绘图窗口, 建立空点 { engine->drawpanel = gtk_window_new(GTK_WINDOW_POPUP); gtk_window_move((GtkWindow*) engine->drawpanel, 500, 550); gtk_widget_add_events(GTK_WIDGET(engine->drawpanel), GDK_POINTER_MOTION_MASK | GDK_BUTTON_RELEASE_MASK | GDK_BUTTON_PRESS_MASK | GDK_EXPOSURE_MASK); g_signal_connect_after(G_OBJECT(engine->drawpanel),"motion_notify_event",G_CALLBACK(on_mouse_move),engine); g_signal_connect(G_OBJECT(engine->drawpanel),"expose-event",G_CALLBACK(paint_ui),engine); g_signal_connect(G_OBJECT(engine->drawpanel),"button-release-event",G_CALLBACK(on_button),engine); g_signal_connect(G_OBJECT(engine->drawpanel),"button-press-event",G_CALLBACK(on_button),engine); gtk_window_resize(GTK_WINDOW(engine->drawpanel), 200, 250); gtk_widget_show(engine->drawpanel); pxmp = gdk_pixmap_new(NULL, 200, 250, 1); gc = gdk_gc_new(GDK_DRAWABLE(pxmp)); gdk_gc_set_foreground(gc, &black); gdk_draw_rectangle(GDK_DRAWABLE(pxmp), gc, 1, 0, 0, 200, 250); gdk_gc_set_foreground(gc, &white); gdk_draw_arc(GDK_DRAWABLE(pxmp), gc, 1, 0, 0, R*2, R*2, 0, 360 * 64); gdk_draw_arc(GDK_DRAWABLE(pxmp), gc, 1, 200 - R*2, 0, R*2, R*2, 0, 360 * 64); gdk_draw_arc(GDK_DRAWABLE(pxmp), gc, 1, 200 - R*2, 250 - R*2, R*2, R*2, 0, 360 * 64); gdk_draw_arc(GDK_DRAWABLE(pxmp), gc, 1, 0, 250 - R*2, R*2, R*2, 0, 360 * 64); gdk_draw_rectangle(GDK_DRAWABLE(pxmp), gc, 1, 0, R, 200, 250 - R*2); gdk_draw_rectangle(GDK_DRAWABLE(pxmp), gc, 1, R, 0, 200 - R*2, 250); gdk_window_shape_combine_mask(engine->drawpanel->window, pxmp, 0, 0); g_object_unref(gc); g_object_unref(pxmp); gtk_window_set_opacity(GTK_WINDOW(engine->drawpanel), 0.62); // engine->GdkPoints = NULL; } // gtk_widget_show_all(engine->drawpanel); }
static void draw(CtkCurve *ctk_curve) { CtrlTarget *ctrl_target = ctk_curve->ctrl_target; gushort *lut; gint n_lut_entries; #ifdef CTK_GTK3 /* Fill Curve surface with black background */ cairo_set_operator(ctk_curve->c_context, CAIRO_OPERATOR_SOURCE); cairo_set_source_rgba(ctk_curve->c_context, 0.0, 0.0, 0.0, 1.0); cairo_rectangle(ctk_curve->c_context, 0, 0, ctk_curve->width, ctk_curve->height); cairo_fill(ctk_curve->c_context); /* Add the Color LUT ramp lines */ cairo_set_operator(ctk_curve->c_context, CAIRO_OPERATOR_ADD); cairo_set_source_rgba(ctk_curve->c_context, 1.0, 0.0, 0.0, 1.0); NvCtrlGetColorRamp(ctrl_target, RED_CHANNEL, &lut, &n_lut_entries); plot_color_ramp(ctk_curve->c_context, lut, n_lut_entries, ctk_curve->width, ctk_curve->height); cairo_set_source_rgba(ctk_curve->c_context, 0.0, 1.0, 0.0, 1.0); NvCtrlGetColorRamp(ctrl_target, GREEN_CHANNEL, &lut, &n_lut_entries); plot_color_ramp(ctk_curve->c_context, lut, n_lut_entries, ctk_curve->width, ctk_curve->height); cairo_set_source_rgba(ctk_curve->c_context, 0.0, 0.0, 1.0, 1.0); NvCtrlGetColorRamp(ctrl_target, BLUE_CHANNEL, &lut, &n_lut_entries); plot_color_ramp(ctk_curve->c_context, lut, n_lut_entries, ctk_curve->width, ctk_curve->height); #else GtkWidget *widget = GTK_WIDGET(ctk_curve); gdk_gc_set_function(ctk_curve->gdk_gc, GDK_COPY); gdk_draw_rectangle(ctk_curve->gdk_pixmap, widget->style->black_gc, TRUE, 0, 0, ctk_curve->width, ctk_curve->height); gdk_gc_set_function(ctk_curve->gdk_gc, GDK_XOR); gdk_gc_set_foreground(ctk_curve->gdk_gc, &ctk_curve->gdk_color_red); NvCtrlGetColorRamp(ctrl_target, RED_CHANNEL, &lut, &n_lut_entries); plot_color_ramp(ctk_curve->gdk_pixmap, ctk_curve->gdk_gc, lut, n_lut_entries, ctk_curve->width, ctk_curve->height); gdk_gc_set_foreground(ctk_curve->gdk_gc, &ctk_curve->gdk_color_green); NvCtrlGetColorRamp(ctrl_target, GREEN_CHANNEL, &lut, &n_lut_entries); plot_color_ramp(ctk_curve->gdk_pixmap, ctk_curve->gdk_gc, lut, n_lut_entries, ctk_curve->width, ctk_curve->height); gdk_gc_set_foreground(ctk_curve->gdk_gc, &ctk_curve->gdk_color_blue); NvCtrlGetColorRamp(ctrl_target, BLUE_CHANNEL, &lut, &n_lut_entries); plot_color_ramp(ctk_curve->gdk_pixmap, ctk_curve->gdk_gc, lut, n_lut_entries, ctk_curve->width, ctk_curve->height); #endif }
/* Draw an exon */ static void drawExon(const MSP* const msp, DrawData *data, const BlxSequence *blxSeq, const gboolean isSelected, const gint x, const gint y, const gint widthIn, const gint heightIn) { /* Clip to the drawing area (or just beyond, so we don't get end lines where the exon doesn't really end) */ gint xStart = x; gint xEnd = x + widthIn; gint width = widthIn; const gint xMin = (data->horizontal ? data->exonViewRect->x : data->exonViewRect->y); const gint xMax = xMin + (data->horizontal ? data->exonViewRect->width : data->exonViewRect->height); if (xStart <= xMax && xEnd >= xMin) { if (xStart < xMin) { xStart = xMin - 1; width = xEnd - xStart; } if (xEnd > xMax) { xEnd = xMax + 1; width = xEnd - xStart; } /* Swap x and y if this is the vertical sequence */ int yStart = y; gint height = heightIn; if (!data->horizontal) { yStart = xStart; xStart = y; height = width; width = heightIn; } /* Draw the fill rectangle */ const GdkColor *fillColor = mspGetColor(msp, data->dc->defaultColors, DOTCOLOR_BACKGROUND, blxSeq, isSelected, data->dwc->usePrintColors, TRUE, DOTCOLOR_EXON_FILL, DOTCOLOR_EXON_LINE, DOTCOLOR_CDS_FILL, DOTCOLOR_CDS_LINE, DOTCOLOR_UTR_FILL, DOTCOLOR_UTR_LINE); gdk_gc_set_foreground(data->gc, fillColor); gdk_draw_rectangle(data->drawable, data->gc, TRUE, xStart, yStart, width, height); /* Draw outline (exon box outline always the same (unselected) color; only intron lines change when selected) */ const GdkColor *lineColor = mspGetColor(msp, data->dc->defaultColors, DOTCOLOR_BACKGROUND, blxSeq, isSelected, data->dwc->usePrintColors, FALSE, DOTCOLOR_EXON_FILL, DOTCOLOR_EXON_LINE, DOTCOLOR_CDS_FILL, DOTCOLOR_CDS_LINE, DOTCOLOR_UTR_FILL, DOTCOLOR_UTR_LINE); gdk_gc_set_foreground(data->gc, lineColor); gdk_draw_rectangle(data->drawable, data->gc, FALSE, xStart, yStart, width, height); } }
static void init_gc(void) { count_new = 0; calculate_standard_signal(); calculate_difficulty(); calculate_sensitivity(); count = 0; count_new = 0; count_standard_signal = border; /* border so that signal starts with low */ initial_count=0; // drawing is_stop=FALSE; is_pause=FALSE; mute=FALSE; image_volume_on = GTK_WIDGET(gtk_image_new_from_file("/home/pi/gtk_drawing/lautsprecher_mit.png")); gtk_button_set_image(GTK_BUTTON(cmd_mute), image_volume_on); gtk_button_set_label(GTK_BUTTON(cmd_pause), "Pause"); count = 0; count_new = 0; count_standard_signal = border; /* border so that signal starts with low */ gtk_widget_get_allocation(draw_area, &draw_area_size); g_print("width: %d \n height: %d \n", draw_area_size.width, draw_area_size.height); pixmap = gdk_pixmap_new(draw_area->window, 2*draw_area_size.width, draw_area_size.height, -1); gdk_colormap_alloc_color(gtk_widget_get_colormap(draw_area), &red, FALSE, TRUE); gdk_colormap_alloc_color(gtk_widget_get_colormap(draw_area), &black, FALSE, TRUE); gdk_colormap_alloc_color(gtk_widget_get_colormap(draw_area), &green, FALSE, TRUE); gc = gdk_gc_new(pixmap); *gc = *(draw_area->style->fg_gc[gtk_widget_get_state(draw_area)]); gdk_gc_set_foreground(gc, &red); gdk_gc_set_line_attributes(gc, 2, GDK_LINE_SOLID, GDK_CAP_NOT_LAST, GDK_JOIN_MITER); gcgr = gdk_gc_new(pixmap); *gcgr = *(draw_area->style->fg_gc[gtk_widget_get_state(draw_area)]); gdk_gc_set_foreground(gcgr, &green); gdk_gc_set_line_attributes(gcgr, 2, GDK_LINE_SOLID, GDK_CAP_NOT_LAST, GDK_JOIN_MITER); gcbl = gdk_gc_new(pixmap); // black graphic context *gcbl = *(draw_area->style->fg_gc[gtk_widget_get_state(draw_area)]); gdk_gc_set_foreground(gcbl, &black); gdk_gc_set_line_attributes(gcbl, 2, GDK_LINE_SOLID, GDK_CAP_NOT_LAST, GDK_JOIN_MITER); }
static void sanalyzer_init(void) { GdkColor color; int i; if(window) return; window = gtk_window_new(GTK_WINDOW_DIALOG); gtk_window_set_title(GTK_WINDOW(window),_("Spectrum analyzer")); gtk_window_set_policy(GTK_WINDOW(window), FALSE, FALSE, FALSE); gtk_widget_realize(window); bg_pixmap = gdk_pixmap_create_from_xpm_d(window->window,NULL,NULL,sanalyzer_xmms_logo_xpm); gdk_window_set_back_pixmap(window->window,bg_pixmap,0); gtk_signal_connect(GTK_OBJECT(window),"destroy",GTK_SIGNAL_FUNC(sanalyzer_destroy_cb),NULL); gtk_signal_connect(GTK_OBJECT(window), "destroy", GTK_SIGNAL_FUNC(gtk_widget_destroyed), &window); gtk_widget_set_usize(window, WIDTH, HEIGHT); gc = gdk_gc_new(window->window); draw_pixmap = gdk_pixmap_new(window->window,WIDTH,HEIGHT,gdk_rgb_get_visual()->depth); bar = gdk_pixmap_new(window->window,25, HEIGHT, gdk_rgb_get_visual()->depth); for(i = 0; i < HEIGHT / 2; i++) { color.red = 0xFFFF; color.green = ((i * 255) / (HEIGHT / 2)) << 8; color.blue = 0; gdk_color_alloc(gdk_colormap_get_system(),&color); gdk_gc_set_foreground(gc,&color); gdk_draw_line(bar,gc,0,i,24,i); } for(i = 0; i < HEIGHT / 2; i++) { color.red = (255 - ((i * 255) / (HEIGHT / 2))) <<8; color.green = 0xFFFF; color.blue = 0; gdk_color_alloc(gdk_colormap_get_system(),&color); gdk_gc_set_foreground(gc,&color); gdk_draw_line(bar,gc,0,i + (HEIGHT / 2),24,i + (HEIGHT / 2)); } scale = HEIGHT / log(256); gdk_color_black(gdk_colormap_get_system(),&color); gdk_gc_set_foreground(gc,&color); area = gtk_drawing_area_new(); gtk_container_add(GTK_CONTAINER(window),area); gtk_widget_realize(area); gdk_window_set_back_pixmap(area->window,bg_pixmap,0); gtk_widget_show(area); gtk_widget_show(window); gdk_window_clear(window->window); gdk_window_clear(area->window); }
void ghid_use_mask (int use_it) { static int mask_seq_id = 0; GdkColor color; render_priv *priv = gport->render_priv; if (!gport->pixmap) return; if (use_it == cur_mask) return; switch (use_it) { case HID_MASK_OFF: gport->drawable = gport->pixmap; mask_seq = 0; break; case HID_MASK_BEFORE: /* The HID asks not to receive this mask type, so warn if we get it */ g_return_if_reached (); case HID_MASK_CLEAR: if (!gport->mask) gport->mask = gdk_pixmap_new (0, gport->width, gport->height, 1); gport->drawable = gport->mask; mask_seq = 0; if (!priv->mask_gc) { priv->mask_gc = gdk_gc_new (gport->drawable); gdk_gc_set_clip_origin (priv->mask_gc, 0, 0); set_clip (priv, priv->mask_gc); } color.pixel = 1; gdk_gc_set_foreground (priv->mask_gc, &color); gdk_draw_rectangle (gport->drawable, priv->mask_gc, TRUE, 0, 0, gport->width, gport->height); color.pixel = 0; gdk_gc_set_foreground (priv->mask_gc, &color); break; case HID_MASK_AFTER: mask_seq_id++; if (!mask_seq_id) mask_seq_id = 1; mask_seq = mask_seq_id; gport->drawable = gport->pixmap; break; } cur_mask = use_it; }
void draw_baseline(int chan_num, int highlight) { scope_disp_t *disp = &(ctrl_usr->disp); scope_chan_t *chan = &(ctrl_usr->chan[chan_num - 1]); double yfoffset = chan->vert_offset; double ypoffset = chan->position * disp->height; double yscale = disp->height / (-10.0 * chan->scale); int y1 = -yfoffset * yscale + ypoffset;; if(highlight) { gdk_gc_set_foreground(disp->context, &(disp->color_grid)); } else { gdk_gc_set_foreground(disp->context, &(disp->color_baseline)); } line(chan_num | 0x100, 0, y1, disp->width, y1); }
static void linewidth_area_draw (GtkWidget *linewidth_area) { GdkColor *win_bg; GdkColor line; int width, height; int i; int x_offs; if (!linewidth_area_pixmap) /* we haven't gotten initial expose yet, * no point in drawing anything */ return; if (!linewidth_area_gc) { linewidth_area_gc = gdk_gc_new (linewidth_area_pixmap); gdk_gc_set_line_attributes(linewidth_area_gc, 1, GDK_LINE_ON_OFF_DASH, GDK_CAP_BUTT, GDK_JOIN_MITER); } gdk_drawable_get_size (linewidth_area_pixmap, &width, &height); win_bg = &(linewidth_area->style->bg[GTK_STATE_NORMAL]); line = color_gdk_black; gdk_gc_set_foreground (linewidth_area_gc, win_bg); gdk_draw_rectangle (linewidth_area_pixmap, linewidth_area_gc, 1, 0, 0, width, height); gdk_gc_set_foreground (linewidth_area_gc, &line); for (i=0;i<=NUMLINES;i++) { x_offs = X_OFFSET(i); gdk_draw_rectangle (linewidth_area_pixmap, linewidth_area_gc, 1, x_offs, 2, i, height-4); } if (active_linewidth != 0) { gdk_draw_rectangle (linewidth_area_pixmap, linewidth_area_gc, 0, X_OFFSET(active_linewidth)-2, 0, active_linewidth+4, height-1); } gdk_draw_drawable (linewidth_area->window, linewidth_area_gc, linewidth_area_pixmap, 0, 0, 0, 0, width, height); }
static void get_alpha_mask(float_shape_t *shape) { GdkColormap *colormap; GdkColor black; GdkColor white; GdkGC *gc; int rowstride, nchannels, x, y; guchar *pixels, *p; bool bright_green, has_alpha; colormap = gdk_colormap_get_system(); gdk_color_black(colormap, &black); gdk_color_white(colormap, &white); shape->mask_bitmap = (GdkDrawable*)gdk_pixmap_new(NULL, shape->width, shape->height, 1); gc = gdk_gc_new(shape->mask_bitmap); gdk_gc_set_foreground(gc, &black); gdk_gc_set_background(gc, &white); gdk_draw_rectangle(shape->mask_bitmap, gc, TRUE, 0, 0, shape->width, shape->height); nchannels = gdk_pixbuf_get_n_channels(shape->pixbuf); g_assert(gdk_pixbuf_get_colorspace(shape->pixbuf) == GDK_COLORSPACE_RGB); g_assert(gdk_pixbuf_get_bits_per_sample(shape->pixbuf) == 8); has_alpha = gdk_pixbuf_get_has_alpha(shape->pixbuf); rowstride = gdk_pixbuf_get_rowstride(shape->pixbuf); pixels = gdk_pixbuf_get_pixels(shape->pixbuf); gdk_gc_set_foreground(gc, &white); gdk_gc_set_background(gc, &black); for (y = 0; y < shape->height; y++) { for (x = 0; x < shape->width; x++) { p = pixels + y*rowstride + x*nchannels; bright_green = 0 == p[0] && 255 == p[1] && 0 == p[2]; if (has_alpha) { if (255 == p[3]) // p[3] is alpha channel gdk_draw_point(shape->mask_bitmap, gc, x, y); } else if (!bright_green) { // Bright green is alpha for RGB images gdk_draw_point(shape->mask_bitmap, gc, x, y); } } } }
static void draw (QCADDesignObject *obj, GdkDrawable *dst, GdkFunction rop) { GdkGC *gc = NULL ; char *pszFont = NULL ; GdkRectangle rc = {0} ; GdkRectangle rcDst = {0} ; GdkRectangle rcDraw = {0} ; QCADLabel *label = NULL ; if ((label = QCAD_LABEL (obj))->bShrinkWrap) qcad_label_shrinkwrap (label) ; world_to_real_rect (&(obj->bounding_box), &rc) ; gdk_drawable_get_size (dst, &(rcDst.width), &(rcDst.height)) ; if (!gdk_rectangle_intersect (&rc, &rcDst, &rcDraw)) return ; gc = gdk_gc_new (dst) ; gdk_gc_set_function (gc, rop) ; gdk_gc_set_clip_rectangle (gc, &rc) ; if (GDK_COPY == rop) { gdk_gc_set_foreground (gc, obj->bSelected ? &(QCAD_DESIGN_OBJECT_GET_CLASS (obj)->clrSelected) : &(obj->clr)) ; draw_string (dst, gc, pszFont = g_strdup_printf ("Courier %d", world_to_real_cy (CYFONT)), rc.x + XTOP_LABEL_OFFSET, rc.y + YTOP_LABEL_OFFSET, label->psz) ; g_free (pszFont) ; } else { if (label->bNeedsEPMDraw) { GdkGC *gcEPM = NULL ; label->bNeedsEPMDraw = FALSE ; label->epm = exp_pixmap_cond_new (label->epm, dst, rcDraw.width, rcDraw.height, -1) ; exp_pixmap_clean (label->epm) ; gcEPM = gdk_gc_new (label->epm->pixmap) ; gdk_gc_set_foreground (gcEPM, obj->bSelected ? &(QCAD_DESIGN_OBJECT_GET_CLASS (obj)->clrSelected) : &(obj->clr)) ; draw_string (label->epm->pixmap, gcEPM, pszFont = g_strdup_printf ("Courier %d", world_to_real_cy (CYFONT)), XTOP_LABEL_OFFSET, YTOP_LABEL_OFFSET, label->psz) ; g_free (pszFont) ; g_object_unref (gcEPM) ; } gdk_draw_drawable (dst, gc, label->epm->pixmap, 0, 0, rc.x, rc.y, rcDraw.width, rcDraw.height) ; } if (obj->bSelected) gdk_draw_rectangle (dst, gc, FALSE, rc.x, rc.y, rc.width - 1, rc.height - 1) ; gdk_gc_unref (gc) ; }
/*! Display a rectangle. \param topLeft : Top-left corner of the rectangle. \param bottomRight : Bottom-right corner of the rectangle. \param color : Rectangle color. \param fill : When set to true fill the rectangle. \param thickness : Thickness of the four lines used to display the rectangle. This parameter is only useful when \e fill is set to false. */ void vpDisplayGTK::displayRectangle ( const vpImagePoint &topLeft, const vpImagePoint &bottomRight, const vpColor &color, bool fill, unsigned int thickness ) { if (displayHasBeenInitialized) { if ( thickness == 1 ) thickness = 0; if (color.id < vpColor::id_unknown) gdk_gc_set_foreground(gc, col[color.id]); else { gdkcolor.red = 256 * color.R; gdkcolor.green = 256 * color.G; gdkcolor.blue = 256 * color.B; gdk_colormap_alloc_color(colormap,&gdkcolor,FALSE,TRUE); gdk_gc_set_foreground(gc, &gdkcolor); } gdk_gc_set_line_attributes(gc, (gint)thickness, GDK_LINE_SOLID, GDK_CAP_BUTT, GDK_JOIN_BEVEL) ; int w = vpMath::round( bottomRight.get_u() - topLeft.get_u() ); int h = vpMath::round( bottomRight.get_v() - topLeft.get_v() ); if (fill == false) gdk_draw_rectangle(background, gc, FALSE, vpMath::round( topLeft.get_u() ), vpMath::round( topLeft.get_v() ), w-1,h-1); else gdk_draw_rectangle(background, gc, TRUE, vpMath::round( topLeft.get_u() ), vpMath::round( topLeft.get_v() ), w, h); if (thickness > 1) gdk_gc_set_line_attributes(gc, 0, GDK_LINE_SOLID, GDK_CAP_BUTT, GDK_JOIN_BEVEL) ; } else { vpERROR_TRACE("GTK not initialized " ) ; throw(vpDisplayException(vpDisplayException::notInitializedError, "GTK not initialized")) ; } }
void update_options(GtkButton * button, gpointer user_data) { GtkWidget *last = lookup_widget(user_data, "last_button"); GtkWidget *back = lookup_widget(user_data, "back_button"); back_color = g_object_get_data(G_OBJECT(back), "color"); last_color = g_object_get_data(G_OBJECT(last), "color"); g_object_set_data(G_OBJECT(main_win), "last_color", last_color); g_object_set_data(G_OBJECT(main_win), "back_color", back_color); gdk_gc_set_foreground(bg_gc, back_color); gdk_gc_set_foreground(last_gc, last_color); display_board(); }
static void sample_display_realize (GtkWidget *widget) { GdkWindowAttr attributes; gint attributes_mask; SampleDisplay *s; g_return_if_fail (widget != NULL); g_return_if_fail (IS_SAMPLE_DISPLAY (widget)); GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED); s = SAMPLE_DISPLAY(widget); attributes.x = widget->allocation.x; attributes.y = widget->allocation.y; attributes.width = widget->allocation.width; attributes.height = widget->allocation.height; attributes.wclass = GDK_INPUT_OUTPUT; attributes.window_type = GDK_WINDOW_CHILD; attributes.event_mask = gtk_widget_get_events (widget) | GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK; attributes.visual = gtk_widget_get_visual (widget); attributes.colormap = gtk_widget_get_colormap (widget); attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP; widget->window = gdk_window_new (widget->parent->window, &attributes, attributes_mask); widget->style = gtk_style_attach (widget->style, widget->window); s->bg_gc = gdk_gc_new(widget->window); s->fg_gc = gdk_gc_new(widget->window); s->zeroline_gc = gdk_gc_new(widget->window); gdk_gc_set_foreground(s->bg_gc, &SAMPLE_DISPLAY_CLASS(GTK_OBJECT_GET_CLASS(widget))->colors[SAMPLE_DISPLAYCOL_BG]); gdk_gc_set_foreground(s->fg_gc, &SAMPLE_DISPLAY_CLASS(GTK_OBJECT_GET_CLASS(widget))->colors[SAMPLE_DISPLAYCOL_FG]); gdk_gc_set_foreground(s->zeroline_gc, &SAMPLE_DISPLAY_CLASS(GTK_OBJECT_GET_CLASS(widget))->colors[SAMPLE_DISPLAYCOL_ZERO]); if(s->edit) { s->loop_gc = gdk_gc_new(widget->window); s->mixerpos_gc = gdk_gc_new(widget->window); gdk_gc_set_foreground(s->loop_gc, &SAMPLE_DISPLAY_CLASS(GTK_OBJECT_GET_CLASS(widget))->colors[SAMPLE_DISPLAYCOL_LOOP]); gdk_gc_set_foreground(s->mixerpos_gc, &SAMPLE_DISPLAY_CLASS(GTK_OBJECT_GET_CLASS(widget))->colors[SAMPLE_DISPLAYCOL_MIXERPOS]); } sample_display_init_display(s, attributes.width, attributes.height); gdk_window_set_user_data (widget->window, widget); }
/* passe en mode color, decharge le pixmap (mais pas le nom) */ void tansetcolormode(GdkColor *acolor, int gcnbr){ GdkPixmap *pixmap; GdkGC *gc; GdkColor *pcolor; GdkColormap *syscmap; gc = tabgc[gcnbr]; pcolor = &colortab[gcnbr]; syscmap = gdk_colormap_get_system(); if (tabcolalloc[gcnbr]) gdk_colormap_free_colors (syscmap, pcolor, 1); if ( gcnbr>=PXSTART && gcnbr<PXSTART+PXNBR ){ tabpxpixmode[gcnbr] = FALSE; if ( (pixmap = tabpxpx[gcnbr])!=NULL ){ tabpxpx[gcnbr] = NULL; gdk_pixmap_unref(pixmap); } } pcolor->red = acolor->red; pcolor->green = acolor->green; pcolor->blue = acolor->blue; tabcolalloc[gcnbr] = gdk_colormap_alloc_color (syscmap, pcolor, FALSE, TRUE); gdk_gc_set_fill (gc, GDK_SOLID); gdk_gc_set_foreground (gc, pcolor); }
/* ***************************************************************************** * Draw Text (lat/lon) into Grid */ void draw_grid_text (GtkWidget * widget, gdouble posx, gdouble posy, gchar * txt) { /* prints in pango */ PangoFontDescription *pfd; PangoLayout *grid_label_layout; gint width, height; grid_label_layout = gtk_widget_create_pango_layout (map_drawingarea, txt); pfd = pango_font_description_from_string ("Sans 8"); pango_layout_set_font_description (grid_label_layout, pfd); pango_layout_get_pixel_size (grid_label_layout, &width, &height); gdk_gc_set_function (kontext_map, GDK_XOR); gdk_gc_set_background (kontext_map, &colors.white); gdk_gc_set_foreground (kontext_map, &colors.mygray); gdk_draw_layout_with_colors (drawable, kontext_map, posx - width / 2, posy - height / 2, grid_label_layout, &colors.black, NULL); if (grid_label_layout != NULL) g_object_unref (G_OBJECT (grid_label_layout)); /* freeing PangoFontDescription, cause it has been copied by prev. call */ pango_font_description_free (pfd); }
/************************************************************************** Draws a rectangle with top left corner at (canvas_x, canvas_y), and width 'w' and height 'h'. It is drawn using the 'selection_gc' context, so the pixel combining function is XOR. This means that drawing twice in the same place will restore the image to its original state. NB: A side effect of this function is to set the 'selection_gc' color to COLOR_MAPVIEW_SELECTION. **************************************************************************/ void draw_selection_rectangle(int canvas_x, int canvas_y, int w, int h) { GdkPoint points[5]; struct color *pcolor; if (w == 0 || h == 0) { return; } pcolor = get_color(tileset, COLOR_MAPVIEW_SELECTION); if (!pcolor) { return; } /* gdk_draw_rectangle() must start top-left.. */ points[0].x = canvas_x; points[0].y = canvas_y; points[1].x = canvas_x + w; points[1].y = canvas_y; points[2].x = canvas_x + w; points[2].y = canvas_y + h; points[3].x = canvas_x; points[3].y = canvas_y + h; points[4].x = canvas_x; points[4].y = canvas_y; gdk_gc_set_foreground(selection_gc, &pcolor->color); gdk_draw_lines(map_canvas->window, selection_gc, points, ARRAY_SIZE(points)); }
void cl_draw_menuitem_gradient (GdkDrawable *window, GtkWidget *widget, GtkStyle *style, GdkRectangle *area, GtkStateType state_type, int x, int y, int width, int height, CLRectangle *r) { ClearlooksStyle *clearlooks_style = (ClearlooksStyle*)style; gboolean menubar = (widget->parent && GTK_IS_MENU_BAR(widget->parent)) ? TRUE : FALSE; GdkColor tmp; GdkColor lower_color; shade (&style->base[GTK_STATE_SELECTED], &lower_color, 0.8); cl_rectangle_set_corners (r, CL_CORNER_NARROW, CL_CORNER_NARROW, CL_CORNER_NARROW, CL_CORNER_NARROW); cl_rectangle_set_gradient (&r->fill_gradient, &style->base[GTK_STATE_SELECTED], &lower_color); r->gradient_type = CL_GRADIENT_VERTICAL; tmp = cl_gc_set_fg_color_shade (style->black_gc, style->colormap, &style->base[GTK_STATE_PRELIGHT], 0.8); r->bordergc = style->black_gc; r->fillgc = style->base_gc[GTK_STATE_PRELIGHT]; if (menubar) height++; cl_rectangle_set_clip_rectangle (r, area); cl_draw_rectangle (window, widget, style, x, y, width, height, r); cl_rectangle_reset_clip_rectangle (r); gdk_gc_set_foreground (style->black_gc, &tmp); }
void gpk_rectangle_draw(GtkWidget *widget, /* plot on this widged */ gdouble *xcord, gdouble *ycord, /* corners */ gdouble xmn,gdouble ymn, /* coordinates of corners */ gdouble xmx,gdouble ymx, GdkColor *color) { GdkPixmap **ppixmap; GdkPoint points[2]; int i; gint16 width,height; GdkGC *gc; gc = gdk_gc_new(widget->window); gdk_gc_set_foreground(gc, color); if ((ppixmap=findpixmap(widget))) { width = widget->allocation.width; height = widget->allocation.height; for (i=0; i<2 ; i++) { points[i].x =.5+ ((xcord[i]-xmn)*(width-1)/(xmx-xmn)); points[i].y =.5+ ((ycord[i]-ymx)*(height-1)/(ymn-ymx)); } width=points[1].x-points[0].x + 1; height=points[1].y-points[0].y + 1; gdk_draw_rectangle(*ppixmap,gc,TRUE, points[0].x,points[0].y,width,height); gpk_redraw(*ppixmap,widget); } gdk_gc_destroy(gc); }