Merge pull request #1881 from hawkw/master

Add support for Jasmin JVM assembly
This commit is contained in:
Arfon Smith
2014-12-16 21:29:19 -06:00
13 changed files with 1117 additions and 0 deletions

View File

@@ -430,3 +430,5 @@ https://github.com/l15n/fish-tmbundle:
- source.fish
https://raw.githubusercontent.com/andik/IDL-Syntax/master/IDL.tmLanguage:
- source.webidl
https://raw.githubusercontent.com/atmarksharp/jasmin-sublime/master/Jasmin.tmLanguage:
- source.jasmin

View File

@@ -1413,6 +1413,13 @@ Jade:
tm_scope: source.jade
ace_mode: jade
Jasmin:
type: programming
ace_mode: java
extensions:
- .j
tm_scope: source.jasmin
Java:
type: programming
ace_mode: java

56
samples/Jasmin/if1.j Normal file
View File

@@ -0,0 +1,56 @@
.class public if1
.super java/lang/Object
;
; standard initializer (calls java.lang.Object's initializer)
;
.method public <init>()V
aload_0
invokenonvirtual java/lang/Object/<init>()V
return
.end method
.method public static main([Ljava/lang/String;)V
.limit locals 1
.limit stack 5
BeginGlobal:
.line 2
ldc 0x1
ldc 0x1
if_icmpeq If556261059
goto IfElse556261059
If556261059:
.line 3
.line 3
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc 0x1
invokevirtual java/io/PrintStream/print(I)V
goto IfDone556261059
IfElse556261059:
.line 5
.line 5
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc 0x2
invokevirtual java/io/PrintStream/print(I)V
IfDone556261059:
.line 6
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc 0x3
invokevirtual java/io/PrintStream/print(I)V
.line 7
ldc 0x1
ldc 0x1
if_icmpne IfNot-920218690
.line 8
.line 8
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc 0x4
invokevirtual java/io/PrintStream/print(I)V
IfNot-920218690:
EndGlobal:
return
.end method

167
samples/Jasmin/if2.j Normal file
View File

@@ -0,0 +1,167 @@
.class public if2
.super java/lang/Object
;
; standard initializer (calls java.lang.Object's initializer)
;
.method public <init>()V
aload_0
invokenonvirtual java/lang/Object/<init>()V
return
.end method
.method public static main([Ljava/lang/String;)V
.limit locals 1
.limit stack 5
BeginGlobal:
.line 2
ldc 0x1
ldc 0x1
if_icmpeq Cmp1893841232
ldc 0x0
goto CmpDone1893841232
Cmp1893841232:
ldc 0x1
CmpDone1893841232:
ldc 0x1
if_icmpeq If-1736765035
goto IfElse-1736765035
If-1736765035:
.line 2
.line 3
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc 0x1
invokevirtual java/io/PrintStream/print(I)V
goto IfDone-1736765035
IfElse-1736765035:
.line 4
.line 4
ldc 0x2
ldc 0x1
if_icmpeq Cmp-1460884369
ldc 0x0
goto CmpDone-1460884369
Cmp-1460884369:
ldc 0x1
CmpDone-1460884369:
ldc 0x1
if_icmpeq If-247349760
goto IfElse-247349760
If-247349760:
.line 4
.line 5
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc 0x2
invokevirtual java/io/PrintStream/print(I)V
goto IfDone-247349760
IfElse-247349760:
.line 6
.line 7
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc 0x3
invokevirtual java/io/PrintStream/print(I)V
IfDone-247349760:
IfDone-1736765035:
.line 10
ldc 0x1
ldc 0x2
if_icmpeq Cmp933554851
ldc 0x0
goto CmpDone933554851
Cmp933554851:
ldc 0x1
CmpDone933554851:
ldc 0x1
if_icmpeq If1623625546
goto IfElse1623625546
If1623625546:
.line 10
.line 11
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc 0x1
invokevirtual java/io/PrintStream/print(I)V
goto IfDone1623625546
IfElse1623625546:
.line 12
.line 12
ldc 0x2
ldc 0x2
if_icmpeq Cmp1572138409
ldc 0x0
goto CmpDone1572138409
Cmp1572138409:
ldc 0x1
CmpDone1572138409:
ldc 0x1
if_icmpeq If126354425
goto IfElse126354425
If126354425:
.line 12
.line 13
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc 0x2
invokevirtual java/io/PrintStream/print(I)V
goto IfDone126354425
IfElse126354425:
.line 14
.line 15
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc 0x3
invokevirtual java/io/PrintStream/print(I)V
IfDone126354425:
IfDone1623625546:
.line 18
ldc 0x1
ldc 0x2
if_icmpeq Cmp126493150
ldc 0x0
goto CmpDone126493150
Cmp126493150:
ldc 0x1
CmpDone126493150:
ldc 0x1
if_icmpeq If1522284422
goto IfElse1522284422
If1522284422:
.line 18
.line 19
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc 0x1
invokevirtual java/io/PrintStream/print(I)V
goto IfDone1522284422
IfElse1522284422:
.line 20
.line 20
ldc 0x2
ldc 0x1
if_icmpeq Cmp-906666545
ldc 0x0
goto CmpDone-906666545
Cmp-906666545:
ldc 0x1
CmpDone-906666545:
ldc 0x1
if_icmpeq If1083939031
goto IfElse1083939031
If1083939031:
.line 20
.line 21
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc 0x2
invokevirtual java/io/PrintStream/print(I)V
goto IfDone1083939031
IfElse1083939031:
.line 22
.line 23
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc 0x3
invokevirtual java/io/PrintStream/print(I)V
IfDone1083939031:
IfDone1522284422:
EndGlobal:
return
.end method

55
samples/Jasmin/if3.j Normal file
View File

@@ -0,0 +1,55 @@
.class public if3
.super java/lang/Object
;
; standard initializer (calls java.lang.Object's initializer)
;
.method public <init>()V
aload_0
invokenonvirtual java/lang/Object/<init>()V
return
.end method
.method public static main([Ljava/lang/String;)V
.limit locals 1
.limit stack 5
BeginGlobal:
.line 2
ldc 0x1
ldc 0x1
if_icmpeq If-811796083
goto IfElse-811796083
If-811796083:
.line 3
.line 3
ldc 0x0
ldc 0x1
if_icmpeq If-1001319390
goto IfElse-1001319390
If-1001319390:
.line 4
.line 4
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc 0x1
invokevirtual java/io/PrintStream/print(I)V
goto IfDone-1001319390
IfElse-1001319390:
.line 6
.line 6
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc 0x2
invokevirtual java/io/PrintStream/print(I)V
IfDone-1001319390:
goto IfDone-811796083
IfElse-811796083:
.line 8
.line 8
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc 0x3
invokevirtual java/io/PrintStream/print(I)V
IfDone-811796083:
EndGlobal:
return
.end method

37
samples/Jasmin/if4.j Normal file
View File

@@ -0,0 +1,37 @@
.class public if4
.super java/lang/Object
;
; standard initializer (calls java.lang.Object's initializer)
;
.method public <init>()V
aload_0
invokenonvirtual java/lang/Object/<init>()V
return
.end method
.method public static main([Ljava/lang/String;)V
.limit locals 1
.limit stack 5
BeginGlobal:
.line 2
ldc 0x1
ldc 0x1
if_icmpne IfNot1919266740
.line 2
.line 2
ldc 0x1
ldc 0x1
if_icmpne IfNot613368541
.line 2
.line 2
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc 0x1
invokevirtual java/io/PrintStream/print(I)V
IfNot613368541:
IfNot1919266740:
EndGlobal:
return
.end method

54
samples/Jasmin/op1.j Normal file
View File

@@ -0,0 +1,54 @@
.class public op1
.super java/lang/Object
;
; standard initializer (calls java.lang.Object's initializer)
;
.method public <init>()V
aload_0
invokenonvirtual java/lang/Object/<init>()V
return
.end method
.method public static main([Ljava/lang/String;)V
.limit locals 1
.limit stack 5
BeginGlobal:
.line 2
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc 0x1
ldc 0x1
iadd
invokevirtual java/io/PrintStream/println(I)V
.line 3
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc 0xa
ldc 0x5
isub
invokevirtual java/io/PrintStream/println(I)V
.line 4
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc 0x15
ldc 0x3
idiv
invokevirtual java/io/PrintStream/println(I)V
.line 5
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc 0x159
ldc 0x38
imul
invokevirtual java/io/PrintStream/println(I)V
.line 6
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc 0x52
ldc 0x9
irem
invokevirtual java/io/PrintStream/println(I)V
EndGlobal:
return
.end method

34
samples/Jasmin/op2.j Normal file
View File

@@ -0,0 +1,34 @@
.class public op2
.super java/lang/Object
;
; standard initializer (calls java.lang.Object's initializer)
;
.method public <init>()V
aload_0
invokenonvirtual java/lang/Object/<init>()V
return
.end method
.method public static main([Ljava/lang/String;)V
.limit locals 1
.limit stack 5
BeginGlobal:
.line 2
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc 0x1
ldc 0x0
iand
invokevirtual java/io/PrintStream/println(Z)V
.line 3
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc 0x1
ldc 0x0
ior
invokevirtual java/io/PrintStream/println(Z)V
EndGlobal:
return
.end method

68
samples/Jasmin/op3.j Normal file
View File

@@ -0,0 +1,68 @@
.class public op3
.super java/lang/Object
;
; standard initializer (calls java.lang.Object's initializer)
;
.method public <init>()V
aload_0
invokenonvirtual java/lang/Object/<init>()V
return
.end method
.method public static main([Ljava/lang/String;)V
.limit locals 1
.limit stack 5
BeginGlobal:
.line 2
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc 0x0
ldc 0x1
if_icmpeq Cmp-1307183590
ldc 0x0
goto CmpDone-1307183590
Cmp-1307183590:
ldc 0x1
CmpDone-1307183590:
invokevirtual java/io/PrintStream/println(Z)V
.line 3
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc 0x0
ldc 0x0
if_icmpeq Cmp-1443270821
ldc 0x0
goto CmpDone-1443270821
Cmp-1443270821:
ldc 0x1
CmpDone-1443270821:
invokevirtual java/io/PrintStream/println(Z)V
.line 4
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc 0x1
ldc 0x1
if_icmpeq Cmp1759327329
ldc 0x0
goto CmpDone1759327329
Cmp1759327329:
ldc 0x1
CmpDone1759327329:
invokevirtual java/io/PrintStream/println(Z)V
.line 5
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc 0x1
ldc 0x0
if_icmpeq Cmp-678570146
ldc 0x0
goto CmpDone-678570146
Cmp-678570146:
ldc 0x1
CmpDone-678570146:
invokevirtual java/io/PrintStream/println(Z)V
EndGlobal:
return
.end method

68
samples/Jasmin/op4.j Normal file
View File

@@ -0,0 +1,68 @@
.class public op4
.super java/lang/Object
;
; standard initializer (calls java.lang.Object's initializer)
;
.method public <init>()V
aload_0
invokenonvirtual java/lang/Object/<init>()V
return
.end method
.method public static main([Ljava/lang/String;)V
.limit locals 1
.limit stack 5
BeginGlobal:
.line 2
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc 0x0
ldc 0x1
if_icmpne Cmp-191731100
ldc 0x0
goto CmpDone-191731100
Cmp-191731100:
ldc 0x1
CmpDone-191731100:
invokevirtual java/io/PrintStream/println(Z)V
.line 3
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc 0x0
ldc 0x0
if_icmpne Cmp-901585603
ldc 0x0
goto CmpDone-901585603
Cmp-901585603:
ldc 0x1
CmpDone-901585603:
invokevirtual java/io/PrintStream/println(Z)V
.line 4
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc 0x1
ldc 0x1
if_icmpne Cmp1522577937
ldc 0x0
goto CmpDone1522577937
Cmp1522577937:
ldc 0x1
CmpDone1522577937:
invokevirtual java/io/PrintStream/println(Z)V
.line 5
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc 0x1
ldc 0x0
if_icmpne Cmp-1653028684
ldc 0x0
goto CmpDone-1653028684
Cmp-1653028684:
ldc 0x1
CmpDone-1653028684:
invokevirtual java/io/PrintStream/println(Z)V
EndGlobal:
return
.end method

View File

@@ -0,0 +1,434 @@
//
// AppController.j
// FlickrPhoto
//
// Created by Ross Boucher.
// Copyright 2008 - 2010, 280 North, Inc. All rights reserved.
@import <Foundation/Foundation.j>
@import <AppKit/AppKit.j>
var SliderToolbarItemIdentifier = "SliderToolbarItemIdentifier",
AddToolbarItemIdentifier = "AddToolbarItemIdentifier",
RemoveToolbarItemIdentifier = "RemoveToolbarItemIdentifier";
/*
Important note about CPJSONPConnection: CPJSONPConnection is ONLY for JSONP APIs.
If aren't sure you NEED JSONP (see http://ajaxian.com/archives/jsonp-json-with-padding ),
you most likely don't want to use CPJSONPConnection, but rather the more standard
CPURLConnection. CPJSONPConnection is designed for cross-domain
connections, and if you are making requests to the same domain (as most web
applications do), you do not need it.
*/
@implementation AppController : CPObject
{
CPString lastIdentifier;
CPDictionary photosets;
CPCollectionView listCollectionView;
CPCollectionView photosCollectionView;
}
- (void)applicationDidFinishLaunching:(CPNotification)aNotification
{
//the first thing we need to do is create a window to take up the full screen
//we'll also create a toolbar to go with it, and grab its size for future reference
var theWindow = [[CPWindow alloc] initWithContentRect:CGRectMakeZero() styleMask:CPBorderlessBridgeWindowMask],
contentView = [theWindow contentView],
toolbar = [[CPToolbar alloc] initWithIdentifier:"Photos"],
bounds = [contentView bounds];
//we tell the toolbar that we want to be its delegate and attach it to theWindow
[toolbar setDelegate:self];
[toolbar setVisible:true];
[theWindow setToolbar:toolbar];
photosets = [CPDictionary dictionary]; //storage for our sets of photos return from Flickr
//now we create a scroll view to contain the list of collections of photos (photosets)
//inside the scroll view, we'll place our collection view, which manages a collection of "cells"
//each cell will represent one photo collection, and choosing cells will select that collection
var listScrollView = [[CPScrollView alloc] initWithFrame:CGRectMake(0, 0, 200, CGRectGetHeight(bounds) - 58)];
[listScrollView setAutohidesScrollers:YES];
[listScrollView setAutoresizingMask:CPViewHeightSizable];
[[listScrollView contentView] setBackgroundColor:[CPColor colorWithRed:213.0 / 255.0 green:221.0 / 255.0 blue:230.0 / 255.0 alpha:1.0]];
//we create the collection view cells by creating a single prototype (CPCollectionViewItem) and setting its view.
//the CPCollectionView class will then duplicate this item as many times as it needs
var photosListItem = [[CPCollectionViewItem alloc] init];
[photosListItem setView:[[PhotosListCell alloc] initWithFrame:CGRectMakeZero()]];
listCollectionView = [[CPCollectionView alloc] initWithFrame:CGRectMake(0, 0, 200, 0)];
[listCollectionView setDelegate:self]; //we want delegate methods
[listCollectionView setItemPrototype:photosListItem]; //set the item prototype
[listCollectionView setMinItemSize:CGSizeMake(20.0, 45.0)];
[listCollectionView setMaxItemSize:CGSizeMake(1000.0, 45.0)];
[listCollectionView setMaxNumberOfColumns:1]; //setting a single column will make this appear as a vertical list
[listCollectionView setVerticalMargin:0.0];
[listCollectionView setAutoresizingMask:CPViewWidthSizable];
//finally, we put our collection view inside the scroll view as it's document view, so it can be scrolled
[listScrollView setDocumentView:listCollectionView];
//and we add it to the window's content view, so it will show up on the screen
[contentView addSubview:listScrollView];
//repeat the process with another collection view for the actual photos
//this time we'll use a different view for the prototype (PhotoCell)
var photoItem = [[CPCollectionViewItem alloc] init];
[photoItem setView:[[PhotoCell alloc] initWithFrame:CGRectMake(0, 0, 150, 150)]];
var scrollView = [[CPScrollView alloc] initWithFrame:CGRectMake(200, 0, CGRectGetWidth(bounds) - 200, CGRectGetHeight(bounds) - 58)];
photosCollectionView = [[CPCollectionView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(bounds) - 200, 0)];
[photosCollectionView setDelegate:self];
[photosCollectionView setItemPrototype:photoItem];
[photosCollectionView setMinItemSize:CGSizeMake(150, 150)];
[photosCollectionView setMaxItemSize:CGSizeMake(150, 150)];
[photosCollectionView setAutoresizingMask:CPViewWidthSizable];
[scrollView setAutoresizingMask:CPViewHeightSizable | CPViewWidthSizable];
[scrollView setDocumentView:photosCollectionView];
[scrollView setAutohidesScrollers:YES];
[[scrollView contentView] setBackgroundColor:[CPColor colorWithCalibratedWhite:0.25 alpha:1.0]];
[contentView addSubview:scrollView];
//bring forward the window to display it
[theWindow orderFront:self];
//get the most interesting photos on flickr
var request = [CPURLRequest requestWithURL:"http://www.flickr.com/services/rest/?method=flickr.interestingness.getList&per_page=20&format=json&api_key=ca4dd89d3dfaeaf075144c3fdec76756"];
// see important note about CPJSONPConnection above
var connection = [CPJSONPConnection sendRequest:request callback:"jsoncallback" delegate:self];
lastIdentifier = "Interesting Photos";
}
- (void)add:(id)sender
{
var string = prompt("Enter a tag to search Flickr for photos.");
if (string)
{
//create a new request for the photos with the tag returned from the javascript prompt
var request = [CPURLRequest requestWithURL:"http://www.flickr.com/services/rest/?"+
"method=flickr.photos.search&tags="+encodeURIComponent(string)+
"&media=photos&machine_tag_mode=any&per_page=20&format=json&api_key=ca4dd89d3dfaeaf075144c3fdec76756"];
// see important note about CPJSONPConnection above
[CPJSONPConnection sendRequest:request callback:"jsoncallback" delegate:self];
lastIdentifier = string;
}
}
- (void)remove:(id)sender
{
//remove this photo
[self removeImageListWithIdentifier:[[photosets allKeys] objectAtIndex:[[listCollectionView selectionIndexes] firstIndex]]];
}
- (void)addImageList:(CPArray)images withIdentifier:(CPString)aString
{
[photosets setObject:images forKey:aString];
[listCollectionView setContent:[[photosets allKeys] copy]];
[listCollectionView setSelectionIndexes:[CPIndexSet indexSetWithIndex:[[photosets allKeys] indexOfObject:aString]]];
}
- (void)removeImageListWithIdentifier:(CPString)aString
{
var nextIndex = MAX([[listCollectionView content] indexOfObject:aString] - 1, 0);
[photosets removeObjectForKey:aString];
[listCollectionView setContent:[[photosets allKeys] copy]];
[listCollectionView setSelectionIndexes:[CPIndexSet indexSetWithIndex:nextIndex]];
}
- (void)adjustImageSize:(id)sender
{
var newSize = [sender value];
[photosCollectionView setMinItemSize:CGSizeMake(newSize, newSize)];
[photosCollectionView setMaxItemSize:CGSizeMake(newSize, newSize)];
}
- (void)collectionViewDidChangeSelection:(CPCollectionView)aCollectionView
{
if (aCollectionView == listCollectionView)
{
var listIndex = [[listCollectionView selectionIndexes] firstIndex];
if (listIndex === CPNotFound)
return;
var key = [listCollectionView content][listIndex];
[photosCollectionView setContent:[photosets objectForKey:key]];
[photosCollectionView setSelectionIndexes:[CPIndexSet indexSet]];
}
}
- (void)connection:(CPJSONPConnection)aConnection didReceiveData:(CPString)data
{
//this method is called when the network request returns. the data is the returned
//information from flickr. we set the array of photo urls as the data to our collection view
[self addImageList:data.photos.photo withIdentifier:lastIdentifier];
}
- (void)connection:(CPJSONPConnection)aConnection didFailWithError:(CPString)error
{
alert(error); //a network error occurred
}
//these two methods are the toolbar delegate methods, and tell the toolbar what it should display to the user
- (CPArray)toolbarAllowedItemIdentifiers:(CPToolbar)aToolbar
{
return [self toolbarDefaultItemIdentifiers:aToolbar];
}
- (CPArray)toolbarDefaultItemIdentifiers:(CPToolbar)aToolbar
{
return [AddToolbarItemIdentifier, RemoveToolbarItemIdentifier, CPToolbarFlexibleSpaceItemIdentifier, SliderToolbarItemIdentifier];
}
//this delegate method returns the actual toolbar item for the given identifier
- (CPToolbarItem)toolbar:(CPToolbar)aToolbar itemForItemIdentifier:(CPString)anItemIdentifier willBeInsertedIntoToolbar:(BOOL)aFlag
{
var toolbarItem = [[CPToolbarItem alloc] initWithItemIdentifier:anItemIdentifier];
if (anItemIdentifier == SliderToolbarItemIdentifier)
{
[toolbarItem setView:[[PhotoResizeView alloc] initWithFrame:CGRectMake(0, 0, 180, 32)]];
[toolbarItem setMinSize:CGSizeMake(180, 32)];
[toolbarItem setMaxSize:CGSizeMake(180, 32)];
[toolbarItem setLabel:"Scale"];
}
else if (anItemIdentifier == AddToolbarItemIdentifier)
{
var image = [[CPImage alloc] initWithContentsOfFile:[[CPBundle mainBundle] pathForResource:"add.png"] size:CPSizeMake(30, 25)],
highlighted = [[CPImage alloc] initWithContentsOfFile:[[CPBundle mainBundle] pathForResource:"addHighlighted.png"] size:CPSizeMake(30, 25)];
[toolbarItem setImage:image];
[toolbarItem setAlternateImage:highlighted];
[toolbarItem setTarget:self];
[toolbarItem setAction:@selector(add:)];
[toolbarItem setLabel:"Add Photo List"];
[toolbarItem setMinSize:CGSizeMake(32, 32)];
[toolbarItem setMaxSize:CGSizeMake(32, 32)];
}
else if (anItemIdentifier == RemoveToolbarItemIdentifier)
{
var image = [[CPImage alloc] initWithContentsOfFile:[[CPBundle mainBundle] pathForResource:"remove.png"] size:CPSizeMake(30, 25)],
highlighted = [[CPImage alloc] initWithContentsOfFile:[[CPBundle mainBundle] pathForResource:"removeHighlighted.png"] size:CPSizeMake(30, 25)];
[toolbarItem setImage:image];
[toolbarItem setAlternateImage:highlighted];
[toolbarItem setTarget:self];
[toolbarItem setAction:@selector(remove:)];
[toolbarItem setLabel:"Remove Photo List"];
[toolbarItem setMinSize:CGSizeMake(32, 32)];
[toolbarItem setMaxSize:CGSizeMake(32, 32)];
}
return toolbarItem;
}
@end
/*
This code demonstrates how to add a category to an existing class.
In this case, we are adding the class method +flickr_labelWithText: to
the CPTextField class. Later on, we can call [CPTextField flickr_labelWithText:"foo"]
to return a new text field with the string foo.
Best practices suggest prefixing category methods with your unique prefix, to prevent collisions.
*/
@implementation CPTextField (CreateLabel)
+ (CPTextField)flickr_labelWithText:(CPString)aString
{
var label = [[CPTextField alloc] initWithFrame:CGRectMakeZero()];
[label setStringValue:aString];
[label sizeToFit];
[label setTextShadowColor:[CPColor whiteColor]];
[label setTextShadowOffset:CGSizeMake(0, 1)];
return label;
}
@end
// This class wraps our slider + labels combo
@implementation PhotoResizeView : CPView
{
}
- (id)initWithFrame:(CGRect)aFrame
{
self = [super initWithFrame:aFrame];
var slider = [[CPSlider alloc] initWithFrame:CGRectMake(30, CGRectGetHeight(aFrame) / 2.0 - 8, CGRectGetWidth(aFrame) - 65, 24)];
[slider setMinValue:50.0];
[slider setMaxValue:250.0];
[slider setIntValue:150.0];
[slider setAction:@selector(adjustImageSize:)];
[self addSubview:slider];
var label = [CPTextField flickr_labelWithText:"50"];
[label setFrameOrigin:CGPointMake(0, CGRectGetHeight(aFrame) / 2.0 - 4.0)];
[self addSubview:label];
label = [CPTextField flickr_labelWithText:"250"];
[label setFrameOrigin:CGPointMake(CGRectGetWidth(aFrame) - CGRectGetWidth([label frame]), CGRectGetHeight(aFrame) / 2.0 - 4.0)];
[self addSubview:label];
return self;
}
@end
// This class displays a single photo collection inside our list of photo collecitions
@implementation PhotosListCell : CPView
{
CPTextField label;
CPView highlightView;
}
- (void)setRepresentedObject:(JSObject)anObject
{
if (!label)
{
label = [[CPTextField alloc] initWithFrame:CGRectInset([self bounds], 4, 4)];
[label setFont:[CPFont systemFontOfSize:16.0]];
[label setTextShadowColor:[CPColor whiteColor]];
[label setTextShadowOffset:CGSizeMake(0, 1)];
[self addSubview:label];
}
[label setStringValue:anObject];
[label sizeToFit];
[label setFrameOrigin:CGPointMake(10,CGRectGetHeight([label bounds]) / 2.0)];
}
- (void)setSelected:(BOOL)flag
{
if (!highlightView)
{
highlightView = [[CPView alloc] initWithFrame:CGRectCreateCopy([self bounds])];
[highlightView setBackgroundColor:[CPColor blueColor]];
}
if (flag)
{
[self addSubview:highlightView positioned:CPWindowBelow relativeTo:label];
[label setTextColor:[CPColor whiteColor]];
[label setTextShadowColor:[CPColor blackColor]];
}
else
{
[highlightView removeFromSuperview];
[label setTextColor:[CPColor blackColor]];
[label setTextShadowColor:[CPColor whiteColor]];
}
}
@end
// This class displays a single photo from our collection
@implementation PhotoCell : CPView
{
CPImage image;
CPImageView imageView;
CPView highlightView;
}
- (void)setRepresentedObject:(JSObject)anObject
{
if (!imageView)
{
imageView = [[CPImageView alloc] initWithFrame:CGRectMakeCopy([self bounds])];
[imageView setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable];
[imageView setImageScaling:CPScaleProportionally];
[imageView setHasShadow:YES];
[self addSubview:imageView];
}
[image setDelegate:nil];
image = [[CPImage alloc] initWithContentsOfFile:thumbForFlickrPhoto(anObject)];
[image setDelegate:self];
if ([image loadStatus] == CPImageLoadStatusCompleted)
[imageView setImage:image];
else
[imageView setImage:nil];
}
- (void)imageDidLoad:(CPImage)anImage
{
[imageView setImage:anImage];
}
- (void)setSelected:(BOOL)flag
{
if (!highlightView)
{
highlightView = [[CPView alloc] initWithFrame:[self bounds]];
[highlightView setBackgroundColor:[CPColor colorWithCalibratedWhite:0.8 alpha:0.6]];
[highlightView setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable];
}
if (flag)
{
[highlightView setFrame:[self bounds]];
[self addSubview:highlightView positioned:CPWindowBelow relativeTo:imageView];
}
else
[highlightView removeFromSuperview];
}
@end
// helper javascript functions for turning a Flickr photo object into a URL for getting the image
function urlForFlickrPhoto(photo)
{
return "http://farm" + photo.farm + ".static.flickr.com/" + photo.server + "/" + photo.id+"_" + photo.secret + ".jpg";
}
function thumbForFlickrPhoto(photo)
{
return "http://farm" + photo.farm + ".static.flickr.com/" + photo.server + "/" + photo.id + "_" + photo.secret + "_m.jpg";
}

View File

@@ -0,0 +1,88 @@
@import <Foundation/CPObject.j>
@import <AppKit/CPView.j>
@import <AppKit/CPButton.j>
@import <AppKit/CPWebView.j>
@import "LOBoard.j"
@implementation LOInfoView : CPView
{
}
- (void)drawRect:(CGRect)r
{
[[CPColor whiteColor] setFill]
var path = [CPBezierPath bezierPath];
[path appendBezierPathWithRoundedRect:CGRectMake(5, 0, CGRectGetWidth([self bounds]) - 10.0, CGRectGetHeight([self bounds])) xRadius:10 yRadius:10];
[path fill];
}
@end
@implementation AppController : CPObject
{
}
- (CPPanel)initInfoWindow
{
var infoWindow = [[CPPanel alloc] initWithContentRect:CGRectMake(400, 50, 320, 480) styleMask:CPHUDBackgroundWindowMask | CPResizableWindowMask];
[infoWindow setFloatingPanel:YES];
var _infoContent = [infoWindow contentView],
_iconImage = [[CPImage alloc] initWithContentsOfFile:"Resources/icon.png" size:CPSizeMake(59, 60)],
_iconView = [[CPImageView alloc] initWithFrame:CGRectMake(125, 0, 59, 60)];
[_iconView setImage:_iconImage];
[_infoContent addSubview:_iconView];
var _infoView = [[LOInfoView alloc] initWithFrame:CGRectMake(0, 65, 320, 395)],
_webView = [[CPWebView alloc] initWithFrame:CGRectMake(20, 0, 270, 370)];
[_webView loadHTMLString:@"<center><h3>Lights Off</h3></center> <p>Lights Off is a fantastic game exclusively for iPhone and iPod touch and inspired by Tiger Electronic's 'Lights Out'.</p> <p>The goal of the game is simply to switch all of the lights off, but it's harder than it looks! Give the first few levels a try in the playable demo to the left.</p><center><img src='Resources/avail_on_app_store.png'></center>"];
[_infoView addSubview:_webView];
[_infoContent addSubview:_infoView];
return infoWindow;
}
- (void)applicationDidFinishLaunching:(CPNotification)aNotification
{
/* Enable Logging (DEBUG) */
// CPLogRegister(CPLogPopup);
var rootWindow = [[CPWindow alloc] initWithContentRect:CGRectMakeZero() styleMask:CPBorderlessBridgeWindowMask];
[rootWindow setBackgroundColor:[CPColor grayColor]];
[rootWindow orderFront:self];
var infoWindow = [self initInfoWindow],
gameWindow = [[CPPanel alloc] initWithContentRect:CGRectMake(50, 50, 324, 482) styleMask:CPHUDBackgroundWindowMask];
[gameWindow setFloatingPanel:YES];
[gameWindow setTitle:@"Lights Off"];
contentView = [gameWindow contentView];
var _board = [[LOBoard alloc] initWithFrame:CGRectMake(2, 0, 320, 480)],
_bgImage = [[CPImage alloc] initWithContentsOfFile:"Resources/lo-background.png" size:CPSizeMake(320, 480)];
[_board setImage:_bgImage];
[_board resetBoard];
var _buttonImage = [[CPImage alloc] initWithContentsOfFile:"Resources/button-reset.png" size:CPSizeMake(90, 28)],
_buttonPressImage = [[CPImage alloc] initWithContentsOfFile:"Resources/button-reset-press.png" size:CPSizeMake(90, 28)],
_resetButton = [[CPButton alloc] initWithFrame:CGRectMake(195, 422, 90, 28)];
[_resetButton setImage:_buttonImage];
[_resetButton setAlternateImage:_buttonPressImage];
[_resetButton setBordered:NO];
[contentView addSubview:_board];
[contentView addSubview:_resetButton];
[_resetButton setTarget:_board];
[_resetButton setAction:@selector(resetBoard)];
[gameWindow orderFront:self];
[infoWindow orderFront:self];
}
@end

View File

@@ -0,0 +1,47 @@
@import <Foundation/CPObject.j>
@implementation AppController : CPObject
{
}
- (void)applicationDidFinishLaunching:(CPNotification)aNotification
{
// The end result of this layout will be the kind of master/detail/auxilliary view
// found in iTunes, Mail, and many other apps.
var theWindow = [[CPWindow alloc] initWithContentRect:CGRectMakeZero() styleMask:CPBorderlessBridgeWindowMask],
contentView = [theWindow contentView];
var navigationArea = [[CPView alloc] initWithFrame:CGRectMake(0.0, 0.0, 150.0, CGRectGetHeight([contentView bounds]) - 150.0)];
[navigationArea setBackgroundColor:[CPColor redColor]];
// This view will grow in height, but stay fixed width attached to the left side of the screen.
[navigationArea setAutoresizingMask:CPViewHeightSizable | CPViewMaxXMargin];
[contentView addSubview:navigationArea];
var metaDataArea = [[CPView alloc] initWithFrame:CGRectMake(0.0, CGRectGetMaxY([navigationArea frame]), 150.0, 150.0)];
[metaDataArea setBackgroundColor:[CPColor greenColor]];
// This view will stay the same size in both directions, and fixed to the lower left corner.
[metaDataArea setAutoresizingMask:CPViewMinYMargin | CPViewMaxXMargin];
[contentView addSubview:metaDataArea];
var contentArea = [[CPView alloc] initWithFrame:CGRectMake(150.0, 0.0, CGRectGetWidth([contentView bounds]) - 150.0, CGRectGetHeight([contentView bounds]))];
[contentArea setBackgroundColor:[CPColor blueColor]];
// This view will grow in both height an width.
[contentArea setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable];
[contentView addSubview:contentArea];
[theWindow orderFront:self];
}
@end