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 09:50:28 +00:00
|
|
|
MilskoLL MilskoLLCreate(MilskoLL parent, int x, int y, int width, int height) {
|
|
|
|
|
MilskoLL r;
|
2025-09-28 09:04:35 +00:00
|
|
|
Window p;
|
|
|
|
|
Window root;
|
|
|
|
|
unsigned int border, depth;
|
2025-09-28 02:51:15 +00:00
|
|
|
|
2025-09-28 22:00:17 +00:00
|
|
|
r = malloc(sizeof(*r));
|
2025-09-28 21:55:50 +00:00
|
|
|
|
2025-09-28 22:00:17 +00:00
|
|
|
MilskoLLCreateCommon(r);
|
2025-09-28 04:06:26 +00:00
|
|
|
|
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 09:50:28 +00:00
|
|
|
void MilskoLLDestroy(MilskoLL handle) {
|
2025-09-28 22:00:17 +00:00
|
|
|
MilskoLLDestroyCommon(handle);
|
|
|
|
|
|
2025-09-28 04:04:30 +00:00
|
|
|
XFreeGC(handle->display, handle->gc);
|
|
|
|
|
XDestroyWindow(handle->display, handle->window);
|
|
|
|
|
free(handle);
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-28 09:50:28 +00:00
|
|
|
void MilskoLLPolygon(MilskoLL handle, MilskoPoint* points, int points_count, MilskoLLColor 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 09:50:28 +00:00
|
|
|
MilskoLLColor MilskoLLAllocColor(MilskoLL handle, int r, int g, int b) {
|
|
|
|
|
MilskoLLColor c = malloc(sizeof(*c));
|
|
|
|
|
XColor xc;
|
2025-09-28 14:36:24 +00:00
|
|
|
|
|
|
|
|
if(r > 255) r = 255;
|
|
|
|
|
if(g > 255) g = 255;
|
|
|
|
|
if(b > 255) b = 255;
|
|
|
|
|
if(r < 0) r = 0;
|
|
|
|
|
if(g < 0) g = 0;
|
|
|
|
|
if(b < 0) b = 0;
|
|
|
|
|
|
2025-09-28 04:07:41 +00:00
|
|
|
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;
|
2025-09-28 13:53:35 +00:00
|
|
|
c->red = r;
|
|
|
|
|
c->green = g;
|
|
|
|
|
c->blue = b;
|
2025-09-28 02:51:15 +00:00
|
|
|
return c;
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-28 09:50:28 +00:00
|
|
|
void MilskoLLGetXYWH(MilskoLL 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);
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-28 09:50:28 +00:00
|
|
|
void MilskoLLSetXY(MilskoLL handle, int x, int y) {
|
2025-09-28 09:04:35 +00:00
|
|
|
XMoveWindow(handle->display, handle->window, x, y);
|
2025-09-28 04:04:30 +00:00
|
|
|
}
|
|
|
|
|
|
2025-09-28 09:50:28 +00:00
|
|
|
void MilskoLLSetWH(MilskoLL handle, int w, int h) {
|
2025-09-28 09:04:35 +00:00
|
|
|
XResizeWindow(handle->display, handle->window, w, h);
|
2025-09-28 08:45:58 +00:00
|
|
|
}
|
|
|
|
|
|
2025-09-28 09:50:28 +00:00
|
|
|
void MilskoLLFreeColor(MilskoLLColor color) {
|
2025-09-28 02:51:15 +00:00
|
|
|
free(color);
|
|
|
|
|
}
|
2025-09-28 04:04:30 +00:00
|
|
|
|
2025-09-28 09:50:28 +00:00
|
|
|
int MilskoLLPending(MilskoLL 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 09:50:28 +00:00
|
|
|
void MilskoLLNextEvent(MilskoLL handle) {
|
2025-09-28 04:09:25 +00:00
|
|
|
XEvent ev;
|
|
|
|
|
if(XCheckWindowEvent(handle->display, handle->window, mask, &ev)) {
|
2025-09-28 09:55:42 +00:00
|
|
|
if(ev.type == Expose) {
|
2025-09-28 21:55:50 +00:00
|
|
|
MilskoLLDispatch(handle, draw);
|
2025-09-28 09:55:42 +00:00
|
|
|
}
|
2025-09-28 04:09:25 +00:00
|
|
|
}
|
|
|
|
|
}
|
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:50:28 +00:00
|
|
|
void MilskoLLSetTitle(MilskoLL 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);
|
|
|
|
|
}
|