mirror of
https://gitea.nishi.boats/pyrite-dev/milsko
synced 2026-01-15 22:03:29 +00:00
appkit
This commit is contained in:
@@ -12,7 +12,7 @@ void* MwDynamicSymbol(void* handle, const char* symbol) {
|
||||
void MwDynamicClose(void* handle) {
|
||||
FreeLibrary(handle);
|
||||
}
|
||||
#elif defined(__unix__)
|
||||
#elif defined(__unix__) || defined(__APPLE__)
|
||||
void* MwDynamicOpen(const char* path) {
|
||||
return dlopen(path, RTLD_LOCAL | RTLD_LAZY);
|
||||
}
|
||||
|
||||
@@ -1,23 +1,47 @@
|
||||
#include <Mw/Milsko.h>
|
||||
#include <Mw/Milsko.h>
|
||||
|
||||
#if defined(_WIN32)
|
||||
long MwTimeGetTick(void) {
|
||||
return GetTickCount();
|
||||
return GetTickCount();
|
||||
}
|
||||
|
||||
void MwTimeSleep(int ms) {
|
||||
Sleep(ms);
|
||||
}
|
||||
#elif defined(__APPLE__)
|
||||
long MwTimeGetTick(void) {
|
||||
struct timespec ts;
|
||||
long n = 0;
|
||||
clock_serv_t cclock;
|
||||
mach_timespec_t mts;
|
||||
|
||||
host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock);
|
||||
clock_get_time(cclock, &mts);
|
||||
mach_port_deallocate(mach_task_self(), cclock);
|
||||
|
||||
n += ts.tv_nsec / 1000 / 1000;
|
||||
n += ts.tv_sec * 1000;
|
||||
|
||||
return n;
|
||||
}
|
||||
void MwTimeSleep(int ms) {
|
||||
struct timespec ts;
|
||||
|
||||
ts.tv_sec = ms / 1000;
|
||||
ts.tv_nsec = (ms % 1000) * 1000 * 1000;
|
||||
|
||||
nanosleep(&ts, NULL);
|
||||
}
|
||||
#elif defined(__unix__)
|
||||
long MwTimeGetTick(void) {
|
||||
struct timespec ts;
|
||||
long n = 0;
|
||||
|
||||
|
||||
clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||
|
||||
n += ts.tv_nsec / 1000 / 1000;
|
||||
n += ts.tv_sec * 1000;
|
||||
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
|
||||
214
src/backend/appkit.m
Normal file
214
src/backend/appkit.m
Normal file
@@ -0,0 +1,214 @@
|
||||
#include <Mw/Milsko.h>
|
||||
|
||||
#include "../../external/stb_ds.h"
|
||||
|
||||
static MwLL MwLLCreateImpl(MwLL parent, int x, int y, int width, int height) {
|
||||
MwLL r;
|
||||
(void)x;
|
||||
(void)y;
|
||||
(void)width;
|
||||
(void)height;
|
||||
|
||||
r = malloc(sizeof(*r));
|
||||
|
||||
|
||||
MwLLCreateCommon(r);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
static void MwLLDestroyImpl(MwLL handle) {
|
||||
MwLLDestroyCommon(handle);
|
||||
|
||||
free(handle);
|
||||
}
|
||||
|
||||
static void MwLLBeginDrawImpl(MwLL handle) {
|
||||
(void)handle;
|
||||
}
|
||||
|
||||
static void MwLLEndDrawImpl(MwLL handle) {
|
||||
(void)handle;
|
||||
}
|
||||
|
||||
static void MwLLPolygonImpl(MwLL handle, MwPoint* points, int points_count, MwLLColor color) {
|
||||
(void)points;
|
||||
(void)points_count;
|
||||
(void)color;
|
||||
}
|
||||
|
||||
static void MwLLLineImpl(MwLL handle, MwPoint* points, MwLLColor color) {
|
||||
(void)handle;
|
||||
(void)points;
|
||||
(void)color;
|
||||
}
|
||||
|
||||
static MwLLColor MwLLAllocColorImpl(MwLL handle, int r, int g, int b) {
|
||||
MwLLColor c = malloc(sizeof(*c));
|
||||
MwLLColorUpdate(handle, c, r, g, b);
|
||||
return c;
|
||||
}
|
||||
|
||||
static void MwLLColorUpdateImpl(MwLL handle, MwLLColor c, int r, int g, int b) {
|
||||
(void)handle;
|
||||
|
||||
c->common.red = r;
|
||||
c->common.green = g;
|
||||
c->common.blue = b;
|
||||
}
|
||||
|
||||
static void MwLLGetXYWHImpl(MwLL handle, int* x, int* y, unsigned int* w, unsigned int* h) {
|
||||
*x = 0;
|
||||
*y = 0;
|
||||
*w = 0;
|
||||
*h = 0;
|
||||
}
|
||||
|
||||
static void MwLLSetXYImpl(MwLL handle, int x, int y) {
|
||||
(void)handle;
|
||||
(void)x;
|
||||
(void)y;
|
||||
}
|
||||
|
||||
static void MwLLSetWHImpl(MwLL handle, int w, int h) {
|
||||
(void)handle;
|
||||
(void)w;
|
||||
(void)h;
|
||||
}
|
||||
|
||||
static void MwLLFreeColorImpl(MwLLColor color) {
|
||||
free(color);
|
||||
}
|
||||
|
||||
static int MwLLPendingImpl(MwLL handle) {
|
||||
(void)handle;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void MwLLNextEventImpl(MwLL handle) {
|
||||
(void)handle;
|
||||
}
|
||||
|
||||
static void MwLLSetTitleImpl(MwLL handle, const char* title) {
|
||||
(void)title;
|
||||
(void)handle;
|
||||
}
|
||||
|
||||
static MwLLPixmap MwLLCreatePixmapImpl(MwLL handle, unsigned char* data, int width, int height) {
|
||||
(void)handle;
|
||||
|
||||
MwLLPixmap r = malloc(sizeof(*r));
|
||||
|
||||
r->common.raw = malloc(4 * width * height);
|
||||
memcpy(r->common.raw, data, 4 * width * height);
|
||||
|
||||
r->common.width = width;
|
||||
r->common.height = height;
|
||||
|
||||
MwLLPixmapUpdate(r);
|
||||
return r;
|
||||
}
|
||||
|
||||
static void MwLLPixmapUpdateImpl(MwLLPixmap r) {
|
||||
(void)r;
|
||||
}
|
||||
|
||||
static void MwLLDestroyPixmapImpl(MwLLPixmap pixmap) {
|
||||
free(pixmap);
|
||||
}
|
||||
|
||||
static void MwLLDrawPixmapImpl(MwLL handle, MwRect* rect, MwLLPixmap pixmap) {
|
||||
(void)handle;
|
||||
(void)rect;
|
||||
(void)pixmap;
|
||||
}
|
||||
|
||||
static void MwLLSetIconImpl(MwLL handle, MwLLPixmap pixmap) {
|
||||
(void)handle;
|
||||
(void)pixmap;
|
||||
}
|
||||
|
||||
static void MwLLForceRenderImpl(MwLL handle) {
|
||||
(void)handle;
|
||||
}
|
||||
|
||||
static void MwLLSetCursorImpl(MwLL handle, MwCursor* image, MwCursor* mask) {
|
||||
(void)handle;
|
||||
(void)image;
|
||||
(void)mask;
|
||||
}
|
||||
|
||||
static void MwLLDetachImpl(MwLL handle, MwPoint* point) {
|
||||
(void)handle;
|
||||
(void)point;
|
||||
}
|
||||
|
||||
static void MwLLShowImpl(MwLL handle, int show) {
|
||||
(void)handle;
|
||||
(void)show;
|
||||
}
|
||||
|
||||
static void MwLLMakePopupImpl(MwLL handle, MwLL parent) {
|
||||
(void)handle;
|
||||
(void)parent;
|
||||
}
|
||||
|
||||
static void MwLLSetSizeHintsImpl(MwLL handle, int minx, int miny, int maxx, int maxy) {
|
||||
(void)handle;
|
||||
(void)minx;
|
||||
(void)miny;
|
||||
(void)maxx;
|
||||
(void)maxy;
|
||||
}
|
||||
|
||||
static void MwLLMakeBorderlessImpl(MwLL handle, int toggle) {
|
||||
(void)handle;
|
||||
(void)toggle;
|
||||
}
|
||||
|
||||
static void MwLLFocusImpl(MwLL handle) {
|
||||
(void)handle;
|
||||
}
|
||||
|
||||
static void MwLLGrabPointerImpl(MwLL handle, int toggle) {
|
||||
(void)handle;
|
||||
(void)toggle;
|
||||
}
|
||||
|
||||
static void MwLLSetClipboardImpl(MwLL handle, const char* text) {
|
||||
(void)handle;
|
||||
(void)text;
|
||||
}
|
||||
|
||||
static void MwLLGetClipboardImpl(MwLL handle) {
|
||||
(void)handle;
|
||||
}
|
||||
|
||||
static void MwLLMakeToolWindowImpl(MwLL handle) {
|
||||
(void)handle;
|
||||
}
|
||||
|
||||
static void MwLLGetCursorCoordImpl(MwLL handle, MwPoint* point) {
|
||||
(void)handle;
|
||||
(void)point;
|
||||
}
|
||||
|
||||
static void MwLLGetScreenSizeImpl(MwLL handle, MwRect* rect) {
|
||||
(void)handle;
|
||||
(void)rect;
|
||||
}
|
||||
|
||||
static void MwLLBeginStateChangeImpl(MwLL handle) {
|
||||
MwLLShow(handle, 0);
|
||||
}
|
||||
|
||||
static void MwLLEndStateChangeImpl(MwLL handle) {
|
||||
MwLLShow(handle, 1);
|
||||
}
|
||||
|
||||
static int AppKit(void) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
#include "call.c"
|
||||
CALL(AppKit);
|
||||
@@ -1,55 +1,70 @@
|
||||
#include <Mw/Milsko.h>
|
||||
|
||||
MwLL (*MwLLCreate)(MwLL parent, int x, int y, int width, int height);
|
||||
void (*MwLLDestroy)(MwLL handle);
|
||||
/* Older GCC doesn't like this part of the code because of common sections.
|
||||
What are common sections? This question is so obscure and unknown
|
||||
that newer GCC actually compiles with -fno-common by default because
|
||||
not enough people ever figured this out. But when compiling under
|
||||
older Mac OS X. specifically the gcc that comes with tigerbrew (this
|
||||
has not yet been tried under XCode 10.5), this comes up. Furthermore,
|
||||
adding -fno-common to either the cflags or ldflags doesn't seem to fix this.
|
||||
But what does fix it is using GNU attributes. So...yeah, sure, we'll just do
|
||||
this.*/
|
||||
#ifdef __APPLE__
|
||||
#define NOCOMMON __attribute__((nocommon))
|
||||
#else
|
||||
#define NOCOMMON
|
||||
#endif
|
||||
|
||||
void (*MwLLPolygon)(MwLL handle, MwPoint* points, int points_count, MwLLColor color);
|
||||
void (*MwLLLine)(MwLL handle, MwPoint* points, MwLLColor color);
|
||||
NOCOMMON MwLL (*MwLLCreate)(MwLL parent, int x, int y, int width, int height);
|
||||
NOCOMMON void (*MwLLDestroy)(MwLL handle);
|
||||
|
||||
void (*MwLLBeginDraw)(MwLL handle);
|
||||
void (*MwLLEndDraw)(MwLL handle);
|
||||
NOCOMMON void (*MwLLPolygon)(MwLL handle, MwPoint* points, int points_count, MwLLColor color);
|
||||
NOCOMMON void (*MwLLLine)(MwLL handle, MwPoint* points, MwLLColor color);
|
||||
|
||||
MwLLColor (*MwLLAllocColor)(MwLL handle, int r, int g, int b);
|
||||
void (*MwLLColorUpdate)(MwLL handle, MwLLColor c, int r, int g, int b);
|
||||
void (*MwLLFreeColor)(MwLLColor color);
|
||||
NOCOMMON void (*MwLLBeginDraw)(MwLL handle);
|
||||
NOCOMMON void (*MwLLEndDraw)(MwLL handle);
|
||||
|
||||
void (*MwLLGetXYWH)(MwLL handle, int* x, int* y, unsigned int* w, unsigned int* h);
|
||||
void (*MwLLSetXY)(MwLL handle, int x, int y);
|
||||
void (*MwLLSetWH)(MwLL handle, int w, int h);
|
||||
NOCOMMON MwLLColor (*MwLLAllocColor)(MwLL handle, int r, int g, int b);
|
||||
NOCOMMON void (*MwLLColorUpdate)(MwLL handle, MwLLColor c, int r, int g, int b);
|
||||
NOCOMMON void (*MwLLFreeColor)(MwLLColor color);
|
||||
|
||||
void (*MwLLSetTitle)(MwLL handle, const char* title);
|
||||
NOCOMMON void (*MwLLGetXYWH)(MwLL handle, int* x, int* y, unsigned int* w, unsigned int* h);
|
||||
NOCOMMON void (*MwLLSetXY)(MwLL handle, int x, int y);
|
||||
NOCOMMON void (*MwLLSetWH)(MwLL handle, int w, int h);
|
||||
|
||||
int (*MwLLPending)(MwLL handle);
|
||||
void (*MwLLNextEvent)(MwLL handle);
|
||||
NOCOMMON void (*MwLLSetTitle)(MwLL handle, const char* title);
|
||||
|
||||
MwLLPixmap (*MwLLCreatePixmap)(MwLL handle, unsigned char* data, int width, int height);
|
||||
void (*MwLLPixmapUpdate)(MwLLPixmap pixmap);
|
||||
void (*MwLLDestroyPixmap)(MwLLPixmap pixmap);
|
||||
void (*MwLLDrawPixmap)(MwLL handle, MwRect* rect, MwLLPixmap pixmap);
|
||||
void (*MwLLSetIcon)(MwLL handle, MwLLPixmap pixmap);
|
||||
NOCOMMON int (*MwLLPending)(MwLL handle);
|
||||
NOCOMMON void (*MwLLNextEvent)(MwLL handle);
|
||||
|
||||
void (*MwLLForceRender)(MwLL handle);
|
||||
NOCOMMON MwLLPixmap (*MwLLCreatePixmap)(MwLL handle, unsigned char* data, int width, int height);
|
||||
NOCOMMON void (*MwLLPixmapUpdate)(MwLLPixmap pixmap);
|
||||
NOCOMMON void (*MwLLDestroyPixmap)(MwLLPixmap pixmap);
|
||||
NOCOMMON void (*MwLLDrawPixmap)(MwLL handle, MwRect* rect, MwLLPixmap pixmap);
|
||||
NOCOMMON void (*MwLLSetIcon)(MwLL handle, MwLLPixmap pixmap);
|
||||
|
||||
void (*MwLLSetCursor)(MwLL handle, MwCursor* image, MwCursor* mask);
|
||||
void (*MwLLDetach)(MwLL handle, MwPoint* point);
|
||||
void (*MwLLShow)(MwLL handle, int show);
|
||||
NOCOMMON void (*MwLLForceRender)(MwLL handle);
|
||||
|
||||
void (*MwLLSetSizeHints)(MwLL handle, int minx, int miny, int maxx, int maxy);
|
||||
void (*MwLLMakeBorderless)(MwLL handle, int toggle);
|
||||
void (*MwLLMakeToolWindow)(MwLL handle);
|
||||
void (*MwLLMakePopup)(MwLL handle, MwLL parent);
|
||||
NOCOMMON void (*MwLLSetCursor)(MwLL handle, MwCursor* image, MwCursor* mask);
|
||||
NOCOMMON void (*MwLLDetach)(MwLL handle, MwPoint* point);
|
||||
NOCOMMON void (*MwLLShow)(MwLL handle, int show);
|
||||
|
||||
void (*MwLLBeginStateChange)(MwLL handle);
|
||||
void (*MwLLEndStateChange)(MwLL handle);
|
||||
NOCOMMON void (*MwLLSetSizeHints)(MwLL handle, int minx, int miny, int maxx, int maxy);
|
||||
NOCOMMON void (*MwLLMakeBorderless)(MwLL handle, int toggle);
|
||||
NOCOMMON void (*MwLLMakeToolWindow)(MwLL handle);
|
||||
NOCOMMON void (*MwLLMakePopup)(MwLL handle, MwLL parent);
|
||||
|
||||
void (*MwLLFocus)(MwLL handle);
|
||||
void (*MwLLGrabPointer)(MwLL handle, int toggle);
|
||||
NOCOMMON void (*MwLLBeginStateChange)(MwLL handle);
|
||||
NOCOMMON void (*MwLLEndStateChange)(MwLL handle);
|
||||
|
||||
void (*MwLLSetClipboard)(MwLL handle, const char* text);
|
||||
void (*MwLLGetClipboard)(MwLL handle);
|
||||
NOCOMMON void (*MwLLFocus)(MwLL handle);
|
||||
NOCOMMON void (*MwLLGrabPointer)(MwLL handle, int toggle);
|
||||
|
||||
void (*MwLLGetCursorCoord)(MwLL handle, MwPoint* point);
|
||||
void (*MwLLGetScreenSize)(MwLL handle, MwRect* rect);
|
||||
NOCOMMON void (*MwLLSetClipboard)(MwLL handle, const char* text);
|
||||
NOCOMMON void (*MwLLGetClipboard)(MwLL handle);
|
||||
|
||||
NOCOMMON void (*MwLLGetCursorCoord)(MwLL handle, MwPoint* point);
|
||||
NOCOMMON void (*MwLLGetScreenSize)(MwLL handle, MwRect* rect);
|
||||
|
||||
void MwLLCreateCommon(MwLL handle) {
|
||||
handle->common.handler = malloc(sizeof(*handle->common.handler));
|
||||
|
||||
Reference in New Issue
Block a user