"Fossies" - the Fresh Open Source Software Archive

Member "tvnserver-2.0.4/region/Rect.h" (3 Aug 2011, 4045 Bytes) of archive /windows/misc/tvnserver-2.0.4-src.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "Rect.h" see the Fossies "Dox" file reference documentation.

    1 // Copyright (C) 2008, 2009, 2010 GlavSoft LLC.
    2 // All rights reserved.
    3 //
    4 //-------------------------------------------------------------------------
    5 // This file is part of the TightVNC software.  Please visit our Web site:
    6 //
    7 //                       http://www.tightvnc.com/
    8 //
    9 // This program is free software; you can redistribute it and/or modify
   10 // it under the terms of the GNU General Public License as published by
   11 // the Free Software Foundation; either version 2 of the License, or
   12 // (at your option) any later version.
   13 //
   14 // This program is distributed in the hope that it will be useful,
   15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
   16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   17 // GNU General Public License for more details.
   18 //
   19 // You should have received a copy of the GNU General Public License along
   20 // with this program; if not, write to the Free Software Foundation, Inc.,
   21 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
   22 //-------------------------------------------------------------------------
   23 //
   24 
   25 #ifndef __RECT_H__
   26 #define __RECT_H__
   27 
   28 #include "util/CommonHeader.h"
   29 
   30 class Rect
   31 {
   32 public:
   33   Rect(void) : left(0), top(0), right(0), bottom(0) {}
   34   Rect(const Rect *rect) { setRect(rect); }
   35   Rect(const Rect &rect) { setRect(&rect); }
   36   Rect(int lt, int tp, int rt, int bm) { setRect(lt, tp, rt, bm); }
   37   Rect(int width, int height) { setRect(0, 0, width, height); }
   38 
   39   virtual ~Rect(void) {}
   40   
   41   int left;
   42   int top;
   43   int right;
   44   int bottom;
   45 
   46   inline void setRect(int lt, int tp, int rt, int bm)
   47   {
   48     left = lt;
   49     top = tp;
   50     right = rt;
   51     bottom = bm;
   52   }
   53 
   54   inline void setRect(const Rect *rect)
   55   {
   56     left    = rect->left;
   57     top     = rect->top;
   58     right   = rect->right;
   59     bottom  = rect->bottom;
   60   }
   61 
   62   inline Rect & operator=(const Rect &rect)
   63   {
   64     setRect(&rect);
   65     return *this;
   66   }
   67 
   68   inline RECT toWindowsRect() const {
   69                                 RECT winRect;
   70                                 winRect.left    = left;
   71                                 winRect.top     = top;
   72                                 winRect.right   = right;
   73                                 winRect.bottom  = bottom;
   74                                 return winRect; } const
   75 
   76   inline void fromWindowsRect(RECT *winRect)
   77   {
   78     left    = winRect->left;
   79     top     = winRect->top;
   80     right   = winRect->right;
   81     bottom  = winRect->bottom;
   82   }
   83 
   84   inline void move(int offsetX, int offsetY)
   85   {
   86     left    += offsetX;
   87     right   += offsetX;
   88     top     += offsetY;
   89     bottom  += offsetY;
   90   }
   91 
   92   inline void setLocation(int destX, int destY)
   93   {
   94     int offsetX = destX - left;
   95     int offsetY = destY - top;
   96     left    = destX;
   97     right   += offsetX;
   98     top     = destY;
   99     bottom  += offsetY;
  100   }
  101 
  102   inline bool isEqualTo(const Rect *rect)  const { return  rect->left == left &&
  103                                                     rect->top == top &&
  104                                                     rect->right == right &&
  105                                                     rect->bottom == bottom; }
  106 
  107   inline void setWidth(int value)   { right = left + value; }
  108   inline void setHeight(int value)  { bottom = top + value; }
  109 
  110   inline int getWidth()  const { return right - left; }
  111   inline int getHeight() const { return bottom - top; }
  112 
  113   inline bool isEmpty() const { return getWidth() <= 0 || getHeight() <= 0; }
  114   inline int area() const { return isEmpty() ? 0 : getWidth() * getHeight(); }
  115 
  116   inline void clear() { left = top = right = bottom = 0; }
  117 
  118   Rect intersection(const Rect *other) const {
  119     Rect result;
  120     result.setRect((left > other->left) ? left : other->left,
  121                    (top > other->top) ? top : other->top,
  122                    (right < other->right) ? right : other->right,
  123                    (bottom < other->bottom) ? bottom : other->bottom);
  124     return result;
  125   }
  126 };
  127 
  128 #endif