Changeset bea947f in mainline for uspace/lib/congfx/src/console.c


Ignore:
Timestamp:
2020-05-24T17:59:02Z (5 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/congfx/src/console.c

    ref20a91 rbea947f  
    129129        console_gc_t *cgc = NULL;
    130130        gfx_context_t *gc = NULL;
     131        sysarg_t rows;
     132        sysarg_t cols;
    131133        errno_t rc;
    132134
     
    137139        }
    138140
     141        rc = console_get_size(con, &cols, &rows);
     142        if (rc != EOK)
     143                goto error;
     144
    139145        rc = gfx_context_new(&console_gc_ops, cgc, &gc);
    140146        if (rc != EOK)
     
    144150        cgc->con = con;
    145151        cgc->fout = fout;
     152        cgc->rect.p0.x = 0;
     153        cgc->rect.p0.y = 0;
     154        cgc->rect.p1.x = cols;
     155        cgc->rect.p1.y = rows - 1; /* make sure we avoid bottom-right corner */
     156
    146157        *rgc = cgc;
    147158        return EOK;
     
    201212        gfx_coord2_subtract(&params->rect.p1, &params->rect.p0, &dim);
    202213        cbm->rect = params->rect;
     214        cbm->flags = params->flags;
     215        cbm->key_color = params->key_color;
    203216
    204217        if (alloc == NULL) {
     
    256269        gfx_rect_t srect;
    257270        gfx_rect_t drect;
     271        gfx_rect_t crect;
    258272        gfx_coord2_t offs;
    259273
     
    270284        }
    271285
    272         // XXX Add function to translate rectangle
    273286        gfx_rect_translate(&offs, &srect, &drect);
     287        gfx_rect_clip(&drect, &cbm->cgc->rect, &crect);
    274288
    275289        pixelmap.width = cbm->rect.p1.x - cbm->rect.p0.x;
     
    277291        pixelmap.data = cbm->alloc.pixels;
    278292
    279         for (y = drect.p0.y; y < drect.p1.y; y++) {
    280                 console_set_pos(cbm->cgc->con, drect.p0.x, y);
    281 
    282                 for (x = drect.p0.x; x < drect.p1.x; x++) {
    283                         clr = pixelmap_get_pixel(&pixelmap,
    284                             x - offs.x - cbm->rect.p0.x,
    285                             y - offs.y - cbm->rect.p0.y);
    286                         console_set_rgb_color(cbm->cgc->con, clr, clr);
    287 
    288                         rv = fputc('X', cbm->cgc->fout);
    289                         if (rv < 0)
    290                                 return EIO;
    291 
    292                         console_flush(cbm->cgc->con);
     293        if ((cbm->flags & bmpf_color_key) == 0) {
     294                for (y = crect.p0.y; y < crect.p1.y; y++) {
     295                        console_set_pos(cbm->cgc->con, crect.p0.x, y);
     296
     297                        for (x = crect.p0.x; x < crect.p1.x; x++) {
     298                                clr = pixelmap_get_pixel(&pixelmap,
     299                                    x - offs.x - cbm->rect.p0.x,
     300                                    y - offs.y - cbm->rect.p0.y);
     301                                console_set_rgb_color(cbm->cgc->con, clr, clr);
     302
     303                                rv = fputc('X', cbm->cgc->fout);
     304                                if (rv < 0)
     305                                        return EIO;
     306
     307                                console_flush(cbm->cgc->con);
     308                        }
     309                }
     310        } else {
     311                for (y = crect.p0.y; y < crect.p1.y; y++) {
     312                        for (x = crect.p0.x; x < crect.p1.x; x++) {
     313
     314                                clr = pixelmap_get_pixel(&pixelmap,
     315                                    x - offs.x - cbm->rect.p0.x,
     316                                    y - offs.y - cbm->rect.p0.y);
     317                                console_set_rgb_color(cbm->cgc->con, clr, clr);
     318
     319                                if (clr != cbm->key_color) {
     320                                        console_set_pos(cbm->cgc->con, x, y);
     321                                        rv = fputc('X', cbm->cgc->fout);
     322                                        if (rv < 0)
     323                                                return EIO;
     324
     325                                        console_flush(cbm->cgc->con);
     326                                }
     327
     328                        }
    293329                }
    294330        }
Note: See TracChangeset for help on using the changeset viewer.