SLProject  4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
SLRect< T, V > Class Template Reference

A rectangle template class. More...

#include <SLRect.h>

Public Member Functions

 SLRect ()
 
 SLRect (const T WIDTH, const T HEIGHT)
 
 SLRect (const T X, const T Y, const T WIDTH, const T HEIGHT)
 
 SLRect (const V &tl, const V &br)
 
void set (const T X, const T Y, const T WIDTH, const T HEIGHT)
 
void set (const T v[2])
 
void set (const V tl, const V br)
 
void setZero ()
 
SLbool operator== (const SLRect &r) const
 
SLbool operator!= (const SLRect &r) const
 
SLRectoperator= (const SLRect &r)
 
void tl (V v)
 top-left corner More...
 
void br (V v)
 bottom-right corner More...
 
void setScnd (V v)
 
tl ()
 top-left corner More...
 
br ()
 bottom-right corner More...
 
area ()
 
SLbool isEmpty () const
 
SLbool isZero ()
 
SLbool contains (T X, T Y)
 
SLbool contains (V v)
 
SLbool contains (const SLRect &r)
 
void print (const char *str=nullptr)
 
void drawGL (const SLCol4f &color)
 

Public Attributes

x
 
y
 
width
 
height
 

Private Attributes

SLGLVertexArrayExt _vao
 

Friends

std::ostream & operator<< (std::ostream &output, const SLRect &r)
 

Detailed Description

template<class T, class V>
class SLRect< T, V >

A rectangle template class.

Defines a rectangle with a top-left corner at x,y measured from top-left of the window and with its width and height. It is used e.g. to draw a selection rectangle in SLSceneView::draw2DGL.

Definition at line 26 of file SLRect.h.

Constructor & Destructor Documentation

◆ SLRect() [1/4]

template<class T , class V >
SLRect< T, V >::SLRect ( )
inline

Definition at line 31 of file SLRect.h.

31 {setZero();}
void setZero()
Definition: SLRect.h:49

◆ SLRect() [2/4]

template<class T , class V >
SLRect< T, V >::SLRect ( const T  WIDTH,
const T  HEIGHT 
)
inline

Definition at line 32 of file SLRect.h.

33  {x=0;y=0;width=WIDTH;height=HEIGHT;}
T width
Definition: SLRect.h:29
T y
Definition: SLRect.h:29
T x
Definition: SLRect.h:29
T height
Definition: SLRect.h:29

◆ SLRect() [3/4]

template<class T , class V >
SLRect< T, V >::SLRect ( const T  X,
const T  Y,
const T  WIDTH,
const T  HEIGHT 
)
inline

Definition at line 34 of file SLRect.h.

37  {x=X;y=Y;width=WIDTH;height=HEIGHT;}

◆ SLRect() [4/4]

template<class T , class V >
SLRect< T, V >::SLRect ( const V &  tl,
const V &  br 
)
inline

Definition at line 38 of file SLRect.h.

39  {x=tl.x; y=tl.y;
40  width=br.x-tl.x;
41  height=br.y-tl.y;}
V tl()
top-left corner
Definition: SLRect.h:71
V br()
bottom-right corner
Definition: SLRect.h:72

Member Function Documentation

◆ area()

template<class T , class V >
T SLRect< T, V >::area ( )
inline

Definition at line 73 of file SLRect.h.

73 {return width * height;}

◆ br() [1/2]

template<class T , class V >
V SLRect< T, V >::br ( )
inline

bottom-right corner

Definition at line 72 of file SLRect.h.

◆ br() [2/2]

template<class T , class V >
void SLRect< T, V >::br ( v)
inline

bottom-right corner

Definition at line 64 of file SLRect.h.

◆ contains() [1/3]

template<class T , class V >
SLbool SLRect< T, V >::contains ( const SLRect< T, V > &  r)
inline

Definition at line 78 of file SLRect.h.

78 {return (r.x>=x && r.x<=x+width && r.y>=y && r.y<=y+height && r.width <= width && r.height <= height);}

◆ contains() [2/3]

template<class T , class V >
SLbool SLRect< T, V >::contains ( X,
Y 
)
inline

Definition at line 76 of file SLRect.h.

76 {return (X>=x && X<=x+width && Y>=y && Y<=y+height);}

◆ contains() [3/3]

template<class T , class V >
SLbool SLRect< T, V >::contains ( v)
inline

Definition at line 77 of file SLRect.h.

77 {return (v.x>=x && v.x<=x+width && v.y>=y && v.y<=y+height);}

◆ drawGL()

template<class T , class V >
void SLRect< T, V >::drawGL ( const SLCol4f color)
inline

Definition at line 88 of file SLRect.h.

89  {
90  SLVVec3f P;
91  P.push_back(SLVec3f(x, -y, 0));
92  P.push_back(SLVec3f(x+width,-y, 0));
93  P.push_back(SLVec3f(x+width,-y-height, 0));
94  P.push_back(SLVec3f(x ,-y-height, 0));
97  }
@ PT_lineLoop
Definition: SLGLEnums.h:33
vector< SLVec3f > SLVVec3f
Definition: SLVec3.h:325
SLVec3< SLfloat > SLVec3f
Definition: SLVec3.h:318
void generateVertexPos(SLVVec2f *p)
Adds or updates & generates a position vertex attribute for colored line or point drawing.
void drawArrayAsColored(SLGLPrimitiveType primitiveType, SLCol4f color, SLfloat lineOrPointSize=1.0f, SLuint indexFirstVertex=0, SLuint countVertices=0)
Draws the array as the specified primitive with the color.
SLGLVertexArrayExt _vao
Definition: SLRect.h:100

◆ isEmpty()

template<class T , class V >
SLbool SLRect< T, V >::isEmpty ( ) const
inline

Definition at line 74 of file SLRect.h.

74 {return (width==0 || height==0);} ;

◆ isZero()

template<class T , class V >
SLbool SLRect< T, V >::isZero ( )
inline

Definition at line 75 of file SLRect.h.

75 {return (x==0 && y==0 && width==0 && height==0);}

◆ operator!=()

template<class T , class V >
SLbool SLRect< T, V >::operator!= ( const SLRect< T, V > &  r) const
inline

Definition at line 53 of file SLRect.h.

53 {return (x!=r.x || y!=r.y || width!=r.width || height!=r.height);}

◆ operator=()

template<class T , class V >
SLRect& SLRect< T, V >::operator= ( const SLRect< T, V > &  r)
inline

Definition at line 56 of file SLRect.h.

56 {x=r.x; y=r.y; width=r.width; height=r.height; return *this;}

◆ operator==()

template<class T , class V >
SLbool SLRect< T, V >::operator== ( const SLRect< T, V > &  r) const
inline

Definition at line 52 of file SLRect.h.

52 {return (x==r.x && y==r.y && width==r.width && height==r.height);}

◆ print()

template<class T , class V >
void SLRect< T, V >::print ( const char *  str = nullptr)
inline

Definition at line 80 of file SLRect.h.

81  {
82  if (str)
83  SL_LOG("%s",str);
84  SL_LOG("% 3.1f, % 3.1f, % 3.1f, % 3.1f",x, y, width, height);
85  }
#define SL_LOG(...)
Definition: SL.h:233

◆ set() [1/3]

template<class T , class V >
void SLRect< T, V >::set ( const T  v[2])
inline

Definition at line 46 of file SLRect.h.

46 {x=v[0]; y=v[1];}

◆ set() [2/3]

template<class T , class V >
void SLRect< T, V >::set ( const T  X,
const T  Y,
const T  WIDTH,
const T  HEIGHT 
)
inline

Definition at line 42 of file SLRect.h.

45  {x=X;y=Y;width=WIDTH;height=HEIGHT;}

◆ set() [3/3]

template<class T , class V >
void SLRect< T, V >::set ( const V  tl,
const V  br 
)
inline

Definition at line 47 of file SLRect.h.

48  {tl(tl); br(br);}

◆ setScnd()

template<class T , class V >
void SLRect< T, V >::setScnd ( v)
inline

Definition at line 67 of file SLRect.h.

67  {if (v.x>x) {width =v.x-x;} else {width+=x-v.x; x=v.x;}
68  if (v.y>y) {height=v.y-y;} else {height+=y-v.y; y=v.y;}}

◆ setZero()

template<class T , class V >
void SLRect< T, V >::setZero ( )
inline

Definition at line 49 of file SLRect.h.

49 {x=0; y=0; width=0; height=0;}

◆ tl() [1/2]

template<class T , class V >
V SLRect< T, V >::tl ( )
inline

top-left corner

Definition at line 71 of file SLRect.h.

◆ tl() [2/2]

template<class T , class V >
void SLRect< T, V >::tl ( v)
inline

top-left corner

Definition at line 63 of file SLRect.h.

Friends And Related Function Documentation

◆ operator<<

template<class T , class V >
std::ostream& operator<< ( std::ostream &  output,
const SLRect< T, V > &  r 
)
friend

Definition at line 59 of file SLRect.h.

60  {output<<"["<<r.x<<","<<r.y<<","<<r.width<<","<<r.height<<"]"; return output;}

Member Data Documentation

◆ _vao

template<class T , class V >
SLGLVertexArrayExt SLRect< T, V >::_vao
private

Definition at line 100 of file SLRect.h.

◆ height

template<class T , class V >
T SLRect< T, V >::height

Definition at line 29 of file SLRect.h.

◆ width

template<class T , class V >
T SLRect< T, V >::width

Definition at line 29 of file SLRect.h.

◆ x

template<class T , class V >
T SLRect< T, V >::x

Definition at line 29 of file SLRect.h.

◆ y

template<class T , class V >
T SLRect< T, V >::y

Definition at line 29 of file SLRect.h.


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