[Bf-blender-cvs] [185f588e1c] temp-layers-ui-table: Initial commit to use uiTable API for collections editor
Julian Eisel
noreply at git.blender.org
Sun Feb 5 18:34:02 CET 2017
Commit: 185f588e1c314aed31fe9a6383642bee6df4913a
Author: Julian Eisel
Date: Sun Feb 5 18:22:47 2017 +0100
Branches: temp-layers-ui-table
https://developer.blender.org/rB185f588e1c314aed31fe9a6383642bee6df4913a
Initial commit to use uiTable API for collections editor
Does nothing but drawing a single column for collection name, but it
shows that the API works ;)
===================================================================
M source/blender/editors/space_collections/CMakeLists.txt
A source/blender/editors/space_collections/collections_draw.c
A source/blender/editors/space_collections/collections_edit.c
M source/blender/editors/space_collections/collections_intern.h
M source/blender/editors/space_collections/collections_ops.c
M source/blender/editors/space_collections/space_collections.c
M source/blender/makesdna/DNA_space_types.h
===================================================================
diff --git a/source/blender/editors/space_collections/CMakeLists.txt b/source/blender/editors/space_collections/CMakeLists.txt
index 1cc4a40d65..738a25ff4f 100644
--- a/source/blender/editors/space_collections/CMakeLists.txt
+++ b/source/blender/editors/space_collections/CMakeLists.txt
@@ -20,6 +20,7 @@
set(INC
../include
+ ../../blenfont
../../blenkernel
../../blenlib
../../blentranslation
@@ -36,6 +37,8 @@ set(INC_SYS
)
set(SRC
+ collections_draw.c
+ collections_edit.c
collections_ops.c
space_collections.c
diff --git a/source/blender/editors/space_collections/collections_intern.h b/source/blender/editors/space_collections/collections_draw.c
similarity index 54%
copy from source/blender/editors/space_collections/collections_intern.h
copy to source/blender/editors/space_collections/collections_draw.c
index 866f59659c..188789f81b 100644
--- a/source/blender/editors/space_collections/collections_intern.h
+++ b/source/blender/editors/space_collections/collections_draw.c
@@ -18,18 +18,36 @@
* ***** END GPL LICENSE BLOCK *****
*/
-/** \file blender/editors/space_collections/collections_intern.h
+/** \file blender/editors/space_collections/collections_draw.c
* \ingroup spcollections
*/
-#ifndef __COLLECTIONS_INTERN_H__
-#define __COLLECTIONS_INTERN_H__
+#include <string.h>
-struct wmKeyConfig;
+#include "BLF_api.h"
-/* collections_ops.c */
-void collections_operatortypes(void);
-void collections_keymap(struct wmKeyConfig *keyconf);
+#include "BLI_rect.h"
-#endif /* __COLLECTIONS_INTERN_H__ */
+#include "DNA_screen_types.h"
+#include "DNA_space_types.h"
+#include "UI_resources.h"
+#include "UI_table.h"
+
+#include "collections_intern.h"
+
+
+void collections_draw_table(SpaceCollections *spc, const ARegion *ar)
+{
+ UI_table_max_width_set(spc->table, BLI_rctf_size_x(&ar->v2d.tot));
+ UI_table_draw(spc->table);
+}
+
+void collections_draw_cell(void *rowdata, rcti drawrect)
+{
+ LayerCollection *collection = rowdata;
+ const char *name = collection->scene_collection->name;
+
+ UI_ThemeColor(TH_TEXT);
+ BLF_draw_default(drawrect.xmin, drawrect.ymin, 0.0f, name, strlen(name));
+}
diff --git a/source/blender/editors/space_collections/collections_intern.h b/source/blender/editors/space_collections/collections_edit.c
similarity index 52%
copy from source/blender/editors/space_collections/collections_intern.h
copy to source/blender/editors/space_collections/collections_edit.c
index 866f59659c..b485ebc1a2 100644
--- a/source/blender/editors/space_collections/collections_intern.h
+++ b/source/blender/editors/space_collections/collections_edit.c
@@ -18,18 +18,38 @@
* ***** END GPL LICENSE BLOCK *****
*/
-/** \file blender/editors/space_collections/collections_intern.h
+/** \file blender/editors/space_collections/collections_edit.c
* \ingroup spcollections
*/
-#ifndef __COLLECTIONS_INTERN_H__
-#define __COLLECTIONS_INTERN_H__
+#include <stdio.h>
-struct wmKeyConfig;
+#include "BKE_context.h"
-/* collections_ops.c */
-void collections_operatortypes(void);
-void collections_keymap(struct wmKeyConfig *keyconf);
+#include "DNA_layer_types.h"
+#include "DNA_screen_types.h"
-#endif /* __COLLECTIONS_INTERN_H__ */
+#include "UI_table.h"
+#include "collections_intern.h"
+
+
+void collections_table_create(SceneLayer *layer, uiTable **r_table)
+{
+ *r_table = UI_table_vertical_flow_create();
+
+ UI_table_column_add(*r_table, "collection_name", "Collection", collections_draw_cell);
+ for (LayerCollection *collection = layer->layer_collections.first; collection; collection = collection->next) {
+ UI_table_row_add(*r_table, collection);
+ }
+}
+
+void collections_table_free(uiTable *table)
+{
+ UI_table_free(table);
+}
+
+void collections_table_item_add(uiTable *table, LayerCollection *collection)
+{
+ UI_table_row_add(table, collection);
+}
diff --git a/source/blender/editors/space_collections/collections_intern.h b/source/blender/editors/space_collections/collections_intern.h
index 866f59659c..fdf135775b 100644
--- a/source/blender/editors/space_collections/collections_intern.h
+++ b/source/blender/editors/space_collections/collections_intern.h
@@ -25,11 +25,22 @@
#ifndef __COLLECTIONS_INTERN_H__
#define __COLLECTIONS_INTERN_H__
+struct rcti;
+struct SceneLayer;
struct wmKeyConfig;
+/* collections_edit.c */
+void collections_table_create(struct SceneLayer *layer, struct uiTable **r_table);
+void collections_table_free(struct uiTable *table);
+void collections_table_item_add(struct uiTable *table, struct LayerCollection *collection);
+
/* collections_ops.c */
void collections_operatortypes(void);
void collections_keymap(struct wmKeyConfig *keyconf);
+/* collections_draw.c */
+void collections_draw_table(struct SpaceCollections *spc, const ARegion *ar);
+void collections_draw_cell(void *rowdata, struct rcti drawrect);
+
#endif /* __COLLECTIONS_INTERN_H__ */
diff --git a/source/blender/editors/space_collections/collections_ops.c b/source/blender/editors/space_collections/collections_ops.c
index 7e1bf8091b..7df9e639e4 100644
--- a/source/blender/editors/space_collections/collections_ops.c
+++ b/source/blender/editors/space_collections/collections_ops.c
@@ -122,11 +122,14 @@ static void COLLECTIONS_OT_collection_unlink(wmOperatorType *ot)
static int collection_new_exec(bContext *C, wmOperator *UNUSED(op))
{
+ SpaceCollections *scol = CTX_wm_space_collections(C);
Scene *scene = CTX_data_scene(C);
SceneLayer *sl = CTX_data_scene_layer(C);
SceneCollection *sc = BKE_collection_add(scene, NULL, NULL);
- BKE_collection_link(sl, sc);
+ LayerCollection *lc = BKE_collection_link(sl, sc);
+
+ collections_table_item_add(scol->table, lc);
WM_main_add_notifier(NC_SCENE | ND_LAYER, NULL);
return OPERATOR_FINISHED;
diff --git a/source/blender/editors/space_collections/space_collections.c b/source/blender/editors/space_collections/space_collections.c
index 7dd50e5cba..a6034988e2 100644
--- a/source/blender/editors/space_collections/space_collections.c
+++ b/source/blender/editors/space_collections/space_collections.c
@@ -47,13 +47,14 @@
/* ******************** default callbacks for collection manager space ***************** */
-static SpaceLink *collections_new(const bContext *UNUSED(C))
+static SpaceLink *collections_new(const bContext *C)
{
ARegion *ar;
- SpaceCollections *scollection; /* hmm, that's actually a good band name... */
+ SpaceCollections *scollection;
scollection = MEM_callocN(sizeof(SpaceCollections), __func__);
scollection->spacetype = SPACE_COLLECTIONS;
+ collections_table_create(CTX_data_scene_layer(C), &scollection->table);
/* header */
ar = MEM_callocN(sizeof(ARegion), "header for collection manager");
@@ -71,8 +72,11 @@ static SpaceLink *collections_new(const bContext *UNUSED(C))
return (SpaceLink *)scollection;
}
-static void collections_free(SpaceLink *UNUSED(sl))
+static void collections_free(SpaceLink *sl)
{
+ SpaceCollections *scollection = (SpaceCollections *)sl;
+
+ collections_table_free(scollection->table);
}
static SpaceLink *collections_duplicate(SpaceLink *sl)
@@ -95,12 +99,15 @@ static void collection_main_region_init(wmWindowManager *wm, ARegion *ar)
WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
}
+#include "UI_table.h" /* XXX temporary for assert, can probably move this assert to collections_draw.c later */
static void collections_main_region_draw(const bContext *C, ARegion *ar)
{
SpaceCollections *spc = CTX_wm_space_collections(C);
+ SceneLayer *layer = CTX_data_scene_layer(C);
View2D *v2d = &ar->v2d;
if (spc->flag & SC_COLLECTION_DATA_REFRESH) {
+ /* TODO no need for this yet. */
}
/* v2d has initialized flag, so this call will only set the mask correct */
@@ -109,6 +116,12 @@ static void collections_main_region_draw(const bContext *C, ARegion *ar)
UI_ThemeClearColor(TH_BACK);
glClear(GL_COLOR_BUFFER_BIT);
+ UI_view2d_view_ortho(v2d);
+
+ BLI_assert(BLI_listbase_count(&layer->layer_collections) == UI_table_get_rowcount(spc->table));
+ UNUSED_VARS_NDEBUG(layer);
+ collections_draw_table(spc, ar);
+
/* reset view matrix */
UI_view2d_view_restore(C);
diff --git a/source/blender/makesdna/DNA_space_types.h b/source/blender/makesdna/DNA_space_types.h
index 14eb93e7f2..bdf0f11cd6 100644
--- a/source/blender/makesdna/DNA_space_types.h
+++ b/source/blender/makesdna/DNA_space_types.h
@@ -1351,6 +1351,8 @@ typedef struct SpaceCollections {
ListBase regionbase; /* storage of regions for inactive spaces */
int spacetype;
int flag; /* eSpaceCollections_Flag */
+
+ struct uiTable *table; /* The uiTable used to manage and draw the table UI. */
} SpaceCollections;
/* SpaceClip->flag */
More information about the Bf-blender-cvs
mailing list