About Store Forum Documentation Contact
Donations:
309$/mo



Post Reply 
Problems positioning GUI window from code using Rect...
Author Message
EvilNoodle Offline
Member

Post: #1
Problems positioning GUI window from code using Rect...
Hi,

I am very confused when it comes to positioning GUI components using Rect objects.

I have a window that I want to position from code with the following attributes:

Top left corner positioned at 1% of the total screen width and 1% of the total screen height.
Bottom right corner positioned at 50% of the total screen width and height.

Assuming the screen width range to be -1.33 to 1.33 and height to be 1 to -1 as in the GUI editor for a 4:3 screen this should give around top left -1.293, 0.98 and bottom right 0, 0.

My question is this...

What Rect should I use to achieve this (Rect, Rect_C, Rect_RD...)because I have tried them all without getting the results I want. The most promising is just plain Rect(-1.293, 0.98, 0, 0) which seems to position the window ok but its title bar is on the bottom (undesirable). The others seem to either screw the position or size to the extent it becomes a tiny box in the top left corner.

I did think the title bar was being rendered at the bottom using plain Rect(...) because of insufficient space above the window to draw it so I changed it to try at -1.293, 0.5 and bottom right 0, 0 and it still happens.

Am I doing something fundamentally wrong here or is there some subtlety I am missing?

Any help on this would be great I have already spent several hours trying to figure this out so I figured the best thing to do is ask.

EvilNoodle
02-22-2010 06:57 PM
Find all posts by this user Quote this message in a reply
McTomas Offline
Member

Post: #2
RE: Problems positioning GUI window from code using Rect...
from what you said I think you want this

Rect_LU(-D.w() + (0.01 * D.w() * 2), D.h() - (0.01 * D.h() * 2), D.w() - (0.01 * D.w() * 2), D.h() - (0.01 * D.h() * 2));

Basically what I've done was:
- Put the reference point as the upper left vertex of the Rect
- Put that reference point at 1% distance of the upper left corner from the viewport
- Create a rect with the size of D.w() - (0.01 * D.w() * 2) : D.h() - (0.01 * D.h() * 2)....that I think was what you meant about 50%

Hope that I could help grin
(This post was last modified: 02-22-2010 07:17 PM by McTomas.)
02-22-2010 07:14 PM
Find all posts by this user Quote this message in a reply
EvilNoodle Offline
Member

Post: #3
RE: Problems positioning GUI window from code using Rect...
Hi,

Thank you for your post. I now have screen positioning working exactly how I want using...

Code:
Rect RectUtil::screenPosition(float x, float y, float width, float height)
{
    float screenWidth = D.w();
    float screenHeight = D.h();

    float tlx = -screenWidth + (x * (screenWidth * 2));
    float tly = screenHeight - (y * (screenHeight * 2));
    float w = (width * (screenWidth * 2));
    float h = (height * (screenHeight * 2));

    Rect dims;
    dims.setLU(tlx, tly, w, h);

    return(dims);
}

Where x, y, width and height are values between 0 and 1.0 representing a portion of the total screen space available.

This gives me positioning and size that is insensitive to screen aspect ratio. Granted there are occasions where this will be inappropriate but for the stuff I am working on right now it is exactly what I wanted!

Many thanks

EvilNoodle
02-22-2010 10:28 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #4
RE: Problems positioning GUI window from code using Rect...
Quote:The most promising is just plain Rect(-1.293, 0.98, 0, 0) which seems to position the window ok but its title bar is on the bottom (undesirable)
you need to set minx miny, then maxx maxy
(the order is wrong)
02-23-2010 04:30 PM
Find all posts by this user Quote this message in a reply
Post Reply