Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Examples

logo.h

GtkGLExt logo demo.
// -*- C++ -*- /* * logo.h: * GtkGLExt logo demo. * * written by Naofumi Yasufuku <naofumi@users.sourceforge.net> */ #ifndef _LOGO_H #define _LOGO_H #include <gtkmm.h> #include <gtkglmm.h> // // Logo classes. // namespace Logo { class Scene; // // View class. // class View : public sigc::trackable { friend class Scene; public: static const float NEAR_CLIP; static const float FAR_CLIP; static const float INIT_POS_X; static const float INIT_POS_Y; static const float INIT_POS_Z; static const float INIT_AXIS_X; static const float INIT_AXIS_Y; static const float INIT_AXIS_Z; static const float INIT_ANGLE; static const float INIT_SCALE; static const float SCALE_MAX; static const float SCALE_MIN; public: View(); virtual ~View(); public: void frustum(int w, int h); void xform(); void reset(); void set_pos(float x, float y, float z) { m_Pos[0] = x; m_Pos[1] = y; m_Pos[2] = z; } void set_quat(float q0, float q1, float q2, float q3) { m_Quat[0] = q0; m_Quat[1] = q1; m_Quat[2] = q2; m_Quat[3] = q3; } void set_scale(float scale) { m_Scale = scale; } protected: // Signal handlers: virtual bool on_button_press_event(GdkEventButton* event, Scene* scene); virtual bool on_motion_notify_event(GdkEventMotion* event, Scene* scene); private: float m_Pos[3]; float m_Quat[4]; float m_Scale; float m_BeginX; float m_BeginY; }; // // Logo model class. // class Model { friend class Scene; public: enum DisplayList { CUBE = 1, G_FORWARD, G_BACKWARD, T_FORWARD, T_BACKWARD, K_FORWARD, K_BACKWARD }; static const float MAT_SPECULAR[4]; static const float MAT_SHININESS[1]; static const float MAT_BLACK[4]; static const float MAT_RED[4]; static const float MAT_GREEN[4]; static const float MAT_BLUE[4]; static const unsigned int DEFAULT_ROT_COUNT; public: explicit Model(unsigned int rot_count = DEFAULT_ROT_COUNT, bool enable_anim = true); virtual ~Model(); private: void init_gl(); public: void draw(); void enable_anim() { m_EnableAnim = true; } void disable_anim() { m_EnableAnim = false; } bool anim_is_enabled() const { return m_EnableAnim; } void reset_anim(); void set_pos(float x, float y, float z) { m_Pos[0] = x; m_Pos[1] = y; m_Pos[2] = z; } void set_quat(float q0, float q1, float q2, float q3) { m_Quat[0] = q0; m_Quat[1] = q1; m_Quat[2] = q2; m_Quat[3] = q3; } private: // Rotation mode. struct RotMode { float *axis; float sign; }; static const RotMode ROT_MODE[]; private: unsigned int m_RotCount; bool m_EnableAnim; unsigned int m_Mode; unsigned int m_Counter; float m_Pos[3]; float m_Quat[4]; }; // // Scene class. // class Scene : public Gtk::GL::DrawingArea { friend class View; friend class Model; public: static const unsigned int TIMEOUT_INTERVAL; // OpenGL scene related constants: static const float CLEAR_COLOR[4]; static const float CLEAR_DEPTH; static const float LIGHT0_POSITION[4]; static const float LIGHT0_DIFFUSE[4]; static const float LIGHT0_SPECULAR[4]; public: explicit Scene(unsigned int rot_count = Model::DEFAULT_ROT_COUNT, bool enable_anim = true); virtual ~Scene(); protected: // signal handlers: virtual void on_realize(); virtual bool on_configure_event(GdkEventConfigure* event); virtual bool on_expose_event(GdkEventExpose* event); virtual bool on_button_press_event(GdkEventButton* event); virtual bool on_map_event(GdkEventAny* event); virtual bool on_unmap_event(GdkEventAny* event); virtual bool on_visibility_notify_event(GdkEventVisibility* event); virtual bool on_timeout(); public: // Invalidate whole window. void invalidate() { get_window()->invalidate_rect(get_allocation(), false); } // Update window synchronously (fast). void update() { get_window()->process_updates(false); } protected: // timeout signal connection: sigc::connection m_ConnectionTimeout; void timeout_add(); void timeout_remove(); public: // OpenGL scene related methods: bool anim_is_enabled() const { return m_Model.anim_is_enabled(); } void toggle_anim(); void init_anim(); protected: Gtk::Menu* create_popup_menu(); protected: // Popup menu: Gtk::Menu* m_Menu; protected: // OpenGL scene related objects: View m_View; Model m_Model; }; // // Application class. // class Application : public Gtk::Window { public: static const Glib::ustring APP_NAME; public: explicit Application(unsigned int rot_count = Model::DEFAULT_ROT_COUNT, bool enable_anim = true); virtual ~Application(); protected: // signal handlers: virtual void on_button_quit_clicked(); virtual bool on_key_press_event(GdkEventKey* event); protected: // member widgets: Gtk::VBox m_VBox; Scene m_Scene; Gtk::Button m_ButtonQuit; }; } // namespace Logo #endif // _LOGO_H
00001 // -*- C++ -*- 00002 /* 00003 * logo.h: 00004 * GtkGLExt logo demo. 00005 * 00006 * written by Naofumi Yasufuku <naofumi@users.sourceforge.net> 00007 */ 00008 00009 #ifndef _LOGO_H 00010 #define _LOGO_H 00011 00012 #include <gtkmm.h> 00013 00014 #include <gtkglmm.h> 00015 00016 00018 // 00019 // Logo classes. 00020 // 00022 00023 namespace Logo 00024 { 00025 00026 class Scene; 00027 00028 // 00029 // View class. 00030 // 00031 00032 class View : public sigc::trackable 00033 { 00034 friend class Scene; 00035 00036 public: 00037 static const float NEAR_CLIP; 00038 static const float FAR_CLIP; 00039 00040 static const float INIT_POS_X; 00041 static const float INIT_POS_Y; 00042 static const float INIT_POS_Z; 00043 00044 static const float INIT_AXIS_X; 00045 static const float INIT_AXIS_Y; 00046 static const float INIT_AXIS_Z; 00047 static const float INIT_ANGLE; 00048 00049 static const float INIT_SCALE; 00050 00051 static const float SCALE_MAX; 00052 static const float SCALE_MIN; 00053 00054 public: 00055 View(); 00056 virtual ~View(); 00057 00058 public: 00059 void frustum(int w, int h); 00060 00061 void xform(); 00062 00063 void reset(); 00064 00065 void set_pos(float x, float y, float z) 00066 { m_Pos[0] = x; m_Pos[1] = y; m_Pos[2] = z; } 00067 00068 void set_quat(float q0, float q1, float q2, float q3) 00069 { m_Quat[0] = q0; m_Quat[1] = q1; m_Quat[2] = q2; m_Quat[3] = q3; } 00070 00071 void set_scale(float scale) 00072 { m_Scale = scale; } 00073 00074 protected: 00075 // Signal handlers: 00076 virtual bool on_button_press_event(GdkEventButton* event, Scene* scene); 00077 virtual bool on_motion_notify_event(GdkEventMotion* event, Scene* scene); 00078 00079 private: 00080 float m_Pos[3]; 00081 float m_Quat[4]; 00082 float m_Scale; 00083 00084 float m_BeginX; 00085 float m_BeginY; 00086 00087 }; 00088 00089 00090 // 00091 // Logo model class. 00092 // 00093 00094 class Model 00095 { 00096 friend class Scene; 00097 00098 public: 00099 enum DisplayList { 00100 CUBE = 1, 00101 G_FORWARD, 00102 G_BACKWARD, 00103 T_FORWARD, 00104 T_BACKWARD, 00105 K_FORWARD, 00106 K_BACKWARD 00107 }; 00108 00109 static const float MAT_SPECULAR[4]; 00110 static const float MAT_SHININESS[1]; 00111 static const float MAT_BLACK[4]; 00112 static const float MAT_RED[4]; 00113 static const float MAT_GREEN[4]; 00114 static const float MAT_BLUE[4]; 00115 00116 static const unsigned int DEFAULT_ROT_COUNT; 00117 00118 public: 00119 explicit Model(unsigned int rot_count = DEFAULT_ROT_COUNT, 00120 bool enable_anim = true); 00121 virtual ~Model(); 00122 00123 private: 00124 void init_gl(); 00125 00126 public: 00127 void draw(); 00128 00129 void enable_anim() 00130 { m_EnableAnim = true; } 00131 00132 void disable_anim() 00133 { m_EnableAnim = false; } 00134 00135 bool anim_is_enabled() const 00136 { return m_EnableAnim; } 00137 00138 void reset_anim(); 00139 00140 void set_pos(float x, float y, float z) 00141 { m_Pos[0] = x; m_Pos[1] = y; m_Pos[2] = z; } 00142 00143 void set_quat(float q0, float q1, float q2, float q3) 00144 { m_Quat[0] = q0; m_Quat[1] = q1; m_Quat[2] = q2; m_Quat[3] = q3; } 00145 00146 private: 00147 // Rotation mode. 00148 struct RotMode 00149 { 00150 float *axis; 00151 float sign; 00152 }; 00153 00154 static const RotMode ROT_MODE[]; 00155 00156 private: 00157 unsigned int m_RotCount; 00158 00159 bool m_EnableAnim; 00160 unsigned int m_Mode; 00161 unsigned int m_Counter; 00162 00163 float m_Pos[3]; 00164 float m_Quat[4]; 00165 00166 }; 00167 00168 00169 // 00170 // Scene class. 00171 // 00172 00173 class Scene : public Gtk::GL::DrawingArea 00174 { 00175 friend class View; 00176 friend class Model; 00177 00178 public: 00179 static const unsigned int TIMEOUT_INTERVAL; 00180 00181 // OpenGL scene related constants: 00182 static const float CLEAR_COLOR[4]; 00183 static const float CLEAR_DEPTH; 00184 00185 static const float LIGHT0_POSITION[4]; 00186 static const float LIGHT0_DIFFUSE[4]; 00187 static const float LIGHT0_SPECULAR[4]; 00188 00189 public: 00190 explicit Scene(unsigned int rot_count = Model::DEFAULT_ROT_COUNT, 00191 bool enable_anim = true); 00192 virtual ~Scene(); 00193 00194 protected: 00195 // signal handlers: 00196 virtual void on_realize(); 00197 virtual bool on_configure_event(GdkEventConfigure* event); 00198 virtual bool on_expose_event(GdkEventExpose* event); 00199 virtual bool on_button_press_event(GdkEventButton* event); 00200 virtual bool on_map_event(GdkEventAny* event); 00201 virtual bool on_unmap_event(GdkEventAny* event); 00202 virtual bool on_visibility_notify_event(GdkEventVisibility* event); 00203 virtual bool on_timeout(); 00204 00205 public: 00206 // Invalidate whole window. 00207 void invalidate() { 00208 get_window()->invalidate_rect(get_allocation(), false); 00209 } 00210 00211 // Update window synchronously (fast). 00212 void update() 00213 { get_window()->process_updates(false); } 00214 00215 protected: 00216 // timeout signal connection: 00217 sigc::connection m_ConnectionTimeout; 00218 00219 void timeout_add(); 00220 void timeout_remove(); 00221 00222 public: 00223 // OpenGL scene related methods: 00224 bool anim_is_enabled() const 00225 { return m_Model.anim_is_enabled(); } 00226 00227 void toggle_anim(); 00228 00229 void init_anim(); 00230 00231 protected: 00232 Gtk::Menu* create_popup_menu(); 00233 00234 protected: 00235 // Popup menu: 00236 Gtk::Menu* m_Menu; 00237 00238 protected: 00239 // OpenGL scene related objects: 00240 View m_View; 00241 Model m_Model; 00242 00243 }; 00244 00245 00246 // 00247 // Application class. 00248 // 00249 00250 class Application : public Gtk::Window 00251 { 00252 public: 00253 static const Glib::ustring APP_NAME; 00254 00255 public: 00256 explicit Application(unsigned int rot_count = Model::DEFAULT_ROT_COUNT, 00257 bool enable_anim = true); 00258 virtual ~Application(); 00259 00260 protected: 00261 // signal handlers: 00262 virtual void on_button_quit_clicked(); 00263 virtual bool on_key_press_event(GdkEventKey* event); 00264 00265 protected: 00266 // member widgets: 00267 Gtk::VBox m_VBox; 00268 Scene m_Scene; 00269 Gtk::Button m_ButtonQuit; 00270 }; 00271 00272 00273 } // namespace Logo 00274 00275 00276 #endif // _LOGO_H

Generated on Sun Jun 20 16:59:38 2004 for gtkglextmm by doxygen 1.3.7