Skip to content

Commit ea5e8a5

Browse files
committed
snapshot: properly light-up rotation symbol when close.
Fixes #19120.
1 parent bc6372d commit ea5e8a5

File tree

1 file changed

+44
-8
lines changed

1 file changed

+44
-8
lines changed

src/libs/snapshots.c

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ typedef struct dt_lib_snapshots_t
7979
gboolean dragging, vertical, inverted, panning, sidebyside;
8080
double vp_width, vp_height, vp_xpointer, vp_ypointer, vp_xrotate, vp_yrotate;
8181
gboolean on_going;
82+
gboolean rotsym_lightup;
8283

8384
GtkWidget *take_button, *sidebyside_button;
8485
} dt_lib_snapshots_t;
@@ -178,6 +179,35 @@ static gboolean _snap_expose_again(gpointer user_data)
178179
return FALSE;
179180
}
180181

182+
/* check if (x,y) closer to rotation sym than area_size. Set the size of area s
183+
and the center of the sym (rx, ry). Return TRUE if (x,y) in sym area. */
184+
static inline gboolean _get_rotation_area(dt_lib_module_t *self,
185+
const int32_t x,
186+
const int32_t y,
187+
double *s,
188+
gint *rx,
189+
gint *ry)
190+
{
191+
dt_lib_snapshots_t *d = self->data;
192+
193+
const double _s = fmin(24, d->vp_width * HANDLE_SIZE);
194+
const gint _rx = (d->vertical
195+
? d->vp_width * d->vp_xpointer
196+
: d->vp_width * 0.5) - (_s * 0.5);
197+
const gint _ry = (d->vertical
198+
? d->vp_height * 0.5
199+
: d->vp_height * d->vp_ypointer) - (_s * 0.5);
200+
201+
if(s) *s = _s;
202+
if(rx) *rx = _rx;
203+
if(ry) *ry = _ry;
204+
205+
const int area_size = 40;
206+
207+
// rotation symbol is light-up or light-off when moving close.
208+
return (abs(x - _rx) < area_size) && (abs(y - _ry) < area_size);
209+
}
210+
181211
/* expose snapshot over center viewport */
182212
void gui_post_expose(dt_lib_module_t *self,
183213
cairo_t *cri,
@@ -336,15 +366,13 @@ void gui_post_expose(dt_lib_module_t *self,
336366
/* if mouse over control lets draw center rotate control, hide if split is dragged */
337367
if(!d->dragging && !d->sidebyside)
338368
{
339-
const double s = fmin(24, width * HANDLE_SIZE);
340-
const gint rx = (d->vertical ? width * d->vp_xpointer : width * 0.5) - (s * 0.5);
341-
const gint ry = (d->vertical ? height * 0.5 : height * d->vp_ypointer) - (s * 0.5);
369+
double s = 0.0;
370+
gint rx = 0;
371+
gint ry = 0;
342372

343-
const gboolean display_rotation =
344-
(abs(pointerx - rx) < 40)
345-
&& (abs(pointery - ry) < 40);
373+
d->rotsym_lightup = _get_rotation_area(self, pointerx, pointery, &s, &rx, &ry);
346374

347-
dt_draw_set_color_overlay(cri, TRUE, display_rotation ? 1.0 : 0.3);
375+
dt_draw_set_color_overlay(cri, TRUE, d->rotsym_lightup ? 1.0 : 0.3);
348376

349377
cairo_set_line_width(cri, 0.5);
350378
dtgtk_cairo_paint_refresh(cri, rx, ry, s, s, 0, NULL);
@@ -469,8 +497,15 @@ int mouse_moved(dt_lib_module_t *self,
469497
{
470498
d->vp_xpointer = xp;
471499
d->vp_ypointer = yp;
472-
dt_control_queue_redraw_center();
473500
}
501+
502+
// Here to ensure the rotation symbol is light-up or light-off
503+
// when moving close.
504+
const gboolean display_rotation = _get_rotation_area(self, x, y, NULL, NULL, NULL);
505+
506+
if(d->dragging || display_rotation != d->rotsym_lightup)
507+
dt_control_queue_redraw_center();
508+
474509
return 1;
475510
}
476511

@@ -759,6 +794,7 @@ void gui_init(dt_lib_module_t *self)
759794
d->vp_yrotate = 0.0;
760795
d->vertical = TRUE;
761796
d->on_going = FALSE;
797+
d->rotsym_lightup = FALSE;
762798
d->panning = FALSE;
763799
d->selected = -1;
764800
d->snap_requested = FALSE;

0 commit comments

Comments
 (0)