From 184a232ccc85fc3aa16d7e5f3adbe55e2b379562 Mon Sep 17 00:00:00 2001 From: Dalai Felinto Date: Fri, 21 Sep 2012 04:09:09 +0000 Subject: 2.49 feature: Game Controller State name shows up when mouse over them (the name of a state is the name of the top controller of this state) review and small tweaks by Campbell Barton --- .../editors/interface/interface_templates.c | 69 ++++++++++++++++++++++ 1 file changed, 69 insertions(+) (limited to 'source/blender/editors/interface') diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c index 4b9d4978948..2027bd84bb0 100644 --- a/source/blender/editors/interface/interface_templates.c +++ b/source/blender/editors/interface/interface_templates.c @@ -57,6 +57,7 @@ #include "BKE_texture.h" #include "BKE_report.h" #include "BKE_displist.h" +#include "BKE_sca.h" #include "BKE_scene.h" #include "ED_screen.h" @@ -2089,6 +2090,74 @@ void uiTemplateLayers(uiLayout *layout, PointerRNA *ptr, const char *propname, } } +void uiTemplateGameStates(uiLayout *layout, PointerRNA *ptr, const char *propname, + PointerRNA *used_ptr, const char *used_propname, int active_state) +{ + uiLayout *uRow, *uCol; + PropertyRNA *prop, *used_prop = NULL; + int groups, cols, states; + int group, col, state, row; + int cols_per_group = 5; + Object *ob = (Object *)ptr->id.data; + + prop = RNA_struct_find_property(ptr, propname); + if (!prop) { + RNA_warning("states property not found: %s.%s", RNA_struct_identifier(ptr->type), propname); + return; + } + + /* the number of states determines the way we group them + * - we want 2 rows only (for now) + * - the number of columns (cols) is the total number of buttons per row + * the 'remainder' is added to this, as it will be ok to have first row slightly wider if need be + * - for now, only split into groups if group will have at least 5 items + */ + states = RNA_property_array_length(ptr, prop); + cols = (states / 2) + (states % 2); + groups = ((cols / 2) < cols_per_group) ? (1) : (cols / cols_per_group); + + if (used_ptr && used_propname) { + used_prop = RNA_struct_find_property(used_ptr, used_propname); + if (!used_prop) { + RNA_warning("used layers property not found: %s.%s", RNA_struct_identifier(ptr->type), used_propname); + return; + } + + if (RNA_property_array_length(used_ptr, used_prop) < states) + used_prop = NULL; + } + + /* layers are laid out going across rows, with the columns being divided into groups */ + + for (group = 0; group < groups; group++) { + uCol = uiLayoutColumn(layout, TRUE); + + for (row = 0; row < 2; row++) { + uiBlock *block; + uiBut *but; + + uRow = uiLayoutRow(uCol, TRUE); + block = uiLayoutGetBlock(uRow); + state = groups * cols_per_group * row + cols_per_group * group; + + /* add layers as toggle buts */ + for (col = 0; (col < cols_per_group) && (state < states); col++, state++) { + int icon = 0; + int butlay = 1 << state; + + if (active_state & butlay) + icon = ICON_LAYER_ACTIVE; + else if (used_prop && RNA_property_boolean_get_index(used_ptr, used_prop, state)) + icon = ICON_LAYER_USED; + + but = uiDefIconButR_prop(block, ICONTOG, 0, icon, 0, 0, UI_UNIT_X / 2, UI_UNIT_Y / 2, ptr, prop, state, 0, 0, -1, -1, sca_state_name_get(ob, state)); + uiButSetFunc(but, handle_layer_buttons, but, SET_INT_IN_POINTER(state)); + but->type = TOG; + } + } + } +} + /************************* List Template **************************/ -- cgit v1.2.3