Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoshua Leung <aligorith@gmail.com>2009-06-13 15:21:02 +0400
committerJoshua Leung <aligorith@gmail.com>2009-06-13 15:21:02 +0400
commitcd3c52db0334950f85911cca9f7b834647950f7b (patch)
tree89bff7bc80671e829e0421be02849be370538ddc /source/blender/editors
parenteed13b43b19c619ccdcda67b17c0da65ad44879c (diff)
2.5 - Armature Buttons + UI-Templates
Added a new template for layer-buttons, which auto-determines the layout of the buttons instead of relying on some hardcoded pattern for n-layers (i.e. 16 or 20 currently). This is a still bit rough, and could do with some refining to allow us to define what extra info (icons) should get drawn on the buttons or so. Currently, this is only used in the Armature buttons to allow showing/hiding layers.
Diffstat (limited to 'source/blender/editors')
-rw-r--r--source/blender/editors/include/UI_interface.h1
-rw-r--r--source/blender/editors/interface/interface_api.c6
-rw-r--r--source/blender/editors/interface/interface_templates.c53
3 files changed, 60 insertions, 0 deletions
diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h
index 48a859dadc4..eb3a037d7b1 100644
--- a/source/blender/editors/include/UI_interface.h
+++ b/source/blender/editors/include/UI_interface.h
@@ -615,6 +615,7 @@ uiLayout *uiTemplateConstraint(uiLayout *layout, struct PointerRNA *ptr);
void uiTemplatePreview(uiLayout *layout, struct ID *id);
void uiTemplateColorRamp(uiLayout *layout, struct ColorBand *coba, int expand);
void uiTemplateCurveMapping(uiLayout *layout, struct CurveMapping *cumap, int type);
+void uiTemplateLayers(uiLayout *layout, struct PointerRNA *ptr, char *propname);
/* items */
void uiItemO(uiLayout *layout, char *name, int icon, char *opname);
diff --git a/source/blender/editors/interface/interface_api.c b/source/blender/editors/interface/interface_api.c
index 60bfe4e79ad..b4e7dc03506 100644
--- a/source/blender/editors/interface/interface_api.c
+++ b/source/blender/editors/interface/interface_api.c
@@ -230,5 +230,11 @@ void RNA_api_ui_layout(StructRNA *srna)
parm= RNA_def_pointer(func, "ramp", "ColorRamp", "", "Color ramp pointer.");
RNA_def_property_flag(parm, PROP_REQUIRED);
RNA_def_boolean(func, "expand", 0, "", "Expand button to show more detail.");
+
+ func= RNA_def_function(srna, "template_layers", "uiTemplateLayers");
+ parm= RNA_def_pointer(func, "data", "AnyType", "", "Data from which to take property.");
+ RNA_def_property_flag(parm, PROP_REQUIRED);
+ parm= RNA_def_string(func, "property", "", 0, "", "Identifier of pointer property in data.");
+ RNA_def_property_flag(parm, PROP_REQUIRED);
}
diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c
index 53238a306cd..63de328af0f 100644
--- a/source/blender/editors/interface/interface_templates.c
+++ b/source/blender/editors/interface/interface_templates.c
@@ -1439,3 +1439,56 @@ void uiTemplateCurveMapping(uiLayout *layout, CurveMapping *cumap, int type)
}
}
+/********************* Layer Buttons Template ************************/
+
+// TODO:
+// - option for showing extra info like whether layer has contents?
+// - for now, grouping of layers is determined by dividing up the length of
+// the array of layer bitflags
+
+void uiTemplateLayers(uiLayout *layout, PointerRNA *ptr, char *propname)
+{
+ uiBlock *block;
+ uiLayout *uRow, *uSplit, *uCol;
+ PropertyRNA *prop;
+ StructRNA *type;
+ int groups, cols, layers;
+ int group, col, layer, row;
+
+ if (!ptr->data)
+ return;
+
+ prop= RNA_struct_find_property(ptr, propname);
+ if (!prop) {
+ printf("uiTemplateLayer: layers property not found: %s\n", propname);
+ return;
+ }
+
+ /* the number of layers 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 if group will have at least 5 items
+ */
+ layers= RNA_property_array_length(prop);
+ cols= (layers / 2) + (layers % 2);
+ groups= ((cols / 2) < 5) ? (1) : (cols / 2);
+
+ /* layers are laid out going across rows, with the columns being divided into groups */
+ uSplit= uiLayoutSplit(layout, (1.0f/(float)groups));
+
+ for (group= 0; group < groups; group++) {
+ uCol= uiLayoutColumn(uSplit, 1);
+
+ for (row= 0; row < 2; row++) {
+ uRow= uiLayoutRow(uCol, 1);
+ layer= groups*cols*row + cols*group;
+
+ /* add layers as toggle buts */
+ for (col= 0; (col < cols) && (layer < layers); col++, layer++) {
+ int icon=0; // XXX - add some way of setting this...
+ uiItemFullR(uRow, "", icon, ptr, prop, layer, 0, 0, 0, 1);
+ }
+ }
+ }
+}