Changeset f6df5a3 in mainline
- 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
- Location:
- uspace
- Files:
-
- 1 added
- 4 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); -
uspace/lib/ui/include/ui/pbutton.h
r47728678 rf6df5a3 47 47 extern void ui_pbutton_set_rect(ui_pbutton_t *, gfx_rect_t *); 48 48 extern errno_t ui_pbutton_paint(ui_pbutton_t *); 49 extern void ui_pbutton_press(ui_pbutton_t *); 50 extern void ui_pbutton_release(ui_pbutton_t *); 49 51 50 52 #endif -
uspace/lib/ui/private/pbutton.h
r47728678 rf6df5a3 40 40 #include <gfx/context.h> 41 41 #include <gfx/coord.h> 42 #include <stdbool.h> 42 43 43 44 /** Actual structure of push button. … … 52 53 /** Caption */ 53 54 const char *caption; 55 /** Button is currently held down */ 56 bool held; 54 57 }; 55 58 -
uspace/lib/ui/src/pbutton.c
r47728678 rf6df5a3 44 44 #include "../private/pbutton.h" 45 45 #include "../private/resource.h" 46 47 /** Caption movement when button is pressed down */ 48 enum { 49 ui_pb_press_dx = 2, 50 ui_pb_press_dy = 2 51 }; 46 52 47 53 /** Create new push button. … … 106 112 errno_t rc; 107 113 108 rc = gfx_color_new_rgb_i16(0xc8c8, 0xc8c8, 0xc8c8, &color); 109 if (rc != EOK) 110 goto error; 114 if (pbutton->held) { 115 rc = gfx_color_new_rgb_i16(0x8000, 0, 0, &color); 116 if (rc != EOK) 117 goto error; 118 } else { 119 rc = gfx_color_new_rgb_i16(0xc8c8, 0xc8c8, 0xc8c8, &color); 120 if (rc != EOK) 121 goto error; 122 } 111 123 112 124 rc = gfx_set_color(pbutton->res->gc, color); … … 132 144 pos.y = (pbutton->rect.p0.y + pbutton->rect.p1.y) / 2; 133 145 146 if (pbutton->held) { 147 pos.x += ui_pb_press_dx; 148 pos.y += ui_pb_press_dy; 149 } 150 134 151 gfx_text_fmt_init(&fmt); 135 152 fmt.halign = gfx_halign_center; … … 149 166 } 150 167 168 /** Press down button. 169 * 170 * This does not automatically repaint the button. 171 * 172 * @param pbutton Push button 173 */ 174 void ui_pbutton_press(ui_pbutton_t *pbutton) 175 { 176 pbutton->held = true; 177 } 178 179 /** Release button. 180 * 181 * This does not automatically repaint the button. 182 * 183 * @param pbutton Push button 184 */ 185 void ui_pbutton_release(ui_pbutton_t *pbutton) 186 { 187 pbutton->held = false; 188 } 189 151 190 /** @} 152 191 */
Note:
See TracChangeset
for help on using the changeset viewer.