Ticket #252: gui_internal_config.diff.sept30

File gui_internal_config.diff.sept30, 7.0 KB (added by Ssinger, 11 years ago)

patch for configurable gui internal settings

Line 
1Index: navit/gui/internal/gui_internal.c
2===================================================================
3--- navit/gui/internal/gui_internal.c   (revision 1419)
4+++ navit/gui/internal/gui_internal.c   (working copy)
5@@ -138,6 +138,57 @@
6        GList *children;
7 };
8 
9+/**
10+ * @brief A structure to store configuration values.
11+ *
12+ * This structure stores configuration values for how gui elements in the internal GUI
13+ * should be drawn. 
14+ */
15+struct gui_config_settings {
16
17+  /**
18+   * The base size (in fractions of a point) to use for text.
19+   */
20+  int font_size;
21+  /**
22+   * The size (in pixels) that xs style icons should be scaled to.
23+   */
24+  int icon_xs;
25+  /**
26+   * The size (in pixels) that s style icons (small) should be scaled to
27+   */
28+  int icon_s;
29+  /**
30+   * The size (in pixels) that l style icons should be scaled to
31+   */
32+  int icon_l;
33+  /**
34+   * The default amount of spacing (in pixels) to place between GUI elements.
35+   */
36+  int spacing;
37
38+};
39+
40+/**
41+ * Indexes into the config_profiles array.
42+ */
43+const int LARGE_PROFILE=0;
44+const int MEDIUM_PROFILE=1;
45+const int SMALL_PROFILE=2;
46+
47+/**
48+ * The default config profiles.
49+ *
50+ * [0] =>  LARGE_PROFILE (screens 640 in one dimension)
51+ * [1] =>  MEDIUM PROFILE (screens larger than 320 in one dimension
52+ * [2] => Small profile (default)
53+ */
54+static struct gui_config_settings config_profiles[]={
55+  {545,32,40,44,2}
56+    , {545,32,48,96,5}
57+      ,{200,16,32,48,2}
58+};
59+
60 //##############################################################################################################
61 //# Description:
62 //# Comment:
63@@ -172,6 +223,11 @@
64        int ignore_button;
65        int menu_on_map_click;
66        char *country_iso2;
67+       /**
68+        * The setting information read from the configuration file.
69+        * values of -1 indicate no value was specified in the config file.
70+        */
71+        struct gui_config_settings config;
72 };
73 
74 static void gui_internal_widget_render(struct gui_priv *this, struct widget *w);
75@@ -179,6 +235,7 @@
76 static struct widget * gui_internal_box_new(struct gui_priv *this, enum flags flags);
77 static void gui_internal_widget_append(struct widget *parent, struct widget *child);
78 static void gui_internal_widget_destroy(struct gui_priv *this, struct widget *w);
79+static void gui_internal_apply_config(struct gui_priv *this);
80 
81 static struct graphics_image *
82 image_new_scaled(struct gui_priv *this, char *name, int w, int h)
83@@ -295,16 +352,18 @@
84 gui_internal_label_new(struct gui_priv *this, char *text)
85 {
86        struct point p[4];
87-       int w=0,h=this->font_size;
88-
89+       int w=0;
90+       int h=0;
91+       
92        struct widget *widget=g_new0(struct widget, 1);
93        widget->type=widget_label;
94        if (text) {
95                widget->text=g_strdup(text);
96                graphics_get_text_bbox(this->gra, this->font, text, 0x10000, 0x0, p);
97                w=p[2].x-p[0].x;
98+               h=p[0].y-p[2].y;
99        }
100-       widget->h=h;
101+       widget->h=h+this->spacing;
102        widget->w=w+this->spacing;
103        widget->flags=gravity_center;
104 
105@@ -1000,36 +1059,101 @@
106        return w;
107 }
108 
109+
110+/**
111+ * Applys the configuration values to this based on the settings
112+ * specified in the configuration file (this->config) and
113+ * the most approriate default profile based on screen resolution.
114+ *
115+ * This function should be run after this->root is setup and could
116+ * be rerun after the window is resized.
117+ *
118+ * @authors Steve Singer <ssinger_pg@sympatico.ca> (09/2008)
119+ */
120+static void gui_internal_apply_config(struct gui_priv *this)
121+{
122+  struct gui_config_settings *  current_config=0;
123+
124+  /**
125+   * Select default values from profile based on the screen.
126+   */
127+  if(this->root.w > 320 || this->root.h > 320)
128+  {
129+    if(this->root.w > 640 || this->root.h > 640)
130+    {
131+      current_config = &config_profiles[LARGE_PROFILE];
132+    }
133+    else
134+    {
135+      current_config = &config_profiles[MEDIUM_PROFILE];
136+    }
137+  }
138+  else
139+  {
140+    current_config = &config_profiles[SMALL_PROFILE];
141+  }
142
143+  /**
144+   * Apply override values from config file
145+   */
146+  if(this->config.font_size == -1 )
147+  {
148+    this->font_size = current_config->font_size;
149+  }
150+  else
151+  {
152+    this->font_size = this->config.font_size;
153+  }
154+
155+  if(this->config.icon_xs == -1 )
156+  {
157+      this->icon_xs = current_config->icon_xs;
158+  }
159+  else
160+  {
161+    this->icon_xs = this->config.icon_xs;
162+  }
163
164+  if(this->config.icon_s == -1 )
165+  {
166+    this->icon_s = current_config->icon_s;
167+  }
168+  else
169+  {
170+    this->icon_s = this->config.icon_s;
171+  }
172+  if(this->config.icon_l == -1 )
173+  {
174+    this->icon_l = current_config->icon_l;
175+  }
176+  else
177+  {
178+    this->icon_l = this->config.icon_l;
179+  }
180+  if(this->config.spacing == -1 )
181+  {
182+    this->spacing = current_config->spacing;
183+  }
184+  else
185+  {
186+    this->spacing = current_config->spacing;
187+  }
188+               
189+}
190+
191 static struct widget *
192 gui_internal_menu(struct gui_priv *this, char *label)
193 {
194        struct widget *menu,*w;
195+       
196+
197        menu=gui_internal_box_new_with_label(this, gravity_center|orientation_vertical, label);
198        menu->w=this->root.w;
199        menu->h=this->root.h;
200        menu->background=this->background;
201-       if (this->root.w > 320 || this->root.h > 320) {
202-               this->font_size=40;
203-               this->icon_xs=32;
204-               this->icon_s=48;
205-               this->icon_l=96;
206-               this->spacing=5;
207-               this->font=graphics_font_new(this->gra, 545, 1);
208-               if (this->root.w > 640 || this->root.h > 640) {
209-                       this->font_size=36;
210-                       this->icon_s=40;
211-                       this->icon_l=44;
212-                       this->spacing=2;
213-                       this->font=graphics_font_new(this->gra, 545, 1);
214-               }
215-       } else {
216-               this->font_size=16;
217-               this->icon_xs=16;
218-               this->icon_s=32;
219-               this->icon_l=48;
220-               this->spacing=2;
221-               this->font=graphics_font_new(this->gra, 200, 1);
222-       }
223+       gui_internal_apply_config(this);
224+       this->font=graphics_font_new(this->gra,this->font_size,1);
225+
226        gui_internal_widget_append(&this->root, menu);
227        w=gui_internal_top_bar(this);
228        gui_internal_widget_append(menu, w);
229@@ -2503,6 +2627,48 @@
230                this->menu_on_map_click=1;
231        navit_command_register(nav,"gui_internal_menu",callback_new_3(gui_internal_cmd_menu,this,NULL,1));
232        navit_command_register(nav,"gui_internal_fullscreen",callback_new_2(gui_internal_cmd_fullscreen,this,NULL));
233+
234+       if( (attr=attr_search(attrs,NULL,attr_font_size)))
235+        {
236+         this->config.font_size=attr->u.num;
237+       }
238+       else
239+       {
240+         this->config.font_size=-1;
241+       }
242+       if( (attr=attr_search(attrs,NULL,attr_icon_xs)))
243+       {
244+         this->config.icon_xs=attr->u.num;
245+       }
246+       else
247+       {
248+         this->config.icon_xs=-1;
249+       }
250+       if( (attr=attr_search(attrs,NULL,attr_icon_l)))
251+       {
252+         this->config.icon_l=attr->u.num;
253+       }
254+       else
255+        {
256+         this->config.icon_l=-1;
257+       }
258+       if( (attr=attr_search(attrs,NULL,attr_icon_s)))
259+       {
260+         this->config.icon_s=attr->u.num;
261+       }
262+       else
263+        {
264+         this->config.icon_s=-1;
265+       }
266+       if( (attr=attr_search(attrs,NULL,attr_spacing)))
267+       {
268+         this->config.spacing=attr->u.num;
269+       }
270+       else
271+       {
272+         this->config.spacing=-1;       
273+       }
274+
275        return this;
276 }
277 
278Index: navit/attr_def.h
279===================================================================
280--- navit/attr_def.h    (revision 1419)
281+++ navit/attr_def.h    (working copy)
282@@ -65,6 +65,11 @@
283 ATTR(antialias)
284 ATTR(order_delta)
285 ATTR(baudrate)
286+ATTR(font_size)
287+ATTR(icon_xs)
288+ATTR(icon_l)
289+ATTR(icon_s)
290+ATTR(spacing)
291 ATTR2(0x00028000,type_boolean_begin)
292 /* boolean */
293 ATTR(overwrite)