Changeset 32066f2 in mainline
- Timestamp:
- 2020-08-27T11:24:39Z (4 years ago)
- 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)
- Location:
- uspace
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/fontedit/fontedit.c
r20d0098 r32066f2 51 51 52 52 enum { 53 glyph_scale = 8 53 glyph_scale = 8, 54 glyph_orig_x = 100, 55 glyph_orig_y = 100 54 56 }; 55 57 … … 102 104 pos_event_t *event = (pos_event_t *) data; 103 105 font_edit_t *fedit; 106 int x, y; 104 107 105 108 fedit = (font_edit_t *) widget_get_data(widget); 106 109 107 110 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); 110 118 font_edit_paint(fedit); 111 119 } 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 */ 132 static 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; 112 141 } 113 142 … … 120 149 gfx_color_t *color = NULL; 121 150 gfx_rect_t rect; 151 gfx_rect_t grect; 122 152 errno_t rc; 123 int w, h;124 153 int x, y; 125 154 int pix; 126 155 127 w = 50;128 h = 50;129 130 156 rc = gfx_color_new_rgb_i16(0xffff, 0xffff, 0xffff, &color); 131 157 if (rc != EOK) … … 136 162 goto error; 137 163 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++) { 140 170 pix = gfx_glyph_bmp_getpix(fedit->gbmp, x, y); 141 171 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 147 172 if (pix != 0) { 173 font_edit_gpix_to_disp(fedit, x, y, &rect); 174 148 175 rc = gfx_fill_rect(fedit->gc, &rect); 149 176 if (rc != EOK) … … 154 181 155 182 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 156 202 return EOK; 157 203 error: -
uspace/lib/gfx/include/gfx/coord.h
r20d0098 r32066f2 40 40 #include <types/gfx/coord.h> 41 41 42 extern gfx_coord_t gfx_coord_div_rneg(gfx_coord_t, gfx_coord_t); 42 43 extern void gfx_coord2_add(gfx_coord2_t *, gfx_coord2_t *, gfx_coord2_t *); 43 44 extern void gfx_coord2_subtract(gfx_coord2_t *, gfx_coord2_t *, gfx_coord2_t *); -
uspace/lib/gfx/src/coord.c
r20d0098 r32066f2 39 39 #include <stddef.h> 40 40 41 /** Divide @a a by @a b and round towards negative numbers. 42 * 43 * Regular integer division always rounds towards zero. This is not useful 44 * e.g. for scaling down, where we always need to round towards negative 45 * numbers. 46 * 47 * @param a Dividend 48 * @param b Divisor 49 * @return Quotient 50 */ 51 gfx_coord_t gfx_coord_div_rneg(gfx_coord_t a, gfx_coord_t b) 52 { 53 if ((a > 0 && b > 0) || (a < 0 && b < 0)) { 54 /* Result is non-negative, round towards zero */ 55 return a / b; 56 } else { 57 /* Result is negative, round away from zero */ 58 return (a - b + 1) / b; 59 } 60 } 61 41 62 /** Add two vectors. 42 63 * -
uspace/lib/gfxfont/include/gfx/glyph_bmp.h
r20d0098 r32066f2 45 45 extern errno_t gfx_glyph_bmp_save(gfx_glyph_bmp_t *); 46 46 extern void gfx_glyph_bmp_close(gfx_glyph_bmp_t *); 47 extern void gfx_glyph_bmp_get_rect(gfx_glyph_bmp_t *, gfx_rect_t *); 47 48 extern int gfx_glyph_bmp_getpix(gfx_glyph_bmp_t *, gfx_coord_t, gfx_coord_t); 48 49 extern errno_t gfx_glyph_bmp_setpix(gfx_glyph_bmp_t *, gfx_coord_t, -
uspace/lib/gfxfont/src/glyph_bmp.c
r20d0098 r32066f2 165 165 } 166 166 167 /** Get rectangle covered by glyph bitmap. 168 * 169 * @param bmp Glyph bitmap 170 * @param rect Place to store rectangle 171 */ 172 void gfx_glyph_bmp_get_rect(gfx_glyph_bmp_t *bmp, gfx_rect_t *rect) 173 { 174 *rect = bmp->rect; 175 } 176 167 177 /** Get pixel from glyph bitmap. 168 178 *
Note:
See TracChangeset
for help on using the changeset viewer.