-
-
Save thbwd/e1de669d112567ed95e79498b25a61c6 to your computer and use it in GitHub Desktop.
Emojicocoa
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Emojicocoa.h | |
// Emojicocoa | |
// | |
// Created by Theo Weidmann on 22.02.20. | |
// Copyright Β© 2020 Theo Weidmann. All rights reserved. | |
// | |
#import <Cocoa/Cocoa.h> | |
#include <emojicode/runtime/Runtime.h> | |
@interface AppDelegate : NSObject<NSApplicationDelegate> { | |
runtime::Callable<void> _ready; | |
} | |
- (id) initWithReady:(runtime::Callable<void>)ready; | |
- (void) applicationDidFinishLaunching:(NSNotification *)notification; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Emojicocoa.m | |
// Emojicocoa | |
// | |
// Created by Theo Weidmann on 22.02.20. | |
// Copyright Β© 2020 Theo Weidmann. All rights reserved. | |
// | |
#import "Emojicocoa.hpp" | |
#include <emojicode/s/String.h> | |
@implementation AppDelegate | |
- (id) initWithReady:(runtime::Callable<void>)ready { | |
self = [super init]; | |
_ready = ready; | |
return self; | |
} | |
- (void) applicationDidFinishLaunching:(NSNotification *)notification { | |
_ready(); | |
} | |
@end | |
template <typename T> | |
class CocoaWrapper : public runtime::Object<CocoaWrapper<T>> { | |
public: | |
CocoaWrapper(T *value) { | |
value_ = value; | |
} | |
T* get() const { return value_; } | |
private: | |
T *value_; | |
}; | |
@interface ControlHandler : NSObject { | |
runtime::Callable<void> _callable; | |
} | |
- (id) initWithHandler:(runtime::Callable<void>)callable; | |
- (void) handle; | |
@end | |
@implementation ControlHandler | |
- (id)initWithHandler:(runtime::Callable<void>)callable { | |
self = [super init]; | |
_callable = callable; | |
_callable.retain(); | |
return self; | |
} | |
- (void)handle { | |
_callable(); | |
} | |
@end | |
extern "C" void startCocoa(void *object, runtime::Callable<void> ready) { | |
NSApplication *application = [NSApplication sharedApplication]; | |
[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular]; | |
[NSApp activateIgnoringOtherApps:YES]; | |
AppDelegate *applicationDelegate = [[AppDelegate alloc] initWithReady: ready]; | |
[application setDelegate:applicationDelegate]; | |
[application run]; | |
} | |
extern "C" CocoaWrapper<NSWindow>* createWindow() { | |
NSRect frame = NSMakeRect(0, 0, 200, 200); | |
NSWindow* window = [[NSWindow alloc] initWithContentRect:frame | |
styleMask:NSWindowStyleMaskResizable | NSWindowStyleMaskTitled | NSWindowStyleMaskMiniaturizable | |
backing:NSBackingStoreBuffered | |
defer:NO]; | |
[window makeKeyAndOrderFront:NSApp]; | |
return CocoaWrapper<NSWindow>::init(window); | |
} | |
extern "C" void addViewToWindow(CocoaWrapper<NSWindow> *window, CocoaWrapper<NSView> *view) { | |
[window->get().contentView addSubview:view->get()]; | |
} | |
NSString* nsstringFromString(s::String *string) { | |
return [[NSString alloc] initWithBytes:string->characters.get() length:string->count encoding:NSUTF8StringEncoding]; | |
} | |
extern "C" CocoaWrapper<NSButton>* createButton(s::String *label, runtime::Callable<void> handler) { | |
NSButton *button = [NSButton buttonWithTitle:nsstringFromString(label) | |
target:[[ControlHandler alloc] initWithHandler:handler] | |
action:@selector(handle)]; | |
return CocoaWrapper<NSButton>::init(button); | |
} | |
extern "C" CocoaWrapper<NSTextField>* createTextField() { | |
NSTextField *field = [[NSTextField textFieldWithString:@""] retain]; | |
field.frame = CGRectMake(100, 100, 100, 20); | |
return CocoaWrapper<NSTextField>::init(field); | |
} | |
extern "C" CocoaWrapper<NSProgressIndicator>* createProgressIndicator() { | |
NSProgressIndicator *pi = [[NSProgressIndicator alloc] initWithFrame:CGRectMake(200, 100, 100, 20)]; | |
pi.indeterminate = false; | |
pi.minValue = 0; | |
pi.maxValue = 1; | |
return CocoaWrapper<NSProgressIndicator>::init(pi); | |
} | |
extern "C" void setProgress(CocoaWrapper<NSProgressIndicator> *pi, runtime::Real pro) { | |
pi->get().doubleValue = pro; | |
} | |
extern "C" s::String* getTextTextField(CocoaWrapper<NSTextField> *field) { | |
return s::String::init([field->get().stringValue UTF8String]); | |
} | |
extern "C" void setTextTextField(CocoaWrapper<NSTextField> *field, s::String *s) { | |
return [field->get() setStringValue:nsstringFromString(s)]; | |
} | |
SET_INFO_FOR(CocoaWrapper<NSWindow>, emojicocoa, 1f499) | |
SET_INFO_FOR(CocoaWrapper<NSButton>, emojicocoa, 1f967) | |
SET_INFO_FOR(CocoaWrapper<NSTextField>, emojicocoa, 1f6f9) | |
SET_INFO_FOR(CocoaWrapper<NSProgressIndicator>, emojicocoa, 1f6e4) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
π¦ emojicocoa π | |
ππ | |
π π€bonjourπ€βοΈ | |
ππ«π | |
π π€let's rockπ€βοΈ | |
ππβοΈ β‘οΈ window | |
ππΉβοΈ β‘οΈ field | |
ππ€βοΈ β‘οΈ progress | |
π window ππ₯§ π€Helloπ€ πππ₯‘ | |
π‘ field π€π§²π°ππ»βοΈπ§²π€βοΈ | |
π― progress 0.5βοΈ | |
πβοΈβοΈ | |
π window fieldβοΈ | |
π window progressβοΈ | |
πβοΈ | |
π |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
π π π« π | |
π ready ππ π» π€startCocoaπ€ | |
π | |
π π» π π π | |
π π» π€createWindowπ€ | |
βοΈπ view π π» π€addViewToWindowπ€ | |
π | |
π π» π π π | |
π | |
π π» π π₯§ π π | |
π label π‘ ππ₯‘ handler ππ π» π€createButtonπ€ | |
π | |
π π» π π€ π π | |
π π» π€createProgressIndicatorπ€ | |
βοΈ π― value π― π» π€setProgressπ€ | |
π | |
π π» π πΉ π π | |
π π» π€createTextFieldπ€ | |
β π‘ β‘οΈ π‘ π» π€getTextTextFieldπ€ | |
βοΈ π‘ text π‘ π» π€setTextTextFieldπ€ | |
π | |
π π€m -framework Foundation -framework Cocoaπ€ π |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment