- Main Page
- Namespaces
- Classes
- Files
- Directories

- File List
- File Members

# StyleEditorDialog.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 // StyleEditorDialog.cpp : implementation file
    00023 //
    00024
    00025 #include "stdafx.h"
    00026 #include <math.h>
    00027 #include <afxdlgs.h>
    00028 #include "StyleEditorDialog.h"
    00029
    00030 IMPLEMENT_DYNAMIC(CColorStatic, CStatic)
    00031
    00032 BEGIN_MESSAGE_MAP(CColorStatic, CStatic)
    00033 END_MESSAGE_MAP()
    00034
    00035
    00036 // CStyleEditorDialog dialog
    00037
    00038 IMPLEMENT_DYNAMIC(CStyleEditorDialog, CDialog)
    00039 CStyleEditorDialog::CStyleEditorDialog(CString title, STSStyle* pstss, CWnd* pParent /*=NULL*/)
    00040         : CDialog(CStyleEditorDialog::IDD, pParent)
    00041         , m_title(title)
    00042         , m_stss(*pstss)
    00043         , m_pParent(pParent)
    00044         , m_iCharset(0)
    00045         , m_spacing(0)
    00046         , m_angle(0)
    00047         , m_scalex(0)
    00048         , m_scaley(0)
    00049         , m_borderstyle(0)
    00050         , m_borderwidth(0)
    00051         , m_shadowdepth(0)
    00052         , m_screenalignment(0)
    00053         , m_margin(0,0,0,0)
    00054         , m_linkalphasliders(FALSE)
    00055 {
    00056 }
    00057
    00058 CStyleEditorDialog::~CStyleEditorDialog()
    00059 {
    00060 }
    00061
    00062 void CStyleEditorDialog::DoDataExchange(CDataExchange* pDX)
    00063 {
    00064         CDialog::DoDataExchange(pDX);
    00065         DDX_Control(pDX, IDC_BUTTON1, m_font);
    00066         DDX_CBIndex(pDX, IDC_COMBO1, m_iCharset);
    00067         DDX_Control(pDX, IDC_COMBO1, m_charset);
    00068         DDX_Text(pDX, IDC_EDIT3, m_spacing);
    00069         DDX_Control(pDX, IDC_SPIN3, m_spacingspin);
    00070         DDX_Text(pDX, IDC_EDIT11, m_angle);
    00071         DDX_Control(pDX, IDC_SPIN10, m_anglespin);
    00072         DDX_Text(pDX, IDC_EDIT5, m_scalex);
    00073         DDX_Control(pDX, IDC_SPIN4, m_scalexspin);
    00074         DDX_Text(pDX, IDC_EDIT6, m_scaley);
    00075         DDX_Control(pDX, IDC_SPIN5, m_scaleyspin);
    00076         DDX_Radio(pDX, IDC_RADIO1, m_borderstyle);
    00077         DDX_Text(pDX, IDC_EDIT1, m_borderwidth);
    00078         DDX_Control(pDX, IDC_SPIN1, m_borderwidthspin);
    00079         DDX_Text(pDX, IDC_EDIT2, m_shadowdepth);
    00080         DDX_Control(pDX, IDC_SPIN2, m_shadowdepthspin);
    00081         DDX_Radio(pDX, IDC_RADIO3, m_screenalignment);
    00082         DDX_Text(pDX, IDC_EDIT7, m_margin.left);
    00083         DDX_Control(pDX, IDC_SPIN6, m_marginleftspin);
    00084         DDX_Text(pDX, IDC_EDIT8, m_margin.right);
    00085         DDX_Control(pDX, IDC_SPIN7, m_marginrightspin);
    00086         DDX_Text(pDX, IDC_EDIT9, m_margin.top);
    00087         DDX_Control(pDX, IDC_SPIN8, m_margintopspin);
    00088         DDX_Text(pDX, IDC_EDIT10, m_margin.bottom);
    00089         DDX_Control(pDX, IDC_SPIN9, m_marginbottomspin);
    00090         DDX_Control(pDX, IDC_COLORPRI, m_color[0]);
    00091         DDX_Control(pDX, IDC_COLORSEC, m_color[1]);
    00092         DDX_Control(pDX, IDC_COLOROUTL, m_color[2]);
    00093         DDX_Control(pDX, IDC_COLORSHAD, m_color[3]);
    00094         DDX_Slider(pDX, IDC_SLIDER2, m_alpha[0]);
    00095         DDX_Slider(pDX, IDC_SLIDER3, m_alpha[1]);
    00096         DDX_Slider(pDX, IDC_SLIDER5, m_alpha[2]);
    00097         DDX_Slider(pDX, IDC_SLIDER6, m_alpha[3]);
    00098         DDX_Control(pDX, IDC_SLIDER2, m_alphasliders[0]);
    00099         DDX_Control(pDX, IDC_SLIDER3, m_alphasliders[1]);
    00100         DDX_Control(pDX, IDC_SLIDER5, m_alphasliders[2]);
    00101         DDX_Control(pDX, IDC_SLIDER6, m_alphasliders[3]);
    00102         DDX_Check(pDX, IDC_CHECK1, m_linkalphasliders);
    00103 }
    00104
    00105 void CStyleEditorDialog::UpdateControlData(bool fSave)
    00106 {
    00107         if(fSave)
    00108         {
    00109                 UpdateData();
    00110
    00111                 if(m_iCharset >= 0) m_stss.charSet = m_charset.GetItemData(m_iCharset);
    00112                 m_stss.fontSpacing = m_spacing;
    00113                 m_stss.fontAngleZ = m_angle;
    00114                 m_stss.fontScaleX = m_scalex;
    00115                 m_stss.fontScaleY = m_scaley;
    00116
    00117                 m_stss.borderStyle = m_borderstyle;
    00118                 m_stss.outlineWidth = m_borderwidth;
    00119                 m_stss.shadowDepth = m_shadowdepth;
    00120
    00121                 m_stss.scrAlignment = m_screenalignment+1;
    00122                 m_stss.marginRect = m_margin;
    00123
    00124                 for(int i = 0; i < 4; i++) m_stss.alpha[i] = 255-m_alpha[i];
    00125         }
    00126         else
    00127         {
    00128                 m_font.SetWindowText(m_stss.fontName);
    00129                 m_iCharset = -1;
    00130                 for(int i = 0; i < CharSetLen; i++)
    00131                 {
    00132                         CString str;
    00133                         str.Format(_T("%s (%d)"), CharSetNames[i], CharSetList[i]);
    00134                         m_charset.AddString(str);
    00135                         m_charset.SetItemData(i, CharSetList[i]);
    00136                         if(m_stss.charSet == CharSetList[i]) m_iCharset = i;
    00137                 }
    00138                 // TODO: allow floats in these edit boxes
    00139                 m_spacing = m_stss.fontSpacing;
    00140                 m_spacingspin.SetRange32(-10000, 10000);
    00141                 while(m_stss.fontAngleZ < 0) m_stss.fontAngleZ += 360;
    00142                 m_angle = fmod(m_stss.fontAngleZ, 360);
    00143                 m_anglespin.SetRange32(0, 359);
    00144                 m_scalex = m_stss.fontScaleX;
    00145                 m_scalexspin.SetRange32(-10000, 10000);
    00146                 m_scaley = m_stss.fontScaleY;
    00147                 m_scaleyspin.SetRange32(-10000, 10000);
    00148
    00149                 m_borderstyle = m_stss.borderStyle;
    00150                 m_borderwidth = m_stss.outlineWidth;
    00151                 m_borderwidthspin.SetRange32(0, 10000);
    00152                 m_shadowdepth = m_stss.shadowDepth;
    00153                 m_shadowdepthspin.SetRange32(0, 10000);
    00154
    00155                 m_screenalignment = m_stss.scrAlignment-1;
    00156                 m_margin = m_stss.marginRect;
    00157                 m_marginleftspin.SetRange32(-10000, 10000);
    00158                 m_marginrightspin.SetRange32(-10000, 10000);
    00159                 m_margintopspin.SetRange32(-10000, 10000);
    00160                 m_marginbottomspin.SetRange32(-10000, 10000);
    00161
    00162                 for(int i = 0; i < 4; i++)
    00163                 {
    00164                         m_color[i].SetColorPtr(&m_stss.colors[i]);
    00165                         m_alpha[i] = 255-m_stss.alpha[i];
    00166                         m_alphasliders[i].SetRange(0, 255);
    00167                 }
    00168
    00169                 m_linkalphasliders = FALSE;
    00170
    00171                 UpdateData(FALSE);
    00172         }
    00173 }
    00174
    00175 void CStyleEditorDialog::AskColor(int i)
    00176 {
    00177         CColorDialog dlg(m_stss.colors[i]);
    00178         dlg.m_cc.Flags |= CC_FULLOPEN;
    00179         if(dlg.DoModal() == IDOK)
    00180         {
    00181                 m_stss.colors[i] = dlg.m_cc.rgbResult;
    00182                 m_color[i].Invalidate();
    00183         }
    00184 }
    00185
    00186 BEGIN_MESSAGE_MAP(CStyleEditorDialog, CDialog)
    00187         ON_BN_CLICKED(IDC_BUTTON1, OnBnClickedButton1)
    00188         ON_STN_CLICKED(IDC_COLORPRI, OnStnClickedColorpri)
    00189         ON_STN_CLICKED(IDC_COLORSEC, OnStnClickedColorsec)
    00190         ON_STN_CLICKED(IDC_COLOROUTL, OnStnClickedColoroutl)
    00191         ON_STN_CLICKED(IDC_COLORSHAD, OnStnClickedColorshad)
    00192         ON_BN_CLICKED(IDC_CHECK1, OnBnClickedCheck1)
    00193         ON_WM_HSCROLL()
    00194 END_MESSAGE_MAP()
    00195
    00196
    00197 // CStyleEditorDialog message handlers
    00198
    00199 BOOL CStyleEditorDialog::OnInitDialog()
    00200 {
    00201         CDialog::OnInitDialog();
    00202
    00203         SetWindowText(_T("Style Editor - \"") + m_title + _T("\""));
    00204
    00205         UpdateControlData(false);
    00206
    00207         return TRUE;  // return TRUE unless you set the focus to a control
    00208         // EXCEPTION: OCX Property Pages should return FALSE
    00209 }
    00210
    00211 void CStyleEditorDialog::OnOK()
    00212 {
    00213         UpdateControlData(true);
    00214
    00215         CDialog::OnOK();
    00216 }
    00217
    00218 void CStyleEditorDialog::OnBnClickedButton1()
    00219 {
    00220         LOGFONT lf;
    00221         lf <<= m_stss;
    00222
    00223         CFontDialog dlg(&lf, CF_SCREENFONTS|CF_INITTOLOGFONTSTRUCT|CF_FORCEFONTEXIST|CF_SCALABLEONLY|CF_EFFECTS);
    00224         if(dlg.DoModal() == IDOK)
    00225         {
    00226                 CString str(lf.lfFaceName);
    00227                 if(str.GetLength() > 16) str = str.Left(14) + _T("...");
    00228                 m_font.SetWindowText(str);
    00229
    00230                 for(int i = 0, j = m_charset.GetCount(); i < j; i++)
    00231                 {
    00232                         if(m_charset.GetItemData(i) == lf.lfCharSet)
    00233                         {
    00234                                 m_charset.SetCurSel(i);
    00235                                 break;
    00236                         }
    00237                 }
    00238
    00239                 m_stss = lf;
    00240         }
    00241 }
    00242
    00243 void CStyleEditorDialog::OnStnClickedColorpri()
    00244 {
    00245         AskColor(0);
    00246 }
    00247
    00248 void CStyleEditorDialog::OnStnClickedColorsec()
    00249 {
    00250         AskColor(1);
    00251 }
    00252
    00253 void CStyleEditorDialog::OnStnClickedColoroutl()
    00254 {
    00255         AskColor(2);
    00256 }
    00257
    00258 void CStyleEditorDialog::OnStnClickedColorshad()
    00259 {
    00260         AskColor(3);
    00261 }
    00262
    00263 void CStyleEditorDialog::OnBnClickedCheck1()
    00264 {
    00265         UpdateData();
    00266
    00267         int avg = 0;
    00268         for(int i = 0; i < 4; i++) avg += m_alphasliders[i].GetPos();
    00269         avg /= 4;
    00270         for(int i = 0; i < 4; i++) m_alphasliders[i].SetPos(avg);
    00271 }
    00272
    00273 void CStyleEditorDialog::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
    00274 {
    00275         if(m_linkalphasliders && pScrollBar)
    00276         {
    00277                 int pos = ((CSliderCtrl*)pScrollBar)->GetPos();
    00278                 for(int i = 0; i < 4; i++) m_alphasliders[i].SetPos(pos);
    00279         }
    00280
    00281         CDialog::OnHScroll(nSBCode, nPos, pScrollBar);
    00282 }