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.
This commit is contained in:
Joshua Leung
2008-12-30 00:28:11 +00:00
parent e114c195a6
commit 2629095828
7 changed files with 63 additions and 46 deletions

View File

@@ -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 */

View File

@@ -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?

View File

@@ -1107,8 +1107,6 @@ int transformEnd(TransInfo *t)
#endif
return 1;
}
t->context= NULL;
t->event = NULL;
return 0;

View File

@@ -234,7 +234,6 @@ typedef struct TransInfo {
/*************** NEW STUFF *********************/
float values[4];
struct bContext *context;
void *view;
struct ScrArea *sa;
struct ARegion *ar;

View File

@@ -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};

View File

@@ -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;

View File

@@ -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);