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.
This commit is contained in:
Bastien Montagne 2013-06-19 19:37:17 +00:00
parent d54d00ef84
commit 881dbac5d9
7 changed files with 144 additions and 175 deletions

@ -68,6 +68,7 @@ _modules = [
"space_nla", "space_nla",
"space_node", "space_node",
"space_outliner", "space_outliner",
"space_properties",
"space_sequencer", "space_sequencer",
"space_text", "space_text",
"space_time", "space_time",

@ -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()

@ -35,7 +35,6 @@ set(INC_SYS
set(SRC set(SRC
buttons_context.c buttons_context.c
buttons_header.c
buttons_ops.c buttons_ops.c
buttons_texture.c buttons_texture.c
space_buttons.c space_buttons.c

@ -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);
}

@ -97,9 +97,6 @@ typedef struct ButsContextTexture {
/* internal exports only */ /* internal exports only */
/* buttons_header.c */
void buttons_header_buttons(const struct bContext *C, struct ARegion *ar);
/* buttons_context.c */ /* buttons_context.c */
void buttons_context_compute(const struct bContext *C, struct SpaceButs *sbuts); void buttons_context_compute(const struct bContext *C, struct SpaceButs *sbuts);
int buttons_context(const struct bContext *C, const char *member, struct bContextDataResult *result); int buttons_context(const struct bContext *C, const char *member, struct bContextDataResult *result);

@ -87,7 +87,7 @@ static SpaceLink *buttons_new(const bContext *UNUSED(C))
BLI_addtail(&sbuts->regionbase, ar); BLI_addtail(&sbuts->regionbase, ar);
ar->regiontype = RGN_TYPE_WINDOW; ar->regiontype = RGN_TYPE_WINDOW;
return (SpaceLink *)sbuts; return (SpaceLink *)sbuts;
} }
@ -200,22 +200,17 @@ static void buttons_keymap(struct wmKeyConfig *keyconf)
/* add handlers, stuff you only do once or on area/region changes */ /* add handlers, stuff you only do once or on area/region changes */
static void buttons_header_area_init(wmWindowManager *UNUSED(wm), ARegion *ar) 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) static void buttons_header_area_draw(const bContext *C, ARegion *ar)
{ {
/* clear */ SpaceButs *sbuts = CTX_wm_space_buts(C);
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);
/* restore view matrix? */ /* Needed for RNA to get the good values! */
UI_view2d_view_restore(C); buttons_context_compute(C, sbuts);
ED_region_header(C, ar);
} }
/* draw a certain button set only if properties area is currently /* draw a certain button set only if properties area is currently

@ -137,6 +137,25 @@ EnumPropertyItem clip_editor_mode_items[] = {
{0, NULL, 0, NULL, NULL} {0, NULL, 0, NULL, NULL}
}; };
/* 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"},
{BCONTEXT_MODIFIER, "MODIFIER", ICON_MODIFIER, "Modifiers", "Object modifiers"},
{BCONTEXT_DATA, "DATA", ICON_NONE, "Data", "Object data"},
{BCONTEXT_BONE, "BONE", ICON_BONE_DATA, "Bone", "Bone"},
{BCONTEXT_BONE_CONSTRAINT, "BONE_CONSTRAINT", ICON_CONSTRAINT, "Bone Constraints", "Bone constraints"},
{BCONTEXT_MATERIAL, "MATERIAL", ICON_MATERIAL, "Material", "Material"},
{BCONTEXT_TEXTURE, "TEXTURE", ICON_TEXTURE, "Texture", "Texture"},
{BCONTEXT_PARTICLE, "PARTICLES", ICON_PARTICLES, "Particles", "Particle"},
{BCONTEXT_PHYSICS, "PHYSICS", ICON_PHYSICS, "Physics", "Physics"},
{0, NULL, 0, NULL, NULL}
};
/* Actually populated dynamically trough a function, but helps for context-less access (e.g. doc, i18n...). */ /* Actually populated dynamically trough a function, but helps for context-less access (e.g. doc, i18n...). */
static EnumPropertyItem buttons_texture_context_items[] = { static EnumPropertyItem buttons_texture_context_items[] = {
{SB_TEXC_MATERIAL, "MATERIAL", ICON_MATERIAL, "", "Show material textures"}, {SB_TEXC_MATERIAL, "MATERIAL", ICON_MATERIAL, "", "Show material textures"},
@ -831,6 +850,76 @@ static void rna_SpaceProperties_context_set(PointerRNA *ptr, int value)
sbuts->mainbuser = value; sbuts->mainbuser = value;
} }
static EnumPropertyItem *rna_SpaceProperties_context_itemf(bContext *C, PointerRNA *ptr,
PropertyRNA *UNUSED(prop), int *free)
{
SpaceButs *sbuts = (SpaceButs *)(ptr->data);
EnumPropertyItem *item = NULL;
int totitem = 0;
if (sbuts->pathflag & (1 << BCONTEXT_RENDER)) {
RNA_enum_items_add_value(&item, &totitem, buttons_context_items, BCONTEXT_RENDER);
}
if (sbuts->pathflag & (1 << BCONTEXT_RENDER_LAYER)) {
RNA_enum_items_add_value(&item, &totitem, buttons_context_items, BCONTEXT_RENDER_LAYER);
}
if (sbuts->pathflag & (1 << BCONTEXT_SCENE)) {
RNA_enum_items_add_value(&item, &totitem, buttons_context_items, BCONTEXT_SCENE);
}
if (sbuts->pathflag & (1 << BCONTEXT_WORLD)) {
RNA_enum_items_add_value(&item, &totitem, buttons_context_items, BCONTEXT_WORLD);
}
if (sbuts->pathflag & (1 << BCONTEXT_OBJECT)) {
RNA_enum_items_add_value(&item, &totitem, buttons_context_items, BCONTEXT_OBJECT);
}
if (sbuts->pathflag & (1 << BCONTEXT_CONSTRAINT)) {
RNA_enum_items_add_value(&item, &totitem, buttons_context_items, BCONTEXT_CONSTRAINT);
}
if (sbuts->pathflag & (1 << BCONTEXT_MODIFIER)) {
RNA_enum_items_add_value(&item, &totitem, buttons_context_items, BCONTEXT_MODIFIER);
}
if (sbuts->pathflag & (1 << BCONTEXT_DATA)) {
RNA_enum_items_add_value(&item, &totitem, buttons_context_items, BCONTEXT_DATA);
(item + totitem - 1)->icon = sbuts->dataicon;
}
if (sbuts->pathflag & (1 << BCONTEXT_BONE)) {
RNA_enum_items_add_value(&item, &totitem, buttons_context_items, BCONTEXT_BONE);
}
if (sbuts->pathflag & (1 << BCONTEXT_BONE_CONSTRAINT)) {
RNA_enum_items_add_value(&item, &totitem, buttons_context_items, BCONTEXT_BONE_CONSTRAINT);
}
if (sbuts->pathflag & (1 << BCONTEXT_MATERIAL)) {
RNA_enum_items_add_value(&item, &totitem, buttons_context_items, BCONTEXT_MATERIAL);
}
if (sbuts->pathflag & (1 << BCONTEXT_TEXTURE)) {
RNA_enum_items_add_value(&item, &totitem, buttons_context_items, BCONTEXT_TEXTURE);
}
if (sbuts->pathflag & (1 << BCONTEXT_PARTICLE)) {
RNA_enum_items_add_value(&item, &totitem, buttons_context_items, BCONTEXT_PARTICLE);
}
if (sbuts->pathflag & (1 << BCONTEXT_PHYSICS)) {
RNA_enum_items_add_value(&item, &totitem, buttons_context_items, BCONTEXT_PHYSICS);
}
RNA_enum_item_end(&item, &totitem);
*free = 1;
return item;
}
static void rna_SpaceProperties_align_set(PointerRNA *ptr, int value) static void rna_SpaceProperties_align_set(PointerRNA *ptr, int value)
{ {
SpaceButs *sbuts = (SpaceButs *)(ptr->data); SpaceButs *sbuts = (SpaceButs *)(ptr->data);
@ -2068,24 +2157,6 @@ static void rna_def_space_buttons(BlenderRNA *brna)
StructRNA *srna; StructRNA *srna;
PropertyRNA *prop; PropertyRNA *prop;
static EnumPropertyItem buttons_context_items[] = {
{BCONTEXT_SCENE, "SCENE", ICON_SCENE, "Scene", "Scene"},
{BCONTEXT_RENDER, "RENDER", ICON_SCENE_DATA, "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", "Constraints"},
{BCONTEXT_MODIFIER, "MODIFIER", ICON_MODIFIER, "Modifiers", "Modifiers"},
{BCONTEXT_DATA, "DATA", 0, "Data", "Data"},
{BCONTEXT_BONE, "BONE", ICON_BONE_DATA, "Bone", "Bone"},
{BCONTEXT_BONE_CONSTRAINT, "BONE_CONSTRAINT", ICON_CONSTRAINT, "Bone Constraints", "Bone Constraints"},
{BCONTEXT_MATERIAL, "MATERIAL", ICON_MATERIAL, "Material", "Material"},
{BCONTEXT_TEXTURE, "TEXTURE", ICON_TEXTURE, "Texture", "Texture"},
{BCONTEXT_PARTICLE, "PARTICLES", ICON_PARTICLES, "Particles", "Particle"},
{BCONTEXT_PHYSICS, "PHYSICS", ICON_PHYSICS, "Physics", "Physics"},
{0, NULL, 0, NULL, NULL}
};
static EnumPropertyItem align_items[] = { static EnumPropertyItem align_items[] = {
{BUT_HORIZONTAL, "HORIZONTAL", 0, "Horizontal", ""}, {BUT_HORIZONTAL, "HORIZONTAL", 0, "Horizontal", ""},
{BUT_VERTICAL, "VERTICAL", 0, "Vertical", ""}, {BUT_VERTICAL, "VERTICAL", 0, "Vertical", ""},
@ -2099,7 +2170,7 @@ static void rna_def_space_buttons(BlenderRNA *brna)
prop = RNA_def_property(srna, "context", PROP_ENUM, PROP_NONE); prop = RNA_def_property(srna, "context", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_sdna(prop, NULL, "mainb"); RNA_def_property_enum_sdna(prop, NULL, "mainb");
RNA_def_property_enum_items(prop, buttons_context_items); RNA_def_property_enum_items(prop, buttons_context_items);
RNA_def_property_enum_funcs(prop, NULL, "rna_SpaceProperties_context_set", NULL); RNA_def_property_enum_funcs(prop, NULL, "rna_SpaceProperties_context_set", "rna_SpaceProperties_context_itemf");
RNA_def_property_ui_text(prop, "Context", "Type of active data to display and edit"); RNA_def_property_ui_text(prop, "Context", "Type of active data to display and edit");
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_PROPERTIES, NULL); RNA_def_property_update(prop, NC_SPACE | ND_SPACE_PROPERTIES, NULL);