Refactor: Make drop-box callbacks more general, not drawing specific

These callbacks were named for the purpose of drawing (and that's probably
their main use case still), but nothing limits them to be used for that only.
They can be useful for non-drawing related things, essentially they act as
drop-box entering and exiting event handlers. Reflect that in the name, so also
more clear when they will be called, as opposed to what they are typically used
for. Drop-boxes already have such event handler callbacks, this makes their API
naming more consistent.
Also better differentiates between drawing and handling callbacks, the
difference matters (attempting to draw during handling won't work).
This commit is contained in:
Julian Eisel
2023-10-12 18:27:46 +02:00
parent 7be1b59daa
commit dab7ac1739
4 changed files with 30 additions and 30 deletions

View File

@@ -613,21 +613,21 @@ static void audio_prefetch(bContext *C, wmDrag *drag)
}
}
static void movie_drop_draw_activate(wmDropBox *drop, wmDrag * /*drag*/)
static void movie_drop_on_enter(wmDropBox *drop, wmDrag * /*drag*/)
{
if (generic_drop_draw_handling(drop)) {
return;
}
}
static void sound_drop_draw_activate(wmDropBox *drop, wmDrag * /*drag*/)
static void sound_drop_on_enter(wmDropBox *drop, wmDrag * /*drag*/)
{
if (generic_drop_draw_handling(drop)) {
return;
}
}
static void image_drop_draw_activate(wmDropBox *drop, wmDrag * /*drag*/)
static void image_drop_on_enter(wmDropBox *drop, wmDrag * /*drag*/)
{
if (generic_drop_draw_handling(drop)) {
return;
@@ -638,7 +638,7 @@ static void image_drop_draw_activate(wmDropBox *drop, wmDrag * /*drag*/)
coords->channel_len = 1;
}
static void sequencer_drop_draw_deactivate(wmDropBox *drop, wmDrag * /*drag*/)
static void sequencer_drop_on_exit(wmDropBox *drop, wmDrag * /*drag*/)
{
SeqDropCoords *coords = static_cast<SeqDropCoords *>(drop->draw_data);
if (coords) {
@@ -666,8 +666,8 @@ static void sequencer_dropboxes_add_to_lb(ListBase *lb)
lb, "SEQUENCER_OT_image_strip_add", image_drop_poll, sequencer_drop_copy, nullptr, nullptr);
drop->draw_droptip = nop_draw_droptip_fn;
drop->draw_in_view = draw_seq_in_view;
drop->draw_activate = image_drop_draw_activate;
drop->draw_deactivate = sequencer_drop_draw_deactivate;
drop->on_enter = image_drop_on_enter;
drop->on_exit = sequencer_drop_on_exit;
drop->on_drag_start = audio_prefetch;
@@ -675,8 +675,8 @@ static void sequencer_dropboxes_add_to_lb(ListBase *lb)
lb, "SEQUENCER_OT_movie_strip_add", movie_drop_poll, sequencer_drop_copy, nullptr, nullptr);
drop->draw_droptip = nop_draw_droptip_fn;
drop->draw_in_view = draw_seq_in_view;
drop->draw_activate = movie_drop_draw_activate;
drop->draw_deactivate = sequencer_drop_draw_deactivate;
drop->on_enter = movie_drop_on_enter;
drop->on_exit = sequencer_drop_on_exit;
drop->on_drag_start = video_prefetch;
@@ -684,8 +684,8 @@ static void sequencer_dropboxes_add_to_lb(ListBase *lb)
lb, "SEQUENCER_OT_sound_strip_add", sound_drop_poll, sequencer_drop_copy, nullptr, nullptr);
drop->draw_droptip = nop_draw_droptip_fn;
drop->draw_in_view = draw_seq_in_view;
drop->draw_activate = sound_drop_draw_activate;
drop->draw_deactivate = sequencer_drop_draw_deactivate;
drop->on_enter = sound_drop_on_enter;
drop->on_exit = sequencer_drop_on_exit;
}
static bool image_drop_preview_poll(bContext * /*C*/, wmDrag *drag, const wmEvent * /*event*/)

View File

@@ -538,7 +538,7 @@ static bool view3d_drop_id_in_main_region_poll(bContext *C,
return WM_drag_is_ID_type(drag, id_type);
}
static void view3d_ob_drop_draw_activate(wmDropBox *drop, wmDrag *drag)
static void view3d_ob_drop_on_enter(wmDropBox *drop, wmDrag *drag)
{
V3DSnapCursorState *state = static_cast<V3DSnapCursorState *>(drop->draw_data);
if (state) {
@@ -575,7 +575,7 @@ static void view3d_ob_drop_draw_activate(wmDropBox *drop, wmDrag *drag)
}
}
static void view3d_ob_drop_draw_deactivate(wmDropBox *drop, wmDrag * /*drag*/)
static void view3d_ob_drop_on_exit(wmDropBox *drop, wmDrag * /*drag*/)
{
V3DSnapCursorState *state = static_cast<V3DSnapCursorState *>(drop->draw_data);
if (state) {
@@ -982,8 +982,8 @@ static void view3d_dropboxes()
nullptr);
drop->draw_droptip = WM_drag_draw_item_name_fn;
drop->draw_activate = view3d_ob_drop_draw_activate;
drop->draw_deactivate = view3d_ob_drop_draw_deactivate;
drop->on_enter = view3d_ob_drop_on_enter;
drop->on_exit = view3d_ob_drop_on_exit;
drop = WM_dropbox_add(lb,
"OBJECT_OT_transform_to_mouse",
@@ -993,8 +993,8 @@ static void view3d_dropboxes()
nullptr);
drop->draw_droptip = WM_drag_draw_item_name_fn;
drop->draw_activate = view3d_ob_drop_draw_activate;
drop->draw_deactivate = view3d_ob_drop_draw_deactivate;
drop->on_enter = view3d_ob_drop_on_enter;
drop->on_exit = view3d_ob_drop_on_exit;
WM_dropbox_add(lb,
"OBJECT_OT_collection_external_asset_drop",

View File

@@ -1186,8 +1186,7 @@ using WMDropboxTooltipFunc = char *(*)(bContext *C,
struct wmDragActiveDropState {
/**
* Informs which dropbox is activated with the drag item.
* When this value changes, the #draw_activate and #draw_deactivate dropbox callbacks are
* triggered.
* When this value changes, the #on_enter() and #on_exit() dropbox callbacks are triggered.
*/
wmDropBox *active_dropbox;
@@ -1258,6 +1257,13 @@ struct wmDropBox {
* So this callback is called on every dropbox that is registered in the current screen. */
void (*on_drag_start)(bContext *C, wmDrag *drag);
/** Called when poll returns true the first time. Typically used to setup some drawing data. */
void (*on_enter)(wmDropBox *drop, wmDrag *drag);
/** Called when poll returns false the first time or when the drag event ends (successful drop or
* canceled). Typically used to cleanup resources or end drawing. */
void (*on_exit)(wmDropBox *drop, wmDrag *drag);
/** Before exec, this copies drag info to #wmDrop properties. */
void (*copy)(bContext *C, wmDrag *drag, wmDropBox *drop);
@@ -1282,12 +1288,6 @@ struct wmDropBox {
*/
void (*draw_in_view)(bContext *C, wmWindow *win, wmDrag *drag, const int xy[2]);
/** Called when poll returns true the first time. */
void (*draw_activate)(wmDropBox *drop, wmDrag *drag);
/** Called when poll returns false the first time or when the drag event ends. */
void (*draw_deactivate)(wmDropBox *drop, wmDrag *drag);
/** Custom data for drawing. */
void *draw_data;

View File

@@ -312,8 +312,8 @@ void WM_drag_data_free(eWM_DragDataType dragtype, void *poin)
void WM_drag_free(wmDrag *drag)
{
if (drag->drop_state.active_dropbox && drag->drop_state.active_dropbox->draw_deactivate) {
drag->drop_state.active_dropbox->draw_deactivate(drag->drop_state.active_dropbox, drag);
if (drag->drop_state.active_dropbox && drag->drop_state.active_dropbox->on_exit) {
drag->drop_state.active_dropbox->on_exit(drag->drop_state.active_dropbox, drag);
}
if (drag->flags & WM_DRAG_FREE_DATA) {
WM_drag_data_free(drag->type, drag->poin);
@@ -447,12 +447,12 @@ static void wm_drop_update_active(bContext *C, wmDrag *drag, const wmEvent *even
wmDropBox *drop_prev = drag->drop_state.active_dropbox;
wmDropBox *drop = wm_dropbox_active(C, drag, event);
if (drop != drop_prev) {
if (drop_prev && drop_prev->draw_deactivate) {
drop_prev->draw_deactivate(drop_prev, drag);
if (drop_prev && drop_prev->on_exit) {
drop_prev->on_exit(drop_prev, drag);
BLI_assert(drop_prev->draw_data == nullptr);
}
if (drop && drop->draw_activate) {
drop->draw_activate(drop, drag);
if (drop && drop->on_enter) {
drop->on_enter(drop, drag);
}
drag->drop_state.active_dropbox = drop;
drag->drop_state.area_from = drop ? CTX_wm_area(C) : nullptr;