Skip to content
This repository has been archived by the owner on Jul 29, 2020. It is now read-only.

Commit

Permalink
Merged menu rework (#55)
Browse files Browse the repository at this point in the history
* Initial Rework

- Separated input management and the control alignment
- Added main initialization
- Added a few virtual classes to make management easier
- Optimized some code using both multithreaded calculations etc.
- Changed function naming to be more coder-friendly
- Added the Focus system, will be useful for comboboxes / colorpickers and other advanced controls
- Changed the way how sections are aligned. Now you set their height as a percentage of the window height and it will align itself properly.
- Added TAB system.
- Prepared sections for scroll functionality

And many many more, basically changed everything.
To be done - all of the other controls that are commented rn.

* Fixed unhooking, more UI improvements

- Fixed unhooking killing fps as NetvarTree was just stuck in a "deleting" loop
- Cleaned and updated slider code as well as other selectables
- Made sections 90% ready for sliders.
  • Loading branch information
kwilcz committed Oct 12, 2018
1 parent 16fc79d commit 3854c9e
Show file tree
Hide file tree
Showing 12 changed files with 1,244 additions and 669 deletions.
1,091 changes: 717 additions & 374 deletions Antario/GUI/GUI.cpp

Large diffs are not rendered by default.

545 changes: 324 additions & 221 deletions Antario/GUI/GUI.h

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion Antario/Hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ void Hooks::Restore()
g_Hooks.pClientModeHook->Unhook(vtable_indexes::createMove);
g_Hooks.pSurfaceHook->Unhook(vtable_indexes::lockCursor);
SetWindowLongPtr(g_Hooks.hCSGOWindow, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(g_Hooks.pOriginalWNDProc));

g_pNetvars.release(); /* Need to release by-hand, global pointer so doesnt go out-of-scope */
}
Utils::Log("Unhooking succeded!");

Expand Down Expand Up @@ -199,7 +201,7 @@ LRESULT Hooks::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
// our wndproc capture fn
if (g_Settings.bMenuOpened)
{
g_Hooks.nMenu.RunThink(uMsg, lParam);
g_Hooks.nMenu.MsgProc(uMsg, wParam, lParam);
return true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion Antario/Hooks.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class Hooks
typedef long (__stdcall* Present_t) (IDirect3DDevice9*, const RECT*, const RECT*, HWND, const RGNDATA*);

private:
MenuMain nMenu;
ui::MenuMain nMenu;
HWND hCSGOWindow = nullptr; // CSGO window handle
bool bInitializedDrawManager = false; // Check if we initialized our draw manager
WNDPROC pOriginalWNDProc = nullptr; // Original CSGO window proc
Expand Down
70 changes: 50 additions & 20 deletions Antario/Menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,60 @@ void MenuMain::Initialize()
static int testint3 = 2;
static float float123 = 10.f;
/* Create our main window (Could have multiple if you'd create vec. for it) */
auto mainWindow = std::make_shared<BaseWindow>(SPoint(450, 450), SPoint(360, 256), g_Fonts.pFontTahoma8.get(), g_Fonts.pFontTahoma10.get(), "Antario - Main");
auto mainWindow = std::make_shared<Window>("Antario - Main", SSize(360, 256), g_Fonts.pFontTahoma8, g_Fonts.pFontTahoma10);
{
/* Create sections for it */
auto sectMain = mainWindow->AddSection(SPoint(310, 100), 2, "Test Section 1");
///TODO: window->AddTab()
auto tab1 = std::make_shared<Tab>("Main Tab", 2, mainWindow);
{
/* Add controls within section */
sectMain->AddCheckBox("Bunnyhop Enabled", &g_Settings.bBhopEnabled);
sectMain->AddCheckBox("Show Player Names", &g_Settings.bShowNames);
sectMain->AddButton("Shutdown", Detach);
sectMain->AddSlider("TestSlider", &float123, 0, 20);
sectMain->AddSlider("intslider", &testint3, 0, 10);
sectMain->AddCombo("TestCombo", std::vector<std::string>{ "Value1", "Value2", "Value3" }, &testint);
}

auto sectMain2 = mainWindow->AddSection(SPoint(310, 100), 2, "Test Section 2");
/* Create sections for it */
auto sectMain = tab1->AddSection("TestSect", 1.f);
{
/* Add controls within section */
sectMain->AddCheckBox("Bunnyhop Enabled", &g_Settings.bBhopEnabled);
sectMain->AddCheckBox("Show Player Names", &g_Settings.bShowNames);
sectMain->AddButton("Shutdown", Detach);
sectMain->AddSlider("TestSlider", &float123, 0, 20);
sectMain->AddSlider("intslider", &testint3, 0, 10);
//sectMain->AddCombo("TestCombo", std::vector<std::string>{ "Value1", "Value2", "Value3" }, &testint);
}

auto sectMain2 = tab1->AddSection("TestSect2", 1.f);
{
//sectMain2->AddCombo("TestCombo2", std::vector<std::string>{ "ttest", "ttest2", "ttest3" }, &testint2);
sectMain2->AddCheckBox("CheckboxSect2_1", &g_Settings.bShowBoxes);
sectMain2->AddCheckBox("Show Player Boxes", &g_Settings.bShowBoxes);
sectMain2->AddCheckBox("Show Player Weapons", &g_Settings.bShowWeapons);
}
} mainWindow->AddChild(tab1); /* For now */

auto tab2 = std::make_shared<Tab>("Test Tab", 1, mainWindow);
{
sectMain2->AddCombo("TestCombo2", std::vector<std::string>{ "ttest", "ttest2", "ttest3" }, &testint2);
sectMain2->AddCheckBox("CheckboxSect2_1", &g_Settings.bShowBoxes);
sectMain2->AddCheckBox("Show Player Boxes", &g_Settings.bShowBoxes);
sectMain2->AddCheckBox("Show Player Weapons", &g_Settings.bShowWeapons);
}
auto sectMain = tab2->AddSection("TestSect", .5f);
{
/* Add controls within section */
sectMain->AddCheckBox("CheckboxSect2_1", &g_Settings.bShowBoxes);
sectMain->AddCheckBox("Show Player Boxes", &g_Settings.bShowBoxes);
sectMain->AddCheckBox("Show Player Weapons", &g_Settings.bShowWeapons);
sectMain->AddButton("Shutdown", Detach);
sectMain->AddSlider("TestSlider", &float123, 0, 20);
sectMain->AddSlider("intslider", &testint3, 0, 10);
//sectMain->AddCombo("TestCombo", std::vector<std::string>{ "Value1", "Value2", "Value3" }, &testint);
}

auto sectMain2 = tab2->AddSection("TestSect2", .5f);
{
//sectMain2->AddCombo("TestCombo2", std::vector<std::string>{ "ttest", "ttest2", "ttest3" }, &testint2);
sectMain2->AddCheckBox("Bunnyhop Enabled", &g_Settings.bBhopEnabled);
sectMain2->AddCheckBox("Show Player Names", &g_Settings.bShowNames);
}
} mainWindow->AddChild(tab2);
}
this->AddChild(mainWindow);
this->vecChildren.push_back(mainWindow);

/* Create our mouse cursor (one instance only) */
mouseCursor = std::make_unique<MouseCursor>();
mouseCursor = std::make_unique<MouseCursor>();

/* Do the first init run through all of the objects */
for (auto& it : vecChildren)
it->Initialize();
}
70 changes: 35 additions & 35 deletions Antario/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,41 +58,41 @@ void Settings::SaveSettings(const std::string& strFileName, MenuMain* pMenuObj)
* Just create a new `MenuSelectableType` for it
* and loop like in TYPE_SECTION to create sub-settings.
*/
case MenuSelectableType::TYPE_MAIN:
case MenuSelectableType::TYPE_WINDOW:
{
/* Recurrent call so we save settings for all of the child objects. */
loopChildSettings(it.get()/*, parentElement*/);
break;
}
case MenuSelectableType::TYPE_SECTION:
{
/*
* Create section inside your file to which you will assign child objects (child elements, w/e)
* Then loop through child objects and save them. You can use it->strLabel to get section name.
*/
loopChildSettings(it.get()/*, SectionElement*/);
break;
}
case MenuSelectableType::TYPE_CHECKBOX:
{
auto tmpChkbx = dynamic_cast<Checkbox*>(it.get());
/*
* Save checkbox value into your settings. Setting parent should be transfered in lambda call
* You can use tmpChkbx->strLabel to get the name and tmpChkbx->bCheckboxValue to get true/false.
*/
break;
}
case MenuSelectableType::TYPE_COMBO:
{
auto tmpCombo = dynamic_cast<ComboBox*>(it.get());
/*
* Save combo index into your settings. Setting parent should be transfered in lambda call
* You can use tmpCombo->strLabel to get the name and tmpCombo->iCurrentValue to get the index.
*/
break;
}
default: break;
case MST::TYPE_INCORR:
case MST::TYPE_WINDOW:
{
/* Recurrent call so we save settings for all of the child objects. */
loopChildSettings(it.get()/*, parentElement*/);
break;
}
case MST::TYPE_SECTION:
{
/*
* Create section inside your file to which you will assign child objects (child elements, w/e)
* Then loop through child objects and save them. You can use it->strLabel to get section name.
*/
loopChildSettings(it.get()/*, SectionElement*/);
break;
}
case MST::TYPE_CHECKBOX:
{
auto tmpChkbx = dynamic_cast<Checkbox*>(it.get());
/*
* Save checkbox value into your settings. Setting parent should be transfered in lambda call
* You can use tmpChkbx->strLabel to get the name and tmpChkbx->bCheckboxValue to get true/false.
*/
break;
}
case MST::TYPE_COMBO:
{
//auto tmpCombo = dynamic_cast<ComboBox*>(it.get());
/*
* Save combo index into your settings. Setting parent should be transfered in lambda call
* You can use tmpCombo->strLabel to get the name and tmpCombo->iCurrentValue to get the index.
*/
break;
}
default: break;
}
}
};
Expand Down
5 changes: 2 additions & 3 deletions Antario/Settings.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#pragma once
#include "GUI\GUI.h"
#include <filesystem>

/* forward declarations so i wont have to include these */
class MenuMain;

using namespace ui;
namespace fs = std::experimental::filesystem;

class Settings
Expand Down
107 changes: 100 additions & 7 deletions Antario/Utils/Color.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,127 @@ struct Color
constexpr Color() : red(0), green(0), blue(0), alpha(255) { }

constexpr Color(int r, int g, int b, int a = 255)
: red(r), green(g), blue(b), alpha(a) { }
: red{ r }, green{ g }, blue{ b }, alpha{ a } { }

constexpr Color& operator *=(const float coeff)
{
this->red = int(this->red * coeff);
this->green = int(this->green * coeff);
this->blue = int(this->blue * coeff);
this->red = static_cast<int>(this->red * coeff);
this->green = static_cast<int>(this->green * coeff);
this->blue = static_cast<int>(this->blue * coeff);
return *this;
}

constexpr Color operator ()(const int a) const
{
return Color(red, green, blue, a);
}

constexpr Color& operator /=(const float div)
{
const float flDiv = 1.f / div;
const auto flDiv = 1.f / div;
*this *= flDiv;
return *this;
}

constexpr Color operator *(const float coeff) const
constexpr Color& operator *(const float coeff) const
{
Color color = *this;
auto color = *this;
return color *= coeff;
}

constexpr DWORD GetARGB() const
{
return 0;
}

constexpr Color& FromHSV(float h, float s, float v)
{
float colOut[3]{ };
if (s == 0.0f)
{
red = green = blue = static_cast<int>(v * 255);
return *this;
}

h = std::fmodf(h, 1.0f) / (60.0f / 360.0f);
int i = static_cast<int>(h);
float f = h - static_cast<float>(i);
float p = v * (1.0f - s);
float q = v * (1.0f - s * f);
float t = v * (1.0f - s * (1.0f - f));

switch (i)
{
case 0:
colOut[0] = v;
colOut[1] = t;
colOut[2] = p;
break;
case 1:
colOut[0] = q;
colOut[1] = v;
colOut[2] = p;
break;
case 2:
colOut[0] = p;
colOut[1] = v;
colOut[2] = t;
break;
case 3:
colOut[0] = p;
colOut[1] = q;
colOut[2] = v;
break;
case 4:
colOut[0] = t;
colOut[1] = p;
colOut[2] = v;
break;
case 5: default:
colOut[0] = v;
colOut[1] = p;
colOut[2] = q;
break;
}

red = static_cast<int>(colOut[0] * 255);
green = static_cast<int>(colOut[1] * 255);
blue = static_cast<int>(colOut[2] * 255);
return *this;
}

constexpr auto ToHSV(float& h, float& s, float& v)
{
float col[3] = { red / 255.f, green / 255.f, blue / 255.f };

float K = 0.f;
if (col[1] < col[2])
{
swap(col[1], col[2]);
K = -1.f;
}
if (col[0] < col[1])
{
swap(col[0], col[1]);
K = -2.f / 6.f - K;
}

const float chroma = col[0] - (col[1] < col[2] ? col[1] : col[2]);
h = colfabs(K + (col[1] - col[2]) / (6.f * chroma + 1e-20f));
s = chroma / (col[0] + 1e-20f);
v = col[1];
}


static constexpr Color Black(int a = 255) { return { 0, 0, 0, a }; }
static constexpr Color Grey(int a = 255) { return { 127, 127, 127, a }; }
static constexpr Color White(int a = 255) { return { 255, 255, 255, a }; }
static constexpr Color Red(int a = 255) { return { 255, 0, 0, a }; }
static constexpr Color Green(int a = 255) { return { 0, 255, 0, a }; }
static constexpr Color Blue(int a = 255) { return { 0, 0, 255, a }; }

private:
constexpr void swap(float& a, float& b) { float tmp = a; a = b; b = tmp; }
constexpr float colfabs(const float& x) { return x < 0 ? x * -1 : x; }

};
6 changes: 2 additions & 4 deletions Antario/Utils/D3DFont.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,8 @@ class CD3DFont

public:
// 2D text drawing functions
HRESULT DrawString(FLOAT x, FLOAT y, DWORD dwColor,
const char* strText, DWORD dwFlags = 0L);
HRESULT DrawStringScaled(FLOAT x, FLOAT y, FLOAT fXScale, FLOAT fYScale,
DWORD dwColor, const char* strText, DWORD dwFlags = 0L);
HRESULT DrawString(FLOAT x, FLOAT y, DWORD dwColor, const char* strText, DWORD dwFlags = 0L);
HRESULT DrawStringScaled(FLOAT x, FLOAT y, FLOAT fXScale, FLOAT fYScale, DWORD dwColor, const char* strText, DWORD dwFlags = 0L);

// Function to get extent of text
HRESULT GetTextExtent(const char* strText, SIZE* pSize);
Expand Down
4 changes: 4 additions & 0 deletions Antario/Utils/DrawManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ void DrawManager::Rect(SPoint vecPos1, SPoint vecPos2, Color color) const
void DrawManager::Rect(int posx1, int posy1, int posx2, int posy2, Color color) const
{
D3DCOLOR dwColor = COL2DWORD(color);

/* Fix that fuckin offset of the rectangles */
posx2 -= 1; posy2 -= 1;

Vertex vert[5] =
{ // Draw lines between declared points, needs primitive count as number of lines (4 here)
{ float(posx1), float(posy1), 1.0f, 1.0f, dwColor }, // Top left corner
Expand Down
4 changes: 2 additions & 2 deletions Antario/Utils/DrawManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ struct Fonts
};

// Fonts
std::unique_ptr<CD3DFont> pFontTahoma8;
std::unique_ptr<CD3DFont> pFontTahoma10;
std::shared_ptr<CD3DFont> pFontTahoma8;
std::shared_ptr<CD3DFont> pFontTahoma10;
};
extern Fonts g_Fonts;

Expand Down
5 changes: 4 additions & 1 deletion Antario/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ VOID WINAPI OnDllDetach()
#ifdef _DEBUG
fclose((FILE*)stdin);
fclose((FILE*)stdout);
FreeConsole(); // Free allocated memory and remove console

HWND hw_ConsoleHwnd = GetConsoleWindow(); //Get the HWND of the console.
FreeConsole(); //Detach the console.
PostMessageW(hw_ConsoleHwnd, WM_CLOSE, 0, 0); //Destroys the window.
#endif
}

Expand Down

0 comments on commit 3854c9e

Please sign in to comment.