]> git.tdb.fi Git - libs/gl.git/blobdiff - source/windowview.cpp
Split the Window-specific parts out of View
[libs/gl.git] / source / windowview.cpp
diff --git a/source/windowview.cpp b/source/windowview.cpp
new file mode 100644 (file)
index 0000000..61027ac
--- /dev/null
@@ -0,0 +1,34 @@
+#include "camera.h"
+#include "windowview.h"
+
+using namespace std;
+
+namespace Msp {
+namespace GL {
+
+WindowView::WindowView(Graphics::Window &w, Graphics::GLContext &c):
+       window(w),
+       context(c)
+{
+       window.signal_resize.connect(sigc::mem_fun(this, &WindowView::window_resized));
+       window_resized(window.get_width(), window.get_height());
+}
+
+void WindowView::render()
+{
+       View::render();
+       context.swap_buffers();
+}
+
+void WindowView::window_resized(unsigned w, unsigned h)
+{
+       target.viewport(0, 0, w, h);
+       float aspect = static_cast<float>(w)/h;
+       if(camera)
+               camera->set_aspect(aspect);
+       for(list<Camera *>::iterator i=synced_cameras.begin(); i!=synced_cameras.end(); ++i)
+               (*i)->set_aspect(aspect);
+}
+
+} // namespace GL
+} // namespace Msp