Changeset bb14312 in mainline
- Timestamp:
- 2021-06-26T16:40:28Z (3 years ago)
- Branches:
- master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 1215db9
- Parents:
- 69511176
- Location:
- uspace/lib
- Files:
-
- 3 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/congfx/src/console.c
r69511176 rbb14312 57 57 static errno_t console_gc_bitmap_render(void *, gfx_rect_t *, gfx_coord2_t *); 58 58 static errno_t console_gc_bitmap_get_alloc(void *, gfx_bitmap_alloc_t *); 59 static errno_t console_gc_cursor_get_pos(void *, gfx_coord2_t *); 60 static errno_t console_gc_cursor_set_pos(void *, gfx_coord2_t *); 61 static errno_t console_gc_cursor_set_visible(void *, bool); 59 62 60 63 gfx_context_ops_t console_gc_ops = { … … 66 69 .bitmap_destroy = console_gc_bitmap_destroy, 67 70 .bitmap_render = console_gc_bitmap_render, 68 .bitmap_get_alloc = console_gc_bitmap_get_alloc 71 .bitmap_get_alloc = console_gc_bitmap_get_alloc, 72 .cursor_get_pos = console_gc_cursor_get_pos, 73 .cursor_set_pos = console_gc_cursor_set_pos, 74 .cursor_set_visible = console_gc_cursor_set_visible 69 75 }; 70 76 … … 435 441 } 436 442 443 /** Get cursor position on console GC. 444 * 445 * @param arg Console GC 446 * @param pos Place to store position 447 * 448 * @return EOK on success or an error code 449 */ 450 static errno_t console_gc_cursor_get_pos(void *arg, gfx_coord2_t *pos) 451 { 452 console_gc_t *cgc = (console_gc_t *) arg; 453 sysarg_t col; 454 sysarg_t row; 455 errno_t rc; 456 457 rc = console_get_pos(cgc->con, &col, &row); 458 if (rc != EOK) 459 return rc; 460 461 pos->x = col; 462 pos->y = row; 463 return EOK; 464 } 465 466 /** Set cursor position on console GC. 467 * 468 * @param arg Console GC 469 * @param pos New cursor position 470 * 471 * @return EOK on success or an error code 472 */ 473 static errno_t console_gc_cursor_set_pos(void *arg, gfx_coord2_t *pos) 474 { 475 console_gc_t *cgc = (console_gc_t *) arg; 476 477 console_set_pos(cgc->con, pos->x, pos->y); 478 return EOK; 479 } 480 481 /** Set cursor visibility on console GC. 482 * 483 * @param arg Console GC 484 * @param visible @c true iff cursor should be made visible 485 * 486 * @return EOK on success or an error code 487 */ 488 static errno_t console_gc_cursor_set_visible(void *arg, bool visible) 489 { 490 console_gc_t *cgc = (console_gc_t *) arg; 491 492 console_cursor_visibility(cgc->con, visible); 493 return EOK; 494 } 495 437 496 /** @} 438 497 */ -
uspace/lib/gfx/include/types/gfx/ops/context.h
r69511176 rbb14312 44 44 #include <types/gfx/coord.h> 45 45 #include <types/gfx/context.h> 46 #include <stdbool.h> 46 47 47 48 /** Graphics context ops */ … … 64 65 /** Get bitmap allocation info */ 65 66 errno_t (*bitmap_get_alloc)(void *, gfx_bitmap_alloc_t *); 67 /** Get hardware cursor position */ 68 errno_t (*cursor_get_pos)(void *, gfx_coord2_t *); 69 /** Set hardware cursor position */ 70 errno_t (*cursor_set_pos)(void *, gfx_coord2_t *); 71 /** Set hardware cursor visibility */ 72 errno_t (*cursor_set_visible)(void *, bool); 66 73 } gfx_context_ops_t; 67 74 -
uspace/lib/gfx/meson.build
r69511176 rbb14312 1 1 # 2 # Copyright (c) 20 19Jiri Svoboda2 # Copyright (c) 2021 Jiri Svoboda 3 3 # All rights reserved. 4 4 # … … 32 32 'src/coord.c', 33 33 'src/context.c', 34 'src/cursor.c', 34 35 'src/render.c' 35 36 ) … … 39 40 'test/color.c', 40 41 'test/coord.c', 42 'test/cursor.c', 41 43 'test/main.c', 42 44 'test/render.c', -
uspace/lib/gfx/test/main.c
r69511176 rbb14312 1 1 /* 2 * Copyright (c) 20 17Jiri Svoboda2 * Copyright (c) 2021 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 34 34 PCUT_IMPORT(color); 35 35 PCUT_IMPORT(coord); 36 PCUT_IMPORT(cursor); 36 37 PCUT_IMPORT(render); 37 38 -
uspace/lib/ui/private/entry.h
r69511176 rbb14312 67 67 extern void ui_entry_backspace(ui_entry_t *); 68 68 extern ui_evclaim_t ui_entry_key_press_unmod(ui_entry_t *, kbd_event_t *); 69 extern void ui_entry_activate(ui_entry_t *); 70 extern void ui_entry_deactivate(ui_entry_t *); 69 71 70 72 #endif -
uspace/lib/ui/src/entry.c
r69511176 rbb14312 39 39 #include <errno.h> 40 40 #include <gfx/context.h> 41 #include <gfx/cursor.h> 41 42 #include <gfx/render.h> 42 43 #include <gfx/text.h> … … 62 63 ui_entry_vpad_text = 0, 63 64 ui_entry_cursor_overshoot = 1, 64 ui_entry_cursor_width = 2, 65 ui_entry_cursor_width_text = 1 65 ui_entry_cursor_width = 2 66 66 }; 67 67 … … 107 107 entry->halign = gfx_halign_left; 108 108 *rentry = entry; 109 109 110 return EOK; 110 111 } … … 194 195 gfx_rect_t rect; 195 196 gfx_font_metrics_t metrics; 196 gfx_coord_t w;197 197 errno_t rc; 198 198 199 199 res = ui_window_get_res(entry->window); 200 200 201 if (res->textmode) { 202 rc = gfx_cursor_set_pos(res->gc, pos); 203 return rc; 204 } 205 201 206 gfx_font_get_metrics(res->font, &metrics); 202 203 w = res->textmode ? ui_entry_cursor_width_text :204 ui_entry_cursor_width;205 207 206 208 rect.p0.x = pos->x; 207 209 rect.p0.y = pos->y - ui_entry_cursor_overshoot; 208 rect.p1.x = pos->x + w;210 rect.p1.x = pos->x + ui_entry_cursor_width; 209 211 rect.p1.y = pos->y + metrics.ascent + metrics.descent + 1 + 210 212 ui_entry_cursor_overshoot; … … 399 401 ui_entry_backspace(entry); 400 402 401 if (event->key == KC_ESCAPE) { 402 entry->active = false; 403 (void) ui_entry_paint(entry); 404 } 403 if (event->key == KC_ESCAPE) 404 ui_entry_deactivate(entry); 405 405 406 406 return ui_claimed; … … 475 475 476 476 if (gfx_pix_inside_rect(&pos, &entry->rect)) { 477 if (!entry->active) { 478 entry->active = true; 479 (void) ui_entry_paint(entry); 480 } 477 ui_entry_activate(entry); 481 478 482 479 return ui_claimed; 483 480 } else { 484 if (entry->active) { 485 entry->active = false; 486 (void) ui_entry_paint(entry); 487 } 481 ui_entry_deactivate(entry); 488 482 } 489 483 } … … 518 512 } 519 513 514 /** Activate text entry. 515 * 516 * @param entry Text entry 517 */ 518 void ui_entry_activate(ui_entry_t *entry) 519 { 520 ui_resource_t *res; 521 522 res = ui_window_get_res(entry->window); 523 524 if (entry->active) 525 return; 526 527 entry->active = true; 528 (void) ui_entry_paint(entry); 529 530 if (res->textmode) 531 gfx_cursor_set_visible(res->gc, true); 532 } 533 534 /** Deactivate text entry. 535 * 536 * @param entry Text entry 537 */ 538 void ui_entry_deactivate(ui_entry_t *entry) 539 { 540 ui_resource_t *res; 541 542 res = ui_window_get_res(entry->window); 543 544 if (!entry->active) 545 return; 546 547 entry->active = false; 548 (void) ui_entry_paint(entry); 549 550 if (res->textmode) 551 gfx_cursor_set_visible(res->gc, false); 552 } 553 520 554 /** @} 521 555 */ -
uspace/lib/ui/src/ui.c
r69511176 rbb14312 128 128 return EIO; 129 129 130 console_cursor_visibility(console, false); 131 130 132 /* ws == ui_ws_console */ 131 133 rc = ui_create_cons(console, &ui); … … 203 205 if (ui->cgc != NULL) 204 206 console_gc_delete(ui->cgc); 205 if (ui->console != NULL) 207 if (ui->console != NULL) { 208 console_cursor_visibility(ui->console, true); 206 209 console_done(ui->console); 210 } 207 211 if (ui->display != NULL) 208 212 display_close(ui->display); -
uspace/lib/ui/test/entry.c
r69511176 rbb14312 270 270 } 271 271 272 /** ui_entry_activate() / ui_entry_deactivate() */ 273 PCUT_TEST(activate_deactivate) 274 { 275 errno_t rc; 276 ui_t *ui = NULL; 277 ui_window_t *window = NULL; 278 ui_wnd_params_t params; 279 ui_entry_t *entry; 280 281 rc = ui_create_disp(NULL, &ui); 282 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 283 284 ui_wnd_params_init(¶ms); 285 params.caption = "Hello"; 286 287 rc = ui_window_create(ui, ¶ms, &window); 288 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 289 PCUT_ASSERT_NOT_NULL(window); 290 291 rc = ui_entry_create(window, "ABC", &entry); 292 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 293 294 PCUT_ASSERT_FALSE(entry->active); 295 296 ui_entry_activate(entry); 297 PCUT_ASSERT_TRUE(entry->active); 298 299 ui_entry_deactivate(entry); 300 PCUT_ASSERT_FALSE(entry->active); 301 302 ui_entry_destroy(entry); 303 ui_window_destroy(window); 304 ui_destroy(ui); 305 } 306 272 307 PCUT_EXPORT(entry);
Note:
See TracChangeset
for help on using the changeset viewer.