Changeset 9259d20 in mainline


Ignore:
Timestamp:
2019-04-16T09:15:55Z (5 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
3e828ea
Parents:
045186b
git-author:
Jiri Svoboda <jiri@…> (2019-04-15 17:15:29)
git-committer:
Jiri Svoboda <jiri@…> (2019-04-16 09:15:55)
Message:

Drawing rectangles in the console

Location:
uspace
Files:
5 added
5 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/gfxdemo/gfxdemo.c

    r045186b r9259d20  
    3333 */
    3434
     35#include <fibril.h>
     36#include <gfx/backend/console.h>
    3537#include <gfx/color.h>
    3638#include <gfx/render.h>
     39#include <io/console.h>
     40#include <stdlib.h>
    3741
    3842int main(int argc, char *argv[])
    3943{
     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;
    4094}
    4195
  • uspace/lib/gfx/Makefile

    r045186b r9259d20  
    3232
    3333SOURCES = \
     34        src/backend/console.c \
    3435        src/color.c \
    3536        src/context.c \
  • uspace/lib/gfx/src/color.c

    r045186b r9259d20  
    3636#include <gfx/color.h>
    3737#include <stdint.h>
     38#include <stdlib.h>
     39#include "private/color.h"
    3840
    3941/** Create new 16-bit per channel RGB color.
     
    5355    gfx_color_t **rcolor)
    5456{
     57        gfx_color_t *color;
     58
     59        color = calloc(1, sizeof(gfx_color_t));
     60        if (color == NULL)
     61                return ENOMEM;
     62
     63        color->r = r;
     64        color->g = g;
     65        color->b = b;
     66
     67        *rcolor = color;
    5568        return EOK;
    5669}
     
    6275void gfx_color_delete(gfx_color_t *color)
    6376{
    64         (void) color;
     77        free(color);
    6578}
    6679
  • uspace/lib/gfx/src/context.c

    r045186b r9259d20  
    6464/** Delete graphics context.
    6565 *
    66  * @param gc Graphics context
     66 * @param gc Graphics context or @c NULL
    6767 */
    6868errno_t gfx_context_delete(gfx_context_t *gc)
    6969{
     70        if (gc == NULL)
     71                return EOK;
     72
    7073        free(gc);
    7174        return EOK;
  • uspace/lib/gfx/test/render.c

    r045186b r9259d20  
    107107}
    108108
    109 errno_t testgc_set_color(void *arg, gfx_color_t *color)
     109static errno_t testgc_set_color(void *arg, gfx_color_t *color)
    110110{
    111111        test_gc_t *tgc = (test_gc_t *) arg;
     
    116116}
    117117
    118 errno_t testgc_fill_rect(void *arg, gfx_rect_t *rect)
     118static errno_t testgc_fill_rect(void *arg, gfx_rect_t *rect)
    119119{
    120120        test_gc_t *tgc = (test_gc_t *) arg;
Note: See TracChangeset for help on using the changeset viewer.