lite-xl icon indicating copy to clipboard operation
lite-xl copied to clipboard

Improve initial scale calculation

Open jgmdev opened this issue 2 years ago • 5 comments

This PR modifies the get_scale() C function used on main to calculate the initical scale by using a base width and height which works better than current strategy based on the dpi value returned by sdl, 1280x720 was chosen as base because it is legible with the default font size of 15, here a comparison of before and after on differently tested resolutions:

1400x900 before 1400x900-by-dpi

1400x900 after 1400x900-by-bw

1600x900 before 1600x900-by-dpi

1600x900 after 1600x900-by-bw

1920x1080 before 1920x1080-by-dpi

1920x1080 after 1920x1080-by-bw

jgmdev avatar May 26 '22 19:05 jgmdev

Yeah; this calculation has always been a little messed up. I think this something like this is the way to go; as so many people seem to have issues with the current function.

adamharrison avatar May 26 '22 19:05 adamharrison

I wonder if we should drop the dpi fall back and also allow the base resolution calculation for mac too

jgmdev avatar May 26 '22 19:05 jgmdev

Reminder note: non sdl renderer gets broken with float Rect and the ~~improve unstable text y axis on fractional scales~~ commit which needs to be reverted for it to work and something like the following to get both SDL Renderer and non sdl renderer working.

+#ifdef LITE_USE_SDL_RENDERER
+#define RECT_TYPE float
+#else
+#define RECT_TYPE int
+#endif
+
 #define FONT_FALLBACK_MAX 4
 typedef struct RenFont RenFont;
 typedef enum { FONT_HINTING_NONE, FONT_HINTING_SLIGHT, FONT_HINTING_FULL } ERenFontHinting;
 typedef enum { FONT_ANTIALIASING_NONE, FONT_ANTIALIASING_GRAYSCALE, FONT_ANTIALIASING_SUBPIXEL } ERenFontAntialiasing;
 typedef enum { FONT_STYLE_BOLD = 1, FONT_STYLE_ITALIC = 2, FONT_STYLE_UNDERLINE = 4 } ERenFontStyle;
 typedef struct { uint8_t b, g, r, a; } RenColor;
-typedef struct { float x, y, width, height; } RenRect;
+typedef struct { RECT_TYPE x, y, width, height; } RenRect;

jgmdev avatar May 29 '22 09:05 jgmdev

Reminder note: resizing the window fetches new scale which most of the time differs by a minimal change in decimal points when doing fractional scaling, but this is enough to cause jumpy text each time the window is resized, a change as follows only applies a new scale if different enough which eliminates the jumpy text at least on window resizing:

static float scale_x = 0, scale_y = 0;
static void update_surface_scale(RenWindow *ren) {
  /* cache the scale to prevent jumpy text on resizing */
  if (scale_x <= 0) {
    int w_pixels, h_pixels;
    int w_points, h_points;
    SDL_GL_GetDrawableSize(ren->window, &w_pixels, &h_pixels);
    SDL_GetWindowSize(ren->window, &w_points, &h_points);
    float temp_scale_x = (float) w_pixels / (float) w_points;
    float temp_scale_y = (float) h_pixels / (float) h_points;
    if (roundf(temp_scale_x * 100) != roundf(scale_x * 100)) {
      scale_x = temp_scale_x;
      scale_y = temp_scale_y;
    }
  }
  ren->surface_scale_x = scale_x;
  ren->surface_scale_y = scale_y;
}

jgmdev avatar May 30 '22 03:05 jgmdev

Removed the improve unstable text y axis on fractional scales commit and added other minor changes for more pristine renderer near to what we had before which still works with non sdl renderer. So next step is to properly trouble shoot the root cause of the jumpy text on y axis when a fractional scale is been used on window resize and scroll.

jgmdev avatar May 30 '22 19:05 jgmdev