Changeset 00e8290 in mainline
- Timestamp:
- 2019-09-23T14:24:09Z (5 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- a3f63ac
- Parents:
- 9be2358
- git-author:
- Jiri Svoboda <jiri@…> (2019-09-22 14:24:05)
- git-committer:
- Jiri Svoboda <jiri@…> (2019-09-23 14:24:09)
- Location:
- uspace
- Files:
-
- 4 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/gfxdemo/gfxdemo.c
r9be2358 r00e8290 33 33 */ 34 34 35 #include <canvas.h> 36 #include <draw/surface.h> 35 37 #include <fibril.h> 38 #include <gfx/backend/canvas.h> 36 39 #include <gfx/backend/console.h> 37 40 #include <gfx/color.h> … … 39 42 #include <io/console.h> 40 43 #include <stdlib.h> 41 42 int main(int argc, char *argv[]) 44 #include <str.h> 45 #include <window.h> 46 47 /** Run rectangle demo on a graphic context. 48 * 49 * @param gc Graphic context 50 */ 51 static errno_t demo_rects(gfx_context_t *gc, int w, int h) 52 { 53 gfx_color_t *color = NULL; 54 gfx_rect_t rect; 55 int i; 56 errno_t rc; 57 58 while (true) { 59 rc = gfx_color_new_rgb_i16(rand() % 0x10000, rand() % 0x10000, 60 rand() % 0x10000, &color); 61 if (rc != EOK) 62 return rc; 63 64 rc = gfx_set_color(gc, color); 65 if (rc != EOK) 66 return rc; 67 68 for (i = 0; i < 10; i++) { 69 rect.p0.x = rand() % (w - 1); 70 rect.p0.y = rand() % (h - 1); 71 rect.p1.x = rect.p0.x + rand() % (w - 1 - rect.p0.x); 72 rect.p1.y = rect.p0.y + rand() % (h - 1 - rect.p0.y); 73 74 rc = gfx_fill_rect(gc, &rect); 75 if (rc != EOK) 76 return rc; 77 } 78 79 gfx_color_delete(color); 80 81 fibril_usleep(500 * 1000); 82 } 83 } 84 85 /** Run demo on console. */ 86 static errno_t demo_console(void) 43 87 { 44 88 console_ctrl_t *con = NULL; 45 gfx_color_t *color = NULL;46 89 console_gc_t *cgc = NULL; 47 90 gfx_context_t *gc; 48 gfx_rect_t rect;49 int i;50 91 errno_t rc; 51 92 … … 53 94 con = console_init(stdin, stdout); 54 95 if (con == NULL) 55 return 1;96 return EIO; 56 97 57 98 printf("Create console GC\n"); 58 99 rc = console_gc_create(con, stdout, &cgc); 59 100 if (rc != EOK) 101 return rc; 102 103 gc = console_gc_get_ctx(cgc); 104 105 rc = demo_rects(gc, 80, 25); 106 if (rc != EOK) 107 return rc; 108 109 rc = console_gc_delete(cgc); 110 if (rc != EOK) 111 return rc; 112 113 return EOK; 114 } 115 116 /** Run demo on canvas. */ 117 static errno_t demo_canvas(void) 118 { 119 console_ctrl_t *con = NULL; 120 canvas_gc_t *cgc = NULL; 121 gfx_context_t *gc; 122 window_t *window = NULL; 123 pixel_t *pixbuf = NULL; 124 surface_t *surface = NULL; 125 canvas_t *canvas = NULL; 126 int vw, vh; 127 errno_t rc; 128 129 printf("Init canvas..\n"); 130 con = console_init(stdin, stdout); 131 if (con == NULL) 132 return EIO; 133 134 window = window_open("comp:0/winreg", NULL, 135 WINDOW_MAIN | WINDOW_DECORATED, "GFX Demo"); 136 if (window == NULL) { 137 printf("Error creating window.\n"); 138 return -1; 139 } 140 141 vw = 400; 142 vh = 300; 143 144 pixbuf = calloc(vw * vh, sizeof(pixel_t)); 145 if (pixbuf == NULL) { 146 printf("Error allocating memory for pixel buffer.\n"); 147 return -1; 148 } 149 150 surface = surface_create(vw, vh, pixbuf, 0); 151 if (surface == NULL) { 152 printf("Error creating surface.\n"); 153 return -1; 154 } 155 156 canvas = create_canvas(window_root(window), NULL, vw, vh, 157 surface); 158 if (canvas == NULL) { 159 printf("Error creating canvas.\n"); 160 return -1; 161 } 162 163 // sig_connect(&canvas->keyboard_event, NULL, wnd_keyboard_event); 164 165 window_resize(window, 0, 0, vw + 10, vh + 30, WINDOW_PLACEMENT_ANY); 166 window_exec(window); 167 168 printf("Create canvas GC\n"); 169 rc = canvas_gc_create(canvas, surface, &cgc); 170 if (rc != EOK) 171 return rc; 172 173 gc = canvas_gc_get_ctx(cgc); 174 175 rc = demo_rects(gc, 400, 300); 176 if (rc != EOK) 177 return rc; 178 179 rc = canvas_gc_delete(cgc); 180 if (rc != EOK) 181 return rc; 182 183 return EOK; 184 } 185 186 static void print_syntax(void) 187 { 188 printf("syntax: gfxdemo {canvas|console}\n"); 189 } 190 191 int main(int argc, char *argv[]) 192 { 193 errno_t rc; 194 195 if (argc < 2) { 196 print_syntax(); 60 197 return 1; 61 62 gc = console_gc_get_ctx(cgc); 63 64 while (true) { 65 rc = gfx_color_new_rgb_i16(rand() % 0x10000, rand() % 0x10000, 66 rand() % 0x10000, &color); 198 } 199 200 if (str_cmp(argv[1], "console") == 0) { 201 rc = demo_console(); 67 202 if (rc != EOK) 68 203 return 1; 69 70 rc = gfx_set_color(gc, color);204 } else if (str_cmp(argv[1], "canvas") == 0) { 205 rc = demo_canvas(); 71 206 if (rc != EOK) 72 207 return 1; 73 74 for (i = 0; i < 10; i++) { 75 rect.p0.x = rand() % 79; 76 rect.p0.y = rand() % 24; 77 rect.p1.x = rect.p0.x + rand() % (79 - rect.p0.x); 78 rect.p1.y = rect.p0.y + rand() % (24 - rect.p0.y); 79 80 rc = gfx_fill_rect(gc, &rect); 81 if (rc != EOK) 82 return 1; 83 } 84 85 gfx_color_delete(color); 86 87 fibril_usleep(500 * 1000); 88 } 89 90 rc = console_gc_delete(cgc); 91 if (rc != EOK) 208 } else { 209 print_syntax(); 92 210 return 1; 93 94 return 0; 211 } 95 212 } 96 213 -
uspace/lib/gfx/meson.build
r9be2358 r00e8290 27 27 # 28 28 29 deps = [ 'gui' ] 29 30 src = files( 31 'src/backend/canvas.c', 30 32 'src/backend/console.c', 31 33 'src/color.c', -
uspace/lib/meson.build
r9be2358 r00e8290 52 52 'fmtutil', 53 53 'fs', 54 'gfx',55 54 'graph', 56 55 'http', … … 83 82 'virtio', 84 83 84 'gfx', 85 85 'ieee80211', 86 86 ]
Note:
See TracChangeset
for help on using the changeset viewer.