From Stephan Huber and Robert Osfield,

Stephan: "attached you'll find some modifications to the GraphicsWindow-class and
their platform-dependant implementations.

The problem:
setWindowRectangle and setWindowDecoration do not update the
traits-object, so, if you call setWindowRectangle on a
not-realized-window it will open with another size when realized later.
getWindowRectangle reports possible wrong sizes if setWindowRectangle
called before.

My solution:
split the implementation in two parts:
GraphicsWindow::setWindowRectangle will update its traits-object and
call afterwards the virtual method setWindowRectangleImplementation
(which is implemented by the derived platformspecific classess). For
setWindowDecoration I am useing a similar mechanism.

I hope you'll find the submission useful, the Win32 and X11 changes are
not tested but should work."

Changes to this made by Robert are call of resized in setWindowRectangle 
instead of setting of Traits, and use of a bool return type.
This commit is contained in:
Robert Osfield
2007-06-10 19:53:18 +00:00
parent 43790b07b3
commit 08a793eb87
7 changed files with 82 additions and 25 deletions

View File

@@ -49,13 +49,32 @@ class OSGVIEWER_EXPORT GraphicsWindow : public osg::GraphicsContext, public osgG
virtual void checkEvents() {}
/** Set the window's position and size.*/
virtual void setWindowRectangle(int /*x*/, int /*y*/, int /*width*/, int /*height*/) { osg::notify(osg::NOTICE)<<"GraphicsWindow::setWindowRectangle(..) not implemented."<<std::endl; }
void setWindowRectangle(int x, int y, int width, int height)
{
if (setWindowRectangleImplementation(x ,y ,width, height) && _traits.valid())
{
resized(x,y,width,height);
}
}
/** implementation of setWindowRectangle, should be implemented by derived classes */
virtual bool setWindowRectangleImplementation(int /*x*/, int /*y*/, int /*width*/, int /*height*/) { osg::notify(osg::NOTICE)<<"GraphicsWindow::setWindowRectangleImplementation(..) not implemented."<<std::endl; return false; }
/** Get the window's position and size.*/
virtual void getWindowRectangle(int& x, int& y, int& width, int& height) { if (_traits.valid()) { x = _traits->x; y = _traits->y; width = _traits->width; height = _traits->height; } }
/** Set Window decoration.*/
virtual void setWindowDecoration(bool /*flag*/) { osg::notify(osg::NOTICE)<<"GraphicsWindow::setWindowDecoration(..) not implemented."<<std::endl; }
void setWindowDecoration(bool flag)
{
if (setWindowDecorationImplementation(flag) && _traits.valid())
{
_traits->windowDecoration = flag;
}
}
/** implementation of setWindowDecoration, should be implemented by derived classes */
virtual bool setWindowDecorationImplementation(bool /*flag*/) { osg::notify(osg::NOTICE)<<"GraphicsWindow::setWindowDecorationImplementation(..) not implemented."<<std::endl; return false; }
/** Set Window decoration.*/
virtual bool getWindowDecoration() const { return _traits.valid() ? _traits->windowDecoration : false; }

View File

@@ -82,10 +82,10 @@ class GraphicsWindowCarbon : public osgViewer::GraphicsWindow
virtual void checkEvents();
/** Set the window's position and size.*/
virtual void setWindowRectangle(int x, int y, int width, int height);
virtual bool setWindowRectangleImplementation(int x, int y, int width, int height);
/** Set Window decoration.*/
virtual void setWindowDecoration(bool flag);
virtual bool setWindowDecorationImplementation(bool flag);
/** Get focus.*/
virtual void grabFocus();

View File

@@ -61,10 +61,10 @@ class GraphicsWindowWin32 : public osgViewer::GraphicsWindow
virtual void checkEvents();
/** Set the window's position and size.*/
virtual void setWindowRectangle(int x, int y, int width, int height);
virtual bool setWindowRectangleImplementation(int x, int y, int width, int height);
/** Set Window decoration.*/
virtual void setWindowDecoration(bool flag);
virtual bool setWindowDecorationImplementation(bool flag);
/** Get focus.*/
virtual void grabFocus();

View File

@@ -92,7 +92,7 @@ class GraphicsWindowX11 : public osgViewer::GraphicsWindow
virtual void checkEvents();
/** Set Window decoration.*/
virtual void setWindowDecoration(bool flag);
virtual bool setWindowDecorationImplementation(bool flag);
/** Get focus.*/
virtual void grabFocus();
@@ -104,7 +104,7 @@ class GraphicsWindowX11 : public osgViewer::GraphicsWindow
virtual void requestWarpPointer(float x,float y);
/** Set the window's position and size.*/
virtual void setWindowRectangle(int x, int y, int width, int height);
virtual bool setWindowRectangleImplementation(int x, int y, int width, int height);
/** Set mouse cursor to a specific shape.*/
virtual void setCursor(MouseCursor cursor);

View File

@@ -611,25 +611,34 @@ void GraphicsWindowCarbon::init()
_initialized = true;
}
void GraphicsWindowCarbon::setWindowDecoration(bool flag)
bool GraphicsWindowCarbon::setWindowDecorationImplementation(bool flag)
{
_useWindowDecoration = flag;
if (_realized) {
if (_realized)
{
OSErr err = noErr;
Rect bounds;
GetWindowBounds(getNativeWindowRef(), kWindowContentRgn, &bounds);
if (_useWindowDecoration) {
if (_useWindowDecoration)
{
err = ChangeWindowAttributes(getNativeWindowRef(), kWindowStandardDocumentAttributes, kWindowNoTitleBarAttribute | kWindowNoShadowAttribute);
SetWindowBounds(getNativeWindowRef(), kWindowContentRgn, &bounds);
} else {
}
else
{
err = ChangeWindowAttributes(getNativeWindowRef(), kWindowNoTitleBarAttribute | kWindowNoShadowAttribute, kWindowStandardDocumentAttributes);
}
if (err != noErr) {
if (err != noErr)
{
osg::notify(osg::WARN) << "GraphicsWindowCarbon::setWindowDecoration failed with " << err << std::endl;
return false;
}
}
return true;
}
WindowAttributes GraphicsWindowCarbon::computeWindowAttributes(bool useWindowDecoration, bool supportsResize) {
@@ -1180,13 +1189,13 @@ void GraphicsWindowCarbon::checkEvents()
}
void GraphicsWindowCarbon::setWindowRectangle(int x, int y, int width, int height)
bool GraphicsWindowCarbon::setWindowRectangleImplementation(int x, int y, int width, int height)
{
Rect bounds = {y, x, y + height, x + width};
SetWindowBounds(getNativeWindowRef(), kWindowContentRgn, &bounds);
aglUpdateContext(_context);
MenubarController::instance()->update();
return true;
}
void GraphicsWindowCarbon::grabFocus()
@@ -1234,4 +1243,10 @@ struct RegisterWindowingSystemInterfaceProxy
RegisterWindowingSystemInterfaceProxy createWindowingSystemInterfaceProxy;
// declare C entry point for static compilation.
extern "C" void graphicswindow_Carbon(void)
{
osg::GraphicsContext::setWindowingSystemInterface(new osgViewer::OSXCarbonWindowingSystemInterface());
}
#endif

View File

@@ -1512,7 +1512,7 @@ bool GraphicsWindowWin32::setPixelFormat()
return true;
}
void GraphicsWindowWin32::setWindowDecoration( bool decorated )
bool GraphicsWindowWin32::setWindowDecorationImplementation( bool decorated )
{
unsigned int windowStyle;
unsigned int extendedStyle;
@@ -1527,7 +1527,7 @@ void GraphicsWindowWin32::setWindowDecoration( bool decorated )
if (!determineWindowPositionAndStyle(decorated, x, y, w, h, windowStyle, extendedStyle))
{
reportErrorForScreen("GraphicsWindowWin32::setWindowDecoration() - Unable to determine the window position and style", _traits->screenNum, 0);
return;
return false;
}
//
@@ -1540,7 +1540,7 @@ void GraphicsWindowWin32::setWindowDecoration( bool decorated )
if (result==0 && error)
{
reportErrorForScreen("GraphicsWindowWin32::setWindowDecoration() - Unable to set window style", _traits->screenNum, error);
return;
return false;
}
//
@@ -1553,7 +1553,7 @@ void GraphicsWindowWin32::setWindowDecoration( bool decorated )
if (result==0 && error)
{
reportErrorForScreen("GraphicsWindowWin32::setWindowDecoration() - Unable to set window extented style", _traits->screenNum, error);
return;
return false;
}
//
@@ -1563,7 +1563,7 @@ void GraphicsWindowWin32::setWindowDecoration( bool decorated )
if (!::SetWindowPos(_hwnd, HWND_TOP, x, y, w, h, SWP_FRAMECHANGED | SWP_NOZORDER | SWP_SHOWWINDOW))
{
reportErrorForScreen("GraphicsWindowWin32::setWindowDecoration() - Unable to set new window position and size", _traits->screenNum, ::GetLastError());
return;
return false;
}
//
@@ -1574,6 +1574,8 @@ void GraphicsWindowWin32::setWindowDecoration( bool decorated )
{
::InvalidateRect(NULL, NULL, TRUE);
}
return true;
}
bool GraphicsWindowWin32::realizeImplementation()
@@ -1760,12 +1762,14 @@ void GraphicsWindowWin32::requestWarpPointer( float x, float y )
getEventQueue()->mouseWarped(x,y);
}
void GraphicsWindowWin32::setWindowRectangle(int x, int y, int width, int height)
bool GraphicsWindowWin32::setWindowRectangleImplementation(int x, int y, int width, int height)
{
if (!::SetWindowPos(_hwnd, HWND_TOP, x, y, width, height, SWP_SHOWWINDOW | SWP_FRAMECHANGED))
{
reportErrorForScreen("GraphicsWindowWin32::setWindowRectangle() - Unable to set new window position and size", _traits->screenNum, ::GetLastError());
return false;
}
return true;
}
void GraphicsWindowWin32::useCursor( bool cursorOn )
@@ -2255,3 +2259,10 @@ struct RegisterWindowingSystemInterfaceProxy
static RegisterWindowingSystemInterfaceProxy createWindowingSystemInterfaceProxy;
}; // namespace OsgViewer
// declare C entry point for static compilation.
extern "C" void graphicswindow_Win32(void)
{
osg::GraphicsContext::setWindowingSystemInterface(osgViewer::Win32WindowingSystem::getInterface());
}

View File

@@ -292,7 +292,7 @@ bool GraphicsWindowX11::createVisualInfo()
return _visualInfo != 0;
}
void GraphicsWindowX11::setWindowDecoration(bool flag)
bool GraphicsWindowX11::setWindowDecorationImplementation(bool flag)
{
Display* display = getDisplayToUse();
@@ -361,15 +361,22 @@ void GraphicsWindowX11::setWindowDecoration(bool flag)
// we don't add this sleep then any X11 calls right afterwards can produce
// X11 errors.
usleep(100000);
return true;
}
else
{
osg::notify(osg::NOTICE)<<"Error: GraphicsWindowX11::setBorder(" << flag << ") - couldn't change decorations." << std::endl;
return false;
}
}
void GraphicsWindowX11::setWindowRectangle(int x, int y, int width, int height)
bool GraphicsWindowX11::setWindowRectangleImplementation(int x, int y, int width, int height)
{
if (!_realized) return;
if (!_realized) return false;
Display* display = getDisplayToUse();
@@ -382,6 +389,8 @@ void GraphicsWindowX11::setWindowRectangle(int x, int y, int width, int height)
// we don't add this sleep then any X11 calls right afterwards can produce
// X11 errors.
usleep(100000);
return true;
}
void GraphicsWindowX11::setCursor(MouseCursor mouseCursor)
@@ -1291,4 +1300,7 @@ struct RegisterWindowingSystemInterfaceProxy
RegisterWindowingSystemInterfaceProxy createWindowingSystemInterfaceProxy;
// declare C entry point for static compilation.
extern "C" void graphicswindow_X11(void) {}
extern "C" void graphicswindow_X11(void)
{
osg::GraphicsContext::setWindowingSystemInterface(new X11WindowingSystemInterface);
}