]> git.saurik.com Git - wxWidgets.git/blob - contrib/samples/ogl/studio/symbols.cpp
wxURI is enough for the basic url operations.
[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/deprecated/setup.h>
28 #include <wx/deprecated/wxexpr.h>
29
30 #include "studio.h"
31 #include "doc.h"
32 #include "shapes.h"
33 #include "view.h"
34 #include "symbols.h"
35
36 /*
37 * csSymbol
38 * Represents information about a symbol.
39 */
40
41 csSymbol::csSymbol(const wxString& name, wxShape* shape)
42 {
43 m_name = name;
44 m_shape = shape;
45 m_toolId = 0;
46 }
47
48 csSymbol::~csSymbol()
49 {
50 delete m_shape;
51 }
52
53 /*
54 * A table of all possible shapes.
55 * We can use this to construct a palette, etc.
56 */
57 csSymbolDatabase::csSymbolDatabase()
58 {
59 m_currentId = 800;
60 }
61
62 csSymbolDatabase::~csSymbolDatabase()
63 {
64 ClearSymbols();
65 }
66
67 void csSymbolDatabase::AddSymbol(csSymbol* symbol)
68 {
69 symbol->SetToolId(m_currentId);
70 m_symbols.Append(symbol);
71
72 m_currentId ++;
73 }
74
75 void csSymbolDatabase::ClearSymbols()
76 {
77 wxObjectList::compatibility_iterator node = m_symbols.GetFirst();
78 while (node)
79 {
80 csSymbol* symbol = (csSymbol*) node->GetData();
81 delete symbol;
82
83 node = node->GetNext();
84 }
85 m_symbols.Clear();
86 }
87
88 csSymbol* csSymbolDatabase::FindSymbol(const wxString& name) const
89 {
90 wxObjectList::compatibility_iterator node = m_symbols.GetFirst();
91 while (node)
92 {
93 csSymbol* symbol = (csSymbol*) node->GetData();
94 if (symbol->GetName() == name)
95 return symbol;
96
97 node = node->GetNext();
98 }
99 return NULL;
100 }
101
102 csSymbol* csSymbolDatabase::FindSymbol(int toolId) const
103 {
104 wxObjectList::compatibility_iterator node = m_symbols.GetFirst();
105 while (node)
106 {
107 csSymbol* symbol = (csSymbol*) node->GetData();
108 if (symbol->GetToolId() == toolId)
109 return symbol;
110
111 node = node->GetNext();
112 }
113 return NULL;
114 }
115
116 // Add symbols to database
117 void csApp::InitSymbols()
118 {
119 m_symbolDatabase = new csSymbolDatabase;
120
121 wxShape* shape = new csCircleShape();
122 shape->AssignNewIds();
123 shape->SetEventHandler(new csEvtHandler(shape, shape, wxEmptyString));
124
125 m_symbolDatabase->AddSymbol(new csSymbol(_T("Circle"), shape));
126
127 shape = new csCircleShadowShape();
128 shape->AssignNewIds();
129 shape->SetEventHandler(new csEvtHandler(shape, shape, wxEmptyString));
130
131 m_symbolDatabase->AddSymbol(new csSymbol(_T("Circle shadow"), shape));
132
133 shape = new csThinRectangleShape();
134 shape->AssignNewIds();
135 shape->SetEventHandler(new csEvtHandler(shape, shape, wxEmptyString));
136
137 m_symbolDatabase->AddSymbol(new csSymbol(_T("Thin Rectangle"), shape));
138
139 shape = new csWideRectangleShape();
140 shape->AssignNewIds();
141 shape->SetEventHandler(new csEvtHandler(shape, shape, wxEmptyString));
142
143 m_symbolDatabase->AddSymbol(new csSymbol(_T("Wide Rectangle"), shape));
144
145 shape = new csSemiCircleShape();
146 shape->AssignNewIds();
147 shape->SetEventHandler(new csEvtHandler(shape, shape, wxEmptyString));
148
149 m_symbolDatabase->AddSymbol(new csSymbol(_T("SemiCircle"), shape));
150
151 shape = new csTriangleShape();
152 shape->AssignNewIds();
153 shape->SetEventHandler(new csEvtHandler(shape, shape, wxEmptyString));
154
155 m_symbolDatabase->AddSymbol(new csSymbol(_T("Triangle"), shape));
156
157 shape = new csOctagonShape();
158 shape->AssignNewIds();
159 shape->SetEventHandler(new csEvtHandler(shape, shape, wxEmptyString));
160
161 m_symbolDatabase->AddSymbol(new csSymbol(_T("Octagon"), shape));
162
163 shape = new csGroupShape();
164 shape->AssignNewIds();
165 shape->SetEventHandler(new csEvtHandler(shape, shape, wxEmptyString));
166
167 m_symbolDatabase->AddSymbol(new csSymbol(_T("Group"), shape));
168 }
169
170 wxBitmap* csSymbolDatabase::CreateToolBitmap(csSymbol* symbol, const wxSize& toolSize)
171 {
172 symbol->GetShape()->Recompute();
173
174 wxBitmap *newBitmap = new wxBitmap(toolSize.x, toolSize.y);
175
176 // Test code
177 #if 0
178 wxMemoryDC memDC;
179 memDC.SelectObject(*newBitmap);
180 memDC.SetPen(* wxBLACK_PEN);
181 memDC.SetBrush(* wxWHITE_BRUSH);
182 memDC.SetBackground(wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE), wxSOLID));
183 memDC.SetLogicalFunction(wxCOPY);
184 memDC.Clear();
185
186 memDC.DrawLine(0, 0, toolSize.x, toolSize.y);
187 memDC.DrawLine(0, toolSize.y, toolSize.x, 0);
188
189 memDC.SelectObject(wxNullBitmap);
190 #endif
191
192 #if 1
193 wxMemoryDC memDC;
194
195 double height, width, maxSize;
196 symbol->GetShape()->GetBoundingBoxMax(&width, &height);
197
198 if (height > width)
199 maxSize = height;
200 else
201 maxSize = width;
202
203 double borderMargin = 4.0;
204 double scaleFactor = (double)(toolSize.x / (maxSize + 2*borderMargin));
205 double centreX = (double)((toolSize.x/scaleFactor)/2.0)-1;
206 double centreY = centreX;
207
208 memDC.SelectObject(*newBitmap);
209
210 memDC.SetUserScale(scaleFactor, scaleFactor);
211
212 memDC.SetBackground(wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE), wxSOLID));
213 memDC.Clear();
214
215 symbol->GetShape()->Show(true);
216 symbol->GetShape()->Move(memDC, centreX, centreY);
217
218 memDC.SelectObject(wxNullBitmap);
219 #endif
220
221 return newBitmap;
222 }
223