Jump to content
  • Advertisement
Sign in to follow this  

valign, halign, alignment code

This topic is 3794 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

i am looking for alignment code( left,right,center and/or top,middle,bottom)this kind of stuff must have been done millions of times before, i don't really want to redo it. anyone have a link or some code snippets?

Share this post

Link to post
Share on other sites
in VS2005 and C++, alignment of boxes on a screen.

class Box
int x;
int y;
int height;
int width;

i have two boxes within a bigger box. Say call the bigger box parent and the two smaller ones child boxes.

I want to code different ways of aligning the two child boxes within the parent.
1) child boxes centered within parent
2) child boxes left aligned within parent
3) child boxes right aligned within parent
4) aligning the boxes along the y-axis or x-axis of the parent
5) aligning the boxes starting from the bottom of the parent box
6) combining one or more of the ways above

// these are my flags
horizontal_align = { left, center, right }
vertical_align = { left, center, right }
axis_align(can't think of a better way to name this) = { top_to_bottom, left_to_right }

you get what i mean, this code i am sure has been done before.

Share this post

Link to post
Share on other sites
Im not sure you'll find code snippets for that, it's an extremely trivial problem.

Share this post

Link to post
Share on other sites
This is trivial. Assuming that your x and y coordinates are the top left center of the box, with (0,0) being the top left corner and the coordinates that you are aligning to are called leftWall, rightWall, bottomWall and topWall, the pseudocode looks something like this:

Left align: x = leftWall;
Right align: x = rightWall - width;
Middle horizontal: x = leftWall + (rightWall - leftWall - width)/2.0;

Top align: y = topWall;
Bottom align: y = bottomWall - height;
Middle vertical: y = topWall + (bottomWall - topWall - height)/2.0;

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!