Jump to content

  • Log In with Google      Sign In   
  • Create Account


Simple math: how does wxWidgets calculate control position?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 SeeForever   Members   -  Reputation: 131

Like
0Likes
Like

Posted 06 February 2012 - 05:15 PM

Hello guys and girls! Posted Image

I made my own GUI system for my game. I just needed buttons, text boxes and a couple custom controls so it wasn't too hard to make. It worked fine for a bit but I couldn't stand the ugliness of pixel-based positioning, and it started getting annoying to code one particular part of the game that relies on the GUI heavily.

Then I remembered how wxWidgets works: it divides the GUI into squares, one control per square, and then you can align and stretch the control in there to get the desired position. I tried to make something similar but I got stuck figuring out how to calculate the positions for the squares. Right now I have this:

control1 | control2
control3 | control4

It works as expected for a 2x2 (or 3x3 or 4x4) grid but what if I want to put a control5 in the same square as control2? So that control4 would be aligned across control2 and control5. The way I have it set up right now, it divides the top row in 3 equal parts and the bottom row in 2 equal parts and this is not what I want. control1 and control3 need to be aligned vertically.

I know it's a matter of simple math but I've been stuck for days thinking about it and playing around with algorithms and I just can't figure it out... Can someone help me out?


Thanks in advance! Posted Image

Sponsor:

#2 freeworld   Members   -  Reputation: 325

Like
0Likes
Like

Posted 07 February 2012 - 12:25 PM

Look up quadTree... I know it's overkill for what you're trying to do but the concept is the same. The control2 square becomes a parent, with two controls in it. These two squares take up the same space as control 2 did but they have they're own size within it. Sorry hard to describe without pictures.
[ dev journal ]
[ current projects' videos ]
[ Zolo Project ]
I'm not mean, I just like to get to the point.

#3 SeeForever   Members   -  Reputation: 131

Like
0Likes
Like

Posted 07 February 2012 - 02:27 PM

Nevermind, I figured it out. It was too simple... I just needed a night's rest. Posted Image

Splitters (like in wxWidgets) are controls that go in other splitters. Splitters break space up into equal portions then inside those you put more splitters. Okay you're right, it's hard to describe without pictures! Posted Image




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS