Changeset faca61b8 in mainline
- Timestamp:
- 2020-10-15T10:05:42Z (4 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 8ef48ece
- Parents:
- 4ed00d3
- git-author:
- Jiri Svoboda <jiri@…> (2020-10-14 19:05:34)
- git-committer:
- Jiri Svoboda <jiri@…> (2020-10-15 10:05:42)
- Location:
- uspace
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/uidemo/uidemo.c
r4ed00d3 rfaca61b8 81 81 { 82 82 ui_demo_t *demo = (ui_demo_t *) arg; 83 gfx_rect_t rect1; 84 gfx_rect_t rect2; 85 gfx_coord2_t pos; 86 87 rect1.p0.x = 20; 88 rect1.p0.y = 50; 89 rect1.p1.x = 100; 90 rect1.p1.y = 80; 91 92 rect2.p0.x = 120; 93 rect2.p0.y = 50; 94 rect2.p1.x = 200; 95 rect2.p1.y = 80; 96 97 pos.x = event->hpos; 98 pos.y = event->vpos; 99 100 if (event->type == POS_PRESS) { 101 printf("Button press\n"); 102 103 if (gfx_pix_inside_rect(&pos, &rect1)) { 104 printf("Press button 1\n"); 105 ui_pbutton_press(demo->pb1); 106 (void) ui_pbutton_paint(demo->pb1); 107 } 108 if (gfx_pix_inside_rect(&pos, &rect2)) { 109 printf("Press button 2\n"); 110 ui_pbutton_press(demo->pb2); 111 (void) ui_pbutton_paint(demo->pb2); 112 } 113 } 114 115 if (event->type == POS_RELEASE) { 116 printf("Button release\n"); 117 if (gfx_pix_inside_rect(&pos, &rect1)) { 118 printf("Release button 1\n"); 119 ui_pbutton_release(demo->pb1); 120 (void) ui_pbutton_paint(demo->pb1); 121 } 122 if (gfx_pix_inside_rect(&pos, &rect2)) { 123 printf("Release button 2\n"); 124 ui_pbutton_release(demo->pb2); 125 (void) ui_pbutton_paint(demo->pb2); 126 } 127 } 83 84 ui_pbutton_pos_event(demo->pb1, event); 85 ui_pbutton_pos_event(demo->pb2, event); 128 86 } 129 87 -
uspace/lib/ui/include/ui/pbutton.h
r4ed00d3 rfaca61b8 39 39 #include <errno.h> 40 40 #include <gfx/coord.h> 41 #include <io/pos_event.h> 41 42 #include <types/ui/pbutton.h> 42 43 #include <types/ui/resource.h> … … 51 52 extern void ui_pbutton_press(ui_pbutton_t *); 52 53 extern void ui_pbutton_release(ui_pbutton_t *); 54 extern void ui_pbutton_pos_event(ui_pbutton_t *, pos_event_t *); 53 55 54 56 #endif -
uspace/lib/ui/src/pbutton.c
r4ed00d3 rfaca61b8 39 39 #include <gfx/render.h> 40 40 #include <gfx/text.h> 41 #include <io/pos_event.h> 41 42 #include <stdlib.h> 42 43 #include <str.h> … … 408 409 } 409 410 411 /** Handle push button position event. 412 * 413 * @param pbutton Push button 414 * @param pos_event Position event 415 */ 416 void ui_pbutton_pos_event(ui_pbutton_t *pbutton, pos_event_t *event) 417 { 418 gfx_coord2_t pos; 419 420 pos.x = event->hpos; 421 pos.y = event->vpos; 422 423 if (gfx_pix_inside_rect(&pos, &pbutton->rect)) { 424 if (event->type == POS_PRESS) { 425 ui_pbutton_press(pbutton); 426 (void) ui_pbutton_paint(pbutton); 427 } 428 } 429 430 if (event->type == POS_RELEASE && pbutton->held) { 431 ui_pbutton_release(pbutton); 432 (void) ui_pbutton_paint(pbutton); 433 } 434 } 435 410 436 /** @} 411 437 */ -
uspace/lib/ui/test/pbutton.c
r4ed00d3 rfaca61b8 185 185 } 186 186 187 /** ui_pos_event() correctly translates POS_PRESS/POS_RELEASE */ 188 PCUT_TEST(pos_event_press_release) 189 { 190 ui_pbutton_t *pbutton; 191 pos_event_t event; 192 gfx_rect_t rect; 193 errno_t rc; 194 195 rc = ui_pbutton_create(NULL, "Hello", &pbutton); 196 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 197 198 PCUT_ASSERT_FALSE(pbutton->held); 199 200 rect.p0.x = 10; 201 rect.p0.y = 20; 202 rect.p1.x = 30; 203 rect.p1.y = 40; 204 ui_pbutton_set_rect(pbutton, &rect); 205 206 /* Press outside does nothing */ 207 event.type = POS_PRESS; 208 event.hpos = 9; 209 event.vpos = 20; 210 ui_pbutton_pos_event(pbutton, &event); 211 PCUT_ASSERT_FALSE(pbutton->held); 212 213 /* Press inside depresses button */ 214 event.type = POS_PRESS; 215 event.hpos = 10; 216 event.vpos = 20; 217 ui_pbutton_pos_event(pbutton, &event); 218 PCUT_ASSERT_TRUE(pbutton->held); 219 220 /* Release outside (or anywhere) relases button */ 221 event.type = POS_RELEASE; 222 event.hpos = 9; 223 event.vpos = 20; 224 ui_pbutton_pos_event(pbutton, &event); 225 PCUT_ASSERT_FALSE(pbutton->held); 226 227 ui_pbutton_destroy(pbutton); 228 } 229 187 230 static errno_t testgc_set_color(void *arg, gfx_color_t *color) 188 231 { … … 214 257 tbm->alloc.off0 = 0; 215 258 tbm->alloc.pixels = calloc(sizeof(uint32_t), 216 217 259 (params->rect.p1.x - params->rect.p0.x) * 260 (params->rect.p1.y - params->rect.p0.y)); 218 261 tbm->myalloc = true; 219 262 if (tbm->alloc.pixels == NULL) { -
uspace/lib/ui/test/resource.c
r4ed00d3 rfaca61b8 114 114 tbm->alloc.off0 = 0; 115 115 tbm->alloc.pixels = calloc(sizeof(uint32_t), 116 117 116 (params->rect.p1.x - params->rect.p0.x) * 117 (params->rect.p1.y - params->rect.p0.y)); 118 118 tbm->myalloc = true; 119 119 if (tbm->alloc.pixels == NULL) {
Note:
See TracChangeset
for help on using the changeset viewer.