[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [57584] trunk/blender: This commit tackles the "context" buttons in Properties header, which were still using "ugly" old UI code.

Bastien Montagne montagne29 at wanadoo.fr
Wed Jun 19 21:37:17 CEST 2013


Revision: 57584
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=57584
Author:   mont29
Date:     2013-06-19 19:37:17 +0000 (Wed, 19 Jun 2013)
Log Message:
-----------
This commit tackles the "context" buttons in Properties header, which were still using "ugly" old UI code.

It removes buttons_header.c file, adds a (small) space_properties.py one, with a PROPERTIES_HT_header class, which simply uses the RNA enum to draw the context buttons.
It also fixes that enum, btw, it always featured all contexts, which means you could (try to!) set through RNA invalid contexts...

Thanks to brecht and dingto for the reviews.

Modified Paths:
--------------
    trunk/blender/release/scripts/startup/bl_ui/__init__.py
    trunk/blender/source/blender/editors/space_buttons/CMakeLists.txt
    trunk/blender/source/blender/editors/space_buttons/buttons_intern.h
    trunk/blender/source/blender/editors/space_buttons/space_buttons.c
    trunk/blender/source/blender/makesrna/intern/rna_space.c

Added Paths:
-----------
    trunk/blender/release/scripts/startup/bl_ui/space_properties.py

Removed Paths:
-------------
    trunk/blender/source/blender/editors/space_buttons/buttons_header.c

Modified: trunk/blender/release/scripts/startup/bl_ui/__init__.py
===================================================================
--- trunk/blender/release/scripts/startup/bl_ui/__init__.py	2013-06-19 18:59:54 UTC (rev 57583)
+++ trunk/blender/release/scripts/startup/bl_ui/__init__.py	2013-06-19 19:37:17 UTC (rev 57584)
@@ -68,6 +68,7 @@
     "space_nla",
     "space_node",
     "space_outliner",
+    "space_properties",
     "space_sequencer",
     "space_text",
     "space_time",

Added: trunk/blender/release/scripts/startup/bl_ui/space_properties.py
===================================================================
--- trunk/blender/release/scripts/startup/bl_ui/space_properties.py	                        (rev 0)
+++ trunk/blender/release/scripts/startup/bl_ui/space_properties.py	2013-06-19 19:37:17 UTC (rev 57584)
@@ -0,0 +1,46 @@
+# ##### 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 #####
+
+# <pep8 compliant>
+import bpy
+from bpy.types import Header
+
+
+class PROPERTIES_HT_header(Header):
+    bl_space_type = 'PROPERTIES'
+
+    def draw(self, context):
+        layout = self.layout
+
+        view = context.space_data
+
+        row = layout.row()
+        row.template_header(menus=False)
+        row.prop(view, "context", expand=True, icon_only=True)
+
+
+def register():
+    bpy.utils.register_module(__name__)
+
+
+def unregister():
+    bpy.utils.unregister_module(__name__)
+
+
+if __name__ == "__main__":
+    register()


Property changes on: trunk/blender/release/scripts/startup/bl_ui/space_properties.py
___________________________________________________________________
Added: svn:eol-style
   + native

Modified: trunk/blender/source/blender/editors/space_buttons/CMakeLists.txt
===================================================================
--- trunk/blender/source/blender/editors/space_buttons/CMakeLists.txt	2013-06-19 18:59:54 UTC (rev 57583)
+++ trunk/blender/source/blender/editors/space_buttons/CMakeLists.txt	2013-06-19 19:37:17 UTC (rev 57584)
@@ -35,7 +35,6 @@
 
 set(SRC
 	buttons_context.c
-	buttons_header.c
 	buttons_ops.c
 	buttons_texture.c
 	space_buttons.c

Deleted: trunk/blender/source/blender/editors/space_buttons/buttons_header.c
===================================================================
--- trunk/blender/source/blender/editors/space_buttons/buttons_header.c	2013-06-19 18:59:54 UTC (rev 57583)
+++ trunk/blender/source/blender/editors/space_buttons/buttons_header.c	2013-06-19 19:37:17 UTC (rev 57584)
@@ -1,140 +0,0 @@
-/*
- * ***** 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.
- *
- * The Original Code is Copyright (C) 2008 Blender Foundation.
- * All rights reserved.
- *
- * 
- * Contributor(s): Blender Foundation
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file blender/editors/space_buttons/buttons_header.c
- *  \ingroup spbuttons
- */
-
-
-#include <string.h>
-#include <stdio.h>
-
-#include "BLI_blenlib.h"
-#include "BLI_utildefines.h"
-
-#include "BLF_translation.h"
-
-#include "BKE_context.h"
-#include "BKE_modifier.h"
-#include "BKE_paint.h"
-#include "BKE_scene.h"
-
-#include "ED_buttons.h"
-#include "ED_screen.h"
-#include "ED_types.h"
-
-#include "DNA_brush_types.h"
-#include "DNA_object_force.h"
-#include "DNA_object_types.h"
-
-#include "UI_interface.h"
-#include "UI_resources.h"
-#include "UI_view2d.h"
-
-#include "buttons_intern.h"
-
-
-#define B_CONTEXT_SWITCH    101
-
-static void do_buttons_buttons(bContext *C, void *UNUSED(arg), int event)
-{
-	SpaceButs *sbuts = CTX_wm_space_buts(C);
-
-	if (!sbuts) /* editor type switch */
-		return;
-
-	switch (event) {
-		case B_CONTEXT_SWITCH:
-			ED_area_tag_redraw(CTX_wm_area(C));
-
-			sbuts->preview = 1;
-			break;
-	}
-
-	sbuts->mainbuser = sbuts->mainb;
-}
-
-#define BUT_UNIT_X (UI_UNIT_X + 2 * U.pixelsize)
-
-void buttons_header_buttons(const bContext *C, ARegion *ar)
-{
-	SpaceButs *sbuts = CTX_wm_space_buts(C);
-	uiBlock *block;
-	uiBut *but;
-	int headery = ED_area_headersize();
-	int xco, yco = 0.5f * (headery - UI_UNIT_Y);
-
-	buttons_context_compute(C, sbuts);
-	
-	block = uiBeginBlock(C, ar, __func__, UI_EMBOSS);
-	uiBlockSetHandleFunc(block, do_buttons_buttons, NULL);
-	
-	xco = ED_area_header_switchbutton(C, block, yco);
-	
-	uiBlockSetEmboss(block, UI_EMBOSS);
-
-	xco -= UI_UNIT_X;
-
-	/* Default panels */
-
-	uiBlockBeginAlign(block);
-
-#define BUTTON_HEADER_CTX(_ctx, _icon, _tip) \
-	if (sbuts->pathflag & (1 << _ctx)) { \
-		but = uiDefIconButS(block, ROW, B_CONTEXT_SWITCH, _icon, xco += BUT_UNIT_X, yco, BUT_UNIT_X, UI_UNIT_Y, \
-		                    &(sbuts->mainb), 0.0, (float)_ctx, 0, 0, TIP_(_tip)); \
-		uiButClearFlag(but, UI_BUT_UNDO); \
-	} (void)0
-
-	BUTTON_HEADER_CTX(BCONTEXT_RENDER, ICON_SCENE, N_("Render"));
-	BUTTON_HEADER_CTX(BCONTEXT_RENDER_LAYER, ICON_RENDERLAYERS, N_("Render Layers"));
-	BUTTON_HEADER_CTX(BCONTEXT_SCENE, ICON_SCENE_DATA, N_("Scene"));
-	BUTTON_HEADER_CTX(BCONTEXT_WORLD, ICON_WORLD, N_("World"));
-	BUTTON_HEADER_CTX(BCONTEXT_OBJECT, ICON_OBJECT_DATA, N_("Object"));
-	BUTTON_HEADER_CTX(BCONTEXT_CONSTRAINT, ICON_CONSTRAINT, N_("Object Constraints"));
-	BUTTON_HEADER_CTX(BCONTEXT_MODIFIER, ICON_MODIFIER, N_("Object Modifiers"));
-	BUTTON_HEADER_CTX(BCONTEXT_DATA, sbuts->dataicon, N_("Object Data"));
-	BUTTON_HEADER_CTX(BCONTEXT_BONE, ICON_BONE_DATA, N_("Bone"));
-	BUTTON_HEADER_CTX(BCONTEXT_BONE_CONSTRAINT, ICON_CONSTRAINT_BONE, N_("Bone Constraints"));
-	BUTTON_HEADER_CTX(BCONTEXT_MATERIAL, ICON_MATERIAL, N_("Material"));
-	BUTTON_HEADER_CTX(BCONTEXT_TEXTURE, ICON_TEXTURE, N_("Textures"));
-	BUTTON_HEADER_CTX(BCONTEXT_PARTICLE, ICON_PARTICLES, N_("Particles"));
-	BUTTON_HEADER_CTX(BCONTEXT_PHYSICS, ICON_PHYSICS, N_("Physics"));
-
-#undef BUTTON_HEADER_CTX
-
-	xco += BUT_UNIT_X;
-	
-	uiBlockEndAlign(block);
-	
-	/* always as last  */
-	UI_view2d_totRect_set(&ar->v2d, xco + (UI_UNIT_X / 2), BLI_rctf_size_y(&ar->v2d.tot));
-	
-	uiEndBlock(C, block);
-	uiDrawBlock(C, block);
-}
-
-

Modified: trunk/blender/source/blender/editors/space_buttons/buttons_intern.h
===================================================================
--- trunk/blender/source/blender/editors/space_buttons/buttons_intern.h	2013-06-19 18:59:54 UTC (rev 57583)
+++ trunk/blender/source/blender/editors/space_buttons/buttons_intern.h	2013-06-19 19:37:17 UTC (rev 57584)
@@ -97,9 +97,6 @@
 
 /* internal exports only */
 
-/* buttons_header.c */
-void buttons_header_buttons(const struct bContext *C, struct ARegion *ar);
-
 /* buttons_context.c */
 void buttons_context_compute(const struct bContext *C, struct SpaceButs *sbuts);
 int buttons_context(const struct bContext *C, const char *member, struct bContextDataResult *result);

Modified: trunk/blender/source/blender/editors/space_buttons/space_buttons.c
===================================================================
--- trunk/blender/source/blender/editors/space_buttons/space_buttons.c	2013-06-19 18:59:54 UTC (rev 57583)
+++ trunk/blender/source/blender/editors/space_buttons/space_buttons.c	2013-06-19 19:37:17 UTC (rev 57584)
@@ -87,7 +87,7 @@
 	
 	BLI_addtail(&sbuts->regionbase, ar);
 	ar->regiontype = RGN_TYPE_WINDOW;
-	
+
 	return (SpaceLink *)sbuts;
 }
 
@@ -200,22 +200,17 @@
 /* add handlers, stuff you only do once or on area/region changes */
 static void buttons_header_area_init(wmWindowManager *UNUSED(wm), ARegion *ar)
 {
-	UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_HEADER, ar->winx, ar->winy);
+	ED_region_header_init(ar);
 }
 
 static void buttons_header_area_draw(const bContext *C, ARegion *ar)
 {
-	/* clear */
-	UI_ThemeClearColor(ED_screen_area_active(C) ? TH_HEADER : TH_HEADERDESEL);
-	glClear(GL_COLOR_BUFFER_BIT);
-	
-	/* set view2d view matrix for scrolling (without scrollers) */
-	UI_view2d_view_ortho(&ar->v2d);
-	
-	buttons_header_buttons(C, ar);
+	SpaceButs *sbuts = CTX_wm_space_buts(C);
 
-	/* restore view matrix? */
-	UI_view2d_view_restore(C);
+	/* Needed for RNA to get the good values! */
+	buttons_context_compute(C, sbuts);
+
+	ED_region_header(C, ar);
 }
 
 /* draw a certain button set only if properties area is currently

Modified: trunk/blender/source/blender/makesrna/intern/rna_space.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_space.c	2013-06-19 18:59:54 UTC (rev 57583)
+++ trunk/blender/source/blender/makesrna/intern/rna_space.c	2013-06-19 19:37:17 UTC (rev 57584)
@@ -138,6 +138,25 @@
 };
 
 /* Actually populated dynamically trough a function, but helps for context-less access (e.g. doc, i18n...). */
+static EnumPropertyItem buttons_context_items[] = {
+	{BCONTEXT_SCENE, "SCENE", ICON_SCENE_DATA, "Scene", "Scene"},
+	{BCONTEXT_RENDER, "RENDER", ICON_SCENE, "Render", "Render"},
+	{BCONTEXT_RENDER_LAYER, "RENDER_LAYER", ICON_RENDERLAYERS, "Render Layers", "Render layers"},
+	{BCONTEXT_WORLD, "WORLD", ICON_WORLD, "World", "World"},
+	{BCONTEXT_OBJECT, "OBJECT", ICON_OBJECT_DATA, "Object", "Object"},
+	{BCONTEXT_CONSTRAINT, "CONSTRAINT", ICON_CONSTRAINT, "Constraints", "Object constraints"},

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list