John's window positioning corrections.
git-svn-id: https://svn.code.sf.net/p/freeglut/code/trunk@62 7f0cb862-5218-0410-a997-914c9d46530a
This commit is contained in:
parent
ba2efda662
commit
d9ea879e8c
@ -212,10 +212,12 @@ int FGAPIENTRY glutGet( GLenum eWhat )
|
||||
*/
|
||||
case GLUT_WINDOW_X:
|
||||
case GLUT_WINDOW_Y:
|
||||
case GLUT_WINDOW_WIDTH:
|
||||
case GLUT_WINDOW_HEIGHT:
|
||||
case GLUT_WINDOW_BORDER_WIDTH :
|
||||
case GLUT_WINDOW_HEADER_HEIGHT :
|
||||
{
|
||||
XWindowAttributes winAttributes;
|
||||
Window another, window;
|
||||
int x, y;
|
||||
|
||||
/*
|
||||
* Return zero if there is no current window set
|
||||
@ -223,53 +225,9 @@ int FGAPIENTRY glutGet( GLenum eWhat )
|
||||
if( fgStructure.Window == NULL )
|
||||
return( 0 );
|
||||
|
||||
/*
|
||||
* So, grab the current window's position
|
||||
*/
|
||||
window = fgStructure.Window->Window.Handle;
|
||||
|
||||
/*
|
||||
* Grab the current window's attributes now
|
||||
*/
|
||||
XGetWindowAttributes(
|
||||
fgDisplay.Display,
|
||||
window,
|
||||
&winAttributes
|
||||
);
|
||||
|
||||
/*
|
||||
* Correct the results for the parental relation and border size
|
||||
*/
|
||||
XTranslateCoordinates(
|
||||
fgDisplay.Display,
|
||||
window,
|
||||
winAttributes.root,
|
||||
-winAttributes.border_width,
|
||||
-winAttributes.border_width,
|
||||
&x, &y,
|
||||
&another
|
||||
);
|
||||
|
||||
/*
|
||||
* See if we have to return the X or Y coordinate
|
||||
*/
|
||||
return( eWhat == GLUT_WINDOW_X ? x : y );
|
||||
}
|
||||
|
||||
case GLUT_WINDOW_WIDTH:
|
||||
case GLUT_WINDOW_HEIGHT:
|
||||
{
|
||||
XWindowAttributes winAttributes;
|
||||
|
||||
/*
|
||||
* Return zero if there is no current window set
|
||||
*/
|
||||
if( fgStructure.Window == NULL )
|
||||
return( 0 );
|
||||
|
||||
/*
|
||||
* Checking for window's size is much easier:
|
||||
*/
|
||||
XGetWindowAttributes(
|
||||
fgDisplay.Display,
|
||||
fgStructure.Window->Window.Handle,
|
||||
@ -277,9 +235,17 @@ int FGAPIENTRY glutGet( GLenum eWhat )
|
||||
);
|
||||
|
||||
/*
|
||||
* See if to return the window's width or height
|
||||
* See which window attribute to return
|
||||
*/
|
||||
return( eWhat == GLUT_WINDOW_WIDTH ? winAttributes.width : winAttributes.height );
|
||||
switch ( eWhat )
|
||||
{
|
||||
case GLUT_WINDOW_X: return winAttributes.x ;
|
||||
case GLUT_WINDOW_Y: return winAttributes.y ;
|
||||
case GLUT_WINDOW_WIDTH: return winAttributes.width ;
|
||||
case GLUT_WINDOW_HEIGHT: return winAttributes.height ;
|
||||
case GLUT_WINDOW_BORDER_WIDTH : return winAttributes.border_width ;
|
||||
case GLUT_WINDOW_HEADER_HEIGHT : return winAttributes.border_width * 3 ; /* a kludge for now */
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@ -364,6 +330,24 @@ int FGAPIENTRY glutGet( GLenum eWhat )
|
||||
case GLUT_WINDOW_WIDTH:
|
||||
case GLUT_WINDOW_HEIGHT:
|
||||
{
|
||||
/*
|
||||
* There is considerable confusion about the "right thing to do" concerning window
|
||||
* size and position. GLUT itself is not consistent between Windows and Linux; since
|
||||
* platform independence is a virtue for "freeglut", we decided to break with GLUT's
|
||||
* behaviour.
|
||||
* Under Linux, it is apparently not possible to get the window border sizes in order
|
||||
* to subtract them off the window's initial position until some time after the window
|
||||
* has been created. Therefore we decided on the following behaviour, both under
|
||||
* Windows and under Linux:
|
||||
* - When you create a window with position (x,y) and size (w,h), the upper left hand
|
||||
* corner of the outside of the window is at (x,y) and the size of the drawable area
|
||||
* is (w,h).
|
||||
* - When you query the size and position of the window--as is happening here for
|
||||
* Windows--"freeglut" will return the size of the drawable area--the (w,h) that you
|
||||
* specified when you created the window--and the coordinates of the upper left hand
|
||||
* corner of the drawable area--which is NOT the (x,y) you specified.
|
||||
*/
|
||||
|
||||
RECT winRect;
|
||||
|
||||
/*
|
||||
@ -373,6 +357,7 @@ int FGAPIENTRY glutGet( GLenum eWhat )
|
||||
|
||||
/*
|
||||
* We need to call GetWindowRect() first...
|
||||
* (this returns the pixel coordinates of the outside of the window)
|
||||
*/
|
||||
GetWindowRect( fgStructure.Window->Window.Handle, &winRect );
|
||||
|
||||
@ -400,6 +385,12 @@ int FGAPIENTRY glutGet( GLenum eWhat )
|
||||
}
|
||||
break;
|
||||
|
||||
case GLUT_WINDOW_BORDER_WIDTH :
|
||||
return ( GetSystemMetrics( SM_CXSIZEFRAME ) ) ;
|
||||
|
||||
case GLUT_WINDOW_HEADER_HEIGHT :
|
||||
return ( GetSystemMetrics( SM_CYCAPTION ) ) ;
|
||||
|
||||
case GLUT_DISPLAY_MODE_POSSIBLE:
|
||||
/*
|
||||
* Check if the current display mode is possible
|
||||
|
@ -40,10 +40,13 @@
|
||||
#define GLUT_ACTION_CONTINUE_EXECUTION 2
|
||||
|
||||
/*
|
||||
* GLUT API macro definitions -- the glutGet parameters
|
||||
* GLUT API Extension macro definitions -- the glutGet parameters
|
||||
*/
|
||||
#define GLUT_ACTION_ON_WINDOW_CLOSE 0x01F9
|
||||
|
||||
#define GLUT_WINDOW_BORDER_WIDTH 0x01FA
|
||||
#define GLUT_WINDOW_HEADER_HEIGHT 0x01FB
|
||||
|
||||
/*
|
||||
* Process loop function, see freeglut_main.c
|
||||
*/
|
||||
|
Reference in New Issue
Block a user