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 ||
379 colorscheme == GLOBAL_COLOR_SCHEME_NIGHT_HICON)
381 else if (colorscheme == GLOBAL_COLOR_SCHEME_NIGHT)
383 tool->icon = SetBitmapBrightnessAbs(bm, dimLevel);
385 tool->icon = SetBitmapBrightness(bm, colorscheme);
388 tool->iconLoaded =
true;
392 case TOOLICON_TOGGLED: {
393 if (tool->toggledLoaded && !rollover)
return tool->toggled;
394 if (tool->rolloverToggledLoaded && rollover)
return tool->rolloverToggled;
396 wxRect location(tool->iconLoc, size);
397 if (rollover) location = wxRect(tool->rolloverLoc, size);
399 if (GetToolSize() != GetToggledToolSize()) {
400 offset = GetToggledToolSize() - GetToolSize();
403 if (currentOrientation) {
404 location.x -= verticalIconOffset.x;
405 location.y -= verticalIconOffset.y;
409 wxString fullFilePath;
411 fullFilePath = myConfigFileDir + this->sysname +
412 wxFileName::GetPathSeparator() + toolname +
413 "_rollover_toggled.svg";
415 fullFilePath = myConfigFileDir + this->sysname +
416 wxFileName::GetPathSeparator() + toolname +
418 if (wxFileExists(fullFilePath))
419 bm =
LoadSVG(fullFilePath, retSize.x, retSize.y);
423 fullFilePath = myConfigFileDir + this->sysname +
424 wxFileName::GetPathSeparator() + toolname +
427 fullFilePath = myConfigFileDir + this->sysname +
428 wxFileName::GetPathSeparator() + toolname +
".svg";
430 if (wxFileExists(fullFilePath)) {
431 bm =
LoadSVG(fullFilePath, retSize.x, retSize.y);
433 wxBitmap bmBack = GetToggledBG();
434 if ((bmBack.GetWidth() != retSize.x) ||
435 (bmBack.GetHeight() != retSize.y)) {
436 wxImage scaled_back = bmBack.ConvertToImage();
438 scaled_back.Scale(retSize.x, retSize.y, wxIMAGE_QUALITY_HIGH));
446 bm = graphics->GetSubBitmap(location);
449 if (retSize != size) {
450 wxImage scaled_image = bm.ConvertToImage();
452 scaled_image.Scale(retSize.x, retSize.y, wxIMAGE_QUALITY_HIGH));
457 tool->rolloverToggled = SetBitmapBrightness(bm, colorscheme);
458 tool->rolloverToggledLoaded =
true;
459 return tool->rolloverToggled;
461 tool->toggled = SetBitmapBrightness(bm, colorscheme);
462 tool->toggledLoaded =
true;
463 return tool->toggled;
466 case TOOLICON_DISABLED: {
467 if (tool->disabledLoaded)
return tool->disabled;
468 wxRect location(tool->disabledLoc, size);
472 wxString fullFilePath = myConfigFileDir + this->sysname +
473 wxFileName::GetPathSeparator() + toolname +
475 if (wxFileExists(fullFilePath))
476 bm =
LoadSVG(fullFilePath, retSize.x, retSize.y);
480 bm = graphics->GetSubBitmap(location);
486 if (retSize != size) {
487 wxImage scaled_image = bm.ConvertToImage();
489 scaled_image.Scale(retSize.x, retSize.y, wxIMAGE_QUALITY_HIGH));
494 if (currentOrientation) {
495 location.x -= verticalIconOffset.x;
496 location.y -= verticalIconOffset.y;
498 tool->disabled = SetBitmapBrightness(bm, colorscheme);
499 tool->disabledLoaded =
true;
500 return tool->disabled;
504 "A requested icon type for this tool was not found in the style: ");
507 return wxBitmap(GetToolSize().x, GetToolSize().y);
510wxBitmap Style::BuildPluginIcon(wxBitmap& bm,
int iconType,
double factor) {
511 if (!bm.IsOk())
return wxNullBitmap;
516 case TOOLICON_NORMAL:
517 case TOOLICON_TOGGLED: {
520 if (iconType == TOOLICON_NORMAL)
525 if ((bg.GetWidth() >= bm.GetWidth()) &&
526 (bg.GetHeight() >= bm.GetHeight())) {
527 int w = bg.GetWidth() * factor;
528 int h = bg.GetHeight() * factor;
529 wxImage scaled_image = bg.ConvertToImage();
530 bg = wxBitmap(scaled_image.Scale(w, h, wxIMAGE_QUALITY_HIGH));
532 wxSize offset = wxSize(bg.GetWidth() - bm.GetWidth(),
533 bg.GetHeight() - bm.GetHeight());
538 double factor = ((double)bm.GetHeight()) / bg.GetHeight();
539 int nw = bg.GetWidth() * factor;
540 int nh = bm.GetHeight();
541 if (bg.GetWidth() == bg.GetHeight()) nw = nh;
542 wxImage scaled_image = bg.ConvertToImage();
543 bg = wxBitmap(scaled_image.Scale(nw, nh, wxIMAGE_QUALITY_HIGH));
545 wxSize offset = wxSize(bg.GetWidth() - bm.GetWidth(),
546 bg.GetHeight() - bm.GetHeight());
552 wxBitmap bg(GetToolSize().x, GetToolSize().y);
554 wxSize offset = GetToolSize() - wxSize(bm.GetWidth(), bm.GetHeight());
556 mdc.SetBackground(wxBrush(GetGlobalColor(
"GREY2"), wxBRUSHSTYLE_SOLID));
558 mdc.SelectObject(wxNullBitmap);
567 return SetBitmapBrightness(iconbm, colorscheme);
570wxBitmap Style::SetBitmapBrightness(wxBitmap& bitmap, ColorScheme cs) {
573 case GLOBAL_COLOR_SCHEME_DUSK:
574 case GLOBAL_COLOR_SCHEME_NIGHT_HICON: {
578 case GLOBAL_COLOR_SCHEME_NIGHT: {
587 return SetBitmapBrightnessAbs(bitmap, dimLevel);
590wxBitmap Style::SetBitmapBrightnessAbs(wxBitmap& bitmap,
double level) {
591 wxImage image = bitmap.ConvertToImage();
593 int gimg_width = image.GetWidth();
594 int gimg_height = image.GetHeight();
596 for (
int iy = 0; iy < gimg_height; iy++) {
597 for (
int ix = 0; ix < gimg_width; ix++) {
598 if (!image.IsTransparent(ix, iy, 30)) {
599 wxImage::RGBValue rgb(image.GetRed(ix, iy), image.GetGreen(ix, iy),
600 image.GetBlue(ix, iy));
601 wxImage::HSVValue hsv = wxImage::RGBtoHSV(rgb);
602 hsv.value = hsv.value * level;
603 wxImage::RGBValue nrgb = wxImage::HSVtoRGB(hsv);
604 image.SetRGB(ix, iy, nrgb.red, nrgb.green, nrgb.blue);
608 return wxBitmap(image);
611wxBitmap Style::GetNormalBG() {
612 wxSize size = toolSize[currentOrientation];
613 return graphics->GetSubBitmap(wxRect(normalBGlocation[currentOrientation].x,
614 normalBGlocation[currentOrientation].y,
618wxBitmap Style::GetActiveBG() {
619 return graphics->GetSubBitmap(wxRect(activeBGlocation[currentOrientation].x,
620 activeBGlocation[currentOrientation].y,
621 toolSize[currentOrientation].x,
622 toolSize[currentOrientation].y));
625wxBitmap Style::GetToggledBG() {
626 wxSize size = toolSize[currentOrientation];
627 if (toggledBGSize[currentOrientation].x) {
628 size = toggledBGSize[currentOrientation];
630 return graphics->GetSubBitmap(
631 wxRect(toggledBGlocation[currentOrientation], size));
634wxBitmap Style::GetToolbarStart() {
635 wxSize size = toolbarStartSize[currentOrientation];
636 if (toolbarStartSize[currentOrientation].x == 0) {
637 size = toolbarStartSize[currentOrientation];
639 return graphics->GetSubBitmap(
640 wxRect(toolbarStartLoc[currentOrientation], size));
643wxBitmap Style::GetToolbarEnd() {
644 wxSize size = toolbarEndSize[currentOrientation];
645 if (toolbarEndSize[currentOrientation].x == 0) {
646 size = toolbarEndSize[currentOrientation];
648 return graphics->GetSubBitmap(
649 wxRect(toolbarEndLoc[currentOrientation], size));
652int Style::GetToolbarCornerRadius() {
return cornerRadius[currentOrientation]; }
654void Style::DrawToolbarLineStart(wxBitmap& bmp,
double scale) {
655 if (!HasToolbarStart())
return;
657 wxBitmap sbmp = GetToolbarStart();
658 if (fabs(
scale - 1.0) > 0.01) {
659 int h = sbmp.GetHeight() *
scale;
660 int w = sbmp.GetWidth() *
scale;
661 if ((h > 0) && (w > 0)) {
662 wxImage scaled_image = sbmp.ConvertToImage();
663 sbmp = wxBitmap(scaled_image.Scale(w, h, wxIMAGE_QUALITY_HIGH));
666 dc.DrawBitmap(sbmp, 0, 0,
true);
667 dc.SelectObject(wxNullBitmap);
670void Style::DrawToolbarLineEnd(wxBitmap& bmp,
double scale) {
671 if (!HasToolbarStart())
return;
673 wxBitmap sbmp = GetToolbarEnd();
674 if (fabs(
scale - 1.0) > 0.01) {
675 int h = sbmp.GetHeight() *
scale;
676 int w = sbmp.GetWidth() *
scale;
677 if ((h > 0) && (w > 0)) {
678 wxImage scaled_image = sbmp.ConvertToImage();
679 sbmp = wxBitmap(scaled_image.Scale(w, h, wxIMAGE_QUALITY_HIGH));
683 if (currentOrientation) {
684 dc.DrawBitmap(sbmp, 0, bmp.GetHeight() - sbmp.GetHeight(),
true);
686 dc.DrawBitmap(sbmp, bmp.GetWidth() - sbmp.GetWidth(), 0,
true);
688 dc.SelectObject(wxNullBitmap);
691void Style::SetOrientation(
long orient) {
693 if (orient == wxTB_VERTICAL) newOrient = 1;
694 if (newOrient == currentOrientation)
return;
695 currentOrientation = newOrient;
699int Style::GetOrientation() {
return currentOrientation; }
701void Style::SetColorScheme(ColorScheme cs) {
705 if ((consoleTextBackgroundSize.x) && (consoleTextBackgroundSize.y)) {
706 wxBitmap bm = graphics->GetSubBitmap(
707 wxRect(consoleTextBackgroundLoc, consoleTextBackgroundSize));
712 consoleTextBackground = SetBitmapBrightness(bm, cs);
716void Style::Unload() {
717 for (
unsigned int i = 0; i < tools.Count(); i++) {
722 for (
unsigned int i = 0; i < icons.Count(); i++) {
730 currentOrientation = 0;
731 colorscheme = GLOBAL_COLOR_SCHEME_DAY;
732 marginsInvisible =
false;
733 hasBackground =
false;
734 chartStatusIconWidth = 0;
735 chartStatusWindowTransparent =
false;
740 compassMarginTop = 4;
741 compassMarginRight = 0;
742 compassMarginBottom = 4;
743 compassMarginLeft = 4;
744 compasscornerRadius = 3;
748 for (
int i = 0; i < 2; i++) {
749 toolbarStartLoc[i] = wxPoint(0, 0);
750 toolbarEndLoc[i] = wxPoint(0, 0);
756 for (
unsigned int i = 0; i < tools.Count(); i++) {
757 delete (
Tool*)(tools[i]);
761 for (
unsigned int i = 0; i < icons.Count(); i++) {
762 delete (
Icon*)(icons[i]);
766 if (graphics)
delete graphics;
772StyleManager::StyleManager() {
775 Init(g_Platform->GetSharedDataDir() +
"uidata" +
776 wxFileName::GetPathSeparator());
777 Init(g_Platform->GetHomeDir());
778 Init(g_Platform->GetHomeDir() +
".opencpn" + wxFileName::GetPathSeparator());
781 wxLogMessage(
"Using SVG Icons");
783 wxLogMessage(
"Using PNG Icons");
787StyleManager::StyleManager(
const wxString& configDir) {
794StyleManager::~StyleManager() {
795 for (
unsigned int i = 0; i < styles.Count(); i++) {
796 delete (
Style*)(styles[i]);
801void StyleManager::Init(
const wxString& fromPath) {
804 if (!wxDir::Exists(fromPath)) {
805 wxString msg =
"No styles found at: ";
812 if (!dir.IsOpened())
return;
819 bool more = dir.GetFirst(&filename,
"style*.xml", wxDIR_FILES);
822 wxString msg =
"No styles found at: ";
828 bool firstFile =
true;
830 wxString name, extension;
832 if (!firstFile) more = dir.GetNext(&filename);
836 wxString fullFilePath = fromPath + filename;
838 if (!doc.LoadFile((
const char*)fullFilePath.mb_str())) {
839 wxString msg(
"Attempt to load styles from this file failed: ");
845 wxString msg(
"Styles loading from ");
849 TiXmlHandle hRoot(doc.RootElement());
851 wxString root = wxString(doc.RootElement()->Value(), wxConvUTF8);
852 if (root !=
"styles") {
853 wxLogMessage(
" StyleManager: Expected XML Root <styles> not found.");
857 TiXmlElement* styleElem = hRoot.FirstChild().Element();
859 for (; styleElem; styleElem = styleElem->NextSiblingElement()) {
860 if (wxString(styleElem->Value(), wxConvUTF8) ==
"style") {
864 style->name = wxString(styleElem->Attribute(
"name"), wxConvUTF8);
865 style->sysname = wxString(styleElem->Attribute(
"sysname"), wxConvUTF8);
866 style->myConfigFileDir = fromPath;
868 TiXmlElement* subNode = styleElem->FirstChild()->ToElement();
870 for (; subNode; subNode = subNode->NextSiblingElement()) {
871 wxString nodeType(subNode->Value(), wxConvUTF8);
873 if (nodeType ==
"description") {
874 style->description = wxString(subNode->GetText(), wxConvUTF8);
877 if (nodeType ==
"chart-status-icon") {
879 subNode->QueryIntAttribute(
"width", &w);
880 style->chartStatusIconWidth = w;
883 if (nodeType ==
"chart-status-window") {
884 style->chartStatusWindowTransparent =
885 wxString(subNode->Attribute(
"transparent"), wxConvUTF8)
890 if (nodeType ==
"embossed-indicators") {
892 wxString(subNode->Attribute(
"font"), wxConvUTF8);
893 subNode->QueryIntAttribute(
"size", &(style->embossHeight));
896 if (nodeType ==
"graphics-file") {
897 style->graphicsFile =
898 wxString(subNode->Attribute(
"name"), wxConvUTF8);
902 if (nodeType ==
"active-route") {
903 TiXmlHandle handle(subNode);
904 TiXmlElement* tag = handle.Child(
"font-color", 0).ToElement();
907 tag->QueryIntAttribute(
"r", &r);
908 tag->QueryIntAttribute(
"g", &g);
909 tag->QueryIntAttribute(
"b", &b);
910 style->consoleFontColor = wxColour(r, g, b);
912 tag = handle.Child(
"text-background-location", 0).ToElement();
915 tag->QueryIntAttribute(
"x", &x);
916 tag->QueryIntAttribute(
"y", &y);
917 tag->QueryIntAttribute(
"width", &w);
918 tag->QueryIntAttribute(
"height", &h);
919 style->consoleTextBackgroundLoc = wxPoint(x, y);
920 style->consoleTextBackgroundSize = wxSize(w, h);
924 if (nodeType ==
"icons") {
925 TiXmlElement* iconNode = subNode->FirstChild()->ToElement();
927 for (; iconNode; iconNode = iconNode->NextSiblingElement()) {
928 wxString nodeType(iconNode->Value(), wxConvUTF8);
929 if (nodeType ==
"icon") {
931 style->icons.Add(icon);
932 icon->name = wxString(iconNode->Attribute(
"name"), wxConvUTF8);
933 style->iconIndex[icon->name] = style->icons.Count() - 1;
934 TiXmlHandle handle(iconNode);
936 handle.Child(
"icon-location", 0).ToElement();
939 tag->QueryIntAttribute(
"x", &x);
940 tag->QueryIntAttribute(
"y", &y);
941 icon->iconLoc = wxPoint(x, y);
943 tag = handle.Child(
"size", 0).ToElement();
946 tag->QueryIntAttribute(
"x", &x);
947 tag->QueryIntAttribute(
"y", &y);
948 icon->size = wxSize(x, y);
953 if (nodeType ==
"tools") {
954 TiXmlElement* toolNode = subNode->FirstChild()->ToElement();
956 for (; toolNode; toolNode = toolNode->NextSiblingElement()) {
957 wxString nodeType(toolNode->Value(), wxConvUTF8);
959 if (nodeType ==
"horizontal" || nodeType ==
"vertical") {
961 if (nodeType ==
"vertical") orientation = 1;
963 TiXmlElement* attrNode = toolNode->FirstChild()->ToElement();
964 for (; attrNode; attrNode = attrNode->NextSiblingElement()) {
965 wxString nodeType(attrNode->Value(), wxConvUTF8);
966 if (nodeType ==
"separation") {
967 attrNode->QueryIntAttribute(
968 "distance", &style->toolSeparation[orientation]);
971 if (nodeType ==
"margin") {
972 attrNode->QueryIntAttribute(
973 "top", &style->toolMarginTop[orientation]);
974 attrNode->QueryIntAttribute(
975 "right", &style->toolMarginRight[orientation]);
976 attrNode->QueryIntAttribute(
977 "bottom", &style->toolMarginBottom[orientation]);
978 attrNode->QueryIntAttribute(
979 "left", &style->toolMarginLeft[orientation]);
981 wxString(attrNode->Attribute(
"invisible"), wxConvUTF8);
982 style->marginsInvisible = (invis.Lower() ==
"true");
986 if (nodeType ==
"toggled-location") {
988 attrNode->QueryIntAttribute(
"x", &x);
989 attrNode->QueryIntAttribute(
"y", &y);
990 style->toggledBGlocation[orientation] = wxPoint(x, y);
993 attrNode->QueryIntAttribute(
"width", &x);
994 attrNode->QueryIntAttribute(
"height", &y);
995 style->toggledBGSize[orientation] = wxSize(x, y);
998 if (nodeType ==
"toolbar-start") {
1000 attrNode->QueryIntAttribute(
"x", &x);
1001 attrNode->QueryIntAttribute(
"y", &y);
1002 style->toolbarStartLoc[orientation] = wxPoint(x, y);
1005 attrNode->QueryIntAttribute(
"width", &x);
1006 attrNode->QueryIntAttribute(
"height", &y);
1007 style->toolbarStartSize[orientation] = wxSize(x, y);
1010 if (nodeType ==
"toolbar-end") {
1012 attrNode->QueryIntAttribute(
"x", &x);
1013 attrNode->QueryIntAttribute(
"y", &y);
1014 style->toolbarEndLoc[orientation] = wxPoint(x, y);
1017 attrNode->QueryIntAttribute(
"width", &x);
1018 attrNode->QueryIntAttribute(
"height", &y);
1019 style->toolbarEndSize[orientation] = wxSize(x, y);
1022 if (nodeType ==
"toolbar-corners") {
1024 attrNode->QueryIntAttribute(
"radius", &r);
1025 style->cornerRadius[orientation] = r;
1028 if (nodeType ==
"background-location") {
1030 attrNode->QueryIntAttribute(
"x", &x);
1031 attrNode->QueryIntAttribute(
"y", &y);
1032 style->normalBGlocation[orientation] = wxPoint(x, y);
1033 style->HasBackground(
true);
1036 if (nodeType ==
"active-location") {
1038 attrNode->QueryIntAttribute(
"x", &x);
1039 attrNode->QueryIntAttribute(
"y", &y);
1040 style->activeBGlocation[orientation] = wxPoint(x, y);
1043 if (nodeType ==
"size") {
1045 attrNode->QueryIntAttribute(
"x", &x);
1046 attrNode->QueryIntAttribute(
"y", &y);
1047 style->toolSize[orientation] = wxSize(x, y);
1050 if (nodeType ==
"icon-offset") {
1052 attrNode->QueryIntAttribute(
"x", &x);
1053 attrNode->QueryIntAttribute(
"y", &y);
1054 style->verticalIconOffset = wxSize(x, y);
1060 if (nodeType ==
"compass") {
1061 TiXmlElement* attrNode = toolNode->FirstChild()->ToElement();
1062 for (; attrNode; attrNode = attrNode->NextSiblingElement()) {
1063 wxString nodeType(attrNode->Value(), wxConvUTF8);
1064 if (nodeType ==
"margin") {
1065 attrNode->QueryIntAttribute(
"top",
1066 &style->compassMarginTop);
1067 attrNode->QueryIntAttribute(
"right",
1068 &style->compassMarginRight);
1069 attrNode->QueryIntAttribute(
"bottom",
1070 &style->compassMarginBottom);
1071 attrNode->QueryIntAttribute(
"left",
1072 &style->compassMarginLeft);
1075 if (nodeType ==
"compass-corners") {
1077 attrNode->QueryIntAttribute(
"radius", &r);
1078 style->compasscornerRadius = r;
1081 if (nodeType ==
"offset") {
1082 attrNode->QueryIntAttribute(
"x", &style->compassXoffset);
1083 attrNode->QueryIntAttribute(
"y", &style->compassYoffset);
1089 if (nodeType ==
"tool") {
1091 style->tools.Add(tool);
1092 tool->name = wxString(toolNode->Attribute(
"name"), wxConvUTF8);
1093 style->toolIndex[tool->name] = style->tools.Count() - 1;
1094 TiXmlHandle toolHandle(toolNode);
1095 TiXmlElement* toolTag =
1096 toolHandle.Child(
"icon-location", 0).ToElement();
1099 toolTag->QueryIntAttribute(
"x", &x);
1100 toolTag->QueryIntAttribute(
"y", &y);
1101 tool->iconLoc = wxPoint(x, y);
1103 toolTag = toolHandle.Child(
"rollover-location", 0).ToElement();
1106 toolTag->QueryIntAttribute(
"x", &x);
1107 toolTag->QueryIntAttribute(
"y", &y);
1108 tool->rolloverLoc = wxPoint(x, y);
1110 toolTag = toolHandle.Child(
"disabled-location", 0).ToElement();
1113 toolTag->QueryIntAttribute(
"x", &x);
1114 toolTag->QueryIntAttribute(
"y", &y);
1115 tool->disabledLoc = wxPoint(x, y);
1117 toolTag = toolHandle.Child(
"size", 0).ToElement();
1120 toolTag->QueryIntAttribute(
"x", &x);
1121 toolTag->QueryIntAttribute(
"y", &y);
1122 tool->customSize = wxSize(x, y);
1135void StyleManager::SetStyle(wxString name) {
1136 Style* style = NULL;
1139 currentStyle->Unload();
1143 bool selectFirst =
false;
1147 bool bstyleFound =
false;
1149 for (
unsigned int i = 0; i < styles.Count(); i++) {
1150 style = (
Style*)(styles.Item(i));
1151 if (style->name == name) {
1157 if ((name.Length() == 0) || !bstyleFound) selectFirst =
true;
1159 for (
unsigned int i = 0; i < styles.Count(); i++) {
1160 style = (
Style*)(styles[i]);
1161 if (style->name == name || selectFirst) {
1162 if (style->graphics) {
1163 currentStyle = style;
1168 wxString fullFilePath = style->myConfigFileDir +
1169 wxFileName::GetPathSeparator() +
1170 style->graphicsFile;
1172 if (!wxFileName::FileExists(fullFilePath)) {
1173 wxString msg(
"Styles Graphics File not found: ");
1174 msg += fullFilePath;
1177 if (selectFirst)
continue;
1183 if (!img.LoadFile(fullFilePath, wxBITMAP_TYPE_PNG)) {
1184 wxString msg(
"Styles Graphics File failed to load: ");
1185 msg += fullFilePath;
1190 style->graphics =
new wxBitmap(img);
1191 currentStyle = style;
1197 if (!ok || !currentStyle->graphics) {
1198 wxString msg(
"The requested style was not found: ");
1205 if ((currentStyle->consoleTextBackgroundSize.x) &&
1206 (currentStyle->consoleTextBackgroundSize.y)) {
1207 currentStyle->consoleTextBackground =
1208 currentStyle->graphics->GetSubBitmap(
1209 wxRect(currentStyle->consoleTextBackgroundLoc,
1210 currentStyle->consoleTextBackgroundSize));
1214 if (currentStyle) nextInvocationStyle = currentStyle->name;
1219Style* 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...