This commit is contained in:
IoIxD 2026-04-13 16:09:28 -07:00
commit 14e908488c
2 changed files with 57 additions and 33 deletions

View file

@ -104,7 +104,11 @@
- (void)destroy; - (void)destroy;
- (NSBitmapImageRep*)getRep; - (NSBitmapImageRep*)getRep;
- (void)setChild; - (void)setChild;
- (void)drawRectSub:(NSRect)dirtyRect;
@end
@interface MilskoCocoaSubView : MilskoCocoaView {
}
@end @end
@interface MilskoCocoa : NSObject { @interface MilskoCocoa : NSObject {
@ -125,6 +129,8 @@
MwBool pointerLocked; MwBool pointerLocked;
MwBool mouseMoved; MwBool mouseMoved;
MwBool rejectFirstTest;
} }
+ (MilskoCocoa*)newWithParent:(MwLL)parent + (MilskoCocoa*)newWithParent:(MwLL)parent

View file

@ -116,8 +116,8 @@ static void recursive_dispatch_key_released(MwLL handle, int* k) {
- (void)destroy { - (void)destroy {
free(self->buf); free(self->buf);
[self->image removeRepresentation:self->rep]; [self->image removeRepresentation:self->rep];
[self->image dealloc]; [self->image release];
[self->rep dealloc]; [self->rep release];
self->image = NULL; self->image = NULL;
self->rep = NULL; self->rep = NULL;
} }
@ -135,6 +135,8 @@ static void recursive_dispatch_key_released(MwLL handle, int* k) {
height:(int)height height:(int)height
handle:(MwLL)r { handle:(MwLL)r {
MilskoCocoa* c = [MilskoCocoa alloc]; MilskoCocoa* c = [MilskoCocoa alloc];
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
[c retain]; [c retain];
/* /*
@ -156,7 +158,6 @@ static void recursive_dispatch_key_released(MwLL handle, int* k) {
c->window = [[MilskoCocoaWindow alloc] c->window = [[MilskoCocoaWindow alloc]
initWithContentRect:rectFlip(c->rect) initWithContentRect:rectFlip(c->rect)
styleMask:(NSTitledWindowMask | styleMask:(NSTitledWindowMask |
NSTexturedBackgroundWindowMask |
NSClosableWindowMask | NSMiniaturizableWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask |
NSResizableWindowMask) NSResizableWindowMask)
backing:NSBackingStoreBuffered backing:NSBackingStoreBuffered
@ -190,15 +191,12 @@ static void recursive_dispatch_key_released(MwLL handle, int* k) {
NSRect rect = localRectFlip(c->rect, p->view); NSRect rect = localRectFlip(c->rect, p->view);
c->view = [[MilskoCocoaView alloc] initWithFrame:rect]; c->view = [[MilskoCocoaView alloc] initWithFrame:rect];
[c->view setBounds:c->rect]; [c->view setBounds:c->rect];
[c->view retain]; [c->view retain];
[c->view setNeedsDisplay:TRUE];
[c->view setChild]; [c->view setChild];
[c->view addTrackingRect:c->rect owner:c->view userData:NULL assumeInside:MwFALSE]; [c->view addTrackingRect:c->rect owner:c->view userData:NULL assumeInside:MwFALSE];
[p->view addSubview:c->view]; [p->view addSubview:c->view];
[p->window setContentView:p->view];
} }
[c->window setAcceptsMouseMovedEvents:MwTRUE]; [c->window setAcceptsMouseMovedEvents:MwTRUE];
@ -219,6 +217,7 @@ static void recursive_dispatch_key_released(MwLL handle, int* k) {
c->pointerLocked = MwFALSE; c->pointerLocked = MwFALSE;
[pool release];
return c; return c;
} }
@ -331,7 +330,8 @@ static void recursive_dispatch_key_released(MwLL handle, int* k) {
frame = localRectFlip(frame, parent->cocoa.real->view); frame = localRectFlip(frame, parent->cocoa.real->view);
[self->view setBounds:frame]; [self->view setBounds:frame];
} }
self->_eventsPending = MwTRUE; // [self->view setNeedsDisplay:true];
[self nudge];
}; };
- (void)setW:(int)w H:(int)h { - (void)setW:(int)w H:(int)h {
NSRect frame = [self->window frame]; NSRect frame = [self->window frame];
@ -346,7 +346,7 @@ static void recursive_dispatch_key_released(MwLL handle, int* k) {
} else { } else {
[self->window setFrame:frame display:YES animate:false]; [self->window setFrame:frame display:YES animate:false];
} }
self->_eventsPending = MwTRUE; [self nudge];
}; };
- (int)pending { - (int)pending {
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
@ -360,12 +360,12 @@ static void recursive_dispatch_key_released(MwLL handle, int* k) {
MwLL h = [self->handle pointer]; MwLL h = [self->handle pointer];
if(_forceRender) { if(_forceRender) {
MwLLDispatch(h, draw, NULL); MwLLDispatch(h, draw, NULL);
[self->view setNeedsDisplay:true]; // [self->view setNeedsDisplay:true];
_forceRender = MwFALSE; _forceRender = MwFALSE;
} }
if(_eventsPending) { if(_eventsPending) {
MwLLDispatch(h, draw, NULL); MwLLDispatch(h, draw, NULL);
[self->view setNeedsDisplay:true]; // [self->view setNeedsDisplay:true];
_eventsPending = MwFALSE; _eventsPending = MwFALSE;
} }
[self sendClipboardEvent]; [self sendClipboardEvent];
@ -579,9 +579,7 @@ static void recursive_dispatch_key_released(MwLL handle, int* k) {
}; };
- (void)destroy { - (void)destroy {
[self->handle release]; [self->handle release];
[self->handle dealloc];
[self->window release]; [self->window release];
[self->window dealloc];
} }
- (MwLL)getParent { - (MwLL)getParent {
@ -596,7 +594,13 @@ static void recursive_dispatch_key_released(MwLL handle, int* k) {
} }
- (void)nudge { - (void)nudge {
MwLL p = self->parent;
self->_eventsPending = MwTRUE; self->_eventsPending = MwTRUE;
if(p) {
[p->cocoa.real->view setNeedsDisplay:true];
p = p->cocoa.real->parent;
}
} }
- (void)pushCursor { - (void)pushCursor {
@ -662,14 +666,9 @@ static void recursive_dispatch_key_released(MwLL handle, int* k) {
- (void)drawRect:(NSRect)dirtyRect { - (void)drawRect:(NSRect)dirtyRect {
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
NSSize sz = [self->rep size];
MwLL ll = [((MilskoFakePointer*)[[[[self window] contentView] subviews]
objectAtIndex:0]) pointer];
NSRect bounds;
NSArray* subviews = [self subviews]; NSArray* subviews = [self subviews];
int i; int i;
[super drawRect:dirtyRect];
if(!self->rep) { if(!self->rep) {
if(dirtyRect.size.width && dirtyRect.size.height) { if(dirtyRect.size.width && dirtyRect.size.height) {
[self initRepAndContextWithWidth:dirtyRect.size.width [self initRepAndContextWithWidth:dirtyRect.size.width
@ -682,22 +681,41 @@ static void recursive_dispatch_key_released(MwLL handle, int* k) {
} }
} }
// MwLLDispatch(ll, draw, NULL); if(!_child)
[self->rep drawInRect:[self bounds]];
[self->rep drawInRect:dirtyRect];
for(i = 0; i < [subviews count]; i++) { for(i = 0; i < [subviews count]; i++) {
NSView* subview = [subviews objectAtIndex:i]; MilskoCocoaView* subview = [subviews objectAtIndex:i];
bounds = [subview bounds]; NSRect bounds = [subview bounds];
[subview drawRect:bounds]; if([subview respondsToSelector:@selector(drawRectSub:)]) {
[subview drawRectSub:bounds];
}
} }
[self->rep bitmapData];
[pool release]; [pool release];
} }
- (void)drawRectSub:(NSRect)dirtyRect {
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
if(!self->rep) {
if(dirtyRect.size.width && dirtyRect.size.height) {
[self initRepAndContextWithWidth:dirtyRect.size.width
Height:dirtyRect.size.height];
self->width = dirtyRect.size.width;
self->height = dirtyRect.size.height;
} else {
[pool release];
return;
}
}
[self->rep drawInRect:dirtyRect];
[pool release];
};
- (void)initRepAndContextWithWidth:(float)w Height:(float)h { - (void)initRepAndContextWithWidth:(float)w Height:(float)h {
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
self->rep = self->rep =
[[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL
pixelsWide:w pixelsWide:w
@ -712,10 +730,14 @@ static void recursive_dispatch_key_released(MwLL handle, int* k) {
assert(self->rep); assert(self->rep);
[self->rep retain]; [self->rep retain];
[self->rep setOpaque:MwFALSE];
[self->rep setAlpha:MwTRUE];
self->context = self->context =
[NSGraphicsContext graphicsContextWithBitmapImageRep:self->rep]; [NSGraphicsContext graphicsContextWithBitmapImageRep:self->rep];
assert(self->context); assert(self->context);
[self->context retain]; [self->context retain];
[pool release];
} }
- (void)destroy { - (void)destroy {
@ -1142,11 +1164,7 @@ static void MwLLFreeColorImpl(MwLLColor color) {
} }
static int MwLLPendingImpl(MwLL handle) { static int MwLLPendingImpl(MwLL handle) {
int p = [handle->cocoa.real pending]; return [handle->cocoa.real pending];
if(p) {
MwLLDispatch(handle, draw, NULL);
}
return p;
} }
static void MwLLNextEventImpl(MwLL handle) { static void MwLLNextEventImpl(MwLL handle) {
@ -1186,7 +1204,7 @@ static void MwLLPixmapUpdateImpl(MwLLPixmap pixmap) {
static void MwLLDestroyPixmapImpl(MwLLPixmap pixmap) { static void MwLLDestroyPixmapImpl(MwLLPixmap pixmap) {
MilskoCocoaPixmap* p = pixmap->cocoa.real; MilskoCocoaPixmap* p = pixmap->cocoa.real;
[p destroy]; [p destroy];
[p dealloc]; [p release];
free(pixmap); free(pixmap);
} }