source: mainline/uspace/app/gfxdemo/gfxdemo.c@ 9be2358

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 9be2358 was 9be2358, checked in by Jiri Svoboda <jiri@…>, 6 years ago

Caller needs entire console GC to be able to destroy it properly

  • Property mode set to 100644
File size: 2.6 KB
Line 
1/*
2 * Copyright (c) 2019 Jiri Svoboda
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
35#include <fibril.h>
36#include <gfx/backend/console.h>
37#include <gfx/color.h>
38#include <gfx/render.h>
39#include <io/console.h>
40#include <stdlib.h>
41
42int main(int argc, char *argv[])
43{
44 console_ctrl_t *con = NULL;
45 gfx_color_t *color = NULL;
46 console_gc_t *cgc = NULL;
47 gfx_context_t *gc;
48 gfx_rect_t rect;
49 int i;
50 errno_t rc;
51
52 printf("Init console..\n");
53 con = console_init(stdin, stdout);
54 if (con == NULL)
55 return 1;
56
57 printf("Create console GC\n");
58 rc = console_gc_create(con, stdout, &cgc);
59 if (rc != EOK)
60 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);
67 if (rc != EOK)
68 return 1;
69
70 rc = gfx_set_color(gc, color);
71 if (rc != EOK)
72 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)
92 return 1;
93
94 return 0;
95}
96
97/** @}
98 */
Note: See TracBrowser for help on using the repository browser.