diff --git a/kitty/graphics.h b/kitty/graphics.h index 55015e88a..daad0bb45 100644 --- a/kitty/graphics.h +++ b/kitty/graphics.h @@ -121,6 +121,24 @@ typedef struct { bool has_margins; } ScrollData; + +static inline float +gl_size(const unsigned int sz, const unsigned int viewport_size) { + // convert pixel sz to OpenGL co-ordinate system. + const float px = 2.f / viewport_size; + return px * sz; +} + +static inline float +clamp_position_to_nearest_pixel(float pos, const unsigned int viewport_size) { + // clamp the specified opengl position to the nearest pixel + const float px = 2.f / viewport_size; + const float distance = pos + 1.f; + const float num_of_pixels = roundf(distance / px); + return -1.f + num_of_pixels * px; +} + + GraphicsManager* grman_alloc(void); void grman_clear(GraphicsManager*, bool, CellPixelSize fg); const char* grman_handle_command(GraphicsManager *self, const GraphicsCommand *g, const uint8_t *payload, Cursor *c, bool *is_dirty, CellPixelSize fg); diff --git a/kitty/shaders.c b/kitty/shaders.c index d32cfd0c1..1a57826ff 100644 --- a/kitty/shaders.c +++ b/kitty/shaders.c @@ -588,24 +588,6 @@ render_window_title(OSWindow *os_window, Screen *screen UNUSED, GLfloat xstart, return 2.f * (GLfloat)bar_height / (GLfloat)os_window->viewport_height; } -static GLfloat -gl_size(const unsigned int sz, const unsigned int viewport_size) { - // convert sz to OpenGL co-ordinate system. Checks that mapping back via roundf() - // yields the same value. - const GLfloat px = 2.f / viewport_size; - GLfloat ans = px * sz; - const unsigned int mapped_val = (unsigned int)roundf((ans * viewport_size) / 2.f); - return ans + px * (sz - mapped_val); -} - -static GLfloat -clamp_position_to_nearest_pixel(GLfloat pos, const unsigned int viewport_size) { - const GLfloat px = 2.f / viewport_size; - const GLfloat distance = pos + 1.f; - const GLfloat num_of_pixels = roundf(distance / px); - return -1.f + num_of_pixels * px; -} - static void draw_window_logo(ssize_t vao_idx, OSWindow *os_window, const WindowLogoRenderData *wl, const CellRenderData *crd) { if (os_window->live_resize.in_progress) return;