Wed, 27 Jan 2016 12:10:42 +0100
added scrollbar (GTK)
application/main.c | file | annotate | diff | comparison | revisions | |
ui/gtk/graphics.c | file | annotate | diff | comparison | revisions | |
ui/gtk/objs.mk | file | annotate | diff | comparison | revisions | |
ui/gtk/range.c | file | annotate | diff | comparison | revisions | |
ui/gtk/range.h | file | annotate | diff | comparison | revisions | |
ui/gtk/toolkit.h | file | annotate | diff | comparison | revisions | |
ui/ui/range.h | file | annotate | diff | comparison | revisions | |
ui/ui/toolkit.h | file | annotate | diff | comparison | revisions | |
ui/ui/ui.h | file | annotate | diff | comparison | revisions |
--- a/application/main.c Tue Jan 26 20:06:16 2016 +0100 +++ b/application/main.c Wed Jan 27 12:10:42 2016 +0100 @@ -34,6 +34,8 @@ #include <ucx/utils.h> UiInteger radio; +UiRange range; +UIWIDGET drawingarea; void action_menu(UiEvent *event, void *data) { printf("action_menu test: {%s}\n", data); @@ -56,7 +58,13 @@ UiTextLayout *text; +void action_scroll(UiEvent *event, void *data) { + ui_drawingarea_redraw(drawingarea); +} + void draw(UiEvent *event, UiGraphics *g, void *data) { + double adjust = range.get(&range); + ///* int width = g->width; int height = g->height; @@ -75,7 +83,7 @@ //printf("ext[%d,%d]\n", w, h); ui_graphics_color(g, 255, 255, 255); - ui_draw_text(g, 50, 50, text); + ui_draw_text(g, 50, 50 + adjust, text); ui_draw_line(g, 50, 55 + h, 50+w, 55 +h); ui_draw_line(g, 50, 55 + h, 50, 75 +h); @@ -106,6 +114,11 @@ int main(int argc, char** argv) { ui_init("app1", argc, argv); + UiList *list = ui_list_new(); + ui_list_append(list, "Hello"); + ui_list_append(list, "World"); + ui_list_append(list, "Test"); + ui_menu("File"); ui_menuitem("Hello", action_menu, "hello"); ui_submenu("Submenu1"); @@ -118,40 +131,29 @@ ui_toolitem("button1", "Test", action_button, NULL); ui_toolitem("button2", "OK", action_button, NULL); + ui_toolbar_combobox_str("combo", list, NULL, NULL); ui_toolbar_add_default("button1"); ui_toolbar_add_default("button2"); + ui_toolbar_add_default("combo"); UiObject *obj = ui_window("Test", NULL); ui_context_closefunc(obj->ctx, window_close, NULL); -/* - UIWIDGET w = ui_drawingarea(obj, draw, NULL); - ctxmenu = ui_contextmenu_w(obj, w); +///* + ui_hbox(obj); + + drawingarea = ui_drawingarea(obj, draw, NULL); + ctxmenu = ui_contextmenu_w(obj, drawingarea); ui_widget_menuitem(obj, "Test1", NULL, NULL); ui_widget_menuitem(obj, "Test2", NULL, NULL); ui_widget_menuitem(obj, "Test3", NULL, NULL); ui_widget_menuitem(obj, "Test4", NULL, NULL); - ui_drawingarea_mousehandler(obj, w, click, NULL); -*/ - -///* - ui_vbox_sp(obj, 0, 0); - - UiList *list = ui_list_new(); - ui_list_append(list, "Hello"); - ui_list_append(list, "World"); - ui_list_append(list, "Test"); + ui_drawingarea_mousehandler(obj, drawingarea, click, NULL); - ui_button(obj, "Button", NULL, NULL); - ui_layout_fill(obj, FALSE); - ui_hbox(obj); - ui_combobox_str(obj, list, NULL, NULL); - ui_end(obj); - ui_button(obj, "Button", NULL, NULL); - //ui_button(obj, "Button", NULL, NULL); - //ui_button(obj, "Button", NULL, NULL); - //ui_button(obj, "Button", NULL, NULL); - //ui_button(obj, "Button", NULL, NULL); + ui_vscrollbar(obj, &range, action_scroll, NULL); + range.setrange(&range, 0, 400); + range.setextent(&range, 1); + range.set(&range, 0); ui_end(obj); //*/
--- a/ui/gtk/graphics.c Tue Jan 26 20:06:16 2016 +0100 +++ b/ui/gtk/graphics.c Wed Jan 27 12:10:42 2016 +0100 @@ -83,6 +83,20 @@ return TRUE; } +void ui_drawingarea_getsize(UIWIDGET drawingarea, int *width, int *height) { +#ifdef UI_GTK3 + *width = gtk_widget_get_allocated_width(drawingarea); + *height = gtk_widget_get_allocated_height(drawingarea); +#else + *width = widget->allocation.width; + *height = widget->allocation.height; +#endif +} + +void ui_drawingarea_redraw(UIWIDGET drawingarea) { + gtk_widget_queue_draw(drawingarea); +} + void ui_drawingarea_mousehandler(UiObject *obj, UIWIDGET widget, ui_callback f, void *u) { gtk_widget_set_events(widget, GDK_BUTTON_PRESS_MASK); if(f) {
--- a/ui/gtk/objs.mk Tue Jan 26 20:06:16 2016 +0100 +++ b/ui/gtk/objs.mk Wed Jan 27 12:10:42 2016 +0100 @@ -42,6 +42,7 @@ GTKOBJ += tree.o GTKOBJ += image.o GTKOBJ += graphics.o +GTKOBJ += range.o TOOLKITOBJS += $(GTKOBJ:%=$(GTK_OBJPRE)%) TOOLKITSOURCE += $(GTKOBJ:%.o=gtk/%.c)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ui/gtk/range.c Wed Jan 27 12:10:42 2016 +0100 @@ -0,0 +1,129 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2016 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 "range.h" +#include "container.h" +#include "../../ucx/mempool.h" +#include "../common/context.h" +#include "../common/object.h" + + +static UIWIDGET ui_scrollbar(UiObject *obj, UiOrientation orientation, UiRange *range, ui_callback f, void *userdata) { +#ifdef UI_GTK3 + GtkWidget *scrollbar = gtk_scrollbar_new(orientation == UI_HORIZONTAL ? GTK_ORIENTATION_HORIZONTAL : GTK_ORIENTATION_VERTICAL, NULL); +#else + GtkWidget *scrollbar; + if(orientation == UI_HORIZONTAL) { + scrollbar = gtk_hscrollbar_new(NULL); + } else { + scrollbar = gtk_hscrollbar_new(NULL); + } +#endif + + if(range) { + range->get = ui_scrollbar_get; + range->set = ui_scrollbar_set; + range->setrange = ui_scrollbar_setrange; + range->setextent = ui_scrollbar_setextent; + range->obj = scrollbar; + } + + if(f) { + UiEventData *event = malloc(sizeof(UiEventData)); + event->obj = obj; + event->userdata = userdata; + event->callback = f; + event->value = 0; + + g_signal_connect( + G_OBJECT(scrollbar), + "value-changed", + G_CALLBACK(ui_scrollbar_value_changed), + event); + g_signal_connect( + scrollbar, + "destroy", + G_CALLBACK(ui_destroy_userdata), + event); + } + + UiContainer *ct = uic_get_current_container(obj); + ct->add(ct, scrollbar, FALSE); + + return scrollbar; +} + +UIWIDGET ui_hscrollbar(UiObject *obj, UiRange *range, ui_callback f, void *userdata) { + return ui_scrollbar(obj, UI_HORIZONTAL, range, f, userdata); +} + +UIWIDGET ui_vscrollbar(UiObject *obj, UiRange *range, ui_callback f, void *userdata) { + return ui_scrollbar(obj, UI_VERTICAL, range, f, userdata); +} + +gboolean ui_scrollbar_value_changed(GtkRange *range, UiEventData *event) { + UiEvent e; + e.obj = event->obj; + e.window = event->obj->window; + e.document = event->obj->ctx->document; + e.eventdata = NULL; + e.intval = event->value; + event->callback(&e, event->userdata); + return TRUE; +} + +double ui_scrollbar_get(UiRange *range) { + double value = gtk_range_get_value(GTK_RANGE(range->obj)); + range->value = value; + return value; +} + +void ui_scrollbar_set(UiRange *range, double value) { + gtk_range_set_value(GTK_RANGE(range->obj), value); + range->value = value; +} + +void ui_scrollbar_setrange(UiRange *range, double min, double max) { + gtk_range_set_range(GTK_RANGE(range->obj), min, max); + range->min = min; + range->max = max; +} + +void ui_scrollbar_setextent(UiRange *range, double extent) { + GtkAdjustment *a = gtk_range_get_adjustment(GTK_RANGE(range->obj)); +#ifdef ui_GTK2LEGACY + a->page_size = extent; +#else + gtk_adjustment_set_page_size(a, extent); +#endif + gtk_adjustment_changed(a); + range->extent = extent; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ui/gtk/range.h Wed Jan 27 12:10:42 2016 +0100 @@ -0,0 +1,50 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2016 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. + */ +#ifndef RANGE_H +#define RANGE_H + +#include "toolkit.h" +#include "../ui/range.h" + +#ifdef __cplusplus +extern "C" { +#endif + +gboolean ui_scrollbar_value_changed(GtkRange *range, UiEventData *event); + +double ui_scrollbar_get(UiRange *range); +void ui_scrollbar_set(UiRange *range, double value); +void ui_scrollbar_setrange(UiRange *range, double min, double max); +void ui_scrollbar_setextent(UiRange *range, double extent); + +#ifdef __cplusplus +} +#endif + +#endif /* RANGE_H */ +
--- a/ui/gtk/toolkit.h Tue Jan 26 20:06:16 2016 +0100 +++ b/ui/gtk/toolkit.h Wed Jan 27 12:10:42 2016 +0100 @@ -52,6 +52,9 @@ void *finish_data; } UiJob; +typedef enum UiOrientation UiOrientation; +enum UiOrientation { UI_HORIZONTAL = 0, UI_VERTICAL }; + void ui_destroy_userdata(GtkWidget *object, void *userdata); void ui_set_active_window(UiObject *obj);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ui/ui/range.h Wed Jan 27 12:10:42 2016 +0100 @@ -0,0 +1,48 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2016 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. + */ + +#ifndef UI_RANGE_H +#define UI_RANGE_H + +#include "toolkit.h" + +#ifdef __cplusplus +extern "C" { +#endif + +UIWIDGET ui_hscrollbar(UiObject *obj, UiRange *range, ui_callback f, void *userdata); +UIWIDGET ui_vscrollbar(UiObject *obj, UiRange *range, ui_callback f, void *userdata); + + + +#ifdef __cplusplus +} +#endif + +#endif /* UI_RANGE_H */ +
--- a/ui/ui/toolkit.h Tue Jan 26 20:06:16 2016 +0100 +++ b/ui/ui/toolkit.h Wed Jan 27 12:10:42 2016 +0100 @@ -93,6 +93,7 @@ typedef struct UiString UiString; typedef struct UiText UiText; typedef struct UiList UiList; +typedef struct UiRange UiRange; /* private types */ typedef struct UiContext UiContext; @@ -235,6 +236,18 @@ }; +struct UiRange { + double (*get)(UiRange *range); + void (*set)(UiRange *range, double value); + void (*setrange)(UiRange *range, double min, double max); + void (*setextent)(UiRange *range, double extent); + double value; + double min; + double max; + double extent; + void *obj; +}; + void ui_init(char *appname, int argc, char **argv); char* ui_appname();