[045186b] | 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 |
|
---|
[9259d20] | 35 | #include <fibril.h>
|
---|
| 36 | #include <gfx/backend/console.h>
|
---|
[045186b] | 37 | #include <gfx/color.h>
|
---|
| 38 | #include <gfx/render.h>
|
---|
[9259d20] | 39 | #include <io/console.h>
|
---|
| 40 | #include <stdlib.h>
|
---|
[045186b] | 41 |
|
---|
| 42 | int main(int argc, char *argv[])
|
---|
| 43 | {
|
---|
[9259d20] | 44 | console_ctrl_t *con = NULL;
|
---|
| 45 | gfx_color_t *color = NULL;
|
---|
| 46 | gfx_context_t *gc = NULL;
|
---|
| 47 | gfx_rect_t rect;
|
---|
| 48 | int i;
|
---|
| 49 | errno_t rc;
|
---|
| 50 |
|
---|
| 51 | printf("Init console..\n");
|
---|
| 52 | con = console_init(stdin, stdout);
|
---|
| 53 | if (con == NULL)
|
---|
| 54 | return 1;
|
---|
| 55 |
|
---|
| 56 | printf("Create console GC\n");
|
---|
| 57 | rc = console_gc_create(con, stdout, &gc);
|
---|
| 58 | if (rc != EOK)
|
---|
| 59 | return 1;
|
---|
| 60 |
|
---|
| 61 | while (true) {
|
---|
| 62 | rc = gfx_color_new_rgb_i16(rand() % 0x10000, rand() % 0x10000,
|
---|
| 63 | rand() % 0x10000, &color);
|
---|
| 64 | if (rc != EOK)
|
---|
| 65 | return 1;
|
---|
| 66 |
|
---|
| 67 | rc = gfx_set_color(gc, color);
|
---|
| 68 | if (rc != EOK)
|
---|
| 69 | return 1;
|
---|
| 70 |
|
---|
| 71 | for (i = 0; i < 10; i++) {
|
---|
| 72 | rect.p0.x = rand() % 79;
|
---|
| 73 | rect.p0.y = rand() % 24;
|
---|
| 74 | rect.p1.x = rect.p0.x + rand() % (79 - rect.p0.x);
|
---|
| 75 | rect.p1.y = rect.p0.y + rand() % (24 - rect.p0.y);
|
---|
| 76 |
|
---|
| 77 | rc = gfx_fill_rect(gc, &rect);
|
---|
| 78 | if (rc != EOK)
|
---|
| 79 | return 1;
|
---|
| 80 | }
|
---|
| 81 |
|
---|
| 82 | gfx_color_delete(color);
|
---|
| 83 |
|
---|
| 84 | fibril_usleep(500 * 1000);
|
---|
| 85 | }
|
---|
| 86 |
|
---|
| 87 | // TODO How will we free GC subclass?
|
---|
| 88 |
|
---|
| 89 | // rc = gfx_context_delete(gc);
|
---|
| 90 | // if (rc != EOK)
|
---|
| 91 | // return 1;
|
---|
| 92 |
|
---|
| 93 | return 0;
|
---|
[045186b] | 94 | }
|
---|
| 95 |
|
---|
| 96 | /** @}
|
---|
| 97 | */
|
---|