-
Автор темы
- #1
Обратите внимание, пользователь заблокирован на форуме. Не рекомендуется проводить сделки.
gui.cpp
window.cpp
void CGUI::Update()
{
static int bWasntHolding = false;
static int bGrabbing = false;
static int iOffsetX = 0, iOffsetY = 0;
//Key Array
std::copy(keys, keys + 255, oldKeys);
for (int x = 0; x < 255; x++)
{
//oldKeys[x] = oldKeys[x] & keys[x];
keys[x] = (GetAsyncKeyState(x));
}
POINT mp; GetCursorPos(&mp);
ScreenToClient(GetForegroundWindow(), &mp);
Mouse.x = mp.x; Mouse.y = mp.y;
RECT Screen = Render::GetViewport();
// Window Binds
for (auto& bind : WindowBinds)
{
if (GetKeyPress(bind.first))
{
bind.second->Toggle();
}
}
// Stop dragging
if (IsDraggingWindow && !GetKeyState(VK_LBUTTON))
{
IsDraggingWindow = false;
DraggingWindow = nullptr;
}
// If we are in the proccess of dragging a window
if (IsDraggingWindow && GetKeyState(VK_LBUTTON) && !GetKeyPress(VK_LBUTTON))
{
if (DraggingWindow)
{
DraggingWindow->m_x = Mouse.x - DragOffsetX;
DraggingWindow->m_y = Mouse.y - DragOffsetY;
}
}
//bWasntHolding = Input->Hovering(x, y, width, 28) && !GetAsyncKeyState(VK_LBUTTON);
// Process some windows
for (auto window : Windows)
{
if (window->m_bIsOpen)
{
// Used to tell the widget processing that there could be a click
bool bCheckWidgetClicks = false;
// If the user clicks inside the window
if (GetKeyPress(VK_LBUTTON) || GetKeyPress(VK_RETURN))
{
//if (IsMouseInRegion(window->m_x, window->m_y, window->m_x + window->m_iWidth, window->m_y + window->m_iHeight))
//{
// Is it inside the client area?
if (IsMouseInRegion(window->GetClientArea1()))
{
// User is selecting a new tab
if (IsMouseInRegion(window->GetTabArea()))
{
// Loose focus on the control
window->IsFocusingControl = false;
window->FocusedControl = nullptr;
int iTab = 0;
int TabCount = window->Tabs.size();
if (TabCount) // If there are some tabs
{
int TabSize = (window->m_iWidth - 4 - 12) / TabCount;
int Dist = Mouse.x - (window->m_x + 8);
while (Dist > TabSize)
{
if (Dist > TabSize)
{
iTab++;
Dist -= TabSize;
}
}
window->SelectedTab = window->Tabs[iTab];
}
}
else
bCheckWidgetClicks = true;
}
else if (IsMouseInRegion(window->m_x, window->m_y, window->m_x + window->m_iWidth, window->m_y + window->m_iHeight))
{
// Must be in the around the title or side of the window
// So we assume the user is trying to drag the window
IsDraggingWindow = true;
DraggingWindow = window;
DragOffsetX = Mouse.x - window->m_x;
DragOffsetY = Mouse.y - window->m_y;
// Loose focus on the control
window->IsFocusingControl = false;
window->FocusedControl = nullptr;
}
//else
//{
// // Loose focus on the control
// window->IsFocusingControl = false;
// window->FocusedControl = nullptr;
//}
}
// Controls
if (window->SelectedTab != nullptr)
{
// Focused widget
bool SkipWidget = false;
CControl* SkipMe = nullptr;
// this window is focusing on a widget??
if (window->IsFocusingControl)
{
if (window->FocusedControl != nullptr)
{
// We've processed it once, skip it later
SkipWidget = true;
SkipMe = window->FocusedControl;
POINT cAbs = window->FocusedControl->GetAbsolutePos();
RECT controlRect = { cAbs.x, cAbs.y, window->FocusedControl->m_iWidth, window->FocusedControl->m_iHeight };
window->FocusedControl->OnUpdate();
if (window->FocusedControl->Flag(UIFlags::UI_Clickable) && IsMouseInRegion(controlRect) && bCheckWidgetClicks)
{
window->FocusedControl->OnClick();
// If it gets clicked we loose focus
window->IsFocusingControl = false;
window->FocusedControl = nullptr;
bCheckWidgetClicks = false;
}
}
}
// Itterate over the rest of the control
for (auto control : window->SelectedTab->Controls)
{
if (control != nullptr)
{
if (SkipWidget && SkipMe == control)
continue;
POINT cAbs = control->GetAbsolutePos();
RECT controlRect = { cAbs.x, cAbs.y, control->m_iWidth, control->m_iHeight };
control->OnUpdate();
if (control->Flag(UIFlags::UI_Clickable) && IsMouseInRegion(controlRect) && bCheckWidgetClicks)
{
control->OnClick();
bCheckWidgetClicks = false;
// Change of focus
if (control->Flag(UIFlags::UI_Focusable))
{
window->IsFocusingControl = true;
window->FocusedControl = control;
}
else
{
window->IsFocusingControl = false;
window->FocusedControl = nullptr;
}
}
}
}
// We must have clicked whitespace
if (bCheckWidgetClicks)
{
// Loose focus on the control
window->IsFocusingControl = false;
window->FocusedControl = nullptr;
}
}
}
}
}
{
static int bWasntHolding = false;
static int bGrabbing = false;
static int iOffsetX = 0, iOffsetY = 0;
//Key Array
std::copy(keys, keys + 255, oldKeys);
for (int x = 0; x < 255; x++)
{
//oldKeys[x] = oldKeys[x] & keys[x];
keys[x] = (GetAsyncKeyState(x));
}
POINT mp; GetCursorPos(&mp);
ScreenToClient(GetForegroundWindow(), &mp);
Mouse.x = mp.x; Mouse.y = mp.y;
RECT Screen = Render::GetViewport();
// Window Binds
for (auto& bind : WindowBinds)
{
if (GetKeyPress(bind.first))
{
bind.second->Toggle();
}
}
// Stop dragging
if (IsDraggingWindow && !GetKeyState(VK_LBUTTON))
{
IsDraggingWindow = false;
DraggingWindow = nullptr;
}
// If we are in the proccess of dragging a window
if (IsDraggingWindow && GetKeyState(VK_LBUTTON) && !GetKeyPress(VK_LBUTTON))
{
if (DraggingWindow)
{
DraggingWindow->m_x = Mouse.x - DragOffsetX;
DraggingWindow->m_y = Mouse.y - DragOffsetY;
}
}
//bWasntHolding = Input->Hovering(x, y, width, 28) && !GetAsyncKeyState(VK_LBUTTON);
// Process some windows
for (auto window : Windows)
{
if (window->m_bIsOpen)
{
// Used to tell the widget processing that there could be a click
bool bCheckWidgetClicks = false;
// If the user clicks inside the window
if (GetKeyPress(VK_LBUTTON) || GetKeyPress(VK_RETURN))
{
//if (IsMouseInRegion(window->m_x, window->m_y, window->m_x + window->m_iWidth, window->m_y + window->m_iHeight))
//{
// Is it inside the client area?
if (IsMouseInRegion(window->GetClientArea1()))
{
// User is selecting a new tab
if (IsMouseInRegion(window->GetTabArea()))
{
// Loose focus on the control
window->IsFocusingControl = false;
window->FocusedControl = nullptr;
int iTab = 0;
int TabCount = window->Tabs.size();
if (TabCount) // If there are some tabs
{
int TabSize = (window->m_iWidth - 4 - 12) / TabCount;
int Dist = Mouse.x - (window->m_x + 8);
while (Dist > TabSize)
{
if (Dist > TabSize)
{
iTab++;
Dist -= TabSize;
}
}
window->SelectedTab = window->Tabs[iTab];
}
}
else
bCheckWidgetClicks = true;
}
else if (IsMouseInRegion(window->m_x, window->m_y, window->m_x + window->m_iWidth, window->m_y + window->m_iHeight))
{
// Must be in the around the title or side of the window
// So we assume the user is trying to drag the window
IsDraggingWindow = true;
DraggingWindow = window;
DragOffsetX = Mouse.x - window->m_x;
DragOffsetY = Mouse.y - window->m_y;
// Loose focus on the control
window->IsFocusingControl = false;
window->FocusedControl = nullptr;
}
//else
//{
// // Loose focus on the control
// window->IsFocusingControl = false;
// window->FocusedControl = nullptr;
//}
}
// Controls
if (window->SelectedTab != nullptr)
{
// Focused widget
bool SkipWidget = false;
CControl* SkipMe = nullptr;
// this window is focusing on a widget??
if (window->IsFocusingControl)
{
if (window->FocusedControl != nullptr)
{
// We've processed it once, skip it later
SkipWidget = true;
SkipMe = window->FocusedControl;
POINT cAbs = window->FocusedControl->GetAbsolutePos();
RECT controlRect = { cAbs.x, cAbs.y, window->FocusedControl->m_iWidth, window->FocusedControl->m_iHeight };
window->FocusedControl->OnUpdate();
if (window->FocusedControl->Flag(UIFlags::UI_Clickable) && IsMouseInRegion(controlRect) && bCheckWidgetClicks)
{
window->FocusedControl->OnClick();
// If it gets clicked we loose focus
window->IsFocusingControl = false;
window->FocusedControl = nullptr;
bCheckWidgetClicks = false;
}
}
}
// Itterate over the rest of the control
for (auto control : window->SelectedTab->Controls)
{
if (control != nullptr)
{
if (SkipWidget && SkipMe == control)
continue;
POINT cAbs = control->GetAbsolutePos();
RECT controlRect = { cAbs.x, cAbs.y, control->m_iWidth, control->m_iHeight };
control->OnUpdate();
if (control->Flag(UIFlags::UI_Clickable) && IsMouseInRegion(controlRect) && bCheckWidgetClicks)
{
control->OnClick();
bCheckWidgetClicks = false;
// Change of focus
if (control->Flag(UIFlags::UI_Focusable))
{
window->IsFocusingControl = true;
window->FocusedControl = control;
}
else
{
window->IsFocusingControl = false;
window->FocusedControl = nullptr;
}
}
}
}
// We must have clicked whitespace
if (bCheckWidgetClicks)
{
// Loose focus on the control
window->IsFocusingControl = false;
window->FocusedControl = nullptr;
}
}
}
}
}
RECT CWindow::GetClientArea()
{
RECT client;
client.left = m_x + 8;
client.top = m_y + 1 + 27;
client.right = m_iWidth - 4 - 12;
client.bottom = m_iHeight - 2 - 8 - 26 + 500;
return client;
}
{
RECT client;
client.left = m_x + 8;
client.top = m_y + 1 + 27;
client.right = m_iWidth - 4 - 12;
client.bottom = m_iHeight - 2 - 8 - 26 + 500;
return client;
}