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/
2011-01-20 06:57:38 +01:00
# include "ass_file.h"
2014-05-22 01:23:28 +02:00
# include "async_video_provider.h"
2013-01-04 16:01:50 +01:00
# include "compat.h"
2008-01-14 00:34:38 +01:00
# include "help_button.h"
2011-01-20 06:57:38 +01:00
# include "include/aegisub/context.h"
2009-07-24 02:08:25 +02:00
# include "libresrc/libresrc.h"
2014-05-22 01:23:28 +02:00
# include "project.h"
2014-05-20 01:47:54 +02:00
# include "resolution_resampler.h"
2009-09-10 15:06:40 +02:00
# include "validators.h"
2006-01-16 22:02:54 +01:00
2013-01-04 16:01:50 +01:00
# include <boost/algorithm/string/predicate.hpp>
2014-05-22 21:07:15 +02:00
# include <vector>
2013-01-04 16:01:50 +01:00
# include <wx/button.h>
# include <wx/checkbox.h>
# include <wx/combobox.h>
2014-05-22 21:07:15 +02:00
# include <wx/dialog.h>
2013-01-04 16:01:50 +01:00
# include <wx/sizer.h>
# include <wx/stattext.h>
# include <wx/textctrl.h>
2014-05-22 21:07:15 +02:00
namespace {
class DialogProperties final : public wxDialog {
agi : : Context * c ; ///< Project this dialog is adjusting the properties of
/// Pairs of a script property and a text control for that property
std : : vector < std : : pair < std : : string , wxTextCtrl * > > properties ;
// Things that effect rendering
wxComboBox * WrapStyle ; ///< Wrapping style for long lines
wxTextCtrl * ResX ; ///< Script x resolution
wxTextCtrl * ResY ; ///< Script y resolution
wxCheckBox * ScaleBorder ; ///< If script resolution != video resolution how should borders be handled
wxComboBox * YCbCrMatrix ;
/// OK button handler
void OnOK ( wxCommandEvent & event ) ;
/// Set script resolution to video resolution button
void OnSetFromVideo ( wxCommandEvent & event ) ;
/// Set a script info field
/// @param key Name of field
/// @param value New value
/// @return Did the value actually need to be changed?
int SetInfoIfDifferent ( std : : string const & key , std : : string const & value ) ;
/// Add a property with label and text box for updating the property
/// @param sizer Sizer to add the label and control to
/// @param label Label text to use
/// @param property Script info property name
void AddProperty ( wxSizer * sizer , wxString const & label , std : : string const & property ) ;
public :
/// Constructor
/// @param c Project context
DialogProperties ( agi : : Context * c ) ;
} ;
2011-01-20 06:57:38 +01:00
DialogProperties : : DialogProperties ( agi : : Context * c )
2011-11-28 23:16:41 +01:00
: wxDialog ( c - > parent , - 1 , _ ( " Script Properties " ) )
2011-01-20 06:57:38 +01:00
, c ( c )
2006-01-16 22:02:54 +01:00
{
2012-04-03 22:40:24 +02:00
SetIcon ( GETICON ( properties_toolbutton_16 ) ) ;
2007-07-05 01:09:40 +02:00
2006-01-16 22:02:54 +01:00
// Script details crap
2007-09-24 19:40:03 +02:00
wxSizer * TopSizer = new wxStaticBoxSizer ( wxHORIZONTAL , this , _ ( " Script " ) ) ;
2013-11-21 18:13:36 +01:00
auto TopSizerGrid = new wxFlexGridSizer ( 0 , 2 , 5 , 5 ) ;
2011-11-28 23:16:41 +01:00
AddProperty ( TopSizerGrid , _ ( " Title: " ) , " Title " ) ;
AddProperty ( TopSizerGrid , _ ( " Original script: " ) , " Original Script " ) ;
AddProperty ( TopSizerGrid , _ ( " Translation: " ) , " Original Translation " ) ;
AddProperty ( TopSizerGrid , _ ( " Editing: " ) , " Original Editing " ) ;
AddProperty ( TopSizerGrid , _ ( " Timing: " ) , " Original Timing " ) ;
AddProperty ( TopSizerGrid , _ ( " Synch point: " ) , " Synch Point " ) ;
AddProperty ( TopSizerGrid , _ ( " Updated by: " ) , " Script Updated By " ) ;
AddProperty ( TopSizerGrid , _ ( " Update details: " ) , " Update Details " ) ;
2007-01-04 23:16:39 +01:00
TopSizerGrid - > AddGrowableCol ( 1 , 1 ) ;
TopSizer - > Add ( TopSizerGrid , 1 , wxALL | wxEXPAND , 0 ) ;
2006-01-16 22:02:54 +01:00
// Resolution box
2013-10-16 01:02:25 +02:00
ResX = new wxTextCtrl ( this , - 1 , " " , wxDefaultPosition , wxSize ( 50 , 20 ) , 0 , IntValidator ( c - > ass - > GetScriptInfoAsInt ( " PlayResX " ) ) ) ;
ResY = new wxTextCtrl ( this , - 1 , " " , wxDefaultPosition , wxSize ( 50 , 20 ) , 0 , IntValidator ( c - > ass - > GetScriptInfoAsInt ( " PlayResY " ) ) ) ;
2011-11-28 23:16:41 +01:00
2011-11-18 19:49:09 +01:00
wxButton * FromVideo = new wxButton ( this , - 1 , _ ( " From &video " ) ) ;
2014-05-22 01:23:28 +02:00
if ( ! c - > project - > VideoProvider ( ) )
2011-01-20 06:57:38 +01:00
FromVideo - > Enable ( false ) ;
2011-11-28 23:16:41 +01:00
else
2013-12-12 03:25:13 +01:00
FromVideo - > Bind ( wxEVT_BUTTON , & DialogProperties : : OnSetFromVideo , this ) ;
2011-11-28 23:16:41 +01:00
2013-09-02 18:21:19 +02:00
auto res_sizer = new wxBoxSizer ( wxHORIZONTAL ) ;
res_sizer - > Add ( ResX , 1 , wxRIGHT | wxALIGN_CENTER_VERTICAL , 5 ) ;
res_sizer - > Add ( new wxStaticText ( this , - 1 , " x " ) , 0 , wxALIGN_CENTER | wxRIGHT , 5 ) ;
res_sizer - > Add ( ResY , 1 , wxRIGHT | wxALIGN_CENTER_VERTICAL , 5 ) ;
res_sizer - > Add ( FromVideo , 1 , 0 , 0 ) ;
YCbCrMatrix = new wxComboBox ( this , - 1 , c - > ass - > GetScriptInfo ( " YCbCr Matrix " ) ,
2014-05-20 01:47:54 +02:00
wxDefaultPosition , wxDefaultSize , to_wx ( MatrixNames ( ) ) , wxCB_READONLY ) ;
2013-09-02 18:21:19 +02:00
auto matrix_sizer = new wxBoxSizer ( wxHORIZONTAL ) ;
matrix_sizer - > Add ( new wxStaticText ( this , - 1 , " YCbCr Matrix: " ) , wxSizerFlags ( ) . Center ( ) ) ;
matrix_sizer - > Add ( YCbCrMatrix , wxSizerFlags ( 1 ) . Expand ( ) . Border ( wxLEFT ) ) ;
auto res_box = new wxStaticBoxSizer ( wxVERTICAL , this , _ ( " Resolution " ) ) ;
res_box - > Add ( res_sizer , wxSizerFlags ( ) . Expand ( ) ) ;
res_box - > Add ( matrix_sizer , wxSizerFlags ( ) . Border ( wxTOP ) . Expand ( ) ) ;
2006-01-16 22:02:54 +01:00
2007-01-04 23:16:39 +01:00
// Options
wxSizer * optionsBox = new wxStaticBoxSizer ( wxHORIZONTAL , this , _ ( " Options " ) ) ;
2013-11-21 18:13:36 +01:00
auto optionsGrid = new wxFlexGridSizer ( 3 , 2 , 5 , 5 ) ;
2011-11-28 23:16:41 +01:00
wxString wrap_opts [ ] = {
_ ( " 0: Smart wrapping, top line is wider " ) ,
_ ( " 1: End-of-line word wrapping, only \\ N breaks " ) ,
_ ( " 2: No word wrapping, both \\ n and \\ N break " ) ,
_ ( " 3: Smart wrapping, bottom line is wider " )
} ;
WrapStyle = new wxComboBox ( this , - 1 , " " , wxDefaultPosition , wxDefaultSize , 4 , wrap_opts , wxCB_READONLY ) ;
WrapStyle - > SetSelection ( c - > ass - > GetScriptInfoAsInt ( " WrapStyle " ) ) ;
2007-07-05 17:23:31 +02:00
optionsGrid - > Add ( new wxStaticText ( this , - 1 , _ ( " Wrap Style: " ) ) , 0 , wxALIGN_CENTER_VERTICAL , 0 ) ;
2007-01-04 23:16:39 +01:00
optionsGrid - > Add ( WrapStyle , 1 , wxEXPAND , 0 ) ;
2011-11-28 23:16:41 +01:00
2007-04-09 23:47:59 +02:00
ScaleBorder = new wxCheckBox ( this , - 1 , _ ( " Scale Border and Shadow " ) ) ;
ScaleBorder - > SetToolTip ( _ ( " Scale border and shadow together with script/render resolution. If this is unchecked, relative border and shadow size will depend on renderer. " ) ) ;
2013-01-04 16:01:50 +01:00
ScaleBorder - > SetValue ( boost : : iequals ( c - > ass - > GetScriptInfo ( " ScaledBorderAndShadow " ) , " yes " ) ) ;
2007-04-09 23:47:59 +02:00
optionsGrid - > AddSpacer ( 0 ) ;
optionsGrid - > Add ( ScaleBorder , 1 , wxEXPAND , 0 ) ;
2007-01-04 23:16:39 +01:00
optionsGrid - > AddGrowableCol ( 1 , 1 ) ;
optionsBox - > Add ( optionsGrid , 1 , wxEXPAND , 0 ) ;
2006-01-16 22:02:54 +01:00
// Button sizer
2011-11-28 23:16:41 +01:00
wxStdDialogButtonSizer * ButtonSizer = CreateStdDialogButtonSizer ( wxOK | wxCANCEL | wxHELP ) ;
2013-12-12 03:25:13 +01:00
Bind ( wxEVT_BUTTON , & DialogProperties : : OnOK , this , wxID_OK ) ;
Bind ( wxEVT_BUTTON , std : : bind ( & HelpButton : : OpenPage , " Properties " ) , wxID_HELP ) ;
2006-01-16 22:02:54 +01:00
// MainSizer
wxSizer * MainSizer = new wxBoxSizer ( wxVERTICAL ) ;
MainSizer - > Add ( TopSizer , 0 , wxLEFT | wxRIGHT | wxBOTTOM | wxEXPAND , 5 ) ;
2013-09-02 18:21:19 +02:00
MainSizer - > Add ( res_box , 0 , wxLEFT | wxRIGHT | wxBOTTOM | wxEXPAND , 5 ) ;
2007-01-04 23:16:39 +01:00
MainSizer - > Add ( optionsBox , 0 , wxLEFT | wxRIGHT | wxBOTTOM | wxEXPAND , 5 ) ;
2006-01-16 22:02:54 +01:00
MainSizer - > Add ( ButtonSizer , 0 , wxLEFT | wxRIGHT | wxBOTTOM | wxEXPAND , 5 ) ;
2011-11-28 23:16:41 +01:00
SetSizerAndFit ( MainSizer ) ;
2006-01-16 22:02:54 +01:00
CenterOnParent ( ) ;
}
2013-01-04 16:01:50 +01:00
void DialogProperties : : AddProperty ( wxSizer * sizer , wxString const & label , std : : string const & property ) {
wxTextCtrl * ctrl = new wxTextCtrl ( this , - 1 , to_wx ( c - > ass - > GetScriptInfo ( property ) ) , wxDefaultPosition , wxSize ( 200 , 20 ) ) ;
2011-11-28 23:16:41 +01:00
sizer - > Add ( new wxStaticText ( this , - 1 , label ) , wxSizerFlags ( ) . Center ( ) . Left ( ) ) ;
sizer - > Add ( ctrl , wxSizerFlags ( 1 ) . Expand ( ) ) ;
2014-05-25 16:41:21 +02:00
properties . push_back ( { property , ctrl } ) ;
2011-11-28 23:16:41 +01:00
}
2011-12-22 22:09:31 +01:00
void DialogProperties : : OnOK ( wxCommandEvent & ) {
2006-01-16 22:02:54 +01:00
int count = 0 ;
2012-11-04 04:53:03 +01:00
for ( auto const & prop : properties )
2013-01-04 16:01:50 +01:00
count + = SetInfoIfDifferent ( prop . first , from_wx ( prop . second - > GetValue ( ) ) ) ;
2011-11-28 23:16:41 +01:00
2013-01-04 16:01:50 +01:00
count + = SetInfoIfDifferent ( " PlayResX " , from_wx ( ResX - > GetValue ( ) ) ) ;
count + = SetInfoIfDifferent ( " PlayResY " , from_wx ( ResY - > GetValue ( ) ) ) ;
count + = SetInfoIfDifferent ( " WrapStyle " , std : : to_string ( WrapStyle - > GetSelection ( ) ) ) ;
count + = SetInfoIfDifferent ( " ScaledBorderAndShadow " , ScaleBorder - > GetValue ( ) ? " yes " : " no " ) ;
2013-09-02 18:21:19 +02:00
count + = SetInfoIfDifferent ( " YCbCr Matrix " , from_wx ( YCbCrMatrix - > GetValue ( ) ) ) ;
2011-01-20 06:57:38 +01:00
2011-09-15 07:16:32 +02:00
if ( count ) c - > ass - > Commit ( _ ( " property changes " ) , AssFile : : COMMIT_SCRIPTINFO ) ;
2011-01-20 06:57:38 +01:00
EndModal ( ! ! count ) ;
2006-01-16 22:02:54 +01:00
}
2013-01-04 16:01:50 +01:00
int DialogProperties : : SetInfoIfDifferent ( std : : string const & key , std : : string const & value ) {
2011-01-20 06:57:38 +01:00
if ( c - > ass - > GetScriptInfo ( key ) ! = value ) {
2011-11-28 23:16:41 +01:00
c - > ass - > SetScriptInfo ( key , value ) ;
2006-01-16 22:02:54 +01:00
return 1 ;
}
2011-01-20 06:57:38 +01:00
return 0 ;
2006-01-16 22:02:54 +01:00
}
2011-12-22 22:09:31 +01:00
void DialogProperties : : OnSetFromVideo ( wxCommandEvent & ) {
2014-05-22 01:23:28 +02:00
ResX - > SetValue ( std : : to_wstring ( c - > project - > VideoProvider ( ) - > GetWidth ( ) ) ) ;
ResY - > SetValue ( std : : to_wstring ( c - > project - > VideoProvider ( ) - > GetHeight ( ) ) ) ;
2006-01-16 22:02:54 +01:00
}
2014-05-22 21:07:15 +02:00
}
void ShowPropertiesDialog ( agi : : Context * c ) {
DialogProperties ( c ) . ShowModal ( ) ;
}