5 * Created by Toshi Nagata on 08/10/24.
6 * Copyright 2008 Toshi Nagata. All rights reserved.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation version 2 of the License.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
18 // For compilers that support precompilation, includes "wx/wx.h".
19 #include "wx/wxprec.h"
29 #if !wxUSE_DOC_VIEW_ARCHITECTURE
30 #error "You should have DocView architecture enabled in your wxWidgets installation."
33 #include "wx/docview.h"
35 #include "MyGLCanvas.h"
36 #include "MoleculeView.h"
39 #include "../MolLib/MolLib.h"
41 BEGIN_EVENT_TABLE(MyGLCanvas, wxGLCanvas)
42 EVT_SIZE(MyGLCanvas::OnSize)
43 EVT_ERASE_BACKGROUND(MyGLCanvas::OnEraseBackground)
44 EVT_MOUSE_EVENTS(MyGLCanvas::OnMouseEvent)
45 EVT_PAINT(MyGLCanvas::OnPaint)
46 EVT_MOUSE_CAPTURE_LOST(MyGLCanvas::OnCaptureLost)
50 int *MyGLAttributes = NULL;
52 int MyGLAttributes[20] = { WX_GL_RGBA, WX_GL_MIN_RED, 1, WX_GL_MIN_GREEN, 1,
53 WX_GL_MIN_BLUE, 1, WX_GL_DEPTH_SIZE, 1,
55 # if defined(__WXMAC__) || defined(__WXCOCOA__)
63 // Define a constructor for my canvas
64 MyGLCanvas::MyGLCanvas(MoleculeView *v, wxWindow *frame, const wxPoint& pos, const wxSize& size, long style):
65 wxGLCanvas(frame, wxID_ANY, MyGLAttributes, pos, size, style)
68 context = new wxGLContext(this);
71 MyGLCanvas::~MyGLCanvas()
76 // Define the repainting behaviour
78 MyGLCanvas::OnPaint( wxPaintEvent &WXUNUSED(event) )
83 // if (!GetContext()) return;
86 context->SetCurrent(*this);
90 glClearColor (0, 0, 0, 0);
91 glClear(GL_COLOR_BUFFER_BIT |
98 MyGLCanvas::OnCaptureLost(wxMouseCaptureLostEvent &event)
101 int w, h, modifierFlags;
108 pt = ScreenToClient(::wxGetMousePosition());
109 GetClientSize(&w, &h);
112 modifierFlags = MainViewCallback_modifierFlags(NULL);
113 mview = ((MoleculeView *)view)->mview;
114 MoleculeLock(mview->mol);
115 MainView_mouseUp(((MoleculeView *)view)->mview, p, modifierFlags, 0);
116 MoleculeUnlock(mview->mol);
120 MyGLCanvas::OnMouseEvent(wxMouseEvent &event)
125 wxPoint pt(event.GetPosition());
127 int modifierFlags, clickCount;
128 MainView *mview = ((MoleculeView *)view)->mview;
130 GetClientSize(&w, &h);
133 p[1] = h - pt.y; /* The origin of the internal coordinate should be left-bottom */
134 modifierFlags = MainViewCallback_modifierFlags(&event);
135 clickCount = MainViewCallback_clickCount(&event);
137 if (event.LeftUp() /* || (mview->isDragging && event.Entering() && !event.LeftIsDown()) */) {
140 MoleculeLock(mview->mol);
141 MainView_mouseUp(mview, p, modifierFlags, clickCount);
142 MoleculeUnlock(mview->mol);
143 } else if (event.LeftDClick()) {
146 MoleculeLock(mview->mol);
147 MainView_mouseUp(mview, p, modifierFlags, 2);
148 MoleculeUnlock(mview->mol);
149 } else if (event.Dragging()) {
150 MoleculeLock(mview->mol);
151 MainView_mouseDragged(mview, p, modifierFlags);
152 MoleculeUnlock(mview->mol);
153 } else if (event.LeftDown()) {
154 if (wxWindow::FindFocus() != this)
157 MoleculeLock(mview->mol);
158 MainView_mouseDown(mview, p, modifierFlags);
159 MoleculeUnlock(mview->mol);
164 MyGLCanvas::OnSize(wxSizeEvent &event)
166 // this is also necessary to update the context on some platforms
167 // wxGLCanvas::OnSize(event);
169 // set GL viewport (not called by wxGLCanvas::OnSize on all platforms...)
171 GetClientSize(&w, &h);
176 context->SetCurrent(*this);
177 glViewport(0, 0, (GLint) w, (GLint) h);
179 #if defined(__WXMSW__)
180 // On MSW, the window is not repainted upon resize event
186 MyGLCanvas::OnEraseBackground(wxEraseEvent & WXUNUSED(event))
188 // Do nothing, to avoid flashing.