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
|
|
|
|
|
|
|
|
2009-01-04 07:31:48 +01:00
|
|
|
#include "config.h"
|
|
|
|
|
2009-09-10 15:06:40 +02:00
|
|
|
#ifndef AGI_PRE
|
2007-09-12 01:22:26 +02:00
|
|
|
#include <wx/dcclient.h>
|
|
|
|
#include <wx/dcmemory.h>
|
2009-09-10 15:06:40 +02:00
|
|
|
#include <wx/msgdlg.h>
|
|
|
|
#endif
|
|
|
|
|
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"
|
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"
|
2009-09-10 15:06:40 +02:00
|
|
|
#include "video_provider_dummy.h"
|
2007-04-16 06:26:42 +02:00
|
|
|
|
2012-03-25 06:05:38 +02:00
|
|
|
SubtitlesPreview::SubtitlesPreview(wxWindow *parent, wxSize size, int winStyle, wxColour col)
|
|
|
|
: wxWindow(parent, -1, wxDefaultPosition, size, winStyle)
|
2010-08-02 22:25:29 +02:00
|
|
|
, style(new AssStyle)
|
2010-06-11 04:25:34 +02:00
|
|
|
, backColour(col)
|
|
|
|
, subFile(new AssFile)
|
|
|
|
, 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
|
|
|
|
2010-06-11 04:25:34 +02:00
|
|
|
subFile->LoadDefault();
|
|
|
|
subFile->InsertStyle(style);
|
|
|
|
subFile->Line.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
|
|
|
|
2010-06-11 04:25:34 +02:00
|
|
|
void SubtitlesPreview::SetStyle(AssStyle const& newStyle) {
|
|
|
|
*style = newStyle;
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SubtitlesPreview::SetText(wxString text) {
|
2011-09-28 21:43:11 +02:00
|
|
|
wxString newText = "{\\q2}" + text;
|
2010-06-11 04:25:34 +02:00
|
|
|
if (newText != line->Text) {
|
|
|
|
line->Text = newText;
|
2007-04-17 01:41:06 +02:00
|
|
|
UpdateBitmap();
|
|
|
|
}
|
2007-04-16 06:26:42 +02:00
|
|
|
}
|
|
|
|
|
2012-03-25 06:05:38 +02:00
|
|
|
void SubtitlesPreview::SetColour(wxColour col) {
|
|
|
|
if (col != backColour) {
|
|
|
|
backColour = col;
|
|
|
|
vid.reset(new DummyVideoProvider(0.0, 10, bmp->GetWidth(), bmp->GetHeight(), backColour, true));
|
|
|
|
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
|
|
|
|
2007-04-17 01:59:38 +02:00
|
|
|
AegiVideoFrame frame;
|
2009-07-20 05:50:25 +02:00
|
|
|
frame.CopyFrom(vid->GetFrame(0));
|
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 {
|
2010-06-11 04:25:34 +02:00
|
|
|
provider->LoadSubtitles(subFile.get());
|
|
|
|
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
|
2010-06-11 04:25:34 +02:00
|
|
|
*bmp = static_cast<wxBitmap>(frame.GetImage());
|
2007-04-16 17:08:09 +02:00
|
|
|
frame.Clear();
|
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
|
|
|
|
2010-06-11 04:25:34 +02:00
|
|
|
bmp.reset(new wxBitmap(w, h, -1));
|
|
|
|
vid.reset(new DummyVideoProvider(0.0, 10, w, h, backColour, true));
|
|
|
|
try {
|
2012-05-03 00:42:43 +02:00
|
|
|
if (!provider)
|
|
|
|
provider.reset(SubtitlesProviderFactory::GetProvider());
|
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
|
|
|
|
2012-03-25 06:05:38 +02:00
|
|
|
subFile->SetScriptInfo("PlayResX", wxString::Format("%d", w));
|
|
|
|
subFile->SetScriptInfo("PlayResY", wxString::Format("%d", 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();
|
|
|
|
}
|