added ui_draw_line function

Sun, 24 Jan 2016 22:20:47 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 24 Jan 2016 22:20:47 +0100
changeset 114
909fe96e5659
parent 113
500c085d2133
child 115
102fc0b8fe3e

added ui_draw_line function

application/main.c file | annotate | diff | comparison | revisions
ui/gtk/draw_cairo.c file | annotate | diff | comparison | revisions
ui/gtk/draw_gdk.c file | annotate | diff | comparison | revisions
ui/motif/graphics.c file | annotate | diff | comparison | revisions
ui/qt/graphics.cpp file | annotate | diff | comparison | revisions
ui/ui/graphics.h file | annotate | diff | comparison | revisions
--- 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);
--- 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);
--- 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; 
--- 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) {
--- 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;
     
--- 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);
 

mercurial