[045186b] | 1 | /*
|
---|
[fd11144] | 2 | * Copyright (c) 2020 Jiri Svoboda
|
---|
[045186b] | 3 | * All rights reserved.
|
---|
| 4 | *
|
---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
---|
| 6 | * modification, are permitted provided that the following conditions
|
---|
| 7 | * are met:
|
---|
| 8 | *
|
---|
| 9 | * - Redistributions of source code must retain the above copyright
|
---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 13 | * documentation and/or other materials provided with the distribution.
|
---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
---|
| 15 | * derived from this software without specific prior written permission.
|
---|
| 16 | *
|
---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 27 | */
|
---|
| 28 |
|
---|
| 29 | /** @addtogroup gfxdemo
|
---|
| 30 | * @{
|
---|
| 31 | */
|
---|
| 32 | /** @file Graphic demo
|
---|
| 33 | */
|
---|
| 34 |
|
---|
[a3f63ac] | 35 | #include <congfx/console.h>
|
---|
[c8cf261] | 36 | #include <display.h>
|
---|
[9259d20] | 37 | #include <fibril.h>
|
---|
[e0545de] | 38 | #include <gfx/bitmap.h>
|
---|
[045186b] | 39 | #include <gfx/color.h>
|
---|
| 40 | #include <gfx/render.h>
|
---|
[8fa65af0] | 41 | #include <gfx/font.h>
|
---|
| 42 | #include <gfx/text.h>
|
---|
| 43 | #include <gfx/typeface.h>
|
---|
[9259d20] | 44 | #include <io/console.h>
|
---|
[e0545de] | 45 | #include <io/pixelmap.h>
|
---|
[b3c185b6] | 46 | #include <stdbool.h>
|
---|
[9259d20] | 47 | #include <stdlib.h>
|
---|
[00e8290] | 48 | #include <str.h>
|
---|
[5bded44] | 49 | #include <task.h>
|
---|
[b93ec7c0] | 50 | #include <ui/ui.h>
|
---|
| 51 | #include <ui/window.h>
|
---|
| 52 | #include <ui/wdecor.h>
|
---|
[045186b] | 53 |
|
---|
[338d0935] | 54 | static void wnd_close_event(void *);
|
---|
[b3c185b6] | 55 | static void wnd_kbd_event(void *, kbd_event_t *);
|
---|
| 56 |
|
---|
| 57 | static display_wnd_cb_t wnd_cb = {
|
---|
[338d0935] | 58 | .close_event = wnd_close_event,
|
---|
[b3c185b6] | 59 | .kbd_event = wnd_kbd_event
|
---|
| 60 | };
|
---|
| 61 |
|
---|
[b93ec7c0] | 62 | static void uiwnd_close_event(ui_window_t *, void *);
|
---|
| 63 | static void uiwnd_kbd_event(ui_window_t *, void *, kbd_event_t *);
|
---|
| 64 |
|
---|
| 65 | static ui_window_cb_t ui_window_cb = {
|
---|
| 66 | .close = uiwnd_close_event,
|
---|
| 67 | .kbd = uiwnd_kbd_event
|
---|
| 68 | };
|
---|
| 69 |
|
---|
[b3c185b6] | 70 | static bool quit = false;
|
---|
| 71 |
|
---|
[587b4cb] | 72 | /** Clear screen.
|
---|
| 73 | *
|
---|
| 74 | * @param gc Graphic context
|
---|
| 75 | * @param w Screen width
|
---|
| 76 | * @param h Screen height
|
---|
| 77 | */
|
---|
| 78 | static errno_t clear_scr(gfx_context_t *gc, gfx_coord_t w, gfx_coord_t h)
|
---|
| 79 | {
|
---|
| 80 | gfx_color_t *color = NULL;
|
---|
| 81 | gfx_rect_t rect;
|
---|
| 82 | errno_t rc;
|
---|
| 83 |
|
---|
| 84 | rc = gfx_color_new_rgb_i16(0, 0, 0, &color);
|
---|
| 85 | if (rc != EOK)
|
---|
| 86 | goto error;
|
---|
| 87 |
|
---|
| 88 | rc = gfx_set_color(gc, color);
|
---|
| 89 | if (rc != EOK)
|
---|
| 90 | goto error;
|
---|
| 91 |
|
---|
| 92 | rect.p0.x = 0;
|
---|
| 93 | rect.p0.y = 0;
|
---|
| 94 | rect.p1.x = w;
|
---|
| 95 | rect.p1.y = h;
|
---|
| 96 |
|
---|
| 97 | rc = gfx_fill_rect(gc, &rect);
|
---|
| 98 | if (rc != EOK)
|
---|
| 99 | goto error;
|
---|
| 100 |
|
---|
| 101 | gfx_color_delete(color);
|
---|
| 102 | return EOK;
|
---|
| 103 | error:
|
---|
| 104 | if (color != NULL)
|
---|
| 105 | gfx_color_delete(color);
|
---|
| 106 | return rc;
|
---|
| 107 | }
|
---|
| 108 |
|
---|
[00e8290] | 109 | /** Run rectangle demo on a graphic context.
|
---|
| 110 | *
|
---|
| 111 | * @param gc Graphic context
|
---|
[e0545de] | 112 | * @param w Width
|
---|
| 113 | * @param h Height
|
---|
[00e8290] | 114 | */
|
---|
[1822545] | 115 | static errno_t demo_rects(gfx_context_t *gc, gfx_coord_t w, gfx_coord_t h)
|
---|
[045186b] | 116 | {
|
---|
[9259d20] | 117 | gfx_color_t *color = NULL;
|
---|
| 118 | gfx_rect_t rect;
|
---|
[e0545de] | 119 | int i, j;
|
---|
[9259d20] | 120 | errno_t rc;
|
---|
| 121 |
|
---|
[4f64b7b8] | 122 | if (quit)
|
---|
| 123 | return EOK;
|
---|
| 124 |
|
---|
[587b4cb] | 125 | rc = clear_scr(gc, w, h);
|
---|
| 126 | if (rc != EOK)
|
---|
| 127 | return rc;
|
---|
| 128 |
|
---|
[e0545de] | 129 | for (j = 0; j < 10; j++) {
|
---|
[9259d20] | 130 | rc = gfx_color_new_rgb_i16(rand() % 0x10000, rand() % 0x10000,
|
---|
| 131 | rand() % 0x10000, &color);
|
---|
| 132 | if (rc != EOK)
|
---|
[00e8290] | 133 | return rc;
|
---|
[9259d20] | 134 |
|
---|
| 135 | rc = gfx_set_color(gc, color);
|
---|
| 136 | if (rc != EOK)
|
---|
[00e8290] | 137 | return rc;
|
---|
[9259d20] | 138 |
|
---|
| 139 | for (i = 0; i < 10; i++) {
|
---|
[00e8290] | 140 | rect.p0.x = rand() % (w - 1);
|
---|
| 141 | rect.p0.y = rand() % (h - 1);
|
---|
| 142 | rect.p1.x = rect.p0.x + rand() % (w - 1 - rect.p0.x);
|
---|
| 143 | rect.p1.y = rect.p0.y + rand() % (h - 1 - rect.p0.y);
|
---|
[9259d20] | 144 |
|
---|
| 145 | rc = gfx_fill_rect(gc, &rect);
|
---|
| 146 | if (rc != EOK)
|
---|
[00e8290] | 147 | return rc;
|
---|
[9259d20] | 148 | }
|
---|
| 149 |
|
---|
| 150 | gfx_color_delete(color);
|
---|
| 151 |
|
---|
| 152 | fibril_usleep(500 * 1000);
|
---|
[b3c185b6] | 153 |
|
---|
| 154 | if (quit)
|
---|
| 155 | break;
|
---|
[9259d20] | 156 | }
|
---|
[e0545de] | 157 |
|
---|
| 158 | return EOK;
|
---|
| 159 | }
|
---|
| 160 |
|
---|
[587b4cb] | 161 | /** Fill bitmap with tartan pattern.
|
---|
| 162 | *
|
---|
| 163 | * @param bitmap Bitmap
|
---|
| 164 | * @param w Bitmap width
|
---|
| 165 | * @param h Bitmap height
|
---|
| 166 | * @return EOK on success or an error code
|
---|
| 167 | */
|
---|
| 168 | static errno_t bitmap_tartan(gfx_bitmap_t *bitmap, gfx_coord_t w, gfx_coord_t h)
|
---|
| 169 | {
|
---|
| 170 | int i, j;
|
---|
| 171 | pixelmap_t pixelmap;
|
---|
| 172 | gfx_bitmap_alloc_t alloc;
|
---|
| 173 | errno_t rc;
|
---|
| 174 |
|
---|
| 175 | rc = gfx_bitmap_get_alloc(bitmap, &alloc);
|
---|
| 176 | if (rc != EOK)
|
---|
| 177 | return rc;
|
---|
| 178 |
|
---|
| 179 | /* In absence of anything else, use pixelmap */
|
---|
| 180 | pixelmap.width = w;
|
---|
| 181 | pixelmap.height = h;
|
---|
| 182 | pixelmap.data = alloc.pixels;
|
---|
| 183 |
|
---|
| 184 | for (i = 0; i < w; i++) {
|
---|
| 185 | for (j = 0; j < h; j++) {
|
---|
| 186 | pixelmap_put_pixel(&pixelmap, i, j,
|
---|
[6a87f28] | 187 | PIXEL(0, (i % 30) < 3 ? 255 : 0,
|
---|
[587b4cb] | 188 | (j % 30) < 3 ? 255 : 0, i / 2));
|
---|
| 189 | }
|
---|
| 190 | }
|
---|
| 191 |
|
---|
| 192 | return EOK;
|
---|
| 193 | }
|
---|
| 194 |
|
---|
| 195 | /** Fill bitmap with moire pattern.
|
---|
| 196 | *
|
---|
| 197 | * @param bitmap Bitmap
|
---|
| 198 | * @param w Bitmap width
|
---|
| 199 | * @param h Bitmap height
|
---|
| 200 | * @return EOK on success or an error code
|
---|
| 201 | */
|
---|
| 202 | static errno_t bitmap_moire(gfx_bitmap_t *bitmap, gfx_coord_t w, gfx_coord_t h)
|
---|
| 203 | {
|
---|
| 204 | int i, j;
|
---|
| 205 | int k;
|
---|
| 206 | pixelmap_t pixelmap;
|
---|
| 207 | gfx_bitmap_alloc_t alloc;
|
---|
| 208 | errno_t rc;
|
---|
| 209 |
|
---|
| 210 | rc = gfx_bitmap_get_alloc(bitmap, &alloc);
|
---|
| 211 | if (rc != EOK)
|
---|
| 212 | return rc;
|
---|
| 213 |
|
---|
| 214 | /* In absence of anything else, use pixelmap */
|
---|
| 215 | pixelmap.width = w;
|
---|
| 216 | pixelmap.height = h;
|
---|
| 217 | pixelmap.data = alloc.pixels;
|
---|
| 218 |
|
---|
| 219 | for (i = 0; i < w; i++) {
|
---|
| 220 | for (j = 0; j < h; j++) {
|
---|
| 221 | k = i * i + j * j;
|
---|
| 222 | pixelmap_put_pixel(&pixelmap, i, j,
|
---|
[6a87f28] | 223 | PIXEL(0, k, k, k));
|
---|
[587b4cb] | 224 | }
|
---|
| 225 | }
|
---|
| 226 |
|
---|
| 227 | return EOK;
|
---|
| 228 | }
|
---|
| 229 |
|
---|
[bea947f] | 230 | /** Render circle to a bitmap.
|
---|
| 231 | *
|
---|
| 232 | * @param bitmap Bitmap
|
---|
| 233 | * @param w Bitmap width
|
---|
| 234 | * @param h Bitmap height
|
---|
| 235 | * @return EOK on success or an error code
|
---|
| 236 | */
|
---|
| 237 | static errno_t bitmap_circle(gfx_bitmap_t *bitmap, gfx_coord_t w, gfx_coord_t h)
|
---|
| 238 | {
|
---|
| 239 | int i, j;
|
---|
| 240 | int k;
|
---|
| 241 | pixelmap_t pixelmap;
|
---|
| 242 | gfx_bitmap_alloc_t alloc;
|
---|
| 243 | errno_t rc;
|
---|
| 244 |
|
---|
| 245 | rc = gfx_bitmap_get_alloc(bitmap, &alloc);
|
---|
| 246 | if (rc != EOK)
|
---|
| 247 | return rc;
|
---|
| 248 |
|
---|
| 249 | /* In absence of anything else, use pixelmap */
|
---|
| 250 | pixelmap.width = w;
|
---|
| 251 | pixelmap.height = h;
|
---|
| 252 | pixelmap.data = alloc.pixels;
|
---|
| 253 |
|
---|
| 254 | for (i = 0; i < w; i++) {
|
---|
| 255 | for (j = 0; j < h; j++) {
|
---|
| 256 | k = i * i + j * j;
|
---|
| 257 | pixelmap_put_pixel(&pixelmap, i, j,
|
---|
[6a87f28] | 258 | k < w * w / 2 ? PIXEL(0, 0, 255, 0) :
|
---|
[bea947f] | 259 | PIXEL(0, 255, 0, 255));
|
---|
| 260 | }
|
---|
| 261 | }
|
---|
| 262 |
|
---|
| 263 | return EOK;
|
---|
| 264 | }
|
---|
| 265 |
|
---|
[e0545de] | 266 | /** Run bitmap demo on a graphic context.
|
---|
| 267 | *
|
---|
| 268 | * @param gc Graphic context
|
---|
| 269 | * @param w Width
|
---|
| 270 | * @param h Height
|
---|
| 271 | */
|
---|
[1822545] | 272 | static errno_t demo_bitmap(gfx_context_t *gc, gfx_coord_t w, gfx_coord_t h)
|
---|
[e0545de] | 273 | {
|
---|
| 274 | gfx_bitmap_t *bitmap;
|
---|
| 275 | gfx_bitmap_params_t params;
|
---|
| 276 | int i, j;
|
---|
| 277 | gfx_coord2_t offs;
|
---|
| 278 | gfx_rect_t srect;
|
---|
| 279 | errno_t rc;
|
---|
[587b4cb] | 280 |
|
---|
[4f64b7b8] | 281 | if (quit)
|
---|
| 282 | return EOK;
|
---|
| 283 |
|
---|
[587b4cb] | 284 | rc = clear_scr(gc, w, h);
|
---|
| 285 | if (rc != EOK)
|
---|
| 286 | return rc;
|
---|
[e0545de] | 287 |
|
---|
[a8eed5f] | 288 | gfx_bitmap_params_init(¶ms);
|
---|
[e0545de] | 289 | params.rect.p0.x = 0;
|
---|
| 290 | params.rect.p0.y = 0;
|
---|
| 291 | params.rect.p1.x = w;
|
---|
| 292 | params.rect.p1.y = h;
|
---|
| 293 |
|
---|
| 294 | rc = gfx_bitmap_create(gc, ¶ms, NULL, &bitmap);
|
---|
| 295 | if (rc != EOK)
|
---|
| 296 | return rc;
|
---|
| 297 |
|
---|
[587b4cb] | 298 | rc = bitmap_tartan(bitmap, w, h);
|
---|
[e0545de] | 299 | if (rc != EOK)
|
---|
[587b4cb] | 300 | goto error;
|
---|
[e0545de] | 301 |
|
---|
| 302 | for (j = 0; j < 10; j++) {
|
---|
| 303 | for (i = 0; i < 5; i++) {
|
---|
| 304 | srect.p0.x = rand() % (w - 40);
|
---|
[d18f3b7] | 305 | srect.p0.y = rand() % (h - 20);
|
---|
[e0545de] | 306 | srect.p1.x = srect.p0.x + rand() % (w - srect.p0.x);
|
---|
| 307 | srect.p1.y = srect.p0.y + rand() % (h - srect.p0.y);
|
---|
| 308 | offs.x = 0;
|
---|
| 309 | offs.y = 0;
|
---|
| 310 |
|
---|
[0008c0f] | 311 | rc = gfx_bitmap_render(bitmap, &srect, &offs);
|
---|
| 312 | if (rc != EOK)
|
---|
| 313 | goto error;
|
---|
[587b4cb] | 314 | fibril_usleep(250 * 1000);
|
---|
[b3c185b6] | 315 |
|
---|
| 316 | if (quit)
|
---|
[4f64b7b8] | 317 | goto out;
|
---|
[587b4cb] | 318 | }
|
---|
| 319 | }
|
---|
| 320 |
|
---|
[4f64b7b8] | 321 | out:
|
---|
[587b4cb] | 322 | gfx_bitmap_destroy(bitmap);
|
---|
| 323 |
|
---|
| 324 | return EOK;
|
---|
| 325 | error:
|
---|
| 326 | gfx_bitmap_destroy(bitmap);
|
---|
| 327 | return rc;
|
---|
| 328 | }
|
---|
| 329 |
|
---|
| 330 | /** Run second bitmap demo on a graphic context.
|
---|
| 331 | *
|
---|
| 332 | * @param gc Graphic context
|
---|
| 333 | * @param w Width
|
---|
| 334 | * @param h Height
|
---|
| 335 | */
|
---|
| 336 | static errno_t demo_bitmap2(gfx_context_t *gc, gfx_coord_t w, gfx_coord_t h)
|
---|
| 337 | {
|
---|
| 338 | gfx_bitmap_t *bitmap;
|
---|
| 339 | gfx_bitmap_params_t params;
|
---|
| 340 | int i, j;
|
---|
| 341 | gfx_coord2_t offs;
|
---|
| 342 | errno_t rc;
|
---|
| 343 |
|
---|
[4f64b7b8] | 344 | if (quit)
|
---|
| 345 | return EOK;
|
---|
| 346 |
|
---|
[587b4cb] | 347 | rc = clear_scr(gc, w, h);
|
---|
| 348 | if (rc != EOK)
|
---|
| 349 | return rc;
|
---|
| 350 |
|
---|
[b3b00b6] | 351 | gfx_bitmap_params_init(¶ms);
|
---|
[587b4cb] | 352 | params.rect.p0.x = 0;
|
---|
| 353 | params.rect.p0.y = 0;
|
---|
| 354 | params.rect.p1.x = 40;
|
---|
| 355 | params.rect.p1.y = 20;
|
---|
| 356 |
|
---|
| 357 | rc = gfx_bitmap_create(gc, ¶ms, NULL, &bitmap);
|
---|
| 358 | if (rc != EOK)
|
---|
| 359 | return rc;
|
---|
| 360 |
|
---|
| 361 | rc = bitmap_moire(bitmap, 40, 20);
|
---|
| 362 | if (rc != EOK)
|
---|
| 363 | goto error;
|
---|
| 364 |
|
---|
| 365 | for (j = 0; j < 10; j++) {
|
---|
| 366 | for (i = 0; i < 10; i++) {
|
---|
| 367 | offs.x = rand() % (w - 40);
|
---|
| 368 | offs.y = rand() % (h - 20);
|
---|
| 369 |
|
---|
| 370 | rc = gfx_bitmap_render(bitmap, NULL, &offs);
|
---|
| 371 | if (rc != EOK)
|
---|
| 372 | goto error;
|
---|
[e0545de] | 373 | }
|
---|
[587b4cb] | 374 |
|
---|
| 375 | fibril_usleep(500 * 1000);
|
---|
[b3c185b6] | 376 |
|
---|
| 377 | if (quit)
|
---|
| 378 | break;
|
---|
[e0545de] | 379 | }
|
---|
| 380 |
|
---|
| 381 | gfx_bitmap_destroy(bitmap);
|
---|
| 382 |
|
---|
| 383 | return EOK;
|
---|
[0008c0f] | 384 | error:
|
---|
| 385 | gfx_bitmap_destroy(bitmap);
|
---|
| 386 | return rc;
|
---|
[e0545de] | 387 | }
|
---|
[8fa65af0] | 388 |
|
---|
[bea947f] | 389 | /** Run bitmap color key demo on a graphic context.
|
---|
| 390 | *
|
---|
| 391 | * @param gc Graphic context
|
---|
| 392 | * @param w Width
|
---|
| 393 | * @param h Height
|
---|
| 394 | */
|
---|
| 395 | static errno_t demo_bitmap_kc(gfx_context_t *gc, gfx_coord_t w, gfx_coord_t h)
|
---|
| 396 | {
|
---|
| 397 | gfx_bitmap_t *bitmap;
|
---|
| 398 | gfx_bitmap_params_t params;
|
---|
| 399 | int i, j;
|
---|
| 400 | gfx_coord2_t offs;
|
---|
| 401 | errno_t rc;
|
---|
| 402 |
|
---|
[4f64b7b8] | 403 | if (quit)
|
---|
| 404 | return EOK;
|
---|
| 405 |
|
---|
[bea947f] | 406 | rc = clear_scr(gc, w, h);
|
---|
| 407 | if (rc != EOK)
|
---|
| 408 | return rc;
|
---|
| 409 |
|
---|
[b3b00b6] | 410 | gfx_bitmap_params_init(¶ms);
|
---|
[bea947f] | 411 | params.rect.p0.x = 0;
|
---|
| 412 | params.rect.p0.y = 0;
|
---|
| 413 | params.rect.p1.x = 40;
|
---|
| 414 | params.rect.p1.y = 40;
|
---|
| 415 | params.flags = bmpf_color_key;
|
---|
| 416 | params.key_color = PIXEL(0, 255, 0, 255);
|
---|
| 417 |
|
---|
| 418 | rc = gfx_bitmap_create(gc, ¶ms, NULL, &bitmap);
|
---|
| 419 | if (rc != EOK)
|
---|
| 420 | return rc;
|
---|
| 421 |
|
---|
| 422 | rc = bitmap_circle(bitmap, 40, 40);
|
---|
| 423 | if (rc != EOK)
|
---|
| 424 | goto error;
|
---|
| 425 |
|
---|
| 426 | for (j = 0; j < 10; j++) {
|
---|
| 427 | for (i = 0; i < 10; i++) {
|
---|
| 428 | offs.x = j * 20 + i * 20;
|
---|
| 429 | offs.y = i * 20;
|
---|
| 430 |
|
---|
| 431 | rc = gfx_bitmap_render(bitmap, NULL, &offs);
|
---|
| 432 | if (rc != EOK)
|
---|
| 433 | goto error;
|
---|
| 434 | }
|
---|
| 435 |
|
---|
| 436 | fibril_usleep(500 * 1000);
|
---|
| 437 |
|
---|
| 438 | if (quit)
|
---|
| 439 | break;
|
---|
| 440 | }
|
---|
| 441 |
|
---|
| 442 | gfx_bitmap_destroy(bitmap);
|
---|
| 443 |
|
---|
| 444 | return EOK;
|
---|
| 445 | error:
|
---|
| 446 | gfx_bitmap_destroy(bitmap);
|
---|
| 447 | return rc;
|
---|
| 448 | }
|
---|
[e0545de] | 449 |
|
---|
[8fa65af0] | 450 | /** Run text demo on a graphic context.
|
---|
| 451 | *
|
---|
| 452 | * @param gc Graphic context
|
---|
| 453 | * @param w Width
|
---|
| 454 | * @param h Height
|
---|
| 455 | */
|
---|
| 456 | static errno_t demo_text(gfx_context_t *gc, gfx_coord_t w, gfx_coord_t h)
|
---|
| 457 | {
|
---|
| 458 | gfx_color_t *color = NULL;
|
---|
| 459 | gfx_rect_t rect;
|
---|
| 460 | gfx_typeface_t *tface = NULL;
|
---|
| 461 | gfx_font_info_t *finfo;
|
---|
| 462 | gfx_font_t *font = NULL;
|
---|
| 463 | gfx_coord2_t pos;
|
---|
| 464 | gfx_text_fmt_t fmt;
|
---|
| 465 | int i;
|
---|
| 466 | errno_t rc;
|
---|
| 467 |
|
---|
[4f64b7b8] | 468 | if (quit)
|
---|
| 469 | return EOK;
|
---|
| 470 |
|
---|
[6a87f28] | 471 | /* XXX Crude way of detecting text mode */
|
---|
| 472 | if (w < 256) {
|
---|
| 473 | /* Create dummy font for text mode */
|
---|
| 474 | rc = gfx_typeface_create(gc, &tface);
|
---|
| 475 | if (rc != EOK) {
|
---|
| 476 | printf("Error creating typeface\n");
|
---|
| 477 | goto error;
|
---|
| 478 | }
|
---|
[8fa65af0] | 479 |
|
---|
[6a87f28] | 480 | rc = gfx_font_create_textmode(tface, &font);
|
---|
| 481 | if (rc != EOK) {
|
---|
| 482 | printf("Error creating font\n");
|
---|
| 483 | goto error;
|
---|
| 484 | }
|
---|
| 485 | } else {
|
---|
| 486 | /* Load font */
|
---|
| 487 | rc = gfx_typeface_open(gc, "/data/font/helena.tpf", &tface);
|
---|
| 488 | if (rc != EOK) {
|
---|
| 489 | printf("Error opening typeface\n");
|
---|
| 490 | goto error;
|
---|
| 491 | }
|
---|
[8fa65af0] | 492 |
|
---|
[6a87f28] | 493 | finfo = gfx_typeface_first_font(tface);
|
---|
| 494 | if (finfo == NULL) {
|
---|
| 495 | printf("Typeface contains no font.\n");
|
---|
| 496 | rc = ENOENT;
|
---|
| 497 | goto error;
|
---|
| 498 | }
|
---|
| 499 |
|
---|
| 500 | rc = gfx_font_open(finfo, &font);
|
---|
| 501 | if (rc != EOK) {
|
---|
| 502 | printf("Error opening font.\n");
|
---|
| 503 | goto error;
|
---|
| 504 | }
|
---|
[8fa65af0] | 505 | }
|
---|
| 506 |
|
---|
| 507 | rc = clear_scr(gc, w, h);
|
---|
| 508 | if (rc != EOK)
|
---|
| 509 | goto error;
|
---|
| 510 |
|
---|
| 511 | /* Vertical bars */
|
---|
| 512 |
|
---|
| 513 | for (i = 0; i < 20; i++) {
|
---|
| 514 | rc = gfx_color_new_rgb_i16(0, 0x8000 * i / 20,
|
---|
| 515 | 0x8000 * i / 20, &color);
|
---|
| 516 | if (rc != EOK)
|
---|
| 517 | goto error;
|
---|
| 518 |
|
---|
| 519 | rc = gfx_set_color(gc, color);
|
---|
| 520 | if (rc != EOK)
|
---|
| 521 | goto error;
|
---|
| 522 |
|
---|
| 523 | rect.p0.x = w * i / 20;
|
---|
| 524 | rect.p0.y = 0;
|
---|
| 525 | rect.p1.x = w * (i + 1) / 20;
|
---|
| 526 | rect.p1.y = h;
|
---|
| 527 |
|
---|
| 528 | rc = gfx_fill_rect(gc, &rect);
|
---|
| 529 | if (rc != EOK)
|
---|
| 530 | goto error;
|
---|
| 531 |
|
---|
| 532 | gfx_color_delete(color);
|
---|
| 533 | }
|
---|
| 534 |
|
---|
| 535 | rc = gfx_color_new_rgb_i16(0, 0, 0x8000, &color);
|
---|
| 536 | if (rc != EOK)
|
---|
| 537 | goto error;
|
---|
| 538 |
|
---|
| 539 | rc = gfx_set_color(gc, color);
|
---|
| 540 | if (rc != EOK)
|
---|
| 541 | goto error;
|
---|
| 542 |
|
---|
| 543 | rect.p0.x = w / 20;
|
---|
[8bf9058] | 544 | rect.p0.y = 2 * h / 15;
|
---|
[8fa65af0] | 545 | rect.p1.x = w - w / 20;
|
---|
| 546 | rect.p1.y = 5 * h / 15;
|
---|
| 547 |
|
---|
| 548 | rc = gfx_fill_rect(gc, &rect);
|
---|
| 549 | if (rc != EOK)
|
---|
| 550 | goto error;
|
---|
| 551 |
|
---|
| 552 | gfx_color_delete(color);
|
---|
| 553 |
|
---|
| 554 | rc = gfx_color_new_rgb_i16(0xffff, 0xffff, 0xffff, &color);
|
---|
| 555 | if (rc != EOK)
|
---|
| 556 | goto error;
|
---|
| 557 |
|
---|
| 558 | gfx_text_fmt_init(&fmt);
|
---|
[b433f68] | 559 | fmt.color = color;
|
---|
[8fa65af0] | 560 |
|
---|
| 561 | pos.x = rect.p0.x;
|
---|
| 562 | pos.y = rect.p0.y;
|
---|
| 563 | rc = gfx_puttext(font, &pos, &fmt, "Top left");
|
---|
| 564 | if (rc != EOK) {
|
---|
| 565 | printf("Error rendering text.\n");
|
---|
| 566 | goto error;
|
---|
| 567 | }
|
---|
| 568 |
|
---|
[8bf9058] | 569 | pos.x = (rect.p0.x + rect.p1.x - 1) / 2;
|
---|
[8fa65af0] | 570 | pos.y = rect.p0.y;
|
---|
| 571 | fmt.halign = gfx_halign_center;
|
---|
| 572 | rc = gfx_puttext(font, &pos, &fmt, "Top center");
|
---|
| 573 | if (rc != EOK)
|
---|
| 574 | goto error;
|
---|
| 575 |
|
---|
[8bf9058] | 576 | pos.x = rect.p1.x - 1;
|
---|
[8fa65af0] | 577 | pos.y = rect.p0.y;
|
---|
| 578 | fmt.halign = gfx_halign_right;
|
---|
| 579 | rc = gfx_puttext(font, &pos, &fmt, "Top right");
|
---|
| 580 | if (rc != EOK)
|
---|
| 581 | goto error;
|
---|
| 582 |
|
---|
| 583 | fmt.valign = gfx_valign_center;
|
---|
| 584 |
|
---|
| 585 | pos.x = rect.p0.x;
|
---|
[8bf9058] | 586 | pos.y = (rect.p0.y + rect.p1.y - 1) / 2;
|
---|
[8fa65af0] | 587 | fmt.halign = gfx_halign_left;
|
---|
| 588 | rc = gfx_puttext(font, &pos, &fmt, "Center left");
|
---|
| 589 | if (rc != EOK)
|
---|
| 590 | goto error;
|
---|
| 591 |
|
---|
[8bf9058] | 592 | pos.x = (rect.p0.x + rect.p1.x - 1) / 2;
|
---|
| 593 | pos.y = (rect.p0.y + rect.p1.y - 1) / 2;
|
---|
[8fa65af0] | 594 | fmt.halign = gfx_halign_center;
|
---|
| 595 | rc = gfx_puttext(font, &pos, &fmt, "Center");
|
---|
| 596 | if (rc != EOK)
|
---|
| 597 | goto error;
|
---|
| 598 |
|
---|
[8bf9058] | 599 | pos.x = rect.p1.x - 1;
|
---|
| 600 | pos.y = (rect.p0.y + rect.p1.y - 1) / 2;
|
---|
[8fa65af0] | 601 | fmt.halign = gfx_halign_right;
|
---|
| 602 | rc = gfx_puttext(font, &pos, &fmt, "Center right");
|
---|
| 603 | if (rc != EOK)
|
---|
| 604 | goto error;
|
---|
| 605 |
|
---|
| 606 | fmt.valign = gfx_valign_bottom;
|
---|
| 607 |
|
---|
| 608 | pos.x = rect.p0.x;
|
---|
[8bf9058] | 609 | pos.y = rect.p1.y - 1;
|
---|
[8fa65af0] | 610 | fmt.halign = gfx_halign_left;
|
---|
| 611 | rc = gfx_puttext(font, &pos, &fmt, "Bottom left");
|
---|
| 612 | if (rc != EOK)
|
---|
| 613 | goto error;
|
---|
| 614 |
|
---|
[8bf9058] | 615 | pos.x = (rect.p0.x + rect.p1.x - 1) / 2;
|
---|
| 616 | pos.y = rect.p1.y - 1;
|
---|
[8fa65af0] | 617 | fmt.halign = gfx_halign_center;
|
---|
| 618 | rc = gfx_puttext(font, &pos, &fmt, "Bottom center");
|
---|
| 619 | if (rc != EOK)
|
---|
| 620 | goto error;
|
---|
| 621 |
|
---|
[8bf9058] | 622 | pos.x = rect.p1.x - 1;
|
---|
| 623 | pos.y = rect.p1.y - 1;
|
---|
[8fa65af0] | 624 | fmt.halign = gfx_halign_right;
|
---|
| 625 | rc = gfx_puttext(font, &pos, &fmt, "Bottom right");
|
---|
| 626 | if (rc != EOK)
|
---|
| 627 | goto error;
|
---|
| 628 |
|
---|
[0d62c10] | 629 | gfx_color_delete(color);
|
---|
| 630 |
|
---|
[8fa65af0] | 631 | gfx_text_fmt_init(&fmt);
|
---|
| 632 |
|
---|
| 633 | for (i = 0; i < 8; i++) {
|
---|
[0d62c10] | 634 | rc = gfx_color_new_rgb_i16((i & 4) ? 0xffff : 0,
|
---|
| 635 | (i & 2) ? 0xffff : 0, (i & 1) ? 0xffff : 0, &color);
|
---|
| 636 | if (rc != EOK)
|
---|
| 637 | goto error;
|
---|
| 638 |
|
---|
[b433f68] | 639 | fmt.color = color;
|
---|
[0d62c10] | 640 |
|
---|
[8fa65af0] | 641 | pos.x = w / 20;
|
---|
| 642 | pos.y = (7 + i) * h / 15;
|
---|
| 643 | rc = gfx_puttext(font, &pos, &fmt, "The quick brown fox jumps over the lazy dog.");
|
---|
| 644 | if (rc != EOK)
|
---|
| 645 | goto error;
|
---|
[0d62c10] | 646 |
|
---|
| 647 | gfx_color_delete(color);
|
---|
[8fa65af0] | 648 | }
|
---|
| 649 |
|
---|
| 650 | for (i = 0; i < 10; i++) {
|
---|
| 651 | fibril_usleep(500 * 1000);
|
---|
| 652 | if (quit)
|
---|
| 653 | break;
|
---|
| 654 | }
|
---|
| 655 |
|
---|
| 656 | gfx_font_close(font);
|
---|
| 657 | gfx_typeface_destroy(tface);
|
---|
| 658 | return EOK;
|
---|
| 659 | error:
|
---|
| 660 | if (font != NULL)
|
---|
| 661 | gfx_font_close(font);
|
---|
| 662 | if (tface != NULL)
|
---|
| 663 | gfx_typeface_destroy(tface);
|
---|
| 664 | return rc;
|
---|
| 665 | }
|
---|
| 666 |
|
---|
[1167ad34] | 667 | /** Run clipping demo on a graphic context.
|
---|
| 668 | *
|
---|
| 669 | * @param gc Graphic context
|
---|
| 670 | * @param w Width
|
---|
| 671 | * @param h Height
|
---|
| 672 | */
|
---|
| 673 | static errno_t demo_clip(gfx_context_t *gc, gfx_coord_t w, gfx_coord_t h)
|
---|
| 674 | {
|
---|
| 675 | gfx_bitmap_t *bitmap;
|
---|
| 676 | gfx_color_t *color;
|
---|
| 677 | gfx_bitmap_params_t params;
|
---|
| 678 | int i, j;
|
---|
| 679 | gfx_coord2_t offs;
|
---|
| 680 | gfx_rect_t rect;
|
---|
| 681 | errno_t rc;
|
---|
| 682 |
|
---|
| 683 | if (quit)
|
---|
| 684 | return EOK;
|
---|
| 685 |
|
---|
| 686 | rc = clear_scr(gc, w, h);
|
---|
| 687 | if (rc != EOK)
|
---|
| 688 | return rc;
|
---|
| 689 |
|
---|
| 690 | gfx_bitmap_params_init(¶ms);
|
---|
| 691 | params.rect.p0.x = 0;
|
---|
| 692 | params.rect.p0.y = 0;
|
---|
| 693 | params.rect.p1.x = 40;
|
---|
| 694 | params.rect.p1.y = 20;
|
---|
| 695 |
|
---|
| 696 | rc = gfx_bitmap_create(gc, ¶ms, NULL, &bitmap);
|
---|
| 697 | if (rc != EOK)
|
---|
| 698 | return rc;
|
---|
| 699 |
|
---|
| 700 | rc = bitmap_moire(bitmap, 40, 20);
|
---|
| 701 | if (rc != EOK)
|
---|
| 702 | goto error;
|
---|
| 703 |
|
---|
| 704 | for (j = 0; j < 10; j++) {
|
---|
| 705 | rect.p0.x = w / 8;
|
---|
| 706 | rect.p0.y = h / 8;
|
---|
| 707 | rect.p1.x = w * 7 / 8;
|
---|
| 708 | rect.p1.y = h * 3 / 8;
|
---|
| 709 |
|
---|
| 710 | rc = gfx_set_clip_rect(gc, &rect);
|
---|
| 711 | if (rc != EOK)
|
---|
| 712 | return rc;
|
---|
| 713 |
|
---|
| 714 | rc = gfx_color_new_rgb_i16(rand() % 0x10000, rand() % 0x10000,
|
---|
| 715 | rand() % 0x10000, &color);
|
---|
| 716 | if (rc != EOK)
|
---|
| 717 | return rc;
|
---|
| 718 |
|
---|
| 719 | rc = gfx_set_color(gc, color);
|
---|
| 720 | if (rc != EOK)
|
---|
| 721 | return rc;
|
---|
| 722 |
|
---|
| 723 | for (i = 0; i < 10; i++) {
|
---|
| 724 | rect.p0.x = rand() % (w - 1);
|
---|
| 725 | rect.p0.y = rand() % (h - 1);
|
---|
| 726 | rect.p1.x = rect.p0.x + rand() % (w - 1 - rect.p0.x);
|
---|
| 727 | rect.p1.y = rect.p0.y + rand() % (h - 1 - rect.p0.y);
|
---|
| 728 |
|
---|
| 729 | rc = gfx_fill_rect(gc, &rect);
|
---|
| 730 | if (rc != EOK)
|
---|
| 731 | return rc;
|
---|
| 732 | }
|
---|
| 733 |
|
---|
| 734 | gfx_color_delete(color);
|
---|
| 735 |
|
---|
| 736 | rect.p0.x = w / 8;
|
---|
| 737 | rect.p0.y = h * 5 / 8;
|
---|
| 738 | rect.p1.x = w * 7 / 8;
|
---|
| 739 | rect.p1.y = h * 7 / 8;
|
---|
| 740 |
|
---|
| 741 | rc = gfx_set_clip_rect(gc, &rect);
|
---|
| 742 | if (rc != EOK)
|
---|
| 743 | return rc;
|
---|
| 744 |
|
---|
| 745 | for (i = 0; i < 10; i++) {
|
---|
| 746 | offs.x = rand() % (w - 40);
|
---|
| 747 | offs.y = rand() % (h - 20);
|
---|
| 748 |
|
---|
| 749 | rc = gfx_bitmap_render(bitmap, NULL, &offs);
|
---|
| 750 | if (rc != EOK)
|
---|
| 751 | goto error;
|
---|
| 752 | }
|
---|
| 753 |
|
---|
| 754 | fibril_usleep(500 * 1000);
|
---|
| 755 |
|
---|
| 756 | if (quit)
|
---|
| 757 | break;
|
---|
| 758 | }
|
---|
| 759 |
|
---|
| 760 | (void) gfx_set_clip_rect(gc, NULL);
|
---|
| 761 | gfx_bitmap_destroy(bitmap);
|
---|
| 762 | return EOK;
|
---|
| 763 | error:
|
---|
| 764 | (void) gfx_set_clip_rect(gc, NULL);
|
---|
| 765 | gfx_bitmap_destroy(bitmap);
|
---|
| 766 | return rc;
|
---|
| 767 | }
|
---|
| 768 |
|
---|
[e0545de] | 769 | /** Run demo loop on a graphic context.
|
---|
| 770 | *
|
---|
| 771 | * @param gc Graphic context
|
---|
| 772 | * @param w Width
|
---|
| 773 | * @param h Height
|
---|
| 774 | */
|
---|
[1822545] | 775 | static errno_t demo_loop(gfx_context_t *gc, gfx_coord_t w, gfx_coord_t h)
|
---|
[e0545de] | 776 | {
|
---|
| 777 | errno_t rc;
|
---|
| 778 |
|
---|
[b3c185b6] | 779 | while (!quit) {
|
---|
[e0545de] | 780 | rc = demo_rects(gc, w, h);
|
---|
| 781 | if (rc != EOK)
|
---|
| 782 | return rc;
|
---|
| 783 |
|
---|
| 784 | rc = demo_bitmap(gc, w, h);
|
---|
| 785 | if (rc != EOK)
|
---|
| 786 | return rc;
|
---|
[587b4cb] | 787 |
|
---|
| 788 | rc = demo_bitmap2(gc, w, h);
|
---|
| 789 | if (rc != EOK)
|
---|
| 790 | return rc;
|
---|
[bea947f] | 791 |
|
---|
| 792 | rc = demo_bitmap_kc(gc, w, h);
|
---|
| 793 | if (rc != EOK)
|
---|
| 794 | return rc;
|
---|
[8fa65af0] | 795 |
|
---|
| 796 | rc = demo_text(gc, w, h);
|
---|
| 797 | if (rc != EOK)
|
---|
| 798 | return rc;
|
---|
[1167ad34] | 799 |
|
---|
| 800 | rc = demo_clip(gc, w, h);
|
---|
| 801 | if (rc != EOK)
|
---|
| 802 | return rc;
|
---|
[e0545de] | 803 | }
|
---|
[b3c185b6] | 804 |
|
---|
| 805 | return EOK;
|
---|
[00e8290] | 806 | }
|
---|
| 807 |
|
---|
| 808 | /** Run demo on console. */
|
---|
| 809 | static errno_t demo_console(void)
|
---|
| 810 | {
|
---|
| 811 | console_ctrl_t *con = NULL;
|
---|
| 812 | console_gc_t *cgc = NULL;
|
---|
| 813 | gfx_context_t *gc;
|
---|
| 814 | errno_t rc;
|
---|
| 815 |
|
---|
| 816 | printf("Init console..\n");
|
---|
| 817 | con = console_init(stdin, stdout);
|
---|
| 818 | if (con == NULL)
|
---|
| 819 | return EIO;
|
---|
| 820 |
|
---|
| 821 | printf("Create console GC\n");
|
---|
| 822 | rc = console_gc_create(con, stdout, &cgc);
|
---|
| 823 | if (rc != EOK)
|
---|
| 824 | return rc;
|
---|
| 825 |
|
---|
| 826 | gc = console_gc_get_ctx(cgc);
|
---|
| 827 |
|
---|
[e0545de] | 828 | rc = demo_loop(gc, 80, 25);
|
---|
[00e8290] | 829 | if (rc != EOK)
|
---|
| 830 | return rc;
|
---|
[9259d20] | 831 |
|
---|
[9be2358] | 832 | rc = console_gc_delete(cgc);
|
---|
| 833 | if (rc != EOK)
|
---|
[00e8290] | 834 | return rc;
|
---|
| 835 |
|
---|
| 836 | return EOK;
|
---|
| 837 | }
|
---|
| 838 |
|
---|
[b93ec7c0] | 839 | /** Run demo on UI. */
|
---|
| 840 | static errno_t demo_ui(const char *display_spec)
|
---|
[00e8290] | 841 | {
|
---|
[b93ec7c0] | 842 | ui_t *ui = NULL;
|
---|
| 843 | ui_wnd_params_t params;
|
---|
| 844 | ui_window_t *window = NULL;
|
---|
[00e8290] | 845 | gfx_context_t *gc;
|
---|
[b93ec7c0] | 846 | gfx_rect_t rect;
|
---|
| 847 | gfx_rect_t wrect;
|
---|
| 848 | gfx_coord2_t off;
|
---|
[00e8290] | 849 | errno_t rc;
|
---|
| 850 |
|
---|
[b93ec7c0] | 851 | printf("Init UI..\n");
|
---|
[00e8290] | 852 |
|
---|
[b93ec7c0] | 853 | rc = ui_create(display_spec, &ui);
|
---|
| 854 | if (rc != EOK) {
|
---|
| 855 | printf("Error initializing UI (%s)\n", display_spec);
|
---|
| 856 | goto error;
|
---|
[00e8290] | 857 | }
|
---|
| 858 |
|
---|
[b93ec7c0] | 859 | rect.p0.x = 0;
|
---|
| 860 | rect.p0.y = 0;
|
---|
| 861 | rect.p1.x = 400;
|
---|
| 862 | rect.p1.y = 300;
|
---|
[00e8290] | 863 |
|
---|
[b93ec7c0] | 864 | ui_wnd_params_init(¶ms);
|
---|
| 865 | params.caption = "GFX Demo";
|
---|
[00e8290] | 866 |
|
---|
[b93ec7c0] | 867 | /*
|
---|
| 868 | * Compute window rectangle such that application area corresponds
|
---|
| 869 | * to rect
|
---|
| 870 | */
|
---|
[266ec54] | 871 | ui_wdecor_rect_from_app(params.style, &rect, &wrect);
|
---|
[b93ec7c0] | 872 | off = wrect.p0;
|
---|
| 873 | gfx_rect_rtranslate(&off, &wrect, ¶ms.rect);
|
---|
[00e8290] | 874 |
|
---|
[b93ec7c0] | 875 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
| 876 | if (rc != EOK) {
|
---|
| 877 | printf("Error creating window.\n");
|
---|
| 878 | goto error;
|
---|
[00e8290] | 879 | }
|
---|
| 880 |
|
---|
[b93ec7c0] | 881 | ui_window_set_cb(window, &ui_window_cb, NULL);
|
---|
[00e8290] | 882 |
|
---|
[b93ec7c0] | 883 | rc = ui_window_get_app_gc(window, &gc);
|
---|
| 884 | if (rc != EOK) {
|
---|
| 885 | printf("Error creating graphic context.\n");
|
---|
| 886 | goto error;
|
---|
| 887 | }
|
---|
[00e8290] | 888 |
|
---|
[5bded44] | 889 | task_retval(0);
|
---|
| 890 |
|
---|
[b93ec7c0] | 891 | rc = demo_loop(gc, rect.p1.x, rect.p1.y);
|
---|
[00e8290] | 892 | if (rc != EOK)
|
---|
[b93ec7c0] | 893 | goto error;
|
---|
[00e8290] | 894 |
|
---|
[b93ec7c0] | 895 | ui_window_destroy(window);
|
---|
| 896 | ui_destroy(ui);
|
---|
[00e8290] | 897 |
|
---|
| 898 | return EOK;
|
---|
[b93ec7c0] | 899 | error:
|
---|
| 900 | if (window != NULL)
|
---|
| 901 | ui_window_destroy(window);
|
---|
| 902 | if (ui != NULL)
|
---|
| 903 | ui_destroy(ui);
|
---|
| 904 | return rc;
|
---|
[00e8290] | 905 | }
|
---|
| 906 |
|
---|
[c8cf261] | 907 | /** Run demo on display server. */
|
---|
[fd11144] | 908 | static errno_t demo_display(const char *display_svc)
|
---|
[c8cf261] | 909 | {
|
---|
| 910 | display_t *display = NULL;
|
---|
| 911 | gfx_context_t *gc;
|
---|
[4d9c807] | 912 | display_wnd_params_t params;
|
---|
[c8cf261] | 913 | display_window_t *window = NULL;
|
---|
| 914 | errno_t rc;
|
---|
| 915 |
|
---|
| 916 | printf("Init display..\n");
|
---|
| 917 |
|
---|
[fd11144] | 918 | rc = display_open(display_svc, &display);
|
---|
[c8cf261] | 919 | if (rc != EOK) {
|
---|
| 920 | printf("Error opening display.\n");
|
---|
| 921 | return rc;
|
---|
| 922 | }
|
---|
| 923 |
|
---|
[4d9c807] | 924 | display_wnd_params_init(¶ms);
|
---|
| 925 | params.rect.p0.x = 0;
|
---|
| 926 | params.rect.p0.y = 0;
|
---|
| 927 | params.rect.p1.x = 400;
|
---|
| 928 | params.rect.p1.y = 300;
|
---|
| 929 |
|
---|
| 930 | rc = display_window_create(display, ¶ms, &wnd_cb, NULL, &window);
|
---|
[c8cf261] | 931 | if (rc != EOK) {
|
---|
| 932 | printf("Error creating window.\n");
|
---|
| 933 | return rc;
|
---|
| 934 | }
|
---|
| 935 |
|
---|
| 936 | rc = display_window_get_gc(window, &gc);
|
---|
| 937 | if (rc != EOK) {
|
---|
| 938 | printf("Error getting graphics context.\n");
|
---|
[32dde7e8] | 939 | return rc;
|
---|
[c8cf261] | 940 | }
|
---|
| 941 |
|
---|
[5bded44] | 942 | task_retval(0);
|
---|
| 943 |
|
---|
[e0545de] | 944 | rc = demo_loop(gc, 400, 300);
|
---|
[c8cf261] | 945 | if (rc != EOK)
|
---|
| 946 | return rc;
|
---|
| 947 |
|
---|
| 948 | rc = gfx_context_delete(gc);
|
---|
| 949 | if (rc != EOK)
|
---|
| 950 | return rc;
|
---|
| 951 |
|
---|
[e49b7997] | 952 | display_window_destroy(window);
|
---|
| 953 | display_close(display);
|
---|
| 954 |
|
---|
[c8cf261] | 955 | return EOK;
|
---|
| 956 | }
|
---|
| 957 |
|
---|
[338d0935] | 958 | static void wnd_close_event(void *arg)
|
---|
| 959 | {
|
---|
| 960 | printf("Close event\n");
|
---|
| 961 | quit = true;
|
---|
| 962 | }
|
---|
| 963 |
|
---|
[b3c185b6] | 964 | static void wnd_kbd_event(void *arg, kbd_event_t *event)
|
---|
| 965 | {
|
---|
| 966 | printf("Keyboard event type=%d key=%d\n", event->type, event->key);
|
---|
[5fae123] | 967 | if (event->type == KEY_PRESS)
|
---|
| 968 | quit = true;
|
---|
[b3c185b6] | 969 | }
|
---|
| 970 |
|
---|
[b93ec7c0] | 971 | static void uiwnd_close_event(ui_window_t *window, void *arg)
|
---|
| 972 | {
|
---|
| 973 | printf("Close event\n");
|
---|
| 974 | quit = true;
|
---|
| 975 | }
|
---|
| 976 |
|
---|
| 977 | static void uiwnd_kbd_event(ui_window_t *window, void *arg, kbd_event_t *event)
|
---|
| 978 | {
|
---|
| 979 | printf("Keyboard event type=%d key=%d\n", event->type, event->key);
|
---|
| 980 | if (event->type == KEY_PRESS)
|
---|
| 981 | quit = true;
|
---|
| 982 | }
|
---|
| 983 |
|
---|
[00e8290] | 984 | static void print_syntax(void)
|
---|
| 985 | {
|
---|
[bac8acab] | 986 | printf("Syntax: gfxdemo [-d <display>] {console|display|ui}\n");
|
---|
[00e8290] | 987 | }
|
---|
| 988 |
|
---|
| 989 | int main(int argc, char *argv[])
|
---|
| 990 | {
|
---|
| 991 | errno_t rc;
|
---|
[fd11144] | 992 | const char *display_svc = DISPLAY_DEFAULT;
|
---|
| 993 | int i;
|
---|
| 994 |
|
---|
| 995 | i = 1;
|
---|
| 996 | while (i < argc && argv[i][0] == '-') {
|
---|
| 997 | if (str_cmp(argv[i], "-d") == 0) {
|
---|
| 998 | ++i;
|
---|
| 999 | if (i >= argc) {
|
---|
| 1000 | printf("Argument missing.\n");
|
---|
| 1001 | print_syntax();
|
---|
| 1002 | return 1;
|
---|
| 1003 | }
|
---|
| 1004 |
|
---|
| 1005 | display_svc = argv[i++];
|
---|
| 1006 | } else {
|
---|
| 1007 | printf("Invalid option '%s'.\n", argv[i]);
|
---|
| 1008 | print_syntax();
|
---|
| 1009 | return 1;
|
---|
| 1010 | }
|
---|
| 1011 | }
|
---|
[00e8290] | 1012 |
|
---|
[fd11144] | 1013 | if (i >= argc || str_cmp(argv[i], "display") == 0) {
|
---|
| 1014 | rc = demo_display(display_svc);
|
---|
[0b63dc2] | 1015 | if (rc != EOK)
|
---|
| 1016 | return 1;
|
---|
[fd11144] | 1017 | } else if (str_cmp(argv[i], "console") == 0) {
|
---|
[00e8290] | 1018 | rc = demo_console();
|
---|
| 1019 | if (rc != EOK)
|
---|
| 1020 | return 1;
|
---|
[b93ec7c0] | 1021 | } else if (str_cmp(argv[i], "ui") == 0) {
|
---|
| 1022 | rc = demo_ui(display_svc);
|
---|
[00e8290] | 1023 | if (rc != EOK)
|
---|
| 1024 | return 1;
|
---|
| 1025 | } else {
|
---|
| 1026 | print_syntax();
|
---|
| 1027 | return 1;
|
---|
| 1028 | }
|
---|
[045186b] | 1029 | }
|
---|
| 1030 |
|
---|
| 1031 | /** @}
|
---|
| 1032 | */
|
---|