]>
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/wxexpr.h>
37 * Represents information about a symbol.
40 csSymbol::csSymbol(const wxString
& name
, wxShape
* shape
)
53 * A table of all possible shapes.
54 * We can use this to construct a palette, etc.
56 csSymbolDatabase::csSymbolDatabase()
61 csSymbolDatabase::~csSymbolDatabase()
66 void csSymbolDatabase::AddSymbol(csSymbol
* symbol
)
68 symbol
->SetToolId(m_currentId
);
69 m_symbols
.Append(symbol
);
74 void csSymbolDatabase::ClearSymbols()
76 wxNode
* node
= m_symbols
.First();
79 csSymbol
* symbol
= (csSymbol
*) node
->Data();
87 csSymbol
* csSymbolDatabase::FindSymbol(const wxString
& name
) const
89 wxNode
* node
= m_symbols
.First();
92 csSymbol
* symbol
= (csSymbol
*) node
->Data();
93 if (symbol
->GetName() == name
)
101 csSymbol
* csSymbolDatabase::FindSymbol(int toolId
) const
103 wxNode
* node
= m_symbols
.First();
106 csSymbol
* symbol
= (csSymbol
*) node
->Data();
107 if (symbol
->GetToolId() == toolId
)
115 // Add symbols to database
116 void csApp::InitSymbols()
118 m_symbolDatabase
= new csSymbolDatabase
;
120 wxShape
* shape
= new csCircleShape();
121 shape
->AssignNewIds();
122 shape
->SetEventHandler(new csEvtHandler(shape
, shape
, wxString("")));
124 m_symbolDatabase
->AddSymbol(new csSymbol("Circle", shape
));
126 shape
= new csCircleShadowShape();
127 shape
->AssignNewIds();
128 shape
->SetEventHandler(new csEvtHandler(shape
, shape
, wxString("")));
130 m_symbolDatabase
->AddSymbol(new csSymbol("Circle shadow", shape
));
132 shape
= new csThinRectangleShape();
133 shape
->AssignNewIds();
134 shape
->SetEventHandler(new csEvtHandler(shape
, shape
, wxString("")));
136 m_symbolDatabase
->AddSymbol(new csSymbol("Thin Rectangle", shape
));
138 shape
= new csWideRectangleShape();
139 shape
->AssignNewIds();
140 shape
->SetEventHandler(new csEvtHandler(shape
, shape
, wxString("")));
142 m_symbolDatabase
->AddSymbol(new csSymbol("Wide Rectangle", shape
));
144 shape
= new csSemiCircleShape();
145 shape
->AssignNewIds();
146 shape
->SetEventHandler(new csEvtHandler(shape
, shape
, wxString("")));
148 m_symbolDatabase
->AddSymbol(new csSymbol("SemiCircle", shape
));
150 shape
= new csTriangleShape();
151 shape
->AssignNewIds();
152 shape
->SetEventHandler(new csEvtHandler(shape
, shape
, wxString("")));
154 m_symbolDatabase
->AddSymbol(new csSymbol("Triangle", shape
));
156 shape
= new csOctagonShape();
157 shape
->AssignNewIds();
158 shape
->SetEventHandler(new csEvtHandler(shape
, shape
, wxString("")));
160 m_symbolDatabase
->AddSymbol(new csSymbol("Octagon", shape
));
162 shape
= new csGroupShape();
163 shape
->AssignNewIds();
164 shape
->SetEventHandler(new csEvtHandler(shape
, shape
, wxString("")));
166 m_symbolDatabase
->AddSymbol(new csSymbol("Group", shape
));
169 wxBitmap
* csSymbolDatabase::CreateToolBitmap(csSymbol
* symbol
, const wxSize
& toolSize
)
171 symbol
->GetShape()->Recompute();
173 wxBitmap
*newBitmap
= new wxBitmap(toolSize
.x
, toolSize
.y
);
178 memDC
.SelectObject(*newBitmap
);
179 memDC
.SetPen(* wxBLACK_PEN
);
180 memDC
.SetBrush(* wxWHITE_BRUSH
);
181 memDC
.SetBackground(wxBrush(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
), wxSOLID
));
182 memDC
.SetLogicalFunction(wxCOPY
);
185 memDC
.DrawLine(0, 0, toolSize
.x
, toolSize
.y
);
186 memDC
.DrawLine(0, toolSize
.y
, toolSize
.x
, 0);
188 memDC
.SelectObject(wxNullBitmap
);
194 double height
, width
, maxSize
;
195 symbol
->GetShape()->GetBoundingBoxMax(&width
, &height
);
202 double borderMargin
= 4.0;
203 double scaleFactor
= (double)(toolSize
.x
/ (maxSize
+ 2*borderMargin
));
204 double centreX
= (double)((toolSize
.x
/scaleFactor
)/2.0)-1;
205 double centreY
= centreX
;
207 memDC
.SelectObject(*newBitmap
);
209 memDC
.SetUserScale(scaleFactor
, scaleFactor
);
211 memDC
.SetBackground(wxBrush(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
), wxSOLID
));
214 symbol
->GetShape()->Show(TRUE
);
215 symbol
->GetShape()->Move(memDC
, centreX
, centreY
);
217 memDC
.SelectObject(wxNullBitmap
);