Changeset e0545de in mainline for uspace/app/gfxdemo/gfxdemo.c


Ignore:
Timestamp:
2019-10-19T10:07:32Z (5 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
d18f3b7
Parents:
dcc4cb31
Message:

Implement bitmaps in canvas GC, demo in gfxdemo

File:
1 edited

Legend:

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

    rdcc4cb31 re0545de  
    3939#include <fibril.h>
    4040#include <guigfx/canvas.h>
     41#include <gfx/bitmap.h>
    4142#include <gfx/color.h>
    4243#include <gfx/render.h>
    4344#include <io/console.h>
     45#include <io/pixelmap.h>
    4446#include <stdlib.h>
    4547#include <str.h>
     
    4951 *
    5052 * @param gc Graphic context
     53 * @param w Width
     54 * @param h Height
    5155 */
    5256static errno_t demo_rects(gfx_context_t *gc, int w, int h)
     
    5458        gfx_color_t *color = NULL;
    5559        gfx_rect_t rect;
    56         int i;
    57         errno_t rc;
    58 
    59         while (true) {
     60        int i, j;
     61        errno_t rc;
     62
     63        for (j = 0; j < 10; j++) {
    6064                rc = gfx_color_new_rgb_i16(rand() % 0x10000, rand() % 0x10000,
    6165                    rand() % 0x10000, &color);
     
    8286                fibril_usleep(500 * 1000);
    8387        }
     88
     89        return EOK;
     90}
     91
     92/** Run bitmap demo on a graphic context.
     93 *
     94 * @param gc Graphic context
     95 * @param w Width
     96 * @param h Height
     97 */
     98static errno_t demo_bitmap(gfx_context_t *gc, int w, int h)
     99{
     100        gfx_bitmap_t *bitmap;
     101        gfx_bitmap_params_t params;
     102        gfx_bitmap_alloc_t alloc;
     103        int i, j;
     104        gfx_coord2_t offs;
     105        gfx_rect_t srect;
     106        errno_t rc;
     107        pixelmap_t pixelmap;
     108
     109        params.rect.p0.x = 0;
     110        params.rect.p0.y = 0;
     111        params.rect.p1.x = w;
     112        params.rect.p1.y = h;
     113
     114        rc = gfx_bitmap_create(gc, &params, NULL, &bitmap);
     115        if (rc != EOK)
     116                return rc;
     117
     118        rc = gfx_bitmap_get_alloc(bitmap, &alloc);
     119        if (rc != EOK)
     120                return rc;
     121
     122        /* Fill bitmap with something. In absence of anything else, use pixelmap */
     123        pixelmap.width = w;
     124        pixelmap.height = h;
     125        pixelmap.data = alloc.pixels;
     126
     127        for (i = 0; i < w; i++) {
     128                for (j = 0; j < h; j++) {
     129                        pixelmap_put_pixel(&pixelmap, i, j,
     130                            PIXEL(255, (i % 30) < 3 ? 255 : 0,
     131                            (j % 30) < 3 ? 255 : 0, i / 2));
     132                }
     133        }
     134
     135        for (j = 0; j < 10; j++) {
     136                for (i = 0; i < 5; i++) {
     137                        srect.p0.x = rand() % (w - 40);
     138                        srect.p0.y = rand() % (h - 40);
     139                        srect.p1.x = srect.p0.x + rand() % (w - srect.p0.x);
     140                        srect.p1.y = srect.p0.y + rand() % (h - srect.p0.y);
     141                        offs.x = rand() % (w - srect.p1.x);
     142                        offs.y = rand() % (h - srect.p1.y);
     143                        offs.x = 0;
     144                        offs.y = 0;
     145
     146                        gfx_bitmap_render(bitmap, &srect, &offs);
     147                        fibril_usleep(500 * 1000);
     148                }
     149        }
     150
     151        gfx_bitmap_destroy(bitmap);
     152
     153        return EOK;
     154}
     155
     156/** Run demo loop on a graphic context.
     157 *
     158 * @param gc Graphic context
     159 * @param w Width
     160 * @param h Height
     161 */
     162static errno_t demo_loop(gfx_context_t *gc, int w, int h)
     163{
     164        errno_t rc;
     165
     166        while (true) {
     167                rc = demo_rects(gc, w, h);
     168                if (rc != EOK)
     169                        return rc;
     170
     171                rc = demo_bitmap(gc, w, h);
     172                if (rc != EOK)
     173                        return rc;
     174        }
    84175}
    85176
     
    104195        gc = console_gc_get_ctx(cgc);
    105196
    106         rc = demo_rects(gc, 80, 25);
     197        rc = demo_loop(gc, 80, 25);
    107198        if (rc != EOK)
    108199                return rc;
     
    168259        gc = canvas_gc_get_ctx(cgc);
    169260
    170         rc = demo_rects(gc, 400, 300);
     261        rc = demo_loop(gc, 400, 300);
    171262        if (rc != EOK)
    172263                return rc;
     
    206297        }
    207298
    208         rc = demo_rects(gc, 400, 300);
     299        rc = demo_loop(gc, 400, 300);
    209300        if (rc != EOK)
    210301                return rc;
Note: See TracChangeset for help on using the changeset viewer.