2011-02-23 10:52:22 +00:00
|
|
|
/*
|
2008-12-20 08:24:24 +00:00
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
2010-02-12 13:34:04 +00:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2008-12-20 08:24:24 +00:00
|
|
|
*
|
|
|
|
* The Original Code is Copyright (C) 2008 Blender Foundation.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Contributor(s): Joshua Leung
|
|
|
|
*
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
*/
|
2011-02-27 20:29:51 +00:00
|
|
|
|
|
|
|
/** \file blender/editors/animation/anim_draw.c
|
|
|
|
* \ingroup edanimation
|
|
|
|
*/
|
|
|
|
|
2013-05-28 19:35:26 +00:00
|
|
|
#include "BLI_sys_types.h"
|
2008-12-20 08:24:24 +00:00
|
|
|
|
2009-01-20 11:07:42 +00:00
|
|
|
#include "DNA_anim_types.h"
|
2008-12-20 08:24:24 +00:00
|
|
|
#include "DNA_scene_types.h"
|
2013-10-29 18:10:52 +00:00
|
|
|
#include "DNA_space_types.h"
|
Holiday coding log :)
Nice formatted version (pictures soon):
http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.66/Usability
Short list of main changes:
- Transparent region option (over main region), added code to blend in/out such panels.
- Min size window now 640 x 480
- Fixed DPI for ui - lots of cleanup and changes everywhere. Icon image need correct size still, layer-in-use icon needs remake.
- Macbook retina support, use command line --no-native-pixels to disable it
- Timeline Marker label was drawing wrong
- Trackpad and magic mouse: supports zoom (hold ctrl)
- Fix for splash position: removed ghost function and made window size update after creation immediate
- Fast undo buffer save now adds UI as well. Could be checked for regular file save even...
Quit.blend and temp file saving use this now.
- Dixed filename in window on reading quit.blend or temp saves, and they now add a warning in window title: "(Recovered)"
- New Userpref option "Keep Session" - this always saves quit.blend, and loads on start.
This allows keeping UI and data without actual saves, until you actually save.
When you load startup.blend and quit, it recognises the quit.blend as a startup (no file name in header)
- Added 3D view copy/paste buffers (selected objects). Shortcuts ctrl-c, ctrl-v (OSX, cmd-c, cmd-v).
Coded partial file saving for it. Could be used for other purposes. Todo: use OS clipboards.
- User preferences (themes, keymaps, user settings) now can be saved as a separate file.
Old option is called "Save Startup File" the new one "Save User Settings".
To visualise this difference, the 'save startup file' button has been removed from user preferences window. That option is available as CTRL+U and in File menu still.
- OSX: fixed bug that stopped giving mouse events outside window.
This also fixes "Continuous Grab" for OSX. (error since 2009)
2012-12-12 18:58:11 +00:00
|
|
|
#include "DNA_userdef_types.h"
|
2015-05-13 20:30:53 +02:00
|
|
|
#include "DNA_screen_types.h"
|
|
|
|
#include "DNA_object_types.h"
|
|
|
|
#include "DNA_gpencil_types.h"
|
|
|
|
#include "DNA_mask_types.h"
|
Holiday coding log :)
Nice formatted version (pictures soon):
http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.66/Usability
Short list of main changes:
- Transparent region option (over main region), added code to blend in/out such panels.
- Min size window now 640 x 480
- Fixed DPI for ui - lots of cleanup and changes everywhere. Icon image need correct size still, layer-in-use icon needs remake.
- Macbook retina support, use command line --no-native-pixels to disable it
- Timeline Marker label was drawing wrong
- Trackpad and magic mouse: supports zoom (hold ctrl)
- Fix for splash position: removed ghost function and made window size update after creation immediate
- Fast undo buffer save now adds UI as well. Could be checked for regular file save even...
Quit.blend and temp file saving use this now.
- Dixed filename in window on reading quit.blend or temp saves, and they now add a warning in window title: "(Recovered)"
- New Userpref option "Keep Session" - this always saves quit.blend, and loads on start.
This allows keeping UI and data without actual saves, until you actually save.
When you load startup.blend and quit, it recognises the quit.blend as a startup (no file name in header)
- Added 3D view copy/paste buffers (selected objects). Shortcuts ctrl-c, ctrl-v (OSX, cmd-c, cmd-v).
Coded partial file saving for it. Could be used for other purposes. Todo: use OS clipboards.
- User preferences (themes, keymaps, user settings) now can be saved as a separate file.
Old option is called "Save Startup File" the new one "Save User Settings".
To visualise this difference, the 'save startup file' button has been removed from user preferences window. That option is available as CTRL+U and in File menu still.
- OSX: fixed bug that stopped giving mouse events outside window.
This also fixes "Continuous Grab" for OSX. (error since 2009)
2012-12-12 18:58:11 +00:00
|
|
|
|
2010-01-26 09:25:32 +00:00
|
|
|
#include "BLI_math.h"
|
2014-01-29 20:01:30 +11:00
|
|
|
#include "BLI_timecode.h"
|
2015-04-13 12:43:56 +02:00
|
|
|
#include "BLI_utildefines.h"
|
2015-05-13 20:30:53 +02:00
|
|
|
#include "BLI_rect.h"
|
|
|
|
#include "BLI_dlrbTree.h"
|
2008-12-20 08:24:24 +00:00
|
|
|
|
|
|
|
#include "BKE_context.h"
|
2011-07-21 00:07:07 +00:00
|
|
|
#include "BKE_global.h"
|
2009-06-23 13:25:31 +00:00
|
|
|
#include "BKE_nla.h"
|
2015-05-13 20:30:53 +02:00
|
|
|
#include "BKE_mask.h"
|
2008-12-20 08:24:24 +00:00
|
|
|
|
|
|
|
#include "ED_anim_api.h"
|
2009-01-03 06:01:11 +00:00
|
|
|
#include "ED_keyframes_edit.h"
|
2015-05-13 20:30:53 +02:00
|
|
|
#include "ED_keyframes_draw.h"
|
2008-12-20 08:24:24 +00:00
|
|
|
|
2010-01-26 03:16:14 +00:00
|
|
|
#include "RNA_access.h"
|
|
|
|
|
2008-12-20 08:24:24 +00:00
|
|
|
#include "BIF_gl.h"
|
|
|
|
|
|
|
|
#include "UI_interface.h"
|
|
|
|
#include "UI_resources.h"
|
|
|
|
#include "UI_view2d.h"
|
|
|
|
|
2010-01-30 04:43:36 +00:00
|
|
|
/* *************************************************** */
|
|
|
|
/* CURRENT FRAME DRAWING */
|
|
|
|
|
|
|
|
/* Draw current frame number in a little green box beside the current frame indicator */
|
2014-01-29 20:01:30 +11:00
|
|
|
static void draw_cfra_number(Scene *scene, View2D *v2d, const float cfra, const bool time)
|
2010-01-30 04:43:36 +00:00
|
|
|
{
|
2015-01-20 14:25:39 +11:00
|
|
|
const uiFontStyle *fstyle = UI_FSTYLE_WIDGET;
|
2010-01-30 04:43:36 +00:00
|
|
|
float xscale, yscale, x, y;
|
2012-05-08 15:30:00 +00:00
|
|
|
char numstr[32] = " t"; /* t is the character to start replacing from */
|
2014-11-11 18:39:43 +01:00
|
|
|
int slen;
|
2010-01-30 04:43:36 +00:00
|
|
|
|
|
|
|
/* because the frame number text is subject to the same scaling as the contents of the view */
|
2014-04-21 18:46:52 +10:00
|
|
|
UI_view2d_scale_get(v2d, &xscale, &yscale);
|
2012-05-08 15:30:00 +00:00
|
|
|
glScalef(1.0f / xscale, 1.0f, 1.0f);
|
2010-01-30 04:43:36 +00:00
|
|
|
|
|
|
|
/* get timecode string
|
|
|
|
* - padding on str-buf passed so that it doesn't sit on the frame indicator
|
2012-03-01 12:20:18 +00:00
|
|
|
* - power = 0, gives 'standard' behavior for time
|
2010-01-30 04:43:36 +00:00
|
|
|
* but power = 1 is required for frames (to get integer frames)
|
|
|
|
*/
|
2014-01-29 20:01:30 +11:00
|
|
|
if (time) {
|
|
|
|
BLI_timecode_string_from_time(&numstr[4], sizeof(numstr) - 4, 0, FRA2TIME(cfra), FPS, U.timecode_style);
|
|
|
|
}
|
|
|
|
else {
|
2015-06-30 14:47:31 +10:00
|
|
|
BLI_timecode_string_from_time_seconds(&numstr[4], sizeof(numstr) - 4, 1, cfra);
|
2014-01-29 20:01:30 +11:00
|
|
|
}
|
2015-01-20 14:25:39 +11:00
|
|
|
|
|
|
|
slen = UI_fontstyle_string_width(fstyle, numstr) - 1;
|
2008-12-20 08:24:24 +00:00
|
|
|
|
|
|
|
/* get starting coordinates for drawing */
|
2012-05-08 15:30:00 +00:00
|
|
|
x = cfra * xscale;
|
Holiday coding log :)
Nice formatted version (pictures soon):
http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.66/Usability
Short list of main changes:
- Transparent region option (over main region), added code to blend in/out such panels.
- Min size window now 640 x 480
- Fixed DPI for ui - lots of cleanup and changes everywhere. Icon image need correct size still, layer-in-use icon needs remake.
- Macbook retina support, use command line --no-native-pixels to disable it
- Timeline Marker label was drawing wrong
- Trackpad and magic mouse: supports zoom (hold ctrl)
- Fix for splash position: removed ghost function and made window size update after creation immediate
- Fast undo buffer save now adds UI as well. Could be checked for regular file save even...
Quit.blend and temp file saving use this now.
- Dixed filename in window on reading quit.blend or temp saves, and they now add a warning in window title: "(Recovered)"
- New Userpref option "Keep Session" - this always saves quit.blend, and loads on start.
This allows keeping UI and data without actual saves, until you actually save.
When you load startup.blend and quit, it recognises the quit.blend as a startup (no file name in header)
- Added 3D view copy/paste buffers (selected objects). Shortcuts ctrl-c, ctrl-v (OSX, cmd-c, cmd-v).
Coded partial file saving for it. Could be used for other purposes. Todo: use OS clipboards.
- User preferences (themes, keymaps, user settings) now can be saved as a separate file.
Old option is called "Save Startup File" the new one "Save User Settings".
To visualise this difference, the 'save startup file' button has been removed from user preferences window. That option is available as CTRL+U and in File menu still.
- OSX: fixed bug that stopped giving mouse events outside window.
This also fixes "Continuous Grab" for OSX. (error since 2009)
2012-12-12 18:58:11 +00:00
|
|
|
y = 0.9f * U.widget_unit;
|
2008-12-20 08:24:24 +00:00
|
|
|
|
|
|
|
/* draw green box around/behind text */
|
2009-11-18 08:50:09 +00:00
|
|
|
UI_ThemeColorShade(TH_CFRAME, 0);
|
Holiday coding log :)
Nice formatted version (pictures soon):
http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.66/Usability
Short list of main changes:
- Transparent region option (over main region), added code to blend in/out such panels.
- Min size window now 640 x 480
- Fixed DPI for ui - lots of cleanup and changes everywhere. Icon image need correct size still, layer-in-use icon needs remake.
- Macbook retina support, use command line --no-native-pixels to disable it
- Timeline Marker label was drawing wrong
- Trackpad and magic mouse: supports zoom (hold ctrl)
- Fix for splash position: removed ghost function and made window size update after creation immediate
- Fast undo buffer save now adds UI as well. Could be checked for regular file save even...
Quit.blend and temp file saving use this now.
- Dixed filename in window on reading quit.blend or temp saves, and they now add a warning in window title: "(Recovered)"
- New Userpref option "Keep Session" - this always saves quit.blend, and loads on start.
This allows keeping UI and data without actual saves, until you actually save.
When you load startup.blend and quit, it recognises the quit.blend as a startup (no file name in header)
- Added 3D view copy/paste buffers (selected objects). Shortcuts ctrl-c, ctrl-v (OSX, cmd-c, cmd-v).
Coded partial file saving for it. Could be used for other purposes. Todo: use OS clipboards.
- User preferences (themes, keymaps, user settings) now can be saved as a separate file.
Old option is called "Save Startup File" the new one "Save User Settings".
To visualise this difference, the 'save startup file' button has been removed from user preferences window. That option is available as CTRL+U and in File menu still.
- OSX: fixed bug that stopped giving mouse events outside window.
This also fixes "Continuous Grab" for OSX. (error since 2009)
2012-12-12 18:58:11 +00:00
|
|
|
glRectf(x, y, x + slen, y + 0.75f * U.widget_unit);
|
2008-12-20 08:24:24 +00:00
|
|
|
|
|
|
|
/* draw current frame number - black text */
|
|
|
|
UI_ThemeColor(TH_TEXT);
|
2015-01-20 14:25:39 +11:00
|
|
|
UI_fontstyle_draw_simple(fstyle, x - 0.25f * U.widget_unit, y + 0.15f * U.widget_unit, numstr);
|
2008-12-20 08:24:24 +00:00
|
|
|
|
|
|
|
/* restore view transform */
|
2008-12-21 03:14:01 +00:00
|
|
|
glScalef(xscale, 1.0, 1.0);
|
2008-12-20 08:24:24 +00:00
|
|
|
}
|
|
|
|
|
2009-10-20 12:04:56 +00:00
|
|
|
/* General call for drawing current frame indicator in animation editor */
|
2012-04-29 17:11:40 +00:00
|
|
|
void ANIM_draw_cfra(const bContext *C, View2D *v2d, short flag)
|
2008-12-20 08:24:24 +00:00
|
|
|
{
|
2012-05-08 15:30:00 +00:00
|
|
|
Scene *scene = CTX_data_scene(C);
|
2008-12-20 08:24:24 +00:00
|
|
|
float vec[2];
|
|
|
|
|
|
|
|
/* Draw a light green line to indicate current frame */
|
2012-05-08 15:30:00 +00:00
|
|
|
vec[0] = (float)(scene->r.cfra * scene->r.framelen);
|
2008-12-20 08:24:24 +00:00
|
|
|
|
|
|
|
UI_ThemeColor(TH_CFRAME);
|
2011-07-12 12:13:23 +00:00
|
|
|
if (flag & DRAWCFRA_WIDE)
|
|
|
|
glLineWidth(3.0);
|
|
|
|
else
|
|
|
|
glLineWidth(2.0);
|
2008-12-20 08:24:24 +00:00
|
|
|
|
|
|
|
glBegin(GL_LINE_STRIP);
|
2012-05-08 15:30:00 +00:00
|
|
|
vec[1] = v2d->cur.ymin - 500.0f; /* XXX arbitrary... want it go to bottom */
|
|
|
|
glVertex2fv(vec);
|
2008-12-20 08:24:24 +00:00
|
|
|
|
2012-05-08 15:30:00 +00:00
|
|
|
vec[1] = v2d->cur.ymax;
|
|
|
|
glVertex2fv(vec);
|
2008-12-20 08:24:24 +00:00
|
|
|
glEnd();
|
|
|
|
|
|
|
|
glLineWidth(1.0);
|
|
|
|
|
|
|
|
/* Draw current frame number in a little box */
|
|
|
|
if (flag & DRAWCFRA_SHOW_NUMBOX) {
|
2010-10-14 01:22:14 +00:00
|
|
|
UI_view2d_view_orthoSpecial(CTX_wm_region(C), v2d, 1);
|
2014-01-29 20:01:30 +11:00
|
|
|
draw_cfra_number(scene, v2d, vec[0], (flag & DRAWCFRA_UNIT_SECONDS) != 0);
|
2008-12-20 08:24:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* *************************************************** */
|
|
|
|
/* PREVIEW RANGE 'CURTAINS' */
|
2008-12-27 05:24:03 +00:00
|
|
|
/* Note: 'Preview Range' tools are defined in anim_ops.c */
|
2008-12-20 08:24:24 +00:00
|
|
|
|
|
|
|
/* Draw preview range 'curtains' for highlighting where the animation data is */
|
2013-05-18 10:24:38 +00:00
|
|
|
void ANIM_draw_previewrange(const bContext *C, View2D *v2d, int end_frame_width)
|
2008-12-20 08:24:24 +00:00
|
|
|
{
|
2012-05-08 15:30:00 +00:00
|
|
|
Scene *scene = CTX_data_scene(C);
|
2008-12-20 08:24:24 +00:00
|
|
|
|
|
|
|
/* only draw this if preview range is set */
|
2010-01-19 20:30:04 +00:00
|
|
|
if (PRVRANGEON) {
|
2008-12-20 08:24:24 +00:00
|
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
glEnable(GL_BLEND);
|
|
|
|
glColor4f(0.0f, 0.0f, 0.0f, 0.4f);
|
|
|
|
|
|
|
|
/* only draw two separate 'curtains' if there's no overlap between them */
|
2013-05-18 11:37:49 +00:00
|
|
|
if (PSFRA < PEFRA + end_frame_width) {
|
2009-01-02 00:56:48 +00:00
|
|
|
glRectf(v2d->cur.xmin, v2d->cur.ymin, (float)PSFRA, v2d->cur.ymax);
|
2013-05-18 11:37:49 +00:00
|
|
|
glRectf((float)(PEFRA + end_frame_width), v2d->cur.ymin, v2d->cur.xmax, v2d->cur.ymax);
|
2012-10-21 05:46:41 +00:00
|
|
|
}
|
2008-12-20 08:24:24 +00:00
|
|
|
else {
|
|
|
|
glRectf(v2d->cur.xmin, v2d->cur.ymin, v2d->cur.xmax, v2d->cur.ymax);
|
|
|
|
}
|
|
|
|
|
|
|
|
glDisable(GL_BLEND);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* *************************************************** */
|
2009-01-03 06:01:11 +00:00
|
|
|
/* NLA-MAPPING UTILITIES (required for drawing and also editing keyframes) */
|
2008-12-22 08:13:25 +00:00
|
|
|
|
2009-06-23 13:25:31 +00:00
|
|
|
/* Obtain the AnimData block providing NLA-mapping for the given channel (if applicable) */
|
2010-01-26 03:16:14 +00:00
|
|
|
// TODO: do not supply return this if the animdata tells us that there is no mapping to perform
|
2009-06-23 13:25:31 +00:00
|
|
|
AnimData *ANIM_nla_mapping_get(bAnimContext *ac, bAnimListElem *ale)
|
2008-12-22 08:13:25 +00:00
|
|
|
{
|
|
|
|
/* sanity checks */
|
|
|
|
if (ac == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2011-07-21 00:07:07 +00:00
|
|
|
/* abort if rendering - we may get some race condition issues... */
|
2012-08-08 18:37:06 +00:00
|
|
|
if (G.is_rendering) return NULL;
|
2011-07-21 00:07:07 +00:00
|
|
|
|
2008-12-22 08:13:25 +00:00
|
|
|
/* handling depends on the type of animation-context we've got */
|
2015-03-29 03:03:05 +13:00
|
|
|
if (ale) {
|
|
|
|
/* NLA Control Curves occur on NLA strips, and shouldn't be subjected to this kind of mapping */
|
|
|
|
if (ale->type != ANIMTYPE_NLACURVE)
|
|
|
|
return ale->adt;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* cannot handle... */
|
|
|
|
return NULL;
|
2008-12-22 08:13:25 +00:00
|
|
|
}
|
|
|
|
|
2009-01-03 06:01:11 +00:00
|
|
|
/* ------------------- */
|
|
|
|
|
2009-06-23 13:25:31 +00:00
|
|
|
/* helper function for ANIM_nla_mapping_apply_fcurve() -> "restore", i.e. mapping points back to action-time */
|
2010-04-02 12:02:39 +00:00
|
|
|
static short bezt_nlamapping_restore(KeyframeEditData *ked, BezTriple *bezt)
|
2009-01-03 06:01:11 +00:00
|
|
|
{
|
2010-01-15 10:34:39 +00:00
|
|
|
/* AnimData block providing scaling is stored in 'data', only_keys option is stored in i1 */
|
2012-05-08 15:30:00 +00:00
|
|
|
AnimData *adt = (AnimData *)ked->data;
|
|
|
|
short only_keys = (short)ked->i1;
|
2010-01-15 10:34:39 +00:00
|
|
|
|
|
|
|
/* adjust BezTriple handles only if allowed to */
|
|
|
|
if (only_keys == 0) {
|
2012-05-08 15:30:00 +00:00
|
|
|
bezt->vec[0][0] = BKE_nla_tweakedit_remap(adt, bezt->vec[0][0], NLATIME_CONVERT_UNMAP);
|
|
|
|
bezt->vec[2][0] = BKE_nla_tweakedit_remap(adt, bezt->vec[2][0], NLATIME_CONVERT_UNMAP);
|
2010-01-15 10:34:39 +00:00
|
|
|
}
|
|
|
|
|
2012-05-08 15:30:00 +00:00
|
|
|
bezt->vec[1][0] = BKE_nla_tweakedit_remap(adt, bezt->vec[1][0], NLATIME_CONVERT_UNMAP);
|
2009-01-03 10:03:26 +00:00
|
|
|
|
|
|
|
return 0;
|
2009-01-03 06:01:11 +00:00
|
|
|
}
|
|
|
|
|
2009-06-23 13:25:31 +00:00
|
|
|
/* helper function for ANIM_nla_mapping_apply_fcurve() -> "apply", i.e. mapping points to NLA-mapped global time */
|
2010-04-02 12:02:39 +00:00
|
|
|
static short bezt_nlamapping_apply(KeyframeEditData *ked, BezTriple *bezt)
|
2009-01-03 06:01:11 +00:00
|
|
|
{
|
2009-06-23 13:25:31 +00:00
|
|
|
/* AnimData block providing scaling is stored in 'data', only_keys option is stored in i1 */
|
2012-05-08 15:30:00 +00:00
|
|
|
AnimData *adt = (AnimData *)ked->data;
|
|
|
|
short only_keys = (short)ked->i1;
|
2009-01-03 06:01:11 +00:00
|
|
|
|
|
|
|
/* adjust BezTriple handles only if allowed to */
|
|
|
|
if (only_keys == 0) {
|
2012-05-08 15:30:00 +00:00
|
|
|
bezt->vec[0][0] = BKE_nla_tweakedit_remap(adt, bezt->vec[0][0], NLATIME_CONVERT_MAP);
|
|
|
|
bezt->vec[2][0] = BKE_nla_tweakedit_remap(adt, bezt->vec[2][0], NLATIME_CONVERT_MAP);
|
2009-01-03 06:01:11 +00:00
|
|
|
}
|
2009-06-23 13:25:31 +00:00
|
|
|
|
2012-05-08 15:30:00 +00:00
|
|
|
bezt->vec[1][0] = BKE_nla_tweakedit_remap(adt, bezt->vec[1][0], NLATIME_CONVERT_MAP);
|
2009-01-03 10:03:26 +00:00
|
|
|
|
|
|
|
return 0;
|
2009-01-03 06:01:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-20 11:07:42 +00:00
|
|
|
/* Apply/Unapply NLA mapping to all keyframes in the nominated F-Curve
|
|
|
|
* - restore = whether to map points back to non-mapped time
|
2012-05-08 15:30:00 +00:00
|
|
|
* - only_keys = whether to only adjust the location of the center point of beztriples
|
2009-01-03 06:01:11 +00:00
|
|
|
*/
|
2014-04-11 11:25:41 +10:00
|
|
|
void ANIM_nla_mapping_apply_fcurve(AnimData *adt, FCurve *fcu, bool restore, bool only_keys)
|
2009-01-03 06:01:11 +00:00
|
|
|
{
|
2012-05-08 15:30:00 +00:00
|
|
|
KeyframeEditData ked = {{NULL}};
|
2010-04-02 12:02:39 +00:00
|
|
|
KeyframeEditFunc map_cb;
|
2009-01-03 06:01:11 +00:00
|
|
|
|
|
|
|
/* init edit data
|
2009-06-23 13:25:31 +00:00
|
|
|
* - AnimData is stored in 'data'
|
2009-01-03 06:01:11 +00:00
|
|
|
* - only_keys is stored in 'i1'
|
|
|
|
*/
|
2012-05-08 15:30:00 +00:00
|
|
|
ked.data = (void *)adt;
|
|
|
|
ked.i1 = (int)only_keys;
|
2009-01-03 06:01:11 +00:00
|
|
|
|
|
|
|
/* get editing callback */
|
|
|
|
if (restore)
|
2012-05-08 15:30:00 +00:00
|
|
|
map_cb = bezt_nlamapping_restore;
|
2009-01-03 06:01:11 +00:00
|
|
|
else
|
2012-05-08 15:30:00 +00:00
|
|
|
map_cb = bezt_nlamapping_apply;
|
2009-01-03 06:01:11 +00:00
|
|
|
|
2009-01-20 11:07:42 +00:00
|
|
|
/* apply to F-Curve */
|
2010-04-02 12:02:39 +00:00
|
|
|
ANIM_fcurve_keyframes_loop(&ked, fcu, NULL, map_cb, NULL);
|
2009-09-27 06:14:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* *************************************************** */
|
2010-01-26 03:16:14 +00:00
|
|
|
/* UNITS CONVERSION MAPPING (required for drawing and editing keyframes) */
|
|
|
|
|
2013-10-29 18:10:52 +00:00
|
|
|
/* Get flags used for normalization in ANIM_unit_mapping_get_factor. */
|
|
|
|
short ANIM_get_normalization_flags(bAnimContext *ac)
|
|
|
|
{
|
|
|
|
if (ac->sl->spacetype == SPACE_IPO) {
|
|
|
|
SpaceIpo *sipo = (SpaceIpo *) ac->sl;
|
|
|
|
bool use_normalization = (sipo->flag & SIPO_NORMALIZE) != 0;
|
|
|
|
bool freeze_normalization = (sipo->flag & SIPO_NORMALIZE_FREEZE) != 0;
|
|
|
|
return use_normalization
|
|
|
|
? (ANIM_UNITCONV_NORMALIZE | (freeze_normalization ? ANIM_UNITCONV_NORMALIZE_FREEZE : 0))
|
|
|
|
: 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-04-13 15:57:46 +02:00
|
|
|
static float normalization_factor_get(Scene *scene, FCurve *fcu, short flag, float *r_offset)
|
2013-10-29 18:10:52 +00:00
|
|
|
{
|
2015-04-13 15:57:46 +02:00
|
|
|
float factor = 1.0f, offset = 0.0f;
|
2013-10-29 18:10:52 +00:00
|
|
|
|
|
|
|
if (flag & ANIM_UNITCONV_RESTORE) {
|
2015-04-13 15:57:46 +02:00
|
|
|
if (r_offset)
|
|
|
|
*r_offset = fcu->prev_offset;
|
|
|
|
|
2013-10-29 18:10:52 +00:00
|
|
|
return 1.0f / fcu->prev_norm_factor;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flag & ANIM_UNITCONV_NORMALIZE_FREEZE) {
|
2015-04-13 15:57:46 +02:00
|
|
|
if (r_offset)
|
|
|
|
*r_offset = fcu->prev_offset;
|
2013-10-29 18:10:52 +00:00
|
|
|
return fcu->prev_norm_factor;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (G.moving & G_TRANSFORM_FCURVES) {
|
2015-04-13 15:57:46 +02:00
|
|
|
if (r_offset)
|
|
|
|
*r_offset = fcu->prev_offset;
|
2013-10-29 18:10:52 +00:00
|
|
|
return fcu->prev_norm_factor;
|
|
|
|
}
|
|
|
|
|
|
|
|
fcu->prev_norm_factor = 1.0f;
|
|
|
|
if (fcu->bezt) {
|
|
|
|
BezTriple *bezt;
|
|
|
|
int i;
|
|
|
|
float max_coord = -FLT_MAX;
|
2015-04-13 15:57:46 +02:00
|
|
|
float min_coord = FLT_MAX;
|
|
|
|
float range;
|
2013-10-29 18:10:52 +00:00
|
|
|
|
|
|
|
if (fcu->totvert < 1) {
|
|
|
|
return 1.0f;
|
|
|
|
}
|
|
|
|
|
2015-04-13 12:43:56 +02:00
|
|
|
if (PRVRANGEON) {
|
|
|
|
for (i = 0, bezt = fcu->bezt; i < fcu->totvert; i++, bezt++) {
|
|
|
|
if (IN_RANGE_INCL(bezt->vec[1][0], scene->r.psfra, scene->r.pefra)) {
|
2015-04-13 15:57:46 +02:00
|
|
|
max_coord = max_ff(max_coord, bezt->vec[0][1]);
|
|
|
|
max_coord = max_ff(max_coord, bezt->vec[1][1]);
|
|
|
|
max_coord = max_ff(max_coord, bezt->vec[2][1]);
|
|
|
|
|
|
|
|
min_coord = min_ff(min_coord, bezt->vec[0][1]);
|
|
|
|
min_coord = min_ff(min_coord, bezt->vec[1][1]);
|
|
|
|
min_coord = min_ff(min_coord, bezt->vec[2][1]);
|
2015-04-13 12:43:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
for (i = 0, bezt = fcu->bezt; i < fcu->totvert; i++, bezt++) {
|
2015-04-13 15:57:46 +02:00
|
|
|
max_coord = max_ff(max_coord, bezt->vec[0][1]);
|
|
|
|
max_coord = max_ff(max_coord, bezt->vec[1][1]);
|
|
|
|
max_coord = max_ff(max_coord, bezt->vec[2][1]);
|
|
|
|
|
|
|
|
min_coord = min_ff(min_coord, bezt->vec[0][1]);
|
|
|
|
min_coord = min_ff(min_coord, bezt->vec[1][1]);
|
|
|
|
min_coord = min_ff(min_coord, bezt->vec[2][1]);
|
2015-04-13 12:43:56 +02:00
|
|
|
}
|
2013-10-29 18:10:52 +00:00
|
|
|
}
|
|
|
|
|
2015-04-13 15:57:46 +02:00
|
|
|
range = max_coord - min_coord;
|
|
|
|
|
|
|
|
if (range > FLT_EPSILON) {
|
2015-04-13 18:37:15 +02:00
|
|
|
factor = 2.0f / range;
|
2013-10-29 18:10:52 +00:00
|
|
|
}
|
2015-04-13 15:57:46 +02:00
|
|
|
offset = -min_coord - range / 2.0f;
|
2013-10-29 18:10:52 +00:00
|
|
|
}
|
2015-04-13 15:57:46 +02:00
|
|
|
|
|
|
|
if (r_offset) {
|
|
|
|
*r_offset = offset;
|
|
|
|
}
|
|
|
|
|
2013-10-29 18:10:52 +00:00
|
|
|
fcu->prev_norm_factor = factor;
|
2015-04-13 15:57:46 +02:00
|
|
|
fcu->prev_offset = offset;
|
2013-10-29 18:10:52 +00:00
|
|
|
return factor;
|
|
|
|
}
|
|
|
|
|
2010-01-26 03:16:14 +00:00
|
|
|
/* Get unit conversion factor for given ID + F-Curve */
|
2015-04-13 15:57:46 +02:00
|
|
|
float ANIM_unit_mapping_get_factor(Scene *scene, ID *id, FCurve *fcu, short flag, float *r_offset)
|
2010-01-26 03:16:14 +00:00
|
|
|
{
|
2013-10-29 18:10:52 +00:00
|
|
|
if (flag & ANIM_UNITCONV_NORMALIZE) {
|
2015-04-13 15:57:46 +02:00
|
|
|
return normalization_factor_get(scene, fcu, flag, r_offset);
|
2013-10-29 18:10:52 +00:00
|
|
|
}
|
|
|
|
|
2015-04-13 15:57:46 +02:00
|
|
|
if (r_offset)
|
|
|
|
*r_offset = 0.0f;
|
|
|
|
|
2010-01-26 03:16:14 +00:00
|
|
|
/* sanity checks */
|
2012-03-06 18:40:15 +00:00
|
|
|
if (id && fcu && fcu->rna_path) {
|
2010-01-26 03:16:14 +00:00
|
|
|
PointerRNA ptr, id_ptr;
|
|
|
|
PropertyRNA *prop;
|
|
|
|
|
|
|
|
/* get RNA property that F-Curve affects */
|
|
|
|
RNA_id_pointer_create(id, &id_ptr);
|
Bugfix [#34836] Crash when driver variable has path == 'data'
Most of the places which relied on RNA_path_resolve() did so believing that if
it returned true, that it had found a valid property, and that the returned
pointer+property combination would be what the path referred to. However, it
turns out that if the property at the end of the path turns out to be a
"pointer" property (e.g. "data" for Object.data), this would automatically
become the pointer part, while the prop part would be set to null. Hence, if a
user accidentally (or otherwise) specifies a path for the single-property driver
variable type like this, then Blender would crash.
This commit introduces two convenience functions - RNA_path_resolve_property()
and RNA_path_resolve_property_full() - which mirror/wrap the existing
RNA_path_resolve() functions. The only difference though is that these include a
check to ensure that what was found from resolving the path was in fact a
property (they only return true iff this is the case), and make it explicitly
clear in the name that this is what they will do so that there's no further
confusion. It is possible to do without these wrapper functions by doing these
checks inline, but the few cases that had been patched already were pretty
hideous looking specimens. Using these just make it clearer and simpler for all.
I've also beefed up the docs on these a bit, and changed these to using bools.
2013-04-22 13:22:07 +00:00
|
|
|
if (RNA_path_resolve_property(&id_ptr, fcu->rna_path, &ptr, &prop)) {
|
2010-01-26 03:16:14 +00:00
|
|
|
/* rotations: radians <-> degrees? */
|
2012-03-06 18:40:15 +00:00
|
|
|
if (RNA_SUBTYPE_UNIT(RNA_property_subtype(prop)) == PROP_UNIT_ROTATION) {
|
2010-01-26 03:16:14 +00:00
|
|
|
/* if the radians flag is not set, default to using degrees which need conversions */
|
2010-11-18 14:10:09 +00:00
|
|
|
if ((scene) && (scene->unit.system_rotation == USER_UNIT_ROT_RADIANS) == 0) {
|
2013-10-29 18:10:52 +00:00
|
|
|
if (flag & ANIM_UNITCONV_RESTORE)
|
2012-05-08 15:30:00 +00:00
|
|
|
return DEG2RADF(1.0f); /* degrees to radians */
|
2010-01-26 03:16:14 +00:00
|
|
|
else
|
2012-05-08 15:30:00 +00:00
|
|
|
return RAD2DEGF(1.0f); /* radians to degrees */
|
2010-01-26 03:16:14 +00:00
|
|
|
}
|
|
|
|
}
|
Axis Colours are now Themeable
This commit allows you to set the RGB <-> XYZ axis colours used for things like
the mini axis indicator, grid axis indicators, manipulators, transform
constraint indicators, F-Curves (when using XYZ to RGB colouring option), and
perhaps something else I've missed. Previously, these places all used hardcoded
defines (220 * i/j/k), but the readability of these colours was often quite
poor, especially when used with certain themes.
The settings for these colours can be found under the "User Interface" section
of the themes (i.e. same set of colours is used across editors). I could have
made these per editor, but since it's unlikely that these will need to be too
different across editors in practice (+ being easier to version patch), they are
stored under the UI section.
2012-11-09 06:36:11 +00:00
|
|
|
|
2012-07-06 23:56:59 +00:00
|
|
|
/* TODO: other rotation types here as necessary */
|
2010-01-26 03:16:14 +00:00
|
|
|
}
|
|
|
|
}
|
2012-07-06 23:56:59 +00:00
|
|
|
|
2010-01-26 03:16:14 +00:00
|
|
|
/* no mapping needs to occur... */
|
|
|
|
return 1.0f;
|
|
|
|
}
|
|
|
|
|
2015-05-15 23:38:53 +10:00
|
|
|
static bool find_prev_next_keyframes(struct bContext *C, int *nextfra, int *prevfra)
|
|
|
|
{
|
2015-05-13 20:30:53 +02:00
|
|
|
Scene *scene = CTX_data_scene(C);
|
|
|
|
Object *ob = CTX_data_active_object(C);
|
|
|
|
bGPdata *gpd = CTX_data_gpencil_data(C);
|
|
|
|
Mask *mask = CTX_data_edit_mask(C);
|
|
|
|
bDopeSheet ads = {NULL};
|
|
|
|
DLRBT_Tree keys;
|
|
|
|
ActKeyColumn *aknext, *akprev;
|
|
|
|
float cfranext, cfraprev;
|
|
|
|
bool donenext = false, doneprev = false;
|
|
|
|
int nextcount = 0, prevcount = 0;
|
|
|
|
|
|
|
|
cfranext = cfraprev = (float)(CFRA);
|
|
|
|
|
|
|
|
/* init binarytree-list for getting keyframes */
|
|
|
|
BLI_dlrbTree_init(&keys);
|
|
|
|
|
|
|
|
/* seed up dummy dopesheet context with flags to perform necessary filtering */
|
|
|
|
if ((scene->flag & SCE_KEYS_NO_SELONLY) == 0) {
|
|
|
|
/* only selected channels are included */
|
|
|
|
ads.filterflag |= ADS_FILTER_ONLYSEL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* populate tree with keyframe nodes */
|
|
|
|
scene_to_keylist(&ads, scene, &keys, NULL);
|
|
|
|
|
|
|
|
if (ob)
|
|
|
|
ob_to_keylist(&ads, ob, &keys, NULL);
|
|
|
|
|
|
|
|
gpencil_to_keylist(&ads, gpd, &keys);
|
|
|
|
|
|
|
|
if (mask) {
|
|
|
|
MaskLayer *masklay = BKE_mask_layer_active(mask);
|
|
|
|
mask_to_keylist(&ads, masklay, &keys);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* build linked-list for searching */
|
|
|
|
BLI_dlrbTree_linkedlist_sync(&keys);
|
|
|
|
|
|
|
|
/* find matching keyframe in the right direction */
|
|
|
|
do {
|
|
|
|
aknext = (ActKeyColumn *)BLI_dlrbTree_search_next(&keys, compare_ak_cfraPtr, &cfranext);
|
|
|
|
|
|
|
|
if (aknext) {
|
|
|
|
if (CFRA == (int)aknext->cfra) {
|
|
|
|
/* make this the new starting point for the search and ignore */
|
|
|
|
cfranext = aknext->cfra;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* this changes the frame, so set the frame and we're done */
|
|
|
|
if (++nextcount == U.view_frame_keyframes)
|
|
|
|
donenext = true;
|
|
|
|
}
|
|
|
|
cfranext = aknext->cfra;
|
|
|
|
}
|
|
|
|
} while ((aknext != NULL) && (donenext == false));
|
|
|
|
|
|
|
|
do {
|
|
|
|
akprev = (ActKeyColumn *)BLI_dlrbTree_search_prev(&keys, compare_ak_cfraPtr, &cfraprev);
|
|
|
|
|
|
|
|
if (akprev) {
|
|
|
|
if (CFRA == (int)akprev->cfra) {
|
|
|
|
/* make this the new starting point for the search */
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* this changes the frame, so set the frame and we're done */
|
|
|
|
if (++prevcount == U.view_frame_keyframes)
|
|
|
|
doneprev = true;
|
|
|
|
}
|
|
|
|
cfraprev = akprev->cfra;
|
|
|
|
}
|
|
|
|
} while ((akprev != NULL) && (doneprev == false));
|
|
|
|
|
|
|
|
/* free temp stuff */
|
|
|
|
BLI_dlrbTree_free(&keys);
|
|
|
|
|
|
|
|
/* any success? */
|
|
|
|
if (doneprev || donenext) {
|
|
|
|
if (doneprev)
|
|
|
|
*prevfra = cfraprev;
|
|
|
|
else
|
|
|
|
*prevfra = CFRA - (cfranext - CFRA);
|
|
|
|
|
|
|
|
if (donenext)
|
|
|
|
*nextfra = cfranext;
|
|
|
|
else
|
|
|
|
*nextfra = CFRA + (CFRA - cfraprev);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ANIM_center_frame(struct bContext *C, int smooth_viewtx)
|
|
|
|
{
|
|
|
|
ARegion *ar = CTX_wm_region(C);
|
|
|
|
Scene *scene = CTX_data_scene(C);
|
|
|
|
float w = BLI_rctf_size_x(&ar->v2d.cur);
|
|
|
|
rctf newrct;
|
|
|
|
int nextfra, prevfra;
|
|
|
|
|
|
|
|
switch (U.view_frame_type) {
|
|
|
|
case ZOOM_FRAME_MODE_SECONDS:
|
|
|
|
newrct.xmax = scene->r.cfra + U.view_frame_seconds * FPS + 1;
|
|
|
|
newrct.xmin = scene->r.cfra - U.view_frame_seconds * FPS - 1;
|
|
|
|
newrct.ymax = ar->v2d.cur.ymax;
|
|
|
|
newrct.ymin = ar->v2d.cur.ymin;
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* hardest case of all, look for all keyframes around frame and display those */
|
|
|
|
case ZOOM_FRAME_MODE_KEYFRAMES:
|
|
|
|
if (find_prev_next_keyframes(C, &nextfra, &prevfra)) {
|
|
|
|
newrct.xmax = nextfra;
|
|
|
|
newrct.xmin = prevfra;
|
|
|
|
newrct.ymax = ar->v2d.cur.ymax;
|
|
|
|
newrct.ymin = ar->v2d.cur.ymin;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* else drop through, keep range instead */
|
|
|
|
|
|
|
|
case ZOOM_FRAME_MODE_KEEP_RANGE:
|
|
|
|
default:
|
|
|
|
newrct.xmax = scene->r.cfra + (w / 2);
|
|
|
|
newrct.xmin = scene->r.cfra - (w / 2);
|
|
|
|
newrct.ymax = ar->v2d.cur.ymax;
|
|
|
|
newrct.ymin = ar->v2d.cur.ymin;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
UI_view2d_smooth_view(C, ar, &newrct, smooth_viewtx);
|
|
|
|
}
|
2010-01-26 03:16:14 +00:00
|
|
|
/* *************************************************** */
|