Port 2V0 UI Python bindings and app module link surface
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
#pragma once
|
||||
|
||||
#include <Python.h>
|
||||
|
||||
// The 40250 Python API represents native handles as integers. Keep that API while allowing a
|
||||
// 64-bit pointer to survive the round trip on macOS and mobile builds.
|
||||
template <typename T>
|
||||
PyObject* Py_BuildPointer(T* pointer)
|
||||
{
|
||||
return PyLong_FromVoidPtr(static_cast<void*>(pointer));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool PyTuple_GetPointer(PyObject* args, int position, T** out)
|
||||
{
|
||||
if (position < 0 || position >= PyTuple_Size(args))
|
||||
return false;
|
||||
PyObject* value = PyTuple_GetItem(args, position);
|
||||
if (!value)
|
||||
return false;
|
||||
void* pointer = PyLong_AsVoidPtr(value);
|
||||
if (PyErr_Occurred())
|
||||
return false;
|
||||
*out = static_cast<T*>(pointer);
|
||||
return true;
|
||||
}
|
||||
@@ -4,10 +4,14 @@
|
||||
#include <cctype>
|
||||
#include <chrono>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <mutex>
|
||||
#include <new>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
#include <glob.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
@@ -44,6 +48,69 @@ int _access(const char* path, int mode)
|
||||
return access(path, m);
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
struct FindState
|
||||
{
|
||||
std::vector<std::string> paths;
|
||||
size_t next = 0;
|
||||
};
|
||||
|
||||
void fill_find_data(const std::string& path, WIN32_FIND_DATA* data)
|
||||
{
|
||||
const size_t slash = path.find_last_of('/');
|
||||
const std::string name = path.substr(slash == std::string::npos ? 0 : slash + 1);
|
||||
std::snprintf(data->cFileName, sizeof(data->cFileName), "%s", name.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
HANDLE FindFirstFile(const char* pattern, WIN32_FIND_DATA* data)
|
||||
{
|
||||
if (!pattern || !data)
|
||||
return INVALID_HANDLE_VALUE;
|
||||
std::string normalized(pattern);
|
||||
for (char& ch : normalized)
|
||||
if (ch == '\\') ch = '/';
|
||||
glob_t matches{};
|
||||
const int result = glob(normalized.c_str(), 0, nullptr, &matches);
|
||||
if (result != 0 || matches.gl_pathc == 0)
|
||||
{
|
||||
globfree(&matches);
|
||||
return INVALID_HANDLE_VALUE;
|
||||
}
|
||||
auto* state = new FindState;
|
||||
for (size_t i = 0; i < matches.gl_pathc; ++i)
|
||||
state->paths.emplace_back(matches.gl_pathv[i]);
|
||||
globfree(&matches);
|
||||
fill_find_data(state->paths[0], data);
|
||||
state->next = 1;
|
||||
return state;
|
||||
}
|
||||
|
||||
BOOL FindNextFile(HANDLE handle, WIN32_FIND_DATA* data)
|
||||
{
|
||||
if (handle == INVALID_HANDLE_VALUE || !handle || !data)
|
||||
return FALSE;
|
||||
auto* state = static_cast<FindState*>(handle);
|
||||
if (state->next >= state->paths.size())
|
||||
return FALSE;
|
||||
fill_find_data(state->paths[state->next++], data);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL FindClose(HANDLE handle)
|
||||
{
|
||||
if (handle == INVALID_HANDLE_VALUE || !handle)
|
||||
return FALSE;
|
||||
delete static_cast<FindState*>(handle);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void Sleep(DWORD milliseconds)
|
||||
{
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(milliseconds));
|
||||
}
|
||||
|
||||
char* _strlwr(char* s)
|
||||
{
|
||||
for (char* p = s; *p; ++p)
|
||||
|
||||
@@ -10,8 +10,15 @@
|
||||
#include <cstring>
|
||||
|
||||
#if !defined(_WIN32)
|
||||
#include <alloca.h>
|
||||
#include <strings.h>
|
||||
|
||||
// The x87 precision-control call has no equivalent on ARM; the script never needs x87 state there.
|
||||
#define _PC_24 0
|
||||
#define _MCW_PC 0
|
||||
inline unsigned _controlfp(unsigned, unsigned) { return 0; }
|
||||
#define _alloca alloca
|
||||
|
||||
#include "Win32MinMax.h"
|
||||
|
||||
// mmsystem.h
|
||||
@@ -54,6 +61,12 @@ int _snprintf(char* buf, size_t count, const char* fmt, ...)
|
||||
BOOL CreateDirectory(LPCSTR path, void* security_attributes);
|
||||
BOOL DeleteFile(LPCSTR path);
|
||||
int _access(const char* path, int mode);
|
||||
struct WIN32_FIND_DATA { char cFileName[MAX_PATH]; };
|
||||
#define INVALID_HANDLE_VALUE (reinterpret_cast<HANDLE>(static_cast<intptr_t>(-1)))
|
||||
HANDLE FindFirstFile(const char* pattern, WIN32_FIND_DATA* data);
|
||||
BOOL FindNextFile(HANDLE handle, WIN32_FIND_DATA* data);
|
||||
BOOL FindClose(HANDLE handle);
|
||||
void Sleep(DWORD milliseconds);
|
||||
|
||||
// winmm `timeGetTime`: milliseconds since system start, wrapping at 2^32.
|
||||
DWORD timeGetTime();
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
// DevIL interface needed by 40250 app.GetImageInfo / MarkImage.
|
||||
typedef unsigned int ILuint;
|
||||
|
||||
#define IL_TYPE_UNKNOWN 0
|
||||
#define IL_IMAGE_WIDTH 0x0DE4
|
||||
#define IL_IMAGE_HEIGHT 0x0DE5
|
||||
|
||||
void ilGenImages(unsigned count, ILuint* images);
|
||||
void ilBindImage(ILuint image);
|
||||
bool ilLoad(unsigned type, const char* filename);
|
||||
int ilGetInteger(unsigned property);
|
||||
void ilDeleteImages(unsigned count, const ILuint* images);
|
||||
@@ -11,3 +11,118 @@ struct IDirectInput8;
|
||||
struct IDirectInputDevice8;
|
||||
typedef IDirectInput8* LPDIRECTINPUT8;
|
||||
typedef IDirectInputDevice8* LPDIRECTINPUTDEVICE8;
|
||||
|
||||
// DirectInput scan codes used by PythonApplicationModule.cpp, from mingw-w64 dinput.h.
|
||||
#define DIK_0 0x0B
|
||||
#define DIK_1 0x02
|
||||
#define DIK_2 0x03
|
||||
#define DIK_3 0x04
|
||||
#define DIK_4 0x05
|
||||
#define DIK_5 0x06
|
||||
#define DIK_6 0x07
|
||||
#define DIK_7 0x08
|
||||
#define DIK_8 0x09
|
||||
#define DIK_9 0x0A
|
||||
#define DIK_A 0x1E
|
||||
#define DIK_ADD 0x4E
|
||||
#define DIK_APOSTROPHE 0x28
|
||||
#define DIK_APPS 0xDD
|
||||
#define DIK_B 0x30
|
||||
#define DIK_BACK 0x0E
|
||||
#define DIK_BACKSLASH 0x2B
|
||||
#define DIK_C 0x2E
|
||||
#define DIK_CALCULATOR 0xA1
|
||||
#define DIK_CAPITAL 0x3A
|
||||
#define DIK_COMMA 0x33
|
||||
#define DIK_D 0x20
|
||||
#define DIK_DECIMAL 0x53
|
||||
#define DIK_DELETE 0xD3
|
||||
#define DIK_DIVIDE 0xB5
|
||||
#define DIK_DOWN 0xD0
|
||||
#define DIK_E 0x12
|
||||
#define DIK_END 0xCF
|
||||
#define DIK_EQUALS 0x0D
|
||||
#define DIK_ESCAPE 0x01
|
||||
#define DIK_F 0x21
|
||||
#define DIK_F1 0x3B
|
||||
#define DIK_F10 0x44
|
||||
#define DIK_F11 0x57
|
||||
#define DIK_F12 0x58
|
||||
#define DIK_F2 0x3C
|
||||
#define DIK_F3 0x3D
|
||||
#define DIK_F4 0x3E
|
||||
#define DIK_F5 0x3F
|
||||
#define DIK_F6 0x40
|
||||
#define DIK_F7 0x41
|
||||
#define DIK_F8 0x42
|
||||
#define DIK_F9 0x43
|
||||
#define DIK_G 0x22
|
||||
#define DIK_GRAVE 0x29
|
||||
#define DIK_H 0x23
|
||||
#define DIK_HOME 0xC7
|
||||
#define DIK_I 0x17
|
||||
#define DIK_INSERT 0xD2
|
||||
#define DIK_J 0x24
|
||||
#define DIK_K 0x25
|
||||
#define DIK_L 0x26
|
||||
#define DIK_LBRACKET 0x1A
|
||||
#define DIK_LCONTROL 0x1D
|
||||
#define DIK_LEFT 0xCB
|
||||
#define DIK_LMENU 0x38
|
||||
#define DIK_LSHIFT 0x2A
|
||||
#define DIK_LWIN 0xDB
|
||||
#define DIK_M 0x32
|
||||
#define DIK_MEDIASTOP 0xA4
|
||||
#define DIK_MINUS 0x0C
|
||||
#define DIK_MULTIPLY 0x37
|
||||
#define DIK_MUTE 0xA0
|
||||
#define DIK_N 0x31
|
||||
#define DIK_NEXT 0xD1
|
||||
#define DIK_NEXTTRACK 0x99
|
||||
#define DIK_NUMLOCK 0x45
|
||||
#define DIK_NUMPAD0 0x52
|
||||
#define DIK_NUMPAD1 0x4F
|
||||
#define DIK_NUMPAD2 0x50
|
||||
#define DIK_NUMPAD3 0x51
|
||||
#define DIK_NUMPAD4 0x4B
|
||||
#define DIK_NUMPAD5 0x4C
|
||||
#define DIK_NUMPAD6 0x4D
|
||||
#define DIK_NUMPAD7 0x47
|
||||
#define DIK_NUMPAD8 0x48
|
||||
#define DIK_NUMPAD9 0x49
|
||||
#define DIK_NUMPADCOMMA 0xB3
|
||||
#define DIK_NUMPADENTER 0x9C
|
||||
#define DIK_O 0x18
|
||||
#define DIK_P 0x19
|
||||
#define DIK_PAUSE 0xC5
|
||||
#define DIK_PERIOD 0x34
|
||||
#define DIK_PLAYPAUSE 0xA2
|
||||
#define DIK_PRIOR 0xC9
|
||||
#define DIK_Q 0x10
|
||||
#define DIK_R 0x13
|
||||
#define DIK_RBRACKET 0x1B
|
||||
#define DIK_RCONTROL 0x9D
|
||||
#define DIK_RETURN 0x1C
|
||||
#define DIK_RIGHT 0xCD
|
||||
#define DIK_RMENU 0xB8
|
||||
#define DIK_RSHIFT 0x36
|
||||
#define DIK_RWIN 0xDC
|
||||
#define DIK_S 0x1F
|
||||
#define DIK_SCROLL 0x46
|
||||
#define DIK_SEMICOLON 0x27
|
||||
#define DIK_SLASH 0x35
|
||||
#define DIK_SPACE 0x39
|
||||
#define DIK_SUBTRACT 0x4A
|
||||
#define DIK_SYSRQ 0xB7
|
||||
#define DIK_T 0x14
|
||||
#define DIK_TAB 0x0F
|
||||
#define DIK_U 0x16
|
||||
#define DIK_UP 0xC8
|
||||
#define DIK_V 0x2F
|
||||
#define DIK_VOLUMEDOWN 0xAE
|
||||
#define DIK_VOLUMEUP 0xB0
|
||||
#define DIK_W 0x11
|
||||
#define DIK_WEBHOME 0xB2
|
||||
#define DIK_X 0x2D
|
||||
#define DIK_Y 0x15
|
||||
#define DIK_Z 0x2C
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
// Win32 shell-folder API used only by the screenshot command in grp.
|
||||
#include <windows.h>
|
||||
|
||||
#define CSIDL_PERSONAL 0x0005
|
||||
|
||||
inline BOOL SHGetSpecialFolderPath(void*, char* path, int, BOOL)
|
||||
{
|
||||
if (path)
|
||||
path[0] = '\0';
|
||||
return FALSE;
|
||||
}
|
||||
@@ -17,3 +17,11 @@
|
||||
#define WHITE_BRUSH 0
|
||||
#define BLACK_BRUSH 4
|
||||
#define KL_NAMELENGTH 9
|
||||
#define FAR
|
||||
#define VK_LEFT 0x25
|
||||
#define VK_UP 0x26
|
||||
#define VK_RIGHT 0x27
|
||||
#define VK_DOWN 0x28
|
||||
#define VK_HOME 0x24
|
||||
#define VK_END 0x23
|
||||
#define VK_DELETE 0x2E
|
||||
|
||||
Reference in New Issue
Block a user