]> git.saurik.com Git - wxWidgets.git/blob - contrib/samples/ogl/studio/symbols.cpp
The Return of WM Size Hints Part IV.
[wxWidgets.git] / contrib / samples / ogl / studio / symbols.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: symbols.cpp
3 // Purpose: Implements the Studio symbol database
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 12/07/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence:
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 // #pragma implementation
14 #endif
15
16 // For compilers that support precompilation, includes "wx.h".
17 #include <wx/wxprec.h>
18
19 #ifdef __BORLANDC__
20 #pragma hdrstop
21 #endif
22
23 #ifndef WX_PRECOMP
24 #include <wx/wx.h>
25 #endif
26
27 #include <wx/wxexpr.h>
28
29 #include "studio.h"
30 #include "doc.h"
31 #include "shapes.h"
32 #include "view.h"
33 #include "symbols.h"
34
35 /*
36 * csSymbol
37 * Represents information about a symbol.
38 */
39
40 csSymbol::csSymbol(const wxString& name, wxShape* shape)
41 {
42 m_name = name;
43 m_shape = shape;
44 m_toolId = 0;
45 }
46
47 csSymbol::~csSymbol()
48 {
49 delete m_shape;
50 }
51
52 /*
53 * A table of all possible shapes.
54 * We can use this to construct a palette, etc.
55 */
56 csSymbolDatabase::csSymbolDatabase()
57 {
58 m_currentId = 800;
59 }
60
61 csSymbolDatabase::~csSymbolDatabase()
62 {
63 ClearSymbols();
64 }
65
66 void csSymbolDatabase::AddSymbol(csSymbol* symbol)
67 {
68 symbol->SetToolId(m_currentId);
69 m_symbols.Append(symbol);
70
71 m_currentId ++;
72 }
73
74 void csSymbolDatabase::ClearSymbols()
75 {
76 wxNode* node = m_symbols.First();
77 while (node)
78 {
79 csSymbol* symbol = (csSymbol*) node->Data();
80 delete symbol;
81
82 node = node->Next();
83 }
84 m_symbols.Clear();
85 }
86
87 csSymbol* csSymbolDatabase::FindSymbol(const wxString& name) const
88 {
89 wxNode* node = m_symbols.First();
90 while (node)
91 {
92 csSymbol* symbol = (csSymbol*) node->Data();
93 if (symbol->GetName() == name)
94 return symbol;
95
96 node = node->Next();
97 }
98 return NULL;
99 }
100
101 csSymbol* csSymbolDatabase::FindSymbol(int toolId) const
102 {
103 wxNode* node = m_symbols.First();
104 while (node)
105 {
106 csSymbol* symbol = (csSymbol*) node->Data();
107 if (symbol->GetToolId() == toolId)
108 return symbol;
109
110 node = node->Next();
111 }
112 return NULL;
113 }
114
115 // Add symbols to database
116 void csApp::InitSymbols()
117 {
118 m_symbolDatabase = new csSymbolDatabase;
119
120 wxShape* shape = new csCircleShape();
121 shape->AssignNewIds();
122 shape->SetEventHandler(new csEvtHandler(shape, shape, wxString("")));
123
124 m_symbolDatabase->AddSymbol(new csSymbol("Circle", shape));
125
126 shape = new csCircleShadowShape();
127 shape->AssignNewIds();
128 shape->SetEventHandler(new csEvtHandler(shape, shape, wxString("")));
129
130 m_symbolDatabase->AddSymbol(new csSymbol("Circle shadow", shape));
131
132 shape = new csThinRectangleShape();
133 shape->AssignNewIds();
134 shape->SetEventHandler(new csEvtHandler(shape, shape, wxString("")));
135
136 m_symbolDatabase->AddSymbol(new csSymbol("Thin Rectangle", shape));
137
138 shape = new csWideRectangleShape();
139 shape->AssignNewIds();
140 shape->SetEventHandler(new csEvtHandler(shape, shape, wxString("")));
141
142 m_symbolDatabase->AddSymbol(new csSymbol("Wide Rectangle", shape));
143
144 shape = new csSemiCircleShape();
145 shape->AssignNewIds();
146 shape->SetEventHandler(new csEvtHandler(shape, shape, wxString("")));
147
148 m_symbolDatabase->AddSymbol(new csSymbol("SemiCircle", shape));
149
150 shape = new csTriangleShape();
151 shape->AssignNewIds();
152 shape->SetEventHandler(new csEvtHandler(shape, shape, wxString("")));
153
154 m_symbolDatabase->AddSymbol(new csSymbol("Triangle", shape));
155
156 shape = new csOctagonShape();
157 shape->AssignNewIds();
158 shape->SetEventHandler(new csEvtHandler(shape, shape, wxString("")));
159
160 m_symbolDatabase->AddSymbol(new csSymbol("Octagon", shape));
161
162 shape = new csGroupShape();
163 shape->AssignNewIds();
164 shape->SetEventHandler(new csEvtHandler(shape, shape, wxString("")));
165
166 m_symbolDatabase->AddSymbol(new csSymbol("Group", shape));
167 }
168
169 wxBitmap* csSymbolDatabase::CreateToolBitmap(csSymbol* symbol)
170 {
171 int objectBitmapSize = 32;
172
173 symbol->GetShape()->Recompute();
174
175 wxBitmap *newBitmap = new wxBitmap(objectBitmapSize, objectBitmapSize);
176
177 wxMemoryDC memDC;
178
179 double height, width, maxSize;
180 symbol->GetShape()->GetBoundingBoxMax(&width, &height);
181
182 if (height > width)
183 maxSize = height;
184 else
185 maxSize = width;
186
187 double borderMargin = 4.0;
188 double scaleFactor = (double)(objectBitmapSize / (maxSize + 2*borderMargin));
189 double centreX = (double)((objectBitmapSize/scaleFactor)/2.0)-1;
190 double centreY = centreX;
191
192 memDC.SelectObject(*newBitmap);
193 memDC.SetUserScale(scaleFactor, scaleFactor);
194
195 memDC.SetBackground(wxBrush(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE), wxSOLID));
196 memDC.Clear();
197 symbol->GetShape()->Show(TRUE);
198 symbol->GetShape()->Move(memDC, centreX, centreY);
199 memDC.SelectObject(wxNullBitmap);
200
201 return newBitmap;
202 }
203