Cleanup: use float2, int2 types for cursor drawing callbacks

Ref !138172
This commit is contained in:
Campbell Barton
2025-05-02 23:01:29 +00:00
parent 0d6a0dfa29
commit 7d97ba4c5f
14 changed files with 82 additions and 62 deletions

View File

@@ -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 */

View File

@@ -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);

View File

@@ -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<MinDistanceEditData *>(customdata);

View File

@@ -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;
}

View File

@@ -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();

View File

@@ -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();

View File

@@ -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();

View File

@@ -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:

View File

@@ -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

View File

@@ -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);

View File

@@ -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 *************** */

View File

@@ -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);
}
}

View File

@@ -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<RadialControl *>(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. */

View File

@@ -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;