* Added support for sending notifiers and updates when setting
  RNA properties. Per property, there is a notifier NC_/ND_ flag,
  and a function that is called. Currently only used for
  Object.loc/rot/size.
* RNA_property_update that does this is not automatically called
  in every _set function, it has do be done separate, and is being
  done by buttons with RNA data.
* Perhaps for python there could be a trick to accumulate these
  flags rather than update each time, though for now the python
  RNA code could just do them everytime. Did not add these calls
  in the python code yet because it needs context, not sure where
  to get that from?
This commit is contained in:
2009-01-01 15:52:51 +00:00
parent a1961436f5
commit fc7944f436
23 changed files with 80 additions and 44 deletions

View File

@@ -1584,8 +1584,8 @@ void ui_check_but(uiBut *but)
value= ui_get_but_val(but);
if(ui_is_but_float(but)) {
if(value == FLT_MAX) sprintf(but->drawstr, "%sFLT_MAX", but->str);
else if(value == -FLT_MAX) sprintf(but->drawstr, "%s-FLT_MAX", but->str);
if(value == FLT_MAX) sprintf(but->drawstr, "%sinf", but->str);
else if(value == -FLT_MAX) sprintf(but->drawstr, "%s-inf", but->str);
else if(but->a2) { /* amount of digits defined */
if(but->a2==1) sprintf(but->drawstr, "%s%.1f", but->str, value);
else if(but->a2==2) sprintf(but->drawstr, "%s%.2f", but->str, value);

View File

@@ -148,6 +148,9 @@ typedef struct uiAfterFunc {
const char *opname;
int opcontext;
IDProperty *opproperties;
PointerRNA rnapoin;
PropertyRNA *rnaprop;
} uiAfterFunc;
static void button_activate_state(bContext *C, uiBut *but, uiHandleButtonState state);
@@ -168,7 +171,7 @@ static void ui_apply_but_func(bContext *C, uiBut *but)
* handling is done, i.e. menus are closed, in order to avoid conflicts
* with these functions removing the buttons we are working with */
if(but->func || block->handle_func || (but->type == BUTM && block->butm_func) || but->opname) {
if(but->func || block->handle_func || (but->type == BUTM && block->butm_func) || but->opname || but->rnaprop) {
after= MEM_callocN(sizeof(uiAfterFunc), "uiAfterFunc");
after->func= but->func;
@@ -189,6 +192,9 @@ static void ui_apply_but_func(bContext *C, uiBut *but)
after->opcontext= but->opcontext;
after->opproperties= but->opproperties;
after->rnapoin= but->rnapoin;
after->rnaprop= but->rnaprop;
but->opname= NULL;
but->opcontext= 0;
but->opproperties= NULL;
@@ -221,6 +227,9 @@ static void ui_apply_but_funcs_after(bContext *C)
IDP_FreeProperty(after->opproperties);
MEM_freeN(after->opproperties);
}
if(after->rnapoin.data)
RNA_property_update(C, &after->rnapoin, after->rnaprop);
}
BLI_freelistN(&funcs);

View File

@@ -269,7 +269,7 @@ const char *RNA_property_ui_description(PointerRNA *ptr, PropertyRNA *prop);
int RNA_property_editable(PointerRNA *ptr, PropertyRNA *prop);
int RNA_property_evaluated(PointerRNA *ptr, PropertyRNA *prop);
void RNA_property_notify(PropertyRNA *prop, struct bContext *C, PointerRNA *ptr);
void RNA_property_update(struct bContext *C, PointerRNA *ptr, PropertyRNA *prop);
/* Property Data */

View File

@@ -44,10 +44,11 @@ void RNA_def_struct_sdna(StructRNA *srna, const char *structname);
void RNA_def_struct_sdna_from(StructRNA *srna, const char *structname, const char *propname);
void RNA_def_struct_name_property(StructRNA *srna, PropertyRNA *prop);
void RNA_def_struct_flag(StructRNA *srna, int flag);
void RNA_def_struct_funcs(StructRNA *srna, const char *notify, const char *refine);
void RNA_def_struct_refine_func(StructRNA *srna, const char *refine);
void RNA_def_struct_identifier(StructRNA *srna, const char *identifier);
void RNA_def_struct_ui_text(StructRNA *srna, const char *name, const char *description);
void RNA_struct_free(BlenderRNA *brna, StructRNA *srna);
/* Property */
PropertyRNA *RNA_def_property(StructRNA *srna, const char *identifier, int type, int subtype);
@@ -83,7 +84,9 @@ void RNA_def_property_string_default(PropertyRNA *prop, const char *value);
void RNA_def_property_ui_text(PropertyRNA *prop, const char *name, const char *description);
void RNA_def_property_ui_range(PropertyRNA *prop, double min, double max, double step, int precision);
void RNA_def_property_funcs(PropertyRNA *prop, const char *notify, const char *editable);
void RNA_def_property_update(PropertyRNA *prop, int noteflag, const char *updatefunc);
void RNA_def_property_editable_func(PropertyRNA *prop, const char *editable);
void RNA_def_property_boolean_funcs(PropertyRNA *prop, const char *get, const char *set);
void RNA_def_property_int_funcs(PropertyRNA *prop, const char *get, const char *set, const char *range);
void RNA_def_property_float_funcs(PropertyRNA *prop, const char *get, const char *set, const char *range);

View File

@@ -7,5 +7,6 @@ o = SConscript('intern/SConscript')
objs += o
incs = '#/intern/guardedalloc ../blenkernel ../blenlib ../makesdna intern .'
incs += ' ../windowmanager'
env.BlenderLib ( 'bf_rna', objs, Split(incs), [], libtype=['core'], priority = [195] )

View File

@@ -66,7 +66,7 @@ SET(SRC
../../../../intern/guardedalloc/intern/mallocn.c
../../../../intern/guardedalloc/intern/mmap_win.c)
INCLUDE_DIRECTORIES(../../../../intern/guardedalloc .. ../../makesdna ../../blenkernel ../../blenlib .)
INCLUDE_DIRECTORIES(../../../../intern/guardedalloc .. ../../makesdna ../../blenkernel ../../blenlib ../../windowmanager .)
FILE(GLOB INC_FILES ../*.h ../../makesdna/*.h)
# Build makesrna executable

View File

@@ -34,6 +34,7 @@ CPPFLAGS += -I$(NAN_GUARDEDALLOC)/include
CPPFLAGS += -I../../blenlib
CPPFLAGS += -I../../blenkernel
CPPFLAGS += -I../../makesdna
CPPFLAGS += -I../../windowmanager
CPPFLAGS += -I..
CPPFLAGS += -I.

View File

@@ -3,7 +3,7 @@ import sys
import os
Import ('env')
cflags = ''
cflags = '-Wall'
defines = []
root_build_dir=env['BF_BUILDDIR']
@@ -22,7 +22,8 @@ makesrna_tool.Append (CPPPATH = ['#/intern/guardedalloc',
'../../blenlib',
'../../blenkernel',
'../../makesdna',
'../../makesrna'])
'../../makesrna',
'../../windowmanager'])
if env['OURPLATFORM'] == 'linuxcross':
makesrna_tool.Replace(CC='gcc')

View File

@@ -785,7 +785,7 @@ static void rna_generate_struct(BlenderRNA *brna, StructRNA *srna, FILE *f)
rna_print_c_string(f, prop->name); fprintf(f, ",\n\t");
rna_print_c_string(f, prop->description); fprintf(f, ",\n");
fprintf(f, "\t%s, %s, %d,\n", rna_property_typename(prop->type), rna_property_subtypename(prop->subtype), prop->arraylength);
fprintf(f, "\t%s, %s},\n", rna_function_string(prop->notify), rna_function_string(prop->editable));
fprintf(f, "\t%s, %d, %s},\n", rna_function_string(prop->update), prop->noteflag, rna_function_string(prop->editable));
switch(prop->type) {
case PROP_BOOLEAN: {
@@ -876,7 +876,7 @@ static void rna_generate_struct(BlenderRNA *brna, StructRNA *srna, FILE *f)
if(srna->from) fprintf(f, "\t&RNA_%s,\n", (char*)srna->from);
else fprintf(f, "\tNULL,\n");
fprintf(f, "\t%s, %s,\n", rna_function_string(srna->notify), rna_function_string(srna->refine));
fprintf(f, "\t%s,\n", rna_function_string(srna->refine));
prop= srna->properties.first;
if(prop) fprintf(f, "\t{(PropertyRNA*)&rna_%s_%s, ", srna->identifier, prop->identifier);

View File

@@ -166,7 +166,7 @@ static void rna_def_ID(BlenderRNA *brna)
RNA_def_struct_ui_text(srna, "ID", "Used as a basis for dealing with many types with unique names, garbage collection and linked libraries");
RNA_def_struct_flag(srna, STRUCT_ID);
RNA_def_struct_funcs(srna, NULL, "rna_ID_refine");
RNA_def_struct_refine_func(srna, "rna_ID_refine");
prop= RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
RNA_def_property_flag(prop, PROP_NOT_EDITABLE); /* must be unique */

View File

@@ -27,14 +27,16 @@
#include "MEM_guardedalloc.h"
#include "DNA_ID.h"
#include "DNA_windowmanager_types.h"
#include "BLI_blenlib.h"
#include "BLI_dynstr.h"
#include "BKE_idprop.h"
#include "BKE_utildefines.h"
#include "DNA_ID.h"
#include "DNA_windowmanager_types.h"
#include "WM_api.h"
#include "RNA_access.h"
#include "RNA_define.h"
@@ -507,12 +509,14 @@ int RNA_property_evaluated(PointerRNA *ptr, PropertyRNA *prop)
return (flag & PROP_EVALUATED);
}
void RNA_property_notify(PropertyRNA *prop, struct bContext *C, PointerRNA *ptr)
void RNA_property_update(struct bContext *C, PointerRNA *ptr, PropertyRNA *prop)
{
rna_idproperty_check(&prop, ptr);
if(prop->notify)
prop->notify(C, ptr);
if(prop->update)
prop->update(C, ptr);
if(prop->noteflag)
WM_event_add_notifier(C, prop->noteflag, ptr->id.data);
}
/* Property Data */

View File

@@ -81,7 +81,7 @@ void RNA_def_controller(BlenderRNA *brna)
srna= RNA_def_struct(brna, "Controller", NULL);
RNA_def_struct_ui_text(srna, "Controller", "logic brick to connect 'Sensors' to 'Actuators'");
RNA_def_struct_sdna(srna, "bController");
RNA_def_struct_funcs(srna, NULL, "rna_Controller_refine");
RNA_def_struct_refine_func(srna, "rna_Controller_refine");
prop= RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
RNA_def_property_ui_text(prop, "Name", "");

View File

@@ -521,18 +521,16 @@ void RNA_def_struct_flag(StructRNA *srna, int flag)
srna->flag= flag;
}
void RNA_def_struct_funcs(StructRNA *srna, const char *notify, const char *refine)
void RNA_def_struct_refine_func(StructRNA *srna, const char *refine)
{
if(!DefRNA.preprocess) {
fprintf(stderr, "RNA_def_struct_funcs: only during preprocessing.\n");
fprintf(stderr, "RNA_def_struct_refine_func: only during preprocessing.\n");
return;
}
if(notify) srna->notify= (NotifyFunc)notify;
if(refine) srna->refine= (StructRefineFunc)refine;
}
void RNA_def_struct_identifier(StructRNA *srna, const char *identifier)
{
if(DefRNA.preprocess) {
@@ -1298,17 +1296,27 @@ void RNA_def_property_collection_sdna(PropertyRNA *prop, const char *structname,
/* Functions */
void RNA_def_property_funcs(PropertyRNA *prop, const char *notify, const char *editable)
void RNA_def_property_editable_func(PropertyRNA *prop, const char *editable)
{
if(!DefRNA.preprocess) {
fprintf(stderr, "RNA_def_property_funcs: only during preprocessing.\n");
fprintf(stderr, "RNA_def_property_editable_func: only during preprocessing.\n");
return;
}
if(notify) prop->notify= (NotifyFunc)notify;
if(editable) prop->editable= (EditableFunc)editable;
}
void RNA_def_property_update(PropertyRNA *prop, int noteflag, const char *func)
{
if(!DefRNA.preprocess) {
fprintf(stderr, "RNA_def_struct_refine_func: only during preprocessing.\n");
return;
}
prop->noteflag= noteflag;
prop->update= (UpdateFunc)func;
}
void RNA_def_property_boolean_funcs(PropertyRNA *prop, const char *get, const char *set)
{
StructRNA *srna= DefRNA.laststruct;

View File

@@ -406,7 +406,7 @@ void RNA_def_fluidsim(BlenderRNA *brna)
srna= RNA_def_struct(brna, "FluidSettings", NULL);
RNA_def_struct_sdna(srna, "FluidsimSettings");
RNA_def_struct_funcs(srna, NULL, "rna_FluidSettings_refine");
RNA_def_struct_refine_func(srna, "rna_FluidSettings_refine");
RNA_def_struct_ui_text(srna, "Fluid Simulation Settings", "");
/* enable and type */

View File

@@ -36,7 +36,7 @@ struct bContext;
/* Function Callbacks */
typedef void (*NotifyFunc)(struct bContext *C, struct PointerRNA *ptr);
typedef void (*UpdateFunc)(struct bContext *C, struct PointerRNA *ptr);
typedef int (*EditableFunc)(struct PointerRNA *ptr);
typedef struct StructRNA *(*StructRefineFunc)(struct PointerRNA *ptr);
@@ -94,8 +94,9 @@ struct PropertyRNA {
/* if an array this is > 0, specifying the length */
unsigned int arraylength;
/* callback for notifys on change */
NotifyFunc notify;
/* callback for updates on change */
UpdateFunc update;
int noteflag;
/* callback for testing if editable/evaluated */
EditableFunc editable;
@@ -226,9 +227,6 @@ struct StructRNA {
/* struct this is derivedfrom */
struct StructRNA *from;
/* callback for notifys on change */
NotifyFunc notify;
/* function to give the more specific type */
StructRefineFunc refine;

View File

@@ -864,18 +864,18 @@ void rna_def_texmat_common(StructRNA *srna, const char *texspace_editable)
prop= RNA_def_property(srna, "texspace_loc", PROP_FLOAT, PROP_VECTOR);
RNA_def_property_float_sdna(prop, NULL, "loc");
RNA_def_property_ui_text(prop, "Texure Space Location", "Texture space location");
RNA_def_property_funcs(prop, NULL, texspace_editable);
RNA_def_property_editable_func(prop, texspace_editable);
prop= RNA_def_property(srna, "texspace_size", PROP_FLOAT, PROP_VECTOR);
RNA_def_property_float_sdna(prop, NULL, "size");
RNA_def_property_ui_text(prop, "Texture Space Size", "Texture space size");
RNA_def_property_funcs(prop, NULL, texspace_editable);
RNA_def_property_editable_func(prop, texspace_editable);
/* not supported yet
prop= RNA_def_property(srna, "texspace_rot", PROP_FLOAT, PROP_ROTATION);
RNA_def_property_float(prop, NULL, "rot");
RNA_def_property_ui_text(prop, "Texture Space Rotation", "Texture space rotation");
RNA_def_property_funcs(prop, NULL, texspace_editable);*/
RNA_def_property_editable_func(prop, texspace_editable);*/
/* materials */
prop= RNA_def_property(srna, "materials", PROP_COLLECTION, PROP_NONE);

View File

@@ -398,7 +398,7 @@ void RNA_def_modifier(BlenderRNA *brna)
/* data */
srna= RNA_def_struct(brna, "Modifier", NULL);
RNA_def_struct_ui_text(srna , "Object Modifier", "DOC_BROKEN");
RNA_def_struct_funcs(srna, NULL, "rna_Modifier_refine");
RNA_def_struct_refine_func(srna, "rna_Modifier_refine");
RNA_def_struct_sdna(srna, "ModifierData");
/* strings */

View File

@@ -33,8 +33,18 @@
#include "DNA_object_types.h"
#include "DNA_property_types.h"
#include "WM_types.h"
#ifdef RNA_RUNTIME
#include "BKE_context.h"
#include "BKE_depsgraph.h"
static void rna_Object_update(bContext *C, PointerRNA *ptr)
{
DAG_object_flush_update(CTX_data_scene(C), ptr->id.data, OB_RECALC_OB);
}
#else
void RNA_def_object(BlenderRNA *brna)
@@ -57,14 +67,15 @@ void RNA_def_object(BlenderRNA *brna)
prop= RNA_def_property(srna, "loc", PROP_FLOAT, PROP_VECTOR);
RNA_def_property_ui_text(prop, "Location", "DOC_BROKEN");
RNA_def_property_update(prop, NC_OBJECT|ND_TRANSFORM, "rna_Object_update");
//prop= RNA_def_property(srna, "rot", PROP_FLOAT, PROP_ROTATION);
//RNA_def_property_ui_text(prop, "Rotation", "");
prop= RNA_def_property(srna, "rot", PROP_FLOAT, PROP_VECTOR);
prop= RNA_def_property(srna, "rot", PROP_FLOAT, PROP_ROTATION);
RNA_def_property_ui_text(prop, "Rotation", "");
RNA_def_property_update(prop, NC_OBJECT|ND_TRANSFORM, "rna_Object_update");
prop= RNA_def_property(srna, "size", PROP_FLOAT, PROP_VECTOR);
RNA_def_property_ui_text(prop, "Scale", "DOC_BROKEN");
RNA_def_property_update(prop, NC_OBJECT|ND_TRANSFORM, "rna_Object_update");
prop= RNA_def_property(srna, "ipo", PROP_POINTER, PROP_NONE);
RNA_def_property_struct_type(prop, "Ipo");

View File

@@ -87,7 +87,7 @@ void RNA_def_gameproperty(BlenderRNA *brna)
srna= RNA_def_struct(brna, "GameProperty", NULL);
RNA_def_struct_ui_text(srna , "Game Property", "DOC_BROKEN");
RNA_def_struct_sdna(srna, "bProperty");
RNA_def_struct_funcs(srna, NULL, "rna_GameProperty_refine");
RNA_def_struct_refine_func(srna, "rna_GameProperty_refine");
prop= RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
RNA_def_property_flag(prop, PROP_NOT_EDITABLE); /* must be unique */

View File

@@ -467,7 +467,7 @@ static void rna_def_property(BlenderRNA *brna)
srna= RNA_def_struct(brna, "Property", NULL);
RNA_def_struct_ui_text(srna, "Property Definition", "DOC_BROKEN2");
RNA_def_struct_funcs(srna, NULL, "rna_Property_refine");
RNA_def_struct_refine_func(srna, "rna_Property_refine");
prop= RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
RNA_def_property_flag(prop, PROP_NOT_EDITABLE);

View File

@@ -98,7 +98,7 @@ void rna_def_sensor(BlenderRNA *brna)
srna= RNA_def_struct(brna, "Sensor", NULL);
RNA_def_struct_ui_text(srna, "Sensor", "DOC_BROKEN");
RNA_def_struct_sdna(srna, "bSensor");
RNA_def_struct_funcs(srna, NULL, "rna_Sensor_refine");
RNA_def_struct_refine_func(srna, "rna_Sensor_refine");
prop= RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
RNA_def_property_ui_text(prop, "Name", "Sensor name.");

View File

@@ -277,7 +277,7 @@ static void rna_def_sequence(BlenderRNA *brna)
srna = RNA_def_struct(brna, "Sequence", NULL);
RNA_def_struct_ui_text(srna, "Sequence", "DOC_BROKEN");
RNA_def_struct_funcs(srna, NULL, "rna_Sequence_refine");
RNA_def_struct_refine_func(srna, "rna_Sequence_refine");
prop= RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
RNA_def_property_string_funcs(prop, "rna_Sequence_name_get", "rna_Sequence_name_length", "rna_Sequence_name_set");

View File

@@ -99,7 +99,7 @@ static void rna_def_operator(BlenderRNA *brna)
srna= RNA_def_struct(brna, "OperatorProperties", NULL);
RNA_def_struct_ui_text(srna, "Operator Properties", "DOC_BROKEN");
RNA_def_struct_funcs(srna, NULL, "rna_OperatorProperties_refine");
RNA_def_struct_refine_func(srna, "rna_OperatorProperties_refine");
}
static void rna_def_operator_utils(BlenderRNA *brna)