/** * CS798 Project - viewer.hpp * April 21, 2006 * * Erika Harrison */ #ifndef CS798_VIEWER_HPP #define CS798_VIEWER_HPP #include "algebra.hpp" #include "design.hpp" #include "const.hpp" #include #include #include // The "main" OpenGL widget class Viewer : public Gtk::GL::DrawingArea { public: Viewer(); virtual ~Viewer(); // A useful function that forces this widget to rerender. If you // want to render a new frame, do not call on_expose_event // directly. Instead call this, which will cause an on_expose_event // call when the time is right. void invalidate(); // sets the modes void setRenderMode(Const::RenderMode m) { renderMode=m; updateStatusBar(); invalidate(); } void setMathMode(Const::MathMode m) { mathMode=m; updateStatusBar(); invalidate(); } void setViewMode(Const::ViewMode m) { viewMode=m; resetOrientation(); updateStatusBar(); invalidate(); } void swapLighting() { lighting = !lighting; invalidate(); } // design properties void addLayer() { design->addLayer(); } void deleteLayer() { design->deleteLayer(); } // sets the status bar for updates void setStatusBar(Gtk::Label * l) { statusBar = l; updateStatusBar(); } // file dealings // TODO: fix up //void newTiling(int tileType); //void exportSVG(string fileName, int width, int height); // resets the space orientation values (ie. rotate/rotating/scaled) void resetPosition(); void resetOrientation(); //void resetTiling(); void resetAll(); // get current design for property changes Design * getCurrentDesign() { return design; } //void setColourMenu(Gtk::Menu * m) { colourMenu = m; updateColourMenu(); } //void updateColourMenu(); protected: // Events we implement // Note that we could use gtkmm's "signals and slots" mechanism // instead, but for many classes there's a convenient member // function one just needs to define that'll be called with the // event. // Called when GL is first initialized virtual void on_realize(); // Called when our window needs to be redrawn virtual bool on_expose_event(GdkEventExpose* event); // Called when the window is resized virtual bool on_configure_event(GdkEventConfigure* event); // Called when a mouse button is pressed virtual bool on_button_press_event(GdkEventButton* event); // Called when a mouse button is released virtual bool on_button_release_event(GdkEventButton* event); // Called when the mouse moves virtual bool on_motion_notify_event(GdkEventMotion* event); private: Design * design; //Gtk::Menu * colourMenu; double currRadius; // RENDERING Const::RenderMode renderMode; // style of rendering Const::MathMode mathMode; // cycloid, vs. roulette Const::ViewMode viewMode; // item being rendered bool lighting; // lighting is on // status bar for updating Gtk::Label * statusBar; void updateStatusBar(); // view stuffs // mouse data actions float startTX, startTY, startTZ; float startRX, startRY; Matrix4x4 mMatrixR, mMatrixT; double zoom; // stores the current z value static const double DEFAULT_VIEW_BACK = -10.0; void setView(); // sets up the translation/rotation of the viewer void setLights(); // sets up the lights void draw(); // draws the current tiling // scene translations/rotations void startTransXY(int x, int y); void setTransXY(int x, int y); void stopTransXY(); void startTransZ(int y); void setTransZ(int y); void stopTransZ(); void startMRotate(int x, int y); void setMRotate(int x, int y); void stopMRotate(); // for use for colour alterations in the sub polygons // TODO: fix?? /*typedef struct Datum { int i, j; }; void setColour(Datum d);*/ // pseudo-trackball helper functions: only use for z rotation void vCalcRotVec(float fNewX, float fNewY, float fOldX, float fOldY, float fDiameter, float & fVecX, float & fVecY, float & fVecZ); void vAxisRotMatrix(float fVecX, float fVecY, float fVecZ, Matrix4x4 & mNewMat); }; #endif