Changeset d8ddf7a in mainline
- Timestamp:
- 2020-11-22T17:52:37Z (4 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 2d879f7
- Parents:
- 4f64b7b8
- Location:
- uspace
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/launcher/launcher.c
r4f64b7b8 rd8ddf7a 228 228 } 229 229 230 off.x = 5;230 off.x = 6; 231 231 off.y = 32; 232 232 gfx_rect_translate(&off, &logo_rect, &rect); 233 234 /* Adjust for frame width (2 x 1 pixel) */ 235 rect.p1.x += 2; 236 rect.p1.y += 2; 233 237 ui_image_set_rect(launcher.image, &rect); 238 ui_image_set_flags(launcher.image, ui_imgf_frame); 234 239 235 240 rc = ui_fixed_add(launcher.fixed, ui_image_ctl(launcher.image)); … … 238 243 return rc; 239 244 } 245 240 246 rc = ui_label_create(ui_res, "Launch application", &launcher.label); 241 247 if (rc != EOK) { -
uspace/app/uidemo/uidemo.c
r4f64b7b8 rd8ddf7a 33 33 */ 34 34 35 #include <gfx/bitmap.h> 35 36 #include <gfx/coord.h> 37 #include <io/pixelmap.h> 36 38 #include <stdio.h> 37 39 #include <str.h> 40 #include <ui/entry.h> 38 41 #include <ui/fixed.h> 42 #include <ui/image.h> 39 43 #include <ui/label.h> 40 44 #include <ui/pbutton.h> … … 44 48 #include "uidemo.h" 45 49 50 static errno_t bitmap_moire(gfx_bitmap_t *, gfx_coord_t, gfx_coord_t); 51 46 52 static void wnd_close(ui_window_t *, void *); 47 53 … … 79 85 80 86 if (pbutton == demo->pb1) { 81 rc = ui_ label_set_text(demo->label, "Confirmed");87 rc = ui_entry_set_text(demo->entry, "OK pressed"); 82 88 if (rc != EOK) 83 printf("Error changing labeltext.\n");84 (void) ui_ label_paint(demo->label);89 printf("Error changing entry text.\n"); 90 (void) ui_entry_paint(demo->entry); 85 91 } else { 86 rc = ui_ label_set_text(demo->label, "Cancelled");92 rc = ui_entry_set_text(demo->entry, "Cancel pressed"); 87 93 if (rc != EOK) 88 printf("Error changing labeltext.\n");89 (void) ui_ label_paint(demo->label);94 printf("Error changing entry text.\n"); 95 (void) ui_entry_paint(demo->entry); 90 96 } 91 97 } … … 99 105 ui_demo_t demo; 100 106 gfx_rect_t rect; 107 gfx_context_t *gc; 101 108 ui_resource_t *ui_res; 109 gfx_bitmap_params_t bparams; 110 gfx_bitmap_t *bitmap; 111 gfx_coord2_t off; 102 112 errno_t rc; 103 113 … … 113 123 params.rect.p0.y = 0; 114 124 params.rect.p1.x = 220; 115 params.rect.p1.y = 1 00;125 params.rect.p1.y = 180; 116 126 117 127 memset((void *) &demo, 0, sizeof(demo)); … … 128 138 129 139 ui_res = ui_window_get_res(window); 140 gc = ui_window_get_gc(window); 130 141 131 142 rc = ui_fixed_create(&demo.fixed); … … 135 146 } 136 147 137 rc = ui_label_create(ui_res, " Hello there!", &demo.label);148 rc = ui_label_create(ui_res, "Text label", &demo.label); 138 149 if (rc != EOK) { 139 150 printf("Error creating label.\n"); … … 154 165 } 155 166 156 rc = ui_pbutton_create(ui_res, " Confirm", &demo.pb1);167 rc = ui_pbutton_create(ui_res, "OK", &demo.pb1); 157 168 if (rc != EOK) { 158 169 printf("Error creating button.\n"); … … 163 174 164 175 rect.p0.x = 15; 165 rect.p0.y = 60;176 rect.p0.y = 70; 166 177 rect.p1.x = 105; 167 rect.p1.y = 88;178 rect.p1.y = 98; 168 179 ui_pbutton_set_rect(demo.pb1, &rect); 169 180 … … 185 196 186 197 rect.p0.x = 115; 187 rect.p0.y = 60;198 rect.p0.y = 70; 188 199 rect.p1.x = 205; 189 rect.p1.y = 88;200 rect.p1.y = 98; 190 201 ui_pbutton_set_rect(demo.pb2, &rect); 191 202 192 203 rc = ui_fixed_add(demo.fixed, ui_pbutton_ctl(demo.pb2)); 204 if (rc != EOK) { 205 printf("Error adding control to layout.\n"); 206 return rc; 207 } 208 209 rc = ui_entry_create(ui_res, "", &demo.entry); 210 if (rc != EOK) { 211 printf("Error creating entry.\n"); 212 return rc; 213 } 214 215 rect.p0.x = 15; 216 rect.p0.y = 110; 217 rect.p1.x = 205; 218 rect.p1.y = 135; 219 ui_entry_set_rect(demo.entry, &rect); 220 ui_entry_set_halign(demo.entry, gfx_halign_center); 221 222 rc = ui_fixed_add(demo.fixed, ui_entry_ctl(demo.entry)); 223 if (rc != EOK) { 224 printf("Error adding control to layout.\n"); 225 return rc; 226 } 227 228 gfx_bitmap_params_init(&bparams); 229 bparams.rect.p0.x = 0; 230 bparams.rect.p0.y = 0; 231 bparams.rect.p1.x = 188; 232 bparams.rect.p1.y = 24; 233 234 rc = gfx_bitmap_create(gc, &bparams, NULL, &bitmap); 235 if (rc != EOK) 236 return rc; 237 238 rc = bitmap_moire(bitmap, bparams.rect.p1.x, bparams.rect.p1.y); 239 if (rc != EOK) 240 return rc; 241 242 rc = ui_image_create(ui_res, bitmap, ¶ms.rect, &demo.image); 243 if (rc != EOK) { 244 printf("Error creating label.\n"); 245 return rc; 246 } 247 248 off.x = 15; 249 off.y = 145; 250 gfx_rect_translate(&off, &bparams.rect, &rect); 251 252 /* Adjust for frame width (2 x 1 pixel) */ 253 rect.p1.x += 2; 254 rect.p1.y += 2; 255 ui_image_set_rect(demo.image, &rect); 256 ui_image_set_flags(demo.image, ui_imgf_frame); 257 258 rc = ui_fixed_add(demo.fixed, ui_image_ctl(demo.image)); 193 259 if (rc != EOK) { 194 260 printf("Error adding control to layout.\n"); … … 208 274 ui_window_destroy(window); 209 275 ui_destroy(ui); 276 277 return EOK; 278 } 279 280 /** Fill bitmap with moire pattern. 281 * 282 * @param bitmap Bitmap 283 * @param w Bitmap width 284 * @param h Bitmap height 285 * @return EOK on success or an error code 286 */ 287 static errno_t bitmap_moire(gfx_bitmap_t *bitmap, gfx_coord_t w, gfx_coord_t h) 288 { 289 int i, j; 290 int k; 291 pixelmap_t pixelmap; 292 gfx_bitmap_alloc_t alloc; 293 errno_t rc; 294 295 rc = gfx_bitmap_get_alloc(bitmap, &alloc); 296 if (rc != EOK) 297 return rc; 298 299 /* In absence of anything else, use pixelmap */ 300 pixelmap.width = w; 301 pixelmap.height = h; 302 pixelmap.data = alloc.pixels; 303 304 for (i = 0; i < w; i++) { 305 for (j = 0; j < h; j++) { 306 k = i * i + j * j; 307 pixelmap_put_pixel(&pixelmap, i, j, 308 PIXEL(255, k, k, 255 - k)); 309 } 310 } 210 311 211 312 return EOK; -
uspace/app/uidemo/uidemo.h
r4f64b7b8 rd8ddf7a 38 38 39 39 #include <display.h> 40 #include <ui/entry.h> 40 41 #include <ui/fixed.h> 41 42 #include <ui/label.h> … … 49 50 ui_window_t *window; 50 51 ui_fixed_t *fixed; 52 ui_entry_t *entry; 53 ui_image_t *image; 51 54 ui_label_t *label; 52 55 ui_pbutton_t *pb1; -
uspace/lib/ui/include/types/ui/image.h
r4f64b7b8 rd8ddf7a 40 40 typedef struct ui_image ui_image_t; 41 41 42 /** UI image flags */ 43 typedef enum { 44 /** Draw a frame around the image */ 45 ui_imgf_frame = 0x1 46 } ui_image_flags_t; 47 42 48 #endif 43 49 -
uspace/lib/ui/include/ui/image.h
r4f64b7b8 rd8ddf7a 50 50 extern void ui_image_set_bmp(ui_image_t *, gfx_bitmap_t *, gfx_rect_t *); 51 51 extern void ui_image_set_rect(ui_image_t *, gfx_rect_t *); 52 extern void ui_image_set_flags(ui_image_t *, ui_image_flags_t); 52 53 extern errno_t ui_image_paint(ui_image_t *); 53 54 -
uspace/lib/ui/private/image.h
r4f64b7b8 rd8ddf7a 52 52 /** Image rectangle */ 53 53 gfx_rect_t rect; 54 /** Flags */ 55 ui_image_flags_t flags; 54 56 /** Bitmap */ 55 57 gfx_bitmap_t *bitmap; 58 /** Bitmap rectangle */ 56 59 gfx_rect_t brect; 57 60 }; -
uspace/lib/ui/src/image.c
r4f64b7b8 rd8ddf7a 124 124 } 125 125 126 /** Set image flags. 127 * 128 * @param image Image 129 * @param flags Flags 130 */ 131 void ui_image_set_flags(ui_image_t *image, ui_image_flags_t flags) 132 { 133 image->flags = flags; 134 } 135 126 136 /** Paint image. 127 137 * … … 131 141 errno_t ui_image_paint(ui_image_t *image) 132 142 { 143 gfx_rect_t irect; 133 144 gfx_rect_t srect; 134 145 gfx_coord2_t offs; 146 errno_t rc; 147 148 if ((image->flags & ui_imgf_frame) != 0) { 149 rc = ui_paint_bevel(image->res->gc, &image->rect, 150 image->res->btn_frame_color, image->res->btn_frame_color, 151 1, NULL); 152 if (rc != EOK) 153 return rc; 154 } 135 155 136 156 if (image->bitmap == NULL) 137 157 return EOK; 158 159 irect = image->rect; 160 if ((image->flags & ui_imgf_frame) != 0) { 161 irect.p0.x++; 162 irect.p0.y++; 163 irect.p1.x--; 164 irect.p1.y--; 165 } 138 166 139 167 /* … … 141 169 * we need to subtract it. 142 170 */ 143 offs.x = i mage->rect.p0.x - image->brect.p0.x;144 offs.y = i mage->rect.p0.y - image->brect.p0.y;171 offs.x = irect.p0.x - image->brect.p0.x; 172 offs.y = irect.p0.y - image->brect.p0.y; 145 173 146 174 /* 147 * Trans alte image rectangle back to bitmap coordinate space.175 * Translate image rectangle back to bitmap coordinate space. 148 176 * Thus the bitmap will be clipped to the image rectangle. 149 177 */ 150 gfx_rect_rtranslate(&offs, &i mage->rect, &srect);178 gfx_rect_rtranslate(&offs, &irect, &srect); 151 179 return gfx_bitmap_render(image->bitmap, &srect, &offs); 180 152 181 } 153 182 -
uspace/lib/ui/test/image.c
r4f64b7b8 rd8ddf7a 110 110 } 111 111 112 /** Set image flags sets internal field */ 113 PCUT_TEST(set_flags) 114 { 115 ui_image_t *image = NULL; 116 gfx_rect_t brect; 117 errno_t rc; 118 119 rc = ui_image_create(NULL, NULL, &brect, &image); 120 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 121 PCUT_ASSERT_NOT_NULL(image); 122 123 PCUT_ASSERT_INT_EQUALS(0, image->flags); 124 125 ui_image_set_flags(image, ui_imgf_frame); 126 PCUT_ASSERT_INT_EQUALS(ui_imgf_frame, image->flags); 127 128 ui_image_destroy(image); 129 } 130 112 131 /** Set image bitmap */ 113 132 PCUT_TEST(set_bmp)
Note:
See TracChangeset
for help on using the changeset viewer.