Changeset d8ddf7a in mainline for uspace/app/uidemo/uidemo.c
- 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
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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;
Note:
See TracChangeset
for help on using the changeset viewer.