00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "3d.h"
00020 #include "input.h"
00021
00022
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)
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
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
00110 SHORT result = GetKeyState(code);
00111
00112
00113
00114
00115
00116
00117
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
00151
00152
00153
00154
00155
00156
00157
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++;
00172 isRuning = FALSE;
00173 }
00174
00175 Timer::~Timer()
00176 {
00177 Stop(id,FALSE);
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();
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;
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;
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(¤tTime);
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