Changeset 8ef48ece in mainline for uspace/lib/ui/src/pbutton.c
- Timestamp:
- 2020-10-15T22:12:22Z (5 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- de9992c
- Parents:
- faca61b8
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/ui/src/pbutton.c
rfaca61b8 r8ef48ece 91 91 } 92 92 93 /** Set push button callbacks. 94 * 95 * @param pbutton Push button 96 * @param cb Push button callbacks 97 * @param arg Callback argument 98 */ 99 void ui_pbutton_set_cb(ui_pbutton_t *pbutton, ui_pbutton_cb_t *cb, void *arg) 100 { 101 pbutton->cb = cb; 102 pbutton->arg = arg; 103 } 104 93 105 /** Set button rectangle. 94 106 * … … 314 326 gfx_rect_t rect; 315 327 gfx_coord_t thickness; 328 bool depressed; 316 329 errno_t rc; 317 330 318 331 thickness = pbutton->isdefault ? 2 : 1; 332 depressed = pbutton->held && pbutton->inside; 319 333 320 334 rect.p0.x = pbutton->rect.p0.x + thickness; … … 350 364 pos.y = (rect.p0.y + rect.p1.y) / 2; 351 365 352 if ( pbutton->held) {366 if (depressed) { 353 367 pos.x += ui_pb_press_dx; 354 368 pos.y += ui_pb_press_dy; … … 370 384 goto error; 371 385 372 if ( pbutton->held) {386 if (depressed) { 373 387 rc = ui_pbutton_paint_inset(pbutton, &rect); 374 388 if (rc != EOK) … … 389 403 /** Press down button. 390 404 * 391 * This does not automatically repaint the button.392 *393 405 * @param pbutton Push button 394 406 */ 395 407 void ui_pbutton_press(ui_pbutton_t *pbutton) 396 408 { 409 if (pbutton->held) 410 return; 411 412 pbutton->inside = true; 397 413 pbutton->held = true; 414 (void) ui_pbutton_paint(pbutton); 398 415 } 399 416 400 417 /** Release button. 401 418 * 402 * This does not automatically repaint the button.403 *404 419 * @param pbutton Push button 405 420 */ 406 421 void ui_pbutton_release(ui_pbutton_t *pbutton) 407 422 { 423 if (!pbutton->held) 424 return; 425 408 426 pbutton->held = false; 427 428 if (pbutton->inside) { 429 (void) ui_pbutton_paint(pbutton); 430 ui_pbutton_clicked(pbutton); 431 } 432 } 433 434 /** Pointer entered button. 435 * 436 * @param pbutton Push button 437 */ 438 void ui_pbutton_enter(ui_pbutton_t *pbutton) 439 { 440 if (pbutton->inside) 441 return; 442 443 pbutton->inside = true; 444 if (pbutton->held) 445 (void) ui_pbutton_paint(pbutton); 446 } 447 448 /** Pointer left button. 449 * 450 * @param pbutton Push button 451 */ 452 void ui_pbutton_leave(ui_pbutton_t *pbutton) 453 { 454 if (!pbutton->inside) 455 return; 456 457 pbutton->inside = false; 458 if (pbutton->held) 459 (void) ui_pbutton_paint(pbutton); 460 } 461 462 /** Button was clicked. 463 * 464 * @param pbutton Push button 465 */ 466 void ui_pbutton_clicked(ui_pbutton_t *pbutton) 467 { 468 if (pbutton->cb != NULL && pbutton->cb->clicked != NULL) 469 pbutton->cb->clicked(pbutton, pbutton->arg); 409 470 } 410 471 … … 417 478 { 418 479 gfx_coord2_t pos; 480 bool inside; 419 481 420 482 pos.x = event->hpos; 421 483 pos.y = event->vpos; 422 484 423 if (gfx_pix_inside_rect(&pos, &pbutton->rect)) { 424 if (event->type == POS_PRESS) { 485 inside = gfx_pix_inside_rect(&pos, &pbutton->rect); 486 487 switch (event->type) { 488 case POS_PRESS: 489 if (inside) 425 490 ui_pbutton_press(pbutton); 426 (void) ui_pbutton_paint(pbutton); 491 break; 492 case POS_RELEASE: 493 ui_pbutton_release(pbutton); 494 break; 495 case POS_UPDATE: 496 if (inside && !pbutton->inside) { 497 ui_pbutton_enter(pbutton); 498 } else if (!inside && pbutton->inside) { 499 ui_pbutton_leave(pbutton); 427 500 } 428 } 429 430 if (event->type == POS_RELEASE && pbutton->held) { 431 ui_pbutton_release(pbutton); 432 (void) ui_pbutton_paint(pbutton); 501 break; 433 502 } 434 503 }
Note:
See TracChangeset
for help on using the changeset viewer.