Simple math: how does wxWidgets calculate control position?

Started by
1 comment, last by SeeForever 12 years, 2 months ago
Hello guys and girls! biggrin.png

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! wink.png
Advertisement
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.
Nevermind, I figured it out. It was too simple... I just needed a night's rest. biggrin.png

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! angry.png

This topic is closed to new replies.

Advertisement