Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorJulian Eisel <julian@blender.org>2022-03-03 17:02:42 +0300
committerJulian Eisel <julian@blender.org>2022-03-03 17:04:45 +0300
commit544bd0c353cf54c28b9bb3e0714f17b16a257731 (patch)
tree5d24be665696bcee4221bba433b3a5eeded870be /source
parent1b863041c9746029bd6d867539550043944822d9 (diff)
Cleanup: Remove redundant drag image size parameters
Just use the image-buffer size and the already provided scale to determine the size, not the button size (which would always have to match the scaled image-buffer size or it would give unexpected results).
Diffstat (limited to 'source')
-rw-r--r--source/blender/editors/interface/interface_handlers.c6
-rw-r--r--source/blender/windowmanager/WM_api.h2
-rw-r--r--source/blender/windowmanager/WM_types.h3
-rw-r--r--source/blender/windowmanager/intern/wm_dragdrop.c39
4 files changed, 28 insertions, 22 deletions
diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c
index e0b64dcd4d6..80fef93faf8 100644
--- a/source/blender/editors/interface/interface_handlers.c
+++ b/source/blender/editors/interface/interface_handlers.c
@@ -2132,11 +2132,7 @@ static bool ui_but_drag_init(bContext *C,
but->dragpoin = NULL;
if (but->imb) {
- WM_event_drag_image(drag,
- but->imb,
- but->imb_scale,
- BLI_rctf_size_x(&but->rect),
- BLI_rctf_size_y(&but->rect));
+ WM_event_drag_image(drag, but->imb, but->imb_scale);
}
/* Special feature for assets: We add another drag item that supports multiple assets. It
diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h
index 21d76ce93bd..ca2aaf4e208 100644
--- a/source/blender/windowmanager/WM_api.h
+++ b/source/blender/windowmanager/WM_api.h
@@ -1129,7 +1129,7 @@ int WM_operator_flag_only_pass_through_on_press(int retval, const struct wmEvent
*/
struct wmDrag *WM_event_start_drag(
struct bContext *C, int icon, int type, void *poin, double value, unsigned int flags);
-void WM_event_drag_image(struct wmDrag *, struct ImBuf *, float scale, int sx, int sy);
+void WM_event_drag_image(struct wmDrag *, struct ImBuf *, float scale);
void WM_drag_free(struct wmDrag *drag);
void WM_drag_data_free(int dragtype, void *poin);
void WM_drag_free_list(struct ListBase *lb);
diff --git a/source/blender/windowmanager/WM_types.h b/source/blender/windowmanager/WM_types.h
index c4858a8a1fa..1f9f3e2c180 100644
--- a/source/blender/windowmanager/WM_types.h
+++ b/source/blender/windowmanager/WM_types.h
@@ -1106,8 +1106,7 @@ typedef struct wmDrag {
/** If no icon but imbuf should be drawn around cursor. */
struct ImBuf *imb;
- float scale;
- int sx, sy;
+ float imbuf_scale;
wmDragActiveDropState drop_state;
diff --git a/source/blender/windowmanager/intern/wm_dragdrop.c b/source/blender/windowmanager/intern/wm_dragdrop.c
index b7c8b29ffb3..4970b09c18b 100644
--- a/source/blender/windowmanager/intern/wm_dragdrop.c
+++ b/source/blender/windowmanager/intern/wm_dragdrop.c
@@ -234,12 +234,10 @@ static void wm_drop_ui_context_free(bContextStore **context_store)
*context_store = NULL;
}
-void WM_event_drag_image(wmDrag *drag, ImBuf *imb, float scale, int sx, int sy)
+void WM_event_drag_image(wmDrag *drag, ImBuf *imb, float scale)
{
drag->imb = imb;
- drag->scale = scale;
- drag->sx = sx;
- drag->sy = sy;
+ drag->imbuf_scale = scale;
}
void WM_drag_data_free(int dragtype, void *poin)
@@ -767,6 +765,16 @@ const char *WM_drag_get_item_name(wmDrag *drag)
return "";
}
+static int wm_drag_imbuf_icon_width_get(const wmDrag *drag)
+{
+ return round_fl_to_int(drag->imb->x * drag->imbuf_scale);
+}
+
+static int wm_drag_imbuf_icon_height_get(const wmDrag *drag)
+{
+ return round_fl_to_int(drag->imb->y * drag->imbuf_scale);
+}
+
static void wm_drag_draw_icon(bContext *UNUSED(C),
wmWindow *UNUSED(win),
wmDrag *drag,
@@ -780,8 +788,8 @@ static void wm_drag_draw_icon(bContext *UNUSED(C),
* #UI_but_drag_attach_image()). */
if (drag->imb) {
- x = xy[0] - drag->sx / 2;
- y = xy[1] - drag->sy / 2;
+ x = xy[0] - (wm_drag_imbuf_icon_width_get(drag) / 2);
+ y = xy[1] - (wm_drag_imbuf_icon_height_get(drag) / 2);
float col[4] = {1.0f, 1.0f, 1.0f, 0.65f}; /* this blends texture */
IMMDrawPixelsTexState state = immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_COLOR);
@@ -793,8 +801,8 @@ static void wm_drag_draw_icon(bContext *UNUSED(C),
GPU_RGBA8,
false,
drag->imb->rect,
- drag->scale,
- drag->scale,
+ drag->imbuf_scale,
+ drag->imbuf_scale,
1.0f,
1.0f,
col);
@@ -850,13 +858,16 @@ static void wm_drag_draw_tooltip(bContext *C, wmWindow *win, wmDrag *drag, const
const int winsize_y = WM_window_pixels_y(win);
int x, y;
if (drag->imb) {
- x = xy[0] - drag->sx / 2;
+ const int icon_width = wm_drag_imbuf_icon_width_get(drag);
+ const int icon_height = wm_drag_imbuf_icon_height_get(drag);
+
+ x = xy[0] - (icon_width / 2);
- if (xy[1] + drag->sy / 2 + padding + iconsize < winsize_y) {
- y = xy[1] + drag->sy / 2 + padding;
+ if (xy[1] + (icon_height / 2) + padding + iconsize < winsize_y) {
+ y = xy[1] + (icon_height / 2) + padding;
}
else {
- y = xy[1] - drag->sy / 2 - padding - iconsize - padding - iconsize;
+ y = xy[1] - (icon_height / 2) - padding - iconsize - padding - iconsize;
}
}
else {
@@ -889,8 +900,8 @@ static void wm_drag_draw_default(bContext *C, wmWindow *win, wmDrag *drag, const
/* Item name. */
if (drag->imb) {
int iconsize = UI_DPI_ICON_SIZE;
- xy_tmp[0] = xy[0] - (drag->sx / 2);
- xy_tmp[1] = xy[1] - (drag->sy / 2) - iconsize;
+ xy_tmp[0] = xy[0] - (wm_drag_imbuf_icon_width_get(drag) / 2);
+ xy_tmp[1] = xy[1] - (wm_drag_imbuf_icon_height_get(drag) / 2) - iconsize;
}
else {
xy_tmp[0] = xy[0] + 10 * UI_DPI_FAC;