@@ -31,10 +31,10 @@ END_EVENT_TABLE()
31
31
void BasicDrawPane::mouseMoved(wxMouseEvent& event) {}
32
32
void BasicDrawPane::mouseDown (wxMouseEvent& event) {
33
33
// boost::put(boost::vertex_distance, g, v, pos[i]);
34
- Graph& g = (( CGTeaFrame*) this ->m_parent )->currentGraph ;
35
- Ver vv = boost::num_vertices (g);
34
+ Graph& g = static_cast < CGTeaFrame*>( this ->m_parent )->currentGraph ;
35
+ const Ver vv = boost::num_vertices (g);
36
36
boost::add_vertex (vv, g);
37
- cgtea_geometry::Point p (event.GetPosition ().x ,event.GetPosition ().y );
37
+ const cgtea_geometry::Point p (event.GetPosition ().x ,event.GetPosition ().y );
38
38
boost::put (boost::vertex_distance, g, vv, p);
39
39
Refresh ();
40
40
// int radius = 20;
@@ -158,10 +158,10 @@ void BasicDrawPane::render(wxPaintDC& dc) {
158
158
159
159
void BasicDrawPane::drawEdges (const Graph &g, wxGraphicsContext* gc) {
160
160
for_each_e_const (g, [&](Edge e) {
161
- Ver src = boost::source (e,g);
162
- Ver tgt = boost::target (e,g);
163
- cgtea_geometry::Point src_pos = boost::get (boost::vertex_distance, g, src);
164
- cgtea_geometry::Point tgt_pos = boost::get (boost::vertex_distance, g, tgt);
161
+ const Ver src = boost::source (e,g);
162
+ const Ver tgt = boost::target (e,g);
163
+ const cgtea_geometry::Point src_pos = boost::get (boost::vertex_distance, g, src);
164
+ const cgtea_geometry::Point tgt_pos = boost::get (boost::vertex_distance, g, tgt);
165
165
gc->SetPen (wxPen (wxColor (0 , 0 , 0 ), 2 )); // black line, 3 pixels thick
166
166
wxGraphicsPath path = gc->CreatePath ();
167
167
path.MoveToPoint (src_pos.x , src_pos.y );
@@ -170,25 +170,99 @@ void BasicDrawPane::drawEdges(const Graph &g, wxGraphicsContext* gc) {
170
170
});
171
171
}
172
172
173
+ // void BasicDrawPane::drawVertices(const Graph &g, wxGraphicsContext* gc) {
174
+ // for_each_v_const(g, [&](Ver v) {
175
+ // int color = boost::get(vertex_color, g,v);
176
+ // gc->SetPen(wxPen(wxColor(255, 0, 0), 1)); // 5-pixels-thick red outline
177
+ // cgtea_geometry::Point pos = boost::get(boost::vertex_distance, g, v);
178
+ // gc->SetBrush(wxBrush( wxColour(255, 255, 255, 255))); // green filling
179
+ // wxGraphicsPath pathBackground = gc->CreatePath();
180
+ // pathBackground.AddCircle(pos.x, pos.y, 20 );
181
+ // gc->FillPath(pathBackground);
182
+ //
183
+ // gc->SetBrush(wxBrush( distinctColors[color + 1]));
184
+ // wxGraphicsPath path = gc->CreatePath();
185
+ // path.AddCircle(pos.x, pos.y, 20 );
186
+ // gc->FillPath(path);
187
+ //
188
+ // gc->SetBrush(wxBrush( wxColour(0, 0, 0, 255)));
189
+ // int tmp = boost::get(boost::vertex_index, g, v) + 1;
190
+ // wxString mystring = wxString::Format(wxT("%i"),tmp);
191
+ // wxDouble w, h;
192
+ // gc->GetTextExtent(mystring, &w, &h, nullptr, nullptr);
193
+ // gc->DrawText(mystring, pos.x-w/2, pos.y-h/2);
194
+ // });
195
+ // }
196
+
197
+ void BasicDrawPane::drawShape (wxGraphicsContext* gc, VertexShape shape,
198
+ const cgtea_geometry::Point& pos, double size) {
199
+ switch (shape) {
200
+ case VertexShape::Square:
201
+ drawSquare (gc, pos, size);
202
+ break ;
203
+ case VertexShape::Triangle:
204
+ drawTriangle (gc, pos, size);
205
+ break ;
206
+ case VertexShape::Diamond:
207
+ drawDiamond (gc, pos, size);
208
+ break ;
209
+ case VertexShape::Circle:
210
+ default :
211
+ drawCircle (gc, pos, size);
212
+ break ;
213
+ }
214
+ }
215
+
216
+ void BasicDrawPane::drawCircle (wxGraphicsContext* gc, const cgtea_geometry::Point& pos, double size) {
217
+ wxGraphicsPath path = gc->CreatePath ();
218
+ path.AddCircle (pos.x , pos.y , size);
219
+ gc->FillPath (path);
220
+ }
221
+
222
+ void BasicDrawPane::drawSquare (wxGraphicsContext* gc, const cgtea_geometry::Point& pos, double size) {
223
+ wxGraphicsPath path = gc->CreatePath ();
224
+ path.AddRectangle (pos.x - size, pos.y - size, size * 2 , size * 2 );
225
+ gc->FillPath (path);
226
+ }
227
+
228
+ void BasicDrawPane::drawTriangle (wxGraphicsContext* gc, const cgtea_geometry::Point& pos, double size) {
229
+ wxGraphicsPath path = gc->CreatePath ();
230
+ path.MoveToPoint (pos.x , pos.y - size);
231
+ path.AddLineToPoint (pos.x - size, pos.y + size);
232
+ path.AddLineToPoint (pos.x + size, pos.y + size);
233
+ path.CloseSubpath ();
234
+ gc->FillPath (path);
235
+ }
236
+
237
+ void BasicDrawPane::drawDiamond (wxGraphicsContext* gc, const cgtea_geometry::Point& pos, double size) {
238
+ wxGraphicsPath path = gc->CreatePath ();
239
+ path.MoveToPoint (pos.x , pos.y - size);
240
+ path.AddLineToPoint (pos.x + size, pos.y );
241
+ path.AddLineToPoint (pos.x , pos.y + size);
242
+ path.AddLineToPoint (pos.x - size, pos.y );
243
+ path.CloseSubpath ();
244
+ gc->FillPath (path);
245
+ }
246
+
173
247
void BasicDrawPane::drawVertices (const Graph &g, wxGraphicsContext* gc) {
174
248
for_each_v_const (g, [&](Ver v) {
175
- int color = boost::get (vertex_color, g,v);
176
- gc->SetPen (wxPen (wxColor (255 , 0 , 0 ), 1 )); // 5-pixels-thick red outline
177
- cgtea_geometry::Point pos = boost::get (boost::vertex_distance, g, v);
178
- // gc->DrawCircle(wxPoint(pos.x, pos.y), 20 /* radius */ );
179
- gc->SetBrush (wxBrush ( wxColour (255 , 255 , 255 , 255 ))); // green filling
180
- wxGraphicsPath pathBackground = gc->CreatePath ();
181
- pathBackground.AddCircle (pos.x , pos.y , 20 );
182
- gc->FillPath (pathBackground);
183
-
184
- gc->SetBrush (wxBrush ( distinctColors[color + 1 ]));
185
- wxGraphicsPath path = gc->CreatePath ();
186
- path.AddCircle (pos.x , pos.y , 20 );
187
- gc->FillPath (path);
249
+ const int color = boost::get (vertex_color, g, v);
250
+ const cgtea_geometry::Point pos = boost::get (boost::vertex_distance, g, v);
251
+ auto shape = VertexShape::Diamond;
252
+
253
+ // Draw a white background
254
+ gc->SetPen (wxPen (wxColor (255 , 0 , 0 ), 1 ));
255
+ gc->SetBrush (wxBrush (wxColour (255 , 255 , 255 , 255 )));
256
+ drawShape (gc, shape, pos, 20 );
257
+
258
+ // Draw a colored shape
259
+ gc->SetBrush (wxBrush (distinctColors[color + 1 ]));
260
+ drawShape (gc, shape, pos, 20 );
188
261
189
- gc->SetBrush (wxBrush ( wxColour (0 , 0 , 0 , 255 )));
262
+ // Draw a vertex number
263
+ gc->SetBrush (wxBrush (wxColour (0 , 0 , 0 , 255 )));
190
264
int tmp = boost::get (boost::vertex_index, g, v) + 1 ;
191
- wxString mystring = wxString::Format (wxT (" %i" ),tmp);
265
+ wxString mystring = wxString::Format (wxT (" %i" ), tmp);
192
266
wxDouble w, h;
193
267
gc->GetTextExtent (mystring, &w, &h, nullptr , nullptr );
194
268
gc->DrawText (mystring, pos.x -w/2 , pos.y -h/2 );
0 commit comments