Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2011
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.08 KB | None | 0 0
  1. #include "../include/gui/Defines.hpp"
  2. #include <sstream>
  3. #include <iostream>
  4.  
  5. namespace gui {
  6.  
  7.     bool IsCollision( const Rect& first, const Rect& second )
  8.     {
  9.         return (    first.x < second.x + second.w &&
  10.             first.x + first.w > second.x  &&
  11.             first.y < second.y + second.h &&
  12.             first.y + first.h > second.y        
  13.             ); 
  14.     }
  15.     Rect::operator sf::IntRect() const
  16.     {
  17.         sf::IntRect temp;
  18.  
  19.         temp.Left = x; temp.Top = y;
  20.         temp.Right = x+w; temp.Bottom = y+h;
  21.  
  22.         return temp;
  23.     }
  24.  
  25.     Rect::Rect( int X/*=0*/, int Y/*=0*/,int W/*=0*/, int H/*=0*/ ) :
  26.                 x(X),y(Y), w(W), h(H)
  27.     {
  28.     }
  29.  
  30.     Rect::Rect( const sf::Vector2i& pos, const sf::Vector2i& size )
  31.     {
  32.         x = pos.x;
  33.         y = pos.y;
  34.         w = size.x;
  35.         h = size.y;
  36.     }
  37.  
  38.     Rect::Rect( const sf::Vector2f& pos, const sf::Vector2f& size )
  39.     {
  40.         x = (int)pos.x;
  41.         y = (int)pos.y;
  42.         w = (int)size.x;
  43.         h = (int)size.y;
  44.     }
  45.  
  46.     Rect::Rect( const sf::IntRect& rect )
  47.     {
  48.         x = rect.Left;
  49.         y = rect.Top;
  50.         w = rect.GetWidth();
  51.         h = rect.GetHeight();
  52.     }
  53.  
  54.     Rect::Rect( const Rect& other )
  55.     {
  56.         x = other.x; y = other.y;
  57.         w = other.w; h = other.h;
  58.     }
  59.     const Rect Rect::operator+( const Rect& other ) const
  60.     {
  61.         return Rect(*this) += other;
  62.     }
  63.  
  64.     const Rect Rect::operator+( int panning ) const
  65.     {
  66.         return Rect(x-panning,y-panning,w+panning,h+panning);
  67.     }
  68.     Rect& Rect::operator+=( const Rect& other )
  69.     {
  70.         x += other.x; y += other.y;
  71.         w += other.w; h += other.h;
  72.         return *this;
  73.     }
  74.  
  75.     Rect& Rect::operator-=( const Rect& other )
  76.     {
  77.         x -= other.x; y -= other.y;
  78.         w -= other.w; h -= other.h;
  79.         return *this;
  80.     }
  81.  
  82.     const Rect Rect::operator-( const Rect& other ) const
  83.     {
  84.         return Rect(*this) -= other;
  85.     }
  86.  
  87.     bool Rect::operator==( const Rect& other ) const
  88.     {
  89.         return (x == other.x && y == other.y &&
  90.                 w == other.w && h == other.h);
  91.     }
  92.  
  93.     bool Rect::operator!=( const Rect& other ) const
  94.     {
  95.         return !(*this == other);
  96.     }
  97.  
  98.     bool Rect::operator!() const
  99.     {
  100.         return (x == 0 && y == 0 && w == 0 && h == 0);
  101.     }
  102.  
  103.     Rect& Rect::operator=( const Rect& other )
  104.     {
  105.         x = other.x; y = other.y;
  106.         w = other.w; h = other.h;
  107.         return *this;      
  108.     }
  109.  
  110.     const Rect Rect::operator-( int panning ) const
  111.     {
  112.         return Rect(x+panning, y+panning,w-panning,h-panning);
  113.     }
  114.  
  115.     Rect& Rect::operator-=( int panning )
  116.     {
  117.         x += panning; y += panning;
  118.         w -= panning; h -= panning;
  119.         return *this;
  120.     }
  121.  
  122.     Rect& Rect::operator+=( int panning )
  123.     {
  124.         x -= panning; y -= panning;
  125.         w += panning; h += panning;
  126.         return *this;
  127.     }
  128.  
  129.     void Functor::operator()()
  130.     {
  131.         std::cout << "Debugging Functor()" << std::endl;
  132.     }
  133.  
  134.     std::string ToUpper( const std::string& text )
  135.     {
  136.         std::locale loc;
  137.         std::string temp;
  138.         temp.resize(text.size());
  139.         for(uint32 i=0; i<text.size(); i++) {
  140.             temp[i] = std::toupper(text[i],loc);
  141.         }
  142.         return temp;
  143.     }
  144.  
  145. }   //end of namespace gui
  146.  
  147.  
  148.  
  149. std::ostream& operator<<( std::ostream& os, gui::Rect& rect)
  150. {
  151.     os << "X: " << rect.x << " \t\tY: " << rect.y << std::endl
  152.         << "Width: " << rect.w << " \tHeight: " << rect.h;
  153.  
  154.     return os;
  155. }
  156.  
  157. std::stringstream& operator<<( std::stringstream& ss, gui::Rect& rect )
  158. {
  159.     ss << "X: " << rect.x << " \t\tY: " << rect.y << std::endl
  160.         << "Width: " << rect.w << " \tHeight: " << rect.h;
  161.  
  162.     return ss;
  163. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement