Changeset f6df5a3 in mainline for uspace/app/uidemo/uidemo.c
- Timestamp:
- 2020-10-13T20:06:47Z (4 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- c9a7adc
- Parents:
- 47728678
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/uidemo/uidemo.c
r47728678 rf6df5a3 39 39 #include <ui/pbutton.h> 40 40 #include <ui/resource.h> 41 #include "uidemo.h" 41 42 42 43 static void wnd_close_event(void *); 43 44 static void wnd_kbd_event(void *, kbd_event_t *); 45 static void wnd_pos_event(void *, pos_event_t *); 44 46 45 47 static display_wnd_cb_t wnd_cb = { 46 48 .close_event = wnd_close_event, 47 .kbd_event = wnd_kbd_event 49 .kbd_event = wnd_kbd_event, 50 .pos_event = wnd_pos_event 48 51 }; 49 52 50 53 static bool quit = false; 51 54 55 /** Print syntax. */ 52 56 static void print_syntax(void) 53 57 { … … 55 59 } 56 60 61 /** Handle window close event. */ 57 62 static void wnd_close_event(void *arg) 58 63 { … … 61 66 } 62 67 68 /** Handle window keyboard event */ 63 69 static void wnd_kbd_event(void *arg, kbd_event_t *event) 64 70 { … … 66 72 if (event->type == KEY_PRESS) 67 73 quit = true; 74 } 75 76 /** Handle window position event */ 77 static void wnd_pos_event(void *arg, pos_event_t *event) 78 { 79 ui_demo_t *demo = (ui_demo_t *) arg; 80 gfx_rect_t rect1; 81 gfx_rect_t rect2; 82 gfx_coord2_t pos; 83 84 rect1.p0.x = 20; 85 rect1.p0.y = 50; 86 rect1.p1.x = 100; 87 rect1.p1.y = 80; 88 89 rect2.p0.x = 120; 90 rect2.p0.y = 50; 91 rect2.p1.x = 200; 92 rect2.p1.y = 80; 93 94 pos.x = event->hpos; 95 pos.y = event->vpos; 96 97 if (event->type == POS_PRESS) { 98 printf("Button press\n"); 99 100 if (gfx_pix_inside_rect(&pos, &rect1)) { 101 printf("Press button 1\n"); 102 ui_pbutton_press(demo->pb1); 103 (void) ui_pbutton_paint(demo->pb1); 104 } 105 if (gfx_pix_inside_rect(&pos, &rect2)) { 106 printf("Press button 2\n"); 107 ui_pbutton_press(demo->pb2); 108 (void) ui_pbutton_paint(demo->pb2); 109 } 110 } 111 112 if (event->type == POS_RELEASE) { 113 printf("Button release\n"); 114 if (gfx_pix_inside_rect(&pos, &rect1)) { 115 printf("Release button 1\n"); 116 ui_pbutton_release(demo->pb1); 117 (void) ui_pbutton_paint(demo->pb1); 118 } 119 if (gfx_pix_inside_rect(&pos, &rect2)) { 120 printf("Release button 2\n"); 121 ui_pbutton_release(demo->pb2); 122 (void) ui_pbutton_paint(demo->pb2); 123 } 124 } 68 125 } 69 126 … … 76 133 display_window_t *window = NULL; 77 134 ui_resource_t *ui_res; 78 ui_pbutton_t *pb1; 79 ui_pbutton_t *pb2; 135 ui_demo_t demo; 80 136 gfx_rect_t rect; 81 137 errno_t rc; … … 95 151 params.rect.p1.y = 100; 96 152 97 rc = display_window_create(display, ¶ms, &wnd_cb, NULL, &window); 153 rc = display_window_create(display, ¶ms, &wnd_cb, (void *) &demo, 154 &window); 98 155 if (rc != EOK) { 99 156 printf("Error creating window.\n"); … … 112 169 if (rc != EOK) { 113 170 printf("Error creating UI.\n"); 114 return 1;115 } 116 117 rc = ui_pbutton_create(ui_res, "Confirm", & pb1);171 return rc; 172 } 173 174 rc = ui_pbutton_create(ui_res, "Confirm", &demo.pb1); 118 175 if (rc != EOK) { 119 176 printf("Error creating button.\n"); 120 return 1;177 return rc; 121 178 } 122 179 … … 125 182 rect.p1.x = 100; 126 183 rect.p1.y = 80; 127 ui_pbutton_set_rect( pb1, &rect);128 129 rc = ui_pbutton_create(ui_res, "Cancel", & pb2);184 ui_pbutton_set_rect(demo.pb1, &rect); 185 186 rc = ui_pbutton_create(ui_res, "Cancel", &demo.pb2); 130 187 if (rc != EOK) { 131 188 printf("Error creating button.\n"); 132 return 1;189 return rc; 133 190 } 134 191 … … 137 194 rect.p1.x = 200; 138 195 rect.p1.y = 80; 139 ui_pbutton_set_rect( pb2, &rect);140 141 rc = ui_pbutton_paint( pb1);196 ui_pbutton_set_rect(demo.pb2, &rect); 197 198 rc = ui_pbutton_paint(demo.pb1); 142 199 if (rc != EOK) { 143 200 printf("Error painting button.\n"); 144 return 1;145 } 146 147 rc = ui_pbutton_paint( pb2);201 return rc; 202 } 203 204 rc = ui_pbutton_paint(demo.pb2); 148 205 if (rc != EOK) { 149 206 printf("Error painting button.\n"); 150 return 1;207 return rc; 151 208 } 152 209 … … 155 212 } 156 213 157 ui_pbutton_destroy( pb1);158 ui_pbutton_destroy( pb2);214 ui_pbutton_destroy(demo.pb1); 215 ui_pbutton_destroy(demo.pb2); 159 216 160 217 rc = gfx_context_delete(gc);
Note:
See TracChangeset
for help on using the changeset viewer.