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