@@ -7,46 +7,58 @@
*/
#include "..\..\..\Core.h"

UI_Window::UI_Window(PCoreString WindowCaption, float x, float y, float w, float h)
UI_Window::UI_Window(PCoreString WindowCaption, float x, float y, float w, float h, bool HasCaption)
{
strcpy_s(Caption, WindowCaption);
X = x;
Y = y;
W = w;
H = h;
WindowHasCaption = HasCaption;
}

void UI_Window::DrawWindow()
{
float _Y = Y;

// Draw titlebar
g_Core->Render->FillRect(X, Y, W, g_Core->CaptionSize + 2, TitleBackgroundColor);
g_Core->Render->DrawString(false, X + 10, Y + 2, TitleTextColor, Caption);
if (WindowHasCaption)
{
g_Core->Render->FillRect(X, _Y, W, g_Core->CaptionSize + 2, TitleBackgroundColor);
g_Core->Render->DrawString(false, X + 10, _Y + 2, TitleTextColor, Caption);

_Y += g_Core->CaptionSize + 2;
}

// Draw window
g_Core->Render->FillRect(X, Y + g_Core->CaptionSize + 2, W, H, BackgroundColor);
g_Core->Render->LineRect(X, Y, W, H + g_Core->CaptionSize + 2, 1, LineColor);
g_Core->Render->Line(X + 1, Y + g_Core->CaptionSize + 2, X + W, Y + g_Core->CaptionSize + 2, 1, LineColor);
g_Core->Render->DepthFrame(X, Y + g_Core->CaptionSize + 2, W, H);
g_Core->Render->FillRect(X, _Y, W, H, BackgroundColor);
g_Core->Render->LineRect(X, _Y - (WindowHasCaption ? g_Core->CaptionSize + 2 : 0), W, H + (WindowHasCaption ? g_Core->CaptionSize + 2 : 0), 1, LineColor);
g_Core->Render->Line(X + 1, _Y, X + W, _Y, 1, LineColor);
g_Core->Render->DepthFrame(X, _Y, W, H);

// Draw groupboxes
for (int i = 0; i < (int)UIGroupbox.size(); ++i)
UIGroupbox[i].Draw(X, Y);
UIGroupbox[i].Draw(X, _Y);

// Draw buttons
for (int i = 0; i < (int)UIGroupbox.size(); ++i)
UIButton[i].Draw(X, Y);
UIButton[i].Draw(X, _Y);

// Draw checkboxes
for (int i = 0; i < (int)UICheckbox.size(); ++i)
UICheckbox[i].Draw(X, Y);
UICheckbox[i].Draw(X, _Y);

// Draw labels
for (int i = 0; i < (int)UILabel.size(); ++i)
UILabel[i].Draw(X, Y);
UILabel[i].Draw(X, _Y);

// Draw Sliders
for (int i = 0; i < (int)UISlider.size(); ++i)
UISlider[i].Draw(X, Y);
UISlider[i].Draw(X, _Y);

// Draw Comboboxes
for (int i = 0; i < (int)UIComboBox.size(); ++i)
UIComboBox[i].Draw(X, _Y);
}

UI_Button* UI_Window::AddButton(UI_Button* Button)
@@ -67,6 +79,12 @@ UI_Checkbox* UI_Window::AddCheckbox(UI_Checkbox* CheckBox)
return &UICheckbox[UICheckbox.size() - 1];
}

UI_ComboBox* UI_Window::AddCombobox(UI_ComboBox* ComboBox)
{
UIComboBox.push_back(*ComboBox);
return &UIComboBox[UIComboBox.size() - 1];
}

UI_Label* UI_Window::AddLabel(UI_Label* Label)
{
UILabel.push_back(*Label);
@@ -79,6 +97,45 @@ UI_Slider* UI_Window::AddSlider(UI_Slider* Slider)
return &UISlider[UISlider.size() - 1];
}



UI_ComboBox* UI_Window::GetCombobox(PCoreString Text)
{
for (int i = 0; i < (int)UIComboBox.size() - 1; ++i)
{
for (int x = 0; x < (int)UIComboBox.size() - 1; ++x)
if (!_stricmp(UIComboBox[i].Items[x].Text, Text))
return &UIComboBox[i];
}

return NULL;
}

UI_ComboBox* UI_Window::GetCombobox(UI_ComboBox* ComboBox)
{
for (int i = 0; i < (int)UIComboBox.size() - 1; ++i)
if (ComboBox == &UIComboBox[i])
return &UIComboBox[i];

return NULL;
}

UI_ComboBox* UI_Window::GetCombobox(int Index)
{
if (Index > (int)UIComboBox.size() - 1)
return NULL;

return &UIComboBox[Index];
}

UI_ComboBox* UI_Window::GetCombobox()
{
if (UIComboBox.size() == 0)
return NULL;

return &UIComboBox[UICheckbox.size() - 1];
}

/*
UI Setup
@@ -96,43 +153,37 @@ void UI_Setup::DrawWindows()
MouseInfo->UpdateInfo();

// Handle window dragging
static UI_Window *DraggedElement = NULL;
for (int i = (int)UIWindow.size() - 1; i >= 0; --i)
{
if (!UIWindow[i].WindowHasCaption)
continue;

// Handle window dragging
static UI_Window *DraggedElement = NULL;
if (MouseInfo->Down)
if (MouseInfo->Down && MouseInfo->DraggedElement == NULL && MouseInfo->MouseOver(UIWindow[i].X, UIWindow[i].Y, UIWindow[i].W, g_Core->CaptionSize) || MouseInfo->Down && MouseInfo->DraggedElement == &UIWindow[i])
{
if (DraggedElement != NULL || MouseInfo->MouseOver(UIWindow[i].X, UIWindow[i].Y, UIWindow[i].W, g_Core->CaptionSize))
static int DiffX = 0;
static int DiffY = 0;

// Rearrange windows
if (MouseInfo->DraggedElement == NULL)
{
static float DiffX = 0;
static float DiffY = 0;

// Rearrange windows
if (DraggedElement == NULL)
{
std::iter_swap(UIWindow.begin() + (int)UIWindow.size() - 1, UIWindow.begin() + i);
DraggedElement = &UIWindow[(int)UIWindow.size() - 1];
DiffX = MouseInfo->X - DraggedElement->X;
DiffY = MouseInfo->Y - DraggedElement->Y;
}

if (DraggedElement != NULL)
{
DraggedElement->X = MouseInfo->X - DiffX;
DraggedElement->Y = MouseInfo->Y - DiffY;
}
std::iter_swap(UIWindow.begin() + (int)UIWindow.size() - 1, UIWindow.begin() + i);
MouseInfo->DraggedElement = &UIWindow[(int)UIWindow.size() - 1];
DiffX = MouseInfo->X - (int)((UI_Window*)(MouseInfo->DraggedElement))->X;
DiffY = MouseInfo->Y - (int)((UI_Window*)(MouseInfo->DraggedElement))->Y;
}

if (MouseInfo->DraggedElement != NULL)
{
((UI_Window*)(MouseInfo->DraggedElement))->X = (float)(MouseInfo->X - DiffX);
((UI_Window*)(MouseInfo->DraggedElement))->Y = (float)(MouseInfo->Y - DiffY);
}
}
else
DraggedElement = NULL;
}

// Handle windows
for (int i = 0; i < (int)UIWindow.size(); ++i)
{


// Draw windows
UIWindow[i].DrawWindow();
}
@@ -31,6 +31,7 @@
//Controls
#include "Controls\UI_Button.h"
#include "Controls\UI_CheckBox.h"
#include "Controls\UI_ComboBox.h"
#include "Controls\UI_Label.h"
#include "Controls\UI_GroupBox.h"
#include "Controls\UI_Slider.h"
@@ -40,7 +41,7 @@
class UI_Window
{
public:
UI_Window(PCoreString WindowCaption, float x, float y, float w, float h);
UI_Window(PCoreString WindowCaption, float x, float y, float w, float h, bool HasCaption = true);
~UI_Window() { }

public:
@@ -51,10 +52,18 @@ class UI_Window
UI_Button* AddButton(UI_Button* Button);
UI_GroupBox* AddGroupbox(UI_GroupBox* Groupbox);
UI_Checkbox* AddCheckbox(UI_Checkbox* CheckBox);
UI_ComboBox* AddCombobox(UI_ComboBox* ComboBox);
UI_Label* AddLabel(UI_Label* Label);
UI_Slider* AddSlider(UI_Slider* Slider);

public:
UI_ComboBox* GetCombobox(PCoreString Text);
UI_ComboBox* GetCombobox(UI_ComboBox* ComboBox);
UI_ComboBox* GetCombobox(int Index);
UI_ComboBox* GetCombobox();

public:
bool WindowHasCaption;
CoreString Caption;
float X, Y, W, H;
COLOR32 BackgroundColor = CLR_WINDOW_BACKGROUND;
@@ -63,10 +72,11 @@ class UI_Window
COLOR32 TitleBackgroundColor = CLR_TITLE_BACKGROUND;
COLOR32 TitleTextColor = CLR_CAPTION_TEXT;

private:
public:
std::vector<UI_Button> UIButton;
std::vector<UI_GroupBox> UIGroupbox;
std::vector<UI_Checkbox> UICheckbox;
std::vector<UI_ComboBox> UIComboBox;
std::vector<UI_Label> UILabel;
std::vector<UI_Slider> UISlider;
};
@@ -50,6 +50,16 @@ void UI_Mouse::UpdateInfo()
if (Y < 0) Y = 0;
if (Pos.x > Info.rcClient.right) X = Info.rcClient.right - Info.rcClient.left;
if (Pos.y > Info.rcClient.bottom) Y = Info.rcClient.bottom - Info.rcClient.top;

// Reset dragged element
if (DraggedElement != NULL)
Clicked = Up = false;
if (!Down)
DraggedElement = NULL;

// Handle focues objects
if (FocusedItem != NULL)
DraggedElement = NULL;
}

bool UI_Mouse::MouseOver(int x, int y, int w, int h)
@@ -12,6 +12,8 @@ typedef struct
bool Up;
bool Down;
bool Clicked;
PCoreFunction DraggedElement;
PCoreFunction FocusedItem;
}CoreMouseInfo;

class UI_Mouse : public CoreMouseInfo
@@ -73,12 +73,11 @@ LRESULT CWindowHandler::Register(HINSTANCE hInst, int nWidth, int nHeight, LPCTS
// Create window
X = 0;
Y = 0;
W = nWidth;
H = nHeight;
Rect = { X, Y, W, H };
W = (float)nWidth;
H = (float)nHeight;
Rect = { (int)X, (int)Y, (int)W, (int)H };
margin = { -1 };
hInstance = hInst;
//AdjustWindowRect(&Rect, WS_OVERLAPPEDWINDOW, FALSE);

if (Overlay)
{
@@ -121,7 +120,7 @@ LRESULT CWindowHandler::Register(HINSTANCE hInst, int nWidth, int nHeight, LPCTS
CLog::Log(eLogType::HIGH, " > SUCCESS [0x%p]", HWnd);
ShowWindow(HWnd, SW_SHOWNORMAL);
UpdateWindow(HWnd);
MoveWindow(HWnd, X, Y, W, H, FALSE);
MoveWindow(HWnd, (int)X, (int)Y, (int)W, (int)H, FALSE);

return S_OK;
}
BIN +60.5 KB (120%) Framework/Framework.exe
Binary file not shown.
@@ -53,14 +53,17 @@ CS16Main::CS16Main()
// Create window
CoreInt Test = 1;
CoreString szTest = "YO MOFO";
CoreFloat SliderValue = 25.0f;
SettingsWindow = GUI->RegisterWindow(new UI_Window("Settings", 200, 200, 400, 300));
CoreFloat SliderValue = 100;
SettingsWindow = GUI->RegisterWindow(new UI_Window("Settings", 200, 200, 400, 300, true));
SettingsWindow->AddCheckbox(new UI_Checkbox(&Test, "Test", 25, 25));
SettingsWindow->AddLabel(new UI_Label("Test Label ", 25, 50, szTest));
SettingsWindow->AddGroupbox(new UI_GroupBox("Test", 15, 15, 200, 150));
SettingsWindow->AddGroupbox(new UI_GroupBox("Test", 15, 15, 300, 200));
SettingsWindow->AddButton(new UI_Button("Test Button", 25, 75, Button_Test));
SettingsWindow->AddSlider(new UI_Slider(25, 125, 75, -50, 50, &SliderValue, UI_SLIDER_VALUE_TEXT));

SettingsWindow->AddSlider(new UI_Slider(25, 125, 150, -25, 25, &SliderValue, UI_SLIDER_VALUE_TEXT));
SettingsWindow->AddCombobox(new UI_ComboBox(25, 175, 150));
SettingsWindow->GetCombobox()->AddItem("First String");
SettingsWindow->GetCombobox()->AddItem("Second String");
SettingsWindow->GetCombobox()->AddItem("Third String");

// Check if core was successfully initialized
if (g_Core->CoreInitialized == false)