Changeset bea947f in mainline for uspace/lib/guigfx/src/canvas.c


Ignore:
Timestamp:
2020-05-24T17:59:02Z (4 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
b3b00b6
Parents:
ef20a91
Message:

Implement bitmap color key to allow transparent cursor background

This seems to be the simplest solution of them all. It will work
on any bit depth except 1 bit per pixel (monochrome), where we would
need to extend the bitmap with a bit mask instead.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/guigfx/src/canvas.c

    ref20a91 rbea947f  
    197197        gfx_coord2_subtract(&params->rect.p1, &params->rect.p0, &dim);
    198198        cbm->rect = params->rect;
     199        cbm->flags = params->flags;
     200        cbm->key_color = params->key_color;
    199201
    200202        if (alloc == NULL) {
     
    259261        gfx_coord2_t offs;
    260262        gfx_coord2_t dim;
     263        gfx_coord_t x, y;
     264        pixel_t pixel;
    261265
    262266        if (srect0 != NULL)
     
    288292            PIXELMAP_EXTEND_TRANSPARENT_BLACK);
    289293
    290         drawctx_t drawctx;
    291         drawctx_init(&drawctx, cbm->cgc->surface);
    292 
    293         drawctx_set_source(&drawctx, &source);
    294         drawctx_transfer(&drawctx, drect.p0.x, drect.p0.y, dim.x, dim.y);
     294        if ((cbm->flags & bmpf_color_key) == 0) {
     295                drawctx_t drawctx;
     296                drawctx_init(&drawctx, cbm->cgc->surface);
     297
     298                drawctx_set_source(&drawctx, &source);
     299                drawctx_transfer(&drawctx, drect.p0.x, drect.p0.y, dim.x, dim.y);
     300        } else {
     301                for (y = drect.p0.y; y < drect.p1.y; y++) {
     302                        for (x = drect.p0.x; x < drect.p1.x; x++) {
     303                                pixel = source_determine_pixel(&source, x, y);
     304                                if (pixel != cbm->key_color) {
     305                                        surface_put_pixel(cbm->cgc->surface,
     306                                            x, y, pixel);
     307                                }
     308                        }
     309                }
     310        }
    295311
    296312        update_canvas(cbm->cgc->canvas, cbm->cgc->surface);
Note: See TracChangeset for help on using the changeset viewer.