OpenCPN Partial API docs
styles.h
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 #ifndef _STYLES_H__
28 #define _STYLES_H__
29 
30 #include <wx/bitmap.h>
31 #include <wx/colour.h>
32 #include <wx/dynarray.h>
33 #include <wx/gdicmn.h>
34 #include <wx/string.h>
35 
36 #include "model/ocpn_types.h"
37 //#include "tinyxml.h"
38 #include "color_types.h"
39 
40 enum StyleToolIconTypes {
41  TOOLICON_NORMAL,
42  TOOLICON_TOGGLED,
43  TOOLICON_DISABLED,
44  TOOLICON_ACTIVE
45 };
46 
47 void bmdump(wxBitmap bm, wxString name);
48 wxBitmap MergeBitmaps(wxBitmap back, wxBitmap front, wxSize offset);
49 wxBitmap ConvertTo24Bit(wxColor bgColor, wxBitmap front);
50 
51 namespace ocpnStyle {
52 
53 WX_DECLARE_STRING_HASH_MAP(int, intHash);
54 
55 class Tool {
56 public:
57  wxString name;
58  wxPoint iconLoc;
59  wxPoint rolloverLoc;
60  wxPoint disabledLoc;
61  wxPoint activeLoc;
62  wxBitmap icon;
63  wxBitmap rollover;
64  wxBitmap rolloverToggled;
65  wxBitmap disabled;
66  wxBitmap active;
67  wxBitmap toggled;
68  bool iconLoaded;
69  bool rolloverLoaded;
70  bool rolloverToggledLoaded;
71  bool disabledLoaded;
72  bool activeLoaded;
73  bool toggledLoaded;
74  wxSize customSize;
75 
76  void Unload(void) {
77  iconLoaded = false;
78  rolloverLoaded = false;
79  rolloverToggledLoaded = false;
80  disabledLoaded = false;
81  activeLoaded = false;
82  toggledLoaded = false;
83  customSize = wxSize(32, 32);
84  }
85 
86  Tool(void) { Unload(); }
87 };
88 
89 class Icon {
90 public:
91  wxString name;
92  wxPoint iconLoc;
93  wxSize size;
94  wxBitmap icon;
95  bool loaded;
96 
97  void Unload(void) { loaded = false; }
98 
99  Icon(void) { Unload(); }
100 };
101 
102 class Style {
103 public:
104  Style(void);
105  ~Style(void);
106 
107  wxBitmap GetNormalBG();
108  wxBitmap GetActiveBG();
109  wxBitmap GetToggledBG();
110  wxBitmap GetToolbarStart();
111  wxBitmap GetToolbarEnd();
112  bool HasBackground() const { return hasBackground; }
113  void HasBackground(bool b) { hasBackground = b; }
114  wxBitmap GetIcon(const wxString& name, int width = -1, int height = -1,
115  bool bforceReload = false);
116  wxBitmap GetIconScaled(const wxString& name, double scaleFactor,
117  bool bforceReload = false );
118 
119  wxBitmap GetToolIcon(const wxString& toolname, int iconType = TOOLICON_NORMAL,
120  bool rollover = false, int width = -1, int height = -1);
121  wxBitmap BuildPluginIcon(wxBitmap& bm, int iconType, double scale = 1.0);
122  bool NativeToolIconExists(const wxString& name);
123 
124  int GetTopMargin() const { return toolMarginTop[currentOrientation]; }
125  int GetRightMargin() const { return toolMarginRight[currentOrientation]; }
126  int GetBottomMargin() const { return toolMarginBottom[currentOrientation]; }
127  int GetLeftMargin() const { return toolMarginLeft[currentOrientation]; }
128  int GetToolbarCornerRadius();
129 
130  int GetCompassTopMargin() const { return compassMarginTop; }
131  int GetCompassRightMargin() const { return compassMarginRight; }
132  int GetCompassBottomMargin() const { return compassMarginBottom; }
133  int GetCompassLeftMargin() const { return compassMarginLeft; }
134  int GetCompassCornerRadius() const { return compasscornerRadius; }
135  int GetCompassXOffset() const { return compassXoffset; }
136  int GetCompassYOffset() const { return compassYoffset; }
137 
138  int GetToolSeparation() const { return toolSeparation[currentOrientation]; }
139  wxSize GetToolSize() const { return toolSize[currentOrientation]; }
140  wxSize GetToggledToolSize() const {
141  return toggledBGSize[currentOrientation];
142  }
143 
144  bool HasToolbarStart() const {
145  return toolbarStartLoc[currentOrientation] != wxPoint(0, 0);
146  }
147  bool HasToolbarEnd() const {
148  return toolbarEndLoc[currentOrientation] != wxPoint(0, 0);
149  }
150  void DrawToolbarLineStart(wxBitmap& bmp, double scale = 1.0);
151  void DrawToolbarLineEnd(wxBitmap& bmp, double scale = 1.0);
152 
153  static wxBitmap SetBitmapBrightness(wxBitmap& bitmap, ColorScheme cs);
154  static wxBitmap SetBitmapBrightnessAbs(wxBitmap& bitmap, double level);
155 
156  void SetOrientation(long orient);
157  int GetOrientation();
158  void SetColorScheme(ColorScheme cs);
159  void Unload();
160 
161  wxString name;
162  wxString sysname;
163  wxString description;
164  wxString graphicsFile;
165  int toolMarginTop[2];
166  int toolMarginRight[2];
167  int toolMarginBottom[2];
168  int toolMarginLeft[2];
169  int toolSeparation[2];
170  int cornerRadius[2];
171  int compassMarginTop;
172  int compassMarginRight;
173  int compassMarginBottom;
174  int compassMarginLeft;
175  int compasscornerRadius;
176  int compassXoffset;
177  int compassYoffset;
178 
179  wxSize toolSize[2];
180  wxSize toggledBGSize[2];
181  wxPoint toggledBGlocation[2];
182  wxPoint activeBGlocation[2];
183  wxPoint normalBGlocation[2];
184  wxSize verticalIconOffset;
185  wxArrayPtrVoid tools;
186  intHash toolIndex;
187  wxArrayPtrVoid icons;
188  intHash iconIndex;
189  wxBitmap* graphics;
190 
191  wxColor consoleFontColor;
192  wxPoint consoleTextBackgroundLoc;
193  wxSize consoleTextBackgroundSize;
194  wxPoint toolbarStartLoc[2];
195  wxSize toolbarStartSize[2];
196  wxPoint toolbarEndLoc[2];
197  wxSize toolbarEndSize[2];
198  wxBitmap consoleTextBackground;
199  wxBitmap toolbarStart[2];
200  wxBitmap toolbarEnd[2];
201 
202  bool marginsInvisible;
203 
204  int chartStatusIconWidth;
205  bool chartStatusWindowTransparent;
206 
207  wxString embossFont;
208  int embossHeight;
209 
210  wxString myConfigFileDir;
211 
212 private:
213  int currentOrientation;
214  ColorScheme colorscheme;
215  bool hasBackground;
216 };
217 
219 public:
220  StyleManager(void);
221  ~StyleManager(void);
222  StyleManager(const wxString& configDir);
223 
224  bool IsOK() const { return isOK; }
225  void Init(const wxString& fromPath);
226  void SetStyle(wxString name);
227  void SetStyleNextInvocation(const wxString& name) {
228  nextInvocationStyle = name;
229  }
230  const wxString& GetStyleNextInvocation() const { return nextInvocationStyle; }
231  Style* GetCurrentStyle();
232  wxArrayPtrVoid GetArrayOfStyles() { return styles; };
233 
234 private:
235  bool isOK;
236  wxArrayPtrVoid styles;
237  Style* currentStyle;
238  wxString nextInvocationStyle;
239 };
240 
241 } // namespace ocpnStyle
242 
243 #endif // _STYLES_H__
Definition: Quilt.cpp:867