|
@@ -7,6 +7,30 @@
|
|
|
#include "draw.h"
|
|
|
|
|
|
|
|
|
+bool zori_widget_is_type(struct zori_widget * widget, zori_widget_type type) {
|
|
|
+ if(!widget) return false;
|
|
|
+ return (type) == widget->type;
|
|
|
+}
|
|
|
+
|
|
|
+bool zori_widget_is_type_predicate(struct zori_widget * widget, void * extra) {
|
|
|
+ zori_widget_type * type_ptr = extra;
|
|
|
+ if(!type_ptr) return false;
|
|
|
+ return zori_widget_is_type(widget, (*type_ptr));
|
|
|
+}
|
|
|
+
|
|
|
+struct zori_widget *
|
|
|
+ zori_widget_get_parent_of_type(struct zori_widget * widget,
|
|
|
+ zori_widget_type type) {
|
|
|
+ return zori_widget_find_parent(widget, zori_widget_is_type_predicate, &type);
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+struct zori_screen * zori_widget_get_screen(struct zori_widget * widget) {
|
|
|
+ struct zori_widget * screen_widget = zori_widget_get_parent_of_type(widget, ZORI_WIDGET_TYPE_SCREEN);
|
|
|
+ return zori_widget_to_screen(screen_widget);
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
|
|
|
* For example, a hidden widget won't draw, and a disabled widget won't
|
|
|
* accept any system events, and a NULL widget doesn't accept events at all.. */
|
|
@@ -153,6 +177,22 @@ struct zori_handler * zori_widget_add_handlers
|
|
|
return handlers + amount - 1;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ * looks for the cursor t determine this. */
|
|
|
+struct zori_style * zori_widget_get_mark_style(struct zori_widget * widget) {
|
|
|
+ struct zori_screen * screen = zori_widget_get_screen(widget);
|
|
|
+ if (!screen) return &widget->style;
|
|
|
+ return &(screen->cursors.keyjoy.target_style);
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+ * looks for the cursor t determine this. */
|
|
|
+struct zori_style * zori_widget_get_hover_style(struct zori_widget * widget) {
|
|
|
+ struct zori_screen * screen = zori_widget_get_screen(widget);
|
|
|
+ if (!screen) return &widget->style;
|
|
|
+ return &(screen->cursors.mouse.target_style);
|
|
|
+}
|
|
|
+
|
|
|
|
|
|
|
|
|
void zori_widget_free(struct zori_widget * widget);
|
|
@@ -218,32 +258,27 @@ zori_widget_margin_(struct zori_widget * widget, int size) {
|
|
|
void zori_widget_draw_background(struct zori_widget * widget) {
|
|
|
float dx, dy, dw, dh;
|
|
|
struct zori_style * style = &widget->style;
|
|
|
- zori_bitmap * background = style->back.bitmap;
|
|
|
- zori_color color = style->back.color;
|
|
|
- struct zori_graphic_style * graphic_style = & style->back;
|
|
|
dx = rebox_x(&widget->box);
|
|
|
dy = rebox_y(&widget->box);
|
|
|
dw = rebox_w(&widget->box);
|
|
|
dh = rebox_h(&widget->box);
|
|
|
|
|
|
if (zori_widget_hover(widget)) {
|
|
|
- graphic_style = &style->hover;
|
|
|
+ style = zori_widget_get_hover_style(widget);
|
|
|
}
|
|
|
|
|
|
if (zori_widget_marked(widget)) {
|
|
|
- graphic_style = &style->mark;
|
|
|
- }
|
|
|
-
|
|
|
- if (graphic_style->bitmap) {
|
|
|
- background = graphic_style->bitmap;
|
|
|
+ style = zori_widget_get_mark_style(widget);
|
|
|
}
|
|
|
|
|
|
- color = graphic_style->color;
|
|
|
-
|
|
|
- if (background) {
|
|
|
+ if (style->back.image) {
|
|
|
+ zori_bitmap * background = style->back.image;
|
|
|
image_blitscale9(background, dx, dy, dw, dh, -1, -1);
|
|
|
} else {
|
|
|
- draw_frame(dx, dy, dw, dh, 3, style->border.color, color);
|
|
|
+ zori_color fillco = style->back.color;
|
|
|
+ zori_color bordco = style->border.color;
|
|
|
+ int thick = style->border.size;
|
|
|
+ draw_frame(dx, dy, dw, dh, thick, bordco, fillco);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -433,6 +468,8 @@ struct zori_widget * zori_widget_init
|
|
|
if (!widget->style.text.font) {
|
|
|
widget->style.text.font = default_style->text.font;
|
|
|
}
|
|
|
+ } else if (parent) {
|
|
|
+ widget->style = parent->style;
|
|
|
} else {
|
|
|
widget->style = *default_style;
|
|
|
}
|
|
@@ -492,28 +529,6 @@ zori_widget_find_parent(struct zori_widget * widget,
|
|
|
return NULL;
|
|
|
}
|
|
|
|
|
|
-bool zori_widget_is_type(struct zori_widget * widget, zori_widget_type type) {
|
|
|
- if(!widget) return false;
|
|
|
- return (type) == widget->type;
|
|
|
-}
|
|
|
-
|
|
|
-bool zori_widget_is_type_predicate(struct zori_widget * widget, void * extra) {
|
|
|
- zori_widget_type * type_ptr = extra;
|
|
|
- if(!type_ptr) return false;
|
|
|
- return zori_widget_is_type(widget, (*type_ptr));
|
|
|
-}
|
|
|
-
|
|
|
-struct zori_widget *
|
|
|
- zori_widget_get_parent_of_type(struct zori_widget * widget,
|
|
|
- zori_widget_type type) {
|
|
|
- return zori_widget_find_parent(widget, zori_widget_is_type_predicate, &type);
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-struct zori_screen * zori_widget_get_screen(struct zori_widget * widget) {
|
|
|
- struct zori_widget * screen_widget = zori_widget_get_parent_of_type(widget, ZORI_WIDGET_TYPE_SCREEN);
|
|
|
- return zori_widget_to_screen(screen_widget);
|
|
|
-}
|
|
|
|
|
|
|
|
|
int zori_mark_widget(struct zori_widget * widget) {
|
|
@@ -555,3 +570,132 @@ zori_id zori_widget_set_closed_result(struct zori_widget * widget, int value) {
|
|
|
return ZORI_ID_EINVAL;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+zori_id zori_set_mark_style(zori_id id, struct zori_style style) {
|
|
|
+ struct zori_widget * widget = zori_get_widget(id);
|
|
|
+ struct zori_screen * screen = zori_widget_get_screen(widget);
|
|
|
+ if (screen) {
|
|
|
+ screen->cursors.keyjoy.style = style;
|
|
|
+ return id;
|
|
|
+ } else {
|
|
|
+ return ZORI_ID_EINVAL;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+zori_id zori_set_hover_style(zori_id id, struct zori_style style) {
|
|
|
+ struct zori_widget * widget = zori_get_widget(id);
|
|
|
+ struct zori_screen * screen = zori_widget_get_screen(widget);
|
|
|
+ if (screen) {
|
|
|
+ screen->cursors.mouse.style = style;
|
|
|
+ return id;
|
|
|
+ } else {
|
|
|
+ return ZORI_ID_EINVAL;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+void zori_widget_move_self_by(struct zori_widget * widget, int dx, int dy) {
|
|
|
+ int index, stop;
|
|
|
+
|
|
|
+ widget->box.at.x += dx;
|
|
|
+ widget->box.at.y += dy;
|
|
|
+ widget->inner.at.x += dx;
|
|
|
+ widget->inner.at.y += dy;
|
|
|
+ widget->outer.at.x += dx;
|
|
|
+ widget->outer.at.y += dy;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+ * Margin and paddding are resized also by dw and dh;
|
|
|
+ */
|
|
|
+void zori_widget_resize_self_by(struct zori_widget * widget, int dw, int dh) {
|
|
|
+ int index, stop;
|
|
|
+
|
|
|
+ widget->box.size.x += dw;
|
|
|
+ widget->box.size.y += dh;
|
|
|
+ widget->inner.size.x += dw;
|
|
|
+ widget->inner.size.y += dh;
|
|
|
+ widget->outer.size.x += dw;
|
|
|
+ widget->outer.size.y += dh;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ * keeping the offset */
|
|
|
+void zori_widget_move_by(struct zori_widget * widget, int dx, int dy) {
|
|
|
+ int index, stop;
|
|
|
+
|
|
|
+ zori_widget_move_self_by(widget, dx, dy);
|
|
|
+
|
|
|
+ stop = zori_widget_count_children(widget);
|
|
|
+ for (index= 0 ; index < stop; index ++) {
|
|
|
+ struct zori_widget * child = zori_widget_get_child(widget, index);
|
|
|
+ zori_widget_move_by(child, dx, dy);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+ * keeping the offset */
|
|
|
+void zori_widget_move_to(struct zori_widget * widget, int x, int y) {
|
|
|
+ int dx = widget->box.at.x - x;
|
|
|
+ int dy = widget->box.at.y - y;
|
|
|
+ zori_widget_move_by(widget, dx, dy);
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+void zori_widget_move_self_to(struct zori_widget * widget, int x, int y) {
|
|
|
+ int dx = widget->box.at.x - x;
|
|
|
+ int dy = widget->box.at.y - y;
|
|
|
+ zori_widget_move_self_by(widget, dx, dy);
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+ * resized accordingly. */
|
|
|
+void zori_widget_resize_self_to(struct zori_widget * widget, int w, int h) {
|
|
|
+ int dw = widget->box.size.x - w;
|
|
|
+ int dh = widget->box.size.y - h;
|
|
|
+ zori_widget_resize_self_by(widget, dw, dh);
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ * Does not resize nor move the children.
|
|
|
+ */
|
|
|
+
|
|
|
+void zori_widget_fit_to_children(struct zori_widget * widget) {
|
|
|
+ int index, stop;
|
|
|
+ int min_x = 640;
|
|
|
+ int min_y = 480;
|
|
|
+ int min_w = 0;
|
|
|
+ int min_h = 0;
|
|
|
+
|
|
|
+
|
|
|
+ struct zori_screen * screen = zori_widget_get_screen(widget);
|
|
|
+ if (screen) {
|
|
|
+ min_x = screen->widget.box.size.x;
|
|
|
+ min_y = screen->widget.box.size.y;
|
|
|
+ }
|
|
|
+
|
|
|
+ stop = zori_widget_count_children(widget);
|
|
|
+ for (index= 0 ; index < stop; index ++) {
|
|
|
+ struct zori_widget * child = zori_widget_get_child(widget, index);
|
|
|
+ if (child->outer.at.x < min_x) {
|
|
|
+ min_x = child->outer.at.x;
|
|
|
+ }
|
|
|
+ if (child->outer.at.y < min_y) {
|
|
|
+ min_y = child->outer.at.y;
|
|
|
+ }
|
|
|
+ if ((child->outer.size.x) > min_w) {
|
|
|
+ min_w = child->outer.size.x;
|
|
|
+ }
|
|
|
+ if ((child->outer.size.y) > min_h) {
|
|
|
+ min_h = child->outer.size.y;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ zori_widget_move_self_to(widget, min_x, min_y);
|
|
|
+ zori_widget_resize_self_to(widget, min_w, min_h);
|
|
|
+}
|
|
|
+
|