Changeset a09d401 in mainline
- Timestamp:
- 2020-11-08T22:25:07Z (4 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 2109961
- Parents:
- f93e4e3
- Location:
- uspace/app/vlaunch
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/vlaunch/meson.build
rf93e4e3 ra09d401 27 27 # 28 28 29 deps = [ ' gui' ]29 deps = [ 'draw', 'ui' ] 30 30 31 31 _images = files('gfx/helenos.tga') -
uspace/app/vlaunch/vlaunch.c
rf93e4e3 ra09d401 1 1 /* 2 * Copyright (c) 2020 Jiri Svoboda 2 3 * Copyright (c) 2012 Petr Koupy 3 4 * All rights reserved. … … 30 31 * @{ 31 32 */ 32 /** @file 33 */ 34 33 /** @file Launcher 34 */ 35 36 #include <errno.h> 37 #include <gfx/coord.h> 35 38 #include <stdbool.h> 36 #include <errno.h>37 39 #include <stdio.h> 38 40 #include <stdlib.h> 39 41 #include <str.h> 42 #include <str_error.h> 40 43 #include <task.h> 41 #include <str_error.h>42 43 #include <window.h>44 #include <grid.h>45 #include <button.h>46 #include <label.h>47 #include <canvas.h>48 44 49 45 #include <draw/surface.h> … … 52 48 #include <draw/codec.h> 53 49 50 #include <ui/fixed.h> 51 #include <ui/image.h> 52 #include <ui/label.h> 53 #include <ui/pbutton.h> 54 #include <ui/resource.h> 55 #include <ui/ui.h> 56 #include <ui/window.h> 57 54 58 #include "images.h" 59 #include "vlaunch.h" 55 60 56 61 #define NAME "vlaunch" 57 62 58 #define LOGO_WIDTH 196 59 #define LOGO_HEIGHT 66 60 61 static char *display_svc = DISPLAY_DEFAULT; 63 static char *display_spec = UI_DISPLAY_DEFAULT; 64 65 static void wnd_close(ui_window_t *, void *); 66 67 static ui_window_cb_t window_cb = { 68 .close = wnd_close 69 }; 70 71 static void pb_clicked(ui_pbutton_t *, void *); 72 73 static ui_pbutton_cb_t pbutton_cb = { 74 .clicked = pb_clicked 75 }; 76 77 static int app_launch(const char *); 78 79 /** Window close button was clicked. 80 * 81 * @param window Window 82 * @param arg Argument (launcher) 83 */ 84 static void wnd_close(ui_window_t *window, void *arg) 85 { 86 launcher_t *launcher = (launcher_t *) arg; 87 88 ui_quit(launcher->ui); 89 } 90 91 /** Push button was clicked. 92 * 93 * @param pbutton Push button 94 * @param arg Argument (launcher) 95 */ 96 static void pb_clicked(ui_pbutton_t *pbutton, void *arg) 97 { 98 launcher_t *launcher = (launcher_t *) arg; 99 100 if (pbutton == launcher->pb1) { 101 app_launch("/app/terminal"); 102 } else if (pbutton == launcher->pb2) { 103 app_launch("/app/vcalc"); 104 } else if (pbutton == launcher->pb3) { 105 app_launch("/app/uidemo"); 106 } else if (pbutton == launcher->pb4) { 107 app_launch("/app/vlaunch"); 108 } 109 } 62 110 63 111 static int app_launch(const char *app) … … 67 115 task_wait_t wait; 68 116 69 if (display_s vc !=DISPLAY_DEFAULT) {70 printf("%s: Spawning %s -d %s\n", NAME, app, display_s vc);71 rc = task_spawnl(&id, &wait, app, app, "-d", display_s vc, NULL);117 if (display_spec != UI_DISPLAY_DEFAULT) { 118 printf("%s: Spawning %s -d %s\n", NAME, app, display_spec); 119 rc = task_spawnl(&id, &wait, app, app, "-d", display_spec, NULL); 72 120 } else { 73 121 printf("%s: Spawning %s\n", NAME, app); … … 77 125 if (rc != EOK) { 78 126 printf("%s: Error spawning %s %s (%s)\n", NAME, app, 79 display_s vc != DISPLAY_DEFAULT ? display_svc :127 display_spec != DISPLAY_DEFAULT ? display_spec : 80 128 "<default>", str_error(rc)); 81 129 return -1; … … 94 142 } 95 143 96 static void on_btn_click(widget_t *widget, void *data)97 {98 const char *app = (const char *) widget_get_data(widget);99 app_launch(app);100 }101 102 144 static void print_syntax(void) 103 145 { 104 printf("Syntax: %s [-d <display >]\n", NAME);146 printf("Syntax: %s [-d <display-spec>]\n", NAME); 105 147 } 106 148 … … 108 150 { 109 151 int i; 152 launcher_t launcher; 153 ui_t *ui = NULL; 154 ui_wnd_params_t params; 155 ui_window_t *window = NULL; 156 ui_resource_t *ui_res; 157 gfx_bitmap_params_t logo_params; 158 gfx_bitmap_t *logo_bmp; 159 gfx_bitmap_alloc_t alloc; 160 gfx_context_t *gc; 161 surface_coord_t w, h; 162 gfx_rect_t logo_rect; 163 gfx_rect_t rect; 164 errno_t rc; 110 165 111 166 i = 1; … … 119 174 } 120 175 121 display_s vc = argv[i++];176 display_spec = argv[i++]; 122 177 } else { 123 178 printf("Invalid option '%s'.\n", argv[i]); … … 127 182 } 128 183 129 surface_t *logo = decode_tga((void *) helenos_tga, helenos_tga_size, 0); 184 surface_t *logo = decode_tga((void *) helenos_tga, helenos_tga_size, 185 SURFACE_FLAG_SHARED); 130 186 if (!logo) { 131 187 printf("Unable to decode logo.\n"); … … 133 189 } 134 190 135 window_t *main_window = window_open(display_svc, NULL, 136 WINDOW_MAIN | WINDOW_DECORATED | WINDOW_RESIZEABLE, "vlaunch"); 137 if (!main_window) { 138 printf("Cannot open main window.\n"); 191 rc = ui_create(display_spec, &ui); 192 if (rc != EOK) { 193 printf("Error creating UI on display %s.\n", display_spec); 194 return rc; 195 } 196 197 ui_wnd_params_init(¶ms); 198 params.caption = "Launcher"; 199 params.rect.p0.x = 0; 200 params.rect.p0.y = 0; 201 params.rect.p1.x = 210; 202 params.rect.p1.y = 300; 203 204 memset((void *) &launcher, 0, sizeof(launcher)); 205 launcher.ui = ui; 206 207 rc = ui_window_create(ui, ¶ms, &window); 208 if (rc != EOK) { 209 printf("Error creating window.\n"); 210 return rc; 211 } 212 213 ui_window_set_cb(window, &window_cb, (void *) &launcher); 214 launcher.window = window; 215 216 ui_res = ui_window_get_res(window); 217 gc = ui_window_get_gc(window); 218 219 surface_get_resolution(logo, &w, &h); 220 gfx_bitmap_params_init(&logo_params); 221 logo_params.rect.p1.x = w; 222 logo_params.rect.p1.y = h; 223 logo_rect = logo_params.rect; 224 225 alloc.pitch = sizeof(uint32_t) * w; 226 alloc.off0 = 0; 227 alloc.pixels = surface_direct_access(logo); 228 229 rc = gfx_bitmap_create(gc, &logo_params, &alloc, &logo_bmp); 230 if (rc != EOK) { 231 printf("Error creating bitmap.\n"); 139 232 return 1; 140 233 } 141 234 142 pixel_t grd_bg = PIXEL(255, 255, 255, 255); 143 144 pixel_t btn_bg = PIXEL(255, 255, 255, 255); 145 pixel_t btn_fg = PIXEL(255, 186, 186, 186); 146 pixel_t btn_text = PIXEL(255, 0, 0, 0); 147 148 pixel_t lbl_bg = PIXEL(255, 255, 255, 255); 149 pixel_t lbl_text = PIXEL(255, 0, 0, 0); 150 151 canvas_t *logo_canvas = create_canvas(NULL, NULL, LOGO_WIDTH, LOGO_HEIGHT, 152 logo); 153 label_t *lbl_caption = create_label(NULL, NULL, "Launch application:", 154 16, lbl_bg, lbl_text); 155 button_t *btn_vterm = create_button(NULL, "/app/vterm", "vterm", 156 16, btn_bg, btn_fg, btn_text); 157 button_t *btn_vcalc = create_button(NULL, "/app/vcalc", "vcalc", 158 16, btn_bg, btn_fg, btn_text); 159 button_t *btn_vdemo = create_button(NULL, "/app/vdemo", "vdemo", 160 16, btn_bg, btn_fg, btn_text); 161 button_t *btn_vlaunch = create_button(NULL, "/app/vlaunch", "vlaunch", 162 16, btn_bg, btn_fg, btn_text); 163 grid_t *grid = create_grid(window_root(main_window), NULL, 1, 6, grd_bg); 164 165 if ((!logo_canvas) || (!lbl_caption) || (!btn_vterm) || 166 (!btn_vcalc) || (!btn_vdemo) || (!btn_vlaunch) || (!grid)) { 167 window_close(main_window); 168 printf("Cannot create widgets.\n"); 169 return 1; 170 } 171 172 sig_connect(&btn_vterm->clicked, &btn_vterm->widget, on_btn_click); 173 sig_connect(&btn_vcalc->clicked, &btn_vcalc->widget, on_btn_click); 174 sig_connect(&btn_vdemo->clicked, &btn_vdemo->widget, on_btn_click); 175 sig_connect(&btn_vlaunch->clicked, &btn_vlaunch->widget, on_btn_click); 176 177 grid->add(grid, &logo_canvas->widget, 0, 0, 1, 1); 178 grid->add(grid, &lbl_caption->widget, 0, 1, 1, 1); 179 grid->add(grid, &btn_vterm->widget, 0, 2, 1, 1); 180 grid->add(grid, &btn_vcalc->widget, 0, 3, 1, 1); 181 grid->add(grid, &btn_vdemo->widget, 0, 4, 1, 1); 182 grid->add(grid, &btn_vlaunch->widget, 0, 5, 1, 1); 183 184 window_resize(main_window, 0, 0, 210, 164 + LOGO_HEIGHT, 185 WINDOW_PLACEMENT_RIGHT | WINDOW_PLACEMENT_TOP); 186 window_exec(main_window); 187 188 task_retval(0); 189 async_manager(); 235 rc = ui_fixed_create(&launcher.fixed); 236 if (rc != EOK) { 237 printf("Error creating fixed layout.\n"); 238 return rc; 239 } 240 241 rc = ui_image_create(ui_res, logo_bmp, &logo_rect, &launcher.image); 242 if (rc != EOK) { 243 printf("Error creating label.\n"); 244 return rc; 245 } 246 247 rect.p0.x = 5; 248 rect.p0.y = 32; 249 rect.p1.x = 5 + w; 250 rect.p1.y = 32 + h; 251 ui_image_set_rect(launcher.image, &rect); 252 253 rc = ui_fixed_add(launcher.fixed, ui_image_ctl(launcher.image)); 254 if (rc != EOK) { 255 printf("Error adding control to layout.\n"); 256 return rc; 257 } 258 rc = ui_label_create(ui_res, "Launch application", &launcher.label); 259 if (rc != EOK) { 260 printf("Error creating label.\n"); 261 return rc; 262 } 263 264 rect.p0.x = 60; 265 rect.p0.y = 107; 266 rect.p1.x = 160; 267 rect.p1.y = 120; 268 ui_label_set_rect(launcher.label, &rect); 269 ui_label_set_halign(launcher.label, gfx_halign_center); 270 271 rc = ui_fixed_add(launcher.fixed, ui_label_ctl(launcher.label)); 272 if (rc != EOK) { 273 printf("Error adding control to layout.\n"); 274 return rc; 275 } 276 277 rc = ui_pbutton_create(ui_res, "Terminal", &launcher.pb1); 278 if (rc != EOK) { 279 printf("Error creating button.\n"); 280 return rc; 281 } 282 283 ui_pbutton_set_cb(launcher.pb1, &pbutton_cb, (void *) &launcher); 284 285 rect.p0.x = 15; 286 rect.p0.y = 130; 287 rect.p1.x = 190; 288 rect.p1.y = 158; 289 ui_pbutton_set_rect(launcher.pb1, &rect); 290 291 rc = ui_fixed_add(launcher.fixed, ui_pbutton_ctl(launcher.pb1)); 292 if (rc != EOK) { 293 printf("Error adding control to layout.\n"); 294 return rc; 295 } 296 297 rc = ui_pbutton_create(ui_res, "Calculator", &launcher.pb2); 298 if (rc != EOK) { 299 printf("Error creating button.\n"); 300 return rc; 301 } 302 303 ui_pbutton_set_cb(launcher.pb2, &pbutton_cb, (void *) &launcher); 304 305 rect.p0.x = 15; 306 rect.p0.y = 170; 307 rect.p1.x = 190; 308 rect.p1.y = 198; 309 ui_pbutton_set_rect(launcher.pb2, &rect); 310 311 rc = ui_fixed_add(launcher.fixed, ui_pbutton_ctl(launcher.pb2)); 312 if (rc != EOK) { 313 printf("Error adding control to layout.\n"); 314 return rc; 315 } 316 317 rc = ui_pbutton_create(ui_res, "UI Demo", &launcher.pb3); 318 if (rc != EOK) { 319 printf("Error creating button.\n"); 320 return rc; 321 } 322 323 ui_pbutton_set_cb(launcher.pb3, &pbutton_cb, (void *) &launcher); 324 325 rect.p0.x = 15; 326 rect.p0.y = 210; 327 rect.p1.x = 190; 328 rect.p1.y = 238; 329 ui_pbutton_set_rect(launcher.pb3, &rect); 330 331 rc = ui_fixed_add(launcher.fixed, ui_pbutton_ctl(launcher.pb3)); 332 if (rc != EOK) { 333 printf("Error adding control to layout.\n"); 334 return rc; 335 } 336 337 rc = ui_pbutton_create(ui_res, "Launcher", &launcher.pb4); 338 if (rc != EOK) { 339 printf("Error creating button.\n"); 340 return rc; 341 } 342 343 ui_pbutton_set_cb(launcher.pb4, &pbutton_cb, (void *) &launcher); 344 345 rect.p0.x = 15; 346 rect.p0.y = 250; 347 rect.p1.x = 190; 348 rect.p1.y = 278; 349 ui_pbutton_set_rect(launcher.pb4, &rect); 350 351 rc = ui_fixed_add(launcher.fixed, ui_pbutton_ctl(launcher.pb4)); 352 if (rc != EOK) { 353 printf("Error adding control to layout.\n"); 354 return rc; 355 } 356 357 ui_window_add(window, ui_fixed_ctl(launcher.fixed)); 358 359 (void) ui_res; 360 (void) app_launch; 361 362 rc = ui_window_paint(window); 363 if (rc != EOK) { 364 printf("Error painting window.\n"); 365 return rc; 366 } 367 368 ui_run(ui); 369 370 ui_window_destroy(window); 371 ui_destroy(ui); 190 372 191 373 return 0;
Note:
See TracChangeset
for help on using the changeset viewer.