00001 /************************************************************************ 00002 filename: CEGUIColourRect.cpp 00003 created: 8/3/2004 00004 author: Paul D Turner 00005 00006 purpose: Implements ColourRect class 00007 *************************************************************************/ 00008 /************************************************************************* 00009 Crazy Eddie's GUI System (http://www.cegui.org.uk) 00010 Copyright (C)2004 - 2005 Paul D Turner (paul@cegui.org.uk) 00011 00012 This library is free software; you can redistribute it and/or 00013 modify it under the terms of the GNU Lesser General Public 00014 License as published by the Free Software Foundation; either 00015 version 2.1 of the License, or (at your option) any later version. 00016 00017 This library is distributed in the hope that it will be useful, 00018 but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00020 Lesser General Public License for more details. 00021 00022 You should have received a copy of the GNU Lesser General Public 00023 License along with this library; if not, write to the Free Software 00024 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00025 *************************************************************************/ 00026 #include "CEGUIColourRect.h" 00027 00028 00029 // Start of CEGUI namespace section 00030 namespace CEGUI 00031 { 00032 /************************************************************************* 00033 Constructor 00034 *************************************************************************/ 00035 ColourRect::ColourRect(const colour& top_left, const colour& top_right, const colour& bottom_left, const colour& bottom_right) : 00036 d_top_left(top_left), 00037 d_top_right(top_right), 00038 d_bottom_left(bottom_left), 00039 d_bottom_right(bottom_right) 00040 { 00041 } 00042 00043 00044 /************************************************************************* 00045 Constructor for ColourRect objects (via single colour). 00046 *************************************************************************/ 00047 ColourRect::ColourRect(const colour& col) : 00048 d_top_left(col), 00049 d_top_right(col), 00050 d_bottom_left(col), 00051 d_bottom_right(col) 00052 { 00053 } 00054 00055 00056 /************************************************************************* 00057 Default constructor 00058 *************************************************************************/ 00059 ColourRect::ColourRect(void) : 00060 d_top_left(), 00061 d_top_right(), 00062 d_bottom_left(), 00063 d_bottom_right() 00064 { 00065 } 00066 00067 00068 /************************************************************************* 00069 Set the alpha value to use for all four corners of the ColourRect. 00070 *************************************************************************/ 00071 void ColourRect::setAlpha(float alpha) 00072 { 00073 d_top_left.setAlpha(alpha); 00074 d_top_right.setAlpha(alpha); 00075 d_bottom_left.setAlpha(alpha); 00076 d_bottom_right.setAlpha(alpha); 00077 } 00078 00079 00080 /************************************************************************* 00081 Set the alpha value to use for the top edge of the ColourRect. 00082 *************************************************************************/ 00083 void ColourRect::setTopAlpha(float alpha) 00084 { 00085 d_top_left.setAlpha(alpha); 00086 d_top_right.setAlpha(alpha); 00087 } 00088 00089 00090 /************************************************************************* 00091 Set the alpha value to use for the bottom edge of the ColourRect. 00092 *************************************************************************/ 00093 void ColourRect::setBottomAlpha(float alpha) 00094 { 00095 d_bottom_left.setAlpha(alpha); 00096 d_bottom_right.setAlpha(alpha); 00097 } 00098 00099 00100 /************************************************************************* 00101 Set the alpha value to use for the left edge of the ColourRect. 00102 *************************************************************************/ 00103 void ColourRect::setLeftAlpha(float alpha) 00104 { 00105 d_top_left.setAlpha(alpha); 00106 d_bottom_left.setAlpha(alpha); 00107 } 00108 00109 00110 /************************************************************************* 00111 Set the alpha value to use for the right edge of the ColourRect. 00112 *************************************************************************/ 00113 void ColourRect::setRightAlpha(float alpha) 00114 { 00115 d_top_right.setAlpha(alpha); 00116 d_bottom_right.setAlpha(alpha); 00117 } 00118 00119 /************************************************************************* 00120 Determinate whehter the ColourRect is monochromatic or variegated 00121 *************************************************************************/ 00122 bool ColourRect::isMonochromatic() const 00123 { 00124 return d_top_left == d_top_right && 00125 d_top_left == d_bottom_left && 00126 d_top_left == d_bottom_right; 00127 } 00128 00129 /************************************************************************* 00130 Get the colour at a specified point 00131 *************************************************************************/ 00132 colour ColourRect::getColourAtPoint( float x, float y ) const 00133 { 00134 colour h1((d_top_right - d_top_left) * x + d_top_left); 00135 colour h2((d_bottom_right - d_bottom_left) * x + d_bottom_left); 00136 return colour((h2 - h1) * y + h1); 00137 } 00138 00139 /************************************************************************* 00140 Get a ColourRectangle from the specified Region 00141 *************************************************************************/ 00142 ColourRect ColourRect::getSubRectangle( float left, float right, float top, float bottom ) const 00143 { 00144 return ColourRect( 00145 getColourAtPoint(left, top), 00146 getColourAtPoint(right, top), 00147 getColourAtPoint(left, bottom), 00148 getColourAtPoint(right, bottom) 00149 ); 00150 } 00151 00152 00153 /************************************************************************* 00154 Set the colour of all four corners simultaneously. 00155 *************************************************************************/ 00156 void ColourRect::setColours(const colour& col) 00157 { 00158 d_top_left = d_top_right = d_bottom_left = d_bottom_right = col; 00159 } 00160 00161 00162 /************************************************************************* 00163 Module the alpha components of each corner's colour by a constant. 00164 *************************************************************************/ 00165 void ColourRect::modulateAlpha(float alpha) 00166 { 00167 d_top_left.setAlpha(d_top_left.getAlpha()*alpha); 00168 d_top_right.setAlpha(d_top_right.getAlpha()*alpha); 00169 d_bottom_left.setAlpha(d_bottom_left.getAlpha()*alpha); 00170 d_bottom_right.setAlpha(d_bottom_right.getAlpha()*alpha); 00171 } 00172 00173 /************************************************************************* 00174 Modulate all components of this colour rect with corresponding 00175 components from another colour rect. 00176 *************************************************************************/ 00177 ColourRect& ColourRect::operator *=(const ColourRect& other) 00178 { 00179 d_top_left *= other.d_top_left; 00180 d_top_right *= other.d_top_right; 00181 d_bottom_left *= other.d_bottom_left; 00182 d_bottom_right *= other.d_bottom_right; 00183 00184 return *this; 00185 } 00186 00187 00188 } // End of CEGUI namespace section