Class catan.gui.Box
A rectangle with width, height, and (x, y)
coordinates.
-- (0, 0) (5, 0) -- o-----------o -- | | -- | | -- o-----------o -- (0, 4) (5, 4) local box = Box:new{w=5, h=4, x=0, y=0} print(box:getWidth()) --> 5 print(box:getHeight()) --> 4 print(box:getLeftX()) --> 0 print(box:getRightX()) --> 5 print(box:getTopY()) --> 0 print(box:getBottomY()) --> 4 -- (-10, 20) (15, 20) -- o--------------------o -- | | -- | | -- | | -- | | -- o--------------------o -- (-10, 24) (15, 24) local biggerBox = box:grow(20, 40) print(biggerBox:getWidth()) --> 25 print(biggerBox:getHeight()) --> 44 print(biggerBox:getLeftX()) --> -10 print(biggerBox:getRightX()) --> 15 print(biggerBox:getTopY()) --> 20 print(biggerBox:getBottomY()) --> 24 -- (0, 0) (5, 0) (0, 0) (12, 0) -- o---------------o o-------------------o -- | | | | -- | (4, 2) | (12, 2) | | -- | o------+-------o | | -- | | | | ===> | | -- o--------+------o | | | -- (0, 7) | (5, 7) | | | -- | | | | -- o--------------o o-------------------o -- (4, 10) (12, 10) (0, 10) (12, 10) local box1 = Box:new{w=5, h=7, x=0, y=0} local box2 = Box:new{w=10, h=8, x=4, y=2} local box1u2 = Box:fromUnion(box1, box2) print(box1u2:getWidth()) --> 12 print(box1u2:getHeight()) --> 10 print(box1u2:getLeftX()) --> 0 print(box1u2:getRightX()) --> 12 print(box1u2:getTopY()) --> 0 print(box1u2:getBottomY()) --> 10
Methods
catan.gui.box:new (t) | Create box. |
catan.gui.box:fromSprite (sprite) | Create box from sprite. |
catan.gui.box:fromUnion (...) | Create box from the union of boxes. |
catan.gui.box:grow (dw[, dh=dw]) | Grow a box by width and height. |
catan.gui.box:getWidth () | Get box width. |
catan.gui.box:getHeight () | Get box height. |
catan.gui.box:getLeftX () | Get box left x coordinate. |
catan.gui.box:getRightX () | Get box right x coordinate. |
catan.gui.box:getTopY () | Get box top y coordinate. |
catan.gui.box:getBottomY () | Get box bottom y coordinate. |
Methods
- catan.gui.box:new (t)
-
Create box.
Parameters:
- t box data
- x number x coordinate
- y number y coordinate
- w number width
- h number height
Returns:
-
catan.gui.Box
a newly-created box
- t box data
- catan.gui.box:fromSprite (sprite)
-
Create box from sprite.
Parameters:
- sprite Sprite the sprite
Returns:
-
catan.gui.Box
a newly-created box
- catan.gui.box:fromUnion (...)
-
Create box from the union of boxes.
Must pass at least one box.
Parameters:
- ... catan.gui.Box boxes
Returns:
-
catan.gui.Box
a newly-created box
- catan.gui.box:grow (dw[, dh=dw])
-
Grow a box by width and height.
Parameters:
- dw number amount to increase symmetrically in width
- dh number amount to symmetrically increase in height (default dw)
Returns:
-
catan.gui.Box
a newly-created box
- catan.gui.box:getWidth ()
-
Get box width.
Returns:
-
number
the box width
- catan.gui.box:getHeight ()
-
Get box height.
Returns:
-
number
the box height
- catan.gui.box:getLeftX ()
-
Get box left x coordinate.
Returns:
-
number
the box left x coordinate
- catan.gui.box:getRightX ()
-
Get box right x coordinate.
Returns:
-
number
the box right x coordinate
- catan.gui.box:getTopY ()
-
Get box top y coordinate.
Returns:
-
number
the box top y coordinate
- catan.gui.box:getBottomY ()
-
Get box bottom y coordinate.
Returns:
-
number
the box bottom y coordinate