File: styles.h

package info (click to toggle)
opencpn 5.2.4%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 101,540 kB
  • sloc: ansic: 414,598; cpp: 253,008; xml: 83,748; sh: 409; python: 353; makefile: 110; javascript: 87; perl: 83
file content (228 lines) | stat: -rw-r--r-- 7,689 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
/***************************************************************************
 *
 * Project:  OpenCPN
 * Purpose:  Chart Symbols
 * Author:   Jesper Weissglas
 *
 ***************************************************************************
 *   Copyright (C) 2010 by David S. Register                               *
 *   bdbcat@yahoo.com                                                      *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,  USA.         *
 **************************************************************************/

#pragma once
#include <tinyxml.h>

#include "ocpn_types.h"

enum StyleToolIconTypes
{
      TOOLICON_NORMAL,
      TOOLICON_TOGGLED,
      TOOLICON_DISABLED,
      TOOLICON_ACTIVE
};

void bmdump(wxBitmap bm, wxString name);
wxBitmap MergeBitmaps( wxBitmap back, wxBitmap front, wxSize offset );
wxBitmap ConvertTo24Bit( wxColor bgColor, wxBitmap front );

namespace ocpnStyle {

WX_DECLARE_STRING_HASH_MAP( int, intHash );

class Tool {
public:
      wxString name;
      wxPoint iconLoc;
      wxPoint rolloverLoc;
      wxPoint disabledLoc;
      wxPoint activeLoc;
      wxBitmap icon;
      wxBitmap rollover;
      wxBitmap rolloverToggled;
      wxBitmap disabled;
      wxBitmap active;
      wxBitmap toggled;
      bool iconLoaded;
      bool rolloverLoaded;
      bool rolloverToggledLoaded;
      bool disabledLoaded;
      bool activeLoaded;
      bool toggledLoaded;
      wxSize customSize;

      void Unload(void) {
            iconLoaded= false;
            rolloverLoaded = false;
            rolloverToggledLoaded = false;
            disabledLoaded = false;
            activeLoaded =false;
            toggledLoaded =false;
            customSize = wxSize( 32, 32 );
      }

      Tool(void) {
          Unload();
      }
};

class Icon {
public:
      wxString name;
      wxPoint iconLoc;
      wxSize size;
      wxBitmap icon;
      bool loaded;

      void Unload(void) {
            loaded = false;
      }

      Icon(void) { Unload(); }
};

class Style {

public:
      Style( void );
      ~Style( void );

      wxBitmap GetNormalBG();
      wxBitmap GetActiveBG();
      wxBitmap GetToggledBG();
      wxBitmap GetToolbarStart();
      wxBitmap GetToolbarEnd();
      bool HasBackground() const { return hasBackground; }
      void HasBackground( bool b ) { hasBackground = b; }
      wxBitmap GetIcon(const wxString & name, int width = -1, int height = -1, bool bforceReload = false);
      wxBitmap GetToolIcon(const wxString & toolname,
                           int iconType = TOOLICON_NORMAL, bool rollover = false,
                           int width = -1, int height = -1);
      wxBitmap BuildPluginIcon( wxBitmap &bm, int iconType, double scale = 1.0 );
      bool NativeToolIconExists(const wxString & name);
      
      int GetTopMargin() const { return toolMarginTop[currentOrientation]; }
      int GetRightMargin() const { return toolMarginRight[currentOrientation]; }
      int GetBottomMargin() const { return toolMarginBottom[currentOrientation]; }
      int GetLeftMargin() const { return toolMarginLeft[currentOrientation]; }
      int GetToolbarCornerRadius();

      int GetCompassTopMargin() const { return compassMarginTop; }
      int GetCompassRightMargin() const { return compassMarginRight; }
      int GetCompassBottomMargin() const { return compassMarginBottom; }
      int GetCompassLeftMargin() const { return compassMarginLeft; }
      int GetCompassCornerRadius() const { return compasscornerRadius; }
      int GetCompassXOffset() const { return compassXoffset; }
      int GetCompassYOffset() const { return compassYoffset; }

      int GetToolSeparation() const { return toolSeparation[currentOrientation]; }
      wxSize GetToolSize() const { return toolSize[currentOrientation]; }
      wxSize GetToggledToolSize() const { return toggledBGSize[currentOrientation]; }

      bool HasToolbarStart() const { return toolbarStartLoc[currentOrientation] != wxPoint(0,0); }
      bool HasToolbarEnd() const { return toolbarEndLoc[currentOrientation] != wxPoint(0,0); }
      void DrawToolbarLineStart( wxBitmap& bmp, double scale = 1.0 );
      void DrawToolbarLineEnd( wxBitmap& bmp, double scale = 1.0 );

      static wxBitmap SetBitmapBrightness( wxBitmap& bitmap, ColorScheme cs );
      static wxBitmap SetBitmapBrightnessAbs( wxBitmap& bitmap, double level );
      
      void SetOrientation( long orient );
      int GetOrientation();
      void SetColorScheme( ColorScheme cs );
      void Unload();

      wxString name;
      wxString sysname;
      wxString description;
      wxString graphicsFile;
      int toolMarginTop[2];
      int toolMarginRight[2];
      int toolMarginBottom[2];
      int toolMarginLeft[2];
      int toolSeparation[2];
      int cornerRadius[2];
      int compassMarginTop;
      int compassMarginRight;
      int compassMarginBottom;
      int compassMarginLeft;
      int compasscornerRadius;
      int compassXoffset;
      int compassYoffset;

      wxSize toolSize[2];
      wxSize toggledBGSize[2];
      wxPoint toggledBGlocation[2];
      wxPoint activeBGlocation[2];
      wxPoint normalBGlocation[2];
      wxSize verticalIconOffset;
      wxArrayPtrVoid tools;
      intHash toolIndex;
      wxArrayPtrVoid icons;
      intHash iconIndex;
      wxBitmap* graphics;

      wxColor consoleFontColor;
      wxPoint consoleTextBackgroundLoc;
      wxSize consoleTextBackgroundSize;
      wxPoint toolbarStartLoc[2];
      wxSize toolbarStartSize[2];
      wxPoint toolbarEndLoc[2];
      wxSize toolbarEndSize[2];
      wxBitmap consoleTextBackground;
      wxBitmap toolbarStart[2];
      wxBitmap toolbarEnd[2];

      bool marginsInvisible;

      int chartStatusIconWidth;
      bool chartStatusWindowTransparent;

      wxString embossFont;
      int embossHeight;

      wxString myConfigFileDir;

private:
      int currentOrientation;
      ColorScheme colorscheme;
      bool hasBackground;
};

class StyleManager {
public:
      StyleManager(void);
      ~StyleManager(void);
      StyleManager(const wxString & configDir);

      bool IsOK() const { return isOK; }
      void Init(const wxString & fromPath);
      void SetStyle(wxString name);
      void SetStyleNextInvocation(const wxString & name) { nextInvocationStyle = name; }
      const wxString & GetStyleNextInvocation() const { return nextInvocationStyle; }
      Style* GetCurrentStyle();
      wxArrayPtrVoid GetArrayOfStyles() { return styles; };

private:
      bool isOK;
      wxArrayPtrVoid styles;
      Style* currentStyle;
      wxString nextInvocationStyle;
};

}