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