2011-11-07 12:55:18 +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
|
2012-03-25 23:19:21 +00:00
|
|
|
* of the License, or (at your option) any later version.
|
2011-11-07 12:55:18 +00:00
|
|
|
*
|
|
|
|
|
* 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,
|
|
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
*
|
|
|
|
|
* The Original Code is Copyright (C) 2011 Blender Foundation.
|
|
|
|
|
* All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* Contributor(s): Blender Foundation,
|
|
|
|
|
* Sergey Sharybin
|
|
|
|
|
*
|
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/** \file blender/editors/space_clip/clip_ops.c
|
|
|
|
|
* \ingroup spclip
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
|
|
|
|
#include "DNA_userdef_types.h"
|
|
|
|
|
#include "DNA_scene_types.h" /* min/max frames */
|
|
|
|
|
|
2012-05-25 11:40:45 +00:00
|
|
|
#include "BLI_path_util.h"
|
2011-11-07 12:55:18 +00:00
|
|
|
#include "BLI_utildefines.h"
|
|
|
|
|
#include "BLI_math.h"
|
|
|
|
|
|
|
|
|
|
#include "BKE_context.h"
|
|
|
|
|
#include "BKE_global.h"
|
|
|
|
|
#include "BKE_report.h"
|
|
|
|
|
#include "BKE_main.h"
|
|
|
|
|
#include "BKE_library.h"
|
|
|
|
|
#include "BKE_movieclip.h"
|
|
|
|
|
#include "BKE_sound.h"
|
|
|
|
|
#include "BKE_tracking.h"
|
|
|
|
|
|
|
|
|
|
#include "WM_api.h"
|
|
|
|
|
#include "WM_types.h"
|
|
|
|
|
|
|
|
|
|
#include "IMB_imbuf_types.h"
|
|
|
|
|
#include "IMB_imbuf.h"
|
|
|
|
|
|
|
|
|
|
#include "ED_screen.h"
|
|
|
|
|
#include "ED_clip.h"
|
|
|
|
|
|
|
|
|
|
#include "UI_interface.h"
|
|
|
|
|
|
|
|
|
|
#include "RNA_access.h"
|
|
|
|
|
#include "RNA_define.h"
|
|
|
|
|
|
|
|
|
|
#include "UI_view2d.h"
|
|
|
|
|
|
|
|
|
|
#include "clip_intern.h" // own include
|
|
|
|
|
|
|
|
|
|
/******************** view navigation utilities *********************/
|
|
|
|
|
|
2012-02-24 14:03:18 +00:00
|
|
|
static void sclip_zoom_set(SpaceClip *sc, ARegion *ar, float zoom, float location[2])
|
2011-11-07 12:55:18 +00:00
|
|
|
{
|
2012-03-25 23:19:21 +00:00
|
|
|
float oldzoom = sc->zoom;
|
2011-11-07 12:55:18 +00:00
|
|
|
int width, height;
|
|
|
|
|
|
2012-03-25 23:19:21 +00:00
|
|
|
sc->zoom = zoom;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-02-24 13:31:18 +00:00
|
|
|
if (sc->zoom < 0.1f || sc->zoom > 4.0f) {
|
|
|
|
|
/* check zoom limits */
|
2012-06-19 14:26:29 +00:00
|
|
|
ED_space_clip_get_clip_size(sc, &width, &height);
|
2012-02-24 13:31:18 +00:00
|
|
|
|
2012-03-25 23:19:21 +00:00
|
|
|
width *= sc->zoom;
|
|
|
|
|
height *= sc->zoom;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if ((width < 4) && (height < 4))
|
2012-03-25 23:19:21 +00:00
|
|
|
sc->zoom = oldzoom;
|
2012-03-24 06:38:07 +00:00
|
|
|
else if ((ar->winrct.xmax - ar->winrct.xmin) <= sc->zoom)
|
2012-03-25 23:19:21 +00:00
|
|
|
sc->zoom = oldzoom;
|
2012-03-24 06:38:07 +00:00
|
|
|
else if ((ar->winrct.ymax - ar->winrct.ymin) <= sc->zoom)
|
2012-03-25 23:19:21 +00:00
|
|
|
sc->zoom = oldzoom;
|
2012-02-24 13:31:18 +00:00
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if ((U.uiflag & USER_ZOOM_TO_MOUSEPOS) && location) {
|
2012-06-19 14:26:29 +00:00
|
|
|
ED_space_clip_get_clip_size(sc, &width, &height);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-05-07 08:53:59 +00:00
|
|
|
sc->xof += ((location[0] - 0.5f) * width - sc->xof) * (sc->zoom - oldzoom) / sc->zoom;
|
|
|
|
|
sc->yof += ((location[1] - 0.5f) * height - sc->yof) * (sc->zoom - oldzoom) / sc->zoom;
|
2012-02-24 13:31:18 +00:00
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
2012-02-24 14:03:18 +00:00
|
|
|
static void sclip_zoom_set_factor(SpaceClip *sc, ARegion *ar, float zoomfac, float location[2])
|
2011-11-07 12:55:18 +00:00
|
|
|
{
|
2012-02-24 14:03:18 +00:00
|
|
|
sclip_zoom_set(sc, ar, sc->zoom*zoomfac, location);
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
2012-02-24 13:31:18 +00:00
|
|
|
static void sclip_zoom_set_factor_exec(bContext *C, wmEvent *event, float factor)
|
|
|
|
|
{
|
2012-03-25 23:19:21 +00:00
|
|
|
SpaceClip *sc = CTX_wm_space_clip(C);
|
|
|
|
|
ARegion *ar = CTX_wm_region(C);
|
2012-02-24 14:03:18 +00:00
|
|
|
float location[2], *mpos = NULL;
|
2012-02-24 13:31:18 +00:00
|
|
|
|
|
|
|
|
if (event) {
|
2012-02-24 14:03:18 +00:00
|
|
|
ED_clip_mouse_pos(C, event, location);
|
|
|
|
|
mpos = location;
|
2012-02-24 13:31:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sclip_zoom_set_factor(sc, ar, factor, mpos);
|
|
|
|
|
|
|
|
|
|
ED_region_tag_redraw(CTX_wm_region(C));
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-07 12:55:18 +00:00
|
|
|
/******************** open clip operator ********************/
|
|
|
|
|
|
|
|
|
|
static void clip_filesel(bContext *C, wmOperator *op, const char *path)
|
|
|
|
|
{
|
2012-05-25 11:40:45 +00:00
|
|
|
RNA_string_set(op->ptr, "directory", path);
|
2012-03-25 23:19:21 +00:00
|
|
|
|
2011-11-07 12:55:18 +00:00
|
|
|
WM_event_add_fileselect(C, op);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void open_init(bContext *C, wmOperator *op)
|
|
|
|
|
{
|
|
|
|
|
PropertyPointerRNA *pprop;
|
|
|
|
|
|
2012-03-25 23:19:21 +00:00
|
|
|
op->customdata = pprop = MEM_callocN(sizeof(PropertyPointerRNA), "OpenPropertyPointerRNA");
|
2011-11-07 12:55:18 +00:00
|
|
|
uiIDContextProperty(C, &pprop->ptr, &pprop->prop);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int open_cancel(bContext *UNUSED(C), wmOperator *op)
|
|
|
|
|
{
|
|
|
|
|
MEM_freeN(op->customdata);
|
2012-03-25 23:19:21 +00:00
|
|
|
op->customdata = NULL;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int open_exec(bContext *C, wmOperator *op)
|
|
|
|
|
{
|
2012-03-25 23:19:21 +00:00
|
|
|
SpaceClip *sc = CTX_wm_space_clip(C);
|
2012-04-30 16:19:20 +00:00
|
|
|
bScreen *screen = CTX_wm_screen(C);
|
2011-11-07 12:55:18 +00:00
|
|
|
PropertyPointerRNA *pprop;
|
|
|
|
|
PointerRNA idptr;
|
2012-03-25 23:19:21 +00:00
|
|
|
MovieClip *clip = NULL;
|
2011-11-07 12:55:18 +00:00
|
|
|
char str[FILE_MAX];
|
|
|
|
|
|
2012-05-25 11:40:45 +00:00
|
|
|
if (RNA_collection_length(op->ptr, "files")) {
|
|
|
|
|
PointerRNA fileptr;
|
|
|
|
|
PropertyRNA *prop;
|
|
|
|
|
char dir_only[FILE_MAX], file_only[FILE_MAX];
|
|
|
|
|
int relative = RNA_boolean_get(op->ptr, "relative_path");
|
|
|
|
|
|
|
|
|
|
RNA_string_get(op->ptr, "directory", dir_only);
|
|
|
|
|
if (relative)
|
|
|
|
|
BLI_path_rel(dir_only, G.main->name);
|
|
|
|
|
|
|
|
|
|
prop = RNA_struct_find_property(op->ptr, "files");
|
|
|
|
|
RNA_property_collection_lookup_int(op->ptr, prop, 0, &fileptr);
|
|
|
|
|
RNA_string_get(&fileptr, "name", file_only);
|
|
|
|
|
|
|
|
|
|
BLI_join_dirfile(str, sizeof(str), dir_only, file_only);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
BKE_reportf(op->reports, RPT_ERROR, "No files selected to be opened");
|
|
|
|
|
|
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-07 12:55:18 +00:00
|
|
|
/* default to frame 1 if there's no scene in context */
|
|
|
|
|
|
2012-03-25 23:19:21 +00:00
|
|
|
errno = 0;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-04-28 16:49:00 +00:00
|
|
|
clip = BKE_movieclip_file_add(str);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (!clip) {
|
|
|
|
|
if (op->customdata)
|
2011-11-07 12:55:18 +00:00
|
|
|
MEM_freeN(op->customdata);
|
|
|
|
|
|
2012-05-07 08:53:59 +00:00
|
|
|
BKE_reportf(op->reports, RPT_ERROR, "Can't read: \"%s\", %s.", str,
|
|
|
|
|
errno ? strerror(errno) : "Unsupported movie clip format");
|
2011-11-07 12:55:18 +00:00
|
|
|
|
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
}
|
|
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (!op->customdata)
|
2011-11-07 12:55:18 +00:00
|
|
|
open_init(C, op);
|
|
|
|
|
|
|
|
|
|
/* hook into UI */
|
2012-03-25 23:19:21 +00:00
|
|
|
pprop = op->customdata;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (pprop->prop) {
|
2011-11-07 12:55:18 +00:00
|
|
|
/* when creating new ID blocks, use is already 1, but RNA
|
|
|
|
|
* pointer se also increases user, so this compensates it */
|
|
|
|
|
clip->id.us--;
|
|
|
|
|
|
|
|
|
|
RNA_id_pointer_create(&clip->id, &idptr);
|
|
|
|
|
RNA_property_pointer_set(&pprop->ptr, pprop->prop, idptr);
|
|
|
|
|
RNA_property_update(C, &pprop->ptr, pprop->prop);
|
|
|
|
|
}
|
2012-03-24 06:38:07 +00:00
|
|
|
else if (sc) {
|
2012-06-19 14:26:29 +00:00
|
|
|
ED_space_clip_set_clip(C, screen, sc, clip);
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
2012-05-07 08:53:59 +00:00
|
|
|
WM_event_add_notifier(C, NC_MOVIECLIP | NA_ADDED, clip);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
|
|
|
|
MEM_freeN(op->customdata);
|
|
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int open_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event))
|
|
|
|
|
{
|
2012-03-25 23:19:21 +00:00
|
|
|
SpaceClip *sc = CTX_wm_space_clip(C);
|
2012-05-25 11:40:45 +00:00
|
|
|
char path[FILE_MAX];
|
2012-03-25 23:19:21 +00:00
|
|
|
MovieClip *clip = NULL;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (sc)
|
2012-06-19 14:26:29 +00:00
|
|
|
clip = ED_space_clip_get_clip(sc);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-05-25 11:40:45 +00:00
|
|
|
if (clip) {
|
|
|
|
|
strncpy(path, clip->name, sizeof(path));
|
|
|
|
|
|
|
|
|
|
BLI_path_abs(path, G.main->name);
|
|
|
|
|
BLI_parent_dir(path);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
strncpy(path, U.textudir, sizeof(path));
|
|
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (!RNA_struct_property_is_set(op->ptr, "relative_path"))
|
2011-11-07 12:55:18 +00:00
|
|
|
RNA_boolean_set(op->ptr, "relative_path", U.flag & USER_RELPATHS);
|
|
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (RNA_struct_property_is_set(op->ptr, "filepath"))
|
2011-11-07 12:55:18 +00:00
|
|
|
return open_exec(C, op);
|
|
|
|
|
|
|
|
|
|
open_init(C, op);
|
|
|
|
|
|
|
|
|
|
clip_filesel(C, op, path);
|
|
|
|
|
|
|
|
|
|
return OPERATOR_RUNNING_MODAL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CLIP_OT_open(wmOperatorType *ot)
|
|
|
|
|
{
|
|
|
|
|
/* identifiers */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Open Clip";
|
|
|
|
|
ot->description = "Load a sequence of frames or a movie file";
|
|
|
|
|
ot->idname = "CLIP_OT_open";
|
2011-11-07 12:55:18 +00:00
|
|
|
|
|
|
|
|
/* api callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->exec = open_exec;
|
|
|
|
|
ot->invoke = open_invoke;
|
|
|
|
|
ot->cancel = open_cancel;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
|
|
|
|
/* flags */
|
2012-05-07 08:53:59 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
|
|
|
|
/* properties */
|
2012-05-07 08:53:59 +00:00
|
|
|
WM_operator_properties_filesel(ot, FOLDERFILE | IMAGEFILE | MOVIEFILE, FILE_SPECIAL, FILE_OPENFILE,
|
2012-05-25 11:40:45 +00:00
|
|
|
WM_FILESEL_RELPATH | WM_FILESEL_FILES | WM_FILESEL_DIRECTORY,
|
|
|
|
|
FILE_DEFAULTDISPLAY);
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/******************* reload clip operator *********************/
|
|
|
|
|
|
|
|
|
|
static int reload_exec(bContext *C, wmOperator *UNUSED(op))
|
|
|
|
|
{
|
2012-03-25 23:19:21 +00:00
|
|
|
MovieClip *clip = CTX_data_edit_movieclip(C);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (!clip)
|
2011-11-07 12:55:18 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
|
|
|
|
|
BKE_movieclip_reload(clip);
|
|
|
|
|
|
2012-05-07 08:53:59 +00:00
|
|
|
WM_event_add_notifier(C, NC_MOVIECLIP | NA_EDITED, clip);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CLIP_OT_reload(wmOperatorType *ot)
|
|
|
|
|
{
|
|
|
|
|
/* identifiers */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Reload Clip";
|
|
|
|
|
ot->description = "Reload clip";
|
|
|
|
|
ot->idname = "CLIP_OT_reload";
|
2011-11-07 12:55:18 +00:00
|
|
|
|
|
|
|
|
/* api callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->exec = reload_exec;
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/********************** view pan operator *********************/
|
|
|
|
|
|
|
|
|
|
typedef struct ViewPanData {
|
|
|
|
|
float x, y;
|
|
|
|
|
float xof, yof, xorig, yorig;
|
|
|
|
|
int event_type;
|
|
|
|
|
float *vec;
|
|
|
|
|
} ViewPanData;
|
|
|
|
|
|
|
|
|
|
static void view_pan_init(bContext *C, wmOperator *op, wmEvent *event)
|
|
|
|
|
{
|
2012-03-25 23:19:21 +00:00
|
|
|
SpaceClip *sc = CTX_wm_space_clip(C);
|
2011-11-07 12:55:18 +00:00
|
|
|
ViewPanData *vpd;
|
|
|
|
|
|
2012-03-25 23:19:21 +00:00
|
|
|
op->customdata = vpd = MEM_callocN(sizeof(ViewPanData), "ClipViewPanData");
|
2011-11-07 12:55:18 +00:00
|
|
|
WM_cursor_modal(CTX_wm_window(C), BC_NSEW_SCROLLCURSOR);
|
|
|
|
|
|
2012-03-25 23:19:21 +00:00
|
|
|
vpd->x = event->x;
|
|
|
|
|
vpd->y = event->y;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-03-25 23:19:21 +00:00
|
|
|
if (sc->flag & SC_LOCK_SELECTION)
|
2012-05-02 17:37:39 +00:00
|
|
|
vpd->vec = &sc->xlockof;
|
2012-03-25 23:19:21 +00:00
|
|
|
else
|
2012-05-02 17:37:39 +00:00
|
|
|
vpd->vec = &sc->xof;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
|
|
|
|
copy_v2_v2(&vpd->xof, vpd->vec);
|
|
|
|
|
copy_v2_v2(&vpd->xorig, &vpd->xof);
|
|
|
|
|
|
2012-05-02 17:37:39 +00:00
|
|
|
vpd->event_type = event->type;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
|
|
|
|
WM_event_add_modal_handler(C, op);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void view_pan_exit(bContext *C, wmOperator *op, int cancel)
|
|
|
|
|
{
|
2012-03-25 23:19:21 +00:00
|
|
|
ViewPanData *vpd = op->customdata;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (cancel) {
|
2011-11-07 12:55:18 +00:00
|
|
|
copy_v2_v2(vpd->vec, &vpd->xorig);
|
|
|
|
|
|
|
|
|
|
ED_region_tag_redraw(CTX_wm_region(C));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WM_cursor_restore(CTX_wm_window(C));
|
|
|
|
|
MEM_freeN(op->customdata);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int view_pan_exec(bContext *C, wmOperator *op)
|
|
|
|
|
{
|
2012-03-25 23:19:21 +00:00
|
|
|
SpaceClip *sc = CTX_wm_space_clip(C);
|
2011-11-07 12:55:18 +00:00
|
|
|
float offset[2];
|
|
|
|
|
|
|
|
|
|
RNA_float_get_array(op->ptr, "offset", offset);
|
|
|
|
|
|
2012-03-25 23:19:21 +00:00
|
|
|
if (sc->flag & SC_LOCK_SELECTION) {
|
|
|
|
|
sc->xlockof += offset[0];
|
|
|
|
|
sc->ylockof += offset[1];
|
2012-03-24 06:38:07 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2012-03-25 23:19:21 +00:00
|
|
|
sc->xof += offset[0];
|
|
|
|
|
sc->yof += offset[1];
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ED_region_tag_redraw(CTX_wm_region(C));
|
|
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int view_pan_invoke(bContext *C, wmOperator *op, wmEvent *event)
|
|
|
|
|
{
|
2012-03-25 23:19:21 +00:00
|
|
|
if (event->type == MOUSEPAN) {
|
|
|
|
|
SpaceClip *sc = CTX_wm_space_clip(C);
|
2011-11-07 12:55:18 +00:00
|
|
|
float offset[2];
|
|
|
|
|
|
2012-03-25 23:19:21 +00:00
|
|
|
offset[0] = (event->x - event->prevx) / sc->zoom;
|
|
|
|
|
offset[1] = (event->y - event->prevy) / sc->zoom;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
|
|
|
|
RNA_float_set_array(op->ptr, "offset", offset);
|
|
|
|
|
|
|
|
|
|
view_pan_exec(C, op);
|
2012-03-25 23:19:21 +00:00
|
|
|
|
2011-11-07 12:55:18 +00:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
view_pan_init(C, op, event);
|
2012-03-25 23:19:21 +00:00
|
|
|
|
2011-11-07 12:55:18 +00:00
|
|
|
return OPERATOR_RUNNING_MODAL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int view_pan_modal(bContext *C, wmOperator *op, wmEvent *event)
|
|
|
|
|
{
|
2012-03-25 23:19:21 +00:00
|
|
|
SpaceClip *sc = CTX_wm_space_clip(C);
|
|
|
|
|
ViewPanData *vpd = op->customdata;
|
2011-11-07 12:55:18 +00:00
|
|
|
float offset[2];
|
|
|
|
|
|
2012-04-28 06:31:57 +00:00
|
|
|
switch (event->type) {
|
2011-11-07 12:55:18 +00:00
|
|
|
case MOUSEMOVE:
|
|
|
|
|
copy_v2_v2(vpd->vec, &vpd->xorig);
|
2012-03-25 23:19:21 +00:00
|
|
|
offset[0] = (vpd->x - event->x) / sc->zoom;
|
|
|
|
|
offset[1] = (vpd->y - event->y) / sc->zoom;
|
2011-11-07 12:55:18 +00:00
|
|
|
RNA_float_set_array(op->ptr, "offset", offset);
|
|
|
|
|
view_pan_exec(C, op);
|
|
|
|
|
break;
|
|
|
|
|
case ESCKEY:
|
|
|
|
|
view_pan_exit(C, op, 1);
|
2012-03-25 23:19:21 +00:00
|
|
|
|
2011-11-07 12:55:18 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
case SPACEKEY:
|
|
|
|
|
view_pan_exit(C, op, 0);
|
2012-03-25 23:19:21 +00:00
|
|
|
|
2011-11-07 12:55:18 +00:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
default:
|
2012-05-20 19:49:27 +00:00
|
|
|
if (event->type == vpd->event_type && event->val == KM_RELEASE) {
|
2011-11-07 12:55:18 +00:00
|
|
|
view_pan_exit(C, op, 0);
|
2012-03-25 23:19:21 +00:00
|
|
|
|
2011-11-07 12:55:18 +00:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return OPERATOR_RUNNING_MODAL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int view_pan_cancel(bContext *C, wmOperator *op)
|
|
|
|
|
{
|
|
|
|
|
view_pan_exit(C, op, 1);
|
|
|
|
|
|
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CLIP_OT_view_pan(wmOperatorType *ot)
|
|
|
|
|
{
|
|
|
|
|
/* identifiers */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "View Pan";
|
|
|
|
|
ot->idname = "CLIP_OT_view_pan";
|
2012-05-04 15:00:36 +00:00
|
|
|
ot->description = "Pan the view";
|
2011-11-07 12:55:18 +00:00
|
|
|
|
|
|
|
|
/* api callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->exec = view_pan_exec;
|
|
|
|
|
ot->invoke = view_pan_invoke;
|
|
|
|
|
ot->modal = view_pan_modal;
|
|
|
|
|
ot->cancel = view_pan_cancel;
|
2012-05-02 17:33:48 +00:00
|
|
|
ot->poll = ED_space_clip_view_clip_poll;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
|
|
|
|
/* flags */
|
2012-05-07 08:55:29 +00:00
|
|
|
ot->flag = OPTYPE_BLOCKING;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
|
|
|
|
/* properties */
|
|
|
|
|
RNA_def_float_vector(ot->srna, "offset", 2, NULL, -FLT_MAX, FLT_MAX,
|
|
|
|
|
"Offset", "Offset in floating point units, 1.0 is the width and height of the image", -FLT_MAX, FLT_MAX);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/********************** view zoom operator *********************/
|
|
|
|
|
|
|
|
|
|
typedef struct ViewZoomData {
|
|
|
|
|
float x, y;
|
|
|
|
|
float zoom;
|
|
|
|
|
int event_type;
|
2012-02-24 14:03:18 +00:00
|
|
|
float location[2];
|
2011-11-07 12:55:18 +00:00
|
|
|
} ViewZoomData;
|
|
|
|
|
|
|
|
|
|
static void view_zoom_init(bContext *C, wmOperator *op, wmEvent *event)
|
|
|
|
|
{
|
2012-03-25 23:19:21 +00:00
|
|
|
SpaceClip *sc = CTX_wm_space_clip(C);
|
2011-11-07 12:55:18 +00:00
|
|
|
ViewZoomData *vpd;
|
|
|
|
|
|
2012-05-03 23:47:39 +00:00
|
|
|
op->customdata = vpd = MEM_callocN(sizeof(ViewZoomData), "ClipViewZoomData");
|
2011-11-07 12:55:18 +00:00
|
|
|
WM_cursor_modal(CTX_wm_window(C), BC_NSEW_SCROLLCURSOR);
|
|
|
|
|
|
2012-03-25 23:19:21 +00:00
|
|
|
vpd->x = event->x;
|
|
|
|
|
vpd->y = event->y;
|
|
|
|
|
vpd->zoom = sc->zoom;
|
|
|
|
|
vpd->event_type = event->type;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-02-24 14:03:18 +00:00
|
|
|
ED_clip_mouse_pos(C, event, vpd->location);
|
2012-02-24 13:31:18 +00:00
|
|
|
|
2011-11-07 12:55:18 +00:00
|
|
|
WM_event_add_modal_handler(C, op);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void view_zoom_exit(bContext *C, wmOperator *op, int cancel)
|
|
|
|
|
{
|
2012-03-25 23:19:21 +00:00
|
|
|
SpaceClip *sc = CTX_wm_space_clip(C);
|
|
|
|
|
ViewZoomData *vpd = op->customdata;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (cancel) {
|
2012-03-25 23:19:21 +00:00
|
|
|
sc->zoom = vpd->zoom;
|
2011-11-07 12:55:18 +00:00
|
|
|
ED_region_tag_redraw(CTX_wm_region(C));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WM_cursor_restore(CTX_wm_window(C));
|
|
|
|
|
MEM_freeN(op->customdata);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int view_zoom_exec(bContext *C, wmOperator *op)
|
|
|
|
|
{
|
2012-03-25 23:19:21 +00:00
|
|
|
SpaceClip *sc = CTX_wm_space_clip(C);
|
|
|
|
|
ARegion *ar = CTX_wm_region(C);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-02-24 13:31:18 +00:00
|
|
|
sclip_zoom_set_factor(sc, ar, RNA_float_get(op->ptr, "factor"), NULL);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
|
|
|
|
ED_region_tag_redraw(CTX_wm_region(C));
|
|
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int view_zoom_invoke(bContext *C, wmOperator *op, wmEvent *event)
|
|
|
|
|
{
|
2012-03-25 23:19:21 +00:00
|
|
|
if (event->type == MOUSEZOOM) {
|
2011-11-07 12:55:18 +00:00
|
|
|
float factor;
|
|
|
|
|
|
2012-03-25 23:19:21 +00:00
|
|
|
factor = 1.0f + (event->x - event->prevx + event->y - event->prevy) / 300.0f;
|
2011-11-07 12:55:18 +00:00
|
|
|
RNA_float_set(op->ptr, "factor", factor);
|
2012-02-24 13:31:18 +00:00
|
|
|
|
|
|
|
|
sclip_zoom_set_factor_exec(C, event, factor);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
view_zoom_init(C, op, event);
|
2012-02-24 13:31:18 +00:00
|
|
|
|
2011-11-07 12:55:18 +00:00
|
|
|
return OPERATOR_RUNNING_MODAL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int view_zoom_modal(bContext *C, wmOperator *op, wmEvent *event)
|
|
|
|
|
{
|
2012-03-25 23:19:21 +00:00
|
|
|
SpaceClip *sc = CTX_wm_space_clip(C);
|
|
|
|
|
ARegion *ar = CTX_wm_region(C);
|
|
|
|
|
ViewZoomData *vpd = op->customdata;
|
2011-11-07 12:55:18 +00:00
|
|
|
float factor;
|
|
|
|
|
|
2012-04-28 06:31:57 +00:00
|
|
|
switch (event->type) {
|
2011-11-07 12:55:18 +00:00
|
|
|
case MOUSEMOVE:
|
2012-05-07 08:53:59 +00:00
|
|
|
factor = 1.0f + (vpd->x - event->x + vpd->y - event->y) / 300.0f;
|
2011-11-07 12:55:18 +00:00
|
|
|
RNA_float_set(op->ptr, "factor", factor);
|
2012-03-25 23:19:21 +00:00
|
|
|
sclip_zoom_set(sc, ar, vpd->zoom * factor, vpd->location);
|
2011-11-07 12:55:18 +00:00
|
|
|
ED_region_tag_redraw(CTX_wm_region(C));
|
|
|
|
|
break;
|
|
|
|
|
default:
|
2012-03-25 23:19:21 +00:00
|
|
|
if (event->type == vpd->event_type && event->val == KM_RELEASE) {
|
2011-11-07 12:55:18 +00:00
|
|
|
view_zoom_exit(C, op, 0);
|
2012-03-25 23:19:21 +00:00
|
|
|
|
2011-11-07 12:55:18 +00:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return OPERATOR_RUNNING_MODAL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int view_zoom_cancel(bContext *C, wmOperator *op)
|
|
|
|
|
{
|
|
|
|
|
view_zoom_exit(C, op, 1);
|
2012-03-25 23:19:21 +00:00
|
|
|
|
2011-11-07 12:55:18 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CLIP_OT_view_zoom(wmOperatorType *ot)
|
|
|
|
|
{
|
|
|
|
|
/* identifiers */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "View Zoom";
|
|
|
|
|
ot->idname = "CLIP_OT_view_zoom";
|
2012-05-07 15:50:57 +00:00
|
|
|
ot->description = "Zoom in/out the view";
|
2011-11-07 12:55:18 +00:00
|
|
|
|
|
|
|
|
/* api callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->exec = view_zoom_exec;
|
|
|
|
|
ot->invoke = view_zoom_invoke;
|
|
|
|
|
ot->modal = view_zoom_modal;
|
|
|
|
|
ot->cancel = view_zoom_cancel;
|
2012-05-02 17:33:48 +00:00
|
|
|
ot->poll = ED_space_clip_view_clip_poll;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
|
|
|
|
/* flags */
|
2012-05-07 08:53:59 +00:00
|
|
|
ot->flag = OPTYPE_BLOCKING | OPTYPE_GRAB_POINTER;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
|
|
|
|
/* properties */
|
|
|
|
|
RNA_def_float(ot->srna, "factor", 0.0f, 0.0f, FLT_MAX,
|
|
|
|
|
"Factor", "Zoom factor, values higher than 1.0 zoom in, lower values zoom out", -FLT_MAX, FLT_MAX);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/********************** view zoom in/out operator *********************/
|
|
|
|
|
|
2012-02-24 13:44:45 +00:00
|
|
|
static int view_zoom_in_exec(bContext *C, wmOperator *op)
|
2011-11-07 12:55:18 +00:00
|
|
|
{
|
2012-03-25 23:19:21 +00:00
|
|
|
SpaceClip *sc = CTX_wm_space_clip(C);
|
|
|
|
|
ARegion *ar = CTX_wm_region(C);
|
2012-02-24 13:44:45 +00:00
|
|
|
float location[2];
|
|
|
|
|
|
|
|
|
|
RNA_float_get_array(op->ptr, "location", location);
|
|
|
|
|
|
|
|
|
|
sclip_zoom_set_factor(sc, ar, 1.25f, location);
|
|
|
|
|
|
|
|
|
|
ED_region_tag_redraw(CTX_wm_region(C));
|
2011-11-07 12:55:18 +00:00
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-24 13:44:45 +00:00
|
|
|
static int view_zoom_in_invoke(bContext *C, wmOperator *op, wmEvent *event)
|
2011-11-07 12:55:18 +00:00
|
|
|
{
|
2012-02-24 13:44:45 +00:00
|
|
|
float location[2];
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-02-24 13:44:45 +00:00
|
|
|
ED_clip_mouse_pos(C, event, location);
|
|
|
|
|
RNA_float_set_array(op->ptr, "location", location);
|
|
|
|
|
|
|
|
|
|
return view_zoom_in_exec(C, op);
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CLIP_OT_view_zoom_in(wmOperatorType *ot)
|
|
|
|
|
{
|
|
|
|
|
/* identifiers */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "View Zoom In";
|
|
|
|
|
ot->idname = "CLIP_OT_view_zoom_in";
|
2012-05-04 15:00:36 +00:00
|
|
|
ot->description = "Zoom in the view";
|
2011-11-07 12:55:18 +00:00
|
|
|
|
|
|
|
|
/* api callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->exec = view_zoom_in_exec;
|
|
|
|
|
ot->invoke = view_zoom_in_invoke;
|
2012-05-02 17:33:48 +00:00
|
|
|
ot->poll = ED_space_clip_view_clip_poll;
|
2012-02-24 13:44:45 +00:00
|
|
|
|
|
|
|
|
/* properties */
|
2012-05-07 08:53:59 +00:00
|
|
|
RNA_def_float_vector(ot->srna, "location", 2, NULL, -FLT_MAX, FLT_MAX, "Location",
|
|
|
|
|
"Cursor location in screen coordinates", -10.0f, 10.0f);
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
2012-02-24 13:44:45 +00:00
|
|
|
static int view_zoom_out_exec(bContext *C, wmOperator *op)
|
2011-11-07 12:55:18 +00:00
|
|
|
{
|
2012-03-25 23:19:21 +00:00
|
|
|
SpaceClip *sc = CTX_wm_space_clip(C);
|
|
|
|
|
ARegion *ar = CTX_wm_region(C);
|
2012-02-24 13:44:45 +00:00
|
|
|
float location[2];
|
|
|
|
|
|
|
|
|
|
RNA_float_get_array(op->ptr, "location", location);
|
|
|
|
|
|
|
|
|
|
sclip_zoom_set_factor(sc, ar, 0.8f, location);
|
|
|
|
|
|
|
|
|
|
ED_region_tag_redraw(CTX_wm_region(C));
|
2012-02-24 13:31:18 +00:00
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-24 13:44:45 +00:00
|
|
|
static int view_zoom_out_invoke(bContext *C, wmOperator *op, wmEvent *event)
|
2012-02-24 13:31:18 +00:00
|
|
|
{
|
2012-02-24 13:44:45 +00:00
|
|
|
float location[2];
|
2012-02-24 13:31:18 +00:00
|
|
|
|
2012-02-24 13:44:45 +00:00
|
|
|
ED_clip_mouse_pos(C, event, location);
|
|
|
|
|
RNA_float_set_array(op->ptr, "location", location);
|
|
|
|
|
|
|
|
|
|
return view_zoom_out_exec(C, op);
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CLIP_OT_view_zoom_out(wmOperatorType *ot)
|
|
|
|
|
{
|
|
|
|
|
/* identifiers */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "View Zoom Out";
|
|
|
|
|
ot->idname = "CLIP_OT_view_zoom_out";
|
2012-05-04 15:00:36 +00:00
|
|
|
ot->description = "Zoom out the view";
|
2011-11-07 12:55:18 +00:00
|
|
|
|
|
|
|
|
/* api callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->exec = view_zoom_out_exec;
|
|
|
|
|
ot->invoke = view_zoom_out_invoke;
|
2012-05-02 17:33:48 +00:00
|
|
|
ot->poll = ED_space_clip_view_clip_poll;
|
2012-02-24 13:44:45 +00:00
|
|
|
|
|
|
|
|
/* properties */
|
2012-05-07 08:53:59 +00:00
|
|
|
RNA_def_float_vector(ot->srna, "location", 2, NULL, -FLT_MAX, FLT_MAX, "Location",
|
|
|
|
|
"Cursor location in normalised (0.0-1.0) coordinates", -10.0f, 10.0f);
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/********************** view zoom ratio operator *********************/
|
|
|
|
|
|
|
|
|
|
static int view_zoom_ratio_exec(bContext *C, wmOperator *op)
|
|
|
|
|
{
|
2012-03-25 23:19:21 +00:00
|
|
|
SpaceClip *sc = CTX_wm_space_clip(C);
|
|
|
|
|
ARegion *ar = CTX_wm_region(C);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-02-24 13:31:18 +00:00
|
|
|
sclip_zoom_set(sc, ar, RNA_float_get(op->ptr, "ratio"), NULL);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
|
|
|
|
/* ensure pixel exact locations for draw */
|
2012-05-02 17:37:39 +00:00
|
|
|
sc->xof = (int) sc->xof;
|
|
|
|
|
sc->yof = (int) sc->yof;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
|
|
|
|
ED_region_tag_redraw(CTX_wm_region(C));
|
|
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CLIP_OT_view_zoom_ratio(wmOperatorType *ot)
|
|
|
|
|
{
|
|
|
|
|
/* identifiers */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "View Zoom Ratio";
|
|
|
|
|
ot->idname = "CLIP_OT_view_zoom_ratio";
|
2012-05-04 15:00:36 +00:00
|
|
|
ot->description = "Set the zoom ratio (based on clip size)";
|
2011-11-07 12:55:18 +00:00
|
|
|
|
|
|
|
|
/* api callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->exec = view_zoom_ratio_exec;
|
2012-05-02 17:33:48 +00:00
|
|
|
ot->poll = ED_space_clip_view_clip_poll;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
|
|
|
|
/* properties */
|
|
|
|
|
RNA_def_float(ot->srna, "ratio", 0.0f, 0.0f, FLT_MAX,
|
|
|
|
|
"Ratio", "Zoom ratio, 1.0 is 1:1, higher is zoomed in, lower is zoomed out", -FLT_MAX, FLT_MAX);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/********************** view all operator *********************/
|
|
|
|
|
|
2012-03-04 21:02:58 +00:00
|
|
|
static int view_all_exec(bContext *C, wmOperator *op)
|
2011-11-07 12:55:18 +00:00
|
|
|
{
|
|
|
|
|
SpaceClip *sc;
|
|
|
|
|
ARegion *ar;
|
|
|
|
|
int w, h, width, height;
|
|
|
|
|
float aspx, aspy;
|
2012-05-03 23:47:39 +00:00
|
|
|
int fit_view = RNA_boolean_get(op->ptr, "fit_view");
|
2012-03-04 21:02:58 +00:00
|
|
|
float zoomx, zoomy;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
|
|
|
|
/* retrieve state */
|
2012-03-25 23:19:21 +00:00
|
|
|
sc = CTX_wm_space_clip(C);
|
|
|
|
|
ar = CTX_wm_region(C);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-19 14:26:29 +00:00
|
|
|
ED_space_clip_get_clip_size(sc, &w, &h);
|
|
|
|
|
ED_space_clip_get_clip_aspect(sc, &aspx, &aspy);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-03-25 23:19:21 +00:00
|
|
|
w = w * aspx;
|
|
|
|
|
h = h * aspy;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-05-03 23:47:39 +00:00
|
|
|
/* check if the image will fit in the image with zoom == 1 */
|
2012-03-25 23:19:21 +00:00
|
|
|
width = ar->winrct.xmax - ar->winrct.xmin + 1;
|
|
|
|
|
height = ar->winrct.ymax - ar->winrct.ymin + 1;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (fit_view) {
|
2012-03-04 21:02:58 +00:00
|
|
|
const int margin = 5; /* margin from border */
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-05-02 17:37:39 +00:00
|
|
|
zoomx = (float) width / (w + 2 * margin);
|
|
|
|
|
zoomy = (float) height / (h + 2 * margin);
|
2012-03-04 21:02:58 +00:00
|
|
|
|
|
|
|
|
sclip_zoom_set(sc, ar, MIN2(zoomx, zoomy), NULL);
|
|
|
|
|
}
|
|
|
|
|
else {
|
2012-03-24 06:38:07 +00:00
|
|
|
if ((w >= width || h >= height) && (width > 0 && height > 0)) {
|
2012-05-02 17:37:39 +00:00
|
|
|
zoomx = (float) width / w;
|
|
|
|
|
zoomy = (float) height / h;
|
2012-03-04 21:02:58 +00:00
|
|
|
|
|
|
|
|
/* find the zoom value that will fit the image in the image space */
|
2012-05-02 17:37:39 +00:00
|
|
|
sclip_zoom_set(sc, ar, 1.0f / power_of_2(1.0f / MIN2(zoomx, zoomy)), NULL);
|
2012-03-04 21:02:58 +00:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
sclip_zoom_set(sc, ar, 1.0f, NULL);
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
2012-03-25 23:19:21 +00:00
|
|
|
sc->xof = sc->yof = 0.0f;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
|
|
|
|
ED_region_tag_redraw(CTX_wm_region(C));
|
|
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CLIP_OT_view_all(wmOperatorType *ot)
|
|
|
|
|
{
|
|
|
|
|
/* identifiers */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "View All";
|
|
|
|
|
ot->idname = "CLIP_OT_view_all";
|
2012-05-04 15:00:36 +00:00
|
|
|
ot->description = "View whole image with markers";
|
2011-11-07 12:55:18 +00:00
|
|
|
|
|
|
|
|
/* api callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->exec = view_all_exec;
|
2012-05-02 17:33:48 +00:00
|
|
|
ot->poll = ED_space_clip_view_clip_poll;
|
2012-03-04 21:02:58 +00:00
|
|
|
|
|
|
|
|
/* properties */
|
|
|
|
|
RNA_def_boolean(ot->srna, "fit_view", 0, "Fit View", "Fit frame to the viewport");
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/********************** view selected operator *********************/
|
|
|
|
|
|
|
|
|
|
static int view_selected_exec(bContext *C, wmOperator *UNUSED(op))
|
|
|
|
|
{
|
2012-03-25 23:19:21 +00:00
|
|
|
SpaceClip *sc = CTX_wm_space_clip(C);
|
|
|
|
|
ARegion *ar = CTX_wm_region(C);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-03-25 23:19:21 +00:00
|
|
|
sc->xlockof = 0.0f;
|
|
|
|
|
sc->ylockof = 0.0f;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
|
|
|
|
ED_clip_view_selection(sc, ar, 1);
|
|
|
|
|
ED_region_tag_redraw(CTX_wm_region(C));
|
|
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CLIP_OT_view_selected(wmOperatorType *ot)
|
|
|
|
|
{
|
|
|
|
|
/* identifiers */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "View Selected";
|
|
|
|
|
ot->idname = "CLIP_OT_view_selected";
|
2012-05-04 15:00:36 +00:00
|
|
|
ot->description = "View all selected elements";
|
2011-11-07 12:55:18 +00:00
|
|
|
|
|
|
|
|
/* api callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->exec = view_selected_exec;
|
2012-05-02 17:33:48 +00:00
|
|
|
ot->poll = ED_space_clip_view_clip_poll;
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/********************** change frame operator *********************/
|
|
|
|
|
|
|
|
|
|
static int change_frame_poll(bContext *C)
|
|
|
|
|
{
|
|
|
|
|
/* prevent changes during render */
|
2012-03-24 06:38:07 +00:00
|
|
|
if (G.rendering)
|
2011-11-07 12:55:18 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
return ED_space_clip_poll(C);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void change_frame_apply(bContext *C, wmOperator *op)
|
|
|
|
|
{
|
2012-03-25 23:19:21 +00:00
|
|
|
Scene *scene = CTX_data_scene(C);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
|
|
|
|
/* set the new frame number */
|
2012-03-25 23:19:21 +00:00
|
|
|
CFRA = RNA_int_get(op->ptr, "frame");
|
2011-11-07 12:55:18 +00:00
|
|
|
FRAMENUMBER_MIN_CLAMP(CFRA);
|
|
|
|
|
SUBFRA = 0.0f;
|
|
|
|
|
|
|
|
|
|
/* do updates */
|
|
|
|
|
sound_seek_scene(CTX_data_main(C), CTX_data_scene(C));
|
2012-05-07 08:53:59 +00:00
|
|
|
WM_event_add_notifier(C, NC_SCENE | ND_FRAME, scene);
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int change_frame_exec(bContext *C, wmOperator *op)
|
|
|
|
|
{
|
|
|
|
|
change_frame_apply(C, op);
|
|
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int frame_from_event(bContext *C, wmEvent *event)
|
|
|
|
|
{
|
2012-03-25 23:19:21 +00:00
|
|
|
ARegion *ar = CTX_wm_region(C);
|
|
|
|
|
Scene *scene = CTX_data_scene(C);
|
|
|
|
|
int framenr = 0;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (ar->regiontype == RGN_TYPE_WINDOW) {
|
2012-03-25 23:19:21 +00:00
|
|
|
float sfra = SFRA, efra = EFRA, framelen = ar->winx / (efra - sfra + 1);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-03-25 23:19:21 +00:00
|
|
|
framenr = sfra + event->mval[0] / framelen;
|
2012-03-24 06:38:07 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2011-11-07 12:55:18 +00:00
|
|
|
float viewx, viewy;
|
|
|
|
|
|
|
|
|
|
UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], &viewx, &viewy);
|
|
|
|
|
|
2012-05-02 17:37:39 +00:00
|
|
|
framenr = (int) floor(viewx + 0.5f);
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return framenr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int change_frame_invoke(bContext *C, wmOperator *op, wmEvent *event)
|
|
|
|
|
{
|
2012-03-25 23:19:21 +00:00
|
|
|
ARegion *ar = CTX_wm_region(C);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (ar->regiontype == RGN_TYPE_WINDOW) {
|
2012-03-25 23:19:21 +00:00
|
|
|
if (event->mval[1] > 16)
|
2011-11-07 12:55:18 +00:00
|
|
|
return OPERATOR_PASS_THROUGH;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RNA_int_set(op->ptr, "frame", frame_from_event(C, event));
|
|
|
|
|
|
|
|
|
|
change_frame_apply(C, op);
|
|
|
|
|
|
|
|
|
|
/* add temp handler */
|
|
|
|
|
WM_event_add_modal_handler(C, op);
|
|
|
|
|
|
|
|
|
|
return OPERATOR_RUNNING_MODAL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int change_frame_modal(bContext *C, wmOperator *op, wmEvent *event)
|
|
|
|
|
{
|
|
|
|
|
switch (event->type) {
|
|
|
|
|
case ESCKEY:
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
|
|
|
|
|
case MOUSEMOVE:
|
|
|
|
|
RNA_int_set(op->ptr, "frame", frame_from_event(C, event));
|
|
|
|
|
change_frame_apply(C, op);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LEFTMOUSE:
|
|
|
|
|
case RIGHTMOUSE:
|
2012-03-25 23:19:21 +00:00
|
|
|
if (event->val == KM_RELEASE)
|
2011-11-07 12:55:18 +00:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return OPERATOR_RUNNING_MODAL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CLIP_OT_change_frame(wmOperatorType *ot)
|
|
|
|
|
{
|
|
|
|
|
/* identifiers */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Change frame";
|
|
|
|
|
ot->idname = "CLIP_OT_change_frame";
|
|
|
|
|
ot->description = "Interactively change the current frame number";
|
2011-11-07 12:55:18 +00:00
|
|
|
|
|
|
|
|
/* api callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->exec = change_frame_exec;
|
|
|
|
|
ot->invoke = change_frame_invoke;
|
|
|
|
|
ot->modal = change_frame_modal;
|
|
|
|
|
ot->poll = change_frame_poll;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
|
|
|
|
/* flags */
|
2012-05-07 08:53:59 +00:00
|
|
|
ot->flag = OPTYPE_BLOCKING | OPTYPE_UNDO;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
|
|
|
|
/* rna */
|
|
|
|
|
RNA_def_int(ot->srna, "frame", 0, MINAFRAME, MAXFRAME, "Frame", "", MINAFRAME, MAXFRAME);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/********************** rebuild proxies operator *********************/
|
|
|
|
|
|
|
|
|
|
typedef struct ProxyBuildJob {
|
|
|
|
|
Scene *scene;
|
|
|
|
|
struct Main *main;
|
|
|
|
|
MovieClip *clip;
|
2012-02-29 12:08:26 +00:00
|
|
|
int clip_flag, stop;
|
|
|
|
|
struct IndexBuildContext *index_context;
|
2011-11-07 12:55:18 +00:00
|
|
|
} ProxyJob;
|
|
|
|
|
|
|
|
|
|
static void proxy_freejob(void *pjv)
|
|
|
|
|
{
|
2012-05-03 23:47:39 +00:00
|
|
|
ProxyJob *pj = pjv;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
|
|
|
|
MEM_freeN(pj);
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-01 18:08:37 +00:00
|
|
|
static int proxy_bitflag_to_array(int size_flag, int build_sizes[4], int undistort)
|
|
|
|
|
{
|
|
|
|
|
int build_count = 0;
|
|
|
|
|
int size_flags[2][4] = {{MCLIP_PROXY_SIZE_25,
|
|
|
|
|
MCLIP_PROXY_SIZE_50,
|
2012-03-24 07:36:32 +00:00
|
|
|
MCLIP_PROXY_SIZE_75,
|
|
|
|
|
MCLIP_PROXY_SIZE_100},
|
|
|
|
|
{MCLIP_PROXY_UNDISTORTED_SIZE_25,
|
|
|
|
|
MCLIP_PROXY_UNDISTORTED_SIZE_50,
|
|
|
|
|
MCLIP_PROXY_UNDISTORTED_SIZE_75,
|
|
|
|
|
MCLIP_PROXY_UNDISTORTED_SIZE_100}};
|
2012-02-01 18:08:37 +00:00
|
|
|
int size_nr = undistort ? 1 : 0;
|
|
|
|
|
|
2012-03-25 23:19:21 +00:00
|
|
|
if (size_flag & size_flags[size_nr][0])
|
2012-05-07 08:53:59 +00:00
|
|
|
build_sizes[build_count++] = MCLIP_PROXY_RENDER_SIZE_25;
|
2012-03-25 23:19:21 +00:00
|
|
|
|
|
|
|
|
if (size_flag & size_flags[size_nr][1])
|
2012-05-07 08:53:59 +00:00
|
|
|
build_sizes[build_count++] = MCLIP_PROXY_RENDER_SIZE_50;
|
2012-03-25 23:19:21 +00:00
|
|
|
|
|
|
|
|
if (size_flag & size_flags[size_nr][2])
|
2012-05-07 08:53:59 +00:00
|
|
|
build_sizes[build_count++] = MCLIP_PROXY_RENDER_SIZE_75;
|
2012-03-25 23:19:21 +00:00
|
|
|
|
|
|
|
|
if (size_flag & size_flags[size_nr][3])
|
2012-05-07 08:53:59 +00:00
|
|
|
build_sizes[build_count++] = MCLIP_PROXY_RENDER_SIZE_100;
|
2012-02-01 18:08:37 +00:00
|
|
|
|
|
|
|
|
return build_count;
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-07 12:55:18 +00:00
|
|
|
/* only this runs inside thread */
|
|
|
|
|
static void proxy_startjob(void *pjv, short *stop, short *do_update, float *progress)
|
|
|
|
|
{
|
2012-03-25 23:19:21 +00:00
|
|
|
ProxyJob *pj = pjv;
|
|
|
|
|
Scene *scene = pj->scene;
|
|
|
|
|
MovieClip *clip = pj->clip;
|
|
|
|
|
struct MovieDistortion *distortion = NULL;
|
2012-03-07 19:19:56 +00:00
|
|
|
short size_flag;
|
2012-03-25 23:19:21 +00:00
|
|
|
int cfra, sfra = SFRA, efra = EFRA;
|
|
|
|
|
int build_sizes[4], build_count = 0;
|
|
|
|
|
int build_undistort_sizes[4], build_undistort_count = 0;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-03-25 23:19:21 +00:00
|
|
|
size_flag = clip->proxy.build_size_flag;
|
2012-02-01 18:08:37 +00:00
|
|
|
|
2012-03-25 23:19:21 +00:00
|
|
|
build_count = proxy_bitflag_to_array(size_flag, build_sizes, 0);
|
|
|
|
|
build_undistort_count = proxy_bitflag_to_array(size_flag, build_undistort_sizes, 1);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (clip->source == MCLIP_SRC_MOVIE) {
|
2012-02-29 12:08:26 +00:00
|
|
|
if (pj->index_context)
|
|
|
|
|
IMB_anim_index_rebuild(pj->index_context, stop, do_update, progress);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (!build_undistort_count) {
|
2012-02-29 12:08:26 +00:00
|
|
|
if (*stop)
|
|
|
|
|
pj->stop = 1;
|
|
|
|
|
|
2011-11-07 12:55:18 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
else {
|
2012-03-25 23:19:21 +00:00
|
|
|
sfra = 1;
|
|
|
|
|
efra = IMB_anim_get_duration(clip->anim, IMB_TC_NONE);
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (build_undistort_count)
|
2012-06-15 11:03:23 +00:00
|
|
|
distortion = BKE_tracking_distortion_new();
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-03-25 23:19:21 +00:00
|
|
|
for (cfra = sfra; cfra <= efra; cfra++) {
|
2012-03-24 06:38:07 +00:00
|
|
|
if (clip->source != MCLIP_SRC_MOVIE)
|
2011-12-27 11:09:06 +00:00
|
|
|
BKE_movieclip_build_proxy_frame(clip, pj->clip_flag, NULL, cfra, build_sizes, build_count, 0);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-05-07 08:53:59 +00:00
|
|
|
BKE_movieclip_build_proxy_frame(clip, pj->clip_flag, distortion, cfra,
|
|
|
|
|
build_undistort_sizes, build_undistort_count, 1);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (*stop || G.afbreek)
|
2011-11-07 12:55:18 +00:00
|
|
|
break;
|
|
|
|
|
|
2012-03-25 23:19:21 +00:00
|
|
|
*do_update = TRUE;
|
2012-05-03 23:47:39 +00:00
|
|
|
*progress = ((float) cfra) / (efra - sfra);
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (distortion)
|
2012-06-15 11:03:23 +00:00
|
|
|
BKE_tracking_distortion_free(distortion);
|
2012-02-19 08:09:10 +00:00
|
|
|
|
2012-02-29 12:08:26 +00:00
|
|
|
if (*stop)
|
|
|
|
|
pj->stop = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void proxy_endjob(void *pjv)
|
|
|
|
|
{
|
|
|
|
|
ProxyJob *pj = pjv;
|
|
|
|
|
|
|
|
|
|
if (pj->clip->anim)
|
|
|
|
|
IMB_close_anim_proxies(pj->clip->anim);
|
|
|
|
|
|
|
|
|
|
if (pj->index_context)
|
|
|
|
|
IMB_anim_index_rebuild_finish(pj->index_context, pj->stop);
|
|
|
|
|
|
|
|
|
|
BKE_movieclip_reload(pj->clip);
|
|
|
|
|
|
2012-05-07 08:53:59 +00:00
|
|
|
WM_main_add_notifier(NC_MOVIECLIP | ND_DISPLAY, pj->clip);
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
2011-12-02 13:07:39 +00:00
|
|
|
static int clip_rebuild_proxy_exec(bContext *C, wmOperator *UNUSED(op))
|
2011-11-07 12:55:18 +00:00
|
|
|
{
|
|
|
|
|
wmJob * steve;
|
|
|
|
|
ProxyJob *pj;
|
2012-03-25 23:19:21 +00:00
|
|
|
Scene *scene = CTX_data_scene(C);
|
|
|
|
|
ScrArea *sa = CTX_wm_area(C);
|
|
|
|
|
SpaceClip *sc = CTX_wm_space_clip(C);
|
2012-06-19 14:26:29 +00:00
|
|
|
MovieClip *clip = ED_space_clip_get_clip(sc);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-03-25 23:19:21 +00:00
|
|
|
if ((clip->flag & MCLIP_USE_PROXY) == 0)
|
2011-11-07 12:55:18 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
|
2012-03-25 23:19:21 +00:00
|
|
|
steve = WM_jobs_get(CTX_wm_manager(C), CTX_wm_window(C), sa, "Building Proxies", WM_JOB_PROGRESS);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-03-25 23:19:21 +00:00
|
|
|
pj = MEM_callocN(sizeof(ProxyJob), "proxy rebuild job");
|
|
|
|
|
pj->scene = scene;
|
|
|
|
|
pj->main = CTX_data_main(C);
|
|
|
|
|
pj->clip = clip;
|
|
|
|
|
pj->clip_flag = clip->flag & MCLIP_TIMECODE_FLAGS;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-02-29 12:08:26 +00:00
|
|
|
if (clip->anim) {
|
|
|
|
|
pj->index_context = IMB_anim_index_rebuild_context(clip->anim, clip->proxy.build_tc_flag,
|
|
|
|
|
clip->proxy.build_size_flag, clip->proxy.quality);
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-07 12:55:18 +00:00
|
|
|
WM_jobs_customdata(steve, pj, proxy_freejob);
|
2012-05-07 08:53:59 +00:00
|
|
|
WM_jobs_timer(steve, 0.2, NC_MOVIECLIP | ND_DISPLAY, 0);
|
2012-02-29 12:08:26 +00:00
|
|
|
WM_jobs_callbacks(steve, proxy_startjob, NULL, NULL, proxy_endjob);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-03-25 23:19:21 +00:00
|
|
|
G.afbreek = 0;
|
2011-11-07 12:55:18 +00:00
|
|
|
WM_jobs_start(CTX_wm_manager(C), steve);
|
|
|
|
|
|
|
|
|
|
ED_area_tag_redraw(CTX_wm_area(C));
|
|
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CLIP_OT_rebuild_proxy(wmOperatorType *ot)
|
|
|
|
|
{
|
|
|
|
|
/* identifiers */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Rebuild Proxy and Timecode Indices";
|
|
|
|
|
ot->idname = "CLIP_OT_rebuild_proxy";
|
|
|
|
|
ot->description = "Rebuild all selected proxies and timecode indices in the background";
|
2011-11-07 12:55:18 +00:00
|
|
|
|
|
|
|
|
/* api callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->exec = clip_rebuild_proxy_exec;
|
|
|
|
|
ot->poll = ED_space_clip_poll;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
|
|
|
|
/* flags */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER;
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/********************** mode set operator *********************/
|
|
|
|
|
|
|
|
|
|
static int mode_set_exec(bContext *C, wmOperator *op)
|
|
|
|
|
{
|
2012-03-25 23:19:21 +00:00
|
|
|
SpaceClip *sc = CTX_wm_space_clip(C);
|
|
|
|
|
int mode = RNA_enum_get(op->ptr, "mode");
|
|
|
|
|
int toggle = RNA_boolean_get(op->ptr, "toggle");
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-03-25 23:19:21 +00:00
|
|
|
if (sc->mode == mode) {
|
2012-03-24 06:38:07 +00:00
|
|
|
if (toggle)
|
2012-03-25 23:19:21 +00:00
|
|
|
sc->mode = SC_MODE_TRACKING;
|
2012-03-24 06:38:07 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2012-03-25 23:19:21 +00:00
|
|
|
sc->mode = mode;
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
2012-05-07 08:53:59 +00:00
|
|
|
WM_event_add_notifier(C, NC_SPACE | ND_SPACE_CLIP, NULL);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CLIP_OT_mode_set(wmOperatorType *ot)
|
|
|
|
|
{
|
|
|
|
|
static EnumPropertyItem mode_items[] = {
|
|
|
|
|
{SC_MODE_TRACKING, "TRACKING", 0, "Tracking", "Show tracking and solving tools"},
|
|
|
|
|
{SC_MODE_RECONSTRUCTION, "RECONSTRUCTION", 0, "Reconstruction", "Show tracking/reconstruction tools"},
|
|
|
|
|
{SC_MODE_DISTORTION, "DISTORTION", 0, "Distortion", "Show distortion tools"},
|
|
|
|
|
{0, NULL, 0, NULL, NULL}};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* identifiers */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Set Clip Mode";
|
2011-11-08 23:27:31 +00:00
|
|
|
ot->description = "Set the clip interaction mode";
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->idname = "CLIP_OT_mode_set";
|
2011-11-07 12:55:18 +00:00
|
|
|
|
|
|
|
|
/* api callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->exec = mode_set_exec;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->poll = ED_space_clip_poll;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
|
|
|
|
/* properties */
|
|
|
|
|
RNA_def_enum(ot->srna, "mode", mode_items, SC_MODE_TRACKING, "Mode", "");
|
|
|
|
|
RNA_def_boolean(ot->srna, "toggle", 0, "Toggle", "");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/********************** macroses *********************/
|
|
|
|
|
|
|
|
|
|
void ED_operatormacros_clip(void)
|
|
|
|
|
{
|
|
|
|
|
wmOperatorType *ot;
|
|
|
|
|
wmOperatorTypeMacro *otmacro;
|
|
|
|
|
|
2012-05-05 19:26:53 +00:00
|
|
|
ot = WM_operatortype_append_macro("CLIP_OT_add_marker_move", "Add Marker and Move",
|
2012-05-07 08:53:59 +00:00
|
|
|
"Add new marker and move it on movie", OPTYPE_UNDO | OPTYPE_REGISTER);
|
2011-11-07 12:55:18 +00:00
|
|
|
WM_operatortype_macro_define(ot, "CLIP_OT_add_marker");
|
2012-03-24 02:51:46 +00:00
|
|
|
otmacro = WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate");
|
2011-11-07 12:55:18 +00:00
|
|
|
RNA_struct_idprops_unset(otmacro->ptr, "release_confirm");
|
|
|
|
|
|
2012-05-05 19:26:53 +00:00
|
|
|
ot = WM_operatortype_append_macro("CLIP_OT_add_marker_slide", "Add Marker and Slide",
|
|
|
|
|
"Add new marker and slide it with mouse until mouse button release",
|
2012-05-07 08:53:59 +00:00
|
|
|
OPTYPE_UNDO | OPTYPE_REGISTER);
|
2011-11-07 12:55:18 +00:00
|
|
|
WM_operatortype_macro_define(ot, "CLIP_OT_add_marker");
|
2012-03-24 02:51:46 +00:00
|
|
|
otmacro = WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate");
|
2012-01-16 16:12:03 +00:00
|
|
|
RNA_boolean_set(otmacro->ptr, "release_confirm", TRUE);
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|