Eyedropper: Support datadropper in the outliner
Adds support for using the eyedropper in the outliner in addition to the 3D view.
This commit is contained in:
@@ -30,6 +30,8 @@ bool ED_outliner_collections_editor_poll(struct bContext *C);
|
|||||||
|
|
||||||
void ED_outliner_selected_objects_get(const struct bContext *C, struct ListBase *objects);
|
void ED_outliner_selected_objects_get(const struct bContext *C, struct ListBase *objects);
|
||||||
|
|
||||||
|
Base *ED_outliner_give_base_under_cursor(struct bContext *C, const int mval[2]);
|
||||||
|
|
||||||
void ED_outliner_select_sync_from_object_tag(struct bContext *C);
|
void ED_outliner_select_sync_from_object_tag(struct bContext *C);
|
||||||
void ED_outliner_select_sync_from_edit_bone_tag(struct bContext *C);
|
void ED_outliner_select_sync_from_edit_bone_tag(struct bContext *C);
|
||||||
void ED_outliner_select_sync_from_pose_bone_tag(struct bContext *C);
|
void ED_outliner_select_sync_from_pose_bone_tag(struct bContext *C);
|
||||||
|
|||||||
@@ -51,6 +51,7 @@
|
|||||||
#include "ED_space_api.h"
|
#include "ED_space_api.h"
|
||||||
#include "ED_screen.h"
|
#include "ED_screen.h"
|
||||||
#include "ED_view3d.h"
|
#include "ED_view3d.h"
|
||||||
|
#include "ED_outliner.h"
|
||||||
|
|
||||||
#include "interface_intern.h"
|
#include "interface_intern.h"
|
||||||
#include "interface_eyedropper_intern.h"
|
#include "interface_eyedropper_intern.h"
|
||||||
@@ -67,6 +68,7 @@ typedef struct DataDropper {
|
|||||||
|
|
||||||
ID *init_id; /* for resetting on cancel */
|
ID *init_id; /* for resetting on cancel */
|
||||||
|
|
||||||
|
ScrArea *cursor_area; /* Area under the cursor */
|
||||||
ARegionType *art;
|
ARegionType *art;
|
||||||
void *draw_handle_pixel;
|
void *draw_handle_pixel;
|
||||||
char name[200];
|
char name[200];
|
||||||
@@ -103,6 +105,7 @@ static int datadropper_init(bContext *C, wmOperator *op)
|
|||||||
|
|
||||||
ddr->is_undo = UI_but_flag_is_set(but, UI_BUT_UNDO);
|
ddr->is_undo = UI_but_flag_is_set(but, UI_BUT_UNDO);
|
||||||
|
|
||||||
|
ddr->cursor_area = CTX_wm_area(C);
|
||||||
ddr->art = art;
|
ddr->art = art;
|
||||||
ddr->draw_handle_pixel = ED_region_draw_cb_activate(
|
ddr->draw_handle_pixel = ED_region_draw_cb_activate(
|
||||||
art, datadropper_draw_cb, ddr, REGION_DRAW_POST_PIXEL);
|
art, datadropper_draw_cb, ddr, REGION_DRAW_POST_PIXEL);
|
||||||
@@ -141,7 +144,7 @@ static void datadropper_exit(bContext *C, wmOperator *op)
|
|||||||
|
|
||||||
/* *** datadropper id helper functions *** */
|
/* *** datadropper id helper functions *** */
|
||||||
/**
|
/**
|
||||||
* \brief get the ID from the screen.
|
* \brief get the ID from the 3D view or outliner.
|
||||||
*/
|
*/
|
||||||
static void datadropper_id_sample_pt(bContext *C, DataDropper *ddr, int mx, int my, ID **r_id)
|
static void datadropper_id_sample_pt(bContext *C, DataDropper *ddr, int mx, int my, ID **r_id)
|
||||||
{
|
{
|
||||||
@@ -155,7 +158,7 @@ static void datadropper_id_sample_pt(bContext *C, DataDropper *ddr, int mx, int
|
|||||||
ddr->name[0] = '\0';
|
ddr->name[0] = '\0';
|
||||||
|
|
||||||
if (sa) {
|
if (sa) {
|
||||||
if (sa->spacetype == SPACE_VIEW3D) {
|
if (ELEM(sa->spacetype, SPACE_VIEW3D, SPACE_OUTLINER)) {
|
||||||
ARegion *ar = BKE_area_find_region_xy(sa, RGN_TYPE_WINDOW, mx, my);
|
ARegion *ar = BKE_area_find_region_xy(sa, RGN_TYPE_WINDOW, mx, my);
|
||||||
if (ar) {
|
if (ar) {
|
||||||
const int mval[2] = {mx - ar->winrct.xmin, my - ar->winrct.ymin};
|
const int mval[2] = {mx - ar->winrct.xmin, my - ar->winrct.ymin};
|
||||||
@@ -167,7 +170,13 @@ static void datadropper_id_sample_pt(bContext *C, DataDropper *ddr, int mx, int
|
|||||||
/* grr, always draw else we leave stale text */
|
/* grr, always draw else we leave stale text */
|
||||||
ED_region_tag_redraw(ar);
|
ED_region_tag_redraw(ar);
|
||||||
|
|
||||||
base = ED_view3d_give_base_under_cursor(C, mval);
|
if (sa->spacetype == SPACE_VIEW3D) {
|
||||||
|
base = ED_view3d_give_base_under_cursor(C, mval);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
base = ED_outliner_give_base_under_cursor(C, mval);
|
||||||
|
}
|
||||||
|
|
||||||
if (base) {
|
if (base) {
|
||||||
Object *ob = base->object;
|
Object *ob = base->object;
|
||||||
ID *id = NULL;
|
ID *id = NULL;
|
||||||
@@ -232,6 +241,36 @@ static void datadropper_cancel(bContext *C, wmOperator *op)
|
|||||||
datadropper_exit(C, op);
|
datadropper_exit(C, op);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* To switch the draw callback when region under mouse event changes */
|
||||||
|
static void datadropper_set_draw_callback_region(bContext *C,
|
||||||
|
DataDropper *ddr,
|
||||||
|
const int mx,
|
||||||
|
const int my)
|
||||||
|
{
|
||||||
|
bScreen *screen = CTX_wm_screen(C);
|
||||||
|
ScrArea *sa = BKE_screen_find_area_xy(screen, -1, mx, my);
|
||||||
|
|
||||||
|
if (sa) {
|
||||||
|
/* If spacetype changed */
|
||||||
|
if (sa->spacetype != ddr->cursor_area->spacetype) {
|
||||||
|
/* Remove old callback */
|
||||||
|
ED_region_draw_cb_exit(ddr->art, ddr->draw_handle_pixel);
|
||||||
|
|
||||||
|
/* Redraw old area */
|
||||||
|
ARegion *ar = BKE_area_find_region_type(ddr->cursor_area, RGN_TYPE_WINDOW);
|
||||||
|
ED_region_tag_redraw(ar);
|
||||||
|
|
||||||
|
/* Set draw callback in new region */
|
||||||
|
ARegionType *art = BKE_regiontype_from_id(sa->type, RGN_TYPE_WINDOW);
|
||||||
|
|
||||||
|
ddr->cursor_area = sa;
|
||||||
|
ddr->art = art;
|
||||||
|
ddr->draw_handle_pixel = ED_region_draw_cb_activate(
|
||||||
|
art, datadropper_draw_cb, ddr, REGION_DRAW_POST_PIXEL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* main modal status check */
|
/* main modal status check */
|
||||||
static int datadropper_modal(bContext *C, wmOperator *op, const wmEvent *event)
|
static int datadropper_modal(bContext *C, wmOperator *op, const wmEvent *event)
|
||||||
{
|
{
|
||||||
@@ -260,6 +299,10 @@ static int datadropper_modal(bContext *C, wmOperator *op, const wmEvent *event)
|
|||||||
}
|
}
|
||||||
else if (event->type == MOUSEMOVE) {
|
else if (event->type == MOUSEMOVE) {
|
||||||
ID *id = NULL;
|
ID *id = NULL;
|
||||||
|
|
||||||
|
/* Set the region for eyedropper cursor text drawing */
|
||||||
|
datadropper_set_draw_callback_region(C, ddr, event->x, event->y);
|
||||||
|
|
||||||
datadropper_id_sample_pt(C, ddr, event->x, event->y, &id);
|
datadropper_id_sample_pt(C, ddr, event->x, event->y, &id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,11 +24,15 @@
|
|||||||
#include "BLI_utildefines.h"
|
#include "BLI_utildefines.h"
|
||||||
|
|
||||||
#include "DNA_action_types.h"
|
#include "DNA_action_types.h"
|
||||||
|
#include "DNA_screen_types.h"
|
||||||
#include "DNA_space_types.h"
|
#include "DNA_space_types.h"
|
||||||
|
|
||||||
|
#include "BKE_context.h"
|
||||||
#include "BKE_outliner_treehash.h"
|
#include "BKE_outliner_treehash.h"
|
||||||
|
#include "BKE_layer.h"
|
||||||
|
|
||||||
#include "ED_armature.h"
|
#include "ED_armature.h"
|
||||||
|
#include "ED_outliner.h"
|
||||||
|
|
||||||
#include "UI_interface.h"
|
#include "UI_interface.h"
|
||||||
#include "UI_view2d.h"
|
#include "UI_view2d.h"
|
||||||
@@ -300,3 +304,27 @@ float outliner_restrict_columns_width(const SpaceOutliner *soops)
|
|||||||
}
|
}
|
||||||
return (num_columns * UI_UNIT_X + V2D_SCROLL_WIDTH);
|
return (num_columns * UI_UNIT_X + V2D_SCROLL_WIDTH);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Get base of object under cursor. Used for eyedropper tool */
|
||||||
|
Base *ED_outliner_give_base_under_cursor(bContext *C, const int mval[2])
|
||||||
|
{
|
||||||
|
ARegion *ar = CTX_wm_region(C);
|
||||||
|
ViewLayer *view_layer = CTX_data_view_layer(C);
|
||||||
|
SpaceOutliner *soops = CTX_wm_space_outliner(C);
|
||||||
|
TreeElement *te;
|
||||||
|
Base *base = NULL;
|
||||||
|
float view_mval[2];
|
||||||
|
|
||||||
|
UI_view2d_region_to_view(&ar->v2d, mval[0], mval[1], &view_mval[0], &view_mval[1]);
|
||||||
|
|
||||||
|
te = outliner_find_item_at_y(soops, &soops->tree, view_mval[1]);
|
||||||
|
if (te) {
|
||||||
|
TreeStoreElem *tselem = TREESTORE(te);
|
||||||
|
if (tselem->type == 0) {
|
||||||
|
Object *ob = (Object *)tselem->id;
|
||||||
|
base = (te->directdata) ? (Base *)te->directdata : BKE_view_layer_base_find(view_layer, ob);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return base;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user