|
@ -25,6 +25,26 @@ GLViewFunctionality simple_draw(std::function<void()> f){ |
|
|
@property GLViewFunctionality functionality; |
|
|
@property GLViewFunctionality functionality; |
|
|
@end |
|
|
@end |
|
|
|
|
|
|
|
|
|
|
|
@interface MySlider : NSSlider |
|
|
|
|
|
- (instancetype) initWithFrame:(NSRect)frame; |
|
|
|
|
|
- (void)action:(MySlider*)sender; |
|
|
|
|
|
@property std::function<void(CGFloat)> callback; |
|
|
|
|
|
@end |
|
|
|
|
|
|
|
|
|
|
|
@implementation MySlider |
|
|
|
|
|
- (instancetype) initWithFrame:(NSRect)frame{ |
|
|
|
|
|
if(self = [super initWithFrame: frame]){ |
|
|
|
|
|
self.target = self; |
|
|
|
|
|
self.action = @selector(action:); |
|
|
|
|
|
} |
|
|
|
|
|
return self; |
|
|
|
|
|
} |
|
|
|
|
|
- (void)action:(MySlider*)sender{ |
|
|
|
|
|
if(self.callback){ |
|
|
|
|
|
self.callback(sender.doubleValue); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
@end |
|
|
|
|
|
|
|
|
struct NSAppWrapperImpl { |
|
|
struct NSAppWrapperImpl { |
|
|
NSAppWrapperImpl() { |
|
|
NSAppWrapperImpl() { |
|
@ -53,7 +73,15 @@ struct NSAppWrapperImpl { |
|
|
defer:YES]; |
|
|
defer:YES]; |
|
|
window.title = appName; |
|
|
window.title = appName; |
|
|
window.collectionBehavior |= NSWindowCollectionBehaviorFullScreenPrimary; |
|
|
window.collectionBehavior |= NSWindowCollectionBehaviorFullScreenPrimary; |
|
|
|
|
|
if(windows.empty()){ |
|
|
[window center]; |
|
|
[window center]; |
|
|
|
|
|
} else { |
|
|
|
|
|
NSWindow * previous_window = windows.back(); |
|
|
|
|
|
NSPoint top_right = previous_window.frame.origin; |
|
|
|
|
|
top_right.x += previous_window.frame.size.width; |
|
|
|
|
|
top_right.y += previous_window.frame.size.height; |
|
|
|
|
|
[window setFrameTopLeftPoint: top_right]; |
|
|
|
|
|
} |
|
|
[window makeKeyAndOrderFront:nil]; |
|
|
[window makeKeyAndOrderFront:nil]; |
|
|
|
|
|
|
|
|
NSRect frame = [window contentRectForFrameRect:window.frame]; |
|
|
NSRect frame = [window contentRectForFrameRect:window.frame]; |
|
@ -63,7 +91,52 @@ struct NSAppWrapperImpl { |
|
|
view.functionality = f; |
|
|
view.functionality = f; |
|
|
|
|
|
|
|
|
window.contentView = view; |
|
|
window.contentView = view; |
|
|
|
|
|
windows.push_back(window); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void create_window(ControlFunctionality const & f) { |
|
|
|
|
|
const CGFloat width = 200; |
|
|
|
|
|
NSWindow * window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, width, 500) |
|
|
|
|
|
styleMask:NSTitledWindowMask | NSResizableWindowMask | NSMiniaturizableWindowMask |
|
|
|
|
|
backing:NSBackingStoreBuffered |
|
|
|
|
|
defer:YES]; |
|
|
|
|
|
window.title = appName; |
|
|
|
|
|
if(windows.empty()){ |
|
|
|
|
|
[window center]; |
|
|
|
|
|
} else { |
|
|
|
|
|
NSWindow * previous_window = windows.back(); |
|
|
|
|
|
NSPoint top_right = previous_window.frame.origin; |
|
|
|
|
|
top_right.x += previous_window.frame.size.width; |
|
|
|
|
|
top_right.y += previous_window.frame.size.height; |
|
|
|
|
|
[window setFrameTopLeftPoint: top_right]; |
|
|
|
|
|
} |
|
|
|
|
|
[window makeKeyAndOrderFront:nil]; |
|
|
|
|
|
|
|
|
|
|
|
NSRect frame = [window contentRectForFrameRect:window.frame]; |
|
|
|
|
|
frame.origin = {0, 0}; |
|
|
|
|
|
NSView * view = [[NSView alloc] initWithFrame:frame]; |
|
|
|
|
|
|
|
|
|
|
|
CGFloat y = 0; |
|
|
|
|
|
CGFloat h = 20; |
|
|
|
|
|
CGFloat padding = 8; |
|
|
|
|
|
for(auto&& c : f.sliders){ |
|
|
|
|
|
NSTextField * label = [[NSTextField alloc] initWithFrame:{padding, y+padding, 20, h}]; |
|
|
|
|
|
label.editable = NO; |
|
|
|
|
|
label.bezeled = NO; |
|
|
|
|
|
label.drawsBackground = NO; |
|
|
|
|
|
label.stringValue = [NSString stringWithUTF8String: c.name.c_str()]; |
|
|
|
|
|
[view addSubview: label]; |
|
|
|
|
|
|
|
|
|
|
|
MySlider * slider = [[MySlider alloc] initWithFrame:{20+padding, y+padding, width-20-2*padding, h}]; |
|
|
|
|
|
slider.minValue = c.min; |
|
|
|
|
|
slider.maxValue = c.max; |
|
|
|
|
|
slider.doubleValue = c.start; |
|
|
|
|
|
slider.callback = c.callback; |
|
|
|
|
|
[view addSubview: slider]; |
|
|
|
|
|
y += h; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
window.contentView = view; |
|
|
windows.push_back(window); |
|
|
windows.push_back(window); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -91,6 +164,10 @@ void NSAppWrapper::create_window(GLViewFunctionality const & f){ |
|
|
impl->create_window(f); |
|
|
impl->create_window(f); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void NSAppWrapper::create_window(ControlFunctionality const & f){ |
|
|
|
|
|
impl->create_window(f); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* |
|
|
/* |
|
@ -129,7 +206,7 @@ void NSAppWrapper::create_window(GLViewFunctionality const & f){ |
|
|
[[self openGLContext] setValues:&swapInt forParameter:NSOpenGLCPSwapInterval]; |
|
|
[[self openGLContext] setValues:&swapInt forParameter:NSOpenGLCPSwapInterval]; |
|
|
|
|
|
|
|
|
if(functionality.initialize_callback){ |
|
|
if(functionality.initialize_callback){ |
|
|
functionality.initialize_callback({*context}); |
|
|
functionality.initialize_callback({*context, nullptr, nullptr}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Create a display link capable of being used with all active displays |
|
|
// Create a display link capable of being used with all active displays |
|
@ -167,7 +244,7 @@ void NSAppWrapper::create_window(GLViewFunctionality const & f){ |
|
|
NSRect viewRectPixels = [self convertRectToBacking:self.bounds]; |
|
|
NSRect viewRectPixels = [self convertRectToBacking:self.bounds]; |
|
|
|
|
|
|
|
|
if(functionality.resize_callback){ |
|
|
if(functionality.resize_callback){ |
|
|
functionality.resize_callback({*context}, viewRectPixels.size.width, viewRectPixels.size.height); |
|
|
functionality.resize_callback({*context, nullptr, nullptr}, viewRectPixels.size.width, viewRectPixels.size.height); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
context->unlock(); |
|
|
context->unlock(); |
|
@ -200,15 +277,18 @@ void NSAppWrapper::create_window(GLViewFunctionality const & f){ |
|
|
context->lock(); |
|
|
context->lock(); |
|
|
|
|
|
|
|
|
NSRect viewRectPixels = [self convertRectToBacking:self.bounds]; |
|
|
NSRect viewRectPixels = [self convertRectToBacking:self.bounds]; |
|
|
|
|
|
auto& ctx = context->ctx; |
|
|
|
|
|
|
|
|
|
|
|
if(functionality.draw_callback){ |
|
|
|
|
|
functionality.draw_callback({*context, [viewRectPixels]{ |
|
|
glBindFramebuffer(GL_FRAMEBUFFER, 0); |
|
|
glBindFramebuffer(GL_FRAMEBUFFER, 0); |
|
|
glViewport(0, 0, (int)viewRectPixels.size.width, (int)viewRectPixels.size.height); |
|
|
glViewport(0, 0, (int)viewRectPixels.size.width, (int)viewRectPixels.size.height); |
|
|
|
|
|
}, [&ctx]{ |
|
|
if(functionality.draw_callback){ |
|
|
CGLFlushDrawable(ctx); |
|
|
functionality.draw_callback({*context}); |
|
|
} |
|
|
|
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
CGLFlushDrawable(context->ctx); |
|
|
|
|
|
context->unlock(); |
|
|
context->unlock(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|