# HG changeset patch # User Olaf Wintermann # Date 1453670447 -3600 # Node ID 909fe96e565913d79e7a1128692d5e75b5a6c6a3 # Parent 500c085d2133773ee5129c2c2c5027c406b873fd added ui_draw_line function diff -r 500c085d2133 -r 909fe96e5659 application/main.c --- a/application/main.c Sun Jan 24 19:57:16 2016 +0100 +++ b/application/main.c Sun Jan 24 22:20:47 2016 +0100 @@ -54,18 +54,22 @@ ui_setval(radio, 1); } +UiTextLayout *text; + void draw(UiEvent *event, UiGraphics *g, void *data) { - /* + ///* int width = g->width; int height = g->height; - printf("rec[%d,%d]\n", width, height); + //printf("rec[%d,%d]\n", width, height); ui_graphics_color(g, 64, 64, 64); ui_draw_rect(g, 0, 0, width, height, TRUE); - UiTextLayout *text = ui_text(g); - ui_text_setfont(text, "Monospace", 12); - ui_text_setstring(text, "Hello World"); + if(!text) { + text = ui_text(g); + ui_text_setfont(text, "Monospace", 12); + ui_text_setstring(text, "Hello World"); + } int w, h; ui_text_getsize(text, &w, &h); //printf("ext[%d,%d]\n", w, h); @@ -73,8 +77,11 @@ ui_graphics_color(g, 255, 255, 255); ui_draw_text(g, 50, 50, text); - ui_text_free(text); - */ + ui_draw_line(g, 0, 120, width, 120); + ui_draw_line(g, 200, 0, 200, height); + + //ui_text_free(text); + //*/ } void click(UiEvent *event, void *data) { @@ -104,12 +111,12 @@ ui_toolbar_add_default("button1"); ui_toolbar_add_default("button2"); - UiObject *obj = ui_simplewindow("Test", NULL); + UiObject *obj = ui_window("Test", NULL); ui_context_closefunc(obj->ctx, window_close, NULL); - //UIWIDGET w = ui_drawingarea(obj, draw, NULL); + UIWIDGET w = ui_drawingarea(obj, draw, NULL); //ui_mouse_handler(obj, w, click, NULL); -///* +/* ui_vbox_sp(obj, 8, 4); ui_button(obj, "Button", NULL, NULL); ui_button(obj, "Button", NULL, NULL); diff -r 500c085d2133 -r 909fe96e5659 ui/gtk/draw_cairo.c --- a/ui/gtk/draw_cairo.c Sun Jan 24 19:57:16 2016 +0100 +++ b/ui/gtk/draw_cairo.c Sun Jan 24 22:20:47 2016 +0100 @@ -105,6 +105,14 @@ } +void ui_draw_line(UiGraphics *g, int x1, int y1, int x2, int y2) { + UiCairoGraphics *gr = (UiCairoGraphics*)g; + cairo_set_line_width(gr->cr, 1); + cairo_move_to(gr->cr, x1, y1); + cairo_line_to(gr->cr, x2, y2); + cairo_stroke(gr->cr); +} + void ui_draw_rect(UiGraphics *g, int x, int y, int w, int h, int fill) { UiCairoGraphics *gr = (UiCairoGraphics*)g; cairo_set_line_width(gr->cr, 1); diff -r 500c085d2133 -r 909fe96e5659 ui/gtk/draw_gdk.c --- a/ui/gtk/draw_gdk.c Sun Jan 24 19:57:16 2016 +0100 +++ b/ui/gtk/draw_gdk.c Sun Jan 24 22:20:47 2016 +0100 @@ -77,6 +77,10 @@ //gdk_gc_set_rgb_bg_color(g->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; diff -r 500c085d2133 -r 909fe96e5659 ui/motif/graphics.c --- a/ui/motif/graphics.c Sun Jan 24 19:57:16 2016 +0100 +++ b/ui/motif/graphics.c Sun Jan 24 22:20:47 2016 +0100 @@ -220,6 +220,11 @@ XSetForeground(gr->display, gr->gc, color.pixel); } +void ui_draw_line(UiGraphics *g, int x1, int y1, int x2, int y2) { + UiXlibGraphics *gr = (UiXlibGraphics*)g; + XDrawLine(gr->display, XtWindow(gr->widget), gr->gc, x1, y1, x2, y2); +} + void ui_draw_rect(UiGraphics *g, int x, int y, int w, int h, int fill) { UiXlibGraphics *gr = (UiXlibGraphics*)g; if(fill) { diff -r 500c085d2133 -r 909fe96e5659 ui/qt/graphics.cpp --- a/ui/qt/graphics.cpp Sun Jan 24 19:57:16 2016 +0100 +++ b/ui/qt/graphics.cpp Sun Jan 24 22:20:47 2016 +0100 @@ -112,6 +112,12 @@ gr->painter->setPen(gr->color); } +void ui_draw_line(UiGraphics *g, int x1, int y1, int x2, int y2) { + UiQtGraphics *gr = (UiQtGraphics*)g; + + gr->painter->drawLine(x1, y1, x2, y2); +} + void ui_draw_rect(UiGraphics *g, int x, int y, int w, int h, int fill) { UiQtGraphics *gr = (UiQtGraphics*)g; diff -r 500c085d2133 -r 909fe96e5659 ui/ui/graphics.h --- a/ui/ui/graphics.h Sun Jan 24 19:57:16 2016 +0100 +++ b/ui/ui/graphics.h Sun Jan 24 22:20:47 2016 +0100 @@ -60,6 +60,7 @@ // drawing functions void ui_graphics_color(UiGraphics *g, int red, int green, int blue); +void ui_draw_line(UiGraphics *g, int x1, int y1, int x2, int y2); void ui_draw_rect(UiGraphics *g, int x, int y, int w, int h, int fill); void ui_draw_text(UiGraphics *g, int x, int y, UiTextLayout *text);