33#include <wx/filename.h>
36#include "OCPNPlatform.h"
39#include "model/wx28compat.h"
43#ifdef __OCPN__ANDROID__
44#include "androidUTIL.h"
52using namespace ocpnStyle;
54void bmdump(wxBitmap bm, wxString name) {
55 wxImage img = bm.ConvertToImage();
56 img.SaveFile(name <<
".png", wxBITMAP_TYPE_PNG);
63wxBitmap MergeBitmaps(wxBitmap back, wxBitmap front, wxSize offset) {
67 wxImage im_front = front.ConvertToImage();
68 if (!im_front.HasAlpha() && (front.GetWidth() == back.GetWidth()))
78 if (!im_front.HasAlpha()) {
79 wxImage im_back = back.ConvertToImage();
80 back = wxBitmap(im_back);
84 wxBitmap merged(back.GetWidth(), back.GetHeight(), back.GetDepth());
90#if !wxCHECK_VERSION(2, 9, 4)
96 wxImage im_back = back.ConvertToImage();
97 wxImage im_result = back.ConvertToImage();
100 unsigned char* presult = im_result.GetData();
101 unsigned char* pback = im_back.GetData();
102 unsigned char* pfront = im_front.GetData();
104 unsigned char* afront = NULL;
105 if (im_front.HasAlpha()) afront = im_front.GetAlpha();
107 unsigned char* aback = NULL;
108 if (im_back.HasAlpha()) aback = im_back.GetAlpha();
110 unsigned char* aresult = NULL;
111 if (im_result.HasAlpha()) aresult = im_result.GetAlpha();
114 if (presult && pback && pfront) {
115 for (
int i = 0; i < back.GetHeight(); i++) {
116 for (
int j = 0; j < back.GetWidth(); j++) {
117 int fX = j - offset.x;
118 int fY = i - offset.y;
121 if (fX < 0 || fY < 0) inFront =
false;
122 if (fX >= front.GetWidth()) inFront =
false;
123 if (fY >= front.GetHeight()) inFront =
false;
127 if (afront) alphaF = (double)(*afront++) / 255.0;
129 if (aback) alphaB = (double)(*aback++) / 255.0;
130 double alphaRes = alphaF + alphaB * (1.0 - alphaF);
132 unsigned char a = alphaRes * 255;
136 (*pfront++ * alphaF + *pback++ * alphaB * (1.0 - alphaF)) /
140 (*pfront++ * alphaF + *pback++ * alphaB * (1.0 - alphaF)) /
144 (*pfront++ * alphaF + *pback++ * alphaB * (1.0 - alphaF)) /
148 if (aresult && aback) *aresult++ = *aback++;
149 *presult++ = *pback++;
150 *presult++ = *pback++;
151 *presult++ = *pback++;
156 merged = wxBitmap(im_result);
158 wxMemoryDC mdc(merged);
160 mdc.DrawBitmap(back, 0, 0,
true);
161 mdc.DrawBitmap(front, offset.x, offset.y,
true);
162 mdc.SelectObject(wxNullBitmap);
172wxBitmap ConvertTo24Bit(wxColor bgColor, wxBitmap front) {
173 if (front.GetDepth() == 24)
return front;
175#if !wxCHECK_VERSION(2, 9, 4)
179 wxImage im_front = front.ConvertToImage();
180 unsigned char* pfront = im_front.GetData();
181 if (!pfront)
return wxNullBitmap;
183 unsigned char* presult =
184 (
unsigned char*)malloc(front.GetWidth() * front.GetHeight() * 3);
185 if (!presult)
return wxNullBitmap;
187 unsigned char* po_result = presult;
189 unsigned char* afront = NULL;
190 if (im_front.HasAlpha()) afront = im_front.GetAlpha();
192 for (
int i = 0; i < front.GetWidth(); i++) {
193 for (
int j = 0; j < front.GetHeight(); j++) {
195 if (afront) alphaF = (double)(*afront++) / 256.0;
196 unsigned char r = *pfront++ * alphaF + bgColor.Red() * (1.0 - alphaF);
198 unsigned char g = *pfront++ * alphaF + bgColor.Green() * (1.0 - alphaF);
200 unsigned char b = *pfront++ * alphaF + bgColor.Blue() * (1.0 - alphaF);
205 wxImage im_result(front.GetWidth(), front.GetHeight(), po_result);
207 wxBitmap result = wxBitmap(im_result);
211bool Style::NativeToolIconExists(
const wxString& name) {
212 if (toolIndex.find(name) == toolIndex.end())
221wxBitmap Style::GetIconScaled(
const wxString& name,
double scaleFactor,
223 if (iconIndex.find(name) == iconIndex.end()) {
224 wxString msg(
"The requested icon was not found in the style: ");
227 return wxBitmap(GetToolSize().x, GetToolSize().y);
230 int index = iconIndex[name];
234 if (icon->size.x == 0) icon->size = toolSize[currentOrientation];
236 return GetIcon(name, icon->size.x * scaleFactor, icon->size.y * scaleFactor,
240wxBitmap Style::GetIcon(
const wxString& name,
int width,
int height,
242 if (iconIndex.find(name) == iconIndex.end()) {
243 wxString msg(
"The requested icon was not found in the style: ");
246 return wxBitmap(GetToolSize().x, GetToolSize().y);
249 int index = iconIndex[name];
254 if (icon->loaded && !bforceReload)
return icon->icon;
255 if (icon->size.x == 0) icon->size = toolSize[currentOrientation];
257 wxSize retSize = icon->size;
258 if ((width > 0) && (height > 0)) retSize = wxSize(width, height);
262 wxString fullFilePath = myConfigFileDir + this->sysname +
263 wxFileName::GetPathSeparator() + name +
".svg";
264 if (wxFileExists(fullFilePath))
265 bm = LoadSVG(fullFilePath, retSize.x, retSize.y);
269 wxRect location(icon->iconLoc, icon->size);
270 bm = graphics->GetSubBitmap(location);
271 if (retSize != icon->size) {
272 wxImage scaled_image = bm.ConvertToImage();
274 scaled_image.Scale(retSize.x, retSize.y, wxIMAGE_QUALITY_HIGH));
280 icon->icon = SetBitmapBrightness(bm, colorscheme);
285wxBitmap Style::GetToolIcon(
const wxString& toolname,
int iconType,
286 bool rollover,
int width,
int height) {
287 if (toolIndex.find(toolname) == toolIndex.end()) {
292 return wxBitmap(GetToolSize().x, GetToolSize().y, 1);
295 int index = toolIndex[toolname];
299 wxSize size = tool->customSize;
300 if (size.x == 0) size = toolSize[currentOrientation];
302 wxSize retSize = size;
303 if ((width > 0) && (height > 0)) retSize = wxSize(width, height);
306 case TOOLICON_NORMAL: {
307 if (tool->iconLoaded && !rollover) {
310 if (tool->rolloverLoaded && rollover)
return tool->rollover;
312 wxRect location(tool->iconLoc, size);
316 if ((tool->rolloverLoc.x != 0) || (tool->rolloverLoc.y != 0))
317 location = wxRect(tool->rolloverLoc, size);
320 if (currentOrientation) {
321 location.x -= verticalIconOffset.x;
322 location.y -= verticalIconOffset.y;
327 wxString fullFilePath;
329 fullFilePath = myConfigFileDir + this->sysname +
330 wxFileName::GetPathSeparator() + toolname +
332 if (!wxFileExists(fullFilePath))
333 fullFilePath = myConfigFileDir + this->sysname +
334 wxFileName::GetPathSeparator() + toolname +
".svg";
336 fullFilePath = myConfigFileDir + this->sysname +
337 wxFileName::GetPathSeparator() + toolname +
".svg";
338 if (wxFileExists(fullFilePath))
339 bm = LoadSVG(fullFilePath, retSize.x, retSize.y);
343 bm = graphics->GetSubBitmap(location);
346 bm = MergeBitmaps(GetNormalBG(), bm, wxSize(0, 0));
348 wxBitmap bg(GetToolSize().x, GetToolSize().y);
351 wxBrush(GetGlobalColor(
"GREY2"), wxBRUSHSTYLE_SOLID));
353 mdc.SelectObject(wxNullBitmap);
354 bm = MergeBitmaps(bg, bm, wxSize(0, 0));
357 if (retSize != size) {
358 wxImage scaled_image = bm.ConvertToImage();
360 scaled_image.Scale(retSize.x, retSize.y, wxIMAGE_QUALITY_HIGH));
368 tool->rollover = SetBitmapBrightness(bm, colorscheme);
369 tool->rolloverLoaded =
true;
370 return tool->rollover;
372 if (toolname ==
"mob_btn") {
373 double dimLevel = 1.0;
374 if (colorscheme == GLOBAL_COLOR_SCHEME_DUSK)
376 else if (colorscheme == GLOBAL_COLOR_SCHEME_NIGHT)
378 tool->icon = SetBitmapBrightnessAbs(bm, dimLevel);
380 tool->icon = SetBitmapBrightness(bm, colorscheme);
383 tool->iconLoaded =
true;
387 case TOOLICON_TOGGLED: {
388 if (tool->toggledLoaded && !rollover)
return tool->toggled;
389 if (tool->rolloverToggledLoaded && rollover)
return tool->rolloverToggled;
391 wxRect location(tool->iconLoc, size);
392 if (rollover) location = wxRect(tool->rolloverLoc, size);
394 if (GetToolSize() != GetToggledToolSize()) {
395 offset = GetToggledToolSize() - GetToolSize();
398 if (currentOrientation) {
399 location.x -= verticalIconOffset.x;
400 location.y -= verticalIconOffset.y;
404 wxString fullFilePath;
406 fullFilePath = myConfigFileDir + this->sysname +
407 wxFileName::GetPathSeparator() + toolname +
408 "_rollover_toggled.svg";
410 fullFilePath = myConfigFileDir + this->sysname +
411 wxFileName::GetPathSeparator() + toolname +
413 if (wxFileExists(fullFilePath))
414 bm = LoadSVG(fullFilePath, retSize.x, retSize.y);
418 fullFilePath = myConfigFileDir + this->sysname +
419 wxFileName::GetPathSeparator() + toolname +
422 fullFilePath = myConfigFileDir + this->sysname +
423 wxFileName::GetPathSeparator() + toolname +
".svg";
425 if (wxFileExists(fullFilePath)) {
426 bm = LoadSVG(fullFilePath, retSize.x, retSize.y);
428 wxBitmap bmBack = GetToggledBG();
429 if ((bmBack.GetWidth() != retSize.x) ||
430 (bmBack.GetHeight() != retSize.y)) {
431 wxImage scaled_back = bmBack.ConvertToImage();
433 scaled_back.Scale(retSize.x, retSize.y, wxIMAGE_QUALITY_HIGH));
435 bm = MergeBitmaps(bmBack, bm, wxSize(0, 0));
441 bm = graphics->GetSubBitmap(location);
442 bm = MergeBitmaps(GetToggledBG(), bm, offset);
444 if (retSize != size) {
445 wxImage scaled_image = bm.ConvertToImage();
447 scaled_image.Scale(retSize.x, retSize.y, wxIMAGE_QUALITY_HIGH));
452 tool->rolloverToggled = SetBitmapBrightness(bm, colorscheme);
453 tool->rolloverToggledLoaded =
true;
454 return tool->rolloverToggled;
456 tool->toggled = SetBitmapBrightness(bm, colorscheme);
457 tool->toggledLoaded =
true;
458 return tool->toggled;
461 case TOOLICON_DISABLED: {
462 if (tool->disabledLoaded)
return tool->disabled;
463 wxRect location(tool->disabledLoc, size);
467 wxString fullFilePath = myConfigFileDir + this->sysname +
468 wxFileName::GetPathSeparator() + toolname +
470 if (wxFileExists(fullFilePath))
471 bm = LoadSVG(fullFilePath, retSize.x, retSize.y);
475 bm = graphics->GetSubBitmap(location);
478 bm = MergeBitmaps(GetNormalBG(), bm, wxSize(0, 0));
481 if (retSize != size) {
482 wxImage scaled_image = bm.ConvertToImage();
484 scaled_image.Scale(retSize.x, retSize.y, wxIMAGE_QUALITY_HIGH));
489 if (currentOrientation) {
490 location.x -= verticalIconOffset.x;
491 location.y -= verticalIconOffset.y;
493 tool->disabled = SetBitmapBrightness(bm, colorscheme);
494 tool->disabledLoaded =
true;
495 return tool->disabled;
499 "A requested icon type for this tool was not found in the style: ");
502 return wxBitmap(GetToolSize().x, GetToolSize().y);
505wxBitmap Style::BuildPluginIcon(wxBitmap& bm,
int iconType,
double factor) {
506 if (!bm.IsOk())
return wxNullBitmap;
511 case TOOLICON_NORMAL:
512 case TOOLICON_TOGGLED: {
515 if (iconType == TOOLICON_NORMAL)
520 if ((bg.GetWidth() >= bm.GetWidth()) &&
521 (bg.GetHeight() >= bm.GetHeight())) {
522 int w = bg.GetWidth() * factor;
523 int h = bg.GetHeight() * factor;
524 wxImage scaled_image = bg.ConvertToImage();
525 bg = wxBitmap(scaled_image.Scale(w, h, wxIMAGE_QUALITY_HIGH));
527 wxSize offset = wxSize(bg.GetWidth() - bm.GetWidth(),
528 bg.GetHeight() - bm.GetHeight());
530 iconbm = MergeBitmaps(bg, bm, offset);
533 double factor = ((double)bm.GetHeight()) / bg.GetHeight();
534 int nw = bg.GetWidth() * factor;
535 int nh = bm.GetHeight();
536 if (bg.GetWidth() == bg.GetHeight()) nw = nh;
537 wxImage scaled_image = bg.ConvertToImage();
538 bg = wxBitmap(scaled_image.Scale(nw, nh, wxIMAGE_QUALITY_HIGH));
540 wxSize offset = wxSize(bg.GetWidth() - bm.GetWidth(),
541 bg.GetHeight() - bm.GetHeight());
543 iconbm = MergeBitmaps(bg, bm, offset);
547 wxBitmap bg(GetToolSize().x, GetToolSize().y);
549 wxSize offset = GetToolSize() - wxSize(bm.GetWidth(), bm.GetHeight());
551 mdc.SetBackground(wxBrush(GetGlobalColor(
"GREY2"), wxBRUSHSTYLE_SOLID));
553 mdc.SelectObject(wxNullBitmap);
554 iconbm = MergeBitmaps(bg, bm, offset);
562 return SetBitmapBrightness(iconbm, colorscheme);
565wxBitmap Style::SetBitmapBrightness(wxBitmap& bitmap, ColorScheme cs) {
568 case GLOBAL_COLOR_SCHEME_DUSK: {
572 case GLOBAL_COLOR_SCHEME_NIGHT: {
581 return SetBitmapBrightnessAbs(bitmap, dimLevel);
584wxBitmap Style::SetBitmapBrightnessAbs(wxBitmap& bitmap,
double level) {
585 wxImage image = bitmap.ConvertToImage();
587 int gimg_width = image.GetWidth();
588 int gimg_height = image.GetHeight();
590 for (
int iy = 0; iy < gimg_height; iy++) {
591 for (
int ix = 0; ix < gimg_width; ix++) {
592 if (!image.IsTransparent(ix, iy, 30)) {
593 wxImage::RGBValue rgb(image.GetRed(ix, iy), image.GetGreen(ix, iy),
594 image.GetBlue(ix, iy));
595 wxImage::HSVValue hsv = wxImage::RGBtoHSV(rgb);
596 hsv.value = hsv.value * level;
597 wxImage::RGBValue nrgb = wxImage::HSVtoRGB(hsv);
598 image.SetRGB(ix, iy, nrgb.red, nrgb.green, nrgb.blue);
602 return wxBitmap(image);
605wxBitmap Style::GetNormalBG() {
606 wxSize size = toolSize[currentOrientation];
607 return graphics->GetSubBitmap(wxRect(normalBGlocation[currentOrientation].x,
608 normalBGlocation[currentOrientation].y,
612wxBitmap Style::GetActiveBG() {
613 return graphics->GetSubBitmap(wxRect(activeBGlocation[currentOrientation].x,
614 activeBGlocation[currentOrientation].y,
615 toolSize[currentOrientation].x,
616 toolSize[currentOrientation].y));
619wxBitmap Style::GetToggledBG() {
620 wxSize size = toolSize[currentOrientation];
621 if (toggledBGSize[currentOrientation].x) {
622 size = toggledBGSize[currentOrientation];
624 return graphics->GetSubBitmap(
625 wxRect(toggledBGlocation[currentOrientation], size));
628wxBitmap Style::GetToolbarStart() {
629 wxSize size = toolbarStartSize[currentOrientation];
630 if (toolbarStartSize[currentOrientation].x == 0) {
631 size = toolbarStartSize[currentOrientation];
633 return graphics->GetSubBitmap(
634 wxRect(toolbarStartLoc[currentOrientation], size));
637wxBitmap Style::GetToolbarEnd() {
638 wxSize size = toolbarEndSize[currentOrientation];
639 if (toolbarEndSize[currentOrientation].x == 0) {
640 size = toolbarEndSize[currentOrientation];
642 return graphics->GetSubBitmap(
643 wxRect(toolbarEndLoc[currentOrientation], size));
646int Style::GetToolbarCornerRadius() {
return cornerRadius[currentOrientation]; }
648void Style::DrawToolbarLineStart(wxBitmap& bmp,
double scale) {
649 if (!HasToolbarStart())
return;
651 wxBitmap sbmp = GetToolbarStart();
652 if (fabs(
scale - 1.0) > 0.01) {
653 int h = sbmp.GetHeight() *
scale;
654 int w = sbmp.GetWidth() *
scale;
655 if ((h > 0) && (w > 0)) {
656 wxImage scaled_image = sbmp.ConvertToImage();
657 sbmp = wxBitmap(scaled_image.Scale(w, h, wxIMAGE_QUALITY_HIGH));
660 dc.DrawBitmap(sbmp, 0, 0,
true);
661 dc.SelectObject(wxNullBitmap);
664void Style::DrawToolbarLineEnd(wxBitmap& bmp,
double scale) {
665 if (!HasToolbarStart())
return;
667 wxBitmap sbmp = GetToolbarEnd();
668 if (fabs(
scale - 1.0) > 0.01) {
669 int h = sbmp.GetHeight() *
scale;
670 int w = sbmp.GetWidth() *
scale;
671 if ((h > 0) && (w > 0)) {
672 wxImage scaled_image = sbmp.ConvertToImage();
673 sbmp = wxBitmap(scaled_image.Scale(w, h, wxIMAGE_QUALITY_HIGH));
677 if (currentOrientation) {
678 dc.DrawBitmap(sbmp, 0, bmp.GetHeight() - sbmp.GetHeight(),
true);
680 dc.DrawBitmap(sbmp, bmp.GetWidth() - sbmp.GetWidth(), 0,
true);
682 dc.SelectObject(wxNullBitmap);
685void Style::SetOrientation(
long orient) {
687 if (orient == wxTB_VERTICAL) newOrient = 1;
688 if (newOrient == currentOrientation)
return;
689 currentOrientation = newOrient;
693int Style::GetOrientation() {
return currentOrientation; }
695void Style::SetColorScheme(ColorScheme cs) {
699 if ((consoleTextBackgroundSize.x) && (consoleTextBackgroundSize.y)) {
700 wxBitmap bm = graphics->GetSubBitmap(
701 wxRect(consoleTextBackgroundLoc, consoleTextBackgroundSize));
706 consoleTextBackground = SetBitmapBrightness(bm, cs);
710void Style::Unload() {
711 for (
unsigned int i = 0; i < tools.Count(); i++) {
716 for (
unsigned int i = 0; i < icons.Count(); i++) {
724 currentOrientation = 0;
725 colorscheme = GLOBAL_COLOR_SCHEME_DAY;
726 marginsInvisible =
false;
727 hasBackground =
false;
728 chartStatusIconWidth = 0;
729 chartStatusWindowTransparent =
false;
731 embossFont = wxEmptyString;
734 compassMarginTop = 4;
735 compassMarginRight = 0;
736 compassMarginBottom = 4;
737 compassMarginLeft = 4;
738 compasscornerRadius = 3;
742 for (
int i = 0; i < 2; i++) {
743 toolbarStartLoc[i] = wxPoint(0, 0);
744 toolbarEndLoc[i] = wxPoint(0, 0);
750 for (
unsigned int i = 0; i < tools.Count(); i++) {
751 delete (
Tool*)(tools[i]);
755 for (
unsigned int i = 0; i < icons.Count(); i++) {
756 delete (
Icon*)(icons[i]);
760 if (graphics)
delete graphics;
766StyleManager::StyleManager(
void) {
769 Init(g_Platform->GetSharedDataDir() +
"uidata" +
770 wxFileName::GetPathSeparator());
771 Init(g_Platform->GetHomeDir());
772 Init(g_Platform->GetHomeDir() +
".opencpn" + wxFileName::GetPathSeparator());
775 wxLogMessage(
"Using SVG Icons");
777 wxLogMessage(
"Using PNG Icons");
781StyleManager::StyleManager(
const wxString& configDir) {
788StyleManager::~StyleManager(
void) {
789 for (
unsigned int i = 0; i < styles.Count(); i++) {
790 delete (
Style*)(styles[i]);
795void StyleManager::Init(
const wxString& fromPath) {
798 if (!wxDir::Exists(fromPath)) {
799 wxString msg =
"No styles found at: ";
806 if (!dir.IsOpened())
return;
813 bool more = dir.GetFirst(&filename,
"style*.xml", wxDIR_FILES);
816 wxString msg =
"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(
"Attempt to load styles from this file failed: ");
839 wxString msg(
"Styles loading from ");
843 TiXmlHandle hRoot(doc.RootElement());
845 wxString root = wxString(doc.RootElement()->Value(), wxConvUTF8);
846 if (root != _T(
"styles" )) {
847 wxLogMessage(
" StyleManager: Expected XML Root <styles> not found.");
851 TiXmlElement* styleElem = hRoot.FirstChild().Element();
853 for (; styleElem; styleElem = styleElem->NextSiblingElement()) {
854 if (wxString(styleElem->Value(), wxConvUTF8) ==
"style") {
858 style->name = wxString(styleElem->Attribute(
"name"), wxConvUTF8);
859 style->sysname = wxString(styleElem->Attribute(
"sysname"), wxConvUTF8);
860 style->myConfigFileDir = fromPath;
862 TiXmlElement* subNode = styleElem->FirstChild()->ToElement();
864 for (; subNode; subNode = subNode->NextSiblingElement()) {
865 wxString nodeType(subNode->Value(), wxConvUTF8);
867 if (nodeType ==
"description") {
868 style->description = wxString(subNode->GetText(), wxConvUTF8);
871 if (nodeType ==
"chart-status-icon") {
873 subNode->QueryIntAttribute(
"width", &w);
874 style->chartStatusIconWidth = w;
877 if (nodeType ==
"chart-status-window") {
878 style->chartStatusWindowTransparent =
879 wxString(subNode->Attribute(
"transparent"), wxConvUTF8)
884 if (nodeType ==
"embossed-indicators") {
886 wxString(subNode->Attribute(
"font"), wxConvUTF8);
887 subNode->QueryIntAttribute(
"size", &(style->embossHeight));
890 if (nodeType ==
"graphics-file") {
891 style->graphicsFile =
892 wxString(subNode->Attribute(
"name"), wxConvUTF8);
896 if (nodeType ==
"active-route") {
897 TiXmlHandle handle(subNode);
898 TiXmlElement* tag = handle.Child(
"font-color", 0).ToElement();
901 tag->QueryIntAttribute(
"r", &r);
902 tag->QueryIntAttribute(
"g", &g);
903 tag->QueryIntAttribute(
"b", &b);
904 style->consoleFontColor = wxColour(r, g, b);
906 tag = handle.Child(
"text-background-location", 0).ToElement();
909 tag->QueryIntAttribute(
"x", &x);
910 tag->QueryIntAttribute(
"y", &y);
911 tag->QueryIntAttribute(
"width", &w);
912 tag->QueryIntAttribute(
"height", &h);
913 style->consoleTextBackgroundLoc = wxPoint(x, y);
914 style->consoleTextBackgroundSize = wxSize(w, h);
918 if (nodeType ==
"icons") {
919 TiXmlElement* iconNode = subNode->FirstChild()->ToElement();
921 for (; iconNode; iconNode = iconNode->NextSiblingElement()) {
922 wxString nodeType(iconNode->Value(), wxConvUTF8);
923 if (nodeType ==
"icon") {
925 style->icons.Add(icon);
926 icon->name = wxString(iconNode->Attribute(
"name"), wxConvUTF8);
927 style->iconIndex[icon->name] = style->icons.Count() - 1;
928 TiXmlHandle handle(iconNode);
930 handle.Child(
"icon-location", 0).ToElement();
933 tag->QueryIntAttribute(
"x", &x);
934 tag->QueryIntAttribute(
"y", &y);
935 icon->iconLoc = wxPoint(x, y);
937 tag = handle.Child(
"size", 0).ToElement();
940 tag->QueryIntAttribute(
"x", &x);
941 tag->QueryIntAttribute(
"y", &y);
942 icon->size = wxSize(x, y);
947 if (nodeType ==
"tools") {
948 TiXmlElement* toolNode = subNode->FirstChild()->ToElement();
950 for (; toolNode; toolNode = toolNode->NextSiblingElement()) {
951 wxString nodeType(toolNode->Value(), wxConvUTF8);
953 if (nodeType ==
"horizontal" || nodeType ==
"vertical") {
955 if (nodeType ==
"vertical") orientation = 1;
957 TiXmlElement* attrNode = toolNode->FirstChild()->ToElement();
958 for (; attrNode; attrNode = attrNode->NextSiblingElement()) {
959 wxString nodeType(attrNode->Value(), wxConvUTF8);
960 if (nodeType ==
"separation") {
961 attrNode->QueryIntAttribute(
962 "distance", &style->toolSeparation[orientation]);
965 if (nodeType ==
"margin") {
966 attrNode->QueryIntAttribute(
967 "top", &style->toolMarginTop[orientation]);
968 attrNode->QueryIntAttribute(
969 "right", &style->toolMarginRight[orientation]);
970 attrNode->QueryIntAttribute(
971 "bottom", &style->toolMarginBottom[orientation]);
972 attrNode->QueryIntAttribute(
973 "left", &style->toolMarginLeft[orientation]);
975 wxString(attrNode->Attribute(
"invisible"), wxConvUTF8);
976 style->marginsInvisible = (invis.Lower() ==
"true");
980 if (nodeType ==
"toggled-location") {
982 attrNode->QueryIntAttribute(
"x", &x);
983 attrNode->QueryIntAttribute(
"y", &y);
984 style->toggledBGlocation[orientation] = wxPoint(x, y);
987 attrNode->QueryIntAttribute(
"width", &x);
988 attrNode->QueryIntAttribute(
"height", &y);
989 style->toggledBGSize[orientation] = wxSize(x, y);
992 if (nodeType ==
"toolbar-start") {
994 attrNode->QueryIntAttribute(
"x", &x);
995 attrNode->QueryIntAttribute(
"y", &y);
996 style->toolbarStartLoc[orientation] = wxPoint(x, y);
999 attrNode->QueryIntAttribute(
"width", &x);
1000 attrNode->QueryIntAttribute(
"height", &y);
1001 style->toolbarStartSize[orientation] = wxSize(x, y);
1004 if (nodeType ==
"toolbar-end") {
1006 attrNode->QueryIntAttribute(
"x", &x);
1007 attrNode->QueryIntAttribute(
"y", &y);
1008 style->toolbarEndLoc[orientation] = wxPoint(x, y);
1011 attrNode->QueryIntAttribute(
"width", &x);
1012 attrNode->QueryIntAttribute(
"height", &y);
1013 style->toolbarEndSize[orientation] = wxSize(x, y);
1016 if (nodeType ==
"toolbar-corners") {
1018 attrNode->QueryIntAttribute(
"radius", &r);
1019 style->cornerRadius[orientation] = r;
1022 if (nodeType ==
"background-location") {
1024 attrNode->QueryIntAttribute(
"x", &x);
1025 attrNode->QueryIntAttribute(
"y", &y);
1026 style->normalBGlocation[orientation] = wxPoint(x, y);
1027 style->HasBackground(
true);
1030 if (nodeType ==
"active-location") {
1032 attrNode->QueryIntAttribute(
"x", &x);
1033 attrNode->QueryIntAttribute(
"y", &y);
1034 style->activeBGlocation[orientation] = wxPoint(x, y);
1037 if (nodeType ==
"size") {
1039 attrNode->QueryIntAttribute(
"x", &x);
1040 attrNode->QueryIntAttribute(
"y", &y);
1041 style->toolSize[orientation] = wxSize(x, y);
1044 if (nodeType ==
"icon-offset") {
1046 attrNode->QueryIntAttribute(
"x", &x);
1047 attrNode->QueryIntAttribute(
"y", &y);
1048 style->verticalIconOffset = wxSize(x, y);
1054 if (nodeType ==
"compass") {
1055 TiXmlElement* attrNode = toolNode->FirstChild()->ToElement();
1056 for (; attrNode; attrNode = attrNode->NextSiblingElement()) {
1057 wxString nodeType(attrNode->Value(), wxConvUTF8);
1058 if (nodeType ==
"margin") {
1059 attrNode->QueryIntAttribute(
"top",
1060 &style->compassMarginTop);
1061 attrNode->QueryIntAttribute(
"right",
1062 &style->compassMarginRight);
1063 attrNode->QueryIntAttribute(
"bottom",
1064 &style->compassMarginBottom);
1065 attrNode->QueryIntAttribute(
"left",
1066 &style->compassMarginLeft);
1069 if (nodeType ==
"compass-corners") {
1071 attrNode->QueryIntAttribute(
"radius", &r);
1072 style->compasscornerRadius = r;
1075 if (nodeType ==
"offset") {
1076 attrNode->QueryIntAttribute(
"x", &style->compassXoffset);
1077 attrNode->QueryIntAttribute(
"y", &style->compassYoffset);
1083 if (nodeType ==
"tool") {
1085 style->tools.Add(tool);
1086 tool->name = wxString(toolNode->Attribute(
"name"), wxConvUTF8);
1087 style->toolIndex[tool->name] = style->tools.Count() - 1;
1088 TiXmlHandle toolHandle(toolNode);
1089 TiXmlElement* toolTag =
1090 toolHandle.Child(
"icon-location", 0).ToElement();
1093 toolTag->QueryIntAttribute(
"x", &x);
1094 toolTag->QueryIntAttribute(
"y", &y);
1095 tool->iconLoc = wxPoint(x, y);
1097 toolTag = toolHandle.Child(
"rollover-location", 0).ToElement();
1100 toolTag->QueryIntAttribute(
"x", &x);
1101 toolTag->QueryIntAttribute(
"y", &y);
1102 tool->rolloverLoc = wxPoint(x, y);
1104 toolTag = toolHandle.Child(
"disabled-location", 0).ToElement();
1107 toolTag->QueryIntAttribute(
"x", &x);
1108 toolTag->QueryIntAttribute(
"y", &y);
1109 tool->disabledLoc = wxPoint(x, y);
1111 toolTag = toolHandle.Child(
"size", 0).ToElement();
1114 toolTag->QueryIntAttribute(
"x", &x);
1115 toolTag->QueryIntAttribute(
"y", &y);
1116 tool->customSize = wxSize(x, y);
1129void StyleManager::SetStyle(wxString name) {
1130 Style* style = NULL;
1133 currentStyle->Unload();
1137 bool selectFirst =
false;
1141 bool bstyleFound =
false;
1143 for (
unsigned int i = 0; i < styles.Count(); i++) {
1144 style = (
Style*)(styles.Item(i));
1145 if (style->name == name) {
1151 if ((name.Length() == 0) || !bstyleFound) selectFirst =
true;
1153 for (
unsigned int i = 0; i < styles.Count(); i++) {
1154 style = (
Style*)(styles[i]);
1155 if (style->name == name || selectFirst) {
1156 if (style->graphics) {
1157 currentStyle = style;
1162 wxString fullFilePath = style->myConfigFileDir +
1163 wxFileName::GetPathSeparator() +
1164 style->graphicsFile;
1166 if (!wxFileName::FileExists(fullFilePath)) {
1167 wxString msg(
"Styles Graphics File not found: ");
1168 msg += fullFilePath;
1171 if (selectFirst)
continue;
1177 if (!img.LoadFile(fullFilePath, wxBITMAP_TYPE_PNG)) {
1178 wxString msg(
"Styles Graphics File failed to load: ");
1179 msg += fullFilePath;
1184 style->graphics =
new wxBitmap(img);
1185 currentStyle = style;
1191 if (!ok || !currentStyle->graphics) {
1192 wxString msg(
"The requested style was not found: ");
1199 if ((currentStyle->consoleTextBackgroundSize.x) &&
1200 (currentStyle->consoleTextBackgroundSize.y)) {
1201 currentStyle->consoleTextBackground =
1202 currentStyle->graphics->GetSubBitmap(
1203 wxRect(currentStyle->consoleTextBackgroundLoc,
1204 currentStyle->consoleTextBackgroundSize));
1208 if (currentStyle) nextInvocationStyle = currentStyle->name;
1213Style* StyleManager::GetCurrentStyle() {
return currentStyle; }
Global color handling by name.