]>
git.saurik.com Git - wxWidgets.git/blob - contrib/samples/ogl/studio/symbols.cpp
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 wxNode
* node
= m_symbols
.First();
80 csSymbol
* symbol
= (csSymbol
*) node
->Data();
88 csSymbol
* csSymbolDatabase::FindSymbol(const wxString
& name
) const
90 wxNode
* node
= m_symbols
.First();
93 csSymbol
* symbol
= (csSymbol
*) node
->Data();
94 if (symbol
->GetName() == name
)
102 csSymbol
* csSymbolDatabase::FindSymbol(int toolId
) const
104 wxNode
* node
= m_symbols
.First();
107 csSymbol
* symbol
= (csSymbol
*) node
->Data();
108 if (symbol
->GetToolId() == toolId
)
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
, wxString("")));
125 m_symbolDatabase
->AddSymbol(new csSymbol("Circle", shape
));
127 shape
= new csCircleShadowShape();
128 shape
->AssignNewIds();
129 shape
->SetEventHandler(new csEvtHandler(shape
, shape
, wxString("")));
131 m_symbolDatabase
->AddSymbol(new csSymbol("Circle shadow", shape
));
133 shape
= new csThinRectangleShape();
134 shape
->AssignNewIds();
135 shape
->SetEventHandler(new csEvtHandler(shape
, shape
, wxString("")));
137 m_symbolDatabase
->AddSymbol(new csSymbol("Thin Rectangle", shape
));
139 shape
= new csWideRectangleShape();
140 shape
->AssignNewIds();
141 shape
->SetEventHandler(new csEvtHandler(shape
, shape
, wxString("")));
143 m_symbolDatabase
->AddSymbol(new csSymbol("Wide Rectangle", shape
));
145 shape
= new csSemiCircleShape();
146 shape
->AssignNewIds();
147 shape
->SetEventHandler(new csEvtHandler(shape
, shape
, wxString("")));
149 m_symbolDatabase
->AddSymbol(new csSymbol("SemiCircle", shape
));
151 shape
= new csTriangleShape();
152 shape
->AssignNewIds();
153 shape
->SetEventHandler(new csEvtHandler(shape
, shape
, wxString("")));
155 m_symbolDatabase
->AddSymbol(new csSymbol("Triangle", shape
));
157 shape
= new csOctagonShape();
158 shape
->AssignNewIds();
159 shape
->SetEventHandler(new csEvtHandler(shape
, shape
, wxString("")));
161 m_symbolDatabase
->AddSymbol(new csSymbol("Octagon", shape
));
163 shape
= new csGroupShape();
164 shape
->AssignNewIds();
165 shape
->SetEventHandler(new csEvtHandler(shape
, shape
, wxString("")));
167 m_symbolDatabase
->AddSymbol(new csSymbol("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
);