From 4c681c40fd37bb0cc1e76f7addba49688dcbf923 Mon Sep 17 00:00:00 2001 From: Kp Date: Sat, 4 Sep 2021 12:17:14 +0000 Subject: [PATCH] Factor out the slider font smoothing hack Move the test from the innermost loop to one layer farther out, since it was conditional on two specific passes of the innermost loop. --- similar/2d/font.cpp | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/similar/2d/font.cpp b/similar/2d/font.cpp index fe9af5654..af7fa2194 100644 --- a/similar/2d/font.cpp +++ b/similar/2d/font.cpp @@ -545,14 +545,13 @@ static void ogl_init_font(grs_font * font) for (const auto y : xrange(h)) { for (const auto x : xrange(w)) - { font->ft_parent_bitmap.get_bitmap_data()[curx+x+(cury+y)*tw] = fp[x+y*w]; // Let's call this a HACK: // If we filter the fonts, the sliders will be messed up as the border pixels will have an // alpha value while filtering. So the slider bitmaps will not look "connected". // To prevent this, duplicate the first/last pixel-row with a 1-pixel offset. - if (gap && i >= 99 && i <= 102) - { + if (gap && i >= 99 && i <= 102) + { // See which bitmaps need left/right shifts: // 99 = SLIDER_LEFT - shift RIGHT // 100 = SLIDER_RIGHT - shift LEFT @@ -560,13 +559,21 @@ static void ogl_init_font(grs_font * font) // 102 = SLIDER_MARKER - shift RIGHT // shift left border - if (x==0 && i != 99 && i != 102) - font->ft_parent_bitmap.get_bitmap_data()[(curx+x+(cury+y)*tw)-1] = fp[x+y*w]; - - // shift right border - if (x==w-1 && i != 100) - font->ft_parent_bitmap.get_bitmap_data()[(curx+x+(cury+y)*tw)+1] = fp[x+y*w]; + std::size_t oi, ii; + if (i != 99 && i != 102) + { + oi = (curx + (cury + y) * tw) - 1; + ii = y * w; } + // shift right border + else if (i != 100) + { + oi = (curx + (w - 1) + (cury + y) * tw) + 1; + ii = (w - 1) + y * w; + } + else + continue; + font->ft_parent_bitmap.get_bitmap_data()[oi] = fp[ii]; } } }