This repository was archived by the owner on Jun 21, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdrawpanel.cpp
More file actions
145 lines (120 loc) · 3.51 KB
/
Copy pathdrawpanel.cpp
File metadata and controls
145 lines (120 loc) · 3.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/////////////////////////////////////////////////////////////////////////////
// Name: drawpanel.cpp
// Description: ...
// Author: Alexey Orlov (https://github.com/m110h)
// Last modification: 18/08/2020
// Licence: MIT licence
/////////////////////////////////////////////////////////////////////////////
#include "drawpanel.h"
BasicDrawPanel::BasicDrawPanel(wxWindow* parent, wxWindowID id, const wxSize& size): wxPanel(parent, id, wxDefaultPosition, size /*, wxBORDER_SIMPLE*/ )
{
SetBackgroundColour(*wxWHITE);
SetBackgroundStyle(wxBG_STYLE_PAINT);
/*
// direct2d will enable only for ms compiler, why?
#if wxUSE_GRAPHICS_CONTEXT
#ifdef __WXMSW__
#if wxUSE_GRAPHICS_DIRECT2D
renderer = wxGraphicsRenderer::GetDirect2DRenderer();
//wxMessageBox(wxT("DIRECT2D"), wxT("Renderer"), wxOK | wxICON_INFORMATION, this);
#elif wxUSE_GRAPHICS_GDIPLUS
renderer = wxGraphicsRenderer::GetGDIPlusRenderer();
//wxMessageBox(wxT("GDIPLUS"), wxT("Renderer"), wxOK | wxICON_INFORMATION, this);
#endif
#endif // __WXMSW__
#endif // wxUSE_GRAPHICS_CONTEXT
*/
this->Bind(wxEVT_SIZE, [&](wxSizeEvent& event){
onSize(event);
});
this->Bind(wxEVT_LEFT_UP, [&](wxMouseEvent& event){
mouseReleased(event);
});
this->Bind(wxEVT_PAINT, [&](wxPaintEvent& event){
onPaint(event);
});
}
void BasicDrawPanel::onSize(wxSizeEvent& event)
{
if (world)
world->SetPanelSize(event.GetSize());
#ifdef __WXMSW__
paintNow();
#endif
}
void BasicDrawPanel::mouseReleased(wxMouseEvent& event)
{
if (world)
world->SelectEntityByPosition(world->PanelToWorld(event.GetPosition()));
paintNow();
wxPostEvent(GetParent(), event);
//if (selectedId != -1)
// wxMessageBox(wxString::Format(wxT("X: %d; Y: %d;"), pos.x, pos.y), wxT("Mouse Click"), wxOK | wxICON_INFORMATION, this);
}
void BasicDrawPanel::paintNow()
{
wxClientDC dc(this);
wxBufferedDC bdc(&dc, dc.GetSize()); // for prevent flickering
softwareRender(&bdc);
//softwareRender(&dc);
}
void BasicDrawPanel::onPaint(wxPaintEvent & evt)
{
wxAutoBufferedPaintDC dc(this);
//wxPaintDC dc(this);
softwareRender(&dc);
}
void BasicDrawPanel::SetWorld(ProtoPuddle::World* _world)
{
world = _world;
}
bool BasicDrawPanel::SwitchAntialiasingMode()
{
return (antialiasingFlag = !antialiasingFlag);
}
void BasicDrawPanel::softwareRender(wxDC* dc)
{
if (dc)
{
dc->Clear();
if (world)
world->Draw(dc);
}
/*
if (renderer)
{
wxGraphicsContext* context {nullptr};
if ( wxBufferedPaintDC* bufferedpaintdc = wxDynamicCast(dc, wxBufferedPaintDC) )
{
context = renderer->CreateContext(*bufferedpaintdc);
}
else if ( wxBufferedDC* buffereddc = wxDynamicCast(dc, wxBufferedDC) )
{
context = renderer->CreateContext(*buffereddc);
}
else
{
return;
}
if (antialiasingFlag)
{
context->SetAntialiasMode(wxANTIALIAS_DEFAULT);
}
else
{
context->SetAntialiasMode(wxANTIALIAS_NONE);
}
wxGCDC gdc;
gdc.SetGraphicsContext(context);
gdc.Clear();
if (world)
world->Draw(static_cast<wxDC*>(&gdc));
}
else
{
dc->Clear();
if (world)
world->Draw(dc);
}
*/
}