2006-01-16 22:02:54 +01:00
|
|
|
// Copyright (c) 2005, Rodrigo Braz Monteiro
|
|
|
|
// All rights reserved.
|
|
|
|
//
|
|
|
|
// Redistribution and use in source and binary forms, with or without
|
|
|
|
// modification, are permitted provided that the following conditions are met:
|
|
|
|
//
|
|
|
|
// * Redistributions of source code must retain the above copyright notice,
|
|
|
|
// this list of conditions and the following disclaimer.
|
|
|
|
// * Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
// this list of conditions and the following disclaimer in the documentation
|
|
|
|
// and/or other materials provided with the distribution.
|
|
|
|
// * Neither the name of the Aegisub Group nor the names of its contributors
|
|
|
|
// may be used to endorse or promote products derived from this software
|
|
|
|
// without specific prior written permission.
|
|
|
|
//
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
|
|
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
// POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
//
|
2009-07-29 07:43:02 +02:00
|
|
|
// Aegisub Project http://www.aegisub.org/
|
|
|
|
|
|
|
|
/// @file video_slider.cpp
|
|
|
|
/// @brief Seek-bar control for video
|
|
|
|
/// @ingroup custom_control
|
|
|
|
///
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2009-01-04 07:31:48 +01:00
|
|
|
#include "config.h"
|
|
|
|
|
2013-06-19 04:28:11 +02:00
|
|
|
#include "video_slider.h"
|
2009-09-10 15:06:40 +02:00
|
|
|
|
2013-06-19 04:28:11 +02:00
|
|
|
#include "base_grid.h"
|
2013-08-15 05:05:48 +02:00
|
|
|
#include "command/command.h"
|
2011-01-21 05:57:36 +01:00
|
|
|
#include "include/aegisub/context.h"
|
|
|
|
#include "include/aegisub/hotkey.h"
|
2013-01-07 02:50:09 +01:00
|
|
|
#include "options.h"
|
2006-02-20 23:15:34 +01:00
|
|
|
#include "utils.h"
|
2009-09-10 15:06:40 +02:00
|
|
|
#include "video_context.h"
|
2013-06-19 04:28:11 +02:00
|
|
|
|
|
|
|
#include <wx/dcbuffer.h>
|
|
|
|
#include <wx/settings.h>
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2011-01-21 05:57:36 +01:00
|
|
|
VideoSlider::VideoSlider (wxWindow* parent, agi::Context *c)
|
|
|
|
: wxWindow(parent, -1, wxDefaultPosition, wxDefaultSize, wxWANTS_CHARS | wxFULL_REPAINT_ON_RESIZE)
|
2011-07-30 01:16:55 +02:00
|
|
|
, c(c)
|
2006-01-16 22:02:54 +01:00
|
|
|
{
|
|
|
|
SetClientSize(20,25);
|
2010-01-05 01:51:53 +01:00
|
|
|
SetMinSize(wxSize(20, 25));
|
2012-02-02 20:18:21 +01:00
|
|
|
SetBackgroundStyle(wxBG_STYLE_PAINT);
|
|
|
|
|
2012-11-13 17:51:01 +01:00
|
|
|
slots.push_back(OPT_SUB("Video/Slider/Show Keyframes", &wxWindow::Refresh, this, false, nullptr));
|
2011-07-30 01:16:55 +02:00
|
|
|
slots.push_back(c->videoController->AddSeekListener(&VideoSlider::SetValue, this));
|
|
|
|
slots.push_back(c->videoController->AddVideoOpenListener(&VideoSlider::VideoOpened, this));
|
|
|
|
slots.push_back(c->videoController->AddKeyframesListener(&VideoSlider::KeyframesChanged, this));
|
2011-07-15 06:04:01 +02:00
|
|
|
|
2011-11-12 02:23:18 +01:00
|
|
|
c->videoSlider = this;
|
|
|
|
|
2011-12-05 06:26:45 +01:00
|
|
|
VideoOpened();
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void VideoSlider::SetValue(int value) {
|
2010-12-07 20:09:21 +01:00
|
|
|
if (val == value) return;
|
2010-12-31 22:03:03 +01:00
|
|
|
val = mid(0, value, max);
|
2006-01-16 22:02:54 +01:00
|
|
|
Refresh(false);
|
|
|
|
}
|
|
|
|
|
2010-12-07 20:09:21 +01:00
|
|
|
void VideoSlider::VideoOpened() {
|
2011-12-05 06:26:45 +01:00
|
|
|
if (c->videoController->IsLoaded()) {
|
|
|
|
max = c->videoController->GetLength() - 1;
|
|
|
|
keyframes = c->videoController->GetKeyFrames();
|
|
|
|
Refresh(false);
|
|
|
|
}
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
|
2010-12-07 20:09:21 +01:00
|
|
|
void VideoSlider::KeyframesChanged(std::vector<int> const& newKeyframes) {
|
|
|
|
keyframes = newKeyframes;
|
|
|
|
Refresh(false);
|
|
|
|
}
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
2006-01-16 22:02:54 +01:00
|
|
|
int VideoSlider::GetValueAtX(int x) {
|
2012-02-02 20:18:21 +01:00
|
|
|
int w = GetClientSize().GetWidth();
|
2006-01-16 22:02:54 +01:00
|
|
|
// Special case
|
|
|
|
if (w <= 10) return 0;
|
|
|
|
|
2010-12-07 20:09:21 +01:00
|
|
|
return (int64_t)(x-5)*(int64_t)max/(int64_t)(w-10);
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int VideoSlider::GetXAtValue(int value) {
|
2010-12-07 20:09:21 +01:00
|
|
|
if (max <= 0) return 0;
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2012-02-02 20:18:21 +01:00
|
|
|
int w = GetClientSize().GetWidth();
|
2010-12-07 20:09:21 +01:00
|
|
|
return (int64_t)value*(int64_t)(w-10)/(int64_t)max+5;
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
BEGIN_EVENT_TABLE(VideoSlider, wxWindow)
|
|
|
|
EVT_MOUSE_EVENTS(VideoSlider::OnMouse)
|
|
|
|
EVT_KEY_DOWN(VideoSlider::OnKeyDown)
|
2012-04-27 21:07:49 +02:00
|
|
|
EVT_CHAR_HOOK(VideoSlider::OnCharHook)
|
2006-01-16 22:02:54 +01:00
|
|
|
EVT_PAINT(VideoSlider::OnPaint)
|
|
|
|
EVT_SET_FOCUS(VideoSlider::OnFocus)
|
|
|
|
EVT_KILL_FOCUS(VideoSlider::OnFocus)
|
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
|
|
|
void VideoSlider::OnMouse(wxMouseEvent &event) {
|
2012-02-02 20:18:21 +01:00
|
|
|
bool had_focus = HasFocus();
|
|
|
|
if (event.ButtonDown())
|
|
|
|
SetFocus();
|
|
|
|
|
2011-12-05 06:26:58 +01:00
|
|
|
if (event.LeftIsDown()) {
|
|
|
|
int x = event.GetX();
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2011-01-21 05:57:36 +01:00
|
|
|
// If the slider didn't already have focus, don't seek if the user
|
|
|
|
// clicked very close to the current location as they were probably
|
|
|
|
// just trying to focus the slider
|
2012-02-02 20:18:21 +01:00
|
|
|
if (!had_focus && abs(x - GetXAtValue(val)) < 4)
|
2011-01-21 05:57:36 +01:00
|
|
|
return;
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2011-01-21 05:57:36 +01:00
|
|
|
// Shift click to snap to keyframe
|
2012-02-02 20:18:21 +01:00
|
|
|
if (event.ShiftDown() && keyframes.size()) {
|
2011-01-21 05:57:36 +01:00
|
|
|
int clickedFrame = GetValueAtX(x);
|
2013-09-16 21:10:00 +02:00
|
|
|
auto pos = lower_bound(keyframes.begin(), keyframes.end(), clickedFrame);
|
2011-01-21 05:57:36 +01:00
|
|
|
if (pos == keyframes.end())
|
|
|
|
--pos;
|
|
|
|
else if (pos + 1 != keyframes.end() && clickedFrame - *pos > (*pos + 1) - clickedFrame)
|
|
|
|
++pos;
|
|
|
|
|
|
|
|
if (*pos == val) return;
|
|
|
|
SetValue(*pos);
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
2011-01-21 05:57:36 +01:00
|
|
|
// Normal click
|
|
|
|
else {
|
|
|
|
int go = GetValueAtX(x);
|
|
|
|
if (go == val) return;
|
|
|
|
SetValue(go);
|
|
|
|
}
|
|
|
|
|
2011-12-05 06:26:58 +01:00
|
|
|
c->videoController->JumpToFrame(val);
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
2013-08-15 05:09:10 +02:00
|
|
|
else if (event.GetWheelRotation() != 0 && ForwardMouseWheelEvent(this, event)) {
|
2013-08-15 05:05:48 +02:00
|
|
|
// If mouse is over the slider, use wheel to step by frames or keyframes (when Shift is held)
|
2013-08-15 05:09:10 +02:00
|
|
|
if (event.ShiftDown())
|
|
|
|
if (event.GetWheelRotation() < 0)
|
|
|
|
cmd::call("video/frame/next/keyframe", c);
|
|
|
|
else
|
|
|
|
cmd::call("video/frame/prev/keyframe", c);
|
|
|
|
else {
|
|
|
|
SetValue(val + (event.GetWheelRotation() > 0 ? -1 : 1));
|
|
|
|
c->videoController->JumpToFrame(val);
|
2013-08-15 05:05:48 +02:00
|
|
|
}
|
|
|
|
}
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
|
2012-04-27 21:07:49 +02:00
|
|
|
void VideoSlider::OnCharHook(wxKeyEvent &event) {
|
|
|
|
hotkey::check("Video", c, event);
|
|
|
|
}
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2012-04-27 21:07:49 +02:00
|
|
|
void VideoSlider::OnKeyDown(wxKeyEvent &event) {
|
2013-08-15 05:06:16 +02:00
|
|
|
// Forward up/down/pgup/pgdn/home/end to grid as those aren't yet handled by commands
|
|
|
|
switch (event.GetKeyCode()) {
|
|
|
|
case WXK_UP:
|
|
|
|
case WXK_DOWN:
|
|
|
|
case WXK_PAGEUP:
|
|
|
|
case WXK_PAGEDOWN:
|
|
|
|
case WXK_HOME:
|
|
|
|
case WXK_END:
|
|
|
|
c->subsGrid->GetEventHandler()->ProcessEvent(event);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
event.Skip();
|
2012-06-12 04:59:38 +02:00
|
|
|
}
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
|
2011-12-22 22:09:31 +01:00
|
|
|
void VideoSlider::OnPaint(wxPaintEvent &) {
|
2012-02-02 20:18:21 +01:00
|
|
|
wxAutoBufferedPaintDC dc(this);
|
2006-01-16 22:02:54 +01:00
|
|
|
int w,h;
|
2012-02-02 20:18:21 +01:00
|
|
|
GetClientSize(&w, &h);
|
2006-01-16 22:02:54 +01:00
|
|
|
|
|
|
|
// Colors
|
|
|
|
wxColour shad = wxSystemSettings::GetColour(wxSYS_COLOUR_3DDKSHADOW);
|
|
|
|
wxColour high = wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT);
|
|
|
|
wxColour face = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE);
|
|
|
|
wxColour sel(123,251,232);
|
|
|
|
wxColour notSel(sel.Red()*2/5,sel.Green()*2/5,sel.Blue()*2/5);
|
|
|
|
wxColour bord(0,0,0);
|
|
|
|
int x1,x2,y1,y2;
|
|
|
|
|
2007-01-21 07:30:19 +01:00
|
|
|
// Background
|
|
|
|
dc.SetPen(*wxTRANSPARENT_PEN);
|
|
|
|
dc.SetBrush(face);
|
|
|
|
dc.DrawRectangle(0,0,w,h);
|
|
|
|
|
2006-01-16 22:02:54 +01:00
|
|
|
// Selection border
|
2012-02-02 20:18:21 +01:00
|
|
|
if (HasFocus()) {
|
2006-01-16 22:02:54 +01:00
|
|
|
dc.SetBrush(*wxTRANSPARENT_BRUSH);
|
|
|
|
dc.SetPen(wxPen(shad,1,wxDOT));
|
|
|
|
dc.DrawRectangle(0,0,w,h);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Draw slider
|
|
|
|
x1 = 5;
|
|
|
|
x2 = w-5;
|
|
|
|
y1 = 8;
|
|
|
|
y2 = h-8;
|
|
|
|
dc.SetPen(wxPen(shad));
|
|
|
|
dc.DrawLine(x1,y1,x2,y1);
|
|
|
|
dc.DrawLine(x1,y1,x1,y2);
|
|
|
|
dc.SetPen(wxPen(high));
|
|
|
|
dc.DrawLine(x1,y2,x2,y2);
|
|
|
|
dc.DrawLine(x2,y1,x2,y2);
|
|
|
|
|
|
|
|
// Draw keyframes
|
|
|
|
int curX;
|
2011-01-21 05:57:36 +01:00
|
|
|
if (OPT_GET("Video/Slider/Show Keyframes")->GetBool()) {
|
2006-01-16 22:02:54 +01:00
|
|
|
dc.SetPen(wxPen(shad));
|
2012-11-04 04:53:03 +01:00
|
|
|
for (int frame : keyframes) {
|
|
|
|
curX = GetXAtValue(frame);
|
2006-01-16 22:02:54 +01:00
|
|
|
dc.DrawLine(curX,2,curX,8);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Draw cursor
|
2010-12-07 20:09:21 +01:00
|
|
|
curX = GetXAtValue(val);
|
2006-01-16 22:02:54 +01:00
|
|
|
|
|
|
|
// Fill bg
|
|
|
|
dc.SetBrush(wxBrush(face));
|
|
|
|
dc.SetPen(*wxTRANSPARENT_PEN);
|
|
|
|
dc.DrawRectangle(curX-2,y1-1,4,y2-y1+5);
|
|
|
|
dc.SetBrush(wxNullBrush);
|
|
|
|
|
|
|
|
// Draw cursor highlights
|
|
|
|
dc.SetPen(wxPen(high));
|
|
|
|
dc.DrawLine(curX,y1-2,curX-4,y1+2);
|
|
|
|
dc.DrawLine(curX-3,y1+2,curX-3,y2+5);
|
|
|
|
|
|
|
|
// Draw cursor shades
|
|
|
|
dc.SetPen(wxPen(shad));
|
|
|
|
dc.DrawLine(curX+1,y1-1,curX+4,y1+2);
|
|
|
|
dc.DrawLine(curX+3,y1+2,curX+3,y2+5);
|
|
|
|
dc.DrawLine(curX-3,y2+4,curX+3,y2+4);
|
|
|
|
|
|
|
|
// Draw cursor outline
|
|
|
|
dc.SetPen(wxPen(bord));
|
|
|
|
dc.DrawLine(curX,y1-3,curX-4,y1+1);
|
|
|
|
dc.DrawLine(curX,y1-3,curX+4,y1+1);
|
|
|
|
dc.DrawLine(curX-4,y1+1,curX-4,y2+5);
|
|
|
|
dc.DrawLine(curX+4,y1+1,curX+4,y2+5);
|
|
|
|
dc.DrawLine(curX-3,y2+5,curX+4,y2+5);
|
|
|
|
dc.DrawLine(curX-3,y2,curX+4,y2);
|
|
|
|
|
|
|
|
// Draw selection
|
|
|
|
dc.SetPen(*wxTRANSPARENT_PEN);
|
2012-02-02 20:18:21 +01:00
|
|
|
dc.SetBrush(HasFocus() ? wxBrush(sel) : wxBrush(notSel));
|
2006-01-16 22:02:54 +01:00
|
|
|
dc.DrawRectangle(curX-3,y2+1,7,4);
|
|
|
|
}
|
|
|
|
|
2011-12-22 22:09:31 +01:00
|
|
|
void VideoSlider::OnFocus(wxFocusEvent &) {
|
2006-01-16 22:02:54 +01:00
|
|
|
Refresh(false);
|
|
|
|
}
|