1 /*************************************************************************** 2 * 3 * Project: OpenCPN 4 * Purpose: Chart Symbols 5 * Author: Jesper Weissglas 6 * 7 *************************************************************************** 8 * Copyright (C) 2010 by David S. Register * 9 * bdbcat@yahoo.com * 10 * * 11 * This program is free software; you can redistribute it and/or modify * 12 * it under the terms of the GNU General Public License as published by * 13 * the Free Software Foundation; either version 2 of the License, or * 14 * (at your option) any later version. * 15 * * 16 * This program is distributed in the hope that it will be useful, * 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 19 * GNU General Public License for more details. * 20 * * 21 * You should have received a copy of the GNU General Public License * 22 * along with this program; if not, write to the * 23 * Free Software Foundation, Inc., * 24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * 25 **************************************************************************/ 26 27 #pragma once 28 #include <tinyxml.h> 29 30 #include "ocpn_types.h" 31 32 enum StyleToolIconTypes 33 { 34 TOOLICON_NORMAL, 35 TOOLICON_TOGGLED, 36 TOOLICON_DISABLED, 37 TOOLICON_ACTIVE 38 }; 39 40 void bmdump(wxBitmap bm, wxString name); 41 wxBitmap MergeBitmaps( wxBitmap back, wxBitmap front, wxSize offset ); 42 wxBitmap ConvertTo24Bit( wxColor bgColor, wxBitmap front ); 43 44 namespace ocpnStyle { 45 46 WX_DECLARE_STRING_HASH_MAP( int, intHash ); 47 48 class Tool { 49 public: 50 wxString name; 51 wxPoint iconLoc; 52 wxPoint rolloverLoc; 53 wxPoint disabledLoc; 54 wxPoint activeLoc; 55 wxBitmap icon; 56 wxBitmap rollover; 57 wxBitmap rolloverToggled; 58 wxBitmap disabled; 59 wxBitmap active; 60 wxBitmap toggled; 61 bool iconLoaded; 62 bool rolloverLoaded; 63 bool rolloverToggledLoaded; 64 bool disabledLoaded; 65 bool activeLoaded; 66 bool toggledLoaded; 67 wxSize customSize; 68 Unload(void)69 void Unload(void) { 70 iconLoaded= false; 71 rolloverLoaded = false; 72 rolloverToggledLoaded = false; 73 disabledLoaded = false; 74 activeLoaded =false; 75 toggledLoaded =false; 76 customSize = wxSize( 32, 32 ); 77 } 78 Tool(void)79 Tool(void) { 80 Unload(); 81 } 82 }; 83 84 class Icon { 85 public: 86 wxString name; 87 wxPoint iconLoc; 88 wxSize size; 89 wxBitmap icon; 90 bool loaded; 91 Unload(void)92 void Unload(void) { 93 loaded = false; 94 } 95 Icon(void)96 Icon(void) { Unload(); } 97 }; 98 99 class Style { 100 101 public: 102 Style( void ); 103 ~Style( void ); 104 105 wxBitmap GetNormalBG(); 106 wxBitmap GetActiveBG(); 107 wxBitmap GetToggledBG(); 108 wxBitmap GetToolbarStart(); 109 wxBitmap GetToolbarEnd(); HasBackground()110 bool HasBackground() const { return hasBackground; } HasBackground(bool b)111 void HasBackground( bool b ) { hasBackground = b; } 112 wxBitmap GetIcon(const wxString & name, int width = -1, int height = -1, bool bforceReload = false); 113 wxBitmap GetToolIcon(const wxString & toolname, 114 int iconType = TOOLICON_NORMAL, bool rollover = false, 115 int width = -1, int height = -1); 116 wxBitmap BuildPluginIcon( wxBitmap &bm, int iconType, double scale = 1.0 ); 117 bool NativeToolIconExists(const wxString & name); 118 GetTopMargin()119 int GetTopMargin() const { return toolMarginTop[currentOrientation]; } GetRightMargin()120 int GetRightMargin() const { return toolMarginRight[currentOrientation]; } GetBottomMargin()121 int GetBottomMargin() const { return toolMarginBottom[currentOrientation]; } GetLeftMargin()122 int GetLeftMargin() const { return toolMarginLeft[currentOrientation]; } 123 int GetToolbarCornerRadius(); 124 GetCompassTopMargin()125 int GetCompassTopMargin() const { return compassMarginTop; } GetCompassRightMargin()126 int GetCompassRightMargin() const { return compassMarginRight; } GetCompassBottomMargin()127 int GetCompassBottomMargin() const { return compassMarginBottom; } GetCompassLeftMargin()128 int GetCompassLeftMargin() const { return compassMarginLeft; } GetCompassCornerRadius()129 int GetCompassCornerRadius() const { return compasscornerRadius; } GetCompassXOffset()130 int GetCompassXOffset() const { return compassXoffset; } GetCompassYOffset()131 int GetCompassYOffset() const { return compassYoffset; } 132 GetToolSeparation()133 int GetToolSeparation() const { return toolSeparation[currentOrientation]; } GetToolSize()134 wxSize GetToolSize() const { return toolSize[currentOrientation]; } GetToggledToolSize()135 wxSize GetToggledToolSize() const { return toggledBGSize[currentOrientation]; } 136 HasToolbarStart()137 bool HasToolbarStart() const { return toolbarStartLoc[currentOrientation] != wxPoint(0,0); } HasToolbarEnd()138 bool HasToolbarEnd() const { return toolbarEndLoc[currentOrientation] != wxPoint(0,0); } 139 void DrawToolbarLineStart( wxBitmap& bmp, double scale = 1.0 ); 140 void DrawToolbarLineEnd( wxBitmap& bmp, double scale = 1.0 ); 141 142 static wxBitmap SetBitmapBrightness( wxBitmap& bitmap, ColorScheme cs ); 143 static wxBitmap SetBitmapBrightnessAbs( wxBitmap& bitmap, double level ); 144 145 void SetOrientation( long orient ); 146 int GetOrientation(); 147 void SetColorScheme( ColorScheme cs ); 148 void Unload(); 149 150 wxString name; 151 wxString sysname; 152 wxString description; 153 wxString graphicsFile; 154 int toolMarginTop[2]; 155 int toolMarginRight[2]; 156 int toolMarginBottom[2]; 157 int toolMarginLeft[2]; 158 int toolSeparation[2]; 159 int cornerRadius[2]; 160 int compassMarginTop; 161 int compassMarginRight; 162 int compassMarginBottom; 163 int compassMarginLeft; 164 int compasscornerRadius; 165 int compassXoffset; 166 int compassYoffset; 167 168 wxSize toolSize[2]; 169 wxSize toggledBGSize[2]; 170 wxPoint toggledBGlocation[2]; 171 wxPoint activeBGlocation[2]; 172 wxPoint normalBGlocation[2]; 173 wxSize verticalIconOffset; 174 wxArrayPtrVoid tools; 175 intHash toolIndex; 176 wxArrayPtrVoid icons; 177 intHash iconIndex; 178 wxBitmap* graphics; 179 180 wxColor consoleFontColor; 181 wxPoint consoleTextBackgroundLoc; 182 wxSize consoleTextBackgroundSize; 183 wxPoint toolbarStartLoc[2]; 184 wxSize toolbarStartSize[2]; 185 wxPoint toolbarEndLoc[2]; 186 wxSize toolbarEndSize[2]; 187 wxBitmap consoleTextBackground; 188 wxBitmap toolbarStart[2]; 189 wxBitmap toolbarEnd[2]; 190 191 bool marginsInvisible; 192 193 int chartStatusIconWidth; 194 bool chartStatusWindowTransparent; 195 196 wxString embossFont; 197 int embossHeight; 198 199 wxString myConfigFileDir; 200 201 private: 202 int currentOrientation; 203 ColorScheme colorscheme; 204 bool hasBackground; 205 }; 206 207 class StyleManager { 208 public: 209 StyleManager(void); 210 ~StyleManager(void); 211 StyleManager(const wxString & configDir); 212 IsOK()213 bool IsOK() const { return isOK; } 214 void Init(const wxString & fromPath); 215 void SetStyle(wxString name); SetStyleNextInvocation(const wxString & name)216 void SetStyleNextInvocation(const wxString & name) { nextInvocationStyle = name; } GetStyleNextInvocation()217 const wxString & GetStyleNextInvocation() const { return nextInvocationStyle; } 218 Style* GetCurrentStyle(); GetArrayOfStyles()219 wxArrayPtrVoid GetArrayOfStyles() { return styles; }; 220 221 private: 222 bool isOK; 223 wxArrayPtrVoid styles; 224 Style* currentStyle; 225 wxString nextInvocationStyle; 226 }; 227 228 } 229