Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added ImageFun example from Chapter 18.

  • Loading branch information...
commit 63372490bec6ab4585a1fa24c72b3a6d478846cd 1 parent ef8239d
@timburks authored
View
BIN  18_MouseEvents/ImageFun/English.lproj/InfoPlist.strings
Binary file not shown
View
2,329 18_MouseEvents/ImageFun/English.lproj/MainMenu.nib/designable.nib
2,329 additions, 0 deletions not shown
View
BIN  18_MouseEvents/ImageFun/English.lproj/MainMenu.nib/keyedobjects.nib
Binary file not shown
View
283 18_MouseEvents/ImageFun/ImageFun.xcodeproj/project.pbxproj
@@ -0,0 +1,283 @@
+// !$*UTF8*$!
+{
+ archiveVersion = 1;
+ classes = {
+ };
+ objectVersion = 44;
+ objects = {
+
+/* Begin PBXBuildFile section */
+ 222A5BFF0DE889630005D8EA /* Nu.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 222A5BFE0DE889630005D8EA /* Nu.framework */; };
+ 222A5C040DE8897A0005D8EA /* main.nu in Resources */ = {isa = PBXBuildFile; fileRef = 222A5C030DE8897A0005D8EA /* main.nu */; };
+ 8D11072A0486CEB800E47090 /* MainMenu.nib in Resources */ = {isa = PBXBuildFile; fileRef = 29B97318FDCFA39411CA2CEA /* MainMenu.nib */; };
+ 8D11072B0486CEB800E47090 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 089C165CFE840E0CC02AAC07 /* InfoPlist.strings */; };
+ 8D11072D0486CEB800E47090 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 29B97316FDCFA39411CA2CEA /* main.m */; settings = {ATTRIBUTES = (); }; };
+ 8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */; };
+/* End PBXBuildFile section */
+
+/* Begin PBXFileReference section */
+ 089C165DFE840E0CC02AAC07 /* English */ = {isa = PBXFileReference; fileEncoding = 10; lastKnownFileType = text.plist.strings; name = English; path = English.lproj/InfoPlist.strings; sourceTree = "<group>"; };
+ 1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = /System/Library/Frameworks/Cocoa.framework; sourceTree = "<absolute>"; };
+ 13E42FB307B3F0F600E4EEF1 /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = /System/Library/Frameworks/CoreData.framework; sourceTree = "<absolute>"; };
+ 222A5BFE0DE889630005D8EA /* Nu.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Nu.framework; path = /Library/Frameworks/Nu.framework; sourceTree = "<absolute>"; };
+ 222A5C030DE8897A0005D8EA /* main.nu */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = main.nu; path = nu/main.nu; sourceTree = "<group>"; };
+ 29B97316FDCFA39411CA2CEA /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
+ 29B97319FDCFA39411CA2CEA /* English */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = English; path = English.lproj/MainMenu.nib; sourceTree = "<group>"; };
+ 29B97324FDCFA39411CA2CEA /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = /System/Library/Frameworks/AppKit.framework; sourceTree = "<absolute>"; };
+ 29B97325FDCFA39411CA2CEA /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = /System/Library/Frameworks/Foundation.framework; sourceTree = "<absolute>"; };
+ 32CA4F630368D1EE00C91783 /* ImageFun_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ImageFun_Prefix.pch; sourceTree = "<group>"; };
+ 8D1107310486CEB800E47090 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
+ 8D1107320486CEB800E47090 /* ImageFun.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ImageFun.app; sourceTree = BUILT_PRODUCTS_DIR; };
+/* End PBXFileReference section */
+
+/* Begin PBXFrameworksBuildPhase section */
+ 8D11072E0486CEB800E47090 /* Frameworks */ = {
+ isa = PBXFrameworksBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ 8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */,
+ 222A5BFF0DE889630005D8EA /* Nu.framework in Frameworks */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXFrameworksBuildPhase section */
+
+/* Begin PBXGroup section */
+ 1058C7A0FEA54F0111CA2CBB /* Linked Frameworks */ = {
+ isa = PBXGroup;
+ children = (
+ 222A5BFE0DE889630005D8EA /* Nu.framework */,
+ 1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */,
+ );
+ name = "Linked Frameworks";
+ sourceTree = "<group>";
+ };
+ 1058C7A2FEA54F0111CA2CBB /* Other Frameworks */ = {
+ isa = PBXGroup;
+ children = (
+ 29B97324FDCFA39411CA2CEA /* AppKit.framework */,
+ 13E42FB307B3F0F600E4EEF1 /* CoreData.framework */,
+ 29B97325FDCFA39411CA2CEA /* Foundation.framework */,
+ );
+ name = "Other Frameworks";
+ sourceTree = "<group>";
+ };
+ 19C28FACFE9D520D11CA2CBB /* Products */ = {
+ isa = PBXGroup;
+ children = (
+ 8D1107320486CEB800E47090 /* ImageFun.app */,
+ );
+ name = Products;
+ sourceTree = "<group>";
+ };
+ 222A5C020DE8896A0005D8EA /* Nu */ = {
+ isa = PBXGroup;
+ children = (
+ 222A5C030DE8897A0005D8EA /* main.nu */,
+ );
+ name = Nu;
+ sourceTree = "<group>";
+ };
+ 29B97314FDCFA39411CA2CEA /* ImageFun */ = {
+ isa = PBXGroup;
+ children = (
+ 222A5C020DE8896A0005D8EA /* Nu */,
+ 29B97315FDCFA39411CA2CEA /* Other Sources */,
+ 29B97317FDCFA39411CA2CEA /* Resources */,
+ 29B97323FDCFA39411CA2CEA /* Frameworks */,
+ 19C28FACFE9D520D11CA2CBB /* Products */,
+ );
+ name = ImageFun;
+ sourceTree = "<group>";
+ };
+ 29B97315FDCFA39411CA2CEA /* Other Sources */ = {
+ isa = PBXGroup;
+ children = (
+ 32CA4F630368D1EE00C91783 /* ImageFun_Prefix.pch */,
+ 29B97316FDCFA39411CA2CEA /* main.m */,
+ );
+ name = "Other Sources";
+ sourceTree = "<group>";
+ };
+ 29B97317FDCFA39411CA2CEA /* Resources */ = {
+ isa = PBXGroup;
+ children = (
+ 8D1107310486CEB800E47090 /* Info.plist */,
+ 089C165CFE840E0CC02AAC07 /* InfoPlist.strings */,
+ 29B97318FDCFA39411CA2CEA /* MainMenu.nib */,
+ );
+ name = Resources;
+ sourceTree = "<group>";
+ };
+ 29B97323FDCFA39411CA2CEA /* Frameworks */ = {
+ isa = PBXGroup;
+ children = (
+ 1058C7A0FEA54F0111CA2CBB /* Linked Frameworks */,
+ 1058C7A2FEA54F0111CA2CBB /* Other Frameworks */,
+ );
+ name = Frameworks;
+ sourceTree = "<group>";
+ };
+/* End PBXGroup section */
+
+/* Begin PBXNativeTarget section */
+ 8D1107260486CEB800E47090 /* ImageFun */ = {
+ isa = PBXNativeTarget;
+ buildConfigurationList = C01FCF4A08A954540054247B /* Build configuration list for PBXNativeTarget "ImageFun" */;
+ buildPhases = (
+ 8D1107290486CEB800E47090 /* Resources */,
+ 8D11072C0486CEB800E47090 /* Sources */,
+ 8D11072E0486CEB800E47090 /* Frameworks */,
+ );
+ buildRules = (
+ );
+ dependencies = (
+ );
+ name = ImageFun;
+ productInstallPath = "$(HOME)/Applications";
+ productName = ImageFun;
+ productReference = 8D1107320486CEB800E47090 /* ImageFun.app */;
+ productType = "com.apple.product-type.application";
+ };
+/* End PBXNativeTarget section */
+
+/* Begin PBXProject section */
+ 29B97313FDCFA39411CA2CEA /* Project object */ = {
+ isa = PBXProject;
+ buildConfigurationList = C01FCF4E08A954540054247B /* Build configuration list for PBXProject "ImageFun" */;
+ compatibilityVersion = "Xcode 3.0";
+ hasScannedForEncodings = 1;
+ mainGroup = 29B97314FDCFA39411CA2CEA /* ImageFun */;
+ projectDirPath = "";
+ projectRoot = "";
+ targets = (
+ 8D1107260486CEB800E47090 /* ImageFun */,
+ );
+ };
+/* End PBXProject section */
+
+/* Begin PBXResourcesBuildPhase section */
+ 8D1107290486CEB800E47090 /* Resources */ = {
+ isa = PBXResourcesBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ 8D11072A0486CEB800E47090 /* MainMenu.nib in Resources */,
+ 8D11072B0486CEB800E47090 /* InfoPlist.strings in Resources */,
+ 222A5C040DE8897A0005D8EA /* main.nu in Resources */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXResourcesBuildPhase section */
+
+/* Begin PBXSourcesBuildPhase section */
+ 8D11072C0486CEB800E47090 /* Sources */ = {
+ isa = PBXSourcesBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ 8D11072D0486CEB800E47090 /* main.m in Sources */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXSourcesBuildPhase section */
+
+/* Begin PBXVariantGroup section */
+ 089C165CFE840E0CC02AAC07 /* InfoPlist.strings */ = {
+ isa = PBXVariantGroup;
+ children = (
+ 089C165DFE840E0CC02AAC07 /* English */,
+ );
+ name = InfoPlist.strings;
+ sourceTree = "<group>";
+ };
+ 29B97318FDCFA39411CA2CEA /* MainMenu.nib */ = {
+ isa = PBXVariantGroup;
+ children = (
+ 29B97319FDCFA39411CA2CEA /* English */,
+ );
+ name = MainMenu.nib;
+ sourceTree = "<group>";
+ };
+/* End PBXVariantGroup section */
+
+/* Begin XCBuildConfiguration section */
+ C01FCF4B08A954540054247B /* Debug */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ COPY_PHASE_STRIP = NO;
+ GCC_DYNAMIC_NO_PIC = NO;
+ GCC_ENABLE_FIX_AND_CONTINUE = YES;
+ GCC_MODEL_TUNING = G5;
+ GCC_OPTIMIZATION_LEVEL = 0;
+ GCC_PRECOMPILE_PREFIX_HEADER = YES;
+ GCC_PREFIX_HEADER = ImageFun_Prefix.pch;
+ INFOPLIST_FILE = Info.plist;
+ INSTALL_PATH = "$(HOME)/Applications";
+ PRODUCT_NAME = ImageFun;
+ WRAPPER_EXTENSION = app;
+ ZERO_LINK = YES;
+ };
+ name = Debug;
+ };
+ C01FCF4C08A954540054247B /* Release */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
+ GCC_MODEL_TUNING = G5;
+ GCC_PRECOMPILE_PREFIX_HEADER = YES;
+ GCC_PREFIX_HEADER = ImageFun_Prefix.pch;
+ INFOPLIST_FILE = Info.plist;
+ INSTALL_PATH = "$(HOME)/Applications";
+ PRODUCT_NAME = ImageFun;
+ WRAPPER_EXTENSION = app;
+ };
+ name = Release;
+ };
+ C01FCF4F08A954540054247B /* Debug */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ GCC_WARN_ABOUT_RETURN_TYPE = YES;
+ GCC_WARN_UNUSED_VARIABLE = YES;
+ PREBINDING = NO;
+ SDKROOT = "$(DEVELOPER_SDK_DIR)/MacOSX10.5.sdk";
+ };
+ name = Debug;
+ };
+ C01FCF5008A954540054247B /* Release */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ ARCHS = (
+ ppc,
+ i386,
+ );
+ GCC_WARN_ABOUT_RETURN_TYPE = YES;
+ GCC_WARN_UNUSED_VARIABLE = YES;
+ PREBINDING = NO;
+ SDKROOT = "$(DEVELOPER_SDK_DIR)/MacOSX10.5.sdk";
+ };
+ name = Release;
+ };
+/* End XCBuildConfiguration section */
+
+/* Begin XCConfigurationList section */
+ C01FCF4A08A954540054247B /* Build configuration list for PBXNativeTarget "ImageFun" */ = {
+ isa = XCConfigurationList;
+ buildConfigurations = (
+ C01FCF4B08A954540054247B /* Debug */,
+ C01FCF4C08A954540054247B /* Release */,
+ );
+ defaultConfigurationIsVisible = 0;
+ defaultConfigurationName = Release;
+ };
+ C01FCF4E08A954540054247B /* Build configuration list for PBXProject "ImageFun" */ = {
+ isa = XCConfigurationList;
+ buildConfigurations = (
+ C01FCF4F08A954540054247B /* Debug */,
+ C01FCF5008A954540054247B /* Release */,
+ );
+ defaultConfigurationIsVisible = 0;
+ defaultConfigurationName = Release;
+ };
+/* End XCConfigurationList section */
+ };
+ rootObject = 29B97313FDCFA39411CA2CEA /* Project object */;
+}
View
7 18_MouseEvents/ImageFun/ImageFun_Prefix.pch
@@ -0,0 +1,7 @@
+//
+// Prefix header for all source files of the 'ImageFun' target in the 'ImageFun' project
+//
+
+#ifdef __OBJC__
+ #import <Cocoa/Cocoa.h>
+#endif
View
28 18_MouseEvents/ImageFun/Info.plist
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>CFBundleDevelopmentRegion</key>
+ <string>English</string>
+ <key>CFBundleExecutable</key>
+ <string>${EXECUTABLE_NAME}</string>
+ <key>CFBundleIconFile</key>
+ <string></string>
+ <key>CFBundleIdentifier</key>
+ <string>com.yourcompany.ImageFun</string>
+ <key>CFBundleInfoDictionaryVersion</key>
+ <string>6.0</string>
+ <key>CFBundleName</key>
+ <string>${PRODUCT_NAME}</string>
+ <key>CFBundlePackageType</key>
+ <string>APPL</string>
+ <key>CFBundleSignature</key>
+ <string>????</string>
+ <key>CFBundleVersion</key>
+ <string>1.0</string>
+ <key>NSMainNibFile</key>
+ <string>MainMenu</string>
+ <key>NSPrincipalClass</key>
+ <string>NSApplication</string>
+</dict>
+</plist>
View
6 18_MouseEvents/ImageFun/main.m
@@ -0,0 +1,6 @@
+int NuMain(int argc, const char *argv[]);
+
+int main(int argc, const char *argv[])
+{
+ return NuMain(argc, argv);
+}
View
128 18_MouseEvents/ImageFun/nu/main.nu
@@ -0,0 +1,128 @@
+;; file main.nu
+;; discussion Entry point for a Nu program.
+;; copyright Copyright (c) 2008 Tim Burks, Neon Design Technology, Inc.
+
+(import Cocoa) ;; bridgesupport
+(load "console") ;; interactive console
+
+(set random (NuBridgedFunction functionWithName:"random" signature:"l"))
+(function min (a b) (if (< a b) then a else b))
+(function max (a b) (if (> a b) then a else b))
+
+(class AppController is NSObject
+ (ivar (id) stretchView)
+
+ (- (void)showOpenPanel:(id)sender is
+ (set op (NSOpenPanel openPanel))
+ (op beginSheetForDirectory:nil
+ file:nil
+ types:(NSImage imageFileTypes)
+ modalForWindow:(@stretchView window)
+ modalDelegate:self
+ didEndSelector:"openPanelDidEnd:returnCode:contextInfo:"
+ contextInfo:nil))
+
+ (- (void)openPanelDidEnd:(id)op
+ returnCode:(int)returnCode
+ contextInfo:(void *)ci is
+ (if (eq returnCode NSOKButton)
+ (set path (op filename))
+ (set image ((NSImage alloc) initWithContentsOfFile:path))
+ (@stretchView setImage:image))))
+
+(class StretchView is NSView
+ (ivar (id) path (id) image (float) opacity (NSPoint) downPoint (NSPoint) currentPoint)
+
+ (- (id)initWithFrame:(NSRect)frame is
+ (unless (super initWithFrame:frame) (return nil))
+ ;; srandom(time(NULL))
+ (set @path ((NSBezierPath alloc) init))
+ (@path setLineWidth:3.0)
+ (set p (self randomPoint))
+ (@path moveToPoint:p)
+ (15 times:
+ (do (i)
+ (set p (self randomPoint))
+ (@path lineToPoint:p)))
+ (@path closePath)
+ (set @opacity 1.0)
+ self)
+
+ (- (NSPoint)randomPoint is
+ (set bounds (self bounds))
+ (list (+ (bounds first) (% (random) ((bounds third) intValue)))
+ (+ (bounds second) (% (random) ((bounds fourth) intValue)))))
+
+ (- (void)drawRect:(NSRect)rect is
+ (set bounds (self bounds))
+ ((NSColor greenColor) set)
+ (NSBezierPath fillRect:bounds)
+ ((NSColor whiteColor) set)
+ (@path fill)
+ (if @image
+ (set imageRect (append '(0 0) (@image size)))
+ (set drawingRect (self currentRect))
+ (puts "drawing image in #{imageRect} #{drawingRect}")
+ (@image drawInRect:drawingRect
+ fromRect:imageRect
+ operation:NSCompositeSourceOver
+ fraction:@opacity)))
+
+ (- (void)mouseDown:(id)event is
+ (set p (event locationInWindow))
+ (set @downPoint (self convertPoint:p fromView:nil))
+ (set @currentPoint @downPoint)
+ (self setNeedsDisplay:YES))
+
+ (- (void)mouseDragged:(id)event is
+ (set p (event locationInWindow))
+ (set @currentPoint (self convertPoint:p fromView:nil))
+ (self autoscroll:event)
+ (self setNeedsDisplay:YES))
+
+ (- (void)mouseUp:(id)event is
+ (set p (event locationInWindow))
+ (set @currentPoint (self convertPoint:p fromView:nil))
+ (self setNeedsDisplay:YES))
+
+ (- (NSRect)currentRect is
+ (set minX (min (@downPoint first) (@currentPoint first)))
+ (set minY (min (@downPoint second) (@currentPoint second)))
+ (set maxX (max (@downPoint first) (@currentPoint first)))
+ (set maxY (max (@downPoint second) (@currentPoint second)))
+ (list minX minY (- maxX minX) (- maxY minY)))
+
+ (- (void)setImage:(id)i is
+ (set @image i)
+ (set imageSize (i size))
+ (set @downPoint '(0 0))
+ (set @currentPoint imageSize)
+ (self setNeedsDisplay:YES))
+
+ (- (float)opacity is @opacity)
+
+ (- (void)setOpacity:(float)f is
+ (set @opacity f)
+ (self setNeedsDisplay:YES)))
+
+(set SHOW_CONSOLE_AT_STARTUP nil)
+
+;; @class ApplicationDelegate
+;; @discussion Methods of this class perform general-purpose tasks that are not appropriate methods of any other classes.
+(class ApplicationDelegate is NSObject
+
+ ;; This method is called after Cocoa has finished its basic application setup.
+ ;; It instantiates application-specific components.
+ ;; In this case, it constructs an interactive Nu console that can be activated from the application's Window menu.
+ (- (void) applicationDidFinishLaunching:(id) sender is
+ (set $console ((NuConsoleWindowController alloc) init))
+ (if SHOW_CONSOLE_AT_STARTUP ($console toggleConsole:self))))
+
+;; install the delegate and keep a reference to it since the application won't retain it.
+((NSApplication sharedApplication) setDelegate:(set $delegate ((ApplicationDelegate alloc) init)))
+
+;; this makes the application window take focus when we've started it from the terminal (or with nuke)
+((NSApplication sharedApplication) activateIgnoringOtherApps:YES)
+
+;; run the main Cocoa event loop
+(NSApplicationMain 0 nil)
Please sign in to comment.
Something went wrong with that request. Please try again.