Changeset 04803bf in mainline for uspace/srv/hid/console/gcons.c
- Timestamp:
- 2011-03-21T22:00:17Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 143932e3
- Parents:
- b50b5af2 (diff), 7308e84 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - File:
-
- 1 moved
-
uspace/srv/hid/console/gcons.c (moved) (moved from uspace/srv/console/gcons.c ) (22 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/hid/console/gcons.c
rb50b5af2 r04803bf 34 34 35 35 #include <ipc/fb.h> 36 #include <ipc/ipc.h>37 36 #include <async.h> 38 37 #include <stdio.h> 39 38 #include <sys/mman.h> 40 #include <str ing.h>39 #include <str.h> 41 40 #include <align.h> 42 41 #include <bool.h> … … 54 53 #define STATUS_HEIGHT 48 55 54 56 #define MAIN_COLOR 0xffffff 55 #define COLOR_MAIN 0xffffff 56 #define COLOR_FOREGROUND 0x202020 57 #define COLOR_BACKGROUND 0xffffff 58 59 extern char _binary_gfx_helenos_ppm_start[0]; 60 extern int _binary_gfx_helenos_ppm_size; 61 extern char _binary_gfx_nameic_ppm_start[0]; 62 extern int _binary_gfx_nameic_ppm_size; 63 64 extern char _binary_gfx_anim_1_ppm_start[0]; 65 extern int _binary_gfx_anim_1_ppm_size; 66 extern char _binary_gfx_anim_2_ppm_start[0]; 67 extern int _binary_gfx_anim_2_ppm_size; 68 extern char _binary_gfx_anim_3_ppm_start[0]; 69 extern int _binary_gfx_anim_3_ppm_size; 70 extern char _binary_gfx_anim_4_ppm_start[0]; 71 extern int _binary_gfx_anim_4_ppm_size; 72 73 extern char _binary_gfx_cons_selected_ppm_start[0]; 74 extern int _binary_gfx_cons_selected_ppm_size; 75 extern char _binary_gfx_cons_idle_ppm_start[0]; 76 extern int _binary_gfx_cons_idle_ppm_size; 77 extern char _binary_gfx_cons_has_data_ppm_start[0]; 78 extern int _binary_gfx_cons_has_data_ppm_size; 79 extern char _binary_gfx_cons_kernel_ppm_start[0]; 80 extern int _binary_gfx_cons_kernel_ppm_size; 57 81 58 82 static bool use_gcons = false; 59 static ipcarg_t xres;60 static ipcarg_t yres;83 static sysarg_t xres; 84 static sysarg_t yres; 61 85 62 86 enum butstate { … … 82 106 static size_t active_console = 0; 83 107 84 s ize_t mouse_x;85 s ize_t mouse_y;86 87 bool btn_pressed;88 s ize_t btn_x;89 s ize_t btn_y;108 static sysarg_t mouse_x = 0; 109 static sysarg_t mouse_y= 0; 110 111 static bool btn_pressed = false; 112 static sysarg_t btn_x = 0; 113 static sysarg_t btn_y = 0; 90 114 91 115 static void vp_switch(int vp) … … 95 119 96 120 /** Create view port */ 97 static int vp_create(s ize_t x, size_t y, size_t width, size_t height)121 static int vp_create(sysarg_t x, sysarg_t y, sysarg_t width, sysarg_t height) 98 122 { 99 123 return async_req_2_0(fbphone, FB_VIEWPORT_CREATE, (x << 16) | y, … … 112 136 113 137 /** Transparent putchar */ 114 static void tran_putch(wchar_t ch, s ize_t col, size_t row)138 static void tran_putch(wchar_t ch, sysarg_t col, sysarg_t row) 115 139 { 116 140 async_msg_3(fbphone, FB_PUTCHAR, ch, col, row); … … 132 156 133 157 char data[5]; 134 snprintf(data, 5, "% u", index + 1);158 snprintf(data, 5, "%zu", index + 1); 135 159 136 160 size_t i; … … 241 265 242 266 /** Return x, where left <= x <= right && |a-x| == min(|a-x|) is smallest */ 243 static inline int limit(size_t a, size_t left,size_t right)267 static inline ssize_t limit(ssize_t a, ssize_t left, ssize_t right) 244 268 { 245 269 if (a < left) … … 259 283 void gcons_mouse_move(ssize_t dx, ssize_t dy) 260 284 { 261 mouse_x = limit(mouse_x + dx, 0, xres); 262 mouse_y = limit(mouse_y + dy, 0, yres); 263 264 async_msg_2(fbphone, FB_POINTER_MOVE, mouse_x, mouse_y); 265 } 266 267 static int gcons_find_conbut(int x, int y) 268 { 269 int status_start = STATUS_START + (xres - 800) / 2; 285 ssize_t nx = (ssize_t) mouse_x + dx; 286 ssize_t ny = (ssize_t) mouse_y + dy; 287 288 /* Until gcons is initalized we don't have the screen resolution */ 289 if (xres == 0 || yres == 0) 290 return; 291 292 mouse_x = (size_t) limit(nx, 0, xres); 293 mouse_y = (size_t) limit(ny, 0, yres); 294 295 if (active_console != KERNEL_CONSOLE) 296 async_msg_2(fbphone, FB_POINTER_MOVE, mouse_x, mouse_y); 297 } 298 299 static int gcons_find_conbut(sysarg_t x, sysarg_t y) 300 { 301 sysarg_t status_start = STATUS_START + (xres - 800) / 2; 270 302 271 303 if ((y < STATUS_TOP) || (y >= STATUS_TOP + STATUS_HEIGHT)) … … 277 309 if (x >= status_start + (STATUS_WIDTH + STATUS_SPACE) * CONSOLE_COUNT) 278 310 return -1; 311 279 312 if (((x - status_start) % (STATUS_WIDTH + STATUS_SPACE)) < STATUS_SPACE) 280 313 return -1; 281 314 282 return (x - status_start) / (STATUS_WIDTH + STATUS_SPACE); 315 sysarg_t btn = (x - status_start) / (STATUS_WIDTH + STATUS_SPACE); 316 317 if (btn < CONSOLE_COUNT) 318 return btn; 319 320 return -1; 283 321 } 284 322 … … 286 324 * 287 325 * @param state New state (true - pressed, false - depressed) 326 * 288 327 */ 289 328 int gcons_mouse_btn(bool state) 290 329 { 291 int conbut; 330 /* Ignore mouse clicks if no buttons 331 are drawn at all */ 332 if (xres < 800) 333 return -1; 292 334 293 335 if (state) { 294 conbut = gcons_find_conbut(mouse_x, mouse_y);336 int conbut = gcons_find_conbut(mouse_x, mouse_y); 295 337 if (conbut != -1) { 296 338 btn_pressed = true; … … 306 348 btn_pressed = false; 307 349 308 conbut = gcons_find_conbut(mouse_x, mouse_y);350 int conbut = gcons_find_conbut(mouse_x, mouse_y); 309 351 if (conbut == gcons_find_conbut(btn_x, btn_y)) 310 352 return conbut; … … 312 354 return -1; 313 355 } 314 315 356 316 357 /** Draw a PPM pixmap to framebuffer … … 320 361 * @param x Coordinate of upper left corner 321 362 * @param y Coordinate of upper left corner 322 */ 323 static void draw_pixmap(char *logo, size_t size, int x, int y) 324 { 325 char *shm; 326 int rc; 327 363 * 364 */ 365 static void draw_pixmap(char *logo, size_t size, sysarg_t x, sysarg_t y) 366 { 328 367 /* Create area */ 329 shm = mmap(NULL, size, PROTO_READ | PROTO_WRITE, MAP_SHARED |368 char *shm = mmap(NULL, size, PROTO_READ | PROTO_WRITE, MAP_SHARED | 330 369 MAP_ANONYMOUS, 0, 0); 331 370 if (shm == MAP_FAILED) … … 335 374 336 375 /* Send area */ 337 rc = async_req_1_0(fbphone, FB_PREPARE_SHM, (ipcarg_t) shm);376 int rc = async_req_1_0(fbphone, FB_PREPARE_SHM, (sysarg_t) shm); 338 377 if (rc) 339 378 goto exit; 340 379 341 rc = ipc_share_out_start(fbphone, shm, PROTO_READ);380 rc = async_share_out_start(fbphone, shm, PROTO_READ); 342 381 if (rc) 343 382 goto drop; … … 355 394 } 356 395 357 extern char _binary_gfx_helenos_ppm_start[0];358 extern int _binary_gfx_helenos_ppm_size;359 extern char _binary_gfx_nameic_ppm_start[0];360 extern int _binary_gfx_nameic_ppm_size;361 362 396 /** Redraws console graphics */ 363 397 void gcons_redraw_console(void) 364 398 { 365 int i;366 367 399 if (!use_gcons) 368 400 return; 369 401 370 402 vp_switch(0); 371 set_rgb_color( MAIN_COLOR, MAIN_COLOR);403 set_rgb_color(COLOR_MAIN, COLOR_MAIN); 372 404 clear(); 373 405 draw_pixmap(_binary_gfx_helenos_ppm_start, … … 376 408 (size_t) &_binary_gfx_nameic_ppm_size, 5, 17); 377 409 410 unsigned int i; 378 411 for (i = 0; i < CONSOLE_COUNT; i++) 379 412 redraw_state(i); … … 392 425 static int make_pixmap(char *data, size_t size) 393 426 { 394 char *shm;395 int rc;396 int pxid = -1;397 398 427 /* Create area */ 399 shm = mmap(NULL, size, PROTO_READ | PROTO_WRITE, MAP_SHARED |428 char *shm = mmap(NULL, size, PROTO_READ | PROTO_WRITE, MAP_SHARED | 400 429 MAP_ANONYMOUS, 0, 0); 401 430 if (shm == MAP_FAILED) … … 404 433 memcpy(shm, data, size); 405 434 435 int pxid = -1; 436 406 437 /* Send area */ 407 rc = async_req_1_0(fbphone, FB_PREPARE_SHM, (ipcarg_t) shm);438 int rc = async_req_1_0(fbphone, FB_PREPARE_SHM, (sysarg_t) shm); 408 439 if (rc) 409 440 goto exit; 410 441 411 rc = ipc_share_out_start(fbphone, shm, PROTO_READ);442 rc = async_share_out_start(fbphone, shm, PROTO_READ); 412 443 if (rc) 413 444 goto drop; … … 431 462 } 432 463 433 extern char _binary_gfx_anim_1_ppm_start[0];434 extern int _binary_gfx_anim_1_ppm_size;435 extern char _binary_gfx_anim_2_ppm_start[0];436 extern int _binary_gfx_anim_2_ppm_size;437 extern char _binary_gfx_anim_3_ppm_start[0];438 extern int _binary_gfx_anim_3_ppm_size;439 extern char _binary_gfx_anim_4_ppm_start[0];440 extern int _binary_gfx_anim_4_ppm_size;441 442 464 static void make_anim(void) 443 465 { 444 int an = async_req_1_0(fbphone, FB_ANIM_CREATE, cstatus_vp[KERNEL_CONSOLE]); 466 int an = async_req_1_0(fbphone, FB_ANIM_CREATE, 467 cstatus_vp[KERNEL_CONSOLE]); 445 468 if (an < 0) 446 469 return; 447 470 448 471 int pm = make_pixmap(_binary_gfx_anim_1_ppm_start, 449 ( int) &_binary_gfx_anim_1_ppm_size);472 (size_t) &_binary_gfx_anim_1_ppm_size); 450 473 async_msg_2(fbphone, FB_ANIM_ADDPIXMAP, an, pm); 451 474 452 475 pm = make_pixmap(_binary_gfx_anim_2_ppm_start, 453 ( int) &_binary_gfx_anim_2_ppm_size);476 (size_t) &_binary_gfx_anim_2_ppm_size); 454 477 async_msg_2(fbphone, FB_ANIM_ADDPIXMAP, an, pm); 455 478 456 479 pm = make_pixmap(_binary_gfx_anim_3_ppm_start, 457 ( int) &_binary_gfx_anim_3_ppm_size);480 (size_t) &_binary_gfx_anim_3_ppm_size); 458 481 async_msg_2(fbphone, FB_ANIM_ADDPIXMAP, an, pm); 459 482 460 483 pm = make_pixmap(_binary_gfx_anim_4_ppm_start, 461 ( int) &_binary_gfx_anim_4_ppm_size);484 (size_t) &_binary_gfx_anim_4_ppm_size); 462 485 async_msg_2(fbphone, FB_ANIM_ADDPIXMAP, an, pm); 463 486 … … 466 489 animation = an; 467 490 } 468 469 extern char _binary_gfx_cons_selected_ppm_start[0];470 extern int _binary_gfx_cons_selected_ppm_size;471 extern char _binary_gfx_cons_idle_ppm_start[0];472 extern int _binary_gfx_cons_idle_ppm_size;473 extern char _binary_gfx_cons_has_data_ppm_start[0];474 extern int _binary_gfx_cons_has_data_ppm_size;475 extern char _binary_gfx_cons_kernel_ppm_start[0];476 extern int _binary_gfx_cons_kernel_ppm_size;477 491 478 492 /** Initialize nice graphical console environment */ … … 499 513 500 514 /* Create status buttons */ 501 s ize_t status_start = STATUS_START + (xres - 800) / 2;515 sysarg_t status_start = STATUS_START + (xres - 800) / 2; 502 516 size_t i; 503 517 for (i = 0; i < CONSOLE_COUNT; i++) { … … 510 524 511 525 vp_switch(cstatus_vp[i]); 512 set_rgb_color( 0x202020, 0xffffff);526 set_rgb_color(COLOR_FOREGROUND, COLOR_BACKGROUND); 513 527 } 514 528
Note:
See TracChangeset
for help on using the changeset viewer.
