From 24a7a3d27bc245bdc1d5011aed0551a27085f0c9 Mon Sep 17 00:00:00 2001 From: Ell Date: Thu, 14 May 2020 23:44:50 +0300 Subject: [PATCH] app: add gimp_display_shell_constrain_angle() ... which constrains an angle to discrete increments in screen space, similarly to gimp_display_shell_constrain_line(). (cherry picked from commit 8c1a277007ec149cfb4ad091d28cb27c32353a85) --- app/display/gimpdisplayshell-utils.c | 20 +++++++++++++++ app/display/gimpdisplayshell-utils.h | 38 +++++++++++++++------------- 2 files changed, 41 insertions(+), 17 deletions(-) diff --git a/app/display/gimpdisplayshell-utils.c b/app/display/gimpdisplayshell-utils.c index 1d4854f93f..8e85e711ef 100644 --- a/app/display/gimpdisplayshell-utils.c +++ b/app/display/gimpdisplayshell-utils.c @@ -89,6 +89,26 @@ gimp_display_shell_constrain_line (GimpDisplayShell *shell, xres, yres); } +gdouble +gimp_display_shell_constrain_angle (GimpDisplayShell *shell, + gdouble angle, + gint n_snap_lines) +{ + gdouble x, y; + + g_return_val_if_fail (GIMP_IS_DISPLAY_SHELL (shell), 0.0); + + x = cos (angle); + y = sin (angle); + + gimp_display_shell_constrain_line (shell, + 0.0, 0.0, + &x, &y, + n_snap_lines); + + return atan2 (y, x); +} + /** * gimp_display_shell_get_line_status: * @status: initial status text. diff --git a/app/display/gimpdisplayshell-utils.h b/app/display/gimpdisplayshell-utils.h index d397ed6a18..3eb52e383b 100644 --- a/app/display/gimpdisplayshell-utils.h +++ b/app/display/gimpdisplayshell-utils.h @@ -19,23 +19,27 @@ #define __GIMP_DISPLAY_SHELL_UTILS_H__ -void gimp_display_shell_get_constrained_line_params (GimpDisplayShell *shell, - gdouble *offset_angle, - gdouble *xres, - gdouble *yres); -void gimp_display_shell_constrain_line (GimpDisplayShell *shell, - gdouble start_x, - gdouble start_y, - gdouble *end_x, - gdouble *end_y, - gint n_snap_lines); -gchar * gimp_display_shell_get_line_status (GimpDisplayShell *shell, - const gchar *status, - const gchar *separator, - gdouble x1, - gdouble y1, - gdouble x2, - gdouble y2); +void gimp_display_shell_get_constrained_line_params (GimpDisplayShell *shell, + gdouble *offset_angle, + gdouble *xres, + gdouble *yres); +void gimp_display_shell_constrain_line (GimpDisplayShell *shell, + gdouble start_x, + gdouble start_y, + gdouble *end_x, + gdouble *end_y, + gint n_snap_lines); +gdouble gimp_display_shell_constrain_angle (GimpDisplayShell *shell, + gdouble angle, + gint n_snap_lines); + +gchar * gimp_display_shell_get_line_status (GimpDisplayShell *shell, + const gchar *status, + const gchar *separator, + gdouble x1, + gdouble y1, + gdouble x2, + gdouble y2); #endif /* __GIMP_DISPLAY_SHELL_UTILS_H__ */