summaryrefslogtreecommitdiff
path: root/iup/src/gtk/iupgtk_draw.c
diff options
context:
space:
mode:
authorPixel <pixel@nobis-crew.org>2010-06-15 00:59:57 -0700
committerPixel <pixel@nobis-crew.org>2010-06-15 00:59:57 -0700
commiteed0eb6a476d54ce19aeff137984aa981d9e3976 (patch)
tree807891636efd2f87dcbd261e971216269973ae07 /iup/src/gtk/iupgtk_draw.c
parentccc8261e4d48de89da4ddfe7b55e378ae0cd6f47 (diff)
Upgrading to iup 3.1
Diffstat (limited to 'iup/src/gtk/iupgtk_draw.c')
-rw-r--r--iup/src/gtk/iupgtk_draw.c161
1 files changed, 161 insertions, 0 deletions
diff --git a/iup/src/gtk/iupgtk_draw.c b/iup/src/gtk/iupgtk_draw.c
new file mode 100644
index 0000000..4390c66
--- /dev/null
+++ b/iup/src/gtk/iupgtk_draw.c
@@ -0,0 +1,161 @@
+/** \file
+ * \brief Draw Functions
+ *
+ * See Copyright Notice in "iup.h"
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <memory.h>
+
+#include <gtk/gtk.h>
+
+#include "iup.h"
+
+#include "iup_attrib.h"
+#include "iup_class.h"
+#include "iup_str.h"
+#include "iup_object.h"
+#include "iup_image.h"
+#include "iup_draw.h"
+
+#include "iupgtk_drv.h"
+
+
+struct _IdrawCanvas{
+ Ihandle* ih;
+ int w, h;
+
+ GdkDrawable* wnd;
+ GdkPixmap* pixmap;
+ GdkGC *gc, *pixmap_gc;
+};
+
+IdrawCanvas* iupDrawCreateCanvas(Ihandle* ih)
+{
+ IdrawCanvas* dc = calloc(1, sizeof(IdrawCanvas));
+
+ dc->wnd = ih->handle->window;
+ dc->gc = gdk_gc_new(dc->wnd);
+
+ gdk_drawable_get_size(dc->wnd, &dc->w, &dc->h);
+
+ dc->pixmap = gdk_pixmap_new(dc->wnd, dc->w, dc->h, gdk_drawable_get_depth(dc->wnd));
+ dc->pixmap_gc = gdk_gc_new(dc->pixmap);
+
+ return dc;
+}
+
+void iupDrawKillCanvas(IdrawCanvas* dc)
+{
+ g_object_unref(dc->pixmap_gc);
+ g_object_unref(dc->pixmap);
+ g_object_unref(dc->gc);
+
+ free(dc);
+}
+
+void iupDrawUpdateSize(IdrawCanvas* dc)
+{
+ int w, h;
+ gdk_drawable_get_size(dc->wnd, &w, &h);
+
+ if (w != dc->w || h != dc->h)
+ {
+ g_object_unref(dc->pixmap_gc);
+ g_object_unref(dc->pixmap);
+
+ dc->pixmap = gdk_pixmap_new(dc->wnd, dc->w, dc->h, gdk_drawable_get_depth(dc->wnd));
+ dc->pixmap_gc = gdk_gc_new(dc->pixmap);
+ }
+}
+
+void iupDrawFlush(IdrawCanvas* dc)
+{
+ gdk_draw_drawable(dc->wnd, dc->gc, dc->pixmap, 0, 0, 0, 0, dc->w, dc->h);
+}
+
+void iupDrawGetSize(IdrawCanvas* dc, int *w, int *h)
+{
+ if (w) *w = dc->w;
+ if (h) *h = dc->h;
+}
+
+void iupDrawParentBackground(IdrawCanvas* dc)
+{
+ unsigned char r=0, g=0, b=0;
+ char* color = iupBaseNativeParentGetBgColorAttrib(dc->ih);
+ iupStrToRGB(color, &r, &g, &b);
+ iupDrawRectangle(dc, 0, 0, dc->w-1, dc->h-1, r, g, b, 1);
+}
+
+void iupDrawRectangle(IdrawCanvas* dc, int x1, int y1, int x2, int y2, unsigned char r, unsigned char g, unsigned char b, int filled)
+{
+ GdkColor color;
+ iupgdkColorSet(&color, r, g, b);
+ gdk_gc_set_rgb_fg_color(dc->pixmap_gc, &color);
+ gdk_draw_rectangle(dc->pixmap, dc->pixmap_gc, filled, x1, y1, x2-x1+1, y2-y1+1);
+}
+
+void iupDrawLine(IdrawCanvas* dc, int x1, int y1, int x2, int y2, unsigned char r, unsigned char g, unsigned char b)
+{
+ GdkColor color;
+ iupgdkColorSet(&color, r, g, b);
+ gdk_gc_set_rgb_fg_color(dc->pixmap_gc, &color);
+ gdk_draw_line(dc->pixmap, dc->pixmap_gc, x1, y1, x2, y2);
+}
+
+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 filled)
+{
+ GdkColor color;
+ iupgdkColorSet(&color, r, g, b);
+ gdk_gc_set_rgb_fg_color(dc->pixmap_gc, &color);
+ gdk_draw_arc(dc->pixmap, dc->pixmap_gc, filled, 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 filled)
+{
+ GdkColor color;
+ iupgdkColorSet(&color, r, g, b);
+ gdk_gc_set_rgb_fg_color(dc->pixmap_gc, &color);
+ gdk_draw_polygon(dc->pixmap, dc->pixmap_gc, filled, (GdkPoint*)points, count);
+}
+
+void iupDrawSetClipRect(IdrawCanvas* dc, int x1, int y1, int x2, int y2)
+{
+ GdkRectangle rect;
+ rect.x = x1;
+ rect.y = y1;
+ rect.width = x2-x1+1;
+ rect.height = y2-y1+1;
+ gdk_gc_set_clip_rectangle(dc->pixmap_gc, &rect);
+}
+
+void iupDrawResetClip(IdrawCanvas* dc)
+{
+ gdk_gc_set_clip_region(dc->pixmap_gc, NULL);
+}
+
+void iupDrawText(IdrawCanvas* dc, const char* text, int len, int x, int y, unsigned char r, unsigned char g, unsigned char b)
+{
+ PangoLayout* fontlayout = (PangoLayout*)IupGetAttribute(dc->ih, "PANGOLAYOUT");
+ 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 iupDrawImage(IdrawCanvas* dc, const char* name, int make_inactive, int x, int y)
+{
+ int img_w, img_h, bpp;
+ GdkPixbuf* pixbuf = iupImageGetImage(name, dc->ih, make_inactive);
+ if (!pixbuf)
+ return;
+
+ /* must use this info, since image can be a driver image loaded from resources */
+ iupdrvImageGetInfo(pixbuf, &img_w, &img_h, &bpp);
+
+ gdk_draw_pixbuf(dc->pixmap, dc->pixmap_gc, pixbuf, 0, 0, x, y, img_w, img_h, GDK_RGB_DITHER_NORMAL, 0, 0);
+}