27 #include <wx/wxprec.h>
33 #include <wx/filename.h>
36 #include "OCPNPlatform.h"
39 #include "model/wx28compat.h"
40 #include "svg_utils.h"
41 #include "color_handler.h"
43 #ifdef __OCPN__ANDROID__
44 #include "androidUTIL.h"
50 using namespace ocpnStyle;
52 void bmdump(wxBitmap bm, wxString name) {
53 wxImage img = bm.ConvertToImage();
54 img.SaveFile(name << _T(
".png"), wxBITMAP_TYPE_PNG);
61 wxBitmap MergeBitmaps(wxBitmap back, wxBitmap front, wxSize offset) {
65 wxImage im_front = front.ConvertToImage();
66 if (!im_front.HasAlpha() && (front.GetWidth() == back.GetWidth()))
76 if (!im_front.HasAlpha()) {
77 wxImage im_back = back.ConvertToImage();
78 back = wxBitmap(im_back);
82 wxBitmap merged(back.GetWidth(), back.GetHeight(), back.GetDepth());
88 #if !wxCHECK_VERSION(2, 9, 4)
94 wxImage im_back = back.ConvertToImage();
95 wxImage im_result = back.ConvertToImage();
98 unsigned char* presult = im_result.GetData();
99 unsigned char* pback = im_back.GetData();
100 unsigned char* pfront = im_front.GetData();
102 unsigned char* afront = NULL;
103 if (im_front.HasAlpha()) afront = im_front.GetAlpha();
105 unsigned char* aback = NULL;
106 if (im_back.HasAlpha()) aback = im_back.GetAlpha();
108 unsigned char* aresult = NULL;
109 if (im_result.HasAlpha()) aresult = im_result.GetAlpha();
112 if (presult && pback && pfront) {
113 for (
int i = 0; i < back.GetHeight(); i++) {
114 for (
int j = 0; j < back.GetWidth(); j++) {
115 int fX = j - offset.x;
116 int fY = i - offset.y;
119 if (fX < 0 || fY < 0) inFront =
false;
120 if (fX >= front.GetWidth()) inFront =
false;
121 if (fY >= front.GetHeight()) inFront =
false;
125 if (afront) alphaF = (double)(*afront++) / 255.0;
127 if (aback) alphaB = (double)(*aback++) / 255.0;
128 double alphaRes = alphaF + alphaB * (1.0 - alphaF);
130 unsigned char a = alphaRes * 255;
134 (*pfront++ * alphaF + *pback++ * alphaB * (1.0 - alphaF)) /
138 (*pfront++ * alphaF + *pback++ * alphaB * (1.0 - alphaF)) /
142 (*pfront++ * alphaF + *pback++ * alphaB * (1.0 - alphaF)) /
146 if (aresult && aback) *aresult++ = *aback++;
147 *presult++ = *pback++;
148 *presult++ = *pback++;
149 *presult++ = *pback++;
154 merged = wxBitmap(im_result);
156 wxMemoryDC mdc(merged);
158 mdc.DrawBitmap(back, 0, 0,
true);
159 mdc.DrawBitmap(front, offset.x, offset.y,
true);
160 mdc.SelectObject(wxNullBitmap);
170 wxBitmap ConvertTo24Bit(wxColor bgColor, wxBitmap front) {
171 if (front.GetDepth() == 24)
return front;
173 #if !wxCHECK_VERSION(2, 9, 4)
177 wxImage im_front = front.ConvertToImage();
178 unsigned char* pfront = im_front.GetData();
179 if (!pfront)
return wxNullBitmap;
181 unsigned char* presult =
182 (
unsigned char*)malloc(front.GetWidth() * front.GetHeight() * 3);
183 if (!presult)
return wxNullBitmap;
185 unsigned char* po_result = presult;
187 unsigned char* afront = NULL;
188 if (im_front.HasAlpha()) afront = im_front.GetAlpha();
190 for (
int i = 0; i < front.GetWidth(); i++) {
191 for (
int j = 0; j < front.GetHeight(); j++) {
193 if (afront) alphaF = (double)(*afront++) / 256.0;
194 unsigned char r = *pfront++ * alphaF + bgColor.Red() * (1.0 - alphaF);
196 unsigned char g = *pfront++ * alphaF + bgColor.Green() * (1.0 - alphaF);
198 unsigned char b = *pfront++ * alphaF + bgColor.Blue() * (1.0 - alphaF);
203 wxImage im_result(front.GetWidth(), front.GetHeight(), po_result);
205 wxBitmap result = wxBitmap(im_result);
209 bool Style::NativeToolIconExists(
const wxString& name) {
210 if (toolIndex.find(name) == toolIndex.end())
219 wxBitmap Style::GetIconScaled(
const wxString& name,
double scaleFactor,
221 if (iconIndex.find(name) == iconIndex.end()) {
222 wxString msg(_T(
"The requested icon was not found in the style: "));
225 return wxBitmap(GetToolSize().x, GetToolSize().y);
228 int index = iconIndex[name];
232 if (icon->size.x == 0) icon->size = toolSize[currentOrientation];
234 return GetIcon(name, icon->size.x * scaleFactor, icon->size.y * scaleFactor,
238 wxBitmap Style::GetIcon(
const wxString& name,
int width,
int height,
240 if (iconIndex.find(name) == iconIndex.end()) {
241 wxString msg(_T(
"The requested icon was not found in the style: "));
244 return wxBitmap(GetToolSize().x, GetToolSize().y);
247 int index = iconIndex[name];
252 if (icon->loaded && !bforceReload)
return icon->icon;
253 if (icon->size.x == 0) icon->size = toolSize[currentOrientation];
255 wxSize retSize = icon->size;
256 if ((width > 0) && (height > 0)) retSize = wxSize(width, height);
260 wxString fullFilePath = myConfigFileDir + this->sysname +
261 wxFileName::GetPathSeparator() + name + _T(
".svg");
262 if (wxFileExists(fullFilePath))
263 bm = LoadSVG(fullFilePath, retSize.x, retSize.y);
267 wxRect location(icon->iconLoc, icon->size);
268 bm = graphics->GetSubBitmap(location);
269 if (retSize != icon->size) {
270 wxImage scaled_image = bm.ConvertToImage();
272 scaled_image.Scale(retSize.x, retSize.y, wxIMAGE_QUALITY_HIGH));
278 icon->icon = SetBitmapBrightness(bm, colorscheme);
283 wxBitmap Style::GetToolIcon(
const wxString& toolname,
int iconType,
284 bool rollover,
int width,
int height) {
285 if (toolIndex.find(toolname) == toolIndex.end()) {
290 return wxBitmap(GetToolSize().x, GetToolSize().y, 1);
293 int index = toolIndex[toolname];
297 wxSize size = tool->customSize;
298 if (size.x == 0) size = toolSize[currentOrientation];
300 wxSize retSize = size;
301 if ((width > 0) && (height > 0)) retSize = wxSize(width, height);
304 case TOOLICON_NORMAL: {
305 if (tool->iconLoaded && !rollover) {
308 if (tool->rolloverLoaded && rollover)
return tool->rollover;
310 wxRect location(tool->iconLoc, size);
314 if ((tool->rolloverLoc.x != 0) || (tool->rolloverLoc.y != 0))
315 location = wxRect(tool->rolloverLoc, size);
318 if (currentOrientation) {
319 location.x -= verticalIconOffset.x;
320 location.y -= verticalIconOffset.y;
325 wxString fullFilePath;
327 fullFilePath = myConfigFileDir + this->sysname +
328 wxFileName::GetPathSeparator() + toolname +
330 if (!wxFileExists(fullFilePath))
331 fullFilePath = myConfigFileDir + this->sysname +
332 wxFileName::GetPathSeparator() + toolname + _T(
".svg");
334 fullFilePath = myConfigFileDir + this->sysname +
335 wxFileName::GetPathSeparator() + toolname + _T(
".svg");
336 if (wxFileExists(fullFilePath))
337 bm = LoadSVG(fullFilePath, retSize.x, retSize.y);
341 bm = graphics->GetSubBitmap(location);
344 bm = MergeBitmaps(GetNormalBG(), bm, wxSize(0, 0));
346 wxBitmap bg(GetToolSize().x, GetToolSize().y);
349 wxBrush(GetGlobalColor(_T(
"GREY2")), wxBRUSHSTYLE_SOLID));
351 mdc.SelectObject(wxNullBitmap);
352 bm = MergeBitmaps(bg, bm, wxSize(0, 0));
355 if (retSize != size) {
356 wxImage scaled_image = bm.ConvertToImage();
358 scaled_image.Scale(retSize.x, retSize.y, wxIMAGE_QUALITY_HIGH));
366 tool->rollover = SetBitmapBrightness(bm, colorscheme);
367 tool->rolloverLoaded =
true;
368 return tool->rollover;
370 if (toolname == _T(
"mob_btn")) {
371 double dimLevel = 1.0;
372 if (colorscheme == GLOBAL_COLOR_SCHEME_DUSK)
374 else if (colorscheme == GLOBAL_COLOR_SCHEME_NIGHT)
376 tool->icon = SetBitmapBrightnessAbs(bm, dimLevel);
378 tool->icon = SetBitmapBrightness(bm, colorscheme);
381 tool->iconLoaded =
true;
385 case TOOLICON_TOGGLED: {
386 if (tool->toggledLoaded && !rollover)
return tool->toggled;
387 if (tool->rolloverToggledLoaded && rollover)
return tool->rolloverToggled;
389 wxRect location(tool->iconLoc, size);
390 if (rollover) location = wxRect(tool->rolloverLoc, size);
392 if (GetToolSize() != GetToggledToolSize()) {
393 offset = GetToggledToolSize() - GetToolSize();
396 if (currentOrientation) {
397 location.x -= verticalIconOffset.x;
398 location.y -= verticalIconOffset.y;
402 wxString fullFilePath;
404 fullFilePath = myConfigFileDir + this->sysname +
405 wxFileName::GetPathSeparator() + toolname +
406 _T(
"_rollover_toggled.svg");
408 fullFilePath = myConfigFileDir + this->sysname +
409 wxFileName::GetPathSeparator() + toolname +
411 if (wxFileExists(fullFilePath))
412 bm = LoadSVG(fullFilePath, retSize.x, retSize.y);
416 fullFilePath = myConfigFileDir + this->sysname +
417 wxFileName::GetPathSeparator() + toolname +
420 fullFilePath = myConfigFileDir + this->sysname +
421 wxFileName::GetPathSeparator() + toolname + _T(
".svg");
423 if (wxFileExists(fullFilePath)) {
424 bm = LoadSVG(fullFilePath, retSize.x, retSize.y);
426 wxBitmap bmBack = GetToggledBG();
427 if ((bmBack.GetWidth() != retSize.x) ||
428 (bmBack.GetHeight() != retSize.y)) {
429 wxImage scaled_back = bmBack.ConvertToImage();
431 scaled_back.Scale(retSize.x, retSize.y, wxIMAGE_QUALITY_HIGH));
433 bm = MergeBitmaps(bmBack, bm, wxSize(0, 0));
439 bm = graphics->GetSubBitmap(location);
440 bm = MergeBitmaps(GetToggledBG(), bm, offset);
442 if (retSize != size) {
443 wxImage scaled_image = bm.ConvertToImage();
445 scaled_image.Scale(retSize.x, retSize.y, wxIMAGE_QUALITY_HIGH));
450 tool->rolloverToggled = SetBitmapBrightness(bm, colorscheme);
451 tool->rolloverToggledLoaded =
true;
452 return tool->rolloverToggled;
454 tool->toggled = SetBitmapBrightness(bm, colorscheme);
455 tool->toggledLoaded =
true;
456 return tool->toggled;
459 case TOOLICON_DISABLED: {
460 if (tool->disabledLoaded)
return tool->disabled;
461 wxRect location(tool->disabledLoc, size);
465 wxString fullFilePath = myConfigFileDir + this->sysname +
466 wxFileName::GetPathSeparator() + toolname +
468 if (wxFileExists(fullFilePath))
469 bm = LoadSVG(fullFilePath, retSize.x, retSize.y);
473 bm = graphics->GetSubBitmap(location);
476 bm = MergeBitmaps(GetNormalBG(), bm, wxSize(0, 0));
479 if (retSize != size) {
480 wxImage scaled_image = bm.ConvertToImage();
482 scaled_image.Scale(retSize.x, retSize.y, wxIMAGE_QUALITY_HIGH));
487 if (currentOrientation) {
488 location.x -= verticalIconOffset.x;
489 location.y -= verticalIconOffset.y;
491 tool->disabled = SetBitmapBrightness(bm, colorscheme);
492 tool->disabledLoaded =
true;
493 return tool->disabled;
497 _T(
"A requested icon type for this tool was not found in the style: "));
500 return wxBitmap(GetToolSize().x, GetToolSize().y);
503 wxBitmap Style::BuildPluginIcon(wxBitmap& bm,
int iconType,
double factor) {
504 if (!bm.IsOk())
return wxNullBitmap;
509 case TOOLICON_NORMAL:
510 case TOOLICON_TOGGLED: {
513 if (iconType == TOOLICON_NORMAL)
518 if ((bg.GetWidth() >= bm.GetWidth()) &&
519 (bg.GetHeight() >= bm.GetHeight())) {
520 int w = bg.GetWidth() * factor;
521 int h = bg.GetHeight() * factor;
522 wxImage scaled_image = bg.ConvertToImage();
523 bg = wxBitmap(scaled_image.Scale(w, h, wxIMAGE_QUALITY_HIGH));
525 wxSize offset = wxSize(bg.GetWidth() - bm.GetWidth(),
526 bg.GetHeight() - bm.GetHeight());
528 iconbm = MergeBitmaps(bg, bm, offset);
531 double factor = ((double)bm.GetHeight()) / bg.GetHeight();
532 int nw = bg.GetWidth() * factor;
533 int nh = bm.GetHeight();
534 if (bg.GetWidth() == bg.GetHeight()) nw = nh;
535 wxImage scaled_image = bg.ConvertToImage();
536 bg = wxBitmap(scaled_image.Scale(nw, nh, wxIMAGE_QUALITY_HIGH));
538 wxSize offset = wxSize(bg.GetWidth() - bm.GetWidth(),
539 bg.GetHeight() - bm.GetHeight());
541 iconbm = MergeBitmaps(bg, bm, offset);
545 wxBitmap bg(GetToolSize().x, GetToolSize().y);
547 wxSize offset = GetToolSize() - wxSize(bm.GetWidth(), bm.GetHeight());
550 wxBrush(GetGlobalColor(_T(
"GREY2")), wxBRUSHSTYLE_SOLID));
552 mdc.SelectObject(wxNullBitmap);
553 iconbm = MergeBitmaps(bg, bm, offset);
561 return SetBitmapBrightness(iconbm, colorscheme);
564 wxBitmap Style::SetBitmapBrightness(wxBitmap& bitmap, ColorScheme cs) {
567 case GLOBAL_COLOR_SCHEME_DUSK: {
571 case GLOBAL_COLOR_SCHEME_NIGHT: {
580 return SetBitmapBrightnessAbs(bitmap, dimLevel);
583 wxBitmap Style::SetBitmapBrightnessAbs(wxBitmap& bitmap,
double level) {
584 wxImage image = bitmap.ConvertToImage();
586 int gimg_width = image.GetWidth();
587 int gimg_height = image.GetHeight();
589 for (
int iy = 0; iy < gimg_height; iy++) {
590 for (
int ix = 0; ix < gimg_width; ix++) {
591 if (!image.IsTransparent(ix, iy, 30)) {
592 wxImage::RGBValue rgb(image.GetRed(ix, iy), image.GetGreen(ix, iy),
593 image.GetBlue(ix, iy));
594 wxImage::HSVValue hsv = wxImage::RGBtoHSV(rgb);
595 hsv.value = hsv.value * level;
596 wxImage::RGBValue nrgb = wxImage::HSVtoRGB(hsv);
597 image.SetRGB(ix, iy, nrgb.red, nrgb.green, nrgb.blue);
601 return wxBitmap(image);
604 wxBitmap Style::GetNormalBG() {
605 wxSize size = toolSize[currentOrientation];
606 return graphics->GetSubBitmap(wxRect(normalBGlocation[currentOrientation].x,
607 normalBGlocation[currentOrientation].y,
611 wxBitmap Style::GetActiveBG() {
612 return graphics->GetSubBitmap(wxRect(activeBGlocation[currentOrientation].x,
613 activeBGlocation[currentOrientation].y,
614 toolSize[currentOrientation].x,
615 toolSize[currentOrientation].y));
618 wxBitmap Style::GetToggledBG() {
619 wxSize size = toolSize[currentOrientation];
620 if (toggledBGSize[currentOrientation].x) {
621 size = toggledBGSize[currentOrientation];
623 return graphics->GetSubBitmap(
624 wxRect(toggledBGlocation[currentOrientation], size));
627 wxBitmap Style::GetToolbarStart() {
628 wxSize size = toolbarStartSize[currentOrientation];
629 if (toolbarStartSize[currentOrientation].x == 0) {
630 size = toolbarStartSize[currentOrientation];
632 return graphics->GetSubBitmap(
633 wxRect(toolbarStartLoc[currentOrientation], size));
636 wxBitmap Style::GetToolbarEnd() {
637 wxSize size = toolbarEndSize[currentOrientation];
638 if (toolbarEndSize[currentOrientation].x == 0) {
639 size = toolbarEndSize[currentOrientation];
641 return graphics->GetSubBitmap(
642 wxRect(toolbarEndLoc[currentOrientation], size));
645 int Style::GetToolbarCornerRadius() {
return cornerRadius[currentOrientation]; }
647 void Style::DrawToolbarLineStart(wxBitmap& bmp,
double scale) {
648 if (!HasToolbarStart())
return;
650 wxBitmap sbmp = GetToolbarStart();
651 if (fabs(
scale - 1.0) > 0.01) {
652 int h = sbmp.GetHeight() *
scale;
653 int w = sbmp.GetWidth() *
scale;
654 if ((h > 0) && (w > 0)) {
655 wxImage scaled_image = sbmp.ConvertToImage();
656 sbmp = wxBitmap(scaled_image.Scale(w, h, wxIMAGE_QUALITY_HIGH));
659 dc.DrawBitmap(sbmp, 0, 0,
true);
660 dc.SelectObject(wxNullBitmap);
663 void Style::DrawToolbarLineEnd(wxBitmap& bmp,
double scale) {
664 if (!HasToolbarStart())
return;
666 wxBitmap sbmp = GetToolbarEnd();
667 if (fabs(
scale - 1.0) > 0.01) {
668 int h = sbmp.GetHeight() *
scale;
669 int w = sbmp.GetWidth() *
scale;
670 if ((h > 0) && (w > 0)) {
671 wxImage scaled_image = sbmp.ConvertToImage();
672 sbmp = wxBitmap(scaled_image.Scale(w, h, wxIMAGE_QUALITY_HIGH));
676 if (currentOrientation) {
677 dc.DrawBitmap(sbmp, 0, bmp.GetHeight() - sbmp.GetHeight(),
true);
679 dc.DrawBitmap(sbmp, bmp.GetWidth() - sbmp.GetWidth(), 0,
true);
681 dc.SelectObject(wxNullBitmap);
684 void Style::SetOrientation(
long orient) {
686 if (orient == wxTB_VERTICAL) newOrient = 1;
687 if (newOrient == currentOrientation)
return;
688 currentOrientation = newOrient;
692 int Style::GetOrientation() {
return currentOrientation; }
694 void Style::SetColorScheme(ColorScheme cs) {
698 if ((consoleTextBackgroundSize.x) && (consoleTextBackgroundSize.y)) {
699 wxBitmap bm = graphics->GetSubBitmap(
700 wxRect(consoleTextBackgroundLoc, consoleTextBackgroundSize));
705 consoleTextBackground = SetBitmapBrightness(bm, cs);
709 void Style::Unload() {
710 for (
unsigned int i = 0; i < tools.Count(); i++) {
715 for (
unsigned int i = 0; i < icons.Count(); i++) {
723 currentOrientation = 0;
724 colorscheme = GLOBAL_COLOR_SCHEME_DAY;
725 marginsInvisible =
false;
726 hasBackground =
false;
727 chartStatusIconWidth = 0;
728 chartStatusWindowTransparent =
false;
730 embossFont = wxEmptyString;
733 compassMarginTop = 4;
734 compassMarginRight = 0;
735 compassMarginBottom = 4;
736 compassMarginLeft = 4;
737 compasscornerRadius = 3;
741 for (
int i = 0; i < 2; i++) {
742 toolbarStartLoc[i] = wxPoint(0, 0);
743 toolbarEndLoc[i] = wxPoint(0, 0);
748 Style::~Style(
void) {
749 for (
unsigned int i = 0; i < tools.Count(); i++) {
750 delete (
Tool*)(tools[i]);
754 for (
unsigned int i = 0; i < icons.Count(); i++) {
755 delete (
Icon*)(icons[i]);
759 if (graphics)
delete graphics;
765 StyleManager::StyleManager(
void) {
768 Init(g_Platform->GetSharedDataDir() + _T(
"uidata") +
769 wxFileName::GetPathSeparator());
770 Init(g_Platform->GetHomeDir());
771 Init(g_Platform->GetHomeDir() + _T(
".opencpn") +
772 wxFileName::GetPathSeparator());
775 wxLogMessage(_T(
"Using SVG Icons"));
777 wxLogMessage(_T(
"Using PNG Icons"));
781 StyleManager::StyleManager(
const wxString& configDir) {
788 StyleManager::~StyleManager(
void) {
789 for (
unsigned int i = 0; i < styles.Count(); i++) {
790 delete (
Style*)(styles[i]);
795 void StyleManager::Init(
const wxString& fromPath) {
798 if (!wxDir::Exists(fromPath)) {
799 wxString msg = _T(
"No styles found at: ");
806 if (!dir.IsOpened())
return;
813 bool more = dir.GetFirst(&filename, _T(
"style*.xml"), wxDIR_FILES);
816 wxString msg = _T(
"No styles found at: ");
822 bool firstFile =
true;
824 wxString name, extension;
826 if (!firstFile) more = dir.GetNext(&filename);
830 wxString fullFilePath = fromPath + filename;
832 if (!doc.LoadFile((
const char*)fullFilePath.mb_str())) {
833 wxString msg(_T(
"Attempt to load styles from this file failed: "));
839 wxString msg(_T(
"Styles loading from "));
843 TiXmlHandle hRoot(doc.RootElement());
845 wxString root = wxString(doc.RootElement()->Value(), wxConvUTF8);
846 if (root != _T(
"styles" )) {
848 _T(
" StyleManager: Expected XML Root <styles> not found."));
852 TiXmlElement* styleElem = hRoot.FirstChild().Element();
854 for (; styleElem; styleElem = styleElem->NextSiblingElement()) {
855 if (wxString(styleElem->Value(), wxConvUTF8) == _T(
"style")) {
859 style->name = wxString(styleElem->Attribute(
"name"), wxConvUTF8);
860 style->sysname = wxString(styleElem->Attribute(
"sysname"), wxConvUTF8);
861 style->myConfigFileDir = fromPath;
863 TiXmlElement* subNode = styleElem->FirstChild()->ToElement();
865 for (; subNode; subNode = subNode->NextSiblingElement()) {
866 wxString nodeType(subNode->Value(), wxConvUTF8);
868 if (nodeType == _T(
"description")) {
869 style->description = wxString(subNode->GetText(), wxConvUTF8);
872 if (nodeType == _T(
"chart-status-icon")) {
874 subNode->QueryIntAttribute(
"width", &w);
875 style->chartStatusIconWidth = w;
878 if (nodeType == _T(
"chart-status-window")) {
879 style->chartStatusWindowTransparent =
880 wxString(subNode->Attribute(
"transparent"), wxConvUTF8)
882 .IsSameAs(_T(
"true"));
885 if (nodeType == _T(
"embossed-indicators")) {
887 wxString(subNode->Attribute(
"font"), wxConvUTF8);
888 subNode->QueryIntAttribute(
"size", &(style->embossHeight));
891 if (nodeType == _T(
"graphics-file")) {
892 style->graphicsFile =
893 wxString(subNode->Attribute(
"name"), wxConvUTF8);
897 if (nodeType == _T(
"active-route")) {
898 TiXmlHandle handle(subNode);
899 TiXmlElement* tag = handle.Child(
"font-color", 0).ToElement();
902 tag->QueryIntAttribute(
"r", &r);
903 tag->QueryIntAttribute(
"g", &g);
904 tag->QueryIntAttribute(
"b", &b);
905 style->consoleFontColor = wxColour(r, g, b);
907 tag = handle.Child(
"text-background-location", 0).ToElement();
910 tag->QueryIntAttribute(
"x", &x);
911 tag->QueryIntAttribute(
"y", &y);
912 tag->QueryIntAttribute(
"width", &w);
913 tag->QueryIntAttribute(
"height", &h);
914 style->consoleTextBackgroundLoc = wxPoint(x, y);
915 style->consoleTextBackgroundSize = wxSize(w, h);
919 if (nodeType == _T(
"icons")) {
920 TiXmlElement* iconNode = subNode->FirstChild()->ToElement();
922 for (; iconNode; iconNode = iconNode->NextSiblingElement()) {
923 wxString nodeType(iconNode->Value(), wxConvUTF8);
924 if (nodeType == _T(
"icon")) {
926 style->icons.Add(icon);
927 icon->name = wxString(iconNode->Attribute(
"name"), wxConvUTF8);
928 style->iconIndex[icon->name] = style->icons.Count() - 1;
929 TiXmlHandle handle(iconNode);
931 handle.Child(
"icon-location", 0).ToElement();
934 tag->QueryIntAttribute(
"x", &x);
935 tag->QueryIntAttribute(
"y", &y);
936 icon->iconLoc = wxPoint(x, y);
938 tag = handle.Child(
"size", 0).ToElement();
941 tag->QueryIntAttribute(
"x", &x);
942 tag->QueryIntAttribute(
"y", &y);
943 icon->size = wxSize(x, y);
948 if (nodeType == _T(
"tools")) {
949 TiXmlElement* toolNode = subNode->FirstChild()->ToElement();
951 for (; toolNode; toolNode = toolNode->NextSiblingElement()) {
952 wxString nodeType(toolNode->Value(), wxConvUTF8);
954 if (nodeType == _T(
"horizontal") || nodeType == _T(
"vertical")) {
956 if (nodeType == _T(
"vertical")) orientation = 1;
958 TiXmlElement* attrNode = toolNode->FirstChild()->ToElement();
959 for (; attrNode; attrNode = attrNode->NextSiblingElement()) {
960 wxString nodeType(attrNode->Value(), wxConvUTF8);
961 if (nodeType == _T(
"separation")) {
962 attrNode->QueryIntAttribute(
963 "distance", &style->toolSeparation[orientation]);
966 if (nodeType == _T(
"margin")) {
967 attrNode->QueryIntAttribute(
968 "top", &style->toolMarginTop[orientation]);
969 attrNode->QueryIntAttribute(
970 "right", &style->toolMarginRight[orientation]);
971 attrNode->QueryIntAttribute(
972 "bottom", &style->toolMarginBottom[orientation]);
973 attrNode->QueryIntAttribute(
974 "left", &style->toolMarginLeft[orientation]);
976 wxString(attrNode->Attribute(
"invisible"), wxConvUTF8);
977 style->marginsInvisible = (invis.Lower() == _T(
"true"));
981 if (nodeType == _T(
"toggled-location")) {
983 attrNode->QueryIntAttribute(
"x", &x);
984 attrNode->QueryIntAttribute(
"y", &y);
985 style->toggledBGlocation[orientation] = wxPoint(x, y);
988 attrNode->QueryIntAttribute(
"width", &x);
989 attrNode->QueryIntAttribute(
"height", &y);
990 style->toggledBGSize[orientation] = wxSize(x, y);
993 if (nodeType == _T(
"toolbar-start")) {
995 attrNode->QueryIntAttribute(
"x", &x);
996 attrNode->QueryIntAttribute(
"y", &y);
997 style->toolbarStartLoc[orientation] = wxPoint(x, y);
1000 attrNode->QueryIntAttribute(
"width", &x);
1001 attrNode->QueryIntAttribute(
"height", &y);
1002 style->toolbarStartSize[orientation] = wxSize(x, y);
1005 if (nodeType == _T(
"toolbar-end")) {
1007 attrNode->QueryIntAttribute(
"x", &x);
1008 attrNode->QueryIntAttribute(
"y", &y);
1009 style->toolbarEndLoc[orientation] = wxPoint(x, y);
1012 attrNode->QueryIntAttribute(
"width", &x);
1013 attrNode->QueryIntAttribute(
"height", &y);
1014 style->toolbarEndSize[orientation] = wxSize(x, y);
1017 if (nodeType == _T(
"toolbar-corners")) {
1019 attrNode->QueryIntAttribute(
"radius", &r);
1020 style->cornerRadius[orientation] = r;
1023 if (nodeType == _T(
"background-location")) {
1025 attrNode->QueryIntAttribute(
"x", &x);
1026 attrNode->QueryIntAttribute(
"y", &y);
1027 style->normalBGlocation[orientation] = wxPoint(x, y);
1028 style->HasBackground(
true);
1031 if (nodeType == _T(
"active-location")) {
1033 attrNode->QueryIntAttribute(
"x", &x);
1034 attrNode->QueryIntAttribute(
"y", &y);
1035 style->activeBGlocation[orientation] = wxPoint(x, y);
1038 if (nodeType == _T(
"size")) {
1040 attrNode->QueryIntAttribute(
"x", &x);
1041 attrNode->QueryIntAttribute(
"y", &y);
1042 style->toolSize[orientation] = wxSize(x, y);
1045 if (nodeType == _T(
"icon-offset")) {
1047 attrNode->QueryIntAttribute(
"x", &x);
1048 attrNode->QueryIntAttribute(
"y", &y);
1049 style->verticalIconOffset = wxSize(x, y);
1055 if (nodeType == _T(
"compass")) {
1056 TiXmlElement* attrNode = toolNode->FirstChild()->ToElement();
1057 for (; attrNode; attrNode = attrNode->NextSiblingElement()) {
1058 wxString nodeType(attrNode->Value(), wxConvUTF8);
1059 if (nodeType == _T(
"margin")) {
1060 attrNode->QueryIntAttribute(
"top",
1061 &style->compassMarginTop);
1062 attrNode->QueryIntAttribute(
"right",
1063 &style->compassMarginRight);
1064 attrNode->QueryIntAttribute(
"bottom",
1065 &style->compassMarginBottom);
1066 attrNode->QueryIntAttribute(
"left",
1067 &style->compassMarginLeft);
1070 if (nodeType == _T(
"compass-corners")) {
1072 attrNode->QueryIntAttribute(
"radius", &r);
1073 style->compasscornerRadius = r;
1076 if (nodeType == _T(
"offset")) {
1077 attrNode->QueryIntAttribute(
"x", &style->compassXoffset);
1078 attrNode->QueryIntAttribute(
"y", &style->compassYoffset);
1084 if (nodeType == _T(
"tool")) {
1086 style->tools.Add(tool);
1087 tool->name = wxString(toolNode->Attribute(
"name"), wxConvUTF8);
1088 style->toolIndex[tool->name] = style->tools.Count() - 1;
1089 TiXmlHandle toolHandle(toolNode);
1090 TiXmlElement* toolTag =
1091 toolHandle.Child(
"icon-location", 0).ToElement();
1094 toolTag->QueryIntAttribute(
"x", &x);
1095 toolTag->QueryIntAttribute(
"y", &y);
1096 tool->iconLoc = wxPoint(x, y);
1098 toolTag = toolHandle.Child(
"rollover-location", 0).ToElement();
1101 toolTag->QueryIntAttribute(
"x", &x);
1102 toolTag->QueryIntAttribute(
"y", &y);
1103 tool->rolloverLoc = wxPoint(x, y);
1105 toolTag = toolHandle.Child(
"disabled-location", 0).ToElement();
1108 toolTag->QueryIntAttribute(
"x", &x);
1109 toolTag->QueryIntAttribute(
"y", &y);
1110 tool->disabledLoc = wxPoint(x, y);
1112 toolTag = toolHandle.Child(
"size", 0).ToElement();
1115 toolTag->QueryIntAttribute(
"x", &x);
1116 toolTag->QueryIntAttribute(
"y", &y);
1117 tool->customSize = wxSize(x, y);
1130 void StyleManager::SetStyle(wxString name) {
1131 Style* style = NULL;
1134 currentStyle->Unload();
1138 bool selectFirst =
false;
1142 bool bstyleFound =
false;
1144 for (
unsigned int i = 0; i < styles.Count(); i++) {
1145 style = (
Style*)(styles.Item(i));
1146 if (style->name == name) {
1152 if ((name.Length() == 0) || !bstyleFound) selectFirst =
true;
1154 for (
unsigned int i = 0; i < styles.Count(); i++) {
1155 style = (
Style*)(styles[i]);
1156 if (style->name == name || selectFirst) {
1157 if (style->graphics) {
1158 currentStyle = style;
1163 wxString fullFilePath = style->myConfigFileDir +
1164 wxFileName::GetPathSeparator() +
1165 style->graphicsFile;
1167 if (!wxFileName::FileExists(fullFilePath)) {
1168 wxString msg(_T(
"Styles Graphics File not found: "));
1169 msg += fullFilePath;
1172 if (selectFirst)
continue;
1178 if (!img.LoadFile(fullFilePath, wxBITMAP_TYPE_PNG)) {
1179 wxString msg(_T(
"Styles Graphics File failed to load: "));
1180 msg += fullFilePath;
1185 style->graphics =
new wxBitmap(img);
1186 currentStyle = style;
1192 if (!ok || !currentStyle->graphics) {
1193 wxString msg(_T(
"The requested style was not found: "));
1200 if ((currentStyle->consoleTextBackgroundSize.x) &&
1201 (currentStyle->consoleTextBackgroundSize.y)) {
1202 currentStyle->consoleTextBackground =
1203 currentStyle->graphics->GetSubBitmap(
1204 wxRect(currentStyle->consoleTextBackgroundLoc,
1205 currentStyle->consoleTextBackgroundSize));
1209 if (currentStyle) nextInvocationStyle = currentStyle->name;
1214 Style* StyleManager::GetCurrentStyle() {
return currentStyle; }