mirror of
https://gitea.nishi.boats/pyrite-dev/milsko
synced 2026-01-16 14:14:07 +00:00
cursor
git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@180 b9cfdab3-6d41-4d17-bbe4-086880011989
This commit is contained in:
@@ -319,3 +319,49 @@ void MwLLSetIcon(MwLL handle, MwLLPixmap pixmap) {
|
||||
void MwLLForceRender(MwLL handle) {
|
||||
InvalidateRect(handle->hWnd, NULL, FALSE);
|
||||
}
|
||||
|
||||
void MwLLSetCursor(MwLL handle, MwCursor* image, MwCursor* mask) {
|
||||
HCURSOR cursor;
|
||||
BYTE* dmask = malloc((MwCursorDataHeight / 8) * MwCursorDataHeight);
|
||||
BYTE* dimage = malloc((MwCursorDataHeight / 8) * MwCursorDataHeight);
|
||||
int y, x;
|
||||
|
||||
memset(dmask, 0xff, (MwCursorDataHeight / 8) * MwCursorDataHeight);
|
||||
memset(dimage, 0, (MwCursorDataHeight / 8) * MwCursorDataHeight);
|
||||
|
||||
for(y = 0; y < mask->height; y++) {
|
||||
BYTE* l = &dmask[y * (MwCursorDataHeight / 8)];
|
||||
unsigned int n = mask->data[y];
|
||||
for(x = mask->width - 1; x >= 0; x--) {
|
||||
l[x / 8] = l[x / 8] >> 1;
|
||||
if(!(n & 1)) {
|
||||
l[x / 8] |= 1 << 7;
|
||||
}
|
||||
|
||||
n = n >> 1;
|
||||
}
|
||||
}
|
||||
|
||||
for(y = 0; y < image->height; y++) {
|
||||
BYTE* l = &dimage[(y + (MwCursorDataHeight + mask->y)) * (MwCursorDataHeight / 8)];
|
||||
unsigned int n = image->data[y];
|
||||
|
||||
for(x = image->width - 1; x >= 0; x--) {
|
||||
if(n & 1) {
|
||||
l[(x - mask->x) / 8] |= (1 << (7 - ((x - mask->x) % 8)));
|
||||
}
|
||||
|
||||
n = n >> 1;
|
||||
}
|
||||
}
|
||||
|
||||
cursor = CreateCursor(GetModuleHandle(NULL), -mask->x, MwCursorDataHeight + mask->y, MwCursorDataHeight, MwCursorDataHeight, dmask, dimage);
|
||||
|
||||
SetClassLongPtr(handle->hWnd, GCLP_HCURSOR, (LONG_PTR)cursor);
|
||||
SetCursor(cursor);
|
||||
|
||||
DestroyCursor(cursor);
|
||||
|
||||
free(dimage);
|
||||
free(dmask);
|
||||
}
|
||||
|
||||
@@ -334,3 +334,39 @@ void MwLLForceRender(MwLL handle) {
|
||||
ev.xexpose.window = handle->window;
|
||||
XSendEvent(handle->display, handle->window, False, ExposureMask, &ev);
|
||||
}
|
||||
|
||||
void MwLLSetCursor(MwLL handle, MwCursor* image, MwCursor* mask) {
|
||||
XcursorImage* img = XcursorImageCreate(MwCursorDataHeight, MwCursorDataHeight);
|
||||
Cursor cur;
|
||||
int y, x;
|
||||
|
||||
img->xhot = -mask->x;
|
||||
img->yhot = MwCursorDataHeight + mask->y;
|
||||
|
||||
memset(img->pixels, 0, MwCursorDataHeight * MwCursorDataHeight * sizeof(XcursorPixel));
|
||||
for(y = 0; y < mask->height; y++) {
|
||||
unsigned int l = mask->data[y];
|
||||
for(x = mask->width - 1; x >= 0; x--) {
|
||||
if(l & 1) {
|
||||
img->pixels[y * MwCursorDataHeight + x] = 0xff000000;
|
||||
}
|
||||
l = l >> 1;
|
||||
}
|
||||
}
|
||||
for(y = 0; y < image->height; y++) {
|
||||
unsigned int l = image->data[y];
|
||||
for(x = image->width - 1; x >= 0; x--) {
|
||||
int px = 0;
|
||||
if(l & 1) px = 255;
|
||||
img->pixels[(img->yhot + y) * MwCursorDataHeight + (img->xhot + x)] |= (px << 16) | (px << 8) | (px);
|
||||
|
||||
l = l >> 1;
|
||||
}
|
||||
}
|
||||
|
||||
cur = XcursorImageLoadCursor(handle->display, img);
|
||||
XDefineCursor(handle->display, handle->window, cur);
|
||||
XFreeCursor(handle->display, cur);
|
||||
|
||||
XcursorImageDestroy(img);
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xutil.h>
|
||||
#include <X11/Xcursor/Xcursor.h>
|
||||
#include <X11/extensions/XShm.h>
|
||||
#include <X11/extensions/Xrender.h>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user