From f4763b58de89df5a112153ce774a430ce52d4954 Mon Sep 17 00:00:00 2001 From: NishiOwO Date: Sun, 28 Sep 2025 02:51:15 +0000 Subject: [PATCH] stuff git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@3 b9cfdab3-6d41-4d17-bbe4-086880011989 --- GNUmakefile | 1 + include/Milsko/LowLevel.h | 27 +++++++++++++++++++++++++++ include/Milsko/Milsko.h | 1 + include/Milsko/TypeDef.h | 10 ++++++++++ include/Milsko/X11.h | 19 +++++++++++++++++++ src/x11.c | 39 +++++++++++++++++++++++++++++++++++++++ 6 files changed, 97 insertions(+) create mode 100644 include/Milsko/LowLevel.h create mode 100644 include/Milsko/TypeDef.h create mode 100644 include/Milsko/X11.h diff --git a/GNUmakefile b/GNUmakefile index 13d4f981a..d9cd31995 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -20,6 +20,7 @@ $(error Add your platform definition) endif ifeq ($(UNIX),1) +CFLAGS += -DUSE_X11 LIB = lib SO = .so L_OBJS += src/x11.o diff --git a/include/Milsko/LowLevel.h b/include/Milsko/LowLevel.h new file mode 100644 index 000000000..26a2bad84 --- /dev/null +++ b/include/Milsko/LowLevel.h @@ -0,0 +1,27 @@ +/* $Id$ */ +#ifndef __MILSKO_PLATFORM_H__ +#define __MILSKO_PLATFORM_H__ + +#include +#include +#include + +#include + +#ifdef _MILSKO +#ifdef USE_X11 +#include +#endif +#ifdef USE_GDI +#include +#endif +#else +typedef void* HMILSKO; +typedef void* HMILSKOCOLOR; +#endif + +HMILSKO MilskoLLCreate(HMILSKO parent, int x, int y, int width, int height); +void MilskoLLPolygon(HMILSKO handle, MilskoPoint* points, int points_count, HMILSKOCOLOR color); +HMILSKOCOLOR MilskoLLAllocColor(HMILSKO handle, int r, int g, int b); + +#endif diff --git a/include/Milsko/Milsko.h b/include/Milsko/Milsko.h index 46760c097..4d9a1f2b6 100644 --- a/include/Milsko/Milsko.h +++ b/include/Milsko/Milsko.h @@ -2,5 +2,6 @@ #ifndef __MILSKO_MILSKO_H__ #define __MILSKO_MILSKO_H__ +#include #endif diff --git a/include/Milsko/TypeDef.h b/include/Milsko/TypeDef.h new file mode 100644 index 000000000..1f98f6f69 --- /dev/null +++ b/include/Milsko/TypeDef.h @@ -0,0 +1,10 @@ +/* $Id$ */ +#ifndef __MILSKO_TYPEDEF_H__ +#define __MILSKO_TYPEDEF_H__ + +typedef struct _MilskoPoint { + int x; + int y; +} MilskoPoint; + +#endif diff --git a/include/Milsko/X11.h b/include/Milsko/X11.h new file mode 100644 index 000000000..090b519f7 --- /dev/null +++ b/include/Milsko/X11.h @@ -0,0 +1,19 @@ +/* $Id$ */ +#ifndef __MILSKO_X11_H__ +#define __MILSKO_X11_H__ + +#include +#include + +typedef struct __Milsko { + Display* display; + Window window; + GC gc; + Colormap colormap; +}* HMILSKO; + +typedef struct __MilskoColor { + unsigned long pixel; +}* HMILSKOCOLOR; + +#endif diff --git a/src/x11.c b/src/x11.c index 102ce9f77..db72522c3 100644 --- a/src/x11.c +++ b/src/x11.c @@ -1,3 +1,42 @@ /* $Id$ */ #include +HMILSKO MilskoLLCreate(HMILSKO parent, int x, int y, int width, int height){ + HMILSKO r; + Window p; + + r = malloc(sizeof(*r)); + if(parent == NULL){ + r->display = XOpenDisplay(NULL); + p = XRootWindow(r->display, XDefaultScreen(r->display)); + }else{ + r->display = parent->display; + p = parent->window; + } + r->window = XCreateSimpleWindow(r->display, p, x, y, width, height, 0, 0, WhitePixel(r->display, XDefaultScreen(r->display))); + r->colormap = DefaultColormap(r->display, XDefaultScreen(r->display)); + r->gc = XCreateGC(r->display, r->window, 0, 0); + + XMapWindow(r->display, r->window); + + return r; +} + +void MilskoLLPolygon(HMILSKO handle, MilskoPoint* points, int points_count, HMILSKOCOLOR color){ +} + +HMILSKOCOLOR MilskoLLAllocColor(HMILSKO handle, int r, int g, int b){ + HMILSKOCOLOR c = malloc(sizeof(*c)); + XColor xc; + xc.red = 256 * r; + xc.green = 256 * g; + xc.blue = 256 * b; + XAllocColor(handle->display, handle->colormap, &xc); + + c->pixel = xc.pixel; + return c; +} + +void MilskoLLFreeColor(HMILSKOCOLOR color){ + free(color); +}