From 60804d6d0d6bff1af63efc8918c61edb0e30c820 Mon Sep 17 00:00:00 2001 From: Lionel AINS Date: Fri, 5 Oct 2018 17:49:20 +0200 Subject: Handling resize for boxes --- navit/gui/internal/gui_internal.c | 15 ++++- navit/gui/internal/gui_internal_menu.c | 105 ++++++++++++++++++++----------- navit/gui/internal/gui_internal_menu.h | 1 + navit/gui/internal/gui_internal_widget.c | 67 +++++++++++++++++++- navit/gui/internal/gui_internal_widget.h | 8 ++- 5 files changed, 154 insertions(+), 42 deletions(-) diff --git a/navit/gui/internal/gui_internal.c b/navit/gui/internal/gui_internal.c index e8ccaab1c..574d1fd90 100644 --- a/navit/gui/internal/gui_internal.c +++ b/navit/gui/internal/gui_internal.c @@ -474,7 +474,7 @@ gui_internal_time_help(struct gui_priv *this) { /** * Applies the configuration values to this based on the settings * specified in the configuration file (this->config) and - * the most approriate default profile based on screen resolution. + * the most appropriate default profile based on screen resolution. * * This function should be run after this->root is setup and could * be rerun after the window is resized. @@ -2701,7 +2701,18 @@ static void gui_internal_resize(void *data, int w, int h) { navit_handle_resize(this->nav, w, h); if (this->root.children) { if (changed) { - gui_internal_html_main_menu(this); + char *href=g_strdup(this->href); + dbg(lvl_error,"href=%s",href); + /*if (*href != '\0') { + gui_internal_prune_menu(this, NULL); + gui_internal_html_load_href(this, href, 0); + } + else*/ { + dbg(lvl_error, "Called resize with w=%d, h=%d", w, h) + gui_internal_menu_resize(this, w, h); //Lionel!!! + gui_internal_menu_render(this); + } + g_free(href); } else { gui_internal_menu_render(this); } diff --git a/navit/gui/internal/gui_internal_menu.c b/navit/gui/internal/gui_internal_menu.c index 9da7f2e4c..857e1e0b2 100644 --- a/navit/gui/internal/gui_internal_menu.c +++ b/navit/gui/internal/gui_internal_menu.c @@ -83,6 +83,30 @@ void gui_internal_prune_menu_count(struct gui_priv *this, int count, int render) } } +void gui_internal_menu_topbox_resize(struct gui_priv *this, struct widget *w, void *data, int neww, int newh) { + w->w=neww; + w->h=newh; +} + +void gui_internal_menu_menu_resize(struct gui_priv *this, struct widget *w, void *data, int neww, int newh) { + struct padding *padding = NULL; + + if (this->gra) { + padding = graphics_get_data(this->gra, "padding"); + } else + dbg(lvl_warning, "cannot get padding: this->gra is NULL"); + if (padding) { + w->p.x = padding->left; + w->p.y = padding->top; + w->w = neww - padding->left - padding->right; + w->h = newh - padding->top - padding->bottom; + } else { + w->p.x = 0; + w->p.y = 0; + w->w = neww; + w->h = newh; + } +} /** * @brief Initializes a GUI screen @@ -110,22 +134,12 @@ gui_internal_menu(struct gui_priv *this, const char *label) { gui_internal_search_idle_end(this); topbox=gui_internal_box_new_with_label(this, 0, label); - topbox->w=this->root.w; - topbox->h=this->root.h; + topbox->on_resize=gui_internal_menu_topbox_resize; gui_internal_widget_append(&this->root, topbox); menu=gui_internal_box_new(this, gravity_left_center|orientation_vertical); - - if (padding) { - menu->p.x = padding->left; - menu->p.y = padding->top; - menu->w = topbox->w - padding->left - padding->right; - menu->h = topbox->h - padding->top - padding->bottom; - } else { - menu->p.x = 0; - menu->p.y = 0; - menu->w = topbox->w; - menu->h = topbox->h; - } + menu->on_resize=gui_internal_menu_menu_resize; + topbox->on_resize(this, topbox, NULL, this->root.w, this->root.h); + menu->on_resize(this, menu, NULL, topbox->w, topbox->h); menu->background=this->background; gui_internal_apply_config(this); topbox->menu_data=g_new0(struct menu_data, 1); @@ -156,17 +170,8 @@ gui_internal_menu(struct gui_priv *this, const char *label) { } if (this->flags & 192) { menu=gui_internal_box_new(this, gravity_left_center|orientation_vertical); - if (padding) { - menu->p.x = padding->left; - menu->p.y = padding->top; - menu->w = topbox->w - padding->left - padding->right; - menu->h = topbox->h - padding->top - padding->bottom; - } else { - menu->p.x = 0; - menu->p.y = 0; - menu->w = topbox->w; - menu->h = topbox->h; - } + menu->on_resize=gui_internal_menu_menu_resize; + menu->on_resize(this, menu, NULL, topbox->w, topbox->h); w1=gui_internal_time_help(this); gui_internal_widget_append(menu, w1); w1=gui_internal_box_new(this, gravity_center|orientation_horizontal_vertical|flags_expand|flags_fill); @@ -176,19 +181,10 @@ gui_internal_menu(struct gui_priv *this, const char *label) { } gui_internal_widget_pack(this, topbox); gui_internal_widget_reset_pack(this, topbox); - topbox->w=this->root.w; - topbox->h=this->root.h; - if (padding) { - menu->p.x = padding->left; - menu->p.y = padding->top; - menu->w = topbox->w - padding->left - padding->right; - menu->h = topbox->h - padding->top - padding->bottom; - } else { - menu->p.x = 0; - menu->p.y = 0; - menu->w = topbox->w; - menu->h = topbox->h; - } + if (topbox->on_resize) + topbox->on_resize(this, topbox, NULL, this->root.w, this->root.h); + if (menu->on_resize) + menu->on_resize(this, menu, NULL, topbox->w, topbox->h); return w; } @@ -211,6 +207,14 @@ void gui_internal_menu_reset_pack(struct gui_priv *this) { gui_internal_widget_reset_pack(this, top_box); } +/** + * @brief Renders a menu GUI on the display + * + * @note The whole sequence of menus is kept in this->root.children (when going back one page, we just move to the previous child in the list) + * Thus, only the last child of this->root.children is actually displayed + * + * @param this The internal GUI context + */ void gui_internal_menu_render(struct gui_priv *this) { GList *l; struct widget *menu; @@ -222,6 +226,31 @@ void gui_internal_menu_render(struct gui_priv *this) { gui_internal_widget_render(this, menu); } +void gui_internal_menu_resize(struct gui_priv *this, int w, int h) { + GList *l; + struct widget *menu; + struct widget *topbox; + struct widget *wb; + + gui_internal_apply_config(this); + l=g_list_last(this->root.children); + menu=l->data; + /* Search for the topbox widget */ + l=g_list_first(menu->children); + topbox=l->data; + if (menu->on_resize) + menu->on_resize(this, menu, NULL, topbox->w, topbox->h); + if (topbox->on_resize) + topbox->on_resize(this, topbox, NULL, this->root.w, this->root.h); + l=topbox->children; + while (l) { + wb=l->data; + if (wb->on_resize) + wb->on_resize(this, wb, NULL, topbox->w, topbox->h); + l=g_list_next(l); + } +} + struct widget * gui_internal_top_bar(struct gui_priv *this) { struct widget *w,*wm,*wh,*wc,*wcn; diff --git a/navit/gui/internal/gui_internal_menu.h b/navit/gui/internal/gui_internal_menu.h index 57e37d91c..6f020d1f1 100644 --- a/navit/gui/internal/gui_internal_menu.h +++ b/navit/gui/internal/gui_internal_menu.h @@ -8,5 +8,6 @@ struct widget *gui_internal_menu(struct gui_priv *this, const char *label); struct menu_data *gui_internal_menu_data(struct gui_priv *this); void gui_internal_menu_reset_pack(struct gui_priv *this); void gui_internal_menu_render(struct gui_priv *this); +void gui_internal_menu_resize(struct gui_priv *this, int w, int h); struct widget *gui_internal_top_bar(struct gui_priv *this); /* end of prototypes */ diff --git a/navit/gui/internal/gui_internal_widget.c b/navit/gui/internal/gui_internal_widget.c index aa4c9eeef..3e9d9e123 100644 --- a/navit/gui/internal/gui_internal_widget.c +++ b/navit/gui/internal/gui_internal_widget.c @@ -12,6 +12,7 @@ #include "gui_internal_menu.h" static void gui_internal_scroll_buttons_init(struct gui_priv *this, struct widget *widget, struct scroll_buttons *sb); +void gui_internal_table_resize(struct gui_priv * this, struct widget * w, int wnew, int hnew); static void gui_internal_background_render(struct gui_priv *this, struct widget *w) { struct point pnt=w->p; @@ -133,6 +134,15 @@ static void gui_internal_label_render(struct gui_priv *this, struct widget *w) { } } +/** + * @brief Resize a label. + * + * @param this The internal GUI instance + * @param w The widget to render + */ +static void gui_internal_label_resize(struct gui_priv *this, struct widget *w, int wnew, int hnew) { +} + /** * @brief Creates a text box. * @@ -325,7 +335,6 @@ static void gui_internal_box_render(struct gui_priv *this, struct widget *w) { gui_internal_widget_render(this, w->scroll_buttons->button_box); } - /** * @brief Computes the size and location for the widget. * @@ -599,6 +608,21 @@ static void gui_internal_box_pack(struct gui_priv *this, struct widget *w) { } } +static void gui_internal_box_resize(struct gui_priv *this, struct widget *w, int wnew, int hnew) { + GList *l; + + gui_internal_widget_reset_pack(this, w); + w->w = wnew; + w->h = hnew; + if (w->on_resize) + w->on_resize(this, w, NULL, wnew, hnew); + + gui_internal_box_pack(this, w); + if (w->on_resize) + w->on_resize(this, w, NULL, wnew, hnew); + /* Note: this widget and its children have been resized, a call to gui_internal_box_render() needs to be done by the caller */ +} + void gui_internal_widget_reset_pack(struct gui_priv *this, struct widget *w) { struct widget *wc; GList *l; @@ -739,6 +763,31 @@ void gui_internal_widget_render(struct gui_priv *this, struct widget *w) { } } +void gui_internal_widget_resize(struct gui_priv *this, struct widget *w, int wnew, int hnew) { + if(w->p.x > this->root.w || w->p.y > this->root.h || w->state & STATE_INVISIBLE) + return; + + switch (w->type) { + case widget_box: + dbg(lvl_error, "Resizing box at %p to w=%d, h=%d", w, wnew, hnew); + gui_internal_box_resize(this, w, wnew, hnew); + break; + case widget_label: + dbg(lvl_error, "Resizing label at %p to w=%d, h=%d (text=\"%s\")", w, wnew, hnew, w->text); + gui_internal_label_resize(this, w, wnew, hnew); + break; + case widget_image: + dbg(lvl_error, "resize not yet implemented for widget_image"); + break; + case widget_table: + dbg(lvl_error, "Not resizing table at %p to w=%d, h=%d", w, wnew, hnew); + //gui_internal_table_resize(this, w, wnew, hnew); + break; + default: + break; + } +} + void gui_internal_widget_pack(struct gui_priv *this, struct widget *w) { switch (w->type) { case widget_box: @@ -1308,6 +1357,22 @@ void gui_internal_table_render(struct gui_priv * this, struct widget * w) { g_list_free(column_desc); } +/** + * @brief Resize a table widget. + * + * @param this The graphics context + * @param w The table widget to render. + */ +void gui_internal_table_resize(struct gui_priv * this, struct widget * w, int wnew, int hnew) { + + + w->w = wnew; + w->h = hnew; + + gui_internal_widget_reset_pack(this, w); + gui_internal_table_pack(this, w); +} + /** * @brief Handles the 'next page' table event. * diff --git a/navit/gui/internal/gui_internal_widget.h b/navit/gui/internal/gui_internal_widget.h index 33f03e478..9017b3741 100644 --- a/navit/gui/internal/gui_internal_widget.h +++ b/navit/gui/internal/gui_internal_widget.h @@ -18,10 +18,15 @@ struct widget { struct graphics_image *img; /** * A function to be invoked on actions. - * @li widget The widget that is receiving the button press. + * @param widget The widget that is receiving the button press. * */ void (*func)(struct gui_priv *priv, struct widget *widget, void *data); + /** + * A function to be invoked on resize or move + * @param widged The widget that is resized + */ + void (*on_resize)(struct gui_priv *priv, struct widget *widget, void *data, int neww, int newh); enum gui_internal_reason reason; int datai; void *data; @@ -174,6 +179,7 @@ void gui_internal_widget_insert_sorted(struct widget *parent, struct widget *chi void gui_internal_widget_children_destroy(struct gui_priv *this, struct widget *w); void gui_internal_widget_destroy(struct gui_priv *this, struct widget *w); void gui_internal_widget_render(struct gui_priv *this, struct widget *w); +void gui_internal_widget_resize(struct gui_priv *this, struct widget *w, int wnew, int hnew); void gui_internal_widget_pack(struct gui_priv *this, struct widget *w); struct widget *gui_internal_button_label(struct gui_priv *this, const char *label, int mode); struct widget *gui_internal_widget_table_new(struct gui_priv *this, enum flags flags, int buttons); -- cgit v1.2.1 From 2b49f03299f8124916957482257f7833d80c299c Mon Sep 17 00:00:00 2001 From: Lionel AINS Date: Sun, 7 Oct 2018 15:25:08 +0200 Subject: Fixing indentation to comply to guidelines --- navit/gui/internal/gui_internal.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/navit/gui/internal/gui_internal.c b/navit/gui/internal/gui_internal.c index 574d1fd90..c799779cf 100644 --- a/navit/gui/internal/gui_internal.c +++ b/navit/gui/internal/gui_internal.c @@ -2701,18 +2701,18 @@ static void gui_internal_resize(void *data, int w, int h) { navit_handle_resize(this->nav, w, h); if (this->root.children) { if (changed) { - char *href=g_strdup(this->href); - dbg(lvl_error,"href=%s",href); - /*if (*href != '\0') { - gui_internal_prune_menu(this, NULL); - gui_internal_html_load_href(this, href, 0); - } - else*/ { - dbg(lvl_error, "Called resize with w=%d, h=%d", w, h) - gui_internal_menu_resize(this, w, h); //Lionel!!! - gui_internal_menu_render(this); - } - g_free(href); + char *href=g_strdup(this->href); + dbg(lvl_error,"href=%s",href); + /*if (*href != '\0') { + gui_internal_prune_menu(this, NULL); + gui_internal_html_load_href(this, href, 0); + } + else*/ { + dbg(lvl_error, "Called resize with w=%d, h=%d", w, h) + gui_internal_menu_resize(this, w, h); //Lionel!!! + gui_internal_menu_render(this); + } + g_free(href); } else { gui_internal_menu_render(this); } -- cgit v1.2.1 From 884a91567c215afa9bac6eec926a7c6e9851ee78 Mon Sep 17 00:00:00 2001 From: Lionel AINS Date: Sat, 13 Oct 2018 11:50:00 +0200 Subject: Handling resize differently on menus (reloading the whole menu instead of resizing widgets) --- navit/gui/internal/gui_internal.c | 39 +++++++++++++--------- navit/gui/internal/gui_internal_menu.c | 59 ++++++++++++++++++++++++++-------- navit/gui/internal/gui_internal_menu.h | 4 +++ 3 files changed, 73 insertions(+), 29 deletions(-) diff --git a/navit/gui/internal/gui_internal.c b/navit/gui/internal/gui_internal.c index c799779cf..016ec92a3 100644 --- a/navit/gui/internal/gui_internal.c +++ b/navit/gui/internal/gui_internal.c @@ -2680,15 +2680,18 @@ static void gui_internal_setup(struct gui_priv *this) { //# Comment: //# Authors: Martin Schaller (04/2008) //############################################################################################################## -static void gui_internal_resize(void *data, int w, int h) { +static void gui_internal_resize(void *data, int wnew, int hnew) { + GList *l; + struct widget *w; + struct gui_priv *this=data; int changed=0; gui_internal_setup(this); - if (this->root.w != w || this->root.h != h) { - this->root.w=w; - this->root.h=h; + if (this->root.w != wnew || this->root.h != hnew) { + this->root.w=wnew; + this->root.h=hnew; changed=1; } /* @@ -2697,22 +2700,26 @@ static void gui_internal_resize(void *data, int w, int h) { */ if (!changed && this->gra && graphics_get_data(this->gra, "padding")) changed = 1; - dbg(lvl_debug,"w=%d h=%d children=%p", w, h, this->root.children); - navit_handle_resize(this->nav, w, h); + dbg(lvl_debug,"w=%d h=%d children=%p", wnew, hnew, this->root.children); + navit_handle_resize(this->nav, wnew, hnew); if (this->root.children) { if (changed) { - char *href=g_strdup(this->href); - dbg(lvl_error,"href=%s",href); - /*if (*href != '\0') { - gui_internal_prune_menu(this, NULL); - gui_internal_html_load_href(this, href, 0); + l = g_list_last(this->root.children); + if (l) { + w=l->data; + void (*redisplay)(struct gui_priv *priv, struct widget *widget, void *data); + redisplay=w->menu_data->redisplay; + dbg(lvl_error, "redisplay%c=NULL", redisplay?'!':'='); + if (!gui_internal_widget_reload_href(this, w)) { + dbg(lvl_error, "Current GUI displayed is not a menu"); + dbg(lvl_error, "Will call resize with w=%d, h=%d", wnew, hnew) + gui_internal_menu_resize(this, wnew, hnew); + gui_internal_menu_render(this); + } } - else*/ { - dbg(lvl_error, "Called resize with w=%d, h=%d", w, h) - gui_internal_menu_resize(this, w, h); //Lionel!!! - gui_internal_menu_render(this); + else { + dbg(lvl_error,"Current GUI displayed is a menu"); } - g_free(href); } else { gui_internal_menu_render(this); } diff --git a/navit/gui/internal/gui_internal_menu.c b/navit/gui/internal/gui_internal_menu.c index 857e1e0b2..4b9512b0a 100644 --- a/navit/gui/internal/gui_internal_menu.c +++ b/navit/gui/internal/gui_internal_menu.c @@ -17,7 +17,7 @@ extern char *version; -static void gui_internal_menu_destroy(struct gui_priv *this, struct widget *w) { +void gui_internal_menu_destroy(struct gui_priv *this, struct widget *w) { struct menu_data *menu_data=w->menu_data; if (menu_data) { if (menu_data->refresh_callback_obj.type) { @@ -36,11 +36,53 @@ static void gui_internal_menu_destroy(struct gui_priv *this, struct widget *w) { this->root.children=g_list_remove(this->root.children, w); } +/** + * @brief Retrieve then html anchor (href) from a menu widger + * + * @param w A widget corresponding to a menu (this widget should be an html menu) + * + * @return the string for the href, or NULL if this menu has no href (or the widget is not a menu) + */ +static char *gui_internal_widget_get_href(struct widget *w) { + if (w && w->menu_data) + return w->menu_data->href; + else + return NULL; +} + +/** + * @brief Reload a menu from its anchor (href) + * + * @param this The internal GUI context + * @param w A widget corresponding to the menu to redraw (this widget should be an html menu, thus it should have a href) + * + * @return 1 in case of success, 0 if no menu could be reloaded + * @note If the widget provided in @p w has no href, we will return 0 + */ +int gui_internal_widget_reload_href(struct gui_priv *this, struct widget *w) { + char *ohref = gui_internal_widget_get_href(w); + if (ohref) { + char *href=g_strdup(ohref); + gui_internal_menu_destroy(this, w); + gui_internal_html_load_href(this, href, 0); + g_free(href); + return 1; + } + return 0; +} + +/** + * @brief Destroy (discard) all menu screens that have been placed after widget @p w + * + * @param this The internal GUI context + * @param w A widget corresponding to the last menu to keep (all subsequent menus in the list will be destroyed). NULL if all menus should be destroyed. + * @param render whether we should render the menu indicated by widget w (render!=0) or not (render==0) + */ static void gui_internal_prune_menu_do(struct gui_priv *this, struct widget *w, int render) { GList *l; struct widget *wr,*wd; gui_internal_search_idle_end(this); - while ((l = g_list_last(this->root.children))) { + while ((l = g_list_last(this->root.children))) { /* Destroy all menus, backwards, starting from the end until we reach widget w, and redraw widget w */ wd=l->data; if (wd == w) { void (*redisplay)(struct gui_priv *priv, struct widget *widget, void *data); @@ -49,7 +91,7 @@ static void gui_internal_prune_menu_do(struct gui_priv *this, struct widget *w, gui_internal_say(this, w, 0); redisplay=w->menu_data->redisplay; wr=w->menu_data->redisplay_widget; - if (!w->menu_data->redisplay && !w->menu_data->href) { + if (!redisplay && !gui_internal_widget_get_href(w)) { gui_internal_widget_render(this, w); return; } @@ -57,10 +99,7 @@ static void gui_internal_prune_menu_do(struct gui_priv *this, struct widget *w, gui_internal_menu_destroy(this, w); redisplay(this, wr, wr->data); } else { - char *href=g_strdup(w->menu_data->href); - gui_internal_menu_destroy(this, w); - gui_internal_html_load_href(this, href, 0); - g_free(href); + gui_internal_widget_reload_href(this, w); } return; } @@ -125,12 +164,6 @@ void gui_internal_menu_menu_resize(struct gui_priv *this, struct widget *w, void struct widget * gui_internal_menu(struct gui_priv *this, const char *label) { struct widget *menu,*w,*w1,*topbox; - struct padding *padding = NULL; - - if (this->gra) { - padding = graphics_get_data(this->gra, "padding"); - } else - dbg(lvl_warning, "cannot get padding: this->gra is NULL"); gui_internal_search_idle_end(this); topbox=gui_internal_box_new_with_label(this, 0, label); diff --git a/navit/gui/internal/gui_internal_menu.h b/navit/gui/internal/gui_internal_menu.h index 6f020d1f1..7bbf7892a 100644 --- a/navit/gui/internal/gui_internal_menu.h +++ b/navit/gui/internal/gui_internal_menu.h @@ -2,8 +2,12 @@ struct gui_priv; struct menu_data; struct widget; +void gui_internal_menu_destroy(struct gui_priv *this, struct widget *w); +int gui_internal_widget_reload_href(struct gui_priv *this, struct widget *w); void gui_internal_prune_menu(struct gui_priv *this, struct widget *w); void gui_internal_prune_menu_count(struct gui_priv *this, int count, int render); +void gui_internal_menu_topbox_resize(struct gui_priv *this, struct widget *w, void *data, int neww, int newh); +void gui_internal_menu_menu_resize(struct gui_priv *this, struct widget *w, void *data, int neww, int newh); struct widget *gui_internal_menu(struct gui_priv *this, const char *label); struct menu_data *gui_internal_menu_data(struct gui_priv *this); void gui_internal_menu_reset_pack(struct gui_priv *this); -- cgit v1.2.1 From 29a4b09f8c0232f4fa99be71627a8c2c41fd02ed Mon Sep 17 00:00:00 2001 From: Lionel AINS Date: Sat, 13 Oct 2018 12:07:45 +0200 Subject: Fixing previous merge --- navit/gui/internal/gui_internal_widget.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/navit/gui/internal/gui_internal_widget.h b/navit/gui/internal/gui_internal_widget.h index 383eeaded..098e9645c 100644 --- a/navit/gui/internal/gui_internal_widget.h +++ b/navit/gui/internal/gui_internal_widget.h @@ -26,7 +26,7 @@ struct widget { * A function to be invoked on resize or move * @param widged The widget that is resized */ - void (*on_resize)(struct gui_priv *priv, struct widget + void (*on_resize)(struct gui_priv *priv, struct widget *widget, void *data, int neww, int newh); enum gui_internal_reason reason; int datai; void *data; -- cgit v1.2.1 From 4886c93b4461799f9742275ed5ee5ed2d31dee22 Mon Sep 17 00:00:00 2001 From: Lionel AINS Date: Sun, 14 Oct 2018 14:21:26 +0200 Subject: Fixing compilation warning and indentation according to style --- navit/gui/internal/gui_internal.c | 5 ++--- navit/gui/internal/gui_internal_menu.c | 29 +++++++++++++++-------------- navit/gui/internal/gui_internal_widget.c | 1 - 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/navit/gui/internal/gui_internal.c b/navit/gui/internal/gui_internal.c index 23b1ba007..34ac3eab9 100644 --- a/navit/gui/internal/gui_internal.c +++ b/navit/gui/internal/gui_internal.c @@ -2710,7 +2710,7 @@ static void gui_internal_resize(void *data, int wnew, int hnew) { if (changed) { l = g_list_last(this->root.children); if (l) { - w=l->data; + w=l->data; void (*redisplay)(struct gui_priv *priv, struct widget *widget, void *data); redisplay=w->menu_data->redisplay; dbg(lvl_error, "redisplay%c=NULL", redisplay?'!':'='); @@ -2720,8 +2720,7 @@ static void gui_internal_resize(void *data, int wnew, int hnew) { gui_internal_menu_resize(this, wnew, hnew); gui_internal_menu_render(this); } - } - else { + } else { dbg(lvl_error,"Current GUI displayed is a menu"); } } else { diff --git a/navit/gui/internal/gui_internal_menu.c b/navit/gui/internal/gui_internal_menu.c index 4b9512b0a..7225c96b0 100644 --- a/navit/gui/internal/gui_internal_menu.c +++ b/navit/gui/internal/gui_internal_menu.c @@ -44,10 +44,10 @@ void gui_internal_menu_destroy(struct gui_priv *this, struct widget *w) { * @return the string for the href, or NULL if this menu has no href (or the widget is not a menu) */ static char *gui_internal_widget_get_href(struct widget *w) { - if (w && w->menu_data) - return w->menu_data->href; - else - return NULL; + if (w && w->menu_data) + return w->menu_data->href; + else + return NULL; } /** @@ -60,15 +60,15 @@ static char *gui_internal_widget_get_href(struct widget *w) { * @note If the widget provided in @p w has no href, we will return 0 */ int gui_internal_widget_reload_href(struct gui_priv *this, struct widget *w) { - char *ohref = gui_internal_widget_get_href(w); - if (ohref) { - char *href=g_strdup(ohref); - gui_internal_menu_destroy(this, w); - gui_internal_html_load_href(this, href, 0); - g_free(href); - return 1; - } - return 0; + char *ohref = gui_internal_widget_get_href(w); + if (ohref) { + char *href=g_strdup(ohref); + gui_internal_menu_destroy(this, w); + gui_internal_html_load_href(this, href, 0); + g_free(href); + return 1; + } + return 0; } /** @@ -82,7 +82,8 @@ static void gui_internal_prune_menu_do(struct gui_priv *this, struct widget *w, GList *l; struct widget *wr,*wd; gui_internal_search_idle_end(this); - while ((l = g_list_last(this->root.children))) { /* Destroy all menus, backwards, starting from the end until we reach widget w, and redraw widget w */ + /* Destroy all menus, backwards, starting from the end until we reach widget w, and redraw widget w */ + while ((l = g_list_last(this->root.children))) { wd=l->data; if (wd == w) { void (*redisplay)(struct gui_priv *priv, struct widget *widget, void *data); diff --git a/navit/gui/internal/gui_internal_widget.c b/navit/gui/internal/gui_internal_widget.c index 3e9d9e123..791c6826c 100644 --- a/navit/gui/internal/gui_internal_widget.c +++ b/navit/gui/internal/gui_internal_widget.c @@ -609,7 +609,6 @@ static void gui_internal_box_pack(struct gui_priv *this, struct widget *w) { } static void gui_internal_box_resize(struct gui_priv *this, struct widget *w, int wnew, int hnew) { - GList *l; gui_internal_widget_reset_pack(this, w); w->w = wnew; -- cgit v1.2.1 From 59948f00ece870973facf2df0e45afd0c3088702 Mon Sep 17 00:00:00 2001 From: Lionel AINS Date: Mon, 15 Oct 2018 08:43:02 +0200 Subject: Cleanup and doxygen doc --- navit/gui/internal/gui_internal.c | 18 ++++++++++------ navit/gui/internal/gui_internal_widget.c | 36 ++++++++++++++++++++++++-------- navit/gui/internal/gui_internal_widget.h | 2 +- 3 files changed, 40 insertions(+), 16 deletions(-) diff --git a/navit/gui/internal/gui_internal.c b/navit/gui/internal/gui_internal.c index 34ac3eab9..2c48efd0c 100644 --- a/navit/gui/internal/gui_internal.c +++ b/navit/gui/internal/gui_internal.c @@ -2679,11 +2679,16 @@ static void gui_internal_setup(struct gui_priv *this) { g_free(gui_file); } -//############################################################################################################## -//# Description: -//# Comment: -//# Authors: Martin Schaller (04/2008) -//############################################################################################################## +/** + * @brief Callback function invoked when display area is resized + * + * @param data A generic argument structure pointer, here we use it to store the the internal GUI context (this) + * @param wnew The new width of the display area + * @param hnew The new height of the display area + * + * @author Martin Schaller + * @date 2008/04 + */ static void gui_internal_resize(void *data, int wnew, int hnew) { GList *l; struct widget *w; @@ -2714,7 +2719,8 @@ static void gui_internal_resize(void *data, int wnew, int hnew) { void (*redisplay)(struct gui_priv *priv, struct widget *widget, void *data); redisplay=w->menu_data->redisplay; dbg(lvl_error, "redisplay%c=NULL", redisplay?'!':'='); - if (!gui_internal_widget_reload_href(this, w)) { + if (!gui_internal_widget_reload_href(this, w)) { /* If the foremost widget is a HTML menu, reload & redraw it from its href */ + /* If not, resize the foremost widget */ dbg(lvl_error, "Current GUI displayed is not a menu"); dbg(lvl_error, "Will call resize with w=%d, h=%d", wnew, hnew) gui_internal_menu_resize(this, wnew, hnew); diff --git a/navit/gui/internal/gui_internal_widget.c b/navit/gui/internal/gui_internal_widget.c index 791c6826c..e91810164 100644 --- a/navit/gui/internal/gui_internal_widget.c +++ b/navit/gui/internal/gui_internal_widget.c @@ -139,6 +139,8 @@ static void gui_internal_label_render(struct gui_priv *this, struct widget *w) { * * @param this The internal GUI instance * @param w The widget to render + * @param wnew The new width of the widget + * @param hnew THe new height of the widget */ static void gui_internal_label_resize(struct gui_priv *this, struct widget *w, int wnew, int hnew) { } @@ -608,6 +610,14 @@ static void gui_internal_box_pack(struct gui_priv *this, struct widget *w) { } } +/** + * @brief Resize a box widget. + * + * @param this The internal GUI instance + * @param w The widget to render + * @param wnew The new width of the widget + * @param hnew THe new height of the widget + */ static void gui_internal_box_resize(struct gui_priv *this, struct widget *w, int wnew, int hnew) { gui_internal_widget_reset_pack(this, w); @@ -762,6 +772,14 @@ void gui_internal_widget_render(struct gui_priv *this, struct widget *w) { } } +/** + * @brief Generic widget resize function (that will call the appropriate resize function depending on the widget type). + * + * @param this The internal GUI instance + * @param w The widget to render + * @param wnew The new width of the widget + * @param hnew THe new height of the widget + */ void gui_internal_widget_resize(struct gui_priv *this, struct widget *w, int wnew, int hnew) { if(w->p.x > this->root.w || w->p.y > this->root.h || w->state & STATE_INVISIBLE) return; @@ -775,12 +793,11 @@ void gui_internal_widget_resize(struct gui_priv *this, struct widget *w, int wne dbg(lvl_error, "Resizing label at %p to w=%d, h=%d (text=\"%s\")", w, wnew, hnew, w->text); gui_internal_label_resize(this, w, wnew, hnew); break; - case widget_image: - dbg(lvl_error, "resize not yet implemented for widget_image"); + case widget_image: /* No resize needed for images */ break; case widget_table: - dbg(lvl_error, "Not resizing table at %p to w=%d, h=%d", w, wnew, hnew); - //gui_internal_table_resize(this, w, wnew, hnew); + dbg(lvl_error, "Resizing table at %p to w=%d, h=%d", w, wnew, hnew); + gui_internal_table_resize(this, w, wnew, hnew); break; default: break; @@ -1359,17 +1376,18 @@ void gui_internal_table_render(struct gui_priv * this, struct widget * w) { /** * @brief Resize a table widget. * - * @param this The graphics context - * @param w The table widget to render. + * @param this The internal GUI instance + * @param w The widget to render + * @param wnew The new width of the widget + * @param hnew THe new height of the widget */ void gui_internal_table_resize(struct gui_priv * this, struct widget * w, int wnew, int hnew) { - w->w = wnew; w->h = hnew; - gui_internal_widget_reset_pack(this, w); - gui_internal_table_pack(this, w); +// gui_internal_widget_reset_pack(this, w); +// gui_internal_table_pack(this, w); } /** diff --git a/navit/gui/internal/gui_internal_widget.h b/navit/gui/internal/gui_internal_widget.h index 098e9645c..c5c5cb681 100644 --- a/navit/gui/internal/gui_internal_widget.h +++ b/navit/gui/internal/gui_internal_widget.h @@ -24,7 +24,7 @@ struct widget { void (*func)(struct gui_priv *priv, struct widget *widget, void *data); /** * A function to be invoked on resize or move - * @param widged The widget that is resized + * @param widget The widget that is resized */ void (*on_resize)(struct gui_priv *priv, struct widget *widget, void *data, int neww, int newh); enum gui_internal_reason reason; -- cgit v1.2.1 From 91a8f7a2b661770453162241f5be38078f6565a3 Mon Sep 17 00:00:00 2001 From: Lionel AINS Date: Mon, 29 Oct 2018 08:25:19 +0100 Subject: Adding virtual keyboard resize handler, improving resize for menu topbox --- navit/gui/internal/gui_internal_keyboard.c | 11 +++++++++++ navit/gui/internal/gui_internal_menu.c | 26 +++++++++----------------- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/navit/gui/internal/gui_internal_keyboard.c b/navit/gui/internal/gui_internal_keyboard.c index 4b2c64cd8..b0c87ce39 100644 --- a/navit/gui/internal/gui_internal_keyboard.c +++ b/navit/gui/internal/gui_internal_keyboard.c @@ -133,6 +133,16 @@ struct gui_internal_keyb_mode { -> datai = (mode & VKBD_MASK_7) | ((x) & VKBD_LAYOUT_MASK) #define SWCASE() MODE(gui_internal_keyb_modes[mode/8].case_mode) #define UMLAUT() MODE(gui_internal_keyb_modes[mode/8].umlaut_mode) + +static void gui_internal_keyboard_topbox_resize(struct gui_priv *this, struct widget *w, void *data, int neww, int newh) { + struct menu_data *md=gui_internal_menu_data(this); + struct widget *old_wkbdb = md->keyboard; + + dbg(lvl_error, "gui_internal_keyboard_topbox_resize called on %p with w=%d, h=%d", w, neww, newh); + dbg(lvl_error, "old keyboard widget was at %p", old_wkbdb); + gui_internal_keyboard_do(this, old_wkbdb, md->keyboard_mode); +} + /** * @brief Creates a new keyboard widget or switches the layout of an existing widget * @@ -176,6 +186,7 @@ gui_internal_keyboard_do(struct gui_priv *this, struct widget *wkbdb, int mode) wkbd->cols=8; wkbd->spx=0; wkbd->spy=0; + wkbd->on_resize=gui_internal_keyboard_topbox_resize; max_w=max_w/8; max_h=max_h/8; // Allows 3 results in the list when searching for Towns wkbd->p.y=max_h*2; diff --git a/navit/gui/internal/gui_internal_menu.c b/navit/gui/internal/gui_internal_menu.c index 7225c96b0..40eb66690 100644 --- a/navit/gui/internal/gui_internal_menu.c +++ b/navit/gui/internal/gui_internal_menu.c @@ -126,6 +126,8 @@ void gui_internal_prune_menu_count(struct gui_priv *this, int count, int render) void gui_internal_menu_topbox_resize(struct gui_priv *this, struct widget *w, void *data, int neww, int newh) { w->w=neww; w->h=newh; + gui_internal_box_resize(this, w, data, w->w, w->h); + /* Note: this widget and its children have been resized, a call to gui_internal_box_render() needs to be done by the caller */ } void gui_internal_menu_menu_resize(struct gui_priv *this, struct widget *w, void *data, int neww, int newh) { @@ -146,6 +148,8 @@ void gui_internal_menu_menu_resize(struct gui_priv *this, struct widget *w, void w->w = neww; w->h = newh; } + gui_internal_box_resize(this, w, data, w->w, w->h); + /* Note: this widget and its children have been resized, a call to gui_internal_box_render() needs to be done by the caller */ } /** @@ -262,26 +266,14 @@ void gui_internal_menu_render(struct gui_priv *this) { void gui_internal_menu_resize(struct gui_priv *this, int w, int h) { GList *l; - struct widget *menu; - struct widget *topbox; - struct widget *wb; + struct widget *menu_topwidget; gui_internal_apply_config(this); l=g_list_last(this->root.children); - menu=l->data; - /* Search for the topbox widget */ - l=g_list_first(menu->children); - topbox=l->data; - if (menu->on_resize) - menu->on_resize(this, menu, NULL, topbox->w, topbox->h); - if (topbox->on_resize) - topbox->on_resize(this, topbox, NULL, this->root.w, this->root.h); - l=topbox->children; - while (l) { - wb=l->data; - if (wb->on_resize) - wb->on_resize(this, wb, NULL, topbox->w, topbox->h); - l=g_list_next(l); + menu_topwidget=l->data; + if (menu_topwidget->on_resize) { + dbg(lvl_error, "Invoking resize handler for menu_topwidget at %p", menu_topwidget); + menu_topwidget->on_resize(this, menu_topwidget, NULL, this->root.w, this->root.h); } } -- cgit v1.2.1 From b8ae292134ae759cb5cb213d5264f728429cf6d1 Mon Sep 17 00:00:00 2001 From: Lionel AINS Date: Mon, 29 Oct 2018 08:32:25 +0100 Subject: Adding virtual keyboard resize handler, improving resize for menu topbox --- navit/gui/internal/gui_internal_widget.c | 79 +++++++++++--------------------- 1 file changed, 28 insertions(+), 51 deletions(-) diff --git a/navit/gui/internal/gui_internal_widget.c b/navit/gui/internal/gui_internal_widget.c index e91810164..082392648 100644 --- a/navit/gui/internal/gui_internal_widget.c +++ b/navit/gui/internal/gui_internal_widget.c @@ -13,6 +13,7 @@ static void gui_internal_scroll_buttons_init(struct gui_priv *this, struct widget *widget, struct scroll_buttons *sb); void gui_internal_table_resize(struct gui_priv * this, struct widget * w, int wnew, int hnew); +void gui_internal_box_pack(struct gui_priv *this, struct widget *w); static void gui_internal_background_render(struct gui_priv *this, struct widget *w) { struct point pnt=w->p; @@ -134,17 +135,6 @@ static void gui_internal_label_render(struct gui_priv *this, struct widget *w) { } } -/** - * @brief Resize a label. - * - * @param this The internal GUI instance - * @param w The widget to render - * @param wnew The new width of the widget - * @param hnew THe new height of the widget - */ -static void gui_internal_label_resize(struct gui_priv *this, struct widget *w, int wnew, int hnew) { -} - /** * @brief Creates a text box. * @@ -298,6 +288,7 @@ gui_internal_box_new_with_label(struct gui_priv *this, enum flags flags, const c widget->text=g_strdup(label); widget->type=widget_box; widget->flags=flags; + widget->on_resize=gui_internal_box_resize; return widget; } @@ -343,7 +334,7 @@ static void gui_internal_box_render(struct gui_priv *this, struct widget *w) { * @param this The internal GUI instance * @param w The widget to render */ -static void gui_internal_box_pack(struct gui_priv *this, struct widget *w) { +void gui_internal_box_pack(struct gui_priv *this, struct widget *w) { struct widget *wc; int x0,x=0,y=0,width=0,height=0,owidth=0,oheight=0,expand=0,expandd=1,count=0,rows=0,cols=w->cols ? w->cols : 0; int hb=w->scroll_buttons?w->scroll_buttons->button_box->h:0; @@ -618,17 +609,35 @@ static void gui_internal_box_pack(struct gui_priv *this, struct widget *w) { * @param wnew The new width of the widget * @param hnew THe new height of the widget */ -static void gui_internal_box_resize(struct gui_priv *this, struct widget *w, int wnew, int hnew) { +void gui_internal_box_resize(struct gui_priv *this, struct widget *w, void *data, int wnew, int hnew) { + GList *l; + struct widget *wb; - gui_internal_widget_reset_pack(this, w); w->w = wnew; w->h = hnew; - if (w->on_resize) - w->on_resize(this, w, NULL, wnew, hnew); - gui_internal_box_pack(this, w); - if (w->on_resize) - w->on_resize(this, w, NULL, wnew, hnew); + l=w->children; + while (l) { + wb=l->data; + dbg(lvl_error, "Checking if widget at %p has resize handler", wb); + if (wb->on_resize) { + dbg(lvl_error, "Widget at %p has resize handler", wb); + int orientation=w->flags & 0xffff0000; + switch(orientation) { + case orientation_horizontal: + case orientation_vertical: + case orientation_horizontal_vertical: + break; + default: + dbg(lvl_error, "Box has no specific orientation, should be expanded to parent size"); + wb->w = w->w; + wb->h = w->h; + } + wb->on_resize(this, wb, NULL, wb->w, wb->h); + } + l=g_list_next(l); + } + /* Note: this widget and its children have been resized, a call to gui_internal_box_render() needs to be done by the caller */ } @@ -772,38 +781,6 @@ void gui_internal_widget_render(struct gui_priv *this, struct widget *w) { } } -/** - * @brief Generic widget resize function (that will call the appropriate resize function depending on the widget type). - * - * @param this The internal GUI instance - * @param w The widget to render - * @param wnew The new width of the widget - * @param hnew THe new height of the widget - */ -void gui_internal_widget_resize(struct gui_priv *this, struct widget *w, int wnew, int hnew) { - if(w->p.x > this->root.w || w->p.y > this->root.h || w->state & STATE_INVISIBLE) - return; - - switch (w->type) { - case widget_box: - dbg(lvl_error, "Resizing box at %p to w=%d, h=%d", w, wnew, hnew); - gui_internal_box_resize(this, w, wnew, hnew); - break; - case widget_label: - dbg(lvl_error, "Resizing label at %p to w=%d, h=%d (text=\"%s\")", w, wnew, hnew, w->text); - gui_internal_label_resize(this, w, wnew, hnew); - break; - case widget_image: /* No resize needed for images */ - break; - case widget_table: - dbg(lvl_error, "Resizing table at %p to w=%d, h=%d", w, wnew, hnew); - gui_internal_table_resize(this, w, wnew, hnew); - break; - default: - break; - } -} - void gui_internal_widget_pack(struct gui_priv *this, struct widget *w) { switch (w->type) { case widget_box: -- cgit v1.2.1 From 9b01401d5bc5bdf9e025404bbfdcab7281ca8fc5 Mon Sep 17 00:00:00 2001 From: Lionel AINS Date: Mon, 29 Oct 2018 09:24:08 +0100 Subject: Fixing indentation for sanity check --- navit/gui/internal/gui_internal.c | 3 ++- navit/gui/internal/gui_internal_keyboard.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/navit/gui/internal/gui_internal.c b/navit/gui/internal/gui_internal.c index 2c48efd0c..74cadce7b 100644 --- a/navit/gui/internal/gui_internal.c +++ b/navit/gui/internal/gui_internal.c @@ -2719,7 +2719,8 @@ static void gui_internal_resize(void *data, int wnew, int hnew) { void (*redisplay)(struct gui_priv *priv, struct widget *widget, void *data); redisplay=w->menu_data->redisplay; dbg(lvl_error, "redisplay%c=NULL", redisplay?'!':'='); - if (!gui_internal_widget_reload_href(this, w)) { /* If the foremost widget is a HTML menu, reload & redraw it from its href */ + if (!gui_internal_widget_reload_href(this, + w)) { /* If the foremost widget is a HTML menu, reload & redraw it from its href */ /* If not, resize the foremost widget */ dbg(lvl_error, "Current GUI displayed is not a menu"); dbg(lvl_error, "Will call resize with w=%d, h=%d", wnew, hnew) diff --git a/navit/gui/internal/gui_internal_keyboard.c b/navit/gui/internal/gui_internal_keyboard.c index b0c87ce39..49ba1c2f2 100644 --- a/navit/gui/internal/gui_internal_keyboard.c +++ b/navit/gui/internal/gui_internal_keyboard.c @@ -134,7 +134,8 @@ struct gui_internal_keyb_mode { #define SWCASE() MODE(gui_internal_keyb_modes[mode/8].case_mode) #define UMLAUT() MODE(gui_internal_keyb_modes[mode/8].umlaut_mode) -static void gui_internal_keyboard_topbox_resize(struct gui_priv *this, struct widget *w, void *data, int neww, int newh) { +static void gui_internal_keyboard_topbox_resize(struct gui_priv *this, struct widget *w, void *data, + int neww, int newh) { struct menu_data *md=gui_internal_menu_data(this); struct widget *old_wkbdb = md->keyboard; -- cgit v1.2.1 From 23e84340c60aa6889f61bc5550734996fe367b15 Mon Sep 17 00:00:00 2001 From: Lionel AINS Date: Mon, 29 Oct 2018 10:22:11 +0100 Subject: Adding declaration of gui_internal_box_resize() in headers --- navit/gui/internal/gui_internal_widget.h | 1 + 1 file changed, 1 insertion(+) diff --git a/navit/gui/internal/gui_internal_widget.h b/navit/gui/internal/gui_internal_widget.h index c5c5cb681..56bfe12cf 100644 --- a/navit/gui/internal/gui_internal_widget.h +++ b/navit/gui/internal/gui_internal_widget.h @@ -175,6 +175,7 @@ void gui_internal_highlight_do(struct gui_priv *this, struct widget *found); void gui_internal_highlight(struct gui_priv *this); struct widget *gui_internal_box_new_with_label(struct gui_priv *this, enum flags flags, const char *label); struct widget *gui_internal_box_new(struct gui_priv *this, enum flags flags); +void gui_internal_box_resize(struct gui_priv *this, struct widget *w, void *data, int wnew, int hnew); void gui_internal_widget_reset_pack(struct gui_priv *this, struct widget *w); void gui_internal_widget_append(struct widget *parent, struct widget *child); void gui_internal_widget_prepend(struct widget *parent, struct widget *child); -- cgit v1.2.1 From 91e6a05e1520926a9c5897fca4b64bdcf11791ad Mon Sep 17 00:00:00 2001 From: Lionel AINS Date: Mon, 5 Nov 2018 19:35:11 +0100 Subject: Repacking virtual keyboard box on resize events --- navit/gui/internal/gui_internal_keyboard.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/navit/gui/internal/gui_internal_keyboard.c b/navit/gui/internal/gui_internal_keyboard.c index 49ba1c2f2..dceadac01 100644 --- a/navit/gui/internal/gui_internal_keyboard.c +++ b/navit/gui/internal/gui_internal_keyboard.c @@ -178,6 +178,8 @@ gui_internal_keyboard_do(struct gui_priv *this, struct widget *wkbdb, int mode) else render=1; gui_internal_widget_children_destroy(this, wkbdb); + gui_internal_widget_reset_pack(this, wkbdb); + gui_internal_widget_pack(this, wkbdb); } else wkbdb=gui_internal_box_new(this, gravity_center|orientation_horizontal_vertical|flags_fill); md->keyboard=wkbdb; -- cgit v1.2.1 From 7562c5a8f9b404168f7fceeb9ecd202c63586f4f Mon Sep 17 00:00:00 2001 From: Lionel AINS Date: Fri, 16 Nov 2018 08:34:57 +0100 Subject: Creating gui_internal_menu_needs_resizing() function from existing code --- .circleci/config.yml | 6 +++--- navit/gui/internal/gui_internal.c | 7 ++----- navit/gui/internal/gui_internal_menu.c | 23 ++++++++++++++++++++++- navit/gui/internal/gui_internal_menu.h | 1 + 4 files changed, 28 insertions(+), 9 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index eecf98b57..ae6348c25 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -62,18 +62,18 @@ jobs: name: Id command: cat /etc/*release - run: - name: Install cmake gettext libsaxonb-java librsvg2-bin pkg-config + name: Install cmake gettext libsaxonb-java librsvg2-bin pkg-config libprotobuf-c-dev protobuf-c-compiler command: | sudo apt-get update sudo apt-get install -y cmake gettext libsaxonb-java librsvg2-bin pkg-config libprotobuf-c-dev protobuf-c-compiler - cmake ./ -Dsvg2png_scaling:STRING=-1,24,32,48,64,96,128 -Dsvg2png_scaling_nav:STRING=-1,24,32,48,64,96,128 -Dsvg2png_scaling_flag:STRING=-1,24,32,64,96 + cmake ./ -Dsvg2png_scaling:STRING=-1,24,32,48,64,96,128,192,256 -Dsvg2png_scaling_nav:STRING=-1,24,32,48,64,96,128,192,256 -Dsvg2png_scaling_flag:STRING=-1,24,32,64,96 -DUSE_PLUGINS=n -DBUILD_MAPTOOL=n -DXSL_PROCESSING=y -DXSLTS=android,lionel -DANDROID=y -DSAMPLE_MAP=n - run: name: Process icons command: | cd navit/icons make mkdir ../android/res/drawable-nodpi - rename 'y/A-Z/a-z/' * + rename 'y/A-Z/a-z/' *.png cp *.png ../android/res/drawable-nodpi cd ../../ - run: diff --git a/navit/gui/internal/gui_internal.c b/navit/gui/internal/gui_internal.c index 74cadce7b..abe67af33 100644 --- a/navit/gui/internal/gui_internal.c +++ b/navit/gui/internal/gui_internal.c @@ -2698,11 +2698,8 @@ static void gui_internal_resize(void *data, int wnew, int hnew) { gui_internal_setup(this); - if (this->root.w != wnew || this->root.h != hnew) { - this->root.w=wnew; - this->root.h=hnew; - changed=1; - } + changed=gui_internal_menu_needs_resizing(this, &(this->root), wnew, hnew); + /* * If we're drawing behind system bars on Android, watching for actual size changes will not catch * fullscreen toggle events. As a workaround, always assume a size change if padding is supplied. diff --git a/navit/gui/internal/gui_internal_menu.c b/navit/gui/internal/gui_internal_menu.c index 40eb66690..98a2c338e 100644 --- a/navit/gui/internal/gui_internal_menu.c +++ b/navit/gui/internal/gui_internal_menu.c @@ -17,6 +17,27 @@ extern char *version; +/** + * @brief Utility function to check if a menu widget is adapted to the display size or needs resizing (if so, the widget dimensions will be set to match those of the display + * + * @param this The GUI instance + * @param w The menu widget (top widget that should spawn over the entire display) + * @param wdisp The width of the display to check the widget against + * @param hdisp The width of the display to check the widget against + * + * @return true if widget w has the same size as the provided display dimensions + */ + +int gui_internal_menu_needs_resizing(struct gui_priv *this, struct widget *w, int wdisp, int hdisp) { + if (w->w != wdisp || w->h != hdisp) { + w->w=wdisp; + w->h=hdisp; + return 1; + } else { + return 0; + } +} + void gui_internal_menu_destroy(struct gui_priv *this, struct widget *w) { struct menu_data *menu_data=w->menu_data; if (menu_data) { @@ -85,7 +106,7 @@ static void gui_internal_prune_menu_do(struct gui_priv *this, struct widget *w, /* Destroy all menus, backwards, starting from the end until we reach widget w, and redraw widget w */ while ((l = g_list_last(this->root.children))) { wd=l->data; - if (wd == w) { + if (wd == w) { /* This is the widget we want to bring back to display (all subsequent widgets will be destroyed in the loop) */ void (*redisplay)(struct gui_priv *priv, struct widget *widget, void *data); if (!render) return; diff --git a/navit/gui/internal/gui_internal_menu.h b/navit/gui/internal/gui_internal_menu.h index 7bbf7892a..85ab4ff78 100644 --- a/navit/gui/internal/gui_internal_menu.h +++ b/navit/gui/internal/gui_internal_menu.h @@ -2,6 +2,7 @@ struct gui_priv; struct menu_data; struct widget; +int gui_internal_menu_needs_resizing(struct gui_priv *this, struct widget *w, int wdisp, int hdisp); void gui_internal_menu_destroy(struct gui_priv *this, struct widget *w); int gui_internal_widget_reload_href(struct gui_priv *this, struct widget *w); void gui_internal_prune_menu(struct gui_priv *this, struct widget *w); -- cgit v1.2.1 From 081fa131e879806d30627c242bd4dbf5b558caf6 Mon Sep 17 00:00:00 2001 From: Lionel AINS Date: Fri, 16 Nov 2018 18:18:12 +0100 Subject: Forcing resize when display is resized then the user goes back in submenus --- navit/gui/internal/gui_internal.c | 4 ++-- navit/gui/internal/gui_internal_menu.c | 21 +++++++++++++-------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/navit/gui/internal/gui_internal.c b/navit/gui/internal/gui_internal.c index abe67af33..31b6e10d2 100644 --- a/navit/gui/internal/gui_internal.c +++ b/navit/gui/internal/gui_internal.c @@ -2723,9 +2723,9 @@ static void gui_internal_resize(void *data, int wnew, int hnew) { dbg(lvl_error, "Will call resize with w=%d, h=%d", wnew, hnew) gui_internal_menu_resize(this, wnew, hnew); gui_internal_menu_render(this); + } else { + dbg(lvl_error,"Current GUI displayed is a menu"); } - } else { - dbg(lvl_error,"Current GUI displayed is a menu"); } } else { gui_internal_menu_render(this); diff --git a/navit/gui/internal/gui_internal_menu.c b/navit/gui/internal/gui_internal_menu.c index 98a2c338e..4e8b434fe 100644 --- a/navit/gui/internal/gui_internal_menu.c +++ b/navit/gui/internal/gui_internal_menu.c @@ -95,7 +95,7 @@ int gui_internal_widget_reload_href(struct gui_priv *this, struct widget *w) { /** * @brief Destroy (discard) all menu screens that have been placed after widget @p w * - * @param this The internal GUI context + * @param this The internal GUI instance * @param w A widget corresponding to the last menu to keep (all subsequent menus in the list will be destroyed). NULL if all menus should be destroyed. * @param render whether we should render the menu indicated by widget w (render!=0) or not (render==0) */ @@ -112,16 +112,21 @@ static void gui_internal_prune_menu_do(struct gui_priv *this, struct widget *w, return; gui_internal_say(this, w, 0); redisplay=w->menu_data->redisplay; - wr=w->menu_data->redisplay_widget; - if (!redisplay && !gui_internal_widget_get_href(w)) { - gui_internal_widget_render(this, w); - return; - } if (redisplay) { + wr=w->menu_data->redisplay_widget; gui_internal_menu_destroy(this, w); redisplay(this, wr, wr->data); - } else { - gui_internal_widget_reload_href(this, w); + } + else { + if (gui_internal_menu_needs_resizing(this, w, this->root.w, this->root.h)) /* Make sure the new menu we are going to display spawns the whole display (in case there was a resize while a submenu was being displayed) */ + if (!gui_internal_widget_reload_href(this, + w)) { /* If the foremost widget is a HTML menu, reload & redraw it from its href */ + /* If not, resize the foremost widget */ + dbg(lvl_error, "Current GUI displayed is not a menu"); + dbg(lvl_error, "Will call resize with w=%d, h=%d", this->root.w, this->root.h) + gui_internal_menu_resize(this, this->root.w, this->root.h); + gui_internal_menu_render(this); + } } return; } -- cgit v1.2.1 From c255e9cc6c5fdfe5928213c4f642595fac111f4f Mon Sep 17 00:00:00 2001 From: Lionel AINS Date: Sat, 17 Nov 2018 08:51:37 +0100 Subject: Fixing indentation --- navit/gui/internal/gui_internal_menu.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/navit/gui/internal/gui_internal_menu.c b/navit/gui/internal/gui_internal_menu.c index 4e8b434fe..292749954 100644 --- a/navit/gui/internal/gui_internal_menu.c +++ b/navit/gui/internal/gui_internal_menu.c @@ -116,16 +116,16 @@ static void gui_internal_prune_menu_do(struct gui_priv *this, struct widget *w, wr=w->menu_data->redisplay_widget; gui_internal_menu_destroy(this, w); redisplay(this, wr, wr->data); - } - else { - if (gui_internal_menu_needs_resizing(this, w, this->root.w, this->root.h)) /* Make sure the new menu we are going to display spawns the whole display (in case there was a resize while a submenu was being displayed) */ - if (!gui_internal_widget_reload_href(this, - w)) { /* If the foremost widget is a HTML menu, reload & redraw it from its href */ - /* If not, resize the foremost widget */ - dbg(lvl_error, "Current GUI displayed is not a menu"); - dbg(lvl_error, "Will call resize with w=%d, h=%d", this->root.w, this->root.h) - gui_internal_menu_resize(this, this->root.w, this->root.h); - gui_internal_menu_render(this); + } else { + /* Make sure the new menu we are going to display spawns the whole display (in case there was a resize while a submenu was being displayed) */ + if (gui_internal_menu_needs_resizing(this, w, this->root.w, this->root.h)) { + if (!gui_internal_widget_reload_href(this,w)) { /* If the foremost widget is a HTML menu, reload & redraw it from its href */ + /* If not, resize the foremost widget */ + dbg(lvl_error, "Current GUI displayed is not a menu"); + dbg(lvl_error, "Will call resize with w=%d, h=%d", this->root.w, this->root.h) + gui_internal_menu_resize(this, this->root.w, this->root.h); + gui_internal_menu_render(this); + } } } return; -- cgit v1.2.1 From 69d43fc78fee6cf5d77a04c24881ef9ff52e169a Mon Sep 17 00:00:00 2001 From: Lionel AINS Date: Sat, 17 Nov 2018 09:09:41 +0100 Subject: Fixing indentation --- navit/gui/internal/gui_internal_menu.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/navit/gui/internal/gui_internal_menu.c b/navit/gui/internal/gui_internal_menu.c index 292749954..df231f849 100644 --- a/navit/gui/internal/gui_internal_menu.c +++ b/navit/gui/internal/gui_internal_menu.c @@ -119,7 +119,8 @@ static void gui_internal_prune_menu_do(struct gui_priv *this, struct widget *w, } else { /* Make sure the new menu we are going to display spawns the whole display (in case there was a resize while a submenu was being displayed) */ if (gui_internal_menu_needs_resizing(this, w, this->root.w, this->root.h)) { - if (!gui_internal_widget_reload_href(this,w)) { /* If the foremost widget is a HTML menu, reload & redraw it from its href */ + /* If the foremost widget is a HTML menu, reload & redraw it from its href using gui_internal_widget_reload_href() */ + if (!gui_internal_widget_reload_href(this,w)) { /* If not, resize the foremost widget */ dbg(lvl_error, "Current GUI displayed is not a menu"); dbg(lvl_error, "Will call resize with w=%d, h=%d", this->root.w, this->root.h) -- cgit v1.2.1 From 534c50ede66c6c8c3cc763b4d006d45dbd7d07a7 Mon Sep 17 00:00:00 2001 From: Lionel AINS Date: Sat, 17 Nov 2018 09:16:04 +0100 Subject: Fixing indentation --- navit/gui/internal/gui_internal_menu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/navit/gui/internal/gui_internal_menu.c b/navit/gui/internal/gui_internal_menu.c index df231f849..0bddee6dd 100644 --- a/navit/gui/internal/gui_internal_menu.c +++ b/navit/gui/internal/gui_internal_menu.c @@ -119,7 +119,7 @@ static void gui_internal_prune_menu_do(struct gui_priv *this, struct widget *w, } else { /* Make sure the new menu we are going to display spawns the whole display (in case there was a resize while a submenu was being displayed) */ if (gui_internal_menu_needs_resizing(this, w, this->root.w, this->root.h)) { - /* If the foremost widget is a HTML menu, reload & redraw it from its href using gui_internal_widget_reload_href() */ + /* If the foremost widget is a HTML menu, reload & redraw it from its href using gui_internal_widget_reload_href() */ if (!gui_internal_widget_reload_href(this,w)) { /* If not, resize the foremost widget */ dbg(lvl_error, "Current GUI displayed is not a menu"); -- cgit v1.2.1 From 0adf12a0166337bf1c33427e009e7cf6194a0c9a Mon Sep 17 00:00:00 2001 From: Lionel AINS Date: Sat, 17 Nov 2018 15:00:41 +0100 Subject: Fixing bug that has been inserted during re-indentation --- navit/gui/internal/gui_internal_menu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/navit/gui/internal/gui_internal_menu.c b/navit/gui/internal/gui_internal_menu.c index 0bddee6dd..9b2d4b90a 100644 --- a/navit/gui/internal/gui_internal_menu.c +++ b/navit/gui/internal/gui_internal_menu.c @@ -125,8 +125,8 @@ static void gui_internal_prune_menu_do(struct gui_priv *this, struct widget *w, dbg(lvl_error, "Current GUI displayed is not a menu"); dbg(lvl_error, "Will call resize with w=%d, h=%d", this->root.w, this->root.h) gui_internal_menu_resize(this, this->root.w, this->root.h); - gui_internal_menu_render(this); } + gui_internal_menu_render(this); } } return; -- cgit v1.2.1 From b51f7a91b79f40de3701311210725f820a0a21ea Mon Sep 17 00:00:00 2001 From: Lionel AINS Date: Mon, 19 Nov 2018 18:49:50 +0100 Subject: Removing debug logs, adding doxygen comments --- navit/gui/internal/gui_internal.c | 10 ++--- navit/gui/internal/gui_internal_menu.c | 63 ++++++++++++++++++++++++++++---- navit/gui/internal/gui_internal_widget.c | 7 +++- 3 files changed, 64 insertions(+), 16 deletions(-) diff --git a/navit/gui/internal/gui_internal.c b/navit/gui/internal/gui_internal.c index 31b6e10d2..afae9a9f1 100644 --- a/navit/gui/internal/gui_internal.c +++ b/navit/gui/internal/gui_internal.c @@ -2706,25 +2706,21 @@ static void gui_internal_resize(void *data, int wnew, int hnew) { */ if (!changed && this->gra && graphics_get_data(this->gra, "padding")) changed = 1; - dbg(lvl_debug,"w=%d h=%d children=%p", wnew, hnew, this->root.children); navit_handle_resize(this->nav, wnew, hnew); if (this->root.children) { if (changed) { l = g_list_last(this->root.children); if (l) { w=l->data; - void (*redisplay)(struct gui_priv *priv, struct widget *widget, void *data); - redisplay=w->menu_data->redisplay; - dbg(lvl_error, "redisplay%c=NULL", redisplay?'!':'='); if (!gui_internal_widget_reload_href(this, w)) { /* If the foremost widget is a HTML menu, reload & redraw it from its href */ /* If not, resize the foremost widget */ - dbg(lvl_error, "Current GUI displayed is not a menu"); - dbg(lvl_error, "Will call resize with w=%d, h=%d", wnew, hnew) + dbg(lvl_debug, "Current GUI displayed is not a menu"); + dbg(lvl_debug, "Will call resize with w=%d, h=%d", wnew, hnew) gui_internal_menu_resize(this, wnew, hnew); gui_internal_menu_render(this); } else { - dbg(lvl_error,"Current GUI displayed is a menu"); + dbg(lvl_debug,"Current GUI displayed is a menu"); } } } else { diff --git a/navit/gui/internal/gui_internal_menu.c b/navit/gui/internal/gui_internal_menu.c index 9b2d4b90a..5c55bfba6 100644 --- a/navit/gui/internal/gui_internal_menu.c +++ b/navit/gui/internal/gui_internal_menu.c @@ -38,6 +38,12 @@ int gui_internal_menu_needs_resizing(struct gui_priv *this, struct widget *w, in } } +/** + * @brief destroy a menu widget and perform the associated cleanup in the menu & submenu list + * + * @param this The GUI instance + * @param w The menu widget to destroy + */ void gui_internal_menu_destroy(struct gui_priv *this, struct widget *w) { struct menu_data *menu_data=w->menu_data; if (menu_data) { @@ -122,23 +128,34 @@ static void gui_internal_prune_menu_do(struct gui_priv *this, struct widget *w, /* If the foremost widget is a HTML menu, reload & redraw it from its href using gui_internal_widget_reload_href() */ if (!gui_internal_widget_reload_href(this,w)) { /* If not, resize the foremost widget */ - dbg(lvl_error, "Current GUI displayed is not a menu"); - dbg(lvl_error, "Will call resize with w=%d, h=%d", this->root.w, this->root.h) gui_internal_menu_resize(this, this->root.w, this->root.h); } gui_internal_menu_render(this); } } return; - } - gui_internal_menu_destroy(this, wd); + } else + gui_internal_menu_destroy(this, wd); } } +/** + * @brief Destroy (discard) all menu screens that have been placed after widget @p w and redraw the display, showing widget @w + * + * @param this The internal GUI instance + * @param w A widget corresponding to the last menu to keep, and to draw (all subsequent menus in the list will be destroyed). NULL if all menus should be destroyed. + */ void gui_internal_prune_menu(struct gui_priv *this, struct widget *w) { gui_internal_prune_menu_do(this, w, 1); } +/** + * @brief Destroy (discard) the last @p count menu screens + * + * @param this The internal GUI instance + * @param count The number of menus to destroy at the tail of the menu/submenu stack (if <=0, no menu will be destroyed) + * @param render whether we should render the new last menu in the stack (render!=0) or not (render==0) + */ void gui_internal_prune_menu_count(struct gui_priv *this, int count, int render) { GList *l=g_list_last(this->root.children); struct widget *w=NULL; @@ -150,16 +167,49 @@ void gui_internal_prune_menu_count(struct gui_priv *this, int count, int render) } } +/** + * @brief Resize the main box widget (and its children) corresponding to a menu, effectively resizing the whole menu display size + * + * Note: once this function has been run, widget @p w and its children have been resized, a call to gui_internal_box_render() needs to be done by the caller + * + * @param this The internal GUI instance + * @param w A box widget corresponding to the menu + * @param data Some data to pass to the box resize handler + * @param neww The new width of the display + * @param newh The new height of the display + */ void gui_internal_menu_topbox_resize(struct gui_priv *this, struct widget *w, void *data, int neww, int newh) { + + if (w->type != widget_box) { + dbg(lvl_warning, "Called on a non-box widget, ignoring"); + return; + } w->w=neww; w->h=newh; gui_internal_box_resize(this, w, data, w->w, w->h); - /* Note: this widget and its children have been resized, a call to gui_internal_box_render() needs to be done by the caller */ } +/** + * @brief Resize the box widget (and its children) corresponding to a menu + * + * Menus are stored in a main box (topbox) that spawn the entire screen, thus, once the topbox has been resized, it will in turn resize its children, + * effectively resizing the whole menu display size + * + * Note: once this function has been run, widget @p w and its children have been resized, a call to gui_internal_box_render() needs to be done by the caller + * + * @param this The internal GUI instance + * @param w A box widget corresponding to the menu widget + * @param data Some data to pass to the box resize handler + * @param neww The new width of the display + * @param newh The new height of the display + */ void gui_internal_menu_menu_resize(struct gui_priv *this, struct widget *w, void *data, int neww, int newh) { struct padding *padding = NULL; + if (w->type != widget_box) { + dbg(lvl_warning, "Called on a non-box widget, ignoring"); + return; + } if (this->gra) { padding = graphics_get_data(this->gra, "padding"); } else @@ -176,11 +226,10 @@ void gui_internal_menu_menu_resize(struct gui_priv *this, struct widget *w, void w->h = newh; } gui_internal_box_resize(this, w, data, w->w, w->h); - /* Note: this widget and its children have been resized, a call to gui_internal_box_render() needs to be done by the caller */ } /** - * @brief Initializes a GUI screen + * @brief Initializes a GUI menu screen * * This method initializes the internal GUI's screen on which all other elements (such as HTML menus, * dialogs or others) are displayed. diff --git a/navit/gui/internal/gui_internal_widget.c b/navit/gui/internal/gui_internal_widget.c index 082392648..e398babb5 100644 --- a/navit/gui/internal/gui_internal_widget.c +++ b/navit/gui/internal/gui_internal_widget.c @@ -619,14 +619,17 @@ void gui_internal_box_resize(struct gui_priv *this, struct widget *w, void *data l=w->children; while (l) { wb=l->data; - dbg(lvl_error, "Checking if widget at %p has resize handler", wb); if (wb->on_resize) { - dbg(lvl_error, "Widget at %p has resize handler", wb); int orientation=w->flags & 0xffff0000; switch(orientation) { case orientation_horizontal: + dbg(lvl_error, "Box has hrz orientation"); + break; case orientation_vertical: + dbg(lvl_error, "Box has vrt orientation"); + break; case orientation_horizontal_vertical: + dbg(lvl_error, "Box has hrz+vrt orientation"); break; default: dbg(lvl_error, "Box has no specific orientation, should be expanded to parent size"); -- cgit v1.2.1 From 2ed7bc8116b584bf84690ffbe15209919e3f20e6 Mon Sep 17 00:00:00 2001 From: Lionel AINS Date: Mon, 19 Nov 2018 21:45:27 +0100 Subject: Reverting unrelated changes committed by mistake --- .circleci/config.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index ae6348c25..8f07440c7 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -66,14 +66,14 @@ jobs: command: | sudo apt-get update sudo apt-get install -y cmake gettext libsaxonb-java librsvg2-bin pkg-config libprotobuf-c-dev protobuf-c-compiler - cmake ./ -Dsvg2png_scaling:STRING=-1,24,32,48,64,96,128,192,256 -Dsvg2png_scaling_nav:STRING=-1,24,32,48,64,96,128,192,256 -Dsvg2png_scaling_flag:STRING=-1,24,32,64,96 -DUSE_PLUGINS=n -DBUILD_MAPTOOL=n -DXSL_PROCESSING=y -DXSLTS=android,lionel -DANDROID=y -DSAMPLE_MAP=n + cmake ./ -Dsvg2png_scaling:STRING=-1,24,32,48,64,96,128 -Dsvg2png_scaling_nav:STRING=-1,24,32,48,64,96,128 -Dsvg2png_scaling_flag:STRING=-1,24,32,64,96 -DUSE_PLUGINS=n -DBUILD_MAPTOOL=n -DXSL_PROCESSING=y -DXSLTS=android -DANDROID=y -DSAMPLE_MAP=n - run: name: Process icons command: | cd navit/icons make mkdir ../android/res/drawable-nodpi - rename 'y/A-Z/a-z/' *.png + rename 'y/A-Z/a-z/' * cp *.png ../android/res/drawable-nodpi cd ../../ - run: -- cgit v1.2.1 From 8b81d29f2fd233d672bce32720f12c26fd459eda Mon Sep 17 00:00:00 2001 From: Lionel AINS Date: Mon, 19 Nov 2018 22:00:16 +0100 Subject: Moving debugging logs to lvl_debug --- navit/gui/internal/gui_internal_keyboard.c | 4 ++-- navit/gui/internal/gui_internal_menu.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/navit/gui/internal/gui_internal_keyboard.c b/navit/gui/internal/gui_internal_keyboard.c index dceadac01..8e758de4f 100644 --- a/navit/gui/internal/gui_internal_keyboard.c +++ b/navit/gui/internal/gui_internal_keyboard.c @@ -134,13 +134,13 @@ struct gui_internal_keyb_mode { #define SWCASE() MODE(gui_internal_keyb_modes[mode/8].case_mode) #define UMLAUT() MODE(gui_internal_keyb_modes[mode/8].umlaut_mode) + static void gui_internal_keyboard_topbox_resize(struct gui_priv *this, struct widget *w, void *data, int neww, int newh) { struct menu_data *md=gui_internal_menu_data(this); struct widget *old_wkbdb = md->keyboard; - dbg(lvl_error, "gui_internal_keyboard_topbox_resize called on %p with w=%d, h=%d", w, neww, newh); - dbg(lvl_error, "old keyboard widget was at %p", old_wkbdb); + dbg(lvl_debug, "resize called for keyboard widget %p with w=%d, h=%d", w, neww, newh); gui_internal_keyboard_do(this, old_wkbdb, md->keyboard_mode); } diff --git a/navit/gui/internal/gui_internal_menu.c b/navit/gui/internal/gui_internal_menu.c index 5c55bfba6..be6482219 100644 --- a/navit/gui/internal/gui_internal_menu.c +++ b/navit/gui/internal/gui_internal_menu.c @@ -348,7 +348,7 @@ void gui_internal_menu_resize(struct gui_priv *this, int w, int h) { l=g_list_last(this->root.children); menu_topwidget=l->data; if (menu_topwidget->on_resize) { - dbg(lvl_error, "Invoking resize handler for menu_topwidget at %p", menu_topwidget); + dbg(lvl_debug, "Invoking resize handler for menu_topwidget at %p", menu_topwidget); menu_topwidget->on_resize(this, menu_topwidget, NULL, this->root.w, this->root.h); } } -- cgit v1.2.1 From 93d74f9b922da183beda900609ea6fd5df060b50 Mon Sep 17 00:00:00 2001 From: Lionel AINS Date: Tue, 20 Nov 2018 20:59:55 +0100 Subject: Fixing redraw of menus when going back from a submenu (if no window resize has been done in the meantime) --- navit/gui/internal/gui_internal_menu.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/navit/gui/internal/gui_internal_menu.c b/navit/gui/internal/gui_internal_menu.c index be6482219..dda458fd5 100644 --- a/navit/gui/internal/gui_internal_menu.c +++ b/navit/gui/internal/gui_internal_menu.c @@ -119,19 +119,19 @@ static void gui_internal_prune_menu_do(struct gui_priv *this, struct widget *w, gui_internal_say(this, w, 0); redisplay=w->menu_data->redisplay; if (redisplay) { - wr=w->menu_data->redisplay_widget; gui_internal_menu_destroy(this, w); + wr=w->menu_data->redisplay_widget; redisplay(this, wr, wr->data); } else { /* Make sure the new menu we are going to display spawns the whole display (in case there was a resize while a submenu was being displayed) */ - if (gui_internal_menu_needs_resizing(this, w, this->root.w, this->root.h)) { - /* If the foremost widget is a HTML menu, reload & redraw it from its href using gui_internal_widget_reload_href() */ - if (!gui_internal_widget_reload_href(this,w)) { - /* If not, resize the foremost widget */ - gui_internal_menu_resize(this, this->root.w, this->root.h); - } - gui_internal_menu_render(this); + w->w=this->root.w; + w->h=this->root.h; + /* If the foremost widget is a HTML menu, reload & redraw it from its href using gui_internal_widget_reload_href() */ + if (!gui_internal_widget_reload_href(this,w)) { + /* If not, resize the foremost widget */ + gui_internal_menu_resize(this, this->root.w, this->root.h); } + gui_internal_menu_render(this); } return; } else -- cgit v1.2.1 From e5bd1d58cddd5f4dc815343f173e48eb3d019412 Mon Sep 17 00:00:00 2001 From: Lionel AINS Date: Mon, 26 Nov 2018 18:17:43 +0100 Subject: Removing unused code --- navit/gui/internal/gui_internal_menu.c | 116 ++++++++++++++++++++++++------- navit/gui/internal/gui_internal_widget.c | 51 ++++++-------- 2 files changed, 110 insertions(+), 57 deletions(-) diff --git a/navit/gui/internal/gui_internal_menu.c b/navit/gui/internal/gui_internal_menu.c index dda458fd5..153cccf0b 100644 --- a/navit/gui/internal/gui_internal_menu.c +++ b/navit/gui/internal/gui_internal_menu.c @@ -167,28 +167,6 @@ void gui_internal_prune_menu_count(struct gui_priv *this, int count, int render) } } -/** - * @brief Resize the main box widget (and its children) corresponding to a menu, effectively resizing the whole menu display size - * - * Note: once this function has been run, widget @p w and its children have been resized, a call to gui_internal_box_render() needs to be done by the caller - * - * @param this The internal GUI instance - * @param w A box widget corresponding to the menu - * @param data Some data to pass to the box resize handler - * @param neww The new width of the display - * @param newh The new height of the display - */ -void gui_internal_menu_topbox_resize(struct gui_priv *this, struct widget *w, void *data, int neww, int newh) { - - if (w->type != widget_box) { - dbg(lvl_warning, "Called on a non-box widget, ignoring"); - return; - } - w->w=neww; - w->h=newh; - gui_internal_box_resize(this, w, data, w->w, w->h); -} - /** * @brief Resize the box widget (and its children) corresponding to a menu * @@ -248,12 +226,11 @@ gui_internal_menu(struct gui_priv *this, const char *label) { gui_internal_search_idle_end(this); topbox=gui_internal_box_new_with_label(this, 0, label); - topbox->on_resize=gui_internal_menu_topbox_resize; gui_internal_widget_append(&this->root, topbox); menu=gui_internal_box_new(this, gravity_left_center|orientation_vertical); menu->on_resize=gui_internal_menu_menu_resize; topbox->on_resize(this, topbox, NULL, this->root.w, this->root.h); - menu->on_resize(this, menu, NULL, topbox->w, topbox->h); + menu->on_resize(this, menu, NULL, topbox->w, topbox->h); /* We also have to invoke onresize() handler on menu because it is not (yet) set as a child of topbox */ menu->background=this->background; gui_internal_apply_config(this); topbox->menu_data=g_new0(struct menu_data, 1); @@ -297,8 +274,6 @@ gui_internal_menu(struct gui_priv *this, const char *label) { gui_internal_widget_reset_pack(this, topbox); if (topbox->on_resize) topbox->on_resize(this, topbox, NULL, this->root.w, this->root.h); - if (menu->on_resize) - menu->on_resize(this, menu, NULL, topbox->w, topbox->h); return w; } @@ -327,7 +302,7 @@ void gui_internal_menu_reset_pack(struct gui_priv *this) { * @note The whole sequence of menus is kept in this->root.children (when going back one page, we just move to the previous child in the list) * Thus, only the last child of this->root.children is actually displayed * - * @param this The internal GUI context + * @param this The internal GUI instance */ void gui_internal_menu_render(struct gui_priv *this) { GList *l; @@ -340,6 +315,13 @@ void gui_internal_menu_render(struct gui_priv *this) { gui_internal_widget_render(this, menu); } +/** + * @brief Resize the currently displayed menu + * + * @param this The internal GUI instance + * @param w The new width of the display + * @param h the new height of the display + */ void gui_internal_menu_resize(struct gui_priv *this, int w, int h) { GList *l; struct widget *menu_topwidget; @@ -353,6 +335,85 @@ void gui_internal_menu_resize(struct gui_priv *this, int w, int h) { } } +/** + * @brief Transfer the content of one widget into another one (and optionally vice-versa) + * + * @param this The internal GUI instance + * @param[in,out] first The first widget + * @param[in,out] second The second widget + * @param move_only If non nul, transfer only the second widget into the first widget. The second widget is then deallocated and should be be used anymore (this is a move operation) + */ +static void gui_internal_widget_transfer_content(struct gui_priv *this, struct widget *first, struct widget *second, int move_only) { + struct widget *temp; + + if (!first) { + dbg(lvl_error, "Refusing copy: first argument is NULL"); + return; + } + if (!second) { + dbg(lvl_error, "Refusing copy: second argument is NULL"); + return; + } + temp=g_new0(struct widget, 1); + memcpy(temp, first, sizeof(struct widget)); + memcpy(first, second, sizeof(struct widget)); + if (move_only) { + gui_internal_widget_destroy(this, temp); /* This will do a g_free(temp), but will also deallocate all children widgets */ + g_free(second); /* We also free the struct widget pointed to by second, so variable second should not be used anymore from this point */ + } else { + memcpy(second, temp, sizeof(struct widget)); + g_free(temp); + } +} + +/** + * @brief Swap two widgets + * + * @param this The internal GUI instance + * @param[in,out] first The first widget + * @param[in,out] second The second widget + */ +static inline void gui_internal_widget_swap(struct gui_priv *this, struct widget *first, struct widget *second) { + gui_internal_widget_transfer_content(this, first, second, 0); +} + +/** + * @brief Move the content of one widget into another one (the @p src widget is then deallocated and should be be used anymore) + * + * @param this The internal GUI instance + * @param[in,out] dst The destination widget + * @param[in,out] src The source widget + */ +static inline void gui_internal_widget_move(struct gui_priv *this, struct widget *dst, struct widget *src) { + gui_internal_widget_transfer_content(this, dst, src, 1); +} + +/** + * @brief Resize a top bar created using gui_internal_top_bar() + * + * @param this The internal GUI instance + * @param data Some data to pass to the box resize handler + * @param neww The new width of the display + * @param newh The new height of the display + */ +static void gui_internal_top_bar_resize(struct gui_priv *this, struct widget *w, void *data, int neww, int newh) { + struct widget *new_top_bar; + + if (w->type != widget_box) { + dbg(lvl_warning, "Called on a non-box widget, ignoring"); + return; + } + new_top_bar=gui_internal_top_bar(this); + gui_internal_widget_move(this, w, new_top_bar); +} + +/** + * @brief Create an GUI top bar (containing the history of GUI menus and submenus) + * + * @param this The internal GUI instance + * + * @return The newly created top bar widget + */ struct widget * gui_internal_top_bar(struct gui_priv *this) { struct widget *w,*wm,*wh,*wc,*wcn; @@ -387,6 +448,7 @@ gui_internal_top_bar(struct gui_priv *this) { w->bt=6; w->bb=6; } + w->on_resize=gui_internal_top_bar_resize; width=this->root.w-w->bl; if (! (this->flags & 2)) { wm=gui_internal_button_new_with_callback(this, NULL, diff --git a/navit/gui/internal/gui_internal_widget.c b/navit/gui/internal/gui_internal_widget.c index e398babb5..7d5d71058 100644 --- a/navit/gui/internal/gui_internal_widget.c +++ b/navit/gui/internal/gui_internal_widget.c @@ -12,7 +12,6 @@ #include "gui_internal_menu.h" static void gui_internal_scroll_buttons_init(struct gui_priv *this, struct widget *widget, struct scroll_buttons *sb); -void gui_internal_table_resize(struct gui_priv * this, struct widget * w, int wnew, int hnew); void gui_internal_box_pack(struct gui_priv *this, struct widget *w); static void gui_internal_background_render(struct gui_priv *this, struct widget *w) { @@ -90,6 +89,12 @@ gui_internal_image_new(struct gui_priv *this, struct graphics_image *image) { return widget; } +/** + * @brief Renders an image or icon, preparing it for drawing on the display + * + * @param this The internal GUI instance + * @param w The widget to render + */ static void gui_internal_image_render(struct gui_priv *this, struct widget *w) { struct point pnt; @@ -103,7 +108,7 @@ static void gui_internal_image_render(struct gui_priv *this, struct widget *w) { } /** - * @brief Renders a label. + * @brief Renders a label, preparing it for drawing on the display * * @param this The internal GUI instance * @param w The widget to render @@ -329,10 +334,10 @@ static void gui_internal_box_render(struct gui_priv *this, struct widget *w) { } /** - * @brief Computes the size and location for the widget. + * @brief Computes the size and location for a box widget * * @param this The internal GUI instance - * @param w The widget to render + * @param w The widget to pack */ void gui_internal_box_pack(struct gui_priv *this, struct widget *w) { struct widget *wc; @@ -605,7 +610,7 @@ void gui_internal_box_pack(struct gui_priv *this, struct widget *w) { * @brief Resize a box widget. * * @param this The internal GUI instance - * @param w The widget to render + * @param w The widget to resize * @param wnew The new width of the widget * @param hnew THe new height of the widget */ @@ -623,16 +628,13 @@ void gui_internal_box_resize(struct gui_priv *this, struct widget *w, void *data int orientation=w->flags & 0xffff0000; switch(orientation) { case orientation_horizontal: - dbg(lvl_error, "Box has hrz orientation"); - break; case orientation_vertical: - dbg(lvl_error, "Box has vrt orientation"); - break; case orientation_horizontal_vertical: - dbg(lvl_error, "Box has hrz+vrt orientation"); + wb->h = 0; + wb->w = 0; + gui_internal_widget_pack(this, wb); break; default: - dbg(lvl_error, "Box has no specific orientation, should be expanded to parent size"); wb->w = w->w; wb->h = w->h; } @@ -762,6 +764,14 @@ void gui_internal_widget_destroy(struct gui_priv *this, struct widget *w) { } +/** + * @brief Renders widgets, preparing it for drawing on the display + * + * The appropriate render function will be called, depending on the type of widget + * + * @param this The internal GUI instance + * @param w The widget to render + */ void gui_internal_widget_render(struct gui_priv *this, struct widget *w) { if(w->p.x > this->root.w || w->p.y > this->root.h || w->state & STATE_INVISIBLE) return; @@ -1353,23 +1363,6 @@ void gui_internal_table_render(struct gui_priv * this, struct widget * w) { g_list_free(column_desc); } -/** - * @brief Resize a table widget. - * - * @param this The internal GUI instance - * @param w The widget to render - * @param wnew The new width of the widget - * @param hnew THe new height of the widget - */ -void gui_internal_table_resize(struct gui_priv * this, struct widget * w, int wnew, int hnew) { - - w->w = wnew; - w->h = hnew; - -// gui_internal_widget_reset_pack(this, w); -// gui_internal_table_pack(this, w); -} - /** * @brief Handles the 'next page' table event. * @@ -1406,8 +1399,6 @@ void gui_internal_table_button_next(struct gui_priv * this, struct widget * wm, gui_internal_menu_render(this); } - - /** * @brief Handles the 'previous page' table event. * -- cgit v1.2.1 From 9a71d6d29d51dd9b1e565252d092087b4b47457f Mon Sep 17 00:00:00 2001 From: Lionel AINS Date: Mon, 26 Nov 2018 18:23:29 +0100 Subject: Moving widget-related swap and move functions to gui_internal_widget.c --- navit/gui/internal/gui_internal_menu.c | 53 -------------------------------- navit/gui/internal/gui_internal_widget.c | 53 ++++++++++++++++++++++++++++++++ navit/gui/internal/gui_internal_widget.h | 2 ++ 3 files changed, 55 insertions(+), 53 deletions(-) diff --git a/navit/gui/internal/gui_internal_menu.c b/navit/gui/internal/gui_internal_menu.c index 153cccf0b..b5d27955b 100644 --- a/navit/gui/internal/gui_internal_menu.c +++ b/navit/gui/internal/gui_internal_menu.c @@ -335,59 +335,6 @@ void gui_internal_menu_resize(struct gui_priv *this, int w, int h) { } } -/** - * @brief Transfer the content of one widget into another one (and optionally vice-versa) - * - * @param this The internal GUI instance - * @param[in,out] first The first widget - * @param[in,out] second The second widget - * @param move_only If non nul, transfer only the second widget into the first widget. The second widget is then deallocated and should be be used anymore (this is a move operation) - */ -static void gui_internal_widget_transfer_content(struct gui_priv *this, struct widget *first, struct widget *second, int move_only) { - struct widget *temp; - - if (!first) { - dbg(lvl_error, "Refusing copy: first argument is NULL"); - return; - } - if (!second) { - dbg(lvl_error, "Refusing copy: second argument is NULL"); - return; - } - temp=g_new0(struct widget, 1); - memcpy(temp, first, sizeof(struct widget)); - memcpy(first, second, sizeof(struct widget)); - if (move_only) { - gui_internal_widget_destroy(this, temp); /* This will do a g_free(temp), but will also deallocate all children widgets */ - g_free(second); /* We also free the struct widget pointed to by second, so variable second should not be used anymore from this point */ - } else { - memcpy(second, temp, sizeof(struct widget)); - g_free(temp); - } -} - -/** - * @brief Swap two widgets - * - * @param this The internal GUI instance - * @param[in,out] first The first widget - * @param[in,out] second The second widget - */ -static inline void gui_internal_widget_swap(struct gui_priv *this, struct widget *first, struct widget *second) { - gui_internal_widget_transfer_content(this, first, second, 0); -} - -/** - * @brief Move the content of one widget into another one (the @p src widget is then deallocated and should be be used anymore) - * - * @param this The internal GUI instance - * @param[in,out] dst The destination widget - * @param[in,out] src The source widget - */ -static inline void gui_internal_widget_move(struct gui_priv *this, struct widget *dst, struct widget *src) { - gui_internal_widget_transfer_content(this, dst, src, 1); -} - /** * @brief Resize a top bar created using gui_internal_top_bar() * diff --git a/navit/gui/internal/gui_internal_widget.c b/navit/gui/internal/gui_internal_widget.c index 7d5d71058..65f786484 100644 --- a/navit/gui/internal/gui_internal_widget.c +++ b/navit/gui/internal/gui_internal_widget.c @@ -14,6 +14,59 @@ static void gui_internal_scroll_buttons_init(struct gui_priv *this, struct widget *widget, struct scroll_buttons *sb); void gui_internal_box_pack(struct gui_priv *this, struct widget *w); +/** + * @brief Transfer the content of one widget into another one (and optionally vice-versa) + * + * @param this The internal GUI instance + * @param[in,out] first The first widget + * @param[in,out] second The second widget + * @param move_only If non nul, transfer only the second widget into the first widget. The second widget is then deallocated and should be be used anymore (this is a move operation) + */ +static void gui_internal_widget_transfer_content(struct gui_priv *this, struct widget *first, struct widget *second, int move_only) { + struct widget *temp; + + if (!first) { + dbg(lvl_error, "Refusing copy: first argument is NULL"); + return; + } + if (!second) { + dbg(lvl_error, "Refusing copy: second argument is NULL"); + return; + } + temp=g_new0(struct widget, 1); + memcpy(temp, first, sizeof(struct widget)); + memcpy(first, second, sizeof(struct widget)); + if (move_only) { + gui_internal_widget_destroy(this, temp); /* This will do a g_free(temp), but will also deallocate all children widgets */ + g_free(second); /* We also free the struct widget pointed to by second, so variable second should not be used anymore from this point */ + } else { + memcpy(second, temp, sizeof(struct widget)); + g_free(temp); + } +} + +/** + * @brief Swap two widgets + * + * @param this The internal GUI instance + * @param[in,out] first The first widget + * @param[in,out] second The second widget + */ +void gui_internal_widget_swap(struct gui_priv *this, struct widget *first, struct widget *second) { + gui_internal_widget_transfer_content(this, first, second, 0); +} + +/** + * @brief Move the content of one widget into another one (the @p src widget is then deallocated and should be be used anymore) + * + * @param this The internal GUI instance + * @param[in,out] dst The destination widget + * @param[in,out] src The source widget + */ +void gui_internal_widget_move(struct gui_priv *this, struct widget *dst, struct widget *src) { + gui_internal_widget_transfer_content(this, dst, src, 1); +} + static void gui_internal_background_render(struct gui_priv *this, struct widget *w) { struct point pnt=w->p; if (w->state & STATE_HIGHLIGHTED) diff --git a/navit/gui/internal/gui_internal_widget.h b/navit/gui/internal/gui_internal_widget.h index 56bfe12cf..cc24cb44e 100644 --- a/navit/gui/internal/gui_internal_widget.h +++ b/navit/gui/internal/gui_internal_widget.h @@ -156,6 +156,8 @@ struct gui_priv; struct point; struct table_data; struct widget; +void gui_internal_widget_swap(struct gui_priv *this, struct widget *first, struct widget *second); +void gui_internal_widget_move(struct gui_priv *this, struct widget *dst, struct widget *src); struct widget *gui_internal_label_font_new(struct gui_priv *this, const char *text, int font); struct widget *gui_internal_label_new(struct gui_priv *this, const char *text); struct widget *gui_internal_label_new_abbrev(struct gui_priv *this, const char *text, int maxwidth); -- cgit v1.2.1 From f6a110206c4af4b0ab6570df19d46d5b52e5d947 Mon Sep 17 00:00:00 2001 From: Lionel AINS Date: Mon, 26 Nov 2018 19:02:05 +0100 Subject: Fixing indentation --- navit/gui/internal/gui_internal_menu.c | 3 ++- navit/gui/internal/gui_internal_widget.c | 9 ++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/navit/gui/internal/gui_internal_menu.c b/navit/gui/internal/gui_internal_menu.c index b5d27955b..6a0d6a52b 100644 --- a/navit/gui/internal/gui_internal_menu.c +++ b/navit/gui/internal/gui_internal_menu.c @@ -230,7 +230,8 @@ gui_internal_menu(struct gui_priv *this, const char *label) { menu=gui_internal_box_new(this, gravity_left_center|orientation_vertical); menu->on_resize=gui_internal_menu_menu_resize; topbox->on_resize(this, topbox, NULL, this->root.w, this->root.h); - menu->on_resize(this, menu, NULL, topbox->w, topbox->h); /* We also have to invoke onresize() handler on menu because it is not (yet) set as a child of topbox */ + /* We also have to invoke onresize() handler on menu because it is not (yet) set as a child of topbox */ + menu->on_resize(this, menu, NULL, topbox->w, topbox->h); menu->background=this->background; gui_internal_apply_config(this); topbox->menu_data=g_new0(struct menu_data, 1); diff --git a/navit/gui/internal/gui_internal_widget.c b/navit/gui/internal/gui_internal_widget.c index 65f786484..0894be5aa 100644 --- a/navit/gui/internal/gui_internal_widget.c +++ b/navit/gui/internal/gui_internal_widget.c @@ -22,7 +22,8 @@ void gui_internal_box_pack(struct gui_priv *this, struct widget *w); * @param[in,out] second The second widget * @param move_only If non nul, transfer only the second widget into the first widget. The second widget is then deallocated and should be be used anymore (this is a move operation) */ -static void gui_internal_widget_transfer_content(struct gui_priv *this, struct widget *first, struct widget *second, int move_only) { +static void gui_internal_widget_transfer_content(struct gui_priv *this, struct widget *first, struct widget *second, + int move_only) { struct widget *temp; if (!first) { @@ -37,8 +38,10 @@ static void gui_internal_widget_transfer_content(struct gui_priv *this, struct w memcpy(temp, first, sizeof(struct widget)); memcpy(first, second, sizeof(struct widget)); if (move_only) { - gui_internal_widget_destroy(this, temp); /* This will do a g_free(temp), but will also deallocate all children widgets */ - g_free(second); /* We also free the struct widget pointed to by second, so variable second should not be used anymore from this point */ + gui_internal_widget_destroy(this, temp); + /* gui_internal_widget_destroy() will do a g_free(temp), but will also deallocate all children widgets */ + /* Now, we also free the struct widget pointed to by second, so variable second should not be used anymore from this point */ + g_free(second); } else { memcpy(second, temp, sizeof(struct widget)); g_free(temp); -- cgit v1.2.1 From caab2508adce05897c405477486158883cd65b85 Mon Sep 17 00:00:00 2001 From: Lionel AINS Date: Mon, 26 Nov 2018 19:26:51 +0100 Subject: Cleanup --- navit/gui/internal/gui_internal_menu.h | 1 - 1 file changed, 1 deletion(-) diff --git a/navit/gui/internal/gui_internal_menu.h b/navit/gui/internal/gui_internal_menu.h index 85ab4ff78..3906ed23c 100644 --- a/navit/gui/internal/gui_internal_menu.h +++ b/navit/gui/internal/gui_internal_menu.h @@ -7,7 +7,6 @@ void gui_internal_menu_destroy(struct gui_priv *this, struct widget *w); int gui_internal_widget_reload_href(struct gui_priv *this, struct widget *w); void gui_internal_prune_menu(struct gui_priv *this, struct widget *w); void gui_internal_prune_menu_count(struct gui_priv *this, int count, int render); -void gui_internal_menu_topbox_resize(struct gui_priv *this, struct widget *w, void *data, int neww, int newh); void gui_internal_menu_menu_resize(struct gui_priv *this, struct widget *w, void *data, int neww, int newh); struct widget *gui_internal_menu(struct gui_priv *this, const char *label); struct menu_data *gui_internal_menu_data(struct gui_priv *this); -- cgit v1.2.1 From 80979882b2ac8faecad3aa105b15fc8644e6d772 Mon Sep 17 00:00:00 2001 From: Stefan Wildemann Date: Mon, 28 Jan 2019 23:39:33 +0100 Subject: Fix:graphics_qt5:Dont't clear overlays on move This commit keeps the internal pixmap of an overlay intact if resize is called for the overlay, but the actual size was not changed. This keeps icons and so on intact as they are not repainted after resize. --- navit/graphics/qt5/graphics_qt5.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/navit/graphics/qt5/graphics_qt5.cpp b/navit/graphics/qt5/graphics_qt5.cpp index c23a4f60f..c71b951a5 100644 --- a/navit/graphics/qt5/graphics_qt5.cpp +++ b/navit/graphics/qt5/graphics_qt5.cpp @@ -304,7 +304,11 @@ static struct graphics_image_priv* image_new(struct graphics_priv* gr, struct gr } QString key(path); QString renderer_key(key); - QString extension = key.right(key.lastIndexOf(".")); + int index = key.lastIndexOf("."); + QString extension; + if(index > 0) { + extension = key.right(index); + } QFile imagefile(key); if (!imagefile.exists()) { /* file doesn't exit. Either navit wants us to guess file name by @@ -348,7 +352,7 @@ static struct graphics_image_priv* image_new(struct graphics_priv* gr, struct gr } /* check if we got image */ - if (image_priv->pixmap->isNull()) { + if ((image_priv->pixmap == NULL) || (image_priv->pixmap->isNull())) { g_free(image_priv); return NULL; } else { @@ -771,15 +775,18 @@ static void overlay_disable(struct graphics_priv* gr, int disable) { } static void overlay_resize(struct graphics_priv* gr, struct point* p, int w, int h, int wraparound) { - // dbg(lvl_debug,"enter"); + // dbg(lvl_debug,"enter %d %d %d %d %d", p->x, p->y, w, h, wraparound); gr->x = p->x; gr->y = p->y; if (gr->painter != NULL) { delete (gr->painter); } - delete (gr->pixmap); - gr->pixmap = new QPixmap(w, h); - gr->pixmap->fill(Qt::transparent); + /* replacing the pixmap clears the content. Only neccesary if size actually changes */ + if((gr->pixmap->height() != h) || (gr->pixmap->width() != w)) { + delete (gr->pixmap); + gr->pixmap = new QPixmap(w, h); + gr->pixmap->fill(Qt::transparent); + } if (gr->painter != NULL) gr->painter = new QPainter(gr->pixmap); } -- cgit v1.2.1 From 1cc47990b8027e797fc2fcd8785203883e5fee8c Mon Sep 17 00:00:00 2001 From: Stefan Wildemann Date: Tue, 29 Jan 2019 00:01:46 +0100 Subject: Fix:graphics_qt5:Dont't clear windows on fake resize Sometimes it happeenes that resize is called, but the new size equals the old one. This change keeps the contents intact if that happens. --- navit/graphics/qt5/QNavitQuick.cpp | 11 +++++++---- navit/graphics/qt5/QNavitWidget.cpp | 10 ++++++---- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/navit/graphics/qt5/QNavitQuick.cpp b/navit/graphics/qt5/QNavitQuick.cpp index 6981f3af7..801827ebc 100644 --- a/navit/graphics/qt5/QNavitQuick.cpp +++ b/navit/graphics/qt5/QNavitQuick.cpp @@ -171,11 +171,14 @@ void QNavitQuick::geometryChanged(const QRectF& newGeometry, const QRectF& oldGe return; } if (graphics_priv->pixmap != NULL) { - delete graphics_priv->pixmap; - graphics_priv->pixmap = NULL; + if((width() != graphics_priv->pixmap->width()) || (height() != graphics_priv->pixmap->height())) { + delete graphics_priv->pixmap; + graphics_priv->pixmap = NULL; + } + } + if (graphics_priv->pixmap == NULL) { + graphics_priv->pixmap = new QPixmap(width(), height()); } - - graphics_priv->pixmap = new QPixmap(width(), height()); painter = new QPainter(graphics_priv->pixmap); if (painter != NULL) { QBrush brush; diff --git a/navit/graphics/qt5/QNavitWidget.cpp b/navit/graphics/qt5/QNavitWidget.cpp index 9c2b96505..6fcc8084a 100644 --- a/navit/graphics/qt5/QNavitWidget.cpp +++ b/navit/graphics/qt5/QNavitWidget.cpp @@ -95,11 +95,13 @@ void QNavitWidget::paintEvent(QPaintEvent* event) { void QNavitWidget::resizeEvent(QResizeEvent* event) { QPainter* painter = NULL; if (graphics_priv->pixmap != NULL) { - delete graphics_priv->pixmap; - graphics_priv->pixmap = NULL; + if((width() != graphics_priv->pixmap->width()) || (height() != graphics_priv->pixmap->height())) { + delete graphics_priv->pixmap; + graphics_priv->pixmap = NULL; + } + if (graphics_priv->pixmap == NULL) { + graphics_priv->pixmap = new QPixmap(size()); } - - graphics_priv->pixmap = new QPixmap(size()); painter = new QPainter(graphics_priv->pixmap); if (painter != NULL) { QBrush brush; -- cgit v1.2.1 From 02aa1898a263b901ebd85b33efda6e272df7aef5 Mon Sep 17 00:00:00 2001 From: Wildemann Stefan Date: Tue, 29 Jan 2019 10:55:50 +0100 Subject: Fix:graphics_qt5: stlye with astyle to comply with style Use astyle --indent=spaces=4 --style=attach -n --max-code-length=120 -xf -xh to obey styling rules. Btw. a big hurdle for newbies to just fix !one line" if one needs to restyle a whole module for ci... --- navit/graphics/qt5/QNavitQuick.cpp | 1 - navit/graphics/qt5/QNavitQuick.h | 4 +- navit/graphics/qt5/QNavitWidget.cpp | 271 ++++++++++++++++++------------------ navit/graphics/qt5/QNavitWidget.h | 8 +- navit/graphics/qt5/event_qt5.cpp | 1 - navit/graphics/qt5/event_qt5.h | 4 +- navit/graphics/qt5/graphics_qt5.cpp | 25 ++-- navit/graphics/qt5/graphics_qt5.h | 4 +- 8 files changed, 157 insertions(+), 161 deletions(-) diff --git a/navit/graphics/qt5/QNavitQuick.cpp b/navit/graphics/qt5/QNavitQuick.cpp index 801827ebc..4884e6f27 100644 --- a/navit/graphics/qt5/QNavitQuick.cpp +++ b/navit/graphics/qt5/QNavitQuick.cpp @@ -16,7 +16,6 @@ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ -//Style with: clang-format -style=WebKit -i #include #ifdef HAVE_UNISTD_H diff --git a/navit/graphics/qt5/QNavitQuick.h b/navit/graphics/qt5/QNavitQuick.h index 3679e8127..39ddfed1d 100644 --- a/navit/graphics/qt5/QNavitQuick.h +++ b/navit/graphics/qt5/QNavitQuick.h @@ -16,7 +16,6 @@ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ -// style with: clang-format -style=WebKit -i * #ifndef QNAVITQUICK_H #define QNAVITQUICK_H @@ -28,8 +27,7 @@ class QNavitQuick; class QNavitQuick : public QQuickPaintedItem { Q_OBJECT -public: - QNavitQuick(QQuickItem* parent = 0); +public: QNavitQuick(QQuickItem* parent = 0); void paint(QPainter* painter); diff --git a/navit/graphics/qt5/QNavitWidget.cpp b/navit/graphics/qt5/QNavitWidget.cpp index 6fcc8084a..cebaed9a1 100644 --- a/navit/graphics/qt5/QNavitWidget.cpp +++ b/navit/graphics/qt5/QNavitWidget.cpp @@ -16,7 +16,6 @@ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ -// style with: clang-format -style=WebKit -i * #include #ifdef HAVE_UNISTD_H @@ -98,149 +97,149 @@ void QNavitWidget::resizeEvent(QResizeEvent* event) { if((width() != graphics_priv->pixmap->width()) || (height() != graphics_priv->pixmap->height())) { delete graphics_priv->pixmap; graphics_priv->pixmap = NULL; + } + if (graphics_priv->pixmap == NULL) { + graphics_priv->pixmap = new QPixmap(size()); + } + painter = new QPainter(graphics_priv->pixmap); + if (painter != NULL) { + QBrush brush; + painter->fillRect(0, 0, width(), height(), brush); + delete painter; + } + dbg(lvl_debug, "size %dx%d", width(), height()); + dbg(lvl_debug, "pixmap %p %dx%d", graphics_priv->pixmap, graphics_priv->pixmap->width(), + graphics_priv->pixmap->height()); + /* if the root window got resized, tell navit about it */ + if (graphics_priv->root) + resize_callback(graphics_priv, width(), height()); } - if (graphics_priv->pixmap == NULL) { - graphics_priv->pixmap = new QPixmap(size()); - } - painter = new QPainter(graphics_priv->pixmap); - if (painter != NULL) { - QBrush brush; - painter->fillRect(0, 0, width(), height(), brush); - delete painter; - } - dbg(lvl_debug, "size %dx%d", width(), height()); - dbg(lvl_debug, "pixmap %p %dx%d", graphics_priv->pixmap, graphics_priv->pixmap->width(), - graphics_priv->pixmap->height()); - /* if the root window got resized, tell navit about it */ - if (graphics_priv->root) - resize_callback(graphics_priv, width(), height()); -} -void QNavitWidget::mouseEvent(int pressed, QMouseEvent* event) { - struct point p; - // dbg(lvl_debug,"enter"); - p.x = event->x(); - p.y = event->y(); - switch (event->button()) { - case Qt::LeftButton: - callback_list_call_attr_3(graphics_priv->callbacks, attr_button, GINT_TO_POINTER(pressed), GINT_TO_POINTER(1), - GINT_TO_POINTER(&p)); - break; - case Qt::MidButton: - callback_list_call_attr_3(graphics_priv->callbacks, attr_button, GINT_TO_POINTER(pressed), GINT_TO_POINTER(2), - GINT_TO_POINTER(&p)); - break; - case Qt::RightButton: - callback_list_call_attr_3(graphics_priv->callbacks, attr_button, GINT_TO_POINTER(pressed), GINT_TO_POINTER(3), - GINT_TO_POINTER(&p)); - break; - default: - break; + void QNavitWidget::mouseEvent(int pressed, QMouseEvent* event) { + struct point p; + // dbg(lvl_debug,"enter"); + p.x = event->x(); + p.y = event->y(); + switch (event->button()) { + case Qt::LeftButton: + callback_list_call_attr_3(graphics_priv->callbacks, attr_button, GINT_TO_POINTER(pressed), GINT_TO_POINTER(1), + GINT_TO_POINTER(&p)); + break; + case Qt::MidButton: + callback_list_call_attr_3(graphics_priv->callbacks, attr_button, GINT_TO_POINTER(pressed), GINT_TO_POINTER(2), + GINT_TO_POINTER(&p)); + break; + case Qt::RightButton: + callback_list_call_attr_3(graphics_priv->callbacks, attr_button, GINT_TO_POINTER(pressed), GINT_TO_POINTER(3), + GINT_TO_POINTER(&p)); + break; + default: + break; + } } -} -void QNavitWidget::keyPressEvent(QKeyEvent* event) { - dbg(lvl_debug, "enter"); - char key[2]; - int keycode; - char* text = NULL; - - keycode = event->key(); - key[0] = '\0'; - key[1] = '\0'; - switch (keycode) { - case Qt::Key_Up: - key[0] = NAVIT_KEY_UP; - break; - case Qt::Key_Down: - key[0] = NAVIT_KEY_DOWN; - break; - case Qt::Key_Left: - key[0] = NAVIT_KEY_LEFT; - break; - case Qt::Key_Right: - key[0] = NAVIT_KEY_RIGHT; - break; - case Qt::Key_Backspace: - key[0] = NAVIT_KEY_BACKSPACE; - break; - case Qt::Key_Tab: - key[0] = NAVIT_KEY_TAB; - break; - case Qt::Key_Delete: - key[0] = NAVIT_KEY_DELETE; - break; - case Qt::Key_Escape: - key[0] = NAVIT_KEY_BACK; - break; - case Qt::Key_Return: - case Qt::Key_Enter: - key[0] = NAVIT_KEY_RETURN; - break; - case Qt::Key_ZoomIn: - key[0] = NAVIT_KEY_ZOOM_IN; - break; - case Qt::Key_ZoomOut: - key[0] = NAVIT_KEY_ZOOM_OUT; - break; - case Qt::Key_PageUp: - key[0] = NAVIT_KEY_PAGE_UP; - break; - case Qt::Key_PageDown: - key[0] = NAVIT_KEY_PAGE_DOWN; - break; - default: - QString str = event->text(); - if ((str != NULL) && (str.size() != 0)) { - text = str.toUtf8().data(); + void QNavitWidget::keyPressEvent(QKeyEvent* event) { + dbg(lvl_debug, "enter"); + char key[2]; + int keycode; + char* text = NULL; + + keycode = event->key(); + key[0] = '\0'; + key[1] = '\0'; + switch (keycode) { + case Qt::Key_Up: + key[0] = NAVIT_KEY_UP; + break; + case Qt::Key_Down: + key[0] = NAVIT_KEY_DOWN; + break; + case Qt::Key_Left: + key[0] = NAVIT_KEY_LEFT; + break; + case Qt::Key_Right: + key[0] = NAVIT_KEY_RIGHT; + break; + case Qt::Key_Backspace: + key[0] = NAVIT_KEY_BACKSPACE; + break; + case Qt::Key_Tab: + key[0] = NAVIT_KEY_TAB; + break; + case Qt::Key_Delete: + key[0] = NAVIT_KEY_DELETE; + break; + case Qt::Key_Escape: + key[0] = NAVIT_KEY_BACK; + break; + case Qt::Key_Return: + case Qt::Key_Enter: + key[0] = NAVIT_KEY_RETURN; + break; + case Qt::Key_ZoomIn: + key[0] = NAVIT_KEY_ZOOM_IN; + break; + case Qt::Key_ZoomOut: + key[0] = NAVIT_KEY_ZOOM_OUT; + break; + case Qt::Key_PageUp: + key[0] = NAVIT_KEY_PAGE_UP; + break; + case Qt::Key_PageDown: + key[0] = NAVIT_KEY_PAGE_DOWN; + break; + default: + QString str = event->text(); + if ((str != NULL) && (str.size() != 0)) { + text = str.toUtf8().data(); + } } + if (text != NULL) + callback_list_call_attr_1(graphics_priv->callbacks, attr_keypress, (void*)text); + else if (key[0]) + callback_list_call_attr_1(graphics_priv->callbacks, attr_keypress, (void*)key); + else + dbg(lvl_debug, "keyval 0x%x", keycode); } - if (text != NULL) - callback_list_call_attr_1(graphics_priv->callbacks, attr_keypress, (void*)text); - else if (key[0]) - callback_list_call_attr_1(graphics_priv->callbacks, attr_keypress, (void*)key); - else - dbg(lvl_debug, "keyval 0x%x", keycode); -} -void QNavitWidget::mousePressEvent(QMouseEvent* event) { - // dbg(lvl_debug,"enter"); - mouseEvent(1, event); -} - -void QNavitWidget::mouseReleaseEvent(QMouseEvent* event) { - // dbg(lvl_debug,"enter"); - mouseEvent(0, event); -} + void QNavitWidget::mousePressEvent(QMouseEvent* event) { + // dbg(lvl_debug,"enter"); + mouseEvent(1, event); + } -void QNavitWidget::mouseMoveEvent(QMouseEvent* event) { - struct point p; - // dbg(lvl_debug,"enter"); - p.x = event->x(); - p.y = event->y(); - callback_list_call_attr_1(graphics_priv->callbacks, attr_motion, (void*)&p); -} + void QNavitWidget::mouseReleaseEvent(QMouseEvent* event) { + // dbg(lvl_debug,"enter"); + mouseEvent(0, event); + } -void QNavitWidget::wheelEvent(QWheelEvent* event) { - struct point p; - int button; - dbg(lvl_debug, "enter"); - p.x = event->x(); // xy-coordinates of the mouse pointer - p.y = event->y(); - - if (event->delta() > 0) // wheel movement away from the person - button = 4; - else if (event->delta() < 0) // wheel movement towards the person - button = 5; - else - button = -1; - - if (button != -1) { - callback_list_call_attr_3(graphics_priv->callbacks, attr_button, GINT_TO_POINTER(1), GINT_TO_POINTER(button), - GINT_TO_POINTER(&p)); - callback_list_call_attr_3(graphics_priv->callbacks, attr_button, GINT_TO_POINTER(0), GINT_TO_POINTER(button), - GINT_TO_POINTER(&p)); + void QNavitWidget::mouseMoveEvent(QMouseEvent* event) { + struct point p; + // dbg(lvl_debug,"enter"); + p.x = event->x(); + p.y = event->y(); + callback_list_call_attr_1(graphics_priv->callbacks, attr_motion, (void*)&p); } - event->accept(); -} + void QNavitWidget::wheelEvent(QWheelEvent* event) { + struct point p; + int button; + dbg(lvl_debug, "enter"); + p.x = event->x(); // xy-coordinates of the mouse pointer + p.y = event->y(); + + if (event->delta() > 0) // wheel movement away from the person + button = 4; + else if (event->delta() < 0) // wheel movement towards the person + button = 5; + else + button = -1; + + if (button != -1) { + callback_list_call_attr_3(graphics_priv->callbacks, attr_button, GINT_TO_POINTER(1), GINT_TO_POINTER(button), + GINT_TO_POINTER(&p)); + callback_list_call_attr_3(graphics_priv->callbacks, attr_button, GINT_TO_POINTER(0), GINT_TO_POINTER(button), + GINT_TO_POINTER(&p)); + } + + event->accept(); + } diff --git a/navit/graphics/qt5/QNavitWidget.h b/navit/graphics/qt5/QNavitWidget.h index 674b69390..40fb88b19 100644 --- a/navit/graphics/qt5/QNavitWidget.h +++ b/navit/graphics/qt5/QNavitWidget.h @@ -16,7 +16,6 @@ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ -// style with: clang-format -style=WebKit -i * #ifndef __QNavitWidget_h #define __QNavitWidget_h @@ -30,10 +29,9 @@ class QNavitWidget; class QNavitWidget : public QWidget { Q_OBJECT -public: - QNavitWidget(struct graphics_priv* my_graphics_priv, - QWidget* parent, - Qt::WindowFlags flags); +public: QNavitWidget(struct graphics_priv* my_graphics_priv, + QWidget* parent, + Qt::WindowFlags flags); protected: virtual bool event(QEvent* event); diff --git a/navit/graphics/qt5/event_qt5.cpp b/navit/graphics/qt5/event_qt5.cpp index 5c7c3ca27..7186534fe 100644 --- a/navit/graphics/qt5/event_qt5.cpp +++ b/navit/graphics/qt5/event_qt5.cpp @@ -16,7 +16,6 @@ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ -// style with: clang-format -style=WebKit -i * #include #include diff --git a/navit/graphics/qt5/event_qt5.h b/navit/graphics/qt5/event_qt5.h index 892e8fca8..7fe184cd1 100644 --- a/navit/graphics/qt5/event_qt5.h +++ b/navit/graphics/qt5/event_qt5.h @@ -16,15 +16,13 @@ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ -// style with: clang-format -style=WebKit -i * #include #include class qt5_navit_timer : public QObject { Q_OBJECT -public: - qt5_navit_timer(QObject* parent = 0); +public: qt5_navit_timer(QObject* parent = 0); GHashTable* timer_type; GHashTable* timer_callback; GHashTable* watches; diff --git a/navit/graphics/qt5/graphics_qt5.cpp b/navit/graphics/qt5/graphics_qt5.cpp index c71b951a5..6a17bd68e 100644 --- a/navit/graphics/qt5/graphics_qt5.cpp +++ b/navit/graphics/qt5/graphics_qt5.cpp @@ -16,7 +16,6 @@ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ -// style with: clang-format -style=WebKit -i * #include #ifdef HAVE_UNISTD_H @@ -180,7 +179,8 @@ static const char* fontfamilies[] = { * * Allocates a font handle and returnes filled interface stucture */ -static struct graphics_font_priv* font_new(struct graphics_priv* gr, struct graphics_font_methods* meth, char* font, int size, int flags) { +static struct graphics_font_priv* font_new(struct graphics_priv* gr, struct graphics_font_methods* meth, char* font, + int size, int flags) { int a = 0; struct graphics_font_priv* font_priv; dbg(lvl_debug, "enter (font %s, %d, 0x%x)", font, size, flags); @@ -295,7 +295,8 @@ struct graphics_image_methods image_methods = { image_destroy }; -static struct graphics_image_priv* image_new(struct graphics_priv* gr, struct graphics_image_methods* meth, char* path, int* w, int* h, struct point* hot, int rotation) { +static struct graphics_image_priv* image_new(struct graphics_priv* gr, struct graphics_image_methods* meth, char* path, + int* w, int* h, struct point* hot, int rotation) { struct graphics_image_priv* image_priv; // dbg(lvl_debug,"enter %s, %d %d", path, *w, *h); if (path[0] == 0) { @@ -448,7 +449,8 @@ static void draw_circle(struct graphics_priv* gr, struct graphics_gc_priv* gc, s * * Renders given text on gr surface. Draws nice contrast outline around text. */ -static void draw_text(struct graphics_priv* gr, struct graphics_gc_priv* fg, struct graphics_gc_priv* bg, struct graphics_font_priv* font, char* text, struct point* p, int dx, int dy) { +static void draw_text(struct graphics_priv* gr, struct graphics_gc_priv* fg, struct graphics_gc_priv* bg, + struct graphics_font_priv* font, char* text, struct point* p, int dx, int dy) { dbg(lvl_debug, "enter gc=%p, fg=%p, bg=%p pos(%d,%d) d(%d, %d) %s", gr, fg, bg, p->x, p->y, dx, dy, text); QPainter* painter = gr->painter; if (painter == NULL) @@ -539,7 +541,8 @@ static void draw_text(struct graphics_priv* gr, struct graphics_gc_priv* fg, str #endif } -static void draw_image(struct graphics_priv* gr, struct graphics_gc_priv* fg, struct point* p, struct graphics_image_priv* img) { +static void draw_image(struct graphics_priv* gr, struct graphics_gc_priv* fg, struct point* p, + struct graphics_image_priv* img) { // dbg(lvl_debug,"enter"); if (gr->painter != NULL) gr->painter->drawPixmap(p->x, p->y, *img->pixmap); @@ -639,7 +642,8 @@ static void draw_mode(struct graphics_priv* gr, enum draw_mode_num mode) { } } -static struct graphics_priv* overlay_new(struct graphics_priv* gr, struct graphics_methods* meth, struct point* p, int w, int h, int wraparound); +static struct graphics_priv* overlay_new(struct graphics_priv* gr, struct graphics_methods* meth, struct point* p, + int w, int h, int wraparound); void resize_callback(struct graphics_priv* gr, int w, int h) { // dbg(lvl_debug,"enter (%d, %d)", w, h); @@ -729,7 +733,8 @@ static void image_free(struct graphics_priv* gr, struct graphics_image_priv* pri * * Calculates the bounding box around the given text. */ -static void get_text_bbox(struct graphics_priv* gr, struct graphics_font_priv* font, char* text, int dx, int dy, struct point* ret, int estimate) { +static void get_text_bbox(struct graphics_priv* gr, struct graphics_font_priv* font, char* text, int dx, int dy, + struct point* ret, int estimate) { int i; struct point pt; QString tmp = QString::fromUtf8(text); @@ -815,7 +820,8 @@ static struct graphics_methods graphics_methods = { }; /* create new graphics context on given context */ -static struct graphics_priv* overlay_new(struct graphics_priv* gr, struct graphics_methods* meth, struct point* p, int w, int h, int wraparound) { +static struct graphics_priv* overlay_new(struct graphics_priv* gr, struct graphics_methods* meth, struct point* p, + int w, int h, int wraparound) { struct graphics_priv* graphics_priv = NULL; graphics_priv = g_new0(struct graphics_priv, 1); *meth = graphics_methods; @@ -859,7 +865,8 @@ static struct graphics_priv* overlay_new(struct graphics_priv* gr, struct graphi } /* create application and initial graphics context */ -static struct graphics_priv* graphics_qt5_new(struct navit* nav, struct graphics_methods* meth, struct attr** attrs, struct callback_list* cbl) { +static struct graphics_priv* graphics_qt5_new(struct navit* nav, struct graphics_methods* meth, struct attr** attrs, + struct callback_list* cbl) { struct graphics_priv* graphics_priv = NULL; struct attr* event_loop_system = NULL; struct attr* platform = NULL; diff --git a/navit/graphics/qt5/graphics_qt5.h b/navit/graphics/qt5/graphics_qt5.h index f9d19616b..0eed89510 100644 --- a/navit/graphics/qt5/graphics_qt5.h +++ b/navit/graphics/qt5/graphics_qt5.h @@ -16,7 +16,6 @@ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ -// style with: clang-format -style=WebKit -i * #ifndef __graphics_qt_h #define __graphics_qt_h @@ -62,8 +61,7 @@ struct graphics_priv; #if USE_QML class GraphicsPriv : public QObject { Q_OBJECT -public: - GraphicsPriv(struct graphics_priv* gp); +public: GraphicsPriv(struct graphics_priv* gp); ~GraphicsPriv(); void emit_update(); -- cgit v1.2.1 From 28f488ac3facea3103decfae79081697d4772870 Mon Sep 17 00:00:00 2001 From: Wildemann Stefan Date: Tue, 29 Jan 2019 15:11:06 +0100 Subject: Fix:graphics_qt5:Correctly disable single overlay. Only disable "all" overlays, if root pane got disabled. --- navit/graphics/qt5/QNavitQuick.cpp | 5 +- navit/graphics/qt5/QNavitWidget.cpp | 274 ++++++++++++++++++------------------ navit/graphics/qt5/graphics_qt5.cpp | 11 +- 3 files changed, 145 insertions(+), 145 deletions(-) diff --git a/navit/graphics/qt5/QNavitQuick.cpp b/navit/graphics/qt5/QNavitQuick.cpp index 4884e6f27..dcd0d2aa5 100644 --- a/navit/graphics/qt5/QNavitQuick.cpp +++ b/navit/graphics/qt5/QNavitQuick.cpp @@ -90,7 +90,10 @@ void QNavitQuick::paint(QPainter* painter) { painter->drawPixmap(graphics_priv->scroll_x, graphics_priv->scroll_y, *graphics_priv->pixmap, boundingRect().x(), boundingRect().y(), boundingRect().width(), boundingRect().height()); - paintOverlays(painter, graphics_priv, &event); + /* disable on root pane disables ALL overlays (for drag of background) */ + if(!(graphics_priv->disable)) { + paintOverlays(painter, graphics_priv, &event); + } } void QNavitQuick::keyPressEvent(QKeyEvent* event) { diff --git a/navit/graphics/qt5/QNavitWidget.cpp b/navit/graphics/qt5/QNavitWidget.cpp index cebaed9a1..355187b49 100644 --- a/navit/graphics/qt5/QNavitWidget.cpp +++ b/navit/graphics/qt5/QNavitWidget.cpp @@ -88,7 +88,10 @@ void QNavitWidget::paintEvent(QPaintEvent* event) { painter.drawPixmap(event->rect().x(), event->rect().y(), *graphics_priv->pixmap, event->rect().x() - graphics_priv->scroll_x, event->rect().y() - graphics_priv->scroll_y, event->rect().width(), event->rect().height()); - paintOverlays(&painter, graphics_priv, event); + /* disable on root pane disables ALL overlays (for drag of background) */ + if(!(graphics_priv->disable)) { + paintOverlays(&painter, graphics_priv, event); + }; } void QNavitWidget::resizeEvent(QResizeEvent* event) { @@ -98,148 +101,149 @@ void QNavitWidget::resizeEvent(QResizeEvent* event) { delete graphics_priv->pixmap; graphics_priv->pixmap = NULL; } - if (graphics_priv->pixmap == NULL) { - graphics_priv->pixmap = new QPixmap(size()); - } - painter = new QPainter(graphics_priv->pixmap); - if (painter != NULL) { - QBrush brush; - painter->fillRect(0, 0, width(), height(), brush); - delete painter; - } - dbg(lvl_debug, "size %dx%d", width(), height()); - dbg(lvl_debug, "pixmap %p %dx%d", graphics_priv->pixmap, graphics_priv->pixmap->width(), - graphics_priv->pixmap->height()); - /* if the root window got resized, tell navit about it */ - if (graphics_priv->root) - resize_callback(graphics_priv, width(), height()); } - - void QNavitWidget::mouseEvent(int pressed, QMouseEvent* event) { - struct point p; - // dbg(lvl_debug,"enter"); - p.x = event->x(); - p.y = event->y(); - switch (event->button()) { - case Qt::LeftButton: - callback_list_call_attr_3(graphics_priv->callbacks, attr_button, GINT_TO_POINTER(pressed), GINT_TO_POINTER(1), - GINT_TO_POINTER(&p)); - break; - case Qt::MidButton: - callback_list_call_attr_3(graphics_priv->callbacks, attr_button, GINT_TO_POINTER(pressed), GINT_TO_POINTER(2), - GINT_TO_POINTER(&p)); - break; - case Qt::RightButton: - callback_list_call_attr_3(graphics_priv->callbacks, attr_button, GINT_TO_POINTER(pressed), GINT_TO_POINTER(3), - GINT_TO_POINTER(&p)); - break; - default: - break; - } + if (graphics_priv->pixmap == NULL) { + graphics_priv->pixmap = new QPixmap(size()); } - - void QNavitWidget::keyPressEvent(QKeyEvent* event) { - dbg(lvl_debug, "enter"); - char key[2]; - int keycode; - char* text = NULL; - - keycode = event->key(); - key[0] = '\0'; - key[1] = '\0'; - switch (keycode) { - case Qt::Key_Up: - key[0] = NAVIT_KEY_UP; - break; - case Qt::Key_Down: - key[0] = NAVIT_KEY_DOWN; - break; - case Qt::Key_Left: - key[0] = NAVIT_KEY_LEFT; - break; - case Qt::Key_Right: - key[0] = NAVIT_KEY_RIGHT; - break; - case Qt::Key_Backspace: - key[0] = NAVIT_KEY_BACKSPACE; - break; - case Qt::Key_Tab: - key[0] = NAVIT_KEY_TAB; - break; - case Qt::Key_Delete: - key[0] = NAVIT_KEY_DELETE; - break; - case Qt::Key_Escape: - key[0] = NAVIT_KEY_BACK; - break; - case Qt::Key_Return: - case Qt::Key_Enter: - key[0] = NAVIT_KEY_RETURN; - break; - case Qt::Key_ZoomIn: - key[0] = NAVIT_KEY_ZOOM_IN; - break; - case Qt::Key_ZoomOut: - key[0] = NAVIT_KEY_ZOOM_OUT; - break; - case Qt::Key_PageUp: - key[0] = NAVIT_KEY_PAGE_UP; - break; - case Qt::Key_PageDown: - key[0] = NAVIT_KEY_PAGE_DOWN; - break; - default: - QString str = event->text(); - if ((str != NULL) && (str.size() != 0)) { - text = str.toUtf8().data(); - } - } - if (text != NULL) - callback_list_call_attr_1(graphics_priv->callbacks, attr_keypress, (void*)text); - else if (key[0]) - callback_list_call_attr_1(graphics_priv->callbacks, attr_keypress, (void*)key); - else - dbg(lvl_debug, "keyval 0x%x", keycode); + painter = new QPainter(graphics_priv->pixmap); + if (painter != NULL) { + QBrush brush; + painter->fillRect(0, 0, width(), height(), brush); + delete painter; } + dbg(lvl_debug, "size %dx%d", width(), height()); + dbg(lvl_debug, "pixmap %p %dx%d", graphics_priv->pixmap, graphics_priv->pixmap->width(), + graphics_priv->pixmap->height()); + /* if the root window got resized, tell navit about it */ + if (graphics_priv->root) + resize_callback(graphics_priv, width(), height()); +} - void QNavitWidget::mousePressEvent(QMouseEvent* event) { - // dbg(lvl_debug,"enter"); - mouseEvent(1, event); +void QNavitWidget::mouseEvent(int pressed, QMouseEvent* event) { + struct point p; + // dbg(lvl_debug,"enter"); + p.x = event->x(); + p.y = event->y(); + switch (event->button()) { + case Qt::LeftButton: + callback_list_call_attr_3(graphics_priv->callbacks, attr_button, GINT_TO_POINTER(pressed), GINT_TO_POINTER(1), + GINT_TO_POINTER(&p)); + break; + case Qt::MidButton: + callback_list_call_attr_3(graphics_priv->callbacks, attr_button, GINT_TO_POINTER(pressed), GINT_TO_POINTER(2), + GINT_TO_POINTER(&p)); + break; + case Qt::RightButton: + callback_list_call_attr_3(graphics_priv->callbacks, attr_button, GINT_TO_POINTER(pressed), GINT_TO_POINTER(3), + GINT_TO_POINTER(&p)); + break; + default: + break; } +} - void QNavitWidget::mouseReleaseEvent(QMouseEvent* event) { - // dbg(lvl_debug,"enter"); - mouseEvent(0, event); +void QNavitWidget::keyPressEvent(QKeyEvent* event) { + dbg(lvl_debug, "enter"); + char key[2]; + int keycode; + char* text = NULL; + + keycode = event->key(); + key[0] = '\0'; + key[1] = '\0'; + switch (keycode) { + case Qt::Key_Up: + key[0] = NAVIT_KEY_UP; + break; + case Qt::Key_Down: + key[0] = NAVIT_KEY_DOWN; + break; + case Qt::Key_Left: + key[0] = NAVIT_KEY_LEFT; + break; + case Qt::Key_Right: + key[0] = NAVIT_KEY_RIGHT; + break; + case Qt::Key_Backspace: + key[0] = NAVIT_KEY_BACKSPACE; + break; + case Qt::Key_Tab: + key[0] = NAVIT_KEY_TAB; + break; + case Qt::Key_Delete: + key[0] = NAVIT_KEY_DELETE; + break; + case Qt::Key_Escape: + key[0] = NAVIT_KEY_BACK; + break; + case Qt::Key_Return: + case Qt::Key_Enter: + key[0] = NAVIT_KEY_RETURN; + break; + case Qt::Key_ZoomIn: + key[0] = NAVIT_KEY_ZOOM_IN; + break; + case Qt::Key_ZoomOut: + key[0] = NAVIT_KEY_ZOOM_OUT; + break; + case Qt::Key_PageUp: + key[0] = NAVIT_KEY_PAGE_UP; + break; + case Qt::Key_PageDown: + key[0] = NAVIT_KEY_PAGE_DOWN; + break; + default: + QString str = event->text(); + if ((str != NULL) && (str.size() != 0)) { + text = str.toUtf8().data(); + } } + if (text != NULL) + callback_list_call_attr_1(graphics_priv->callbacks, attr_keypress, (void*)text); + else if (key[0]) + callback_list_call_attr_1(graphics_priv->callbacks, attr_keypress, (void*)key); + else + dbg(lvl_debug, "keyval 0x%x", keycode); +} - void QNavitWidget::mouseMoveEvent(QMouseEvent* event) { - struct point p; - // dbg(lvl_debug,"enter"); - p.x = event->x(); - p.y = event->y(); - callback_list_call_attr_1(graphics_priv->callbacks, attr_motion, (void*)&p); - } +void QNavitWidget::mousePressEvent(QMouseEvent* event) { + // dbg(lvl_debug,"enter"); + mouseEvent(1, event); +} - void QNavitWidget::wheelEvent(QWheelEvent* event) { - struct point p; - int button; - dbg(lvl_debug, "enter"); - p.x = event->x(); // xy-coordinates of the mouse pointer - p.y = event->y(); - - if (event->delta() > 0) // wheel movement away from the person - button = 4; - else if (event->delta() < 0) // wheel movement towards the person - button = 5; - else - button = -1; - - if (button != -1) { - callback_list_call_attr_3(graphics_priv->callbacks, attr_button, GINT_TO_POINTER(1), GINT_TO_POINTER(button), - GINT_TO_POINTER(&p)); - callback_list_call_attr_3(graphics_priv->callbacks, attr_button, GINT_TO_POINTER(0), GINT_TO_POINTER(button), - GINT_TO_POINTER(&p)); - } +void QNavitWidget::mouseReleaseEvent(QMouseEvent* event) { + // dbg(lvl_debug,"enter"); + mouseEvent(0, event); +} - event->accept(); +void QNavitWidget::mouseMoveEvent(QMouseEvent* event) { + struct point p; + // dbg(lvl_debug,"enter"); + p.x = event->x(); + p.y = event->y(); + callback_list_call_attr_1(graphics_priv->callbacks, attr_motion, (void*)&p); +} + +void QNavitWidget::wheelEvent(QWheelEvent* event) { + struct point p; + int button; + dbg(lvl_debug, "enter"); + p.x = event->x(); // xy-coordinates of the mouse pointer + p.y = event->y(); + + if (event->delta() > 0) // wheel movement away from the person + button = 4; + else if (event->delta() < 0) // wheel movement towards the person + button = 5; + else + button = -1; + + if (button != -1) { + callback_list_call_attr_3(graphics_priv->callbacks, attr_button, GINT_TO_POINTER(1), GINT_TO_POINTER(button), + GINT_TO_POINTER(&p)); + callback_list_call_attr_3(graphics_priv->callbacks, attr_button, GINT_TO_POINTER(0), GINT_TO_POINTER(button), + GINT_TO_POINTER(&p)); } + + event->accept(); +} diff --git a/navit/graphics/qt5/graphics_qt5.cpp b/navit/graphics/qt5/graphics_qt5.cpp index 6a17bd68e..502cd18e2 100644 --- a/navit/graphics/qt5/graphics_qt5.cpp +++ b/navit/graphics/qt5/graphics_qt5.cpp @@ -768,15 +768,8 @@ static void get_text_bbox(struct graphics_priv* gr, struct graphics_font_priv* f } static void overlay_disable(struct graphics_priv* gr, int disable) { - GHashTableIter iter; - struct graphics_priv *key, *value; - // dbg(lvl_debug,"enter gr=%p, %d", gr, disable); - - g_hash_table_iter_init(&iter, gr->overlays); - while (g_hash_table_iter_next(&iter, (void**)&key, (void**)&value)) { - /* disable or enable all overlays of this pane */ - value->disable = disable; - } + //dbg(lvl_error,"enter gr=%p, %d", gr, disable); + gr->disable = disable; } static void overlay_resize(struct graphics_priv* gr, struct point* p, int w, int h, int wraparound) { -- cgit v1.2.1 From 9993cd9706b0619f61e44cdebecb0eea75680ad5 Mon Sep 17 00:00:00 2001 From: Wildemann Stefan Date: Tue, 29 Jan 2019 15:38:58 +0100 Subject: Fix:graphics_qt5:reorder class members to workaround astyle --- navit/graphics/qt5/QNavitQuick.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/navit/graphics/qt5/QNavitQuick.h b/navit/graphics/qt5/QNavitQuick.h index 39ddfed1d..40c6639ae 100644 --- a/navit/graphics/qt5/QNavitQuick.h +++ b/navit/graphics/qt5/QNavitQuick.h @@ -27,9 +27,10 @@ class QNavitQuick; class QNavitQuick : public QQuickPaintedItem { Q_OBJECT -public: QNavitQuick(QQuickItem* parent = 0); - +public: void paint(QPainter* painter); + QNavitQuick(QQuickItem* parent = 0); + Q_INVOKABLE void setGraphicContext(GraphicsPriv* gp); -- cgit v1.2.1 From 33064cf47768f61479e277094862a806dc1421a7 Mon Sep 17 00:00:00 2001 From: Wildemann Stefan Date: Tue, 29 Jan 2019 17:39:18 +0100 Subject: Fix:graphics_qt5:redraw after overlay action --- navit/graphics/qt5/graphics_qt5.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/navit/graphics/qt5/graphics_qt5.cpp b/navit/graphics/qt5/graphics_qt5.cpp index 502cd18e2..e7b31c605 100644 --- a/navit/graphics/qt5/graphics_qt5.cpp +++ b/navit/graphics/qt5/graphics_qt5.cpp @@ -770,6 +770,16 @@ static void get_text_bbox(struct graphics_priv* gr, struct graphics_font_priv* f static void overlay_disable(struct graphics_priv* gr, int disable) { //dbg(lvl_error,"enter gr=%p, %d", gr, disable); gr->disable = disable; +#if USE_QWIDGET + /* call repaint on widget */ + if (gr->widget != NULL) + gr->widget->repaint(gr->x, gr->y, gr->pixmap->width(), gr->pixmap->height()); +#endif +#if USE_QML + if (gr->GPriv != NULL) + gr->GPriv->emit_update(); + +#endif } static void overlay_resize(struct graphics_priv* gr, struct point* p, int w, int h, int wraparound) { @@ -787,6 +797,16 @@ static void overlay_resize(struct graphics_priv* gr, struct point* p, int w, int } if (gr->painter != NULL) gr->painter = new QPainter(gr->pixmap); +#if USE_QWIDGET + /* call repaint on widget */ + if (gr->widget != NULL) + gr->widget->repaint(gr->x, gr->y, gr->pixmap->width(), gr->pixmap->height()); +#endif +#if USE_QML + if (gr->GPriv != NULL) + gr->GPriv->emit_update(); + +#endif } static struct graphics_methods graphics_methods = { -- cgit v1.2.1 From 474e26635d92f27d4e0af1cd3c7a780c7e78fab3 Mon Sep 17 00:00:00 2001 From: metalstrolch Date: Wed, 30 Jan 2019 22:19:24 +0100 Subject: Fix:vehicle_qt5:Properly update position status --- navit/vehicle/qt5/vehicle_qt5.cpp | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/navit/vehicle/qt5/vehicle_qt5.cpp b/navit/vehicle/qt5/vehicle_qt5.cpp index 5771f1da7..b855d12b9 100644 --- a/navit/vehicle/qt5/vehicle_qt5.cpp +++ b/navit/vehicle/qt5/vehicle_qt5.cpp @@ -116,7 +116,6 @@ void QNavitGeoReceiver::positionUpdated(const QGeoPositionInfo& info) { dbg(lvl_debug, "Got valid coordinate (lat %f, lon %f)", info.coordinate().latitude(), info.coordinate().longitude()); priv->geo.lat = info.coordinate().latitude(); priv->geo.lng = info.coordinate().longitude(); - priv->have_coords = 1; if (info.coordinate().type() == QGeoCoordinate::Coordinate3D) { dbg(lvl_debug, "Got valid altitude (alt %f)", info.coordinate().altitude()); priv->height = info.coordinate().altitude(); @@ -124,10 +123,17 @@ void QNavitGeoReceiver::positionUpdated(const QGeoPositionInfo& info) { //dbg(lvl_debug, "Time %s", info.timestamp().toUTC().toString().toLatin1().data()); priv->fix_time = info.timestamp().toUTC().toTime_t(); callback_list_call_attr_0(priv->cbl, attr_position_coord_geo); + if(priv->have_coords != attr_position_valid_valid) { + priv->have_coords = attr_position_valid_valid; + callback_list_call_attr_0(priv->cbl, attr_position_valid); + } } else { dbg(lvl_debug, "Got invalid coordinate"); - priv->have_coords = 0; callback_list_call_attr_0(priv->cbl, attr_position_coord_geo); + if(priv->have_coords != attr_position_valid_invalid) { + priv->have_coords = attr_position_valid_invalid; + callback_list_call_attr_0(priv->cbl, attr_position_valid); + } } } @@ -185,7 +191,7 @@ static int vehicle_qt5_position_attr_get(struct vehicle_priv* priv, break; case attr_position_coord_geo: attr->u.coord_geo = &priv->geo; - if (!priv->have_coords) + if (priv->have_coords != attr_position_valid_valid) return 0; break; case attr_position_time_iso8601: @@ -233,7 +239,10 @@ static int vehicle_qt5_set_attr(struct vehicle_priv* priv, struct attr* attr) { break; case attr_position_coord_geo: priv->geo = *attr->u.coord_geo; - priv->have_coords = 1; + if(priv->have_coords != attr_position_valid_valid) { + priv->have_coords = attr_position_valid_valid; + callback_list_call_attr_0(priv->cbl, attr_position_valid); + } break; default: break; @@ -273,8 +282,10 @@ static struct vehicle_priv* vehicle_qt5_new_qt5(struct vehicle_methods* meth, } else { dbg(lvl_debug, "Using %s", ret->source->sourceName().toLatin1().data()); ret->receiver = new QNavitGeoReceiver(NULL, ret); - ret->satellites->setUpdateInterval(1000); - ret->satellites->startUpdates(); + if(ret->satellites != NULL) { + ret->satellites->setUpdateInterval(1000); + ret->satellites->startUpdates(); + } ret->source->setUpdateInterval(500); ret->source->startUpdates(); } -- cgit v1.2.1