diff options
author | Joshua Leung <aligorith@gmail.com> | 2008-12-30 03:28:11 +0300 |
---|---|---|
committer | Joshua Leung <aligorith@gmail.com> | 2008-12-30 03:28:11 +0300 |
commit | 26290958289e8a8f3eebccbd67b5968d2dae7d96 (patch) | |
tree | f1957bbed71f7bb52e31e2f4d8b7f5775febaf7c /source/blender/editors | |
parent | e114c195a630c397fee106d1baa9bfda04a4511e (diff) |
2.5 - Transform Code for Animation Editors (Part 1)
Remove context pointer from transform code. Solved the need for this by modifying the code that needed it.
Diffstat (limited to 'source/blender/editors')
-rw-r--r-- | source/blender/editors/animation/anim_filter.c | 71 | ||||
-rw-r--r-- | source/blender/editors/include/ED_anim_api.h | 6 | ||||
-rw-r--r-- | source/blender/editors/transform/transform.c | 2 | ||||
-rw-r--r-- | source/blender/editors/transform/transform.h | 1 | ||||
-rw-r--r-- | source/blender/editors/transform/transform_conversions.c | 24 | ||||
-rw-r--r-- | source/blender/editors/transform/transform_generics.c | 1 | ||||
-rw-r--r-- | source/blender/editors/transform/transform_ops.c | 4 |
7 files changed, 63 insertions, 46 deletions
diff --git a/source/blender/editors/animation/anim_filter.c b/source/blender/editors/animation/anim_filter.c index f9eddd1c2a8..e604af4d242 100644 --- a/source/blender/editors/animation/anim_filter.c +++ b/source/blender/editors/animation/anim_filter.c @@ -99,13 +99,13 @@ /* Get shapekey data being edited (for Action Editor -> ShapeKey mode) */ /* Note: there's a similar function in key.c (ob_get_key) */ -Key *actedit_get_shapekeys (const bContext *C, SpaceAction *saction) +Key *actedit_get_shapekeys (bAnimContext *ac, SpaceAction *saction) { - Scene *scene= CTX_data_scene(C); + Scene *scene= ac->scene; Object *ob; Key *key; - ob = OBACT; // XXX er... + ob = OBACT; if (ob == NULL) return NULL; @@ -140,7 +140,7 @@ Key *actedit_get_shapekeys (const bContext *C, SpaceAction *saction) } /* Get data being edited in Action Editor (depending on current 'mode') */ -static short actedit_get_context (const bContext *C, bAnimContext *ac, SpaceAction *saction) +static short actedit_get_context (bAnimContext *ac, SpaceAction *saction) { /* sync settings with current view status, then return appropriate data */ switch (saction->mode) { @@ -161,14 +161,15 @@ static short actedit_get_context (const bContext *C, bAnimContext *ac, SpaceActi case SACTCONT_SHAPEKEY: /* 'ShapeKey Editor' */ ac->datatype= ANIMCONT_SHAPEKEY; - ac->data= actedit_get_shapekeys(C, saction); + ac->data= actedit_get_shapekeys(ac, saction); ac->mode= saction->mode; return 1; case SACTCONT_GPENCIL: /* Grease Pencil */ // XXX review how this mode is handled... ac->datatype=ANIMCONT_GPENCIL; - ac->data= CTX_wm_screen(C); // FIXME: add that dopesheet type thing here! + //ac->data= CTX_wm_screen(C); // FIXME: add that dopesheet type thing here! + ac->data= NULL; // !!! ac->mode= saction->mode; return 1; @@ -195,7 +196,7 @@ static short actedit_get_context (const bContext *C, bAnimContext *ac, SpaceActi /* ----------- Private Stuff - IPO Editor ------------- */ /* Get data being edited in IPO Editor (depending on current 'mode') */ -static short ipoedit_get_context (const bContext *C, bAnimContext *ac, SpaceIpo *sipo) +static short ipoedit_get_context (bAnimContext *ac, SpaceIpo *sipo) { // XXX FIXME... return 0; @@ -203,44 +204,29 @@ static short ipoedit_get_context (const bContext *C, bAnimContext *ac, SpaceIpo /* ----------- Public API --------------- */ -/* Obtain current anim-data context from Blender Context info +/* Obtain current anim-data context, given that context info from Blender context has already been set * - AnimContext to write to is provided as pointer to var on stack so that we don't have * allocation/freeing costs (which are not that avoidable with channels). - * - */ -short ANIM_animdata_get_context (const bContext *C, bAnimContext *ac) +short ANIM_animdata_context_getdata (bAnimContext *ac) { - ScrArea *sa= CTX_wm_area(C); - ARegion *ar= CTX_wm_region(C); - Scene *scene= CTX_data_scene(C); + ScrArea *sa= ac->sa; short ok= 0; - /* clear old context info */ - if (ac == NULL) return 0; - memset(ac, 0, sizeof(bAnimContext)); - - /* set default context settings */ - ac->scene= scene; - ac->obact= (scene && scene->basact)? scene->basact->object : NULL; - ac->sa= sa; - ac->ar= ar; - ac->spacetype= (sa) ? sa->spacetype : 0; - ac->regiontype= (ar) ? ar->regiontype : 0; - /* context depends on editor we are currently in */ if (sa) { switch (sa->spacetype) { case SPACE_ACTION: { - SpaceAction *saction= (SpaceAction *)CTX_wm_space_data(C); - ok= actedit_get_context(C, ac, saction); + SpaceAction *saction= (SpaceAction *)sa->spacedata.first; + ok= actedit_get_context(ac, saction); } break; case SPACE_IPO: { - SpaceIpo *sipo= (SpaceIpo *)CTX_wm_space_data(C); - ok= ipoedit_get_context(C, ac, sipo); + SpaceIpo *sipo= (SpaceIpo *)sa->spacedata.first; + ok= ipoedit_get_context(ac, sipo); } break; } @@ -253,6 +239,33 @@ short ANIM_animdata_get_context (const bContext *C, bAnimContext *ac) return 0; } +/* Obtain current anim-data context from Blender Context info + * - AnimContext to write to is provided as pointer to var on stack so that we don't have + * allocation/freeing costs (which are not that avoidable with channels). + * - Clears data and sets the information from Blender Context which is useful + */ +short ANIM_animdata_get_context (const bContext *C, bAnimContext *ac) +{ + ScrArea *sa= CTX_wm_area(C); + ARegion *ar= CTX_wm_region(C); + Scene *scene= CTX_data_scene(C); + + /* clear old context info */ + if (ac == NULL) return 0; + memset(ac, 0, sizeof(bAnimContext)); + + /* get useful default context settings from context */ + ac->scene= scene; + ac->obact= (scene && scene->basact)? scene->basact->object : NULL; + ac->sa= sa; + ac->ar= ar; + ac->spacetype= (sa) ? sa->spacetype : 0; + ac->regiontype= (ar) ? ar->regiontype : 0; + + /* get data context info */ + return ANIM_animdata_context_getdata(ac); +} + /* ************************************************************ */ /* Blender Data <-- Filter --> Channels to be operated on */ diff --git a/source/blender/editors/include/ED_anim_api.h b/source/blender/editors/include/ED_anim_api.h index 4e55f8c364c..f5cd576c8a3 100644 --- a/source/blender/editors/include/ED_anim_api.h +++ b/source/blender/editors/include/ED_anim_api.h @@ -229,6 +229,12 @@ int ANIM_animdata_filter(ListBase *anim_data, int filter_mode, void *data, short */ short ANIM_animdata_get_context(const struct bContext *C, bAnimContext *ac); +/* Obtain current anim-data context (from Animation Editor) given + * that Blender Context info has already been set. + * Returns whether the operation was successful. + */ +short ANIM_animdata_context_getdata(bAnimContext *ac); + /* ************************************************ */ /* DRAWING API */ // XXX should this get its own header file? diff --git a/source/blender/editors/transform/transform.c b/source/blender/editors/transform/transform.c index 90107bee339..bb333b2cfbb 100644 --- a/source/blender/editors/transform/transform.c +++ b/source/blender/editors/transform/transform.c @@ -1107,8 +1107,6 @@ int transformEnd(TransInfo *t) #endif return 1; } - - t->context= NULL; t->event = NULL; return 0; diff --git a/source/blender/editors/transform/transform.h b/source/blender/editors/transform/transform.h index 68be5f35790..dc7949ed0ab 100644 --- a/source/blender/editors/transform/transform.h +++ b/source/blender/editors/transform/transform.h @@ -234,7 +234,6 @@ typedef struct TransInfo { /*************** NEW STUFF *********************/ float values[4]; - struct bContext *context; void *view; struct ScrArea *sa; struct ARegion *ar; diff --git a/source/blender/editors/transform/transform_conversions.c b/source/blender/editors/transform/transform_conversions.c index 36deae8b98e..fc32ac5a846 100644 --- a/source/blender/editors/transform/transform_conversions.c +++ b/source/blender/editors/transform/transform_conversions.c @@ -2575,6 +2575,8 @@ void flushTransIpoData(TransInfo *t) /* flush to 2d vector from internally used 3d vector */ for (a=0, td= t->data2d; a<t->total; a++, td++) { + // FIXME: autosnap needs to be here... + /* we need to unapply the nla-scaling from the time in some situations */ if (NLA_IPO_SCALED) td->loc2d[0]= get_action_frame(OBACT, td->loc[0]); @@ -3974,18 +3976,22 @@ void special_aftertrans_update(TransInfo *t) if (t->spacetype == SPACE_ACTION) { SpaceAction *saction= (SpaceAction *)t->sa->spacedata.first; - Scene *scene= NULL; + Scene *scene; bAnimContext ac; - /* determine what type of data we are operating on */ - if (ANIM_animdata_get_context(t->context, &ac) == 0) { - printf("space action transform -> special aftertrans exit. no context \n"); // XXX - return; - } + /* initialise relevant anim-context 'context' data from TransInfo data */ + /* NOTE: sync this with the code in ANIM_animdata_get_context() */ + memset(&ac, 0, sizeof(bAnimContext)); - /* get pointers to useful data */ - scene= ac.scene; - ob = OBACT; + scene= ac.scene= t->scene; + ob= ac.obact= OBACT; + ac.sa= t->sa; + ac.ar= t->ar; + ac.spacetype= (t->sa)? t->sa->spacetype : 0; + ac.regiontype= (t->ar)? t->ar->regiontype : 0; + + if (ANIM_animdata_context_getdata(&ac) == 0) + return; if (ac.datatype == ANIMCONT_DOPESHEET) { ListBase anim_data = {NULL, NULL}; diff --git a/source/blender/editors/transform/transform_generics.c b/source/blender/editors/transform/transform_generics.c index 1bac195911e..25413d25b9d 100644 --- a/source/blender/editors/transform/transform_generics.c +++ b/source/blender/editors/transform/transform_generics.c @@ -674,7 +674,6 @@ void initTransInfo (bContext *C, TransInfo *t, wmEvent *event) // else if(G.f & G_PARTICLEEDIT) G.moving= G_TRANSFORM_PARTICLE; // else G.moving= G_TRANSFORM_OBJ; - t->context= C; t->scene = sce; t->sa = sa; t->ar = ar; diff --git a/source/blender/editors/transform/transform_ops.c b/source/blender/editors/transform/transform_ops.c index 4ecb9358cc7..abd31801ca6 100644 --- a/source/blender/editors/transform/transform_ops.c +++ b/source/blender/editors/transform/transform_ops.c @@ -63,10 +63,6 @@ static int transform_modal(bContext *C, wmOperator *op, wmEvent *event) { TransInfo *t = op->customdata; - /* need to set context here, otherwise we get crashes with things that use context */ - // XXX this seems quite hackish - Aligorith - t->context= C; - transformEvent(t, event); transformApply(t); |