Commit: c86e114e757065e3b06d319e2bc93f8846d8d9e8 Author: Julian Eisel Date: Tue May 24 17:24:34 2016 +0200 Branches: soc-2016-layer_manager https://developer.blender.org/rBc86e114e757065e3b06d319e2bc93f8846d8d9e8
Prepare layer manager editor code for further changes * Add (empty) keymap for layer manager * Move list drawing into own file * Add and use a LayerTreeItem wrapper for drawing in editor (will be used later for extra drawing info). =================================================================== M source/blender/blenkernel/BKE_context.h M source/blender/editors/include/ED_object.h M source/blender/editors/object/object_layer.c M source/blender/editors/space_layers/CMakeLists.txt A source/blender/editors/space_layers/layers_draw.c M source/blender/editors/space_layers/layers_intern.h M source/blender/editors/space_layers/layers_ops.c A source/blender/editors/space_layers/layers_util.c M source/blender/editors/space_layers/space_layers.c M source/blender/makesdna/DNA_space_types.h M source/blender/windowmanager/CMakeLists.txt M source/blender/windowmanager/intern/wm_keymap.c =================================================================== diff --git a/source/blender/blenkernel/BKE_context.h b/source/blender/blenkernel/BKE_context.h index 2c34156..2bcb7d4 100644 --- a/source/blender/blenkernel/BKE_context.h +++ b/source/blender/blenkernel/BKE_context.h @@ -162,9 +162,9 @@ struct SpaceAction *CTX_wm_space_action(const bContext *C); struct SpaceInfo *CTX_wm_space_info(const bContext *C); struct SpaceUserPref *CTX_wm_space_userpref(const bContext *C); struct SpaceClip *CTX_wm_space_clip(const bContext *C); -#ifdef WITH_ADVANCED_LAYERS +//#ifdef WITH_ADVANCED_LAYERS struct SpaceLayers *CTX_wm_space_layers(const bContext *C); -#endif +//#endif void CTX_wm_manager_set(bContext *C, struct wmWindowManager *wm); void CTX_wm_window_set(bContext *C, struct wmWindow *win); diff --git a/source/blender/editors/include/ED_object.h b/source/blender/editors/include/ED_object.h index f781736..f4ab00b 100644 --- a/source/blender/editors/include/ED_object.h +++ b/source/blender/editors/include/ED_object.h @@ -179,7 +179,7 @@ void undo_push_lattice(struct bContext *C, const char *name); void ED_lattice_flags_set(struct Object *obedit, int flag); /* object_layer.c */ -void ED_object_layer_add(struct LayerTree *ltree, const char *name); +struct LayerTreeItem *ED_object_layer_add(struct LayerTree *ltree, const char *name); /* object_modifier.c */ enum { diff --git a/source/blender/editors/object/object_layer.c b/source/blender/editors/object/object_layer.c index bc0c831..2ba31b4 100644 --- a/source/blender/editors/object/object_layer.c +++ b/source/blender/editors/object/object_layer.c @@ -57,9 +57,9 @@ static void object_layer_draw_settings(LayerTreeItem *UNUSED(litem), uiLayout *U * Add an object layer to \a ltree. * \param name: Name of the layer to add. NULL for default ("Untitled Layer"). */ -void ED_object_layer_add(LayerTree *ltree, const char *name) +LayerTreeItem *ED_object_layer_add(LayerTree *ltree, const char *name) { - BKE_layeritem_add( + return BKE_layeritem_add( ltree, NULL, LAYER_TREETYPE_OBJECT, name ? name : OBJECTLAYER_DEFAULT_NAME, NULL, object_layer_draw, object_layer_draw_settings); } diff --git a/source/blender/editors/space_layers/CMakeLists.txt b/source/blender/editors/space_layers/CMakeLists.txt index 397b2f4..9df1798 100644 --- a/source/blender/editors/space_layers/CMakeLists.txt +++ b/source/blender/editors/space_layers/CMakeLists.txt @@ -35,7 +35,9 @@ set(INC_SYS ) set(SRC + layers_draw.c layers_ops.c + layers_util.c space_layers.c layers_intern.h diff --git a/source/blender/editors/space_layers/layers_draw.c b/source/blender/editors/space_layers/layers_draw.c new file mode 100644 index 0000000..f149134 --- /dev/null +++ b/source/blender/editors/space_layers/layers_draw.c @@ -0,0 +1,67 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/editors/space_layers/layers_draw.c + * \ingroup splayers + */ + +#include "BLI_listbase.h" + +#include "BKE_context.h" +#include "BKE_layer.h" + +#include "DNA_scene_types.h" +#include "DNA_screen_types.h" +#include "DNA_space_types.h" + +#include "UI_interface.h" +#include "UI_view2d.h" + +#include "layers_intern.h" /* own include */ + +void layers_draw_tiles(const bContext *C, ARegion *ar) +{ + uiStyle *style = UI_style_get_dpi(); + SpaceLayers *slayer = CTX_wm_space_layers(C); + View2D *v2d = &ar->v2d; + float size_x = ar->winx; + float size_y = 0.0f; + + uiBlock *block = UI_block_begin(C, ar, __func__, UI_EMBOSS); + + /* draw items */ + for (LayerTile *tile = slayer->layer_tiles.first; tile; tile = tile->next) { + LayerTreeItem *litem = tile->litem; + if (litem->draw) { + uiLayout *layout = UI_block_layout( + block, UI_LAYOUT_HORIZONTAL, UI_LAYOUT_HEADER, + 0, ar->winy - size_y, litem->height, 0, 0, style); + litem->draw(litem, layout); + UI_block_layout_resolve(block, NULL, NULL); + } + size_y += litem->height; + } + + UI_block_end(C, block); + UI_block_draw(C, block); + + /* update size of tot-rect (extents of data/viewable area) */ + UI_view2d_totRect_set(v2d, size_x, size_y); +} diff --git a/source/blender/editors/space_layers/layers_intern.h b/source/blender/editors/space_layers/layers_intern.h index 95d6a40..a14d678 100644 --- a/source/blender/editors/space_layers/layers_intern.h +++ b/source/blender/editors/space_layers/layers_intern.h @@ -22,11 +22,30 @@ * \ingroup splayers */ - #ifndef __LAYERS_INTERN_H__ #define __LAYERS_INTERN_H__ +struct ARegion; +struct wmKeyConfig; + +/** + * Wrapper around LayerTreeItem with extra info for drawing in layer manager editor. + */ +typedef struct LayerTile { + struct LayerTile *next, *prev; + + LayerTreeItem *litem; +} LayerTile; + +/* layers_draw.c */ +void layers_draw_tiles(const struct bContext *C, struct ARegion *ar); + +/* layers_util.c */ +LayerTile *layers_tile_add(struct SpaceLayers *slayer, struct LayerTreeItem *litem); + +/* layers_ops.c */ void layers_operatortypes(void); +void layers_keymap(struct wmKeyConfig *keyconf); #endif /* __LAYERS_INTERN_H__ */ diff --git a/source/blender/editors/space_layers/layers_ops.c b/source/blender/editors/space_layers/layers_ops.c index 18283ae..ee0bb5a 100644 --- a/source/blender/editors/space_layers/layers_ops.c +++ b/source/blender/editors/space_layers/layers_ops.c @@ -23,6 +23,7 @@ */ #include "BKE_context.h" +#include "BKE_layer.h" #include "BLI_compiler_attrs.h" @@ -39,10 +40,17 @@ static int layer_add_invoke(bContext *C, wmOperator *UNUSED(op), const wmEvent *UNUSED(event)) { + SpaceLayers *slayer = CTX_wm_space_layers(C); + LayerTreeItem *new_item; + if (true) { /* context check (like: slayer->context == SLAYER_CONTEXT_OBJECT) */ Scene *scene = CTX_data_scene(C); - ED_object_layer_add(scene->object_layers, NULL); + new_item = ED_object_layer_add(scene->object_layers, NULL); + } + else { + BLI_assert(0); } + layers_tile_add(slayer, new_item); WM_event_add_notifier(C, NC_SCENE | ND_LAYER, NULL); @@ -71,3 +79,9 @@ void layers_operatortypes(void) { WM_operatortype_append(LAYERS_OT_layer_add); } + +void layers_keymap(wmKeyConfig *keyconf) +{ + wmKeyMap *keymap = WM_keymap_find(keyconf, "Layer Manager", SPACE_LAYERS, 0); + (void)keymap; +} diff --git a/source/blender/editors/space_layers/layers_intern.h b/source/blender/editors/space_layers/layers_util.c similarity index 60% copy from source/blender/editors/space_layers/layers_intern.h copy to source/blender/editors/space_layers/layers_util.c index 95d6a40..d35df82 100644 --- a/source/blender/editors/space_layers/layers_intern.h +++ b/source/blender/editors/space_layers/layers_util.c @@ -18,15 +18,32 @@ * ***** END GPL LICENSE BLOCK ***** */ -/** \file blender/editors/space_layers/layers_intern.h +/** \file blender/editors/space_layers/layers_util.c * \ingroup splayers + * + * Utility functions for layer manager editor. */ +#include "BLI_listbase.h" + +#include "BKE_layer.h" + +#include "DNA_space_types.h" -#ifndef __LAYERS_INTERN_H__ -#define __LAYERS_INTERN_H__ +#include "MEM_guardedalloc.h" -void layers_operatortypes(void); +#include "layers_intern.h" + + +/** + * Allocate and register a LayerTile entry for \a litem in layer_item list of \a slayer. + */ +LayerTile *layers_tile_add(SpaceLayers *slayer, LayerTreeItem *litem) +{ + LayerTile *tile = MEM_callocN(sizeof(LayerTile), __func__); -#endif /* __LAYERS_INTERN_H__ */ + tile->litem = litem; + BLI_addhead(&slayer->layer_tiles, tile); + return tile; +} diff --git a/source/blender/editors/space_layers/space_layers.c b/source/blender/editors/space_layers/space_layers.c index 8c11faa..36554a1 100644 --- a/source/blender/editors/space_layers/space_layers.c +++ b/source/blender/editors/space_layers/space_layers.c @@ -33,18 +33,14 @@ #include "BKE_screen.h" #include "BLI_listbase.h" -#include "BLI_utildefines.h" - -#include "DNA_space_types.h" -#include "DNA_windowmanager_types.h" #include "ED_screen.h" #include "ED_space_api.h" -#include "UI_interface.h" #include "UI_resources.h" #include "UI_view2d.h" +#include "WM_api.h" #include "WM_types.h" #include "layers_intern.h" /* own include */ @@ -76,6 +72,13 @@ static SpaceLink *layers_new(const bContext *UNUSED(C)) return (SpaceLink *)slayer; } +/* not spacelink itself */ +static void layers_free(SpaceLink *sl) +{ + SpaceLayers *slayer = (SpaceLayers *)sl; + BLI_freelistN(&slayer->layer_tiles); +} + static SpaceLink *layers_duplicate(SpaceLink *sl) { SpaceLayers *slayer = MEM_dupallocN(sl); @@ -85,6 +88,14 @@ static SpaceLink *layers_duplicate(SpaceLink *sl) return (SpaceLink *)slayer; } +/* add handlers, stuff you only do once or on area changes */ +static void layer_init(wmWindowManager *wm, ScrArea *sa) +{ + /* own keymap */ + wmKeyMap *keymap = WM_keymap_find(wm->defaultconf, "Layer Manager", SPACE_LAYERS, 0); + WM_event_add_keymap_handler(&sa->handlers, keymap); +} + /* add handlers, stuff you only do once or on area/region changes */ static void layer_main_region_init(wmWindowManager *UNUSED(wm), ARegion *ar) { @@ -96,33 +107,12 @@ static void layer_main_region_init(wmWindowManager *UNUSED(wm), ARegion *ar) static void layers_main_region_draw(const bContext *C, ARegion *ar) { - Scene *scene = CTX_data_scene(C); - uiStyle *style = UI_style_get_dpi(); View2D *v2d = &ar->v2d; - float size_x = ar->winx; - float size_y = 0.0f; UI_ThemeClearColor(TH_BACK); glClear(GL_COLOR_BUFFE @@ Diff output truncated at 10240 characters. @@ _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org https://lists.blender.org/mailman/listinfo/bf-blender-cvs