36#include <wx/filename.h>
40#include <wx/dcmemory.h>
49#include "androidUTIL.h"
55using namespace ocpnStyle;
57static void bmdump(wxBitmap bm, wxString name) {
58 wxImage img = bm.ConvertToImage();
59 img.SaveFile(name <<
".png", wxBITMAP_TYPE_PNG);
66wxBitmap
MergeBitmaps(wxBitmap back, wxBitmap front, wxSize offset) {
70 wxImage im_front = front.ConvertToImage();
71 if (!im_front.HasAlpha() && (front.GetWidth() == back.GetWidth()))
81 if (!im_front.HasAlpha()) {
82 wxImage im_back = back.ConvertToImage();
83 back = wxBitmap(im_back);
87 wxBitmap merged(back.GetWidth(), back.GetHeight(), back.GetDepth());
93#if !wxCHECK_VERSION(2, 9, 4)
99 wxImage im_back = back.ConvertToImage();
100 wxImage im_result = back.ConvertToImage();
103 unsigned char* presult = im_result.GetData();
104 unsigned char* pback = im_back.GetData();
105 unsigned char* pfront = im_front.GetData();
107 unsigned char* afront = NULL;
108 if (im_front.HasAlpha()) afront = im_front.GetAlpha();
110 unsigned char* aback = NULL;
111 if (im_back.HasAlpha()) aback = im_back.GetAlpha();
113 unsigned char* aresult = NULL;
114 if (im_result.HasAlpha()) aresult = im_result.GetAlpha();
117 if (presult && pback && pfront) {
118 for (
int i = 0; i < back.GetHeight(); i++) {
119 for (
int j = 0; j < back.GetWidth(); j++) {
120 int fX = j - offset.x;
121 int fY = i - offset.y;
124 if (fX < 0 || fY < 0) inFront =
false;
125 if (fX >= front.GetWidth()) inFront =
false;
126 if (fY >= front.GetHeight()) inFront =
false;
130 if (afront) alphaF = (double)(*afront++) / 255.0;
132 if (aback) alphaB = (double)(*aback++) / 255.0;
133 double alphaRes = alphaF + alphaB * (1.0 - alphaF);
135 unsigned char a = alphaRes * 255;
139 (*pfront++ * alphaF + *pback++ * alphaB * (1.0 - alphaF)) /
143 (*pfront++ * alphaF + *pback++ * alphaB * (1.0 - alphaF)) /
147 (*pfront++ * alphaF + *pback++ * alphaB * (1.0 - alphaF)) /
151 if (aresult && aback) *aresult++ = *aback++;
152 *presult++ = *pback++;
153 *presult++ = *pback++;
154 *presult++ = *pback++;
159 merged = wxBitmap(im_result);
161 wxMemoryDC mdc(merged);
163 mdc.DrawBitmap(back, 0, 0,
true);
164 mdc.DrawBitmap(front, offset.x, offset.y,
true);
165 mdc.SelectObject(wxNullBitmap);
175wxBitmap ConvertTo24Bit(wxColor bgColor, wxBitmap front) {
176 if (front.GetDepth() == 24)
return front;
178#if !wxCHECK_VERSION(2, 9, 4)
182 wxImage im_front = front.ConvertToImage();
183 unsigned char* pfront = im_front.GetData();
184 if (!pfront)
return wxNullBitmap;
186 unsigned char* presult =
187 (
unsigned char*)malloc(front.GetWidth() * front.GetHeight() * 3);
188 if (!presult)
return wxNullBitmap;
190 unsigned char* po_result = presult;
192 unsigned char* afront = NULL;
193 if (im_front.HasAlpha()) afront = im_front.GetAlpha();
195 for (
int i = 0; i < front.GetWidth(); i++) {
196 for (
int j = 0; j < front.GetHeight(); j++) {
198 if (afront) alphaF = (double)(*afront++) / 256.0;
199 unsigned char r = *pfront++ * alphaF + bgColor.Red() * (1.0 - alphaF);
201 unsigned char g = *pfront++ * alphaF + bgColor.Green() * (1.0 - alphaF);
203 unsigned char b = *pfront++ * alphaF + bgColor.Blue() * (1.0 - alphaF);
208 wxImage im_result(front.GetWidth(), front.GetHeight(), po_result);
210 wxBitmap result = wxBitmap(im_result);
214bool Style::NativeToolIconExists(
const wxString& name) {
215 if (toolIndex.find(name) == toolIndex.end())
224wxBitmap Style::GetIconScaled(
const wxString& name,
double scaleFactor,
226 if (iconIndex.find(name) == iconIndex.end()) {
227 wxString msg(
"The requested icon was not found in the style: ");
230 return wxBitmap(GetToolSize().x, GetToolSize().y);
233 int index = iconIndex[name];
237 if (icon->size.x == 0) icon->size = toolSize[currentOrientation];
239 return GetIcon(name, icon->size.x * scaleFactor, icon->size.y * scaleFactor,
243wxBitmap Style::GetIcon(
const wxString& name,
int width,
int height,
245 if (iconIndex.find(name) == iconIndex.end()) {
246 wxString msg(
"The requested icon was not found in the style: ");
249 return wxBitmap(GetToolSize().x, GetToolSize().y);
252 int index = iconIndex[name];
257 if (icon->loaded && !bforceReload)
return icon->icon;
258 if (icon->size.x == 0) icon->size = toolSize[currentOrientation];
260 wxSize retSize = icon->size;
261 if ((width > 0) && (height > 0)) retSize = wxSize(width, height);
265 wxString fullFilePath = myConfigFileDir + this->sysname +
266 wxFileName::GetPathSeparator() + name +
".svg";
267 if (wxFileExists(fullFilePath))
268 bm =
LoadSVG(fullFilePath, retSize.x, retSize.y);
272 wxRect location(icon->iconLoc, icon->size);
273 bm = graphics->GetSubBitmap(location);
274 if (retSize != icon->size) {
275 wxImage scaled_image = bm.ConvertToImage();
277 scaled_image.Scale(retSize.x, retSize.y, wxIMAGE_QUALITY_HIGH));
283 icon->icon = SetBitmapBrightness(bm, colorscheme);
288wxBitmap Style::GetToolIcon(
const wxString& toolname,
int iconType,
289 bool rollover,
int width,
int height) {
290 if (toolIndex.find(toolname) == toolIndex.end()) {
295 return wxBitmap(GetToolSize().x, GetToolSize().y, 1);
298 int index = toolIndex[toolname];
302 wxSize size = tool->customSize;
303 if (size.x == 0) size = toolSize[currentOrientation];
305 wxSize retSize = size;
306 if ((width > 0) && (height > 0)) retSize = wxSize(width, height);
309 case TOOLICON_NORMAL: {
310 if (tool->iconLoaded && !rollover) {
313 if (tool->rolloverLoaded && rollover)
return tool->rollover;
315 wxRect location(tool->iconLoc, size);
319 if ((tool->rolloverLoc.x != 0) || (tool->rolloverLoc.y != 0))
320 location = wxRect(tool->rolloverLoc, size);
323 if (currentOrientation) {
324 location.x -= verticalIconOffset.x;
325 location.y -= verticalIconOffset.y;
330 wxString fullFilePath;
332 fullFilePath = myConfigFileDir + this->sysname +
333 wxFileName::GetPathSeparator() + toolname +
335 if (!wxFileExists(fullFilePath))
336 fullFilePath = myConfigFileDir + this->sysname +
337 wxFileName::GetPathSeparator() + toolname +
".svg";
339 fullFilePath = myConfigFileDir + this->sysname +
340 wxFileName::GetPathSeparator() + toolname +
".svg";
341 if (wxFileExists(fullFilePath))
342 bm =
LoadSVG(fullFilePath, retSize.x, retSize.y);
346 bm = graphics->GetSubBitmap(location);
351 wxBitmap bg(GetToolSize().x, GetToolSize().y);
354 wxBrush(GetGlobalColor(
"GREY2"), wxBRUSHSTYLE_SOLID));
356 mdc.SelectObject(wxNullBitmap);
360 if (retSize != size) {
361 wxImage scaled_image = bm.ConvertToImage();
363 scaled_image.Scale(retSize.x, retSize.y, wxIMAGE_QUALITY_HIGH));
371 tool->rollover = SetBitmapBrightness(bm, colorscheme);
372 tool->rolloverLoaded =
true;
373 return tool->rollover;
375 if (toolname ==
"mob_btn") {
376 double dimLevel = 1.0;
377 if (colorscheme == GLOBAL_COLOR_SCHEME_DUSK)
379 else if (colorscheme == GLOBAL_COLOR_SCHEME_NIGHT)
381 tool->icon = SetBitmapBrightnessAbs(bm, dimLevel);
383 tool->icon = SetBitmapBrightness(bm, colorscheme);
386 tool->iconLoaded =
true;
390 case TOOLICON_TOGGLED: {
391 if (tool->toggledLoaded && !rollover)
return tool->toggled;
392 if (tool->rolloverToggledLoaded && rollover)
return tool->rolloverToggled;
394 wxRect location(tool->iconLoc, size);
395 if (rollover) location = wxRect(tool->rolloverLoc, size);
397 if (GetToolSize() != GetToggledToolSize()) {
398 offset = GetToggledToolSize() - GetToolSize();
401 if (currentOrientation) {
402 location.x -= verticalIconOffset.x;
403 location.y -= verticalIconOffset.y;
407 wxString fullFilePath;
409 fullFilePath = myConfigFileDir + this->sysname +
410 wxFileName::GetPathSeparator() + toolname +
411 "_rollover_toggled.svg";
413 fullFilePath = myConfigFileDir + this->sysname +
414 wxFileName::GetPathSeparator() + toolname +
416 if (wxFileExists(fullFilePath))
417 bm =
LoadSVG(fullFilePath, retSize.x, retSize.y);
421 fullFilePath = myConfigFileDir + this->sysname +
422 wxFileName::GetPathSeparator() + toolname +
425 fullFilePath = myConfigFileDir + this->sysname +
426 wxFileName::GetPathSeparator() + toolname +
".svg";
428 if (wxFileExists(fullFilePath)) {
429 bm =
LoadSVG(fullFilePath, retSize.x, retSize.y);
431 wxBitmap bmBack = GetToggledBG();
432 if ((bmBack.GetWidth() != retSize.x) ||
433 (bmBack.GetHeight() != retSize.y)) {
434 wxImage scaled_back = bmBack.ConvertToImage();
436 scaled_back.Scale(retSize.x, retSize.y, wxIMAGE_QUALITY_HIGH));
444 bm = graphics->GetSubBitmap(location);
447 if (retSize != size) {
448 wxImage scaled_image = bm.ConvertToImage();
450 scaled_image.Scale(retSize.x, retSize.y, wxIMAGE_QUALITY_HIGH));
455 tool->rolloverToggled = SetBitmapBrightness(bm, colorscheme);
456 tool->rolloverToggledLoaded =
true;
457 return tool->rolloverToggled;
459 tool->toggled = SetBitmapBrightness(bm, colorscheme);
460 tool->toggledLoaded =
true;
461 return tool->toggled;
464 case TOOLICON_DISABLED: {
465 if (tool->disabledLoaded)
return tool->disabled;
466 wxRect location(tool->disabledLoc, size);
470 wxString fullFilePath = myConfigFileDir + this->sysname +
471 wxFileName::GetPathSeparator() + toolname +
473 if (wxFileExists(fullFilePath))
474 bm =
LoadSVG(fullFilePath, retSize.x, retSize.y);
478 bm = graphics->GetSubBitmap(location);
484 if (retSize != size) {
485 wxImage scaled_image = bm.ConvertToImage();
487 scaled_image.Scale(retSize.x, retSize.y, wxIMAGE_QUALITY_HIGH));
492 if (currentOrientation) {
493 location.x -= verticalIconOffset.x;
494 location.y -= verticalIconOffset.y;
496 tool->disabled = SetBitmapBrightness(bm, colorscheme);
497 tool->disabledLoaded =
true;
498 return tool->disabled;
502 "A requested icon type for this tool was not found in the style: ");
505 return wxBitmap(GetToolSize().x, GetToolSize().y);
508wxBitmap Style::BuildPluginIcon(wxBitmap& bm,
int iconType,
double factor) {
509 if (!bm.IsOk())
return wxNullBitmap;
514 case TOOLICON_NORMAL:
515 case TOOLICON_TOGGLED: {
518 if (iconType == TOOLICON_NORMAL)
523 if ((bg.GetWidth() >= bm.GetWidth()) &&
524 (bg.GetHeight() >= bm.GetHeight())) {
525 int w = bg.GetWidth() * factor;
526 int h = bg.GetHeight() * factor;
527 wxImage scaled_image = bg.ConvertToImage();
528 bg = wxBitmap(scaled_image.Scale(w, h, wxIMAGE_QUALITY_HIGH));
530 wxSize offset = wxSize(bg.GetWidth() - bm.GetWidth(),
531 bg.GetHeight() - bm.GetHeight());
536 double factor = ((double)bm.GetHeight()) / bg.GetHeight();
537 int nw = bg.GetWidth() * factor;
538 int nh = bm.GetHeight();
539 if (bg.GetWidth() == bg.GetHeight()) nw = nh;
540 wxImage scaled_image = bg.ConvertToImage();
541 bg = wxBitmap(scaled_image.Scale(nw, nh, wxIMAGE_QUALITY_HIGH));
543 wxSize offset = wxSize(bg.GetWidth() - bm.GetWidth(),
544 bg.GetHeight() - bm.GetHeight());
550 wxBitmap bg(GetToolSize().x, GetToolSize().y);
552 wxSize offset = GetToolSize() - wxSize(bm.GetWidth(), bm.GetHeight());
554 mdc.SetBackground(wxBrush(GetGlobalColor(
"GREY2"), wxBRUSHSTYLE_SOLID));
556 mdc.SelectObject(wxNullBitmap);
565 return SetBitmapBrightness(iconbm, colorscheme);
568wxBitmap Style::SetBitmapBrightness(wxBitmap& bitmap, ColorScheme cs) {
571 case GLOBAL_COLOR_SCHEME_DUSK: {
575 case GLOBAL_COLOR_SCHEME_NIGHT: {
584 return SetBitmapBrightnessAbs(bitmap, dimLevel);
587wxBitmap Style::SetBitmapBrightnessAbs(wxBitmap& bitmap,
double level) {
588 wxImage image = bitmap.ConvertToImage();
590 int gimg_width = image.GetWidth();
591 int gimg_height = image.GetHeight();
593 for (
int iy = 0; iy < gimg_height; iy++) {
594 for (
int ix = 0; ix < gimg_width; ix++) {
595 if (!image.IsTransparent(ix, iy, 30)) {
596 wxImage::RGBValue rgb(image.GetRed(ix, iy), image.GetGreen(ix, iy),
597 image.GetBlue(ix, iy));
598 wxImage::HSVValue hsv = wxImage::RGBtoHSV(rgb);
599 hsv.value = hsv.value * level;
600 wxImage::RGBValue nrgb = wxImage::HSVtoRGB(hsv);
601 image.SetRGB(ix, iy, nrgb.red, nrgb.green, nrgb.blue);
605 return wxBitmap(image);
608wxBitmap Style::GetNormalBG() {
609 wxSize size = toolSize[currentOrientation];
610 return graphics->GetSubBitmap(wxRect(normalBGlocation[currentOrientation].x,
611 normalBGlocation[currentOrientation].y,
615wxBitmap Style::GetActiveBG() {
616 return graphics->GetSubBitmap(wxRect(activeBGlocation[currentOrientation].x,
617 activeBGlocation[currentOrientation].y,
618 toolSize[currentOrientation].x,
619 toolSize[currentOrientation].y));
622wxBitmap Style::GetToggledBG() {
623 wxSize size = toolSize[currentOrientation];
624 if (toggledBGSize[currentOrientation].x) {
625 size = toggledBGSize[currentOrientation];
627 return graphics->GetSubBitmap(
628 wxRect(toggledBGlocation[currentOrientation], size));
631wxBitmap Style::GetToolbarStart() {
632 wxSize size = toolbarStartSize[currentOrientation];
633 if (toolbarStartSize[currentOrientation].x == 0) {
634 size = toolbarStartSize[currentOrientation];
636 return graphics->GetSubBitmap(
637 wxRect(toolbarStartLoc[currentOrientation], size));
640wxBitmap Style::GetToolbarEnd() {
641 wxSize size = toolbarEndSize[currentOrientation];
642 if (toolbarEndSize[currentOrientation].x == 0) {
643 size = toolbarEndSize[currentOrientation];
645 return graphics->GetSubBitmap(
646 wxRect(toolbarEndLoc[currentOrientation], size));
649int Style::GetToolbarCornerRadius() {
return cornerRadius[currentOrientation]; }
651void Style::DrawToolbarLineStart(wxBitmap& bmp,
double scale) {
652 if (!HasToolbarStart())
return;
654 wxBitmap sbmp = GetToolbarStart();
655 if (fabs(
scale - 1.0) > 0.01) {
656 int h = sbmp.GetHeight() *
scale;
657 int w = sbmp.GetWidth() *
scale;
658 if ((h > 0) && (w > 0)) {
659 wxImage scaled_image = sbmp.ConvertToImage();
660 sbmp = wxBitmap(scaled_image.Scale(w, h, wxIMAGE_QUALITY_HIGH));
663 dc.DrawBitmap(sbmp, 0, 0,
true);
664 dc.SelectObject(wxNullBitmap);
667void Style::DrawToolbarLineEnd(wxBitmap& bmp,
double scale) {
668 if (!HasToolbarStart())
return;
670 wxBitmap sbmp = GetToolbarEnd();
671 if (fabs(
scale - 1.0) > 0.01) {
672 int h = sbmp.GetHeight() *
scale;
673 int w = sbmp.GetWidth() *
scale;
674 if ((h > 0) && (w > 0)) {
675 wxImage scaled_image = sbmp.ConvertToImage();
676 sbmp = wxBitmap(scaled_image.Scale(w, h, wxIMAGE_QUALITY_HIGH));
680 if (currentOrientation) {
681 dc.DrawBitmap(sbmp, 0, bmp.GetHeight() - sbmp.GetHeight(),
true);
683 dc.DrawBitmap(sbmp, bmp.GetWidth() - sbmp.GetWidth(), 0,
true);
685 dc.SelectObject(wxNullBitmap);
688void Style::SetOrientation(
long orient) {
690 if (orient == wxTB_VERTICAL) newOrient = 1;
691 if (newOrient == currentOrientation)
return;
692 currentOrientation = newOrient;
696int Style::GetOrientation() {
return currentOrientation; }
698void Style::SetColorScheme(ColorScheme cs) {
702 if ((consoleTextBackgroundSize.x) && (consoleTextBackgroundSize.y)) {
703 wxBitmap bm = graphics->GetSubBitmap(
704 wxRect(consoleTextBackgroundLoc, consoleTextBackgroundSize));
709 consoleTextBackground = SetBitmapBrightness(bm, cs);
713void Style::Unload() {
714 for (
unsigned int i = 0; i < tools.Count(); i++) {
719 for (
unsigned int i = 0; i < icons.Count(); i++) {
727 currentOrientation = 0;
728 colorscheme = GLOBAL_COLOR_SCHEME_DAY;
729 marginsInvisible =
false;
730 hasBackground =
false;
731 chartStatusIconWidth = 0;
732 chartStatusWindowTransparent =
false;
737 compassMarginTop = 4;
738 compassMarginRight = 0;
739 compassMarginBottom = 4;
740 compassMarginLeft = 4;
741 compasscornerRadius = 3;
745 for (
int i = 0; i < 2; i++) {
746 toolbarStartLoc[i] = wxPoint(0, 0);
747 toolbarEndLoc[i] = wxPoint(0, 0);
753 for (
unsigned int i = 0; i < tools.Count(); i++) {
754 delete (
Tool*)(tools[i]);
758 for (
unsigned int i = 0; i < icons.Count(); i++) {
759 delete (
Icon*)(icons[i]);
763 if (graphics)
delete graphics;
769StyleManager::StyleManager() {
772 Init(g_Platform->GetSharedDataDir() +
"uidata" +
773 wxFileName::GetPathSeparator());
774 Init(g_Platform->GetHomeDir());
775 Init(g_Platform->GetHomeDir() +
".opencpn" + wxFileName::GetPathSeparator());
778 wxLogMessage(
"Using SVG Icons");
780 wxLogMessage(
"Using PNG Icons");
784StyleManager::StyleManager(
const wxString& configDir) {
791StyleManager::~StyleManager() {
792 for (
unsigned int i = 0; i < styles.Count(); i++) {
793 delete (
Style*)(styles[i]);
798void StyleManager::Init(
const wxString& fromPath) {
801 if (!wxDir::Exists(fromPath)) {
802 wxString msg =
"No styles found at: ";
809 if (!dir.IsOpened())
return;
816 bool more = dir.GetFirst(&filename,
"style*.xml", wxDIR_FILES);
819 wxString msg =
"No styles found at: ";
825 bool firstFile =
true;
827 wxString name, extension;
829 if (!firstFile) more = dir.GetNext(&filename);
833 wxString fullFilePath = fromPath + filename;
835 if (!doc.LoadFile((
const char*)fullFilePath.mb_str())) {
836 wxString msg(
"Attempt to load styles from this file failed: ");
842 wxString msg(
"Styles loading from ");
846 TiXmlHandle hRoot(doc.RootElement());
848 wxString root = wxString(doc.RootElement()->Value(), wxConvUTF8);
849 if (root !=
"styles") {
850 wxLogMessage(
" StyleManager: Expected XML Root <styles> not found.");
854 TiXmlElement* styleElem = hRoot.FirstChild().Element();
856 for (; styleElem; styleElem = styleElem->NextSiblingElement()) {
857 if (wxString(styleElem->Value(), wxConvUTF8) ==
"style") {
861 style->name = wxString(styleElem->Attribute(
"name"), wxConvUTF8);
862 style->sysname = wxString(styleElem->Attribute(
"sysname"), wxConvUTF8);
863 style->myConfigFileDir = fromPath;
865 TiXmlElement* subNode = styleElem->FirstChild()->ToElement();
867 for (; subNode; subNode = subNode->NextSiblingElement()) {
868 wxString nodeType(subNode->Value(), wxConvUTF8);
870 if (nodeType ==
"description") {
871 style->description = wxString(subNode->GetText(), wxConvUTF8);
874 if (nodeType ==
"chart-status-icon") {
876 subNode->QueryIntAttribute(
"width", &w);
877 style->chartStatusIconWidth = w;
880 if (nodeType ==
"chart-status-window") {
881 style->chartStatusWindowTransparent =
882 wxString(subNode->Attribute(
"transparent"), wxConvUTF8)
887 if (nodeType ==
"embossed-indicators") {
889 wxString(subNode->Attribute(
"font"), wxConvUTF8);
890 subNode->QueryIntAttribute(
"size", &(style->embossHeight));
893 if (nodeType ==
"graphics-file") {
894 style->graphicsFile =
895 wxString(subNode->Attribute(
"name"), wxConvUTF8);
899 if (nodeType ==
"active-route") {
900 TiXmlHandle handle(subNode);
901 TiXmlElement* tag = handle.Child(
"font-color", 0).ToElement();
904 tag->QueryIntAttribute(
"r", &r);
905 tag->QueryIntAttribute(
"g", &g);
906 tag->QueryIntAttribute(
"b", &b);
907 style->consoleFontColor = wxColour(r, g, b);
909 tag = handle.Child(
"text-background-location", 0).ToElement();
912 tag->QueryIntAttribute(
"x", &x);
913 tag->QueryIntAttribute(
"y", &y);
914 tag->QueryIntAttribute(
"width", &w);
915 tag->QueryIntAttribute(
"height", &h);
916 style->consoleTextBackgroundLoc = wxPoint(x, y);
917 style->consoleTextBackgroundSize = wxSize(w, h);
921 if (nodeType ==
"icons") {
922 TiXmlElement* iconNode = subNode->FirstChild()->ToElement();
924 for (; iconNode; iconNode = iconNode->NextSiblingElement()) {
925 wxString nodeType(iconNode->Value(), wxConvUTF8);
926 if (nodeType ==
"icon") {
928 style->icons.Add(icon);
929 icon->name = wxString(iconNode->Attribute(
"name"), wxConvUTF8);
930 style->iconIndex[icon->name] = style->icons.Count() - 1;
931 TiXmlHandle handle(iconNode);
933 handle.Child(
"icon-location", 0).ToElement();
936 tag->QueryIntAttribute(
"x", &x);
937 tag->QueryIntAttribute(
"y", &y);
938 icon->iconLoc = wxPoint(x, y);
940 tag = handle.Child(
"size", 0).ToElement();
943 tag->QueryIntAttribute(
"x", &x);
944 tag->QueryIntAttribute(
"y", &y);
945 icon->size = wxSize(x, y);
950 if (nodeType ==
"tools") {
951 TiXmlElement* toolNode = subNode->FirstChild()->ToElement();
953 for (; toolNode; toolNode = toolNode->NextSiblingElement()) {
954 wxString nodeType(toolNode->Value(), wxConvUTF8);
956 if (nodeType ==
"horizontal" || nodeType ==
"vertical") {
958 if (nodeType ==
"vertical") orientation = 1;
960 TiXmlElement* attrNode = toolNode->FirstChild()->ToElement();
961 for (; attrNode; attrNode = attrNode->NextSiblingElement()) {
962 wxString nodeType(attrNode->Value(), wxConvUTF8);
963 if (nodeType ==
"separation") {
964 attrNode->QueryIntAttribute(
965 "distance", &style->toolSeparation[orientation]);
968 if (nodeType ==
"margin") {
969 attrNode->QueryIntAttribute(
970 "top", &style->toolMarginTop[orientation]);
971 attrNode->QueryIntAttribute(
972 "right", &style->toolMarginRight[orientation]);
973 attrNode->QueryIntAttribute(
974 "bottom", &style->toolMarginBottom[orientation]);
975 attrNode->QueryIntAttribute(
976 "left", &style->toolMarginLeft[orientation]);
978 wxString(attrNode->Attribute(
"invisible"), wxConvUTF8);
979 style->marginsInvisible = (invis.Lower() ==
"true");
983 if (nodeType ==
"toggled-location") {
985 attrNode->QueryIntAttribute(
"x", &x);
986 attrNode->QueryIntAttribute(
"y", &y);
987 style->toggledBGlocation[orientation] = wxPoint(x, y);
990 attrNode->QueryIntAttribute(
"width", &x);
991 attrNode->QueryIntAttribute(
"height", &y);
992 style->toggledBGSize[orientation] = wxSize(x, y);
995 if (nodeType ==
"toolbar-start") {
997 attrNode->QueryIntAttribute(
"x", &x);
998 attrNode->QueryIntAttribute(
"y", &y);
999 style->toolbarStartLoc[orientation] = wxPoint(x, y);
1002 attrNode->QueryIntAttribute(
"width", &x);
1003 attrNode->QueryIntAttribute(
"height", &y);
1004 style->toolbarStartSize[orientation] = wxSize(x, y);
1007 if (nodeType ==
"toolbar-end") {
1009 attrNode->QueryIntAttribute(
"x", &x);
1010 attrNode->QueryIntAttribute(
"y", &y);
1011 style->toolbarEndLoc[orientation] = wxPoint(x, y);
1014 attrNode->QueryIntAttribute(
"width", &x);
1015 attrNode->QueryIntAttribute(
"height", &y);
1016 style->toolbarEndSize[orientation] = wxSize(x, y);
1019 if (nodeType ==
"toolbar-corners") {
1021 attrNode->QueryIntAttribute(
"radius", &r);
1022 style->cornerRadius[orientation] = r;
1025 if (nodeType ==
"background-location") {
1027 attrNode->QueryIntAttribute(
"x", &x);
1028 attrNode->QueryIntAttribute(
"y", &y);
1029 style->normalBGlocation[orientation] = wxPoint(x, y);
1030 style->HasBackground(
true);
1033 if (nodeType ==
"active-location") {
1035 attrNode->QueryIntAttribute(
"x", &x);
1036 attrNode->QueryIntAttribute(
"y", &y);
1037 style->activeBGlocation[orientation] = wxPoint(x, y);
1040 if (nodeType ==
"size") {
1042 attrNode->QueryIntAttribute(
"x", &x);
1043 attrNode->QueryIntAttribute(
"y", &y);
1044 style->toolSize[orientation] = wxSize(x, y);
1047 if (nodeType ==
"icon-offset") {
1049 attrNode->QueryIntAttribute(
"x", &x);
1050 attrNode->QueryIntAttribute(
"y", &y);
1051 style->verticalIconOffset = wxSize(x, y);
1057 if (nodeType ==
"compass") {
1058 TiXmlElement* attrNode = toolNode->FirstChild()->ToElement();
1059 for (; attrNode; attrNode = attrNode->NextSiblingElement()) {
1060 wxString nodeType(attrNode->Value(), wxConvUTF8);
1061 if (nodeType ==
"margin") {
1062 attrNode->QueryIntAttribute(
"top",
1063 &style->compassMarginTop);
1064 attrNode->QueryIntAttribute(
"right",
1065 &style->compassMarginRight);
1066 attrNode->QueryIntAttribute(
"bottom",
1067 &style->compassMarginBottom);
1068 attrNode->QueryIntAttribute(
"left",
1069 &style->compassMarginLeft);
1072 if (nodeType ==
"compass-corners") {
1074 attrNode->QueryIntAttribute(
"radius", &r);
1075 style->compasscornerRadius = r;
1078 if (nodeType ==
"offset") {
1079 attrNode->QueryIntAttribute(
"x", &style->compassXoffset);
1080 attrNode->QueryIntAttribute(
"y", &style->compassYoffset);
1086 if (nodeType ==
"tool") {
1088 style->tools.Add(tool);
1089 tool->name = wxString(toolNode->Attribute(
"name"), wxConvUTF8);
1090 style->toolIndex[tool->name] = style->tools.Count() - 1;
1091 TiXmlHandle toolHandle(toolNode);
1092 TiXmlElement* toolTag =
1093 toolHandle.Child(
"icon-location", 0).ToElement();
1096 toolTag->QueryIntAttribute(
"x", &x);
1097 toolTag->QueryIntAttribute(
"y", &y);
1098 tool->iconLoc = wxPoint(x, y);
1100 toolTag = toolHandle.Child(
"rollover-location", 0).ToElement();
1103 toolTag->QueryIntAttribute(
"x", &x);
1104 toolTag->QueryIntAttribute(
"y", &y);
1105 tool->rolloverLoc = wxPoint(x, y);
1107 toolTag = toolHandle.Child(
"disabled-location", 0).ToElement();
1110 toolTag->QueryIntAttribute(
"x", &x);
1111 toolTag->QueryIntAttribute(
"y", &y);
1112 tool->disabledLoc = wxPoint(x, y);
1114 toolTag = toolHandle.Child(
"size", 0).ToElement();
1117 toolTag->QueryIntAttribute(
"x", &x);
1118 toolTag->QueryIntAttribute(
"y", &y);
1119 tool->customSize = wxSize(x, y);
1132void StyleManager::SetStyle(wxString name) {
1133 Style* style = NULL;
1136 currentStyle->Unload();
1140 bool selectFirst =
false;
1144 bool bstyleFound =
false;
1146 for (
unsigned int i = 0; i < styles.Count(); i++) {
1147 style = (
Style*)(styles.Item(i));
1148 if (style->name == name) {
1154 if ((name.Length() == 0) || !bstyleFound) selectFirst =
true;
1156 for (
unsigned int i = 0; i < styles.Count(); i++) {
1157 style = (
Style*)(styles[i]);
1158 if (style->name == name || selectFirst) {
1159 if (style->graphics) {
1160 currentStyle = style;
1165 wxString fullFilePath = style->myConfigFileDir +
1166 wxFileName::GetPathSeparator() +
1167 style->graphicsFile;
1169 if (!wxFileName::FileExists(fullFilePath)) {
1170 wxString msg(
"Styles Graphics File not found: ");
1171 msg += fullFilePath;
1174 if (selectFirst)
continue;
1180 if (!img.LoadFile(fullFilePath, wxBITMAP_TYPE_PNG)) {
1181 wxString msg(
"Styles Graphics File failed to load: ");
1182 msg += fullFilePath;
1187 style->graphics =
new wxBitmap(img);
1188 currentStyle = style;
1194 if (!ok || !currentStyle->graphics) {
1195 wxString msg(
"The requested style was not found: ");
1202 if ((currentStyle->consoleTextBackgroundSize.x) &&
1203 (currentStyle->consoleTextBackgroundSize.y)) {
1204 currentStyle->consoleTextBackground =
1205 currentStyle->graphics->GetSubBitmap(
1206 wxRect(currentStyle->consoleTextBackgroundLoc,
1207 currentStyle->consoleTextBackgroundSize));
1211 if (currentStyle) nextInvocationStyle = currentStyle->name;
1216Style* StyleManager::GetCurrentStyle() {
return currentStyle; }
Global color handling by name.
wxBitmap MergeBitmaps(wxBitmap back, wxBitmap front, wxSize offset)
ocpnStyle::StyleManager * g_StyleManager
Global instance.
wxBitmap LoadSVG(const wxString filename, const unsigned int width, const unsigned int height, wxBitmap *default_bitmap, bool use_cache)
Load SVG file and return it's bitmap representation of requested size In case file can't be loaded an...