| author | ole00 <ole00@post.cz> | 2021-06-13 10:36:19 (GMT) |
|---|---|---|
| committer | bert <bert.timmerman@xs4all.nl> | 2021-06-13 11:04:23 (GMT) |
| commit | 2fadd60c0cd87f87a693111abcac03248899f76a (patch) (side-by-side diff) | |
| tree | cb2630dedf0690653cc7f130644d92b35c5a3b39 | |
| parent | 40b229b1682d455bb196ca1ab6d8afe77cf9118e (diff) | |
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 <bert.timmerman@xs4all.nl>
| -rw-r--r-- | src/hid/common/hidgl.c | 22 | ||||
| -rw-r--r-- | src/hid/common/hidgl.h | 2 | ||||
| -rw-r--r-- | 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 f785f62..6983902 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 124ba95..9141b06 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 475fc8a..4afd99e 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); } |
