Jump to content
  • Advertisement
Sign in to follow this  
SeeForever

Simple math: how does wxWidgets calculate control position?

This topic is 2504 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!