Changeset 1769693 in mainline
- Timestamp:
- 2020-10-19T20:17:11Z (4 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- ba09d06
- Parents:
- de9992c
- Location:
- uspace
- Files:
-
- 5 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/uidemo/uidemo.c
rde9992c r1769693 42 42 #include <ui/pbutton.h> 43 43 #include <ui/resource.h> 44 #include <ui/wdecor.h> 44 45 #include "uidemo.h" 45 46 46 47 static void wnd_close_event(void *); 48 static void wnd_focus_event(void *); 47 49 static void wnd_kbd_event(void *, kbd_event_t *); 48 50 static void wnd_pos_event(void *, pos_event_t *); 51 static void wnd_unfocus_event(void *); 49 52 50 53 static display_wnd_cb_t wnd_cb = { 51 54 .close_event = wnd_close_event, 55 .focus_event = wnd_focus_event, 52 56 .kbd_event = wnd_kbd_event, 53 .pos_event = wnd_pos_event 57 .pos_event = wnd_pos_event, 58 .unfocus_event = wnd_unfocus_event 54 59 }; 55 60 … … 60 65 }; 61 66 67 static void wd_move(ui_wdecor_t *, void *, gfx_coord2_t *); 68 69 static ui_wdecor_cb_t wdecor_cb = { 70 .move = wd_move 71 }; 72 62 73 static bool quit = false; 63 74 … … 73 84 printf("Close event\n"); 74 85 quit = true; 86 } 87 88 /** Handle window focus event. */ 89 static void wnd_focus_event(void *arg) 90 { 91 ui_demo_t *demo = (ui_demo_t *) arg; 92 93 if (demo->wdecor != NULL) { 94 ui_wdecor_set_active(demo->wdecor, true); 95 ui_wdecor_paint(demo->wdecor); 96 } 75 97 } 76 98 … … 88 110 ui_demo_t *demo = (ui_demo_t *) arg; 89 111 112 /* Make sure we don't process events until fully initialized */ 113 if (demo->wdecor == NULL || demo->pb1 == NULL || demo->pb2 == NULL) 114 return; 115 116 ui_wdecor_pos_event(demo->wdecor, event); 90 117 ui_pbutton_pos_event(demo->pb1, event); 91 118 ui_pbutton_pos_event(demo->pb2, event); 119 } 120 121 /** Handle window unfocus event. */ 122 static void wnd_unfocus_event(void *arg) 123 { 124 ui_demo_t *demo = (ui_demo_t *) arg; 125 126 if (demo->wdecor != NULL) { 127 ui_wdecor_set_active(demo->wdecor, false); 128 ui_wdecor_paint(demo->wdecor); 129 } 92 130 } 93 131 … … 106 144 printf("Clicked 'Cancel' button\n"); 107 145 } 146 } 147 148 /** Window decoration requested window move. 149 * 150 * @param wdecor Window decoration 151 * @param arg Argument (demo) 152 * @param pos Position where the title bar was pressed 153 */ 154 static void wd_move(ui_wdecor_t *wdecor, void *arg, gfx_coord2_t *pos) 155 { 156 ui_demo_t *demo = (ui_demo_t *) arg; 157 158 (void) display_window_move_req(demo->dwindow, pos); 108 159 } 109 160 … … 135 186 params.rect.p1.y = 100; 136 187 188 memset((void *) &demo, 0, sizeof(demo)); 189 137 190 rc = display_window_create(display, ¶ms, &wnd_cb, (void *) &demo, 138 191 &window); … … 142 195 } 143 196 197 demo.dwindow = window; 198 144 199 rc = display_window_get_gc(window, &gc); 145 200 if (rc != EOK) { … … 155 210 return rc; 156 211 } 212 213 printf("Create window decoration\n"); 214 rc = ui_wdecor_create(ui_res, "UI Demo", &demo.wdecor); 215 if (rc != EOK) { 216 printf("Error creating window decoration.\n"); 217 return rc; 218 } 219 220 ui_wdecor_set_rect(demo.wdecor, ¶ms.rect); 221 ui_wdecor_set_cb(demo.wdecor, &wdecor_cb, (void *) &demo); 157 222 158 223 rc = ui_pbutton_create(ui_res, "Confirm", &demo.pb1); … … 207 272 color = NULL; 208 273 274 rc = ui_wdecor_paint(demo.wdecor); 275 if (rc != EOK) { 276 printf("Error painting window decoration.\n"); 277 return rc; 278 } 279 209 280 rc = ui_pbutton_paint(demo.pb1); 210 281 if (rc != EOK) { … … 223 294 } 224 295 296 ui_wdecor_destroy(demo.wdecor); 225 297 ui_pbutton_destroy(demo.pb1); 226 298 ui_pbutton_destroy(demo.pb2); -
uspace/app/uidemo/uidemo.h
rde9992c r1769693 37 37 #define UIDEMO_H 38 38 39 #include <display.h> 40 #include <ui/pbutton.h> 41 #include <ui/wdecor.h> 42 39 43 /** User interface demo */ 40 44 typedef struct { 45 display_window_t *dwindow; 46 ui_wdecor_t *wdecor; 41 47 ui_pbutton_t *pb1; 42 48 ui_pbutton_t *pb2; -
uspace/lib/ui/meson.build
rde9992c r1769693 32 32 'src/pbutton.c', 33 33 'src/resource.c', 34 'src/wdecor.c' 34 35 ) 35 36 … … 39 40 'test/pbutton.c', 40 41 'test/resource.c', 42 'test/wdecor.c', 41 43 ) -
uspace/lib/ui/private/pbutton.h
rde9992c r1769693 38 38 #define _UI_PRIVATE_PBUTTON_H 39 39 40 #include <gfx/context.h>41 40 #include <gfx/coord.h> 42 41 #include <stdbool.h> -
uspace/lib/ui/private/resource.h
rde9992c r1769693 65 65 /** Button shadow color */ 66 66 gfx_color_t *btn_shadow_color; 67 68 /** Window face color */ 69 gfx_color_t *wnd_face_color; 70 /** Window text color */ 71 gfx_color_t *wnd_text_color; 72 /** Window frame hightlight color */ 73 gfx_color_t *wnd_frame_hi_color; 74 /** Window frame shadow color */ 75 gfx_color_t *wnd_frame_sh_color; 76 /** Window highlight color */ 77 gfx_color_t *wnd_highlight_color; 78 /** Window shadow color */ 79 gfx_color_t *wnd_shadow_color; 80 81 /** Active titlebar background color */ 82 gfx_color_t *tbar_act_bg_color; 83 /** Active titlebar text color */ 84 gfx_color_t *tbar_act_text_color; 85 /** Inactive titlebar background color */ 86 gfx_color_t *tbar_inact_bg_color; 87 /** Inactive titlebar text color */ 88 gfx_color_t *tbar_inact_text_color; 67 89 }; 68 90 -
uspace/lib/ui/src/resource.c
rde9992c r1769693 64 64 gfx_color_t *btn_highlight_color = NULL; 65 65 gfx_color_t *btn_shadow_color = NULL; 66 gfx_color_t *wnd_face_color = NULL; 67 gfx_color_t *wnd_text_color = NULL; 68 gfx_color_t *wnd_frame_hi_color = NULL; 69 gfx_color_t *wnd_frame_sh_color = NULL; 70 gfx_color_t *wnd_highlight_color = NULL; 71 gfx_color_t *wnd_shadow_color = NULL; 72 gfx_color_t *tbar_act_bg_color = NULL; 73 gfx_color_t *tbar_inact_bg_color = NULL; 74 gfx_color_t *tbar_act_text_color = NULL; 75 gfx_color_t *tbar_inact_text_color = NULL; 66 76 errno_t rc; 67 77 … … 105 115 goto error; 106 116 117 rc = gfx_color_new_rgb_i16(0xc8c8, 0xc8c8, 0xc8c8, &wnd_face_color); 118 if (rc != EOK) 119 goto error; 120 121 rc = gfx_color_new_rgb_i16(0, 0, 0, &wnd_text_color); 122 if (rc != EOK) 123 goto error; 124 125 rc = gfx_color_new_rgb_i16(0x8888, 0x8888, 0x8888, &wnd_frame_hi_color); 126 if (rc != EOK) 127 goto error; 128 129 rc = gfx_color_new_rgb_i16(0, 0, 0, &wnd_frame_sh_color); 130 if (rc != EOK) 131 goto error; 132 133 rc = gfx_color_new_rgb_i16(0xffff, 0xffff, 0xffff, 134 &wnd_highlight_color); 135 if (rc != EOK) 136 goto error; 137 138 rc = gfx_color_new_rgb_i16(0x8888, 0x8888, 0x8888, &wnd_shadow_color); 139 if (rc != EOK) 140 goto error; 141 142 rc = gfx_color_new_rgb_i16(0x5858, 0x6a6a, 0xc4c4, &tbar_act_bg_color); 143 if (rc != EOK) 144 goto error; 145 146 rc = gfx_color_new_rgb_i16(0xffff, 0xffff, 0xffff, 147 &tbar_act_text_color); 148 if (rc != EOK) 149 goto error; 150 151 rc = gfx_color_new_rgb_i16(0xdddd, 0xdddd, 0xdddd, 152 &tbar_inact_bg_color); 153 if (rc != EOK) 154 goto error; 155 156 rc = gfx_color_new_rgb_i16(0x5858, 0x5858, 0x5858, 157 &tbar_inact_text_color); 158 if (rc != EOK) 159 goto error; 160 107 161 resource->gc = gc; 108 162 resource->tface = tface; 109 163 resource->font = font; 164 110 165 resource->btn_frame_color = btn_frame_color; 111 166 resource->btn_face_color = btn_face_color; … … 113 168 resource->btn_highlight_color = btn_highlight_color; 114 169 resource->btn_shadow_color = btn_shadow_color; 170 171 resource->wnd_face_color = wnd_face_color; 172 resource->wnd_text_color = wnd_text_color; 173 resource->wnd_frame_hi_color = wnd_frame_hi_color; 174 resource->wnd_frame_sh_color = wnd_frame_sh_color; 175 resource->wnd_highlight_color = wnd_highlight_color; 176 resource->wnd_shadow_color = wnd_shadow_color; 177 178 resource->tbar_act_bg_color = tbar_act_bg_color; 179 resource->tbar_act_text_color = tbar_act_text_color; 180 resource->tbar_inact_bg_color = tbar_inact_bg_color; 181 resource->tbar_inact_text_color = tbar_inact_text_color; 182 115 183 *rresource = resource; 116 184 return EOK; … … 126 194 if (btn_shadow_color != NULL) 127 195 gfx_color_delete(btn_shadow_color); 196 197 if (wnd_face_color != NULL) 198 gfx_color_delete(wnd_face_color); 199 if (wnd_text_color != NULL) 200 gfx_color_delete(wnd_text_color); 201 if (wnd_frame_hi_color != NULL) 202 gfx_color_delete(wnd_frame_hi_color); 203 if (wnd_frame_sh_color != NULL) 204 gfx_color_delete(wnd_frame_sh_color); 205 if (wnd_highlight_color != NULL) 206 gfx_color_delete(wnd_highlight_color); 207 if (wnd_shadow_color != NULL) 208 gfx_color_delete(wnd_shadow_color); 209 210 if (tbar_act_bg_color != NULL) 211 gfx_color_delete(tbar_act_bg_color); 212 if (tbar_act_text_color != NULL) 213 gfx_color_delete(tbar_act_text_color); 214 if (tbar_inact_bg_color != NULL) 215 gfx_color_delete(tbar_inact_bg_color); 216 if (tbar_inact_text_color != NULL) 217 gfx_color_delete(tbar_inact_text_color); 218 128 219 if (tface != NULL) 129 220 gfx_typeface_destroy(tface); … … 147 238 gfx_color_delete(resource->btn_shadow_color); 148 239 240 gfx_color_delete(resource->wnd_face_color); 241 gfx_color_delete(resource->wnd_text_color); 242 gfx_color_delete(resource->wnd_frame_hi_color); 243 gfx_color_delete(resource->wnd_frame_sh_color); 244 gfx_color_delete(resource->wnd_highlight_color); 245 gfx_color_delete(resource->wnd_shadow_color); 246 247 gfx_color_delete(resource->tbar_act_bg_color); 248 gfx_color_delete(resource->tbar_act_text_color); 249 gfx_color_delete(resource->tbar_inact_bg_color); 250 gfx_color_delete(resource->tbar_inact_text_color); 251 149 252 gfx_font_close(resource->font); 150 253 gfx_typeface_destroy(resource->tface); -
uspace/lib/ui/test/main.c
rde9992c r1769693 34 34 PCUT_IMPORT(pbutton); 35 35 PCUT_IMPORT(resource); 36 PCUT_IMPORT(wdecor); 36 37 37 38 PCUT_MAIN();
Note:
See TracChangeset
for help on using the changeset viewer.