Changeset 32066f2 in mainline for uspace/app/fontedit/fontedit.c


Ignore:
Timestamp:
2020-08-27T11:24:39Z (4 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
e2776ff
Parents:
20d0098
git-author:
Jiri Svoboda <jiri@…> (2020-08-26 18:34:29)
git-committer:
Jiri Svoboda <jiri@…> (2020-08-27 11:24:39)
Message:

Need to be able to paint in the negative quadrants

File:
1 edited

Legend:

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

    r20d0098 r32066f2  
    5151
    5252enum {
    53         glyph_scale = 8
     53        glyph_scale = 8,
     54        glyph_orig_x = 100,
     55        glyph_orig_y = 100
    5456};
    5557
     
    102104        pos_event_t *event = (pos_event_t *) data;
    103105        font_edit_t *fedit;
     106        int x, y;
    104107
    105108        fedit = (font_edit_t *) widget_get_data(widget);
    106109
    107110        if (event->type == POS_PRESS) {
    108                 gfx_glyph_bmp_setpix(fedit->gbmp, event->hpos / glyph_scale,
    109                     event->vpos / glyph_scale, 1);
     111                x = gfx_coord_div_rneg((int)event->hpos - glyph_orig_x,
     112                    glyph_scale);
     113                y = gfx_coord_div_rneg((int)event->vpos - glyph_orig_y,
     114                    glyph_scale);
     115
     116                printf("x=%d y=%d\n", x, y);
     117                gfx_glyph_bmp_setpix(fedit->gbmp, x, y, 1);
    110118                font_edit_paint(fedit);
    111119        }
     120}
     121
     122/** Convert glyph pixel coordinates to displayed rectangle.
     123 *
     124 * Since we upscale the glyph a pixel in the glyph corresponds to a rectangle
     125 * on the screen.
     126 *
     127 * @param fedit Font editor
     128 * @param x X coordinate in glyph
     129 * @param y Y coordinate in glyph
     130 * @param drect Place to store displayed rectangle coordinates
     131 */
     132static void font_edit_gpix_to_disp(font_edit_t *fedit, int x, int y,
     133    gfx_rect_t *drect)
     134{
     135        (void) fedit;
     136
     137        drect->p0.x = glyph_orig_x + x * glyph_scale;
     138        drect->p0.y = glyph_orig_y + y * glyph_scale;
     139        drect->p1.x = glyph_orig_x + (x + 1) * glyph_scale;
     140        drect->p1.y = glyph_orig_y + (y + 1) * glyph_scale;
    112141}
    113142
     
    120149        gfx_color_t *color = NULL;
    121150        gfx_rect_t rect;
     151        gfx_rect_t grect;
    122152        errno_t rc;
    123         int w, h;
    124153        int x, y;
    125154        int pix;
    126155
    127         w = 50;
    128         h = 50;
    129 
    130156        rc = gfx_color_new_rgb_i16(0xffff, 0xffff, 0xffff, &color);
    131157        if (rc != EOK)
     
    136162                goto error;
    137163
    138         for (y = 0; y < h; y++) {
    139                 for (x = 0; x < w; x++) {
     164        gfx_glyph_bmp_get_rect(fedit->gbmp, &grect);
     165        printf("grect=%d,%d,%d,%d\n", grect.p0.x, grect.p0.y,
     166            grect.p1.x, grect.p1.y);
     167
     168        for (y = grect.p0.y; y < grect.p1.y; y++) {
     169                for (x = grect.p0.x; x < grect.p1.x; x++) {
    140170                        pix = gfx_glyph_bmp_getpix(fedit->gbmp, x, y);
    141171
    142                         rect.p0.x = x * glyph_scale;
    143                         rect.p0.y = y * glyph_scale;
    144                         rect.p1.x = (x + 1) * glyph_scale;
    145                         rect.p1.y = (y + 1) * glyph_scale;
    146 
    147172                        if (pix != 0) {
     173                                font_edit_gpix_to_disp(fedit, x, y, &rect);
     174
    148175                                rc = gfx_fill_rect(fedit->gc, &rect);
    149176                                if (rc != EOK)
     
    154181
    155182        gfx_color_delete(color);
     183
     184        /* Display glyph origin */
     185
     186        rc = gfx_color_new_rgb_i16(0, 0xffff, 0, &color);
     187        if (rc != EOK)
     188                goto error;
     189
     190        rc = gfx_set_color(fedit->gc, color);
     191        if (rc != EOK)
     192                goto error;
     193
     194        font_edit_gpix_to_disp(fedit, 0, 0, &rect);
     195
     196        rc = gfx_fill_rect(fedit->gc, &rect);
     197        if (rc != EOK)
     198                goto error;
     199
     200        gfx_color_delete(color);
     201
    156202        return EOK;
    157203error:
Note: See TracChangeset for help on using the changeset viewer.