16#include <fmt/format.h>
76 switch (modal_state) {
176 if (wait_for_input) {
203 switch (event->
val) {
236 switch (event->
type) {
242 else if (gesture->
move) {
257#ifdef WITH_INPUT_NDOF
369 bool is_circle_size =
false;
370 bool is_finished =
false;
373 switch (event->
val) {
375 fac = 0.3f * (
event->xy[1] -
event->prev_xy[1]);
382 rect->
xmax = std::max(rect->
xmax, 1);
383 is_circle_size =
true;
387 is_circle_size =
true;
391 rect->
xmax = std::max(rect->
xmax, 1);
392 is_circle_size =
true;
424 if (is_circle_size) {
431#ifdef WITH_INPUT_NDOF
460 ot->name =
"Circle Gesture";
461 ot->idname =
"WM_OT_circle_gesture";
462 ot->description =
"Enter rotate mode with a circular gesture";
535 const float *lasso =
static_cast<const float *
>(gesture->
customdata);
540 for (
i = 0;
i < gesture->
points;
i++, lasso += 2) {
564 switch (event->
val) {
572 switch (event->
type) {
588 const float2 last_position(lasso[gesture->
points - 1][0], lasso[gesture->
points - 1][1]);
590 const float2 delta = current_mouse_position - last_position;
595 for (
int i = 0;
i < gesture->
points;
i++) {
596 lasso[
i][0] += delta.
x;
597 lasso[
i][1] += delta.
y;
601 if (dist_squared >
square_f(radius)) {
603 current_mouse_position, last_position, factor);
675 mcoords[
i] =
int2(loc[0], loc[1]);
692 printf(
"Location: %f %f\n", loc[0], loc[1]);
703 ot->name =
"Lasso Gesture";
704 ot->idname =
"WM_OT_lasso_gesture";
705 ot->description =
"Draw a shape defined by the cursor";
709 ot->exec = gesture_lasso_exec;
755 if (is_click_submitted) {
761 const short prev_x = points[num_points - 1][0];
762 const short prev_y = points[num_points - 1][1];
782 if (valid_points <= 2) {
791 const bool is_click_submitted)
797 const short *border =
static_cast<const short int *
>(gesture->
customdata);
802 for (
int i = 0;
i < gesture->
points;
i++, border += 2) {
808 if (valid_points > gesture->
points) {
809 loc[0] = gesture->
mval.x;
810 loc[1] = gesture->
mval.y;
831 switch (event->
val) {
837 short (*border)[2] =
static_cast<short int (*)[2]
>(gesture->
customdata);
838 const short prev_x = border[gesture->
points - 1][0];
839 const short prev_y = border[gesture->
points - 1][1];
841 if (gesture->
mval.x == prev_x && gesture->
mval.y == prev_y) {
846 const float2 orig(border[0][0], border[0][1]);
848 const float dist =
len_v2v2(cur, orig);
857 border[gesture->
points - 1][0] = gesture->
mval.x;
858 border[gesture->
points - 1][1] = gesture->
mval.y;
872 switch (event->
type) {
883 short (*border)[2] =
static_cast<short int (*)[2]
>(gesture->
customdata);
887 const int dx = gesture->mval.x - border[gesture->points - 1][0];
888 const int dy = gesture->mval.y - border[gesture->points - 1][1];
890 for (int i = 0; i < gesture->points; i++) {
920 printf(
"Location: %f %f\n", loc[0], loc[1]);
931 ot->name =
"Polyline Gesture";
932 ot->idname =
"WM_OT_polyline_gesture";
933 ot->description =
"Outline a selection area with each mouse click";
937 ot->exec = gesture_polyline_exec;
1042 const float x_axis[2] = {1.0f, 0.0f};
1044 float line_direction[2];
1045 sub_v2_v2v2(line_direction, line_end, line_start);
1046 const float line_length =
normalize_v2(line_direction);
1049 const float adjusted_angle = current_angle + (snap_angle / 2.0f);
1050 const float angle_snapped = -
floorf(adjusted_angle / snap_angle) * snap_angle;
1052 float line_snapped_end[2];
1054 mul_v2_fl(line_snapped_end, line_length);
1055 add_v2_v2(line_snapped_end, line_start);
1057 rect->
xmax = int(line_snapped_end[0]);
1058 rect->
ymax = int(line_snapped_end[1]);
1069 int ylen = rect->
ymax - rect->
ymin;
1070 if (
abs(ylen) != xlen) {
1071 ylen = xlen * (ylen >= 0 ? 1 : -1);
1088 switch (event->
val) {
1127 switch (event->
type) {
1133 else if (gesture->
move) {
1177 switch (event->
val) {
1221 switch (event->
type) {
1227 else if (gesture->
move) {
1266 ot->name =
"Straight Line Gesture";
1267 ot->idname =
"WM_OT_straightline_gesture";
1268 ot->description =
"Draw a straight line defined by the cursor";
1272 ot->exec = gesture_straightline_exec;
ScrArea * CTX_wm_area(const bContext *C)
wmWindow * CTX_wm_window(const bContext *C)
Scene * CTX_data_scene(const bContext *C)
ARegion * CTX_wm_region(const bContext *C)
MINLINE int min_ii(int a, int b)
MINLINE float pow2f(float x)
MINLINE int max_ii(int a, int b)
MINLINE float square_f(float a)
MINLINE int compare_ff(float a, float b, float max_diff)
MINLINE float len_v2v2(const float v1[2], const float v2[2]) ATTR_WARN_UNUSED_RESULT
MINLINE void mul_v2_fl(float r[2], float f)
MINLINE void add_v2_v2(float r[2], const float a[2])
float angle_signed_v2v2(const float v1[2], const float v2[2]) ATTR_WARN_UNUSED_RESULT
MINLINE void sub_v2_v2v2(float r[2], const float a[2], const float b[2])
MINLINE float normalize_v2(float n[2])
void rotate_v2_v2fl(float r[2], const float p[2], float angle)
void BLI_rcti_translate(struct rcti *rect, int x, int y)
#define UNUSED_FUNCTION(x)
#define OPERATOR_RETVAL_CHECK(ret)
void ED_area_tag_redraw(ScrArea *area)
Read Guarded memory(de)allocation.
#define MEM_reallocN(vmemh, len)
#define RNA_BEGIN(sptr, itemptr, propname)
#define RNA_PROP_BEGIN(sptr, itemptr, prop)
#define WM_GESTURE_STRAIGHTLINE
@ OPTYPE_DEPENDS_ON_CURSOR
#define WM_GESTURE_CIRCLE
#define WM_GESTURE_CROSS_RECT
#define WM_GESTURE_POLYLINE
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
T length_squared(const VecBase< T, Size > &a)
T interpolate(const T &a, const T &b, const FactorT &t)
constexpr float POLYLINE_CLICK_RADIUS
VecBase< int32_t, 2 > int2
VecBase< float, 2 > float2
void RNA_collection_clear(PointerRNA *ptr, const char *name)
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
void RNA_boolean_set(PointerRNA *ptr, const char *name, bool value)
bool RNA_property_is_set(PointerRNA *ptr, PropertyRNA *prop)
void RNA_int_set(PointerRNA *ptr, const char *name, int value)
void RNA_property_enum_set(PointerRNA *ptr, PropertyRNA *prop, int value)
void RNA_float_get_array(PointerRNA *ptr, const char *name, float *values)
bool RNA_property_boolean_get(PointerRNA *ptr, PropertyRNA *prop)
int RNA_property_int_get(PointerRNA *ptr, PropertyRNA *prop)
void RNA_collection_add(PointerRNA *ptr, const char *name, PointerRNA *r_value)
int RNA_int_get(PointerRNA *ptr, const char *name)
void RNA_property_boolean_set(PointerRNA *ptr, PropertyRNA *prop, bool value)
float RNA_float_get(PointerRNA *ptr, const char *name)
int RNA_property_enum_get(PointerRNA *ptr, PropertyRNA *prop)
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
void RNA_float_set_array(PointerRNA *ptr, const char *name, const float *values)
int RNA_property_collection_length(PointerRNA *ptr, PropertyRNA *prop)
void RNA_def_property_struct_runtime(StructOrFunctionRNA *cont, PropertyRNA *prop, StructRNA *type)
PropertyRNA * RNA_def_property(StructOrFunctionRNA *cont_, const char *identifier, int type, int subtype)
struct ToolSettings * toolsettings
wmOperatorStatus(* exec)(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
struct wmOperatorType * type
void WM_cursor_modal_set(wmWindow *win, int val)
void WM_cursor_modal_restore(wmWindow *win)
bool WM_event_is_mouse_drag_or_press(const wmEvent *event)
wmEventHandler_Op * WM_event_add_modal_handler(bContext *C, wmOperator *op)
@ GESTURE_MODAL_CIRCLE_SIZE
@ GESTURE_MODAL_CIRCLE_ADD
@ GESTURE_MODAL_CIRCLE_SUB
wmGesture * WM_gesture_new(wmWindow *window, const ARegion *region, const wmEvent *event, int type)
void wm_gesture_tag_redraw(wmWindow *win)
void WM_gesture_end(wmWindow *win, wmGesture *gesture)
static int UNUSED_FUNCTION gesture_modal_state_from_operator(wmOperator *op)
void WM_gesture_box_cancel(bContext *C, wmOperator *op)
static SnapAngle get_snap_angle(const ScrArea &area, const ToolSettings &tool_settings)
static bool gesture_box_apply(bContext *C, wmOperator *op)
wmOperatorStatus WM_gesture_polyline_modal(bContext *C, wmOperator *op, const wmEvent *event)
static wmOperatorStatus gesture_lasso_apply(bContext *C, wmOperator *op)
wmOperatorStatus WM_gesture_circle_invoke(bContext *C, wmOperator *op, const wmEvent *event)
static void gesture_modal_end(bContext *C, wmOperator *op)
Array< int2 > WM_gesture_lasso_path_to_array(bContext *, wmOperator *op)
void WM_gesture_straightline_cancel(bContext *C, wmOperator *op)
wmOperatorStatus WM_gesture_lasso_modal(bContext *C, wmOperator *op, const wmEvent *event)
void WM_gesture_polyline_cancel(bContext *C, wmOperator *op)
void WM_gesture_lines_cancel(bContext *C, wmOperator *op)
wmOperatorStatus WM_gesture_box_modal(bContext *C, wmOperator *op, const wmEvent *event)
wmOperatorStatus WM_gesture_box_invoke(bContext *C, wmOperator *op, const wmEvent *event)
static bool gesture_polyline_can_apply(const wmGesture &wmGesture, const bool is_click_submitted)
static bool gesture_straightline_apply(bContext *C, wmOperator *op)
void WM_gesture_circle_cancel(bContext *C, wmOperator *op)
wmOperatorStatus WM_gesture_straightline_active_side_invoke(bContext *C, wmOperator *op, const wmEvent *event)
static void gesture_circle_apply(bContext *C, wmOperator *op)
static void wm_gesture_straightline_do_angle_snap(rcti *rect, float snap_angle)
wmOperatorStatus WM_gesture_lines_modal(bContext *C, wmOperator *op, const wmEvent *event)
wmOperatorStatus WM_gesture_lines_invoke(bContext *C, wmOperator *op, const wmEvent *event)
static bool gesture_box_apply_rect(wmOperator *op)
wmOperatorStatus WM_gesture_polyline_invoke(bContext *C, wmOperator *op, const wmEvent *event)
void WM_gesture_lasso_cancel(bContext *C, wmOperator *op)
wmOperatorStatus WM_gesture_straightline_invoke(bContext *C, wmOperator *op, const wmEvent *event)
static void gesture_modal_state_to_operator(wmOperator *op, int modal_state)
static int gesture_polyline_valid_points(const wmGesture &wmGesture, const bool is_click_submitted)
wmOperatorStatus WM_gesture_circle_modal(bContext *C, wmOperator *op, const wmEvent *event)
wmOperatorStatus WM_gesture_lasso_invoke(bContext *C, wmOperator *op, const wmEvent *event)
static wmOperatorStatus gesture_polyline_apply(bContext *C, wmOperator *op, const bool is_click_submitted)
wmOperatorStatus WM_gesture_straightline_oneshot_modal(bContext *C, wmOperator *op, const wmEvent *event)
wmOperatorStatus WM_gesture_straightline_modal(bContext *C, wmOperator *op, const wmEvent *event)
void WM_operator_properties_gesture_straightline(wmOperatorType *ot, int cursor)
void WM_operator_properties_gesture_polyline(wmOperatorType *ot)
void WM_operator_properties_gesture_circle(wmOperatorType *ot)
bool WM_operator_winactive(bContext *C)