00001 //------------------------------------------------------------------------------ 00002 // Lamp : Open source game middleware 00003 // Copyright (C) 2004 Junpei Ohtani ( Email : junpee@users.sourceforge.jp ) 00004 // 00005 // This library is free software; you can redistribute it and/or 00006 // modify it under the terms of the GNU Lesser General Public 00007 // License as published by the Free Software Foundation; either 00008 // version 2.1 of the License, or (at your option) any later version. 00009 // 00010 // This library is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 // Lesser General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU Lesser General Public 00016 // License along with this library; if not, write to the Free Software 00017 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00018 //------------------------------------------------------------------------------ 00019 00020 /** @file 00021 * 整数矩形ヘッダ 00022 * @author Junpee 00023 */ 00024 00025 #ifndef RECTANGLE_I_H_ 00026 #define RECTANGLE_I_H_ 00027 00028 namespace Lamp{ 00029 00030 class RectangleF; 00031 00032 //------------------------------------------------------------------------------ 00033 /** 00034 * 整数矩形 00035 * 00036 * このクラスは継承しないで下さい。 00037 */ 00038 class RectangleI{ 00039 public: 00040 //-------------------------------------------------------------------------- 00041 // メンバ変数 00042 //-------------------------------------------------------------------------- 00043 /// メンバ変数 00044 union{ 00045 /// 各要素 00046 struct{ 00047 /// X値 00048 int x; 00049 /// Y値 00050 int y; 00051 /// 幅 00052 int width; 00053 /// 高さ 00054 int height; 00055 }; 00056 00057 /// 配列 00058 int array[4]; 00059 }; 00060 00061 //-------------------------------------------------------------------------- 00062 // 定数 00063 //-------------------------------------------------------------------------- 00064 /// ゼロ矩形 00065 static const RectangleI zero; 00066 00067 /// 単位矩形 00068 static const RectangleI unit; 00069 00070 //-------------------------------------------------------------------------- 00071 // コンストラクタ 00072 //-------------------------------------------------------------------------- 00073 /** 00074 * コンストラクタ 00075 * 00076 * このコンストラクタは初期値の設定を行わないため値は不定です。 00077 */ 00078 RectangleI(){} 00079 00080 /** 00081 * コンストラクタ 00082 * @param sourceX X値の初期値 00083 * @param sourceY Y値の初期値 00084 * @param sourceWidth 幅の初期値 00085 * @param sourceHeight 高さの初期値 00086 */ 00087 RectangleI(int sourceX, int sourceY, int sourceWidth, int sourceHeight) : 00088 x(sourceX), y(sourceY), width(sourceWidth), height(sourceHeight){} 00089 00090 /** 00091 * コンストラクタ 00092 * @param sourceArray 初期値配列 00093 */ 00094 explicit RectangleI(int sourceArray[4]) : 00095 x(sourceArray[0]), y(sourceArray[1]), 00096 width(sourceArray[2]), height(sourceArray[3]){} 00097 00098 /** 00099 * コンストラクタ 00100 * @param source 設定する矩形 00101 */ 00102 explicit RectangleI(const RectangleF& source); 00103 00104 //-------------------------------------------------------------------------- 00105 // 値の設定 00106 //-------------------------------------------------------------------------- 00107 /** 00108 * 値の設定 00109 * @param sourceX X値の設定値 00110 * @param sourceY Y値の設定値 00111 * @param sourceWidth 幅の設定値 00112 * @param sourceHeight 高さの設定値 00113 */ 00114 inline void set(int sourceX, int sourceY, int sourceWidth, int sourceHeight){ 00115 x = sourceX; 00116 y = sourceY; 00117 width = sourceWidth; 00118 height = sourceHeight; 00119 } 00120 00121 /** 00122 * 値の設定 00123 * @param sourceArray 設定値配列 00124 */ 00125 inline void set(int sourceArray[4]){ 00126 x = sourceArray[0]; 00127 y = sourceArray[1]; 00128 width = sourceArray[2]; 00129 height = sourceArray[3]; 00130 } 00131 00132 /** 00133 * 値の設定 00134 * @param source 設定する矩形 00135 */ 00136 void set(const RectangleF& source); 00137 00138 //-------------------------------------------------------------------------- 00139 // 論理演算 00140 //-------------------------------------------------------------------------- 00141 /** 00142 * 同じ値かどうか 00143 * @param target 比較する矩形 00144 * @return 同じ値であればtrueを返す 00145 */ 00146 inline bool operator ==(const RectangleI& target) const{ 00147 return ((x == target.x) && (y == target.y) && 00148 (width == target.width) && (height == target.height)); 00149 } 00150 00151 /** 00152 * 同じ値でないかどうか 00153 * @param target 比較する矩形 00154 * @return 同じ値でなければtrueを返す 00155 */ 00156 inline bool operator !=(const RectangleI& target) const{ 00157 return ((x != target.x) || (y != target.y) || 00158 (width != target.width) || (height != target.height)); 00159 } 00160 00161 //-------------------------------------------------------------------------- 00162 // その他 00163 //-------------------------------------------------------------------------- 00164 /** 00165 * 文字列化 00166 * @return 矩形の文字列表記 00167 */ 00168 inline String toString() const{ 00169 String returnString; 00170 returnString.format("( %d, %d, %d, %d )", x, y, width, height); 00171 return returnString; 00172 } 00173 00174 }; 00175 00176 //------------------------------------------------------------------------------ 00177 } // End of namespace Lamp 00178 #endif // End of RECTANGLE_I_H_ 00179 //------------------------------------------------------------------------------