37#include <wx/filename.h>
41#include <wx/dcmemory.h>
50#include "androidUTIL.h"
56using namespace ocpnStyle;
58static void bmdump(wxBitmap bm, wxString name) {
59 wxImage img = bm.ConvertToImage();
60 img.SaveFile(name <<
".png", wxBITMAP_TYPE_PNG);
67wxBitmap
MergeBitmaps(wxBitmap back, wxBitmap front, wxSize offset) {
71 wxImage im_front = front.ConvertToImage();
72 if (!im_front.HasAlpha() && (front.GetWidth() == back.GetWidth()))
82 if (!im_front.HasAlpha()) {
83 wxImage im_back = back.ConvertToImage();
84 back = wxBitmap(im_back);
88 wxBitmap merged(back.GetWidth(), back.GetHeight(), back.GetDepth());
94#if !wxCHECK_VERSION(2, 9, 4)
100 wxImage im_back = back.ConvertToImage();
101 wxImage im_result = back.ConvertToImage();
104 unsigned char* presult = im_result.GetData();
105 unsigned char* pback = im_back.GetData();
106 unsigned char* pfront = im_front.GetData();
108 unsigned char* afront = NULL;
109 if (im_front.HasAlpha()) afront = im_front.GetAlpha();
111 unsigned char* aback = NULL;
112 if (im_back.HasAlpha()) aback = im_back.GetAlpha();
114 unsigned char* aresult = NULL;
115 if (im_result.HasAlpha()) aresult = im_result.GetAlpha();
118 if (presult && pback && pfront) {
119 for (
int i = 0; i < back.GetHeight(); i++) {
120 for (
int j = 0; j < back.GetWidth(); j++) {
121 int fX = j - offset.x;
122 int fY = i - offset.y;
125 if (fX < 0 || fY < 0) inFront =
false;
126 if (fX >= front.GetWidth()) inFront =
false;
127 if (fY >= front.GetHeight()) inFront =
false;
131 if (afront) alphaF = (double)(*afront++) / 255.0;
133 if (aback) alphaB = (double)(*aback++) / 255.0;
134 double alphaRes = alphaF + alphaB * (1.0 - alphaF);
136 unsigned char a = alphaRes * 255;
140 (*pfront++ * alphaF + *pback++ * alphaB * (1.0 - alphaF)) /
144 (*pfront++ * alphaF + *pback++ * alphaB * (1.0 - alphaF)) /
148 (*pfront++ * alphaF + *pback++ * alphaB * (1.0 - alphaF)) /
152 if (aresult && aback) *aresult++ = *aback++;
153 *presult++ = *pback++;
154 *presult++ = *pback++;
155 *presult++ = *pback++;
160 merged = wxBitmap(im_result);
162 wxMemoryDC mdc(merged);
164 mdc.DrawBitmap(back, 0, 0,
true);
165 mdc.DrawBitmap(front, offset.x, offset.y,
true);
166 mdc.SelectObject(wxNullBitmap);
176wxBitmap ConvertTo24Bit(wxColor bgColor, wxBitmap front) {
177 if (front.GetDepth() == 24)
return front;
179#if !wxCHECK_VERSION(2, 9, 4)
183 wxImage im_front = front.ConvertToImage();
184 unsigned char* pfront = im_front.GetData();
185 if (!pfront)
return wxNullBitmap;
187 unsigned char* presult =
188 (
unsigned char*)malloc(front.GetWidth() * front.GetHeight() * 3);
189 if (!presult)
return wxNullBitmap;
191 unsigned char* po_result = presult;
193 unsigned char* afront = NULL;
194 if (im_front.HasAlpha()) afront = im_front.GetAlpha();
196 for (
int i = 0; i < front.GetWidth(); i++) {
197 for (
int j = 0; j < front.GetHeight(); j++) {
199 if (afront) alphaF = (double)(*afront++) / 256.0;
200 unsigned char r = *pfront++ * alphaF + bgColor.Red() * (1.0 - alphaF);
202 unsigned char g = *pfront++ * alphaF + bgColor.Green() * (1.0 - alphaF);
204 unsigned char b = *pfront++ * alphaF + bgColor.Blue() * (1.0 - alphaF);
209 wxImage im_result(front.GetWidth(), front.GetHeight(), po_result);
211 wxBitmap result = wxBitmap(im_result);
215bool Style::NativeToolIconExists(
const wxString& name) {
216 if (toolIndex.find(name) == toolIndex.end())
225wxBitmap Style::GetIconScaled(
const wxString& name,
double scaleFactor,
227 if (iconIndex.find(name) == iconIndex.end()) {
228 wxString msg(
"The requested icon was not found in the style: ");
231 return wxBitmap(GetToolSize().x, GetToolSize().y);
234 int index = iconIndex[name];
238 if (icon->size.x == 0) icon->size = toolSize[currentOrientation];
240 return GetIcon(name, icon->size.x * scaleFactor, icon->size.y * scaleFactor,
244wxBitmap Style::GetIcon(
const wxString& name,
int width,
int height,
246 if (iconIndex.find(name) == iconIndex.end()) {
247 wxString msg(
"The requested icon was not found in the style: ");
250 return wxBitmap(GetToolSize().x, GetToolSize().y);
253 int index = iconIndex[name];
258 if (icon->loaded && !bforceReload)
return icon->icon;
259 if (icon->size.x == 0) icon->size = toolSize[currentOrientation];
261 wxSize retSize = icon->size;
262 if ((width > 0) && (height > 0)) retSize = wxSize(width, height);
266 wxString fullFilePath = myConfigFileDir + this->sysname +
267 wxFileName::GetPathSeparator() + name +
".svg";
268 if (wxFileExists(fullFilePath))
269 bm =
LoadSVG(fullFilePath, retSize.x, retSize.y);
273 wxRect location(icon->iconLoc, icon->size);
274 bm = graphics->GetSubBitmap(location);
275 if (retSize != icon->size) {
276 wxImage scaled_image = bm.ConvertToImage();
278 scaled_image.Scale(retSize.x, retSize.y, wxIMAGE_QUALITY_HIGH));
284 icon->icon = SetBitmapBrightness(bm, colorscheme);
289wxBitmap Style::GetToolIcon(
const wxString& toolname,
int iconType,
290 bool rollover,
int width,
int height) {
291 if (toolIndex.find(toolname) == toolIndex.end()) {
296 return wxBitmap(GetToolSize().x, GetToolSize().y, 1);
299 int index = toolIndex[toolname];
303 wxSize size = tool->customSize;
304 if (size.x == 0) size = toolSize[currentOrientation];
306 wxSize retSize = size;
307 if ((width > 0) && (height > 0)) retSize = wxSize(width, height);
310 case TOOLICON_NORMAL: {
311 if (tool->iconLoaded && !rollover) {
314 if (tool->rolloverLoaded && rollover)
return tool->rollover;
316 wxRect location(tool->iconLoc, size);
320 if ((tool->rolloverLoc.x != 0) || (tool->rolloverLoc.y != 0))
321 location = wxRect(tool->rolloverLoc, size);
324 if (currentOrientation) {
325 location.x -= verticalIconOffset.x;
326 location.y -= verticalIconOffset.y;
331 wxString fullFilePath;
333 fullFilePath = myConfigFileDir + this->sysname +
334 wxFileName::GetPathSeparator() + toolname +
336 if (!wxFileExists(fullFilePath))
337 fullFilePath = myConfigFileDir + this->sysname +
338 wxFileName::GetPathSeparator() + toolname +
".svg";
340 fullFilePath = myConfigFileDir + this->sysname +
341 wxFileName::GetPathSeparator() + toolname +
".svg";
342 if (wxFileExists(fullFilePath))
343 bm =
LoadSVG(fullFilePath, retSize.x, retSize.y);
347 bm = graphics->GetSubBitmap(location);
352 wxBitmap bg(GetToolSize().x, GetToolSize().y);
355 wxBrush(GetGlobalColor(
"GREY2"), wxBRUSHSTYLE_SOLID));
357 mdc.SelectObject(wxNullBitmap);
361 if (retSize != size) {
362 wxImage scaled_image = bm.ConvertToImage();
364 scaled_image.Scale(retSize.x, retSize.y, wxIMAGE_QUALITY_HIGH));
372 tool->rollover = SetBitmapBrightness(bm, colorscheme);
373 tool->rolloverLoaded =
true;
374 return tool->rollover;
376 if (toolname ==
"mob_btn") {
377 double dimLevel = 1.0;
378 if (colorscheme == GLOBAL_COLOR_SCHEME_DUSK)
380 else if (colorscheme == GLOBAL_COLOR_SCHEME_NIGHT)
382 tool->icon = SetBitmapBrightnessAbs(bm, dimLevel);
384 tool->icon = SetBitmapBrightness(bm, colorscheme);
387 tool->iconLoaded =
true;
391 case TOOLICON_TOGGLED: {
392 if (tool->toggledLoaded && !rollover)
return tool->toggled;
393 if (tool->rolloverToggledLoaded && rollover)
return tool->rolloverToggled;
395 wxRect location(tool->iconLoc, size);
396 if (rollover) location = wxRect(tool->rolloverLoc, size);
398 if (GetToolSize() != GetToggledToolSize()) {
399 offset = GetToggledToolSize() - GetToolSize();
402 if (currentOrientation) {
403 location.x -= verticalIconOffset.x;
404 location.y -= verticalIconOffset.y;
408 wxString fullFilePath;
410 fullFilePath = myConfigFileDir + this->sysname +
411 wxFileName::GetPathSeparator() + toolname +
412 "_rollover_toggled.svg";
414 fullFilePath = myConfigFileDir + this->sysname +
415 wxFileName::GetPathSeparator() + toolname +
417 if (wxFileExists(fullFilePath))
418 bm =
LoadSVG(fullFilePath, retSize.x, retSize.y);
422 fullFilePath = myConfigFileDir + this->sysname +
423 wxFileName::GetPathSeparator() + toolname +
426 fullFilePath = myConfigFileDir + this->sysname +
427 wxFileName::GetPathSeparator() + toolname +
".svg";
429 if (wxFileExists(fullFilePath)) {
430 bm =
LoadSVG(fullFilePath, retSize.x, retSize.y);
432 wxBitmap bmBack = GetToggledBG();
433 if ((bmBack.GetWidth() != retSize.x) ||
434 (bmBack.GetHeight() != retSize.y)) {
435 wxImage scaled_back = bmBack.ConvertToImage();
437 scaled_back.Scale(retSize.x, retSize.y, wxIMAGE_QUALITY_HIGH));
445 bm = graphics->GetSubBitmap(location);
448 if (retSize != size) {
449 wxImage scaled_image = bm.ConvertToImage();
451 scaled_image.Scale(retSize.x, retSize.y, wxIMAGE_QUALITY_HIGH));
456 tool->rolloverToggled = SetBitmapBrightness(bm, colorscheme);
457 tool->rolloverToggledLoaded =
true;
458 return tool->rolloverToggled;
460 tool->toggled = SetBitmapBrightness(bm, colorscheme);
461 tool->toggledLoaded =
true;
462 return tool->toggled;
465 case TOOLICON_DISABLED: {
466 if (tool->disabledLoaded)
return tool->disabled;
467 wxRect location(tool->disabledLoc, size);
471 wxString fullFilePath = myConfigFileDir + this->sysname +
472 wxFileName::GetPathSeparator() + toolname +
474 if (wxFileExists(fullFilePath))
475 bm =
LoadSVG(fullFilePath, retSize.x, retSize.y);
479 bm = graphics->GetSubBitmap(location);
485 if (retSize != size) {
486 wxImage scaled_image = bm.ConvertToImage();
488 scaled_image.Scale(retSize.x, retSize.y, wxIMAGE_QUALITY_HIGH));
493 if (currentOrientation) {
494 location.x -= verticalIconOffset.x;
495 location.y -= verticalIconOffset.y;
497 tool->disabled = SetBitmapBrightness(bm, colorscheme);
498 tool->disabledLoaded =
true;
499 return tool->disabled;
503 "A requested icon type for this tool was not found in the style: ");
506 return wxBitmap(GetToolSize().x, GetToolSize().y);
509wxBitmap Style::BuildPluginIcon(wxBitmap& bm,
int iconType,
double factor) {
510 if (!bm.IsOk())
return wxNullBitmap;
515 case TOOLICON_NORMAL:
516 case TOOLICON_TOGGLED: {
519 if (iconType == TOOLICON_NORMAL)
524 if ((bg.GetWidth() >= bm.GetWidth()) &&
525 (bg.GetHeight() >= bm.GetHeight())) {
526 int w = bg.GetWidth() * factor;
527 int h = bg.GetHeight() * factor;
528 wxImage scaled_image = bg.ConvertToImage();
529 bg = wxBitmap(scaled_image.Scale(w, h, wxIMAGE_QUALITY_HIGH));
531 wxSize offset = wxSize(bg.GetWidth() - bm.GetWidth(),
532 bg.GetHeight() - bm.GetHeight());
537 double factor = ((double)bm.GetHeight()) / bg.GetHeight();
538 int nw = bg.GetWidth() * factor;
539 int nh = bm.GetHeight();
540 if (bg.GetWidth() == bg.GetHeight()) nw = nh;
541 wxImage scaled_image = bg.ConvertToImage();
542 bg = wxBitmap(scaled_image.Scale(nw, nh, wxIMAGE_QUALITY_HIGH));
544 wxSize offset = wxSize(bg.GetWidth() - bm.GetWidth(),
545 bg.GetHeight() - bm.GetHeight());
551 wxBitmap bg(GetToolSize().x, GetToolSize().y);
553 wxSize offset = GetToolSize() - wxSize(bm.GetWidth(), bm.GetHeight());
555 mdc.SetBackground(wxBrush(GetGlobalColor(
"GREY2"), wxBRUSHSTYLE_SOLID));
557 mdc.SelectObject(wxNullBitmap);
566 return SetBitmapBrightness(iconbm, colorscheme);
569wxBitmap Style::SetBitmapBrightness(wxBitmap& bitmap, ColorScheme cs) {
572 case GLOBAL_COLOR_SCHEME_DUSK: {
576 case GLOBAL_COLOR_SCHEME_NIGHT: {
585 return SetBitmapBrightnessAbs(bitmap, dimLevel);
588wxBitmap Style::SetBitmapBrightnessAbs(wxBitmap& bitmap,
double level) {
589 wxImage image = bitmap.ConvertToImage();
591 int gimg_width = image.GetWidth();
592 int gimg_height = image.GetHeight();
594 for (
int iy = 0; iy < gimg_height; iy++) {
595 for (
int ix = 0; ix < gimg_width; ix++) {
596 if (!image.IsTransparent(ix, iy, 30)) {
597 wxImage::RGBValue rgb(image.GetRed(ix, iy), image.GetGreen(ix, iy),
598 image.GetBlue(ix, iy));
599 wxImage::HSVValue hsv = wxImage::RGBtoHSV(rgb);
600 hsv.value = hsv.value * level;
601 wxImage::RGBValue nrgb = wxImage::HSVtoRGB(hsv);
602 image.SetRGB(ix, iy, nrgb.red, nrgb.green, nrgb.blue);
606 return wxBitmap(image);
609wxBitmap Style::GetNormalBG() {
610 wxSize size = toolSize[currentOrientation];
611 return graphics->GetSubBitmap(wxRect(normalBGlocation[currentOrientation].x,
612 normalBGlocation[currentOrientation].y,
616wxBitmap Style::GetActiveBG() {
617 return graphics->GetSubBitmap(wxRect(activeBGlocation[currentOrientation].x,
618 activeBGlocation[currentOrientation].y,
619 toolSize[currentOrientation].x,
620 toolSize[currentOrientation].y));
623wxBitmap Style::GetToggledBG() {
624 wxSize size = toolSize[currentOrientation];
625 if (toggledBGSize[currentOrientation].x) {
626 size = toggledBGSize[currentOrientation];
628 return graphics->GetSubBitmap(
629 wxRect(toggledBGlocation[currentOrientation], size));
632wxBitmap Style::GetToolbarStart() {
633 wxSize size = toolbarStartSize[currentOrientation];
634 if (toolbarStartSize[currentOrientation].x == 0) {
635 size = toolbarStartSize[currentOrientation];
637 return graphics->GetSubBitmap(
638 wxRect(toolbarStartLoc[currentOrientation], size));
641wxBitmap Style::GetToolbarEnd() {
642 wxSize size = toolbarEndSize[currentOrientation];
643 if (toolbarEndSize[currentOrientation].x == 0) {
644 size = toolbarEndSize[currentOrientation];
646 return graphics->GetSubBitmap(
647 wxRect(toolbarEndLoc[currentOrientation], size));
650int Style::GetToolbarCornerRadius() {
return cornerRadius[currentOrientation]; }
652void Style::DrawToolbarLineStart(wxBitmap& bmp,
double scale) {
653 if (!HasToolbarStart())
return;
655 wxBitmap sbmp = GetToolbarStart();
656 if (fabs(
scale - 1.0) > 0.01) {
657 int h = sbmp.GetHeight() *
scale;
658 int w = sbmp.GetWidth() *
scale;
659 if ((h > 0) && (w > 0)) {
660 wxImage scaled_image = sbmp.ConvertToImage();
661 sbmp = wxBitmap(scaled_image.Scale(w, h, wxIMAGE_QUALITY_HIGH));
664 dc.DrawBitmap(sbmp, 0, 0,
true);
665 dc.SelectObject(wxNullBitmap);
668void Style::DrawToolbarLineEnd(wxBitmap& bmp,
double scale) {
669 if (!HasToolbarStart())
return;
671 wxBitmap sbmp = GetToolbarEnd();
672 if (fabs(
scale - 1.0) > 0.01) {
673 int h = sbmp.GetHeight() *
scale;
674 int w = sbmp.GetWidth() *
scale;
675 if ((h > 0) && (w > 0)) {
676 wxImage scaled_image = sbmp.ConvertToImage();
677 sbmp = wxBitmap(scaled_image.Scale(w, h, wxIMAGE_QUALITY_HIGH));
681 if (currentOrientation) {
682 dc.DrawBitmap(sbmp, 0, bmp.GetHeight() - sbmp.GetHeight(),
true);
684 dc.DrawBitmap(sbmp, bmp.GetWidth() - sbmp.GetWidth(), 0,
true);
686 dc.SelectObject(wxNullBitmap);
689void Style::SetOrientation(
long orient) {
691 if (orient == wxTB_VERTICAL) newOrient = 1;
692 if (newOrient == currentOrientation)
return;
693 currentOrientation = newOrient;
697int Style::GetOrientation() {
return currentOrientation; }
699void Style::SetColorScheme(ColorScheme cs) {
703 if ((consoleTextBackgroundSize.x) && (consoleTextBackgroundSize.y)) {
704 wxBitmap bm = graphics->GetSubBitmap(
705 wxRect(consoleTextBackgroundLoc, consoleTextBackgroundSize));
710 consoleTextBackground = SetBitmapBrightness(bm, cs);
714void Style::Unload() {
715 for (
unsigned int i = 0; i < tools.Count(); i++) {
720 for (
unsigned int i = 0; i < icons.Count(); i++) {
728 currentOrientation = 0;
729 colorscheme = GLOBAL_COLOR_SCHEME_DAY;
730 marginsInvisible =
false;
731 hasBackground =
false;
732 chartStatusIconWidth = 0;
733 chartStatusWindowTransparent =
false;
738 compassMarginTop = 4;
739 compassMarginRight = 0;
740 compassMarginBottom = 4;
741 compassMarginLeft = 4;
742 compasscornerRadius = 3;
746 for (
int i = 0; i < 2; i++) {
747 toolbarStartLoc[i] = wxPoint(0, 0);
748 toolbarEndLoc[i] = wxPoint(0, 0);
754 for (
unsigned int i = 0; i < tools.Count(); i++) {
755 delete (
Tool*)(tools[i]);
759 for (
unsigned int i = 0; i < icons.Count(); i++) {
760 delete (
Icon*)(icons[i]);
764 if (graphics)
delete graphics;
770StyleManager::StyleManager() {
773 Init(g_Platform->GetSharedDataDir() +
"uidata" +
774 wxFileName::GetPathSeparator());
775 Init(g_Platform->GetHomeDir());
776 Init(g_Platform->GetHomeDir() +
".opencpn" + wxFileName::GetPathSeparator());
779 wxLogMessage(
"Using SVG Icons");
781 wxLogMessage(
"Using PNG Icons");
785StyleManager::StyleManager(
const wxString& configDir) {
792StyleManager::~StyleManager() {
793 for (
unsigned int i = 0; i < styles.Count(); i++) {
794 delete (
Style*)(styles[i]);
799void StyleManager::Init(
const wxString& fromPath) {
802 if (!wxDir::Exists(fromPath)) {
803 wxString msg =
"No styles found at: ";
810 if (!dir.IsOpened())
return;
817 bool more = dir.GetFirst(&filename,
"style*.xml", wxDIR_FILES);
820 wxString msg =
"No styles found at: ";
826 bool firstFile =
true;
828 wxString name, extension;
830 if (!firstFile) more = dir.GetNext(&filename);
834 wxString fullFilePath = fromPath + filename;
836 if (!doc.LoadFile((
const char*)fullFilePath.mb_str())) {
837 wxString msg(
"Attempt to load styles from this file failed: ");
843 wxString msg(
"Styles loading from ");
847 TiXmlHandle hRoot(doc.RootElement());
849 wxString root = wxString(doc.RootElement()->Value(), wxConvUTF8);
850 if (root !=
"styles") {
851 wxLogMessage(
" StyleManager: Expected XML Root <styles> not found.");
855 TiXmlElement* styleElem = hRoot.FirstChild().Element();
857 for (; styleElem; styleElem = styleElem->NextSiblingElement()) {
858 if (wxString(styleElem->Value(), wxConvUTF8) ==
"style") {
862 style->name = wxString(styleElem->Attribute(
"name"), wxConvUTF8);
863 style->sysname = wxString(styleElem->Attribute(
"sysname"), wxConvUTF8);
864 style->myConfigFileDir = fromPath;
866 TiXmlElement* subNode = styleElem->FirstChild()->ToElement();
868 for (; subNode; subNode = subNode->NextSiblingElement()) {
869 wxString nodeType(subNode->Value(), wxConvUTF8);
871 if (nodeType ==
"description") {
872 style->description = wxString(subNode->GetText(), wxConvUTF8);
875 if (nodeType ==
"chart-status-icon") {
877 subNode->QueryIntAttribute(
"width", &w);
878 style->chartStatusIconWidth = w;
881 if (nodeType ==
"chart-status-window") {
882 style->chartStatusWindowTransparent =
883 wxString(subNode->Attribute(
"transparent"), wxConvUTF8)
888 if (nodeType ==
"embossed-indicators") {
890 wxString(subNode->Attribute(
"font"), wxConvUTF8);
891 subNode->QueryIntAttribute(
"size", &(style->embossHeight));
894 if (nodeType ==
"graphics-file") {
895 style->graphicsFile =
896 wxString(subNode->Attribute(
"name"), wxConvUTF8);
900 if (nodeType ==
"active-route") {
901 TiXmlHandle handle(subNode);
902 TiXmlElement* tag = handle.Child(
"font-color", 0).ToElement();
905 tag->QueryIntAttribute(
"r", &r);
906 tag->QueryIntAttribute(
"g", &g);
907 tag->QueryIntAttribute(
"b", &b);
908 style->consoleFontColor = wxColour(r, g, b);
910 tag = handle.Child(
"text-background-location", 0).ToElement();
913 tag->QueryIntAttribute(
"x", &x);
914 tag->QueryIntAttribute(
"y", &y);
915 tag->QueryIntAttribute(
"width", &w);
916 tag->QueryIntAttribute(
"height", &h);
917 style->consoleTextBackgroundLoc = wxPoint(x, y);
918 style->consoleTextBackgroundSize = wxSize(w, h);
922 if (nodeType ==
"icons") {
923 TiXmlElement* iconNode = subNode->FirstChild()->ToElement();
925 for (; iconNode; iconNode = iconNode->NextSiblingElement()) {
926 wxString nodeType(iconNode->Value(), wxConvUTF8);
927 if (nodeType ==
"icon") {
929 style->icons.Add(icon);
930 icon->name = wxString(iconNode->Attribute(
"name"), wxConvUTF8);
931 style->iconIndex[icon->name] = style->icons.Count() - 1;
932 TiXmlHandle handle(iconNode);
934 handle.Child(
"icon-location", 0).ToElement();
937 tag->QueryIntAttribute(
"x", &x);
938 tag->QueryIntAttribute(
"y", &y);
939 icon->iconLoc = wxPoint(x, y);
941 tag = handle.Child(
"size", 0).ToElement();
944 tag->QueryIntAttribute(
"x", &x);
945 tag->QueryIntAttribute(
"y", &y);
946 icon->size = wxSize(x, y);
951 if (nodeType ==
"tools") {
952 TiXmlElement* toolNode = subNode->FirstChild()->ToElement();
954 for (; toolNode; toolNode = toolNode->NextSiblingElement()) {
955 wxString nodeType(toolNode->Value(), wxConvUTF8);
957 if (nodeType ==
"horizontal" || nodeType ==
"vertical") {
959 if (nodeType ==
"vertical") orientation = 1;
961 TiXmlElement* attrNode = toolNode->FirstChild()->ToElement();
962 for (; attrNode; attrNode = attrNode->NextSiblingElement()) {
963 wxString nodeType(attrNode->Value(), wxConvUTF8);
964 if (nodeType ==
"separation") {
965 attrNode->QueryIntAttribute(
966 "distance", &style->toolSeparation[orientation]);
969 if (nodeType ==
"margin") {
970 attrNode->QueryIntAttribute(
971 "top", &style->toolMarginTop[orientation]);
972 attrNode->QueryIntAttribute(
973 "right", &style->toolMarginRight[orientation]);
974 attrNode->QueryIntAttribute(
975 "bottom", &style->toolMarginBottom[orientation]);
976 attrNode->QueryIntAttribute(
977 "left", &style->toolMarginLeft[orientation]);
979 wxString(attrNode->Attribute(
"invisible"), wxConvUTF8);
980 style->marginsInvisible = (invis.Lower() ==
"true");
984 if (nodeType ==
"toggled-location") {
986 attrNode->QueryIntAttribute(
"x", &x);
987 attrNode->QueryIntAttribute(
"y", &y);
988 style->toggledBGlocation[orientation] = wxPoint(x, y);
991 attrNode->QueryIntAttribute(
"width", &x);
992 attrNode->QueryIntAttribute(
"height", &y);
993 style->toggledBGSize[orientation] = wxSize(x, y);
996 if (nodeType ==
"toolbar-start") {
998 attrNode->QueryIntAttribute(
"x", &x);
999 attrNode->QueryIntAttribute(
"y", &y);
1000 style->toolbarStartLoc[orientation] = wxPoint(x, y);
1003 attrNode->QueryIntAttribute(
"width", &x);
1004 attrNode->QueryIntAttribute(
"height", &y);
1005 style->toolbarStartSize[orientation] = wxSize(x, y);
1008 if (nodeType ==
"toolbar-end") {
1010 attrNode->QueryIntAttribute(
"x", &x);
1011 attrNode->QueryIntAttribute(
"y", &y);
1012 style->toolbarEndLoc[orientation] = wxPoint(x, y);
1015 attrNode->QueryIntAttribute(
"width", &x);
1016 attrNode->QueryIntAttribute(
"height", &y);
1017 style->toolbarEndSize[orientation] = wxSize(x, y);
1020 if (nodeType ==
"toolbar-corners") {
1022 attrNode->QueryIntAttribute(
"radius", &r);
1023 style->cornerRadius[orientation] = r;
1026 if (nodeType ==
"background-location") {
1028 attrNode->QueryIntAttribute(
"x", &x);
1029 attrNode->QueryIntAttribute(
"y", &y);
1030 style->normalBGlocation[orientation] = wxPoint(x, y);
1031 style->HasBackground(
true);
1034 if (nodeType ==
"active-location") {
1036 attrNode->QueryIntAttribute(
"x", &x);
1037 attrNode->QueryIntAttribute(
"y", &y);
1038 style->activeBGlocation[orientation] = wxPoint(x, y);
1041 if (nodeType ==
"size") {
1043 attrNode->QueryIntAttribute(
"x", &x);
1044 attrNode->QueryIntAttribute(
"y", &y);
1045 style->toolSize[orientation] = wxSize(x, y);
1048 if (nodeType ==
"icon-offset") {
1050 attrNode->QueryIntAttribute(
"x", &x);
1051 attrNode->QueryIntAttribute(
"y", &y);
1052 style->verticalIconOffset = wxSize(x, y);
1058 if (nodeType ==
"compass") {
1059 TiXmlElement* attrNode = toolNode->FirstChild()->ToElement();
1060 for (; attrNode; attrNode = attrNode->NextSiblingElement()) {
1061 wxString nodeType(attrNode->Value(), wxConvUTF8);
1062 if (nodeType ==
"margin") {
1063 attrNode->QueryIntAttribute(
"top",
1064 &style->compassMarginTop);
1065 attrNode->QueryIntAttribute(
"right",
1066 &style->compassMarginRight);
1067 attrNode->QueryIntAttribute(
"bottom",
1068 &style->compassMarginBottom);
1069 attrNode->QueryIntAttribute(
"left",
1070 &style->compassMarginLeft);
1073 if (nodeType ==
"compass-corners") {
1075 attrNode->QueryIntAttribute(
"radius", &r);
1076 style->compasscornerRadius = r;
1079 if (nodeType ==
"offset") {
1080 attrNode->QueryIntAttribute(
"x", &style->compassXoffset);
1081 attrNode->QueryIntAttribute(
"y", &style->compassYoffset);
1087 if (nodeType ==
"tool") {
1089 style->tools.Add(tool);
1090 tool->name = wxString(toolNode->Attribute(
"name"), wxConvUTF8);
1091 style->toolIndex[tool->name] = style->tools.Count() - 1;
1092 TiXmlHandle toolHandle(toolNode);
1093 TiXmlElement* toolTag =
1094 toolHandle.Child(
"icon-location", 0).ToElement();
1097 toolTag->QueryIntAttribute(
"x", &x);
1098 toolTag->QueryIntAttribute(
"y", &y);
1099 tool->iconLoc = wxPoint(x, y);
1101 toolTag = toolHandle.Child(
"rollover-location", 0).ToElement();
1104 toolTag->QueryIntAttribute(
"x", &x);
1105 toolTag->QueryIntAttribute(
"y", &y);
1106 tool->rolloverLoc = wxPoint(x, y);
1108 toolTag = toolHandle.Child(
"disabled-location", 0).ToElement();
1111 toolTag->QueryIntAttribute(
"x", &x);
1112 toolTag->QueryIntAttribute(
"y", &y);
1113 tool->disabledLoc = wxPoint(x, y);
1115 toolTag = toolHandle.Child(
"size", 0).ToElement();
1118 toolTag->QueryIntAttribute(
"x", &x);
1119 toolTag->QueryIntAttribute(
"y", &y);
1120 tool->customSize = wxSize(x, y);
1133void StyleManager::SetStyle(wxString name) {
1134 Style* style = NULL;
1137 currentStyle->Unload();
1141 bool selectFirst =
false;
1145 bool bstyleFound =
false;
1147 for (
unsigned int i = 0; i < styles.Count(); i++) {
1148 style = (
Style*)(styles.Item(i));
1149 if (style->name == name) {
1155 if ((name.Length() == 0) || !bstyleFound) selectFirst =
true;
1157 for (
unsigned int i = 0; i < styles.Count(); i++) {
1158 style = (
Style*)(styles[i]);
1159 if (style->name == name || selectFirst) {
1160 if (style->graphics) {
1161 currentStyle = style;
1166 wxString fullFilePath = style->myConfigFileDir +
1167 wxFileName::GetPathSeparator() +
1168 style->graphicsFile;
1170 if (!wxFileName::FileExists(fullFilePath)) {
1171 wxString msg(
"Styles Graphics File not found: ");
1172 msg += fullFilePath;
1175 if (selectFirst)
continue;
1181 if (!img.LoadFile(fullFilePath, wxBITMAP_TYPE_PNG)) {
1182 wxString msg(
"Styles Graphics File failed to load: ");
1183 msg += fullFilePath;
1188 style->graphics =
new wxBitmap(img);
1189 currentStyle = style;
1195 if (!ok || !currentStyle->graphics) {
1196 wxString msg(
"The requested style was not found: ");
1203 if ((currentStyle->consoleTextBackgroundSize.x) &&
1204 (currentStyle->consoleTextBackgroundSize.y)) {
1205 currentStyle->consoleTextBackground =
1206 currentStyle->graphics->GetSubBitmap(
1207 wxRect(currentStyle->consoleTextBackgroundLoc,
1208 currentStyle->consoleTextBackgroundSize));
1212 if (currentStyle) nextInvocationStyle = currentStyle->name;
1217Style* 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...