1 /*
2 Copyright (C) 2009-2010 wxLauncher Team
3 
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8 
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 GNU General Public License for more details.
13 
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17 */
18 
19 #include "apis/SkinManager.h"
20 #include <wx/artprov.h>
21 #include <wx/filename.h>
22 #include "generated/configure_launcher.h"
23 
24 #include "global/MemoryDebugging.h" // Last include for memory debugging
25 
26 class ArtProvider: public wxArtProvider {
27 public:
28 	ArtProvider(SkinSystem *skinSystem);
29 private:
30 	SkinSystem *skinSystem;
31 	virtual wxBitmap CreateBitmap(const wxArtID& id, const wxArtClient& client, const wxSize& size);
32 };
33 
Skin()34 Skin::Skin() {
35 	this->windowTitle = NULL;
36 	this->windowIcon = NULL;
37 	this->welcomeHeader = NULL;
38 	this->welcomeIcon = NULL;
39 	this->modsIcon = NULL;
40 	this->basicIcon = NULL;
41 	this->advancedIcon = NULL;
42 	this->installIcon = NULL;
43 	this->idealIcon = NULL;
44 	this->baseFont = NULL;
45 	this->welcomePageText = NULL;
46 	this->warningIcon = NULL;
47 	this->bigWarningIcon = NULL;
48 }
49 
~Skin()50 Skin::~Skin() {
51 	if (this->windowTitle != NULL) delete this->windowTitle;
52 	if (this->windowIcon != NULL) delete this->windowIcon;
53 	if (this->welcomeHeader != NULL) delete this->welcomeHeader;
54 	if (this->welcomeIcon != NULL) delete this->welcomeIcon;
55 	if (this->modsIcon != NULL) delete this->modsIcon;
56 	if (this->basicIcon != NULL) delete this->basicIcon;
57 	if (this->advancedIcon != NULL) delete this->advancedIcon;
58 	if (this->installIcon != NULL) delete this->installIcon;
59 	if (this->idealIcon != NULL) delete this->idealIcon;
60 	if (this->baseFont != NULL) delete this->baseFont;
61 	if (this->welcomePageText != NULL) delete this->welcomePageText;
62 	if (this->warningIcon != NULL) delete this->warningIcon;
63 	if (this->bigWarningIcon != NULL) delete this->bigWarningIcon;
64 }
65 
SkinSystem(Skin * defaultSkin)66 SkinSystem::SkinSystem(Skin *defaultSkin) {
67 	if ( defaultSkin != NULL ) {
68 		this->defaultSkin = defaultSkin;
69 	} else {
70 		this->defaultSkin = new Skin();
71 	}
72 	this->TCSkin = NULL;
73 	this->modSkin = NULL;
74 
75 	wxArtProvider::Push(new ArtProvider(this));
76 
77 	// Verify that the default skin is complete and if not addin anything missing.
78 
79 	if ( this->defaultSkin->windowTitle == NULL ) {
80 		this->defaultSkin->windowTitle =
81 			new wxString(_("wxLauncher for Diaspora"));
82 	}
83 
84 	if ( this->defaultSkin->windowIcon == NULL ) {
85 		wxFileName filename(_T(RESOURCES_PATH), _T("wxlauncher.ico"));
86 		wxIcon* temp = new wxIcon(filename.GetFullPath(), wxBITMAP_TYPE_ANY);
87 		if (!temp->IsOk())
88 			wxLogFatalError( _T("Icon not valid") );
89 
90 		this->defaultSkin->windowIcon = temp;
91 	}
92 
93 	if ( this->defaultSkin->welcomeHeader == NULL ) {
94 		wxFileName filename(_T(RESOURCES_PATH), _T("SCP_Header.png"));
95 		this->defaultSkin->welcomeHeader =
96 			new wxBitmap(filename.GetFullPath(), wxBITMAP_TYPE_ANY);
97 		wxASSERT(this->defaultSkin->welcomeHeader->IsOk());
98 	}
99 
100 	if ( this->defaultSkin->welcomeIcon == NULL ) {
101 		wxFileName filename(_T(RESOURCES_PATH), _T("welcome.png"));
102 		this->defaultSkin->welcomeIcon =
103 			new wxBitmap(filename.GetFullPath(), wxBITMAP_TYPE_ANY);
104 		wxASSERT(this->defaultSkin->welcomeIcon->IsOk());
105 	}
106 	if ( this->defaultSkin->modsIcon == NULL ) {
107 		wxFileName filename(_T(RESOURCES_PATH), _T("mods.png"));
108 		this->defaultSkin->modsIcon =
109 			new wxBitmap(filename.GetFullPath(), wxBITMAP_TYPE_ANY);
110 		wxASSERT(this->defaultSkin->modsIcon->IsOk());
111 	}
112 	if ( this->defaultSkin->basicIcon == NULL ) {
113 		wxFileName filename(_T(RESOURCES_PATH), _T("basic.png"));
114 		this->defaultSkin->basicIcon =
115 			new wxBitmap(filename.GetFullPath(), wxBITMAP_TYPE_ANY);
116 		wxASSERT(this->defaultSkin->basicIcon->IsOk());
117 	}
118 	if ( this->defaultSkin->advancedIcon == NULL ) {
119 		wxFileName filename(_T(RESOURCES_PATH), _T("advanced.png"));
120 		this->defaultSkin->advancedIcon =
121 			new wxBitmap(filename.GetFullPath(), wxBITMAP_TYPE_ANY);
122 		wxASSERT(this->defaultSkin->advancedIcon->IsOk());
123 	}
124 	if ( this->defaultSkin->installIcon == NULL ) {
125 		wxFileName filename(_T(RESOURCES_PATH), _T("install.png"));
126 		this->defaultSkin->installIcon =
127 			new wxBitmap(filename.GetFullPath(), wxBITMAP_TYPE_ANY);
128 		wxASSERT(this->defaultSkin->installIcon->IsOk());
129 	}
130 	if ( this->defaultSkin->idealIcon == NULL ) {
131 		wxFileName filename(_T(RESOURCES_PATH), _T("recommended.png"));
132 		this->defaultSkin->idealIcon =
133 			new wxBitmap(filename.GetFullPath(), wxBITMAP_TYPE_ANY);
134 		wxASSERT(this->defaultSkin->idealIcon->IsOk());
135 	}
136 
137 	if ( this->defaultSkin->baseFont == NULL ) {
138 		this->defaultSkin->baseFont =
139 			new wxFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
140 	}
141 
142 	if ( this->defaultSkin->welcomePageText == NULL ) {
143 		this->defaultSkin->welcomePageText =
144 			new wxString(
145 _("<p><center><b><font size='3'>Welcome to the Colonial Fleet</font></b><br><br><br> = <a href='http://diaspora.hard-light.net/'>Diaspora Homepage</a> = <a href='http://www.hard-light.net/forums/index.php?board=175.0'>Diaspora Forums</a> = <br> = <a href='http://fs2netd.game-warden.com/'>Register To Play Multiplayer</a> = <a href='http://www.hard-light.net/forums/index.php?board=237.0'>Support Forum</a> = <br> = <a href='http://www.hard-light.net/forums/index.php?topic=56783.0'>Diaspora FAQ</a> = </center></p>"));
146 	}
147 
148 	if ( this->defaultSkin->warningIcon == NULL ) {
149 		wxFileName filename(_T(RESOURCES_PATH), _T("icon_warning.png"));
150 		this->defaultSkin->warningIcon = new wxBitmap(filename.GetFullPath(), wxBITMAP_TYPE_ANY);
151 		wxASSERT(this->defaultSkin->warningIcon->IsOk());
152 	}
153 
154 	if ( this->defaultSkin->bigWarningIcon == NULL ) {
155 		wxFileName filename(_T(RESOURCES_PATH), _T("warning_big.png"));
156 		this->defaultSkin->bigWarningIcon = new wxBitmap(filename.GetFullPath(), wxBITMAP_TYPE_ANY);
157 		if ( !this->defaultSkin->bigWarningIcon->IsOk() ) {
158 			delete this->defaultSkin->bigWarningIcon;
159 			this->defaultSkin->bigWarningIcon = NULL;
160 		}
161 	}
162 }
163 
~SkinSystem()164 SkinSystem::~SkinSystem() {
165 	if (this->defaultSkin != NULL) delete this->defaultSkin;
166 	if (this->TCSkin != NULL) delete this->TCSkin;
167 	if (this->modSkin != NULL) delete this->modSkin;
168 }
169 
GetTitle()170 wxString SkinSystem::GetTitle() {
171 	if ( this->modSkin != NULL
172 		&& this->modSkin->windowTitle != NULL ) {
173 			return *(this->modSkin->windowTitle);
174 	} else if ( this->TCSkin != NULL
175 		&& this->TCSkin->windowTitle != NULL ) {
176 			return *(this->TCSkin->windowTitle);
177 	} else if ( this->defaultSkin != NULL
178 		&& this->defaultSkin->windowTitle != NULL ) {
179 			return *(this->defaultSkin->windowTitle);
180 	} else {
181 		wxLogFatalError(_T("Cannot retrieve a window title. (%p, %p, %p)"),
182 			this->modSkin, this->TCSkin, this->defaultSkin);
183 		return wxString();
184 	}
185 }
186 
GetWelcomeIcon()187 wxBitmap SkinSystem::GetWelcomeIcon() {
188 	if ( this->modSkin != NULL
189 		&& this->modSkin->welcomeIcon != NULL ) {
190 			return *(this->modSkin->welcomeIcon);
191 	} else if ( this->TCSkin != NULL
192 		&& this->TCSkin->welcomeIcon != NULL ) {
193 			return *(this->TCSkin->welcomeIcon);
194 	} else if ( this->defaultSkin != NULL
195 		&& this->defaultSkin->welcomeIcon != NULL ) {
196 			return *(this->defaultSkin->welcomeIcon);
197 	} else {
198 		wxLogFatalError(_T("Cannot retrieve a welcome icon. (%p, %p, %p)"),
199 			this->modSkin, this->TCSkin, this->defaultSkin);
200 		return wxNullBitmap;
201 	}
202 }
203 
GetModsIcon()204 wxBitmap SkinSystem::GetModsIcon() {
205 	if ( this->modSkin != NULL
206 		&& this->modSkin->modsIcon != NULL ) {
207 			return *(this->modSkin->modsIcon);
208 	} else if ( this->TCSkin != NULL
209 		&& this->TCSkin->modsIcon != NULL ) {
210 			return *(this->TCSkin->modsIcon);
211 	} else if ( this->defaultSkin != NULL
212 		&& this->defaultSkin->modsIcon != NULL ) {
213 			return *(this->defaultSkin->modsIcon);
214 	} else {
215 		wxLogFatalError(_T("Cannot retrieve a mods icon. (%p, %p, %p)"),
216 			this->modSkin, this->TCSkin, this->defaultSkin);
217 		return wxNullBitmap;
218 	}
219 }
220 
GetBasicIcon()221 wxBitmap SkinSystem::GetBasicIcon() {
222 	if ( this->modSkin != NULL
223 		&& this->modSkin->basicIcon != NULL ) {
224 			return *(this->modSkin->basicIcon);
225 	} else if ( this->TCSkin != NULL
226 		&& this->TCSkin->basicIcon != NULL ) {
227 			return *(this->TCSkin->basicIcon);
228 	} else if ( this->defaultSkin != NULL
229 		&& this->defaultSkin->basicIcon != NULL ) {
230 			return *(this->defaultSkin->basicIcon);
231 	} else {
232 		wxLogFatalError(_T("Cannot retrieve a basic icon. (%p, %p, %p)"),
233 			this->modSkin, this->TCSkin, this->defaultSkin);
234 		return wxNullBitmap;
235 	}
236 }
237 
GetAdvancedIcon()238 wxBitmap SkinSystem::GetAdvancedIcon() {
239 	if ( this->modSkin != NULL
240 		&& this->modSkin->advancedIcon != NULL ) {
241 			return *(this->modSkin->advancedIcon);
242 	} else if ( this->TCSkin != NULL
243 		&& this->TCSkin->advancedIcon != NULL ) {
244 			return *(this->TCSkin->advancedIcon);
245 	} else if ( this->defaultSkin != NULL
246 		&& this->defaultSkin->advancedIcon != NULL ) {
247 			return *(this->defaultSkin->advancedIcon);
248 	} else {
249 		wxLogFatalError(_T("Cannot retrieve a advanced icon. (%p, %p, %p)"),
250 			this->modSkin, this->TCSkin, this->defaultSkin);
251 		return wxNullBitmap;
252 	}
253 }
254 
GetInstallIcon()255 wxBitmap SkinSystem::GetInstallIcon() {
256 	if ( this->modSkin != NULL
257 		&& this->modSkin->installIcon != NULL ) {
258 			return *(this->modSkin->installIcon);
259 	} else if ( this->TCSkin != NULL
260 		&& this->TCSkin->installIcon != NULL ) {
261 			return *(this->TCSkin->installIcon);
262 	} else if ( this->defaultSkin != NULL
263 		&& this->defaultSkin->installIcon != NULL ) {
264 			return *(this->defaultSkin->installIcon);
265 	} else {
266 		wxLogFatalError(_T("Cannot retrieve a install icon. (%p, %p, %p)"),
267 			this->modSkin, this->TCSkin, this->defaultSkin);
268 		return wxNullBitmap;
269 	}
270 }
271 
GetIdealIcon()272 wxBitmap SkinSystem::GetIdealIcon() {
273 	if ( this->modSkin != NULL
274 		&& this->modSkin->idealIcon != NULL ) {
275 			return *(this->modSkin->idealIcon);
276 	} else if ( this->TCSkin != NULL
277 		&& this->TCSkin->idealIcon != NULL ) {
278 			return *(this->TCSkin->idealIcon);
279 	} else if ( this->defaultSkin != NULL
280 		&& this->defaultSkin->idealIcon != NULL ) {
281 			return *(this->defaultSkin->idealIcon);
282 	} else {
283 		wxLogFatalError(_T("Cannot retrieve an ideal icon. (%p, %p, %p)"),
284 			this->modSkin, this->TCSkin, this->defaultSkin);
285 		return wxNullBitmap;
286 	}
287 }
288 
GetBanner()289 wxBitmap SkinSystem::GetBanner() {
290 	if ( this->modSkin != NULL
291 		&& this->modSkin->welcomeHeader != NULL ) {
292 			return *(this->modSkin->welcomeHeader);
293 	} else if ( this->TCSkin != NULL
294 		&& this->TCSkin->welcomeHeader != NULL ) {
295 			return *(this->TCSkin->welcomeHeader);
296 	} else if ( this->defaultSkin != NULL
297 		&& this->defaultSkin->welcomeHeader != NULL ) {
298 			return *(this->defaultSkin->welcomeHeader);
299 	} else {
300 		wxLogFatalError(_T("Cannot retrieve a banner. (%p, %p, %p)"),
301 			this->modSkin, this->TCSkin, this->defaultSkin);
302 		return wxNullBitmap;
303 	}
304 }
305 
GetFont()306 wxFont SkinSystem::GetFont() {
307 	const wxFont *temp = GetFontPointer();
308 	return (temp == NULL) ? wxNullFont : *temp;
309 }
310 
GetFontPointer()311 const wxFont* SkinSystem::GetFontPointer() {
312 	if ( this->modSkin != NULL
313 		&& this->modSkin->baseFont != NULL ) {
314 			return this->modSkin->baseFont;
315 	} else if ( this->TCSkin != NULL
316 		&& this->TCSkin->baseFont != NULL ) {
317 			return this->TCSkin->baseFont;
318 	} else if ( this->defaultSkin != NULL
319 		&& this->defaultSkin->baseFont != NULL ) {
320 			return this->defaultSkin->baseFont;
321 	} else {
322 		wxLogFatalError(_T("Cannot retrieve a font. (%p, %p, %p)"),
323 			this->modSkin, this->TCSkin, this->defaultSkin);
324 		return NULL;
325 	}
326 }
327 
GetWelcomePageText()328 wxString SkinSystem::GetWelcomePageText() {
329 	if ( this->modSkin != NULL
330 		&& this->modSkin->welcomePageText != NULL ) {
331 			return *(this->modSkin->welcomePageText);
332 	} else if ( this->TCSkin != NULL
333 		&& this->TCSkin->welcomePageText != NULL ) {
334 			return *(this->TCSkin->welcomePageText);
335 	} else if ( this->defaultSkin != NULL
336 		&& this->defaultSkin->welcomePageText ) {
337 			return *(this->defaultSkin->welcomePageText);
338 	} else {
339 		wxLogFatalError(_T("Cannot retrieve a font. (%p, %p, %p)"),
340 			this->modSkin, this->TCSkin, this->defaultSkin);
341 		return wxEmptyString;
342 	}
343 }
344 
GetWarningIcon()345 wxBitmap SkinSystem::GetWarningIcon() {
346 	if ( this->modSkin != NULL
347 		&& this->modSkin->warningIcon != NULL ) {
348 			return *(this->modSkin->warningIcon);
349 	} else if ( this->TCSkin != NULL
350 		&& this->TCSkin->warningIcon != NULL ) {
351 			return *(this->TCSkin->warningIcon);
352 	} else if ( this->defaultSkin != NULL
353 		&& this->defaultSkin->warningIcon ) {
354 			return *(this->defaultSkin->warningIcon);
355 	} else {
356 		wxLogFatalError(_T("Cannot retrieve a warning icon. (%p, %p, %p)"),
357 			this->modSkin, this->TCSkin, this->defaultSkin);
358 		return wxNullBitmap;
359 	}
360 }
361 
GetBigWarningIcon()362 wxBitmap SkinSystem::GetBigWarningIcon() {
363 	if ( this->modSkin != NULL
364 		&& this->modSkin->bigWarningIcon != NULL ) {
365 			return *(this->modSkin->bigWarningIcon);
366 	} else if ( this->TCSkin != NULL
367 		&& this->TCSkin->bigWarningIcon != NULL ) {
368 			return *(this->TCSkin->bigWarningIcon);
369 	} else if ( this->defaultSkin != NULL
370 		&& this->defaultSkin->bigWarningIcon ) {
371 			return *(this->defaultSkin->bigWarningIcon);
372 	} else {
373 		wxImage image = this->GetWarningIcon().ConvertToImage();
374 		image = image.Scale(SkinSystem::BigWarningIconWidth, SkinSystem::BigWarningIconHeight);
375 		return wxBitmap(image);
376 	}
377 }
378 
379 
380 
381 
382 
383 
384 /** Opens, verifies and resizes (if nessisary) the 255x112 image that is needed
385 on the mods page.
386 \note Does allocate memory.*/
VerifySmallImage(wxString current,wxString shortmodname,wxString filepath)387 wxBitmap* SkinSystem::VerifySmallImage(wxString current, wxString shortmodname,
388 									   wxString filepath) {
389 	wxFileName filename;
390 	if ( SkinSystem::SearchFile(&filename, current, shortmodname, filepath) ) {
391 		wxLogDebug(_T("   Opening: %s"), filename.GetFullPath().c_str());
392 		wxImage image(filename.GetFullPath());
393 		if ( image.IsOk() ) {
394 			if ( image.GetWidth() > 255 || image.GetHeight() > 112 ) {
395 				wxLogDebug(_T("   Resizing."));
396 				image = image.Scale(255, 112, wxIMAGE_QUALITY_HIGH);
397 			}
398 			return new wxBitmap(image);
399 		} else {
400 			wxLogDebug(_T("   Image is not Ok!"));
401 		}
402 	}
403 	return NULL;
404 }
405 
406 /** Opens, verifies, the window icon, returning NULL if anything is not valid.
407 \note Does allocate memory. */
VerifyWindowIcon(wxString current,wxString shortmodname,wxString filepath)408 wxBitmap* SkinSystem::VerifyWindowIcon(wxString current, wxString shortmodname,
409 									   wxString filepath) {
410    wxFileName filename;
411    if ( SkinSystem::SearchFile(&filename, current, shortmodname, filepath) ) {
412 	   wxLogDebug(_T("   Opening: %s"), filename.GetFullPath().c_str());
413 
414 	   wxImage image(filename.GetFullPath());
415 	   if ( image.IsOk() ) {
416 		   if ( image.GetWidth() == 32 && image.GetHeight() == 32 ) {
417 			   return new wxBitmap(image);
418 		   } else {
419 			   wxLogDebug(_T("   Image size wrong"));
420 		   }
421 	   } else {
422 		   wxLogDebug(_T("   Image not valid."));
423 	   }
424    }
425    return NULL;
426 }
427 
428 /** Returns true if function is able to get a valid filename object for the
429 passed paths.  Filename is returned via the param filename. */
SearchFile(wxFileName * filename,wxString currentTC,wxString shortmodname,wxString filepath)430 bool SkinSystem::SearchFile(wxFileName *filename, wxString currentTC,
431 							wxString shortmodname, wxString filepath) {
432 	if (shortmodname.IsEmpty()) { // indicates that the mod is (No mod)
433 		filename->Assign(
434 			wxString::Format(_T("%s"), filepath.c_str()));
435 	} else {
436 		filename->Assign(
437 			wxString::Format(_T("%s/%s"), shortmodname.c_str(), filepath.c_str()));
438 	}
439 
440 	if ( filename->Normalize(wxPATH_NORM_ALL, currentTC, wxPATH_UNIX) ) {
441 		if ( filename->IsOk() ) {
442 			if ( filename->FileExists() ) {
443 				return true;
444 			} else {
445 				wxLogDebug(_T("   File '%s' does not exist"),
446 					filename->GetFullPath().c_str());
447 			}
448 		} else {
449 			wxLogDebug(_T("   File '%s' is not valid"), filename->GetFullPath().c_str());
450 		}
451 	} else {
452 		wxLogDebug(_T("   Unable to normalize '%s' '%s' '%s'"),	currentTC.c_str(),
453 			shortmodname.c_str(), filepath.c_str());
454 	}
455 	return false;
456 }
457 
458 /** Verifies that the icon exists, is the correct size (resizing if needed)
459 and then returns a new wxBitmap that contains the file. */
VerifyTabIcon(wxString currentTC,wxString shortmodname,wxString filepath)460 wxBitmap* SkinSystem::VerifyTabIcon(wxString currentTC, wxString shortmodname,
461 									wxString filepath) {
462 	wxFileName filename;
463 	if ( SkinSystem::SearchFile(&filename, currentTC, shortmodname, filepath) ) {
464 		wxLogDebug(_T("   Opening: %s"), filename.GetFullPath().c_str());
465 
466 		wxImage image(filename.GetFullPath());
467 
468 		if ( image.IsOk() ) {
469 			if ( image.GetWidth() != static_cast<int>(SkinSystem::TabIconWidth)
470 				|| image.GetHeight() != static_cast<int>(SkinSystem::TabIconHeight) ) {
471 					wxLogDebug(_T("   Resizing image from %dx%d"),
472 						image.GetWidth(), image.GetHeight());
473 
474 					image = image.Scale(
475 						SkinSystem::TabIconWidth,
476 						SkinSystem::TabIconHeight,
477 						wxIMAGE_QUALITY_HIGH);
478 			}
479 			return new wxBitmap(image);
480 		} else {
481 			wxLogDebug(_T("   Image not valid!"));
482 		}
483 	}
484 	return NULL;
485 }
486 
487 /** Verifies that the ideal icon exists and is the correct size. Returns a
488 new wxBitmap allocated on the heap, otherwise returns NULL if any errors.*/
VerifyIdealIcon(wxString currentTC,wxString shortname,wxString filepath)489 wxBitmap* SkinSystem::VerifyIdealIcon(wxString currentTC, wxString shortname,
490 									  wxString filepath) {
491 	  wxFileName filename;
492 	  if ( SkinSystem::SearchFile(&filename, currentTC, shortname, filepath) ) {
493 		  wxLogDebug(_T("   Opening: %s"), filename.GetFullPath().c_str());
494 
495 		  wxImage image(filename.GetFullPath());
496 
497 		  if ( image.IsOk() ) {
498 			  if ( image.GetWidth() == static_cast<int>(SkinSystem::IdealIconWidth)
499 				  && image.GetHeight() == static_cast<int>(SkinSystem::IdealIconHeight) ) {
500 					  return new wxBitmap(image);
501 			  } else {
502 				  wxLogDebug(_T("   Icon is incorrect size. Got (%d,%d); Need (%d,%d)"),
503 					  image.GetWidth(), image.GetHeight(),
504 					  SkinSystem::IdealIconWidth, SkinSystem::IdealIconHeight);
505 			  }
506 		  } else {
507 			  wxLogDebug(_T("   Icon is not valid."));
508 		  }
509 	  }
510 	  return NULL;
511 }
512 
513 /** Returns a valid font object based on the font name and/or size passed in. */
VerifyFontChoice(wxString currentTC,wxString shortmodname,wxString fontname,int fontsize,wxString fontFamilyStr,wxString fontStyleStr,wxString fontWeightStr,bool underline)514 wxFont* SkinSystem::VerifyFontChoice(wxString currentTC, wxString shortmodname,
515 									 wxString fontname, int fontsize,
516 									 wxString fontFamilyStr, wxString fontStyleStr,
517 									 wxString fontWeightStr, bool underline) {
518 	 WXUNUSED(currentTC);
519 	 WXUNUSED(shortmodname);
520 
521 	// interpret the fontfamily string
522 
523 	 wxFontFamily fontfamily = wxFONTFAMILY_UNKNOWN;
524 	 fontFamilyStr.MakeLower();
525 	 if ( fontFamilyStr.StartsWith(_T("decorative")) ) {
526 		 fontfamily = wxFONTFAMILY_DECORATIVE;
527 	 } else if ( fontFamilyStr.StartsWith(_T("roman")) ) {
528 		 fontfamily = wxFONTFAMILY_ROMAN;
529 	 } else if ( fontFamilyStr.StartsWith(_T("script")) ) {
530 		 fontfamily = wxFONTFAMILY_SCRIPT;
531 	 } else if ( fontFamilyStr.StartsWith(_T("swiss")) ) {
532 		 fontfamily = wxFONTFAMILY_SWISS;
533 	 } else if ( fontFamilyStr.StartsWith(_T("modern")) ) {
534 		 fontfamily = wxFONTFAMILY_MODERN;
535 	 } else if ( fontFamilyStr.StartsWith(_T("teletype")) ) {
536 		 fontfamily = wxFONTFAMILY_TELETYPE;
537 	 }
538 
539 	 wxFontStyle fontstyle = wxFONTSTYLE_MAX;
540 	 fontStyleStr.MakeLower();
541 	 if ( fontStyleStr.StartsWith(_T("slant")) ) {
542 		fontstyle = wxFONTSTYLE_SLANT;
543 	 } else if ( fontStyleStr.StartsWith(_T("italic")) ) {
544 		 fontstyle = wxFONTSTYLE_ITALIC;
545 	 }
546 
547 	 wxFontWeight fontweight = wxFONTWEIGHT_MAX;
548 	 fontStyleStr.MakeLower();
549 	 if ( fontStyleStr.StartsWith(_T("bold")) ) {
550 		 fontweight = wxFONTWEIGHT_BOLD;
551 	 } else if ( fontStyleStr.StartsWith(_T("light")) ) {
552 		 fontweight = wxFONTWEIGHT_LIGHT;
553 	 }
554 
555 	 wxFont font(
556 		 (fontsize < 0) ? 12 : fontsize,	// font size
557 		 (fontfamily == wxFONTFAMILY_UNKNOWN) ? wxFONTFAMILY_DEFAULT : fontfamily,
558 		 (fontstyle == wxFONTSTYLE_MAX) ? wxFONTSTYLE_NORMAL : fontstyle,
559 		 (fontweight == wxFONTWEIGHT_MAX) ? wxFONTWEIGHT_NORMAL : fontweight,
560 		 underline,
561 		 fontname);
562 
563 	 if ( font.IsOk() ) {
564 		 return new wxFont(font);
565 	 } else {
566 		 return NULL;
567 	 }
568 }
569 
MakeModsListImage(const wxBitmap & orig)570 wxBitmap SkinSystem::MakeModsListImage(const wxBitmap &orig) {
571 	wxImage temp = orig.ConvertToImage();
572 	wxImage temp1 = temp.Scale(SkinSystem::ModsListImageWidth,
573 		SkinSystem::ModsListImageHeight,
574 		wxIMAGE_QUALITY_HIGH);
575 	wxBitmap outimg = wxBitmap(temp1);
576 	wxASSERT( outimg.GetWidth() == static_cast<int>(SkinSystem::ModsListImageWidth));
577 	wxASSERT( outimg.GetHeight() == static_cast<int>(SkinSystem::ModsListImageHeight));
578 	return outimg;
579 }
580 
ArtProvider(SkinSystem * skinSystem)581 ArtProvider::ArtProvider(SkinSystem *skinSystem) {
582 	this->skinSystem = skinSystem;
583 }
584 
CreateBitmap(const wxArtID & id,const wxArtClient & client,const wxSize & size)585 wxBitmap ArtProvider::CreateBitmap(const wxArtID &id, const wxArtClient &client, const wxSize &size) {
586 	wxBitmap bitmap;
587 	if ( id == wxART_HELP ) {
588 		wxFileName filename(_T(RESOURCES_PATH), _T("helpicon.png"));
589 		if ( bitmap.LoadFile(filename.GetFullPath(), wxBITMAP_TYPE_ANY) ) {
590 			return bitmap;
591 		} else {
592 			return wxNullBitmap;
593 		}
594 	} else {
595 		return wxNullBitmap;
596 	}
597 }
598