質問編集履歴
1
プログラムの簡素化 タイトル変更
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
wxWidgets AUIが
|
1
|
+
wxWidgets AUI フローティング時に他コントロールとの連動ができない
|
body
CHANGED
@@ -1,243 +1,108 @@
|
|
1
|
-
MyFrameにwxAuiManager m_mgrを持たせて
|
2
|
-
OpenGLを絵画するためのTestGLCanvasと
|
3
|
-
|
1
|
+
wxTextCtrlとMyPanelを
|
4
|
-
|
2
|
+
wxAuiManagerで管理できるようにしました
|
5
|
-
MyPanel
|
3
|
+
MyPanel内にはwxButtonがあり、ボタンを押すと
|
6
|
-
|
4
|
+
wxTextCtrl内に"a"を追加していきます
|
7
|
-
|
8
|
-
ここまでは良いのですが
|
9
5
|
これが上手くいくのはMyPanelがドッキングされている時です
|
10
|
-
ドッキングを外し、フローティングしている状態で
|
6
|
+
ドッキングを外し、フローティングしている状態でボタンを押すと
|
11
|
-
|
7
|
+
読み取りアクセス違反ということでエラー落ちしてしまいます
|
12
8
|
|
13
|
-
ブレークポイントで少し見てみたらMyPanel::OnButton関数内の
|
14
|
-
TestGLCanvas* tempglc = ((MyFrame*)GetParent())->GetGLCanvas();
|
15
|
-
tempglcがドッキングしている時とフローティングしている時では
|
16
|
-
別の値になっていました ドッキングすると元の値に戻ります
|
17
|
-
GetParent()はどちらの時でも同じ値でした
|
18
|
-
ここが原因だと思うのですが具体的に何をしたら良いかわかりません
|
19
|
-
どのように修正すれば良いか
|
9
|
+
どのように修正すれば良いか教えてください
|
20
10
|
|
21
11
|
```C++
|
22
12
|
//wxTest.h
|
23
13
|
#ifndef _WX_TEST_H_
|
24
14
|
#define _WX_TEST_H_
|
25
15
|
|
26
|
-
#include
|
16
|
+
#include <wx/wx.h>
|
27
17
|
#include "wx/aui/aui.h"
|
28
|
-
#include <random>
|
29
18
|
|
30
|
-
class
|
19
|
+
class MyPanel : public wxPanel
|
31
20
|
{
|
32
21
|
public:
|
22
|
+
enum {
|
23
|
+
ID_BUTTON = wxID_HIGHEST + 1
|
24
|
+
};
|
33
|
-
|
25
|
+
MyPanel(wxWindow* parent);
|
34
|
-
|
35
26
|
private:
|
27
|
+
wxButton* m_btn;
|
36
|
-
void
|
28
|
+
void OnButton(wxCommandEvent& event);
|
37
29
|
DECLARE_EVENT_TABLE()
|
38
30
|
};
|
39
31
|
|
40
|
-
class TestGLContext : public wxGLContext
|
41
|
-
{
|
42
|
-
public:
|
43
|
-
TestGLContext(wxGLCanvas* canvas);
|
44
|
-
void Draw();
|
45
|
-
};
|
46
|
-
|
47
32
|
class MyApp : public wxApp
|
48
33
|
{
|
49
34
|
public:
|
50
|
-
MyApp() { m_glContext = NULL; }
|
51
|
-
|
52
|
-
TestGLContext& GetContext(wxGLCanvas* canvas);
|
53
|
-
|
54
35
|
virtual bool OnInit();
|
55
|
-
virtual int OnExit();
|
56
|
-
|
57
|
-
private:
|
58
|
-
TestGLContext* m_glContext;
|
59
36
|
};
|
60
37
|
|
61
38
|
class MyFrame : public wxFrame
|
62
39
|
{
|
63
40
|
private:
|
64
41
|
wxAuiManager m_mgr;
|
42
|
+
MyPanel* m_panel;
|
65
|
-
|
43
|
+
wxTextCtrl* m_txt;
|
44
|
+
|
66
45
|
public:
|
67
|
-
TestGLCanvas* GetGLCanvas();
|
68
46
|
MyFrame();
|
69
47
|
~MyFrame();
|
70
|
-
|
71
|
-
private:
|
72
|
-
|
48
|
+
wxTextCtrl* GetTextCtrl() { return m_txt; }
|
73
|
-
DECLARE_EVENT_TABLE()
|
74
49
|
};
|
75
50
|
|
76
|
-
class MyPanel : public wxPanel
|
77
|
-
{
|
78
|
-
public:
|
79
|
-
enum {
|
80
|
-
ID_BUTTON = wxID_HIGHEST + 1
|
81
|
-
};
|
82
|
-
MyPanel(wxWindow* parent);
|
83
|
-
private:
|
84
|
-
wxButton* btn;
|
85
|
-
void OnButton(wxCommandEvent& event);
|
86
|
-
DECLARE_EVENT_TABLE()
|
87
|
-
};
|
88
51
|
#endif // _WX_TEST_H_
|
89
52
|
|
90
53
|
```
|
91
54
|
|
92
55
|
```C++
|
93
56
|
//wxTest.cpp
|
94
|
-
#include "wx/wxprec.h"
|
95
57
|
#include "wxTest.h"
|
96
58
|
|
59
|
+
IMPLEMENT_APP(MyApp)
|
60
|
+
|
61
|
+
BEGIN_EVENT_TABLE(MyPanel, wxPanel)
|
62
|
+
EVT_BUTTON(ID_BUTTON, MyPanel::OnButton)
|
63
|
+
END_EVENT_TABLE()
|
64
|
+
|
97
|
-
|
65
|
+
MyPanel::MyPanel(wxWindow* parent)
|
98
|
-
:
|
66
|
+
:wxPanel(parent, -1)
|
99
67
|
{
|
68
|
+
m_btn = new wxButton(this, ID_BUTTON, wxT("button"));
|
100
|
-
|
69
|
+
wxBoxSizer* vbox = new wxBoxSizer(wxVERTICAL);
|
70
|
+
wxBoxSizer* hbox = new wxBoxSizer(wxHORIZONTAL);
|
101
|
-
|
71
|
+
this->SetSizer(hbox);
|
102
|
-
|
72
|
+
vbox->Add(m_btn, 1, wxEXPAND);
|
103
|
-
glEnable(GL_LIGHT0);
|
104
|
-
|
73
|
+
hbox->Add(vbox, 1, wxEXPAND);
|
105
|
-
glLoadIdentity();
|
106
|
-
glFrustum(-0.5f, 0.5f, -0.5f, 0.5f, 1.0f, 3.0f);
|
107
74
|
}
|
108
75
|
|
109
|
-
void
|
76
|
+
void MyPanel::OnButton(wxCommandEvent& event)
|
110
77
|
{
|
111
|
-
std::random_device rnd;
|
112
|
-
|
78
|
+
wxTextCtrl* temp = ((MyFrame*)GetParent())->GetTextCtrl();
|
113
|
-
|
114
|
-
glMatrixMode(GL_MODELVIEW);
|
115
|
-
glLoadIdentity();
|
116
|
-
glTranslatef(0.0f, 0.0f, -2.0f);
|
117
|
-
|
79
|
+
temp->AppendText(wxT("a"));
|
118
|
-
|
119
|
-
glBegin(GL_QUADS);
|
120
|
-
glNormal3f(0.0f, 0.0f, 1.0f);
|
121
|
-
glVertex3f(0.5f, 0.5f, 0.5f);
|
122
|
-
glVertex3f(-0.5f, 0.5f, 0.5f);
|
123
|
-
glVertex3f(-0.5f, -0.5f, 0.5f);
|
124
|
-
glVertex3f(0.5f, -0.5f, 0.5f);
|
125
|
-
glEnd();
|
126
|
-
|
127
|
-
glFlush();
|
128
80
|
}
|
129
81
|
|
130
|
-
IMPLEMENT_APP(MyApp)
|
131
|
-
|
132
82
|
bool MyApp::OnInit()
|
133
83
|
{
|
134
84
|
if (!wxApp::OnInit())
|
135
85
|
return false;
|
136
|
-
|
137
86
|
new MyFrame();
|
138
87
|
return true;
|
139
88
|
}
|
140
89
|
|
141
|
-
int MyApp::OnExit()
|
142
|
-
{
|
143
|
-
delete m_glContext;
|
144
|
-
return wxApp::OnExit();
|
145
|
-
}
|
146
|
-
|
147
|
-
TestGLContext& MyApp::GetContext(wxGLCanvas* canvas)
|
148
|
-
{
|
149
|
-
if (!m_glContext)
|
150
|
-
{
|
151
|
-
m_glContext = new TestGLContext(canvas);
|
152
|
-
}
|
153
|
-
m_glContext->SetCurrent(*canvas);
|
154
|
-
return *m_glContext;
|
155
|
-
}
|
156
|
-
|
157
|
-
BEGIN_EVENT_TABLE(TestGLCanvas, wxGLCanvas)
|
158
|
-
EVT_PAINT(TestGLCanvas::OnPaint)
|
159
|
-
END_EVENT_TABLE()
|
160
|
-
|
161
|
-
TestGLCanvas::TestGLCanvas(wxWindow* parent)
|
162
|
-
: wxGLCanvas(parent, wxID_ANY, NULL,
|
163
|
-
wxDefaultPosition, wxDefaultSize,
|
164
|
-
wxFULL_REPAINT_ON_RESIZE)
|
165
|
-
{
|
166
|
-
}
|
167
|
-
|
168
|
-
void TestGLCanvas::OnPaint(wxPaintEvent& WXUNUSED(event))
|
169
|
-
{
|
170
|
-
wxPaintDC dc(this);
|
171
|
-
const wxSize ClientSize = GetClientSize();
|
172
|
-
|
173
|
-
TestGLContext& canvas = wxGetApp().GetContext(this);
|
174
|
-
glViewport(0, 0, ClientSize.x, ClientSize.y);
|
175
|
-
|
176
|
-
canvas.Draw();
|
177
|
-
SwapBuffers();
|
178
|
-
}
|
179
|
-
|
180
|
-
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
|
181
|
-
EVT_MENU(wxID_CLOSE, MyFrame::OnClose)
|
182
|
-
END_EVENT_TABLE()
|
183
|
-
|
184
|
-
|
185
90
|
MyFrame::MyFrame()
|
186
|
-
: wxFrame(NULL, wxID_ANY, wxT("
|
91
|
+
: wxFrame(NULL, wxID_ANY, wxT("sample"))
|
187
92
|
{
|
188
93
|
m_mgr.SetManagedWindow(this);
|
189
|
-
|
94
|
+
m_panel = new MyPanel(this);
|
95
|
+
m_txt = new wxTextCtrl(this, wxID_ANY);
|
96
|
+
m_mgr.AddPane(m_panel, wxAuiPaneInfo().MinSize(wxSize(100,100)));
|
190
|
-
m_mgr.AddPane(
|
97
|
+
m_mgr.AddPane(m_txt, wxAuiPaneInfo().CenterPane());
|
191
|
-
Caption(wxT("button")).
|
192
|
-
Right().MinSize(wxSize(100, 100))
|
193
|
-
);
|
194
|
-
m_glc = new TestGLCanvas(this);
|
195
|
-
m_mgr.AddPane(m_glc, wxAuiPaneInfo().Name(wxT("aui_gl_content")).CenterPane());
|
196
98
|
m_mgr.Update();
|
197
99
|
|
198
100
|
SetClientSize(600, 600);
|
199
101
|
Show();
|
200
|
-
|
201
|
-
static const int attribs[] = { WX_GL_RGBA, WX_GL_DOUBLEBUFFER, 0 };
|
202
|
-
wxLogStatus("Double-buffered display %s supported",
|
203
|
-
wxGLCanvas::IsDisplaySupported(attribs) ? "is" : "not");
|
204
102
|
}
|
205
103
|
|
206
|
-
void MyFrame::OnClose(wxCommandEvent& WXUNUSED(event))
|
207
|
-
{
|
208
|
-
Close(true);
|
209
|
-
}
|
210
|
-
|
211
|
-
TestGLCanvas* MyFrame::GetGLCanvas()
|
212
|
-
{
|
213
|
-
return m_glc;
|
214
|
-
}
|
215
|
-
|
216
104
|
MyFrame::~MyFrame()
|
217
105
|
{
|
218
106
|
m_mgr.UnInit();
|
219
107
|
}
|
220
|
-
|
221
|
-
BEGIN_EVENT_TABLE(MyPanel, wxPanel)
|
222
|
-
EVT_BUTTON(ID_BUTTON, MyPanel::OnButton)
|
223
|
-
END_EVENT_TABLE()
|
224
|
-
|
225
|
-
MyPanel::MyPanel(wxWindow* parent)
|
226
|
-
:wxPanel(parent, -1)
|
227
|
-
{
|
228
|
-
btn = new wxButton(this, ID_BUTTON, wxT("button"));
|
229
|
-
wxBoxSizer* vbox = new wxBoxSizer(wxVERTICAL);
|
230
|
-
wxBoxSizer* hbox = new wxBoxSizer(wxHORIZONTAL);
|
231
|
-
this->SetSizer(hbox);
|
232
|
-
vbox->Add(btn, 1, wxEXPAND);
|
233
|
-
hbox->Add(vbox, 1, wxEXPAND);
|
234
|
-
}
|
235
|
-
|
236
|
-
void MyPanel::OnButton(wxCommandEvent& event)
|
237
|
-
{
|
238
|
-
TestGLCanvas* tempglc = ((MyFrame*)GetParent())->GetGLCanvas();
|
239
|
-
TestGLContext& canvas = wxGetApp().GetContext(tempglc);
|
240
|
-
canvas.Draw();
|
241
|
-
tempglc->SwapBuffers();
|
242
|
-
}
|
243
108
|
```
|