fix cursor thing for x11/gdi, also format
All checks were successful
pyrite-dev/milsko/pipeline/head This commit looks good

This commit is contained in:
Nishi 2026-03-24 04:26:26 +09:00
commit 6d7fe3271f
Signed by: nishi
GPG key ID: 27EF69B208EB9343
8 changed files with 231 additions and 228 deletions

View file

@ -20,18 +20,18 @@ static void draw(void) {
glRotatef(deg, 0, 1, 0);
glRotatef(deg, 0, 0, 1);
for (i = 0; i < 6; i++) {
if (i == 0)
for(i = 0; i < 6; i++) {
if(i == 0)
glColor3f(1, 0, 0);
if (i == 1)
if(i == 1)
glColor3f(0, 1, 0);
if (i == 2)
if(i == 2)
glColor3f(1, 1, 0);
if (i == 3)
if(i == 3)
glColor3f(0, 0, 1);
if (i == 4)
if(i == 4)
glColor3f(1, 0, 1);
if (i == 5)
if(i == 5)
glColor3f(0, 1, 1);
glBegin(GL_QUADS);
@ -42,17 +42,19 @@ static void draw(void) {
glVertex3f(1, 1, -1);
glEnd();
if (i < 3)
if(i < 3)
glRotatef(90, 0, 0, 1);
if (i == 3)
if(i == 3)
glRotatef(90, 1, 0, 0);
if (i == 4)
if(i == 4)
glRotatef(180, 0, 0, 1);
}
glPopMatrix();
}
static void idle(void) { deg += 1.0; }
static void idle(void) {
deg += 1.0;
}
static void reshape(int width, int height) {
GLfloat lpos[4];
@ -86,4 +88,6 @@ static void init(void) {
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
}
static void key(int k) { (void)k; }
static void key(int k) {
(void)k;
}

View file

@ -23,9 +23,9 @@
// Note: implements NSApplicationDelegate
@interface MilskoCocoaApplicationDelegate : NSObject {
NSApplication *appl;
NSApplication* appl;
}
- (MilskoCocoaApplicationDelegate *)initWithAppl:(NSApplication *)appl;
- (MilskoCocoaApplicationDelegate*)initWithAppl:(NSApplication*)appl;
@end
@interface MilskoCocoaWindow : NSWindow {
@ -34,9 +34,9 @@
// Note: implements NSWindowDelegate
@interface MilskoCocoaWindowDelegate : NSObject {
MilskoCocoaWindow *w;
MilskoCocoaWindow* w;
}
- (MilskoCocoaWindowDelegate *)initWithWin:(MilskoCocoaWindow *)win;
- (MilskoCocoaWindowDelegate*)initWithWin:(MilskoCocoaWindow*)win;
@end
/*
@ -52,11 +52,11 @@
retrieved appropriately.
*/
@interface MilskoFakePointer : NSView {
void *ptr;
void* ptr;
}
- (void)setPointer:(void *)ptr;
- (void *)pointer;
- (void)setPointer:(void*)ptr;
- (void*)pointer;
@end
@ -64,24 +64,24 @@
MwBool valid;
int width;
int height;
unsigned char *buf;
NSImage *image;
NSBitmapImageRep *rep;
unsigned char* buf;
NSImage* image;
NSBitmapImageRep* rep;
}
+ (MilskoCocoaPixmap *)newWithWidth:(int)width height:(int)height;
- (void)updateWithData:(unsigned char *)data;
+ (MilskoCocoaPixmap*)newWithWidth:(int)width height:(int)height;
- (void)updateWithData:(unsigned char*)data;
- (void)destroy;
/* using @property to create instance variables fucks up 10.4 gcc for some
* reason? */
- (NSImage *)image;
- (NSImage*)image;
@end
@interface MilskoCocoaView : NSView {
NSBitmapImageRep *rep;
NSGraphicsContext *context;
NSBitmapImageRep* rep;
NSGraphicsContext* context;
MwBool valid;
CGColorSpaceRef space;
CGDataProviderRef provider;
@ -90,56 +90,55 @@
}
- (void)initRepAndContextWithWidth:(float)w Height:(float)h;
- (NSGraphicsContext *)context;
- (NSGraphicsContext*)context;
- (void)destroy;
- (NSBitmapImageRep *)getRep;
- (NSBitmapImageRep*)getRep;
@end
@interface MilskoCocoa : NSObject {
NSApplication *application;
NSApplication* application;
MwBool _forceRender;
MilskoCocoaWindow *window;
MilskoCocoaWindow* window;
NSRect rect;
MilskoCocoaView *view;
MilskoCocoaView* view;
MwLL parent;
MilskoFakePointer *handle;
MilskoFakePointer* handle;
unsigned int strHash;
NSEvent *lastEvent;
NSEvent* lastEvent;
MilskoCocoaPixmap *cursorPixmap;
NSCursor *cursor;
MilskoCocoaPixmap* cursorPixmap;
NSCursor* cursor;
NSModalSession modalSession;
MwBool pointerLocked;
MwBool mouseMoved;
}
+ (MilskoCocoa *)newWithParent:(MwLL)parent
+ (MilskoCocoa*)newWithParent:(MwLL)parent
x:(int)x
y:(int)y
width:(int)width
height:(int)height
handle:(MwLL)handle;
- (void)polygonWithPoints:(MwPoint *)points
- (void)polygonWithPoints:(MwPoint*)points
points_count:(int)points_count
color:(MwLLColor)color;
- (void)lineWithPoints:(MwPoint *)points color:(MwLLColor)color;
- (void)getX:(int *)x Y:(int *)y W:(unsigned int *)w H:(unsigned int *)h;
- (void)lineWithPoints:(MwPoint*)points color:(MwLLColor)color;
- (void)getX:(int*)x Y:(int*)y W:(unsigned int*)w H:(unsigned int*)h;
- (void)setX:(int)x Y:(int)y;
- (void)setW:(int)w H:(int)h;
- (int)pending;
- (void)eventProcess:(NSEvent *)ev;
- (void)handleKeyEvent:(NSEvent *)ev ll:(MwLL)ll;
- (void)handleMouseEvent:(NSEvent *)ev ll:(MwLL)ll;
- (void)eventProcess:(NSEvent*)ev;
- (void)handleKeyEvent:(NSEvent*)ev ll:(MwLL)ll;
- (void)handleMouseEvent:(NSEvent*)ev ll:(MwLL)ll;
- (void)getNextEvent;
- (void)setTitle:(const char *)title;
- (void)drawPixmap:(MwLLPixmap)pixmap rect:(MwRect *)rect;
- (void)setTitle:(const char*)title;
- (void)drawPixmap:(MwLLPixmap)pixmap rect:(MwRect*)rect;
- (void)setIcon:(MwLLPixmap)pixmap;
- (void)forceRender;
- (void)setCursor:(MwCursor *)image mask:(MwCursor *)mask;
- (void)detachWithPoint:(MwPoint *)point;
- (void)setCursor:(MwCursor*)image mask:(MwCursor*)mask;
- (void)detachWithPoint:(MwPoint*)point;
- (void)show:(int)show;
- (void)makePopupWithParent:(MwLL)parent;
- (void)setSizeHintsWithMinX:(int)minx
@ -149,31 +148,31 @@
- (void)makeBorderless:(int)toggle;
- (void)focus;
- (void)grabPointer:(int)toggle;
- (void)setClipboard:(const char *)text;
- (void)setClipboard:(const char*)text;
- (void)makeToolWindow;
- (void)getCursorCoord:(MwPoint *)point;
- (void)getScreenSize:(MwRect *)rect;
- (void)getCursorCoord:(MwPoint*)point;
- (void)getScreenSize:(MwRect*)rect;
- (void)destroy;
- (void)sendClipboardEvent;
- (MwLL)getParent;
- (NSView *)getView;
- (MilskoCocoaWindow *)getWindow;
- (NSView*)getView;
- (MilskoCocoaWindow*)getWindow;
- (MilskoFakePointer *)getHandle;
+ (void)eventCanceller:(MilskoCocoa *)this;
- (MilskoFakePointer*)getHandle;
+ (void)eventCanceller:(MilskoCocoa*)this;
@end
#define OBJC(x) x
#else
#define OBJC(x) void *
#define OBJC(x) void*
#endif
MWDECL int MwLLCocoaCallInit(void);
struct _MwLLCocoa {
struct _MwLLCommon common;
OBJC(MilskoCocoa *)
OBJC(MilskoCocoa*)
real;
};
@ -183,7 +182,7 @@ struct _MwLLCocoaColor {
struct _MwLLCocoaPixmap {
struct _MwLLCommonPixmap common;
OBJC(MilskoCocoaPixmap *)
OBJC(MilskoCocoaPixmap*)
real;
};

View file

@ -52,8 +52,8 @@ MwInline void MwOpenGLMakeCurrent(MwWidget handle) {
* @param name Name
* @return Procedure
*/
MwInline void *MwOpenGLGetProcAddress(MwWidget handle, const char *name) {
void *out;
MwInline void* MwOpenGLGetProcAddress(MwWidget handle, const char* name) {
void* out;
MwVaWidgetExecute(handle, "mwOpenGLGetProcAddress", &out, name);
return out;
}

View file

@ -55,7 +55,7 @@ if (grep(/^cocoa$/, @backends)) {
new_object("src/widget/opengl_cocoa.m");
}
# tim cook my man literally everybody and their mother who knows what opengl is knows its deprecated on macos and i'm not having you spam the console with this
# tim cook my man literally everybody and their mother who knows what opengl is knows its deprecated on macos and i'm not having you spam the console with this
add_cflags("-DGL_SILENCE_DEPRECATION");
$gl_libs = "-framework OpenGL";

View file

@ -621,7 +621,7 @@ HCURSOR MwLLGDICreateCursor(MwCursor* image, MwCursor* mask) {
}
}
cursor = CreateCursor(GetModuleHandle(NULL), xs, ys, MwCursorDataHeight, MwCursorDataHeight, dmask, dimage);
cursor = CreateCursor(GetModuleHandle(NULL), xs - image->x, ys + (MwCursorDataHeight + image->y), MwCursorDataHeight, MwCursorDataHeight, dmask, dimage);
free(dimage);
free(dmask);

View file

@ -849,7 +849,7 @@ Cursor MwLLX11CreateCursor(Display* display, MwCursor* image, MwCursor* mask) {
XPutImage(display, pimage, imagegc, cimage, 0, 0, 0, 0, MwCursorDataHeight, MwCursorDataHeight);
XPutImage(display, pmask, maskgc, cmask, 0, 0, 0, 0, MwCursorDataHeight, MwCursorDataHeight);
cur = XCreatePixmapCursor(display, pimage, pmask, &cfg, &cbg, xs, ys);
cur = XCreatePixmapCursor(display, pimage, pmask, &cfg, &cbg, xs - image->x, ys + (MwCursorDataHeight + image->y));
XFreePixmap(display, pimage);
XFreePixmap(display, pmask);

View file

@ -7,21 +7,21 @@
#import <mach-o/dyld.h>
@interface MacOpenGLWidget : NSObject {
NSOpenGLPixelFormat *pixelFormat;
NSOpenGLContext *glc;
MilskoCocoa *_win;
NSOpenGLPixelFormat* pixelFormat;
NSOpenGLContext* glc;
MilskoCocoa* _win;
}
- (MacOpenGLWidget *)initWithWindow:(MilskoCocoa *)w;
- (MacOpenGLWidget*)initWithWindow:(MilskoCocoa*)w;
- (void)destroy;
- (void)makeCurrent;
- (void)swapBuffer;
- (void *)getProcAddressWithName:(const char *)name;
- (void*)getProcAddressWithName:(const char*)name;
@end
static int create(MwWidget handle) {
void *r = NULL;
void* r = NULL;
MwWidget w = handle;
int x = MwGetInteger(w, MwNx);
@ -37,7 +37,7 @@ static int create(MwWidget handle) {
MwSetDefault(handle);
while (w->parent != NULL)
while(w->parent != NULL)
w = w->parent;
w->berserk++;
@ -46,38 +46,38 @@ static int create(MwWidget handle) {
}
static void destroy(MwWidget handle) {
[(MacOpenGLWidget *)handle->internal destroy];
[(MacOpenGLWidget*)handle->internal destroy];
}
static void mwOpenGLMakeCurrentImpl(MwWidget handle) {
[(MacOpenGLWidget *)handle->internal makeCurrent];
[(MacOpenGLWidget*)handle->internal makeCurrent];
}
static void mwOpenGLSwapBufferImpl(MwWidget handle) {
[(MacOpenGLWidget *)handle->internal swapBuffer];
[(MacOpenGLWidget*)handle->internal swapBuffer];
}
static void *mwOpenGLGetProcAddressImpl(MwWidget handle, const char *name) {
return [(MacOpenGLWidget *)handle->internal getProcAddressWithName:name];
static void* mwOpenGLGetProcAddressImpl(MwWidget handle, const char* name) {
return [(MacOpenGLWidget*)handle->internal getProcAddressWithName:name];
}
static void func_handler(MwWidget handle, const char *name, void *out,
static void func_handler(MwWidget handle, const char* name, void* out,
va_list va) {
if (strcmp(name, "mwOpenGLMakeCurrent") == 0) {
if(strcmp(name, "mwOpenGLMakeCurrent") == 0) {
mwOpenGLMakeCurrentImpl(handle);
}
if (strcmp(name, "mwOpenGLSwapBuffer") == 0) {
if(strcmp(name, "mwOpenGLSwapBuffer") == 0) {
mwOpenGLSwapBufferImpl(handle);
}
if (strcmp(name, "mwOpenGLGetProcAddress") == 0) {
const char *_name = va_arg(va, const char *);
*(void **)out = mwOpenGLGetProcAddressImpl(handle, _name);
if(strcmp(name, "mwOpenGLGetProcAddress") == 0) {
const char* _name = va_arg(va, const char*);
*(void**)out = mwOpenGLGetProcAddressImpl(handle, _name);
}
}
@implementation MacOpenGLWidget
- (MacOpenGLWidget *)initWithWindow:(MilskoCocoa *)w {
- (MacOpenGLWidget*)initWithWindow:(MilskoCocoa*)w {
NSOpenGLPixelFormatAttribute pixelFormatAttributes[] = {
NSOpenGLPFAColorSize, 24,
NSOpenGLPFAStencilSize, 8,
@ -87,7 +87,8 @@ static void func_handler(MwWidget handle, const char *name, void *out,
self->pixelFormat =
[[NSOpenGLPixelFormat alloc] initWithAttributes:pixelFormatAttributes];
self->glc =
[[NSOpenGLContext alloc] initWithFormat:pixelFormat shareContext:nil];
[[NSOpenGLContext alloc] initWithFormat:pixelFormat
shareContext:nil];
[self->glc setView:[w getView]];
self->_win = w;
return self;
@ -100,8 +101,8 @@ static void func_handler(MwWidget handle, const char *name, void *out,
- (void)swapBuffer {
[self->glc flushBuffer];
};
- (void *)getProcAddressWithName:(const char *)name {
if (NSIsSymbolNameDefined(name)) {
- (void*)getProcAddressWithName:(const char*)name {
if(NSIsSymbolNameDefined(name)) {
return NSAddressOfSymbol(NSLookupAndBindSymbol(name));
} else {
return NULL;

View file

@ -58,8 +58,7 @@ l(
l("");
c("Requirements");
l("");
l(
" Milsko requires either");
l(" Milsko requires either");
l(" * A Windows environment with GDI (so anything NT or 9x)");
l(" * A MacOS environment with Cocoa (10.4 or above supported)");
l(" * A Unix-like environment with X11 for runtime.");