ManaPlus
Public Member Functions | Data Fields
Rect Class Reference

#include <rect.h>

Inheritance diagram for Rect:
ClipRect

Public Member Functions

 Rect ()
 
 Rect (const int x_, const int y_, const int width_, const int height_)
 
 Rect (const Rect &r)
 
Rectoperator= (const Rect &r)
 
virtual ~Rect ()
 
void setAll (const int x0, const int y0, const int width0, const int height0)
 
bool isIntersecting (const Rect &rectangle) const
 
bool isPointInRect (const int x_, const int y_) const
 

Data Fields

int x
 
int y
 
int width
 
int height
 

Detailed Description

Represents a rectangle.

Definition at line 72 of file rect.h.

Constructor & Destructor Documentation

◆ Rect() [1/3]

Rect::Rect ( )
inline

Constructor. The default rectangle is an empty rectangle at the coordinates (0,0).

Definition at line 79 of file rect.h.

79  :
80  x(0),
81  y(0),
82  width(0),
83  height(0)
84  {
85  }
int width
Definition: rect.h:218
int x
Definition: rect.h:208
int y
Definition: rect.h:213
int height
Definition: rect.h:223

◆ Rect() [2/3]

Rect::Rect ( const int  x_,
const int  y_,
const int  width_,
const int  height_ 
)
inline

Constructor.

Parameters
x_The x coordinate of the rectangle.
y_The y coordinate of the rectangle.
width_The width of the rectangle.
height_The height of the rectangle.

Definition at line 95 of file rect.h.

98  :
99  x(x_),
100  y(y_),
101  width(width_),
102  height(height_)
103  {
104  }
int width
Definition: rect.h:218
int x
Definition: rect.h:208
int y
Definition: rect.h:213
int height
Definition: rect.h:223

◆ Rect() [3/3]

Rect::Rect ( const Rect r)
inline

Definition at line 106 of file rect.h.

References A_DEFAULT_COPY.

106  :
107  x(r.x),
108  y(r.y),
109  width(r.width),
110  height(r.height)
111  {
112  }
int width
Definition: rect.h:218
int x
Definition: rect.h:208
int y
Definition: rect.h:213
int height
Definition: rect.h:223

◆ ~Rect()

virtual Rect::~Rect ( )
inlinevirtual

Definition at line 125 of file rect.h.

126  { }

Member Function Documentation

◆ isIntersecting()

bool Rect::isIntersecting ( const Rect rectangle) const
inline

Checks if another rectangle intersects with the rectangle.

Parameters
rectangleAnother rectangle to check for intersection.
Returns
True if the rectangles intersect, false otherwise.

Definition at line 153 of file rect.h.

References height, width, x, and y.

Referenced by SDLGraphics::fillRectangle().

154  {
155  int x_ = x;
156  int y_ = y;
157  int width_ = width;
158  int height_ = height;
159 
160  x_ -= rectangle.x;
161  y_ -= rectangle.y;
162 
163  if (x_ < 0)
164  {
165  width_ += x_;
166  }
167  else if (x_ + width_ > rectangle.width)
168  {
169  width_ = rectangle.width - x_;
170  }
171 
172  if (y_ < 0)
173  {
174  height_ += y_;
175  }
176  else if (y_ + height_ > rectangle.height)
177  {
178  height_ = rectangle.height - y_;
179  }
180 
181  if (width_ <= 0 || height_ <= 0)
182  {
183  return false;
184  }
185 
186  return true;
187  }
int width
Definition: rect.h:218
int x
Definition: rect.h:208
int y
Definition: rect.h:213
int height
Definition: rect.h:223

◆ isPointInRect()

bool Rect::isPointInRect ( const int  x_,
const int  y_ 
) const
inline

Checks if a point is inside the rectangle

Parameters
x_The x coordinate of the point.
y_The y coordinate of the point.
Returns
True if the point is inside the rectangle.

Definition at line 196 of file rect.h.

References height, width, x, and y.

Referenced by SDLGraphics::drawPoint(), OutfitWindow::getIndexFromGrid(), ShortcutContainer::getIndexFromGrid(), EquipmentWindow::getItem(), Window::getResizeHandles(), GuiTable::getWidgetAt(), BasicContainer::getWidgetAt(), Gui::handleMouseMoved(), EquipmentWindow::mousePressed(), Window::mousePressed(), EquipmentWindow::mouseReleased(), and TouchManager::processEvent().

198  {
199  return x_ >= x
200  && y_ >= y
201  && x_ < x + width
202  && y_ < y + height;
203  }
int width
Definition: rect.h:218
int x
Definition: rect.h:208
int y
Definition: rect.h:213
int height
Definition: rect.h:223

◆ operator=()

Rect& Rect::operator= ( const Rect r)
inline

Definition at line 116 of file rect.h.

References height, width, x, and y.

117  {
118  x = r.x;
119  y = r.y;
120  width = r.width;
121  height = r.height;
122  return *this;
123  }
int width
Definition: rect.h:218
int x
Definition: rect.h:208
int y
Definition: rect.h:213
int height
Definition: rect.h:223

◆ setAll()

void Rect::setAll ( const int  x0,
const int  y0,
const int  width0,
const int  height0 
)
inline

Sets the dimension of a rectangle.

Parameters
x0The x coordinate of the rectangle.
y0The y coordinate of the rectangle.
width0The width of the rectangle.
height0The height of the rectangle.

Definition at line 136 of file rect.h.

References height, width, x, and y.

140  {
141  x = x0;
142  y = y0;
143  width = width0;
144  height = height0;
145  }
int width
Definition: rect.h:218
int x
Definition: rect.h:208
int y
Definition: rect.h:213
int height
Definition: rect.h:223

Field Documentation

◆ height

int Rect::height

Holds the height of the rectangle.

Definition at line 223 of file rect.h.

Referenced by Window::adjustPositionAfterResize(), PopupList::adjustSize(), TabbedArea::adjustSize(), Window::adjustSizeToScreen(), ChatWindow::adjustTabSize(), ScrollArea::calcHBar(), ScrollArea::calcHMarker(), ScrollArea::calcVBar(), ScrollArea::calcVMarker(), DebugWindow::DebugWindow(), ProgressIndicator::draw(), DebugWindow::draw(), Desktop::draw(), DropDown::draw(), Icon::draw(), ProgressBar::draw(), PlayerBox::draw(), Popup::draw(), TextPreview::draw(), StaticBrowserBox::draw(), Tab::draw(), BrowserBox::draw(), Label::draw(), GuiTable::draw(), Slider::draw(), Window::draw(), BasicContainer2::draw(), Button::draw(), Minimap::draw2(), DropDown::drawButton(), TextField::drawCaret(), BasicContainer::drawChildren(), DropDown::drawFrame(), PlayerBox::drawFrame(), TextField::drawFrame(), ScrollArea::drawFrame(), ScrollArea::drawHBar(), SDLGraphics::drawHLine(), ScrollArea::drawHMarker(), TouchManager::drawText(), ScrollArea::drawVBar(), ScrollArea::drawVMarker(), DropDown::dropDown(), Window::ensureOnScreen(), SDLGraphics::fillRectangle(), MiniStatusWindow::getChildrenArea(), GuiTable::getChildrenArea(), BasicContainer::getChildrenArea(), DropDown::getChildrenArea(), Popup::getChildrenArea(), ScrollArea::getChildrenArea(), Window::getChildrenArea(), ScrollArea::getDownButtonDimension(), Widget::getHeight(), ScrollArea::getHorizontalBarDimension(), ScrollArea::getHorizontalMarkerDimension(), EmotePage::getIndexFromGrid(), ScrollArea::getLeftButtonDimension(), Window::getResizeHandles(), ScrollArea::getRightButtonDimension(), ScrollArea::getVerticalBarDimension(), ScrollArea::getVerticalMarkerDimension(), ScrollArea::getVerticalMaxScroll(), Window::getWindowArea(), isIntersecting(), isPointInRect(), TextBox::keyPressed(), Window::loadWindowState(), ScrollArea::logic(), Slider::markerPositionToValue(), Slider::mouseDragged(), ScrollArea::mouseDragged(), Window::mouseDragged(), Slider::mousePressed(), DropDown::mouseReleased(), operator=(), MobileOpenGL2Graphics::popClipArea(), MobileOpenGLGraphics::popClipArea(), ModernOpenGLGraphics::popClipArea(), SafeOpenGLGraphics::popClipArea(), NormalOpenGLGraphics::popClipArea(), Popup::position(), EquipmentWindow::postInit(), MobileOpenGLGraphics::pushClipArea(), MobileOpenGL2Graphics::pushClipArea(), NormalOpenGLGraphics::pushClipArea(), SafeOpenGLGraphics::pushClipArea(), ModernOpenGLGraphics::pushClipArea(), Graphics::pushClipArea(), Window::redraw(), CharacterViewSmall::resize(), ProgressIndicator::safeDraw(), DebugWindow::safeDraw(), Icon::safeDraw(), ProgressBar::safeDraw(), Popup::safeDraw(), Tab::safeDraw(), GuiTable::safeDraw(), Slider::safeDraw(), Window::safeDraw(), BasicContainer2::safeDraw(), Button::safeDraw(), BasicContainer::safeDrawChildren(), DropDown::safeDrawFrame(), PlayerBox::safeDrawFrame(), TextField::safeDrawFrame(), ScrollArea::safeDrawFrame(), Window::saveWindowState(), ChatTab::scroll(), TextBox::scrollToCaret(), NpcSellDialog::sellOneItem(), setAll(), Desktop::setBestFittingWallpaper(), Window::setDefaultSize(), Widget::setDimension(), Widget::setHeight(), Popup::setLocationRelativeTo(), Window::setLocationRelativeTo(), Minimap::setMap(), Window::setResizable(), ListBox::setSelected(), Widget::setSize(), Window::setVisible(), PopupList::show(), TextBoxPopup::show(), TextPopup::show(), BasicContainer::showWidgetPart(), ScrollArea::updateCalcFlag(), SliderList::updateLabel(), WhoIsOnline::updateSize(), Slider::valueToMarkerPosition(), SpellPopup::view(), DebugWindow::widgetResized(), EmoteWindow::widgetResized(), SetupWindow::widgetResized(), LayoutHelper::widgetResized(), Window::widgetResized(), ScrollArea::widgetResized(), and TabbedArea::widgetResized().

◆ width

int Rect::width

Holds the width of the rectangle.

Definition at line 218 of file rect.h.

Referenced by VertContainer::add2(), Window::adjustPositionAfterResize(), PopupList::adjustSize(), TabbedArea::adjustSize(), Window::adjustSizeToScreen(), ChatWindow::adjustTabSize(), ScrollArea::calcHBar(), BrowserBox::calcHeight(), ScrollArea::calcHMarker(), ScrollArea::calcVBar(), ScrollArea::calcVMarker(), DebugWindow::DebugWindow(), ColorPage::draw(), EmotePage::draw(), ExtendedListBox::draw(), ProgressIndicator::draw(), DebugWindow::draw(), SliderList::draw(), ShopListBox::draw(), Desktop::draw(), Icon::draw(), DropDown::draw(), ProgressBar::draw(), PlayerBox::draw(), Popup::draw(), TextPreview::draw(), StaticBrowserBox::draw(), ListBox::draw(), Tab::draw(), BrowserBox::draw(), Label::draw(), GuiTable::draw(), Window::draw(), BasicContainer2::draw(), Button::draw(), Minimap::draw2(), DropDown::drawButton(), BasicContainer::drawChildren(), DropDown::drawFrame(), PlayerBox::drawFrame(), TextField::drawFrame(), ScrollArea::drawFrame(), ScrollArea::drawHBar(), SDLGraphics::drawHLine(), ScrollArea::drawHMarker(), TouchManager::drawText(), ScrollArea::drawVBar(), ScrollArea::drawVMarker(), DropDown::dropDown(), Window::ensureOnScreen(), SDLGraphics::fillRectangle(), TextField::fixScroll(), MiniStatusWindow::getChildrenArea(), GuiTable::getChildrenArea(), BasicContainer::getChildrenArea(), DropDown::getChildrenArea(), Popup::getChildrenArea(), ScrollArea::getChildrenArea(), Window::getChildrenArea(), ScrollArea::getDownButtonDimension(), ScrollArea::getHorizontalBarDimension(), ScrollArea::getHorizontalMarkerDimension(), ScrollArea::getHorizontalMaxScroll(), EmotePage::getIndexFromGrid(), Window::getResizeHandles(), ScrollArea::getRightButtonDimension(), ItemContainer::getSlotByXY(), ItemContainer::getSlotIndex(), ScrollArea::getUpButtonDimension(), ScrollArea::getVerticalBarDimension(), ScrollArea::getVerticalMarkerDimension(), Widget::getWidth(), Window::getWindowArea(), isIntersecting(), isPointInRect(), Window::loadWindowState(), ScrollArea::logic(), Slider::markerPositionToValue(), ScrollArea::mouseDragged(), Window::mouseDragged(), Slider::mousePressed(), DropDown::mouseReleased(), operator=(), MobileOpenGL2Graphics::popClipArea(), MobileOpenGLGraphics::popClipArea(), ModernOpenGLGraphics::popClipArea(), NormalOpenGLGraphics::popClipArea(), SafeOpenGLGraphics::popClipArea(), Popup::position(), EquipmentWindow::postInit(), ModernOpenGLGraphics::pushClipArea(), NormalOpenGLGraphics::pushClipArea(), MobileOpenGL2Graphics::pushClipArea(), MobileOpenGLGraphics::pushClipArea(), SafeOpenGLGraphics::pushClipArea(), Graphics::pushClipArea(), Window::redraw(), CharacterViewSmall::resize(), EmotePage::safeDraw(), ProgressIndicator::safeDraw(), DebugWindow::safeDraw(), SliderList::safeDraw(), Icon::safeDraw(), ProgressBar::safeDraw(), Popup::safeDraw(), Tab::safeDraw(), GuiTable::safeDraw(), Window::safeDraw(), BasicContainer2::safeDraw(), Button::safeDraw(), BasicContainer::safeDrawChildren(), DropDown::safeDrawFrame(), PlayerBox::safeDrawFrame(), TextField::safeDrawFrame(), ScrollArea::safeDrawFrame(), Window::saveWindowState(), TextBox::scrollToCaret(), setAll(), Desktop::setBestFittingWallpaper(), Window::setDefaultSize(), Widget::setDimension(), Window::setLocationHorisontallyRelativeTo(), Popup::setLocationRelativeTo(), Window::setLocationRelativeTo(), Minimap::setMap(), Window::setResizable(), Widget::setSize(), Window::setVisible(), Widget::setWidth(), PopupList::show(), TextBoxPopup::show(), TextPopup::show(), BasicContainer::showWidgetPart(), TabbedArea::updateArrowEnableState(), ScrollArea::updateCalcFlag(), StaticBrowserBox::updateHeight(), BrowserBox::updateHeight(), SliderList::updateLabel(), WhoIsOnline::updateSize(), ItemContainer::updateSize(), Slider::valueToMarkerPosition(), SpellPopup::view(), ShortcutContainer::widgetResized(), DebugWindow::widgetResized(), EmoteWindow::widgetResized(), SetupWindow::widgetResized(), LayoutHelper::widgetResized(), Window::widgetResized(), ScrollArea::widgetResized(), and TabbedArea::widgetResized().

◆ x

int Rect::x

Holds the x coordinate of the rectangle.

Definition at line 208 of file rect.h.

Referenced by Window::adjustPositionAfterResize(), Window::adjustSizeToScreen(), ScrollArea::calcButton(), ScrollArea::calcHBar(), ScrollArea::calcHMarker(), ScrollArea::calcVBar(), ScrollArea::calcVMarker(), Window::draw(), ScrollArea::drawButton(), BasicContainer::drawChildren(), ScrollArea::drawHBar(), SDLGraphics::drawHLine(), ScrollArea::drawHMarker(), SDLGraphics::drawImageCached(), SDLGraphics::drawImageInline(), ModernOpenGLGraphics::drawRectangle(), ScrollArea::drawVBar(), ScrollArea::drawVMarker(), Window::ensureOnScreen(), SDLGraphics::fillRectangle(), ModernOpenGLGraphics::fillRectangle(), Widget::getAbsolutePosition(), Window::getResizeHandles(), BasicContainer::getWidgetAt(), Widget::getX(), isIntersecting(), isPointInRect(), Window::isResizeAllowed(), Window::loadWindowState(), ScrollArea::mouseDragged(), Window::mouseDragged(), WindowMenu::mouseMoved(), Minimap::mouseMoved(), MiniStatusWindow::mouseMoved(), InventoryWindow::mouseMoved(), ScrollArea::mousePressed(), operator=(), MobileOpenGL2Graphics::popClipArea(), ModernOpenGLGraphics::popClipArea(), MobileOpenGLGraphics::popClipArea(), NormalOpenGLGraphics::popClipArea(), SafeOpenGLGraphics::popClipArea(), SafeOpenGLGraphics::pushClipArea(), ModernOpenGLGraphics::pushClipArea(), MobileOpenGL2Graphics::pushClipArea(), MobileOpenGLGraphics::pushClipArea(), NormalOpenGLGraphics::pushClipArea(), Graphics::pushClipArea(), TouchManager::resize(), Window::safeDraw(), BasicContainer::safeDrawChildren(), Window::saveWindowState(), Minimap::screenToMap(), TextBox::scrollToCaret(), setAll(), Window::setDefaultSize(), Widget::setDimension(), Window::setLocationHorisontallyRelativeTo(), Popup::setLocationRelativeTo(), Window::setLocationRelativeTo(), Minimap::setMap(), Widget::setPosition(), Window::setResizable(), Widget::setX(), and Window::widgetResized().

◆ y

int Rect::y

Holds the x coordinate of the rectangle.

Definition at line 213 of file rect.h.

Referenced by Window::adjustPositionAfterResize(), Window::adjustSizeToScreen(), ScrollArea::calcButton(), ScrollArea::calcHBar(), ScrollArea::calcHMarker(), ScrollArea::calcVBar(), ScrollArea::calcVMarker(), StaticBrowserBox::draw(), BrowserBox::draw(), GuiTable::draw(), Window::draw(), ScrollArea::drawButton(), BasicContainer::drawChildren(), ScrollArea::drawHBar(), SDLGraphics::drawHLine(), ScrollArea::drawHMarker(), ScrollArea::drawVBar(), ScrollArea::drawVMarker(), Window::ensureOnScreen(), SDLGraphics::fillRectangle(), Widget::getAbsolutePosition(), Window::getResizeHandles(), BasicContainer::getWidgetAt(), Widget::getY(), isIntersecting(), isPointInRect(), Window::isResizeAllowed(), Window::loadWindowState(), ScrollArea::mouseDragged(), Window::mouseDragged(), WindowMenu::mouseMoved(), Minimap::mouseMoved(), MiniStatusWindow::mouseMoved(), InventoryWindow::mouseMoved(), ScrollArea::mousePressed(), operator=(), SafeOpenGLGraphics::popClipArea(), NormalOpenGLGraphics::popClipArea(), MobileOpenGL2Graphics::popClipArea(), MobileOpenGLGraphics::popClipArea(), ModernOpenGLGraphics::popClipArea(), NormalOpenGLGraphics::pushClipArea(), MobileOpenGLGraphics::pushClipArea(), SafeOpenGLGraphics::pushClipArea(), ModernOpenGLGraphics::pushClipArea(), MobileOpenGL2Graphics::pushClipArea(), Graphics::pushClipArea(), TouchManager::resize(), GuiTable::safeDraw(), Window::safeDraw(), BasicContainer::safeDrawChildren(), Window::saveWindowState(), Minimap::screenToMap(), ChatTab::scroll(), TextBox::scrollToCaret(), NpcSellDialog::sellOneItem(), setAll(), Window::setDefaultSize(), Widget::setDimension(), Popup::setLocationRelativeTo(), Window::setLocationRelativeTo(), Minimap::setMap(), Widget::setPosition(), Window::setResizable(), ListBox::setSelected(), Widget::setY(), and Window::widgetResized().


The documentation for this class was generated from the following file: