diff options
author | infirit <[email protected]> | 2015-09-07 01:41:47 +0200 |
---|---|---|
committer | infirit <[email protected]> | 2015-09-07 02:52:53 +0200 |
commit | 2997a9df6be9444e8d29541ae87a46e93552992f (patch) | |
tree | 854bde340458865eb70a51f3e692cfc1bc0b1a8e | |
parent | 81b2a5edf60e51eea7906663d34a5fd3d68726d3 (diff) | |
download | libmatekbd-2997a9df6be9444e8d29541ae87a46e93552992f.tar.bz2 libmatekbd-2997a9df6be9444e8d29541ae87a46e93552992f.tar.xz |
Improved cooords for labels - consider complex outlines
taken from libgnomekbd,
commit: 378d768da68f9b6efce80081bb1c4c8729a4f7b9
from: Sergey V. Udaltsov <[email protected]>
gnome bug: https://bugzilla.gnome.org/show_bug.cgi?id=640425
-rw-r--r-- | libmatekbd/matekbd-keyboard-drawing.c | 36 |
1 files changed, 32 insertions, 4 deletions
diff --git a/libmatekbd/matekbd-keyboard-drawing.c b/libmatekbd/matekbd-keyboard-drawing.c index 7ef81df..7883c99 100644 --- a/libmatekbd/matekbd-keyboard-drawing.c +++ b/libmatekbd/matekbd-keyboard-drawing.c @@ -1003,6 +1003,31 @@ draw_key_label (MatekbdKeyboardDrawingRenderContext * context, } } +/** + The x offset is calculated for complex shapes. It is the rightmost of the vertical lines in the outline + */ +static gint +calc_origin_offset_x (XkbOutlineRec * outline) +{ + gint rv = 0; + gint i; + if (outline->num_points < 3) + return 0; + XkbPointPtr point = outline->points; + for (i = outline->num_points; --i > 0;) { + gint x1 = point->x; + gint y1 = point++->y; + gint x2 = point->x; + gint y2 = point->y; + + /*vertical, bottom to top (clock-wise), on the left */ + if ((x1 == x2) && (y1 > y2) && (x1 > rv)) { + rv = x1; + } + } + return rv; +} + /* groups are from 0-3 */ static void draw_key (MatekbdKeyboardDrawingRenderContext * context, @@ -1010,6 +1035,8 @@ draw_key (MatekbdKeyboardDrawingRenderContext * context, { XkbShapeRec *shape; GdkColor *color; + XkbOutlineRec *outline; + int origin_offset_x; /* gint i; */ if (!drawing->xkb) @@ -1038,9 +1065,9 @@ draw_key (MatekbdKeyboardDrawingRenderContext * context, #endif /* draw the primary outline */ - draw_outline (context, - shape->primary ? shape->primary : shape->outlines, - color, key->angle, key->origin_x, key->origin_y); + outline = shape->primary ? shape->primary : shape->outlines; + draw_outline (context, outline, color, key->angle, key->origin_x, + key->origin_y); #if 0 /* don't draw other outlines for now, since * the text placement does not take them into account @@ -1054,8 +1081,9 @@ draw_key (MatekbdKeyboardDrawingRenderContext * context, } #endif + origin_offset_x = calc_origin_offset_x (outline); draw_key_label (context, drawing, key->keycode, key->angle, - key->origin_x, key->origin_y, + key->origin_x + origin_offset_x, key->origin_y, shape->bounds.x2, shape->bounds.y2); } |