1 /* gui.h - GUI components header file. */
3 * GRUB -- GRand Unified Bootloader
4 * Copyright (C) 2008,2009 Free Software Foundation, Inc.
6 * GRUB is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * GRUB is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
20 #include <grub/types.h>
22 #include <grub/video.h>
23 #include <grub/bitmap.h>
24 #include <grub/gfxmenu_view.h>
30 /* The component ID identifying GUI components to be updated as the timeout
32 #define GRUB_GFXMENU_TIMEOUT_COMPONENT_ID "__timeout__"
34 typedef struct grub_gui_component
*grub_gui_component_t
;
35 typedef struct grub_gui_container
*grub_gui_container_t
;
36 typedef struct grub_gui_list
*grub_gui_list_t
;
38 typedef void (*grub_gui_component_callback
) (grub_gui_component_t component
,
41 /* Component interface. */
43 struct grub_gui_component_ops
45 void (*destroy
) (void *self
);
46 const char * (*get_id
) (void *self
);
47 int (*is_instance
) (void *self
, const char *type
);
48 void (*paint
) (void *self
, const grub_video_rect_t
*bounds
);
49 void (*set_parent
) (void *self
, grub_gui_container_t parent
);
50 grub_gui_container_t (*get_parent
) (void *self
);
51 void (*set_bounds
) (void *self
, const grub_video_rect_t
*bounds
);
52 void (*get_bounds
) (void *self
, grub_video_rect_t
*bounds
);
53 void (*get_minimal_size
) (void *self
, unsigned *width
, unsigned *height
);
54 grub_err_t (*set_property
) (void *self
, const char *name
, const char *value
);
55 void (*repaint
) (void *self
, int second_pass
);
58 struct grub_gui_container_ops
60 void (*add
) (void *self
, grub_gui_component_t comp
);
61 void (*remove
) (void *self
, grub_gui_component_t comp
);
62 void (*iterate_children
) (void *self
,
63 grub_gui_component_callback cb
, void *userdata
);
66 struct grub_gui_list_ops
68 void (*set_view_info
) (void *self
,
69 grub_gfxmenu_view_t view
);
70 void (*refresh_list
) (void *self
,
71 grub_gfxmenu_view_t view
);
74 struct grub_gui_progress_ops
76 void (*set_state
) (void *self
, int visible
, int start
, int current
, int end
);
79 typedef void (*grub_gfxmenu_set_state_t
) (void *self
, int visible
, int start
,
80 int current
, int end
);
82 struct grub_gfxmenu_timeout_notify
84 struct grub_gfxmenu_timeout_notify
*next
;
85 grub_gfxmenu_set_state_t set_state
;
86 grub_gui_component_t self
;
89 extern struct grub_gfxmenu_timeout_notify
*grub_gfxmenu_timeout_notifications
;
91 static inline grub_err_t
92 grub_gfxmenu_timeout_register (grub_gui_component_t self
,
93 grub_gfxmenu_set_state_t set_state
)
95 struct grub_gfxmenu_timeout_notify
*ne
= grub_malloc (sizeof (*ne
));
98 ne
->set_state
= set_state
;
100 ne
->next
= grub_gfxmenu_timeout_notifications
;
101 grub_gfxmenu_timeout_notifications
= ne
;
102 return GRUB_ERR_NONE
;
106 grub_gfxmenu_timeout_unregister (grub_gui_component_t self
)
108 struct grub_gfxmenu_timeout_notify
**p
, *q
;
110 for (p
= &grub_gfxmenu_timeout_notifications
, q
= *p
;
111 q
; p
= &(q
->next
), q
= q
->next
)
120 typedef signed grub_fixed_signed_t
;
121 #define GRUB_FIXED_1 0x10000
123 /* Special care is taken to round to nearest integer and not just truncate. */
125 grub_divide_round (signed a
, signed b
)
139 ret
= (unsigned) (a
+ b
/ 2) / (unsigned) b
;
140 return neg
? -ret
: ret
;
144 grub_fixed_sfs_divide (signed a
, grub_fixed_signed_t b
)
146 return grub_divide_round (a
* GRUB_FIXED_1
, b
);
149 static inline grub_fixed_signed_t
150 grub_fixed_fsf_divide (grub_fixed_signed_t a
, signed b
)
152 return grub_divide_round (a
, b
);
156 grub_fixed_sfs_multiply (signed a
, grub_fixed_signed_t b
)
158 return (a
* b
) / GRUB_FIXED_1
;
162 grub_fixed_to_signed (grub_fixed_signed_t in
)
164 return in
/ GRUB_FIXED_1
;
167 static inline grub_fixed_signed_t
168 grub_signed_to_fixed (signed in
)
170 return in
* GRUB_FIXED_1
;
173 struct grub_gui_component
175 struct grub_gui_component_ops
*ops
;
177 grub_fixed_signed_t xfrac
;
179 grub_fixed_signed_t yfrac
;
181 grub_fixed_signed_t wfrac
;
183 grub_fixed_signed_t hfrac
;
186 struct grub_gui_progress
188 struct grub_gui_component component
;
189 struct grub_gui_progress_ops
*ops
;
192 struct grub_gui_container
194 struct grub_gui_component component
;
195 struct grub_gui_container_ops
*ops
;
200 struct grub_gui_component component
;
201 struct grub_gui_list_ops
*ops
;
205 /* Interfaces to concrete component classes. */
207 grub_gui_container_t
grub_gui_canvas_new (void);
208 grub_gui_container_t
grub_gui_vbox_new (void);
209 grub_gui_container_t
grub_gui_hbox_new (void);
210 grub_gui_component_t
grub_gui_label_new (void);
211 grub_gui_component_t
grub_gui_image_new (void);
212 grub_gui_component_t
grub_gui_progress_bar_new (void);
213 grub_gui_component_t
grub_gui_list_new (void);
214 grub_gui_component_t
grub_gui_circular_progress_new (void);
216 /* Manipulation functions. */
218 /* Visit all components with the specified ID. */
219 void grub_gui_find_by_id (grub_gui_component_t root
,
221 grub_gui_component_callback cb
,
224 /* Visit all components. */
225 void grub_gui_iterate_recursively (grub_gui_component_t root
,
226 grub_gui_component_callback cb
,
229 /* Helper functions. */
232 grub_gui_save_viewport (grub_video_rect_t
*r
)
234 grub_video_get_viewport ((unsigned *) &r
->x
,
236 (unsigned *) &r
->width
,
237 (unsigned *) &r
->height
);
241 grub_gui_restore_viewport (const grub_video_rect_t
*r
)
243 grub_video_set_viewport (r
->x
, r
->y
, r
->width
, r
->height
);
246 /* Set a new viewport relative the the current one, saving the current
247 viewport in OLD so it can be later restored. */
249 grub_gui_set_viewport (const grub_video_rect_t
*r
, grub_video_rect_t
*old
)
251 grub_gui_save_viewport (old
);
252 grub_video_set_viewport (old
->x
+ r
->x
,
259 grub_video_have_common_points (const grub_video_rect_t
*a
,
260 const grub_video_rect_t
*b
)
262 if (!((a
->x
<= b
->x
&& b
->x
<= a
->x
+ a
->width
)
263 || (b
->x
<= a
->x
&& a
->x
<= b
->x
+ b
->width
)))
265 if (!((a
->y
<= b
->y
&& b
->y
<= a
->y
+ a
->height
)
266 || (b
->y
<= a
->y
&& a
->y
<= b
->y
+ b
->height
)))
272 grub_video_bounds_inside_region (const grub_video_rect_t
*b
,
273 const grub_video_rect_t
*r
)
275 if (r
->x
> b
->x
|| r
->x
+ r
->width
< b
->x
+ b
->width
)
277 if (r
->y
> b
->y
|| r
->y
+ r
->height
< b
->y
+ b
->height
)
282 #endif /* ! GRUB_GUI_H */