userinput.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880
  1. //---------------------------------------------------------------------------
  2. //
  3. // MechCommander 2
  4. //
  5. // UserInput Class -- Polls the state of keyboard, mouse, joystick
  6. // for this frame and stores values.
  7. //
  8. //---------------------------------------------------------------------------//
  9. // Copyright (C) Microsoft Corporation. All rights reserved. //
  10. //===========================================================================//
  11. #ifndef USERINPUT_H
  12. #include "userinput.h"
  13. #endif
  14. #ifndef TIMING_H
  15. #include "timing.h"
  16. #endif
  17. #ifndef CIDENT_H
  18. #include "cident.h"
  19. #endif
  20. #ifndef INIFILE_H
  21. #include "inifile.h"
  22. #endif
  23. #ifndef PATHS_H
  24. #include "paths.h"
  25. #endif
  26. #ifndef CLIP_H
  27. #include "clip.h"
  28. #endif
  29. #ifndef TXMMGR_H
  30. #include "txmmgr.h"
  31. #endif
  32. #include <windows.h>
  33. #include <stuff\stuff.hpp>
  34. #include <math.h>
  35. //---------------------------------------------------------------------------
  36. UserInput *userInput = NULL;
  37. extern bool hasGuardBand;
  38. volatile bool UserInput::drawMouse = false;
  39. extern volatile bool mc2IsInDisplayBackBuffer;
  40. extern volatile bool mc2IsInMouseTimer;
  41. void MouseTimerInit();
  42. void MouseTimerKill();
  43. //---------------------------------------------------------------------------
  44. void MouseCursorData::initCursors (char *cursorFileName)
  45. {
  46. //New
  47. // add an "a" to the end of the cursorFileName IF we are running in 800x600 or less.
  48. // Loads different sized cursors.
  49. char realHackName[1024];
  50. strcpy(realHackName,cursorFileName);
  51. if (Environment.screenWidth <= 800)
  52. sprintf(realHackName,"%sa",cursorFileName);
  53. FullPathFileName cursorName;
  54. cursorName.init(artPath,realHackName,".fit");
  55. FitIniFile cursorFile;
  56. long result = cursorFile.open(cursorName);
  57. gosASSERT(result == NO_ERR);
  58. result = cursorFile.seekBlock("Main");
  59. gosASSERT(result == NO_ERR);
  60. result = cursorFile.readIdLong("NumCursors",numCursors);
  61. gosASSERT(result == NO_ERR);
  62. gosASSERT( numCursors < MAX_MOUSE_STATES );
  63. cursorInfos = new StaticInfo[numCursors];
  64. //----------------------------------------------
  65. // Each cursor is defined as a number of frames
  66. // and a TGA File Name which we use to create
  67. // the texture handle.
  68. char blockName[32];
  69. for (long i=0;i<numCursors;i++)
  70. {
  71. sprintf( blockName, "Cursor%ld", i );
  72. cursorInfos[i].init( cursorFile, blockName,0,0,0x1);
  73. cursorFile.readIdChar( "HotSpotX", mouseHS[i][0] );
  74. cursorFile.readIdChar( "HotSpotY", mouseHS[i][1] );
  75. cursorFile.readIdULong( "NumFrames", numFrames[i] );
  76. cursorFile.readIdFloat( "FrameLength", frameLengths[i] );
  77. }
  78. cursorFile.close();
  79. }
  80. //---------------------------------------------------------------------------
  81. void MouseCursorData::destroy (void)
  82. {
  83. if (mc2UseAsyncMouse && mc2MouseThreadStarted)
  84. MouseTimerKill();
  85. if (numCursors)
  86. {
  87. userInput->mouseOff();
  88. if ( cursorInfos )
  89. {
  90. delete [] cursorInfos;
  91. cursorInfos = NULL;
  92. }
  93. numCursors = 0;
  94. }
  95. }
  96. //---------------------------------------------------------------------------
  97. void UserInput::mouseOn (void) //Draw Mouse Cursor
  98. {
  99. drawMouse = true;
  100. }
  101. void UserInput::mouseOff (void) //Don't Draw Mouse Cursor
  102. {
  103. drawMouse = false;
  104. }
  105. void UserInput::setMouseCursor (long state)
  106. {
  107. if ((state < 0) || (state >= mState_NUMMOUSESTATES))
  108. return;
  109. //DEBUG!!!!!!!!!!!!!!!!!!!!!!
  110. if (state == mState_NORMAL)
  111. printf("Go Flash");
  112. mouseState = state;
  113. }
  114. //---------------------------------------------------------------------------
  115. void UserInput::update (void)
  116. {
  117. if (mc2UseAsyncMouse && !mc2MouseThreadStarted)
  118. MouseTimerInit();
  119. if (!mc2UseAsyncMouse && mc2MouseThreadStarted)
  120. MouseTimerKill();
  121. //-----------------------------
  122. // Save the last Mouse States
  123. lastLeftMouseButtonState = leftMouseButtonState;
  124. lastRightMouseButtonState = rightMouseButtonState;
  125. lastMouseXPosition = mouseXPosition;
  126. lastMouseYPosition = mouseYPosition;
  127. leftMouseJustUp = 0;
  128. rightMouseJustUp = 0;
  129. bool bWasDouble = leftDoubleClick;
  130. //------------------------------------------------------
  131. // Reset Frame dependant variables
  132. leftClick = rightClick = middleClick = false;
  133. leftDoubleClick = rightDoubleClick = middleDoubleClick = false;
  134. DWORD LEFT_MOUSE_CODE = VK_LBUTTON;
  135. DWORD RIGHT_MOUSE_CODE = VK_RBUTTON;
  136. if ( GetSystemMetrics(SM_SWAPBUTTON) )
  137. {
  138. RIGHT_MOUSE_CODE = VK_LBUTTON;
  139. LEFT_MOUSE_CODE = VK_RBUTTON;
  140. }
  141. //-----------------
  142. // Poll the mouse.
  143. DWORD buttonStates;
  144. gos_GetMouseInfo(&mouseXPosition,&mouseYPosition,(int *)&mouseXDelta,(int *)&mouseYDelta,(int *)&mouseWheelDelta,&buttonStates);
  145. // leftMouseButtonState = buttonStates & 1;
  146. // rightMouseButtonState = (buttonStates & 2) >> 1;
  147. // middleMouseButtonState = (buttonStates & 4) >> 2;
  148. SHORT code = GetAsyncKeyState(LEFT_MOUSE_CODE);
  149. SHORT rCode = GetAsyncKeyState( RIGHT_MOUSE_CODE );
  150. SHORT mCode = GetAsyncKeyState( VK_MBUTTON );
  151. leftMouseButtonState = code ? MC2_MOUSE_DOWN : MC2_MOUSE_UP;
  152. rightMouseButtonState = rCode ? MC2_MOUSE_DOWN : MC2_MOUSE_UP;
  153. middleMouseButtonState = mCode ? MC2_MOUSE_DOWN : MC2_MOUSE_UP;
  154. //---------------------------------------------------------
  155. // Adjust MouseWheelDelta to get old Broken Win2K values.
  156. mouseWheelDelta *= -100;
  157. //-------------------------------------
  158. // Determine drag, double click states
  159. if ((leftMouseButtonState == MC2_MOUSE_UP) && (lastLeftMouseButtonState == MC2_MOUSE_DOWN))
  160. {
  161. //--------------------------------------------------------------------
  162. // Just lifted the button. Drags are OFF! Double Click clock starts!
  163. wasLeftMouseDrag = leftMouseDrag;
  164. wasRightMouseDrag = rightMouseDrag;
  165. leftMouseDrag = false;
  166. mouseLeftUpTime += frameLength;
  167. // if ( !bWasDouble )
  168. leftMouseJustUp = 1;
  169. mouseLeftHeldTime = 0.f;
  170. }
  171. if ((leftMouseButtonState == MC2_MOUSE_UP) && (lastLeftMouseButtonState == MC2_MOUSE_UP))
  172. {
  173. //--------------------------------------------
  174. // We are still up. Increment mouse up time.
  175. mouseLeftUpTime += frameLength;
  176. mouseLeftHeldTime = 0.f;
  177. }
  178. if ( gos_GetKeyStatus( KEY_LMOUSE ) == KEY_PRESSED /*code & 0x0001*/ ) // clicked
  179. {
  180. //-------------------------------------------------------------------------------
  181. // We just clicked down. If mouseUpTime is < threshold, this was a double click
  182. if ( (mouseLeftUpTime > 0.0 ) && (mouseLeftUpTime < mouseDblClickThreshold) && !bWasDouble)
  183. {
  184. leftDoubleClick = true;
  185. mouseLeftUpTime = 0.f; // make sure if we hold it, we don't keep clicking
  186. }
  187. else
  188. {
  189. leftClick = true;
  190. mouseLeftUpTime = 0.001f;
  191. }
  192. mouseDragX = lastMouseXPosition;
  193. mouseDragY = lastMouseYPosition;
  194. leftMouseDrag = 0;
  195. }
  196. else if (gos_GetKeyStatus( KEY_LMOUSE ) == KEY_HELD /*code & 0x8000*/) // held
  197. {
  198. mouseLeftUpTime = 5.0;
  199. //-----------------------------------------------------------------------
  200. // Down and still down should indicate dragging. Check threshold of
  201. // Deltas to see if this is TRUE IF AND ONLY IF we are NOT yet DRAGGING!
  202. if (!leftMouseDrag)
  203. {
  204. if ((fabs(mouseDragX - mouseXPosition) > mouseDragThreshold) ||
  205. (fabs(mouseDragY - mouseYPosition) > mouseDragThreshold))
  206. {
  207. //------------------
  208. // We are dragging.
  209. leftMouseDrag = true;
  210. }
  211. }
  212. mouseLeftUpTime = 0;
  213. mouseLeftHeldTime += frameLength;
  214. }
  215. if ((rightMouseButtonState == MC2_MOUSE_UP) && (lastRightMouseButtonState == MC2_MOUSE_DOWN))
  216. {
  217. //--------------------------------------------------------------------
  218. // Just lifted the button. Drags are OFF! Double Click clock starts!
  219. wasRightMouseDrag = rightMouseDrag;
  220. rightMouseDrag = false;
  221. mouseRightUpTime = 0.001f;
  222. rightMouseJustUp = true;
  223. mouseRightHeldTime = 0.f;
  224. }
  225. if ((rightMouseButtonState == MC2_MOUSE_UP) && (lastRightMouseButtonState == MC2_MOUSE_UP))
  226. {
  227. //--------------------------------------------
  228. // We are still up. Increment mouse up time.
  229. mouseRightUpTime += frameLength;
  230. rightMouseDrag = 0;
  231. mouseRightHeldTime = 0.f;
  232. }
  233. if (gos_GetKeyStatus( KEY_RMOUSE ) == KEY_PRESSED /*rCode & 0x0001*/)
  234. {
  235. //-------------------------------------------------------------------------------
  236. // We just clicked down. If mouseUpTime is < threshold, this was a double click
  237. if (mouseRightUpTime && mouseRightUpTime < mouseDblClickThreshold)
  238. rightDoubleClick = true;
  239. else
  240. rightClick = true;
  241. mouseDragX = lastMouseXPosition;
  242. mouseDragY = lastMouseYPosition;
  243. rightMouseDrag = 0;
  244. }
  245. else if (gos_GetKeyStatus( KEY_RMOUSE ) == KEY_HELD /*rCode & 0x8000*/)
  246. {
  247. //-----------------------------------------------------------------------
  248. // Down and still down should indicate dragging. Check threshold of
  249. // Deltas to see if this is TRUE IF AND ONLY IF we are NOT yet DRAGGING!
  250. if (!rightMouseDrag)
  251. {
  252. if ((fabs(mouseDragX - mouseXPosition) > mouseDragThreshold) ||
  253. (fabs(mouseDragY - mouseYPosition) > mouseDragThreshold))
  254. {
  255. //------------------
  256. // We are dragging.
  257. rightMouseDrag = true;
  258. }
  259. }
  260. rightClick = true;
  261. mouseRightUpTime = 0;
  262. mouseRightHeldTime += frameLength;
  263. }
  264. if ((middleMouseButtonState == MC2_MOUSE_UP) && (lastMiddleMouseButtonState == MC2_MOUSE_DOWN))
  265. {
  266. //--------------------------------------------------------------------
  267. // Just lifted the button. Drags are OFF! Double Click clock starts!
  268. mouseMiddleUpTime = 0.0;
  269. }
  270. if ((middleMouseButtonState == MC2_MOUSE_UP) && (lastMiddleMouseButtonState == MC2_MOUSE_UP))
  271. {
  272. //--------------------------------------------
  273. // We are still up. Increment mouse up time.
  274. mouseMiddleUpTime += frameLength;
  275. }
  276. if (gos_GetKeyStatus( KEY_MMOUSE ) == KEY_PRESSED /*mCode & 0x0001*/)
  277. {
  278. //-------------------------------------------------------------------------------
  279. // We just clicked down. If mouseUpTime is < threshold, this was a double click
  280. if (mouseMiddleUpTime < mouseDblClickThreshold)
  281. middleDoubleClick = true;
  282. else
  283. middleClick = true;
  284. }
  285. if (cursors->getNumFrames( mouseState ) > 1 )
  286. {
  287. mouseFrameLength += frameLength;
  288. if (mouseFrameLength > cursors->frameLengths[mouseState] )
  289. {
  290. mouseFrame++;
  291. if (mouseFrame >= cursors->getNumFrames(mouseState))
  292. {
  293. mouseFrame = 0;
  294. }
  295. mouseFrameLength = 0.0;
  296. }
  297. }
  298. if (mc2UseAsyncMouse)
  299. {
  300. //Wait for thread to finish. Otherwise, we may move its data buffer halfway through!!
  301. while (mc2IsInMouseTimer)
  302. ;
  303. //ONLY set the mouse BLT data at the end of each update. NO MORE FLICKERING THEN!!!
  304. // BLOCK THREAD WHILE THIS IS HAPPENING
  305. mc2IsInDisplayBackBuffer = true;
  306. if (!mc2MouseData)
  307. {
  308. mc2MouseData = (MemoryPtr)malloc(sizeof(DWORD) * MOUSE_WIDTH * MOUSE_WIDTH);
  309. memset(mc2MouseData,0,sizeof(DWORD) * MOUSE_WIDTH * MOUSE_WIDTH);
  310. }
  311. //Need to update the mouse in the mouse thread to inform it that the cursor
  312. // possibly changed size and shape.
  313. mc2MouseHotSpotX = cursors->getMouseHSX( mouseState );
  314. mc2MouseHotSpotY = cursors->getMouseHSY( mouseState );
  315. mc2MouseWidth = cursors->cursorInfos[mouseState].width();
  316. mc2MouseHeight = cursors->cursorInfos[mouseState].height();
  317. DWORD totalMouseFrames = cursors->getNumFrames(mouseState);
  318. if ( totalMouseFrames > 1 )
  319. {
  320. long framesPerRow = cursors->cursorInfos[mouseState].textureWidth/cursors->cursorInfos[mouseState].width();
  321. int iIndex = mouseFrame % framesPerRow;
  322. int jIndex = mouseFrame / framesPerRow;
  323. float oldU = cursors->cursorInfos[mouseState].u;
  324. float oldV = cursors->cursorInfos[mouseState].v;
  325. float newU = (.1f + oldU)/cursors->cursorInfos[mouseState].textureWidth + ((float)iIndex * cursors->cursorInfos[mouseState].width()/cursors->cursorInfos[mouseState].textureWidth);
  326. float newV = (.1f + oldV)/cursors->cursorInfos[mouseState].textureWidth + (float)jIndex * cursors->cursorInfos[mouseState].height()/cursors->cursorInfos[mouseState].textureWidth;
  327. float newU2 = newU + (cursors->cursorInfos[mouseState].width() + .1)/cursors->cursorInfos[mouseState].textureWidth;
  328. float newV2 = newV + (cursors->cursorInfos[mouseState].height() + .1)/cursors->cursorInfos[mouseState].textureWidth;
  329. cursors->cursorInfos[mouseState].setNewUVs( newU, newV, newU2, newV2 );
  330. cursors->cursorInfos[mouseState].getData(mc2MouseData);
  331. cursors->cursorInfos[mouseState].u = oldU;
  332. cursors->cursorInfos[mouseState].v = oldV;
  333. }
  334. else if (totalMouseFrames)
  335. {
  336. cursors->cursorInfos[mouseState].getData(mc2MouseData);
  337. }
  338. //Unblock Thread
  339. mc2IsInDisplayBackBuffer = false;
  340. }
  341. }
  342. //---------------------------------------------------------------------------
  343. void UserInput::initMouseCursors (char *mouseFile)
  344. {
  345. if (cursors)
  346. {
  347. cursors->destroy();
  348. delete cursors;
  349. cursors = NULL;
  350. }
  351. cursors = new MouseCursorData;
  352. gosASSERT(cursors != NULL);
  353. cursors->initCursors(mouseFile);
  354. mouseFrame = 0;
  355. }
  356. //---------------------------------------------------------------------------
  357. float smallTextureTLUVX[4] =
  358. {
  359. 0.00,
  360. 0.50,
  361. 0.00,
  362. 0.50
  363. };
  364. float smallTextureTLUVY[4] =
  365. {
  366. 0.00,
  367. 0.00,
  368. 0.50,
  369. 0.50
  370. };
  371. float smallTextureBRUVX[4] =
  372. {
  373. 0.50,
  374. 1.00,
  375. 0.50,
  376. 1.00
  377. };
  378. float smallTextureBRUVY[4] =
  379. {
  380. 0.50,
  381. 0.50,
  382. 1.00,
  383. 1.00
  384. };
  385. //---------------------------------------------------------------------------
  386. float mediumTextureTLUVX[16] =
  387. {
  388. 0.00,
  389. 0.25,
  390. 0.50,
  391. 0.75,
  392. 0.00,
  393. 0.25,
  394. 0.50,
  395. 0.75,
  396. 0.00,
  397. 0.25,
  398. 0.50,
  399. 0.75,
  400. 0.00,
  401. 0.25,
  402. 0.50,
  403. 0.75
  404. };
  405. float mediumTextureTLUVY[16] =
  406. {
  407. 0.00,
  408. 0.00,
  409. 0.00,
  410. 0.00,
  411. 0.25,
  412. 0.25,
  413. 0.25,
  414. 0.25,
  415. 0.50,
  416. 0.50,
  417. 0.50,
  418. 0.50,
  419. 0.75,
  420. 0.75,
  421. 0.75,
  422. 0.75
  423. };
  424. float mediumTextureBRUVX[16] =
  425. {
  426. 0.25,
  427. 0.50,
  428. 0.75,
  429. 1.00,
  430. 0.25,
  431. 0.50,
  432. 0.75,
  433. 1.00,
  434. 0.25,
  435. 0.50,
  436. 0.75,
  437. 1.00,
  438. 0.25,
  439. 0.50,
  440. 0.75,
  441. 1.00
  442. };
  443. float mediumTextureBRUVY[16] =
  444. {
  445. 0.25,
  446. 0.25,
  447. 0.25,
  448. 0.25,
  449. 0.50,
  450. 0.50,
  451. 0.50,
  452. 0.50,
  453. 0.75,
  454. 0.75,
  455. 0.75,
  456. 0.75,
  457. 1.00,
  458. 1.00,
  459. 1.00,
  460. 1.00
  461. };
  462. //---------------------------------------------------------------------------
  463. float largeTextureTLUVX[64] =
  464. {
  465. 0.00,
  466. 0.125,
  467. 0.25,
  468. 0.375,
  469. 0.50,
  470. 0.625,
  471. 0.75,
  472. 0.875,
  473. 0.00,
  474. 0.125,
  475. 0.25,
  476. 0.375,
  477. 0.50,
  478. 0.625,
  479. 0.75,
  480. 0.875,
  481. 0.00,
  482. 0.125,
  483. 0.25,
  484. 0.375,
  485. 0.50,
  486. 0.625,
  487. 0.75,
  488. 0.875,
  489. 0.00,
  490. 0.125,
  491. 0.25,
  492. 0.375,
  493. 0.50,
  494. 0.625,
  495. 0.75,
  496. 0.875,
  497. 0.00,
  498. 0.125,
  499. 0.25,
  500. 0.375,
  501. 0.50,
  502. 0.625,
  503. 0.75,
  504. 0.875,
  505. 0.00,
  506. 0.125,
  507. 0.25,
  508. 0.375,
  509. 0.50,
  510. 0.625,
  511. 0.75,
  512. 0.875,
  513. 0.00,
  514. 0.125,
  515. 0.25,
  516. 0.375,
  517. 0.50,
  518. 0.625,
  519. 0.75,
  520. 0.875,
  521. 0.00,
  522. 0.125,
  523. 0.25,
  524. 0.375,
  525. 0.50,
  526. 0.625,
  527. 0.75,
  528. 0.875
  529. };
  530. float largeTextureTLUVY[64] =
  531. {
  532. 0.00,
  533. 0.00,
  534. 0.00,
  535. 0.00,
  536. 0.00,
  537. 0.00,
  538. 0.00,
  539. 0.00,
  540. 0.125,
  541. 0.125,
  542. 0.125,
  543. 0.125,
  544. 0.125,
  545. 0.125,
  546. 0.125,
  547. 0.125,
  548. 0.25,
  549. 0.25,
  550. 0.25,
  551. 0.25,
  552. 0.25,
  553. 0.25,
  554. 0.25,
  555. 0.25,
  556. 0.375,
  557. 0.375,
  558. 0.375,
  559. 0.375,
  560. 0.375,
  561. 0.375,
  562. 0.375,
  563. 0.375,
  564. 0.50,
  565. 0.50,
  566. 0.50,
  567. 0.50,
  568. 0.50,
  569. 0.50,
  570. 0.50,
  571. 0.50,
  572. 0.625,
  573. 0.625,
  574. 0.625,
  575. 0.625,
  576. 0.625,
  577. 0.625,
  578. 0.625,
  579. 0.625,
  580. 0.75,
  581. 0.75,
  582. 0.75,
  583. 0.75,
  584. 0.75,
  585. 0.75,
  586. 0.75,
  587. 0.75,
  588. 0.875,
  589. 0.875,
  590. 0.875,
  591. 0.875,
  592. 0.875,
  593. 0.875,
  594. 0.875,
  595. 0.875
  596. };
  597. float largeTextureBRUVX[64] =
  598. {
  599. 0.125,
  600. 0.25,
  601. 0.375,
  602. 0.50,
  603. 0.625,
  604. 0.75,
  605. 0.875,
  606. 1.00,
  607. 0.125,
  608. 0.25,
  609. 0.375,
  610. 0.50,
  611. 0.625,
  612. 0.75,
  613. 0.875,
  614. 1.00,
  615. 0.125,
  616. 0.25,
  617. 0.375,
  618. 0.50,
  619. 0.625,
  620. 0.75,
  621. 0.875,
  622. 1.00,
  623. 0.125,
  624. 0.25,
  625. 0.375,
  626. 0.50,
  627. 0.625,
  628. 0.75,
  629. 0.875,
  630. 1.00,
  631. 0.125,
  632. 0.25,
  633. 0.375,
  634. 0.50,
  635. 0.625,
  636. 0.75,
  637. 0.875,
  638. 1.00,
  639. 0.125,
  640. 0.25,
  641. 0.375,
  642. 0.50,
  643. 0.625,
  644. 0.75,
  645. 0.875,
  646. 1.00,
  647. 0.125,
  648. 0.25,
  649. 0.375,
  650. 0.50,
  651. 0.625,
  652. 0.75,
  653. 0.875,
  654. 1.00,
  655. 0.125,
  656. 0.25,
  657. 0.375,
  658. 0.50,
  659. 0.625,
  660. 0.75,
  661. 0.875,
  662. 1.00
  663. };
  664. float largeTextureBRUVY[64] =
  665. {
  666. 0.125,
  667. 0.125,
  668. 0.125,
  669. 0.125,
  670. 0.125,
  671. 0.125,
  672. 0.125,
  673. 0.125,
  674. 0.25,
  675. 0.25,
  676. 0.25,
  677. 0.25,
  678. 0.25,
  679. 0.25,
  680. 0.25,
  681. 0.25,
  682. 0.375,
  683. 0.375,
  684. 0.375,
  685. 0.375,
  686. 0.375,
  687. 0.375,
  688. 0.375,
  689. 0.375,
  690. 0.50,
  691. 0.50,
  692. 0.50,
  693. 0.50,
  694. 0.50,
  695. 0.50,
  696. 0.50,
  697. 0.50,
  698. 0.625,
  699. 0.625,
  700. 0.625,
  701. 0.625,
  702. 0.625,
  703. 0.625,
  704. 0.625,
  705. 0.625,
  706. 0.75,
  707. 0.75,
  708. 0.75,
  709. 0.75,
  710. 0.75,
  711. 0.75,
  712. 0.75,
  713. 0.75,
  714. 0.875,
  715. 0.875,
  716. 0.875,
  717. 0.875,
  718. 0.875,
  719. 0.875,
  720. 0.875,
  721. 0.875,
  722. 1.00,
  723. 1.00,
  724. 1.00,
  725. 1.00,
  726. 1.00,
  727. 1.00,
  728. 1.00,
  729. 1.00
  730. };
  731. //---------------------------------------------------------------------------
  732. void UserInput::setMouseScale (float scaleFactor)
  733. {
  734. if (scaleFactor > 0.0f)
  735. mouseScale = scaleFactor;
  736. }
  737. //---------------------------------------------------------------------------
  738. void UserInput::render (void) //Last thing rendered. Draws Mouse.
  739. {
  740. if (!mc2UseAsyncMouse)
  741. {
  742. if (drawMouse && mouseState != -1)
  743. {
  744. // figure out where to put the thing
  745. long mouseX = getMouseX();
  746. long mouseY = getMouseY();
  747. mouseX -= cursors->getMouseHSX( mouseState );
  748. mouseY -= cursors->getMouseHSY( mouseState );
  749. cursors->cursorInfos[mouseState].setLocation( mouseX, mouseY );
  750. long totalMouseFrames = cursors->getNumFrames(mouseState);
  751. if ( totalMouseFrames > 1 )
  752. {
  753. long framesPerRow = cursors->cursorInfos[mouseState].textureWidth/cursors->cursorInfos[mouseState].width();
  754. int iIndex = mouseFrame % framesPerRow;
  755. int jIndex = mouseFrame / framesPerRow;
  756. float oldU = cursors->cursorInfos[mouseState].u;
  757. float oldV = cursors->cursorInfos[mouseState].v;
  758. float newU = (.1f + oldU)/cursors->cursorInfos[mouseState].textureWidth + ((float)iIndex * cursors->cursorInfos[mouseState].width()/cursors->cursorInfos[mouseState].textureWidth);
  759. float newV = (.1f + oldV)/cursors->cursorInfos[mouseState].textureWidth + (float)jIndex * cursors->cursorInfos[mouseState].height()/cursors->cursorInfos[mouseState].textureWidth;
  760. float newU2 = newU + (cursors->cursorInfos[mouseState].width() + .1)/cursors->cursorInfos[mouseState].textureWidth;
  761. float newV2 = newV + (cursors->cursorInfos[mouseState].height() + .1)/cursors->cursorInfos[mouseState].textureWidth;
  762. cursors->cursorInfos[mouseState].setNewUVs( newU, newV, newU2, newV2 );
  763. cursors->cursorInfos[mouseState].render();
  764. cursors->cursorInfos[mouseState].u = oldU;
  765. cursors->cursorInfos[mouseState].v = oldV;
  766. }
  767. else
  768. cursors->cursorInfos[mouseState].render();
  769. }
  770. }
  771. }
  772. //---------------------------------------------------------------------------