Centering a Newt window?

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Centering a Newt window?

Stephen
Hi, I want to center a window that I've created with Newt on the screen.

I can probably use the Window.setTopLevelPosition or Window.setPosition methods.. though I need to determine the actual resolution of the screen, so that I can center the window, e.g. screenResolutionX/2, screenResolutionY/2..

How can I find the screen resolution?

Thank you,
Stephen
Reply | Threaded
Open this post in threaded view
|

Re: Centering a Newt window?

Sven Gothel
Administrator
On 10/10/2012 06:36 AM, Stephen [via jogamp] wrote:
> Hi, I want to center a window that I've created with Newt on the screen.
>
> I can probably use the Window.setTopLevelPosition or Window.setPosition
> methods.. though I need to determine the actual resolution of the screen, so
> that I can center the window, e.g. screenResolutionX/2, screenResolutionY/2..
>
> How can I find the screen resolution?
>
Use the window's Screen reference.
There you find ScreenMode .. etc ..

~Sven



signature.asc (907 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Centering a Newt window?

Stephen
Thank you Sven!

I used getRotatedWidth/getRotatedHeight and used newWidth = (screenWidth / 2) -  (windowWidth / 2) and same thing for height.

Thank you again,
~Stephen
adi
Reply | Threaded
Open this post in threaded view
|

Re: Centering a Newt window?

adi
I also have had that problem, if i use GLWindow.

First after a setVisible(true) the correct screen coordinates can
get from getScreen().getWidth() and getScreen().getHeight(),
so i must use
Dimension screenSize         = Toolkit.getDefaultToolkit().getScreenSize();

Reply | Threaded
Open this post in threaded view
|

Re: Centering a Newt window?

Sven Gothel
Administrator
On 10/16/2012 12:30 AM, adi [via jogamp] wrote:
> I also have had that problem, if i use GLWindow.
>
> First after a setVisible(true) the correct screen coordinates can
> get from getScreen().getWidth() and getScreen().getHeight(),
> so i must use
> Dimension screenSize         = Toolkit.getDefaultToolkit().getScreenSize();
>

You can also create a NEWT Screen via NEWT factory
and force it's instantiation by issuing 'addReference()' !
This is due to our lazy initialization ..

You then can reuse that Screen instance for GLWindow,
after which initialization (setVisible() )
I would 'removeReference()' to give the GLWindow
the 'right' to destroy it later on.

~Sven



signature.asc (907 bytes) Download Attachment
adi
Reply | Threaded
Open this post in threaded view
|

Re: Centering a Newt window?

adi
Thanks.

Do you mean that ??:

Display myDisplay = NewtFactory.createDisplay(NativeWindowFactory.TYPE_DEFAULT, "MySreen");
int undefined = myDisplay.addReference();
Screen myScreen = NewtFactory.createScreen(myDisplay, undefined );
Reply | Threaded
Open this post in threaded view
|

Re: Centering a Newt window?

Sven Gothel
Administrator
On 10/16/2012 11:16 AM, adi [via jogamp] wrote:
> Thanks.
>
> Do you mean that ??:
>
> Display myDisplay =
> NewtFactory.createDisplay(NativeWindowFactory.TYPE_DEFAULT, "MySreen");
> int undefined = myDisplay.addReference();
> Screen myScreen = NewtFactory.createScreen(myDisplay, undefined );

addReference() returns the ref-count .., see following code-snippet:

final com.jogamp.newt.Display dpy = NewtFactory.createDisplay(null);
final com.jogamp.newt.Screen scrn = NewtFactory.createScreen(dpy, 0);
scrn.addReference(); // gain ref-count 0 -> 1, which actually creates native resource

// now you can query details
// like int width = scrn.* whatever ..
             
final GLWindow win = GLWindow.create(scrn, new GLCapabilities(null));
win.setSize(width,height);
win.setVisible(true);
scrn.removeReference(); // release count 2 -> 1

...

win.destroy(); // will also destroy scrn ..

+++

Note: You can use your IDE (eclipse, ..)
and open the JOGL project, go to Screen.addReference()
and click: 'Open Call Hierarchy'
This will show you a list of callers .. and hence examples.

~Sven


signature.asc (907 bytes) Download Attachment
adi
Reply | Threaded
Open this post in threaded view
|

Re: Centering a Newt window?

adi
Thanks! That works.