Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Relevant parts:
- Declaration of the objectArray:
- ///////////////////
- Cursor playerElement[MAX_PLAYER_ELEMENTS];
- //////////////////
- That's where the ugly things happen:
- //////////////////
- void Cursor::SetPlayerElement
- //////////////////
- */
- #include "stdafx.h"
- #include <Windows.h>
- #include "C_cursor.h"
- #include "dllmain.h"
- #include "Csprite.h"
- #include "Cdynamic_graph.h"
- #include "CIniManager.h"
- #include <iostream>
- #include <ios>
- #include <fstream>
- void DrawMenu();
- Cursor menuElement[MAX_MENU_ELEMENTS];
- Cursor playerElement[MAX_PLAYER_ELEMENTS];
- float xPos=NULL;
- float yPos=NULL;
- POINT cPos;
- int lastClickedMenuButton=INVALID_ELEMENT;//can't be 0 because 0 is an actual element number too
- bool positionMenuOnOff=NULL;
- int adjustRadarModeOnOff=NULL;
- void Main_DrawLabel(int, float, float);
- void Main_ButtonAction(int buttonNum);
- void Position_DrawLabel(int, float, float);
- void Position_ButtonAction(int buttonNum);
- void DrawAdjuster(int);
- Cursor::Cursor()
- {
- id = INVALID_ELEMENT;
- listed = false;//is anything assigned to the element
- pos.l = 0.0f;
- pos.t = 0.0f;
- pos.r = 0.0f;
- pos.b = 0.0f;
- type = NULL; //personalized texture/any others(?)
- state = NULL; // clicked/notclicked/cursor_over/normal
- allignTo = NULL;
- }
- void ManageCursorElements()
- {
- if(isCursorEnabled)
- {
- //DrawMenu();
- //manage player elements
- for(int i=0;i<MAX_PLAYER_ELEMENTS;i++)
- {
- ofstream log("logfile.txt", ios_base::app | ios_base::out);
- if((playerElement[i].GetID()) != 2000)
- {
- log<<"found playerElement[i] i="<<i<<"\n";
- playerElement[i].DrawFrame();
- }
- else
- {
- log<<"NOT FOUND playerElement[i] i="<<i<<"\n";
- }
- }
- }
- }
- int Cursor::GetID()
- {
- return id;
- }
- void Cursor::UpdateElement()
- {
- //if(IsCursorOverElement())
- //{
- DrawFrame();
- //do the magic;d
- //}
- }
- void Cursor::DrawFrame()
- {
- ofstream log("logfile.txt", ios_base::app | ios_base::out);
- log<<"DRAWFRAME ID="<<id<< " x="<<pos.l<<" y="<<pos.t<<" x2="<<pos.r<<" y2="<<pos.b<<"\n";
- if(pLine)
- {
- pLine->SetWidth(2);
- pLine->SetAntialias(0);
- pLine->Begin();
- D3DXVECTOR2 line[] = {D3DXVECTOR2(1, 1), D3DXVECTOR2(1, 1)};
- //same y pos
- line[0].x = pos.l;
- line[0].y = pos.t;
- line[1].x = pos.r;
- line[1].y = pos.t;
- pLine->Draw(line, 2, D3DCOLOR_XRGB(255, 255, 255)); //top line
- line[0].x = pos.l;
- line[0].y = pos.b;
- line[1].x = pos.r;
- line[1].y = pos.b;
- pLine->Draw(line, 2, D3DCOLOR_XRGB(255, 255, 255));//bot line
- line[0].x = pos.l;
- line[0].y = pos.t;
- line[1].x = pos.l;
- line[1].y = pos.b;
- pLine->Draw(line, 2, D3DCOLOR_XRGB(255, 255, 255));//left line
- line[0].x = pos.r;
- line[0].y = pos.t;
- line[1].x = pos.r;
- line[1].y = pos.b;
- pLine->Draw(line, 2, D3DCOLOR_XRGB(255, 255, 255));//right line
- pLine->End();
- }
- }
- void Cursor::SetPlayerElement(float x, float y, float x2, float y2, int plID, int elementID)
- {
- pos.l = x;
- pos.t = y;
- pos.r = x2;
- pos.b = y2;
- id = plID;
- ofstream log("logfile.txt", ios_base::app | ios_base::out);
- log<<"SETPLAYERELEMENT ID="<<id<< " x="<<pos.l<<" y="<<pos.t<<" x2="<<pos.r<<" y2="<<pos.b<<" elementID="<<elementID<<"\n";
- 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";
- }
- bool Cursor::IsCursorOverElement()
- {
- 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
- //ofstream log("logfile.txt", ios_base::app | ios_base::out);
- //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";
- if((float)cPos.x > pos.l && (float)cPos.x < pos.r && (float)cPos.y > pos.t && (float)cPos.y < pos.b)
- {
- //log <<"true \n";
- return true;
- }
- return false;
- }
- void DrawMenu()
- {
- if(pulseButton.IsInitialized())
- {
- if(pLine)
- {
- pLine->SetWidth(2);
- pLine->SetAntialias(0);
- pLine->Begin();
- for(int i=4;i>=0;i--)//Main menu
- {
- int frameNum = 14;//plain black
- xPos = resolutionX * 0.9f;
- yPos = resolutionY * 0.93f - (((float)pulseButton.height + 5.0f) * i);
- menuElement[i].pos.l = xPos - (pulseButton.width/2); menuElement[i].pos.r = xPos + (pulseButton.width/2);
- menuElement[i].pos.t = yPos - (pulseButton.height/2); menuElement[i].pos.b = yPos + (pulseButton.height/2);
- pulseButton.SetPosition(xPos, yPos, NULL, NULL);
- if(menuElement[i].IsCursorOverElement()){frameNum = 0;}
- if(lastClickedMenuButton == i)
- {
- if(!KeyPressed(VK_LBUTTON) && menuElement[i].IsCursorOverElement())
- {
- lastClickedMenuButton = INVALID_ELEMENT;//reset
- //do the work for the specific button
- Main_ButtonAction(i);
- }
- }
- if(menuElement[i].IsCursorOverElement() && KeyPressed(VK_LBUTTON))
- {
- lastClickedMenuButton = i;
- pulseButton.DrawGif(16, NULL, false);
- }
- else
- {
- 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
- if(pulseButton.sprite && pulseButton.frameTex[frameNum])//14 is just a plain black
- {
- pulseButton.DrawGifFrame(frameNum);
- }
- }
- //draw label here
- Main_DrawLabel(i, xPos, yPos);
- }
- if(positionMenuOnOff)
- {
- for(int i=5;i>=0;i--)//Position menu
- {
- int frameNum = 14;//plain black
- xPos = resolutionX * 0.9f - (float)pulseButton.width - 5.0f;
- yPos = resolutionY * 0.93f - (((float)pulseButton.height + 5.0f) * i);
- menuElement[i].pos.l = xPos - (pulseButton.width/2); menuElement[i].pos.r = xPos + (pulseButton.width/2);
- menuElement[i].pos.t = yPos - (pulseButton.height/2); menuElement[i].pos.b = yPos + (pulseButton.height/2);
- pulseButton.SetPosition(xPos, yPos, NULL, NULL);
- if(menuElement[i].IsCursorOverElement()){frameNum = 0;}
- if(lastClickedMenuButton == i && !KeyPressed(VK_LBUTTON) && menuElement[i].IsCursorOverElement())//what happens after the button is clicked
- {
- lastClickedMenuButton = INVALID_ELEMENT;//reset
- //do the work for the specific button
- Position_ButtonAction(i);
- }
- if(menuElement[i].IsCursorOverElement() && KeyPressed(VK_LBUTTON))
- {
- lastClickedMenuButton = i;
- pulseButton.DrawGif(16, NULL, false);
- if(i == MENU_BUTTON_HEIGHT || i == MENU_BUTTON_WIDTH || i == MENU_BUTTON_UPPERTHRESHOLD || i == MENU_BUTTON_LOWERTHRESHOLD || i == MENU_BUTTON_HORIZONTALOFFSET){Position_ButtonAction(i);}
- }
- else
- {
- 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
- if(pulseButton.sprite && pulseButton.frameTex[frameNum])//14 is just a plain black
- {
- pulseButton.DrawGifFrame(frameNum);
- }
- }
- if(adjustRadarModeOnOff == 1)
- {
- //draw template/ruler
- if(ruler.IsInitialized())
- {
- POINT cPos;
- GetCursorPos(&cPos);
- ruler.SetPosition((float)cPos.x, (float)cPos.y, NULL, NULL);
- ruler.Draw();
- if(KeyPressed(VK_LBUTTON))
- {
- Position_ButtonAction(MENU_BUTTON_RADARMIDDLE);
- }
- }
- }
- //draw label here
- Position_DrawLabel(i, xPos, yPos);
- }
- }
- pLine->End();
- }
- }
- }
- void Main_DrawLabel(int buttonNum, float x, float y)
- {
- RECT rect = { (int)x, (int)y, (int)x, (int)y};
- stringstream sso;
- switch(buttonNum)
- {
- case MENU_BUTTON_STREAMED:
- sso << "Mode: "<<(streamedOnOff?"All streamed":"faceTag");
- break;
- case MENU_BUTTON_FACETAG:
- sso << "State: " << (faceTagOnOff?"ON":"OFF");
- break;
- case MENU_BUTTON_LIST:
- sso << "Data list: " << (listOnOff?"ON":"OFF");
- break;
- case MENU_BUTTON_POSITION:
- sso << "Adjust position";
- break;
- case MENU_BUTTON_NAMES:
- sso << "Display names: " << (namesOnOff?"ON":"OFF");
- break;
- }
- pFont->DrawTextA(NULL, sso.str().c_str(), -1, &rect, DT_CENTER | DT_VCENTER | DT_NOCLIP, D3DCOLOR_RGBA(255,255,255,255));
- }
- void Main_ButtonAction(int buttonNum)
- {
- if(buttonNum == MENU_BUTTON_FACETAG)//togs everything
- {
- faceTagOnOff = !faceTagOnOff;
- settingsIni.WriteBoolean("Settings", "autoTurnOn", faceTagOnOff);
- }
- if(buttonNum == MENU_BUTTON_STREAMED)
- {
- streamedOnOff = !streamedOnOff;
- settingsIni.WriteBoolean("Settings", "displayAllStreamed", streamedOnOff);
- if(!streamedOnOff){namesOnOff = false;}//there's no name drawing for personalized players so it's needed to avoid falsely displaying "names: ON"
- }
- if(buttonNum == MENU_BUTTON_LIST)
- {
- listOnOff = !listOnOff;
- }
- if(buttonNum == MENU_BUTTON_POSITION)
- {
- positionMenuOnOff = !positionMenuOnOff;
- }
- if(buttonNum == MENU_BUTTON_NAMES)
- {
- namesOnOff = !namesOnOff;
- settingsIni.WriteBoolean("Settings", "displayNames", namesOnOff);
- }
- }
- void Position_DrawLabel(int buttonNum, float x, float y)
- {
- RECT rect = { (int)x, (int)y, (int)x, (int)y};
- stringstream sso;
- switch(buttonNum)
- {
- case MENU_BUTTON_HEIGHT:
- sso<<"Graphs height";
- rect.bottom -= (int)((float)pulseButton.height / 5.0f);
- rect.top -= (int)((float)pulseButton.height / 5.0f);
- DrawAdjuster(buttonNum);
- break;
- case MENU_BUTTON_WIDTH:
- sso<<"Graphs width";
- rect.bottom -= (int)((float)pulseButton.height / 5.0f);
- rect.top -= (int)((float)pulseButton.height / 5.0f);
- DrawAdjuster(buttonNum);
- break;
- case MENU_BUTTON_UPPERTHRESHOLD:
- sso<<"Upper threshold";
- rect.bottom -= (int)((float)pulseButton.height / 5.0f);
- rect.top -= (int)((float)pulseButton.height / 5.0f);
- DrawAdjuster(buttonNum);
- break;
- case MENU_BUTTON_LOWERTHRESHOLD:
- sso<<"Lower threshold";
- rect.bottom -= (int)((float)pulseButton.height / 5.0f);
- rect.top -= (int)((float)pulseButton.height / 5.0f);
- DrawAdjuster(buttonNum);
- break;
- case MENU_BUTTON_RADARMIDDLE:
- sso<<"Adjust radar position";
- break;
- case MENU_BUTTON_HORIZONTALOFFSET:
- sso<<"Horizontal position";
- rect.bottom -= (int)((float)pulseButton.height / 5.0f);
- rect.top -= (int)((float)pulseButton.height / 5.0f);
- DrawAdjuster(buttonNum);
- break;
- }
- pFont->DrawTextA(NULL, sso.str().c_str(), -1, &rect, DT_CENTER | DT_VCENTER | DT_NOCLIP, D3DCOLOR_RGBA(255,255,255,255));
- }
- void Position_ButtonAction(int buttonNum)
- {
- if(buttonNum == MENU_BUTTON_HEIGHT)
- {
- graphsSizeY = (int)menuElement[buttonNum].SetAdjusterValue(70.0f)*2.0f;
- settingsIni.WriteInteger("Settings", "graphsSizeY", (int)graphsSizeY);
- }
- if(buttonNum == MENU_BUTTON_WIDTH)
- {
- graphsSizeX = (int)menuElement[buttonNum].SetAdjusterValue(299.0f);
- settingsIni.WriteInteger("Settings", "graphsSizeX", graphsSizeX);
- }
- if(buttonNum == MENU_BUTTON_UPPERTHRESHOLD)
- {
- upperThreshold = menuElement[buttonNum].SetAdjusterValue(resolutionY);
- if(lowerThreshold > upperThreshold){lowerThreshold = menuElement[MENU_BUTTON_LOWERTHRESHOLD].SetAdjusterValue(resolutionY) - 1.0f;settingsIni.WriteFloat("Settings", "lowerThreshold", lowerThreshold);}
- settingsIni.WriteFloat("Settings", "upperThreshold", upperThreshold);
- }
- if(buttonNum == MENU_BUTTON_LOWERTHRESHOLD)
- {
- lowerThreshold = menuElement[buttonNum].SetAdjusterValue(resolutionY);
- if(lowerThreshold > upperThreshold){upperThreshold = menuElement[MENU_BUTTON_UPPERTHRESHOLD].SetAdjusterValue(resolutionY) + 1.0f;settingsIni.WriteFloat("Settings", "upperThreshold", upperThreshold);}
- settingsIni.WriteFloat("Settings", "lowerThreshold", lowerThreshold);
- }
- if(buttonNum == MENU_BUTTON_RADARMIDDLE)
- {
- adjustRadarModeOnOff++;
- if(adjustRadarModeOnOff == 2)
- {
- adjustRadarModeOnOff = 0;
- radarPosX = (float)cPos.x;
- radarPosY = (float)cPos.y;
- settingsIni.WriteFloat("Settings", "radarPosX", radarPosX);
- settingsIni.WriteFloat("Settings", "radarPosY", radarPosY);
- }
- }
- if(buttonNum == MENU_BUTTON_HORIZONTALOFFSET)
- {
- horizontalOffset = menuElement[buttonNum].SetAdjusterValue(resolutionX);
- settingsIni.WriteFloat("Settings", "horizontalOffset", horizontalOffset);
- }
- }
- void DrawAdjuster(int i)
- {
- D3DXVECTOR2 line[] = {D3DXVECTOR2(1, 1), D3DXVECTOR2(1, 1)};
- //same y pos
- line[0].y = yPos + pulseButton.height / 5.0f;
- line[1].y = yPos + pulseButton.height / 5.0f;
- line[0].x = xPos - pulseButton.width * 0.4f;
- line[1].x = xPos + pulseButton.width * 0.4f;
- pLine->Draw(line, 2, D3DCOLOR_XRGB(255, 255, 255));
- //here draw some knob sprite depending on graphsSizeX and graphsSizeY
- if(adjArrow.IsInitialized())
- {
- if(!menuElement[i].arrowPosX)
- {
- menuElement[MENU_BUTTON_HEIGHT].arrowPosX= line[0].x + ((line[1].x-line[0].x)/140.0f*graphsSizeY);
- menuElement[MENU_BUTTON_WIDTH].arrowPosX= line[0].x + ((line[1].x-line[0].x)/299.0f*graphsSizeX);
- menuElement[MENU_BUTTON_UPPERTHRESHOLD].arrowPosX= line[0].x + ((line[1].x-line[0].x)/resolutionY*upperThreshold);
- menuElement[MENU_BUTTON_LOWERTHRESHOLD].arrowPosX= line[0].x + ((line[1].x-line[0].x)/resolutionY*lowerThreshold);
- }
- adjArrow.SetPosition(menuElement[i].arrowPosX, line[0].y, NULL, NULL);
- adjArrow.Draw();
- }
- }
- float Cursor::SetAdjusterValue(float maxVal)
- {
- float retVal = NULL;
- float lStart = xPos - (float)pulseButton.width * 0.4f;//line start
- float lEnd = xPos + (float)pulseButton.width * 0.4f;//line end
- float lWidth = lEnd - lStart;
- GetCursorPos(&cPos);
- if(cPos.x < lStart)
- {
- arrowPosX = lStart;
- retVal = 0.001f * maxVal;
- }
- else if(cPos.x > lEnd)
- {
- arrowPosX = lEnd;
- retVal = 1.0f * maxVal;
- }
- else
- {
- arrowPosX = (float)cPos.x;
- retVal = (cPos.x - lStart) / lWidth * maxVal;
- }
- return retVal;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement