1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Implements the Studio symbol database
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
10 /////////////////////////////////////////////////////////////////////////////
13 // #pragma implementation
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
27 #include <wx/deprecated/setup.h>
28 #include <wx/deprecated/wxexpr.h>
38 * Represents information about a symbol.
41 csSymbol::csSymbol(const wxString
& name
, wxShape
* shape
)
54 * A table of all possible shapes.
55 * We can use this to construct a palette, etc.
57 csSymbolDatabase::csSymbolDatabase()
62 csSymbolDatabase::~csSymbolDatabase()
67 void csSymbolDatabase::AddSymbol(csSymbol
* symbol
)
69 symbol
->SetToolId(m_currentId
);
70 m_symbols
.Append(symbol
);
75 void csSymbolDatabase::ClearSymbols()
77 wxObjectList::compatibility_iterator node
= m_symbols
.GetFirst();
80 csSymbol
* symbol
= (csSymbol
*) node
->GetData();
83 node
= node
->GetNext();
88 csSymbol
* csSymbolDatabase::FindSymbol(const wxString
& name
) const
90 wxObjectList::compatibility_iterator node
= m_symbols
.GetFirst();
93 csSymbol
* symbol
= (csSymbol
*) node
->GetData();
94 if (symbol
->GetName() == name
)
97 node
= node
->GetNext();
102 csSymbol
* csSymbolDatabase::FindSymbol(int toolId
) const
104 wxObjectList::compatibility_iterator node
= m_symbols
.GetFirst();
107 csSymbol
* symbol
= (csSymbol
*) node
->GetData();
108 if (symbol
->GetToolId() == toolId
)
111 node
= node
->GetNext();
116 // Add symbols to database
117 void csApp::InitSymbols()
119 m_symbolDatabase
= new csSymbolDatabase
;
121 wxShape
* shape
= new csCircleShape();
122 shape
->AssignNewIds();
123 shape
->SetEventHandler(new csEvtHandler(shape
, shape
, wxEmptyString
));
125 m_symbolDatabase
->AddSymbol(new csSymbol(_T("Circle"), shape
));
127 shape
= new csCircleShadowShape();
128 shape
->AssignNewIds();
129 shape
->SetEventHandler(new csEvtHandler(shape
, shape
, wxEmptyString
));
131 m_symbolDatabase
->AddSymbol(new csSymbol(_T("Circle shadow"), shape
));
133 shape
= new csThinRectangleShape();
134 shape
->AssignNewIds();
135 shape
->SetEventHandler(new csEvtHandler(shape
, shape
, wxEmptyString
));
137 m_symbolDatabase
->AddSymbol(new csSymbol(_T("Thin Rectangle"), shape
));
139 shape
= new csWideRectangleShape();
140 shape
->AssignNewIds();
141 shape
->SetEventHandler(new csEvtHandler(shape
, shape
, wxEmptyString
));
143 m_symbolDatabase
->AddSymbol(new csSymbol(_T("Wide Rectangle"), shape
));
145 shape
= new csSemiCircleShape();
146 shape
->AssignNewIds();
147 shape
->SetEventHandler(new csEvtHandler(shape
, shape
, wxEmptyString
));
149 m_symbolDatabase
->AddSymbol(new csSymbol(_T("SemiCircle"), shape
));
151 shape
= new csTriangleShape();
152 shape
->AssignNewIds();
153 shape
->SetEventHandler(new csEvtHandler(shape
, shape
, wxEmptyString
));
155 m_symbolDatabase
->AddSymbol(new csSymbol(_T("Triangle"), shape
));
157 shape
= new csOctagonShape();
158 shape
->AssignNewIds();
159 shape
->SetEventHandler(new csEvtHandler(shape
, shape
, wxEmptyString
));
161 m_symbolDatabase
->AddSymbol(new csSymbol(_T("Octagon"), shape
));
163 shape
= new csGroupShape();
164 shape
->AssignNewIds();
165 shape
->SetEventHandler(new csEvtHandler(shape
, shape
, wxEmptyString
));
167 m_symbolDatabase
->AddSymbol(new csSymbol(_T("Group"), shape
));
170 wxBitmap
* csSymbolDatabase::CreateToolBitmap(csSymbol
* symbol
, const wxSize
& toolSize
)
172 symbol
->GetShape()->Recompute();
174 wxBitmap
*newBitmap
= new wxBitmap(toolSize
.x
, toolSize
.y
);
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
);
186 memDC
.DrawLine(0, 0, toolSize
.x
, toolSize
.y
);
187 memDC
.DrawLine(0, toolSize
.y
, toolSize
.x
, 0);
189 memDC
.SelectObject(wxNullBitmap
);
195 double height
, width
, maxSize
;
196 symbol
->GetShape()->GetBoundingBoxMax(&width
, &height
);
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
;
208 memDC
.SelectObject(*newBitmap
);
210 memDC
.SetUserScale(scaleFactor
, scaleFactor
);
212 memDC
.SetBackground(wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
), wxSOLID
));
215 symbol
->GetShape()->Show(true);
216 symbol
->GetShape()->Move(memDC
, centreX
, centreY
);
218 memDC
.SelectObject(wxNullBitmap
);