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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user