------------------------------------------------------------ revno: 3224 committer: poy <p...@123gen.com> branch nick: trunk timestamp: Sat 2013-03-16 16:11:42 +0100 message: clean dwt::Rectangle up modified: dwt/include/dwt/Rectangle.h dwt/src/CanvasClasses.cpp dwt/src/Rectangle.cpp
-- lp:dcplusplus https://code.launchpad.net/~dcplusplus-team/dcplusplus/trunk Your team Dcplusplus-team is subscribed to branch lp:dcplusplus. To unsubscribe from this branch go to https://code.launchpad.net/~dcplusplus-team/dcplusplus/trunk/+edit-subscription
=== modified file 'dwt/include/dwt/Rectangle.h' --- dwt/include/dwt/Rectangle.h 2013-03-16 13:25:11 +0000 +++ dwt/include/dwt/Rectangle.h 2013-03-16 15:11:42 +0000 @@ -85,223 +85,9 @@ long height() const { return size.y; } + /** Check whether the point is inside the rectangle. */ bool contains(const Point& pt) const; - const Point& upperLeft() const { return pos; } - - /// Return the lower right point of the rectangle. - /** - * Example: <br> - * Rectangle r1( 10, 10, 100, 200 ); <br> - * Point lr = r1.LowRight() <br> - * gives lr.x = 110, lr.y = 210 - */ - Point lowRight() const { return Point(x() + width(), y() + height()); } - - /// 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 <br> - * r1.SubRect( 0.5, 0, 0.5, 1 ) gives the right half of r1 <br> - * r1.SubRect( .334, .334, .334, .334 ) centers r2 inside r1 <br> - * r1.SubRect( .2, .2, .6, .6 ) also centers r2 inside r1 <br> - * <pre> - * 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 - * </pre> - */ - Rectangle subRect( double xFraction, double yFraction, - double widthFraction, double heightFraction ) const; - - /// Size of the rectangle will be * factor, Position adjusted for the same center. - /** Creates a smaller rectangle from the old rectangle. <br> - * size.x *= factor, and pos.x is adjusted inwards to compensate. <br> - * <pre> - * #### - * #### -> ## - * #### ## - * #### - * </pre> - * shows the effect of shrink( 0.5 ) <br> - * shrink( long border ) is similar, but removes a constant border amount of - * pixels on all sides. - */ - Rectangle shrinkFactor( double factor ) const; - - /// Move inwards by xBorder and shrink the size by 2*xBorder - /** A rectangle of #### changes to ##.<br> - * The rectangle becomes smaller at the left and right, but has the same center. - */ - Rectangle shrinkWidth( long xBorder ) const; - - /// Move inwards by yBorder and shrink the size by 2*yBorder - /** <pre> - * #### - * #### -> #### - * #### #### - * #### - * - * </pre> - * The rectangle becomes smaller at the top and bottom, but has the same center. - */ - Rectangle shrinkHeight( long yBorder ) const; - - /// Move inwards by both xBorder and yBorder and shrink the size by 2*yBorder - /// and 2*xBorder - /** <pre> - * #### - * #### -> ## - * #### ## - * #### - * </pre> - * The rectangle shrinks, but has the same center. - */ - Rectangle shrink( long xBorder, long yBorder ) 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 border ) const; - - /// Return the upper rectangle of height y - /** We return the upper rectangle of height y.<br> - * Example: <br> - * Rectangle rect( 0,0, 100, 100 );<br> - * Rectangle t = rect.getTop( 10 ); - * Now: t.pos = 0,0 t.size = 100,10<br> - */ - Rectangle getTop( long y ) const; - - /// Return the lower rectangle starting from y - /** We return the lower rectangle of height y<br> - * Example: <br> - * Rectangle rect( 0,0, 100, 100 );<br> - * Rectangle t = rect.getBottom( 10 ); - * Now: t.pos = 0,90 t.size = 100,10<br> - */ - Rectangle getBottom( long y ) const; - - /// Return the left rectangle of widght x. - /** We return the left rectangle of width x<br> - * Example: <br> - * Rectangle rect( 0, 0, 100, 100 );<br> - * Rectangle t = rect.getLeft( 10 ); - * Now: t.pos= 0,0 t.size= 10,100<br> - */ - Rectangle getLeft( long x ) const; - - /// Return the right rectangle of widght x. - /** We return the right rectangle of width x<br> - * Example: <br> - * Rectangle rect( 0, 0, 100, 100 );<br> - * Rectangle t = rect.getRight( 10 ); - * Now: t.pos= 90,0 t.size= 10,100<br> - */ - Rectangle getRight( long x ) const; - - /// Move the Upper Left position by adjust, and keep the same Lower Right corner. - /** <pre> - * OOOOOO - * OOOO++ - * OOOO++ - * </pre> - * upperLeftAdjust( Point( 4, 1 ) ); will give the + rectangle afterwards. - */ - Rectangle upperLeftAdjust( const Point & adjust ) const; - - /// Move the Lower Right position by adjust, and keep the same Upper Left corner. - /** <pre> - * ++++O - * ++++O - * OOOOO - * </pre> - * lowerRightAdjust( Point( -1, -1 ) ); will give the + rectangle afterwards. - */ - Rectangle lowerRightAdjust( const Point & adjust ) const; - - /// Produce the Left portion of a Rectangle with portion width, same height, - /// same position. - /** If the original rectangle is as below: <br> - * <pre> - * XXXOOOOOOO - * XXXOOOOOOO - * XXXOOOOOOO - * XXXOOOOOOO - * </pre> - * left( 0.3 )returns the X rectangle. <br> - */ - Rectangle toleft( 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. <br> - * <pre> - * OOOOOOO### - * OOOOOOO### - * OOOOOOO### - * OOOOOOO### - * </pre> - * right( 0.3 )returns the # rectangle. <br> - */ - Rectangle toright( 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. <br> - * <pre> - * ########## - * ########## - * OOOOOOOOOO - * OOOOOOOOOO - * </pre> - * top( 0.5 ) or Top() returns the # rectangle. <br> - */ - Rectangle upper( 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. <br> - * <pre> - * OOOOOOOOOO - * ########## - * ########## - * ########## - * </pre> - * Bottom( 0.75 ) returns the # rectangle. <br> - */ - Rectangle lower( double portion = 0.5 ) 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. <br> - * row0 <br> - * row1 <-- Row( 1, 3 ) will return the "row1" rectangle.<br> - * row2 <br> - */ - Rectangle row( int row, int rows ) 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. <br> - *<br> - * col0 col1 col2 col3 <br> - *<br> - *Col( 2, 4 ) will return the "col2" rectangle.<br> - */ - Rectangle col( int column, int columns ) const; - - /// Produce a Rectangle with the top portion removed - Rectangle cropTop( const int a_ToRemove ) const; - - /// Produce a Rectangle with the bottom portion removed - Rectangle cropBottom( const int a_ToRemove ) const; - - /// Produce a Rectangle with the left portion removed - Rectangle cropLeft( const int a_ToRemove ) const; - - /// Produce a Rectangle with the right portion removed - Rectangle cropRight( const int a_ToRemove ) const; - /** Adjust the rectangle to make sure it is not outside of the desktop of the monitor closest to the given base widget. */ Rectangle& ensureVisibility(Widget* base); === modified file 'dwt/src/CanvasClasses.cpp' --- dwt/src/CanvasClasses.cpp 2013-01-18 21:28:38 +0000 +++ dwt/src/CanvasClasses.cpp 2013-03-16 15:11:42 +0000 @@ -132,7 +132,7 @@ void Canvas::line( const dwt::Rectangle & rect ) { moveTo( rect.pos ); - dwt::Point lr( rect.lowRight() ); + dwt::Point lr { rect.right(), rect.bottom() }; lineTo( lr.x, rect.pos.y ); lineTo( lr.x, lr.y ); lineTo( rect.x(), lr.y ); === modified file 'dwt/src/Rectangle.cpp' --- dwt/src/Rectangle.cpp 2013-03-16 13:25:11 +0000 +++ dwt/src/Rectangle.cpp 2013-03-16 15:11:42 +0000 @@ -54,142 +54,6 @@ return ::PtInRect(&rect, pt); } -Rectangle Rectangle::subRect( double xFraction, double yFraction, - double widthFraction, double heightFraction ) const -{ - Rectangle retVal; - retVal.pos.x = pos.x + ( long )( xFraction * size.x ); - retVal.pos.y = pos.y + ( long )( yFraction * size.y ); - - retVal.size.x = ( long )( size.x * widthFraction ); - retVal.size.y = ( long )( size.y * heightFraction ); - return retVal; -} - -// Size of the rectangle will be * factor. -// Position adjusted for the same center. -Rectangle Rectangle::shrinkFactor( double factor ) const -{ - double posFactor = ( 1.0 - factor ) * 0.5; - return subRect( posFactor, posFactor, factor, factor ); -} - -Rectangle Rectangle::shrinkWidth( long xBorder ) const -{ - Rectangle retVal = * this; - retVal.pos.x = pos.x + xBorder; - retVal.size.x = size.x - ( xBorder + xBorder ); - return retVal; -} - -Rectangle Rectangle::shrinkHeight( long yBorder ) const -{ - Rectangle retVal = * this; - retVal.pos.y += yBorder; - retVal.size.y -= ( yBorder + yBorder ); - return retVal; -} - -Rectangle Rectangle::shrink( long border ) const -{ - Rectangle retVal = shrinkWidth( border ); - retVal = retVal.shrinkHeight( border ); - return retVal; -} - -Rectangle Rectangle::shrink( long xBorder, long yBorder ) const -{ - Rectangle retVal = shrinkWidth( xBorder ); - retVal = retVal.shrinkHeight( yBorder ); - return retVal; -} - -Rectangle Rectangle::getTop( long y ) const -{ - Rectangle top = Rectangle( pos, Point( size.x, y ) ); - return top; -} - -Rectangle Rectangle::getBottom( long y ) const -{ - Rectangle bottom = Rectangle( - Point( pos.x, pos.y + size.y - y ), - Point( size.x, y ) ); - return bottom; -} - -Rectangle Rectangle::getLeft( long x ) const -{ - Rectangle left = Rectangle( pos, Point( x, size.y ) ); - return left; -} - -Rectangle Rectangle::getRight( long x ) const -{ - Rectangle bottom = Rectangle( - Point( pos.x + size.x - x, pos.y ), - Point( x, size.y ) ); - return bottom; -} - -Rectangle Rectangle::upperLeftAdjust( const Point & adjust ) const -{ - Rectangle retVal = * this; - retVal.pos.x += adjust.x; - retVal.pos.y += adjust.y; - retVal.size.x -= adjust.x; - retVal.size.y -= adjust.y; - return retVal; -} - -Rectangle Rectangle::lowerRightAdjust( const Point & adjust ) const -{ - Rectangle retVal = * this; - retVal.size.x += adjust.x; - retVal.size.y += adjust.y; - return retVal; -} - -Rectangle Rectangle::row( int row, int rows ) const -{ - int rowheight = size.y / rows; - return Rectangle( pos.x, pos.y + ( row * rowheight ), size.x, rowheight ); -} - -Rectangle Rectangle::col( int column, int columns ) const -{ - int colwidth = size.x / columns; - return( Rectangle( pos.x + ( colwidth * column ), pos.y, colwidth, size.y ) ); -} - -Rectangle Rectangle::cropTop( const int a_ToRemove ) const -{ - register int d_NewSize = size.y - a_ToRemove; - - return Rectangle( pos.x, pos.y + a_ToRemove, size.x, d_NewSize > 0 ? d_NewSize : 0 ); -} - -Rectangle Rectangle::cropBottom( const int a_ToRemove ) const -{ - register int d_NewSize = size.y - a_ToRemove; - - return Rectangle( pos.x, pos.y, size.x, d_NewSize > 0 ? d_NewSize : 0 ); -} - -Rectangle Rectangle::cropLeft( const int a_ToRemove ) const -{ - register int d_NewSize = size.x - a_ToRemove; - - return Rectangle( pos.x + a_ToRemove, pos.y, d_NewSize > 0 ? d_NewSize : 0, size.y ); -} - -Rectangle Rectangle::cropRight( const int a_ToRemove ) const -{ - register int d_NewSize = size.x - a_ToRemove; - - return Rectangle( pos.x, pos.y, d_NewSize > 0 ? d_NewSize : 0, size.y ); -} - Rectangle& Rectangle::ensureVisibility(Widget* base) { auto desktop = base->getDesktopSize(); if(right() > desktop.right()) { pos.x = desktop.right() - width(); }
_______________________________________________ Mailing list: https://launchpad.net/~linuxdcpp-team Post to : linuxdcpp-team@lists.launchpad.net Unsubscribe : https://launchpad.net/~linuxdcpp-team More help : https://help.launchpad.net/ListHelp