mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-04 10:54:24 -04:00
better osx window resizing
This commit is contained in:
parent
b9a108f9cd
commit
2df2142906
@ -586,6 +586,8 @@ set_properties_now(WindowProperties &properties) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
properties.clear_open();
|
||||||
|
|
||||||
// The window is already open; we are limited to what we can change
|
// The window is already open; we are limited to what we can change
|
||||||
// on the fly.
|
// on the fly.
|
||||||
|
|
||||||
@ -618,12 +620,12 @@ set_properties_now(WindowProperties &properties) {
|
|||||||
if (do_reshape_request(x_origin, y_origin, has_origin,
|
if (do_reshape_request(x_origin, y_origin, has_origin,
|
||||||
reshape_props.get_x_size(),
|
reshape_props.get_x_size(),
|
||||||
reshape_props.get_y_size())) {
|
reshape_props.get_y_size())) {
|
||||||
system_changed_size(reshape_props.get_x_size(),
|
|
||||||
reshape_props.get_y_size());
|
|
||||||
_properties.add_properties(reshape_props);
|
|
||||||
properties.clear_size();
|
properties.clear_size();
|
||||||
properties.clear_origin();
|
properties.clear_origin();
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
properties.clear_size();
|
||||||
|
properties.clear_origin();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -729,8 +731,8 @@ system_changed_size(int x_size, int y_size) {
|
|||||||
<< "system_changed_size(" << x_size << ", " << y_size << ")\n";
|
<< "system_changed_size(" << x_size << ", " << y_size << ")\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (x_size != _properties.get_x_size() ||
|
if (!_properties.has_size() || (x_size != _properties.get_x_size() ||
|
||||||
y_size != _properties.get_y_size()) {
|
y_size != _properties.get_y_size())) {
|
||||||
set_size_and_recalc(x_size, y_size);
|
set_size_and_recalc(x_size, y_size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -745,7 +745,6 @@ extern OSErr CPSSetFrontProcess( struct CPSProcessSerNum *psn);
|
|||||||
bool osxGraphicsWindow::open_window()
|
bool osxGraphicsWindow::open_window()
|
||||||
{
|
{
|
||||||
WindowProperties req_properties = _properties;
|
WindowProperties req_properties = _properties;
|
||||||
_properties.clear();
|
|
||||||
|
|
||||||
if (_gsg == 0) {
|
if (_gsg == 0) {
|
||||||
_gsg = new osxGraphicsStateGuardian(_pipe, NULL);
|
_gsg = new osxGraphicsStateGuardian(_pipe, NULL);
|
||||||
@ -794,7 +793,7 @@ bool osxGraphicsWindow::OSOpenWindow(WindowProperties &req_properties )
|
|||||||
if(req_properties.has_title())
|
if(req_properties.has_title())
|
||||||
{
|
{
|
||||||
err = CPSSetProcessName(&PSN,(char *)req_properties.get_title().c_str());
|
err = CPSSetProcessName(&PSN,(char *)req_properties.get_title().c_str());
|
||||||
//_properties.set_title(req_properties.get_title());
|
//_properties.set_title(req_properties.get_title());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
err = CPSSetProcessName(&PSN,"");
|
err = CPSSetProcessName(&PSN,"");
|
||||||
@ -807,32 +806,7 @@ bool osxGraphicsWindow::OSOpenWindow(WindowProperties &req_properties )
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if(req_properties.has_fullscreen() && req_properties.get_fullscreen())
|
||||||
Rect r;
|
|
||||||
if(req_properties.has_origin())
|
|
||||||
{
|
|
||||||
r.top = req_properties.get_y_origin();
|
|
||||||
r.left =req_properties.get_x_origin();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
r.top = 50;
|
|
||||||
r.left = 10;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(req_properties.has_size())
|
|
||||||
{
|
|
||||||
r.right = r.left + req_properties.get_x_size();
|
|
||||||
r.bottom = r.top + req_properties.get_y_size();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
r.right = r.left + 512;
|
|
||||||
r.bottom = r.top + 512;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if(req_properties.has_fullscreen() && req_properties.get_fullscreen() == true)
|
|
||||||
{
|
{
|
||||||
// if(FullScreenWindow != NULL)
|
// if(FullScreenWindow != NULL)
|
||||||
// return false;
|
// return false;
|
||||||
@ -843,9 +817,28 @@ bool osxGraphicsWindow::OSOpenWindow(WindowProperties &req_properties )
|
|||||||
if(req_properties.has_size())
|
if(req_properties.has_size())
|
||||||
{
|
{
|
||||||
_originalMode = CGDisplayCurrentMode( kCGDirectMainDisplay );
|
_originalMode = CGDisplayCurrentMode( kCGDirectMainDisplay );
|
||||||
CGDisplaySwitchToMode( kCGDirectMainDisplay,
|
CFDictionaryRef newMode = CGDisplayBestModeForParameters( kCGDirectMainDisplay, 32, req_properties.get_x_size(), req_properties.get_y_size(), 0 );
|
||||||
CGDisplayBestModeForParameters( kCGDirectMainDisplay, 32, req_properties.get_x_size(), req_properties.get_y_size(), 0 ) );
|
if (newMode == NULL) {
|
||||||
|
osxdisplay_cat.error()
|
||||||
|
<< "Invalid fullscreen size: " << req_properties.get_x_size()
|
||||||
|
<< ", " << req_properties.get_y_size()
|
||||||
|
<< "\n";
|
||||||
|
|
||||||
|
} else {
|
||||||
|
CGDisplaySwitchToMode( kCGDirectMainDisplay, newMode);
|
||||||
|
|
||||||
|
// Set our new window size according to the size we actually got.
|
||||||
|
|
||||||
|
SInt32 width, height;
|
||||||
|
CFNumberGetValue((CFNumberRef)CFDictionaryGetValue(newMode, kCGDisplayWidth),
|
||||||
|
kCFNumberSInt32Type,
|
||||||
|
&width);
|
||||||
|
CFNumberGetValue((CFNumberRef)CFDictionaryGetValue(newMode, kCGDisplayHeight),
|
||||||
|
kCFNumberSInt32Type,
|
||||||
|
&height);
|
||||||
|
|
||||||
|
_properties.set_size(width, height);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -868,48 +861,100 @@ bool osxGraphicsWindow::OSOpenWindow(WindowProperties &req_properties )
|
|||||||
// if (!aglSetInteger (get_context(), AGL_SWAP_INTERVAL, &swap))
|
// if (!aglSetInteger (get_context(), AGL_SWAP_INTERVAL, &swap))
|
||||||
// aglReportError ();
|
// aglReportError ();
|
||||||
|
|
||||||
_properties.set_fullscreen(true);
|
_properties.set_fullscreen(true);
|
||||||
|
|
||||||
_is_fullsreen =true;
|
_is_fullsreen =true;
|
||||||
FullScreenWindow = this;
|
FullScreenWindow = this;
|
||||||
req_properties.clear_fullscreen();
|
req_properties.clear_fullscreen();
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
// lets use this as a crome based window..
|
||||||
|
Rect r;
|
||||||
|
if(req_properties.has_origin())
|
||||||
|
{
|
||||||
|
r.top = req_properties.get_y_origin();
|
||||||
|
r.left =req_properties.get_x_origin();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
r.top = 50;
|
||||||
|
r.left = 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(req_properties.has_size())
|
||||||
|
{
|
||||||
|
r.right = r.left + req_properties.get_x_size();
|
||||||
|
r.bottom = r.top + req_properties.get_y_size();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
r.right = r.left + 512;
|
||||||
|
r.bottom = r.top + 512;
|
||||||
|
}
|
||||||
|
|
||||||
// lets use this as a crome based window..
|
if(req_properties.has_undecorated() && req_properties.get_undecorated())
|
||||||
|
{ // create a unmovable .. no edge window..
|
||||||
|
CreateNewWindow(//
|
||||||
|
kDocumentWindowClass,
|
||||||
|
kWindowStandardDocumentAttributes | kWindowNoTitleBarAttribute,
|
||||||
|
&r,
|
||||||
|
&_osx_window);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{ // create a window with crome and sizing and sucj
|
||||||
|
|
||||||
|
// In this case, we want to constrain the window to the
|
||||||
|
// available size.
|
||||||
|
Rect bounds;
|
||||||
|
GetAvailableWindowPositioningBounds(GetMainDevice(), &bounds);
|
||||||
|
|
||||||
if( !req_properties.has_undecorated() || req_properties.get_undecorated() == false)
|
r.left = max(r.left, bounds.left);
|
||||||
{ // create a window with crome and sizing and sucj
|
r.right = min(r.right, bounds.right);
|
||||||
CreateNewWindow(//
|
r.top = max(r.top, bounds.top);
|
||||||
kDocumentWindowClass,
|
r.bottom = min(r.bottom, bounds.bottom);
|
||||||
kWindowStandardDocumentAttributes | kWindowStandardHandlerAttribute,
|
|
||||||
&r,
|
|
||||||
&_osx_window);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{ // create a unmovable .. no edge window..
|
|
||||||
|
|
||||||
CreateNewWindow(//
|
CreateNewWindow(//
|
||||||
kDocumentWindowClass,
|
kDocumentWindowClass,
|
||||||
kWindowStandardDocumentAttributes | kWindowNoTitleBarAttribute,
|
kWindowStandardDocumentAttributes |
|
||||||
&r,
|
kWindowStandardHandlerAttribute,
|
||||||
&_osx_window);
|
&r,
|
||||||
}
|
&_osx_window);
|
||||||
|
}
|
||||||
|
|
||||||
if (_osx_window)
|
if (_osx_window)
|
||||||
{
|
{
|
||||||
EventHandlerUPP gWinEvtHandler; // window event handler
|
EventHandlerUPP gWinEvtHandler; // window event handler
|
||||||
//EventHandlerRef ref;
|
//EventHandlerRef ref;
|
||||||
EventTypeSpec list[] = {
|
EventTypeSpec list[] = {
|
||||||
{ kEventClassWindow, kEventWindowCollapsing },
|
{ kEventClassWindow, kEventWindowCollapsing },
|
||||||
{ kEventClassWindow, kEventWindowShown },
|
{ kEventClassWindow, kEventWindowShown },
|
||||||
{ kEventClassWindow, kEventWindowActivated },
|
{ kEventClassWindow, kEventWindowActivated },
|
||||||
{ kEventClassWindow, kEventWindowClose },
|
{ kEventClassWindow, kEventWindowDeactivated },
|
||||||
{ kEventClassWindow,kEventWindowBoundsChanged },
|
{ kEventClassWindow, kEventWindowClose },
|
||||||
|
{ kEventClassWindow, kEventWindowBoundsChanged },
|
||||||
|
|
||||||
|
{ kEventClassWindow, kEventWindowHidden },
|
||||||
|
{ kEventClassWindow, kEventWindowCollapsed },
|
||||||
|
{ kEventClassWindow, kEventWindowExpanded },
|
||||||
|
{ kEventClassWindow, kEventWindowZoomed },
|
||||||
|
//{ kEventClassWindow, kEventWindowDragStarted },
|
||||||
|
//{ kEventClassWindow, kEventWindowDragCompleted },
|
||||||
|
//{ kEventClassWindow, kEventWindowTransitionCompleted },
|
||||||
|
{ kEventClassWindow, kEventWindowClosed },
|
||||||
|
|
||||||
|
/*
|
||||||
|
{ kEventClassWindow, kEventWindowClickDragRgn },
|
||||||
|
{ kEventClassWindow, kEventWindowClickResizeRgn },
|
||||||
|
{ kEventClassWindow, kEventWindowClickCollapseRgn },
|
||||||
|
{ kEventClassWindow, kEventWindowClickCloseRgn },
|
||||||
|
{ kEventClassWindow, kEventWindowClickZoomRgn },
|
||||||
|
{ kEventClassWindow, kEventWindowClickContentRgn },
|
||||||
|
{ kEventClassWindow, kEventWindowClickProxyIconRgn },
|
||||||
|
{ kEventClassWindow, kEventWindowClickToolbarButtonRgn },
|
||||||
|
{ kEventClassWindow, kEventWindowClickStructureRgn },
|
||||||
|
*/
|
||||||
|
|
||||||
// { kEventClassMouse, kEventMouseDown },// handle trackball functionality globaly because there is only a single user
|
// { kEventClassMouse, kEventMouseDown },// handle trackball functionality globaly because there is only a single user
|
||||||
// { kEventClassMouse, kEventMouseUp },
|
// { kEventClassMouse, kEventMouseUp },
|
||||||
@ -973,38 +1018,24 @@ bool osxGraphicsWindow::OSOpenWindow(WindowProperties &req_properties )
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Now measure the size and placement of the window we
|
||||||
|
// actually ended up with.
|
||||||
|
Rect rectPort = {0,0,0,0};
|
||||||
|
GetWindowPortBounds (_osx_window, &rectPort);
|
||||||
|
_properties.set_size((int)(rectPort.right - rectPort.left),(int) (rectPort.bottom - rectPort.top));
|
||||||
|
req_properties.clear_size();
|
||||||
|
req_properties.clear_origin();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//
|
|
||||||
// pull the size from the real window .. do not trust the requested values?f
|
|
||||||
// WindowProperties properties;
|
|
||||||
|
|
||||||
_properties.set_foreground(true);
|
_properties.set_foreground(true);
|
||||||
_properties.set_minimized(false);
|
_properties.set_minimized(false);
|
||||||
_properties.set_open(true);
|
_properties.set_open(true);
|
||||||
Rect rectPort = {0,0,0,0};
|
|
||||||
if(_is_fullsreen)
|
|
||||||
{
|
|
||||||
CGDirectDisplayID display = CGMainDisplayID ();
|
|
||||||
|
|
||||||
// if (osxdisplay_cat.is_debug())
|
if (_properties.has_size()) {
|
||||||
osxdisplay_cat.debug() << "Full Screen Size ["<< CGDisplayPixelsWide (display) <<","<< CGDisplayPixelsHigh (display) << "]\n";
|
set_size_and_recalc(_properties.get_x_size(),
|
||||||
// _properties.set_size((int)800,(int) 600);
|
_properties.get_y_size());
|
||||||
_properties.set_size((int)CGDisplayPixelsWide (display),(int) CGDisplayPixelsHigh (display));
|
|
||||||
_properties.set_origin((int) 0,(int)0);
|
|
||||||
req_properties.clear_size();
|
|
||||||
req_properties.clear_origin();
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
GetWindowPortBounds (_osx_window, &rectPort);
|
|
||||||
_properties.set_size((int)(rectPort.right - rectPort.left),(int) (rectPort.bottom - rectPort.top));
|
|
||||||
_properties.set_origin((int) rectPort.left,(int)rectPort.top);
|
|
||||||
req_properties.clear_size();
|
|
||||||
req_properties.clear_origin();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// cerr << " Generate Output Properties "<< _properties <<"\n";
|
// cerr << " Generate Output Properties "<< _properties <<"\n";
|
||||||
|
|
||||||
@ -1408,7 +1439,19 @@ bool osxGraphicsWindow::do_reshape_request(int x_origin, int y_origin, bool has_
|
|||||||
MoveWindow(_osx_window, x_origin, y_origin, false);
|
MoveWindow(_osx_window, x_origin, y_origin, false);
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
if (!_properties.get_undecorated()) {
|
||||||
|
// Constrain the window to the available desktop size.
|
||||||
|
Rect bounds;
|
||||||
|
GetAvailableWindowPositioningBounds(GetMainDevice(), &bounds);
|
||||||
|
|
||||||
|
x_size = min(x_size, bounds.right - bounds.left);
|
||||||
|
y_size = min(y_size, bounds.bottom - bounds.top);
|
||||||
|
}
|
||||||
|
|
||||||
SizeWindow(_osx_window, x_size, y_size, false);
|
SizeWindow(_osx_window, x_size, y_size, false);
|
||||||
|
|
||||||
|
system_changed_size(x_size, y_size);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1503,16 +1546,10 @@ void osxGraphicsWindow::set_properties_now(WindowProperties &properties)
|
|||||||
// new allowed to overwrite the old states. and start a bootstrap
|
// new allowed to overwrite the old states. and start a bootstrap
|
||||||
// of a new window ..
|
// of a new window ..
|
||||||
|
|
||||||
if (properties.has_size()) {
|
|
||||||
// Make sure the DisplayRegions, etc., will be updated.
|
|
||||||
system_changed_size(properties.get_x_size(), properties.get_y_size());
|
|
||||||
}
|
|
||||||
|
|
||||||
// get a copy of my properties..
|
// get a copy of my properties..
|
||||||
WindowProperties req_properties(_properties);
|
WindowProperties req_properties(_properties);
|
||||||
// cerr<< "-------------------------------------Lets Go Full Rebuild Request=[" <<properties <<"]\n";
|
// cerr<< "-------------------------------------Lets Go Full Rebuild Request=[" <<properties <<"]\n";
|
||||||
ReleaseSystemResources();
|
ReleaseSystemResources();
|
||||||
_properties.clear();
|
|
||||||
req_properties.add_properties(properties);
|
req_properties.add_properties(properties);
|
||||||
|
|
||||||
OSOpenWindow(req_properties);
|
OSOpenWindow(req_properties);
|
||||||
|
@ -606,10 +606,6 @@ do_reshape_request(int x_origin, int y_origin, bool has_origin,
|
|||||||
view_rect.bottom - view_rect.top,
|
view_rect.bottom - view_rect.top,
|
||||||
flags);
|
flags);
|
||||||
|
|
||||||
// This isn't quite right, because handle_reshape() calls
|
|
||||||
// system_changed_properties(), generating the event indicating
|
|
||||||
// the window has changed size externally--even though it changed
|
|
||||||
// due to an internal request.
|
|
||||||
handle_reshape();
|
handle_reshape();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -699,6 +695,7 @@ do_fullscreen_resize(int x_size, int y_size) {
|
|||||||
<< " bitdepth " << dwFullScreenBitDepth << ", "
|
<< " bitdepth " << dwFullScreenBitDepth << ", "
|
||||||
<< dm.dmDisplayFrequency << "Hz\n";
|
<< dm.dmDisplayFrequency << "Hz\n";
|
||||||
|
|
||||||
|
system_changed_size(x_size, y_size);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user