Port 2V0-f window input and UI render command bridge
This commit is contained in:
@@ -2,10 +2,12 @@
|
||||
// split so the launcher can outlive the call that creates it.
|
||||
#include "ScriptLib/StdAfx.h"
|
||||
#include "ScriptLib/PythonLauncher.h"
|
||||
#include "ScriptLib/Resource.h"
|
||||
#include "UserInterface/StdAfx.h" // initpack and the rest of the module initializer list
|
||||
#include "EterPythonLib/StdAfx.h"
|
||||
#include "PythonBoot.h"
|
||||
#include "PythonHost.h"
|
||||
#include "../EterLib/UIRenderCommands.h"
|
||||
#include "../EterBase/LogBox.h"
|
||||
|
||||
#include <memory>
|
||||
@@ -15,6 +17,7 @@ namespace
|
||||
// 40250 has this on Main()'s stack. CPythonLauncher is a CSingleton, so there is still only ever one.
|
||||
std::unique_ptr<CPythonLauncher> g_launcher;
|
||||
std::unique_ptr<UI::CWindowManager> g_window_manager;
|
||||
std::unique_ptr<CPythonResource> g_resource;
|
||||
|
||||
bool fail(std::string* error, const std::string& text)
|
||||
{
|
||||
@@ -34,6 +37,50 @@ bool IsRunning()
|
||||
return g_launcher != nullptr;
|
||||
}
|
||||
|
||||
void SetUISize(int width, int height)
|
||||
{
|
||||
if (!g_window_manager || width <= 0 || height <= 0) return;
|
||||
g_window_manager->SetScreenSize(width, height);
|
||||
g_window_manager->SetResolution(width, height);
|
||||
UIRenderSetSize(width, height);
|
||||
}
|
||||
|
||||
void UIMouseMove(int x, int y)
|
||||
{
|
||||
if (g_window_manager) g_window_manager->RunMouseMove(x, y);
|
||||
}
|
||||
|
||||
void UIMouseButton(int button, bool pressed, int x, int y)
|
||||
{
|
||||
if (!g_window_manager) return;
|
||||
g_window_manager->RunMouseMove(x, y);
|
||||
switch (button)
|
||||
{
|
||||
case 1: if (pressed) g_window_manager->RunMouseLeftButtonDown(x, y); else g_window_manager->RunMouseLeftButtonUp(x, y); break;
|
||||
case 2: if (pressed) g_window_manager->RunMouseRightButtonDown(x, y); else g_window_manager->RunMouseRightButtonUp(x, y); break;
|
||||
case 3: if (pressed) g_window_manager->RunMouseMiddleButtonDown(x, y); else g_window_manager->RunMouseMiddleButtonUp(x, y); break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
void UIKey(int key, bool pressed)
|
||||
{
|
||||
if (!g_window_manager) return;
|
||||
if (pressed) g_window_manager->RunKeyDown(key);
|
||||
else g_window_manager->RunKeyUp(key);
|
||||
}
|
||||
|
||||
void UIUpdate()
|
||||
{
|
||||
if (g_window_manager) g_window_manager->Update();
|
||||
}
|
||||
|
||||
void UIRender()
|
||||
{
|
||||
UIRenderBeginFrame();
|
||||
if (g_window_manager) g_window_manager->Render();
|
||||
}
|
||||
|
||||
bool Start(const char* stdlib_path, std::string* error)
|
||||
{
|
||||
if (g_launcher)
|
||||
@@ -59,6 +106,7 @@ bool Start(const char* stdlib_path, std::string* error)
|
||||
Stop();
|
||||
return fail(error, "InstallStdLib(" + stdlib + "): " + stdlib_error);
|
||||
}
|
||||
g_resource = std::make_unique<CPythonResource>();
|
||||
g_window_manager = std::make_unique<UI::CWindowManager>();
|
||||
return true;
|
||||
}
|
||||
@@ -158,6 +206,7 @@ void Stop()
|
||||
if (!g_launcher)
|
||||
return;
|
||||
g_window_manager.reset();
|
||||
g_resource.reset();
|
||||
g_launcher->Clear(); // Main() calls Clear() explicitly before the launcher leaves scope
|
||||
g_launcher.reset();
|
||||
}
|
||||
|
||||
@@ -36,6 +36,15 @@ bool RunMainScript(const char* lpCmdLine, std::string* error);
|
||||
// no 40250 packs, which is where RunMainScript cannot run at all.
|
||||
bool RunLine(const char* source, std::string* error);
|
||||
|
||||
// Forward physical Godot input to the original 40250 window manager. Coordinates
|
||||
// are viewport pixels; SetUISize also establishes its logical resolution.
|
||||
void SetUISize(int width, int height);
|
||||
void UIMouseMove(int x, int y);
|
||||
void UIMouseButton(int button, bool pressed, int x, int y);
|
||||
void UIKey(int key, bool pressed);
|
||||
void UIUpdate();
|
||||
void UIRender();
|
||||
|
||||
// 40250 Main() calls Clear() and lets the launcher leave scope.
|
||||
void Stop();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
#include "ScriptLib/StdAfx.h"
|
||||
#include "ScriptLib/Resource.h"
|
||||
#include "EterLib/GrpImage.h"
|
||||
#include "EterLib/GrpSubImage.h"
|
||||
|
||||
namespace {
|
||||
CResource* NewUIImage(const char* name) { return new CGraphicImage(name); }
|
||||
CResource* NewUISubImage(const char* name) { return new CGraphicSubImage(name); }
|
||||
}
|
||||
|
||||
CPythonResource::CPythonResource() {
|
||||
for (const char* ext : {"tga", "dds", "png", "jpg", "bmp"})
|
||||
m_resManager.RegisterResourceNewFunctionPointer(ext, NewUIImage);
|
||||
m_resManager.RegisterResourceNewFunctionPointer("sub", NewUISubImage);
|
||||
}
|
||||
CPythonResource::~CPythonResource() { m_resManager.DestroyDeletingList(); }
|
||||
void CPythonResource::Destroy() { m_resManager.DestroyDeletingList(); m_resManager.Destroy(); }
|
||||
void CPythonResource::DumpFileList(const char* name) { m_resManager.DumpFileListToTextFile(name); }
|
||||
Reference in New Issue
Block a user