void iupDrawText(IdrawCanvas* dc, const char* text, int len, int x, int y, unsigned char r, unsigned char g, unsigned char b, const char* font) { PangoLayout* fontlayout = (PangoLayout*)iupgtkGetPangoLayout(font); GdkColor color; iupgdkColorSet(&color, r, g, b); gdk_gc_set_rgb_fg_color(dc->pixmap_gc, &color); pango_layout_set_text(fontlayout, iupgtkStrConvertToUTF8(text), len); gdk_draw_layout(dc->pixmap, dc->pixmap_gc, x, y, fontlayout); }
void iupDrawRectangleInvert(IdrawCanvas* dc, int x1, int y1, int x2, int y2) { GdkColor color; iupgdkColorSet(&color, 255, 255, 255); gdk_gc_set_rgb_fg_color(dc->pixmap_gc, &color); gdk_gc_set_function(dc->pixmap_gc, GDK_XOR); gdk_draw_rectangle(dc->pixmap, dc->pixmap_gc, TRUE, x1, y1, x2-x1+1, y2-y1+1); gdk_gc_set_function(dc->pixmap_gc, GDK_COPY); }
void iupdrvDrawLine(IdrawCanvas* dc, int x1, int y1, int x2, int y2, unsigned char r, unsigned char g, unsigned char b, int style) { GdkColor color; iupgdkColorSet(&color, r, g, b); gdk_gc_set_rgb_fg_color(dc->pixmap_gc, &color); iDrawSetLineStyle(dc, style); gdk_draw_line(dc->pixmap, dc->pixmap_gc, x1, y1, x2, y2); }
void iupdrvDrawLine(IdrawCanvas* dc, int x1, int y1, int x2, int y2, long color, int style, int line_width) { GdkColor c; iupgdkColorSet(&c, color); gdk_gc_set_rgb_fg_color(dc->pixmap_gc, &c); iDrawSetLineWidth(dc, line_width); iDrawSetLineStyle(dc, style); gdk_draw_line(dc->pixmap, dc->pixmap_gc, x1, y1, x2, y2); }
void iupdrvDrawPolygon(IdrawCanvas* dc, int* points, int count, unsigned char r, unsigned char g, unsigned char b, int style) { GdkColor color; iupgdkColorSet(&color, r, g, b); gdk_gc_set_rgb_fg_color(dc->pixmap_gc, &color); if (style!=IUP_DRAW_FILL) iDrawSetLineStyle(dc, style); gdk_draw_polygon(dc->pixmap, dc->pixmap_gc, style==IUP_DRAW_FILL, (GdkPoint*)points, count); }
void iupdrvDrawArc(IdrawCanvas* dc, int x1, int y1, int x2, int y2, double a1, double a2, unsigned char r, unsigned char g, unsigned char b, int style) { GdkColor color; iupgdkColorSet(&color, r, g, b); gdk_gc_set_rgb_fg_color(dc->pixmap_gc, &color); if (style!=IUP_DRAW_FILL) iDrawSetLineStyle(dc, style); gdk_draw_arc(dc->pixmap, dc->pixmap_gc, style == IUP_DRAW_FILL, x1, y1, x2 - x1 + 1, y2 - y1 + 1, iupRound(a1 * 64), iupRound((a2 - a1) * 64)); }
void iupDrawLine(IdrawCanvas* dc, int x1, int y1, int x2, int y2, unsigned char r, unsigned char g, unsigned char b, int style) { GdkGCValues gcval; GdkColor color; iupgdkColorSet(&color, r, g, b); gdk_gc_set_rgb_fg_color(dc->pixmap_gc, &color); if (style==IUP_DRAW_STROKE_DASH) gcval.line_style = GDK_LINE_ON_OFF_DASH; else gcval.line_style = GDK_LINE_SOLID; gdk_gc_set_values(dc->pixmap_gc, &gcval, GDK_GC_LINE_STYLE); gdk_draw_line(dc->pixmap, dc->pixmap_gc, x1, y1, x2, y2); }
void iupdrvDrawRectangle(IdrawCanvas* dc, int x1, int y1, int x2, int y2, unsigned char r, unsigned char g, unsigned char b, int style) { GdkColor color; iupgdkColorSet(&color, r, g, b); gdk_gc_set_rgb_fg_color(dc->pixmap_gc, &color); if (style==IUP_DRAW_FILL) gdk_draw_rectangle(dc->pixmap, dc->pixmap_gc, TRUE, x1, y1, x2-x1+1, y2-y1+1); else { iDrawSetLineStyle(dc, style); gdk_draw_rectangle(dc->pixmap, dc->pixmap_gc, FALSE, x1, y1, x2-x1, y2-y1); /* outlined rectangle is actually of size w+1,h+1 */ } }
void iupdrvDrawPolygon(IdrawCanvas* dc, int* points, int count, long color, int style, int line_width) { GdkColor c; iupgdkColorSet(&c, color); gdk_gc_set_rgb_fg_color(dc->pixmap_gc, &c); if (style != IUP_DRAW_FILL) { iDrawSetLineWidth(dc, line_width); iDrawSetLineStyle(dc, style); } if (style == IUP_DRAW_FILL) gdk_draw_polygon(dc->pixmap, dc->pixmap_gc, TRUE, (GdkPoint*)points, count); else gdk_draw_lines(dc->pixmap, dc->pixmap_gc, (GdkPoint*)points, count); }
void iupdrvDrawArc(IdrawCanvas* dc, int x1, int y1, int x2, int y2, double a1, double a2, long color, int style, int line_width) { GdkColor c; iupgdkColorSet(&c, color); gdk_gc_set_rgb_fg_color(dc->pixmap_gc, &c); iupDrawCheckSwapCoord(x1, x2); iupDrawCheckSwapCoord(y1, y2); if (style != IUP_DRAW_FILL) { iDrawSetLineWidth(dc, line_width); iDrawSetLineStyle(dc, style); } /* using x2-x1+1 was resulting in a pixel larger arc */ gdk_draw_arc(dc->pixmap, dc->pixmap_gc, style == IUP_DRAW_FILL, x1, y1, x2 - x1, y2 - y1, iupRound(a1 * 64), iupRound((a2 - a1) * 64)); /* angle = 1/64ths of a degree */ }
void iupDrawArc(IdrawCanvas* dc, int x1, int y1, int x2, int y2, double a1, double a2, unsigned char r, unsigned char g, unsigned char b, int style) { GdkColor color; iupgdkColorSet(&color, r, g, b); gdk_gc_set_rgb_fg_color(dc->pixmap_gc, &color); if (style!=IUP_DRAW_FILL) { GdkGCValues gcval; if (style==IUP_DRAW_STROKE_DASH) gcval.line_style = GDK_LINE_ON_OFF_DASH; else gcval.line_style = GDK_LINE_SOLID; gdk_gc_set_values(dc->pixmap_gc, &gcval, GDK_GC_LINE_STYLE); } gdk_draw_arc(dc->pixmap, dc->pixmap_gc, style==IUP_DRAW_FILL, x1, y1, x2-x1+1, y2-y1+1, iupROUND(a1*64), iupROUND((a2 - a1)*64)); }
void iupDrawPolygon(IdrawCanvas* dc, int* points, int count, unsigned char r, unsigned char g, unsigned char b, int style) { GdkColor color; iupgdkColorSet(&color, r, g, b); gdk_gc_set_rgb_fg_color(dc->pixmap_gc, &color); if (style!=IUP_DRAW_FILL) { GdkGCValues gcval; if (style==IUP_DRAW_STROKE_DASH) gcval.line_style = GDK_LINE_ON_OFF_DASH; else gcval.line_style = GDK_LINE_SOLID; gdk_gc_set_values(dc->pixmap_gc, &gcval, GDK_GC_LINE_STYLE); } gdk_draw_polygon(dc->pixmap, dc->pixmap_gc, style==IUP_DRAW_FILL, (GdkPoint*)points, count); }
void iupgtkBaseSetBgColor(InativeHandle* handle, unsigned char r, unsigned char g, unsigned char b) { GtkRcStyle *rc_style; GdkColor color; iupgdkColorSet(&color, r, g, b); rc_style = gtk_widget_get_modifier_style(handle); rc_style->base[GTK_STATE_NORMAL] = rc_style->bg[GTK_STATE_NORMAL] = rc_style->bg[GTK_STATE_INSENSITIVE] = color; rc_style->bg[GTK_STATE_ACTIVE] = rc_style->base[GTK_STATE_ACTIVE] = gtkDarkerColor(&color); rc_style->base[GTK_STATE_PRELIGHT] = rc_style->bg[GTK_STATE_PRELIGHT] = rc_style->base[GTK_STATE_INSENSITIVE] = gtkLighterColor(&color); rc_style->color_flags[GTK_STATE_NORMAL] |= GTK_RC_BASE | GTK_RC_BG; rc_style->color_flags[GTK_STATE_ACTIVE] |= GTK_RC_BASE | GTK_RC_BG; rc_style->color_flags[GTK_STATE_PRELIGHT] |= GTK_RC_BASE | GTK_RC_BG; rc_style->color_flags[GTK_STATE_INSENSITIVE] |= GTK_RC_BASE | GTK_RC_BG; gtk_widget_modify_style(handle, rc_style); }
void iupdrvDrawRectangle(IdrawCanvas* dc, int x1, int y1, int x2, int y2, long color, int style, int line_width) { GdkColor c; iupgdkColorSet(&c, color); gdk_gc_set_rgb_fg_color(dc->pixmap_gc, &c); iupDrawCheckSwapCoord(x1, x2); iupDrawCheckSwapCoord(y1, y2); if (style==IUP_DRAW_FILL) gdk_draw_rectangle(dc->pixmap, dc->pixmap_gc, TRUE, x1, y1, x2 - x1 + 1, y2 - y1 + 1); else { iDrawSetLineWidth(dc, line_width); iDrawSetLineStyle(dc, style); gdk_draw_rectangle(dc->pixmap, dc->pixmap_gc, FALSE, x1, y1, x2 - x1, y2 - y1); /* outlined rectangle is actually of size w+1,h+1 */ } }
void iupDrawRectangle(IdrawCanvas* dc, int x1, int y1, int x2, int y2, unsigned char r, unsigned char g, unsigned char b, int style) { GdkColor color; iupgdkColorSet(&color, r, g, b); gdk_gc_set_rgb_fg_color(dc->pixmap_gc, &color); if (style==IUP_DRAW_FILL) gdk_draw_rectangle(dc->pixmap, dc->pixmap_gc, TRUE, x1, y1, x2-x1+1, y2-y1+1); else { GdkGCValues gcval; if (style==IUP_DRAW_STROKE_DASH) gcval.line_style = GDK_LINE_ON_OFF_DASH; else gcval.line_style = GDK_LINE_SOLID; gdk_gc_set_values(dc->pixmap_gc, &gcval, GDK_GC_LINE_STYLE); gdk_draw_rectangle(dc->pixmap, dc->pixmap_gc, FALSE, x1, y1, x2-x1, y2-y1); /* outlined rectangle is actually of size w+1,h+1 */ } }
void iupgtkBaseSetFgColor(InativeHandle* handle, unsigned char r, unsigned char g, unsigned char b) { GdkColor color; iupgdkColorSet(&color, r, g, b); iupgtkBaseSetFgGdkColor(handle, &color); }
static int gtkColorDlgPopup(Ihandle* ih, int x, int y) { InativeHandle* parent = iupDialogGetNativeParent(ih); GtkColorSelectionDialog* dialog; GtkColorSelection* colorsel; GdkColor color; char *value; unsigned char r = 0, g = 0, b = 0, a = 255; int response, ret; iupAttribSetInt(ih, "_IUPDLG_X", x); /* used in iupDialogUpdatePosition */ iupAttribSetInt(ih, "_IUPDLG_Y", y); dialog = (GtkColorSelectionDialog*)gtk_color_selection_dialog_new(iupgtkStrConvertToUTF8(iupAttribGet(ih, "TITLE"))); if (!dialog) return IUP_ERROR; if (parent) gtk_window_set_transient_for((GtkWindow*)dialog, (GtkWindow*)parent); ret = iupStrToRGBA(iupAttribGet(ih, "VALUE"), &r, &g, &b, &a); colorsel = (GtkColorSelection*)dialog->colorsel; iupgdkColorSet(&color, r, g, b); gtk_color_selection_set_current_color(colorsel, &color); value = iupAttribGetStr(ih, "ALPHA"); if (value) { int alpha; if (iupStrToInt(value, &alpha)) { if (alpha<0) alpha=0; if (alpha>255) alpha=255; gtk_color_selection_set_has_opacity_control(colorsel, TRUE); gtk_color_selection_set_current_alpha(colorsel, iupCOLOR8TO16(alpha)); } } else if (iupAttribGetBoolean(ih, "SHOWALPHA") || ret == 4) { gtk_color_selection_set_has_opacity_control(colorsel, TRUE); gtk_color_selection_set_current_alpha(colorsel, iupCOLOR8TO16(a)); } else gtk_color_selection_set_has_opacity_control(colorsel, FALSE); value = iupAttribGetStr(ih, "COLORTABLE"); if (value) { gtk_color_selection_set_has_palette (colorsel, TRUE); gtkColorDlgSetPalette(colorsel, value); } else if (iupAttribGetBoolean(ih, "SHOWCOLORTABLE")) gtk_color_selection_set_has_palette (colorsel, TRUE); else gtk_color_selection_set_has_palette (colorsel, FALSE); if (IupGetCallback(ih, "HELP_CB")) gtk_widget_show(dialog->help_button); /* initialize the widget */ gtk_widget_realize(GTK_WIDGET(dialog)); ih->handle = GTK_WIDGET(dialog); iupDialogUpdatePosition(ih); ih->handle = NULL; do { response = gtk_dialog_run(GTK_DIALOG(dialog)); if (response == GTK_RESPONSE_HELP) { Icallback cb = IupGetCallback(ih, "HELP_CB"); if (cb && cb(ih) == IUP_CLOSE) response = GTK_RESPONSE_CANCEL; } } while (response == GTK_RESPONSE_HELP); if (response == GTK_RESPONSE_OK) { GdkColor color; gtk_color_selection_get_current_color(colorsel, &color); IupSetAttribute(ih, "STATUS", "1"); if (gtk_color_selection_get_has_opacity_control(colorsel)) { int alpha = gtk_color_selection_get_current_alpha(colorsel); iupAttribSetInt(ih, "ALPHA", (int)iupCOLOR16TO8(alpha)); iupAttribSetStrf(ih, "VALUE", "%d %d %d %d", (int)iupCOLOR16TO8(color.red), (int)iupCOLOR16TO8(color.green), (int)iupCOLOR16TO8(color.blue), (int)iupCOLOR16TO8(alpha)); } else iupAttribSetStrf(ih, "VALUE", "%d %d %d", (int)iupCOLOR16TO8(color.red), (int)iupCOLOR16TO8(color.green), (int)iupCOLOR16TO8(color.blue)); if (gtk_color_selection_get_has_palette(colorsel)) gtkColorDlgGetPalette(ih, colorsel); } else { iupAttribSetStr(ih, "ALPHA", NULL); iupAttribSetStr(ih, "VALUE", NULL); iupAttribSetStr(ih, "COLORTABLE", NULL); iupAttribSetStr(ih, "STATUS", NULL); } gtk_widget_destroy(GTK_WIDGET(dialog)); return IUP_NOERROR; }
void* iupdrvImageCreateCursor(Ihandle *ih) { GdkCursor *cursor; int hx, hy, bpp; hx=0; hy=0; iupStrToIntInt(iupAttribGet(ih, "HOTSPOT"), &hx, &hy, ':'); bpp = iupAttribGetInt(ih, "BPP"); if (bpp == 8 && !iupAttribGet(ih, "3")) { GdkPixmap *source, *mask; GdkColor fg, bg; unsigned char r, g, b; char *sbits, *mbits, *sb, *mb; int y, x, line_size = (ih->currentwidth+7)/8; int size_bytes = line_size*ih->currentheight; unsigned char* imgdata = (unsigned char*)iupAttribGetStr(ih, "WID"); r = 255; g = 255; b = 255; iupStrToRGB(iupAttribGet(ih, "1"), &r, &g, &b ); iupgdkColorSet(&fg, r, g, b); r = 0; g = 0; b = 0; iupStrToRGB(iupAttribGet(ih, "2"), &r, &g, &b ); iupgdkColorSet(&bg, r, g, b); sbits = (char*)malloc(2*size_bytes); if (!sbits) return NULL; memset(sbits, 0, 2*size_bytes); mbits = sbits + size_bytes; sb = sbits; mb = mbits; for (y=0; y<ih->currentheight; y++) { for (x=0; x<ih->currentwidth; x++) { int byte = x/8; int bit = x%8; int index = (int)imgdata[y*ih->currentwidth+x]; /* index==0 is transparent */ if (index == 1) sb[byte] = (char)(sb[byte] | (1<<bit)); if (index != 0) mb[byte] = (char)(mb[byte] | (1<<bit)); } sb += line_size; mb += line_size; } source = gdk_bitmap_create_from_data(NULL, sbits, ih->currentwidth, ih->currentheight); mask = gdk_bitmap_create_from_data(NULL, mbits, ih->currentwidth, ih->currentheight); cursor = gdk_cursor_new_from_pixmap(source, mask, &fg, &bg, hx, hy); gdk_pixmap_unref(source); gdk_pixmap_unref(mask); free(sbits); } else { GdkPixbuf* pixbuf = iupdrvImageCreateImage(ih, NULL, 0); cursor = gdk_cursor_new_from_pixbuf(gdk_display_get_default(), pixbuf, hx, hy); g_object_unref(pixbuf); } return cursor; }
void iupdrvDrawText(IdrawCanvas* dc, const char* text, int len, int x, int y, int w, int h, long color, const char* font, int flags, double text_orientation) { PangoLayout* fontlayout = (PangoLayout*)iupgtkGetPangoLayout(font); PangoAlignment alignment = PANGO_ALIGN_LEFT; GdkColor c; PangoContext* fontcontext = NULL; int layout_w = w, layout_h = h; int layout_center = flags & IUP_DRAW_LAYOUTCENTER; if (text_orientation && layout_center) iupDrawGetTextInnerBounds(w, h, text_orientation, &layout_w, &layout_h); iupgdkColorSet(&c, color); gdk_gc_set_rgb_fg_color(dc->pixmap_gc, &c); text = iupgtkStrConvertToSystemLen(text, &len); pango_layout_set_text(fontlayout, text, len); if (flags & IUP_DRAW_RIGHT) alignment = PANGO_ALIGN_RIGHT; else if (flags & IUP_DRAW_CENTER) alignment = PANGO_ALIGN_CENTER; if (flags & IUP_DRAW_WRAP) { pango_layout_set_width(fontlayout, iupGTK_PIXELS2PANGOUNITS(layout_w)); #ifdef PANGO_VERSION_CHECK #if PANGO_VERSION_CHECK(1,2,0) pango_layout_set_height(fontlayout, iupGTK_PIXELS2PANGOUNITS(layout_h)); #endif #endif } else if (flags & IUP_DRAW_ELLIPSIS) { pango_layout_set_width(fontlayout, iupGTK_PIXELS2PANGOUNITS(layout_w)); #ifdef PANGO_VERSION_CHECK #if PANGO_VERSION_CHECK(1,2,0) pango_layout_set_height(fontlayout, iupGTK_PIXELS2PANGOUNITS(layout_h)); #endif #endif pango_layout_set_ellipsize(fontlayout, PANGO_ELLIPSIZE_END); } pango_layout_set_alignment(fontlayout, alignment); if (flags & IUP_DRAW_CLIP) { GdkRectangle rect; rect.x = x; rect.y = y; rect.width = w; rect.height = h; gdk_gc_set_clip_rectangle(dc->pixmap_gc, &rect); } if (text_orientation) { PangoRectangle rect; PangoMatrix fontmatrix = PANGO_MATRIX_INIT; fontcontext = pango_layout_get_context(fontlayout); pango_matrix_rotate(&fontmatrix, text_orientation); pango_context_set_matrix(fontcontext, &fontmatrix); pango_layout_context_changed(fontlayout); pango_layout_get_pixel_extents(fontlayout, NULL, &rect); #ifdef PANGO_VERSION_CHECK #if PANGO_VERSION_CHECK(1,16,0) pango_matrix_transform_pixel_rectangle(&fontmatrix, &rect); #endif #endif /* Adjust the position considering the Pango rectangle transformed */ if (layout_center) { x += (w - rect.width) / 2; y += (h - rect.height) / 2; } else { x += (int)rect.x; y += (int)rect.y; } } gdk_draw_layout(dc->pixmap, dc->pixmap_gc, x, y, fontlayout); /* restore settings */ if ((flags & IUP_DRAW_WRAP) || (flags & IUP_DRAW_ELLIPSIS)) { pango_layout_set_width(fontlayout, -1); #ifdef PANGO_VERSION_CHECK #if PANGO_VERSION_CHECK(1,2,0) pango_layout_set_height(fontlayout, -1); #endif #endif } if (flags & IUP_DRAW_ELLIPSIS) pango_layout_set_ellipsize(fontlayout, PANGO_ELLIPSIZE_NONE); if (flags & IUP_DRAW_CLIP) gdk_gc_set_clip_region(dc->pixmap_gc, NULL); if (text_orientation) pango_context_set_matrix(fontcontext, NULL); }