Panda3D
windowFramework.h
1 // Filename: windowFramework.h
2 // Created by: drose (02Apr02)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef WINDOWFRAMEWORK_H
16 #define WINDOWFRAMEWORK_H
17 
18 #include "pandabase.h"
19 #include "nodePath.h"
20 #include "camera.h"
21 #include "graphicsOutput.h"
22 #include "graphicsWindow.h"
23 #include "animControlCollection.h"
24 #include "trackball.h"
25 #include "filename.h"
26 #include "frameRateMeter.h"
27 #include "sceneGraphAnalyzerMeter.h"
28 #include "pointerTo.h"
29 #include "partGroup.h"
30 #include "pvector.h"
31 #include "typedWritableReferenceCount.h"
32 #include "loaderOptions.h"
33 #include "pgSliderBar.h"
34 #include "textNode.h"
35 #include "eventHandler.h"
36 #include "genericAsyncTask.h"
37 
38 class PandaFramework;
39 class AmbientLight;
40 class DirectionalLight;
41 class GraphicsEngine;
42 class GraphicsPipe;
43 class DisplayRegion;
44 
45 ////////////////////////////////////////////////////////////////////
46 // Class : WindowFramework
47 // Description : This encapsulates the data that is normally
48 // associated with a single window, or with a single
49 // display region within a window. (In the case where a
50 // window has been subdivided with split_window(), there
51 // may be multiple WindowFrameworks objects that share
52 // the same GraphicsOutput pointer, but reference
53 // different display regions within that window).
54 ////////////////////////////////////////////////////////////////////
55 class EXPCL_FRAMEWORK WindowFramework : public TypedWritableReferenceCount {
56 protected:
57  WindowFramework(PandaFramework *panda_framework);
58  WindowFramework(const WindowFramework &copy, DisplayRegion *display_region);
59 
60 public:
61  virtual ~WindowFramework();
62 
63 protected:
64  GraphicsOutput *open_window(const WindowProperties &props, int flags,
65  GraphicsEngine *engine, GraphicsPipe *pipe,
66  GraphicsStateGuardian *gsg = NULL,
67  const FrameBufferProperties &fbprops =
69  void close_window();
70 
71 public:
72  INLINE PandaFramework *get_panda_framework() const;
73  INLINE GraphicsWindow *get_graphics_window() const;
74  INLINE GraphicsOutput *get_graphics_output() const;
75  NodePath get_camera_group();
76 
77  INLINE int get_num_cameras() const;
78  INLINE Camera *get_camera(int n) const;
79 
80  INLINE DisplayRegion *get_display_region_2d() const;
81  INLINE DisplayRegion *get_display_region_3d() const;
82 
83  NodePath get_render();
84  NodePath get_render_2d();
85  NodePath get_aspect_2d();
86  NodePath get_pixel_2d();
87  NodePath get_mouse();
88  NodePath get_button_thrower();
89 
90  void enable_keyboard();
91  void setup_trackball();
92  void center_trackball(const NodePath &object);
93 
94  bool load_models(const NodePath &parent,
95  int argc, char *argv[], int first_arg = 1);
96  bool load_models(const NodePath &parent,
97  const pvector<Filename> &files);
98  NodePath load_model(const NodePath &parent, Filename filename);
99  NodePath load_default_model(const NodePath &parent);
100  void loop_animations(int hierarchy_match_flags =
101  PartGroup::HMF_ok_part_extra |
102  PartGroup::HMF_ok_anim_extra);
103  void stagger_animations();
104  void next_anim_control();
105  void set_anim_controls(bool enable);
106  INLINE bool get_anim_controls() const;
107  void adjust_dimensions();
108 
109  enum BackgroundType {
110  BT_other = 0,
111  BT_default,
112  BT_black,
113  BT_gray,
114  BT_white,
115  BT_none
116  };
117 
118  enum SplitType {
119  ST_default,
120  ST_horizontal,
121  ST_vertical,
122  };
123  WindowFramework *split_window(SplitType split_type = ST_default);
124 
125  void set_wireframe(bool enable, bool filled=false);
126  void set_texture(bool enable);
127  void set_two_sided(bool enable);
128  void set_one_sided_reverse(bool enable);
129  void set_lighting(bool enable);
130  void set_perpixel(bool enable);
131  void set_background_type(BackgroundType type);
132 
133  INLINE bool get_wireframe() const;
134  INLINE bool get_wireframe_filled() const;
135  INLINE bool get_texture() const;
136  INLINE bool get_two_sided() const;
137  INLINE bool get_one_sided_reverse() const;
138  INLINE bool get_lighting() const;
139  INLINE bool get_perpixel() const;
140  INLINE BackgroundType get_background_type() const;
141 
142  static TextFont *get_shuttle_controls_font();
143  NodePath make_camera();
144 
145 protected:
146  void setup_lights();
147 
148 private:
149  PT(PandaNode) load_image_as_model(const Filename &filename);
150  void create_anim_controls();
151  void destroy_anim_controls();
152  void update_anim_controls();
153 
154  void setup_shuttle_button(const string &label, int index,
155  EventHandler::EventCallbackFunction *func);
156  void back_button();
157  void pause_button();
158  void play_button();
159  void forward_button();
160 
161  static AsyncTask::DoneStatus st_update_anim_controls(GenericAsyncTask *task, void *data);
162 
163  static void st_back_button(const Event *, void *data);
164  static void st_pause_button(const Event *, void *data);
165  static void st_play_button(const Event *, void *data);
166  static void st_forward_button(const Event *, void *data);
167 
168 private:
169  PandaFramework *_panda_framework;
170  PT(GraphicsOutput) _window;
171  PT(DisplayRegion) _display_region_2d;
172  PT(DisplayRegion) _display_region_3d;
173 
174  NodePath _camera_group;
176  Cameras _cameras;
177 
178  NodePath _render;
179  NodePath _render_2d;
180  NodePath _aspect_2d;
181  NodePath _pixel_2d;
182 
183  AnimControlCollection _anim_controls;
184  bool _anim_controls_enabled;
185  int _anim_index;
186  NodePath _anim_controls_group;
187  PT(PGSliderBar) _anim_slider;
188  PT(PGSliderBar) _play_rate_slider;
189  PT(TextNode) _frame_number;
190  PT(GenericAsyncTask) _update_anim_controls_task;
191 
192  NodePath _mouse;
193  NodePath _button_thrower;
194  PT(Trackball) _trackball;
195 
196  NodePath _alight;
197  NodePath _dlight;
198 
199  bool _got_keyboard;
200  bool _got_trackball;
201  bool _got_lights;
202 
203  bool _wireframe_enabled;
204  bool _wireframe_filled;
205  bool _texture_enabled;
206  bool _two_sided_enabled;
207  bool _one_sided_reverse_enabled;
208  bool _lighting_enabled;
209  bool _perpixel_enabled;
210 
211  PT(FrameRateMeter) _frame_rate_meter;
212  PT(SceneGraphAnalyzerMeter) _scene_graph_analyzer_meter;
213 
214  BackgroundType _background_type;
215 
216  static PT(TextFont) _shuttle_controls_font;
217 
218 public:
219  static TypeHandle get_class_type() {
220  return _type_handle;
221  }
222  static void init_type() {
223  TypedWritableReferenceCount::init_type();
224  register_type(_type_handle, "WindowFramework",
225  TypedWritableReferenceCount::get_class_type());
226  }
227  virtual TypeHandle get_type() const {
228  return get_class_type();
229  }
230  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
231 
232 private:
233  static TypeHandle _type_handle;
234 
235  friend class PandaFramework;
236 };
237 
238 #include "windowFramework.I"
239 
240 #endif
static const FrameBufferProperties & get_default()
Returns a FrameBufferProperties structure with all of the default values filled in according to the u...
A light shining from infinitely far away in a particular direction, like sunlight.
A basic node of the scene graph or data graph.
Definition: pandaNode.h:72
This is a special TextNode that automatically updates itself with output from a SceneGraphAnalyzer in...
This encapsulates the data that is normally associated with a single window, or with a single display...
Trackball acts like Performer in trackball mode.
Definition: trackball.h:40
A light source that seems to illuminate all points in space at once.
Definition: ambientLight.h:29
A window, fullscreen or on a desktop, into which a graphics device sends its output for interactive d...
An encapsulation of a font; i.e.
Definition: textFont.h:36
A container for the various kinds of properties we might ask to have on a graphics window before we o...
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:44
This is a named collection of AnimControl pointers.
An object to create GraphicsOutputs that share a particular 3-D API.
Definition: graphicsPipe.h:58
Associates a generic C-style function pointer with an AsyncTask object.
A base class for things which need to inherit from both TypedWritable and from ReferenceCount.
This is a base class for the various different classes that represent the result of a frame of render...
A named event, possibly with parameters.
Definition: event.h:36
The primary interface to this module.
Definition: textNode.h:52
Encapsulates all the communication with a particular instance of a given rendering backend...
This is a special TextNode that automatically updates itself with the current frame rate...
A rectangular subregion within a window for rendering into.
Definition: displayRegion.h:61
This class serves to provide a high-level framework for basic applications that use Panda in simple w...
This class is the main interface to controlling the render process.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
A container for the various kinds of properties we might ask to have on a graphics frameBuffer before...
A node that can be positioned around in the scene graph to represent a point of view for rendering a ...
Definition: camera.h:37
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
Definition: nodePath.h:165
This is a particular kind of PGItem that draws a little bar with a slider that moves from left to rig...
Definition: pgSliderBar.h:34