PrevNextUpHome SophiaFramework UNIVERSE 5.3

12.5. Graphic Operation

In SFXRectangle class, there are functions for comparison, evaluation, and operation.

Example 12.29. Graphic operation

SFXRectangle rectangle1(10, 20, 30, 40);
SFXRectangle rectangle2(20, 10, 30, 40);
SFXRectangle rectangle3;

// compare
if (rectangle1 == rectangle2) {             
    // when rectangle1 equals rectangle2
    
}

// whether rectangle is valid or not
if (rectangle1.IsEmpty()) {                 
    // when width or height is less than or equal to 0
   
}

// inclusion relation of rectangles
if (rectangle1.IsInsideOf(rectangle2)) {    
    // when rectangle1 is included in rectangle2
    
}

// get intersectional part of two rectangles
rectangle3 = rectangle1.Intersection(rectangle2);

// check whether two rectangles intersect each other or not
if (rectangle1.IntersectsWith(rectangle2)) { 
    // when intersectional part of two rectangles exists
    
}

// get rectangle including two given rectangles
rectangle3 = rectangle1.Union(rectangle2);

// check whether rectangle that includes two given rectangles exists or not
if (rectangle1.UnifiesWith(rectangle2)) {    
    // when exist such rectangle
   
}

// when width or height is negative, make it positive value
rectangle1.Normalize();

Example 12.30. Combine the operations

// draw rectangle from origin one by adding 50 to height and moving down by 30 
// original rectangle is also changed
graphics->DrawRectangle(rectangle.AddHeight(50).AddY(30));

// draw line bottom edge of rectangle of which start point is moved 20 pixels right and end point is moved 40 pixels down
// (rectangle is not changed)
graphics->DrawLine(rectangle.GetEdgeBottom().AddStartX(20).AddEndY(40));

// get rectangle of screen size by SFXGraphics::GetDeviceRectangle()
// shrink it by 40 pixels left and right, 20 pixels up and down
// move it 10 pixels down
// and then draw it

graphics->DrawRectangle(SFXGraphics::GetDeviceRectangle().Deflate(40, 20).AddY(10));

// extend rectangle of top-left (30, 20), 40 pixels width, and 10 pixels height 
// by 5 pixels left and right, 10 pixels up and down 
// and then draw it
graphics->DrawRectangle(SFXRectangle(30, 20, 40, 10).Inflate(5, 10));