sierpinski-gtk/SierpinskiDA.cc
josh 2b5692498c initial commit
git-svn-id: svn://anubis/misc/sierpinski-gtk@246 bd8a9e45-a331-0410-811e-c64571078777
2010-10-21 17:07:00 +00:00

100 lines
2.0 KiB
C++

#include <GL/gl.h>
#include <GL/glu.h>
#include <gdkmm/cursor.h>
#include "SierpinskiDA.h"
SierpinskiDA::SierpinskiDA(const Glib::RefPtr<const Gdk::GL::Config> & config)
: Gtk::GL::DrawingArea(config)
{
set_gl_capability(config);
set_events(Gdk::POINTER_MOTION_MASK
| Gdk::BUTTON_PRESS_MASK
| Gdk::BUTTON_RELEASE_MASK
| Gdk::SCROLL_MASK);
}
bool SierpinskiDA::draw()
{
Glib::RefPtr<Gdk::GL::Window> glwindow = get_gl_window();
if (!glwindow->gl_begin(get_gl_context()))
return false;
glClearColor(0.1, 0.6, 1.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0, -2, 0,
0, 0, 0,
0, 0, 1);
if (glwindow->is_double_buffered())
glwindow->swap_buffers();
else
glFlush();
return true;
}
bool SierpinskiDA::on_motion_notify_event(GdkEventMotion * event)
{
get_pointer(m_x, m_y);
return true;
}
bool SierpinskiDA::on_button_press_event(GdkEventButton * event)
{
return false;
}
bool SierpinskiDA::on_button_release_event(GdkEventButton * event)
{
return false;
}
bool SierpinskiDA::on_scroll_event(GdkEventScroll * event)
{
return false;
}
void SierpinskiDA::on_realize()
{
Gtk::GL::DrawingArea::on_realize();
Glib::RefPtr<Gdk::GL::Window> glwindow = get_gl_window();
glwindow->get_window()->set_cursor(Gdk::Cursor(Gdk::CROSSHAIR));
if (!glwindow->gl_begin(get_gl_context()))
return;
glViewport(0, 0, get_width(), get_height());
glwindow->gl_end();
}
/*
* called on widget resizes
*/
bool SierpinskiDA::on_configure_event(GdkEventConfigure * event)
{
Glib::RefPtr<Gdk::GL::Window> glwindow = get_gl_window();
if (!glwindow->gl_begin(get_gl_context()))
return false;
glViewport(0, 0, get_width(), get_height());
glwindow->gl_end();
return true;
}
bool SierpinskiDA::on_expose_event(GdkEventExpose * event)
{
return draw();
}