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