Changeset 214aefb in mainline
- Timestamp:
- 2021-04-09T22:41:22Z (4 years ago)
- Branches:
- master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 0262f16c
- Parents:
- b0858150
- git-author:
- Jiri Svoboda <jiri@…> (2021-03-27 22:52:09)
- git-committer:
- jxsvoboda <5887334+jxsvoboda@…> (2021-04-09 22:41:22)
- Location:
- uspace
- Files:
-
- 12 added
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/uidemo/uidemo.c
rb0858150 r214aefb 43 43 #include <ui/image.h> 44 44 #include <ui/label.h> 45 #include <ui/menubar.h> 46 #include <ui/menuentry.h> 47 #include <ui/menu.h> 45 48 #include <ui/pbutton.h> 46 49 #include <ui/resource.h> … … 80 83 .moved = slider_moved 81 84 }; 85 86 static void uidemo_file_exit(ui_menu_entry_t *, void *); 82 87 83 88 /** Window close button was clicked. … … 185 190 } 186 191 192 /** File/exit menu entry selected. 193 * 194 * @param mentry Menu entry 195 * @param arg Argument (demo) 196 */ 197 static void uidemo_file_exit(ui_menu_entry_t *mentry, void *arg) 198 { 199 ui_demo_t *demo = (ui_demo_t *) arg; 200 201 ui_quit(demo->ui); 202 } 203 187 204 /** Run UI demo on display server. */ 188 205 static errno_t ui_demo(const char *display_spec) … … 198 215 gfx_bitmap_t *bitmap; 199 216 gfx_coord2_t off; 217 ui_menu_entry_t *mfoo; 218 ui_menu_entry_t *mbar; 219 ui_menu_entry_t *mfoobar; 220 ui_menu_entry_t *mexit; 221 ui_menu_entry_t *mabout; 200 222 errno_t rc; 201 223 … … 212 234 params.rect.p0.y = 0; 213 235 params.rect.p1.x = 220; 214 params.rect.p1.y = 3 40;236 params.rect.p1.y = 350; 215 237 216 238 memset((void *) &demo, 0, sizeof(demo)); … … 235 257 } 236 258 259 rc = ui_menu_bar_create(ui_res, &demo.mbar); 260 if (rc != EOK) { 261 printf("Error creating menu bar.\n"); 262 return rc; 263 } 264 265 rc = ui_menu_create(demo.mbar, "File", &demo.mfile); 266 if (rc != EOK) { 267 printf("Error creating menu.\n"); 268 return rc; 269 } 270 271 rc = ui_menu_entry_create(demo.mfile, "Foo", &mfoo); 272 if (rc != EOK) { 273 printf("Error creating menu.\n"); 274 return rc; 275 } 276 277 rc = ui_menu_entry_create(demo.mfile, "Bar", &mbar); 278 if (rc != EOK) { 279 printf("Error creating menu.\n"); 280 return rc; 281 } 282 283 rc = ui_menu_entry_create(demo.mfile, "Foobar", &mfoobar); 284 if (rc != EOK) { 285 printf("Error creating menu.\n"); 286 return rc; 287 } 288 289 rc = ui_menu_entry_create(demo.mfile, "Exit", &mexit); 290 if (rc != EOK) { 291 printf("Error creating menu.\n"); 292 return rc; 293 } 294 295 ui_menu_entry_set_cb(mexit, uidemo_file_exit, (void *) &demo); 296 297 rc = ui_menu_create(demo.mbar, "Edit", &demo.medit); 298 if (rc != EOK) { 299 printf("Error creating menu.\n"); 300 return rc; 301 } 302 303 rc = ui_menu_create(demo.mbar, "Preferences", &demo.mpreferences); 304 if (rc != EOK) { 305 printf("Error creating menu.\n"); 306 return rc; 307 } 308 309 rc = ui_menu_create(demo.mbar, "Help", &demo.mhelp); 310 if (rc != EOK) { 311 printf("Error creating menu.\n"); 312 return rc; 313 } 314 315 rc = ui_menu_entry_create(demo.mhelp, "About", &mabout); 316 if (rc != EOK) { 317 printf("Error creating menu.\n"); 318 return rc; 319 } 320 321 rect.p0.x = 4; 322 rect.p0.y = 30; 323 rect.p1.x = 216; 324 rect.p1.y = 52; 325 ui_menu_bar_set_rect(demo.mbar, &rect); 326 327 rc = ui_fixed_add(demo.fixed, ui_menu_bar_ctl(demo.mbar)); 328 if (rc != EOK) { 329 printf("Error adding control to layout.\n"); 330 return rc; 331 } 332 333 rc = ui_entry_create(ui_res, "", &demo.entry); 334 if (rc != EOK) { 335 printf("Error creating entry.\n"); 336 return rc; 337 } 338 339 rect.p0.x = 15; 340 rect.p0.y = 53; 341 rect.p1.x = 205; 342 rect.p1.y = 78; 343 ui_entry_set_rect(demo.entry, &rect); 344 ui_entry_set_halign(demo.entry, gfx_halign_center); 345 346 rc = ui_fixed_add(demo.fixed, ui_entry_ctl(demo.entry)); 347 if (rc != EOK) { 348 printf("Error adding control to layout.\n"); 349 return rc; 350 } 351 237 352 rc = ui_label_create(ui_res, "Text label", &demo.label); 238 353 if (rc != EOK) { … … 242 357 243 358 rect.p0.x = 60; 244 rect.p0.y = 37;359 rect.p0.y = 88; 245 360 rect.p1.x = 160; 246 rect.p1.y = 50;361 rect.p1.y = 101; 247 362 ui_label_set_rect(demo.label, &rect); 248 363 ui_label_set_halign(demo.label, gfx_halign_center); … … 263 378 264 379 rect.p0.x = 15; 265 rect.p0.y = 70;380 rect.p0.y = 111; 266 381 rect.p1.x = 105; 267 rect.p1.y = 98;382 rect.p1.y = 139; 268 383 ui_pbutton_set_rect(demo.pb1, &rect); 269 384 … … 285 400 286 401 rect.p0.x = 115; 287 rect.p0.y = 70;402 rect.p0.y = 111; 288 403 rect.p1.x = 205; 289 rect.p1.y = 98;404 rect.p1.y = 139; 290 405 ui_pbutton_set_rect(demo.pb2, &rect); 291 406 292 407 rc = ui_fixed_add(demo.fixed, ui_pbutton_ctl(demo.pb2)); 293 if (rc != EOK) {294 printf("Error adding control to layout.\n");295 return rc;296 }297 298 rc = ui_entry_create(ui_res, "", &demo.entry);299 if (rc != EOK) {300 printf("Error creating entry.\n");301 return rc;302 }303 304 rect.p0.x = 15;305 rect.p0.y = 110;306 rect.p1.x = 205;307 rect.p1.y = 135;308 ui_entry_set_rect(demo.entry, &rect);309 ui_entry_set_halign(demo.entry, gfx_halign_center);310 311 rc = ui_fixed_add(demo.fixed, ui_entry_ctl(demo.entry));312 408 if (rc != EOK) { 313 409 printf("Error adding control to layout.\n"); … … 336 432 337 433 off.x = 15; 338 off.y = 1 45;434 off.y = 155; 339 435 gfx_rect_translate(&off, &bparams.rect, &rect); 340 436 … … 360 456 361 457 rect.p0.x = 15; 362 rect.p0.y = 1 80;458 rect.p0.y = 190; 363 459 rect.p1.x = 140; 364 rect.p1.y = 2 00;460 rect.p1.y = 210; 365 461 ui_checkbox_set_rect(demo.checkbox, &rect); 366 462 … … 388 484 389 485 rect.p0.x = 15; 390 rect.p0.y = 2 10;486 rect.p0.y = 220; 391 487 rect.p1.x = 140; 392 rect.p1.y = 2 30;488 rect.p1.y = 240; 393 489 ui_rbutton_set_rect(demo.rb1, &rect); 394 490 … … 407 503 408 504 rect.p0.x = 15; 409 rect.p0.y = 2 40;505 rect.p0.y = 250; 410 506 rect.p1.x = 140; 411 rect.p1.y = 2 60;507 rect.p1.y = 270; 412 508 ui_rbutton_set_rect(demo.rb2, &rect); 413 509 … … 426 522 427 523 rect.p0.x = 15; 428 rect.p0.y = 2 70;524 rect.p0.y = 280; 429 525 rect.p1.x = 140; 430 rect.p1.y = 290;526 rect.p1.y = 300; 431 527 ui_rbutton_set_rect(demo.rb3, &rect); 432 528 … … 446 542 447 543 rect.p0.x = 15; 448 rect.p0.y = 3 00;544 rect.p0.y = 310; 449 545 rect.p1.x = 130; 450 rect.p1.y = 3 20;546 rect.p1.y = 330; 451 547 ui_slider_set_rect(demo.slider, &rect); 452 548 -
uspace/app/uidemo/uidemo.h
rb0858150 r214aefb 42 42 #include <ui/fixed.h> 43 43 #include <ui/label.h> 44 #include <ui/menu.h> 45 #include <ui/menubar.h> 44 46 #include <ui/pbutton.h> 45 47 #include <ui/rbutton.h> … … 53 55 ui_window_t *window; 54 56 ui_fixed_t *fixed; 57 ui_menu_bar_t *mbar; 58 ui_menu_t *mfile; 59 ui_menu_t *medit; 60 ui_menu_t *mpreferences; 61 ui_menu_t *mhelp; 55 62 ui_entry_t *entry; 56 63 ui_image_t *image; -
uspace/lib/ui/include/types/ui/rbutton.h
rb0858150 r214aefb 37 37 #define _UI_TYPES_RBUTTON_H 38 38 39 #include <stdbool.h>40 41 39 struct ui_rbutton_group; 42 40 typedef struct ui_rbutton_group ui_rbutton_group_t; -
uspace/lib/ui/include/types/ui/resource.h
rb0858150 r214aefb 40 40 typedef struct ui_resource ui_resource_t; 41 41 42 typedef void (*ui_expose_cb_t)(void *); 43 42 44 #endif 43 45 -
uspace/lib/ui/include/ui/paint.h
rb0858150 r214aefb 47 47 extern errno_t ui_paint_inset_frame(ui_resource_t *, gfx_rect_t *, 48 48 gfx_rect_t *); 49 extern errno_t ui_paint_outset_frame(ui_resource_t *, gfx_rect_t *, 50 gfx_rect_t *); 49 51 extern errno_t ui_paint_filled_circle(gfx_context_t *, gfx_coord2_t *, 50 52 gfx_coord_t, ui_fcircle_part_t); -
uspace/lib/ui/include/ui/resource.h
rb0858150 r214aefb 44 44 extern errno_t ui_resource_create(gfx_context_t *, bool, ui_resource_t **); 45 45 extern void ui_resource_destroy(ui_resource_t *); 46 extern void ui_resource_set_expose_cb(ui_resource_t *, ui_expose_cb_t, 47 void *); 48 extern void ui_resource_expose(ui_resource_t *); 46 49 47 50 #endif -
uspace/lib/ui/meson.build
rb0858150 r214aefb 36 36 'src/image.c', 37 37 'src/label.c', 38 'src/menu.c', 39 'src/menubar.c', 40 'src/menuentry.c', 38 41 'src/paint.c', 39 42 'src/pbutton.c', -
uspace/lib/ui/private/resource.h
rb0858150 r214aefb 43 43 #include <gfx/typeface.h> 44 44 #include <stdbool.h> 45 #include <types/ui/resource.h> 45 46 46 47 /** Actual structure of UI resources. … … 73 74 /** Window text color */ 74 75 gfx_color_t *wnd_text_color; 76 /** Window selected text color */ 77 gfx_color_t *wnd_sel_text_color; 78 /** Window selected text background color */ 79 gfx_color_t *wnd_sel_text_bg_color; 75 80 /** Window frame hightlight color */ 76 81 gfx_color_t *wnd_frame_hi_color; … … 97 102 /** Entry (text entry, checkbox, raido button) active background color */ 98 103 gfx_color_t *entry_act_bg_color; 104 105 /** Expose callback or @c NULL */ 106 ui_expose_cb_t expose_cb; 107 /** Expose callback argument */ 108 void *expose_arg; 99 109 }; 100 110 -
uspace/lib/ui/src/paint.c
rb0858150 r214aefb 149 149 } 150 150 151 /** Paint outset frame. 152 * 153 * @param resource UI resource 154 * @param rect Rectangle to paint onto 155 * @param inside Place to store inside rectangle or @c NULL 156 * @return EOK on success or an error code 157 */ 158 errno_t ui_paint_outset_frame(ui_resource_t *resource, gfx_rect_t *rect, 159 gfx_rect_t *inside) 160 { 161 gfx_rect_t frame; 162 errno_t rc; 163 164 rc = ui_paint_bevel(resource->gc, rect, 165 resource->wnd_frame_hi_color, resource->wnd_frame_sh_color, 166 1, &frame); 167 if (rc != EOK) 168 goto error; 169 170 rc = ui_paint_bevel(resource->gc, &frame, 171 resource->wnd_highlight_color, resource->wnd_shadow_color, 172 1, inside); 173 if (rc != EOK) 174 goto error; 175 176 return EOK; 177 error: 178 return rc; 179 } 180 151 181 /** Paint filled circle vertical scanline. 152 182 * -
uspace/lib/ui/src/resource.c
rb0858150 r214aefb 68 68 gfx_color_t *wnd_face_color = NULL; 69 69 gfx_color_t *wnd_text_color = NULL; 70 gfx_color_t *wnd_sel_text_color = NULL; 71 gfx_color_t *wnd_sel_text_bg_color = NULL; 70 72 gfx_color_t *wnd_frame_hi_color = NULL; 71 73 gfx_color_t *wnd_frame_sh_color = NULL; … … 139 141 goto error; 140 142 143 rc = gfx_color_new_rgb_i16(0xffff, 0xffff, 0xffff, &wnd_sel_text_color); 144 if (rc != EOK) 145 goto error; 146 147 rc = gfx_color_new_rgb_i16(0x5858, 0x6a6a, 0xc4c4, 148 &wnd_sel_text_bg_color); 149 if (rc != EOK) 150 goto error; 151 141 152 rc = gfx_color_new_rgb_i16(0x8888, 0x8888, 0x8888, &wnd_frame_hi_color); 142 153 if (rc != EOK) … … 200 211 resource->wnd_face_color = wnd_face_color; 201 212 resource->wnd_text_color = wnd_text_color; 213 resource->wnd_sel_text_color = wnd_sel_text_color; 214 resource->wnd_sel_text_bg_color = wnd_sel_text_bg_color; 202 215 resource->wnd_frame_hi_color = wnd_frame_hi_color; 203 216 resource->wnd_frame_sh_color = wnd_frame_sh_color; … … 232 245 if (wnd_text_color != NULL) 233 246 gfx_color_delete(wnd_text_color); 247 if (wnd_sel_text_color != NULL) 248 gfx_color_delete(wnd_sel_text_color); 249 if (wnd_sel_text_bg_color != NULL) 250 gfx_color_delete(wnd_sel_text_bg_color); 234 251 if (wnd_frame_hi_color != NULL) 235 252 gfx_color_delete(wnd_frame_hi_color); … … 280 297 gfx_color_delete(resource->wnd_face_color); 281 298 gfx_color_delete(resource->wnd_text_color); 299 gfx_color_delete(resource->wnd_sel_text_color); 300 gfx_color_delete(resource->wnd_sel_text_bg_color); 282 301 gfx_color_delete(resource->wnd_frame_hi_color); 283 302 gfx_color_delete(resource->wnd_frame_sh_color); … … 299 318 } 300 319 320 /** Set UI resource expose callback. 321 * 322 * @param resource Resource 323 * @param cb Callback 324 * @param arg Callback argument 325 */ 326 void ui_resource_set_expose_cb(ui_resource_t *resource, 327 ui_expose_cb_t cb, void *arg) 328 { 329 resource->expose_cb = cb; 330 resource->expose_arg = arg; 331 } 332 333 /** Force UI repaint after an area has been exposed. 334 * 335 * This is called when a popup disappears, which could have exposed some 336 * other UI elements. It causes complete repaint of the UI. 337 * 338 * NOTE Ideally we could specify the exposed rectangle and then limit 339 * the repaint to just that. That would, however, require means of 340 * actually clipping the repaint operation. 341 */ 342 void ui_resource_expose(ui_resource_t *resource) 343 { 344 if (resource->expose_cb != NULL) 345 resource->expose_cb(resource->expose_arg); 346 } 347 301 348 /** @} 302 349 */ -
uspace/lib/ui/src/wdecor.c
rb0858150 r214aefb 178 178 179 179 if ((wdecor->style & ui_wds_frame) != 0) { 180 rc = ui_paint_bevel(wdecor->res->gc, &rect, 181 wdecor->res->wnd_frame_hi_color, 182 wdecor->res->wnd_frame_sh_color, 1, &rect); 183 if (rc != EOK) 184 return rc; 185 186 if (wdecor->res->textmode == false) { 180 181 if (wdecor->res->textmode != false) { 187 182 rc = ui_paint_bevel(wdecor->res->gc, &rect, 188 wdecor->res->wnd_highlight_color, 189 wdecor->res->wnd_shadow_color, 1, &rect); 183 wdecor->res->wnd_frame_hi_color, 184 wdecor->res->wnd_frame_sh_color, 1, &rect); 185 if (rc != EOK) 186 return rc; 187 } else { 188 rc = ui_paint_outset_frame(wdecor->res, &rect, 189 &rect); 190 190 if (rc != EOK) 191 191 return rc; -
uspace/lib/ui/src/window.c
rb0858150 r214aefb 90 90 static void ui_window_app_invalidate(void *, gfx_rect_t *); 91 91 static void ui_window_app_update(void *); 92 static void ui_window_expose_cb(void *); 92 93 93 94 /** Initialize window parameters structure. … … 270 271 ui_wdecor_paint(wdecor); 271 272 273 ui_resource_set_expose_cb(res, ui_window_expose_cb, (void *) window); 274 272 275 window->ui = ui; 273 276 window->dwindow = dwindow; … … 922 925 } 923 926 927 /** Window expose callback. */ 928 static void ui_window_expose_cb(void *arg) 929 { 930 ui_window_t *window = (ui_window_t *) arg; 931 932 ui_window_paint(window); 933 } 934 924 935 /** @} 925 936 */
Note:
See TracChangeset
for help on using the changeset viewer.