-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCTLabel.extern.c
More file actions
87 lines (79 loc) · 3.16 KB
/
CTLabel.extern.c
File metadata and controls
87 lines (79 loc) · 3.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include "CTLabel.extern.h"
#import <Cocoa/Cocoa.h>
Int initLabel_CTLabel(World w, Int dummy) {
__block NSTextField *textField;
dispatch_sync(dispatch_get_main_queue(), ^{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
textField = [[NSTextField alloc] initWithFrame:NSMakeRect(10, 10, 200, 17)];
[textField setStringValue:@"defaultLabelString"];
[textField setBezeled:NO];
[textField setDrawsBackground:YES];
[textField setEditable:NO];
[textField setSelectable:NO];
[pool drain];
});
return (Int)textField;
}
TUP0 labelSetTextColor_CTLabel(Int cocoaRef, Color_CocoaDef color, Int dummy) {
float r = color->r_CocoaDef/255.0;
float g = color->g_CocoaDef/255.0;
float b = color->b_CocoaDef/255.0;
dispatch_async(dispatch_get_main_queue(), ^{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSTextField *thisLabel = (NSTextField*) cocoaRef;
NSColor *color = [NSColor colorWithCalibratedRed:r green:g blue:b alpha:1.0];
[thisLabel setTextColor:color];
[thisLabel setNeedsDisplay];
[pool drain];
});
}
TUP0 labelSetText_CTLabel(Int cocoaRef, LIST str, Int dummy) {
char* buf = listToChars(str);
dispatch_async(dispatch_get_main_queue(), ^{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSTextField *thisLabel = (NSTextField*) cocoaRef;
[thisLabel setStringValue:[NSString stringWithFormat:@"%s", buf]];
[thisLabel setNeedsDisplay];
[pool drain];
free(buf);
});
}
TUP0 labelSetSize_CTLabel(Int cocoaRef, Size_CocoaDef size, Int dummy) {
int width = size->width_CocoaDef;
int height = size->height_CocoaDef;
dispatch_async(dispatch_get_main_queue(), ^{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSTextField *thisLabel = (NSTextField*) cocoaRef;
NSSize size0 = NSMakeSize(width,height);
[thisLabel setFrameSize: size0];
[pool drain];
});
}
TUP0 labelSetPosition_CTLabel(Int cocoaRef, Position_CocoaDef pos, Int dummy) {
int x = pos->x_CocoaDef;
int y = pos->y_CocoaDef;
dispatch_async(dispatch_get_main_queue(), ^{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSTextField *thisLabel = (NSTextField*) cocoaRef;
NSPoint p = NSMakePoint(x,y);
[thisLabel setFrameOrigin: p];
[thisLabel setNeedsDisplay];
[pool drain];
});
}
TUP0 labelSetBackgroundColor_CTLabel(Int cocoaRef, Color_CocoaDef color, Float a, Int dummy) {
float r = color->r_CocoaDef/255.0;
float g = color->g_CocoaDef/255.0;
float b = color->b_CocoaDef/255.0;
dispatch_async(dispatch_get_main_queue(), ^{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSTextField *thisLabel = (NSTextField*) cocoaRef;
NSColor *color = [NSColor colorWithCalibratedRed:r green:g blue:b alpha:a];
[thisLabel setBackgroundColor: color];
[thisLabel setNeedsDisplay];
[pool drain];
});
}
void _init_external_CTLabel(void) {
// Do nothing
}