]>
Commit | Line | Data |
---|---|---|
1fc25a89 JS |
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". | |
92a19c2e | 17 | #include "wx/wxprec.h" |
1fc25a89 JS |
18 | |
19 | #ifdef __BORLANDC__ | |
20 | #pragma hdrstop | |
21 | #endif | |
22 | ||
23 | #ifndef WX_PRECOMP | |
24 | #include <wx/wx.h> | |
25 | #endif | |
26 | ||
cecdcad1 | 27 | #include <wx/ogl/ogl.h> // base header of OGL, includes and adjusts wx/deprecated/setup.h |
1fc25a89 JS |
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 | { | |
36ca94a2 | 76 | wxObjectList::compatibility_iterator node = m_symbols.GetFirst(); |
1fc25a89 JS |
77 | while (node) |
78 | { | |
8552e6f0 | 79 | csSymbol* symbol = (csSymbol*) node->GetData(); |
1fc25a89 JS |
80 | delete symbol; |
81 | ||
8552e6f0 | 82 | node = node->GetNext(); |
1fc25a89 JS |
83 | } |
84 | m_symbols.Clear(); | |
85 | } | |
86 | ||
87 | csSymbol* csSymbolDatabase::FindSymbol(const wxString& name) const | |
88 | { | |
36ca94a2 | 89 | wxObjectList::compatibility_iterator node = m_symbols.GetFirst(); |
1fc25a89 JS |
90 | while (node) |
91 | { | |
8552e6f0 | 92 | csSymbol* symbol = (csSymbol*) node->GetData(); |
1fc25a89 JS |
93 | if (symbol->GetName() == name) |
94 | return symbol; | |
95 | ||
8552e6f0 | 96 | node = node->GetNext(); |
1fc25a89 JS |
97 | } |
98 | return NULL; | |
99 | } | |
100 | ||
101 | csSymbol* csSymbolDatabase::FindSymbol(int toolId) const | |
102 | { | |
36ca94a2 | 103 | wxObjectList::compatibility_iterator node = m_symbols.GetFirst(); |
1fc25a89 JS |
104 | while (node) |
105 | { | |
8552e6f0 | 106 | csSymbol* symbol = (csSymbol*) node->GetData(); |
1fc25a89 JS |
107 | if (symbol->GetToolId() == toolId) |
108 | return symbol; | |
109 | ||
8552e6f0 | 110 | node = node->GetNext(); |
1fc25a89 JS |
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(); | |
1484b5cc | 122 | shape->SetEventHandler(new csEvtHandler(shape, shape, wxEmptyString)); |
1fc25a89 | 123 | |
1484b5cc | 124 | m_symbolDatabase->AddSymbol(new csSymbol(_T("Circle"), shape)); |
1fc25a89 JS |
125 | |
126 | shape = new csCircleShadowShape(); | |
127 | shape->AssignNewIds(); | |
1484b5cc | 128 | shape->SetEventHandler(new csEvtHandler(shape, shape, wxEmptyString)); |
1fc25a89 | 129 | |
1484b5cc | 130 | m_symbolDatabase->AddSymbol(new csSymbol(_T("Circle shadow"), shape)); |
1fc25a89 JS |
131 | |
132 | shape = new csThinRectangleShape(); | |
133 | shape->AssignNewIds(); | |
1484b5cc | 134 | shape->SetEventHandler(new csEvtHandler(shape, shape, wxEmptyString)); |
1fc25a89 | 135 | |
1484b5cc | 136 | m_symbolDatabase->AddSymbol(new csSymbol(_T("Thin Rectangle"), shape)); |
1fc25a89 JS |
137 | |
138 | shape = new csWideRectangleShape(); | |
139 | shape->AssignNewIds(); | |
1484b5cc | 140 | shape->SetEventHandler(new csEvtHandler(shape, shape, wxEmptyString)); |
1fc25a89 | 141 | |
1484b5cc | 142 | m_symbolDatabase->AddSymbol(new csSymbol(_T("Wide Rectangle"), shape)); |
1fc25a89 JS |
143 | |
144 | shape = new csSemiCircleShape(); | |
145 | shape->AssignNewIds(); | |
1484b5cc | 146 | shape->SetEventHandler(new csEvtHandler(shape, shape, wxEmptyString)); |
1fc25a89 | 147 | |
1484b5cc | 148 | m_symbolDatabase->AddSymbol(new csSymbol(_T("SemiCircle"), shape)); |
1fc25a89 JS |
149 | |
150 | shape = new csTriangleShape(); | |
151 | shape->AssignNewIds(); | |
1484b5cc | 152 | shape->SetEventHandler(new csEvtHandler(shape, shape, wxEmptyString)); |
1fc25a89 | 153 | |
1484b5cc | 154 | m_symbolDatabase->AddSymbol(new csSymbol(_T("Triangle"), shape)); |
1fc25a89 JS |
155 | |
156 | shape = new csOctagonShape(); | |
157 | shape->AssignNewIds(); | |
1484b5cc | 158 | shape->SetEventHandler(new csEvtHandler(shape, shape, wxEmptyString)); |
1fc25a89 | 159 | |
1484b5cc | 160 | m_symbolDatabase->AddSymbol(new csSymbol(_T("Octagon"), shape)); |
1fc25a89 JS |
161 | |
162 | shape = new csGroupShape(); | |
163 | shape->AssignNewIds(); | |
1484b5cc | 164 | shape->SetEventHandler(new csEvtHandler(shape, shape, wxEmptyString)); |
1fc25a89 | 165 | |
1484b5cc | 166 | m_symbolDatabase->AddSymbol(new csSymbol(_T("Group"), shape)); |
1fc25a89 JS |
167 | } |
168 | ||
0a0352f2 | 169 | wxBitmap* csSymbolDatabase::CreateToolBitmap(csSymbol* symbol, const wxSize& toolSize) |
1fc25a89 | 170 | { |
1fc25a89 JS |
171 | symbol->GetShape()->Recompute(); |
172 | ||
0a0352f2 | 173 | wxBitmap *newBitmap = new wxBitmap(toolSize.x, toolSize.y); |
1fc25a89 | 174 | |
0a0352f2 JS |
175 | // Test code |
176 | #if 0 | |
1fc25a89 | 177 | wxMemoryDC memDC; |
0a0352f2 JS |
178 | memDC.SelectObject(*newBitmap); |
179 | memDC.SetPen(* wxBLACK_PEN); | |
180 | memDC.SetBrush(* wxWHITE_BRUSH); | |
e1c6c6ae | 181 | memDC.SetBackground(wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE), wxSOLID)); |
0a0352f2 JS |
182 | memDC.SetLogicalFunction(wxCOPY); |
183 | memDC.Clear(); | |
184 | ||
185 | memDC.DrawLine(0, 0, toolSize.x, toolSize.y); | |
186 | memDC.DrawLine(0, toolSize.y, toolSize.x, 0); | |
187 | ||
188 | memDC.SelectObject(wxNullBitmap); | |
189 | #endif | |
190 | ||
cecdcad1 | 191 | #if 1 |
0a0352f2 JS |
192 | wxMemoryDC memDC; |
193 | ||
1fc25a89 JS |
194 | double height, width, maxSize; |
195 | symbol->GetShape()->GetBoundingBoxMax(&width, &height); | |
196 | ||
197 | if (height > width) | |
198 | maxSize = height; | |
199 | else | |
200 | maxSize = width; | |
201 | ||
202 | double borderMargin = 4.0; | |
0a0352f2 JS |
203 | double scaleFactor = (double)(toolSize.x / (maxSize + 2*borderMargin)); |
204 | double centreX = (double)((toolSize.x/scaleFactor)/2.0)-1; | |
1fc25a89 JS |
205 | double centreY = centreX; |
206 | ||
207 | memDC.SelectObject(*newBitmap); | |
0a0352f2 | 208 | |
1fc25a89 JS |
209 | memDC.SetUserScale(scaleFactor, scaleFactor); |
210 | ||
e1c6c6ae | 211 | memDC.SetBackground(wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE), wxSOLID)); |
1fc25a89 | 212 | memDC.Clear(); |
0a0352f2 | 213 | |
2ba06d5a | 214 | symbol->GetShape()->Show(true); |
1fc25a89 | 215 | symbol->GetShape()->Move(memDC, centreX, centreY); |
0a0352f2 | 216 | |
1fc25a89 | 217 | memDC.SelectObject(wxNullBitmap); |
0a0352f2 | 218 | #endif |
1fc25a89 JS |
219 | |
220 | return newBitmap; | |
221 | } | |
222 |