Canvas.h

Go to the documentation of this file.
00001 /**<!-------------------------------------------------------------------->
00002    @class  Canvas
00003    @author Travis Fischer (fisch0920@gmail.com)
00004    @author Matthew Jacobs (jacobs.mh@gmail.com)
00005    @date   Fall 2008
00006    
00007    @brief
00008       Provides a generic Canvas interface, shared between OpenGL canvases 
00009    and pixel-based canvases
00010    <!-------------------------------------------------------------------->**/
00011 
00012 #ifndef CANVAS_H_
00013 #define CANVAS_H_
00014 
00015 #include "Visualization.h"
00016 #include <renderers/Renderer.h>
00017 #include <core/Ray.h>
00018 
00019 #define DEFAULT_WIDTH      (480)
00020 #define DEFAULT_HEIGHT     (480)
00021 
00022 DECLARE_STL_TYPEDEF(std::vector<InteractionListener*>, ListenerList);
00023 
00024 class QWidget;
00025 class Camera;
00026 class Scene;
00027 class Gui;
00028 
00029 class Canvas {
00030    friend class InteractionListener;
00031    
00032    public:
00033       ///@name Constructors
00034       //@{-----------------------------------------------------------------
00035       
00036       Canvas(Gui *gui, 
00037              unsigned width = DEFAULT_WIDTH, 
00038              unsigned height = DEFAULT_HEIGHT);
00039       
00040       virtual ~Canvas();
00041       
00042       
00043       //@}-----------------------------------------------------------------
00044       ///@name Saving
00045       //@{-----------------------------------------------------------------
00046       
00047       /**
00048        * Attempts to saver this canvas' image to the specified file
00049        * @returns whether or not the save was successful
00050        */
00051       virtual bool save(const char *fileName) = 0;
00052       
00053       
00054       //@}-----------------------------------------------------------------
00055       ///@name Interaction/Visualization interface
00056       //@{-----------------------------------------------------------------
00057       
00058       virtual void init();
00059       
00060       virtual void registerInteractionListener(InteractionListener *listener);
00061       virtual void unregisterInteractionListener(InteractionListener *listener);
00062       
00063       
00064       //@}-----------------------------------------------------------------
00065       ///@name Accessors
00066       //@{-----------------------------------------------------------------
00067       
00068       /**
00069        * @returns true iff this Canvas supports OpenGL
00070        * 
00071        * @note Gui assumes that if a Canvas supports OpenGL, it also 
00072        *    derives from QGLWidget
00073        * @see also OpenGLCanvas
00074        */
00075       virtual bool supportsOpenGL() const = 0;
00076       
00077       /**
00078        * @returns the QWidget associated with this Canvas
00079        */
00080       virtual QWidget *getQWidget() = 0;
00081       
00082       inline Gui *getGui() const {
00083          return m_gui;
00084       }
00085       
00086       inline Renderer *getRenderer() {
00087          return m_renderer;
00088       }
00089       
00090       inline Camera *getCamera() {
00091          ASSERT(m_renderer);
00092          return m_renderer->getCamera();
00093       }
00094       
00095       inline Scene *getScene() {
00096          ASSERT(m_renderer);
00097          return m_renderer->getScene();
00098       }
00099       
00100       //@}-----------------------------------------------------------------
00101       ///@name Mutators
00102       //@{-----------------------------------------------------------------
00103       
00104       virtual void setRenderer(Renderer *renderer);
00105       
00106       inline void setGui(Gui *gui) {
00107          m_gui = gui;
00108       }
00109       
00110       
00111       //@}-----------------------------------------------------------------
00112       ///@name Canvas dimensions
00113       //@{-----------------------------------------------------------------
00114       
00115       inline unsigned getWidth() const {
00116          return m_width;
00117       }
00118       
00119       inline unsigned getHeight() const {
00120          return m_height;
00121       }
00122       
00123       
00124       //@}-----------------------------------------------------------------
00125       
00126       virtual void redraw() = 0;
00127       
00128    protected:
00129       ///@name Interaction/Visualization interface to children
00130       //@{-----------------------------------------------------------------
00131       
00132       virtual void mousePressed (QMouseEvent *event);
00133       virtual void mouseReleased(QMouseEvent *event);
00134       virtual void mouseMoved   (QMouseEvent *event);
00135        
00136       virtual void keyPressed (QKeyEvent *event);
00137       virtual void keyReleased(QKeyEvent *event);
00138       
00139       
00140       //@}-----------------------------------------------------------------
00141       
00142    protected:
00143       Gui         *m_gui;
00144       Renderer    *m_renderer;
00145       
00146       unsigned     m_width;
00147       unsigned     m_height;
00148       bool         m_initted;
00149       
00150       ListenerList m_interactionListeners;
00151       
00152    private:
00153       void _init();
00154 };
00155 
00156 #endif // CANVAS_H_
00157 

Generated on 28 Feb 2009 for Milton by doxygen 1.5.6