screen_rect.h

Go to the documentation of this file.
00001 
00002 //            Copyright (C) 2004-2007 by The Allacrost Project
00003 //                         All Rights Reserved
00004 //
00005 // This code is licensed under the GNU GPL version 2. It is free software 
00006 // and you may modify it and/or redistribute it under the terms of this license.
00007 // See http://www.gnu.org/copyleft/gpl.html for details.
00009 
00017 #ifndef __SCREEN_RECT_HEADER__
00018 #define __SCREEN_RECT_HEADER__
00019 
00020 #include "defs.h"
00021 #include "utils.h"
00022 
00023 namespace hoa_video {
00024 
00032 class ScreenRect {
00033 public: 
00034   ScreenRect()
00035     {}
00036   ScreenRect(int32 l, int32 t, int32 w, int32 h)
00037     : left(l), top(t), width(w), height(h) {}
00038 
00047   void Intersect(const ScreenRect &rect)
00048   {
00049     // Find max left and top coordinates
00050     if (rect.left > left)
00051       left = rect.left;
00052     if (rect.top > top)
00053       top = rect.top;
00054 
00055     // Find min right and bottom coordinates
00056     int32 right = left + width - 1;
00057     int32 bottom = top + height - 1;
00058     if (rect.left + rect.width - 1 < right)
00059       right = rect.left + rect.width - 1;
00060     if (rect.top + rect.height - 1 < bottom)
00061       bottom = rect.top + rect.height - 1;
00062 
00063     if (left > right || top > bottom) {
00064       left = right = width = height = 0;
00065     }
00066     else {
00067       width = right - left + 1;
00068       height = bottom - top + 1;
00069     }
00070   }
00071 
00073   int32 left, top;
00074 
00076   int32 width, height;
00077 }; // class ScreenRect
00078 
00079 }  // namespace hoa_video
00080 
00081 #endif // __SCREEN_RECT_HEADER__

Generated on Fri Jul 6 23:11:21 2007 for Hero of Allacrost by  doxygen 1.5.1