diff options
-rw-r--r-- | bootloader/x1000/gui.c | 64 | ||||
-rw-r--r-- | bootloader/x1000/x1000bootloader.h | 24 |
2 files changed, 88 insertions, 0 deletions
diff --git a/bootloader/x1000/gui.c b/bootloader/x1000/gui.c index da20a9b128..a672c30380 100644 --- a/bootloader/x1000/gui.c +++ b/bootloader/x1000/gui.c | |||
@@ -111,3 +111,67 @@ void gui_shutdown(void) | |||
111 | 111 | ||
112 | backlight_hw_off(); | 112 | backlight_hw_off(); |
113 | } | 113 | } |
114 | |||
115 | void gui_list_init(struct bl_list* list, struct viewport* vp) | ||
116 | { | ||
117 | list->vp = vp; | ||
118 | list->num_items = 0; | ||
119 | list->selected_item = 0; | ||
120 | list->top_item = 0; | ||
121 | list->item_height = SYSFONT_HEIGHT; | ||
122 | list->draw_item = NULL; | ||
123 | } | ||
124 | |||
125 | void gui_list_draw(struct bl_list* list) | ||
126 | { | ||
127 | struct bl_listitem item = { | ||
128 | .list = list, | ||
129 | .x = 0, .y = 0, | ||
130 | .width = list->vp->width, | ||
131 | .height = list->item_height, | ||
132 | }; | ||
133 | |||
134 | struct viewport* old_vp = lcd_set_viewport(list->vp); | ||
135 | lcd_clear_viewport(); | ||
136 | |||
137 | int items_on_screen = list->vp->height / list->item_height; | ||
138 | for(int i = 0; i < items_on_screen; ++i) { | ||
139 | item.index = list->top_item + i; | ||
140 | if(item.index >= list->num_items) | ||
141 | break; | ||
142 | |||
143 | list->draw_item(&item); | ||
144 | |||
145 | item.y += item.height; | ||
146 | } | ||
147 | |||
148 | lcd_set_viewport(old_vp); | ||
149 | } | ||
150 | |||
151 | void gui_list_select(struct bl_list* list, int item_index) | ||
152 | { | ||
153 | /* clamp the selection */ | ||
154 | list->selected_item = item_index; | ||
155 | |||
156 | if(list->selected_item < 0) | ||
157 | list->selected_item = 0; | ||
158 | else if(list->selected_item >= list->num_items) | ||
159 | list->selected_item = list->num_items - 1; | ||
160 | |||
161 | /* handle scrolling the list view */ | ||
162 | int items_on_screen = list->vp->height / list->item_height; | ||
163 | int bottom_item = list->top_item + items_on_screen; | ||
164 | |||
165 | if(list->selected_item < list->top_item) { | ||
166 | list->top_item = list->selected_item; | ||
167 | } else if(list->selected_item >= bottom_item) { | ||
168 | list->top_item = list->selected_item - items_on_screen + 1; | ||
169 | if(list->top_item < 0) | ||
170 | list->top_item = 0; | ||
171 | } | ||
172 | } | ||
173 | |||
174 | void gui_list_scroll(struct bl_list* list, int delta) | ||
175 | { | ||
176 | gui_list_select(list, list->selected_item + delta); | ||
177 | } | ||
diff --git a/bootloader/x1000/x1000bootloader.h b/bootloader/x1000/x1000bootloader.h index c5984c9a91..9090523c14 100644 --- a/bootloader/x1000/x1000bootloader.h +++ b/bootloader/x1000/x1000bootloader.h | |||
@@ -23,6 +23,7 @@ | |||
23 | #define __X1000BOOTLOADER_H__ | 23 | #define __X1000BOOTLOADER_H__ |
24 | 24 | ||
25 | #include "config.h" | 25 | #include "config.h" |
26 | #include "lcd.h" | ||
26 | #include <stddef.h> | 27 | #include <stddef.h> |
27 | #include <stdint.h> | 28 | #include <stdint.h> |
28 | #include <stdbool.h> | 29 | #include <stdbool.h> |
@@ -70,6 +71,24 @@ struct uimage_header; | |||
70 | * GUI stuff | 71 | * GUI stuff |
71 | */ | 72 | */ |
72 | 73 | ||
74 | struct bl_listitem { | ||
75 | struct bl_list* list; | ||
76 | |||
77 | int index; | ||
78 | int x, y, width, height; | ||
79 | }; | ||
80 | |||
81 | struct bl_list { | ||
82 | struct viewport* vp; | ||
83 | |||
84 | int num_items; | ||
85 | int selected_item; | ||
86 | int top_item; | ||
87 | int item_height; | ||
88 | |||
89 | void(*draw_item)(const struct bl_listitem* item); | ||
90 | }; | ||
91 | |||
73 | void clearscreen(void); | 92 | void clearscreen(void); |
74 | void putversion(void); | 93 | void putversion(void); |
75 | void putcenter_y(int y, const char* msg); | 94 | void putcenter_y(int y, const char* msg); |
@@ -81,6 +100,11 @@ void init_lcd(void); | |||
81 | 100 | ||
82 | void gui_shutdown(void); | 101 | void gui_shutdown(void); |
83 | 102 | ||
103 | void gui_list_init(struct bl_list* list, struct viewport* vp); | ||
104 | void gui_list_draw(struct bl_list* list); | ||
105 | void gui_list_select(struct bl_list* list, int item_index); | ||
106 | void gui_list_scroll(struct bl_list* list, int delta); | ||
107 | |||
84 | /* | 108 | /* |
85 | * Installer | 109 | * Installer |
86 | */ | 110 | */ |