2007-04-16 06:26:42 +02:00
|
|
|
// Copyright (c) 2007, 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 subs_preview.cpp
|
|
|
|
/// @brief Preview control using a dummy video provider and subtitles provider to render a preview
|
|
|
|
/// @ingroup custom_control
|
|
|
|
///
|
2007-04-16 06:26:42 +02:00
|
|
|
|
2010-06-11 04:25:34 +02:00
|
|
|
#include "ass_dialogue.h"
|
2009-09-10 15:06:40 +02:00
|
|
|
#include "ass_file.h"
|
2007-04-17 01:41:06 +02:00
|
|
|
#include "ass_style.h"
|
2014-03-25 17:51:38 +01:00
|
|
|
#include "dialog_progress.h"
|
2007-04-16 06:26:42 +02:00
|
|
|
#include "subs_preview.h"
|
2010-08-02 08:31:38 +02:00
|
|
|
#include "include/aegisub/subtitles_provider.h"
|
2013-07-01 05:15:43 +02:00
|
|
|
#include "video_frame.h"
|
2009-09-10 15:06:40 +02:00
|
|
|
#include "video_provider_dummy.h"
|
2007-04-16 06:26:42 +02:00
|
|
|
|
2014-04-23 22:53:24 +02:00
|
|
|
#include <libaegisub/make_unique.h>
|
2013-06-08 06:19:40 +02:00
|
|
|
|
|
|
|
#include <wx/dcclient.h>
|
|
|
|
#include <wx/msgdlg.h>
|
|
|
|
|
2012-10-26 16:09:14 +02:00
|
|
|
SubtitlesPreview::SubtitlesPreview(wxWindow *parent, wxSize size, int winStyle, agi::Color col)
|
2012-03-25 06:05:38 +02:00
|
|
|
: wxWindow(parent, -1, wxDefaultPosition, size, winStyle)
|
2010-08-02 22:25:29 +02:00
|
|
|
, style(new AssStyle)
|
2014-03-25 17:51:38 +01:00
|
|
|
, back_color(col)
|
2014-04-23 22:53:24 +02:00
|
|
|
, sub_file(agi::make_unique<AssFile>())
|
2010-06-11 04:25:34 +02:00
|
|
|
, line(new AssDialogue)
|
2007-04-16 06:26:42 +02:00
|
|
|
{
|
2010-06-11 04:25:34 +02:00
|
|
|
line->Text = "{\\q2}preview";
|
2007-04-16 06:26:42 +02:00
|
|
|
|
2010-06-11 04:25:34 +02:00
|
|
|
SetStyle(*style);
|
2007-04-16 06:26:42 +02:00
|
|
|
|
2013-06-08 06:19:40 +02:00
|
|
|
sub_file->LoadDefault();
|
2014-03-07 18:02:24 +01:00
|
|
|
sub_file->Styles.push_back(*style);
|
|
|
|
sub_file->Events.push_back(*line);
|
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
|
|
|
|
2010-06-11 04:25:34 +02:00
|
|
|
SetSizeHints(size.GetWidth(), size.GetHeight(), -1, -1);
|
|
|
|
wxSizeEvent evt(size);
|
|
|
|
OnSize(evt);
|
|
|
|
UpdateBitmap();
|
2012-03-25 06:05:38 +02:00
|
|
|
|
|
|
|
Bind(wxEVT_PAINT, &SubtitlesPreview::OnPaint, this);
|
|
|
|
Bind(wxEVT_SIZE, &SubtitlesPreview::OnSize, this);
|
2007-04-16 06:26:42 +02:00
|
|
|
}
|
|
|
|
|
2010-06-11 04:25:34 +02:00
|
|
|
SubtitlesPreview::~SubtitlesPreview() {
|
|
|
|
}
|
2007-04-16 06:26:42 +02:00
|
|
|
|
2013-06-08 06:19:40 +02:00
|
|
|
void SubtitlesPreview::SetStyle(AssStyle const& new_style) {
|
|
|
|
*style = new_style;
|
2010-06-11 04:25:34 +02:00
|
|
|
style->name = "Default";
|
|
|
|
style->alignment = 5;
|
2012-10-26 16:29:52 +02:00
|
|
|
std::fill(style->Margin.begin(), style->Margin.end(), 0);
|
2010-06-11 04:25:34 +02:00
|
|
|
style->UpdateData();
|
2007-04-16 06:26:42 +02:00
|
|
|
UpdateBitmap();
|
|
|
|
}
|
|
|
|
|
2013-01-04 16:01:50 +01:00
|
|
|
void SubtitlesPreview::SetText(std::string const& text) {
|
2013-06-08 06:19:40 +02:00
|
|
|
std::string new_text = "{\\q2}" + text;
|
|
|
|
if (new_text != line->Text) {
|
|
|
|
line->Text = new_text;
|
2007-04-17 01:41:06 +02:00
|
|
|
UpdateBitmap();
|
|
|
|
}
|
2007-04-16 06:26:42 +02:00
|
|
|
}
|
|
|
|
|
2012-10-26 16:09:14 +02:00
|
|
|
void SubtitlesPreview::SetColour(agi::Color col) {
|
2013-06-08 06:19:40 +02:00
|
|
|
if (col != back_color) {
|
|
|
|
back_color = col;
|
2014-04-23 22:53:24 +02:00
|
|
|
vid = agi::make_unique<DummyVideoProvider>(0.0, 10, bmp->GetWidth(), bmp->GetHeight(), back_color, true);
|
2012-03-25 06:05:38 +02:00
|
|
|
UpdateBitmap();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-11 04:25:34 +02:00
|
|
|
void SubtitlesPreview::UpdateBitmap() {
|
2012-03-25 06:05:38 +02:00
|
|
|
if (!vid) return;
|
2007-04-16 06:26:42 +02:00
|
|
|
|
2014-06-12 23:34:21 +02:00
|
|
|
VideoFrame frame;
|
|
|
|
vid->GetFrame(0, frame);
|
2007-04-16 06:26:42 +02:00
|
|
|
|
2012-03-25 06:05:38 +02:00
|
|
|
if (provider) {
|
2007-06-16 21:38:44 +02:00
|
|
|
try {
|
2013-06-08 06:19:40 +02:00
|
|
|
provider->LoadSubtitles(sub_file.get());
|
2014-06-12 23:34:21 +02:00
|
|
|
provider->DrawSubtitles(frame, 0.1);
|
2007-06-16 21:38:44 +02:00
|
|
|
}
|
2010-06-11 04:25:34 +02:00
|
|
|
catch (...) { }
|
2007-04-16 06:26:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Convert frame to bitmap
|
2014-06-12 23:34:21 +02:00
|
|
|
*bmp = static_cast<wxBitmap>(GetImage(frame));
|
2007-04-16 06:26:42 +02:00
|
|
|
Refresh();
|
|
|
|
}
|
|
|
|
|
2010-06-11 04:25:34 +02:00
|
|
|
void SubtitlesPreview::OnPaint(wxPaintEvent &) {
|
2012-03-25 06:05:38 +02:00
|
|
|
wxPaintDC(this).DrawBitmap(*bmp, 0, 0);
|
2007-04-16 06:26:42 +02:00
|
|
|
}
|
|
|
|
|
2010-06-11 04:25:34 +02:00
|
|
|
void SubtitlesPreview::OnSize(wxSizeEvent &evt) {
|
|
|
|
if (bmp.get() && evt.GetSize() == bmp->GetSize()) return;
|
2007-04-16 06:26:42 +02:00
|
|
|
|
2010-06-11 04:25:34 +02:00
|
|
|
int w = evt.GetSize().GetWidth();
|
|
|
|
int h = evt.GetSize().GetHeight();
|
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
|
|
|
|
2014-04-23 22:53:24 +02:00
|
|
|
bmp = agi::make_unique<wxBitmap>(w, h, -1);
|
|
|
|
vid = agi::make_unique<DummyVideoProvider>(0.0, 10, w, h, back_color, true);
|
2010-06-11 04:25:34 +02:00
|
|
|
try {
|
2014-03-25 21:21:57 +01:00
|
|
|
if (!progress)
|
2014-04-23 22:53:24 +02:00
|
|
|
progress = agi::make_unique<DialogProgress>(this);
|
2014-03-25 21:21:57 +01:00
|
|
|
if (!provider)
|
|
|
|
provider = SubtitlesProviderFactory::GetProvider(progress.get());
|
2010-06-11 04:25:34 +02:00
|
|
|
}
|
|
|
|
catch (...) {
|
|
|
|
wxMessageBox(
|
|
|
|
"Could not get any subtitles provider for the preview box. Make "
|
|
|
|
"sure that you have a provider installed.",
|
2012-03-29 01:59:19 +02:00
|
|
|
"No subtitles provider", wxOK | wxICON_ERROR | wxCENTER);
|
2010-06-11 04:25:34 +02:00
|
|
|
}
|
2007-05-21 06:53:14 +02:00
|
|
|
|
2013-06-08 06:19:40 +02:00
|
|
|
sub_file->SetScriptInfo("PlayResX", std::to_string(w));
|
|
|
|
sub_file->SetScriptInfo("PlayResY", std::to_string(h));
|
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
|
|
|
|
2007-05-21 06:53:14 +02:00
|
|
|
UpdateBitmap();
|
|
|
|
}
|