Style editor layout redesign and added a style preview box to it (doesn't autoupdate yet, though).

Originally committed to SVN as r1079.
This commit is contained in:
Rodrigo Braz Monteiro 2007-04-16 04:26:42 +00:00
parent e2c9befeae
commit 50f63ba3fe
6 changed files with 271 additions and 11 deletions

View File

@ -109,6 +109,7 @@ aegisub_SOURCES = \
subs_edit_box.cpp \
subs_edit_ctrl.cpp \
subs_grid.cpp \
subs_preview.cpp \
subtitle_format.cpp \
subtitle_format_ass.cpp \
subtitle_format_mkv.cpp \

View File

@ -48,12 +48,13 @@
#include "utils.h"
#include "dialog_colorpicker.h"
#include "colour_button.h"
#include "subs_preview.h"
///////////////
// Constructor
DialogStyleEditor::DialogStyleEditor (wxWindow *parent, AssStyle *_style, SubtitlesGrid *_grid)
: wxDialog (parent,-1,_("Style Editor"),wxDefaultPosition,wxDefaultSize,wxDEFAULT_DIALOG_STYLE,_T("DialogStyleEditor"))
: wxDialog (parent,-1,_("Style Editor"),wxDefaultPosition,wxDefaultSize,wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER,_T("DialogStyleEditor"))
{
// Set styles
grid = _grid;
@ -244,6 +245,8 @@ DialogStyleEditor::DialogStyleEditor (wxWindow *parent, AssStyle *_style, Subtit
Angle->SetToolTip(_("Angle to rotate in Z axis, in degrees"));
Encoding->SetToolTip(_("Encoding, only useful in unicode if the font doesn't have the proper unicode mapping."));
Spacing->SetToolTip(_("Character spacing, in pixels"));
SubsPreview = new SubtitlesPreview(this,-1,wxDefaultPosition,wxSize(100,60),wxSUNKEN_BORDER);
SubsPreview->SetStyle(style);
MiscBoxTop->Add(new wxStaticText(this,-1,_("Scale X%:")),1,wxALIGN_CENTER,0);
MiscBoxTop->Add(ScaleX,0,wxLEFT | wxALIGN_CENTER | wxEXPAND,5);
MiscBoxTop->Add(new wxStaticText(this,-1,_("Scale Y%:")),1,wxLEFT | wxALIGN_CENTER,5);
@ -254,8 +257,9 @@ DialogStyleEditor::DialogStyleEditor (wxWindow *parent, AssStyle *_style, Subtit
MiscBoxTop->Add(Spacing,0,wxLEFT | wxALIGN_CENTER | wxEXPAND,5);
MiscBoxBottom->Add(new wxStaticText(this,-1,_("Encoding:")),0,wxLEFT | wxALIGN_CENTER,5);
MiscBoxBottom->Add(Encoding,1,wxLEFT | wxALIGN_CENTER,5);
MiscBox->Add(MiscBoxTop,1,wxEXPAND | wxALIGN_CENTER,0);
MiscBox->Add(MiscBoxTop,0,wxEXPAND | wxALIGN_CENTER,0);
MiscBox->Add(MiscBoxBottom,0,wxEXPAND | wxTOP | wxALIGN_CENTER,5);
MiscBox->Add(SubsPreview,1,wxEXPAND | wxTOP,5);
// Set encoding value
int encLen = EncodingValue.Length();
@ -284,19 +288,31 @@ DialogStyleEditor::DialogStyleEditor (wxWindow *parent, AssStyle *_style, Subtit
#endif
okButton->SetDefault();
// Left side sizer
wxSizer *LeftSizer = new wxBoxSizer(wxVERTICAL);
LeftSizer->Add(NameSizer,0,wxBOTTOM | wxEXPAND,5);
LeftSizer->Add(FontSizer,0,wxBOTTOM | wxEXPAND,5);
LeftSizer->Add(ColorsSizer,0,wxBOTTOM | wxEXPAND,5);
LeftSizer->Add(OutlineBox,0,wxEXPAND,0);
// Right side sizer
wxSizer *RightSizer = new wxBoxSizer(wxVERTICAL);
RightSizer->Add(MarginAlign,0,wxBOTTOM | wxEXPAND,5);
RightSizer->Add(MiscBox,1,wxEXPAND,0);
// Controls Sizer
wxSizer *ControlSizer = new wxBoxSizer(wxHORIZONTAL);
ControlSizer->Add(LeftSizer,0,wxEXPAND,0);
ControlSizer->Add(RightSizer,1,wxLEFT | wxEXPAND,5);
// General Layout
MainSizer = new wxBoxSizer(wxVERTICAL);
MainSizer->Add(NameSizer,0,wxALL | wxEXPAND,5);
MainSizer->Add(FontSizer,0,wxLEFT | wxRIGHT | wxBOTTOM | wxEXPAND,5);
MainSizer->Add(ColorsSizer,0,wxLEFT | wxRIGHT | wxBOTTOM | wxEXPAND,5);
MainSizer->Add(MarginAlign,0,wxLEFT | wxRIGHT | wxBOTTOM | wxEXPAND,5);
MainSizer->Add(OutlineBox,0,wxLEFT | wxRIGHT | wxBOTTOM | wxEXPAND,5);
MainSizer->Add(MiscBox,0,wxLEFT | wxRIGHT | wxBOTTOM | wxEXPAND,5);
MainSizer->Add(ControlSizer,1,wxALL | wxALIGN_CENTER | wxEXPAND,5);
MainSizer->Add(ButtonSizer,0,wxBOTTOM | wxALIGN_CENTER | wxEXPAND,5);
// Set sizer
SetSizer(MainSizer);
MainSizer->SetSizeHints(this);
SetSizer(MainSizer);
CenterOnParent();
}
@ -457,6 +473,9 @@ void DialogStyleEditor::Apply (bool apply,bool close) {
// Exit
if (close) EndModal(1);
// Update preview
SubsPreview->SetStyle(style);
}
// Close

View File

@ -48,6 +48,7 @@
// Prototypes
class AssStyle;
class SubtitlesGrid;
class SubtitlesPreview;
/////////
@ -99,6 +100,7 @@ private:
wxTextCtrl *Angle;
wxComboBox *Encoding;
wxTextCtrl *Spacing;
SubtitlesPreview *SubsPreview;
wxSizer *MainSizer;
void SetBitmapColor (int n,wxColour color);

168
aegisub/subs_preview.cpp Normal file
View File

@ -0,0 +1,168 @@
// 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.
//
// -----------------------------------------------------------------------------
//
// AEGISUB
//
// Website: http://aegisub.cellosoft.com
// Contact: mailto:zeratul@cellosoft.com
//
#pragma once
////////////
// Includes
#include "subs_preview.h"
#include "video_provider_dummy.h"
#include "subtitles_provider.h"
#include "ass_file.h"
#include "ass_style.h"
///////////////
// Constructor
SubtitlesPreview::SubtitlesPreview(wxWindow *parent,int id,wxPoint pos,wxSize size,int style)
: wxWindow(parent,id,pos,size,style)
{
SetSizeHints(size.GetWidth(),size.GetHeight(),-1,-1);
bmp = NULL;
AssStyle temp;
wxString text = _T("Aegisub 0123 ");
text += 0x6708;
text += 0x8a9e;
SetText(text);
SetStyle(&temp);
}
//////////////
// Destructor
SubtitlesPreview::~SubtitlesPreview() {
delete bmp;
}
/////////////
// Set style
void SubtitlesPreview::SetStyle(AssStyle *_style) {
style = AssEntry::GetAsStyle(_style->Clone());
style->name = _T("Preview");
style->alignment = 5;
for (int i=0;i<4;i++) style->Margin[i] = 0;
style->UpdateData();
UpdateBitmap();
}
////////////
// Set text
void SubtitlesPreview::SetText(wxString text) {
showText = text;
UpdateBitmap();
}
////////////////
// Update image
void SubtitlesPreview::UpdateBitmap(int w,int h) {
// Visible?
if (!IsShownOnScreen()) return;
// Get size
if (w == -1) {
w = GetClientSize().GetWidth();
h = GetClientSize().GetHeight();
}
// Delete old bmp if needed
if (bmp) {
if (bmp->GetWidth() != w || bmp->GetHeight() != h) {
delete bmp;
bmp = NULL;
}
}
// Create bitmap
if (!bmp) {
bmp = new wxBitmap(w,h,-1);
}
// Get AegiVideoFrame
DummyVideoProvider vid(0.0,10,w,h,wxColour(47,163,255),true);
AegiVideoFrame frame = vid.GetFrame(0);
// Generate subtitles
AssFile *subs = new AssFile();
subs->LoadDefault();
int ver = 1;
wxString outGroup;
subs->InsertStyle(style);
subs->SetScriptInfo(_T("PlayResX"),wxString::Format(_T("%i"),w));
subs->SetScriptInfo(_T("PlayResY"),wxString::Format(_T("%i"),h));
subs->AddLine(_T("Dialogue: 0,0:00:00.00,0:00:05.00,Preview,,0000,0000,0000,,") + showText,_T("[Events]"),0,ver,&outGroup);
// Apply subtitles
SubtitlesProvider *provider = SubtitlesProviderFactory::GetProvider();
if (provider) {
provider->LoadSubtitles(subs);
provider->DrawSubtitles(frame,0.1);
delete provider;
}
// Convert frame to bitmap
wxMemoryDC dc(*bmp);
wxBitmap tempBmp(frame.GetImage());
dc.DrawBitmap(tempBmp,0,0);
Refresh();
}
///////////////
// Event table
BEGIN_EVENT_TABLE(SubtitlesPreview,wxWindow)
EVT_PAINT(SubtitlesPreview::OnPaint)
EVT_SIZE(SubtitlesPreview::OnSize)
END_EVENT_TABLE()
///////////////
// Paint event
void SubtitlesPreview::OnPaint(wxPaintEvent &event) {
wxPaintDC dc(this);
if (!bmp) UpdateBitmap();
if (bmp) dc.DrawBitmap(*bmp,0,0);
}
//////////////
// Size event
void SubtitlesPreview::OnSize(wxSizeEvent &event) {
UpdateBitmap(event.GetSize().GetWidth(),event.GetSize().GetHeight());
}

70
aegisub/subs_preview.h Normal file
View File

@ -0,0 +1,70 @@
// 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.
//
// -----------------------------------------------------------------------------
//
// AEGISUB
//
// Website: http://aegisub.cellosoft.com
// Contact: mailto:zeratul@cellosoft.com
//
#pragma once
////////////
// Includes
#include <wx/wxprec.h>
//////////////
// Prototypes
class AssStyle;
/////////////////////////
// Subtitles preview box
class SubtitlesPreview : public wxWindow {
private:
wxBitmap *bmp;
AssStyle *style;
wxString showText;
void UpdateBitmap(int w=-1,int h=-1);
void OnSize(wxSizeEvent &event);
void OnPaint(wxPaintEvent &event);
public:
void SetStyle(AssStyle *style);
void SetText(wxString text);
SubtitlesPreview(wxWindow *parent,int id,wxPoint pos,wxSize size,int style);
~SubtitlesPreview();
DECLARE_EVENT_TABLE()
};

View File

@ -110,7 +110,7 @@ wxString TextFileReader::GetEncoding(const wxString _filename) {
CloseHandle(ifile);
#else
ifstream ifile;
ifile.open(wxFNCONV(_filename));
ifile.open(wxFNCONV(_filename).c_str());
if (!ifile.is_open()) {
return _T("unknown");
}
@ -279,7 +279,7 @@ void TextFileReader::Open() {
throw _T("Failed opening file for reading.");
}
#else
file.open(wxFNCONV(filename),std::ios::in | std::ios::binary);
file.open(wxFNCONV(filename).c_str(),std::ios::in | std::ios::binary);
if (!file.is_open()) {
throw _T("Failed opening file for reading.");
}