2011-02-23 10:52:22 +00:00
|
|
|
/*
|
2009-01-14 16:13:50 +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.
|
2009-01-14 16:13:50 +00:00
|
|
|
*
|
|
|
|
* The Original Code is Copyright (C) 2008, Blender Foundation
|
|
|
|
* This is a new part of Blender
|
|
|
|
*
|
|
|
|
* Contributor(s): Joshua Leung
|
|
|
|
*
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
*/
|
2011-02-27 20:29:51 +00:00
|
|
|
|
|
|
|
/** \file blender/editors/gpencil/editaction_gpencil.c
|
|
|
|
* \ingroup edgpencil
|
|
|
|
*/
|
|
|
|
|
2014-12-26 20:00:52 +01:00
|
|
|
|
2009-01-14 16:13:50 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <math.h>
|
|
|
|
|
2011-01-10 22:10:28 +00:00
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
2009-01-14 16:13:50 +00:00
|
|
|
#include "BLI_blenlib.h"
|
2011-01-10 22:10:28 +00:00
|
|
|
#include "BLI_utildefines.h"
|
2009-01-14 16:13:50 +00:00
|
|
|
|
2011-01-10 22:10:28 +00:00
|
|
|
#include "DNA_gpencil_types.h"
|
|
|
|
#include "DNA_scene_types.h"
|
2009-01-14 16:13:50 +00:00
|
|
|
|
2011-01-10 22:10:28 +00:00
|
|
|
#include "BKE_fcurve.h"
|
|
|
|
#include "BKE_gpencil.h"
|
2009-05-05 23:25:12 +00:00
|
|
|
|
2011-01-10 22:10:28 +00:00
|
|
|
#include "ED_gpencil.h"
|
|
|
|
#include "ED_keyframes_edit.h"
|
2012-12-03 13:07:43 +00:00
|
|
|
#include "ED_markers.h"
|
2009-01-14 16:13:50 +00:00
|
|
|
|
|
|
|
/* ***************************************** */
|
|
|
|
/* NOTE ABOUT THIS FILE:
|
2012-05-08 18:29:02 +00:00
|
|
|
* This file contains code for editing Grease Pencil data in the Action Editor
|
|
|
|
* as a 'keyframes', so that a user can adjust the timing of Grease Pencil drawings.
|
|
|
|
* Therefore, this file mostly contains functions for selecting Grease-Pencil frames.
|
2009-01-14 16:13:50 +00:00
|
|
|
*/
|
|
|
|
/* ***************************************** */
|
|
|
|
/* Generics - Loopers */
|
|
|
|
|
|
|
|
/* Loops over the gp-frames for a gp-layer, and applies the given callback */
|
2014-06-14 02:54:17 +10:00
|
|
|
bool ED_gplayer_frames_looper(bGPDlayer *gpl, Scene *scene, short (*gpf_cb)(bGPDframe *, Scene *))
|
2009-01-14 16:13:50 +00:00
|
|
|
{
|
|
|
|
bGPDframe *gpf;
|
2014-12-27 12:09:29 +13:00
|
|
|
|
2009-01-14 16:13:50 +00:00
|
|
|
/* error checker */
|
|
|
|
if (gpl == NULL)
|
2014-06-14 02:54:17 +10:00
|
|
|
return false;
|
2014-12-27 12:09:29 +13:00
|
|
|
|
2009-01-14 16:13:50 +00:00
|
|
|
/* do loop */
|
2012-05-08 18:29:02 +00:00
|
|
|
for (gpf = gpl->frames.first; gpf; gpf = gpf->next) {
|
2009-01-14 16:13:50 +00:00
|
|
|
/* execute callback */
|
|
|
|
if (gpf_cb(gpf, scene))
|
2014-06-14 02:54:17 +10:00
|
|
|
return true;
|
2009-01-14 16:13:50 +00:00
|
|
|
}
|
2014-12-27 12:09:29 +13:00
|
|
|
|
2009-01-14 16:13:50 +00:00
|
|
|
/* nothing to return */
|
2014-06-14 02:54:17 +10:00
|
|
|
return false;
|
2009-01-14 16:13:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ****************************************** */
|
|
|
|
/* Data Conversion Tools */
|
|
|
|
|
|
|
|
/* make a listing all the gp-frames in a layer as cfraelems */
|
2014-06-14 02:54:17 +10:00
|
|
|
void ED_gplayer_make_cfra_list(bGPDlayer *gpl, ListBase *elems, bool onlysel)
|
2009-01-14 16:13:50 +00:00
|
|
|
{
|
|
|
|
bGPDframe *gpf;
|
|
|
|
CfraElem *ce;
|
2014-12-27 12:09:29 +13:00
|
|
|
|
2009-01-14 16:13:50 +00:00
|
|
|
/* error checking */
|
|
|
|
if (ELEM(NULL, gpl, elems))
|
|
|
|
return;
|
2014-12-27 12:09:29 +13:00
|
|
|
|
2009-01-14 16:13:50 +00:00
|
|
|
/* loop through gp-frames, adding */
|
2012-05-08 18:29:02 +00:00
|
|
|
for (gpf = gpl->frames.first; gpf; gpf = gpf->next) {
|
2009-01-14 16:13:50 +00:00
|
|
|
if ((onlysel == 0) || (gpf->flag & GP_FRAME_SELECT)) {
|
2012-05-08 18:29:02 +00:00
|
|
|
ce = MEM_callocN(sizeof(CfraElem), "CfraElem");
|
2014-12-27 12:09:29 +13:00
|
|
|
|
2012-05-08 18:29:02 +00:00
|
|
|
ce->cfra = (float)gpf->framenum;
|
|
|
|
ce->sel = (gpf->flag & GP_FRAME_SELECT) ? 1 : 0;
|
2014-12-27 12:09:29 +13:00
|
|
|
|
2009-01-14 16:13:50 +00:00
|
|
|
BLI_addtail(elems, ce);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ***************************************** */
|
|
|
|
/* Selection Tools */
|
|
|
|
|
|
|
|
/* check if one of the frames in this layer is selected */
|
2014-06-14 02:54:17 +10:00
|
|
|
bool ED_gplayer_frame_select_check(bGPDlayer *gpl)
|
2009-01-14 16:13:50 +00:00
|
|
|
{
|
|
|
|
bGPDframe *gpf;
|
2014-12-27 12:09:29 +13:00
|
|
|
|
2009-01-14 16:13:50 +00:00
|
|
|
/* error checking */
|
2014-12-26 20:00:52 +01:00
|
|
|
if (gpl == NULL)
|
2014-06-14 02:54:17 +10:00
|
|
|
return false;
|
2014-12-27 12:09:29 +13:00
|
|
|
|
2009-01-14 16:13:50 +00:00
|
|
|
/* stop at the first one found */
|
2012-05-08 18:29:02 +00:00
|
|
|
for (gpf = gpl->frames.first; gpf; gpf = gpf->next) {
|
2009-01-14 16:13:50 +00:00
|
|
|
if (gpf->flag & GP_FRAME_SELECT)
|
2014-06-14 02:54:17 +10:00
|
|
|
return true;
|
2009-01-14 16:13:50 +00:00
|
|
|
}
|
2014-12-27 12:09:29 +13:00
|
|
|
|
2009-01-14 16:13:50 +00:00
|
|
|
/* not found */
|
2014-06-14 02:54:17 +10:00
|
|
|
return false;
|
2009-01-14 16:13:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* helper function - select gp-frame based on SELECT_* mode */
|
2012-05-08 18:29:02 +00:00
|
|
|
static void gpframe_select(bGPDframe *gpf, short select_mode)
|
2009-01-14 16:13:50 +00:00
|
|
|
{
|
2011-01-10 22:10:28 +00:00
|
|
|
if (gpf == NULL)
|
|
|
|
return;
|
2014-12-27 12:09:29 +13:00
|
|
|
|
2009-01-14 16:13:50 +00:00
|
|
|
switch (select_mode) {
|
|
|
|
case SELECT_ADD:
|
|
|
|
gpf->flag |= GP_FRAME_SELECT;
|
|
|
|
break;
|
|
|
|
case SELECT_SUBTRACT:
|
|
|
|
gpf->flag &= ~GP_FRAME_SELECT;
|
|
|
|
break;
|
|
|
|
case SELECT_INVERT:
|
|
|
|
gpf->flag ^= GP_FRAME_SELECT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* set all/none/invert select (like above, but with SELECT_* modes) */
|
2012-06-08 21:48:04 +00:00
|
|
|
void ED_gpencil_select_frames(bGPDlayer *gpl, short select_mode)
|
2009-01-14 16:13:50 +00:00
|
|
|
{
|
|
|
|
bGPDframe *gpf;
|
2014-12-27 12:09:29 +13:00
|
|
|
|
2009-01-14 16:13:50 +00:00
|
|
|
/* error checking */
|
2014-12-26 20:00:52 +01:00
|
|
|
if (gpl == NULL)
|
2009-01-14 16:13:50 +00:00
|
|
|
return;
|
2014-12-27 12:09:29 +13:00
|
|
|
|
2009-01-14 16:13:50 +00:00
|
|
|
/* handle according to mode */
|
2012-05-08 18:29:02 +00:00
|
|
|
for (gpf = gpl->frames.first; gpf; gpf = gpf->next) {
|
2009-01-14 16:13:50 +00:00
|
|
|
gpframe_select(gpf, select_mode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* set all/none/invert select */
|
2012-06-08 21:48:04 +00:00
|
|
|
void ED_gplayer_frame_select_set(bGPDlayer *gpl, short mode)
|
2009-01-14 16:13:50 +00:00
|
|
|
{
|
|
|
|
/* error checking */
|
2014-12-26 20:00:52 +01:00
|
|
|
if (gpl == NULL)
|
2009-01-14 16:13:50 +00:00
|
|
|
return;
|
2014-12-27 12:09:29 +13:00
|
|
|
|
2009-01-14 16:13:50 +00:00
|
|
|
/* now call the standard function */
|
2012-06-08 21:48:04 +00:00
|
|
|
ED_gpencil_select_frames(gpl, mode);
|
2009-01-14 16:13:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* select the frame in this layer that occurs on this frame (there should only be one at most) */
|
2012-06-08 21:48:04 +00:00
|
|
|
void ED_gpencil_select_frame(bGPDlayer *gpl, int selx, short select_mode)
|
2009-01-14 16:13:50 +00:00
|
|
|
{
|
|
|
|
bGPDframe *gpf;
|
2014-12-27 12:09:29 +13:00
|
|
|
|
2014-12-26 20:00:52 +01:00
|
|
|
if (gpl == NULL)
|
2011-01-10 22:10:28 +00:00
|
|
|
return;
|
2014-12-27 12:09:29 +13:00
|
|
|
|
2012-06-08 22:07:57 +00:00
|
|
|
gpf = BKE_gpencil_layer_find_frame(gpl, selx);
|
2014-12-27 12:09:29 +13:00
|
|
|
|
2012-06-08 22:07:57 +00:00
|
|
|
if (gpf) {
|
|
|
|
gpframe_select(gpf, select_mode);
|
2009-01-14 16:13:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* select the frames in this layer that occur within the bounds specified */
|
2012-06-08 21:48:04 +00:00
|
|
|
void ED_gplayer_frames_select_border(bGPDlayer *gpl, float min, float max, short select_mode)
|
2009-01-14 16:13:50 +00:00
|
|
|
{
|
|
|
|
bGPDframe *gpf;
|
2014-12-27 12:09:29 +13:00
|
|
|
|
2011-01-10 22:10:28 +00:00
|
|
|
if (gpl == NULL)
|
|
|
|
return;
|
2014-12-27 12:09:29 +13:00
|
|
|
|
2009-01-14 16:13:50 +00:00
|
|
|
/* only select those frames which are in bounds */
|
2012-05-08 18:29:02 +00:00
|
|
|
for (gpf = gpl->frames.first; gpf; gpf = gpf->next) {
|
2009-01-14 16:13:50 +00:00
|
|
|
if (IN_RANGE(gpf->framenum, min, max))
|
|
|
|
gpframe_select(gpf, select_mode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ***************************************** */
|
|
|
|
/* Frame Editing Tools */
|
|
|
|
|
|
|
|
/* Delete selected frames */
|
2013-11-25 04:55:26 +01:00
|
|
|
bool ED_gplayer_frames_delete(bGPDlayer *gpl)
|
2009-01-14 16:13:50 +00:00
|
|
|
{
|
|
|
|
bGPDframe *gpf, *gpfn;
|
2013-11-26 06:39:14 +11:00
|
|
|
bool changed = false;
|
2014-12-27 12:09:29 +13:00
|
|
|
|
2009-01-14 16:13:50 +00:00
|
|
|
/* error checking */
|
|
|
|
if (gpl == NULL)
|
2013-11-25 04:55:26 +01:00
|
|
|
return false;
|
2014-12-27 12:09:29 +13:00
|
|
|
|
2009-01-14 16:13:50 +00:00
|
|
|
/* check for frames to delete */
|
2012-05-08 18:29:02 +00:00
|
|
|
for (gpf = gpl->frames.first; gpf; gpf = gpfn) {
|
|
|
|
gpfn = gpf->next;
|
2014-12-27 12:09:29 +13:00
|
|
|
|
2009-01-14 16:13:50 +00:00
|
|
|
if (gpf->flag & GP_FRAME_SELECT)
|
2013-11-26 06:39:14 +11:00
|
|
|
changed |= gpencil_layer_delframe(gpl, gpf);
|
2009-01-14 16:13:50 +00:00
|
|
|
}
|
2014-12-27 12:09:29 +13:00
|
|
|
|
2013-11-26 06:39:14 +11:00
|
|
|
return changed;
|
2009-01-14 16:13:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Duplicate selected frames from given gp-layer */
|
2012-06-08 21:48:04 +00:00
|
|
|
void ED_gplayer_frames_duplicate(bGPDlayer *gpl)
|
2009-01-14 16:13:50 +00:00
|
|
|
{
|
|
|
|
bGPDframe *gpf, *gpfn;
|
2014-12-27 12:09:29 +13:00
|
|
|
|
2009-01-14 16:13:50 +00:00
|
|
|
/* error checking */
|
|
|
|
if (gpl == NULL)
|
|
|
|
return;
|
2014-12-27 12:09:29 +13:00
|
|
|
|
2009-01-14 16:13:50 +00:00
|
|
|
/* duplicate selected frames */
|
2012-05-08 18:29:02 +00:00
|
|
|
for (gpf = gpl->frames.first; gpf; gpf = gpfn) {
|
|
|
|
gpfn = gpf->next;
|
2014-12-27 12:09:29 +13:00
|
|
|
|
2009-01-14 16:13:50 +00:00
|
|
|
/* duplicate this frame */
|
|
|
|
if (gpf->flag & GP_FRAME_SELECT) {
|
2014-12-26 20:00:52 +01:00
|
|
|
bGPDframe *gpfd;
|
2014-12-27 12:09:29 +13:00
|
|
|
|
2009-01-14 16:13:50 +00:00
|
|
|
/* duplicate frame, and deselect self */
|
2012-05-08 18:29:02 +00:00
|
|
|
gpfd = gpencil_frame_duplicate(gpf);
|
2009-01-14 16:13:50 +00:00
|
|
|
gpf->flag &= ~GP_FRAME_SELECT;
|
2014-12-27 12:09:29 +13:00
|
|
|
|
2009-01-14 16:13:50 +00:00
|
|
|
BLI_insertlinkafter(&gpl->frames, gpf, gpfd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-26 20:00:52 +01:00
|
|
|
/* Set keyframe type for selected frames from given gp-layer
|
Grease Pencil - Storyboarding Features (merge from GPencil_EditStrokes branch)
This merge-commit brings in a number of new features and workflow/UI improvements for
working with Grease Pencil. While these were originally targetted at improving
the workflow for creating 3D storyboards in Blender using the Grease Pencil,
many of these changes should also prove useful in other workflows too.
The main highlights here are:
1) It is now possible to edit Grease Pencil strokes
- Use D Tab, or toggle the "Enable Editing" toggles in the Toolbar/Properties regions
to enter "Stroke Edit Mode". In this mode, many common editing tools will
operate on Grease Pencil stroke points instead.
- Tools implemented include Select, Select All/Border/Circle/Linked/More/Less,
Grab, Rotate, Scale, Bend, Shear, To Sphere, Mirror, Duplicate, Delete.
- Proportional Editing works when using the transform tools
2) Grease Pencil stroke settings can now be animated
NOTE: Currently drivers don't work, but if time allows, this may still be
added before the release.
3) Strokes can be drawn with "filled" interiors, using a separate set of
colour/opacity settings to the ones used for the lines themselves.
This makes use of OpenGL filled polys, which has the limitation of only
being able to fill convex shapes. Some artifacts may be visible on concave
shapes (e.g. pacman's mouth will be overdrawn)
4) "Volumetric Strokes" - An alternative drawing technique for stroke drawing
has been added which draws strokes as a series of screen-aligned discs.
While this was originally a partial experimental technique at getting better
quality 3D lines, the effects possible using this technique were interesting
enough to warrant making this a dedicated feature. Best results when partial
opacity and large stroke widths are used.
5) Improved Onion Skinning Support
- Different colours can be selected for the before/after ghosts. To do so,
enable the "colour wheel" toggle beside the Onion Skinning toggle, and set
the colours accordingly.
- Different numbers of ghosts can be shown before/after the current frame
6) Grease Pencil datablocks are now attached to the scene by default instead of
the active object.
- For a long time, the object-attachment has proved to be quite problematic
for users to keep track of. Now that this is done at scene level, it is
easier for most users to use.
- An exception for old files (and for any addons which may benefit from object
attachment instead), is that if the active object has a Grease Pencil datablock,
that will be used instead.
- It is not currently possible to choose object-attachment from the UI, but
it is simple to do this from the console instead, by doing:
context.active_object.grease_pencil = bpy.data.grease_pencil["blah"]
7) Various UI Cleanups
- The layers UI has been cleaned up to use a list instead of the nested-panels
design. Apart from saving space, this is also much nicer to look at now.
- The UI code is now all defined in Python. To support this, it has been necessary
to add some new context properties to make it easier to access these settings.
e.g. "gpencil_data" for the datablock
"active_gpencil_layer" and "active_gpencil_frame" for active data,
"editable_gpencil_strokes" for the strokes that can be edited
- The "stroke placement/alignment" settings (previously "Drawing Settings" at the
bottom of the Grease Pencil panel in the Properties Region) is now located in
the toolbar. These were more toolsettings than properties for how GPencil got drawn.
- "Use Sketching Sessions" has been renamed "Continuous Drawing", as per a
suggestion for an earlier discussion on developer.blender.org
- By default, the painting operator will wait for a mouse button to be pressed
before it starts creating the stroke. This is to make it easier to include
this operator in various toolbars/menus/etc. To get it immediately starting
(as when you hold down DKEy to draw), set "wait_for_input" to False.
- GPencil Layers can be rearranged in the "Grease Pencil" mode of the Action Editor
- Toolbar panels have been added to all the other editors which support these.
8) Pie menus for quick-access to tools
A set of experimental pie menus has been included for quick access to many
tools and settings. It is not necessary to use these to get things done,
but they have been designed to help make certain common tasks easier.
- Ctrl-D = The main pie menu. Reveals tools in a context sensitive and
spatially stable manner.
- D Q = "Quick Settings" pie. This allows quick access to the active
layer's settings. Notably, colours, thickness, and turning
onion skinning on/off.
2014-12-01 01:52:06 +13:00
|
|
|
* \param type The type of keyframe (eBezTriple_KeyframeType) to set selected frames to
|
|
|
|
*/
|
|
|
|
void ED_gplayer_frames_keytype_set(bGPDlayer *gpl, short type)
|
|
|
|
{
|
|
|
|
bGPDframe *gpf;
|
2014-12-27 12:09:29 +13:00
|
|
|
|
Grease Pencil - Storyboarding Features (merge from GPencil_EditStrokes branch)
This merge-commit brings in a number of new features and workflow/UI improvements for
working with Grease Pencil. While these were originally targetted at improving
the workflow for creating 3D storyboards in Blender using the Grease Pencil,
many of these changes should also prove useful in other workflows too.
The main highlights here are:
1) It is now possible to edit Grease Pencil strokes
- Use D Tab, or toggle the "Enable Editing" toggles in the Toolbar/Properties regions
to enter "Stroke Edit Mode". In this mode, many common editing tools will
operate on Grease Pencil stroke points instead.
- Tools implemented include Select, Select All/Border/Circle/Linked/More/Less,
Grab, Rotate, Scale, Bend, Shear, To Sphere, Mirror, Duplicate, Delete.
- Proportional Editing works when using the transform tools
2) Grease Pencil stroke settings can now be animated
NOTE: Currently drivers don't work, but if time allows, this may still be
added before the release.
3) Strokes can be drawn with "filled" interiors, using a separate set of
colour/opacity settings to the ones used for the lines themselves.
This makes use of OpenGL filled polys, which has the limitation of only
being able to fill convex shapes. Some artifacts may be visible on concave
shapes (e.g. pacman's mouth will be overdrawn)
4) "Volumetric Strokes" - An alternative drawing technique for stroke drawing
has been added which draws strokes as a series of screen-aligned discs.
While this was originally a partial experimental technique at getting better
quality 3D lines, the effects possible using this technique were interesting
enough to warrant making this a dedicated feature. Best results when partial
opacity and large stroke widths are used.
5) Improved Onion Skinning Support
- Different colours can be selected for the before/after ghosts. To do so,
enable the "colour wheel" toggle beside the Onion Skinning toggle, and set
the colours accordingly.
- Different numbers of ghosts can be shown before/after the current frame
6) Grease Pencil datablocks are now attached to the scene by default instead of
the active object.
- For a long time, the object-attachment has proved to be quite problematic
for users to keep track of. Now that this is done at scene level, it is
easier for most users to use.
- An exception for old files (and for any addons which may benefit from object
attachment instead), is that if the active object has a Grease Pencil datablock,
that will be used instead.
- It is not currently possible to choose object-attachment from the UI, but
it is simple to do this from the console instead, by doing:
context.active_object.grease_pencil = bpy.data.grease_pencil["blah"]
7) Various UI Cleanups
- The layers UI has been cleaned up to use a list instead of the nested-panels
design. Apart from saving space, this is also much nicer to look at now.
- The UI code is now all defined in Python. To support this, it has been necessary
to add some new context properties to make it easier to access these settings.
e.g. "gpencil_data" for the datablock
"active_gpencil_layer" and "active_gpencil_frame" for active data,
"editable_gpencil_strokes" for the strokes that can be edited
- The "stroke placement/alignment" settings (previously "Drawing Settings" at the
bottom of the Grease Pencil panel in the Properties Region) is now located in
the toolbar. These were more toolsettings than properties for how GPencil got drawn.
- "Use Sketching Sessions" has been renamed "Continuous Drawing", as per a
suggestion for an earlier discussion on developer.blender.org
- By default, the painting operator will wait for a mouse button to be pressed
before it starts creating the stroke. This is to make it easier to include
this operator in various toolbars/menus/etc. To get it immediately starting
(as when you hold down DKEy to draw), set "wait_for_input" to False.
- GPencil Layers can be rearranged in the "Grease Pencil" mode of the Action Editor
- Toolbar panels have been added to all the other editors which support these.
8) Pie menus for quick-access to tools
A set of experimental pie menus has been included for quick access to many
tools and settings. It is not necessary to use these to get things done,
but they have been designed to help make certain common tasks easier.
- Ctrl-D = The main pie menu. Reveals tools in a context sensitive and
spatially stable manner.
- D Q = "Quick Settings" pie. This allows quick access to the active
layer's settings. Notably, colours, thickness, and turning
onion skinning on/off.
2014-12-01 01:52:06 +13:00
|
|
|
if (gpl == NULL)
|
|
|
|
return;
|
2014-12-27 12:09:29 +13:00
|
|
|
|
Grease Pencil - Storyboarding Features (merge from GPencil_EditStrokes branch)
This merge-commit brings in a number of new features and workflow/UI improvements for
working with Grease Pencil. While these were originally targetted at improving
the workflow for creating 3D storyboards in Blender using the Grease Pencil,
many of these changes should also prove useful in other workflows too.
The main highlights here are:
1) It is now possible to edit Grease Pencil strokes
- Use D Tab, or toggle the "Enable Editing" toggles in the Toolbar/Properties regions
to enter "Stroke Edit Mode". In this mode, many common editing tools will
operate on Grease Pencil stroke points instead.
- Tools implemented include Select, Select All/Border/Circle/Linked/More/Less,
Grab, Rotate, Scale, Bend, Shear, To Sphere, Mirror, Duplicate, Delete.
- Proportional Editing works when using the transform tools
2) Grease Pencil stroke settings can now be animated
NOTE: Currently drivers don't work, but if time allows, this may still be
added before the release.
3) Strokes can be drawn with "filled" interiors, using a separate set of
colour/opacity settings to the ones used for the lines themselves.
This makes use of OpenGL filled polys, which has the limitation of only
being able to fill convex shapes. Some artifacts may be visible on concave
shapes (e.g. pacman's mouth will be overdrawn)
4) "Volumetric Strokes" - An alternative drawing technique for stroke drawing
has been added which draws strokes as a series of screen-aligned discs.
While this was originally a partial experimental technique at getting better
quality 3D lines, the effects possible using this technique were interesting
enough to warrant making this a dedicated feature. Best results when partial
opacity and large stroke widths are used.
5) Improved Onion Skinning Support
- Different colours can be selected for the before/after ghosts. To do so,
enable the "colour wheel" toggle beside the Onion Skinning toggle, and set
the colours accordingly.
- Different numbers of ghosts can be shown before/after the current frame
6) Grease Pencil datablocks are now attached to the scene by default instead of
the active object.
- For a long time, the object-attachment has proved to be quite problematic
for users to keep track of. Now that this is done at scene level, it is
easier for most users to use.
- An exception for old files (and for any addons which may benefit from object
attachment instead), is that if the active object has a Grease Pencil datablock,
that will be used instead.
- It is not currently possible to choose object-attachment from the UI, but
it is simple to do this from the console instead, by doing:
context.active_object.grease_pencil = bpy.data.grease_pencil["blah"]
7) Various UI Cleanups
- The layers UI has been cleaned up to use a list instead of the nested-panels
design. Apart from saving space, this is also much nicer to look at now.
- The UI code is now all defined in Python. To support this, it has been necessary
to add some new context properties to make it easier to access these settings.
e.g. "gpencil_data" for the datablock
"active_gpencil_layer" and "active_gpencil_frame" for active data,
"editable_gpencil_strokes" for the strokes that can be edited
- The "stroke placement/alignment" settings (previously "Drawing Settings" at the
bottom of the Grease Pencil panel in the Properties Region) is now located in
the toolbar. These were more toolsettings than properties for how GPencil got drawn.
- "Use Sketching Sessions" has been renamed "Continuous Drawing", as per a
suggestion for an earlier discussion on developer.blender.org
- By default, the painting operator will wait for a mouse button to be pressed
before it starts creating the stroke. This is to make it easier to include
this operator in various toolbars/menus/etc. To get it immediately starting
(as when you hold down DKEy to draw), set "wait_for_input" to False.
- GPencil Layers can be rearranged in the "Grease Pencil" mode of the Action Editor
- Toolbar panels have been added to all the other editors which support these.
8) Pie menus for quick-access to tools
A set of experimental pie menus has been included for quick access to many
tools and settings. It is not necessary to use these to get things done,
but they have been designed to help make certain common tasks easier.
- Ctrl-D = The main pie menu. Reveals tools in a context sensitive and
spatially stable manner.
- D Q = "Quick Settings" pie. This allows quick access to the active
layer's settings. Notably, colours, thickness, and turning
onion skinning on/off.
2014-12-01 01:52:06 +13:00
|
|
|
for (gpf = gpl->frames.first; gpf; gpf = gpf->next) {
|
|
|
|
if (gpf->flag & GP_FRAME_SELECT) {
|
|
|
|
gpf->key_type = type;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-10 22:10:28 +00:00
|
|
|
#if 0 // XXX disabled until grease pencil code stabilises again
|
2009-01-14 16:13:50 +00:00
|
|
|
/* -------------------------------------- */
|
|
|
|
/* Copy and Paste Tools */
|
|
|
|
/* - The copy/paste buffer currently stores a set of GP_Layers, with temporary
|
|
|
|
* GP_Frames with the necessary strokes
|
2011-10-15 14:14:22 +00:00
|
|
|
* - Unless there is only one element in the buffer, names are also tested to check for compatibility.
|
2009-01-14 16:13:50 +00:00
|
|
|
* - All pasted frames are offset by the same amount. This is calculated as the difference in the times of
|
|
|
|
* the current frame and the 'first keyframe' (i.e. the earliest one in all channels).
|
|
|
|
* - The earliest frame is calculated per copy operation.
|
|
|
|
*/
|
2014-12-26 20:00:52 +01:00
|
|
|
|
2009-01-14 16:13:50 +00:00
|
|
|
/* globals for copy/paste data (like for other copy/paste buffers) */
|
|
|
|
ListBase gpcopybuf = {NULL, NULL};
|
2012-05-08 18:29:02 +00:00
|
|
|
static int gpcopy_firstframe = 999999999;
|
2009-01-14 16:13:50 +00:00
|
|
|
|
|
|
|
/* This function frees any MEM_calloc'ed copy/paste buffer data */
|
2012-04-29 17:11:40 +00:00
|
|
|
void free_gpcopybuf()
|
2009-01-14 16:13:50 +00:00
|
|
|
{
|
2014-12-26 20:00:52 +01:00
|
|
|
free_gpencil_layers(&gpcopybuf);
|
2014-12-27 12:09:29 +13:00
|
|
|
|
2014-02-08 06:07:10 +11:00
|
|
|
BLI_listbase_clear(&gpcopybuf);
|
2012-05-08 18:29:02 +00:00
|
|
|
gpcopy_firstframe = 999999999;
|
2009-01-14 16:13:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* This function adds data to the copy/paste buffer, freeing existing data first
|
|
|
|
* Only the selected GP-layers get their selected keyframes copied.
|
|
|
|
*/
|
2012-04-29 17:11:40 +00:00
|
|
|
void copy_gpdata()
|
2009-01-14 16:13:50 +00:00
|
|
|
{
|
|
|
|
ListBase act_data = {NULL, NULL};
|
|
|
|
bActListElem *ale;
|
|
|
|
int filter;
|
|
|
|
void *data;
|
|
|
|
short datatype;
|
2014-12-27 12:09:29 +13:00
|
|
|
|
2009-01-14 16:13:50 +00:00
|
|
|
/* clear buffer first */
|
|
|
|
free_gpcopybuf();
|
2014-12-27 12:09:29 +13:00
|
|
|
|
2009-01-14 16:13:50 +00:00
|
|
|
/* get data */
|
2012-05-08 18:29:02 +00:00
|
|
|
data = get_action_context(&datatype);
|
2009-01-14 16:13:50 +00:00
|
|
|
if (data == NULL) return;
|
|
|
|
if (datatype != ACTCONT_GPENCIL) return;
|
2014-12-27 12:09:29 +13:00
|
|
|
|
2009-01-14 16:13:50 +00:00
|
|
|
/* filter data */
|
2012-05-08 18:29:02 +00:00
|
|
|
filter = (ACTFILTER_VISIBLE | ACTFILTER_SEL);
|
2009-01-14 16:13:50 +00:00
|
|
|
actdata_filter(&act_data, filter, data, datatype);
|
2014-12-27 12:09:29 +13:00
|
|
|
|
2009-01-14 16:13:50 +00:00
|
|
|
/* assume that each of these is an ipo-block */
|
2012-05-08 18:29:02 +00:00
|
|
|
for (ale = act_data.first; ale; ale = ale->next) {
|
2009-01-14 16:13:50 +00:00
|
|
|
bGPDlayer *gpls, *gpln;
|
|
|
|
bGPDframe *gpf, *gpfn;
|
2014-12-27 12:09:29 +13:00
|
|
|
|
2009-01-14 16:13:50 +00:00
|
|
|
/* get new layer to put into buffer */
|
2012-05-08 18:29:02 +00:00
|
|
|
gpls = (bGPDlayer *)ale->data;
|
|
|
|
gpln = MEM_callocN(sizeof(bGPDlayer), "GPCopyPasteLayer");
|
2014-12-27 12:09:29 +13:00
|
|
|
|
2014-02-08 06:07:10 +11:00
|
|
|
BLI_listbase_clear(&gpln->frames);
|
2011-10-19 23:10:54 +00:00
|
|
|
BLI_strncpy(gpln->info, gpls->info, sizeof(gpln->info));
|
2014-12-27 12:09:29 +13:00
|
|
|
|
2009-01-14 16:13:50 +00:00
|
|
|
BLI_addtail(&gpcopybuf, gpln);
|
2014-12-27 12:09:29 +13:00
|
|
|
|
2009-01-14 16:13:50 +00:00
|
|
|
/* loop over frames, and copy only selected frames */
|
2012-05-08 18:29:02 +00:00
|
|
|
for (gpf = gpls->frames.first; gpf; gpf = gpf->next) {
|
2009-01-14 16:13:50 +00:00
|
|
|
/* if frame is selected, make duplicate it and its strokes */
|
|
|
|
if (gpf->flag & GP_FRAME_SELECT) {
|
|
|
|
/* add frame to buffer */
|
2012-05-08 18:29:02 +00:00
|
|
|
gpfn = gpencil_frame_duplicate(gpf);
|
2009-01-14 16:13:50 +00:00
|
|
|
BLI_addtail(&gpln->frames, gpfn);
|
2014-12-27 12:09:29 +13:00
|
|
|
|
2009-01-14 16:13:50 +00:00
|
|
|
/* check if this is the earliest frame encountered so far */
|
|
|
|
if (gpf->framenum < gpcopy_firstframe)
|
2012-05-08 18:29:02 +00:00
|
|
|
gpcopy_firstframe = gpf->framenum;
|
2009-01-14 16:13:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-12-27 12:09:29 +13:00
|
|
|
|
2009-01-14 16:13:50 +00:00
|
|
|
/* check if anything ended up in the buffer */
|
|
|
|
if (ELEM(NULL, gpcopybuf.first, gpcopybuf.last))
|
|
|
|
error("Nothing copied to buffer");
|
2014-12-27 12:09:29 +13:00
|
|
|
|
2009-01-14 16:13:50 +00:00
|
|
|
/* free temp memory */
|
|
|
|
BLI_freelistN(&act_data);
|
|
|
|
}
|
|
|
|
|
2012-04-29 17:11:40 +00:00
|
|
|
void paste_gpdata(Scene *scene)
|
2009-01-14 16:13:50 +00:00
|
|
|
{
|
|
|
|
ListBase act_data = {NULL, NULL};
|
|
|
|
bActListElem *ale;
|
|
|
|
int filter;
|
|
|
|
void *data;
|
|
|
|
short datatype;
|
2014-12-27 12:09:29 +13:00
|
|
|
|
2009-01-14 16:13:50 +00:00
|
|
|
const int offset = (CFRA - gpcopy_firstframe);
|
2012-05-08 18:29:02 +00:00
|
|
|
short no_name = 0;
|
2014-12-27 12:09:29 +13:00
|
|
|
|
2009-01-14 16:13:50 +00:00
|
|
|
/* check if buffer is empty */
|
|
|
|
if (ELEM(NULL, gpcopybuf.first, gpcopybuf.last)) {
|
|
|
|
error("No data in buffer to paste");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* check if single channel in buffer (disregard names if so) */
|
|
|
|
if (gpcopybuf.first == gpcopybuf.last)
|
2012-05-08 18:29:02 +00:00
|
|
|
no_name = 1;
|
2014-12-27 12:09:29 +13:00
|
|
|
|
2009-01-14 16:13:50 +00:00
|
|
|
/* get data */
|
2012-05-08 18:29:02 +00:00
|
|
|
data = get_action_context(&datatype);
|
2009-01-14 16:13:50 +00:00
|
|
|
if (data == NULL) return;
|
|
|
|
if (datatype != ACTCONT_GPENCIL) return;
|
2014-12-27 12:09:29 +13:00
|
|
|
|
2009-01-14 16:13:50 +00:00
|
|
|
/* filter data */
|
2012-05-08 18:29:02 +00:00
|
|
|
filter = (ACTFILTER_VISIBLE | ACTFILTER_SEL | ACTFILTER_FOREDIT);
|
2009-01-14 16:13:50 +00:00
|
|
|
actdata_filter(&act_data, filter, data, datatype);
|
2014-12-27 12:09:29 +13:00
|
|
|
|
2009-01-14 16:13:50 +00:00
|
|
|
/* from selected channels */
|
2012-05-08 18:29:02 +00:00
|
|
|
for (ale = act_data.first; ale; ale = ale->next) {
|
|
|
|
bGPDlayer *gpld = (bGPDlayer *)ale->data;
|
|
|
|
bGPDlayer *gpls = NULL;
|
2009-01-14 16:13:50 +00:00
|
|
|
bGPDframe *gpfs, *gpf;
|
2014-12-27 12:09:29 +13:00
|
|
|
|
2009-01-14 16:13:50 +00:00
|
|
|
/* find suitable layer from buffer to use to paste from */
|
2012-05-08 18:29:02 +00:00
|
|
|
for (gpls = gpcopybuf.first; gpls; gpls = gpls->next) {
|
2009-01-14 16:13:50 +00:00
|
|
|
/* check if layer name matches */
|
2015-01-26 16:03:11 +01:00
|
|
|
if ((no_name) || STREQ(gpls->info, gpld->info))
|
2009-01-14 16:13:50 +00:00
|
|
|
break;
|
|
|
|
}
|
2014-12-27 12:09:29 +13:00
|
|
|
|
2009-01-14 16:13:50 +00:00
|
|
|
/* this situation might occur! */
|
|
|
|
if (gpls == NULL)
|
|
|
|
continue;
|
2014-12-27 12:09:29 +13:00
|
|
|
|
2009-01-14 16:13:50 +00:00
|
|
|
/* add frames from buffer */
|
2012-05-08 18:29:02 +00:00
|
|
|
for (gpfs = gpls->frames.first; gpfs; gpfs = gpfs->next) {
|
2009-01-14 16:13:50 +00:00
|
|
|
/* temporarily apply offset to buffer-frame while copying */
|
|
|
|
gpfs->framenum += offset;
|
2014-12-27 12:09:29 +13:00
|
|
|
|
2009-01-14 16:13:50 +00:00
|
|
|
/* get frame to copy data into (if no frame returned, then just ignore) */
|
2012-05-08 18:29:02 +00:00
|
|
|
gpf = gpencil_layer_getframe(gpld, gpfs->framenum, 1);
|
2009-01-14 16:13:50 +00:00
|
|
|
if (gpf) {
|
|
|
|
bGPDstroke *gps, *gpsn;
|
|
|
|
ScrArea *sa;
|
2014-12-27 12:09:29 +13:00
|
|
|
|
2009-01-14 16:13:50 +00:00
|
|
|
/* get area that gp-data comes from */
|
2012-10-26 04:14:10 +00:00
|
|
|
//sa = gpencil_data_findowner((bGPdata *)ale->owner);
|
2009-05-05 23:25:12 +00:00
|
|
|
sa = NULL;
|
2014-12-27 12:09:29 +13:00
|
|
|
|
2014-12-26 20:00:52 +01:00
|
|
|
/* this should be the right frame... as it may be a pre-existing frame,
|
|
|
|
* must make sure that only compatible stroke types get copied over
|
2009-01-14 16:13:50 +00:00
|
|
|
* - we cannot just add a duplicate frame, as that would cause errors
|
2012-07-04 15:04:38 +00:00
|
|
|
* - need to check for compatible types to minimize memory usage (copying 'junk' over)
|
2009-01-14 16:13:50 +00:00
|
|
|
*/
|
2012-05-08 18:29:02 +00:00
|
|
|
for (gps = gpfs->strokes.first; gps; gps = gps->next) {
|
2009-01-14 16:13:50 +00:00
|
|
|
short stroke_ok;
|
2014-12-27 12:09:29 +13:00
|
|
|
|
2009-01-14 16:13:50 +00:00
|
|
|
/* if there's an area, check that it supports this type of stroke */
|
|
|
|
if (sa) {
|
2012-05-08 18:29:02 +00:00
|
|
|
stroke_ok = 0;
|
2014-12-27 12:09:29 +13:00
|
|
|
|
2009-01-14 16:13:50 +00:00
|
|
|
/* check if spacetype supports this type of stroke
|
|
|
|
* - NOTE: must sync this with gp_paint_initstroke() in gpencil.c
|
|
|
|
*/
|
|
|
|
switch (sa->spacetype) {
|
|
|
|
case SPACE_VIEW3D: /* 3D-View: either screen-aligned or 3d-space */
|
|
|
|
if ((gps->flag == 0) || (gps->flag & GP_STROKE_3DSPACE))
|
2012-05-08 18:29:02 +00:00
|
|
|
stroke_ok = 1;
|
2009-01-14 16:13:50 +00:00
|
|
|
break;
|
2014-12-27 12:09:29 +13:00
|
|
|
|
2009-01-14 16:13:50 +00:00
|
|
|
case SPACE_NODE: /* Nodes Editor: either screen-aligned or view-aligned */
|
|
|
|
case SPACE_IMAGE: /* Image Editor: either screen-aligned or view\image-aligned */
|
2011-11-07 12:55:18 +00:00
|
|
|
case SPACE_CLIP: /* Image Editor: either screen-aligned or view\image-aligned */
|
2009-01-14 16:13:50 +00:00
|
|
|
if ((gps->flag == 0) || (gps->flag & GP_STROKE_2DSPACE))
|
2012-05-08 18:29:02 +00:00
|
|
|
stroke_ok = 1;
|
2009-01-14 16:13:50 +00:00
|
|
|
break;
|
2014-12-27 12:09:29 +13:00
|
|
|
|
2009-01-14 16:13:50 +00:00
|
|
|
case SPACE_SEQ: /* Sequence Editor: either screen-aligned or view-aligned */
|
|
|
|
if ((gps->flag == 0) || (gps->flag & GP_STROKE_2DIMAGE))
|
2012-05-08 18:29:02 +00:00
|
|
|
stroke_ok = 1;
|
2009-01-14 16:13:50 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2012-05-08 18:29:02 +00:00
|
|
|
stroke_ok = 1;
|
2014-12-27 12:09:29 +13:00
|
|
|
|
2009-01-14 16:13:50 +00:00
|
|
|
/* if stroke is ok, we make a copy of this stroke and add to frame */
|
|
|
|
if (stroke_ok) {
|
|
|
|
/* make a copy of stroke, then of its points array */
|
2012-05-08 18:29:02 +00:00
|
|
|
gpsn = MEM_dupallocN(gps);
|
|
|
|
gpsn->points = MEM_dupallocN(gps->points);
|
2014-12-27 12:09:29 +13:00
|
|
|
|
2009-01-14 16:13:50 +00:00
|
|
|
/* append stroke to frame */
|
|
|
|
BLI_addtail(&gpf->strokes, gpsn);
|
|
|
|
}
|
|
|
|
}
|
2014-12-27 12:09:29 +13:00
|
|
|
|
2009-01-14 16:13:50 +00:00
|
|
|
/* if no strokes (i.e. new frame) added, free gpf */
|
2014-02-08 06:07:10 +11:00
|
|
|
if (BLI_listbase_is_empty(&gpf->strokes))
|
2009-01-14 16:13:50 +00:00
|
|
|
gpencil_layer_delframe(gpld, gpf);
|
|
|
|
}
|
2014-12-27 12:09:29 +13:00
|
|
|
|
2009-01-14 16:13:50 +00:00
|
|
|
/* unapply offset from buffer-frame */
|
|
|
|
gpfs->framenum -= offset;
|
|
|
|
}
|
|
|
|
}
|
2014-12-27 12:09:29 +13:00
|
|
|
|
2009-01-14 16:13:50 +00:00
|
|
|
/* free temp memory */
|
|
|
|
BLI_freelistN(&act_data);
|
2014-12-27 12:09:29 +13:00
|
|
|
|
2009-01-14 16:13:50 +00:00
|
|
|
/* undo and redraw stuff */
|
|
|
|
BIF_undo_push("Paste Grease Pencil Frames");
|
|
|
|
}
|
2012-12-03 13:07:43 +00:00
|
|
|
#endif /* XXX disabled until Grease Pencil code stabilises again... */
|
2009-01-14 16:13:50 +00:00
|
|
|
|
|
|
|
/* -------------------------------------- */
|
|
|
|
/* Snap Tools */
|
|
|
|
|
2014-01-15 15:45:55 +11:00
|
|
|
static short snap_gpf_nearest(bGPDframe *UNUSED(gpf), Scene *UNUSED(scene))
|
2009-01-14 16:13:50 +00:00
|
|
|
{
|
2014-01-15 15:45:55 +11:00
|
|
|
#if 0 /* note: gpf->framenum is already an int! */
|
2009-01-14 16:13:50 +00:00
|
|
|
if (gpf->flag & GP_FRAME_SELECT)
|
2012-05-08 18:29:02 +00:00
|
|
|
gpf->framenum = (int)(floor(gpf->framenum + 0.5));
|
2014-01-15 14:54:00 +13:00
|
|
|
#endif
|
2009-01-14 16:13:50 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-05-08 18:29:02 +00:00
|
|
|
static short snap_gpf_nearestsec(bGPDframe *gpf, Scene *scene)
|
2009-01-14 16:13:50 +00:00
|
|
|
{
|
|
|
|
float secf = (float)FPS;
|
|
|
|
if (gpf->flag & GP_FRAME_SELECT)
|
2012-12-03 13:58:08 +00:00
|
|
|
gpf->framenum = (int)(floorf(gpf->framenum / secf + 0.5f) * secf);
|
2009-01-14 16:13:50 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-05-08 18:29:02 +00:00
|
|
|
static short snap_gpf_cframe(bGPDframe *gpf, Scene *scene)
|
2009-01-14 16:13:50 +00:00
|
|
|
{
|
|
|
|
if (gpf->flag & GP_FRAME_SELECT)
|
2012-05-08 18:29:02 +00:00
|
|
|
gpf->framenum = (int)CFRA;
|
2009-01-14 16:13:50 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-05-08 18:29:02 +00:00
|
|
|
static short snap_gpf_nearmarker(bGPDframe *gpf, Scene *scene)
|
2009-01-14 16:13:50 +00:00
|
|
|
{
|
|
|
|
if (gpf->flag & GP_FRAME_SELECT)
|
2012-12-03 13:07:43 +00:00
|
|
|
gpf->framenum = (int)ED_markers_find_nearest_marker_time(&scene->markers, (float)gpf->framenum);
|
2009-01-14 16:13:50 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* snap selected frames to ... */
|
2012-12-03 13:07:43 +00:00
|
|
|
void ED_gplayer_snap_frames(bGPDlayer *gpl, Scene *scene, short mode)
|
2009-01-14 16:13:50 +00:00
|
|
|
{
|
|
|
|
switch (mode) {
|
2012-12-03 13:07:43 +00:00
|
|
|
case SNAP_KEYS_NEARFRAME: /* snap to nearest frame */
|
2012-06-08 21:48:04 +00:00
|
|
|
ED_gplayer_frames_looper(gpl, scene, snap_gpf_nearest);
|
2009-01-14 16:13:50 +00:00
|
|
|
break;
|
2012-12-03 13:07:43 +00:00
|
|
|
case SNAP_KEYS_CURFRAME: /* snap to current frame */
|
2012-06-08 21:48:04 +00:00
|
|
|
ED_gplayer_frames_looper(gpl, scene, snap_gpf_cframe);
|
2009-01-14 16:13:50 +00:00
|
|
|
break;
|
2012-12-03 13:07:43 +00:00
|
|
|
case SNAP_KEYS_NEARMARKER: /* snap to nearest marker */
|
2012-06-08 21:48:04 +00:00
|
|
|
ED_gplayer_frames_looper(gpl, scene, snap_gpf_nearmarker);
|
2009-01-14 16:13:50 +00:00
|
|
|
break;
|
2012-12-03 13:07:43 +00:00
|
|
|
case SNAP_KEYS_NEARSEC: /* snap to nearest second */
|
2012-06-08 21:48:04 +00:00
|
|
|
ED_gplayer_frames_looper(gpl, scene, snap_gpf_nearestsec);
|
2009-01-14 16:13:50 +00:00
|
|
|
break;
|
|
|
|
default: /* just in case */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-03 13:07:43 +00:00
|
|
|
#if 0 /* XXX disabled until grease pencil code stabilises again */
|
2009-01-14 16:13:50 +00:00
|
|
|
/* -------------------------------------- */
|
|
|
|
/* Mirror Tools */
|
|
|
|
|
2012-05-08 18:29:02 +00:00
|
|
|
static short mirror_gpf_cframe(bGPDframe *gpf, Scene *scene)
|
2009-01-14 16:13:50 +00:00
|
|
|
{
|
|
|
|
int diff;
|
2014-12-27 12:09:29 +13:00
|
|
|
|
2009-01-14 16:13:50 +00:00
|
|
|
if (gpf->flag & GP_FRAME_SELECT) {
|
2012-05-08 18:29:02 +00:00
|
|
|
diff = CFRA - gpf->framenum;
|
|
|
|
gpf->framenum = CFRA;
|
2009-01-14 16:13:50 +00:00
|
|
|
}
|
2014-12-27 12:09:29 +13:00
|
|
|
|
2009-01-14 16:13:50 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-05-08 18:29:02 +00:00
|
|
|
static short mirror_gpf_yaxis(bGPDframe *gpf, Scene *scene)
|
2009-01-14 16:13:50 +00:00
|
|
|
{
|
|
|
|
int diff;
|
2014-12-27 12:09:29 +13:00
|
|
|
|
2009-01-14 16:13:50 +00:00
|
|
|
if (gpf->flag & GP_FRAME_SELECT) {
|
2012-05-08 18:29:02 +00:00
|
|
|
diff = -gpf->framenum;
|
|
|
|
gpf->framenum = diff;
|
2009-01-14 16:13:50 +00:00
|
|
|
}
|
2014-12-27 12:09:29 +13:00
|
|
|
|
2009-01-14 16:13:50 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-05-08 18:29:02 +00:00
|
|
|
static short mirror_gpf_xaxis(bGPDframe *gpf, Scene *scene)
|
2009-01-14 16:13:50 +00:00
|
|
|
{
|
|
|
|
int diff;
|
2014-12-27 12:09:29 +13:00
|
|
|
|
2009-01-14 16:13:50 +00:00
|
|
|
if (gpf->flag & GP_FRAME_SELECT) {
|
2012-05-08 18:29:02 +00:00
|
|
|
diff = -gpf->framenum;
|
|
|
|
gpf->framenum = diff;
|
2009-01-14 16:13:50 +00:00
|
|
|
}
|
2014-12-27 12:09:29 +13:00
|
|
|
|
2009-01-14 16:13:50 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-05-08 18:29:02 +00:00
|
|
|
static short mirror_gpf_marker(bGPDframe *gpf, Scene *scene)
|
2009-01-14 16:13:50 +00:00
|
|
|
{
|
|
|
|
static TimeMarker *marker;
|
2012-03-18 07:38:51 +00:00
|
|
|
static short initialized = 0;
|
2009-01-14 16:13:50 +00:00
|
|
|
int diff;
|
2014-12-27 12:09:29 +13:00
|
|
|
|
2009-01-14 16:13:50 +00:00
|
|
|
/* In order for this mirror function to work without
|
|
|
|
* any extra arguments being added, we use the case
|
2014-12-26 20:00:52 +01:00
|
|
|
* of bezt==NULL to denote that we should find the
|
2009-01-14 16:13:50 +00:00
|
|
|
* marker to mirror over. The static pointer is safe
|
2014-12-26 20:00:52 +01:00
|
|
|
* to use this way, as it will be set to null after
|
2009-01-14 16:13:50 +00:00
|
|
|
* each cycle in which this is called.
|
|
|
|
*/
|
2014-12-27 12:09:29 +13:00
|
|
|
|
2009-01-14 16:13:50 +00:00
|
|
|
if (gpf) {
|
|
|
|
/* mirroring time */
|
|
|
|
if ((gpf->flag & GP_FRAME_SELECT) && (marker)) {
|
2012-05-08 18:29:02 +00:00
|
|
|
diff = (marker->frame - gpf->framenum);
|
|
|
|
gpf->framenum = (marker->frame + diff);
|
2009-01-14 16:13:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2012-03-01 12:20:18 +00:00
|
|
|
/* initialization time */
|
2012-03-18 07:38:51 +00:00
|
|
|
if (initialized) {
|
2009-01-14 16:13:50 +00:00
|
|
|
/* reset everything for safety */
|
|
|
|
marker = NULL;
|
2012-03-18 07:38:51 +00:00
|
|
|
initialized = 0;
|
2009-01-14 16:13:50 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* try to find a marker */
|
2012-05-08 18:29:02 +00:00
|
|
|
marker = ED_markers_get_first_selected(&scene->markers);
|
2012-03-24 06:38:07 +00:00
|
|
|
if (marker) {
|
2012-05-08 18:29:02 +00:00
|
|
|
initialized = 1;
|
2009-01-14 16:13:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-12-27 12:09:29 +13:00
|
|
|
|
2009-01-14 16:13:50 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* mirror selected gp-frames on... */
|
2012-04-29 17:11:40 +00:00
|
|
|
void mirror_gplayer_frames(bGPDlayer *gpl, Scene *scene, short mode)
|
2009-01-14 16:13:50 +00:00
|
|
|
{
|
|
|
|
switch (mode) {
|
|
|
|
case 1: /* mirror over current frame */
|
2012-06-08 21:48:04 +00:00
|
|
|
ED_gplayer_frames_looper(gpl, scene, mirror_gpf_cframe);
|
2009-01-14 16:13:50 +00:00
|
|
|
break;
|
|
|
|
case 2: /* mirror over frame 0 */
|
2012-06-08 21:48:04 +00:00
|
|
|
ED_gplayer_frames_looper(gpl, scene, mirror_gpf_yaxis);
|
2009-01-14 16:13:50 +00:00
|
|
|
break;
|
|
|
|
case 3: /* mirror over value 0 */
|
2012-06-08 21:48:04 +00:00
|
|
|
ED_gplayer_frames_looper(gpl, scene, mirror_gpf_xaxis);
|
2009-01-14 16:13:50 +00:00
|
|
|
break;
|
|
|
|
case 4: /* mirror over marker */
|
|
|
|
mirror_gpf_marker(NULL, NULL);
|
2012-06-08 21:48:04 +00:00
|
|
|
ED_gplayer_frames_looper(gpl, scene, mirror_gpf_marker);
|
2009-01-14 16:13:50 +00:00
|
|
|
mirror_gpf_marker(NULL, NULL);
|
|
|
|
break;
|
|
|
|
default: /* just in case */
|
2012-06-08 21:48:04 +00:00
|
|
|
ED_gplayer_frames_looper(gpl, scene, mirror_gpf_yaxis);
|
2009-01-14 16:13:50 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ***************************************** */
|
2009-05-05 23:25:12 +00:00
|
|
|
#endif // XXX disabled until Grease Pencil code stabilises again...
|