mirror of
https://github.com/ZDoom/gzdoom.git
synced 2025-02-22 20:11:14 +00:00
Hook up the zwidget launcher window on Linux
This commit is contained in:
parent
b0f1edf297
commit
2863c89af7
3 changed files with 64 additions and 83 deletions
|
@ -18,9 +18,14 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
SDL2DisplayWindow::SDL2DisplayWindow(DisplayWindowHost* windowHost) : WindowHost(windowHost)
|
static void CheckInitSDL()
|
||||||
{
|
{
|
||||||
static InitSDL initsdl;
|
static InitSDL initsdl;
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL2DisplayWindow::SDL2DisplayWindow(DisplayWindowHost* windowHost) : WindowHost(windowHost)
|
||||||
|
{
|
||||||
|
CheckInitSDL();
|
||||||
|
|
||||||
int result = SDL_CreateWindowAndRenderer(320, 200, SDL_WINDOW_HIDDEN /*| SDL_WINDOW_ALLOW_HIGHDPI*/, &WindowHandle, &RendererHandle);
|
int result = SDL_CreateWindowAndRenderer(320, 200, SDL_WINDOW_HIDDEN /*| SDL_WINDOW_ALLOW_HIGHDPI*/, &WindowHandle, &RendererHandle);
|
||||||
if (result != 0)
|
if (result != 0)
|
||||||
|
@ -32,6 +37,13 @@ SDL2DisplayWindow::SDL2DisplayWindow(DisplayWindowHost* windowHost) : WindowHost
|
||||||
SDL2DisplayWindow::~SDL2DisplayWindow()
|
SDL2DisplayWindow::~SDL2DisplayWindow()
|
||||||
{
|
{
|
||||||
WindowList.erase(WindowList.find(SDL_GetWindowID(WindowHandle)));
|
WindowList.erase(WindowList.find(SDL_GetWindowID(WindowHandle)));
|
||||||
|
|
||||||
|
if (BackBufferTexture)
|
||||||
|
{
|
||||||
|
SDL_DestroyTexture(BackBufferTexture);
|
||||||
|
BackBufferTexture = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
SDL_DestroyRenderer(RendererHandle);
|
SDL_DestroyRenderer(RendererHandle);
|
||||||
SDL_DestroyWindow(WindowHandle);
|
SDL_DestroyWindow(WindowHandle);
|
||||||
RendererHandle = nullptr;
|
RendererHandle = nullptr;
|
||||||
|
@ -182,6 +194,36 @@ double SDL2DisplayWindow::GetDpiScale() const
|
||||||
|
|
||||||
void SDL2DisplayWindow::PresentBitmap(int width, int height, const uint32_t* pixels)
|
void SDL2DisplayWindow::PresentBitmap(int width, int height, const uint32_t* pixels)
|
||||||
{
|
{
|
||||||
|
if (!BackBufferTexture || BackBufferWidth != width || BackBufferHeight != height)
|
||||||
|
{
|
||||||
|
if (BackBufferTexture)
|
||||||
|
{
|
||||||
|
SDL_DestroyTexture(BackBufferTexture);
|
||||||
|
BackBufferTexture = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
BackBufferTexture = SDL_CreateTexture(RendererHandle, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, width, height);
|
||||||
|
if (!BackBufferTexture)
|
||||||
|
return;
|
||||||
|
|
||||||
|
BackBufferWidth = width;
|
||||||
|
BackBufferHeight = height;
|
||||||
|
}
|
||||||
|
|
||||||
|
int destpitch = 0;
|
||||||
|
void* dest = nullptr;
|
||||||
|
int result = SDL_LockTexture(BackBufferTexture, nullptr, &dest, &destpitch);
|
||||||
|
if (result != 0) return;
|
||||||
|
for (int y = 0; y < height; y++)
|
||||||
|
{
|
||||||
|
const void* sline = pixels + y * width;
|
||||||
|
void* dline = (uint8_t*)dest + y * destpitch;
|
||||||
|
memcpy(dline, sline, width << 2);
|
||||||
|
}
|
||||||
|
SDL_UnlockTexture(BackBufferTexture);
|
||||||
|
|
||||||
|
SDL_RenderCopy(RendererHandle, BackBufferTexture, nullptr, nullptr);
|
||||||
|
SDL_RenderPresent(RendererHandle);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SDL2DisplayWindow::SetBorderColor(uint32_t bgra8)
|
void SDL2DisplayWindow::SetBorderColor(uint32_t bgra8)
|
||||||
|
@ -216,6 +258,8 @@ void SDL2DisplayWindow::SetClipboardText(const std::string& text)
|
||||||
|
|
||||||
void SDL2DisplayWindow::ProcessEvents()
|
void SDL2DisplayWindow::ProcessEvents()
|
||||||
{
|
{
|
||||||
|
CheckInitSDL();
|
||||||
|
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
while (SDL_PollEvent(&event) != 0)
|
while (SDL_PollEvent(&event) != 0)
|
||||||
{
|
{
|
||||||
|
@ -225,6 +269,8 @@ void SDL2DisplayWindow::ProcessEvents()
|
||||||
|
|
||||||
void SDL2DisplayWindow::RunLoop()
|
void SDL2DisplayWindow::RunLoop()
|
||||||
{
|
{
|
||||||
|
CheckInitSDL();
|
||||||
|
|
||||||
while (!ExitRunLoop)
|
while (!ExitRunLoop)
|
||||||
{
|
{
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
|
@ -237,11 +283,15 @@ void SDL2DisplayWindow::RunLoop()
|
||||||
|
|
||||||
void SDL2DisplayWindow::ExitLoop()
|
void SDL2DisplayWindow::ExitLoop()
|
||||||
{
|
{
|
||||||
|
CheckInitSDL();
|
||||||
|
|
||||||
ExitRunLoop = true;
|
ExitRunLoop = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Size SDL2DisplayWindow::GetScreenSize()
|
Size SDL2DisplayWindow::GetScreenSize()
|
||||||
{
|
{
|
||||||
|
CheckInitSDL();
|
||||||
|
|
||||||
SDL_Rect rect = {};
|
SDL_Rect rect = {};
|
||||||
int result = SDL_GetDisplayBounds(0, &rect);
|
int result = SDL_GetDisplayBounds(0, &rect);
|
||||||
if (result != 0)
|
if (result != 0)
|
||||||
|
@ -253,11 +303,18 @@ Size SDL2DisplayWindow::GetScreenSize()
|
||||||
|
|
||||||
void* SDL2DisplayWindow::StartTimer(int timeoutMilliseconds, std::function<void()> onTimer)
|
void* SDL2DisplayWindow::StartTimer(int timeoutMilliseconds, std::function<void()> onTimer)
|
||||||
{
|
{
|
||||||
|
CheckInitSDL();
|
||||||
|
|
||||||
|
// To do: implement timers
|
||||||
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SDL2DisplayWindow::StopTimer(void* timerID)
|
void SDL2DisplayWindow::StopTimer(void* timerID)
|
||||||
{
|
{
|
||||||
|
CheckInitSDL();
|
||||||
|
|
||||||
|
// To do: implement timers
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL2DisplayWindow* SDL2DisplayWindow::FindEventWindow(const SDL_Event& event)
|
SDL2DisplayWindow* SDL2DisplayWindow::FindEventWindow(const SDL_Event& event)
|
||||||
|
|
|
@ -78,6 +78,9 @@ public:
|
||||||
DisplayWindowHost* WindowHost = nullptr;
|
DisplayWindowHost* WindowHost = nullptr;
|
||||||
SDL_Window* WindowHandle = nullptr;
|
SDL_Window* WindowHandle = nullptr;
|
||||||
SDL_Renderer* RendererHandle = nullptr;
|
SDL_Renderer* RendererHandle = nullptr;
|
||||||
|
SDL_Texture* BackBufferTexture = nullptr;
|
||||||
|
int BackBufferWidth = 0;
|
||||||
|
int BackBufferHeight = 0;
|
||||||
|
|
||||||
static bool ExitRunLoop;
|
static bool ExitRunLoop;
|
||||||
static Uint32 PaintEventNumber;
|
static Uint32 PaintEventNumber;
|
||||||
|
|
|
@ -65,7 +65,7 @@
|
||||||
#include "palutil.h"
|
#include "palutil.h"
|
||||||
#include "st_start.h"
|
#include "st_start.h"
|
||||||
#include "printf.h"
|
#include "printf.h"
|
||||||
|
#include "common/widgets/launcherwindow.h"
|
||||||
|
|
||||||
#ifndef NO_GTK
|
#ifndef NO_GTK
|
||||||
bool I_GtkAvailable ();
|
bool I_GtkAvailable ();
|
||||||
|
@ -300,95 +300,16 @@ void I_PrintStr(const char *cp)
|
||||||
|
|
||||||
int I_PickIWad (WadStuff *wads, int numwads, bool showwin, int defaultiwad, int& autoloadflags)
|
int I_PickIWad (WadStuff *wads, int numwads, bool showwin, int defaultiwad, int& autoloadflags)
|
||||||
{
|
{
|
||||||
int i;
|
|
||||||
|
|
||||||
if (!showwin)
|
if (!showwin)
|
||||||
{
|
{
|
||||||
return defaultiwad;
|
return defaultiwad;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef __APPLE__
|
|
||||||
if(I_FileAvailable("kdialog"))
|
|
||||||
{
|
|
||||||
FString cmd("kdialog --title \"" GAMENAME " ");
|
|
||||||
cmd << GetVersionString() << ": Select an IWAD to use\""
|
|
||||||
" --menu \"" GAMENAME " found more than one IWAD\n"
|
|
||||||
"Select from the list below to determine which one to use:\"";
|
|
||||||
|
|
||||||
for(i = 0; i < numwads; ++i)
|
|
||||||
{
|
|
||||||
const char *filepart = strrchr(wads[i].Path.GetChars(), '/');
|
|
||||||
if(filepart == NULL)
|
|
||||||
filepart = wads[i].Path.GetChars();
|
|
||||||
else
|
|
||||||
filepart++;
|
|
||||||
// Menu entries are specified in "tag" "item" pairs, where when a
|
|
||||||
// particular item is selected (and the Okay button clicked), its
|
|
||||||
// corresponding tag is printed to stdout for identification.
|
|
||||||
cmd.AppendFormat(" \"%d\" \"%s (%s)\"", i, wads[i].Name.GetChars(), filepart);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(defaultiwad >= 0 && defaultiwad < numwads)
|
|
||||||
{
|
|
||||||
const char *filepart = strrchr(wads[defaultiwad].Path.GetChars(), '/');
|
|
||||||
if(filepart == NULL)
|
|
||||||
filepart = wads[defaultiwad].Path.GetChars();
|
|
||||||
else
|
|
||||||
filepart++;
|
|
||||||
cmd.AppendFormat(" --default \"%s (%s)\"", wads[defaultiwad].Name.GetChars(), filepart);
|
|
||||||
}
|
|
||||||
|
|
||||||
FILE *f = popen(cmd.GetChars(), "r");
|
|
||||||
if(f != NULL)
|
|
||||||
{
|
|
||||||
char gotstr[16];
|
|
||||||
|
|
||||||
if(fgets(gotstr, sizeof(gotstr), f) == NULL ||
|
|
||||||
sscanf(gotstr, "%d", &i) != 1)
|
|
||||||
i = -1;
|
|
||||||
|
|
||||||
// Exit status = 1 means the selection was canceled (either by
|
|
||||||
// Cancel/Esc or the X button), not that there was an error running
|
|
||||||
// the program. In that case, nothing was printed so fgets will
|
|
||||||
// have failed. Other values can indicate an error running the app,
|
|
||||||
// so fall back to whatever else can be used.
|
|
||||||
int status = pclose(f);
|
|
||||||
if(WIFEXITED(status) && (WEXITSTATUS(status) == 0 || WEXITSTATUS(status) == 1))
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef NO_GTK
|
|
||||||
if (I_GtkAvailable())
|
|
||||||
{
|
|
||||||
return I_PickIWad_Gtk (wads, numwads, showwin, defaultiwad, autoloadflags);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
return I_PickIWad_Cocoa (wads, numwads, showwin, defaultiwad);
|
return I_PickIWad_Cocoa (wads, numwads, showwin, defaultiwad);
|
||||||
|
#else
|
||||||
|
return LauncherWindow::ExecModal(wads, numwads, defaultiwad, &autoloadflags);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!isatty(fileno(stdin)))
|
|
||||||
{
|
|
||||||
return defaultiwad;
|
|
||||||
}
|
|
||||||
|
|
||||||
printf ("Please select a game wad (or 0 to exit):\n");
|
|
||||||
for (i = 0; i < numwads; ++i)
|
|
||||||
{
|
|
||||||
const char *filepart = strrchr (wads[i].Path.GetChars(), '/');
|
|
||||||
if (filepart == NULL)
|
|
||||||
filepart = wads[i].Path.GetChars();
|
|
||||||
else
|
|
||||||
filepart++;
|
|
||||||
printf ("%d. %s (%s)\n", i+1, wads[i].Name.GetChars(), filepart);
|
|
||||||
}
|
|
||||||
printf ("Which one? ");
|
|
||||||
if (scanf ("%d", &i) != 1 || i > numwads)
|
|
||||||
return -1;
|
|
||||||
return i-1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void I_PutInClipboard (const char *str)
|
void I_PutInClipboard (const char *str)
|
||||||
|
|
Loading…
Reference in a new issue