1 /////////////////////////////////////////////////////////////////////////////
2 // Name: contrib/samples/ogl/studio/symbols.cpp
3 // Purpose: Implements the Studio symbol database
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
23 #include "wx/ogl/ogl.h" // base header of OGL, includes and adjusts wx/deprecated/setup.h
33 * Represents information about a symbol.
36 csSymbol::csSymbol(const wxString
& name
, wxShape
* shape
)
49 * A table of all possible shapes.
50 * We can use this to construct a palette, etc.
52 csSymbolDatabase::csSymbolDatabase()
57 csSymbolDatabase::~csSymbolDatabase()
62 void csSymbolDatabase::AddSymbol(csSymbol
* symbol
)
64 symbol
->SetToolId(m_currentId
);
65 m_symbols
.Append(symbol
);
70 void csSymbolDatabase::ClearSymbols()
72 wxObjectList::compatibility_iterator node
= m_symbols
.GetFirst();
75 csSymbol
* symbol
= (csSymbol
*) node
->GetData();
78 node
= node
->GetNext();
83 csSymbol
* csSymbolDatabase::FindSymbol(const wxString
& name
) const
85 wxObjectList::compatibility_iterator node
= m_symbols
.GetFirst();
88 csSymbol
* symbol
= (csSymbol
*) node
->GetData();
89 if (symbol
->GetName() == name
)
92 node
= node
->GetNext();
97 csSymbol
* csSymbolDatabase::FindSymbol(int toolId
) const
99 wxObjectList::compatibility_iterator node
= m_symbols
.GetFirst();
102 csSymbol
* symbol
= (csSymbol
*) node
->GetData();
103 if (symbol
->GetToolId() == toolId
)
106 node
= node
->GetNext();
111 // Add symbols to database
112 void csApp::InitSymbols()
114 m_symbolDatabase
= new csSymbolDatabase
;
116 wxShape
* shape
= new csCircleShape();
117 shape
->AssignNewIds();
118 shape
->SetEventHandler(new csEvtHandler(shape
, shape
, wxEmptyString
));
120 m_symbolDatabase
->AddSymbol(new csSymbol(_T("Circle"), shape
));
122 shape
= new csCircleShadowShape();
123 shape
->AssignNewIds();
124 shape
->SetEventHandler(new csEvtHandler(shape
, shape
, wxEmptyString
));
126 m_symbolDatabase
->AddSymbol(new csSymbol(_T("Circle shadow"), shape
));
128 shape
= new csThinRectangleShape();
129 shape
->AssignNewIds();
130 shape
->SetEventHandler(new csEvtHandler(shape
, shape
, wxEmptyString
));
132 m_symbolDatabase
->AddSymbol(new csSymbol(_T("Thin Rectangle"), shape
));
134 shape
= new csWideRectangleShape();
135 shape
->AssignNewIds();
136 shape
->SetEventHandler(new csEvtHandler(shape
, shape
, wxEmptyString
));
138 m_symbolDatabase
->AddSymbol(new csSymbol(_T("Wide Rectangle"), shape
));
140 shape
= new csSemiCircleShape();
141 shape
->AssignNewIds();
142 shape
->SetEventHandler(new csEvtHandler(shape
, shape
, wxEmptyString
));
144 m_symbolDatabase
->AddSymbol(new csSymbol(_T("SemiCircle"), shape
));
146 shape
= new csTriangleShape();
147 shape
->AssignNewIds();
148 shape
->SetEventHandler(new csEvtHandler(shape
, shape
, wxEmptyString
));
150 m_symbolDatabase
->AddSymbol(new csSymbol(_T("Triangle"), shape
));
152 shape
= new csOctagonShape();
153 shape
->AssignNewIds();
154 shape
->SetEventHandler(new csEvtHandler(shape
, shape
, wxEmptyString
));
156 m_symbolDatabase
->AddSymbol(new csSymbol(_T("Octagon"), shape
));
158 shape
= new csGroupShape();
159 shape
->AssignNewIds();
160 shape
->SetEventHandler(new csEvtHandler(shape
, shape
, wxEmptyString
));
162 m_symbolDatabase
->AddSymbol(new csSymbol(_T("Group"), shape
));
165 wxBitmap
* csSymbolDatabase::CreateToolBitmap(csSymbol
* symbol
, const wxSize
& toolSize
)
167 symbol
->GetShape()->Recompute();
169 wxBitmap
*newBitmap
= new wxBitmap(toolSize
.x
, toolSize
.y
);
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
);
181 memDC
.DrawLine(0, 0, toolSize
.x
, toolSize
.y
);
182 memDC
.DrawLine(0, toolSize
.y
, toolSize
.x
, 0);
184 memDC
.SelectObject(wxNullBitmap
);
190 double height
, width
, maxSize
;
191 symbol
->GetShape()->GetBoundingBoxMax(&width
, &height
);
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
;
203 memDC
.SelectObject(*newBitmap
);
205 memDC
.SetUserScale(scaleFactor
, scaleFactor
);
207 memDC
.SetBackground(wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
), wxSOLID
));
210 symbol
->GetShape()->Show(true);
211 symbol
->GetShape()->Move(memDC
, centreX
, centreY
);
213 memDC
.SelectObject(wxNullBitmap
);