#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;
}
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);
}
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);
}
void ui_draw_line(UiGraphics *g,
int x1,
int y1,
int x2,
int y2) {
UiGdkGraphics *gr = (UiGdkGraphics*)g;
gdk_draw_line(gr->widget->window, gr->gc, x1, y1, x2, y2);
}
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);
}