/******************************************************************************** * * * R e c t a n g l e C l a s s * * * ********************************************************************************* * Copyright (C) 1994,2024 by Jeroen van der Zijp. All Rights Reserved. * ********************************************************************************* * This library is free software; you can redistribute it and/or modify * * it under the terms of the GNU Lesser General Public License as published by * * the Free Software Foundation; either version 3 of the License, or * * (at your option) any later version. * * * * This library is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public License * * along with this program. If not, see * ********************************************************************************/ #ifndef FXRECTANGLE_H #define FXRECTANGLE_H #ifndef FXPOINT_H #include "FXPoint.h" #endif namespace FX { /// Rectangle class FXAPI FXRectangle { public: FXshort x; FXshort y; FXshort w; FXshort h; public: /// Constructors FXRectangle(){ } FXRectangle(FXshort xx,FXshort yy,FXshort ww,FXshort hh):x(xx),y(yy),w(ww),h(hh){ } FXRectangle(const FXRectangle& src):x(src.x),y(src.y),w(src.w),h(src.h){ } FXRectangle(const FXPoint& p,const FXSize& s):x(p.x),y(p.y),w(s.w),h(s.h){ } FXRectangle(const FXPoint& topleft,const FXPoint& bottomright):x(topleft.x),y(topleft.y),w(bottomright.x-topleft.x+1),h(bottomright.y-topleft.y+1){ } /// Test if empty FXbool empty() const { return w<=0 || h<=0; } /// Test if zero FXbool operator!() const { return x==0 && y==0 && w==0 && h==0; } /// Equality FXbool operator==(const FXRectangle& r) const { return x==r.x && y==r.y && w==r.w && h==r.h; } FXbool operator!=(const FXRectangle& r) const { return x!=r.x || y!=r.y || w!=r.w || h!=r.h; } /// Point in rectangle FXbool contains(const FXPoint& p) const { return x<=p.x && y<=p.y && p.x>(FXStream& store,FXRectangle& r); } #endif