ui/gtk/draw_gdk.c

changeset 95
29f5cd5f5367
child 114
909fe96e5659
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ui/gtk/draw_gdk.c	Sun Nov 29 17:22:15 2015 +0100
@@ -0,0 +1,89 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2011 Olaf Wintermann. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *   1. Redistributions of source code must retain the above copyright
+ *      notice, this list of conditions and the following disclaimer.
+ *
+ *   2. Redistributions in binary form must reproduce the above copyright
+ *      notice, this list of conditions and the following disclaimer in the
+ *      documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "container.h"
+
+#include "draw_gdk.h"
+
+
+gboolean ui_drawingarea_expose(GtkWidget *w, GdkEventExpose *e, void *data) {
+    UiGdkGraphics g;
+    g.g.width = w->allocation.width;
+    g.g.height = w->allocation.height;
+    g.widget = w;
+    g.gc = gdk_gc_new(w->window);
+    
+    UiDrawEvent *event = data;
+    UiEvent ev;
+    ev.obj = event->obj;
+    ev.window = event->obj->window;
+    ev.document = event->obj->ctx->document;
+    
+    event->callback(&ev, &g.g, event->userdata);
+    
+    return FALSE;
+}
+
+// function from graphics.h
+
+void ui_connect_draw_handler(GtkWidget *widget, UiDrawEvent *event) {
+    g_signal_connect(G_OBJECT(widget),
+            "expose_event",
+            G_CALLBACK(ui_drawingarea_expose),
+            event);
+}
+
+PangoContext *ui_get_pango_context(UiGraphics *g) {
+    UiGdkGraphics *gr = (UiGdkGraphics*)g;
+    return gtk_widget_get_pango_context(gr->widget);
+}
+
+// drawing functions
+void ui_graphics_color(UiGraphics *g, int red, int green, int blue) {
+    UiGdkGraphics *gr = (UiGdkGraphics*)g;
+    GdkColor color;
+    color.red = red * 257;
+    color.green = green * 257;
+    color.blue = blue * 257;
+    gdk_gc_set_rgb_fg_color(gr->gc, &color);
+    //gdk_gc_set_rgb_bg_color(g->gc, &color);
+}
+
+
+void ui_draw_rect(UiGraphics *g, int x, int y, int w, int h, int fill) {
+    UiGdkGraphics *gr = (UiGdkGraphics*)g; 
+    gdk_draw_rectangle(gr->widget->window, gr->gc, fill, x, y, w, h);
+}
+
+void ui_draw_text(UiGraphics *g, int x, int y, UiTextLayout *text) {
+    UiGdkGraphics *gr = (UiGdkGraphics*)g; 
+    gdk_draw_layout(gr->widget->window, gr->gc, x, y, text->layout);
+}

mercurial