Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

input.cpp

Go to the documentation of this file.
00001 /* *************************************************************************************
00002         Writer:         Sebastien Bloc
00003         Copyright:      2003-2004
00004         eMail:          sebastien.bloc@free.fr
00005         URL:            http://mignonsoft.free.fr
00006 
00007         This program is free software; you can redistribute it and/or
00008         modify it under the terms of the GNU General Public License
00009         as published by the Free Software Foundation; either version 2
00010         of the License, or (at your option) any later version.
00011 
00012         This program is distributed in the hope that it will be useful,
00013         but WITHOUT ANY WARRANTY; without even the implied warranty of
00014         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015         GNU General Public License for more details.
00016         http://www.gnu.org/copyleft/gpl.html
00017 ************************************************************************************* */
00018 
00019 #include "3d.h"
00020 #include "input.h"
00021 
00022 // StateMouse ********************************************************************************
00023         
00024 StateMouse::StateMouse()
00025 {
00026         pos.Zero();
00027         leftBtn=FALSE;
00028         rightBtn=FALSE;
00029         midBtn=FALSE;
00030         wheelVal=0;
00031         wheelDelta=0;
00032 }
00033 
00034 void StateMouse::operator= (StateMouse &src)
00035 {
00036         pos=src.pos;
00037         leftBtn=src.leftBtn;
00038         rightBtn=src.rightBtn;
00039         midBtn=src.midBtn;
00040         wheelVal=src.wheelVal;
00041         wheelDelta=src.wheelDelta;
00042 }
00043 
00044 int StateMouse::GetNbButtonPush()
00045 {
00046         return leftBtn+midBtn+rightBtn;
00047 }
00048 
00057 StateMouse * StateMouse::GetDelta(StateMouse *second) // delta = second-this
00058 {
00059         static StateMouse delta;
00060         delta.pos = second->pos-pos;
00061         delta.leftBtn = second->leftBtn-leftBtn;
00062         delta.midBtn = second->midBtn-midBtn;
00063         delta.rightBtn = second->rightBtn-rightBtn;
00064         delta.wheelVal = second->wheelVal-wheelVal;
00065         delta.wheelDelta = second->wheelDelta-wheelDelta;
00066         return δ
00067 }
00068 
00069 
00070 void StateMouse::ToString(MyString &str)
00071 {
00072         str.AddFormat("x:%d y:%d leftBtn:%d rightBtn:%d midBtn:%d wheelVal:%d wheelDelta:%d",pos.x,pos.y,leftBtn,rightBtn,midBtn,wheelVal,wheelDelta);
00073 }
00074 
00075 // StateKey ********************************************************************************
00076         
00077 StateKey::StateKey()
00078 {
00079         letter='\0';
00080         code=0;
00081         isPush=FALSE;
00082         SaveDelayAndRepeate();
00083 }
00084 
00085 StateKey::~StateKey()
00086 {
00087         RestoreDelayAndRepeate();
00088 }
00089 
00090 void StateKey::operator= (StateKey &src)
00091 {
00092         letter=src.letter;
00093         code=src.code;
00094         isPush=src.isPush;
00095 }
00096 
00097 void StateKey::ToString(MyString &str)
00098 {
00099         str.AddFormat("letter: %c code:%d isPush:%d",letter,code,isPush);
00100 }
00101 
00107 BOOL StateKey::GetState(int code)
00108 {
00109         // autre solution ou BOOL isUp = GetAsyncKeyState(code) & 0x8000 
00110         SHORT result = GetKeyState(code);
00111         /*
00112         The return value specifies the status of the specified virtual key, as follows: 
00113         If the high-order bit is 1, the key is down; otherwise, it is up.
00114         If the low-order bit is 1, the key is toggled. 
00115         A key, such as the CAPS LOCK key, is toggled if it is turned on. 
00116         The key is off and untoggled if the low-order bit is 0. 
00117         A toggle key's indicator light (if any) on the keyboard will be on when the key is toggled, and off when the key is untoggled.
00118         */
00119         BOOL isUp=(result&0x0100)==0x0100;
00120         BOOL isToggled=(result&0x0001)==0x0001;
00121         return isUp;
00122 }
00123 
00131 void StateKey::SetDelayAndRepeate(int delay,int repeate)
00132 {
00133         SystemParametersInfo(SPI_SETKEYBOARDDELAY,delay,NULL,0);
00134         SystemParametersInfo(SPI_SETKEYBOARDSPEED,repeate,NULL,0);
00135 }
00137 void StateKey::SaveDelayAndRepeate()
00138 {
00139         SystemParametersInfo(SPI_GETKEYBOARDDELAY,0,&oldDelay,0);
00140         SystemParametersInfo(SPI_GETKEYBOARDSPEED,0,&oldRepeate,0);
00141 }
00142 
00144 void StateKey::RestoreDelayAndRepeate()
00145 {
00146         SetDelayAndRepeate(oldDelay,oldRepeate);
00147 }
00148 
00149 
00150 // EventMouse ********************************************************************************
00151 
00152 /* // voir ci cela est necessaire
00153 void EventMouse::operator=(MouseEvent &src)
00154 {
00155         left=src.left;
00156         right=src.right;
00157         mid=src.mid;
00158 }
00159 */
00160 
00161 BOOL Timer::Init(HWND _hWnd)
00162 {
00163         hWnd=_hWnd;
00164         return QueryPerformanceFrequency(&frecTimer);
00165 }
00166 
00167 Timer::Timer()
00168 {
00169         insideList=FALSE;
00170         id=nextFreeId;
00171         nextFreeId++; // attention au bout d'un momenet les numeros d'id seron depasser, programmer un "garbage collector"
00172         isRuning = FALSE;
00173 }
00174 
00175 Timer::~Timer()
00176 {
00177         Stop(id,FALSE); // suprime l'event de la list d'instanciation
00178 }
00179 
00186 Timer * Timer::Find(int idToFind)
00187 {
00188         for (list.i=0;list.i.More();list.i++)
00189         {
00190                 Timer *event = list.i.GetElem();
00191                 if (event->id==idToFind) return event;
00192         }
00193         return NULL;
00194 }
00195 
00199 BOOL Timer::Call(int idToFind)
00200 {
00201         Timer *timer;
00202         timer = Find(idToFind);
00203         if (timer) 
00204         {
00205                 timer->onTimer(timer);
00206                 return TRUE;
00207         }
00208         return FALSE;
00209 }
00210 
00211 BOOL Timer::Stop()
00212 {       
00213         return Stop(id,FALSE);
00214 }
00215 
00216 BOOL Timer::StopAndUnBind()
00217 {
00218         return Stop(id,TRUE);
00219 }
00220 BOOL Timer::Stop(int idToFind,BOOL unBind)
00221 {
00222         Timer *event = Find(idToFind);
00223         if (event) 
00224         {
00225                 isRuning = FALSE;
00226                 if (!KillTimer(hWnd,idToFind)) return FALSE;
00227                 if (unBind) onTimer.disconnect_all();
00228                 event->insideList=FALSE;
00229                 list.i.Supr(); // car find place sur le current
00230                 return TRUE;
00231         }
00232         return FALSE;
00233 }
00234 
00235 BOOL Timer::Start()
00236 {
00237         Start(1000);
00238         return Pause();
00239 }
00240 
00241 BOOL Timer::Start(int freq)
00242 {
00243         frequency=freq;
00244         QueryPerformanceCounter(&beginTime);
00245         if (!insideList) { list.i+=this; insideList=TRUE; }
00246         if(!SetTimer(hWnd,id,frequency,NULL)) return NULL;
00247         isRuning = TRUE;
00248         return TRUE;
00249 }
00250 
00251 BOOL Timer::Pause()
00252 {
00253         if (!isRuning) return FALSE;
00254         return SetTimer(hWnd,id,0x7fffffff,NULL)?TRUE:FALSE; // valeur max d'un timeout que donne 1 ?
00255 }
00256 
00257 BOOL Timer::Resume()
00258 {
00259         if (!isRuning) return FALSE;
00260         return SetTimer(hWnd,id,frequency,NULL)?TRUE:FALSE;
00261 }
00262 
00263 double Timer::GetDeltaTime(BOOL reset)
00264 {
00265         if (!insideList) isRuning = TRUE; // en mode simple cronos definis le runing
00266         return GetDeltaTime(reset,&beginTime);
00267 }
00268 
00269 double Timer::GetDeltaTime(BOOL reset,LARGE_INTEGER *referenceTime)
00270 {
00271         if (!referenceTime) return -1;
00272         LARGE_INTEGER currentTime;
00273         QueryPerformanceCounter(&currentTime);  
00274         double delta = ((double)((UINT)currentTime.LowPart  - (UINT)(*referenceTime).LowPart) / frecTimer.LowPart);
00275         if (reset) *referenceTime=currentTime;
00276         return delta;
00277 }
00278 
00279 BOOL Timer::IsRuning()
00280 {
00281         return isRuning;
00282 }
00283 
00284 // ********************************************************************************

Generated on Fri Aug 20 19:19:46 2004 for 3d Controls by doxygen 1.3.6