Support unrar64.dll
[xy_vsfilter.git] / src / apps / mplayerc / PPageSubStyle.cpp
blob71a982a40f3c77117a289d0a89c0b58cb30440c7
1 /*
2 * Copyright (C) 2003-2006 Gabest
3 * http://www.gabest.org
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
8 * any later version.
9 *
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with GNU Make; see the file COPYING. If not, write to
17 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
18 * http://www.gnu.org/copyleft/gpl.html
22 // PPageSubStyle.cpp : implementation file
25 #include "stdafx.h"
26 #include <math.h>
27 #include "mplayerc.h"
28 #include "MainFrm.h"
29 #include "PPageSubStyle.h"
31 // CColorStatic
33 //IMPLEMENT_DYNAMIC(CColorStatic, CStatic)
35 //BEGIN_MESSAGE_MAP(CColorStatic, CStatic)
36 //END_MESSAGE_MAP()
38 // CPPageSubStyle dialog
40 IMPLEMENT_DYNAMIC(CPPageSubStyle, CPPageBase)
41 CPPageSubStyle::CPPageSubStyle()
42 : CPPageBase(CPPageSubStyle::IDD, CPPageSubStyle::IDD)
43 , m_iCharset(0)
44 , m_spacing(0)
45 , m_angle(0)
46 , m_scalex(0)
47 , m_scaley(0)
48 , m_borderstyle(0)
49 , m_borderwidth(0)
50 , m_shadowdepth(0)
51 , m_screenalignment(0)
52 , m_margin(0,0,0,0)
53 , m_linkalphasliders(FALSE)
54 , m_relativeTo(FALSE)
56 m_stss = AfxGetAppSettings().subdefstyle;
57 m_fUseDefaultStyle = true;
60 CPPageSubStyle::~CPPageSubStyle()
64 void CPPageSubStyle::InitStyle(CString title, STSStyle& stss)
66 m_pPSP->pszTitle = (m_title = title);
67 m_psp.dwFlags |= PSP_USETITLE;
69 m_stss = stss;
70 m_fUseDefaultStyle = false;
73 void CPPageSubStyle::AskColor(int i)
75 CColorDialog dlg(m_stss.colors[i]);
76 dlg.m_cc.Flags |= CC_FULLOPEN;
77 if(dlg.DoModal() == IDOK)
79 m_stss.colors[i] = dlg.m_cc.rgbResult;
80 m_color[i].Invalidate();
84 void CPPageSubStyle::DoDataExchange(CDataExchange* pDX)
86 CPPageBase::DoDataExchange(pDX);
87 DDX_Control(pDX, IDC_BUTTON1, m_font);
88 DDX_CBIndex(pDX, IDC_COMBO1, m_iCharset);
89 DDX_Control(pDX, IDC_COMBO1, m_charset);
90 DDX_Text(pDX, IDC_EDIT3, m_spacing);
91 DDX_Control(pDX, IDC_SPIN3, m_spacingspin);
92 DDX_Text(pDX, IDC_EDIT4, m_angle);
93 DDX_Control(pDX, IDC_SPIN10, m_anglespin);
94 DDX_Text(pDX, IDC_EDIT5, m_scalex);
95 DDX_Control(pDX, IDC_SPIN4, m_scalexspin);
96 DDX_Text(pDX, IDC_EDIT6, m_scaley);
97 DDX_Control(pDX, IDC_SPIN5, m_scaleyspin);
98 DDX_Radio(pDX, IDC_RADIO1, m_borderstyle);
99 DDX_Text(pDX, IDC_EDIT1, m_borderwidth);
100 DDX_Control(pDX, IDC_SPIN1, m_borderwidthspin);
101 DDX_Text(pDX, IDC_EDIT2, m_shadowdepth);
102 DDX_Control(pDX, IDC_SPIN2, m_shadowdepthspin);
103 DDX_Radio(pDX, IDC_RADIO3, m_screenalignment);
104 DDX_Text(pDX, IDC_EDIT7, m_margin.left);
105 DDX_Control(pDX, IDC_SPIN6, m_marginleftspin);
106 DDX_Text(pDX, IDC_EDIT8, m_margin.right);
107 DDX_Control(pDX, IDC_SPIN7, m_marginrightspin);
108 DDX_Text(pDX, IDC_EDIT9, m_margin.top);
109 DDX_Control(pDX, IDC_SPIN8, m_margintopspin);
110 DDX_Text(pDX, IDC_EDIT10, m_margin.bottom);
111 DDX_Control(pDX, IDC_SPIN9, m_marginbottomspin);
112 DDX_Control(pDX, IDC_COLORPRI, m_color[0]);
113 DDX_Control(pDX, IDC_COLORSEC, m_color[1]);
114 DDX_Control(pDX, IDC_COLOROUTL, m_color[2]);
115 DDX_Control(pDX, IDC_COLORSHAD, m_color[3]);
116 DDX_Slider(pDX, IDC_SLIDER1, m_alpha[0]);
117 DDX_Slider(pDX, IDC_SLIDER2, m_alpha[1]);
118 DDX_Slider(pDX, IDC_SLIDER3, m_alpha[2]);
119 DDX_Slider(pDX, IDC_SLIDER4, m_alpha[3]);
120 DDX_Control(pDX, IDC_SLIDER1, m_alphasliders[0]);
121 DDX_Control(pDX, IDC_SLIDER2, m_alphasliders[1]);
122 DDX_Control(pDX, IDC_SLIDER3, m_alphasliders[2]);
123 DDX_Control(pDX, IDC_SLIDER4, m_alphasliders[3]);
124 DDX_Check(pDX, IDC_CHECK1, m_linkalphasliders);
125 DDX_Check(pDX, IDC_CHECK_RELATIVETO, m_relativeTo);
129 BEGIN_MESSAGE_MAP(CPPageSubStyle, CPPageBase)
130 ON_BN_CLICKED(IDC_BUTTON1, OnBnClickedButton1)
131 ON_STN_CLICKED(IDC_COLORPRI, OnStnClickedColorpri)
132 ON_STN_CLICKED(IDC_COLORSEC, OnStnClickedColorsec)
133 ON_STN_CLICKED(IDC_COLOROUTL, OnStnClickedColoroutl)
134 ON_STN_CLICKED(IDC_COLORSHAD, OnStnClickedColorshad)
135 ON_BN_CLICKED(IDC_CHECK1, OnBnClickedCheck1)
136 ON_WM_HSCROLL()
137 END_MESSAGE_MAP()
140 // CPPageSubStyle message handlers
142 BOOL CPPageSubStyle::OnInitDialog()
144 __super::OnInitDialog();
146 m_font.SetWindowText(m_stss.fontName);
147 m_iCharset = -1;
148 for(int i = 0; i < CharSetLen; i++)
150 CString str;
151 str.Format(_T("%s (%d)"), CharSetNames[i], CharSetList[i]);
152 m_charset.AddString(str);
153 m_charset.SetItemData(i, CharSetList[i]);
154 if(m_stss.charSet == CharSetList[i]) m_iCharset = i;
157 // TODO: allow floats in these edit boxes
158 m_spacing = (int)m_stss.fontSpacing;
159 m_spacingspin.SetRange32(-10000, 10000);
160 while(m_stss.fontAngleZ < 0) m_stss.fontAngleZ += 360;
161 m_angle = (int)fmod(m_stss.fontAngleZ, 360);
162 m_anglespin.SetRange32(0, 359);
163 m_scalex = (int)m_stss.fontScaleX;
164 m_scalexspin.SetRange32(-10000, 10000);
165 m_scaley = (int)m_stss.fontScaleY;
166 m_scaleyspin.SetRange32(-10000, 10000);
168 m_borderstyle = m_stss.borderStyle;
169 m_borderwidth = min(m_stss.outlineWidthX, m_stss.outlineWidthY);
170 m_borderwidthspin.SetRange32(0, 10000);
171 m_shadowdepth = min(m_stss.shadowDepthX, m_stss.shadowDepthY);
172 m_shadowdepthspin.SetRange32(0, 10000);
174 m_screenalignment = m_stss.scrAlignment-1;
175 m_margin = m_stss.marginRect;
176 m_marginleftspin.SetRange32(-10000, 10000);
177 m_marginrightspin.SetRange32(-10000, 10000);
178 m_margintopspin.SetRange32(-10000, 10000);
179 m_marginbottomspin.SetRange32(-10000, 10000);
180 m_relativeTo = m_stss.relativeTo;
182 for(int i = 0; i < 4; i++)
184 m_color[i].SetColorPtr(&m_stss.colors[i]);
185 m_alpha[i] = 255-m_stss.alpha[i];
186 m_alphasliders[i].SetRange(0, 255);
189 m_linkalphasliders = FALSE;
191 UpdateData(FALSE);
193 CreateToolTip();
195 return TRUE; // return TRUE unless you set the focus to a control
196 // EXCEPTION: OCX Property Pages should return FALSE
199 BOOL CPPageSubStyle::OnApply()
201 UpdateData();
203 if(m_iCharset >= 0) m_stss.charSet = m_charset.GetItemData(m_iCharset);
204 m_stss.fontSpacing = m_spacing;
205 m_stss.fontAngleZ = m_angle;
206 m_stss.fontScaleX = m_scalex;
207 m_stss.fontScaleY = m_scaley;
209 m_stss.borderStyle = m_borderstyle;
210 m_stss.outlineWidthX = m_stss.outlineWidthY = m_borderwidth;
211 m_stss.shadowDepthX = m_stss.shadowDepthY = m_shadowdepth;
213 m_stss.scrAlignment = m_screenalignment+1;
214 m_stss.marginRect = m_margin;
215 m_stss.relativeTo = m_relativeTo;
217 for(int i = 0; i < 4; i++) m_stss.alpha[i] = 255-m_alpha[i];
219 if(m_fUseDefaultStyle)
221 STSStyle& stss = AfxGetAppSettings().subdefstyle;
222 if(!(stss == m_stss))
224 stss = m_stss;
225 if(CMainFrame* pFrame = dynamic_cast<CMainFrame*>(AfxGetMainWnd()))
226 pFrame->UpdateSubtitle(true);
230 return __super::OnApply();
233 void CPPageSubStyle::OnBnClickedButton1()
235 LOGFONT lf;
236 lf <<= m_stss;
238 CFontDialog dlg(&lf, CF_SCREENFONTS|CF_INITTOLOGFONTSTRUCT|CF_FORCEFONTEXIST|CF_SCALABLEONLY|CF_EFFECTS);
239 if(dlg.DoModal() == IDOK)
241 CString str(lf.lfFaceName);
242 if(str.GetLength() > 16) str = str.Left(14) + _T("...");
243 m_font.SetWindowText(str);
245 for(int i = 0, j = m_charset.GetCount(); i < j; i++)
247 if(m_charset.GetItemData(i) == lf.lfCharSet)
249 m_charset.SetCurSel(i);
250 break;
254 m_stss = lf;
256 SetModified();
260 void CPPageSubStyle::OnStnClickedColorpri()
262 AskColor(0);
265 void CPPageSubStyle::OnStnClickedColorsec()
267 AskColor(1);
270 void CPPageSubStyle::OnStnClickedColoroutl()
272 AskColor(2);
275 void CPPageSubStyle::OnStnClickedColorshad()
277 AskColor(3);
280 void CPPageSubStyle::OnBnClickedCheck1()
282 UpdateData();
284 int avg = 0;
285 for(int i = 0; i < 4; i++) avg += m_alphasliders[i].GetPos();
286 avg /= 4;
287 for(int i = 0; i < 4; i++) m_alphasliders[i].SetPos(avg);
289 SetModified();
292 void CPPageSubStyle::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
294 if(m_linkalphasliders && pScrollBar)
296 int pos = ((CSliderCtrl*)pScrollBar)->GetPos();
297 for(int i = 0; i < 4; i++) m_alphasliders[i].SetPos(pos);
300 SetModified();
302 __super::OnHScroll(nSBCode, nPos, pScrollBar);