Skip navigation.
Home
The QNX Community Portal

View topic - Center a Photon Window

Center a Photon Window

Isn't the name clear?

Center a Photon Window

Postby copperleaf » Wed Feb 28, 2007 10:06 pm

I have a PtWindow that I want to center on the screen. Is there a way to do this? I know how to get the current screen width and height with PgGetVideoMode and PgGetVideoModeInfo, but it's not clear to me how to get the outside dimensions of the window (which I don't think can be determined until after the window has be realized), and then how to move the window to the proper location.

TIA,
Bill
copperleaf
New Member
 
Posts: 9
Joined: Thu Jan 13, 2005 1:29 pm
Location: Richmond, VA

RE: Center a Photon Window

Postby maschoen » Thu Mar 01, 2007 8:34 pm

You could set the windows size yourself. You can definitely set it's location. Since you know the other relevent information, centering should be straight forward.
maschoen
QNX Master
 
Posts: 2640
Joined: Wed Jun 25, 2003 5:18 pm

RE: Center a Photon Window

Postby maschoen » Thu Mar 01, 2007 8:36 pm

Also, there are both pre and post realize callbacks for startup, so if you want the window to set its own size, you can check afterwards and just reset its location. This can cause a visual jump, which you can mitigate by setting the location off screen in the pre-realize callback.
maschoen
QNX Master
 
Posts: 2640
Joined: Wed Jun 25, 2003 5:18 pm

RE: Center a Photon Window

Postby copperleaf » Fri Mar 02, 2007 2:18 pm

Thanks for the idea. I've run into a small problem though. I'm drawing the window initially offscreen and registering the Pt_CB_REALIZED callback on the window. In the callback, I'm setting the position with PtSetResource(window, Pt_ARG_POS, *pos, 0), but nothing happens. I've confirmed that the callback is being made and that PtSetResource is not returning -1. If I move the window with a PtTimer,with the same callback code, that works but that seems hackish to use a timer to move a window one time especially when there is a callback that should work.
copperleaf
New Member
 
Posts: 9
Joined: Thu Jan 13, 2005 1:29 pm
Location: Richmond, VA

RE: Center a Photon Window

Postby copperleaf » Fri Mar 02, 2007 3:13 pm

In addition, when I make the call to PtWindowGetFrameSize, my upper left point is the same as my lower right point. This occurs even in the timer callback.

Here is my code for creating the window:

Code: Select all
  PtSetArg(&args[0], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_FALSE,
      Ph_WM_RENDER_CLOSE | Ph_WM_RENDER_TITLE | Ph_WM_RENDER_RESIZE);
  PtSetArg(&args[1], Pt_CB_REALIZED, windowCBs, sizeof(windowCBs)/sizeof(windowCBs[0]));
  window = PtCreateWidget(PtWindow, Pt_NO_PARENT, 2, args);


and here is my code for centering the window:
Code: Select all
  PgDisplaySettings_t displaySettings;
  PgVideoModeInfo_t modeInfo;
  PhRect_t windowRect;
  PhPoint_t newPos;
 
  PgGetVideoMode(&displaySettings);
  PgGetVideoModeInfo(displaySettings.mode, &modeInfo);
 
  PtWindowGetFrameSize(window, &windowRect);
 
  newPos.x = (modeInfo.width - (windowRect.lr.x - windowRect.ul.x)) / 2;
  newPos.y = (modeInfo.height - (windowRect.lr.y - windowRect.ul.y)) / 2;
 
  PtSetResource(window, Pt_ARG_POS, &newPos, 0);
copperleaf
New Member
 
Posts: 9
Joined: Thu Jan 13, 2005 1:29 pm
Location: Richmond, VA

RE: Center a Photon Window

Postby maschoen » Fri Mar 02, 2007 7:48 pm

Assuming you are doing things right, it seems that somehow setting the new position in the Realized callback doesn't work.
Maybe you need to "damage" the widget?
maschoen
QNX Master
 
Posts: 2640
Joined: Wed Jun 25, 2003 5:18 pm


Return to GUI Programming

Who is online

Users browsing this forum: No registered users and 2 guests

cron