From 7d97ba4c5f20998c8d13b110fae5f384caf620dd Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 2 May 2025 23:01:29 +0000 Subject: [PATCH] Cleanup: use float2, int2 types for cursor drawing callbacks Ref !138172 --- .../editors/gpencil_legacy/annotate_paint.cc | 24 +++++++++++-------- .../blender/editors/physics/particle_edit.cc | 8 ++++--- .../editors/sculpt_paint/curves_sculpt_ops.cc | 6 +++-- .../editors/sculpt_paint/paint_cursor.cc | 20 ++++++++-------- .../sculpt_paint/paint_image_ops_paint.cc | 10 ++++---- .../editors/sculpt_paint/paint_stroke.cc | 16 +++++-------- .../space_view3d/view3d_cursor_snap.cc | 9 +++---- .../transform/transform_draw_cursors.cc | 8 ++++--- .../transform/transform_draw_cursors.hh | 8 +++++-- .../blender/python/intern/bpy_rna_callback.cc | 8 ++++--- source/blender/windowmanager/WM_types.hh | 6 +++-- .../blender/windowmanager/intern/wm_draw.cc | 7 +----- .../windowmanager/intern/wm_operators.cc | 7 ++++-- source/blender/windowmanager/wm.hh | 7 +++++- 14 files changed, 82 insertions(+), 62 deletions(-) diff --git a/source/blender/editors/gpencil_legacy/annotate_paint.cc b/source/blender/editors/gpencil_legacy/annotate_paint.cc index 88bd05e623f..7d8557a8e75 100644 --- a/source/blender/editors/gpencil_legacy/annotate_paint.cc +++ b/source/blender/editors/gpencil_legacy/annotate_paint.cc @@ -1716,8 +1716,10 @@ static void annotation_paint_cleanup(tGPsdata *p) /* ------------------------------- */ /* Helper callback for drawing the cursor itself */ -static void annotation_draw_eraser( - bContext * /*C*/, int x, int y, float /*x_tilt*/, float /*y_tilt*/, void *p_ptr) +static void annotation_draw_eraser(bContext * /*C*/, + const blender::int2 &xy, + const blender::float2 & /*tilt*/, + void *p_ptr) { tGPsdata *p = (tGPsdata *)p_ptr; @@ -1730,7 +1732,7 @@ static void annotation_draw_eraser( GPU_blend(GPU_BLEND_ALPHA); immUniformColor4ub(255, 100, 100, 20); - imm_draw_circle_fill_2d(shdr_pos, x, y, p->radius, 40); + imm_draw_circle_fill_2d(shdr_pos, xy[0], xy[1], p->radius, 40); immUnbindProgram(); @@ -1746,8 +1748,8 @@ static void annotation_draw_eraser( immUniform1f("udash_factor", 0.5f); imm_draw_circle_wire_2d(shdr_pos, - x, - y, + xy.y, + xy.x, p->radius, /* XXX Dashed shader gives bad results with sets of small segments * currently, temp hack around the issue. :( */ @@ -1777,8 +1779,10 @@ static void annotation_draw_toggle_eraser_cursor(tGPsdata *p, short enable) p); } } -static void annotation_draw_stabilizer( - bContext *C, int x, int y, float /*x_tilt*/, float /*y_tilt*/, void *p_ptr) +static void annotation_draw_stabilizer(bContext *C, + const blender::int2 &xy, + const blender::float2 & /*tilt*/, + void *p_ptr) { ARegion *region = CTX_wm_region(C); tGPsdata *p = (tGPsdata *)p_ptr; @@ -1804,18 +1808,18 @@ static void annotation_draw_stabilizer( /* Inner Ring: Color from UI panel */ immUniformColor4f(color[0], color[1], color[2], 0.8f); - imm_draw_circle_wire_2d(pos, x, y, radius, 40); + imm_draw_circle_wire_2d(pos, xy.x, xy.y, radius, 40); /* Outer Ring: Dark color for contrast on light backgrounds (e.g. gray on white) */ mul_v3_v3fl(darkcolor, color, 0.40f); immUniformColor4f(darkcolor[0], darkcolor[1], darkcolor[2], 0.8f); - imm_draw_circle_wire_2d(pos, x, y, radius + 1, 40); + imm_draw_circle_wire_2d(pos, xy.x, xy.y, radius + 1, 40); /* Rope Simple. */ immUniformColor4f(color[0], color[1], color[2], 0.8f); immBegin(GPU_PRIM_LINES, 2); immVertex2f(pos, pt->m_xy[0] + region->winrct.xmin, pt->m_xy[1] + region->winrct.ymin); - immVertex2f(pos, x, y); + immVertex2iv(pos, xy); immEnd(); /* Returns back all GPU settings */ diff --git a/source/blender/editors/physics/particle_edit.cc b/source/blender/editors/physics/particle_edit.cc index 1c43e228a4d..2e50c44ac7f 100644 --- a/source/blender/editors/physics/particle_edit.cc +++ b/source/blender/editors/physics/particle_edit.cc @@ -3393,8 +3393,10 @@ void PARTICLE_OT_weight_set(wmOperatorType *ot) /** \name Cursor Drawing * \{ */ -static void brush_drawcursor( - bContext *C, int x, int y, float /*x_tilt*/, float /*y_tilt*/, void * /*customdata*/) +static void brush_drawcursor(bContext *C, + const blender::int2 &xy, + const blender::float2 & /*tilt*/, + void * /*customdata*/) { Scene *scene = CTX_data_scene(C); ParticleEditSettings *pset = PE_settings(scene); @@ -3415,7 +3417,7 @@ static void brush_drawcursor( GPU_line_smooth(true); GPU_blend(GPU_BLEND_ALPHA); - imm_draw_circle_wire_2d(pos, float(x), float(y), pe_brush_size_get(scene, brush), 40); + imm_draw_circle_wire_2d(pos, float(xy.x), float(xy.y), pe_brush_size_get(scene, brush), 40); GPU_blend(GPU_BLEND_NONE); GPU_line_smooth(false); diff --git a/source/blender/editors/sculpt_paint/curves_sculpt_ops.cc b/source/blender/editors/sculpt_paint/curves_sculpt_ops.cc index 9f85abf9708..668c3d5bd3e 100644 --- a/source/blender/editors/sculpt_paint/curves_sculpt_ops.cc +++ b/source/blender/editors/sculpt_paint/curves_sculpt_ops.cc @@ -912,8 +912,10 @@ static int calculate_points_per_side(bContext *C, MinDistanceEditData &op_data) return std::min(300, needed_points); } -static void min_distance_edit_draw( - bContext *C, int /*x*/, int /*y*/, float /*x_tilt*/, float /*y_tilt*/, void *customdata) +static void min_distance_edit_draw(bContext *C, + const blender::int2 & /*xy*/, + const blender::float2 & /*tilt*/, + void *customdata) { Scene *scene = CTX_data_scene(C); MinDistanceEditData &op_data = *static_cast(customdata); diff --git a/source/blender/editors/sculpt_paint/paint_cursor.cc b/source/blender/editors/sculpt_paint/paint_cursor.cc index 8ad2fa79ae9..941a6fe7c91 100644 --- a/source/blender/editors/sculpt_paint/paint_cursor.cc +++ b/source/blender/editors/sculpt_paint/paint_cursor.cc @@ -1299,10 +1299,8 @@ struct PaintCursorContext { }; static bool paint_cursor_context_init(bContext *C, - const int x, - const int y, - const float x_tilt, - const float y_tilt, + const blender::int2 &xy, + const blender::float2 &tilt, PaintCursorContext &pcontext) { ARegion *region = CTX_wm_region(C); @@ -1340,9 +1338,9 @@ static bool paint_cursor_context_init(bContext *C, pcontext.cursor_type = PaintCursorDrawingType::Cursor3D; } - pcontext.mval = {x, y}; - pcontext.translation = {float(x), float(y)}; - pcontext.tilt = {x_tilt, y_tilt}; + pcontext.mval = xy; + pcontext.translation = {float(xy[0]), float(xy[1])}; + pcontext.tilt = tilt; float zoomx, zoomy; get_imapaint_zoom(C, &zoomx, &zoomy); @@ -2150,11 +2148,13 @@ static void paint_cursor_restore_drawing_state() GPU_line_smooth(false); } -static void paint_draw_cursor( - bContext *C, int x, int y, float x_tilt, float y_tilt, void * /*unused*/) +static void paint_draw_cursor(bContext *C, + const blender::int2 &xy, + const blender::float2 &tilt, + void * /*unused*/) { PaintCursorContext pcontext; - if (!paint_cursor_context_init(C, x, y, x_tilt, y_tilt, pcontext)) { + if (!paint_cursor_context_init(C, xy, tilt, pcontext)) { return; } diff --git a/source/blender/editors/sculpt_paint/paint_image_ops_paint.cc b/source/blender/editors/sculpt_paint/paint_image_ops_paint.cc index 10696bbebb9..8b1204691f0 100644 --- a/source/blender/editors/sculpt_paint/paint_image_ops_paint.cc +++ b/source/blender/editors/sculpt_paint/paint_image_ops_paint.cc @@ -242,8 +242,10 @@ struct PaintOperation : public PaintModeData { } }; -static void gradient_draw_line( - bContext * /*C*/, int x, int y, float /*x_tilt*/, float /*y_tilt*/, void *customdata) +static void gradient_draw_line(bContext * /*C*/, + const blender::int2 &xy, + const blender::float2 & /*tilt*/, + void *customdata) { PaintOperation *pop = (PaintOperation *)customdata; @@ -262,7 +264,7 @@ static void gradient_draw_line( immUniformColor4ub(0, 0, 0, 255); immBegin(GPU_PRIM_LINES, 2); - immVertex2i(pos, x, y); + immVertex2iv(pos, xy); immVertex2i( pos, pop->startmouse[0] + region->winrct.xmin, pop->startmouse[1] + region->winrct.ymin); immEnd(); @@ -271,7 +273,7 @@ static void gradient_draw_line( immUniformColor4ub(255, 255, 255, 255); immBegin(GPU_PRIM_LINES, 2); - immVertex2i(pos, x, y); + immVertex2iv(pos, xy); immVertex2i( pos, pop->startmouse[0] + region->winrct.xmin, pop->startmouse[1] + region->winrct.ymin); immEnd(); diff --git a/source/blender/editors/sculpt_paint/paint_stroke.cc b/source/blender/editors/sculpt_paint/paint_stroke.cc index 70118828566..1c5952bf2fa 100644 --- a/source/blender/editors/sculpt_paint/paint_stroke.cc +++ b/source/blender/editors/sculpt_paint/paint_stroke.cc @@ -136,10 +136,8 @@ struct PaintStroke { /*** Cursors ***/ static void paint_draw_smooth_cursor(bContext *C, - const int x, - const int y, - const float /*x_tilt*/, - const float /*y_tilt*/, + const blender::int2 &xy, + const blender::float2 & /*tilt*/, void *customdata) { const Paint *paint = BKE_paint_get_active_from_context(C); @@ -163,7 +161,7 @@ static void paint_draw_smooth_cursor(bContext *C, immUniformColor4ubv(paint->paint_cursor_col); immBegin(GPU_PRIM_LINES, 2); - immVertex2f(pos, x, y); + immVertex2iv(pos, xy); immVertex2f(pos, stroke->last_mouse_position[0] + region->winrct.xmin, stroke->last_mouse_position[1] + region->winrct.ymin); @@ -178,10 +176,8 @@ static void paint_draw_smooth_cursor(bContext *C, } static void paint_draw_line_cursor(bContext *C, - const int x, - const int y, - const float /*x_tilt*/, - const float /*y_tilt*/, + const blender::int2 &xy, + const blender::float2 & /*tilt*/, void *customdata) { const Paint *paint = BKE_paint_get_active_from_context(C); @@ -223,7 +219,7 @@ static void paint_draw_line_cursor(bContext *C, stroke->last_mouse_position[0] + region->winrct.xmin, stroke->last_mouse_position[1] + region->winrct.ymin); - immVertex2f(shdr_pos, x, y); + immVertex2iv(shdr_pos, xy); } immEnd(); diff --git a/source/blender/editors/space_view3d/view3d_cursor_snap.cc b/source/blender/editors/space_view3d/view3d_cursor_snap.cc index 6682a42a9b7..5aa92176487 100644 --- a/source/blender/editors/space_view3d/view3d_cursor_snap.cc +++ b/source/blender/editors/space_view3d/view3d_cursor_snap.cc @@ -865,22 +865,23 @@ static bool v3d_cursor_snap_poll_fn(bContext *C) return true; } -static void v3d_cursor_snap_draw_fn( - bContext *C, int x, int y, float /*x_tilt*/, float /*y_tilt*/, void * /*customdata*/) +static void v3d_cursor_snap_draw_fn(bContext *C, + const blender::int2 &xy, + const blender::float2 & /*tilt*/, + void * /*customdata*/) { using namespace blender; ScrArea *area = CTX_wm_area(C); ARegion *region = BKE_area_find_region_type(area, RGN_TYPE_WINDOW); if (region->alignment == RGN_ALIGN_QSPLIT) { /* Quad-View. */ - const int2 xy = {x, y}; region = BKE_area_find_region_xy(area, RGN_TYPE_WINDOW, xy); if (region == nullptr) { return; } } - const int2 mval(x - region->winrct.xmin, y - region->winrct.ymin); + const int2 mval(xy.x - region->winrct.xmin, xy.y - region->winrct.ymin); SnapCursorDataIntern *data_intern = &g_data_intern; V3DSnapCursorState *state = ED_view3d_cursor_snap_state_active_get(); diff --git a/source/blender/editors/transform/transform_draw_cursors.cc b/source/blender/editors/transform/transform_draw_cursors.cc index e7cd919b058..16ee741ecc6 100644 --- a/source/blender/editors/transform/transform_draw_cursors.cc +++ b/source/blender/editors/transform/transform_draw_cursors.cc @@ -80,8 +80,10 @@ bool transform_draw_cursor_poll(bContext *C) return (region && ELEM(region->regiontype, RGN_TYPE_WINDOW, RGN_TYPE_PREVIEW)) ? true : false; } -void transform_draw_cursor_draw( - bContext *C, int x, int y, float /*x_tilt*/, float /*y_tilt*/, void *customdata) +void transform_draw_cursor_draw(bContext *C, + const blender::int2 &xy, + const blender::float2 & /*tilt*/, + void *customdata) { TransInfo *t = (TransInfo *)customdata; @@ -164,7 +166,7 @@ void transform_draw_cursor_draw( immUniform1f("lineWidth", ARROW_WIDTH * 2.0f); GPU_matrix_push(); - GPU_matrix_translate_3f(float(x), float(y), 0.0f); + GPU_matrix_translate_3f(float(xy.x), float(xy.y), 0.0f); switch (t->helpline) { case HLP_SPRING: diff --git a/source/blender/editors/transform/transform_draw_cursors.hh b/source/blender/editors/transform/transform_draw_cursors.hh index 2c72f1a817a..3e93480d5c7 100644 --- a/source/blender/editors/transform/transform_draw_cursors.hh +++ b/source/blender/editors/transform/transform_draw_cursors.hh @@ -8,6 +8,8 @@ #pragma once +#include "BLI_math_vector_types.hh" + struct bContext; namespace blender::ed::transform { @@ -23,7 +25,9 @@ bool transform_draw_cursor_poll(bContext *C); * Cursor and help-line drawing, callback for: * #WM_paint_cursor_activate */ -void transform_draw_cursor_draw( - bContext *C, int x, int y, float x_tilt, float y_tilt, void *customdata); +void transform_draw_cursor_draw(bContext *C, + const blender::int2 &xy, + const blender::float2 &tilt, + void *customdata); } // namespace blender::ed::transform diff --git a/source/blender/python/intern/bpy_rna_callback.cc b/source/blender/python/intern/bpy_rna_callback.cc index 716f99dd153..017355a097d 100644 --- a/source/blender/python/intern/bpy_rna_callback.cc +++ b/source/blender/python/intern/bpy_rna_callback.cc @@ -80,8 +80,10 @@ static PyObject *PyC_Tuple_CopySized(PyObject *src, int len_dst) return dst; } -static void cb_wm_cursor_draw( - bContext *C, int x, int y, float /*x_tilt*/, float /*y_tilt*/, void *customdata) +static void cb_wm_cursor_draw(bContext *C, + const blender::int2 &xy, + const blender::float2 & /*tilt*/, + void *customdata) { PyGILState_STATE gilstate; bpy_context_set(C, &gilstate); @@ -93,7 +95,7 @@ static void cb_wm_cursor_draw( const int cb_args_len = PyTuple_GET_SIZE(cb_args); PyObject *cb_args_xy = PyTuple_New(2); - PyTuple_SET_ITEMS(cb_args_xy, PyLong_FromLong(x), PyLong_FromLong(y)); + PyTuple_SET_ITEMS(cb_args_xy, PyLong_FromLong(xy.x), PyLong_FromLong(xy.y)); PyObject *cb_args_with_xy = PyC_Tuple_CopySized(cb_args, cb_args_len + 1); PyTuple_SET_ITEM(cb_args_with_xy, cb_args_len, cb_args_xy); diff --git a/source/blender/windowmanager/WM_types.hh b/source/blender/windowmanager/WM_types.hh index 733b51e3e46..a0ccce37de7 100644 --- a/source/blender/windowmanager/WM_types.hh +++ b/source/blender/windowmanager/WM_types.hh @@ -1189,8 +1189,10 @@ struct wmIMEData { /* **************** Paint Cursor ******************* */ -using wmPaintCursorDraw = - void (*)(bContext *C, int x, int y, float x_tilt, float y_tilt, void *customdata); +using wmPaintCursorDraw = void (*)(bContext *C, + const blender::int2 &xy, + const blender::float2 &tilt, + void *customdata); /* *************** Drag and drop *************** */ diff --git a/source/blender/windowmanager/intern/wm_draw.cc b/source/blender/windowmanager/intern/wm_draw.cc index dee1da8a9aa..082db2e2266 100644 --- a/source/blender/windowmanager/intern/wm_draw.cc +++ b/source/blender/windowmanager/intern/wm_draw.cc @@ -150,12 +150,7 @@ static void wm_paintcursor_draw(bContext *C, ScrArea *area, ARegion *region) xy = xy_buf; } - pc->draw(C, - xy[0], - xy[1], - win->eventstate->tablet.tilt.x, - win->eventstate->tablet.tilt.y, - pc->customdata); + pc->draw(C, xy, win->eventstate->tablet.tilt, pc->customdata); GPU_scissor_test(false); } } diff --git a/source/blender/windowmanager/intern/wm_operators.cc b/source/blender/windowmanager/intern/wm_operators.cc index 6928e1aed7d..6076a987af7 100644 --- a/source/blender/windowmanager/intern/wm_operators.cc +++ b/source/blender/windowmanager/intern/wm_operators.cc @@ -2766,8 +2766,10 @@ static void radial_control_paint_curve(uint pos, Brush *br, float radius, int li immEnd(); } -static void radial_control_paint_cursor( - bContext * /*C*/, int x, int y, float /*x_tilt*/, float /*y_tilt*/, void *customdata) +static void radial_control_paint_cursor(bContext * /*C*/, + const blender::int2 & /*xy*/, + const blender::float2 & /*tilt*/, + void *customdata) { RadialControl *rc = static_cast(customdata); const uiStyle *style = UI_style_get(); @@ -2822,6 +2824,7 @@ static void radial_control_paint_cursor( break; } + int x, y; if (rc->subtype == PROP_ANGLE) { /* Use the initial mouse position to draw the rotation preview. This avoids starting the * rotation in a random direction. */ diff --git a/source/blender/windowmanager/wm.hh b/source/blender/windowmanager/wm.hh index 4db8925d996..1b1725c387f 100644 --- a/source/blender/windowmanager/wm.hh +++ b/source/blender/windowmanager/wm.hh @@ -10,6 +10,8 @@ #include "BLI_compiler_attrs.h" +#include "BLI_math_vector_types.hh" + struct wmOperator; struct wmTimer; struct wmWindow; @@ -24,7 +26,10 @@ struct wmPaintCursor { void *customdata; bool (*poll)(bContext *C); - void (*draw)(bContext *C, int, int, float, float, void *customdata); + void (*draw)(bContext *C, + const blender::int2 &xy, + const blender::float2 &tilt, + void *customdata); short space_type; short region_type;