Panda3D
Loading...
Searching...
No Matches
showBase.cxx
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 showBase.cxx
10 * @author shochet
11 * @date 2000-02-02
12 */
13
14#ifdef __APPLE__
15// We have to include this before we include any Panda libraries, because one
16// of the things we pick up in Panda defines a macro for TCP_NODELAY and
17// friends, causing heartaches for the header files picked up here.
18#include <Carbon/Carbon.h>
19extern "C" { void CPSEnableForegroundOperation(ProcessSerialNumber* psn); }
20#endif
21
22#include "showBase.h"
23
24#include "throw_event.h"
25#include "graphicsWindow.h"
26#include "renderBuffer.h"
27#include "camera.h"
29
30#ifdef WIN32
31#include <windows.h> // For SystemParametersInfo()
32STICKYKEYS g_StartupStickyKeys = {sizeof(STICKYKEYS), 0};
33TOGGLEKEYS g_StartupToggleKeys = {sizeof(TOGGLEKEYS), 0};
34FILTERKEYS g_StartupFilterKeys = {sizeof(FILTERKEYS), 0};
35#endif
36
37using std::max;
38using std::min;
39
40#if !defined(CPPPARSER) && !defined(LINK_ALL_STATIC) && !defined(BUILDING_DIRECT_SHOWBASE)
41 #error Buildsystem error: BUILDING_DIRECT_SHOWBASE not defined
42#endif
43
44ConfigureDef(config_showbase);
45ConfigureFn(config_showbase) {
46}
47
48ConfigVariableSearchPath particle_path
49("particle-path",
50 PRC_DESC("The directories to search for particle files to be loaded."));
51
53get_particle_path() {
54 return particle_path;
55}
56
57// Throw the "NewFrame" event in the C++ world. Some of the lerp code depends
58// on receiving this.
59void
60throw_new_frame() {
61 throw_event("NewFrame");
62}
63
64// Initialize the application for making a Gui-based app, such as wx. At the
65// moment, this is a no-op except on Mac.
66void
67init_app_for_gui() {
68#ifdef IS_OSX
69 // Rudely bring the application to the foreground. This is particularly
70 // important when running wx via the plugin, since the plugin app is seen as
71 // separate from the browser app, even though the user sees them as the same
72 // thing. We need to bring the plugin app to the foreground to make its wx
73 // windows visible.
74 activate_osx_application();
75#endif
76
77 // We don't appear need to do the following, however, if we launch the
78 // plugin correctly from its own bundle.
79 /*
80 static bool initted_for_gui = false;
81 if (!initted_for_gui) {
82 initted_for_gui = true;
83#ifdef IS_OSX
84 ProcessSerialNumber psn;
85
86 GetCurrentProcess(&psn);
87 CPSEnableForegroundOperation(&psn);
88 SetFrontProcess(&psn);
89#endif // IS_OSX
90 }
91 */
92}
93
94// klunky interface since we cant pass array from python->C++ to use
95// verify_window_sizes directly
96static int num_fullscreen_testsizes = 0;
97#define MAX_FULLSCREEN_TESTS 10
98static int fullscreen_testsizes[MAX_FULLSCREEN_TESTS * 2];
99
100void
101add_fullscreen_testsize(int xsize, int ysize) {
102 if ((xsize == 0) && (ysize == 0)) {
103 num_fullscreen_testsizes = 0;
104 return;
105 }
106
107 // silently fail if maxtests exceeded
108 if (num_fullscreen_testsizes < MAX_FULLSCREEN_TESTS) {
109 fullscreen_testsizes[num_fullscreen_testsizes * 2] = xsize;
110 fullscreen_testsizes[num_fullscreen_testsizes * 2 + 1] = ysize;
111 num_fullscreen_testsizes++;
112 }
113}
114
115void
116runtest_fullscreen_sizes(GraphicsWindow *win) {
117 win->verify_window_sizes(num_fullscreen_testsizes, fullscreen_testsizes);
118}
119
120bool
121query_fullscreen_testresult(int xsize, int ysize) {
122 // stupid linear search that works ok as long as total tests are small
123 int i;
124 for (i=0; i < num_fullscreen_testsizes; i++) {
125 if((fullscreen_testsizes[i * 2] == xsize) &&
126 (fullscreen_testsizes[i * 2 + 1] == ysize))
127 return true;
128 }
129 return false;
130}
131
132void
133store_accessibility_shortcut_keys() {
134#ifdef WIN32
135 SystemParametersInfo(SPI_GETSTICKYKEYS, sizeof(STICKYKEYS), &g_StartupStickyKeys, 0);
136 SystemParametersInfo(SPI_GETTOGGLEKEYS, sizeof(TOGGLEKEYS), &g_StartupToggleKeys, 0);
137 SystemParametersInfo(SPI_GETFILTERKEYS, sizeof(FILTERKEYS), &g_StartupFilterKeys, 0);
138#endif
139}
140
141void
142allow_accessibility_shortcut_keys(bool allowKeys) {
143#ifdef WIN32
144 if( allowKeys )
145 {
146 // Restore StickyKeysetc to original state and enable Windows key
147 SystemParametersInfo(SPI_SETSTICKYKEYS, sizeof(STICKYKEYS), &g_StartupStickyKeys, 0);
148 SystemParametersInfo(SPI_SETTOGGLEKEYS, sizeof(TOGGLEKEYS), &g_StartupToggleKeys, 0);
149 SystemParametersInfo(SPI_SETFILTERKEYS, sizeof(FILTERKEYS), &g_StartupFilterKeys, 0);
150 } else {
151 // Disable StickyKeysetc shortcuts but if the accessibility feature is on,
152 // then leave the settings alone as its probably being usefully used
153
154 STICKYKEYS skOff = g_StartupStickyKeys;
155 if( (skOff.dwFlags & SKF_STICKYKEYSON) == 0 )
156 {
157 // Disable the hotkey and the confirmation
158 skOff.dwFlags &= ~SKF_HOTKEYACTIVE;
159 skOff.dwFlags &= ~SKF_CONFIRMHOTKEY;
160
161 SystemParametersInfo(SPI_SETSTICKYKEYS, sizeof(STICKYKEYS), &skOff, 0);
162 }
163
164 TOGGLEKEYS tkOff = g_StartupToggleKeys;
165 if( (tkOff.dwFlags & TKF_TOGGLEKEYSON) == 0 )
166 {
167 // Disable the hotkey and the confirmation
168 tkOff.dwFlags &= ~TKF_HOTKEYACTIVE;
169 tkOff.dwFlags &= ~TKF_CONFIRMHOTKEY;
170
171 SystemParametersInfo(SPI_SETTOGGLEKEYS, sizeof(TOGGLEKEYS), &tkOff, 0);
172 }
173
174 FILTERKEYS fkOff = g_StartupFilterKeys;
175 if( (fkOff.dwFlags & FKF_FILTERKEYSON) == 0 )
176 {
177 // Disable the hotkey and the confirmation
178 fkOff.dwFlags &= ~FKF_HOTKEYACTIVE;
179 fkOff.dwFlags &= ~FKF_CONFIRMHOTKEY;
180
181 SystemParametersInfo(SPI_SETFILTERKEYS, sizeof(FILTERKEYS), &fkOff, 0);
182 }
183 }
184#endif
185}
186
187#if 0
188int TempGridZoneManager::
189add_grid_zone(unsigned int x,
190 unsigned int y,
191 unsigned int width,
192 unsigned int height,
193 unsigned int zoneBase,
194 unsigned int xZoneResolution,
195 unsigned int yZoneResolution) {
196 // zoneBase is the first zone in the grid (e.g. the upper left)
197 // zoneResolution is the number of cells on each axsis. returns the next
198 // available zoneBase (i.e. zoneBase+xZoneResolution*yZoneResolution)
199 std::cerr<<"adding grid zone with a zoneBase of "<<zoneBase<<" and a zoneResolution of "<<zoneResolution;
200 _grids.append(TempGridZoneManager::GridZone(x, y, width, height, zoneBase, xZoneResolution, yZoneResolution));
201 return zoneBase+xZoneResolution*yZoneResolution;
202}
203
204void TempGridZoneManager::GridZone
205GridZone(unsigned int x,
206 unsigned int y,
207 unsigned int width,
208 unsigned int height,
209 unsigned int zoneBase,
210 unsigned int xZoneResolution,
211 unsigned int yZoneResolution) {
212 _x=x;
213 _y=y;
214 _width=width;
215 _height=heigth;
216 _zoneBase=zoneBase;
217 _xZoneResolution=xZoneResolution;
218 _yZoneResolution=yZoneResolution;
219
220 // The cellVis is the number of cells radius that can be seen, including the
221 // center cell. So, for a 5 x 5 visible area, the cellVis is 3.
222 const float cellVis=3.0;
223 unsigned int xMargine=(unsigned int)((float)width/(float)xZoneResolution*cellVis+0.5);
224 unsigned int yMargine=(unsigned int)((float)height/(float)yZoneResolution*cellVis+0.5);
225 _xMinVis=x-xMargine;
226 _yMinVis=y-yMargine;
227 _xMaxVis=x+width+xMargine;
228 _yMaxVis=y+height+yMargine;
229}
230
231void TempGridZoneManager::
232get_grids(int x, int y) {
233 TempGridZoneManager::ZoneSet canSee;
234 TempGridZoneManager::GridSet::const_iterator i=_grids.begin();
235 for (; i!=_grids.end(); ++i) {
236 if (x >= i._xMinVis && x < i._xMaxVis && y >= i._yMinVis && y < i._yMaxVis) {
237 add_to_zone_list(i, x, y, canSee);
238 }
239 }
240}
241
242void TempGridZoneManager::
243add_to_zone_list(const TempGridZoneManager::GridZone &gridZone,
244 unsigned int x,
245 unsigned int y,
246 TempGridZoneManager::ZoneSet &zoneSet) {
247 unsigned int xRes=gridZone._xZoneResolution;
248 unsigned int yRes=gridZone._yZoneResolution;
249 float xP=((float)(x-gridZone._x))/gridZone._width;
250 float yP=((float)(y-gridZone._y))/gridZone._height;
251 int xCell=(int)(xP*xRes);
252 int yCell=(int)(yP*yRes);
253
254 // range is how many cells can be seen in each direction:
255 const int range=2;
256 int yBegin=max(0, yCell-range);
257 int yEnd=min(yRes, yCell+range);
258 int xBegin=max(0, xCell-range);
259 int xEnd=min(xRes, xCell+range);
260 unsigned int zone=gridZone._zoneBase+yBegin*xRes+xBegin;
261
262 for (yCell=yBegin; yCell < yEnd; ++yCell) {
263 for (xCell=xBegin; xCell < xEnd; ++xCell) {
264 zoneSet.append(zone+xCell);
265 }
266 zone+=xRes;
267 }
268}
269
270int TempGridZoneManager::
271get_zone_list(int x, int y, int resolution) {
272 // x is a float in the range 0.0 to 1.0 y is a float in the range 0.0 to 1.0
273 // resolution is the number of cells on each axsis. returns a list of zone
274 // ids. Create a box of cell numbers, while clipping to the edges of the
275 // set of cells.
276 if (x < 0.0 || x > 1.0 || y < 0.0 || y > 1.0) {
277 return 0;
278 }
279 std::cerr<<"resolution="<<resolution;
280 xCell=min(int(x*resolution), resolution-1)
281 yCell=min(int(y*resolution), resolution-1)
282 cell=yCell*resolution+xCell
283 print "cell", cell,
284 zone=zoneBase+cell
285 print "zone", zone
286
287 zone=zone-2*resolution
288 endZone=zone+5*resolution
289 yCell=yCell-2
290 while zone < endZone:
291 if yCell >= 0 and yCell < resolution:
292 if xCell > 1:
293 zoneList.append(zone-2)
294 zoneList.append(zone-1)
295 elif xCell > 0:
296 zoneList.append(zone-1)
297 r.append(zone)
298 if xCell < resolution-2:
299 zoneList.append(zone+1)
300 zoneList.append(zone+2)
301 elif xCell < resolution-1:
302 zoneList.append(zone+1)
303 yCell+=1
304 zone+=resolution
305 return zoneList
306 return 5;
307}
308#endif
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is similar to a ConfigVariableList, but it returns its list as a DSearchPath,...
A window, fullscreen or on a desktop, into which a graphics device sends its output for interactive d...
virtual int verify_window_sizes(int numsizes, int *dimen)
Determines which of the indicated window sizes are supported by available hardware (e....
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.