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_pixel_2d();
00085   NodePath get_mouse();
00086   NodePath get_button_thrower();
00087 
00088   void enable_keyboard();
00089   void setup_trackball();
00090   void center_trackball(const NodePath &object);
00091 
00092   bool load_models(const NodePath &parent,
00093                    int argc, char *argv[], int first_arg = 1);
00094   bool load_models(const NodePath &parent,
00095                    const pvector<Filename> &files);
00096   NodePath load_model(const NodePath &parent, Filename filename);
00097   NodePath load_default_model(const NodePath &parent);
00098   void loop_animations(int hierarchy_match_flags = 
00099                        PartGroup::HMF_ok_part_extra |
00100                        PartGroup::HMF_ok_anim_extra);
00101   void stagger_animations();
00102   void next_anim_control();
00103   void set_anim_controls(bool enable);
00104   INLINE bool get_anim_controls() const;
00105   void adjust_dimensions();
00106 
00107   enum BackgroundType {
00108     BT_other = 0,
00109     BT_default,
00110     BT_black,
00111     BT_gray,
00112     BT_white,
00113     BT_none
00114   };
00115 
00116   enum SplitType {
00117     ST_default,
00118     ST_horizontal,
00119     ST_vertical,
00120   };
00121   WindowFramework *split_window(SplitType split_type = ST_default);
00122 
00123   void set_wireframe(bool enable);
00124   void set_texture(bool enable);
00125   void set_two_sided(bool enable);
00126   void set_one_sided_reverse(bool enable);
00127   void set_lighting(bool enable);
00128   void set_perpixel(bool enable);
00129   void set_background_type(BackgroundType type);
00130 
00131   INLINE bool get_wireframe() const;
00132   INLINE bool get_texture() const;
00133   INLINE bool get_two_sided() const;
00134   INLINE bool get_one_sided_reverse() const;
00135   INLINE bool get_lighting() const;
00136   INLINE bool get_perpixel() const;
00137   INLINE BackgroundType get_background_type() const;
00138 
00139   static TextFont *get_shuttle_controls_font();
00140   NodePath make_camera();
00141 
00142 protected:
00143   void setup_lights();
00144 
00145 private:
00146   PT(PandaNode) load_image_as_model(const Filename &filename);
00147   void create_anim_controls();
00148   void destroy_anim_controls();
00149   void update_anim_controls();
00150 
00151   void setup_shuttle_button(const string &label, int index, 
00152                             EventHandler::EventCallbackFunction *func);
00153   void back_button();
00154   void pause_button();
00155   void play_button();
00156   void forward_button();
00157 
00158   static AsyncTask::DoneStatus st_update_anim_controls(GenericAsyncTask *task, void *data);
00159 
00160   static void st_back_button(const Event *, void *data);
00161   static void st_pause_button(const Event *, void *data);
00162   static void st_play_button(const Event *, void *data);
00163   static void st_forward_button(const Event *, void *data);
00164 
00165 private:
00166   PandaFramework *_panda_framework;
00167   PT(GraphicsOutput) _window;
00168   PT(DisplayRegion) _display_region_2d;
00169   PT(DisplayRegion) _display_region_3d;
00170 
00171   NodePath _camera_group;
00172   typedef pvector< PT(Camera) > Cameras;
00173   Cameras _cameras;
00174 
00175   NodePath _render;
00176   NodePath _render_2d;
00177   NodePath _aspect_2d;
00178   NodePath _pixel_2d;
00179 
00180   AnimControlCollection _anim_controls;
00181   bool _anim_controls_enabled;
00182   int _anim_index;
00183   NodePath _anim_controls_group;
00184   PT(PGSliderBar) _anim_slider;
00185   PT(PGSliderBar) _play_rate_slider;
00186   PT(TextNode) _frame_number;
00187   PT(GenericAsyncTask) _update_anim_controls_task;
00188 
00189   NodePath _mouse;
00190   NodePath _button_thrower;
00191   PT(Trackball) _trackball;
00192 
00193   NodePath _alight;
00194   NodePath _dlight;
00195   
00196   bool _got_keyboard;
00197   bool _got_trackball;
00198   bool _got_lights;
00199 
00200   bool _wireframe_enabled;
00201   bool _texture_enabled;
00202   bool _two_sided_enabled;
00203   bool _one_sided_reverse_enabled;
00204   bool _lighting_enabled;
00205   bool _perpixel_enabled;
00206 
00207   PT(FrameRateMeter) _frame_rate_meter;
00208   PT(SceneGraphAnalyzerMeter) _scene_graph_analyzer_meter;
00209 
00210   BackgroundType _background_type;
00211   
00212   static PT(TextFont) _shuttle_controls_font;
00213 
00214 public:
00215   static TypeHandle get_class_type() {
00216     return _type_handle;
00217   }
00218   static void init_type() {
00219     TypedWritableReferenceCount::init_type();
00220     register_type(_type_handle, "WindowFramework",
00221                   TypedWritableReferenceCount::get_class_type());
00222   }
00223   virtual TypeHandle get_type() const {
00224     return get_class_type();
00225   }
00226   virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00227 
00228 private:
00229   static TypeHandle _type_handle;
00230 
00231   friend class PandaFramework;
00232 };
00233 
00234 #include "windowFramework.I"
00235 
00236 #endif
 All Classes Functions Variables Enumerations