-
Notifications
You must be signed in to change notification settings - Fork 2
/
EditStyleDlg.cpp
163 lines (132 loc) · 4.38 KB
/
EditStyleDlg.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/*
This file is part of Tibia Map Viewer.
Copyright (c) 2001-2006 by Yury Sidorov.
Tibia Map Viewer is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Tibia Map Viewer is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Tibia Map Viewer; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
// EditStyleDlg.cpp : implementation file
//
#include "stdafx.h"
#include "TMViewer.h"
#include "EditStyleDlg.h"
#include "StylesListDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CEditStyleDlg dialog
CEditStyleDlg::CEditStyleDlg(CWnd* pParent /*=NULL*/)
: CDialog(CEditStyleDlg::IDD, pParent), m_Style(&m_Content),
m_SampleText(m_Content)
{
//{{AFX_DATA_INIT(CEditStyleDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
void CEditStyleDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CEditStyleDlg)
DDX_Control(pDX, IDC_chkShadow, m_Shadow);
DDX_Control(pDX, IDC_edFontName, m_FontName);
DDX_Control(pDX, IDC_edStyleName, m_StyleName);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CEditStyleDlg, CDialog)
//{{AFX_MSG_MAP(CEditStyleDlg)
ON_BN_CLICKED(IDC_btChangeFont, OnbtChangeFont)
ON_WM_PAINT()
ON_BN_CLICKED(IDC_chkShadow, OnchkShadow)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CEditStyleDlg message handlers
BOOL CEditStyleDlg::OnInitDialog()
{
CDialog::OnInitDialog();
if (!m_Caption.IsEmpty())
SetWindowText(m_Caption);
m_StyleName.SetWindowText(m_Style.GetStyleName());
m_FontName.SetWindowText(GetFontStr());
m_Shadow.SetCheck(m_Style.Shadow);
m_Style.SetZoom();
m_SampleText.Style = &m_Style;
m_SampleText.SetText("Sample text");
CRect r;
GetDlgItem(IDC_FRAME)->GetWindowRect(m_SampleRect);
ScreenToClient(m_SampleRect);
m_Shadow.GetWindowRect(r);
ScreenToClient(r);
m_SampleRect.top = r.bottom;
m_SampleRect.DeflateRect(13, 13);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CEditStyleDlg::OnbtChangeFont()
{
LOGFONT lf;
m_Style.Font.GetLogFont(&lf);
CFontDialog fd(&lf, CF_TTONLY | CF_EFFECTS | CF_FORCEFONTEXIST | CF_INITTOLOGFONTSTRUCT | CF_SCREENFONTS, NULL, this);
fd.m_cf.rgbColors = m_Style.TextColor;
if (fd.DoModal() == IDOK) {
BYTE fs = 0;
if (fd.IsBold())
fs |= fsBold;
if (fd.IsItalic())
fs |= fsItalic;
if (fd.IsUnderline())
fs |= fsUnderline;
m_Style.FontName = fd.GetFaceName();
m_Style.FontSize = fd.GetSize()/10;
m_Style.FontStyle = fs;
m_Style.FontCharSet = lf.lfCharSet;
m_Style.TextColor = fd.GetColor();
m_Style.SetZoom();
m_FontName.SetWindowText(GetFontStr());
m_SampleText.SetText(m_SampleText.GetText());
InvalidateRect(m_SampleRect, FALSE);
}
}
CString CEditStyleDlg::GetFontStr()
{
CString res, s;
if (!m_Style.FontName.IsEmpty()) {
if (m_Style.FontStyle & fsBold)
s += ", Bold";
if (m_Style.FontStyle & fsItalic)
s += ", Italic";
if (m_Style.FontStyle & fsUnderline)
s += ", Underline";
res.Format("%s, %d%s", m_Style.FontName, m_Style.FontSize, s);
}
return res;
}
void CEditStyleDlg::OnOK()
{
CString s;
m_StyleName.GetWindowText(s);
m_Style.SetStyleName(s);
CDialog::OnOK();
}
void CEditStyleDlg::OnPaint()
{
CPaintDC dc(this); // device context for painting
DrawSample(dc, m_SampleRect, m_SampleText, FALSE);
}
void CEditStyleDlg::OnchkShadow()
{
m_Style.Shadow = m_Shadow.GetCheck();
m_SampleText.SetText(m_SampleText.GetText());
InvalidateRect(m_SampleRect, FALSE);
}