public
Description: A lean-and-mean Ruby/ObjC bridge
Homepage: http://rubyobjc.com
Clone URL: git://github.com/timburks/rubyobjc.git
rubyobjc / test / teststructs.m
100644 69 lines (55 sloc) 1.701 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
/*
* teststructs.m
*
* Copyright (c) 2007 Tim Burks, Neon Design Technology, Inc.
* For more information about this file, visit http://www.rubyobjc.com.
*/
 
#import <Foundation/Foundation.h>
 
@interface StructTester : NSObject
{
}
@end
 
@interface StructTester(Ruby)
- (NSSize) rubyScaleSize:(NSSize) size by:(float)scale;
- (NSPoint) rubyScalePoint:(NSPoint) size by:(float)scale;
- (NSRect) rubyScaleRect:(NSRect) size by:(float)scale;
- (NSRange) rubyScaleRange:(NSRange) size by:(float)scale;
@end
 
@implementation StructTester
 
- (NSSize) scaleSize:(NSSize)size by:(float)scale
{
    return [self rubyScaleSize:size by:scale];
}
 
- (NSPoint) scalePoint:(NSPoint)point by:(float)scale
{
    return [self rubyScalePoint:point by:scale];
}
 
- (NSRect) scaleRect:(NSRect)rect by:(float)scale
{
    NSRect returnValue = [self rubyScaleRect:rect by:scale];
//  NSLog(@"scaleRect got %f %f %f %f from rubyScaleRect", returnValue.origin.x, returnValue.origin.y, returnValue.size.width, returnValue.size.height);
  return returnValue;
}
 
- (NSRange) scaleRange:(NSRange)range by:(float)scale
{
    return [self rubyScaleRange:range by:scale];
}
 
@end
 
// C functions that we call from Ruby with an ObjC::Function wrapper
NSSize scaleSize(NSSize size, float scale)
{
    NSSize newsize;
    newsize.width = size.width * scale;
    newsize.height = size.height * scale;
    return newsize;
}
 
NSRect scaleRect(NSRect rect, float scale)
{
    NSRect newrect;
    newrect.origin.x = rect.origin.x * scale;
    newrect.origin.y = rect.origin.y * scale;
    newrect.size.width = rect.size.width * scale;
    newrect.size.height = rect.size.height * scale;
    return newrect;
}
 
 
void Init_teststructs() {}