Changes in uspace/app/gfxdemo/gfxdemo.c [9e240c1:901b302] in mainline
- File:
-
- 1 edited
-
uspace/app/gfxdemo/gfxdemo.c (modified) (22 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/gfxdemo/gfxdemo.c
r9e240c1 r901b302 1 1 /* 2 * Copyright (c) 202 3Jiri Svoboda2 * Copyright (c) 2022 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 51 51 #include <ui/window.h> 52 52 #include <ui/wdecor.h> 53 #include "gfxdemo.h"54 53 55 54 static void wnd_close_event(void *); … … 69 68 }; 70 69 71 static void demo_kbd_event(kbd_event_t *);72 73 70 static bool quit = false; 74 static FIBRIL_MUTEX_INITIALIZE(quit_lock);75 static FIBRIL_CONDVAR_INITIALIZE(quit_cv);76 71 static gfx_typeface_t *tface; 77 72 static gfx_font_t *font; 78 73 static gfx_coord_t vpad; 79 static console_ctrl_t *con = NULL;80 static ui_t *ui;81 74 82 75 /** Determine if we are running in text mode. … … 90 83 // XXX Need a proper way to determine text mode 91 84 return w <= 80; 92 }93 94 /** Sleep until timeout or quit request.95 *96 * @param msec Number of microseconds to sleep for97 */98 static void demo_msleep(unsigned msec)99 {100 errno_t rc;101 usec_t usec;102 cons_event_t cevent;103 104 if (ui != NULL)105 ui_unlock(ui);106 fibril_mutex_lock(&quit_lock);107 if (!quit) {108 if (con != NULL) {109 usec = (usec_t)msec * 1000;110 while (usec > 0 && !quit) {111 rc = console_get_event_timeout(con, &cevent, &usec);112 if (rc == EOK) {113 if (cevent.type == CEV_KEY) {114 fibril_mutex_unlock(&quit_lock);115 demo_kbd_event(&cevent.ev.key);116 fibril_mutex_lock(&quit_lock);117 }118 }119 }120 } else {121 (void) fibril_condvar_wait_timeout(&quit_cv, &quit_lock,122 (usec_t)msec * 1000);123 }124 }125 fibril_mutex_unlock(&quit_lock);126 if (ui != NULL)127 ui_lock(ui);128 85 } 129 86 … … 359 316 gfx_color_delete(color); 360 317 361 demo_msleep(500); 318 fibril_usleep(500 * 1000); 319 362 320 if (quit) 363 321 break; … … 520 478 if (rc != EOK) 521 479 goto error; 522 523 demo_msleep(250); 480 fibril_usleep(250 * 1000); 481 524 482 if (quit) 525 483 goto out; … … 581 539 } 582 540 583 demo_msleep(500); 541 fibril_usleep(500 * 1000); 542 584 543 if (quit) 585 544 break; … … 641 600 } 642 601 643 demo_msleep(500); 602 fibril_usleep(500 * 1000); 603 644 604 if (quit) 645 605 break; … … 831 791 832 792 for (i = 0; i < 10; i++) { 833 demo_msleep(500);793 fibril_usleep(500 * 1000); 834 794 if (quit) 835 795 break; … … 912 872 913 873 for (i = 0; i < 10; i++) { 914 demo_msleep(500);874 fibril_usleep(500 * 1000); 915 875 if (quit) 916 876 break; … … 1009 969 } 1010 970 1011 demo_msleep(500); 971 fibril_usleep(500 * 1000); 972 1012 973 if (quit) 1013 974 break; … … 1075 1036 static errno_t demo_console(void) 1076 1037 { 1038 console_ctrl_t *con = NULL; 1077 1039 console_gc_t *cgc = NULL; 1078 1040 gfx_context_t *gc; 1079 sysarg_t cols, rows;1080 errno_t rc; 1081 1041 errno_t rc; 1042 1043 printf("Init console..\n"); 1082 1044 con = console_init(stdin, stdout); 1083 1045 if (con == NULL) 1084 1046 return EIO; 1085 1047 1086 rc = console_get_size(con, &cols, &rows); 1087 if (rc != EOK) 1088 return rc; 1089 1048 printf("Create console GC\n"); 1090 1049 rc = console_gc_create(con, stdout, &cgc); 1091 1050 if (rc != EOK) … … 1094 1053 gc = console_gc_get_ctx(cgc); 1095 1054 1096 rc = demo_loop(gc, cols, rows);1055 rc = demo_loop(gc, 80, 25); 1097 1056 if (rc != EOK) 1098 1057 return rc; … … 1103 1062 1104 1063 return EOK; 1105 }1106 1107 static errno_t demo_ui_fibril(void *arg)1108 {1109 demo_ui_args_t *args = (demo_ui_args_t *)arg;1110 errno_t rc;1111 1112 ui_lock(args->ui);1113 rc = demo_loop(args->gc, args->dims.x, args->dims.y);1114 ui_unlock(args->ui);1115 ui_quit(args->ui);1116 return rc;1117 1064 } 1118 1065 … … 1120 1067 static errno_t demo_ui(const char *display_spec) 1121 1068 { 1069 ui_t *ui = NULL; 1122 1070 ui_wnd_params_t params; 1123 1071 ui_window_t *window = NULL; … … 1126 1074 gfx_rect_t wrect; 1127 1075 gfx_coord2_t off; 1128 gfx_rect_t ui_rect; 1129 gfx_coord2_t dims; 1130 demo_ui_args_t args; 1131 fid_t fid; 1132 errno_t rc; 1076 errno_t rc; 1077 1078 printf("Init UI..\n"); 1133 1079 1134 1080 rc = ui_create(display_spec, &ui); 1135 1081 if (rc != EOK) { 1136 1082 printf("Error initializing UI (%s)\n", display_spec); 1137 goto error;1138 }1139 1140 rc = ui_get_rect(ui, &ui_rect);1141 if (rc != EOK) {1142 printf("Error getting display size.\n");1143 1083 goto error; 1144 1084 } … … 1151 1091 ui_wnd_params_init(¶ms); 1152 1092 params.caption = "GFX Demo"; 1153 1154 /* Do not decorate the window in fullscreen mode */1155 if (ui_is_fullscreen(ui))1156 params.style &= ~ui_wds_decorated;1157 1093 1158 1094 /* … … 1164 1100 gfx_rect_rtranslate(&off, &wrect, ¶ms.rect); 1165 1101 1166 gfx_rect_dims(&ui_rect, &dims);1167 1168 /* Make sure window is not larger than the entire screen */1169 if (params.rect.p1.x > dims.x)1170 params.rect.p1.x = dims.x;1171 if (params.rect.p1.y > dims.y)1172 params.rect.p1.y = dims.y;1173 1174 1102 rc = ui_window_create(ui, ¶ms, &window); 1175 1103 if (rc != EOK) { … … 1186 1114 } 1187 1115 1188 ui_window_get_app_rect(window, &rect); 1189 gfx_rect_dims(&rect, &dims); 1190 1191 if (!ui_is_fullscreen(ui)) 1192 task_retval(0); 1193 1194 args.gc = gc; 1195 args.dims = dims; 1196 args.ui = ui; 1197 1198 fid = fibril_create(demo_ui_fibril, (void *)&args); 1199 if (fid == 0) { 1200 rc = ENOMEM; 1201 goto error; 1202 } 1203 1204 fibril_add_ready(fid); 1205 1206 ui_run(ui); 1116 task_retval(0); 1117 1118 rc = demo_loop(gc, rect.p1.x, rect.p1.y); 1119 if (rc != EOK) 1120 goto error; 1121 1207 1122 ui_window_destroy(window); 1208 1123 ui_destroy(ui); … … 1226 1141 errno_t rc; 1227 1142 1143 printf("Init display..\n"); 1144 1228 1145 rc = display_open(display_svc, &display); 1229 1146 if (rc != EOK) { … … 1267 1184 } 1268 1185 1269 static void demo_quit(void)1270 { 1271 fibril_mutex_lock(&quit_lock);1186 static void wnd_close_event(void *arg) 1187 { 1188 printf("Close event\n"); 1272 1189 quit = true; 1273 fibril_mutex_unlock(&quit_lock);1274 fibril_condvar_broadcast(&quit_cv);1275 }1276 1277 static void wnd_close_event(void *arg)1278 {1279 demo_quit();1280 }1281 1282 static void demo_kbd_event(kbd_event_t *event)1283 {1284 if (event->type == KEY_PRESS) {1285 /* Ctrl-Q */1286 if ((event->mods & KM_CTRL) != 0 &&1287 (event->mods & KM_ALT) == 0 &&1288 (event->mods & KM_SHIFT) == 0 &&1289 event->key == KC_Q) {1290 demo_quit();1291 }1292 1293 /* Escape */1294 if ((event->mods & KM_CTRL) == 0 &&1295 (event->mods & KM_ALT) == 0 &&1296 (event->mods & KM_SHIFT) == 0 &&1297 event->key == KC_ESCAPE) {1298 demo_quit();1299 }1300 }1301 1190 } 1302 1191 1303 1192 static void wnd_kbd_event(void *arg, kbd_event_t *event) 1304 1193 { 1305 (void)arg; 1306 demo_kbd_event(event); 1194 printf("Keyboard event type=%d key=%d\n", event->type, event->key); 1195 if (event->type == KEY_PRESS) 1196 quit = true; 1307 1197 } 1308 1198 1309 1199 static void uiwnd_close_event(ui_window_t *window, void *arg) 1310 1200 { 1311 demo_quit(); 1201 printf("Close event\n"); 1202 quit = true; 1312 1203 } 1313 1204 1314 1205 static void uiwnd_kbd_event(ui_window_t *window, void *arg, kbd_event_t *event) 1315 1206 { 1316 (void)window;1317 (void)arg;1318 demo_kbd_event(event);1207 printf("Keyboard event type=%d key=%d\n", event->type, event->key); 1208 if (event->type == KEY_PRESS) 1209 quit = true; 1319 1210 } 1320 1211 … … 1328 1219 errno_t rc; 1329 1220 const char *display_svc = DISPLAY_DEFAULT; 1330 const char *ui_display_spec = UI_ ANY_DEFAULT;1221 const char *ui_display_spec = UI_DISPLAY_DEFAULT; 1331 1222 int i; 1332 1223
Note:
See TracChangeset
for help on using the changeset viewer.
