![[]](/images/special/trans.gif)
LibN2L-4 Library Code ReferenceClassesCompounds Files Members Method Index Full Reference cGuiSpriteMousePointer.cppGo to the documentation of this file.00001 /************************************************************************ 00002 Nova-2 Library (libN2L, or simply n2l) Game development C++ Library 00003 Copyright (C) 2003 Aaron Cameron 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 A copy of the GNU Lesser General Public License has been provided with 00020 this library in the file 'COPYING'. 00021 00022 Contact information for the author of this library has been provided 00023 with this library in the file 'AUTHOR'. 00024 ************************************************************************/ 00025 #include "cGuiSpriteMousePointer.h" 00026 00027 #include "n2l/vfs.h" 00028 #include "n2l/events.h" 00029 #include "n2l/dynVars.h" 00030 #include "n2l/resourceManagement.h" 00031 00032 /******************************************************************************/ 00033 namespace n2l 00034 { 00035 00036 # ifdef N2L_PASSIVE_GUI_REG 00037 tBool cGuiSpriteMousePointer::smRegistered = 00038 cGuiFactory::current().registerLoader( 00039 "n2l::cGuiSpriteMousePointer", 00040 cGuiElement::loadNew<cGuiSpriteMousePointer> ); 00041 # endif 00042 /**************************************************************************/ 00043 cGuiSpriteMousePointer::cGuiSpriteMousePointer() : 00044 cGuiElement( tGuiPos(0,0), tGuiPos(1,1) ), 00045 mState(State_None), 00046 mVisible(true) 00047 { 00048 } 00049 00050 /**************************************************************************/ 00051 cGuiSpriteMousePointer::cGuiSpriteMousePointer( 00052 const cVfsNodeInterface &iNode ) : 00053 cGuiElement( tGuiPos(0,0), tGuiPos(1,1) ), 00054 mState(State_None), 00055 mVisible(true) 00056 { 00057 load( iNode ); 00058 } 00059 00060 /**************************************************************************/ 00061 cGuiSpriteMousePointer::cGuiSpriteMousePointer( const cDynVar &iDef ) : 00062 cGuiElement( tGuiPos(0,0), tGuiPos(1,1) ), 00063 mState(State_None), 00064 mVisible(true) 00065 { 00066 load( iDef ); 00067 } 00068 00069 /**************************************************************************/ 00070 cGuiSpriteMousePointer::~cGuiSpriteMousePointer() 00071 { 00072 } 00073 00074 /**************************************************************************/ 00075 void cGuiSpriteMousePointer::load( const cVfsNodeInterface & iNode ) 00076 { 00077 if (!iNode.likeFile()) 00078 throw cBadDataUseException( "cGuiSpriteMousePointer::load", 00079 "Provided node isn\'t like a file" ); 00080 // Load it. 00081 if (iNode.firstLine()!="n2l::cGuiSpriteMousePointer") 00082 throw cParsingException( "cGuiSpriteMousePointer::load", 00083 "This file isn\'t the right type" ); 00084 00085 cDynVar def; 00086 if (iNode.buffer().size()<=(iNode.firstLine().size()+1)) 00087 throw cParsingException( "cGuiSpriteMousePointer::load", 00088 "No data after header!" ); 00089 def.unserialize( iNode.buffer().c_str()+iNode.firstLine().size()+1 ); 00090 00091 load(def); 00092 } 00093 00094 /**************************************************************************/ 00095 void cGuiSpriteMousePointer::load( const cDynVar &iDefinition ) 00096 { 00097 // Load parent properties 00098 cGuiElement::load( iDefinition ); 00099 00100 if (iDefinition["fill"]) 00101 for (tSint i=State_None; i<State_NumStates; ++i) 00102 if (iDefinition["fill"][i]) { 00103 if (iDefinition["fill"][i].isArray()) 00104 fill( tState(i), iDefinition["fill"][i] ); 00105 else 00106 fill( tState(i), *cResourceManager::get<cGuiFill>( 00107 iDefinition["fill"][i]) ); 00108 } 00109 } 00110 00111 /**************************************************************************/ 00112 void cGuiSpriteMousePointer::systemEvent( 00113 const cAutoPtr<const cEventInterface> &i_iEvent ) 00114 { 00115 switch (i_iEvent->type()) 00116 { 00117 case EventType_MouseMotion: { 00118 const cAutoPtr<const cMouseMotionEvent> Motion(i_iEvent); 00119 pos( Motion->pos() ); 00120 mVisible = true; // Must be if we're seeing motion events 00121 break; 00122 } 00123 00124 case EventType_MouseButton: { 00125 const cAutoPtr<const cMouseButtonEvent> Button(i_iEvent); 00126 if (Button->pressed()) 00127 mState = State_Any; 00128 else 00129 mState = State_None; 00130 break; 00131 } 00132 00133 case EventType_Active: { 00134 const cAutoPtr<const cActiveEvent> Active(i_iEvent); 00135 if (Active->whatActive() == cActiveEvent::WhatActive_Mouse) 00136 if (!Active->gained()) mVisible = false; 00137 } 00138 00139 default: 00140 // Nothing. 00141 break; 00142 } // switch 00143 } 00144 00145 /**************************************************************************/ 00146 void cGuiSpriteMousePointer::draw() const 00147 { 00148 if (!mVisible) return; 00149 mFill[mState].draw( pos(), innerSize() ); 00150 } 00151 00152 /**************************************************************************/ 00153 void cGuiSpriteMousePointer::fill( const tState iState, 00154 const cGuiFill &iFill ) 00155 { 00156 if (iState<0 || iState>=State_NumStates) 00157 throw cOutOfBoundsException( "cGuiSpriteMousePointer::fill", 00158 "State out of range" ); 00159 mFill[iState] = iFill; 00160 } 00161 00162 /**************************************************************************/ 00163 const cAutoPtr<cGuiElement> cGuiSpriteMousePointer::clone() const 00164 { 00165 cAutoPtr<cGuiElement> newElement( new cGuiSpriteMousePointer ); 00166 cloneInto( newElement ); 00167 return newElement; 00168 } 00169 00170 /**************************************************************************/ 00171 void cGuiSpriteMousePointer::cloneInto( 00172 const cAutoPtr<cGuiSpriteMousePointer> &i_ioElement ) const 00173 { 00174 // Parent Properties first 00175 cGuiElement::cloneInto( i_ioElement ); 00176 00177 // Now our properties. 00178 for (tSint i=0; i<State_NumStates; ++i) 00179 i_ioElement->fill(tState(i), mFill[i]); 00180 00181 i_ioElement->mVisible = mVisible; 00182 } 00183 00184 } // namespace n2l |