Panda3D

windowFramework.h

00001 // Filename: windowFramework.h
00002 // Created by:  drose (02Apr02)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #ifndef WINDOWFRAMEWORK_H
00016 #define WINDOWFRAMEWORK_H
00017 
00018 #include "pandabase.h"
00019 #include "nodePath.h"
00020 #include "camera.h"
00021 #include "graphicsOutput.h"
00022 #include "graphicsWindow.h"
00023 #include "animControlCollection.h"
00024 #include "trackball.h"
00025 #include "filename.h"
00026 #include "frameRateMeter.h"
00027 #include "sceneGraphAnalyzerMeter.h"
00028 #include "pointerTo.h"
00029 #include "partGroup.h"
00030 #include "pvector.h"
00031 #include "typedWritableReferenceCount.h"
00032 #include "loaderOptions.h"
00033 #include "pgSliderBar.h"
00034 #include "textNode.h"
00035 #include "eventHandler.h"
00036 #include "genericAsyncTask.h"
00037 
00038 class PandaFramework;
00039 class AmbientLight;
00040 class DirectionalLight;
00041 class GraphicsEngine;
00042 class GraphicsPipe;
00043 class DisplayRegion;
00044 
00045 ////////////////////////////////////////////////////////////////////
00046 //       Class : WindowFramework
00047 // Description : This encapsulates the data that is normally
00048 //               associated with a single window, or with a single
00049 //               display region within a window.  (In the case where a
00050 //               window has been subdivided with split_window(), there
00051 //               may be multiple WindowFrameworks objects that share
00052 //               the same GraphicsOutput pointer, but reference
00053 //               different display regions within that window).
00054 ////////////////////////////////////////////////////////////////////
00055 class EXPCL_FRAMEWORK WindowFramework : public TypedWritableReferenceCount {
00056 protected:
00057   WindowFramework(PandaFramework *panda_framework);
00058   WindowFramework(const WindowFramework &copy, DisplayRegion *display_region);
00059 
00060 public:
00061   virtual ~WindowFramework();
00062 
00063 protected:
00064   GraphicsOutput *open_window(const WindowProperties &props, int flags,
00065                               GraphicsEngine *engine, GraphicsPipe *pipe,
00066                               GraphicsStateGuardian *gsg = NULL);
00067   void close_window();
00068 
00069 public:
00070   INLINE PandaFramework *get_panda_framework() const;
00071   INLINE GraphicsWindow *get_graphics_window() const;
00072   INLINE GraphicsOutput *get_graphics_output() const;
00073   NodePath get_camera_group();
00074 
00075   INLINE int get_num_cameras() const;
00076   INLINE Camera *get_camera(int n) const;
00077 
00078   INLINE DisplayRegion *get_display_region_2d() const;
00079   INLINE DisplayRegion *get_display_region_3d() const;
00080 
00081   NodePath get_render();
00082   NodePath get_render_2d();
00083   NodePath get_aspect_2d();
00084   NodePath get_mouse();
00085   NodePath get_button_thrower();
00086 
00087   void enable_keyboard();
00088   void setup_trackball();
00089   void center_trackball(const NodePath &object);
00090 
00091   bool load_models(const NodePath &parent,
00092                    int argc, char *argv[], int first_arg = 1);
00093   bool load_models(const NodePath &parent,
00094                    const pvector<Filename> &files);
00095   NodePath load_model(const NodePath &parent, Filename filename);
00096   NodePath load_default_model(const NodePath &parent);
00097   void loop_animations(int hierarchy_match_flags = 
00098                        PartGroup::HMF_ok_part_extra |
00099                        PartGroup::HMF_ok_anim_extra);
00100   void stagger_animations();
00101   void next_anim_control();
00102   void set_anim_controls(bool enable);
00103   INLINE bool get_anim_controls() const;
00104   void adjust_aspect_ratio();
00105 
00106   enum BackgroundType {
00107     BT_other = 0,
00108     BT_default,
00109     BT_black,
00110     BT_gray,
00111     BT_white,
00112     BT_none
00113   };
00114 
00115   enum SplitType {
00116     ST_default,
00117     ST_horizontal,
00118     ST_vertical,
00119   };
00120   WindowFramework *split_window(SplitType split_type = ST_default);
00121 
00122   void set_wireframe(bool enable);
00123   void set_texture(bool enable);
00124   void set_two_sided(bool enable);
00125   void set_one_sided_reverse(bool enable);
00126   void set_lighting(bool enable);
00127   void set_perpixel(bool enable);
00128   void set_background_type(BackgroundType type);
00129 
00130   INLINE bool get_wireframe() const;
00131   INLINE bool get_texture() const;
00132   INLINE bool get_two_sided() const;
00133   INLINE bool get_one_sided_reverse() const;
00134   INLINE bool get_lighting() const;
00135   INLINE bool get_perpixel() const;
00136   INLINE BackgroundType get_background_type() const;
00137 
00138   static TextFont *get_shuttle_controls_font();
00139   NodePath make_camera();
00140 
00141 protected:
00142   void setup_lights();
00143 
00144 private:
00145   PT(PandaNode) load_image_as_model(const Filename &filename);
00146   void create_anim_controls();
00147   void destroy_anim_controls();
00148   void update_anim_controls();
00149 
00150   void setup_shuttle_button(const string &label, int index, 
00151                             EventHandler::EventCallbackFunction *func);
00152   void back_button();
00153   void pause_button();
00154   void play_button();
00155   void forward_button();
00156 
00157   static AsyncTask::DoneStatus st_update_anim_controls(GenericAsyncTask *task, void *data);
00158 
00159   static void st_back_button(const Event *, void *data);
00160   static void st_pause_button(const Event *, void *data);
00161   static void st_play_button(const Event *, void *data);
00162   static void st_forward_button(const Event *, void *data);
00163 
00164 private:
00165   PandaFramework *_panda_framework;
00166   PT(GraphicsOutput) _window;
00167   PT(DisplayRegion) _display_region_2d;
00168   PT(DisplayRegion) _display_region_3d;
00169 
00170   NodePath _camera_group;
00171   typedef pvector< PT(Camera) > Cameras;
00172   Cameras _cameras;
00173 
00174   NodePath _render;
00175   NodePath _render_2d;
00176   NodePath _aspect_2d;
00177 
00178   AnimControlCollection _anim_controls;
00179   bool _anim_controls_enabled;
00180   int _anim_index;
00181   NodePath _anim_controls_group;
00182   PT(PGSliderBar) _anim_slider;
00183   PT(PGSliderBar) _play_rate_slider;
00184   PT(TextNode) _frame_number;
00185   PT(GenericAsyncTask) _update_anim_controls_task;
00186 
00187   NodePath _mouse;
00188   NodePath _button_thrower;
00189   PT(Trackball) _trackball;
00190 
00191   NodePath _alight;
00192   NodePath _dlight;
00193   
00194   bool _got_keyboard;
00195   bool _got_trackball;
00196   bool _got_lights;
00197 
00198   bool _wireframe_enabled;
00199   bool _texture_enabled;
00200   bool _two_sided_enabled;
00201   bool _one_sided_reverse_enabled;
00202   bool _lighting_enabled;
00203   bool _perpixel_enabled;
00204 
00205   PT(FrameRateMeter) _frame_rate_meter;
00206   PT(SceneGraphAnalyzerMeter) _scene_graph_analyzer_meter;
00207 
00208   BackgroundType _background_type;
00209   
00210   static PT(TextFont) _shuttle_controls_font;
00211 
00212 public:
00213   static TypeHandle get_class_type() {
00214     return _type_handle;
00215   }
00216   static void init_type() {
00217     TypedWritableReferenceCount::init_type();
00218     register_type(_type_handle, "WindowFramework",
00219                   TypedWritableReferenceCount::get_class_type());
00220   }
00221   virtual TypeHandle get_type() const {
00222     return get_class_type();
00223   }
00224   virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00225 
00226 private:
00227   static TypeHandle _type_handle;
00228 
00229   friend class PandaFramework;
00230 };
00231 
00232 #include "windowFramework.I"
00233 
00234 #endif
 All Classes Functions Variables Enumerations