Panda3D
Loading...
Searching...
No Matches
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"
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
37class PandaFramework;
38class AmbientLight;
40class GraphicsEngine;
41class GraphicsPipe;
42class 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 */
51class EXPCL_FRAMEWORK WindowFramework : public TypedWritableReferenceCount {
52protected:
53 WindowFramework(PandaFramework *panda_framework);
54 WindowFramework(const WindowFramework &copy, DisplayRegion *display_region);
55
56public:
57 virtual ~WindowFramework();
58
59protected:
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
67public:
68 INLINE PandaFramework *get_panda_framework() const;
69 INLINE GraphicsWindow *get_graphics_window() const;
70 INLINE GraphicsOutput *get_graphics_output() const;
72
73 INLINE int get_num_cameras() const;
74 INLINE Camera *get_camera(int n) const;
75
78
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);
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
140
141protected:
142 void setup_lights();
143
144private:
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
164private:
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
214public:
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
228private:
229 static TypeHandle _type_handle;
230
231 friend class PandaFramework;
232};
233
234#include "windowFramework.I"
235
236#endif
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.
This is a named collection of AnimControl pointers.
A node that can be positioned around in the scene graph to represent a point of view for rendering a ...
Definition camera.h:35
A light shining from infinitely far away in a particular direction, like sunlight.
A rectangular subregion within a window for rendering into.
A named event, possibly with parameters.
Definition event.h:33
The name of a file, such as a texture file or an Egg file.
Definition filename.h:44
A container for the various kinds of properties we might ask to have on a graphics frameBuffer before...
static const FrameBufferProperties & get_default()
Returns a FrameBufferProperties structure with all of the default values filled in according to the u...
This is a special TextNode that automatically updates itself with the current frame rate.
Associates a generic C-style function pointer with an AsyncTask object.
This class is the main interface to controlling the render process.
This is a base class for the various different classes that represent the result of a frame of render...
An object to create GraphicsOutputs that share a particular 3-D API.
Encapsulates all the communication with a particular instance of a given rendering backend.
A window, fullscreen or on a desktop, into which a graphics device sends its output for interactive d...
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
Definition nodePath.h:159
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
This class serves to provide a high-level framework for basic applications that use Panda in simple w...
A basic node of the scene graph or data graph.
Definition pandaNode.h:65
This is a special TextNode that automatically updates itself with output from a SceneGraphAnalyzer in...
An encapsulation of a font; i.e.
Definition textFont.h:32
The primary interface to this module.
Definition textNode.h:48
Trackball acts like Performer in trackball mode.
Definition trackball.h:35
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
void set_wireframe(bool enable, bool filled=false)
Forces wireframe state (true) or restores default rendering (false).
NodePath make_camera()
Makes a new 3-d camera for the window.
NodePath load_default_model(const NodePath &parent)
Loads our favorite blue triangle.
void setup_trackball()
Sets up the mouse to trackball around the camera.
NodePath get_aspect_2d()
Returns the node under the 2-d scene graph that is scaled to suit the window's aspect ratio.
WindowFramework * split_window(SplitType split_type=ST_default)
Divides the window into two display regions, each of which gets its own trackball and keyboard events...
bool get_lighting() const
Returns the current state of the lighting flag.
bool get_wireframe() const
Returns the current state of the wireframe flag.
void stagger_animations()
Walks through all the animations that were bound by loop_animations() and staggers their play rate sl...
int get_num_cameras() const
Returns the number of 3-d cameras associated with the window.
NodePath get_button_thrower()
Returns the node in the data graph corresponding to the ButtonThrower object associated with this win...
bool get_texture() const
Returns the current state of the texture flag.
void set_one_sided_reverse(bool enable)
Toggles one-sided reverse mode.
NodePath get_render_2d()
Returns the root of the 2-d scene graph.
DisplayRegion * get_display_region_3d() const
Returns the default DisplayRegion created for the 3-d scene (render).
BackgroundType get_background_type() const
Returns the current background type setting.
void loop_animations(int hierarchy_match_flags=PartGroup::HMF_ok_part_extra|PartGroup::HMF_ok_anim_extra)
Looks for characters and their matching animation files in the scene graph; binds and loops any match...
void set_two_sided(bool enable)
Forces two-sided rendering (true) or restores default rendering (false).
bool get_one_sided_reverse() const
Returns the current state of the one_sided_reverse flag.
void set_texture(bool enable)
Forces textures off (false) or restores default rendering (true).
void next_anim_control()
Rotates the animation controls through all of the available animations.
bool get_two_sided() const
Returns the current state of the two_sided flag.
void enable_keyboard()
Creates a ButtonThrower to listen to button presses and throw them as events.
NodePath get_render()
Returns the root of the 3-d scene graph.
void center_trackball(const NodePath &object)
Centers the trackball on the indicated object, and scales the trackball motion suitably.
NodePath get_mouse()
Returns the node in the data graph corresponding to the mouse associated with this window.
bool get_anim_controls() const
Returns the current state of the anim_controls flag.
void set_anim_controls(bool enable)
Creates an onscreen animation slider for frame-stepping through the animations.
PandaFramework * get_panda_framework() const
Returns a pointer to the associated PandaFramework object.
void adjust_dimensions()
Reevaluates the dimensions of the window, presumably after the window has been resized by the user or...
Camera * get_camera(int n) const
Returns the nth camera associated with the window.
bool load_models(const NodePath &parent, int argc, char *argv[], int first_arg=1)
Loads up all the model files listed in the indicated argument list.
DisplayRegion * get_display_region_2d() const
Returns the default DisplayRegion created for the 2-d scene (render2d).
NodePath get_camera_group()
Returns the node above the collection of 3-d cameras in the scene graph.
bool get_perpixel() const
Returns the current state of the perpixel flag.
void set_background_type(BackgroundType type)
Sets the background of the window to one of the pre-canned background types (or to BT_other,...
NodePath get_pixel_2d()
Returns a special root that uses units in pixels that are relative to the window.
bool get_wireframe_filled() const
Returns the current state of the wireframe_filled flag.
static TextFont * get_shuttle_controls_font()
Returns a font that contains the shuttle controls icons.
GraphicsWindow * get_graphics_window() const
Returns a pointer to the underlying GraphicsWindow object, if it is in fact a window; or NULL if it i...
void set_lighting(bool enable)
Turns lighting on (true) or off (false).
void set_perpixel(bool enable)
Turns per-pixel lighting on (true) or off (false).
NodePath load_model(const NodePath &parent, Filename filename)
Loads up the indicated model and returns the new NodePath, or the empty NodePath if the model could n...
GraphicsOutput * get_graphics_output() const
Returns a pointer to the underlying GraphicsOutput object.
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.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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(),...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.