]>
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 | ||
7c9955d1 JS |
27 | #include <wx/deprecated/setup.h> |
28 | #include <wx/deprecated/wxexpr.h> | |
1fc25a89 JS |
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 | wxNode* node = m_symbols.First(); | |
78 | while (node) | |
79 | { | |
80 | csSymbol* symbol = (csSymbol*) node->Data(); | |
81 | delete symbol; | |
82 | ||
83 | node = node->Next(); | |
84 | } | |
85 | m_symbols.Clear(); | |
86 | } | |
87 | ||
88 | csSymbol* csSymbolDatabase::FindSymbol(const wxString& name) const | |
89 | { | |
90 | wxNode* node = m_symbols.First(); | |
91 | while (node) | |
92 | { | |
93 | csSymbol* symbol = (csSymbol*) node->Data(); | |
94 | if (symbol->GetName() == name) | |
95 | return symbol; | |
96 | ||
97 | node = node->Next(); | |
98 | } | |
99 | return NULL; | |
100 | } | |
101 | ||
102 | csSymbol* csSymbolDatabase::FindSymbol(int toolId) const | |
103 | { | |
104 | wxNode* node = m_symbols.First(); | |
105 | while (node) | |
106 | { | |
107 | csSymbol* symbol = (csSymbol*) node->Data(); | |
108 | if (symbol->GetToolId() == toolId) | |
109 | return symbol; | |
110 | ||
111 | node = node->Next(); | |
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, wxString(""))); | |
124 | ||
125 | m_symbolDatabase->AddSymbol(new csSymbol("Circle", shape)); | |
126 | ||
127 | shape = new csCircleShadowShape(); | |
128 | shape->AssignNewIds(); | |
129 | shape->SetEventHandler(new csEvtHandler(shape, shape, wxString(""))); | |
130 | ||
131 | m_symbolDatabase->AddSymbol(new csSymbol("Circle shadow", shape)); | |
132 | ||
133 | shape = new csThinRectangleShape(); | |
134 | shape->AssignNewIds(); | |
135 | shape->SetEventHandler(new csEvtHandler(shape, shape, wxString(""))); | |
136 | ||
137 | m_symbolDatabase->AddSymbol(new csSymbol("Thin Rectangle", shape)); | |
138 | ||
139 | shape = new csWideRectangleShape(); | |
140 | shape->AssignNewIds(); | |
141 | shape->SetEventHandler(new csEvtHandler(shape, shape, wxString(""))); | |
142 | ||
143 | m_symbolDatabase->AddSymbol(new csSymbol("Wide Rectangle", shape)); | |
144 | ||
145 | shape = new csSemiCircleShape(); | |
146 | shape->AssignNewIds(); | |
147 | shape->SetEventHandler(new csEvtHandler(shape, shape, wxString(""))); | |
148 | ||
149 | m_symbolDatabase->AddSymbol(new csSymbol("SemiCircle", shape)); | |
150 | ||
151 | shape = new csTriangleShape(); | |
152 | shape->AssignNewIds(); | |
153 | shape->SetEventHandler(new csEvtHandler(shape, shape, wxString(""))); | |
154 | ||
155 | m_symbolDatabase->AddSymbol(new csSymbol("Triangle", shape)); | |
156 | ||
157 | shape = new csOctagonShape(); | |
158 | shape->AssignNewIds(); | |
159 | shape->SetEventHandler(new csEvtHandler(shape, shape, wxString(""))); | |
160 | ||
161 | m_symbolDatabase->AddSymbol(new csSymbol("Octagon", shape)); | |
162 | ||
163 | shape = new csGroupShape(); | |
164 | shape->AssignNewIds(); | |
165 | shape->SetEventHandler(new csEvtHandler(shape, shape, wxString(""))); | |
166 | ||
167 | m_symbolDatabase->AddSymbol(new csSymbol("Group", shape)); | |
168 | } | |
169 | ||
0a0352f2 | 170 | wxBitmap* csSymbolDatabase::CreateToolBitmap(csSymbol* symbol, const wxSize& toolSize) |
1fc25a89 | 171 | { |
1fc25a89 JS |
172 | symbol->GetShape()->Recompute(); |
173 | ||
0a0352f2 | 174 | wxBitmap *newBitmap = new wxBitmap(toolSize.x, toolSize.y); |
1fc25a89 | 175 | |
0a0352f2 JS |
176 | // Test code |
177 | #if 0 | |
1fc25a89 | 178 | wxMemoryDC memDC; |
0a0352f2 JS |
179 | memDC.SelectObject(*newBitmap); |
180 | memDC.SetPen(* wxBLACK_PEN); | |
181 | memDC.SetBrush(* wxWHITE_BRUSH); | |
e1c6c6ae | 182 | memDC.SetBackground(wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE), wxSOLID)); |
0a0352f2 JS |
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 | ||
1fc25a89 JS |
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; | |
0a0352f2 JS |
204 | double scaleFactor = (double)(toolSize.x / (maxSize + 2*borderMargin)); |
205 | double centreX = (double)((toolSize.x/scaleFactor)/2.0)-1; | |
1fc25a89 JS |
206 | double centreY = centreX; |
207 | ||
208 | memDC.SelectObject(*newBitmap); | |
0a0352f2 | 209 | |
1fc25a89 JS |
210 | memDC.SetUserScale(scaleFactor, scaleFactor); |
211 | ||
e1c6c6ae | 212 | memDC.SetBackground(wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE), wxSOLID)); |
1fc25a89 | 213 | memDC.Clear(); |
0a0352f2 | 214 | |
1fc25a89 JS |
215 | symbol->GetShape()->Show(TRUE); |
216 | symbol->GetShape()->Move(memDC, centreX, centreY); | |
0a0352f2 | 217 | |
1fc25a89 | 218 | memDC.SelectObject(wxNullBitmap); |
0a0352f2 | 219 | #endif |
1fc25a89 JS |
220 | |
221 | return newBitmap; | |
222 | } | |
223 |