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:
authorBrecht Van Lommel <brechtvanlommel@pandora.be>2009-01-01 23:44:40 +0300
committerBrecht Van Lommel <brechtvanlommel@pandora.be>2009-01-01 23:44:40 +0300
commit112385660aeefbd503b128c91a3c7fc09d1e6d5a (patch)
tree3db61ae0103dab6ba41bdfbf015ccb8b05bba0d6 /source/blender/windowmanager
parentddabed9c9625f7109b703ed88c88247bfb14aaba (diff)
RNA
* Object has some more properties wrapped, mostly game related. * Scene frame changes now send a notifier. * Added functions to create/free operator properties for calling operators. This also simplifies some duplicated code that did this. Ideally though this kind of thing should use the properties pointer provided by buttons and keymap items. Example code: PointerRNA ptr; WM_operator_properties_create(&ptr, "SOME_OT_name"); RNA_int_set(&ptr, "value", 42); WM_operator_name_call(C, "SOME_OT_name", WM_OP_EXEC_DEFAULT, &ptr); WM_operator_properties_free(&ptr);
Diffstat (limited to 'source/blender/windowmanager')
-rw-r--r--source/blender/windowmanager/WM_api.h6
-rw-r--r--source/blender/windowmanager/intern/wm.c24
-rw-r--r--source/blender/windowmanager/intern/wm_event_system.c15
-rw-r--r--source/blender/windowmanager/intern/wm_keymap.c10
-rw-r--r--source/blender/windowmanager/intern/wm_operators.c20
5 files changed, 49 insertions, 26 deletions
diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h
index 3125a21bbd2..8ec6078e1d9 100644
--- a/source/blender/windowmanager/WM_api.h
+++ b/source/blender/windowmanager/WM_api.h
@@ -37,6 +37,7 @@ struct wmEvent;
struct wmEventHandler;
struct wmGesture;
struct rcti;
+struct PointerRNA;
/* general API */
void WM_setprefsize (int stax, int stay, int sizx, int sizy);
@@ -122,7 +123,10 @@ void WM_operatortype_append_ptr (void (*opfunc)(wmOperatorType*, void *), void
int WM_operatortype_remove(const char *idname);
int WM_operator_call (struct bContext *C, struct wmOperator *op);
-int WM_operator_name_call (struct bContext *C, const char *opstring, int context, struct IDProperty *properties);
+int WM_operator_name_call (struct bContext *C, const char *opstring, int context, struct PointerRNA *properties);
+
+void WM_operator_properties_create(struct PointerRNA *ptr, const char *opstring);
+void WM_operator_properties_free(struct PointerRNA *ptr);
/* operator as a python command (resultuing string must be free'd) */
char *WM_operator_pystring(struct wmOperator *op);
diff --git a/source/blender/windowmanager/intern/wm.c b/source/blender/windowmanager/intern/wm.c
index 62cf31b5ffc..2008c3c1c6f 100644
--- a/source/blender/windowmanager/intern/wm.c
+++ b/source/blender/windowmanager/intern/wm.c
@@ -48,21 +48,24 @@
#include "ED_screen.h"
+#include "RNA_types.h"
+
/* ****************************************************** */
#define MAX_OP_REGISTERED 32
void WM_operator_free(wmOperator *op)
{
+ if(op->ptr) {
+ op->properties= op->ptr->data;
+ MEM_freeN(op->ptr);
+ }
+
if(op->properties) {
IDP_FreeProperty(op->properties);
MEM_freeN(op->properties);
- op->properties= NULL;
}
- if(op->ptr)
- MEM_freeN(op->ptr);
-
if(op->reports) {
BKE_reports_clear(op->reports);
MEM_freeN(op->reports);
@@ -77,6 +80,12 @@ void wm_operator_register(wmWindowManager *wm, wmOperator *op)
{
int tot;
+ if(op->ptr) {
+ op->properties= op->ptr->data;
+ MEM_freeN(op->ptr);
+ op->ptr= NULL;
+ }
+
BLI_addtail(&wm->operators, op);
tot= BLI_countlist(&wm->operators);
@@ -152,12 +161,9 @@ void wm_close_and_free(bContext *C, wmWindowManager *wm)
while((km= wm->keymaps.first)) {
for(kmi=km->keymap.first; kmi; kmi=kmi->next) {
- if(kmi->ptr)
+ if(kmi->ptr) {
+ WM_operator_properties_free(kmi->ptr);
MEM_freeN(kmi->ptr);
-
- if(kmi->properties) {
- IDP_FreeProperty(kmi->properties);
- MEM_freeN(kmi->properties);
}
}
diff --git a/source/blender/windowmanager/intern/wm_event_system.c b/source/blender/windowmanager/intern/wm_event_system.c
index 96a97e95bd7..6dffc0ff29e 100644
--- a/source/blender/windowmanager/intern/wm_event_system.c
+++ b/source/blender/windowmanager/intern/wm_event_system.c
@@ -355,7 +355,7 @@ int WM_operator_call(bContext *C, wmOperator *op)
return retval;
}
-static int wm_operator_invoke(bContext *C, wmOperatorType *ot, wmEvent *event, IDProperty *properties)
+static int wm_operator_invoke(bContext *C, wmOperatorType *ot, wmEvent *event, PointerRNA *properties)
{
wmWindowManager *wm= CTX_wm_manager(C);
int retval= OPERATOR_PASS_THROUGH;
@@ -363,15 +363,14 @@ static int wm_operator_invoke(bContext *C, wmOperatorType *ot, wmEvent *event, I
if(ot->poll==NULL || ot->poll(C)) {
wmOperator *op= MEM_callocN(sizeof(wmOperator), ot->idname); /* XXX operatortype names are static still. for debug */
- if(properties)
- op->properties= IDP_CopyProperty(properties);
-
/* XXX adding new operator could be function, only happens here now */
op->type= ot;
BLI_strncpy(op->idname, ot->idname, OP_MAX_TYPENAME);
op->ptr= MEM_callocN(sizeof(PointerRNA), "wmOperatorPtrRNA");
- RNA_pointer_create(&RNA_WindowManager, &wm->id, ot->srna, &op->properties, op->ptr);
+ if(properties && properties->data)
+ op->ptr->data= IDP_CopyProperty(properties->data);
+ RNA_pointer_create(&RNA_WindowManager, &wm->id, ot->srna, op->ptr->data, op->ptr);
op->reports= MEM_callocN(sizeof(ReportList), "wmOperatorReportList");
BKE_reports_init(op->reports, RPT_STORE);
@@ -402,7 +401,7 @@ static int wm_operator_invoke(bContext *C, wmOperatorType *ot, wmEvent *event, I
}
/* invokes operator in context */
-int WM_operator_name_call(bContext *C, const char *opstring, int context, IDProperty *properties)
+int WM_operator_name_call(bContext *C, const char *opstring, int context, PointerRNA *properties)
{
wmOperatorType *ot= WM_operatortype_find(opstring);
wmWindow *window= CTX_wm_window(C);
@@ -605,7 +604,7 @@ static int wm_event_always_pass(wmEvent *event)
}
/* Warning: this function removes a modal handler, when finished */
-static int wm_handler_operator_call(bContext *C, ListBase *handlers, wmEventHandler *handler, wmEvent *event, IDProperty *properties)
+static int wm_handler_operator_call(bContext *C, ListBase *handlers, wmEventHandler *handler, wmEvent *event, PointerRNA *properties)
{
int retval= OPERATOR_PASS_THROUGH;
@@ -746,7 +745,7 @@ static int wm_handlers_do(bContext *C, wmEvent *event, ListBase *handlers)
event->keymap_idname= kmi->idname; /* weak, but allows interactive callback to not use rawkey */
- action= wm_handler_operator_call(C, handlers, handler, event, kmi->properties);
+ action= wm_handler_operator_call(C, handlers, handler, event, kmi->ptr);
if(action==WM_HANDLER_BREAK) /* not wm_event_always_pass(event) here, it denotes removed handler */
break;
}
diff --git a/source/blender/windowmanager/intern/wm_keymap.c b/source/blender/windowmanager/intern/wm_keymap.c
index eac51559269..3a05a319e8a 100644
--- a/source/blender/windowmanager/intern/wm_keymap.c
+++ b/source/blender/windowmanager/intern/wm_keymap.c
@@ -84,15 +84,9 @@ static void keymap_event_set(wmKeymapItem *kmi, short type, short val, int modif
static void keymap_properties_set(wmKeymapItem *kmi)
{
- wmOperatorType *ot;
-
if(!kmi->ptr) {
- ot= WM_operatortype_find(kmi->idname);
-
- if(ot) {
- kmi->ptr= MEM_callocN(sizeof(PointerRNA), "wmKeymapItemPtr");
- RNA_pointer_create(NULL, NULL, ot->srna, &kmi->properties, kmi->ptr);
- }
+ kmi->ptr= MEM_callocN(sizeof(PointerRNA), "wmKeymapItemPtr");
+ WM_operator_properties_create(kmi->ptr, kmi->idname);
}
}
diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c
index 7d2c4a12ef4..f099122096d 100644
--- a/source/blender/windowmanager/intern/wm_operators.c
+++ b/source/blender/windowmanager/intern/wm_operators.c
@@ -164,6 +164,26 @@ char *WM_operator_pystring(wmOperator *op)
return cstring;
}
+void WM_operator_properties_create(PointerRNA *ptr, const char *opstring)
+{
+ wmOperatorType *ot= WM_operatortype_find(opstring);
+
+ if(ot)
+ RNA_pointer_create(NULL, NULL, ot->srna, NULL, ptr);
+ else
+ memset(ptr, 0, sizeof(*ptr));
+}
+
+void WM_operator_properties_free(PointerRNA *ptr)
+{
+ IDProperty *properties= ptr->data;
+
+ if(properties) {
+ IDP_FreeProperty(properties);
+ MEM_freeN(properties);
+ }
+}
+
/* ************ default op callbacks, exported *********** */
/* invoke callback, uses enum property named "type" */