Changeset e0545de in mainline for uspace/app/gfxdemo/gfxdemo.c
- Timestamp:
- 2019-10-19T10:07:32Z (5 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- d18f3b7
- Parents:
- dcc4cb31
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/gfxdemo/gfxdemo.c
rdcc4cb31 re0545de 39 39 #include <fibril.h> 40 40 #include <guigfx/canvas.h> 41 #include <gfx/bitmap.h> 41 42 #include <gfx/color.h> 42 43 #include <gfx/render.h> 43 44 #include <io/console.h> 45 #include <io/pixelmap.h> 44 46 #include <stdlib.h> 45 47 #include <str.h> … … 49 51 * 50 52 * @param gc Graphic context 53 * @param w Width 54 * @param h Height 51 55 */ 52 56 static errno_t demo_rects(gfx_context_t *gc, int w, int h) … … 54 58 gfx_color_t *color = NULL; 55 59 gfx_rect_t rect; 56 int i ;57 errno_t rc; 58 59 while (true) {60 int i, j; 61 errno_t rc; 62 63 for (j = 0; j < 10; j++) { 60 64 rc = gfx_color_new_rgb_i16(rand() % 0x10000, rand() % 0x10000, 61 65 rand() % 0x10000, &color); … … 82 86 fibril_usleep(500 * 1000); 83 87 } 88 89 return EOK; 90 } 91 92 /** Run bitmap demo on a graphic context. 93 * 94 * @param gc Graphic context 95 * @param w Width 96 * @param h Height 97 */ 98 static errno_t demo_bitmap(gfx_context_t *gc, int w, int h) 99 { 100 gfx_bitmap_t *bitmap; 101 gfx_bitmap_params_t params; 102 gfx_bitmap_alloc_t alloc; 103 int i, j; 104 gfx_coord2_t offs; 105 gfx_rect_t srect; 106 errno_t rc; 107 pixelmap_t pixelmap; 108 109 params.rect.p0.x = 0; 110 params.rect.p0.y = 0; 111 params.rect.p1.x = w; 112 params.rect.p1.y = h; 113 114 rc = gfx_bitmap_create(gc, ¶ms, NULL, &bitmap); 115 if (rc != EOK) 116 return rc; 117 118 rc = gfx_bitmap_get_alloc(bitmap, &alloc); 119 if (rc != EOK) 120 return rc; 121 122 /* Fill bitmap with something. In absence of anything else, use pixelmap */ 123 pixelmap.width = w; 124 pixelmap.height = h; 125 pixelmap.data = alloc.pixels; 126 127 for (i = 0; i < w; i++) { 128 for (j = 0; j < h; j++) { 129 pixelmap_put_pixel(&pixelmap, i, j, 130 PIXEL(255, (i % 30) < 3 ? 255 : 0, 131 (j % 30) < 3 ? 255 : 0, i / 2)); 132 } 133 } 134 135 for (j = 0; j < 10; j++) { 136 for (i = 0; i < 5; i++) { 137 srect.p0.x = rand() % (w - 40); 138 srect.p0.y = rand() % (h - 40); 139 srect.p1.x = srect.p0.x + rand() % (w - srect.p0.x); 140 srect.p1.y = srect.p0.y + rand() % (h - srect.p0.y); 141 offs.x = rand() % (w - srect.p1.x); 142 offs.y = rand() % (h - srect.p1.y); 143 offs.x = 0; 144 offs.y = 0; 145 146 gfx_bitmap_render(bitmap, &srect, &offs); 147 fibril_usleep(500 * 1000); 148 } 149 } 150 151 gfx_bitmap_destroy(bitmap); 152 153 return EOK; 154 } 155 156 /** Run demo loop on a graphic context. 157 * 158 * @param gc Graphic context 159 * @param w Width 160 * @param h Height 161 */ 162 static errno_t demo_loop(gfx_context_t *gc, int w, int h) 163 { 164 errno_t rc; 165 166 while (true) { 167 rc = demo_rects(gc, w, h); 168 if (rc != EOK) 169 return rc; 170 171 rc = demo_bitmap(gc, w, h); 172 if (rc != EOK) 173 return rc; 174 } 84 175 } 85 176 … … 104 195 gc = console_gc_get_ctx(cgc); 105 196 106 rc = demo_ rects(gc, 80, 25);197 rc = demo_loop(gc, 80, 25); 107 198 if (rc != EOK) 108 199 return rc; … … 168 259 gc = canvas_gc_get_ctx(cgc); 169 260 170 rc = demo_ rects(gc, 400, 300);261 rc = demo_loop(gc, 400, 300); 171 262 if (rc != EOK) 172 263 return rc; … … 206 297 } 207 298 208 rc = demo_ rects(gc, 400, 300);299 rc = demo_loop(gc, 400, 300); 209 300 if (rc != EOK) 210 301 return rc;
Note:
See TracChangeset
for help on using the changeset viewer.