Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "../include/gui/Defines.hpp"
- #include <sstream>
- #include <iostream>
- namespace gui {
- bool IsCollision( const Rect& first, const Rect& second )
- {
- return ( first.x < second.x + second.w &&
- first.x + first.w > second.x &&
- first.y < second.y + second.h &&
- first.y + first.h > second.y
- );
- }
- Rect::operator sf::IntRect() const
- {
- sf::IntRect temp;
- temp.Left = x; temp.Top = y;
- temp.Right = x+w; temp.Bottom = y+h;
- return temp;
- }
- Rect::Rect( int X/*=0*/, int Y/*=0*/,int W/*=0*/, int H/*=0*/ ) :
- x(X),y(Y), w(W), h(H)
- {
- }
- Rect::Rect( const sf::Vector2i& pos, const sf::Vector2i& size )
- {
- x = pos.x;
- y = pos.y;
- w = size.x;
- h = size.y;
- }
- Rect::Rect( const sf::Vector2f& pos, const sf::Vector2f& size )
- {
- x = (int)pos.x;
- y = (int)pos.y;
- w = (int)size.x;
- h = (int)size.y;
- }
- Rect::Rect( const sf::IntRect& rect )
- {
- x = rect.Left;
- y = rect.Top;
- w = rect.GetWidth();
- h = rect.GetHeight();
- }
- Rect::Rect( const Rect& other )
- {
- x = other.x; y = other.y;
- w = other.w; h = other.h;
- }
- const Rect Rect::operator+( const Rect& other ) const
- {
- return Rect(*this) += other;
- }
- const Rect Rect::operator+( int panning ) const
- {
- return Rect(x-panning,y-panning,w+panning,h+panning);
- }
- Rect& Rect::operator+=( const Rect& other )
- {
- x += other.x; y += other.y;
- w += other.w; h += other.h;
- return *this;
- }
- Rect& Rect::operator-=( const Rect& other )
- {
- x -= other.x; y -= other.y;
- w -= other.w; h -= other.h;
- return *this;
- }
- const Rect Rect::operator-( const Rect& other ) const
- {
- return Rect(*this) -= other;
- }
- bool Rect::operator==( const Rect& other ) const
- {
- return (x == other.x && y == other.y &&
- w == other.w && h == other.h);
- }
- bool Rect::operator!=( const Rect& other ) const
- {
- return !(*this == other);
- }
- bool Rect::operator!() const
- {
- return (x == 0 && y == 0 && w == 0 && h == 0);
- }
- Rect& Rect::operator=( const Rect& other )
- {
- x = other.x; y = other.y;
- w = other.w; h = other.h;
- return *this;
- }
- const Rect Rect::operator-( int panning ) const
- {
- return Rect(x+panning, y+panning,w-panning,h-panning);
- }
- Rect& Rect::operator-=( int panning )
- {
- x += panning; y += panning;
- w -= panning; h -= panning;
- return *this;
- }
- Rect& Rect::operator+=( int panning )
- {
- x -= panning; y -= panning;
- w += panning; h += panning;
- return *this;
- }
- void Functor::operator()()
- {
- std::cout << "Debugging Functor()" << std::endl;
- }
- std::string ToUpper( const std::string& text )
- {
- std::locale loc;
- std::string temp;
- temp.resize(text.size());
- for(uint32 i=0; i<text.size(); i++) {
- temp[i] = std::toupper(text[i],loc);
- }
- return temp;
- }
- } //end of namespace gui
- std::ostream& operator<<( std::ostream& os, gui::Rect& rect)
- {
- os << "X: " << rect.x << " \t\tY: " << rect.y << std::endl
- << "Width: " << rect.w << " \tHeight: " << rect.h;
- return os;
- }
- std::stringstream& operator<<( std::stringstream& ss, gui::Rect& rect )
- {
- ss << "X: " << rect.x << " \t\tY: " << rect.y << std::endl
- << "Width: " << rect.w << " \tHeight: " << rect.h;
- return ss;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement