2025-09-27 14:29:44 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
#include <Milsko/Milsko.h>
|
|
|
|
|
|
2025-09-28 04:04:30 +00:00
|
|
|
static unsigned long mask = ExposureMask | StructureNotifyMask | ButtonPressMask | ButtonReleaseMask;
|
|
|
|
|
|
2025-09-28 06:52:49 +00:00
|
|
|
HMILSKOLL MilskoLLCreate(HMILSKOLL parent, int x, int y, int width, int height) {
|
2025-09-28 09:04:35 +00:00
|
|
|
HMILSKOLL r;
|
|
|
|
|
Window p;
|
|
|
|
|
Window root;
|
|
|
|
|
unsigned int border, depth;
|
2025-09-28 02:51:15 +00:00
|
|
|
|
2025-09-28 04:07:41 +00:00
|
|
|
r = malloc(sizeof(*r));
|
|
|
|
|
r->x = x;
|
|
|
|
|
r->y = y;
|
|
|
|
|
r->width = width;
|
2025-09-28 04:06:26 +00:00
|
|
|
r->height = height;
|
|
|
|
|
|
2025-09-28 04:07:41 +00:00
|
|
|
if(parent == NULL) {
|
2025-09-28 02:51:15 +00:00
|
|
|
r->display = XOpenDisplay(NULL);
|
2025-09-28 04:07:41 +00:00
|
|
|
p = XRootWindow(r->display, XDefaultScreen(r->display));
|
|
|
|
|
} else {
|
2025-09-28 02:51:15 +00:00
|
|
|
r->display = parent->display;
|
2025-09-28 04:07:41 +00:00
|
|
|
p = parent->window;
|
2025-09-28 02:51:15 +00:00
|
|
|
}
|
2025-09-28 04:07:41 +00:00
|
|
|
r->window = XCreateSimpleWindow(r->display, p, x, y, width, height, 0, 0, WhitePixel(r->display, XDefaultScreen(r->display)));
|
2025-09-28 02:51:15 +00:00
|
|
|
r->colormap = DefaultColormap(r->display, XDefaultScreen(r->display));
|
2025-09-28 09:04:35 +00:00
|
|
|
|
|
|
|
|
r->gc = XCreateGC(r->display, r->window, 0, 0);
|
2025-09-28 02:51:15 +00:00
|
|
|
|
2025-09-28 04:04:30 +00:00
|
|
|
XSelectInput(r->display, r->window, mask);
|
2025-09-28 02:51:15 +00:00
|
|
|
XMapWindow(r->display, r->window);
|
|
|
|
|
|
|
|
|
|
return r;
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-28 06:52:49 +00:00
|
|
|
void MilskoLLDestroy(HMILSKOLL handle) {
|
2025-09-28 04:04:30 +00:00
|
|
|
XFreeGC(handle->display, handle->gc);
|
|
|
|
|
XDestroyWindow(handle->display, handle->window);
|
|
|
|
|
free(handle);
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-28 06:52:49 +00:00
|
|
|
void MilskoLLPolygon(HMILSKOLL handle, MilskoPoint* points, int points_count, HMILSKOCOLOR color) {
|
2025-09-28 04:07:41 +00:00
|
|
|
int i;
|
2025-09-28 04:04:30 +00:00
|
|
|
XPoint* p = malloc(sizeof(*p) * points_count);
|
|
|
|
|
|
|
|
|
|
XSetForeground(handle->display, handle->gc, color->pixel);
|
|
|
|
|
|
2025-09-28 04:07:41 +00:00
|
|
|
for(i = 0; i < points_count; i++) {
|
2025-09-28 04:04:30 +00:00
|
|
|
p[i].x = points[i].x;
|
|
|
|
|
p[i].y = points[i].y;
|
|
|
|
|
}
|
|
|
|
|
XFillPolygon(handle->display, handle->window, handle->gc, p, points_count, Convex, CoordModeOrigin);
|
|
|
|
|
|
|
|
|
|
free(p);
|
2025-09-28 02:51:15 +00:00
|
|
|
}
|
|
|
|
|
|
2025-09-28 06:52:49 +00:00
|
|
|
HMILSKOCOLOR MilskoLLAllocColor(HMILSKOLL handle, int r, int g, int b) {
|
2025-09-28 02:51:15 +00:00
|
|
|
HMILSKOCOLOR c = malloc(sizeof(*c));
|
2025-09-28 04:07:41 +00:00
|
|
|
XColor xc;
|
|
|
|
|
xc.red = 256 * r;
|
2025-09-28 02:51:15 +00:00
|
|
|
xc.green = 256 * g;
|
2025-09-28 04:07:41 +00:00
|
|
|
xc.blue = 256 * b;
|
2025-09-28 02:51:15 +00:00
|
|
|
XAllocColor(handle->display, handle->colormap, &xc);
|
|
|
|
|
|
|
|
|
|
c->pixel = xc.pixel;
|
|
|
|
|
return c;
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-28 06:52:49 +00:00
|
|
|
void MilskoLLGetXYWH(HMILSKOLL handle, int* x, int* y, unsigned int* w, unsigned int* h) {
|
2025-09-28 09:04:35 +00:00
|
|
|
Window root;
|
|
|
|
|
unsigned int border, depth;
|
|
|
|
|
|
|
|
|
|
XGetGeometry(handle->display, handle->window, &root, x, y, w, h, &border, &depth);
|
|
|
|
|
|
|
|
|
|
handle->x = *x;
|
|
|
|
|
handle->y = *y;
|
|
|
|
|
handle->width = *w;
|
|
|
|
|
handle->height = *h;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MilskoLLSetXY(HMILSKOLL handle, int x, int y) {
|
|
|
|
|
XMoveWindow(handle->display, handle->window, x, y);
|
2025-09-28 04:04:30 +00:00
|
|
|
}
|
|
|
|
|
|
2025-09-28 09:04:35 +00:00
|
|
|
void MilskoLLSetWH(HMILSKOLL handle, int w, int h) {
|
|
|
|
|
XResizeWindow(handle->display, handle->window, w, h);
|
2025-09-28 08:45:58 +00:00
|
|
|
}
|
|
|
|
|
|
2025-09-28 04:07:41 +00:00
|
|
|
void MilskoLLFreeColor(HMILSKOCOLOR color) {
|
2025-09-28 02:51:15 +00:00
|
|
|
free(color);
|
|
|
|
|
}
|
2025-09-28 04:04:30 +00:00
|
|
|
|
2025-09-28 06:52:49 +00:00
|
|
|
int MilskoLLPending(HMILSKOLL handle) {
|
2025-09-28 04:04:30 +00:00
|
|
|
XEvent ev;
|
2025-09-28 04:07:41 +00:00
|
|
|
if(XCheckWindowEvent(handle->display, handle->window, mask, &ev)) {
|
2025-09-28 04:04:30 +00:00
|
|
|
XPutBackEvent(handle->display, &ev);
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2025-09-28 04:09:25 +00:00
|
|
|
|
2025-09-28 06:52:49 +00:00
|
|
|
void MilskoLLNextEvent(HMILSKOLL handle) {
|
2025-09-28 04:09:25 +00:00
|
|
|
XEvent ev;
|
|
|
|
|
if(XCheckWindowEvent(handle->display, handle->window, mask, &ev)) {
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-09-28 08:37:12 +00:00
|
|
|
|
2025-09-28 08:37:21 +00:00
|
|
|
void MilskoLLSleep(int ms) {
|
2025-09-28 08:37:12 +00:00
|
|
|
usleep(ms * 1000);
|
|
|
|
|
}
|
2025-09-28 09:08:53 +00:00
|
|
|
|
2025-09-28 09:14:57 +00:00
|
|
|
void MilskoLLSetTitle(HMILSKOLL handle, const char* title) {
|
2025-09-28 09:08:53 +00:00
|
|
|
XSetStandardProperties(handle->display, handle->window, title, "Milsko Widget Toolkit", None, (char**)NULL, 0, NULL);
|
|
|
|
|
}
|