2026-01-09 21:35:23 -07:00
|
|
|
#include <Mw/Milsko.h>
|
2026-03-03 23:24:28 -07:00
|
|
|
#include <assert.h>
|
|
|
|
|
#include <stdbool.h>
|
2026-01-09 21:35:23 -07:00
|
|
|
|
2026-01-12 13:04:30 -07:00
|
|
|
@implementation MilskoCocoaPixmap
|
|
|
|
|
|
2026-03-03 23:24:28 -07:00
|
|
|
+ (MilskoCocoaPixmap *)newWithWidth:(int)width height:(int)height {
|
|
|
|
|
MilskoCocoaPixmap *p = [MilskoCocoaPixmap alloc];
|
|
|
|
|
|
|
|
|
|
p->width = width;
|
|
|
|
|
p->height = height;
|
|
|
|
|
p->data = NULL;
|
|
|
|
|
p->image = NULL;
|
|
|
|
|
return p;
|
|
|
|
|
}
|
|
|
|
|
- (void)updateWithData:(unsigned char *)_data {
|
|
|
|
|
[self destroy];
|
|
|
|
|
|
|
|
|
|
self->rep =
|
|
|
|
|
[[NSBitmapImageRep alloc] initWithBitmapDataPlanes:&_data
|
|
|
|
|
pixelsWide:(int)width
|
|
|
|
|
pixelsHigh:(int)height
|
|
|
|
|
bitsPerSample:8
|
|
|
|
|
samplesPerPixel:4
|
|
|
|
|
hasAlpha:YES
|
|
|
|
|
isPlanar:NO
|
|
|
|
|
colorSpaceName:NSDeviceRGBColorSpace
|
|
|
|
|
bytesPerRow:(int)width * 4
|
|
|
|
|
bitsPerPixel:32];
|
|
|
|
|
|
|
|
|
|
assert(self->rep);
|
|
|
|
|
self->data = [NSData dataWithBytes:[self->rep bitmapData]
|
|
|
|
|
length:self->width * self->height * 4];
|
|
|
|
|
assert(self->data);
|
|
|
|
|
self->image = [[NSImage alloc] initWithSize:NSMakeSize(width, height)];
|
|
|
|
|
assert(self->image);
|
|
|
|
|
[self->image addRepresentation:self->rep];
|
2026-01-12 13:04:30 -07:00
|
|
|
}
|
|
|
|
|
- (void)destroy {
|
2026-03-03 23:24:28 -07:00
|
|
|
if (self->data != NULL) {
|
|
|
|
|
[self->data dealloc];
|
|
|
|
|
}
|
|
|
|
|
if (self->image != NULL) {
|
|
|
|
|
[self->image dealloc];
|
|
|
|
|
}
|
2026-01-14 17:13:12 -07:00
|
|
|
}
|
2026-03-03 23:24:28 -07:00
|
|
|
- (NSImage *)image {
|
|
|
|
|
return self->image;
|
2026-01-12 13:04:30 -07:00
|
|
|
}
|
|
|
|
|
@end
|
|
|
|
|
|
2026-01-09 21:35:23 -07:00
|
|
|
@implementation MilskoCocoa
|
|
|
|
|
|
2026-03-03 23:24:28 -07:00
|
|
|
+ (MilskoCocoa *)newWithParent:(MwLL)parent
|
|
|
|
|
x:(int)x
|
|
|
|
|
y:(int)y
|
|
|
|
|
width:(int)width
|
|
|
|
|
height:(int)height {
|
|
|
|
|
MilskoCocoa *c = [MilskoCocoa alloc];
|
|
|
|
|
bool centerX = false, centerY = false;
|
|
|
|
|
|
|
|
|
|
if (x == MwDEFAULT) {
|
|
|
|
|
x = 0;
|
|
|
|
|
centerX = true;
|
|
|
|
|
}
|
|
|
|
|
if (y == MwDEFAULT) {
|
|
|
|
|
y = 0;
|
|
|
|
|
centerY = true;
|
|
|
|
|
}
|
|
|
|
|
c->application = [NSApplication sharedApplication];
|
|
|
|
|
|
|
|
|
|
c->rect = NSMakeRect(x, y, width, height);
|
|
|
|
|
|
|
|
|
|
if (parent == NULL) {
|
|
|
|
|
c->window = [[NSWindow alloc]
|
|
|
|
|
initWithContentRect:c->rect
|
|
|
|
|
styleMask:(NSTitledWindowMask | NSClosableWindowMask |
|
|
|
|
|
NSMiniaturizableWindowMask | NSResizableWindowMask)
|
|
|
|
|
backing:NSBackingStoreBuffered
|
|
|
|
|
defer:NO];
|
|
|
|
|
} else {
|
|
|
|
|
NSWindow *parentWindow = parent->cocoa.real->window;
|
|
|
|
|
|
|
|
|
|
c->rect = [parentWindow frameRectForContentRect:c->rect];
|
|
|
|
|
c->rect.origin.y =
|
|
|
|
|
y -
|
|
|
|
|
[parentWindow contentRectForFrameRect:parentWindow.frame].size.height;
|
|
|
|
|
|
|
|
|
|
c->window = [[NSWindow alloc] initWithContentRect:c->rect
|
|
|
|
|
styleMask:NSBorderlessWindowMask
|
|
|
|
|
backing:NSBackingStoreBuffered
|
|
|
|
|
defer:NO];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[c->window makeKeyAndOrderFront:c->application];
|
|
|
|
|
|
|
|
|
|
if (parent != NULL) {
|
|
|
|
|
MilskoCocoa *p = parent->cocoa.real;
|
|
|
|
|
[p->window addChildWindow:c->window ordered:NSWindowAbove];
|
|
|
|
|
} else {
|
|
|
|
|
[c->application activateIgnoringOtherApps:true];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
c->view = [[MilskoCocoaView alloc] initWithFrame:c->rect];
|
|
|
|
|
[c->window setContentView:c->view];
|
|
|
|
|
|
|
|
|
|
c->parent = parent;
|
|
|
|
|
|
|
|
|
|
return c;
|
|
|
|
|
}
|
|
|
|
|
- (void)polygonWithPoints:(MwPoint *)points
|
|
|
|
|
points_count:(int)points_count
|
|
|
|
|
color:(MwLLColor)color {
|
|
|
|
|
int i;
|
|
|
|
|
CGContextRef cg = [self->view context];
|
|
|
|
|
|
|
|
|
|
[self->view lockFocus];
|
|
|
|
|
|
|
|
|
|
CGContextSetRGBFillColor(cg, color->common.red / 255.,
|
|
|
|
|
color->common.blue / 255.,
|
|
|
|
|
color->common.green / 255., 1);
|
|
|
|
|
CGContextBeginPath(cg);
|
|
|
|
|
for (i = 0; i < points_count; i++) {
|
|
|
|
|
CGContextMoveToPoint(cg, points[i].x, points[i].y);
|
|
|
|
|
if (i < points_count - 1) {
|
|
|
|
|
CGContextAddLineToPoint(cg, points[i + 1].x, points[i + 1].y);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
CGContextFillPath(cg);
|
|
|
|
|
[self->view unlockFocus];
|
|
|
|
|
|
|
|
|
|
[self->view setNeedsDisplay:true];
|
2026-01-09 21:35:23 -07:00
|
|
|
};
|
2026-03-03 23:24:28 -07:00
|
|
|
- (void)lineWithPoints:(MwPoint *)points color:(MwLLColor)color {
|
2026-01-09 21:35:23 -07:00
|
|
|
};
|
2026-03-03 23:24:28 -07:00
|
|
|
- (void)getX:(int *)x Y:(int *)y W:(unsigned int *)w H:(unsigned int *)h {
|
|
|
|
|
NSRect frame = [self->window frame];
|
2026-01-12 13:04:30 -07:00
|
|
|
|
2026-03-03 23:24:28 -07:00
|
|
|
*x = frame.origin.x;
|
|
|
|
|
*y = frame.origin.y - frame.size.height;
|
|
|
|
|
*w = frame.size.width;
|
|
|
|
|
*h = frame.size.height;
|
2026-01-09 21:35:23 -07:00
|
|
|
};
|
|
|
|
|
- (void)setX:(int)x Y:(int)y {
|
2026-03-03 23:24:28 -07:00
|
|
|
NSRect frame = [self->window frame];
|
|
|
|
|
|
|
|
|
|
frame.origin.x = x;
|
|
|
|
|
frame.origin.y = y;
|
|
|
|
|
|
|
|
|
|
if (self->parent) {
|
|
|
|
|
NSWindow *parentWindow = self->parent->cocoa.real->window;
|
|
|
|
|
frame = [parentWindow contentRectForFrameRect:frame];
|
|
|
|
|
frame.origin.y =
|
|
|
|
|
[parentWindow contentRectForFrameRect:parentWindow.frame].size.height -
|
|
|
|
|
y;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[self->window setFrame:frame display:YES animate:false];
|
2026-01-09 21:35:23 -07:00
|
|
|
};
|
|
|
|
|
- (void)setW:(int)w H:(int)h {
|
2026-03-03 23:24:28 -07:00
|
|
|
NSRect frame = [self->window frame];
|
|
|
|
|
frame.size.width = w;
|
|
|
|
|
frame.size.height = h;
|
|
|
|
|
|
|
|
|
|
if (self->parent) {
|
|
|
|
|
NSWindow *parentWindow = self->parent->cocoa.real->window;
|
|
|
|
|
// frame = [parentWindow contentRectForFrameRect:frame];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[self->window setFrame:frame display:YES animate:false];
|
2026-01-09 21:35:23 -07:00
|
|
|
};
|
|
|
|
|
- (int)pending {
|
2026-03-03 23:24:28 -07:00
|
|
|
self->lastEvent =
|
|
|
|
|
[self->application nextEventMatchingMask:NSAnyEventMask
|
|
|
|
|
untilDate:nil
|
|
|
|
|
inMode:NSDefaultRunLoopMode
|
|
|
|
|
dequeue:YES];
|
|
|
|
|
return self->lastEvent != NULL;
|
2026-01-09 21:35:23 -07:00
|
|
|
};
|
|
|
|
|
- (void)getNextEvent {
|
2026-03-03 23:24:28 -07:00
|
|
|
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
2026-01-15 05:31:04 +09:00
|
|
|
|
2026-03-03 23:24:28 -07:00
|
|
|
if (self->lastEvent != nil) {
|
|
|
|
|
// printf("got event: %ld\n", self->lastEvent.type);
|
|
|
|
|
}
|
2026-01-14 17:13:12 -07:00
|
|
|
|
2026-03-03 23:24:28 -07:00
|
|
|
[self->application sendEvent:self->lastEvent];
|
2026-01-14 17:13:12 -07:00
|
|
|
|
2026-03-03 23:24:28 -07:00
|
|
|
/* this should be in the draw functions but it's here for now for testing */
|
|
|
|
|
[self->view setNeedsDisplay:true];
|
2026-01-14 17:13:12 -07:00
|
|
|
|
2026-03-03 23:24:28 -07:00
|
|
|
[pool release];
|
2026-01-09 21:35:23 -07:00
|
|
|
};
|
2026-03-03 23:24:28 -07:00
|
|
|
- (void)setTitle:(const char *)title {
|
|
|
|
|
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
|
|
|
|
[self->window
|
|
|
|
|
setTitleWithRepresentedFilename:[NSString stringWithUTF8String:title]];
|
|
|
|
|
[pool release];
|
2026-01-09 21:35:23 -07:00
|
|
|
};
|
2026-03-03 23:24:28 -07:00
|
|
|
- (void)drawPixmap:(MwLLPixmap)pixmap rect:(MwRect *)_rect {
|
|
|
|
|
MilskoCocoaPixmap *p = pixmap->cocoa.real;
|
|
|
|
|
NSGraphicsContext *ctx = [self->view context];
|
|
|
|
|
if (ctx) {
|
|
|
|
|
[NSGraphicsContext saveGraphicsState];
|
|
|
|
|
[NSGraphicsContext setCurrentContext:ctx];
|
|
|
|
|
|
|
|
|
|
[[NSColor redColor] setFill];
|
|
|
|
|
[[p image] drawInRect:NSMakeRect(_rect->x, _rect->y, _rect->width,
|
|
|
|
|
_rect->height)
|
|
|
|
|
fromRect:NSZeroRect
|
|
|
|
|
operation:NSCompositeSourceOver
|
|
|
|
|
fraction:1.0
|
|
|
|
|
respectFlipped:NO
|
|
|
|
|
hints:nil];
|
|
|
|
|
|
|
|
|
|
[NSGraphicsContext restoreGraphicsState];
|
|
|
|
|
|
|
|
|
|
[self->view setNeedsDisplay:YES];
|
|
|
|
|
}
|
2026-01-09 21:35:23 -07:00
|
|
|
};
|
|
|
|
|
- (void)setIcon:(MwLLPixmap)pixmap {
|
|
|
|
|
};
|
|
|
|
|
- (void)forceRender {
|
|
|
|
|
};
|
2026-03-03 23:24:28 -07:00
|
|
|
- (void)setCursor:(MwCursor *)image mask:(MwCursor *)mask {
|
2026-01-09 21:35:23 -07:00
|
|
|
};
|
2026-03-03 23:24:28 -07:00
|
|
|
- (void)detachWithPoint:(MwPoint *)point {
|
2026-01-09 21:35:23 -07:00
|
|
|
};
|
|
|
|
|
- (void)show:(int)show {
|
|
|
|
|
};
|
|
|
|
|
- (void)makePopupWithParent:(MwLL)parent {
|
|
|
|
|
};
|
|
|
|
|
- (void)setSizeHintsWithMinX:(int)minx
|
2026-03-03 23:24:28 -07:00
|
|
|
MinY:(int)miny
|
|
|
|
|
MaxX:(int)maxx
|
|
|
|
|
MaxY:(int)maxy {
|
2026-01-09 21:35:23 -07:00
|
|
|
};
|
|
|
|
|
- (void)makeBorderless:(int)toggle {
|
2026-03-03 23:24:28 -07:00
|
|
|
MwU32 mask = [self->window styleMask];
|
|
|
|
|
if (mask & NSBorderlessWindowMask) {
|
|
|
|
|
mask ^= NSBorderlessWindowMask;
|
|
|
|
|
mask |= NSTitledWindowMask;
|
|
|
|
|
} else {
|
|
|
|
|
mask |= NSBorderlessWindowMask;
|
|
|
|
|
mask ^= NSTitledWindowMask;
|
|
|
|
|
}
|
|
|
|
|
[self->window initWithContentRect:self->rect
|
|
|
|
|
styleMask:mask
|
|
|
|
|
backing:NSBackingStoreBuffered
|
|
|
|
|
defer:NO];
|
2026-01-09 21:35:23 -07:00
|
|
|
};
|
|
|
|
|
- (void)focus {
|
2026-03-03 23:24:28 -07:00
|
|
|
[self->window makeMainWindow];
|
2026-01-09 21:35:23 -07:00
|
|
|
};
|
|
|
|
|
- (void)grabPointer:(int)toggle {
|
2026-03-03 23:24:28 -07:00
|
|
|
/* MacOS didn't have a "pointer grab" function until 10.13.2 so I need to do
|
|
|
|
|
* this manually */
|
2026-01-09 21:35:23 -07:00
|
|
|
};
|
2026-03-03 23:24:28 -07:00
|
|
|
- (void)setClipboard:(const char *)text {
|
2026-01-09 21:35:23 -07:00
|
|
|
};
|
|
|
|
|
- (void)getClipboard {
|
|
|
|
|
};
|
|
|
|
|
- (void)makeToolWindow {
|
|
|
|
|
};
|
2026-03-03 23:24:28 -07:00
|
|
|
- (void)getCursorCoord:(MwPoint *)point {
|
|
|
|
|
NSPoint p = [NSEvent mouseLocation];
|
|
|
|
|
point->x = p.x;
|
|
|
|
|
point->y = p.y;
|
2026-01-09 21:35:23 -07:00
|
|
|
};
|
2026-03-03 23:24:28 -07:00
|
|
|
- (void)getScreenSize:(MwRect *)_rect {
|
|
|
|
|
NSScreen *screen = [self->window screen];
|
|
|
|
|
_rect->x = [screen frame].origin.x;
|
|
|
|
|
_rect->y = [screen frame].origin.y;
|
|
|
|
|
_rect->width = [screen frame].size.width;
|
|
|
|
|
_rect->height = [screen frame].size.height;
|
2026-01-09 21:35:23 -07:00
|
|
|
};
|
|
|
|
|
- (void)destroy {
|
2026-03-03 23:24:28 -07:00
|
|
|
[self->window dealloc];
|
2026-01-09 21:35:23 -07:00
|
|
|
}
|
2026-01-14 17:13:12 -07:00
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
@implementation MilskoCocoaView
|
|
|
|
|
- (id)initWithFrame:(NSRect)frame {
|
2026-03-03 23:24:28 -07:00
|
|
|
self = [super initWithFrame:frame];
|
|
|
|
|
self->width = frame.size.width;
|
|
|
|
|
self->height = frame.size.height;
|
|
|
|
|
self->buf = malloc(self->width * self->height * 4);
|
|
|
|
|
self->space = CGColorSpaceCreateDeviceRGB();
|
|
|
|
|
|
|
|
|
|
if (width == 0 || height == 0) {
|
|
|
|
|
self->rep = NULL;
|
|
|
|
|
self->context = NULL;
|
|
|
|
|
} else {
|
|
|
|
|
self->rep =
|
|
|
|
|
[[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL
|
|
|
|
|
pixelsWide:width
|
|
|
|
|
pixelsHigh:height
|
|
|
|
|
bitsPerSample:8
|
|
|
|
|
samplesPerPixel:4
|
|
|
|
|
hasAlpha:YES
|
|
|
|
|
isPlanar:NO
|
|
|
|
|
colorSpaceName:NSDeviceRGBColorSpace
|
|
|
|
|
bytesPerRow:width * 4
|
|
|
|
|
bitsPerPixel:32];
|
|
|
|
|
assert(self->rep);
|
|
|
|
|
|
|
|
|
|
self->context =
|
|
|
|
|
[NSGraphicsContext graphicsContextWithBitmapImageRep:self->rep];
|
|
|
|
|
assert(self->context);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (NSGraphicsContext *)context {
|
|
|
|
|
return self->context;
|
2026-01-14 17:13:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)drawRect:(NSRect)dirtyRect {
|
2026-03-03 23:24:28 -07:00
|
|
|
[super drawRect:dirtyRect];
|
|
|
|
|
if (!self->rep) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
[self->rep drawInRect:NSMakeRect(0, 0, self->width, self->height)];
|
2026-01-14 17:13:12 -07:00
|
|
|
|
2026-03-03 23:24:28 -07:00
|
|
|
unsigned char *pixels = [self->rep bitmapData];
|
2026-01-14 17:13:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)destroy {
|
2026-03-03 23:24:28 -07:00
|
|
|
free(self->buf);
|
|
|
|
|
CGColorSpaceRelease(self->space);
|
2026-01-14 17:13:12 -07:00
|
|
|
}
|
|
|
|
|
|
2026-01-09 21:35:23 -07:00
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
static MwLL MwLLCreateImpl(MwLL parent, int x, int y, int width, int height) {
|
2026-03-03 23:24:28 -07:00
|
|
|
MwLL r;
|
|
|
|
|
(void)x;
|
|
|
|
|
(void)y;
|
|
|
|
|
(void)width;
|
|
|
|
|
(void)height;
|
2026-01-09 21:35:23 -07:00
|
|
|
|
2026-03-03 23:24:28 -07:00
|
|
|
r = malloc(sizeof(*r));
|
2026-01-09 21:35:23 -07:00
|
|
|
|
2026-03-03 23:24:28 -07:00
|
|
|
MwLLCreateCommon(r);
|
2026-01-09 21:35:23 -07:00
|
|
|
|
2026-03-03 23:24:28 -07:00
|
|
|
MilskoCocoa *o =
|
|
|
|
|
[MilskoCocoa newWithParent:parent x:x y:y width:width height:height];
|
|
|
|
|
r->cocoa.real = o;
|
2026-01-09 21:35:23 -07:00
|
|
|
|
2026-03-03 23:24:28 -07:00
|
|
|
return r;
|
2026-01-09 21:35:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void MwLLDestroyImpl(MwLL handle) {
|
2026-03-03 23:24:28 -07:00
|
|
|
MilskoCocoa *h = handle->cocoa.real;
|
2026-01-09 21:35:23 -07:00
|
|
|
|
2026-03-03 23:24:28 -07:00
|
|
|
[h destroy];
|
2026-01-09 21:35:23 -07:00
|
|
|
|
2026-03-03 23:24:28 -07:00
|
|
|
MwLLDestroyCommon(handle);
|
2026-01-09 21:35:23 -07:00
|
|
|
|
2026-03-03 23:24:28 -07:00
|
|
|
free(handle);
|
2026-01-09 21:35:23 -07:00
|
|
|
}
|
|
|
|
|
|
2026-03-03 23:24:28 -07:00
|
|
|
static void MwLLBeginDrawImpl(MwLL handle) { (void)handle; }
|
2026-01-09 21:35:23 -07:00
|
|
|
|
2026-03-03 23:24:28 -07:00
|
|
|
static void MwLLEndDrawImpl(MwLL handle) { (void)handle; }
|
2026-01-09 21:35:23 -07:00
|
|
|
|
2026-03-03 23:24:28 -07:00
|
|
|
static void MwLLPolygonImpl(MwLL handle, MwPoint *points, int points_count,
|
|
|
|
|
MwLLColor color) {
|
|
|
|
|
MilskoCocoa *h = handle->cocoa.real;
|
|
|
|
|
[h polygonWithPoints:points points_count:points_count color:color];
|
2026-01-09 21:35:23 -07:00
|
|
|
}
|
|
|
|
|
|
2026-03-03 23:24:28 -07:00
|
|
|
static void MwLLLineImpl(MwLL handle, MwPoint *points, MwLLColor color) {
|
|
|
|
|
MilskoCocoa *h = handle->cocoa.real;
|
|
|
|
|
[h lineWithPoints:points color:color];
|
2026-01-09 21:35:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static MwLLColor MwLLAllocColorImpl(MwLL handle, int r, int g, int b) {
|
2026-03-03 23:24:28 -07:00
|
|
|
MwLLColor c = malloc(sizeof(*c));
|
|
|
|
|
MwLLColorUpdate(handle, c, r, g, b);
|
|
|
|
|
return c;
|
2026-01-09 21:35:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void MwLLColorUpdateImpl(MwLL handle, MwLLColor c, int r, int g, int b) {
|
2026-03-03 23:24:28 -07:00
|
|
|
(void)handle;
|
2026-01-09 21:35:23 -07:00
|
|
|
|
2026-03-03 23:24:28 -07:00
|
|
|
c->common.red = r;
|
|
|
|
|
c->common.green = g;
|
|
|
|
|
c->common.blue = b;
|
2026-01-09 21:35:23 -07:00
|
|
|
}
|
|
|
|
|
|
2026-03-03 23:24:28 -07:00
|
|
|
static void MwLLGetXYWHImpl(MwLL handle, int *x, int *y, unsigned int *w,
|
|
|
|
|
unsigned int *height) {
|
|
|
|
|
MilskoCocoa *h = handle->cocoa.real;
|
|
|
|
|
[h getX:x Y:y W:w H:height];
|
2026-01-09 21:35:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void MwLLSetXYImpl(MwLL handle, int x, int y) {
|
2026-03-03 23:24:28 -07:00
|
|
|
MilskoCocoa *h = handle->cocoa.real;
|
|
|
|
|
[h setX:x Y:y];
|
2026-01-09 21:35:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void MwLLSetWHImpl(MwLL handle, int w, int height) {
|
2026-03-03 23:24:28 -07:00
|
|
|
MilskoCocoa *h = handle->cocoa.real;
|
|
|
|
|
[h setW:w H:height];
|
2026-01-09 21:35:23 -07:00
|
|
|
}
|
|
|
|
|
|
2026-03-03 23:24:28 -07:00
|
|
|
static void MwLLFreeColorImpl(MwLLColor color) { free(color); }
|
2026-01-09 21:35:23 -07:00
|
|
|
|
|
|
|
|
static int MwLLPendingImpl(MwLL handle) {
|
2026-03-03 23:24:28 -07:00
|
|
|
MilskoCocoa *h = handle->cocoa.real;
|
|
|
|
|
if ([h pending]) {
|
|
|
|
|
MwLLDispatch(handle, draw, NULL);
|
|
|
|
|
return 1;
|
|
|
|
|
};
|
2026-01-09 21:35:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void MwLLNextEventImpl(MwLL handle) {
|
|
|
|
|
|
2026-03-03 23:24:28 -07:00
|
|
|
MilskoCocoa *h = handle->cocoa.real;
|
|
|
|
|
[h getNextEvent];
|
2026-01-09 21:35:23 -07:00
|
|
|
}
|
|
|
|
|
|
2026-03-03 23:24:28 -07:00
|
|
|
static void MwLLSetTitleImpl(MwLL handle, const char *title) {
|
|
|
|
|
MilskoCocoa *h = handle->cocoa.real;
|
|
|
|
|
[h setTitle:title];
|
2026-01-09 21:35:23 -07:00
|
|
|
}
|
|
|
|
|
|
2026-03-03 23:24:28 -07:00
|
|
|
static MwLLPixmap MwLLCreatePixmapImpl(MwLL handle, unsigned char *data,
|
|
|
|
|
int width, int height) {
|
|
|
|
|
(void)handle;
|
2026-01-09 21:35:23 -07:00
|
|
|
|
2026-03-03 23:24:28 -07:00
|
|
|
MwLLPixmap r = malloc(sizeof(*r));
|
2026-01-09 21:35:23 -07:00
|
|
|
|
2026-03-03 23:24:28 -07:00
|
|
|
r->common.raw = malloc(4 * width * height);
|
|
|
|
|
memcpy(r->common.raw, data, 4 * width * height);
|
2026-01-09 21:35:23 -07:00
|
|
|
|
2026-03-03 23:24:28 -07:00
|
|
|
r->common.width = width;
|
|
|
|
|
r->common.height = height;
|
2026-01-09 21:35:23 -07:00
|
|
|
|
2026-03-03 23:24:28 -07:00
|
|
|
r->cocoa.real = [MilskoCocoaPixmap newWithWidth:width height:height];
|
2026-01-12 13:04:30 -07:00
|
|
|
|
2026-03-03 23:24:28 -07:00
|
|
|
MwLLPixmapUpdate(r);
|
|
|
|
|
return r;
|
2026-01-09 21:35:23 -07:00
|
|
|
}
|
|
|
|
|
|
2026-01-12 13:04:30 -07:00
|
|
|
static void MwLLPixmapUpdateImpl(MwLLPixmap pixmap) {
|
2026-03-03 23:24:28 -07:00
|
|
|
MilskoCocoaPixmap *p = pixmap->cocoa.real;
|
|
|
|
|
[p updateWithData:pixmap->common.raw];
|
2026-01-12 13:04:30 -07:00
|
|
|
}
|
2026-01-09 21:35:23 -07:00
|
|
|
|
2026-01-12 13:04:30 -07:00
|
|
|
static void MwLLDestroyPixmapImpl(MwLLPixmap pixmap) {
|
2026-03-03 23:24:28 -07:00
|
|
|
MilskoCocoaPixmap *p = pixmap->cocoa.real;
|
|
|
|
|
[p destroy];
|
|
|
|
|
free(pixmap);
|
2026-01-12 13:04:30 -07:00
|
|
|
}
|
2026-01-09 21:35:23 -07:00
|
|
|
|
2026-03-03 23:24:28 -07:00
|
|
|
static void MwLLDrawPixmapImpl(MwLL handle, MwRect *rect, MwLLPixmap pixmap) {
|
|
|
|
|
MilskoCocoa *h = handle->cocoa.real;
|
|
|
|
|
[h drawPixmap:pixmap rect:rect];
|
|
|
|
|
MwLLForceRender(handle);
|
2026-01-09 21:35:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void MwLLSetIconImpl(MwLL handle, MwLLPixmap pixmap) {
|
2026-03-03 23:24:28 -07:00
|
|
|
MilskoCocoa *h = handle->cocoa.real;
|
|
|
|
|
[h setIcon:pixmap];
|
2026-01-09 21:35:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void MwLLForceRenderImpl(MwLL handle) {
|
2026-03-03 23:24:28 -07:00
|
|
|
MilskoCocoa *h = handle->cocoa.real;
|
|
|
|
|
[h forceRender];
|
2026-01-09 21:35:23 -07:00
|
|
|
}
|
|
|
|
|
|
2026-03-03 23:24:28 -07:00
|
|
|
static void MwLLSetCursorImpl(MwLL handle, MwCursor *image, MwCursor *mask) {
|
|
|
|
|
MilskoCocoa *h = handle->cocoa.real;
|
|
|
|
|
[h setCursor:image mask:mask];
|
2026-01-09 21:35:23 -07:00
|
|
|
}
|
|
|
|
|
|
2026-03-03 23:24:28 -07:00
|
|
|
static void MwLLDetachImpl(MwLL handle, MwPoint *point) {
|
|
|
|
|
MilskoCocoa *h = handle->cocoa.real;
|
|
|
|
|
[h detachWithPoint:point];
|
2026-01-09 21:35:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void MwLLShowImpl(MwLL handle, int show) {
|
2026-03-03 23:24:28 -07:00
|
|
|
MilskoCocoa *h = handle->cocoa.real;
|
|
|
|
|
[h show:show];
|
2026-01-09 21:35:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void MwLLMakePopupImpl(MwLL handle, MwLL parent) {
|
2026-03-03 23:24:28 -07:00
|
|
|
MilskoCocoa *h = handle->cocoa.real;
|
|
|
|
|
[h makePopupWithParent:parent];
|
2026-01-09 21:35:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void MwLLSetSizeHintsImpl(MwLL handle, int minx, int miny, int maxx,
|
2026-03-03 23:24:28 -07:00
|
|
|
int maxy) {
|
|
|
|
|
MilskoCocoa *h = handle->cocoa.real;
|
|
|
|
|
[h setSizeHintsWithMinX:minx MinY:miny MaxX:maxx MaxY:maxy];
|
2026-01-09 21:35:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void MwLLMakeBorderlessImpl(MwLL handle, int toggle) {
|
2026-03-03 23:24:28 -07:00
|
|
|
MilskoCocoa *h = handle->cocoa.real;
|
|
|
|
|
[h makeBorderless:toggle];
|
2026-01-09 21:35:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void MwLLFocusImpl(MwLL handle) {
|
2026-03-03 23:24:28 -07:00
|
|
|
MilskoCocoa *h = handle->cocoa.real;
|
|
|
|
|
[h focus];
|
2026-01-09 21:35:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void MwLLGrabPointerImpl(MwLL handle, int toggle) {
|
2026-03-03 23:24:28 -07:00
|
|
|
MilskoCocoa *h = handle->cocoa.real;
|
|
|
|
|
[h grabPointer:toggle];
|
2026-01-09 21:35:23 -07:00
|
|
|
}
|
|
|
|
|
|
2026-03-03 23:24:28 -07:00
|
|
|
static void MwLLSetClipboardImpl(MwLL handle, const char *text) {
|
|
|
|
|
MilskoCocoa *h = handle->cocoa.real;
|
|
|
|
|
[h setClipboard:text];
|
2026-01-09 21:35:23 -07:00
|
|
|
}
|
|
|
|
|
|
2026-03-03 23:24:28 -07:00
|
|
|
static void MwLLGetClipboardImpl(MwLL handle) { (void)handle; }
|
2026-01-09 21:35:23 -07:00
|
|
|
|
|
|
|
|
static void MwLLMakeToolWindowImpl(MwLL handle) {
|
|
|
|
|
|
2026-03-03 23:24:28 -07:00
|
|
|
MilskoCocoa *h = handle->cocoa.real;
|
|
|
|
|
[h makeToolWindow];
|
2026-01-09 21:35:23 -07:00
|
|
|
}
|
|
|
|
|
|
2026-03-03 23:24:28 -07:00
|
|
|
static void MwLLGetCursorCoordImpl(MwLL handle, MwPoint *point) {
|
|
|
|
|
MilskoCocoa *h = handle->cocoa.real;
|
|
|
|
|
[h getCursorCoord:point];
|
2026-01-09 21:35:23 -07:00
|
|
|
}
|
|
|
|
|
|
2026-03-03 23:24:28 -07:00
|
|
|
static void MwLLGetScreenSizeImpl(MwLL handle, MwRect *rect) {
|
|
|
|
|
MilskoCocoa *h = handle->cocoa.real;
|
|
|
|
|
[h getScreenSize:rect];
|
2026-01-09 21:35:23 -07:00
|
|
|
}
|
|
|
|
|
|
2026-03-03 23:24:28 -07:00
|
|
|
static void MwLLBeginStateChangeImpl(MwLL handle) { MwLLShow(handle, 0); }
|
2026-01-09 21:35:23 -07:00
|
|
|
|
2026-03-03 23:24:28 -07:00
|
|
|
static void MwLLEndStateChangeImpl(MwLL handle) { MwLLShow(handle, 1); }
|
2026-01-09 21:35:23 -07:00
|
|
|
|
2026-03-03 23:24:28 -07:00
|
|
|
static int MwLLCocoaCallInitImpl(void) { return 0; }
|
2026-01-09 21:35:23 -07:00
|
|
|
|
|
|
|
|
#include "call.c"
|
|
|
|
|
CALL(Cocoa);
|