mirror of
https://gitea.nishi.boats/pyrite-dev/milsko
synced 2026-01-15 22:03:29 +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>
|
||||
|
||||
|
||||
@@ -299,6 +299,8 @@ void MwVaListApply(MwWidget handle, va_list va) {
|
||||
}
|
||||
|
||||
void MwSetDefault(MwWidget handle) {
|
||||
MwLLSetCursor(handle->lowlevel, &MwCursorDefault, &MwCursorDefaultMask);
|
||||
|
||||
MwSetText(handle, MwNbackground, MwDefaultBackground);
|
||||
MwSetText(handle, MwNforeground, MwDefaultForeground);
|
||||
}
|
||||
|
||||
44
src/cursor/default.c
Normal file
44
src/cursor/default.c
Normal file
@@ -0,0 +1,44 @@
|
||||
/* $Id$ */
|
||||
#include <Mw/Milsko.h>
|
||||
|
||||
/**
|
||||
* Created by bitmaptobdf
|
||||
*
|
||||
* Copyright notice:
|
||||
* These ""glyphs"" are unencumbered
|
||||
*/
|
||||
MwCursor MwCursorDefault = {
|
||||
8, 14, 0, -14, {128, /* #....... */
|
||||
192, /* ##...... */
|
||||
224, /* ###..... */
|
||||
240, /* ####.... */
|
||||
248, /* #####... */
|
||||
252, /* ######.. */
|
||||
254, /* #######. */
|
||||
255, /* ######## */
|
||||
248, /* #####... */
|
||||
216, /* ##.##... */
|
||||
140, /* #...##.. */
|
||||
12, /* ....##.. */
|
||||
6, /* .....##. */
|
||||
6, /* .....##. */
|
||||
0, 0}};
|
||||
MwCursor MwCursorDefaultMask = {
|
||||
10, 16, -1, -15, {
|
||||
768, /* ##........ */
|
||||
896, /* ###....... */
|
||||
960, /* ####...... */
|
||||
992, /* #####..... */
|
||||
1008, /* ######.... */
|
||||
1016, /* #######... */
|
||||
1020, /* ########.. */
|
||||
1022, /* #########. */
|
||||
1023, /* ########## */
|
||||
1023, /* ########## */
|
||||
1016, /* #######... */
|
||||
956, /* ###.####.. */
|
||||
828, /* ##..####.. */
|
||||
30, /* .....####. */
|
||||
30, /* .....####. */
|
||||
12 /* ......##.. */
|
||||
}};
|
||||
@@ -106,9 +106,10 @@ static void draw(MwWidget handle) {
|
||||
MwDrawRect(handle, &r, base);
|
||||
|
||||
BEGIN_MENU_LOOP;
|
||||
(void)in_area;
|
||||
if(m->sub[i]->wsub != NULL) {
|
||||
MwDrawFrame(handle, &r, base, 0);
|
||||
} else if(in_area && handle->pressed) {
|
||||
MwDrawFrame(handle, &r, base, 0);
|
||||
}
|
||||
|
||||
MwDrawText(handle, &p, m->sub[i]->name + incr, 1, text);
|
||||
|
||||
Reference in New Issue
Block a user