From 2fadd60c0cd87f87a693111abcac03248899f76a Mon Sep 17 00:00:00 2001 From: ole00 Date: Sun, 13 Jun 2021 12:36:19 +0200 Subject: [PATCH] implemented grid thickness Previously the grid point was only one pixel of size. On hi-dpi screen a single pixel is nearly invisible. This change increases the grid point size dynamically based on the distance between grid points. Signed-off-by: bert --- src/hid/common/hidgl.c | 22 +++++++++++++++++++++- src/hid/common/hidgl.h | 2 +- src/hid/gtk/gtkhid-gl.c | 2 +- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/hid/common/hidgl.c b/src/hid/common/hidgl.c index f785f62e..6983902f 100644 --- a/src/hid/common/hidgl.c +++ b/src/hid/common/hidgl.c @@ -128,12 +128,15 @@ hidgl_set_depth (float depth) * \brief Draw the grid on the 3D canvas */ void -hidgl_draw_grid (BoxType *drawn_area) +hidgl_draw_grid (BoxType *drawn_area, double coord_per_px) { static GLfloat *points = 0; static int npoints = 0; Coord x1, y1, x2, y2, n, i; double x, y; + double pixels; + double grid_px; + double point_size; if (!Settings.DrawGrid) return; /* grid hidden */ @@ -165,6 +168,22 @@ hidgl_draw_grid (BoxType *drawn_area) points = realloc (points, npoints * 3 * sizeof (GLfloat)); } + pixels = (x2 - x1) / coord_per_px; /* visible grid area in pixels */ + grid_px = pixels / n; /* distance between grid dots in pixels */ + point_size = 1.0 + grid_px / 30.0; + /* limit the maximum and minimum size of the grid dot - these should really be taken from settings */ + if (point_size > 4) + { + point_size = 4; + } + else if (point_size < 1) + { + point_size = 1; + } + /* ensure grid point size is an integer value to prevent moira artefacts */ + point_size = (int)(point_size + 0.5); + + glPointSize (point_size); glEnableClientState (GL_VERTEX_ARRAY); glVertexPointer (3, GL_FLOAT, 0, points); @@ -184,6 +203,7 @@ hidgl_draw_grid (BoxType *drawn_area) } glDisableClientState (GL_VERTEX_ARRAY); + glPointSize (1); } #define MAX_PIXELS_ARC_TO_CHORD 0.5 diff --git a/src/hid/common/hidgl.h b/src/hid/common/hidgl.h index 124ba959..9141b064 100644 --- a/src/hid/common/hidgl.h +++ b/src/hid/common/hidgl.h @@ -69,7 +69,7 @@ hidgl_add_triangle (triangle_buffer *buffer, x3, y3, global_depth); } -void hidgl_draw_grid (BoxType *drawn_area); +void hidgl_draw_grid (BoxType *drawn_area, double coord_per_px); void hidgl_set_depth (float depth); void hidgl_draw_line (int cap, Coord width, Coord x1, Coord y1, Coord x2, Coord y2, double scale); void hidgl_draw_arc (Coord width, Coord vx, Coord vy, Coord vrx, Coord vry, Angle start_angle, Angle delta_angle, double scale); diff --git a/src/hid/gtk/gtkhid-gl.c b/src/hid/gtk/gtkhid-gl.c index 475fc8a2..4afd99e6 100644 --- a/src/hid/gtk/gtkhid-gl.c +++ b/src/hid/gtk/gtkhid-gl.c @@ -233,7 +233,7 @@ ghid_draw_grid (BoxType *drawn_area) gport->grid_color.green / 65535., gport->grid_color.blue / 65535.); - hidgl_draw_grid (drawn_area); + hidgl_draw_grid (drawn_area, gport->view.coord_per_px); glDisable (GL_COLOR_LOGIC_OP); } -- 2.11.4.GIT