16#include <fmt/format.h>
44#define GESTURE_EDGE_PAN_INSIDE_PAD 2
45#define GESTURE_EDGE_PAN_OUTSIDE_PAD 0
46#define GESTURE_EDGE_PAN_SPEED_RAMP 1.0f
47#define GESTURE_EDGE_PAN_MAX_SPEED 26.0f
48#define GESTURE_EDGE_PAN_DELAY 0.5f
49#define GESTURE_EDGE_PAN_ZOOM_INFLUENCE 0.0f
83 switch (modal_state) {
105 if (
gesture->edge_pan_data ==
nullptr) {
193 if (wait_for_input) {
202 gesture->wait_for_input = wait_for_input;
204 gesture->edge_pan_data = MEM_new<ui::View2DEdgePanData>(__func__);
234 switch (event->
val) {
251 gesture->modal_state =
event->val;
267 switch (event->
type) {
299#ifdef WITH_INPUT_NDOF
348 gesture->wait_for_input = wait_for_input;
352 if (
gesture->wait_for_input ==
false) {
355 gesture->is_active_prev =
true;
411 bool is_circle_size =
false;
412 bool is_finished =
false;
415 switch (event->
val) {
417 fac = 0.3f * (
event->xy[1] -
event->prev_xy[1]);
424 rect->
xmax = std::max(rect->
xmax, 1);
425 is_circle_size =
true;
429 is_circle_size =
true;
433 rect->
xmax = std::max(rect->
xmax, 1);
434 is_circle_size =
true;
440 gesture->modal_state =
event->val;
444 if (
gesture->wait_for_input ==
false) {
466 if (is_circle_size) {
473#ifdef WITH_INPUT_NDOF
500void WM_OT_circle_gesture(wmOperatorType *ot)
502 ot->name =
"Circle Gesture";
503 ot->idname =
"WM_OT_circle_gesture";
504 ot->description =
"Enter rotate mode with a circular gesture";
577 const float *lasso =
static_cast<const float *
>(
gesture->customdata);
582 for (i = 0; i <
gesture->points; i++, lasso += 2) {
606 switch (event->
val) {
614 switch (event->
type) {
628 float (*lasso)[2] =
static_cast<float (*)[2]
>(
gesture->customdata);
632 const float2 delta = current_mouse_position - last_position;
637 for (
int i = 0; i <
gesture->points; i++) {
638 lasso[i][0] += delta.x;
639 lasso[i][1] += delta.y;
642 else if (
gesture->use_smooth) {
643 if (dist_squared >
square_f(radius)) {
716 mcoords[i] =
int2(loc[0], loc[1]);
733 printf(
"Location: %f %f\n", loc[0], loc[1]);
744 ot->
name =
"Lasso Gesture";
745 ot->idname =
"WM_OT_lasso_gesture";
746 ot->description =
"Draw a shape defined by the cursor";
750 ot->exec = gesture_lasso_exec;
796 if (is_click_submitted) {
802 const short prev_x = points[num_points - 1][0];
803 const short prev_y = points[num_points - 1][1];
823 if (valid_points <= 2) {
832 const bool is_click_submitted)
838 const short *border =
static_cast<const short int *
>(
gesture->customdata);
843 for (
int i = 0; i <
gesture->points; i++, border += 2) {
849 if (valid_points >
gesture->points) {
872 switch (event->
val) {
878 short (*border)[2] =
static_cast<short int (*)[2]
>(
gesture->customdata);
879 const short prev_x = border[
gesture->points - 1][0];
880 const short prev_y = border[
gesture->points - 1][1];
887 const float2 orig(border[0][0], border[0][1]);
889 const float dist =
len_v2v2(cur, orig);
913 switch (event->
type) {
924 short (*border)[2] =
static_cast<short int (*)[2]
>(
gesture->customdata);
928 const int dx = gesture->mval.x - border[gesture->points - 1][0];
929 const int dy = gesture->mval.y - border[gesture->points - 1][1];
931 for (int i = 0; i < gesture->points; i++) {
955static wmOperatorStatus gesture_polyline_exec(bContext *
C, wmOperator *op)
960 RNA_float_get_array(&itemptr,
"loc", loc);
961 printf(
"Location: %f %f\n", loc[0], loc[1]);
968void WM_OT_polyline_gesture(wmOperatorType *ot)
972 ot->name =
"Polyline Gesture";
973 ot->idname =
"WM_OT_polyline_gesture";
974 ot->description =
"Outline a selection area with each mouse click";
978 ot->exec = gesture_polyline_exec;
1074 gesture->draw_active_side =
true;
1083 const float x_axis[2] = {1.0f, 0.0f};
1085 float line_direction[2];
1086 sub_v2_v2v2(line_direction, line_end, line_start);
1087 const float line_length =
normalize_v2(line_direction);
1090 const float adjusted_angle = current_angle + (snap_angle / 2.0f);
1091 const float angle_snapped = -
floorf(adjusted_angle / snap_angle) * snap_angle;
1093 float line_snapped_end[2];
1095 mul_v2_fl(line_snapped_end, line_length);
1096 add_v2_v2(line_snapped_end, line_start);
1098 rect->
xmax = int(line_snapped_end[0]);
1099 rect->
ymax = int(line_snapped_end[1]);
1110 int ylen = rect->
ymax - rect->
ymin;
1111 if (
abs(ylen) != xlen) {
1112 ylen = xlen * (ylen >= 0 ? 1 : -1);
1129 switch (event->
val) {
1135 if (
gesture->is_active ==
false) {
1168 switch (event->
type) {
1170 if (
gesture->is_active ==
false) {
1218 switch (event->
val) {
1224 if (
gesture->is_active ==
false) {
1245 if (
gesture->wait_for_input) {
1246 gesture->modal_state =
event->val;
1262 switch (event->
type) {
1264 if (
gesture->is_active ==
false) {
1303void WM_OT_straightline_gesture(wmOperatorType *ot)
1307 ot->name =
"Straight Line Gesture";
1308 ot->idname =
"WM_OT_straightline_gesture";
1309 ot->description =
"Draw a straight line defined by the cursor";
1311 ot->invoke = WM_gesture_straightline_invoke;
1312 ot->modal = WM_gesture_straightline_modal;
1313 ot->exec = gesture_straightline_exec;
1315 ot->poll = WM_operator_winactive;
1317 WM_operator_properties_gesture_straightline(ot, 0);
#define OPERATOR_RETVAL_CHECK(ret)
Read Blender memory allocation and freeing.
#define RNA_BEGIN(sptr, itemptr, propname)
#define RNA_PROP_BEGIN(sptr, itemptr, prop)
#define WM_GESTURE_STRAIGHTLINE
#define WM_GESTURE_CIRCLE
#define WM_GESTURE_CROSS_RECT
#define WM_GESTURE_POLYLINE
#define UNUSED_FUNCTION(x)
#define MEM_realloc_uninitialized(vmemh, len)
ccl_device_inline dual1 len(const ccl_private dual< T > &a)
T length_squared(const VecBase< T, Size > &a)
T interpolate(const T &a, const T &b, const FactorT &t)
float view2d_view_to_region_y(const View2D *v2d, float y)
float view2d_region_to_view_x(const View2D *v2d, float x)
float view2d_region_to_view_y(const View2D *v2d, float y)
void view2d_edge_pan_init(bContext *C, View2DEdgePanData *vpd, float inside_pad, float outside_pad, float speed_ramp, float max_speed, float delay, float zoom_influence)
void void view2d_edge_pan_apply_event(bContext *C, View2DEdgePanData *vpd, const wmEvent *event)
bool view2d_edge_pan_poll(bContext *C)
float view2d_view_to_region_x(const View2D *v2d, float x)
constexpr float POLYLINE_CLICK_RADIUS
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void RNA_float_set_array(PointerRNA *ptr, const char *name, const float *values)
ScrArea * CTX_wm_area(const bContext *C)
void WM_operator_properties_gesture_circle(wmOperatorType *ot)
static void gesture_modal_state_to_operator(wmOperator *op, int modal_state)
wmOperatorStatus WM_gesture_polyline_invoke(bContext *C, wmOperator *op, const wmEvent *event)
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
wmOperatorStatus WM_gesture_box_invoke(bContext *C, wmOperator *op, const wmEvent *event)
wmOperatorStatus WM_gesture_straightline_invoke(bContext *C, wmOperator *op, const wmEvent *event)
MINLINE void mul_v2_fl(float r[2], float f)
static int UNUSED_FUNCTION gesture_modal_state_from_operator(wmOperator *op)
static void gesture_circle_apply(bContext *C, wmOperator *op)
void WM_gesture_lasso_cancel(bContext *C, wmOperator *op)
int RNA_property_enum_get(PointerRNA *ptr, PropertyRNA *prop)
wmGesture * WM_gesture_new(wmWindow *window, const ARegion *region, const wmEvent *event, int type)
void RNA_int_set(PointerRNA *ptr, const char *name, int value)
wmOperatorStatus WM_gesture_straightline_modal(bContext *C, wmOperator *op, const wmEvent *event)
void WM_cursor_modal_set(wmWindow *win, int val)
static void gesture_modal_end(bContext *C, wmOperator *op)
MINLINE float fractf(float a)
float angle_signed_v2v2(const float v1[2], const float v2[2]) ATTR_WARN_UNUSED_RESULT
int RNA_int_get(PointerRNA *ptr, const char *name)
MINLINE void sub_v2_v2v2(float r[2], const float a[2], const float b[2])
wmWindow * CTX_wm_window(const bContext *C)
MINLINE float normalize_v2(float n[2])
MINLINE int max_ii(int a, int b)
@ GESTURE_MODAL_CIRCLE_ADD
@ GESTURE_MODAL_CIRCLE_SUB
@ GESTURE_MODAL_CIRCLE_SIZE
int RNA_property_collection_length(PointerRNA *ptr, PropertyRNA *prop)
wmOperatorStatus WM_gesture_straightline_active_side_invoke(bContext *C, wmOperator *op, const wmEvent *event)
wmOperatorStatus WM_gesture_lasso_modal(bContext *C, wmOperator *op, const wmEvent *event)
static bool gesture_box_apply(bContext *C, wmOperator *op)
void WM_gesture_circle_cancel(bContext *C, wmOperator *op)
static void gesture_init_mval_set(wmGesture *gesture, const int2 mval)
MINLINE float pow2f(float x)
bool RNA_property_boolean_get(PointerRNA *ptr, PropertyRNA *prop)
void WM_gesture_lines_cancel(bContext *C, wmOperator *op)
wmOperatorStatus WM_gesture_lines_modal(bContext *C, wmOperator *op, const wmEvent *event)
PropertyRNA * RNA_def_property(StructOrFunctionRNA *cont_, const char *identifier_c_str, int type, int subtype)
static bool gesture_polyline_can_apply(const wmGesture &wmGesture, const bool is_click_submitted)
wmOperatorStatus WM_gesture_lines_invoke(bContext *C, wmOperator *op, const wmEvent *event)
VecBase< int32_t, 2 > int2
VecBase< float, 2 > float2
static void wm_gesture_straightline_do_angle_snap(rcti *rect, float snap_angle)
void RNA_collection_clear(PointerRNA *ptr, const char *name)
MINLINE void add_v2_v2(float r[2], const float a[2])
void rotate_v2_v2fl(float r[2], const float p[2], float angle)
static wmOperatorStatus gesture_lasso_apply(bContext *C, wmOperator *op)
static wmOperatorStatus gesture_polyline_apply(bContext *C, wmOperator *op, const bool is_click_submitted)
wmOperatorStatus WM_gesture_circle_invoke(bContext *C, wmOperator *op, const wmEvent *event)
void BLI_rcti_translate(struct rcti *rect, int x, int y)
void WM_cursor_modal_restore(wmWindow *win)
static bool gesture_straightline_apply(bContext *C, wmOperator *op)
void wm_gesture_tag_redraw(wmWindow *win)
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
void WM_gesture_end(wmWindow *win, wmGesture *gesture)
wmOperatorStatus WM_gesture_polyline_modal(bContext *C, wmOperator *op, const wmEvent *event)
void RNA_boolean_set(PointerRNA *ptr, const char *name, bool value)
void RNA_def_property_struct_runtime(StructOrFunctionRNA *cont, PropertyRNA *prop, StructRNA *type)
void WM_gesture_polyline_cancel(bContext *C, wmOperator *op)
wmEventHandler_Op * WM_event_add_modal_handler(bContext *C, wmOperator *op)
wmOperatorStatus WM_gesture_box_modal(bContext *C, wmOperator *op, const wmEvent *event)
bool WM_operator_winactive(bContext *C)
wmOperatorStatus WM_gesture_lasso_invoke(bContext *C, wmOperator *op, const wmEvent *event)
MINLINE float len_v2v2(const float v1[2], const float v2[2]) ATTR_WARN_UNUSED_RESULT
Array< int2 > WM_gesture_lasso_path_to_array(bContext *, wmOperator *op)
void WM_gesture_box_cancel(bContext *C, wmOperator *op)
static bool gesture_box_apply_rect(wmOperator *op)
static int gesture_polyline_valid_points(const wmGesture &wmGesture, const bool is_click_submitted)
void RNA_property_enum_set(PointerRNA *ptr, PropertyRNA *prop, int value)
MINLINE float square_f(float a)
void RNA_property_boolean_set(PointerRNA *ptr, PropertyRNA *prop, bool value)
Scene * CTX_data_scene(const bContext *C)
wmOperatorStatus WM_gesture_straightline_oneshot_modal(bContext *C, wmOperator *op, const wmEvent *event)
@ OPTYPE_DEPENDS_ON_CURSOR
static SnapAngle get_snap_angle(const ScrArea &area, const ToolSettings &tool_settings)
void WM_operator_properties_gesture_polyline(wmOperatorType *ot)
bool WM_event_is_mouse_drag_or_press(const wmEvent *event)
int RNA_property_int_get(PointerRNA *ptr, PropertyRNA *prop)
wmOperatorStatus WM_gesture_circle_modal(bContext *C, wmOperator *op, const wmEvent *event)
void RNA_collection_add(PointerRNA *ptr, const char *name, PointerRNA *r_value)
MINLINE int min_ii(int a, int b)
ARegion * CTX_wm_region(const bContext *C)
float RNA_float_get(PointerRNA *ptr, const char *name)
bool RNA_property_is_set(PointerRNA *ptr, PropertyRNA *prop)
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
MINLINE int compare_ff(float a, float b, float max_diff)
void RNA_float_get_array(PointerRNA *ptr, const char *name, float *values)
void ED_area_tag_redraw(ScrArea *area)
void WM_gesture_straightline_cancel(bContext *C, wmOperator *op)
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
struct ToolSettings * toolsettings
wmOperatorStatus(*) exec(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
struct wmOperatorType * type
#define GESTURE_EDGE_PAN_DELAY
#define GESTURE_EDGE_PAN_OUTSIDE_PAD
#define GESTURE_EDGE_PAN_MAX_SPEED
#define GESTURE_EDGE_PAN_ZOOM_INFLUENCE
#define GESTURE_EDGE_PAN_INSIDE_PAD
#define GESTURE_EDGE_PAN_SPEED_RAMP