Changeset d284ce9 in mainline for uspace/app/uidemo/uidemo.c
- Timestamp:
- 2020-10-27T21:56:15Z (5 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f03d1308
- Parents:
- f7a90df
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/uidemo/uidemo.c
rf7a90df rd284ce9 33 33 */ 34 34 35 #include <display.h>36 35 #include <gfx/color.h> 37 36 #include <gfx/coord.h> 38 37 #include <gfx/render.h> 38 #include <io/pos_event.h> 39 39 #include <stdio.h> 40 40 #include <str.h> … … 43 43 #include <ui/pbutton.h> 44 44 #include <ui/resource.h> 45 #include <ui/ui.h> 45 46 #include <ui/wdecor.h> 47 #include <ui/window.h> 46 48 #include "uidemo.h" 47 49 48 static void wnd_close_event(void *); 49 static void wnd_focus_event(void *); 50 static void wnd_kbd_event(void *, kbd_event_t *); 51 static void wnd_pos_event(void *, pos_event_t *); 52 static void wnd_unfocus_event(void *); 53 54 static display_wnd_cb_t wnd_cb = { 55 .close_event = wnd_close_event, 56 .focus_event = wnd_focus_event, 57 .kbd_event = wnd_kbd_event, 58 .pos_event = wnd_pos_event, 59 .unfocus_event = wnd_unfocus_event 50 static void wnd_close(ui_window_t *, void *); 51 static void wnd_pos(ui_window_t *, void *, pos_event_t *pos); 52 53 static ui_window_cb_t window_cb = { 54 .close = wnd_close, 55 .pos = wnd_pos 60 56 }; 61 57 … … 66 62 }; 67 63 68 static void wd_close(ui_wdecor_t *, void *); 69 static void wd_move(ui_wdecor_t *, void *, gfx_coord2_t *); 70 71 static ui_wdecor_cb_t wdecor_cb = { 72 .close = wd_close, 73 .move = wd_move 74 }; 75 76 /** Print syntax. */ 77 static void print_syntax(void) 78 { 79 printf("Syntax: uidemo [-d <display>]\n"); 80 } 81 82 /** Handle window close event. */ 83 static void wnd_close_event(void *arg) 64 /** Window close button was clicked. 65 * 66 * @param window Window 67 * @param arg Argument (demo) 68 */ 69 static void wnd_close(ui_window_t *window, void *arg) 84 70 { 85 71 ui_demo_t *demo = (ui_demo_t *) arg; 86 72 87 demo->quit = true; 88 } 89 90 /** Handle window focus event. */ 91 static void wnd_focus_event(void *arg) 73 ui_quit(demo->ui); 74 } 75 76 /** Window position event. 77 * 78 * @param window Window 79 * @param arg Argument (demo) 80 */ 81 static void wnd_pos(ui_window_t *window, void *arg, pos_event_t *event) 92 82 { 93 83 ui_demo_t *demo = (ui_demo_t *) arg; 94 84 95 if (demo->wdecor != NULL) {96 ui_wdecor_set_active(demo->wdecor, true);97 ui_wdecor_paint(demo->wdecor);98 }99 }100 101 /** Handle window keyboard event */102 static void wnd_kbd_event(void *arg, kbd_event_t *event)103 {104 ui_demo_t *demo = (ui_demo_t *) arg;105 106 (void) demo;107 }108 109 /** Handle window position event */110 static void wnd_pos_event(void *arg, pos_event_t *event)111 {112 ui_demo_t *demo = (ui_demo_t *) arg;113 114 85 /* Make sure we don't process events until fully initialized */ 115 if (demo-> wdecor == NULL || demo->pb1 == NULL || demo->pb2 == NULL)86 if (demo->pb1 == NULL || demo->pb2 == NULL) 116 87 return; 117 88 118 ui_wdecor_pos_event(demo->wdecor, event);119 89 ui_pbutton_pos_event(demo->pb1, event); 120 90 ui_pbutton_pos_event(demo->pb2, event); 121 }122 123 /** Handle window unfocus event. */124 static void wnd_unfocus_event(void *arg)125 {126 ui_demo_t *demo = (ui_demo_t *) arg;127 128 if (demo->wdecor != NULL) {129 ui_wdecor_set_active(demo->wdecor, false);130 ui_wdecor_paint(demo->wdecor);131 }132 91 } 133 92 … … 155 114 } 156 115 157 /** Window decoration requested window closure.158 *159 * @param wdecor Window decoration160 * @param arg Argument (demo)161 */162 static void wd_close(ui_wdecor_t *wdecor, void *arg)163 {164 ui_demo_t *demo = (ui_demo_t *) arg;165 166 demo->quit = true;167 }168 169 /** Window decoration requested window move.170 *171 * @param wdecor Window decoration172 * @param arg Argument (demo)173 * @param pos Position where the title bar was pressed174 */175 static void wd_move(ui_wdecor_t *wdecor, void *arg, gfx_coord2_t *pos)176 {177 ui_demo_t *demo = (ui_demo_t *) arg;178 179 (void) display_window_move_req(demo->dwindow, pos);180 }181 182 116 /** Run UI demo on display server. */ 183 static errno_t ui_demo_display(const char *display_svc) 184 { 185 display_t *display = NULL; 186 gfx_context_t *gc; 187 display_wnd_params_t params; 188 display_window_t *window = NULL; 189 ui_resource_t *ui_res; 117 static errno_t ui_demo(const char *display_spec) 118 { 119 ui_t *ui = NULL; 120 ui_wnd_params_t params; 121 ui_window_t *window = NULL; 190 122 ui_demo_t demo; 191 123 gfx_rect_t rect; 192 gfx_color_t *color = NULL; 124 gfx_rect_t app_rect; 125 gfx_color_t *color; 126 ui_resource_t *ui_res; 127 gfx_context_t *gc; 193 128 errno_t rc; 194 129 195 rc = display_open(display_svc, &display); 196 if (rc != EOK) { 197 printf("Error opening display.\n"); 198 return rc; 199 } 200 201 display_wnd_params_init(¶ms); 130 rc = ui_create(display_spec, &ui); 131 if (rc != EOK) { 132 printf("Error creating UI on display %s.\n", display_spec); 133 return rc; 134 } 135 136 ui_wnd_params_init(¶ms); 137 params.caption = "UI Demo"; 202 138 params.rect.p0.x = 0; 203 139 params.rect.p0.y = 0; … … 206 142 207 143 memset((void *) &demo, 0, sizeof(demo)); 208 209 rc = display_window_create(display, ¶ms, &wnd_cb, (void *) &demo, 210 144 demo.ui = ui; 145 146 rc = ui_window_create(ui, ¶ms, &window); 211 147 if (rc != EOK) { 212 148 printf("Error creating window.\n"); … … 214 150 } 215 151 216 demo.quit = false; 217 demo.dwindow = window; 218 219 rc = display_window_get_gc(window, &gc); 220 if (rc != EOK) { 221 printf("Error getting graphics context.\n"); 222 return rc; 223 } 152 ui_window_set_cb(window, &window_cb, (void *) &demo); 153 demo.window = window; 224 154 225 155 task_retval(0); 226 156 227 rc = ui_resource_create(gc, &ui_res); 228 if (rc != EOK) { 229 printf("Error creating UI.\n"); 230 return rc; 231 } 232 233 rc = ui_wdecor_create(ui_res, "UI Demo", &demo.wdecor); 234 if (rc != EOK) { 235 printf("Error creating window decoration.\n"); 236 return rc; 237 } 238 239 ui_wdecor_set_rect(demo.wdecor, ¶ms.rect); 240 ui_wdecor_set_cb(demo.wdecor, &wdecor_cb, (void *) &demo); 157 ui_res = ui_window_get_res(window); 158 gc = ui_window_get_gc(window); 159 ui_window_get_app_rect(window, &app_rect); 241 160 242 161 rc = ui_label_create(ui_res, "Hello there!", &demo.label); … … 295 214 } 296 215 297 rc = gfx_fill_rect(gc, & params.rect);216 rc = gfx_fill_rect(gc, &app_rect); 298 217 if (rc != EOK) { 299 218 printf("Error filling background.\n"); … … 301 220 } 302 221 303 gfx_color_delete(color);304 color = NULL;305 306 rc = ui_wdecor_paint(demo.wdecor);307 if (rc != EOK) {308 printf("Error painting window decoration.\n");309 return rc;310 }311 312 222 rc = ui_label_paint(demo.label); 313 223 if (rc != EOK) { … … 328 238 } 329 239 330 while (!demo.quit) { 331 fibril_usleep(100 * 1000); 332 } 333 334 ui_wdecor_destroy(demo.wdecor); 240 ui_run(ui); 241 335 242 ui_pbutton_destroy(demo.pb1); 336 243 ui_pbutton_destroy(demo.pb2); 337 244 338 rc = gfx_context_delete(gc); 339 if (rc != EOK) 340 return rc; 341 342 display_window_destroy(window); 343 display_close(display); 245 ui_window_destroy(window); 246 ui_destroy(ui); 344 247 345 248 return EOK; 346 249 } 347 250 251 static void print_syntax(void) 252 { 253 printf("Syntax: uidemo [-d <display-spec>]\n"); 254 } 255 348 256 int main(int argc, char *argv[]) 349 257 { 350 const char *display_s vc =DISPLAY_DEFAULT;258 const char *display_spec = UI_DISPLAY_DEFAULT; 351 259 errno_t rc; 352 260 int i; … … 362 270 } 363 271 364 display_s vc = argv[i++];272 display_spec = argv[i++]; 365 273 } else { 366 274 printf("Invalid option '%s'.\n", argv[i]); … … 375 283 } 376 284 377 rc = ui_demo _display(display_svc);285 rc = ui_demo(display_spec); 378 286 if (rc != EOK) 379 287 return 1;
Note:
See TracChangeset
for help on using the changeset viewer.