mirror of
https://github.com/ZDoom/gzdoom.git
synced 2025-01-18 23:52:02 +00:00
Implement launcher window base functionality
This commit is contained in:
parent
0b3d3966a6
commit
19c2ea171d
5 changed files with 89 additions and 7 deletions
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include "../../core/widget.h"
|
||||
#include <vector>
|
||||
#include <functional>
|
||||
|
||||
class ListView : public Widget
|
||||
{
|
||||
|
@ -10,6 +11,11 @@ public:
|
|||
ListView(Widget* parent = nullptr);
|
||||
|
||||
void AddItem(const std::string& text);
|
||||
int GetSelectedItem() const { return selectedItem; }
|
||||
|
||||
void Activate();
|
||||
|
||||
std::function<void()> OnActivated;
|
||||
|
||||
protected:
|
||||
void OnPaint(Canvas* canvas) override;
|
||||
|
|
|
@ -12,6 +12,12 @@ void ListView::AddItem(const std::string& text)
|
|||
Update();
|
||||
}
|
||||
|
||||
void ListView::Activate()
|
||||
{
|
||||
if (OnActivated)
|
||||
OnActivated();
|
||||
}
|
||||
|
||||
void ListView::OnPaint(Canvas* canvas)
|
||||
{
|
||||
double y = 20.0;
|
||||
|
@ -47,10 +53,24 @@ void ListView::OnPaintFrame(Canvas* canvas)
|
|||
void ListView::OnMouseDown(const Point& pos, int key)
|
||||
{
|
||||
SetFocus();
|
||||
|
||||
if (key == IK_LeftMouse)
|
||||
{
|
||||
int index = (int)((pos.y - 5.0) / 20.0);
|
||||
if (index >= 0 && (size_t)index < items.size())
|
||||
{
|
||||
selectedItem = index;
|
||||
Update();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ListView::OnMouseDoubleclick(const Point& pos, int key)
|
||||
{
|
||||
if (key == IK_LeftMouse)
|
||||
{
|
||||
Activate();
|
||||
}
|
||||
}
|
||||
|
||||
void ListView::OnKeyDown(EInputKey key)
|
||||
|
@ -71,4 +91,8 @@ void ListView::OnKeyDown(EInputKey key)
|
|||
Update();
|
||||
}
|
||||
}
|
||||
else if (key == IK_Enter)
|
||||
{
|
||||
Activate();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -69,7 +69,12 @@ Win32Window::Win32Window(DisplayWindowHost* windowHost) : WindowHost(windowHost)
|
|||
classdesc.lpfnWndProc = &Win32Window::WndProc;
|
||||
RegisterClassEx(&classdesc);
|
||||
|
||||
CreateWindowEx(WS_EX_APPWINDOW, L"ZWidgetWindow", L"", WS_OVERLAPPEDWINDOW, 0, 0, 100, 100, 0, 0, GetModuleHandle(0), this);
|
||||
// Microsoft logic at its finest:
|
||||
// WS_EX_DLGMODALFRAME hides the sysmenu icon
|
||||
// WS_CAPTION shows the caption (yay! actually a flag that does what it says it does!)
|
||||
// WS_SYSMENU shows the min/max/close buttons
|
||||
// WS_THICKFRAME makes the window resizable
|
||||
CreateWindowEx(WS_EX_APPWINDOW | WS_EX_DLGMODALFRAME, L"ZWidgetWindow", L"", WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX, 0, 0, 100, 100, 0, 0, GetModuleHandle(0), this);
|
||||
|
||||
/*
|
||||
RAWINPUTDEVICE rid;
|
||||
|
|
|
@ -20,16 +20,16 @@ int LauncherWindow::ExecModal(WadStuff* wads, int numwads, int defaultiwad, int*
|
|||
double windowWidth = 615.0;
|
||||
double windowHeight = 668.0;
|
||||
|
||||
auto launcher = new LauncherWindow(wads, numwads, defaultiwad, autoloadflags);
|
||||
auto launcher = std::make_unique<LauncherWindow>(wads, numwads, defaultiwad, autoloadflags);
|
||||
launcher->SetFrameGeometry((screenSize.width - windowWidth) * 0.5, (screenSize.height - windowHeight) * 0.5, windowWidth, windowHeight);
|
||||
launcher->Show();
|
||||
|
||||
DisplayWindow::RunLoop();
|
||||
|
||||
return 0;
|
||||
return launcher->ExecResult;
|
||||
}
|
||||
|
||||
LauncherWindow::LauncherWindow(WadStuff* wads, int numwads, int defaultiwad, int* autoloadflags) : Widget(nullptr, WidgetType::Window)
|
||||
LauncherWindow::LauncherWindow(WadStuff* wads, int numwads, int defaultiwad, int* autoloadflags) : Widget(nullptr, WidgetType::Window), AutoloadFlags(autoloadflags)
|
||||
{
|
||||
SetWindowBackground(Colorf::fromRgba8(51, 51, 51));
|
||||
SetWindowBorderColor(Colorf::fromRgba8(51, 51, 51));
|
||||
|
@ -53,6 +53,10 @@ LauncherWindow::LauncherWindow(WadStuff* wads, int numwads, int defaultiwad, int
|
|||
ExitButton = new PushButton(this);
|
||||
GamesList = new ListView(this);
|
||||
|
||||
PlayButton->OnClick = [=]() { OnPlayButtonClicked(); };
|
||||
ExitButton->OnClick = [=]() { OnExitButtonClicked(); };
|
||||
GamesList->OnActivated = [=]() { OnGamesListActivated(); };
|
||||
|
||||
SelectLabel->SetText("Select which game file (IWAD) to run.");
|
||||
PlayButton->SetText("Play Game");
|
||||
ExitButton->SetText("Exit");
|
||||
|
@ -72,10 +76,11 @@ LauncherWindow::LauncherWindow(WadStuff* wads, int numwads, int defaultiwad, int
|
|||
WelcomeLabel->SetText(welcomeText.GetChars());
|
||||
VersionLabel->SetText(versionText.GetChars());
|
||||
|
||||
int flags = *autoloadflags;
|
||||
FullscreenCheckbox->SetChecked(vid_fullscreen);
|
||||
DisableAutoloadCheckbox->SetChecked(flags & 1);
|
||||
DontAskAgainCheckbox->SetChecked(!queryiwad);
|
||||
|
||||
int flags = *autoloadflags;
|
||||
DisableAutoloadCheckbox->SetChecked(flags & 1);
|
||||
LightsCheckbox->SetChecked(flags & 2);
|
||||
BrightmapsCheckbox->SetChecked(flags & 4);
|
||||
WidescreenCheckbox->SetChecked(flags & 8);
|
||||
|
@ -96,6 +101,40 @@ LauncherWindow::LauncherWindow(WadStuff* wads, int numwads, int defaultiwad, int
|
|||
}
|
||||
|
||||
Logo->SetImage(Image::LoadResource("widgets/banner.png"));
|
||||
|
||||
GamesList->SetFocus();
|
||||
}
|
||||
|
||||
void LauncherWindow::OnClose()
|
||||
{
|
||||
OnExitButtonClicked();
|
||||
}
|
||||
|
||||
void LauncherWindow::OnPlayButtonClicked()
|
||||
{
|
||||
vid_fullscreen = FullscreenCheckbox->GetChecked();
|
||||
queryiwad = !DontAskAgainCheckbox->GetChecked();
|
||||
|
||||
int flags = 0;
|
||||
if (DisableAutoloadCheckbox->GetChecked()) flags |= 1;
|
||||
if (LightsCheckbox->GetChecked()) flags |= 2;
|
||||
if (BrightmapsCheckbox->GetChecked()) flags |= 4;
|
||||
if (WidescreenCheckbox->GetChecked()) flags |= 8;
|
||||
*AutoloadFlags = flags;
|
||||
|
||||
ExecResult = GamesList->GetSelectedItem();
|
||||
DisplayWindow::ExitLoop();
|
||||
}
|
||||
|
||||
void LauncherWindow::OnExitButtonClicked()
|
||||
{
|
||||
ExecResult = -1;
|
||||
DisplayWindow::ExitLoop();
|
||||
}
|
||||
|
||||
void LauncherWindow::OnGamesListActivated()
|
||||
{
|
||||
OnPlayButtonClicked();
|
||||
}
|
||||
|
||||
void LauncherWindow::OnGeometryChanged()
|
||||
|
|
|
@ -14,9 +14,14 @@ class LauncherWindow : public Widget
|
|||
public:
|
||||
static int ExecModal(WadStuff* wads, int numwads, int defaultiwad, int* autoloadflags);
|
||||
|
||||
private:
|
||||
LauncherWindow(WadStuff* wads, int numwads, int defaultiwad, int* autoloadflags);
|
||||
|
||||
private:
|
||||
void OnPlayButtonClicked();
|
||||
void OnExitButtonClicked();
|
||||
void OnGamesListActivated();
|
||||
|
||||
void OnClose() override;
|
||||
void OnGeometryChanged() override;
|
||||
|
||||
ImageBox* Logo = nullptr;
|
||||
|
@ -34,4 +39,7 @@ private:
|
|||
PushButton* PlayButton = nullptr;
|
||||
PushButton* ExitButton = nullptr;
|
||||
ListView* GamesList = nullptr;
|
||||
|
||||
int* AutoloadFlags = nullptr;
|
||||
int ExecResult = -1;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue