Changeset 2d879f7 in mainline for uspace/lib/ui/src
- Timestamp:
- 2020-11-26T11:59:59Z (5 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/lib/ui/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
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
Note:
See TracChangeset
for help on using the changeset viewer.