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:
authorCampbell Barton <ideasman42@gmail.com>2017-06-21 06:54:46 +0300
committerCampbell Barton <ideasman42@gmail.com>2017-06-21 07:10:14 +0300
commitb7669ac1c672a92f31735ae9f92b369f9ba30eb1 (patch)
tree1747e45bcc61cd4c2fc02dd3f006f49b4a18ca2b /source/blender/windowmanager
parent5b51dcacbc81df6283518317c274bf897010e967 (diff)
Manipulators: move settings to ID properties
This makes manipulator access closer to operators, and allows Python access. This adds RNA for manipulators, but not Python registration yet. - Split draw style into 2x settings: `draw_style` (enum) & `draw_options` (enum-flag) - Rename wmManipulator.properties -> properties_edit, Use wmManipulator.properties for ID-properties. Note that this area of the API will need further work since manipulators now have 2 kinds of properties & API's to access them.
Diffstat (limited to 'source/blender/windowmanager')
-rw-r--r--source/blender/windowmanager/manipulators/WM_manipulator_api.h20
-rw-r--r--source/blender/windowmanager/manipulators/WM_manipulator_types.h10
-rw-r--r--source/blender/windowmanager/manipulators/intern/wm_manipulator.c192
-rw-r--r--source/blender/windowmanager/manipulators/intern/wm_manipulator_map.c8
-rw-r--r--source/blender/windowmanager/manipulators/intern/wm_manipulator_property.c4
-rw-r--r--source/blender/windowmanager/manipulators/intern/wm_manipulator_type.c9
6 files changed, 227 insertions, 16 deletions
diff --git a/source/blender/windowmanager/manipulators/WM_manipulator_api.h b/source/blender/windowmanager/manipulators/WM_manipulator_api.h
index f435ced75e7..43a80cb1f80 100644
--- a/source/blender/windowmanager/manipulators/WM_manipulator_api.h
+++ b/source/blender/windowmanager/manipulators/WM_manipulator_api.h
@@ -55,11 +55,11 @@ struct wmManipulatorMapType_Params;
/* wmManipulator */
struct wmManipulator *WM_manipulator_new_ptr(
- const struct wmManipulatorType *wt,
- struct wmManipulatorGroup *mgroup, const char *name);
+ const struct wmManipulatorType *wt, struct wmManipulatorGroup *mgroup,
+ const char *name, struct PointerRNA *properties);
struct wmManipulator *WM_manipulator_new(
- const char *idname,
- struct wmManipulatorGroup *mgroup, const char *name);
+ const char *idname, struct wmManipulatorGroup *mgroup,
+ const char *name, struct PointerRNA *properties);
void WM_manipulator_free(
ListBase *manipulatorlist, struct wmManipulatorMap *mmap, struct wmManipulator *mpr,
struct bContext *C);
@@ -92,6 +92,17 @@ void WM_manipulator_set_color(struct wmManipulator *mpr, const float col[4]);
void WM_manipulator_get_color_highlight(const struct wmManipulator *mpr, float col_hi[4]);
void WM_manipulator_set_color_highlight(struct wmManipulator *mpr, const float col[4]);
+/* properties */
+void WM_manipulator_properties_create_ptr(struct PointerRNA *ptr, struct wmManipulatorType *wt);
+void WM_manipulator_properties_create(struct PointerRNA *ptr, const char *opstring);
+void WM_manipulator_properties_alloc(struct PointerRNA **ptr, struct IDProperty **properties, const char *wtstring);
+void WM_manipulator_properties_sanitize(struct PointerRNA *ptr, const bool no_context);
+bool WM_manipulator_properties_default(struct PointerRNA *ptr, const bool do_update);
+void WM_manipulator_properties_reset(struct wmManipulator *op);
+void WM_manipulator_properties_clear(struct PointerRNA *ptr);
+void WM_manipulator_properties_free(struct PointerRNA *ptr);
+
+
/* wm_manipulator_type.c */
const struct wmManipulatorType *WM_manipulatortype_find(const char *idname, bool quiet);
void WM_manipulatortype_append(void (*wtfunc)(struct wmManipulatorType *));
@@ -165,6 +176,7 @@ struct wmKeyMap *WM_manipulatorgroup_keymap_common_select(
struct wmManipulatorMap *WM_manipulatormap_new_from_type(
const struct wmManipulatorMapType_Params *mmap_params);
+const struct ListBase *WM_manipulatormap_group_list(struct wmManipulatorMap *mmap);
void WM_manipulatormap_tag_refresh(struct wmManipulatorMap *mmap);
void WM_manipulatormap_draw(struct wmManipulatorMap *mmap, const struct bContext *C, const int drawstep);
void WM_manipulatormap_add_handlers(struct ARegion *ar, struct wmManipulatorMap *mmap);
diff --git a/source/blender/windowmanager/manipulators/WM_manipulator_types.h b/source/blender/windowmanager/manipulators/WM_manipulator_types.h
index ae27de60805..f3064a62607 100644
--- a/source/blender/windowmanager/manipulators/WM_manipulator_types.h
+++ b/source/blender/windowmanager/manipulators/WM_manipulator_types.h
@@ -70,6 +70,9 @@ struct wmManipulator {
void *py_instance;
+ /* rna pointer to access properties */
+ struct PointerRNA *ptr;
+
int flag; /* flags that influence the behavior or how the manipulators are drawn */
short state; /* state flags (active, highlighted, selected) */
@@ -113,7 +116,9 @@ struct wmManipulator {
* Public API's should use string names,
* private API's can pass 'wmManipulatorProperty' directly.
*/
- ListBase properties;
+ ListBase properties_edit;
+
+ struct IDProperty *properties;
};
typedef void (*wmManipulatorGroupFnInit)(
@@ -223,6 +228,9 @@ typedef struct wmManipulatorType {
/* called when manipulator selection state changes */
wmManipulatorFnSelect select;
+ /* RNA for properties */
+ struct StructRNA *srna;
+
/* RNA integration */
ExtensionRNA ext;
} wmManipulatorType;
diff --git a/source/blender/windowmanager/manipulators/intern/wm_manipulator.c b/source/blender/windowmanager/manipulators/intern/wm_manipulator.c
index 6a36a99d9c5..938edb56153 100644
--- a/source/blender/windowmanager/manipulators/intern/wm_manipulator.c
+++ b/source/blender/windowmanager/manipulators/intern/wm_manipulator.c
@@ -44,6 +44,11 @@
#include "MEM_guardedalloc.h"
#include "RNA_access.h"
+#include "RNA_define.h"
+
+#include "BKE_global.h"
+#include "BKE_main.h"
+#include "BKE_idprop.h"
#include "WM_api.h"
#include "WM_types.h"
@@ -66,7 +71,8 @@ static void wm_manipulator_register(
* \note Follow #wm_operator_create convention.
*/
static wmManipulator *wm_manipulator_create(
- const wmManipulatorType *wt)
+ const wmManipulatorType *wt,
+ PointerRNA *properties)
{
BLI_assert(wt != NULL);
BLI_assert(wt->struct_size >= sizeof(wmManipulator));
@@ -74,15 +80,30 @@ static wmManipulator *wm_manipulator_create(
wmManipulator *mpr = MEM_callocN(wt->struct_size, __func__);
mpr->type = wt;
+ /* initialize properties, either copy or create */
+ mpr->ptr = MEM_callocN(sizeof(PointerRNA), "wmManipulatorPtrRNA");
+ if (properties && properties->data) {
+ mpr->properties = IDP_CopyProperty(properties->data);
+ }
+ else {
+ IDPropertyTemplate val = {0};
+ mpr->properties = IDP_New(IDP_GROUP, &val, "wmManipulatorProperties");
+ }
+ RNA_pointer_create(G.main->wm.first, wt->srna, mpr->properties, mpr->ptr);
+
+ WM_manipulator_properties_sanitize(mpr->ptr, 0);
+
unit_m4(mpr->matrix);
unit_m4(mpr->matrix_offset);
return mpr;
}
-wmManipulator *WM_manipulator_new_ptr(const wmManipulatorType *wt, wmManipulatorGroup *mgroup, const char *name)
+wmManipulator *WM_manipulator_new_ptr(
+ const wmManipulatorType *wt, wmManipulatorGroup *mgroup,
+ const char *name, PointerRNA *properties)
{
- wmManipulator *mpr = wm_manipulator_create(wt);
+ wmManipulator *mpr = wm_manipulator_create(wt, properties);
wm_manipulator_register(mgroup, mpr, name);
@@ -98,10 +119,12 @@ wmManipulator *WM_manipulator_new_ptr(const wmManipulatorType *wt, wmManipulator
* if you need to check it exists use #WM_manipulator_new_ptr
* because callers of this function don't NULL check the return value.
*/
-wmManipulator *WM_manipulator_new(const char *idname, wmManipulatorGroup *mgroup, const char *name)
+wmManipulator *WM_manipulator_new(
+ const char *idname, wmManipulatorGroup *mgroup,
+ const char *name, PointerRNA *properties)
{
const wmManipulatorType *wt = WM_manipulatortype_find(idname, false);
- return WM_manipulator_new_ptr(wt, mgroup, name);
+ return WM_manipulator_new_ptr(wt, mgroup, name, properties);
}
/**
@@ -174,7 +197,12 @@ void WM_manipulator_free(ListBase *manipulatorlist, wmManipulatorMap *mmap, wmMa
if (mpr->op_data.ptr.data) {
WM_operator_properties_free(&mpr->op_data.ptr);
}
- BLI_freelistN(&mpr->properties);
+ BLI_freelistN(&mpr->properties_edit);
+
+ if (mpr->ptr != NULL) {
+ WM_manipulator_properties_free(mpr->ptr);
+ MEM_freeN(mpr->ptr);
+ }
if (manipulatorlist) {
BLI_remlink(manipulatorlist, mpr);
@@ -433,8 +461,8 @@ void wm_manipulator_calculate_scale(wmManipulator *mpr, const bContext *C)
static void manipulator_update_prop_data(wmManipulator *mpr)
{
/* manipulator property might have been changed, so update manipulator */
- if (mpr->type->property_update && !BLI_listbase_is_empty(&mpr->properties)) {
- for (wmManipulatorProperty *mpr_prop = mpr->properties.first; mpr_prop; mpr_prop = mpr_prop->next) {
+ if (mpr->type->property_update && !BLI_listbase_is_empty(&mpr->properties_edit)) {
+ for (wmManipulatorProperty *mpr_prop = mpr->properties_edit.first; mpr_prop; mpr_prop = mpr_prop->next) {
if (WM_manipulator_property_is_valid(mpr_prop)) {
mpr->type->property_update(mpr, mpr_prop);
}
@@ -471,3 +499,151 @@ bool wm_manipulator_is_visible(wmManipulator *mpr)
return true;
}
+
+
+/** \name Manipulator Propery Access
+ *
+ * Matches `WM_operator_properties` conventions.
+ *
+ * \{ */
+
+
+void WM_manipulator_properties_create_ptr(PointerRNA *ptr, wmManipulatorType *wt)
+{
+ RNA_pointer_create(NULL, wt->srna, NULL, ptr);
+}
+
+void WM_manipulator_properties_create(PointerRNA *ptr, const char *wtstring)
+{
+ const wmManipulatorType *wt = WM_manipulatortype_find(wtstring, false);
+
+ if (wt)
+ WM_manipulator_properties_create_ptr(ptr, (wmManipulatorType *)wt);
+ else
+ RNA_pointer_create(NULL, &RNA_ManipulatorProperties, NULL, ptr);
+}
+
+/* similar to the function above except its uses ID properties
+ * used for keymaps and macros */
+void WM_manipulator_properties_alloc(PointerRNA **ptr, IDProperty **properties, const char *wtstring)
+{
+ if (*properties == NULL) {
+ IDPropertyTemplate val = {0};
+ *properties = IDP_New(IDP_GROUP, &val, "wmOpItemProp");
+ }
+
+ if (*ptr == NULL) {
+ *ptr = MEM_callocN(sizeof(PointerRNA), "wmOpItemPtr");
+ WM_manipulator_properties_create(*ptr, wtstring);
+ }
+
+ (*ptr)->data = *properties;
+
+}
+
+void WM_manipulator_properties_sanitize(PointerRNA *ptr, const bool no_context)
+{
+ RNA_STRUCT_BEGIN (ptr, prop)
+ {
+ switch (RNA_property_type(prop)) {
+ case PROP_ENUM:
+ if (no_context)
+ RNA_def_property_flag(prop, PROP_ENUM_NO_CONTEXT);
+ else
+ RNA_def_property_clear_flag(prop, PROP_ENUM_NO_CONTEXT);
+ break;
+ case PROP_POINTER:
+ {
+ StructRNA *ptype = RNA_property_pointer_type(ptr, prop);
+
+ /* recurse into manipulator properties */
+ if (RNA_struct_is_a(ptype, &RNA_ManipulatorProperties)) {
+ PointerRNA opptr = RNA_property_pointer_get(ptr, prop);
+ WM_manipulator_properties_sanitize(&opptr, no_context);
+ }
+ break;
+ }
+ default:
+ break;
+ }
+ }
+ RNA_STRUCT_END;
+}
+
+
+/** set all props to their default,
+ * \param do_update Only update un-initialized props.
+ *
+ * \note, theres nothing specific to manipulators here.
+ * this could be made a general function.
+ */
+bool WM_manipulator_properties_default(PointerRNA *ptr, const bool do_update)
+{
+ bool changed = false;
+ RNA_STRUCT_BEGIN (ptr, prop)
+ {
+ switch (RNA_property_type(prop)) {
+ case PROP_POINTER:
+ {
+ StructRNA *ptype = RNA_property_pointer_type(ptr, prop);
+ if (ptype != &RNA_Struct) {
+ PointerRNA opptr = RNA_property_pointer_get(ptr, prop);
+ changed |= WM_manipulator_properties_default(&opptr, do_update);
+ }
+ break;
+ }
+ default:
+ if ((do_update == false) || (RNA_property_is_set(ptr, prop) == false)) {
+ if (RNA_property_reset(ptr, prop, -1)) {
+ changed = true;
+ }
+ }
+ break;
+ }
+ }
+ RNA_STRUCT_END;
+
+ return changed;
+}
+
+/* remove all props without PROP_SKIP_SAVE */
+void WM_manipulator_properties_reset(wmManipulator *mpr)
+{
+ if (mpr->ptr->data) {
+ PropertyRNA *iterprop;
+ iterprop = RNA_struct_iterator_property(mpr->type->srna);
+
+ RNA_PROP_BEGIN (mpr->ptr, itemptr, iterprop)
+ {
+ PropertyRNA *prop = itemptr.data;
+
+ if ((RNA_property_flag(prop) & PROP_SKIP_SAVE) == 0) {
+ const char *identifier = RNA_property_identifier(prop);
+ RNA_struct_idprops_unset(mpr->ptr, identifier);
+ }
+ }
+ RNA_PROP_END;
+ }
+}
+
+void WM_manipulator_properties_clear(PointerRNA *ptr)
+{
+ IDProperty *properties = ptr->data;
+
+ if (properties) {
+ IDP_ClearProperty(properties);
+ }
+}
+
+void WM_manipulator_properties_free(PointerRNA *ptr)
+{
+ IDProperty *properties = ptr->data;
+
+ if (properties) {
+ IDP_FreeProperty(properties);
+ MEM_freeN(properties);
+ ptr->data = NULL; /* just in case */
+ }
+}
+
+/** \} */
diff --git a/source/blender/windowmanager/manipulators/intern/wm_manipulator_map.c b/source/blender/windowmanager/manipulators/intern/wm_manipulator_map.c
index 0f1a6e9d96e..e5f32ec5eed 100644
--- a/source/blender/windowmanager/manipulators/intern/wm_manipulator_map.c
+++ b/source/blender/windowmanager/manipulators/intern/wm_manipulator_map.c
@@ -88,7 +88,8 @@ enum eManipulatorMapUpdateFlags {
/**
* Creates a manipulator-map with all registered manipulators for that type
*/
-wmManipulatorMap *WM_manipulatormap_new_from_type(const struct wmManipulatorMapType_Params *mmap_params)
+wmManipulatorMap *WM_manipulatormap_new_from_type(
+ const struct wmManipulatorMapType_Params *mmap_params)
{
wmManipulatorMapType *mmap_type = WM_manipulatormaptype_ensure(mmap_params);
wmManipulatorMap *mmap;
@@ -129,6 +130,11 @@ void wm_manipulatormap_remove(wmManipulatorMap *mmap)
MEM_freeN(mmap);
}
+const ListBase *WM_manipulatormap_group_list(wmManipulatorMap *mmap)
+{
+ return &mmap->groups;
+}
+
/**
* Creates and returns idname hash table for (visible) manipulators in \a mmap
*
diff --git a/source/blender/windowmanager/manipulators/intern/wm_manipulator_property.c b/source/blender/windowmanager/manipulators/intern/wm_manipulator_property.c
index 58dcfa586d8..beaf2abdc17 100644
--- a/source/blender/windowmanager/manipulators/intern/wm_manipulator_property.c
+++ b/source/blender/windowmanager/manipulators/intern/wm_manipulator_property.c
@@ -55,7 +55,7 @@
wmManipulatorProperty *WM_manipulator_property_find(wmManipulator *mpr, const char *idname)
{
- return BLI_findstring(&mpr->properties, idname, offsetof(wmManipulatorProperty, idname));
+ return BLI_findstring(&mpr->properties_edit, idname, offsetof(wmManipulatorProperty, idname));
}
static wmManipulatorProperty *wm_manipulator_property_def_internal(
@@ -67,7 +67,7 @@ static wmManipulatorProperty *wm_manipulator_property_def_internal(
const uint idname_size = strlen(idname) + 1;
mpr_prop = MEM_callocN(sizeof(wmManipulatorProperty) + idname_size, __func__);
memcpy(mpr_prop->idname, idname, idname_size);
- BLI_addtail(&mpr->properties, mpr_prop);
+ BLI_addtail(&mpr->properties_edit, mpr_prop);
}
return mpr_prop;
}
diff --git a/source/blender/windowmanager/manipulators/intern/wm_manipulator_type.c b/source/blender/windowmanager/manipulators/intern/wm_manipulator_type.c
index e89d4cc6e81..94b4000b841 100644
--- a/source/blender/windowmanager/manipulators/intern/wm_manipulator_type.c
+++ b/source/blender/windowmanager/manipulators/intern/wm_manipulator_type.c
@@ -31,6 +31,7 @@
#include "MEM_guardedalloc.h"
#include "RNA_access.h"
+#include "RNA_define.h"
#include "WM_api.h"
#include "WM_types.h"
@@ -82,12 +83,20 @@ void WM_manipulatortype_iter(GHashIterator *ghi)
static wmManipulatorType *wm_manipulatortype_append__begin(void)
{
wmManipulatorType *wt = MEM_callocN(sizeof(wmManipulatorType), "manipulatortype");
+ wt->srna = RNA_def_struct_ptr(&BLENDER_RNA, "", &RNA_ManipulatorProperties);
+#if 0
+ /* Set the default i18n context now, so that opfunc can redefine it if needed! */
+ RNA_def_struct_translation_context(ot->srna, BLT_I18NCONTEXT_OPERATOR_DEFAULT);
+ ot->translation_context = BLT_I18NCONTEXT_OPERATOR_DEFAULT;
+#endif
return wt;
}
static void wm_manipulatortype_append__end(wmManipulatorType *wt)
{
BLI_assert(wt->struct_size >= sizeof(wmManipulator));
+ RNA_def_struct_identifier(wt->srna, wt->idname);
+
BLI_ghash_insert(global_manipulatortype_hash, (void *)wt->idname, wt);
}