-
Notifications
You must be signed in to change notification settings - Fork 1
/
XPMImagePropertiesPanel.cpp
432 lines (362 loc) · 15.7 KB
/
XPMImagePropertiesPanel.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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
/***************************************************************
* Plugin: XPMEditor for Code::Blocks
* Name: XPMImagePropertiesPanel.cpp
* Purpose: A panel containing the image properties: size, file format, compression, resolution - code
* Author: Seb ([email protected])
* Created: 2010-05-19
* Copyright: Seb ()
* License: GPL 3.0
**************************************************************/
#include "AdvancedOptions.h"
#include "XPMEditor.h"
#include "XPMImagePropertiesPanel.h"
#include "XPMEditorPanel.h"
#define ID_FIRST_HELP 46
//#include <sdk.h>
//(*InternalHeaders(XPMImagePropertiesPanel)
#include <wx/intl.h>
#include <wx/string.h>
//*)
//(*IdInit(XPMImagePropertiesPanel)
const long XPMImagePropertiesPanel::ID_SPINCTRL1 = wxNewId();
const long XPMImagePropertiesPanel::ID_STATICTEXT1 = wxNewId();
const long XPMImagePropertiesPanel::ID_SPINCTRL2 = wxNewId();
const long XPMImagePropertiesPanel::ID_CHOICE1 = wxNewId();
const long XPMImagePropertiesPanel::ID_BUTTON1 = wxNewId();
//*)
BEGIN_EVENT_TABLE(XPMImagePropertiesPanel,wxPanel)
//(*EventTable(XPMImagePropertiesPanel)
//*)
END_EVENT_TABLE()
XPMImagePropertiesPanel::XPMImagePropertiesPanel(wxWindow* parent,wxWindowID id,const wxPoint& pos,const wxSize& size)
{
//(*Initialize(XPMImagePropertiesPanel)
wxBoxSizer* BoxSizer8;
Create(parent, id, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL, _T("id"));
BoxSizer8 = new wxBoxSizer(wxVERTICAL);
StaticBoxSizer1 = new wxStaticBoxSizer(wxVERTICAL, this, _("Width x Heigth"));
BMPWidth = new wxSpinCtrl(this, ID_SPINCTRL1, _T("0"), wxDefaultPosition, wxSize(82,21), 0, 0, 10000, 0, _T("ID_SPINCTRL1"));
BMPWidth->SetValue(_T("0"));
BMPWidth->SetToolTip(_("Width of the image, in pixels."));
StaticBoxSizer1->Add(BMPWidth, 0, wxALL|wxEXPAND, 2);
StaticText1 = new wxStaticText(this, ID_STATICTEXT1, _("x"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT1"));
StaticBoxSizer1->Add(StaticText1, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 2);
BMPHeight = new wxSpinCtrl(this, ID_SPINCTRL2, _T("0"), wxDefaultPosition, wxSize(65,21), 0, 0, 10000, 0, _T("ID_SPINCTRL2"));
BMPHeight->SetValue(_T("0"));
BMPHeight->SetToolTip(_("Height of the image, in pixels."));
StaticBoxSizer1->Add(BMPHeight, 0, wxALL|wxEXPAND, 2);
BoxSizer8->Add(StaticBoxSizer1, 0, wxALL|wxEXPAND, 2);
StaticBoxSizer2 = new wxStaticBoxSizer(wxVERTICAL, this, _("Format"));
Choice1 = new wxChoice(this, ID_CHOICE1, wxDefaultPosition, wxSize(69,21), 0, 0, 0, wxDefaultValidator, _T("ID_CHOICE1"));
Choice1->SetToolTip(_("Select a format for saving the image. \n\"Automatic\" means that the format will be decided based on the file extension (*.jpg is a JPEG, *.png is a PNG, ...). \nAnother format will force the editor to use this format, whatever the file extension is."));
StaticBoxSizer2->Add(Choice1, 0, wxALL|wxEXPAND, 2);
Button1 = new wxButton(this, ID_BUTTON1, _("Advanced"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON1"));
Button1->SetToolTip(_("Advanced images options (compression, resolution, ...)"));
StaticBoxSizer2->Add(Button1, 0, wxALL|wxEXPAND, 2);
BoxSizer8->Add(StaticBoxSizer2, 0, wxALL|wxEXPAND, 2);
SetSizer(BoxSizer8);
BoxSizer8->Fit(this);
BoxSizer8->SetSizeHints(this);
Connect(ID_SPINCTRL1,wxEVT_COMMAND_SPINCTRL_UPDATED,(wxObjectEventFunction)&XPMImagePropertiesPanel::OnImageSizeChanged);
Connect(ID_SPINCTRL2,wxEVT_COMMAND_SPINCTRL_UPDATED,(wxObjectEventFunction)&XPMImagePropertiesPanel::OnImageSizeChanged);
Connect(ID_CHOICE1,wxEVT_COMMAND_CHOICE_SELECTED,(wxObjectEventFunction)&XPMImagePropertiesPanel::OnImageTypeChanged);
Connect(ID_BUTTON1,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&XPMImagePropertiesPanel::OnButtonAdvancedPropClick);
//*)
//help handlers
BMPWidth->Connect(wxEVT_ENTER_WINDOW,(wxObjectEventFunction)&XPMImagePropertiesPanel::OnWidthWidgetsMouseEnter,0,this);
BMPWidth->Connect(wxEVT_LEAVE_WINDOW,(wxObjectEventFunction)&XPMImagePropertiesPanel::OnWidgetsMouseLeave,0,this);
BMPHeight->Connect(wxEVT_ENTER_WINDOW,(wxObjectEventFunction)&XPMImagePropertiesPanel::OnHeightWidgetsMouseEnter,0,this);
BMPHeight->Connect(wxEVT_LEAVE_WINDOW,(wxObjectEventFunction)&XPMImagePropertiesPanel::OnWidgetsMouseLeave,0,this);
Choice1->Connect(wxEVT_ENTER_WINDOW,(wxObjectEventFunction)&XPMImagePropertiesPanel::OnFormatWidgetsMouseEnter,0,this);
Choice1->Connect(wxEVT_LEAVE_WINDOW,(wxObjectEventFunction)&XPMImagePropertiesPanel::OnWidgetsMouseLeave,0,this);
Button1->Connect(wxEVT_ENTER_WINDOW,(wxObjectEventFunction)&XPMImagePropertiesPanel::OnAdvancedWidgetsMouseEnter,0,this);
Button1->Connect(wxEVT_LEAVE_WINDOW,(wxObjectEventFunction)&XPMImagePropertiesPanel::OnWidgetsMouseLeave,0,this);
AppendFormatsToChoice();
m_parent = NULL;
/*
wxSize sSize;
sSize = StaticBoxSizer1->GetMinSize();
Manager::Get()->GetLogManager()->Log(wxString::Format(_("StaticBoxSizer sBestSize w=%d h=%d"), sSize.GetWidth(), sSize.GetHeight()));
sSize = StaticBoxSizer2->GetMinSize();
Manager::Get()->GetLogManager()->Log(wxString::Format(_("StaticBoxSizer2 sBestSize w=%d h=%d"), sSize.GetWidth(), sSize.GetHeight()));
*/
}
XPMImagePropertiesPanel::~XPMImagePropertiesPanel()
{
//(*Destroy(XPMImagePropertiesPanel)
//*)
}
/** Populate the wxChoice with the available formats
*/
void XPMImagePropertiesPanel::AppendFormatsToChoice(void)
{
if (XPM_Plugin())
{
XPM_Plugin()->GetFileSavingFormat(m_sFormats);
}
else
{
m_sFormats.Clear();
}
if (Choice1)
{
size_t i, iMax;
int iIndex;
Choice1->Clear();
m_iIndex.Clear();
iMax = m_sFormats.GetCount();
for(i=0;i<iMax;i++)
{
iIndex = Choice1->Append(m_sFormats.Item(i));
m_iIndex.Add(iIndex);
}
}
}
/** Set the parent panel
* \param [in] p a pointer to the new parent
*/
void XPMImagePropertiesPanel::SetParentPanel(XPMEditorPanel *p)
{
m_parent = p;
}
/** set the image saving file format in the wxChoice
* \param [in] bt : the wxBitmapType to use for saving the image
* See wxWidgets documentation for more information (keywords wxImage, wxBitmapType)
*/
void XPMImagePropertiesPanel::SetImageFormat(wxBitmapType bt)
{
if (!XPM_Plugin()) return; //nothing done
wxBitmapType bt2;
wxString sFormatString;
XPM_Plugin()->GetFileSavingFormat(m_sFormats);
if (bt == wxBITMAP_TYPE_ANY)
{
Choice1->SetStringSelection(m_sFormats.Item(0));
return;
}
bt2 = XPM_Plugin()->GetCompatibleSavingFormat(bt);
sFormatString = XPM_Plugin()->GetFormatString(bt2);
Choice1->SetStringSelection(sFormatString);
}
/** The button "ADVANCED" has been clicked.
*/
void XPMImagePropertiesPanel::OnButtonAdvancedPropClick(wxCommandEvent& event)
{
if (m_parent)
{
AdvancedOptions dao(this);
wxImage img = m_parent->GetImage();
//initialisation of the dialog box
//resolution
bool bModified, bResolution, bJPG, bPNGFormat, bPNGBitDepth;
int iResolutionUnit, iResolutionX, iResolutionY, iJPGQuality;
int iPNGBitDepth, iPNGFormat;
wxString sString;
wxString sString2;
wxString sPNGFormat;
wxString sPNGBitDepths;
bModified = false;
if ((img.HasOption(wxIMAGE_OPTION_RESOLUTIONUNIT)) || (img.HasOption(wxIMAGE_OPTION_RESOLUTIONUNIT)) || (img.HasOption(wxIMAGE_OPTION_RESOLUTIONUNIT)))
{
bResolution = true;
iResolutionUnit = img.GetOptionInt(wxIMAGE_OPTION_RESOLUTIONUNIT);
switch(iResolutionUnit)
{
case wxIMAGE_RESOLUTION_INCHES : sString = _("Inch"); break;
case wxIMAGE_RESOLUTION_CM : sString = _("Cm"); break;
#if wxCHECK_VERSION(2, 9, 0)
case wxIMAGE_RESOLUTION_NONE :
#endif
default : sString = _("Not Specified"); break;
}
iResolutionX = img.GetOptionInt(wxIMAGE_OPTION_RESOLUTIONX);
iResolutionY = img.GetOptionInt(wxIMAGE_OPTION_RESOLUTIONY);
}
else
{
bResolution = false;
iResolutionUnit = 0;
iResolutionX = 0;
iResolutionY = 0;
sString = _("Not Specified");
}
dao.ChoiceResolutionUnit->SetStringSelection(sString);
dao.SpinResolutionX->SetValue(iResolutionX);
dao.SpinResolutionY->SetValue(iResolutionY);
dao.EnableResolutionOption(bResolution);
//JPG quality
if (img.HasOption(wxIMAGE_OPTION_QUALITY))
{
iJPGQuality = img.GetOptionInt(wxIMAGE_OPTION_QUALITY);
bJPG = true;
}
else
{
iJPGQuality = 0;
bJPG = false;
}
dao.SliderJPGCompression->SetValue(iJPGQuality);
dao.EnableJPGOption(bJPG);
//PNG Format
if (img.HasOption(wxIMAGE_OPTION_PNG_FORMAT))
{
bPNGFormat = true;
iPNGFormat = img.GetOptionInt(wxIMAGE_OPTION_PNG_FORMAT);
switch(iPNGFormat)
{
case wxPNG_TYPE_COLOUR : sPNGFormat = _("0 - Colour PNG"); break;
case wxPNG_TYPE_GREY : sPNGFormat = _("2 - Grey Scale PNG"); break;
case wxPNG_TYPE_GREY_RED : sPNGFormat = _("3 - Grey Scale using Red as Grey"); break;
default : sPNGFormat = _("0 - Colour PNG"); break;
}
}
else
{
bPNGFormat = false;
iPNGFormat = wxPNG_TYPE_COLOUR;
sPNGFormat = _("0 - Colour PNG");
}
dao.ChoicePNGFormat->SetStringSelection(sPNGFormat);
dao.EnablePNGFormat(bPNGFormat);
//PNG Bit Depths
if (img.HasOption(wxIMAGE_OPTION_PNG_BITDEPTH))
{
bPNGBitDepth = true;
iPNGBitDepth = img.GetOptionInt(wxIMAGE_OPTION_PNG_BITDEPTH);
//only 8 or 16 are valid values
if (iPNGBitDepth < 16) iPNGBitDepth = 8;
if (iPNGBitDepth > 16) iPNGBitDepth = 16;
if (iPNGBitDepth == 8) sPNGBitDepths = _("8");
if (iPNGBitDepth == 16) sPNGBitDepths = _("16");
}
else
{
bPNGBitDepth = false;
iPNGBitDepth = 8;
sPNGBitDepths = _("8");
}
dao.ChoicePNGBitDepths->SetStringSelection(sPNGBitDepths);
dao.EnablePNGBitsDepth(bPNGBitDepth);
if (dao.ShowModal() == 0)
{
//set the resolution
if (dao.CheckBoxResolutionOption->IsChecked())
{
sString2 = dao.ChoiceResolutionUnit->GetStringSelection();
if ((sString2 == _("Inch")) && (sString != sString2)) img.SetOption(wxIMAGE_OPTION_RESOLUTIONUNIT, wxIMAGE_RESOLUTION_INCHES);
if ((sString2 == _("Cm")) && (sString != sString2)) img.SetOption(wxIMAGE_OPTION_RESOLUTIONUNIT, wxIMAGE_RESOLUTION_CM);
#if wxCHECK_VERSION(2, 9, 0)
if ((sString2 == _("Not Specified")) && (sString != sString2)) img.SetOption(wxIMAGE_OPTION_RESOLUTIONUNIT, wxIMAGE_RESOLUTION_NONE);
#else
if ((sString2 == _("Not Specified")) && (sString != sString2)) img.SetOption(wxIMAGE_OPTION_RESOLUTIONUNIT, wxIMAGE_RESOLUTION_INCHES);
#endif
if (sString2 != sString) bModified = true;
int iResolutionX2, iResolutionY2;
iResolutionX2 = dao.SpinResolutionX->GetValue();
iResolutionY2 = dao.SpinResolutionY->GetValue();
img.SetOption(wxIMAGE_OPTION_RESOLUTIONX, iResolutionX2);
img.SetOption(wxIMAGE_OPTION_RESOLUTIONY, iResolutionY2);
if (iResolutionX != iResolutionX2) bModified = true;
if (iResolutionY != iResolutionY2) bModified = true;
}
if (bResolution != dao.CheckBoxResolutionOption->IsChecked()) bModified = true;
//set the JPG quality
if (dao.CheckBoxJPGCompression->IsChecked())
{
int iJPGQuality2;
iJPGQuality2 = dao.SliderJPGCompression->GetValue();
img.SetOption(wxIMAGE_OPTION_QUALITY, iJPGQuality2);
if (iJPGQuality != iJPGQuality2) bModified = true;
}
if (bJPG != dao.CheckBoxJPGCompression->IsChecked()) bModified = true;
//set the PNG Format
if (dao.CheckBoxPNGFormat->IsChecked())
{
wxString sPNGFormat2;
sPNGFormat2 = dao.ChoicePNGFormat->GetStringSelection();
if ((sPNGFormat != sPNGFormat2) && (sPNGFormat2 == _("0 - Colour PNG"))) img.SetOption(wxIMAGE_OPTION_PNG_FORMAT, wxPNG_TYPE_COLOUR);
if ((sPNGFormat != sPNGFormat2) && (sPNGFormat2 == _("2 - Grey Scale PNG"))) img.SetOption(wxIMAGE_OPTION_PNG_FORMAT, wxPNG_TYPE_GREY);
if ((sPNGFormat != sPNGFormat2) && (sPNGFormat2 == _("3 - Grey Scale using Red as Grey"))) img.SetOption(wxIMAGE_OPTION_PNG_FORMAT, wxPNG_TYPE_GREY_RED);
if (sPNGFormat != sPNGFormat2) bModified = true;
}
//set the PNG Bit Depth
if (dao.CheckBoxPNGBitDepth->IsChecked())
{
wxString sPNGBitDepths2;
sPNGBitDepths2 = dao.ChoicePNGBitDepths->GetStringSelection();
if ((sPNGBitDepths != sPNGBitDepths2) && (sPNGBitDepths2 == _("8"))) img.SetOption(wxIMAGE_OPTION_PNG_BITDEPTH , 8);
if ((sPNGBitDepths != sPNGBitDepths2) && (sPNGBitDepths2 == _("16"))) img.SetOption(wxIMAGE_OPTION_PNG_BITDEPTH , 16);
if (sPNGBitDepths != sPNGBitDepths2) bModified = true;
}
if (bModified)
{
m_parent->SetModified(bModified);
m_parent->SetImage(&img);
}
}
}
}
/** The type of the image has changed (BMP, PNG, JPEG, XPM, ...)
*/
void XPMImagePropertiesPanel::OnImageTypeChanged(wxCommandEvent& event)
{
if ((m_parent) && (XPM_Plugin()))
{
wxBitmapType bt;
wxString sSelection;
sSelection = event.GetString();
bt = XPM_Plugin()->GetFormatBitmap(sSelection);
//Manager::Get()->GetLogManager()->Log(wxString::Format(_("bt=%d"), bt));
m_parent->SetImageFormat(bt);
}
}
/** The width or the height of the Image changed
*/
void XPMImagePropertiesPanel::OnImageSizeChanged(wxSpinEvent& event)
{
if (m_parent)
{
m_parent->OnImageSizeChanged(event);
}
}
/** HELP HANDLERS **/
void XPMImagePropertiesPanel::OnWidgetsMouseLeave(wxMouseEvent& event)
{
if (m_parent)
{
m_parent->DisplayHelpText(-1);
}
event.Skip();
}
void XPMImagePropertiesPanel::OnWidthWidgetsMouseEnter(wxMouseEvent& event)
{
if (m_parent)
{
m_parent->DisplayHelpText(ID_FIRST_HELP);
}
event.Skip();
}
void XPMImagePropertiesPanel::OnHeightWidgetsMouseEnter(wxMouseEvent& event)
{
if (m_parent)
{
m_parent->DisplayHelpText(ID_FIRST_HELP + 1);
}
event.Skip();
}
void XPMImagePropertiesPanel::OnFormatWidgetsMouseEnter(wxMouseEvent& event)
{
if (m_parent)
{
m_parent->DisplayHelpText(ID_FIRST_HELP + 2);
}
event.Skip();
}
void XPMImagePropertiesPanel::OnAdvancedWidgetsMouseEnter(wxMouseEvent& event)
{
if (m_parent)
{
m_parent->DisplayHelpText(ID_FIRST_HELP + 3);
}
event.Skip();
}