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