Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

Icon.cpp

Go to the documentation of this file.
00001 /*
00002 CS Senior Project 2003
00003 Team : Leftfield
00004 Project : ModernWarfare
00005 Members :
00006 - Russ Christensen              <rchriste@cs.utah.edu>
00007 - Todd Smith                    <tcsmith@cs.utah.edu>
00008 - Usit Duongsaa                 <duongsaa@cs.utah.edu>
00009 Copyright 2003 Russ Christensen, Usit Duongsaa, and Todd Smith. All rights reserved.
00010 
00011 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
00012 
00013 Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 
00014 Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 
00015 THIS SOFTWARE IS PROVIDED BY RUSS CHRISTENSEN, USIT DUONGSAA, AND TODD SMITH ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RUSS, USIT, TODD OR OTHER CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00016 */
00017 
00022 #include "Icon.h"
00023 
00024 Icon::Icon() : Rect(Vec2D(0.0,0.0), Vec2D(0.0,0.0)), 
00025                m_img(0),
00026                m_center(Vec2D(0.0,0.0)), 
00027                m_size(Vec2D(0.0,0.0)) 
00028 {
00029 }
00030 
00031 Icon::Icon(Vec2D& ul, Vec2D& lr, ATexture img) : Rect(ul,lr), m_img(img)
00032 {
00033   m_size.x = m_lr.x - m_ul.x;
00034   m_size.y = m_lr.y - m_ul.y;
00035   m_center.x = m_ul.x + m_size.x/2;
00036   m_center.y = m_ul.y + m_size.y/2;
00037 }
00038 
00039 void Icon::setBounds(const Vec2D& ul, const Vec2D &lr) 
00040 {
00041   m_bounds[0] = m_ul = ul;
00042   m_bounds[1] = m_lr = lr;
00043   m_size.x = m_lr.x - m_ul.x;
00044   m_size.y = m_lr.y - m_ul.y;
00045   m_center.x = m_ul.x + m_size.x/2;
00046   m_center.y = m_ul.y + m_size.y/2;
00047 }
00048 
00049 void Icon::drawOutline( Vec3D color ) const
00050 {
00051         overlay_rect(   bounds()[0], bounds()[1], false, color,
00052                                         BlendModes::NONE, 1.0f, 6 );
00053 }
00054 
00055 void Icon::drawHelpString() const
00056 {
00057         //if( input_mouseIdleTime() < 0.3f ) return;                                    // cursor must be idle at least 0.4 sec
00058 
00059         Vec2D mousePos( input_getMouseX(), input_getMouseY() );
00060         if( !contains(mousePos) ) return;                                                       // cursor must be inside this icon
00061 
00062         string s( m_helpString );
00063         if( s.length()==0 ) s = "No Help Yet\nFix me plz";
00064         int lineCount = 0;
00065         for( UINT i=0; i<s.length(); i++ )
00066                 if( s[i] == '\n' ) lineCount++;
00067         if( s[s.length()-1] != '\n' ) lineCount++;
00068 
00069         FLOAT width  = 0.37f;
00070         FLOAT height = lineCount*0.037f;
00071         Vec2D drawPos( mousePos );                                              // top-left corner of help box
00072         if( mousePos.y > 0.98f-height ) drawPos.y -= height;
00073         if( mousePos.x > 0.98f-width  ) drawPos.x -= width;
00074         Vec2D drawPos2( drawPos+Vec2D(width,height) );  // lower-right corner
00075 
00076         overlay_rect( drawPos, drawPos2, true,  Colors::gray,  BlendModes::MIX,  0.7f, 7 );
00077         overlay_rect( drawPos, drawPos2, false, Colors::white, BlendModes::NONE, 1.0f, 7 );
00078         overlay_text() << s;
00079         overlay_textOut( drawPos+Vec2D(0.003f,0.003f), 1.0f, Colors::white, NULL, 7 );
00080 }

Generated on Wed Apr 23 05:50:15 2003 for Modern Warfare by doxygen1.3-rc2