Advertisement
michalmonday

C_cursor.cpp (classFile.cpp)

Dec 13th, 2015
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.02 KB | None | 0 0
  1. /*
  2. Relevant parts:
  3.  
  4.  
  5. Declaration of the objectArray:
  6. ///////////////////
  7. Cursor playerElement[MAX_PLAYER_ELEMENTS];
  8. //////////////////
  9.  
  10.  
  11. That's where the ugly things happen:
  12. //////////////////
  13. void Cursor::SetPlayerElement
  14. //////////////////
  15.  
  16.  
  17.  
  18.  
  19. */
  20.  
  21. #include "stdafx.h"
  22. #include <Windows.h>
  23. #include "C_cursor.h"
  24. #include "dllmain.h"
  25. #include "Csprite.h"
  26. #include "Cdynamic_graph.h"
  27. #include "CIniManager.h"
  28. #include <iostream>
  29. #include <ios>
  30. #include <fstream>
  31.  
  32.  
  33. void DrawMenu();
  34.  
  35. Cursor menuElement[MAX_MENU_ELEMENTS];
  36. Cursor playerElement[MAX_PLAYER_ELEMENTS];
  37. float xPos=NULL;
  38. float yPos=NULL;
  39.  
  40. POINT cPos;
  41.  
  42. int lastClickedMenuButton=INVALID_ELEMENT;//can't be 0 because 0 is an actual element number too
  43. bool positionMenuOnOff=NULL;
  44. int adjustRadarModeOnOff=NULL;
  45.  
  46. void Main_DrawLabel(int, float, float);
  47. void Main_ButtonAction(int buttonNum);
  48.  
  49. void Position_DrawLabel(int, float, float);
  50. void Position_ButtonAction(int buttonNum);
  51. void DrawAdjuster(int);
  52.  
  53.  
  54.  
  55.  
  56. Cursor::Cursor()
  57. {
  58. id = INVALID_ELEMENT;
  59. listed = false;//is anything assigned to the element
  60. pos.l = 0.0f;
  61. pos.t = 0.0f;
  62. pos.r = 0.0f;
  63. pos.b = 0.0f;
  64. type = NULL; //personalized texture/any others(?)
  65. state = NULL; // clicked/notclicked/cursor_over/normal
  66. allignTo = NULL;
  67. }
  68.  
  69.  
  70.  
  71.  
  72. void ManageCursorElements()
  73. {
  74. if(isCursorEnabled)
  75. {
  76. //DrawMenu();
  77.  
  78.  
  79. //manage player elements
  80. for(int i=0;i<MAX_PLAYER_ELEMENTS;i++)
  81. {
  82. ofstream log("logfile.txt", ios_base::app | ios_base::out);
  83. if((playerElement[i].GetID()) != 2000)
  84. {
  85. log<<"found playerElement[i] i="<<i<<"\n";
  86. playerElement[i].DrawFrame();
  87. }
  88. else
  89. {
  90. log<<"NOT FOUND playerElement[i] i="<<i<<"\n";
  91. }
  92. }
  93.  
  94. }
  95. }
  96.  
  97. int Cursor::GetID()
  98. {
  99. return id;
  100. }
  101.  
  102. void Cursor::UpdateElement()
  103. {
  104. //if(IsCursorOverElement())
  105. //{
  106. DrawFrame();
  107. //do the magic;d
  108. //}
  109. }
  110.  
  111. void Cursor::DrawFrame()
  112. {
  113. ofstream log("logfile.txt", ios_base::app | ios_base::out);
  114. log<<"DRAWFRAME ID="<<id<< " x="<<pos.l<<" y="<<pos.t<<" x2="<<pos.r<<" y2="<<pos.b<<"\n";
  115.  
  116. if(pLine)
  117. {
  118. pLine->SetWidth(2);
  119. pLine->SetAntialias(0);
  120. pLine->Begin();
  121.  
  122. D3DXVECTOR2 line[] = {D3DXVECTOR2(1, 1), D3DXVECTOR2(1, 1)};
  123. //same y pos
  124. line[0].x = pos.l;
  125. line[0].y = pos.t;
  126.  
  127. line[1].x = pos.r;
  128. line[1].y = pos.t;
  129. pLine->Draw(line, 2, D3DCOLOR_XRGB(255, 255, 255)); //top line
  130.  
  131. line[0].x = pos.l;
  132. line[0].y = pos.b;
  133.  
  134. line[1].x = pos.r;
  135. line[1].y = pos.b;
  136. pLine->Draw(line, 2, D3DCOLOR_XRGB(255, 255, 255));//bot line
  137.  
  138. line[0].x = pos.l;
  139. line[0].y = pos.t;
  140.  
  141. line[1].x = pos.l;
  142. line[1].y = pos.b;
  143. pLine->Draw(line, 2, D3DCOLOR_XRGB(255, 255, 255));//left line
  144.  
  145. line[0].x = pos.r;
  146. line[0].y = pos.t;
  147.  
  148. line[1].x = pos.r;
  149. line[1].y = pos.b;
  150. pLine->Draw(line, 2, D3DCOLOR_XRGB(255, 255, 255));//right line
  151.  
  152. pLine->End();
  153.  
  154.  
  155. }
  156.  
  157.  
  158. }
  159.  
  160. void Cursor::SetPlayerElement(float x, float y, float x2, float y2, int plID, int elementID)
  161. {
  162.  
  163. pos.l = x;
  164. pos.t = y;
  165. pos.r = x2;
  166. pos.b = y2;
  167. id = plID;
  168. ofstream log("logfile.txt", ios_base::app | ios_base::out);
  169. log<<"SETPLAYERELEMENT ID="<<id<< " x="<<pos.l<<" y="<<pos.t<<" x2="<<pos.r<<" y2="<<pos.b<<" elementID="<<elementID<<"\n";
  170. log<<"SETPLAYERELEMENT elementID="<<playerElement[elementID].id<< " x="<<playerElement[elementID].pos.l<<" y="<<playerElement[elementID].pos.t<<" x2="<<playerElement[elementID].pos.r<<" y2="<<playerElement[elementID].pos.b<<"\n";
  171. }
  172.  
  173. bool Cursor::IsCursorOverElement()
  174. {
  175. GetCursorPos(&cPos);//check if it gives value with account to current pc resolution or game resolution, if it's game res then adjust by multiplying/dividing it
  176.  
  177. //ofstream log("logfile.txt", ios_base::app | ios_base::out);
  178. //log <<"cPox.y="<<cPos.x<<" cPos.y="<<cPos.y<<" elem.pos.l="<<pos.l<<" elem.pos.r="<<pos.r<<" elem.pos.t="<<pos.t<<" elem.pos.b="<<pos.b<<"\n";
  179.  
  180. if((float)cPos.x > pos.l && (float)cPos.x < pos.r && (float)cPos.y > pos.t && (float)cPos.y < pos.b)
  181. {
  182. //log <<"true \n";
  183. return true;
  184. }
  185. return false;
  186. }
  187.  
  188.  
  189.  
  190. void DrawMenu()
  191. {
  192. if(pulseButton.IsInitialized())
  193. {
  194. if(pLine)
  195. {
  196. pLine->SetWidth(2);
  197. pLine->SetAntialias(0);
  198. pLine->Begin();
  199.  
  200. for(int i=4;i>=0;i--)//Main menu
  201. {
  202. int frameNum = 14;//plain black
  203. xPos = resolutionX * 0.9f;
  204. yPos = resolutionY * 0.93f - (((float)pulseButton.height + 5.0f) * i);
  205. menuElement[i].pos.l = xPos - (pulseButton.width/2); menuElement[i].pos.r = xPos + (pulseButton.width/2);
  206. menuElement[i].pos.t = yPos - (pulseButton.height/2); menuElement[i].pos.b = yPos + (pulseButton.height/2);
  207. pulseButton.SetPosition(xPos, yPos, NULL, NULL);
  208.  
  209. if(menuElement[i].IsCursorOverElement()){frameNum = 0;}
  210.  
  211. if(lastClickedMenuButton == i)
  212. {
  213. if(!KeyPressed(VK_LBUTTON) && menuElement[i].IsCursorOverElement())
  214. {
  215. lastClickedMenuButton = INVALID_ELEMENT;//reset
  216. //do the work for the specific button
  217. Main_ButtonAction(i);
  218. }
  219. }
  220.  
  221. if(menuElement[i].IsCursorOverElement() && KeyPressed(VK_LBUTTON))
  222. {
  223. lastClickedMenuButton = i;
  224. pulseButton.DrawGif(16, NULL, false);
  225. }
  226. else
  227. {
  228. if(!KeyPressed(VK_LBUTTON))pulseButton.SetCurrentFrame(1);//gif drawing mechanism requires setting the frame to 0 to avoid the gif starting from the middle when lmb is pressed again
  229.  
  230.  
  231. if(pulseButton.sprite && pulseButton.frameTex[frameNum])//14 is just a plain black
  232. {
  233. pulseButton.DrawGifFrame(frameNum);
  234. }
  235. }
  236.  
  237. //draw label here
  238. Main_DrawLabel(i, xPos, yPos);
  239. }
  240.  
  241.  
  242.  
  243.  
  244. if(positionMenuOnOff)
  245. {
  246. for(int i=5;i>=0;i--)//Position menu
  247. {
  248. int frameNum = 14;//plain black
  249. xPos = resolutionX * 0.9f - (float)pulseButton.width - 5.0f;
  250. yPos = resolutionY * 0.93f - (((float)pulseButton.height + 5.0f) * i);
  251. menuElement[i].pos.l = xPos - (pulseButton.width/2); menuElement[i].pos.r = xPos + (pulseButton.width/2);
  252. menuElement[i].pos.t = yPos - (pulseButton.height/2); menuElement[i].pos.b = yPos + (pulseButton.height/2);
  253. pulseButton.SetPosition(xPos, yPos, NULL, NULL);
  254.  
  255. if(menuElement[i].IsCursorOverElement()){frameNum = 0;}
  256.  
  257. if(lastClickedMenuButton == i && !KeyPressed(VK_LBUTTON) && menuElement[i].IsCursorOverElement())//what happens after the button is clicked
  258. {
  259. lastClickedMenuButton = INVALID_ELEMENT;//reset
  260. //do the work for the specific button
  261. Position_ButtonAction(i);
  262. }
  263.  
  264. if(menuElement[i].IsCursorOverElement() && KeyPressed(VK_LBUTTON))
  265. {
  266. lastClickedMenuButton = i;
  267. pulseButton.DrawGif(16, NULL, false);
  268. if(i == MENU_BUTTON_HEIGHT || i == MENU_BUTTON_WIDTH || i == MENU_BUTTON_UPPERTHRESHOLD || i == MENU_BUTTON_LOWERTHRESHOLD || i == MENU_BUTTON_HORIZONTALOFFSET){Position_ButtonAction(i);}
  269. }
  270. else
  271. {
  272. if(!KeyPressed(VK_LBUTTON))pulseButton.SetCurrentFrame(1);//gif drawing mechanism requires setting the frame to 0 to avoid the gif starting from the middle when lmb is pressed again
  273.  
  274.  
  275. if(pulseButton.sprite && pulseButton.frameTex[frameNum])//14 is just a plain black
  276. {
  277. pulseButton.DrawGifFrame(frameNum);
  278. }
  279. }
  280.  
  281. if(adjustRadarModeOnOff == 1)
  282. {
  283. //draw template/ruler
  284. if(ruler.IsInitialized())
  285. {
  286. POINT cPos;
  287. GetCursorPos(&cPos);
  288. ruler.SetPosition((float)cPos.x, (float)cPos.y, NULL, NULL);
  289. ruler.Draw();
  290. if(KeyPressed(VK_LBUTTON))
  291. {
  292. Position_ButtonAction(MENU_BUTTON_RADARMIDDLE);
  293. }
  294. }
  295. }
  296.  
  297. //draw label here
  298. Position_DrawLabel(i, xPos, yPos);
  299. }
  300. }
  301. pLine->End();
  302. }
  303. }
  304. }
  305.  
  306.  
  307. void Main_DrawLabel(int buttonNum, float x, float y)
  308. {
  309. RECT rect = { (int)x, (int)y, (int)x, (int)y};
  310. stringstream sso;
  311. switch(buttonNum)
  312. {
  313. case MENU_BUTTON_STREAMED:
  314. sso << "Mode: "<<(streamedOnOff?"All streamed":"faceTag");
  315. break;
  316.  
  317. case MENU_BUTTON_FACETAG:
  318. sso << "State: " << (faceTagOnOff?"ON":"OFF");
  319. break;
  320.  
  321. case MENU_BUTTON_LIST:
  322. sso << "Data list: " << (listOnOff?"ON":"OFF");
  323. break;
  324.  
  325. case MENU_BUTTON_POSITION:
  326. sso << "Adjust position";
  327. break;
  328.  
  329. case MENU_BUTTON_NAMES:
  330. sso << "Display names: " << (namesOnOff?"ON":"OFF");
  331. break;
  332. }
  333. pFont->DrawTextA(NULL, sso.str().c_str(), -1, &rect, DT_CENTER | DT_VCENTER | DT_NOCLIP, D3DCOLOR_RGBA(255,255,255,255));
  334. }
  335. void Main_ButtonAction(int buttonNum)
  336. {
  337. if(buttonNum == MENU_BUTTON_FACETAG)//togs everything
  338. {
  339. faceTagOnOff = !faceTagOnOff;
  340. settingsIni.WriteBoolean("Settings", "autoTurnOn", faceTagOnOff);
  341. }
  342.  
  343. if(buttonNum == MENU_BUTTON_STREAMED)
  344. {
  345. streamedOnOff = !streamedOnOff;
  346. settingsIni.WriteBoolean("Settings", "displayAllStreamed", streamedOnOff);
  347. if(!streamedOnOff){namesOnOff = false;}//there's no name drawing for personalized players so it's needed to avoid falsely displaying "names: ON"
  348. }
  349.  
  350. if(buttonNum == MENU_BUTTON_LIST)
  351. {
  352. listOnOff = !listOnOff;
  353. }
  354.  
  355. if(buttonNum == MENU_BUTTON_POSITION)
  356. {
  357. positionMenuOnOff = !positionMenuOnOff;
  358. }
  359.  
  360. if(buttonNum == MENU_BUTTON_NAMES)
  361. {
  362. namesOnOff = !namesOnOff;
  363. settingsIni.WriteBoolean("Settings", "displayNames", namesOnOff);
  364. }
  365. }
  366.  
  367.  
  368. void Position_DrawLabel(int buttonNum, float x, float y)
  369. {
  370. RECT rect = { (int)x, (int)y, (int)x, (int)y};
  371. stringstream sso;
  372. switch(buttonNum)
  373. {
  374. case MENU_BUTTON_HEIGHT:
  375. sso<<"Graphs height";
  376. rect.bottom -= (int)((float)pulseButton.height / 5.0f);
  377. rect.top -= (int)((float)pulseButton.height / 5.0f);
  378. DrawAdjuster(buttonNum);
  379. break;
  380.  
  381. case MENU_BUTTON_WIDTH:
  382. sso<<"Graphs width";
  383. rect.bottom -= (int)((float)pulseButton.height / 5.0f);
  384. rect.top -= (int)((float)pulseButton.height / 5.0f);
  385. DrawAdjuster(buttonNum);
  386. break;
  387.  
  388.  
  389. case MENU_BUTTON_UPPERTHRESHOLD:
  390. sso<<"Upper threshold";
  391. rect.bottom -= (int)((float)pulseButton.height / 5.0f);
  392. rect.top -= (int)((float)pulseButton.height / 5.0f);
  393. DrawAdjuster(buttonNum);
  394. break;
  395.  
  396. case MENU_BUTTON_LOWERTHRESHOLD:
  397. sso<<"Lower threshold";
  398. rect.bottom -= (int)((float)pulseButton.height / 5.0f);
  399. rect.top -= (int)((float)pulseButton.height / 5.0f);
  400. DrawAdjuster(buttonNum);
  401. break;
  402.  
  403. case MENU_BUTTON_RADARMIDDLE:
  404. sso<<"Adjust radar position";
  405. break;
  406.  
  407. case MENU_BUTTON_HORIZONTALOFFSET:
  408. sso<<"Horizontal position";
  409. rect.bottom -= (int)((float)pulseButton.height / 5.0f);
  410. rect.top -= (int)((float)pulseButton.height / 5.0f);
  411. DrawAdjuster(buttonNum);
  412. break;
  413. }
  414. pFont->DrawTextA(NULL, sso.str().c_str(), -1, &rect, DT_CENTER | DT_VCENTER | DT_NOCLIP, D3DCOLOR_RGBA(255,255,255,255));
  415. }
  416. void Position_ButtonAction(int buttonNum)
  417. {
  418. if(buttonNum == MENU_BUTTON_HEIGHT)
  419. {
  420. graphsSizeY = (int)menuElement[buttonNum].SetAdjusterValue(70.0f)*2.0f;
  421. settingsIni.WriteInteger("Settings", "graphsSizeY", (int)graphsSizeY);
  422. }
  423.  
  424. if(buttonNum == MENU_BUTTON_WIDTH)
  425. {
  426. graphsSizeX = (int)menuElement[buttonNum].SetAdjusterValue(299.0f);
  427. settingsIni.WriteInteger("Settings", "graphsSizeX", graphsSizeX);
  428. }
  429.  
  430. if(buttonNum == MENU_BUTTON_UPPERTHRESHOLD)
  431. {
  432. upperThreshold = menuElement[buttonNum].SetAdjusterValue(resolutionY);
  433. if(lowerThreshold > upperThreshold){lowerThreshold = menuElement[MENU_BUTTON_LOWERTHRESHOLD].SetAdjusterValue(resolutionY) - 1.0f;settingsIni.WriteFloat("Settings", "lowerThreshold", lowerThreshold);}
  434. settingsIni.WriteFloat("Settings", "upperThreshold", upperThreshold);
  435. }
  436.  
  437. if(buttonNum == MENU_BUTTON_LOWERTHRESHOLD)
  438. {
  439. lowerThreshold = menuElement[buttonNum].SetAdjusterValue(resolutionY);
  440. if(lowerThreshold > upperThreshold){upperThreshold = menuElement[MENU_BUTTON_UPPERTHRESHOLD].SetAdjusterValue(resolutionY) + 1.0f;settingsIni.WriteFloat("Settings", "upperThreshold", upperThreshold);}
  441. settingsIni.WriteFloat("Settings", "lowerThreshold", lowerThreshold);
  442. }
  443.  
  444. if(buttonNum == MENU_BUTTON_RADARMIDDLE)
  445. {
  446. adjustRadarModeOnOff++;
  447. if(adjustRadarModeOnOff == 2)
  448. {
  449. adjustRadarModeOnOff = 0;
  450. radarPosX = (float)cPos.x;
  451. radarPosY = (float)cPos.y;
  452. settingsIni.WriteFloat("Settings", "radarPosX", radarPosX);
  453. settingsIni.WriteFloat("Settings", "radarPosY", radarPosY);
  454. }
  455. }
  456.  
  457. if(buttonNum == MENU_BUTTON_HORIZONTALOFFSET)
  458. {
  459. horizontalOffset = menuElement[buttonNum].SetAdjusterValue(resolutionX);
  460. settingsIni.WriteFloat("Settings", "horizontalOffset", horizontalOffset);
  461. }
  462. }
  463.  
  464.  
  465. void DrawAdjuster(int i)
  466. {
  467. D3DXVECTOR2 line[] = {D3DXVECTOR2(1, 1), D3DXVECTOR2(1, 1)};
  468. //same y pos
  469. line[0].y = yPos + pulseButton.height / 5.0f;
  470. line[1].y = yPos + pulseButton.height / 5.0f;
  471.  
  472. line[0].x = xPos - pulseButton.width * 0.4f;
  473. line[1].x = xPos + pulseButton.width * 0.4f;
  474. pLine->Draw(line, 2, D3DCOLOR_XRGB(255, 255, 255));
  475.  
  476. //here draw some knob sprite depending on graphsSizeX and graphsSizeY
  477. if(adjArrow.IsInitialized())
  478. {
  479. if(!menuElement[i].arrowPosX)
  480. {
  481. menuElement[MENU_BUTTON_HEIGHT].arrowPosX= line[0].x + ((line[1].x-line[0].x)/140.0f*graphsSizeY);
  482. menuElement[MENU_BUTTON_WIDTH].arrowPosX= line[0].x + ((line[1].x-line[0].x)/299.0f*graphsSizeX);
  483. menuElement[MENU_BUTTON_UPPERTHRESHOLD].arrowPosX= line[0].x + ((line[1].x-line[0].x)/resolutionY*upperThreshold);
  484. menuElement[MENU_BUTTON_LOWERTHRESHOLD].arrowPosX= line[0].x + ((line[1].x-line[0].x)/resolutionY*lowerThreshold);
  485. }
  486.  
  487. adjArrow.SetPosition(menuElement[i].arrowPosX, line[0].y, NULL, NULL);
  488. adjArrow.Draw();
  489. }
  490.  
  491. }
  492.  
  493. float Cursor::SetAdjusterValue(float maxVal)
  494. {
  495. float retVal = NULL;
  496. float lStart = xPos - (float)pulseButton.width * 0.4f;//line start
  497. float lEnd = xPos + (float)pulseButton.width * 0.4f;//line end
  498. float lWidth = lEnd - lStart;
  499. GetCursorPos(&cPos);
  500.  
  501. if(cPos.x < lStart)
  502. {
  503. arrowPosX = lStart;
  504. retVal = 0.001f * maxVal;
  505. }
  506. else if(cPos.x > lEnd)
  507. {
  508. arrowPosX = lEnd;
  509. retVal = 1.0f * maxVal;
  510. }
  511. else
  512. {
  513. arrowPosX = (float)cPos.x;
  514. retVal = (cPos.x - lStart) / lWidth * maxVal;
  515. }
  516. return retVal;
  517. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement