[Bf-blender-cvs] [cb2b5da12db] soc-2020-outliner: Outliner: Pass tselem instead of te to button functions
Nathan Craddock
noreply at git.blender.org
Thu Jun 11 05:55:15 CEST 2020
Commit: cb2b5da12db6aec13c022db31773fa1bbd75cbca
Author: Nathan Craddock
Date: Wed Jun 10 20:57:02 2020 -0600
Branches: soc-2020-outliner
https://developer.blender.org/rBcb2b5da12db6aec13c022db31773fa1bbd75cbca
Outliner: Pass tselem instead of te to button functions
When adding callback functions to icon buttons in the outliner, don't
pass the tree element as a pointer because the pointer address changes
between redraws. Instead, pass the tree store element, or pass the data
that is needed.
===================================================================
M source/blender/editors/space_outliner/outliner_draw.c
M source/blender/editors/space_outliner/outliner_intern.h
M source/blender/editors/space_outliner/outliner_select.c
===================================================================
diff --git a/source/blender/editors/space_outliner/outliner_draw.c b/source/blender/editors/space_outliner/outliner_draw.c
index dd2fb39513f..4fddccd4bff 100644
--- a/source/blender/editors/space_outliner/outliner_draw.c
+++ b/source/blender/editors/space_outliner/outliner_draw.c
@@ -1902,12 +1902,11 @@ static void outliner_buttons(const bContext *C,
}
}
-static void outliner_set_active_data_fn(bContext *C, void *te_poin, void *UNUSED(arg2))
+static void outliner_set_active_data_fn(bContext *C, void *tselem_poin, void *UNUSED(arg2))
{
Scene *scene = CTX_data_scene(C);
- TreeElement *te = (TreeElement *)te_poin;
- outliner_set_active_camera(C, scene, te);
+ outliner_set_active_camera(C, scene, tselem_poin);
}
/* Draw icons for setting activation when in object mode */
@@ -1926,7 +1925,7 @@ static void outliner_draw_left_column_activation(const bContext *C,
if (tvc->scene->camera == ob) {
/* Draw check for active camera */
but = uiDefIconBut(block,
- UI_BTYPE_LABEL,
+ UI_BTYPE_ICON_TOGGLE,
0,
ICON_CHECKMARK,
0,
@@ -1943,7 +1942,7 @@ static void outliner_draw_left_column_activation(const bContext *C,
else {
/* Draw dot icon to set active camera */
but = uiDefIconBut(block,
- UI_BTYPE_LABEL,
+ UI_BTYPE_ICON_TOGGLE,
0,
ICON_DOT,
0,
@@ -1957,7 +1956,7 @@ static void outliner_draw_left_column_activation(const bContext *C,
0.0,
TIP_("Set active camera"));
/* TODO: adding functions to these buttons doesn't work well */
- /* UI_but_func_set(but, outliner_set_active_data_fn, te, NULL); */
+ UI_but_func_set(but, outliner_set_active_data_fn, tselem, NULL);
}
}
}
@@ -1967,7 +1966,7 @@ static void outliner_draw_left_column_activation(const bContext *C,
if (tvc->scene == scene) {
/* Draw check for active scene */
but = uiDefIconBut(block,
- UI_BTYPE_LABEL,
+ UI_BTYPE_ICON_TOGGLE,
0,
ICON_CHECKMARK,
0,
@@ -1984,7 +1983,7 @@ static void outliner_draw_left_column_activation(const bContext *C,
else {
/* Draw dot icon to set active scene */
but = uiDefIconBut(block,
- UI_BTYPE_LABEL,
+ UI_BTYPE_ICON_TOGGLE,
0,
ICON_DOT,
0,
@@ -1997,7 +1996,7 @@ static void outliner_draw_left_column_activation(const bContext *C,
0.0,
0.0,
TIP_("Set active scene"));
- /* UI_but_func_set(but, outliner_set_active_data_fn, te, NULL); */
+ UI_but_func_set(but, outliner_set_active_data_fn, tselem, NULL);
}
}
else if (ELEM(tselem->type, TSE_VIEW_COLLECTION_BASE, TSE_LAYER_COLLECTION)) {
@@ -2008,7 +2007,7 @@ static void outliner_draw_left_column_activation(const bContext *C,
(tselem->type == TSE_LAYER_COLLECTION && active == te->directdata)) {
/* Draw check for active collection */
but = uiDefIconBut(block,
- UI_BTYPE_LABEL,
+ UI_BTYPE_ICON_TOGGLE,
0,
ICON_CHECKMARK,
0,
@@ -2025,7 +2024,7 @@ static void outliner_draw_left_column_activation(const bContext *C,
else {
/* Draw dot icon to set active collection */
but = uiDefIconBut(block,
- UI_BTYPE_LABEL,
+ UI_BTYPE_ICON_TOGGLE,
0,
ICON_DOT,
0,
@@ -2038,7 +2037,7 @@ static void outliner_draw_left_column_activation(const bContext *C,
0.0,
0.0,
TIP_("Set active collection"));
- /* UI_but_func_set(but, outliner_set_active_data_fn, te, NULL); */
+ UI_but_func_set(but, outliner_set_active_data_fn, tselem, NULL);
}
}
}
@@ -2059,7 +2058,7 @@ static void outliner_draw_left_column_mode_toggle(const bContext *C,
if (ob->mode == tvc->ob_edit->mode) {
/* Draw mode icon for objects in edit mode */
but = uiDefIconBut(block,
- UI_BTYPE_LABEL,
+ UI_BTYPE_ICON_TOGGLE,
0,
ICON_EDITMODE_HLT,
0,
@@ -2076,7 +2075,7 @@ static void outliner_draw_left_column_mode_toggle(const bContext *C,
else {
/* Draw dot for objects that are compatible with the current edit mode */
but = uiDefIconBut(block,
- UI_BTYPE_LABEL,
+ UI_BTYPE_ICON_TOGGLE,
0,
ICON_DOT,
0,
diff --git a/source/blender/editors/space_outliner/outliner_intern.h b/source/blender/editors/space_outliner/outliner_intern.h
index 551212a4aee..93fcf84928d 100644
--- a/source/blender/editors/space_outliner/outliner_intern.h
+++ b/source/blender/editors/space_outliner/outliner_intern.h
@@ -292,7 +292,7 @@ bool outliner_item_is_co_over_name_icons(const TreeElement *te, float view_co_x)
bool outliner_item_is_co_within_close_toggle(const TreeElement *te, float view_co_x);
/* TODO: Temporary while testing */
-void outliner_set_active_camera(struct bContext *C, Scene *scene, TreeElement *te);
+void outliner_set_active_camera(struct bContext *C, Scene *scene, struct TreeStoreElem *tselem);
/* outliner_edit.c ---------------------------------------------- */
typedef void (*outliner_operation_cb)(struct bContext *C,
diff --git a/source/blender/editors/space_outliner/outliner_select.c b/source/blender/editors/space_outliner/outliner_select.c
index 4f2b9500391..f1a5373574c 100644
--- a/source/blender/editors/space_outliner/outliner_select.c
+++ b/source/blender/editors/space_outliner/outliner_select.c
@@ -1141,9 +1141,8 @@ eOLDrawState tree_element_type_active(bContext *C,
}
/* TODO: Temporary while testing */
-void outliner_set_active_camera(bContext *C, Scene *scene, TreeElement *te)
+void outliner_set_active_camera(bContext *C, Scene *scene, TreeStoreElem *tselem)
{
- TreeStoreElem *tselem = TREESTORE(te);
Object *ob = (Object *)tselem->id;
scene->camera = ob;
@@ -1165,7 +1164,7 @@ static void outliner_set_active_data(bContext *C,
if (tselem->type == 0 && te->idcode == ID_OB) {
Object *ob = (Object *)tselem->id;
if (ob->type == OB_CAMERA) {
- outliner_set_active_camera(C, tvc->scene, te);
+ outliner_set_active_camera(C, tvc->scene, tselem);
}
}
else if (tselem->type == 0 && te->idcode == ID_SCE) {
@@ -1443,6 +1442,9 @@ static int outliner_item_do_activate_from_cursor(bContext *C,
if (outliner_is_co_within_restrict_columns(soops, region, view_mval[0])) {
return OPERATOR_CANCELLED;
}
+ else if (soops->flag & SO_LEFT_COLUMN && view_mval[0] < UI_UNIT_X) {
+ return OPERATOR_CANCELLED;
+ }
if (!(te = outliner_find_item_at_y(soops, &soops->tree, view_mval[1]))) {
if (deselect_all) {
@@ -1455,11 +1457,6 @@ static int outliner_item_do_activate_from_cursor(bContext *C,
outliner_item_is_co_within_close_toggle(te, view_mval[0])) {
return OPERATOR_CANCELLED | OPERATOR_PASS_THROUGH;
}
- /* Set active data on left column click */
- /* TODO: Decide if this is best as button callbacks or here in outliner_select */
- else if (soops->flag & SO_LEFT_COLUMN && view_mval[0] < UI_UNIT_X) {
- outliner_left_column_click(C, soops, te);
- }
else {
/* The row may also contain children, if one is hovered we want this instead of current te */
bool merged_elements = false;
More information about the Bf-blender-cvs
mailing list