Browse Source

Basic functionality recreated with dynamically blended graphics from sprite dump

Thomas Buck 8 years ago
parent
commit
62678ba3aa
43 changed files with 357 additions and 39 deletions
  1. 6
    0
      OtaClock.xcodeproj/project.pbxproj
  2. 10
    19
      OtaClock/Images.xcassets/AppIcon.appiconset/Contents.json
  3. BIN
      OtaClock/Images.xcassets/AppIcon.appiconset/icon.png
  4. BIN
      OtaClock/Images.xcassets/AppIcon.appiconset/icon_1024.png
  5. BIN
      OtaClock/Images.xcassets/AppIcon.appiconset/icon_128.png
  6. BIN
      OtaClock/Images.xcassets/AppIcon.appiconset/icon_16.png
  7. BIN
      OtaClock/Images.xcassets/AppIcon.appiconset/icon_256-1.png
  8. BIN
      OtaClock/Images.xcassets/AppIcon.appiconset/icon_256.png
  9. BIN
      OtaClock/Images.xcassets/AppIcon.appiconset/icon_32-1.png
  10. BIN
      OtaClock/Images.xcassets/AppIcon.appiconset/icon_32.png
  11. BIN
      OtaClock/Images.xcassets/AppIcon.appiconset/icon_512-1.png
  12. BIN
      OtaClock/Images.xcassets/AppIcon.appiconset/icon_512.png
  13. BIN
      OtaClock/Images.xcassets/AppIcon.appiconset/icon_64.png
  14. BIN
      OtaClock/Images.xcassets/Menu.imageset/menu16.png
  15. BIN
      OtaClock/Images.xcassets/Menu.imageset/menu32.png
  16. 2
    3
      OtaClock/Images.xcassets/alarm.imageset/Contents.json
  17. BIN
      OtaClock/Images.xcassets/alarm.imageset/alarm.png
  18. 21
    0
      OtaClock/Images.xcassets/bubble.imageset/Contents.json
  19. BIN
      OtaClock/Images.xcassets/bubble.imageset/bubble.png
  20. 21
    0
      OtaClock/Images.xcassets/eyes_0.imageset/Contents.json
  21. BIN
      OtaClock/Images.xcassets/eyes_0.imageset/eyes_0.png
  22. 21
    0
      OtaClock/Images.xcassets/eyes_1.imageset/Contents.json
  23. BIN
      OtaClock/Images.xcassets/eyes_1.imageset/eyes_1.png
  24. 21
    0
      OtaClock/Images.xcassets/eyes_2.imageset/Contents.json
  25. BIN
      OtaClock/Images.xcassets/eyes_2.imageset/eyes_2.png
  26. 21
    0
      OtaClock/Images.xcassets/eyes_3.imageset/Contents.json
  27. BIN
      OtaClock/Images.xcassets/eyes_3.imageset/eyes_3.png
  28. 21
    0
      OtaClock/Images.xcassets/eyes_4.imageset/Contents.json
  29. BIN
      OtaClock/Images.xcassets/eyes_4.imageset/eyes_4.png
  30. 21
    0
      OtaClock/Images.xcassets/font_days.imageset/Contents.json
  31. BIN
      OtaClock/Images.xcassets/font_days.imageset/font_days.png
  32. 21
    0
      OtaClock/Images.xcassets/font_large.imageset/Contents.json
  33. BIN
      OtaClock/Images.xcassets/font_large.imageset/font_large.png
  34. 21
    0
      OtaClock/Images.xcassets/font_small.imageset/Contents.json
  35. BIN
      OtaClock/Images.xcassets/font_small.imageset/font_small.png
  36. 1
    2
      OtaClock/Images.xcassets/otacon.imageset/Contents.json
  37. BIN
      OtaClock/Images.xcassets/otacon.imageset/otacon.png
  38. BIN
      OtaClock/Images.xcassets/otacon.imageset/otacon2.png
  39. 1
    1
      OtaClock/Info.plist
  40. 0
    2
      OtaClock/MainView.h
  41. 11
    12
      OtaClock/MainView.m
  42. 19
    0
      OtaClock/Render.h
  43. 118
    0
      OtaClock/Render.m

+ 6
- 0
OtaClock.xcodeproj/project.pbxproj View File

@@ -13,6 +13,7 @@
13 13
 		E92321D11B8128E700D79B33 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = E92321CF1B8128E700D79B33 /* MainMenu.xib */; };
14 14
 		E92321E81B8129FD00D79B33 /* MainView.m in Sources */ = {isa = PBXBuildFile; fileRef = E92321E71B8129FD00D79B33 /* MainView.m */; };
15 15
 		E92321EB1B812A1000D79B33 /* MainWindow.m in Sources */ = {isa = PBXBuildFile; fileRef = E92321EA1B812A1000D79B33 /* MainWindow.m */; };
16
+		E92321EF1B8202D300D79B33 /* Render.m in Sources */ = {isa = PBXBuildFile; fileRef = E92321EE1B8202D300D79B33 /* Render.m */; };
16 17
 /* End PBXBuildFile section */
17 18
 
18 19
 /* Begin PBXFileReference section */
@@ -27,6 +28,8 @@
27 28
 		E92321E71B8129FD00D79B33 /* MainView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MainView.m; sourceTree = "<group>"; };
28 29
 		E92321E91B812A1000D79B33 /* MainWindow.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MainWindow.h; sourceTree = "<group>"; };
29 30
 		E92321EA1B812A1000D79B33 /* MainWindow.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MainWindow.m; sourceTree = "<group>"; };
31
+		E92321ED1B8202D300D79B33 /* Render.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Render.h; sourceTree = "<group>"; };
32
+		E92321EE1B8202D300D79B33 /* Render.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Render.m; sourceTree = "<group>"; };
30 33
 /* End PBXFileReference section */
31 34
 
32 35
 /* Begin PBXFrameworksBuildPhase section */
@@ -65,6 +68,8 @@
65 68
 				E92321CF1B8128E700D79B33 /* MainMenu.xib */,
66 69
 				E92321E61B8129FD00D79B33 /* MainView.h */,
67 70
 				E92321E71B8129FD00D79B33 /* MainView.m */,
71
+				E92321ED1B8202D300D79B33 /* Render.h */,
72
+				E92321EE1B8202D300D79B33 /* Render.m */,
68 73
 				E92321E91B812A1000D79B33 /* MainWindow.h */,
69 74
 				E92321EA1B812A1000D79B33 /* MainWindow.m */,
70 75
 				E92321C61B8128E700D79B33 /* Supporting Files */,
@@ -171,6 +176,7 @@
171 176
 				E92321CC1B8128E700D79B33 /* main.m in Sources */,
172 177
 				E92321CA1B8128E700D79B33 /* AppDelegate.m in Sources */,
173 178
 				E92321E81B8129FD00D79B33 /* MainView.m in Sources */,
179
+				E92321EF1B8202D300D79B33 /* Render.m in Sources */,
174 180
 			);
175 181
 			runOnlyForDeploymentPostprocessing = 0;
176 182
 		};

+ 10
- 19
OtaClock/Images.xcassets/AppIcon.appiconset/Contents.json View File

@@ -3,61 +3,52 @@
3 3
     {
4 4
       "size" : "16x16",
5 5
       "idiom" : "mac",
6
-      "filename" : "icon_16.png",
6
+      "filename" : "icon.png",
7 7
       "scale" : "1x"
8 8
     },
9 9
     {
10
-      "size" : "16x16",
11 10
       "idiom" : "mac",
12
-      "filename" : "icon_32-1.png",
11
+      "size" : "16x16",
13 12
       "scale" : "2x"
14 13
     },
15 14
     {
16
-      "size" : "32x32",
17 15
       "idiom" : "mac",
18
-      "filename" : "icon_32.png",
16
+      "size" : "32x32",
19 17
       "scale" : "1x"
20 18
     },
21 19
     {
22
-      "size" : "32x32",
23 20
       "idiom" : "mac",
24
-      "filename" : "icon_64.png",
21
+      "size" : "32x32",
25 22
       "scale" : "2x"
26 23
     },
27 24
     {
28
-      "size" : "128x128",
29 25
       "idiom" : "mac",
30
-      "filename" : "icon_128.png",
26
+      "size" : "128x128",
31 27
       "scale" : "1x"
32 28
     },
33 29
     {
34
-      "size" : "128x128",
35 30
       "idiom" : "mac",
36
-      "filename" : "icon_256-1.png",
31
+      "size" : "128x128",
37 32
       "scale" : "2x"
38 33
     },
39 34
     {
40
-      "size" : "256x256",
41 35
       "idiom" : "mac",
42
-      "filename" : "icon_256.png",
36
+      "size" : "256x256",
43 37
       "scale" : "1x"
44 38
     },
45 39
     {
46
-      "size" : "256x256",
47 40
       "idiom" : "mac",
48
-      "filename" : "icon_512-1.png",
41
+      "size" : "256x256",
49 42
       "scale" : "2x"
50 43
     },
51 44
     {
52
-      "size" : "512x512",
53 45
       "idiom" : "mac",
54
-      "filename" : "icon_512.png",
46
+      "size" : "512x512",
55 47
       "scale" : "1x"
56 48
     },
57 49
     {
58
-      "size" : "512x512",
59 50
       "idiom" : "mac",
60
-      "filename" : "icon_1024.png",
51
+      "size" : "512x512",
61 52
       "scale" : "2x"
62 53
     }
63 54
   ],

BIN
OtaClock/Images.xcassets/AppIcon.appiconset/icon.png View File


BIN
OtaClock/Images.xcassets/AppIcon.appiconset/icon_1024.png View File


BIN
OtaClock/Images.xcassets/AppIcon.appiconset/icon_128.png View File


BIN
OtaClock/Images.xcassets/AppIcon.appiconset/icon_16.png View File


BIN
OtaClock/Images.xcassets/AppIcon.appiconset/icon_256-1.png View File


BIN
OtaClock/Images.xcassets/AppIcon.appiconset/icon_256.png View File


BIN
OtaClock/Images.xcassets/AppIcon.appiconset/icon_32-1.png View File


BIN
OtaClock/Images.xcassets/AppIcon.appiconset/icon_32.png View File


BIN
OtaClock/Images.xcassets/AppIcon.appiconset/icon_512-1.png View File


BIN
OtaClock/Images.xcassets/AppIcon.appiconset/icon_512.png View File


BIN
OtaClock/Images.xcassets/AppIcon.appiconset/icon_64.png View File


BIN
OtaClock/Images.xcassets/Menu.imageset/menu16.png View File


BIN
OtaClock/Images.xcassets/Menu.imageset/menu32.png View File


OtaClock/Images.xcassets/Menu.imageset/Contents.json → OtaClock/Images.xcassets/alarm.imageset/Contents.json View File

@@ -3,12 +3,11 @@
3 3
     {
4 4
       "idiom" : "universal",
5 5
       "scale" : "1x",
6
-      "filename" : "menu16.png"
6
+      "filename" : "alarm.png"
7 7
     },
8 8
     {
9 9
       "idiom" : "universal",
10
-      "scale" : "2x",
11
-      "filename" : "menu32.png"
10
+      "scale" : "2x"
12 11
     },
13 12
     {
14 13
       "idiom" : "universal",

BIN
OtaClock/Images.xcassets/alarm.imageset/alarm.png View File


+ 21
- 0
OtaClock/Images.xcassets/bubble.imageset/Contents.json View File

@@ -0,0 +1,21 @@
1
+{
2
+  "images" : [
3
+    {
4
+      "idiom" : "universal",
5
+      "scale" : "1x",
6
+      "filename" : "bubble.png"
7
+    },
8
+    {
9
+      "idiom" : "universal",
10
+      "scale" : "2x"
11
+    },
12
+    {
13
+      "idiom" : "universal",
14
+      "scale" : "3x"
15
+    }
16
+  ],
17
+  "info" : {
18
+    "version" : 1,
19
+    "author" : "xcode"
20
+  }
21
+}

BIN
OtaClock/Images.xcassets/bubble.imageset/bubble.png View File


+ 21
- 0
OtaClock/Images.xcassets/eyes_0.imageset/Contents.json View File

@@ -0,0 +1,21 @@
1
+{
2
+  "images" : [
3
+    {
4
+      "idiom" : "universal",
5
+      "scale" : "1x",
6
+      "filename" : "eyes_0.png"
7
+    },
8
+    {
9
+      "idiom" : "universal",
10
+      "scale" : "2x"
11
+    },
12
+    {
13
+      "idiom" : "universal",
14
+      "scale" : "3x"
15
+    }
16
+  ],
17
+  "info" : {
18
+    "version" : 1,
19
+    "author" : "xcode"
20
+  }
21
+}

BIN
OtaClock/Images.xcassets/eyes_0.imageset/eyes_0.png View File


+ 21
- 0
OtaClock/Images.xcassets/eyes_1.imageset/Contents.json View File

@@ -0,0 +1,21 @@
1
+{
2
+  "images" : [
3
+    {
4
+      "idiom" : "universal",
5
+      "scale" : "1x",
6
+      "filename" : "eyes_1.png"
7
+    },
8
+    {
9
+      "idiom" : "universal",
10
+      "scale" : "2x"
11
+    },
12
+    {
13
+      "idiom" : "universal",
14
+      "scale" : "3x"
15
+    }
16
+  ],
17
+  "info" : {
18
+    "version" : 1,
19
+    "author" : "xcode"
20
+  }
21
+}

BIN
OtaClock/Images.xcassets/eyes_1.imageset/eyes_1.png View File


+ 21
- 0
OtaClock/Images.xcassets/eyes_2.imageset/Contents.json View File

@@ -0,0 +1,21 @@
1
+{
2
+  "images" : [
3
+    {
4
+      "idiom" : "universal",
5
+      "scale" : "1x",
6
+      "filename" : "eyes_2.png"
7
+    },
8
+    {
9
+      "idiom" : "universal",
10
+      "scale" : "2x"
11
+    },
12
+    {
13
+      "idiom" : "universal",
14
+      "scale" : "3x"
15
+    }
16
+  ],
17
+  "info" : {
18
+    "version" : 1,
19
+    "author" : "xcode"
20
+  }
21
+}

BIN
OtaClock/Images.xcassets/eyes_2.imageset/eyes_2.png View File


+ 21
- 0
OtaClock/Images.xcassets/eyes_3.imageset/Contents.json View File

@@ -0,0 +1,21 @@
1
+{
2
+  "images" : [
3
+    {
4
+      "idiom" : "universal",
5
+      "scale" : "1x",
6
+      "filename" : "eyes_3.png"
7
+    },
8
+    {
9
+      "idiom" : "universal",
10
+      "scale" : "2x"
11
+    },
12
+    {
13
+      "idiom" : "universal",
14
+      "scale" : "3x"
15
+    }
16
+  ],
17
+  "info" : {
18
+    "version" : 1,
19
+    "author" : "xcode"
20
+  }
21
+}

BIN
OtaClock/Images.xcassets/eyes_3.imageset/eyes_3.png View File


+ 21
- 0
OtaClock/Images.xcassets/eyes_4.imageset/Contents.json View File

@@ -0,0 +1,21 @@
1
+{
2
+  "images" : [
3
+    {
4
+      "idiom" : "universal",
5
+      "scale" : "1x",
6
+      "filename" : "eyes_4.png"
7
+    },
8
+    {
9
+      "idiom" : "universal",
10
+      "scale" : "2x"
11
+    },
12
+    {
13
+      "idiom" : "universal",
14
+      "scale" : "3x"
15
+    }
16
+  ],
17
+  "info" : {
18
+    "version" : 1,
19
+    "author" : "xcode"
20
+  }
21
+}

BIN
OtaClock/Images.xcassets/eyes_4.imageset/eyes_4.png View File


+ 21
- 0
OtaClock/Images.xcassets/font_days.imageset/Contents.json View File

@@ -0,0 +1,21 @@
1
+{
2
+  "images" : [
3
+    {
4
+      "idiom" : "universal",
5
+      "scale" : "1x",
6
+      "filename" : "font_days.png"
7
+    },
8
+    {
9
+      "idiom" : "universal",
10
+      "scale" : "2x"
11
+    },
12
+    {
13
+      "idiom" : "universal",
14
+      "scale" : "3x"
15
+    }
16
+  ],
17
+  "info" : {
18
+    "version" : 1,
19
+    "author" : "xcode"
20
+  }
21
+}

BIN
OtaClock/Images.xcassets/font_days.imageset/font_days.png View File


+ 21
- 0
OtaClock/Images.xcassets/font_large.imageset/Contents.json View File

@@ -0,0 +1,21 @@
1
+{
2
+  "images" : [
3
+    {
4
+      "idiom" : "universal",
5
+      "scale" : "1x",
6
+      "filename" : "font_large.png"
7
+    },
8
+    {
9
+      "idiom" : "universal",
10
+      "scale" : "2x"
11
+    },
12
+    {
13
+      "idiom" : "universal",
14
+      "scale" : "3x"
15
+    }
16
+  ],
17
+  "info" : {
18
+    "version" : 1,
19
+    "author" : "xcode"
20
+  }
21
+}

BIN
OtaClock/Images.xcassets/font_large.imageset/font_large.png View File


+ 21
- 0
OtaClock/Images.xcassets/font_small.imageset/Contents.json View File

@@ -0,0 +1,21 @@
1
+{
2
+  "images" : [
3
+    {
4
+      "idiom" : "universal",
5
+      "scale" : "1x",
6
+      "filename" : "font_small.png"
7
+    },
8
+    {
9
+      "idiom" : "universal",
10
+      "scale" : "2x"
11
+    },
12
+    {
13
+      "idiom" : "universal",
14
+      "scale" : "3x"
15
+    }
16
+  ],
17
+  "info" : {
18
+    "version" : 1,
19
+    "author" : "xcode"
20
+  }
21
+}

BIN
OtaClock/Images.xcassets/font_small.imageset/font_small.png View File


+ 1
- 2
OtaClock/Images.xcassets/otacon.imageset/Contents.json View File

@@ -7,8 +7,7 @@
7 7
     },
8 8
     {
9 9
       "idiom" : "universal",
10
-      "scale" : "2x",
11
-      "filename" : "otacon2.png"
10
+      "scale" : "2x"
12 11
     },
13 12
     {
14 13
       "idiom" : "universal",

BIN
OtaClock/Images.xcassets/otacon.imageset/otacon.png View File


BIN
OtaClock/Images.xcassets/otacon.imageset/otacon2.png View File


+ 1
- 1
OtaClock/Info.plist View File

@@ -19,7 +19,7 @@
19 19
 	<key>CFBundleSignature</key>
20 20
 	<string>????</string>
21 21
 	<key>CFBundleVersion</key>
22
-	<string>52</string>
22
+	<string>107</string>
23 23
 	<key>LSApplicationCategoryType</key>
24 24
 	<string>public.app-category.utilities</string>
25 25
 	<key>LSMinimumSystemVersion</key>

+ 0
- 2
OtaClock/MainView.h View File

@@ -10,6 +10,4 @@
10 10
 
11 11
 @interface MainView : NSView
12 12
 
13
-@property (strong) NSImage *otaconImage;
14
-
15 13
 @end

+ 11
- 12
OtaClock/MainView.m View File

@@ -7,23 +7,22 @@
7 7
 //
8 8
 
9 9
 #import "MainWindow.h"
10
+#import "Render.h"
10 11
 #import "MainView.h"
11 12
 
12
-#define BASE_IMAGE_RESIZE_FACTOR 0.2
13
+@interface MainView ()
14
+
15
+@property (strong) Render *render;
16
+
17
+@end
13 18
 
14 19
 @implementation MainView
15 20
 
16
-@synthesize otaconImage;
21
+@synthesize render;
17 22
 
18 23
 -(void)awakeFromNib {
19
-    // Load background image
20
-    self.otaconImage = [NSImage imageNamed:@"Otacon"];
21
-    
22
-    // Set window to a useful default size
23
-    NSSize newSize = [otaconImage size];
24
-    newSize.width *= BASE_IMAGE_RESIZE_FACTOR;
25
-    newSize.height *= BASE_IMAGE_RESIZE_FACTOR;
26
-    [(MainWindow*)[self window] setDefaultBackgroundSize:newSize];
24
+    render = [[Render alloc] init];
25
+    [(MainWindow*)[self window] setDefaultBackgroundSize:[render baseSize]]; // Set window to a useful default size
27 26
 }
28 27
 
29 28
 -(void)drawRect:(NSRect)dirtyRect {
@@ -31,8 +30,8 @@
31 30
     [[NSColor clearColor] set];
32 31
     NSRectFill([self frame]);
33 32
     
34
-    // Draw main image into window bounds
35
-    [otaconImage drawInRect:[self bounds]];
33
+    [render drawWith:0]; // Should be done somewhere else!
34
+    [render drawInto:self]; // Draw composite image
36 35
 }
37 36
 
38 37
 -(BOOL)acceptsFirstMouse:(NSEvent *)theEvent {

+ 19
- 0
OtaClock/Render.h View File

@@ -0,0 +1,19 @@
1
+//
2
+//  Render.h
3
+//  OtaClock
4
+//
5
+//  Created by Thomas Buck on 17.08.15.
6
+//  Copyright (c) 2015 xythobuz. All rights reserved.
7
+//
8
+
9
+#import <Cocoa/Cocoa.h>
10
+
11
+@interface Render : NSObject
12
+
13
+- (id)init;
14
+- (NSSize)baseSize;
15
+
16
+- (void)drawWith:(NSInteger)eyeIndex;
17
+- (void)drawInto:(NSView *)view;
18
+
19
+@end

+ 118
- 0
OtaClock/Render.m View File

@@ -0,0 +1,118 @@
1
+//
2
+//  Render.m
3
+//  OtaClock
4
+//
5
+//  Created by Thomas Buck on 17.08.15.
6
+//  Copyright (c) 2015 xythobuz. All rights reserved.
7
+//
8
+
9
+#import "Render.h"
10
+
11
+#define FULL_IMAGE_WIDTH 86
12
+#define FULL_IMAGE_HEIGHT 80
13
+#define BUBBLE_Y_OFFSET 45
14
+#define OTACON_X_OFFSET 1
15
+#define EYE_X_OFFSET 60
16
+#define EYE_Y_OFFSET 45
17
+
18
+@interface Render ()
19
+
20
+@property (assign) CGImageRef otaconGraphic;
21
+@property (assign) CGImageRef bubbleGraphic;
22
+@property (assign) CGImageRef eye0, eye1, eye2, eye3, eye4;
23
+
24
+@property (assign) NSSize fullSize;
25
+@property (assign) CGContextRef drawContext;
26
+
27
+@end
28
+
29
+@implementation Render
30
+
31
+@synthesize otaconGraphic;
32
+@synthesize bubbleGraphic;
33
+@synthesize eye0, eye1, eye2, eye3, eye4;
34
+
35
+@synthesize fullSize;
36
+@synthesize drawContext;
37
+
38
+- (CGImageRef)eyeHelper:(NSInteger)index {
39
+    if (index == 0) return eye0;
40
+    if (index == 1) return eye1;
41
+    if (index == 2) return eye2;
42
+    if (index == 3) return eye3;
43
+    if (index == 4) return eye4;
44
+    
45
+    NSLog(@"Render:eyeHelper:%ld unknown index!", (long)index);
46
+    return eye0;
47
+}
48
+
49
+- (id)init {
50
+    self = [super init];
51
+    if (self == nil) return nil;
52
+    
53
+    NSImage *otaconImage = [NSImage imageNamed:@"otacon"];
54
+    NSImage *bubbleImage = [NSImage imageNamed:@"bubble"];
55
+    NSImage *eye0Image = [NSImage imageNamed:@"eyes_0"];
56
+    NSImage *eye1Image = [NSImage imageNamed:@"eyes_1"];
57
+    NSImage *eye2Image = [NSImage imageNamed:@"eyes_2"];
58
+    NSImage *eye3Image = [NSImage imageNamed:@"eyes_3"];
59
+    NSImage *eye4Image = [NSImage imageNamed:@"eyes_4"];
60
+    
61
+    NSGraphicsContext *context = [NSGraphicsContext graphicsContextWithAttributes:nil];
62
+    
63
+    otaconGraphic = [otaconImage CGImageForProposedRect:nil context:context hints:nil];
64
+    bubbleGraphic = [bubbleImage CGImageForProposedRect:nil context:context hints:nil];
65
+    eye0 = [eye0Image CGImageForProposedRect:nil context:context hints:nil];
66
+    eye1 = [eye1Image CGImageForProposedRect:nil context:context hints:nil];
67
+    eye2 = [eye2Image CGImageForProposedRect:nil context:context hints:nil];
68
+    eye3 = [eye3Image CGImageForProposedRect:nil context:context hints:nil];
69
+    eye4 = [eye4Image CGImageForProposedRect:nil context:context hints:nil];
70
+    
71
+    fullSize.width = FULL_IMAGE_WIDTH;
72
+    fullSize.height = FULL_IMAGE_HEIGHT;
73
+    
74
+    drawContext = CGBitmapContextCreate(NULL, fullSize.width, fullSize.height, 8, 0, CGColorSpaceCreateDeviceRGB(), kCGImageAlphaPremultipliedLast | kCGBitmapByteOrderDefault);
75
+    
76
+    return self;
77
+}
78
+
79
+- (NSSize)baseSize {
80
+    return fullSize;
81
+}
82
+
83
+- (void)drawWith:(NSInteger)eyeIndex {
84
+    CGRect size;
85
+    
86
+    // Clear entire canvas
87
+    size.size = fullSize;
88
+    size.origin = NSZeroPoint;
89
+    CGContextClearRect(drawContext, size);
90
+    
91
+    // Draw Speech Bubble
92
+    size.size.width = CGImageGetWidth(bubbleGraphic);
93
+    size.size.height = CGImageGetHeight(bubbleGraphic);
94
+    size.origin.y = BUBBLE_Y_OFFSET;
95
+    CGContextDrawImage(drawContext, size, bubbleGraphic);
96
+    
97
+    // Draw Otacon
98
+    size.size.width = CGImageGetWidth(otaconGraphic);
99
+    size.size.height = CGImageGetHeight(otaconGraphic);
100
+    size.origin = NSZeroPoint;
101
+    size.origin.x = CGImageGetWidth(bubbleGraphic) + OTACON_X_OFFSET;
102
+    CGContextDrawImage(drawContext, size, otaconGraphic);
103
+    
104
+    // Draw eyes
105
+    size.size.width = CGImageGetWidth([self eyeHelper:eyeIndex]);
106
+    size.size.height = CGImageGetHeight([self eyeHelper:eyeIndex]);
107
+    size.origin.x = EYE_X_OFFSET;
108
+    size.origin.y = EYE_Y_OFFSET;
109
+    CGContextDrawImage(drawContext, size, [self eyeHelper:eyeIndex]);
110
+}
111
+
112
+- (void)drawInto:(NSView *)view {
113
+    CGImageRef drawnImage = CGBitmapContextCreateImage(drawContext);
114
+    NSImage *result = [[NSImage alloc] initWithCGImage:drawnImage size:fullSize];
115
+    [result drawInRect:[view bounds] fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0 respectFlipped:NO hints:[NSDictionary dictionaryWithObject:[NSNumber numberWithInteger:NSImageInterpolationNone] forKey:NSImageHintInterpolation]];
116
+}
117
+
118
+@end

Loading…
Cancel
Save