Rectangle Struct Reference
[Layout of widgets in windows]

Data structure for defining a rectangle. More...

List of all members.

Public Member Functions

Rectangle bottom (double portion=0.5) const
 Produce a Rectangle with the portion % height, same width, position moved downwards.
Rectangle col (int column, int columns) const
 Produce a Rectangle with the 1/cols % width, same height, colth position.
Rectangle cropBottom (const int a_ToRemove) const
 Produce a Rectangle with the bottom portion removed.
Rectangle cropLeft (const int a_ToRemove) const
 Produce a Rectangle with the left portion removed.
Rectangle cropRight (const int a_ToRemove) const
 Produce a Rectangle with the right portion removed.
Rectangle cropTop (const int a_ToRemove) const
 Produce a Rectangle with the top portion removed.
Rectangle getBottom (long y) const
 Return the lower rectangle starting from y.
Rectangle getLeft (long x) const
 Return the left rectangle of widght x.
Rectangle getRight (long x) const
 Return the right rectangle of widght x.
Rectangle getTop (long y) const
 Return the upper rectangle of height y.
Rectangle left (double portion=0.5) const
 same position.
Rectangle lowerRightAdjust (const Point &adjust) const
 Move the Lower Right position by adjust, and keep the same Upper Left corner.
Point lowRight () const
 Return the lower right point of the rectangle.
 Rectangle (const Rectangle &rect, double xFraction, double yFraction, double widthFraction, double heightFraction)
 the old rect.
 Rectangle (long x, long y, long width, long height)
 Constructor initializing the rectangle with longs instead of Points.
 Rectangle (const Point &pSize)
 Constructor initializing the rectangle with a size.
 Rectangle (const Point &pPos, const Point &pSize)
 Constructor initializing the rectangle with a position and size.
 Rectangle ()
 Constructor initializing the rectangle to (0, 0, 0, 0).
Rectangle right (double portion=0.5) const
 Produce a Rectangle with the portion % width, same height, position moved to right.
Rectangle row (int row, int rows) const
 Produce a Rectangle with the 1/rows % height, same width, rowth position.
Rectangle shrink (long border) const
 For both dimensions, move inwards by Border and shrink the size by 2*Border.
Rectangle shrink (long xBorder, long yBorder) const
 and 2*xBorder
Rectangle shrink (double factor) const
 Size of the rectangle will be * factor, Position adjusted for the same center.
Rectangle shrinkHeight (long yBorder) const
 Move inwards by yBorder and shrink the size by 2*yBorder.
Rectangle shrinkWidth (long xBorder) const
 Move inwards by xBorder and shrink the size by 2*xBorder.
Rectangle subRect (double xFraction, double yFraction, double widthFraction, double heightFraction) const
 Creates a sub rectangle from an old rectangle.
Rectangle top (double portion=0.5) const
 Produce a Rectangle with the portion % height, same width, same position.
Rectangle upperLeftAdjust (const Point &adjust) const
 Move the Upper Left position by adjust, and keep the same Lower Right corner.

Static Public Member Functions

static Rectangle FromRECT (const ::RECT &)
 Creates a new rectangle from a Windows RECT.

Public Attributes

Point pos
 Position of the upper left corner of the Rectangle.
Point size
 Size of the Rectangle.


Detailed Description

Data structure for defining a rectangle.

The two Point data members, pos and size, define a rectangle.
pos has the x,y position of the upper-left rectangle coordinate.
size defines the x and y distance between the upper left and the lower right coordinate.
(pos + size) defines the lower right coordinate.
Many window functions takes or returns a Rectangle.
See the Layout module documentation for the use of Rectangle in positioning widgets.
The member functions are helpful in dividing large rectangles into smaller ones, which is exactly what is needed to layout widgets in windows.


Constructor & Destructor Documentation

Rectangle (  ) 

Constructor initializing the rectangle to (0, 0, 0, 0).

Default constructor initializing everything to zero (0)

Rectangle ( const Point pPos,
const Point pSize 
)

Constructor initializing the rectangle with a position and size.

Note that the pSize is actually a size and NOT the lower right Point.

Rectangle ( const Point pSize  )  [explicit]

Constructor initializing the rectangle with a size.

Note that the pSize is actually a size and NOT the lower right Point, position is defaulted to 0,0.

Rectangle ( long  x,
long  y,
long  width,
long  height 
)

Constructor initializing the rectangle with longs instead of Points.

( x,y ) defines the upper right corner, ( x+width, y+height ) defines the lower left corner.

Rectangle ( const Rectangle rect,
double  xFraction,
double  yFraction,
double  widthFraction,
double  heightFraction 
)

the old rect.

It computes the new rectangle by using subrect():
(xFraction * size.x) is the amount to add to pos.x
size.x *= widthFraction

 Examples :
  upper half is r2( r1, 0, 0, 1, 0.5 )   (Same position, same width, 0.5 height )
  lower half is r2( r1, 0, 0.5, 1, 0.5 ) (y half down, same width, 0.5 height )
  left  half is r2( r1, 0, 0, 0.5, 1 )   (Same position, 0.5 width, same height )
  right half is r2( r1, 0.5, 0, 0.5, 1 )
  Lower right quarter is r2( r1, .5, .5, .5, .5)
  center r2 inside r1 is r2( r1, .334, .334, .334, .334)
 


Member Function Documentation

Rectangle bottom ( double  portion = 0.5  )  const

Produce a Rectangle with the portion % height, same width, position moved downwards.

Produce a Rectangle with the portion % height, same width, position moved downwards.

 OOOOOOOOOO
 ##########
 ##########
 ##########
 
Bottom( 0.75 ) returns the # rectangle.

Rectangle col ( int  column,
int  columns 
) const

Produce a Rectangle with the 1/cols % width, same height, colth position.

Produce a Rectangle with the 1/cols % width, same height, colth position.

col0 col1 col2 col3

Col( 2, 4 ) will return the "col2" rectangle.

Rectangle FromRECT ( const ::RECT &   )  [static]

Creates a new rectangle from a Windows RECT.

Windows RECT structure uses the coordinates of the top-left and bottom-right points. SmartWin::Rectangle, on the other hand, uses top-left, width-height.

Rectangle getBottom ( long  y  )  const

Return the lower rectangle starting from y.

We return the lower rectangle of height y
Example:
Rectangle rect( 0,0, 100, 100 );
Rectangle t = rect.getBottom( 10 ); Now: t.pos = 0,90 t.size = 100,10

Rectangle getLeft ( long  x  )  const

Return the left rectangle of widght x.

We return the left rectangle of width x
Example:
Rectangle rect( 0, 0, 100, 100 );
Rectangle t = rect.getLeft( 10 ); Now: t.pos= 0,0 t.size= 10,100

Rectangle getRight ( long  x  )  const

Return the right rectangle of widght x.

We return the right rectangle of width x
Example:
Rectangle rect( 0, 0, 100, 100 );
Rectangle t = rect.getRight( 10 ); Now: t.pos= 90,0 t.size= 10,100

Rectangle getTop ( long  y  )  const

Return the upper rectangle of height y.

We return the upper rectangle of height y.
Example:
Rectangle rect( 0,0, 100, 100 );
Rectangle t = rect.getTop( 10 ); Now: t.pos = 0,0 t.size = 100,10

Rectangle left ( double  portion = 0.5  )  const

same position.

If the original rectangle is as below:

 XXXOOOOOOO
 XXXOOOOOOO
 XXXOOOOOOO
 XXXOOOOOOO
 
left( 0.3 )returns the X rectangle.

Rectangle lowerRightAdjust ( const Point adjust  )  const

Move the Lower Right position by adjust, and keep the same Upper Left corner.

 ++++O
 ++++O
 OOOOO
 
lowerRightAdjust( Point( -1, -1 ) ); will give the + rectangle afterwards.

Point lowRight (  )  const

Return the lower right point of the rectangle.

Note that the rectangle is defined with pos, and a size, so we need this function.
Example:
Rectangle r1( 10, 10, 100, 200 );
Point lr = r1.LowRight()
gives lr.x = 110, lr.y = 210

Rectangle right ( double  portion = 0.5  )  const

Produce a Rectangle with the portion % width, same height, position moved to right.

Produce a Rectangle with the portion % width, same height, position moved to right.

 OOOOOOO###
 OOOOOOO###
 OOOOOOO###
 OOOOOOO###
 
right( 0.3 )returns the # rectangle.

Rectangle row ( int  row,
int  rows 
) const

Produce a Rectangle with the 1/rows % height, same width, rowth position.

Produce a Rectangle with the 1/rows % height, same width, rowth position.
row0
row1 <-- Row( 1, 3 ) will return the "row1" rectangle.
row2

Rectangle shrink ( long  border  )  const

For both dimensions, move inwards by Border and shrink the size by 2*Border.

We add border to the position, and subtract it twice from the size. Same as shrink( long xBorder, long yBorder ); except the x and y border are the same. shrink( double factor ) is similar, but expresses the new rectangle as a fraction of the old.

Rectangle shrink ( long  xBorder,
long  yBorder 
) const

and 2*xBorder

 ####
 ####    ->  ##
 ####        ##
 ####
 
The rectangle shrinks, but has the same center.

Rectangle shrink ( double  factor  )  const

Size of the rectangle will be * factor, Position adjusted for the same center.

Creates a smaller rectangle from the old rectangle.
size.x *= factor, and pos.x is adjusted inwards to compensate.

 ####
 ####    ->  ##
 ####        ##
 ####
 
shows the effect of shrink( 0.5 )
shrink( long border ) is similar, but removes a constant border amount of pixels on all sides.

Rectangle shrinkHeight ( long  yBorder  )  const

Move inwards by yBorder and shrink the size by 2*yBorder.

 ####
 ####    ->  ####
 ####        ####
 ####

 
The rectangle becomes smaller at the top and bottom, but has the same center.

Rectangle shrinkWidth ( long  xBorder  )  const

Move inwards by xBorder and shrink the size by 2*xBorder.

A rectangle of #### changes to ##.
The rectangle becomes smaller at the left and right, but has the same center.

Rectangle subRect ( double  xFraction,
double  yFraction,
double  widthFraction,
double  heightFraction 
) const

Creates a sub rectangle from an old rectangle.

The pos is adjusted by the xFraction and yFraction of the width and height of r. The size is also shrunk. r1.SubRect( 0, 0, 1, 0.5 ) gives the upper half of r1
r1.SubRect( 0.5, 0, 0.5, 1 ) gives the right half of r1
r1.SubRect( .334, .334, .334, .334 ) centers r2 inside r1
r1.SubRect( .2, .2, .6, .6 ) also centers r2 inside r1

 OOOOOOOOOO    is given by subRect( 0.3, 0.5, 0.4, 0.5 );
 OOOOOOOOOO    (x moved 30%, y moved 50% )
 OOO++++OOO    (x resized to 40%, y resized to 50% )
 OOO++++OOO
 

Rectangle top ( double  portion = 0.5  )  const

Produce a Rectangle with the portion % height, same width, same position.

Produce a Rectangle with the portion % height, same width, same position.

 ##########
 ##########
 OOOOOOOOOO
 OOOOOOOOOO
 
top( 0.5 ) or Top() returns the # rectangle.

Rectangle upperLeftAdjust ( const Point adjust  )  const

Move the Upper Left position by adjust, and keep the same Lower Right corner.

 OOOOOO
 OOOO++
 OOOO++
 
upperLeftAdjust( Point( 4, 1 ) ); will give the + rectangle afterwards.

Back to SmartWin website
SourceForge.net Logo