Compare commits
2 commits
e2f34df4e3
...
04f1a94cb5
| Author | SHA1 | Date | |
|---|---|---|---|
| 04f1a94cb5 | |||
| a710967115 |
3 changed files with 199 additions and 78 deletions
|
|
@ -6,6 +6,7 @@
|
||||||
#ifndef __MW_LOWLEVEL_H__
|
#ifndef __MW_LOWLEVEL_H__
|
||||||
#define __MW_LOWLEVEL_H__
|
#define __MW_LOWLEVEL_H__
|
||||||
|
|
||||||
|
#include "Mw/BaseTypes.h"
|
||||||
#include <Mw/MachDep.h>
|
#include <Mw/MachDep.h>
|
||||||
|
|
||||||
typedef struct _MwLLHandler* MwLLHandler;
|
typedef struct _MwLLHandler* MwLLHandler;
|
||||||
|
|
@ -40,9 +41,9 @@ struct _MwLLCommon {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _MwLLCommonColor {
|
struct _MwLLCommonColor {
|
||||||
int red;
|
MwU8 red;
|
||||||
int green;
|
MwU8 green;
|
||||||
int blue;
|
MwU8 blue;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _MwLLCommonPixmap {
|
struct _MwLLCommonPixmap {
|
||||||
|
|
|
||||||
|
|
@ -10,11 +10,100 @@
|
||||||
#include <Mw/MachDep.h>
|
#include <Mw/MachDep.h>
|
||||||
#include <Mw/TypeDefs.h>
|
#include <Mw/TypeDefs.h>
|
||||||
|
|
||||||
|
#ifdef __OBJC__
|
||||||
|
|
||||||
|
#import <Foundation/NSGeometry.h>
|
||||||
|
#import <AppKit/AppKit.h>
|
||||||
|
#import <Foundation/Foundation.h>
|
||||||
|
|
||||||
|
#ifdef __APPLE__
|
||||||
|
#import <CoreServices/CoreServices.h>
|
||||||
|
#else
|
||||||
|
#import <CoreGraphics/CoreGraphics.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
@interface MilskoCocoaPixmap : NSObject {
|
||||||
|
int width;
|
||||||
|
int height;
|
||||||
|
NSData* data;
|
||||||
|
NSImage* image;
|
||||||
|
}
|
||||||
|
|
||||||
|
+ (MilskoCocoaPixmap*)newWithWidth:(int)width height:(int)height;
|
||||||
|
- (void)updateWithData:(void*)data;
|
||||||
|
- (void)destroy;
|
||||||
|
|
||||||
|
/* using @property to create instance variables fucks up 10.4 gcc for some reason? */
|
||||||
|
- (NSImage*)image;
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
@interface MilskoCocoaView : NSView {
|
||||||
|
CGContextRef cg;
|
||||||
|
CGColorSpaceRef space;
|
||||||
|
CGDataProviderRef provider;
|
||||||
|
MwU32* buf;
|
||||||
|
float width;
|
||||||
|
float height;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (CGContextRef)context;
|
||||||
|
@end
|
||||||
|
|
||||||
|
@interface MilskoCocoa : NSObject {
|
||||||
|
NSApplication* application;
|
||||||
|
NSWindow* window;
|
||||||
|
NSRect rect;
|
||||||
|
MilskoCocoaView* view;
|
||||||
|
}
|
||||||
|
|
||||||
|
+ (MilskoCocoa*)newWithParent:(MwLL)parent
|
||||||
|
x:(int)x
|
||||||
|
y:(int)y
|
||||||
|
width:(int)width
|
||||||
|
height:(int)height;
|
||||||
|
- (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)setX:(int)x Y:(int)y;
|
||||||
|
- (void)setW:(int)w H:(int)h;
|
||||||
|
- (int)pending;
|
||||||
|
- (void)getNextEvent;
|
||||||
|
- (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)show:(int)show;
|
||||||
|
- (void)makePopupWithParent:(MwLL)parent;
|
||||||
|
- (void)setSizeHintsWithMinX:(int)minx
|
||||||
|
MinY:(int)miny
|
||||||
|
MaxX:(int)maxx
|
||||||
|
MaxY:(int)maxy;
|
||||||
|
- (void)makeBorderless:(int)toggle;
|
||||||
|
- (void)focus;
|
||||||
|
- (void)grabPointer:(int)toggle;
|
||||||
|
- (void)setClipboard:(const char*)text;
|
||||||
|
- (void)makeToolWindow;
|
||||||
|
- (void)getCursorCoord:(MwPoint*)point;
|
||||||
|
- (void)getScreenSize:(MwRect*)rect;
|
||||||
|
- (void)destroy;
|
||||||
|
|
||||||
|
@end
|
||||||
|
#define OBJC(x) x
|
||||||
|
#else
|
||||||
|
#define OBJC(x) void*
|
||||||
|
#endif
|
||||||
|
|
||||||
MWDECL int MwLLCocoaCallInit(void);
|
MWDECL int MwLLCocoaCallInit(void);
|
||||||
|
|
||||||
struct _MwLLCocoa {
|
struct _MwLLCocoa {
|
||||||
struct _MwLLCommon common;
|
struct _MwLLCommon common;
|
||||||
void* real;
|
OBJC(MilskoCocoa*)
|
||||||
|
real;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _MwLLCocoaColor {
|
struct _MwLLCocoaColor {
|
||||||
|
|
@ -23,7 +112,8 @@ struct _MwLLCocoaColor {
|
||||||
|
|
||||||
struct _MwLLCocoaPixmap {
|
struct _MwLLCocoaPixmap {
|
||||||
struct _MwLLCommonPixmap common;
|
struct _MwLLCommonPixmap common;
|
||||||
void* real;
|
OBJC(MilskoCocoaPixmap*)
|
||||||
|
real;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -1,86 +1,41 @@
|
||||||
#ifndef USE_COCOA
|
#include <AppKit/NSGraphicsContext.h>
|
||||||
#define USE_COCOA
|
|
||||||
#include <Foundation/NSGeometry.h>
|
|
||||||
#include <Foundation/NSObjCRuntime.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#import <AppKit/AppKit.h>
|
|
||||||
#import <AppKit/NSEvent.h>
|
|
||||||
#import <Foundation/Foundation.h>
|
|
||||||
|
|
||||||
#include <Mw/Milsko.h>
|
#include <Mw/Milsko.h>
|
||||||
|
#include <assert.h>
|
||||||
|
#include <limits.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
#include "../../external/stb_ds.h"
|
#include "../../external/stb_ds.h"
|
||||||
|
#include "Mw/BaseTypes.h"
|
||||||
@interface MilskoCocoaPixmap : NSObject {
|
|
||||||
NSImage* image;
|
|
||||||
}
|
|
||||||
+ (MilskoCocoaPixmap*)newWithWidth:(int)width height:(int)height;
|
|
||||||
- (void)updateWithData:(void*)data;
|
|
||||||
- (void)destroy;
|
|
||||||
@end
|
|
||||||
|
|
||||||
@implementation MilskoCocoaPixmap
|
@implementation MilskoCocoaPixmap
|
||||||
|
|
||||||
+ (MilskoCocoaPixmap*)newWithWidth:(int)width height:(int)height {
|
+ (MilskoCocoaPixmap*)newWithWidth:(int)width height:(int)height {
|
||||||
MilskoCocoaPixmap* p = [MilskoCocoaPixmap alloc];
|
MilskoCocoaPixmap* p = [MilskoCocoaPixmap alloc];
|
||||||
NSSize sz;
|
|
||||||
|
|
||||||
sz.width = width;
|
p->width = width;
|
||||||
sz.height = height;
|
p->height = height;
|
||||||
|
p->data = NULL;
|
||||||
p->image = [[NSImage alloc] initWithSize:sz];
|
p->image = NULL;
|
||||||
|
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
- (void)updateWithData:(void*)data {
|
- (void)updateWithData:(void*)_data {
|
||||||
|
[self destroy];
|
||||||
|
|
||||||
|
self->data = [NSData dataWithBytes:_data length:self->width * self->height * 4];
|
||||||
|
self->image = [[NSImage alloc] initWithData:self->data];
|
||||||
}
|
}
|
||||||
- (void)destroy {
|
- (void)destroy {
|
||||||
[self->image dealloc];
|
if(self->data != NULL) {
|
||||||
|
[self->data dealloc];
|
||||||
|
}
|
||||||
|
if(self->image != NULL) {
|
||||||
|
[self->image dealloc];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@end
|
- (NSImage*)image {
|
||||||
|
return self->image;
|
||||||
@interface MilskoCocoa : NSObject {
|
|
||||||
NSApplication* application;
|
|
||||||
NSWindow* window;
|
|
||||||
NSRect rect;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (MilskoCocoa*)newWithParent:(MwLL)parent
|
|
||||||
x:(int)x
|
|
||||||
y:(int)y
|
|
||||||
width:(int)width
|
|
||||||
height:(int)height;
|
|
||||||
- (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)setX:(int)x Y:(int)y;
|
|
||||||
- (void)setW:(int)w H:(int)h;
|
|
||||||
- (int)pending;
|
|
||||||
- (void)getNextEvent;
|
|
||||||
- (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)show:(int)show;
|
|
||||||
- (void)makePopupWithParent:(MwLL)parent;
|
|
||||||
- (void)setSizeHintsWithMinX:(int)minx
|
|
||||||
MinY:(int)miny
|
|
||||||
MaxX:(int)maxx
|
|
||||||
MaxY:(int)maxy;
|
|
||||||
- (void)makeBorderless:(int)toggle;
|
|
||||||
- (void)focus;
|
|
||||||
- (void)grabPointer:(int)toggle;
|
|
||||||
- (void)setClipboard:(const char*)text;
|
|
||||||
- (void)makeToolWindow;
|
|
||||||
- (void)getCursorCoord:(MwPoint*)point;
|
|
||||||
- (void)getScreenSize:(MwRect*)rect;
|
|
||||||
- (void)destroy;
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation MilskoCocoa
|
@implementation MilskoCocoa
|
||||||
|
|
@ -119,13 +74,32 @@
|
||||||
if(parent != NULL) {
|
if(parent != NULL) {
|
||||||
MilskoCocoa* p = parent->cocoa.real;
|
MilskoCocoa* p = parent->cocoa.real;
|
||||||
[p->window addChildWindow:c->window ordered:NSWindowAbove];
|
[p->window addChildWindow:c->window ordered:NSWindowAbove];
|
||||||
|
} else {
|
||||||
|
[c->application activateIgnoringOtherApps:true];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
c->view = [[MilskoCocoaView alloc] initWithFrame:c->rect];
|
||||||
|
[c->window setContentView:c->view];
|
||||||
|
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
- (void)polygonWithPoints:(MwPoint*)points
|
- (void)polygonWithPoints:(MwPoint*)points
|
||||||
points_count:(int)points_count
|
points_count:(int)points_count
|
||||||
color:(MwLLColor)color {
|
color:(MwLLColor)color {
|
||||||
|
int i;
|
||||||
|
CGContextRef cg = [self->view context];
|
||||||
|
|
||||||
|
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 setNeedsDisplay:true];
|
||||||
};
|
};
|
||||||
- (void)lineWithPoints:(MwPoint*)points color:(MwLLColor)color {
|
- (void)lineWithPoints:(MwPoint*)points color:(MwLLColor)color {
|
||||||
};
|
};
|
||||||
|
|
@ -156,15 +130,22 @@
|
||||||
return 1;
|
return 1;
|
||||||
};
|
};
|
||||||
- (void)getNextEvent {
|
- (void)getNextEvent {
|
||||||
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
|
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
|
||||||
NSEvent* event = [self->application nextEventMatchingMask:NSAnyEventMask
|
|
||||||
untilDate:nil
|
NSEvent* event = [self->application nextEventMatchingMask:NSAnyEventMask
|
||||||
inMode:NSDefaultRunLoopMode
|
untilDate:nil
|
||||||
dequeue:YES];
|
inMode:NSDefaultRunLoopMode
|
||||||
|
dequeue:YES];
|
||||||
|
|
||||||
if(event != nil) {
|
if(event != nil) {
|
||||||
printf("got event: %p\n", event);
|
printf("got event: %p\n", event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[self->application sendEvent:event];
|
||||||
|
|
||||||
|
/* this should be in the draw functions but it's here for now for testing */
|
||||||
|
[self->view setNeedsDisplay:true];
|
||||||
|
|
||||||
[pool release];
|
[pool release];
|
||||||
};
|
};
|
||||||
- (void)setTitle:(const char*)title {
|
- (void)setTitle:(const char*)title {
|
||||||
|
|
@ -173,7 +154,9 @@
|
||||||
setTitleWithRepresentedFilename:[NSString stringWithUTF8String:title]];
|
setTitleWithRepresentedFilename:[NSString stringWithUTF8String:title]];
|
||||||
[pool release];
|
[pool release];
|
||||||
};
|
};
|
||||||
- (void)drawPixmap:(MwLLPixmap)pixmap rect:(MwRect*)rect {
|
- (void)drawPixmap:(MwLLPixmap)pixmap rect:(MwRect*)_rect {
|
||||||
|
MilskoCocoaPixmap* p = pixmap->cocoa.real;
|
||||||
|
[[p image] drawAtPoint:NSMakePoint(_rect->x, _rect->y) fromRect:NSMakeRect(_rect->x, _rect->y, _rect->width, _rect->height) operation:NSCompositeClear fraction:1.0];
|
||||||
};
|
};
|
||||||
- (void)setIcon:(MwLLPixmap)pixmap {
|
- (void)setIcon:(MwLLPixmap)pixmap {
|
||||||
};
|
};
|
||||||
|
|
@ -234,6 +217,53 @@
|
||||||
- (void)destroy {
|
- (void)destroy {
|
||||||
[self->window dealloc];
|
[self->window dealloc];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
@implementation MilskoCocoaView
|
||||||
|
- (id)initWithFrame:(NSRect)frame {
|
||||||
|
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();
|
||||||
|
self->cg = CGBitmapContextCreate(self->buf,
|
||||||
|
self->width,
|
||||||
|
self->height,
|
||||||
|
CHAR_BIT,
|
||||||
|
self->width * sizeof(uint32_t),
|
||||||
|
self->space, kCGBitmapByteOrder32Host | kCGImageAlphaPremultipliedLast);
|
||||||
|
assert(self->cg);
|
||||||
|
printf("%p\n", self->cg);
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (CGContextRef)context {
|
||||||
|
return self->cg;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)drawRect:(NSRect)dirtyRect {
|
||||||
|
[super drawRect:dirtyRect];
|
||||||
|
if(self) {
|
||||||
|
|
||||||
|
CGImageRef img = CGBitmapContextCreateImage(self->cg);
|
||||||
|
if(!img) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
printf("printed image\n");
|
||||||
|
|
||||||
|
CGContextDrawImage([[NSGraphicsContext currentContext] graphicsPort], CGRectMake(0, 0, self->width, self->height), img);
|
||||||
|
CGImageRelease(img);
|
||||||
|
}
|
||||||
|
// printf("%0.2f %0.2f %0.2f %0.2f\n", dirtyRect.origin.x, dirtyRect.origin.y, dirtyRect.size.width, dirtyRect.size.height);
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)destroy {
|
||||||
|
free(self->buf);
|
||||||
|
CGContextRelease(self->cg);
|
||||||
|
CGColorSpaceRelease(self->space);
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
static MwLL MwLLCreateImpl(MwLL parent, int x, int y, int width, int height) {
|
static MwLL MwLLCreateImpl(MwLL parent, int x, int y, int width, int height) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue