From edeaf98352d10d9f22c941a6130bad295d0ec451 Mon Sep 17 00:00:00 2001 From: Rodrigo Braz Monteiro Date: Tue, 17 Apr 2007 23:00:30 +0000 Subject: [PATCH] Created browse button and added it to several (but not all) places on the options dialog. Originally committed to SVN as r1088. --- aegisub/browse_button.cpp | 94 ++++++++++++++++++++++++++++++++++++++ aegisub/browse_button.h | 66 ++++++++++++++++++++++++++ aegisub/dialog_options.cpp | 44 ++++++++++++++---- aegisub/subs_preview.cpp | 31 ++++++++----- 4 files changed, 215 insertions(+), 20 deletions(-) create mode 100644 aegisub/browse_button.cpp create mode 100644 aegisub/browse_button.h diff --git a/aegisub/browse_button.cpp b/aegisub/browse_button.cpp new file mode 100644 index 000000000..3989606c2 --- /dev/null +++ b/aegisub/browse_button.cpp @@ -0,0 +1,94 @@ +// 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 +// + + +/////////// +// Headers +#include +#include +#include +#include "browse_button.h" +#include "utils.h" +#include "main.h" + + +/////////////// +// Constructor +BrowseButton::BrowseButton(wxWindow *parent,int id,wxString text,BrowseType _type,wxPoint position,wxSize size) +: wxButton (parent,id,text == _T("") ? _("Browse...") : text,position,size) +{ + type = _type; + ctrl[0] = NULL; + ctrl[1] = NULL; + Connect(GetId(),wxEVT_COMMAND_BUTTON_CLICKED,wxCommandEventHandler(BrowseButton::OnPressed)); +} + + +//////// +// Bind +void BrowseButton::Bind(wxTextCtrl *control,int pos) { + ctrl[pos] = control; +} + + +/////////// +// Pressed +void BrowseButton::OnPressed(wxCommandEvent &event) { + // Folder + if (type == BROWSE_FOLDER) { + wxString def = DecodeRelativePath(ctrl[0]->GetValue(),AegisubApp::folderName); + wxString dir = MakeRelativePath(wxDirSelector(_("Please choose the folder:"),def),AegisubApp::folderName); + if (dir != _T("")) ctrl[0]->SetValue(dir); + } + + // File + else if (type == BROWSE_FILE) { + } + + // Font + else if (type == BROWSE_FONT) { + wxFont font; + long size; + ctrl[1]->GetValue().ToLong(&size); + font.SetFaceName(ctrl[0]->GetValue()); + font.SetPointSize(size); + font = wxGetFontFromUser(NULL,font); + if (font.IsOk()) { + ctrl[0]->SetValue(font.GetFaceName()); + ctrl[1]->SetValue(wxString::Format(_T("%i"),font.GetPointSize())); + } + } +} + diff --git a/aegisub/browse_button.h b/aegisub/browse_button.h new file mode 100644 index 000000000..bddb586e4 --- /dev/null +++ b/aegisub/browse_button.h @@ -0,0 +1,66 @@ +// 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 + + +/////////////// +// Browse type +enum BrowseType { + BROWSE_FILE, + BROWSE_FOLDER, + BROWSE_FONT +}; + + +/////////////////////// +// Browse button class +class BrowseButton : public wxButton { +private: + wxTextCtrl *ctrl[2]; + BrowseType type; + + void OnPressed(wxCommandEvent &event); + +public: + BrowseButton(wxWindow *parent,int id=-1,wxString text=_T(""),BrowseType type=BROWSE_FILE,wxPoint position=wxDefaultPosition,wxSize size=wxDefaultSize); + void Bind(wxTextCtrl *control,int pos=0); +}; diff --git a/aegisub/dialog_options.cpp b/aegisub/dialog_options.cpp index 7f7193df5..a8b14609f 100644 --- a/aegisub/dialog_options.cpp +++ b/aegisub/dialog_options.cpp @@ -58,6 +58,7 @@ #include "audio_box.h" #include "audio_display.h" #include "video_context.h" +#include "browse_button.h" /////////////// @@ -84,6 +85,7 @@ DialogOptions::DialogOptions(wxWindow *parent) wxPanel *displayPage = new wxPanel(book,-1); wxPanel *autoPage = new wxPanel(book,-1); wxPanel *hotkeysPage = new wxPanel(book,-1); + BrowseButton *browse; // General page { @@ -126,7 +128,7 @@ DialogOptions::DialogOptions(wxWindow *parent) wxSizer *fileSizer1 = new wxStaticBoxSizer(wxVERTICAL,filePage,_("Auto-save")); wxSizer *fileSizer2 = new wxBoxSizer(wxHORIZONTAL); wxSizer *fileSizer3 = new wxStaticBoxSizer(wxHORIZONTAL,filePage,_("File paths")); - wxFlexGridSizer *fileSizer4 = new wxFlexGridSizer(3,2,5,5); + wxFlexGridSizer *fileSizer4 = new wxFlexGridSizer(3,3,5,5); wxSizer *fileSizer5 = new wxStaticBoxSizer(wxHORIZONTAL,filePage,_("Miscelanea")); wxFlexGridSizer *fileSizer6 = new wxFlexGridSizer(3,2,5,5); @@ -146,14 +148,25 @@ DialogOptions::DialogOptions(wxWindow *parent) edit = new wxTextCtrl(filePage,-1); Bind(edit,_T("Auto save path")); fileSizer4->Add(edit,1,wxEXPAND); + browse = new BrowseButton(filePage,-1,_T(""),BROWSE_FOLDER); + browse->Bind(edit); + fileSizer4->Add(browse,0,wxEXPAND); + fileSizer4->Add(new wxStaticText(filePage,-1,_("Auto-backup path:")),0,wxRIGHT | wxALIGN_CENTRE_VERTICAL,5); edit = new wxTextCtrl(filePage,-1); Bind(edit,_T("Auto backup path")); fileSizer4->Add(edit,1,wxEXPAND); + browse = new BrowseButton(filePage,-1,_T(""),BROWSE_FOLDER); + browse->Bind(edit); + fileSizer4->Add(browse,0,wxEXPAND); + fileSizer4->Add(new wxStaticText(filePage,-1,_("Crash recovery path:")),0,wxRIGHT | wxALIGN_CENTRE_VERTICAL,5); edit = new wxTextCtrl(filePage,-1); Bind(edit,_T("Auto recovery path")); fileSizer4->Add(edit,1,wxEXPAND); + browse = new BrowseButton(filePage,-1,_T(""),BROWSE_FOLDER); + browse->Bind(edit); + fileSizer4->Add(browse,0,wxEXPAND); fileSizer4->AddGrowableCol(1,1); // Third static box @@ -189,19 +202,23 @@ DialogOptions::DialogOptions(wxWindow *parent) // Sizers wxSizer *editMainSizer = new wxBoxSizer(wxVERTICAL); wxSizer *editSizer1 = new wxStaticBoxSizer(wxVERTICAL,editPage,_("Options")); + wxSizer *editSizer6 = new wxBoxSizer(wxHORIZONTAL); wxFlexGridSizer *editSizer2 = new wxFlexGridSizer(4,2,5,5); wxSizer *editSizer3 = new wxStaticBoxSizer(wxVERTICAL,editPage,_("Style")); wxFlexGridSizer *editSizer4 = new wxFlexGridSizer(9,2,2,2); wxSizer *editSizer5 = new wxBoxSizer(wxHORIZONTAL); // First static box - wxString labels1[4] = { _("Path to dictionaries"), _("Enable call tips"), _("Link commiting of times"), _("Enable syntax highlighting") }; - wxString options1[4] = { _T("Dictionaries path"), _T("Call Tips Enabled"), _T("Link Time Boxes Commit"), _T("Syntax Highlight Enabled") }; - editSizer2->Add(new wxStaticText(editPage,-1,labels1[0]+_T(": ")),0,wxALIGN_CENTER_VERTICAL|wxRIGHT,5); + wxString labels1[3] = { _("Enable call tips"), _("Enable syntax highlighting"), _("Link commiting of times") }; + wxString options1[3] = { _T("Call Tips Enabled"), _T("Syntax Highlight Enabled"), _T("Link Time Boxes Commit") }; + editSizer6->Add(new wxStaticText(editPage,-1,_("Path to dictionary files:")),0,wxALIGN_CENTER_VERTICAL|wxRIGHT,5); wxTextCtrl *edit = new wxTextCtrl(editPage,-1,_T("")); - Bind(edit,options1[0]); - editSizer2->Add(edit,0,wxEXPAND|wxALIGN_CENTER_VERTICAL|wxRIGHT,5); - for (int i=1;i<4;i++) { + Bind(edit,_T("Dictionaries path")); + editSizer6->Add(edit,1,wxEXPAND|wxALIGN_CENTER_VERTICAL|wxRIGHT,5); + browse = new BrowseButton(editPage,-1,_T(""),BROWSE_FOLDER); + browse->Bind(edit); + editSizer6->Add(browse,0,wxEXPAND); + for (int i=0;i<3;i++) { wxCheckBox *control = new wxCheckBox(editPage,-1,labels1[i]); Bind(control,options1[i]); editSizer2->Add(control,1,wxEXPAND,0); @@ -231,15 +248,20 @@ DialogOptions::DialogOptions(wxWindow *parent) // Third sizer editSizer5->Add(new wxStaticText(editPage,-1,_("Font: ")),0,wxALIGN_CENTER_VERTICAL | wxRIGHT,10); + browse = new BrowseButton(editPage,-1,_T(""),BROWSE_FONT); control = new wxTextCtrl(editPage,-1); + browse->Bind((wxTextCtrl*)control); Bind(control,options2[9]); editSizer5->Add(control,1,wxEXPAND | wxRIGHT,5); control = new wxTextCtrl(editPage,-1,_T(""),wxDefaultPosition,wxSize(50,-1),0,NumValidator(NULL,false));; + browse->Bind((wxTextCtrl*)control,1); Bind(control,options2[10]); - editSizer5->Add(control,0,wxEXPAND | wxRIGHT,0); + editSizer5->Add(control,0,wxEXPAND | wxRIGHT,5); + editSizer5->Add(browse,0,wxEXPAND); // Sizers editSizer1->Add(editSizer2,1,wxEXPAND | wxALL,5); + editSizer1->Add(editSizer6,0,wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM,5); editSizer3->Add(editSizer4,1,wxEXPAND | wxALL,5); editSizer3->Add(editSizer5,0,wxEXPAND | wxALL,5); editMainSizer->Add(editSizer1,0,wxEXPAND | wxALL,0); @@ -290,12 +312,16 @@ DialogOptions::DialogOptions(wxWindow *parent) // Third sizer gridSizer4->Add(new wxStaticText(gridPage,-1,_("Font: ")),0,wxALIGN_CENTER_VERTICAL | wxRIGHT,10); + browse = new BrowseButton(gridPage,-1,_T(""),BROWSE_FONT); control = new wxTextCtrl(gridPage,-1); Bind(control,_T("Grid font face")); + browse->Bind((wxTextCtrl*)control); gridSizer4->Add(control,1,wxEXPAND | wxRIGHT,5); control = new wxTextCtrl(gridPage,-1,_T(""),wxDefaultPosition,wxSize(50,-1),0,NumValidator(NULL,false));; Bind(control,_T("Grid font size")); - gridSizer4->Add(control,0,wxEXPAND | wxRIGHT,0); + browse->Bind((wxTextCtrl*)control,1); + gridSizer4->Add(control,0,wxEXPAND | wxRIGHT,5); + gridSizer4->Add(browse,0,wxEXPAND); // Fourth sizer gridSizer5->Add(new wxStaticText(gridPage,-1,_("Replace override tags with: ")),0,wxALIGN_CENTER_VERTICAL | wxRIGHT,10); diff --git a/aegisub/subs_preview.cpp b/aegisub/subs_preview.cpp index 1b6b58078..2014e2f79 100644 --- a/aegisub/subs_preview.cpp +++ b/aegisub/subs_preview.cpp @@ -135,19 +135,28 @@ void SubtitlesPreview::UpdateBitmap(int w,int h) { AegiVideoFrame frame; frame.CopyFrom(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,,{\\q2}") + showText,_T("[Events]"),0,ver,&outGroup); + // Try to get subtitles provider + SubtitlesProvider *provider = NULL; + try { + provider = SubtitlesProviderFactory::GetProvider(); + } + catch (...) { + wxMessageBox(_T("Could not get any subtitles provider for the preview box. Make sure that you have a provider installed."),_T("No subtitles provider"),wxICON_ERROR); + } - // Apply subtitles - SubtitlesProvider *provider = SubtitlesProviderFactory::GetProvider(); + // Provider OK if (provider) { + // 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,,{\\q2}") + showText,_T("[Events]"),0,ver,&outGroup); + + // Apply subtitles provider->LoadSubtitles(subs); provider->DrawSubtitles(frame,0.1); delete provider;