PPageSubStyle.cpp

00001 /* 
00002  *      Copyright (C) 2003-2005 Gabest
00003  *      http://www.gabest.org
00004  *
00005  *  This Program is free software; you can redistribute it and/or modify
00006  *  it under the terms of the GNU General Public License as published by
00007  *  the Free Software Foundation; either version 2, or (at your option)
00008  *  any later version.
00009  *   
00010  *  This Program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00013  *  GNU General Public License for more details.
00014  *   
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with GNU Make; see the file COPYING.  If not, write to
00017  *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 
00018  *  http://www.gnu.org/copyleft/gpl.html
00019  *
00020  */
00021 
00022 // PPageSubStyle.cpp : implementation file
00023 //
00024 
00025 #include "stdafx.h"
00026 #include <math.h>
00027 #include "mplayerc.h"
00028 #include "MainFrm.h"
00029 #include "PPageSubStyle.h"
00030 
00031 // CColorStatic
00032 
00033 //IMPLEMENT_DYNAMIC(CColorStatic, CStatic)
00034 
00035 //BEGIN_MESSAGE_MAP(CColorStatic, CStatic)
00036 //END_MESSAGE_MAP()
00037 
00038 // CPPageSubStyle dialog
00039 
00040 IMPLEMENT_DYNAMIC(CPPageSubStyle, CPPageBase)
00041 CPPageSubStyle::CPPageSubStyle()
00042         : CPPageBase(CPPageSubStyle::IDD, CPPageSubStyle::IDD)
00043         , m_iCharset(0)
00044         , m_spacing(0)
00045         , m_angle(0)
00046         , m_scalex(0)
00047         , m_scaley(0)
00048         , m_borderstyle(0)
00049         , m_borderwidth(0)
00050         , m_shadowdepth(0)
00051         , m_screenalignment(0)
00052         , m_margin(0,0,0,0)
00053         , m_linkalphasliders(FALSE)
00054         , m_relativeTo(FALSE)
00055 {
00056         m_stss = AfxGetAppSettings().subdefstyle;
00057         m_fUseDefaultStyle = true;
00058 }
00059 
00060 CPPageSubStyle::~CPPageSubStyle()
00061 {
00062 }
00063 
00064 void CPPageSubStyle::InitStyle(CString title, STSStyle& stss)
00065 {
00066         m_pPSP->pszTitle = (m_title = title);
00067         m_psp.dwFlags |= PSP_USETITLE;
00068 
00069         m_stss = stss; 
00070         m_fUseDefaultStyle = false;
00071 }
00072 
00073 void CPPageSubStyle::AskColor(int i)
00074 {
00075         CColorDialog dlg(m_stss.colors[i]);
00076         dlg.m_cc.Flags |= CC_FULLOPEN;
00077         if(dlg.DoModal() == IDOK)
00078         {
00079                 m_stss.colors[i] = dlg.m_cc.rgbResult;
00080                 m_color[i].Invalidate();
00081         }
00082 }
00083 
00084 void CPPageSubStyle::DoDataExchange(CDataExchange* pDX)
00085 {
00086         CPPageBase::DoDataExchange(pDX);
00087         DDX_Control(pDX, IDC_BUTTON1, m_font);
00088         DDX_CBIndex(pDX, IDC_COMBO1, m_iCharset);
00089         DDX_Control(pDX, IDC_COMBO1, m_charset);
00090         DDX_Text(pDX, IDC_EDIT3, m_spacing);
00091         DDX_Control(pDX, IDC_SPIN3, m_spacingspin);
00092         DDX_Text(pDX, IDC_EDIT11, m_angle);
00093         DDX_Control(pDX, IDC_SPIN10, m_anglespin);
00094         DDX_Text(pDX, IDC_EDIT5, m_scalex);
00095         DDX_Control(pDX, IDC_SPIN4, m_scalexspin);
00096         DDX_Text(pDX, IDC_EDIT6, m_scaley);
00097         DDX_Control(pDX, IDC_SPIN5, m_scaleyspin);
00098         DDX_Radio(pDX, IDC_RADIO1, m_borderstyle);
00099         DDX_Text(pDX, IDC_EDIT1, m_borderwidth);
00100         DDX_Control(pDX, IDC_SPIN1, m_borderwidthspin);
00101         DDX_Text(pDX, IDC_EDIT2, m_shadowdepth);
00102         DDX_Control(pDX, IDC_SPIN2, m_shadowdepthspin);
00103         DDX_Radio(pDX, IDC_RADIO3, m_screenalignment);
00104         DDX_Text(pDX, IDC_EDIT7, m_margin.left);
00105         DDX_Control(pDX, IDC_SPIN6, m_marginleftspin);
00106         DDX_Text(pDX, IDC_EDIT8, m_margin.right);
00107         DDX_Control(pDX, IDC_SPIN7, m_marginrightspin);
00108         DDX_Text(pDX, IDC_EDIT9, m_margin.top);
00109         DDX_Control(pDX, IDC_SPIN8, m_margintopspin);
00110         DDX_Text(pDX, IDC_EDIT10, m_margin.bottom);
00111         DDX_Control(pDX, IDC_SPIN9, m_marginbottomspin);
00112         DDX_Control(pDX, IDC_COLORPRI, m_color[0]);
00113         DDX_Control(pDX, IDC_COLORSEC, m_color[1]);
00114         DDX_Control(pDX, IDC_COLOROUTL, m_color[2]);
00115         DDX_Control(pDX, IDC_COLORSHAD, m_color[3]);
00116         DDX_Slider(pDX, IDC_SLIDER2, m_alpha[0]);
00117         DDX_Slider(pDX, IDC_SLIDER3, m_alpha[1]);
00118         DDX_Slider(pDX, IDC_SLIDER5, m_alpha[2]);
00119         DDX_Slider(pDX, IDC_SLIDER6, m_alpha[3]);
00120         DDX_Control(pDX, IDC_SLIDER2, m_alphasliders[0]);
00121         DDX_Control(pDX, IDC_SLIDER3, m_alphasliders[1]);
00122         DDX_Control(pDX, IDC_SLIDER5, m_alphasliders[2]);
00123         DDX_Control(pDX, IDC_SLIDER6, m_alphasliders[3]);
00124         DDX_Check(pDX, IDC_CHECK1, m_linkalphasliders);
00125         DDX_Check(pDX, IDC_CHECK_RELATIVETO, m_relativeTo);
00126 }
00127 
00128 
00129 BEGIN_MESSAGE_MAP(CPPageSubStyle, CPPageBase)
00130         ON_BN_CLICKED(IDC_BUTTON1, OnBnClickedButton1)
00131         ON_STN_CLICKED(IDC_COLORPRI, OnStnClickedColorpri)
00132         ON_STN_CLICKED(IDC_COLORSEC, OnStnClickedColorsec)
00133         ON_STN_CLICKED(IDC_COLOROUTL, OnStnClickedColoroutl)
00134         ON_STN_CLICKED(IDC_COLORSHAD, OnStnClickedColorshad)
00135         ON_BN_CLICKED(IDC_CHECK1, OnBnClickedCheck1)
00136         ON_WM_HSCROLL()
00137 END_MESSAGE_MAP()
00138 
00139 
00140 // CPPageSubStyle message handlers
00141 
00142 BOOL CPPageSubStyle::OnInitDialog()
00143 {
00144         __super::OnInitDialog();
00145 
00146         m_font.SetWindowText(m_stss.fontName);
00147         m_iCharset = -1;
00148         for(int i = 0; i < CharSetLen; i++)
00149         {
00150                 CString str;
00151                 str.Format(_T("%s (%d)"), CharSetNames[i], CharSetList[i]);
00152                 m_charset.AddString(str);
00153                 m_charset.SetItemData(i, CharSetList[i]);
00154                 if(m_stss.charSet == CharSetList[i]) m_iCharset = i;
00155         }
00156         
00157         // TODO: allow floats in these edit boxes
00158         m_spacing = (int)m_stss.fontSpacing;
00159         m_spacingspin.SetRange32(-10000, 10000);
00160         while(m_stss.fontAngleZ < 0) m_stss.fontAngleZ += 360;
00161         m_angle = (int)fmod(m_stss.fontAngleZ, 360);
00162         m_anglespin.SetRange32(0, 359);
00163         m_scalex = (int)m_stss.fontScaleX;
00164         m_scalexspin.SetRange32(-10000, 10000);
00165         m_scaley = (int)m_stss.fontScaleY;
00166         m_scaleyspin.SetRange32(-10000, 10000);
00167 
00168         m_borderstyle = m_stss.borderStyle;
00169         m_borderwidth = (int)m_stss.outlineWidth;
00170         m_borderwidthspin.SetRange32(0, 10000);
00171         m_shadowdepth = (int)m_stss.shadowDepth;
00172         m_shadowdepthspin.SetRange32(0, 10000);
00173 
00174         m_screenalignment = m_stss.scrAlignment-1;
00175         m_margin = m_stss.marginRect;
00176         m_marginleftspin.SetRange32(-10000, 10000);
00177         m_marginrightspin.SetRange32(-10000, 10000);
00178         m_margintopspin.SetRange32(-10000, 10000);
00179         m_marginbottomspin.SetRange32(-10000, 10000);
00180         m_relativeTo = m_stss.relativeTo;
00181 
00182         for(int i = 0; i < 4; i++)
00183         {
00184                 m_color[i].SetColorPtr(&m_stss.colors[i]);
00185                 m_alpha[i] = 255-m_stss.alpha[i];
00186                 m_alphasliders[i].SetRange(0, 255);
00187         }
00188                 
00189         m_linkalphasliders = FALSE;
00190 
00191         UpdateData(FALSE);
00192 
00193         CreateToolTip();
00194 
00195         return TRUE;  // return TRUE unless you set the focus to a control
00196         // EXCEPTION: OCX Property Pages should return FALSE
00197 }
00198 
00199 BOOL CPPageSubStyle::OnApply()
00200 {
00201         UpdateData();
00202 
00203         if(m_iCharset >= 0) m_stss.charSet = m_charset.GetItemData(m_iCharset);
00204         m_stss.fontSpacing = m_spacing;
00205         m_stss.fontAngleZ = m_angle;
00206         m_stss.fontScaleX = m_scalex;
00207         m_stss.fontScaleY = m_scaley;
00208 
00209         m_stss.borderStyle = m_borderstyle;
00210         m_stss.outlineWidth = m_borderwidth;
00211         m_stss.shadowDepth = m_shadowdepth;
00212 
00213         m_stss.scrAlignment = m_screenalignment+1;
00214         m_stss.marginRect = m_margin;
00215         m_stss.relativeTo = m_relativeTo;
00216 
00217         for(int i = 0; i < 4; i++) m_stss.alpha[i] = 255-m_alpha[i];
00218 
00219         if(m_fUseDefaultStyle)
00220         {
00221                 STSStyle& stss = AfxGetAppSettings().subdefstyle;
00222                 if(!(stss == m_stss))
00223                 {
00224                         stss = m_stss;
00225                         if(CMainFrame* pFrame = dynamic_cast<CMainFrame*>(AfxGetMainWnd()))
00226                                 pFrame->UpdateSubtitle(true);
00227                 }
00228         }
00229 
00230         return __super::OnApply();
00231 }
00232 
00233 void CPPageSubStyle::OnBnClickedButton1()
00234 {
00235         LOGFONT lf;
00236         lf <<= m_stss;
00237 
00238         CFontDialog dlg(&lf, CF_SCREENFONTS|CF_INITTOLOGFONTSTRUCT|CF_FORCEFONTEXIST|CF_SCALABLEONLY|CF_EFFECTS);
00239         if(dlg.DoModal() == IDOK)
00240         {
00241                 CString str(lf.lfFaceName);
00242                 if(str.GetLength() > 16) str = str.Left(14) + _T("...");
00243                 m_font.SetWindowText(str);
00244 
00245                 for(int i = 0, j = m_charset.GetCount(); i < j; i++)
00246                 {
00247                         if(m_charset.GetItemData(i) == lf.lfCharSet)
00248                         {
00249                                 m_charset.SetCurSel(i);
00250                                 break;
00251                         }
00252                 }
00253 
00254                 m_stss = lf;
00255 
00256                 SetModified();
00257         }
00258 }
00259 
00260 void CPPageSubStyle::OnStnClickedColorpri()
00261 {
00262         AskColor(0);
00263 }
00264 
00265 void CPPageSubStyle::OnStnClickedColorsec()
00266 {
00267         AskColor(1);
00268 }
00269 
00270 void CPPageSubStyle::OnStnClickedColoroutl()
00271 {
00272         AskColor(2);
00273 }
00274 
00275 void CPPageSubStyle::OnStnClickedColorshad()
00276 {
00277         AskColor(3);
00278 }
00279 
00280 void CPPageSubStyle::OnBnClickedCheck1()
00281 {
00282         UpdateData();
00283 
00284         int avg = 0;
00285         for(int i = 0; i < 4; i++) avg += m_alphasliders[i].GetPos();
00286         avg /= 4;
00287         for(int i = 0; i < 4; i++) m_alphasliders[i].SetPos(avg);
00288 
00289         SetModified();
00290 }
00291 
00292 void CPPageSubStyle::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
00293 {
00294         if(m_linkalphasliders && pScrollBar)
00295         {
00296                 int pos = ((CSliderCtrl*)pScrollBar)->GetPos();
00297                 for(int i = 0; i < 4; i++) m_alphasliders[i].SetPos(pos);
00298         }
00299         
00300         SetModified();
00301 
00302         __super::OnHScroll(nSBCode, nPos, pScrollBar);
00303 }

Generated on Tue Dec 13 14:47:02 2005 for guliverkli by  doxygen 1.4.5