Changeset fd11144 in mainline for uspace/app/vdemo/vdemo.c
- Timestamp:
- 2020-07-04T21:52:35Z (4 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- fc4abca
- Parents:
- e79a025
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/vdemo/vdemo.c
re79a025 rfd11144 1 1 /* 2 * Copyright (c) 2020 Jiri Svoboda 2 3 * Copyright (c) 2012 Petr Koupy 3 4 * All rights reserved. … … 36 37 #include <stdio.h> 37 38 #include <stdlib.h> 39 #include <str.h> 38 40 #include <io/pixel.h> 39 41 #include <task.h> … … 107 109 } 108 110 111 static void print_syntax(void) 112 { 113 printf("Syntax: %s [-d <display>]\n", NAME); 114 } 115 109 116 int main(int argc, char *argv[]) 110 117 { 111 if (argc >= 2) { 112 window_t *main_window = window_open(argv[1], NULL, 113 WINDOW_MAIN | WINDOW_DECORATED | WINDOW_RESIZEABLE, "vdemo"); 114 if (!main_window) { 115 printf("Cannot open main window.\n"); 118 const char *disp_svc = DISPLAY_DEFAULT; 119 int i; 120 121 i = 1; 122 while (i < argc) { 123 if (str_cmp(argv[i], "-d") == 0) { 124 ++i; 125 if (i >= argc) { 126 printf("Argument missing.\n"); 127 print_syntax(); 128 return 1; 129 } 130 131 disp_svc = argv[i++]; 132 } else { 133 printf("Invalid option '%s'.\n", argv[i]); 134 print_syntax(); 116 135 return 1; 117 136 } 137 } 118 138 119 pixel_t grd_bg = PIXEL(255, 240, 240, 240); 120 121 pixel_t btn_bg = PIXEL(255, 240, 240, 240); 122 pixel_t btn_fg = PIXEL(255, 186, 186, 186); 123 pixel_t btn_text = PIXEL(255, 0, 0, 0); 124 125 pixel_t lbl_bg = PIXEL(255, 240, 240, 240); 126 pixel_t lbl_text = PIXEL(255, 0, 0, 0); 127 128 my_label_t *lbl_action = create_my_label(NULL, "Hello there!", 16, 129 lbl_bg, lbl_text); 130 button_t *btn_confirm = create_button(NULL, NULL, "Confirm", 16, 131 btn_bg, btn_fg, btn_text); 132 button_t *btn_cancel = create_button(NULL, NULL, "Cancel", 16, 133 btn_bg, btn_fg, btn_text); 134 grid_t *grid = create_grid(window_root(main_window), NULL, 2, 2, 135 grd_bg); 136 if (!lbl_action || !btn_confirm || !btn_cancel || !grid) { 137 window_close(main_window); 138 printf("Cannot create widgets.\n"); 139 return 1; 140 } 141 142 sig_connect( 143 &btn_confirm->clicked, 144 &lbl_action->label.widget, 145 lbl_action->confirm); 146 sig_connect( 147 &btn_cancel->clicked, 148 &lbl_action->label.widget, 149 lbl_action->cancel); 150 151 grid->add(grid, &lbl_action->label.widget, 0, 0, 2, 1); 152 grid->add(grid, &btn_confirm->widget, 0, 1, 1, 1); 153 grid->add(grid, &btn_cancel->widget, 1, 1, 1, 1); 154 window_resize(main_window, 0, 0, 200, 76, 155 WINDOW_PLACEMENT_CENTER); 156 157 window_exec(main_window); 158 task_retval(0); 159 async_manager(); 160 return 1; 161 } else { 162 printf("Compositor server not specified.\n"); 139 window_t *main_window = window_open(disp_svc, NULL, 140 WINDOW_MAIN | WINDOW_DECORATED | WINDOW_RESIZEABLE, "vdemo"); 141 if (!main_window) { 142 printf("Cannot open main window.\n"); 163 143 return 1; 164 144 } 145 146 pixel_t grd_bg = PIXEL(255, 240, 240, 240); 147 148 pixel_t btn_bg = PIXEL(255, 240, 240, 240); 149 pixel_t btn_fg = PIXEL(255, 186, 186, 186); 150 pixel_t btn_text = PIXEL(255, 0, 0, 0); 151 152 pixel_t lbl_bg = PIXEL(255, 240, 240, 240); 153 pixel_t lbl_text = PIXEL(255, 0, 0, 0); 154 155 my_label_t *lbl_action = create_my_label(NULL, "Hello there!", 16, 156 lbl_bg, lbl_text); 157 button_t *btn_confirm = create_button(NULL, NULL, "Confirm", 16, 158 btn_bg, btn_fg, btn_text); 159 button_t *btn_cancel = create_button(NULL, NULL, "Cancel", 16, 160 btn_bg, btn_fg, btn_text); 161 grid_t *grid = create_grid(window_root(main_window), NULL, 2, 2, 162 grd_bg); 163 if (!lbl_action || !btn_confirm || !btn_cancel || !grid) { 164 window_close(main_window); 165 printf("Cannot create widgets.\n"); 166 return 1; 167 } 168 169 sig_connect( 170 &btn_confirm->clicked, 171 &lbl_action->label.widget, 172 lbl_action->confirm); 173 sig_connect( 174 &btn_cancel->clicked, 175 &lbl_action->label.widget, 176 lbl_action->cancel); 177 178 grid->add(grid, &lbl_action->label.widget, 0, 0, 2, 1); 179 grid->add(grid, &btn_confirm->widget, 0, 1, 1, 1); 180 grid->add(grid, &btn_cancel->widget, 1, 1, 1, 1); 181 window_resize(main_window, 0, 0, 200, 76, 182 WINDOW_PLACEMENT_CENTER); 183 184 window_exec(main_window); 185 task_retval(0); 186 async_manager(); 187 return 0; 165 188 } 166 189
Note:
See TracChangeset
for help on using the changeset viewer.