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/
2006-01-16 22:02:54 +01:00
//
2009-07-29 07:43:02 +02:00
// $Id$
/// @file dialog_properties.cpp
/// @brief Dialogue box to set subtitle meta-data
/// @ingroup secondary_ui
///
2006-01-16 22:02:54 +01:00
2009-01-04 07:31:48 +01:00
# include "config.h"
2009-09-10 15:06:40 +02:00
# ifndef AGI_PRE
# include <wx/button.h>
2007-09-12 01:22:26 +02:00
# include <wx/dialog.h>
# include <wx/sizer.h>
2009-09-10 15:06:40 +02:00
# include <wx/stattext.h>
# endif
# include "dialog_properties.h"
2011-01-20 06:57:38 +01:00
# include "ass_file.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"
2009-09-10 15:06:40 +02:00
# include "utils.h"
# include "validators.h"
2009-09-10 03:41:34 +02:00
# include "video_context.h"
2009-09-10 15:06:40 +02:00
# include "video_provider_manager.h"
2006-01-16 22:02:54 +01:00
2011-01-20 06:57:38 +01:00
DialogProperties : : DialogProperties ( agi : : Context * c )
: wxDialog ( c - > parent , - 1 , _ ( " Script Properties " ) , wxDefaultPosition , wxDefaultSize , wxDEFAULT_DIALOG_STYLE )
, c ( c )
2006-01-16 22:02:54 +01:00
{
2009-07-25 06:49:59 +02:00
SetIcon ( BitmapToIcon ( GETIMAGE ( properties_toolbutton_24 ) ) ) ;
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 " ) ) ;
2006-01-16 22:02:54 +01:00
wxStaticText * TitleLabel = new wxStaticText ( this , - 1 , _ ( " Title: " ) ) ;
2011-01-20 06:57:38 +01:00
TitleEdit = new wxTextCtrl ( this , - 1 , c - > ass - > GetScriptInfo ( " Title " ) , wxDefaultPosition , wxSize ( 200 , 20 ) ) ;
2006-01-16 22:02:54 +01:00
wxStaticText * OrigScriptLabel = new wxStaticText ( this , - 1 , _ ( " Original script: " ) ) ;
2011-01-20 06:57:38 +01:00
OrigScriptEdit = new wxTextCtrl ( this , - 1 , c - > ass - > GetScriptInfo ( " Original Script " ) , wxDefaultPosition , wxSize ( 200 , 20 ) ) ;
2006-01-16 22:02:54 +01:00
wxStaticText * TranslationLabel = new wxStaticText ( this , - 1 , _ ( " Translation: " ) ) ;
2011-01-20 06:57:38 +01:00
TranslationEdit = new wxTextCtrl ( this , - 1 , c - > ass - > GetScriptInfo ( " Original Translation " ) , wxDefaultPosition , wxSize ( 200 , 20 ) ) ;
2006-01-16 22:02:54 +01:00
wxStaticText * EditingLabel = new wxStaticText ( this , - 1 , _ ( " Editing: " ) ) ;
2011-01-20 06:57:38 +01:00
EditingEdit = new wxTextCtrl ( this , - 1 , c - > ass - > GetScriptInfo ( " Original Editing " ) , wxDefaultPosition , wxSize ( 200 , 20 ) ) ;
2006-01-16 22:02:54 +01:00
wxStaticText * TimingLabel = new wxStaticText ( this , - 1 , _ ( " Timing: " ) ) ;
2011-01-20 06:57:38 +01:00
TimingEdit = new wxTextCtrl ( this , - 1 , c - > ass - > GetScriptInfo ( " Original Timing " ) , wxDefaultPosition , wxSize ( 200 , 20 ) ) ;
2006-01-16 22:02:54 +01:00
wxStaticText * SyncLabel = new wxStaticText ( this , - 1 , _ ( " Synch point: " ) ) ;
2011-01-20 06:57:38 +01:00
SyncEdit = new wxTextCtrl ( this , - 1 , c - > ass - > GetScriptInfo ( " Synch Point " ) , wxDefaultPosition , wxSize ( 200 , 20 ) ) ;
2006-01-16 22:02:54 +01:00
wxStaticText * UpdatedLabel = new wxStaticText ( this , - 1 , _ ( " Updated by: " ) ) ;
2011-01-20 06:57:38 +01:00
UpdatedEdit = new wxTextCtrl ( this , - 1 , c - > ass - > GetScriptInfo ( " Script Updated By " ) , wxDefaultPosition , wxSize ( 200 , 20 ) ) ;
2006-01-16 22:02:54 +01:00
wxStaticText * UpdateDetailsLabel = new wxStaticText ( this , - 1 , _ ( " Update details: " ) ) ;
2011-01-20 06:57:38 +01:00
UpdateDetailsEdit = new wxTextCtrl ( this , - 1 , c - > ass - > GetScriptInfo ( " Update Details " ) , wxDefaultPosition , wxSize ( 200 , 20 ) ) ;
2007-01-04 23:16:39 +01:00
wxFlexGridSizer * TopSizerGrid = new wxFlexGridSizer ( 0 , 2 , 5 , 5 ) ;
2006-01-16 22:02:54 +01:00
TopSizerGrid - > Add ( TitleLabel , 0 , wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL , 0 ) ;
2007-01-04 23:16:39 +01:00
TopSizerGrid - > Add ( TitleEdit , 1 , wxEXPAND , 0 ) ;
2006-01-16 22:02:54 +01:00
TopSizerGrid - > Add ( OrigScriptLabel , 0 , wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL , 0 ) ;
2007-01-04 23:16:39 +01:00
TopSizerGrid - > Add ( OrigScriptEdit , 1 , wxEXPAND , 0 ) ;
2006-01-16 22:02:54 +01:00
TopSizerGrid - > Add ( TranslationLabel , 0 , wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL , 0 ) ;
2007-01-04 23:16:39 +01:00
TopSizerGrid - > Add ( TranslationEdit , 1 , wxEXPAND , 0 ) ;
2006-01-16 22:02:54 +01:00
TopSizerGrid - > Add ( EditingLabel , 0 , wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL , 0 ) ;
2007-01-04 23:16:39 +01:00
TopSizerGrid - > Add ( EditingEdit , 1 , wxEXPAND , 0 ) ;
2006-01-16 22:02:54 +01:00
TopSizerGrid - > Add ( TimingLabel , 0 , wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL , 0 ) ;
2007-01-04 23:16:39 +01:00
TopSizerGrid - > Add ( TimingEdit , 1 , wxEXPAND , 0 ) ;
2006-01-16 22:02:54 +01:00
TopSizerGrid - > Add ( SyncLabel , 0 , wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL , 0 ) ;
2007-01-04 23:16:39 +01:00
TopSizerGrid - > Add ( SyncEdit , 1 , wxEXPAND , 0 ) ;
2006-01-16 22:02:54 +01:00
TopSizerGrid - > Add ( UpdatedLabel , 0 , wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL , 0 ) ;
2007-01-04 23:16:39 +01:00
TopSizerGrid - > Add ( UpdatedEdit , 1 , wxEXPAND , 0 ) ;
2006-01-16 22:02:54 +01:00
TopSizerGrid - > Add ( UpdateDetailsLabel , 0 , wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL , 0 ) ;
2007-01-04 23:16:39 +01:00
TopSizerGrid - > Add ( UpdateDetailsEdit , 1 , wxEXPAND , 0 ) ;
TopSizerGrid - > AddGrowableCol ( 1 , 1 ) ;
TopSizer - > Add ( TopSizerGrid , 1 , wxALL | wxEXPAND , 0 ) ;
2006-01-16 22:02:54 +01:00
// Resolution box
wxSizer * ResSizer = new wxStaticBoxSizer ( wxHORIZONTAL , this , _ ( " Resolution " ) ) ;
2011-01-20 06:57:38 +01:00
ResX = new wxTextCtrl ( this , - 1 , " " , wxDefaultPosition , wxSize ( 50 , 20 ) , 0 , NumValidator ( c - > ass - > GetScriptInfo ( " PlayResX " ) ) ) ;
ResY = new wxTextCtrl ( this , - 1 , " " , wxDefaultPosition , wxSize ( 50 , 20 ) , 0 , NumValidator ( c - > ass - > GetScriptInfo ( " PlayResY " ) ) ) ;
wxStaticText * ResText = new wxStaticText ( this , - 1 , " x " ) ;
wxButton * FromVideo = new wxButton ( this , - 1 , _ ( " From video " ) ) ;
if ( ! c - > videoController - > IsLoaded ( ) ) {
FromVideo - > Enable ( false ) ;
}
else {
FromVideo - > Bind ( wxEVT_COMMAND_BUTTON_CLICKED , & DialogProperties : : OnSetFromVideo , this ) ;
}
2006-01-16 22:02:54 +01:00
ResSizer - > Add ( ResX , 1 , wxRIGHT , 5 ) ;
ResSizer - > Add ( ResText , 0 , wxALIGN_CENTER | wxRIGHT , 5 ) ;
ResSizer - > Add ( ResY , 1 , wxRIGHT , 5 ) ;
ResSizer - > Add ( FromVideo , 1 , 0 , 0 ) ;
2007-01-04 23:16:39 +01:00
// Options
wxSizer * optionsBox = new wxStaticBoxSizer ( wxHORIZONTAL , this , _ ( " Options " ) ) ;
2007-04-09 23:47:59 +02:00
wxFlexGridSizer * optionsGrid = new wxFlexGridSizer ( 3 , 2 , 5 , 5 ) ;
2006-01-16 22:02:54 +01:00
wxArrayString options ;
options . Add ( _ ( " 0: Smart wrapping, top line is wider " ) ) ;
options . Add ( _ ( " 1: End-of-line word wrapping, only \\ N breaks " ) ) ;
options . Add ( _ ( " 2: No word wrapping, both \\ n and \\ N break " ) ) ;
options . Add ( _ ( " 3: Smart wrapping, bottom line is wider " ) ) ;
2011-01-20 06:57:38 +01:00
WrapStyle = new wxComboBox ( this , - 1 , " " , wxDefaultPosition , wxDefaultSize , options , wxCB_READONLY ) ;
2006-01-16 22:02:54 +01:00
long n ;
2011-01-20 06:57:38 +01:00
c - > ass - > GetScriptInfo ( " WrapStyle " ) . ToLong ( & n ) ;
2006-01-16 22:02:54 +01:00
WrapStyle - > SetSelection ( n ) ;
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 ) ;
options . Clear ( ) ;
options . Add ( _ ( " Normal " ) ) ;
options . Add ( _ ( " Reverse " ) ) ;
2011-01-20 06:57:38 +01:00
collision = new wxComboBox ( this , - 1 , " " , wxDefaultPosition , wxDefaultSize , options , wxCB_READONLY ) ;
wxString col = c - > ass - > GetScriptInfo ( " Collisions " ) ;
if ( col . Lower ( ) = = " reverse " ) collision - > SetSelection ( 1 ) ;
2007-01-04 23:16:39 +01:00
else collision - > SetSelection ( 0 ) ;
optionsGrid - > Add ( new wxStaticText ( this , - 1 , _ ( " Collision: " ) ) , 0 , wxALIGN_CENTER_VERTICAL , 0 ) ;
optionsGrid - > Add ( collision , 1 , wxEXPAND , 0 ) ;
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. " ) ) ;
2011-01-20 06:57:38 +01:00
ScaleBorder - > SetValue ( c - > ass - > GetScriptInfo ( " ScaledBorderAndShadow " ) . Lower ( ) = = " yes " ? 1 : 0 ) ;
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
2008-01-14 00:34:38 +01:00
wxStdDialogButtonSizer * ButtonSizer = new wxStdDialogButtonSizer ( ) ;
ButtonSizer - > AddButton ( new wxButton ( this , wxID_OK ) ) ;
2008-01-16 02:01:40 +01:00
ButtonSizer - > AddButton ( new wxButton ( this , wxID_CANCEL ) ) ;
2011-01-20 06:57:38 +01:00
ButtonSizer - > AddButton ( new HelpButton ( this , " Properties " ) ) ;
2008-01-14 00:34:38 +01:00
ButtonSizer - > Realize ( ) ;
2011-01-20 06:57:38 +01:00
Bind ( wxEVT_COMMAND_BUTTON_CLICKED , & DialogProperties : : OnOK , this , wxID_OK ) ;
2006-01-16 22:02:54 +01:00
// MainSizer
wxSizer * MainSizer = new wxBoxSizer ( wxVERTICAL ) ;
MainSizer - > Add ( TopSizer , 0 , wxLEFT | wxRIGHT | wxBOTTOM | wxEXPAND , 5 ) ;
MainSizer - > Add ( ResSizer , 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 ) ;
// Set sizer
SetSizer ( MainSizer ) ;
MainSizer - > SetSizeHints ( this ) ;
CenterOnParent ( ) ;
}
void DialogProperties : : OnOK ( wxCommandEvent & event ) {
int count = 0 ;
2011-01-20 06:57:38 +01:00
count + = SetInfoIfDifferent ( " Title " , TitleEdit - > GetValue ( ) ) ;
count + = SetInfoIfDifferent ( " Original Script " , OrigScriptEdit - > GetValue ( ) ) ;
count + = SetInfoIfDifferent ( " Original Translation " , TranslationEdit - > GetValue ( ) ) ;
count + = SetInfoIfDifferent ( " Original Editing " , EditingEdit - > GetValue ( ) ) ;
count + = SetInfoIfDifferent ( " Original Timing " , TimingEdit - > GetValue ( ) ) ;
count + = SetInfoIfDifferent ( " Synch Point " , SyncEdit - > GetValue ( ) ) ;
count + = SetInfoIfDifferent ( " Script Updated By " , UpdatedEdit - > GetValue ( ) ) ;
count + = SetInfoIfDifferent ( " Update Details " , UpdateDetailsEdit - > GetValue ( ) ) ;
count + = SetInfoIfDifferent ( " PlayResX " , ResX - > GetValue ( ) ) ;
count + = SetInfoIfDifferent ( " PlayResY " , ResY - > GetValue ( ) ) ;
count + = SetInfoIfDifferent ( " WrapStyle " , wxString : : Format ( " %i " , WrapStyle - > GetSelection ( ) ) ) ;
wxString col [ 2 ] = { " Normal " , " Reverse " } ;
count + = SetInfoIfDifferent ( " Collisions " , col [ collision - > GetSelection ( ) ] ) ;
count + = SetInfoIfDifferent ( " ScaledBorderAndShadow " , ScaleBorder - > GetValue ( ) ? " yes " : " no " ) ;
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
}
int DialogProperties : : SetInfoIfDifferent ( wxString key , wxString value ) {
2011-01-20 06:57:38 +01:00
if ( c - > ass - > GetScriptInfo ( key ) ! = value ) {
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
}
void DialogProperties : : OnSetFromVideo ( wxCommandEvent & event ) {
2011-01-20 06:57:38 +01:00
ResX - > SetValue ( wxString : : Format ( " %i " , c - > videoController - > GetWidth ( ) ) ) ;
ResY - > SetValue ( wxString : : Format ( " %i " , c - > videoController - > GetHeight ( ) ) ) ;
2006-01-16 22:02:54 +01:00
event . Skip ( ) ;
}