Changeset 2d879f7 in mainline
- Timestamp:
- 2020-11-26T11:59:59Z (4 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 554a5f1
- Parents:
- d8ddf7a
- git-author:
- Jiri Svoboda <jiri@…> (2020-11-25 18:46:07)
- git-committer:
- Jiri Svoboda <jiri@…> (2020-11-26 11:59:59)
- Location:
- uspace
- Files:
-
- 1 added
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/uidemo/uidemo.c
rd8ddf7a r2d879f7 120 120 ui_wnd_params_init(¶ms); 121 121 params.caption = "UI Demo"; 122 params.style |= ui_wds_resizable; 122 123 params.rect.p0.x = 0; 123 124 params.rect.p0.y = 0; -
uspace/lib/display/include/types/display/wndparams.h
rd8ddf7a r2d879f7 41 41 * 42 42 * The window's dimensions are determined by the bounding rectangle, 43 * the position of which does not relate to its posit on on the display,43 * the position of which does not relate to its position on the display, 44 44 * it just determines which range of logical coordinates is used 45 45 * by the window. -
uspace/lib/ui/include/types/ui/wdecor.h
rd8ddf7a r2d879f7 38 38 39 39 #include <gfx/coord.h> 40 #include <types/ui/cursor.h> 40 41 41 42 struct ui_wdecor; 42 43 typedef struct ui_wdecor ui_wdecor_t; 44 45 /** Window decoration style */ 46 typedef enum { 47 ui_wds_none = 0x0, 48 ui_wds_resizable = 0x1 49 } ui_wdecor_style_t; 50 51 /** Window resize type */ 52 typedef enum { 53 ui_wr_none = 0, 54 55 ui_wr_top = 0x1, 56 ui_wr_left = 0x2, 57 ui_wr_bottom = 0x4, 58 ui_wr_right = 0x8, 59 60 ui_wr_top_left = ui_wr_top | ui_wr_left, 61 ui_wr_bottom_left = ui_wr_bottom | ui_wr_left, 62 ui_wr_bottom_right = ui_wr_bottom | ui_wr_right, 63 ui_wr_top_right = ui_wr_top | ui_wr_right 64 } ui_wdecor_rsztype_t; 43 65 44 66 /** Window decoration callbacks */ … … 46 68 void (*close)(ui_wdecor_t *, void *); 47 69 void (*move)(ui_wdecor_t *, void *, gfx_coord2_t *); 70 void (*resize)(ui_wdecor_t *, void *, ui_wdecor_rsztype_t, 71 gfx_coord2_t *); 72 void (*set_cursor)(ui_wdecor_t *, void *, ui_stock_cursor_t); 48 73 } ui_wdecor_cb_t; 49 74 -
uspace/lib/ui/include/types/ui/window.h
rd8ddf7a r2d879f7 40 40 #include <io/kbd_event.h> 41 41 #include <io/pos_event.h> 42 #include <types/ui/wdecor.h> 42 43 43 44 struct ui_window; … … 64 65 /** Window caption */ 65 66 const char *caption; 67 /** Window decoration style */ 68 ui_wdecor_style_t style; 66 69 /** Window placement */ 67 70 ui_wnd_placement_t placement; -
uspace/lib/ui/include/ui/wdecor.h
rd8ddf7a r2d879f7 45 45 46 46 extern errno_t ui_wdecor_create(ui_resource_t *, const char *, 47 ui_wdecor_ t **);47 ui_wdecor_style_t, ui_wdecor_t **); 48 48 extern void ui_wdecor_destroy(ui_wdecor_t *); 49 49 extern void ui_wdecor_set_cb(ui_wdecor_t *, ui_wdecor_cb_t *, void *); -
uspace/lib/ui/private/wdecor.h
rd8ddf7a r2d879f7 39 39 40 40 #include <gfx/coord.h> 41 #include <io/pos_event.h> 41 42 #include <stdbool.h> 43 #include <types/ui/cursor.h> 42 44 #include <types/ui/wdecor.h> 43 45 … … 55 57 /** Window decoration rectangle */ 56 58 gfx_rect_t rect; 59 /** Style */ 60 ui_wdecor_style_t style; 57 61 /** Caption */ 58 62 char *caption; … … 80 84 extern void ui_wdecor_close(ui_wdecor_t *); 81 85 extern void ui_wdecor_move(ui_wdecor_t *, gfx_coord2_t *); 86 extern void ui_wdecor_resize(ui_wdecor_t *, ui_wdecor_rsztype_t, 87 gfx_coord2_t *); 88 extern void ui_wdecor_set_cursor(ui_wdecor_t *, ui_stock_cursor_t); 82 89 extern void ui_wdecor_get_geom(ui_wdecor_t *, ui_wdecor_geom_t *); 90 extern void ui_wdecor_frame_pos_event(ui_wdecor_t *, pos_event_t *); 91 extern ui_wdecor_rsztype_t ui_wdecor_get_rsztype(ui_wdecor_t *, 92 gfx_coord2_t *); 93 extern ui_stock_cursor_t ui_wdecor_cursor_from_rsztype(ui_wdecor_rsztype_t); 83 94 84 95 #endif -
uspace/lib/ui/private/window.h
rd8ddf7a r2d879f7 59 59 /** Window GC */ 60 60 gfx_context_t *gc; 61 /** Window rectangle */ 62 gfx_rect_t rect; 61 63 /** Application area bitmap */ 62 64 gfx_bitmap_t *app_bmp; … … 69 71 /** Top-level control in the application area */ 70 72 struct ui_control *control; 73 /** Current cursor */ 74 ui_stock_cursor_t cursor; 71 75 }; 72 76 -
uspace/lib/ui/src/wdecor.c
rd8ddf7a r2d879f7 34 34 */ 35 35 36 #include <assert.h> 36 37 #include <errno.h> 37 38 #include <gfx/color.h> … … 54 55 }; 55 56 57 enum { 58 wdecor_corner_w = 24, 59 wdecor_corner_h = 24, 60 wdecor_edge_w = 4, 61 wdecor_edge_h = 4 62 }; 63 56 64 /** Create new window decoration. 57 65 * 58 66 * @param resource UI resource 59 67 * @param caption Window caption 68 * @param style Style 60 69 * @param rwdecor Place to store pointer to new window decoration 61 70 * @return EOK on success, ENOMEM if out of memory 62 71 */ 63 72 errno_t ui_wdecor_create(ui_resource_t *resource, const char *caption, 64 ui_wdecor_ t **rwdecor)73 ui_wdecor_style_t style, ui_wdecor_t **rwdecor) 65 74 { 66 75 ui_wdecor_t *wdecor; … … 89 98 wdecor->res = resource; 90 99 wdecor->active = true; 100 wdecor->style = style; 91 101 *rwdecor = wdecor; 92 102 return EOK; … … 244 254 } 245 255 256 /** Send decoration resize event. 257 * 258 * @param wdecor Window decoration 259 * @param rsztype Resize type 260 * @param pos Position where the button was pressed 261 */ 262 void ui_wdecor_resize(ui_wdecor_t *wdecor, ui_wdecor_rsztype_t rsztype, 263 gfx_coord2_t *pos) 264 { 265 if (wdecor->cb != NULL && wdecor->cb->resize != NULL) 266 wdecor->cb->resize(wdecor, wdecor->arg, rsztype, pos); 267 } 268 269 /** Send cursor change event. 270 * 271 * @param wdecor Window decoration 272 * @param cursor Cursor 273 */ 274 void ui_wdecor_set_cursor(ui_wdecor_t *wdecor, ui_stock_cursor_t cursor) 275 { 276 if (wdecor->cb != NULL && wdecor->cb->set_cursor != NULL) 277 wdecor->cb->set_cursor(wdecor, wdecor->arg, cursor); 278 } 279 246 280 /** Get window decoration geometry. 247 281 * … … 287 321 } 288 322 323 /** Get resize type for pointer at the specified position. 324 * 325 * @param wdecor Window decoration 326 * @param pos Pointer position 327 * @return Resize type 328 */ 329 ui_wdecor_rsztype_t ui_wdecor_get_rsztype(ui_wdecor_t *wdecor, 330 gfx_coord2_t *pos) 331 { 332 bool eleft, eright; 333 bool etop, ebottom; 334 bool edge; 335 bool cleft, cright; 336 bool ctop, cbottom; 337 338 /* Window not resizable? */ 339 if ((wdecor->style & ui_wds_resizable) == 0) 340 return ui_wr_none; 341 342 /* Position not inside window? */ 343 if (!gfx_pix_inside_rect(pos, &wdecor->rect)) 344 return ui_wr_none; 345 346 /* Position is within edge width from the outside */ 347 eleft = (pos->x < wdecor->rect.p0.x + wdecor_edge_w); 348 eright = (pos->x >= wdecor->rect.p1.x - wdecor_edge_w); 349 etop = (pos->y < wdecor->rect.p0.y + wdecor_edge_h); 350 ebottom = (pos->y >= wdecor->rect.p1.y - wdecor_edge_h); 351 352 /* Position is on one of the four edges */ 353 edge = eleft || eright || etop || ebottom; 354 355 /* Position is within resize-corner distance from the outside */ 356 cleft = (pos->x < wdecor->rect.p0.x + wdecor_corner_w); 357 cright = (pos->x >= wdecor->rect.p1.x - wdecor_corner_w); 358 ctop = (pos->y < wdecor->rect.p0.y + wdecor_corner_h); 359 cbottom = (pos->y >= wdecor->rect.p1.y - wdecor_corner_h); 360 361 /* Top-left corner */ 362 if (edge && cleft && ctop) 363 return ui_wr_top_left; 364 365 /* Top-right corner */ 366 if (edge && cright && ctop) 367 return ui_wr_top_right; 368 369 /* Bottom-left corner */ 370 if (edge && cleft && cbottom) 371 return ui_wr_bottom_left; 372 373 /* Bottom-right corner */ 374 if (edge && cright && cbottom) 375 return ui_wr_bottom_right; 376 377 /* Left edge */ 378 if (eleft) 379 return ui_wr_left; 380 381 /* Right edge */ 382 if (eright) 383 return ui_wr_right; 384 385 /* Top edge */ 386 if (etop) 387 return ui_wr_top; 388 389 /* Bottom edge */ 390 if (ebottom) 391 return ui_wr_bottom; 392 393 return ui_wr_none; 394 } 395 396 /** Get stock cursor to use for the specified window resize type. 397 * 398 * The resize type must be valid, otherwise behavior is undefined. 399 * 400 * @param rsztype Resize type 401 * @return Cursor to use for this resize type 402 */ 403 ui_stock_cursor_t ui_wdecor_cursor_from_rsztype(ui_wdecor_rsztype_t rsztype) 404 { 405 switch (rsztype) { 406 case ui_wr_none: 407 return ui_curs_arrow; 408 409 case ui_wr_top: 410 case ui_wr_bottom: 411 return ui_curs_size_ud; 412 413 case ui_wr_left: 414 case ui_wr_right: 415 return ui_curs_size_lr; 416 417 case ui_wr_top_left: 418 case ui_wr_bottom_right: 419 return ui_curs_size_uldr; 420 421 case ui_wr_top_right: 422 case ui_wr_bottom_left: 423 return ui_curs_size_urdl; 424 425 default: 426 assert(false); 427 return ui_curs_arrow; 428 } 429 } 430 431 /** Handle window frame position event. 432 * 433 * @param wdecor Window decoration 434 * @param pos_event Position event 435 */ 436 void ui_wdecor_frame_pos_event(ui_wdecor_t *wdecor, pos_event_t *event) 437 { 438 gfx_coord2_t pos; 439 ui_wdecor_rsztype_t rsztype; 440 ui_stock_cursor_t cursor; 441 442 pos.x = event->hpos; 443 pos.y = event->vpos; 444 445 /* Set appropriate resizing cursor, or set arrow cursor */ 446 447 rsztype = ui_wdecor_get_rsztype(wdecor, &pos); 448 cursor = ui_wdecor_cursor_from_rsztype(rsztype); 449 450 ui_wdecor_set_cursor(wdecor, cursor); 451 452 /* Press on window border? */ 453 if (rsztype != ui_wr_none && event->type == POS_PRESS) 454 ui_wdecor_resize(wdecor, rsztype, &pos); 455 } 456 289 457 /** Handle window decoration position event. 290 458 * … … 307 475 return; 308 476 477 ui_wdecor_frame_pos_event(wdecor, event); 478 309 479 if (event->type == POS_PRESS && 310 480 gfx_pix_inside_rect(&pos, &geom.title_bar_rect)) -
uspace/lib/ui/src/window.c
rd8ddf7a r2d879f7 59 59 static void dwnd_kbd_event(void *, kbd_event_t *); 60 60 static void dwnd_pos_event(void *, pos_event_t *); 61 static void dwnd_resize_event(void *, gfx_rect_t *); 61 62 static void dwnd_unfocus_event(void *); 62 63 … … 66 67 .kbd_event = dwnd_kbd_event, 67 68 .pos_event = dwnd_pos_event, 69 .resize_event = dwnd_resize_event, 68 70 .unfocus_event = dwnd_unfocus_event 69 71 }; … … 71 73 static void wd_close(ui_wdecor_t *, void *); 72 74 static void wd_move(ui_wdecor_t *, void *, gfx_coord2_t *); 75 static void wd_resize(ui_wdecor_t *, void *, ui_wdecor_rsztype_t, 76 gfx_coord2_t *); 77 static void wd_set_cursor(ui_wdecor_t *, void *, ui_stock_cursor_t); 73 78 74 79 static ui_wdecor_cb_t wdecor_cb = { 75 80 .close = wd_close, 76 .move = wd_move 81 .move = wd_move, 82 .resize = wd_resize, 83 .set_cursor = wd_set_cursor 77 84 }; 78 85 … … 118 125 display_wnd_params_init(&dparams); 119 126 dparams.rect = params->rect; 127 /* Only allow making the window larger */ 128 gfx_rect_dims(¶ms->rect, &dparams.min_size); 120 129 121 130 if (ui->display != NULL) { … … 175 184 goto error; 176 185 177 rc = ui_wdecor_create(res, params->caption, &wdecor);186 rc = ui_wdecor_create(res, params->caption, params->style, &wdecor); 178 187 if (rc != EOK) 179 188 goto error; … … 185 194 window->ui = ui; 186 195 window->dwindow = dwindow; 196 window->rect = params->rect; 187 197 window->gc = gc; 188 198 window->res = res; 189 199 window->wdecor = wdecor; 200 window->cursor = ui_curs_arrow; 190 201 *rwindow = window; 191 202 return EOK; … … 435 446 } 436 447 448 /** Handle window resize event */ 449 static void dwnd_resize_event(void *arg, gfx_rect_t *rect) 450 { 451 ui_window_t *window = (ui_window_t *) arg; 452 453 /* Make sure we don't process events until fully initialized */ 454 if (window->wdecor == NULL) 455 return; 456 457 if ((window->wdecor->style & ui_wds_resizable) == 0) 458 return; 459 460 (void) ui_window_resize(window, rect); 461 (void) ui_window_paint(window); 462 } 463 437 464 /** Handle window unfocus event. */ 438 465 static void dwnd_unfocus_event(void *arg) … … 451 478 * 452 479 * @param wdecor Window decoration 453 * @param arg Argument ( demo)480 * @param arg Argument (window) 454 481 */ 455 482 static void wd_close(ui_wdecor_t *wdecor, void *arg) … … 463 490 * 464 491 * @param wdecor Window decoration 465 * @param arg Argument ( demo)492 * @param arg Argument (window) 466 493 * @param pos Position where the title bar was pressed 467 494 */ … … 471 498 472 499 (void) display_window_move_req(window->dwindow, pos); 500 } 501 502 /** Window decoration requested window resize. 503 * 504 * @param wdecor Window decoration 505 * @param arg Argument (window) 506 * @param rsztype Resize type 507 * @param pos Position where the button was pressed 508 */ 509 static void wd_resize(ui_wdecor_t *wdecor, void *arg, 510 ui_wdecor_rsztype_t rsztype, gfx_coord2_t *pos) 511 { 512 ui_window_t *window = (ui_window_t *) arg; 513 514 (void) display_window_resize_req(window->dwindow, rsztype, pos); 515 } 516 517 /** Window decoration requested changing cursor. 518 * 519 * @param wdecor Window decoration 520 * @param arg Argument (window) 521 * @param cursor Cursor to set 522 */ 523 static void wd_set_cursor(ui_wdecor_t *wdecor, void *arg, 524 ui_stock_cursor_t cursor) 525 { 526 ui_window_t *window = (ui_window_t *) arg; 527 display_stock_cursor_t dcursor; 528 529 if (cursor == window->cursor) 530 return; 531 532 dcursor = dcurs_arrow; 533 534 switch (cursor) { 535 case ui_curs_arrow: 536 dcursor = dcurs_arrow; 537 break; 538 case ui_curs_size_ud: 539 dcursor = dcurs_size_ud; 540 break; 541 case ui_curs_size_lr: 542 dcursor = dcurs_size_lr; 543 break; 544 case ui_curs_size_uldr: 545 dcursor = dcurs_size_uldr; 546 break; 547 case ui_curs_size_urdl: 548 dcursor = dcurs_size_urdl; 549 break; 550 } 551 552 (void) display_window_set_cursor(window->dwindow, dcursor); 553 window->cursor = cursor; 473 554 } 474 555 -
uspace/lib/ui/test/wdecor.c
rd8ddf7a r2d879f7 60 60 static void test_wdecor_close(ui_wdecor_t *, void *); 61 61 static void test_wdecor_move(ui_wdecor_t *, void *, gfx_coord2_t *); 62 static void test_wdecor_resize(ui_wdecor_t *, void *, ui_wdecor_rsztype_t, 63 gfx_coord2_t *); 64 static void test_wdecor_set_cursor(ui_wdecor_t *, void *, ui_stock_cursor_t); 62 65 63 66 static ui_wdecor_cb_t test_wdecor_cb = { 64 67 .close = test_wdecor_close, 65 .move = test_wdecor_move 68 .move = test_wdecor_move, 69 .resize = test_wdecor_resize, 70 .set_cursor = test_wdecor_set_cursor 66 71 }; 67 72 … … 90 95 bool move; 91 96 gfx_coord2_t pos; 97 bool resize; 98 ui_wdecor_rsztype_t rsztype; 99 bool set_cursor; 100 ui_stock_cursor_t cursor; 92 101 } test_cb_resp_t; 93 102 … … 98 107 errno_t rc; 99 108 100 rc = ui_wdecor_create(NULL, "Hello", &wdecor);109 rc = ui_wdecor_create(NULL, "Hello", ui_wds_none, &wdecor); 101 110 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 102 111 PCUT_ASSERT_NOT_NULL(wdecor); … … 118 127 errno_t rc; 119 128 120 rc = ui_wdecor_create(NULL, "Hello", &wdecor);129 rc = ui_wdecor_create(NULL, "Hello", ui_wds_none, &wdecor); 121 130 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 122 131 … … 141 150 errno_t rc; 142 151 143 rc = ui_wdecor_create(NULL, "Hello", &wdecor);152 rc = ui_wdecor_create(NULL, "Hello", ui_wds_none, &wdecor); 144 153 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 145 154 … … 172 181 PCUT_ASSERT_NOT_NULL(resource); 173 182 174 rc = ui_wdecor_create(resource, "Hello", &wdecor);183 rc = ui_wdecor_create(resource, "Hello", ui_wds_none, &wdecor); 175 184 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 176 185 … … 192 201 test_cb_resp_t resp; 193 202 194 rc = ui_wdecor_create(NULL, "Hello", &wdecor);203 rc = ui_wdecor_create(NULL, "Hello", ui_wds_none, &wdecor); 195 204 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 196 205 … … 219 228 gfx_coord2_t pos; 220 229 221 rc = ui_wdecor_create(NULL, "Hello", &wdecor);230 rc = ui_wdecor_create(NULL, "Hello", ui_wds_none, &wdecor); 222 231 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 223 232 … … 245 254 } 246 255 256 /** Test ui_wdecor_resize() */ 257 PCUT_TEST(resize) 258 { 259 errno_t rc; 260 ui_wdecor_t *wdecor; 261 test_cb_resp_t resp; 262 ui_wdecor_rsztype_t rsztype; 263 gfx_coord2_t pos; 264 265 rc = ui_wdecor_create(NULL, "Hello", ui_wds_none, &wdecor); 266 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 267 268 rsztype = ui_wr_bottom; 269 pos.x = 3; 270 pos.y = 4; 271 272 /* Resize callback with no callbacks set */ 273 ui_wdecor_resize(wdecor, rsztype, &pos); 274 275 /* Resize callback with move callback not implemented */ 276 ui_wdecor_set_cb(wdecor, &dummy_wdecor_cb, NULL); 277 ui_wdecor_resize(wdecor, rsztype, &pos); 278 279 /* Resize callback with real callback set */ 280 resp.resize = false; 281 resp.rsztype = ui_wr_none; 282 resp.pos.x = 0; 283 resp.pos.y = 0; 284 ui_wdecor_set_cb(wdecor, &test_wdecor_cb, &resp); 285 ui_wdecor_resize(wdecor, rsztype, &pos); 286 PCUT_ASSERT_TRUE(resp.resize); 287 PCUT_ASSERT_INT_EQUALS(rsztype, resp.rsztype); 288 PCUT_ASSERT_INT_EQUALS(pos.x, resp.pos.x); 289 PCUT_ASSERT_INT_EQUALS(pos.y, resp.pos.y); 290 291 ui_wdecor_destroy(wdecor); 292 } 293 294 /** Test ui_wdecor_set_cursor() */ 295 PCUT_TEST(set_cursor) 296 { 297 errno_t rc; 298 ui_wdecor_t *wdecor; 299 test_cb_resp_t resp; 300 ui_stock_cursor_t cursor; 301 302 rc = ui_wdecor_create(NULL, "Hello", ui_wds_none, &wdecor); 303 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 304 305 cursor = ui_curs_size_uldr; 306 307 /* Set cursor callback with no callbacks set */ 308 ui_wdecor_set_cursor(wdecor, cursor); 309 310 /* Set cursor callback with move callback not implemented */ 311 ui_wdecor_set_cb(wdecor, &dummy_wdecor_cb, NULL); 312 ui_wdecor_set_cursor(wdecor, cursor); 313 314 /* Set cursor callback with real callback set */ 315 resp.set_cursor = false; 316 resp.cursor = ui_curs_arrow; 317 ui_wdecor_set_cb(wdecor, &test_wdecor_cb, &resp); 318 ui_wdecor_set_cursor(wdecor, cursor); 319 PCUT_ASSERT_TRUE(resp.set_cursor); 320 PCUT_ASSERT_INT_EQUALS(cursor, resp.cursor); 321 322 ui_wdecor_destroy(wdecor); 323 } 324 247 325 /** Clicking the close button generates close callback */ 248 326 PCUT_TEST(close_btn_clicked) … … 253 331 errno_t rc; 254 332 255 rc = ui_wdecor_create(NULL, "Hello", &wdecor);333 rc = ui_wdecor_create(NULL, "Hello", ui_wds_none, &wdecor); 256 334 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 257 335 … … 282 360 errno_t rc; 283 361 284 rc = ui_wdecor_create(NULL, "Hello", &wdecor);362 rc = ui_wdecor_create(NULL, "Hello", ui_wds_none, &wdecor); 285 363 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 286 364 … … 318 396 errno_t rc; 319 397 320 rc = ui_wdecor_create(NULL, "Hello", &wdecor);398 rc = ui_wdecor_create(NULL, "Hello", ui_wds_none, &wdecor); 321 399 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 322 400 … … 369 447 PCUT_ASSERT_INT_EQUALS(100, rect.p1.x); 370 448 PCUT_ASSERT_INT_EQUALS(200, rect.p1.y); 449 } 450 451 /** Test ui_wdecor_get_rsztype() */ 452 PCUT_TEST(get_rsztype) 453 { 454 ui_wdecor_t *wdecor; 455 gfx_rect_t rect; 456 ui_wdecor_rsztype_t rsztype; 457 gfx_coord2_t pos; 458 errno_t rc; 459 460 rc = ui_wdecor_create(NULL, "Hello", ui_wds_resizable, &wdecor); 461 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 462 463 rect.p0.x = 10; 464 rect.p0.y = 20; 465 rect.p1.x = 100; 466 rect.p1.y = 200; 467 468 ui_wdecor_set_rect(wdecor, &rect); 469 470 /* Outside of the window */ 471 pos.x = 0; 472 pos.y = -1; 473 rsztype = ui_wdecor_get_rsztype(wdecor, &pos); 474 PCUT_ASSERT_EQUALS(ui_wr_none, rsztype); 475 476 /* Middle of the window */ 477 pos.x = 50; 478 pos.y = 100; 479 rsztype = ui_wdecor_get_rsztype(wdecor, &pos); 480 PCUT_ASSERT_EQUALS(ui_wr_none, rsztype); 481 482 /* Top-left corner, but not on edge */ 483 pos.x = 20; 484 pos.y = 30; 485 rsztype = ui_wdecor_get_rsztype(wdecor, &pos); 486 PCUT_ASSERT_EQUALS(ui_wr_none, rsztype); 487 488 /* Top-left corner on top edge */ 489 pos.x = 20; 490 pos.y = 20; 491 rsztype = ui_wdecor_get_rsztype(wdecor, &pos); 492 PCUT_ASSERT_EQUALS(ui_wr_top_left, rsztype); 493 494 /* Top-left corner on left edge */ 495 pos.x = 10; 496 pos.y = 30; 497 rsztype = ui_wdecor_get_rsztype(wdecor, &pos); 498 PCUT_ASSERT_EQUALS(ui_wr_top_left, rsztype); 499 500 /* Top-right corner on top edge */ 501 pos.x = 90; 502 pos.y = 20; 503 rsztype = ui_wdecor_get_rsztype(wdecor, &pos); 504 PCUT_ASSERT_EQUALS(ui_wr_top_right, rsztype); 505 506 /* Top-right corner on right edge */ 507 pos.x = 99; 508 pos.y = 30; 509 rsztype = ui_wdecor_get_rsztype(wdecor, &pos); 510 PCUT_ASSERT_EQUALS(ui_wr_top_right, rsztype); 511 512 /* Top edge */ 513 pos.x = 50; 514 pos.y = 20; 515 rsztype = ui_wdecor_get_rsztype(wdecor, &pos); 516 PCUT_ASSERT_EQUALS(ui_wr_top, rsztype); 517 518 /* Bottom edge */ 519 pos.x = 50; 520 pos.y = 199; 521 rsztype = ui_wdecor_get_rsztype(wdecor, &pos); 522 PCUT_ASSERT_EQUALS(ui_wr_bottom, rsztype); 523 524 /* Left edge */ 525 pos.x = 10; 526 pos.y = 100; 527 rsztype = ui_wdecor_get_rsztype(wdecor, &pos); 528 PCUT_ASSERT_EQUALS(ui_wr_left, rsztype); 529 530 /* Right edge */ 531 pos.x = 99; 532 pos.y = 100; 533 rsztype = ui_wdecor_get_rsztype(wdecor, &pos); 534 PCUT_ASSERT_EQUALS(ui_wr_right, rsztype); 535 536 ui_wdecor_destroy(wdecor); 537 538 /* Non-resizable window */ 539 540 rc = ui_wdecor_create(NULL, "Hello", ui_wds_none, &wdecor); 541 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 542 543 rect.p0.x = 10; 544 rect.p0.y = 20; 545 rect.p1.x = 100; 546 rect.p1.y = 200; 547 548 ui_wdecor_set_rect(wdecor, &rect); 549 550 pos.x = 10; 551 pos.y = 20; 552 rsztype = ui_wdecor_get_rsztype(wdecor, &pos); 553 PCUT_ASSERT_EQUALS(ui_wr_none, rsztype); 554 555 ui_wdecor_destroy(wdecor); 556 } 557 558 /** Test ui_wdecor_cursor_from_rsztype() */ 559 PCUT_TEST(cursor_from_rsztype) 560 { 561 PCUT_ASSERT_EQUALS(ui_curs_arrow, 562 ui_wdecor_cursor_from_rsztype(ui_wr_none)); 563 PCUT_ASSERT_EQUALS(ui_curs_size_ud, 564 ui_wdecor_cursor_from_rsztype(ui_wr_top)); 565 PCUT_ASSERT_EQUALS(ui_curs_size_ud, 566 ui_wdecor_cursor_from_rsztype(ui_wr_bottom)); 567 PCUT_ASSERT_EQUALS(ui_curs_size_lr, 568 ui_wdecor_cursor_from_rsztype(ui_wr_left)); 569 PCUT_ASSERT_EQUALS(ui_curs_size_lr, 570 ui_wdecor_cursor_from_rsztype(ui_wr_right)); 571 PCUT_ASSERT_EQUALS(ui_curs_size_uldr, 572 ui_wdecor_cursor_from_rsztype(ui_wr_top_left)); 573 PCUT_ASSERT_EQUALS(ui_curs_size_uldr, 574 ui_wdecor_cursor_from_rsztype(ui_wr_bottom_right)); 575 PCUT_ASSERT_EQUALS(ui_curs_size_urdl, 576 ui_wdecor_cursor_from_rsztype(ui_wr_top_right)); 577 PCUT_ASSERT_EQUALS(ui_curs_size_urdl, 578 ui_wdecor_cursor_from_rsztype(ui_wr_bottom_left)); 579 } 580 581 /** Test ui_wdecor_frame_pos_event() */ 582 PCUT_TEST(frame_pos_event) 583 { 584 ui_wdecor_t *wdecor; 585 gfx_rect_t rect; 586 test_cb_resp_t resp; 587 pos_event_t event; 588 errno_t rc; 589 590 rc = ui_wdecor_create(NULL, "Hello", ui_wds_resizable, &wdecor); 591 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 592 593 rect.p0.x = 10; 594 rect.p0.y = 20; 595 rect.p1.x = 100; 596 rect.p1.y = 200; 597 598 ui_wdecor_set_rect(wdecor, &rect); 599 ui_wdecor_set_cb(wdecor, &test_wdecor_cb, &resp); 600 601 /* Release on window border should do nothing */ 602 resp.resize = false; 603 event.type = POS_RELEASE; 604 event.hpos = 10; 605 event.vpos = 10; 606 ui_wdecor_frame_pos_event(wdecor, &event); 607 PCUT_ASSERT_FALSE(resp.resize); 608 609 /* Press in the middle of the window should do nothing */ 610 resp.resize = false; 611 event.type = POS_PRESS; 612 event.hpos = 50; 613 event.vpos = 100; 614 ui_wdecor_frame_pos_event(wdecor, &event); 615 PCUT_ASSERT_FALSE(resp.resize); 616 617 /* Press on window border should cause resize to be called */ 618 resp.resize = false; 619 event.type = POS_PRESS; 620 event.hpos = 10; 621 event.vpos = 20; 622 ui_wdecor_frame_pos_event(wdecor, &event); 623 PCUT_ASSERT_TRUE(resp.resize); 624 625 ui_wdecor_destroy(wdecor); 371 626 } 372 627 … … 462 717 } 463 718 719 static void test_wdecor_resize(ui_wdecor_t *wdecor, void *arg, 720 ui_wdecor_rsztype_t rsztype, gfx_coord2_t *pos) 721 { 722 test_cb_resp_t *resp = (test_cb_resp_t *) arg; 723 724 resp->resize = true; 725 resp->rsztype = rsztype; 726 resp->pos = *pos; 727 } 728 729 static void test_wdecor_set_cursor(ui_wdecor_t *wdecor, void *arg, 730 ui_stock_cursor_t cursor) 731 { 732 test_cb_resp_t *resp = (test_cb_resp_t *) arg; 733 734 resp->set_cursor = true; 735 resp->cursor = cursor; 736 } 737 464 738 PCUT_EXPORT(wdecor);
Note:
See TracChangeset
for help on using the changeset viewer.