rubymotionr 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +2 -0
- data/.rspec +2 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +24 -0
- data/LICENSE.txt +22 -0
- data/README.md +31 -0
- data/Rakefile +1 -0
- data/lib/rubymotionr.rb +7 -0
- data/lib/rubymotionr/project.rb +18 -0
- data/lib/rubymotionr/repo.rb +18 -0
- data/lib/rubymotionr/version.rb +3 -0
- data/rubymotionr.gemspec +19 -0
- data/spec/.DS_Store +0 -0
- data/spec/multiple-rubymotion-apps/Beers/README +5 -0
- data/spec/multiple-rubymotion-apps/Beers/Rakefile +8 -0
- data/spec/multiple-rubymotion-apps/Beers/app/app_delegate.rb +16 -0
- data/spec/multiple-rubymotion-apps/Beers/app/beer.rb +22 -0
- data/spec/multiple-rubymotion-apps/Beers/app/beer_details_controller.rb +15 -0
- data/spec/multiple-rubymotion-apps/Beers/app/beer_list_controller.rb +40 -0
- data/spec/multiple-rubymotion-apps/Beers/app/beer_map_controller.rb +51 -0
- data/spec/multiple-rubymotion-apps/Beers/resources/.gitignore +0 -0
- data/spec/multiple-rubymotion-apps/Beers/resources/list.png +0 -0
- data/spec/multiple-rubymotion-apps/Beers/resources/map.png +0 -0
- data/spec/multiple-rubymotion-apps/CircleLayout/.gitignore +5 -0
- data/spec/multiple-rubymotion-apps/CircleLayout/README +5 -0
- data/spec/multiple-rubymotion-apps/CircleLayout/Rakefile +9 -0
- data/spec/multiple-rubymotion-apps/CircleLayout/app/app_delegate.rb +8 -0
- data/spec/multiple-rubymotion-apps/CircleLayout/app/cell.rb +13 -0
- data/spec/multiple-rubymotion-apps/CircleLayout/app/circle_layout.rb +41 -0
- data/spec/multiple-rubymotion-apps/CircleLayout/app/view_controller.rb +33 -0
- data/spec/multiple-rubymotion-apps/Fonts/README +7 -0
- data/spec/multiple-rubymotion-apps/Fonts/Rakefile +8 -0
- data/spec/multiple-rubymotion-apps/Fonts/app/app_delegate.rb +9 -0
- data/spec/multiple-rubymotion-apps/Fonts/app/detail_controller.rb +50 -0
- data/spec/multiple-rubymotion-apps/Fonts/app/root_controller.rb +65 -0
- data/spec/multiple-rubymotion-apps/Fonts/resources/.gitkeep +0 -0
- data/spec/multiple-rubymotion-apps/GestureTable/README +8 -0
- data/spec/multiple-rubymotion-apps/GestureTable/Rakefile +8 -0
- data/spec/multiple-rubymotion-apps/GestureTable/app/UIColor_extensions.rb +32 -0
- data/spec/multiple-rubymotion-apps/GestureTable/app/UITableView_extensions.rb +7 -0
- data/spec/multiple-rubymotion-apps/GestureTable/app/app_delegate.rb +9 -0
- data/spec/multiple-rubymotion-apps/GestureTable/app/gesture_recognizer.rb +361 -0
- data/spec/multiple-rubymotion-apps/GestureTable/app/transformable_cells.rb +92 -0
- data/spec/multiple-rubymotion-apps/GestureTable/app/view_controller.rb +173 -0
- data/spec/multiple-rubymotion-apps/GestureTable/resources/.gitignore +0 -0
- data/spec/multiple-rubymotion-apps/Hello/README +3 -0
- data/spec/multiple-rubymotion-apps/Hello/Rakefile +8 -0
- data/spec/multiple-rubymotion-apps/Hello/app/app_delegate.rb +9 -0
- data/spec/multiple-rubymotion-apps/Hello/app/hello_view.rb +33 -0
- data/spec/multiple-rubymotion-apps/Hello/app/hello_view_controller.rb +5 -0
- data/spec/multiple-rubymotion-apps/Hello/resources/.gitignore +0 -0
- data/spec/multiple-rubymotion-apps/Hello/resources/icon.png +0 -0
- data/spec/multiple-rubymotion-apps/HelloGL/README +9 -0
- data/spec/multiple-rubymotion-apps/HelloGL/Rakefile +11 -0
- data/spec/multiple-rubymotion-apps/HelloGL/app/app_delegate.rb +16 -0
- data/spec/multiple-rubymotion-apps/HelloGL/app/index_data.rb +19 -0
- data/spec/multiple-rubymotion-apps/HelloGL/app/motiongl_controller.rb +139 -0
- data/spec/multiple-rubymotion-apps/HelloGL/app/vertex_data.rb +22 -0
- data/spec/multiple-rubymotion-apps/HelloGL/resources/rubymotion.png +0 -0
- data/spec/multiple-rubymotion-apps/Locations/README +3 -0
- data/spec/multiple-rubymotion-apps/Locations/Rakefile +8 -0
- data/spec/multiple-rubymotion-apps/Locations/app/app_delegate.rb +11 -0
- data/spec/multiple-rubymotion-apps/Locations/app/location.rb +21 -0
- data/spec/multiple-rubymotion-apps/Locations/app/locations_controller.rb +66 -0
- data/spec/multiple-rubymotion-apps/Locations/app/locations_store.rb +61 -0
- data/spec/multiple-rubymotion-apps/Locations/resources/.gitignore +0 -0
- data/spec/multiple-rubymotion-apps/Mustache/README +5 -0
- data/spec/multiple-rubymotion-apps/Mustache/Rakefile +10 -0
- data/spec/multiple-rubymotion-apps/Mustache/app/app_delegate.rb +9 -0
- data/spec/multiple-rubymotion-apps/Mustache/app/mustache_view_controller.rb +99 -0
- data/spec/multiple-rubymotion-apps/Mustache/resources/.gitignore +0 -0
- data/spec/multiple-rubymotion-apps/Mustache/resources/guido.jpg +0 -0
- data/spec/multiple-rubymotion-apps/Mustache/resources/jmccolor.jpg +0 -0
- data/spec/multiple-rubymotion-apps/Mustache/resources/kay.jpg +0 -0
- data/spec/multiple-rubymotion-apps/Mustache/resources/matz.jpg +0 -0
- data/spec/multiple-rubymotion-apps/Mustache/resources/mustache.png +0 -0
- data/spec/multiple-rubymotion-apps/Paint/README +3 -0
- data/spec/multiple-rubymotion-apps/Paint/Rakefile +8 -0
- data/spec/multiple-rubymotion-apps/Paint/app/app_delegate.rb +9 -0
- data/spec/multiple-rubymotion-apps/Paint/app/paint_view.rb +57 -0
- data/spec/multiple-rubymotion-apps/Paint/app/paint_view_controller.rb +13 -0
- data/spec/multiple-rubymotion-apps/Paint/resources/.gitignore +0 -0
- data/spec/multiple-rubymotion-apps/Paint/resources/erase.caf +0 -0
- data/spec/multiple-rubymotion-apps/PaintHTML/README +8 -0
- data/spec/multiple-rubymotion-apps/PaintHTML/Rakefile +10 -0
- data/spec/multiple-rubymotion-apps/PaintHTML/app/app_delegate.rb +10 -0
- data/spec/multiple-rubymotion-apps/PaintHTML/app/web_view_controller.rb +48 -0
- data/spec/multiple-rubymotion-apps/PaintHTML/resources/index.html +211 -0
- data/spec/multiple-rubymotion-apps/PaintHTML/resources/index2.html +14 -0
- data/spec/multiple-rubymotion-apps/README.rdoc +47 -0
- data/spec/multiple-rubymotion-apps/StoryboardCustoms/README.md +42 -0
- data/spec/multiple-rubymotion-apps/StoryboardCustoms/Rakefile +7 -0
- data/spec/multiple-rubymotion-apps/StoryboardCustoms/app/app_delegate.rb +12 -0
- data/spec/multiple-rubymotion-apps/StoryboardCustoms/app/custom_view_controller1.rb +31 -0
- data/spec/multiple-rubymotion-apps/StoryboardCustoms/app/custom_view_controller2.rb +29 -0
- data/spec/multiple-rubymotion-apps/StoryboardCustoms/app/helpers.rb +4 -0
- data/spec/multiple-rubymotion-apps/StoryboardCustoms/resources/Master.storyboard +127 -0
- data/spec/multiple-rubymotion-apps/TicTacToe/.gitignore +5 -0
- data/spec/multiple-rubymotion-apps/TicTacToe/Rakefile +7 -0
- data/spec/multiple-rubymotion-apps/TicTacToe/app/app_delegate.rb +8 -0
- data/spec/multiple-rubymotion-apps/TicTacToe/app/board.rb +59 -0
- data/spec/multiple-rubymotion-apps/TicTacToe/app/board_view_controller.rb +86 -0
- data/spec/multiple-rubymotion-apps/Timer/README +3 -0
- data/spec/multiple-rubymotion-apps/Timer/Rakefile +7 -0
- data/spec/multiple-rubymotion-apps/Timer/app/app_delegate.rb +9 -0
- data/spec/multiple-rubymotion-apps/Timer/app/timer_controller.rb +38 -0
- data/spec/multiple-rubymotion-apps/Timer/resources/.gitignore +0 -0
- data/spec/multiple-rubymotion-apps/Trollify/README +6 -0
- data/spec/multiple-rubymotion-apps/Trollify/Rakefile +9 -0
- data/spec/multiple-rubymotion-apps/Trollify/app/app_delegate.rb +9 -0
- data/spec/multiple-rubymotion-apps/Trollify/app/image_composition_controller.rb +193 -0
- data/spec/multiple-rubymotion-apps/Trollify/app/uiimage_extension.rb +27 -0
- data/spec/multiple-rubymotion-apps/Trollify/resources/.gitignore +0 -0
- data/spec/multiple-rubymotion-apps/Trollify/resources/ballmer.jpg +0 -0
- data/spec/multiple-rubymotion-apps/Trollify/resources/icon.png +0 -0
- data/spec/multiple-rubymotion-apps/Trollify/resources/icon@2x.png +0 -0
- data/spec/multiple-rubymotion-apps/Trollify/resources/trollface.png +0 -0
- data/spec/multiple-rubymotion-apps/Tweets/README +3 -0
- data/spec/multiple-rubymotion-apps/Tweets/Rakefile +7 -0
- data/spec/multiple-rubymotion-apps/Tweets/app/app_delegate.rb +9 -0
- data/spec/multiple-rubymotion-apps/Tweets/app/data_parser.rb +10 -0
- data/spec/multiple-rubymotion-apps/Tweets/app/json_parser.rb +12 -0
- data/spec/multiple-rubymotion-apps/Tweets/app/tweet.rb +11 -0
- data/spec/multiple-rubymotion-apps/Tweets/app/tweet_cell.rb +51 -0
- data/spec/multiple-rubymotion-apps/Tweets/app/tweets_controller.rb +72 -0
- data/spec/multiple-rubymotion-apps/Tweets/resources/.gitignore +0 -0
- data/spec/repo_spec.rb +27 -0
- data/spec/rubymotion-example/.DS_Store +0 -0
- data/spec/rubymotion-example/README +3 -0
- data/spec/rubymotion-example/Rakefile +7 -0
- data/spec/rubymotion-example/app/app_delegate.rb +9 -0
- data/spec/rubymotion-example/app/data_parser.rb +10 -0
- data/spec/rubymotion-example/app/json_parser.rb +12 -0
- data/spec/rubymotion-example/app/tweet.rb +11 -0
- data/spec/rubymotion-example/app/tweet_cell.rb +51 -0
- data/spec/rubymotion-example/app/tweets_controller.rb +72 -0
- data/spec/rubymotion-example/resources/.gitignore +0 -0
- data/spec/spec_helper.rb +9 -0
- metadata +309 -0
|
File without changes
|
|
Binary file
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
PaintHTML.app
|
|
2
|
+
|
|
3
|
+
This sample demonstrates the following concepts: WebView, HTML5 backend.
|
|
4
|
+
|
|
5
|
+
This sample shows how to wrap a full-screen HTML5 app into a RubyMotion app.
|
|
6
|
+
It was contributed by Thijs van der Vossen.
|
|
7
|
+
|
|
8
|
+
https://github.com/tvandervossen/motion-webview
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
$:.unshift("/Library/RubyMotion/lib")
|
|
2
|
+
require 'motion/project'
|
|
3
|
+
|
|
4
|
+
Motion::Project::App.setup do |app|
|
|
5
|
+
# Use `rake config' to see complete project settings.
|
|
6
|
+
app.name = 'WebView'
|
|
7
|
+
app.device_family = [:iphone, :ipad]
|
|
8
|
+
# Set the status bar style, other options are UIStatusBarStyleDefault and UIStatusBarStyleBlackOpaque
|
|
9
|
+
app.info_plist['UIStatusBarStyle'] = 'UIStatusBarStyleBlackTranslucent'
|
|
10
|
+
end
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
class AppDelegate
|
|
2
|
+
def application(application, didFinishLaunchingWithOptions:launchOptions)
|
|
3
|
+
# Remove the following line if you don't want the status bar to be hidden
|
|
4
|
+
UIApplication.sharedApplication.setStatusBarHidden(true, withAnimation:UIStatusBarAnimationFade)
|
|
5
|
+
@window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds)
|
|
6
|
+
@window.rootViewController = WebViewController.alloc.init
|
|
7
|
+
@window.makeKeyAndVisible
|
|
8
|
+
true
|
|
9
|
+
end
|
|
10
|
+
end
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
class WebViewController < UIViewController
|
|
2
|
+
def loadView
|
|
3
|
+
# Background color while loading and scrolling beyond the page boundaries
|
|
4
|
+
background = UIColor.blackColor
|
|
5
|
+
self.view = UIView.alloc.initWithFrame(UIScreen.mainScreen.applicationFrame)
|
|
6
|
+
self.view.backgroundColor = background
|
|
7
|
+
webFrame = UIScreen.mainScreen.applicationFrame
|
|
8
|
+
webFrame.origin.y = 0.0
|
|
9
|
+
@webView = UIWebView.alloc.initWithFrame(webFrame)
|
|
10
|
+
@webView.backgroundColor = background
|
|
11
|
+
@webView.scalesPageToFit = true
|
|
12
|
+
@webView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)
|
|
13
|
+
@webView.delegate = self
|
|
14
|
+
@webView.loadRequest(NSURLRequest.requestWithURL(NSURL.fileURLWithPath(NSBundle.mainBundle.pathForResource('index2', ofType:'html'))))
|
|
15
|
+
# @webView.loadRequest(NSURLRequest.requestWithURL(NSURL.URLWithString("http://www.fngtps.com/")))
|
|
16
|
+
# @webView.loadHTMLString('<h1><a href="http://www.fngtps.com">Click me!</h1>', baseURL:nil)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# Remove the following if you're showing a status bar that's not translucent
|
|
20
|
+
def wantsFullScreenLayout
|
|
21
|
+
true
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# Only add the web view when the page has finished loading
|
|
25
|
+
def webViewDidFinishLoad(webView)
|
|
26
|
+
self.view.addSubview(@webView)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# Enable rotation
|
|
30
|
+
def shouldAutorotateToInterfaceOrientation(interfaceOrientation)
|
|
31
|
+
# On the iPhone, don't rotate to upside-down portrait orientation
|
|
32
|
+
if UIDevice.currentDevice.userInterfaceIdiom != UIUserInterfaceIdiomPad
|
|
33
|
+
if interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown
|
|
34
|
+
return false
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
true
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# Open absolute links in Mobile Safari
|
|
41
|
+
def webView(inWeb, shouldStartLoadWithRequest:inRequest, navigationType:inType)
|
|
42
|
+
if inType == UIWebViewNavigationTypeLinkClicked && inRequest.URL.scheme != 'file'
|
|
43
|
+
UIApplication.sharedApplication.openURL(inRequest.URL)
|
|
44
|
+
return false
|
|
45
|
+
end
|
|
46
|
+
true
|
|
47
|
+
end
|
|
48
|
+
end
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<meta name="viewport" content="initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no">
|
|
6
|
+
<title>Sketch</title>
|
|
7
|
+
<style>
|
|
8
|
+
body
|
|
9
|
+
{
|
|
10
|
+
width: 100%;
|
|
11
|
+
height: 100%;
|
|
12
|
+
margin: 0;
|
|
13
|
+
padding: 0;
|
|
14
|
+
}
|
|
15
|
+
canvas
|
|
16
|
+
{
|
|
17
|
+
display: block;
|
|
18
|
+
width: 100%;
|
|
19
|
+
height: 100%;
|
|
20
|
+
}
|
|
21
|
+
</style>
|
|
22
|
+
</head>
|
|
23
|
+
<body>
|
|
24
|
+
|
|
25
|
+
<canvas id="canvas"></canvas>
|
|
26
|
+
|
|
27
|
+
<script>
|
|
28
|
+
var canvas = document.getElementById('canvas');
|
|
29
|
+
canvas.width = canvas.offsetWidth;
|
|
30
|
+
canvas.height = canvas.offsetHeight;
|
|
31
|
+
var context = canvas.getContext("2d");
|
|
32
|
+
|
|
33
|
+
var isDown = false;
|
|
34
|
+
var stroke = [];
|
|
35
|
+
var strokes = {};
|
|
36
|
+
var pixels;
|
|
37
|
+
|
|
38
|
+
clearCanvas();
|
|
39
|
+
|
|
40
|
+
context.lineWidth = 5;
|
|
41
|
+
context.lineCap = 'round';
|
|
42
|
+
context.strokeStyle = 'white';
|
|
43
|
+
|
|
44
|
+
canvas.addEventListener('mousedown', mouseDown, false);
|
|
45
|
+
canvas.addEventListener('mousemove', mouseMove, false);
|
|
46
|
+
canvas.addEventListener('mouseup', mouseUpOrOut, false);
|
|
47
|
+
canvas.addEventListener('mouseout', mouseUpOrOut, false);
|
|
48
|
+
|
|
49
|
+
canvas.addEventListener('touchstart', touchStart, false);
|
|
50
|
+
canvas.addEventListener('touchmove', touchMove, false);
|
|
51
|
+
canvas.addEventListener('touchend', touchEnd, false);
|
|
52
|
+
|
|
53
|
+
canvas.addEventListener('touchstart', function(e) { e.preventDefault() }, false);
|
|
54
|
+
|
|
55
|
+
function getMousePosition(e) {
|
|
56
|
+
var p = {};
|
|
57
|
+
if (e.pageX || e.pageY) {
|
|
58
|
+
p.x = e.pageX;
|
|
59
|
+
p.y = e.pageY;
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
p.x = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
|
|
63
|
+
p.y = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
|
|
64
|
+
}
|
|
65
|
+
p.x -= canvas.offsetLeft;
|
|
66
|
+
p.y -= canvas.offsetTop;
|
|
67
|
+
return p;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function getTouchPosition(touch) {
|
|
71
|
+
var p = {};
|
|
72
|
+
p.x = touch.clientX + document.body.scrollLeft + document.documentElement.scrollLeft - canvas.offsetLeft;
|
|
73
|
+
p.y = touch.clientY + document.body.scrollTop + document.documentElement.scrollTop - canvas.offsetTop;
|
|
74
|
+
return p;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function smooth(a1, a2, b1, b2) {
|
|
78
|
+
var ua_t = (b2.x - b1.x) * (a1.y - b1.y) - (b2.y - b1.y) * (a1.x - b1.x);
|
|
79
|
+
var ub_t = (a2.x - a1.x) * (a1.y - b1.y) - (a2.y - a1.y) * (a1.x - b1.x);
|
|
80
|
+
var u_b = (b2.y - b1.y) * (a2.x - a1.x) - (b2.x - b1.x) * (a2.y - a1.y);
|
|
81
|
+
|
|
82
|
+
if ( u_b == 0 ) {
|
|
83
|
+
// parallel
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
var ua = ua_t / u_b;
|
|
88
|
+
var ub = ub_t / u_b;
|
|
89
|
+
|
|
90
|
+
if (ua > 6 || ua < -6 || ub > 6 || ub < -6) {
|
|
91
|
+
// intersection point too far from surrounding points; use average
|
|
92
|
+
return false
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// find intersection point
|
|
96
|
+
var x = a1.x + ua * (a2.x - a1.x);
|
|
97
|
+
var y = a1.y + ua * (a2.y - a1.y);
|
|
98
|
+
|
|
99
|
+
// average with surrounding points
|
|
100
|
+
x = (x + x + a2.x + b1.x) / 4;
|
|
101
|
+
y = (y + y + a2.y + b1.y) / 4;
|
|
102
|
+
|
|
103
|
+
return {x: x, y: y};
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function nearby(a, b) {
|
|
107
|
+
return Math.abs(a.x - b.x) < 5 && Math.abs(a.y - b.y) < 5;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function drawLine(from, to) {
|
|
111
|
+
context.beginPath();
|
|
112
|
+
context.moveTo(from.x, from.y);
|
|
113
|
+
context.lineTo(to.x, to.y);
|
|
114
|
+
context.stroke();
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function drawStroke(original_points) {
|
|
118
|
+
var points = [original_points[0]];
|
|
119
|
+
var control;
|
|
120
|
+
|
|
121
|
+
for (i=1; i<original_points.length-1; i++) {
|
|
122
|
+
if (!nearby(points[points.length-1], original_points[i])) {
|
|
123
|
+
points.push(original_points[i])
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
points.push(original_points[original_points.length-1])
|
|
127
|
+
|
|
128
|
+
context.beginPath();
|
|
129
|
+
for (i=0; i<points.length-1; i++) {
|
|
130
|
+
context.moveTo(points[i].x, points[i].y);
|
|
131
|
+
if (i < 2 || i > points.length-3) {
|
|
132
|
+
context.lineTo(points[i+1].x, points[i+1].y);
|
|
133
|
+
} else {
|
|
134
|
+
control = smooth(points[i-1], points[i], points[i+1], points[i+2]);
|
|
135
|
+
if (!control) {
|
|
136
|
+
context.lineTo(points[i+1].x, points[i+1].y);
|
|
137
|
+
} else {
|
|
138
|
+
context.quadraticCurveTo(control.x, control.y, points[i+1].x, points[i+1].y);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
context.stroke();
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function mouseDown(e) {
|
|
146
|
+
stroke.push(getMousePosition(e));
|
|
147
|
+
isDown = true;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function mouseMove(e) {
|
|
151
|
+
if (isDown) {
|
|
152
|
+
stroke.push(getMousePosition(e));
|
|
153
|
+
var l = stroke.length;
|
|
154
|
+
drawLine(stroke[l-2], stroke[l-1]);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function mouseUpOrOut(e) {
|
|
159
|
+
if (isDown) {
|
|
160
|
+
stroke.push(getMousePosition(e));
|
|
161
|
+
context.putImageData(pixels, 0, 0);
|
|
162
|
+
drawStroke(stroke);
|
|
163
|
+
pixels = context.getImageData(0, 0, canvas.width, canvas.height);
|
|
164
|
+
stroke = [];
|
|
165
|
+
isDown = false;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function touchStart(e) {
|
|
170
|
+
for (i=0; i<e.changedTouches.length ;i++) {
|
|
171
|
+
var touch = e.changedTouches[i];
|
|
172
|
+
strokes[touch.identifier] = [getTouchPosition(touch)];
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function touchMove(e) {
|
|
177
|
+
for (i=0; i<e.changedTouches.length ;i++) {
|
|
178
|
+
var touch = e.changedTouches[i];
|
|
179
|
+
strokes[touch.identifier].push(getTouchPosition(touch));
|
|
180
|
+
var l = strokes[touch.identifier].length;
|
|
181
|
+
drawLine(strokes[touch.identifier][l-2], strokes[touch.identifier][l-1]);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
function touchEnd(e) {
|
|
186
|
+
for (i=0; i<e.changedTouches.length ;i++) {
|
|
187
|
+
var touch = e.changedTouches[i];
|
|
188
|
+
}
|
|
189
|
+
if (e.touches.length == 0) {
|
|
190
|
+
context.putImageData(pixels, 0, 0);
|
|
191
|
+
var identifier;
|
|
192
|
+
for (identifier in strokes) {
|
|
193
|
+
if (strokes[identifier].length > 1) {
|
|
194
|
+
drawStroke(strokes[identifier]);
|
|
195
|
+
strokes[identifier] = [];
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
pixels = context.getImageData(0, 0, canvas.width, canvas.height);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
function clearCanvas() {
|
|
203
|
+
context.fillRect(0, 0, canvas.width, canvas.height);
|
|
204
|
+
stroke = [];
|
|
205
|
+
strokes = {};
|
|
206
|
+
pixels = context.getImageData(0, 0, canvas.width, canvas.height);
|
|
207
|
+
}
|
|
208
|
+
</script>
|
|
209
|
+
|
|
210
|
+
</body>
|
|
211
|
+
</html>
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<meta name="viewport" content="initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no">
|
|
6
|
+
<title>Sketch</title>
|
|
7
|
+
</head>
|
|
8
|
+
<body>
|
|
9
|
+
|
|
10
|
+
<a href="index.html">Relative link to drawing web app</a>
|
|
11
|
+
<a href="http://www.fngtps.com">Absolute link, should open in Mobile Safari</a>
|
|
12
|
+
|
|
13
|
+
</body>
|
|
14
|
+
</html>
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
= RubyMotion Samples
|
|
2
|
+
|
|
3
|
+
This repository contains a collection of RubyMotion examples.
|
|
4
|
+
|
|
5
|
+
== Requirements
|
|
6
|
+
|
|
7
|
+
* RubyMotion 1.0 or greater (see http://www.rubymotion.com).
|
|
8
|
+
|
|
9
|
+
== Projects
|
|
10
|
+
|
|
11
|
+
Each one of the sub-directories in this repository is a genuine RubyMotion project that demonstrates one or more particular features of iOS.
|
|
12
|
+
|
|
13
|
+
Check their +README+ files to know more. Type +rake+ from there to build and try the sample in the simulator. You can find the full source code from their +app+ directory.
|
|
14
|
+
|
|
15
|
+
For instance, to try the +Tweets+ sample:
|
|
16
|
+
|
|
17
|
+
$ cd Tweets
|
|
18
|
+
$ rake
|
|
19
|
+
|
|
20
|
+
If you have a sample to contribute, please create a pull request!
|
|
21
|
+
|
|
22
|
+
== License
|
|
23
|
+
|
|
24
|
+
All samples are covered by the MIT license. Feel free to reuse the source code in your projects.
|
|
25
|
+
|
|
26
|
+
Copyright (c) 2012 HipByte SPRL and Contributors
|
|
27
|
+
|
|
28
|
+
Permission is hereby granted, free of charge, to any person
|
|
29
|
+
obtaining a copy of this software and associated documentation
|
|
30
|
+
files (the “Software”), to deal in the Software without
|
|
31
|
+
restriction, including without limitation the rights to use,
|
|
32
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
33
|
+
copies of the Software, and to permit persons to whom the
|
|
34
|
+
Software is furnished to do so, subject to the following
|
|
35
|
+
conditions:
|
|
36
|
+
|
|
37
|
+
The above copyright notice and this permission notice shall be
|
|
38
|
+
included in all copies or substantial portions of the Software.
|
|
39
|
+
|
|
40
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
|
|
41
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
42
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
43
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
44
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
45
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
46
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
47
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# RubyMotion Storyboard With Automatic View-Loading
|
|
2
|
+
This is a [RubyMotion](http://www.rubymotion.com) sample project to demonstrate:
|
|
3
|
+
|
|
4
|
+
* Storyboard based view design
|
|
5
|
+
* view transition using segues
|
|
6
|
+
* automatic instatiation of **custom** ViewControllers via the storyboard
|
|
7
|
+
* passing variables to new VCs using prepareForSegue:sender: callback
|
|
8
|
+
|
|
9
|
+
* * *
|
|
10
|
+
|
|
11
|
+
The project was inpired by a great series of blog posts by @dalacv.
|
|
12
|
+
You can find his original project on [WordSearcher](https://github.com/dalacv/WordSearcher) on [GitHub](http://www.github.com).
|
|
13
|
+
His blog posts describing the project are located here:
|
|
14
|
+
|
|
15
|
+
* [Rubymotion and Storyboards](http://dangerousapps.com/blog/2012/05/08/rubymotion-and-storyboards/)
|
|
16
|
+
* [Rubymotion ViewController Setup And Uibutton Actions](http://dangerousapps.com/blog/2012/05/08/rubymotion-viewcontroller-setup-and-uibutton-actions/)
|
|
17
|
+
|
|
18
|
+
### **Note:** *you no longer need to compile the storybord manually RubyMotion 1.4 will take care of that.*
|
|
19
|
+
|
|
20
|
+
### My code is different in two points:
|
|
21
|
+
|
|
22
|
+
First it's using the segue machinism to load and move between views on the storyboard.
|
|
23
|
+
Second I'm only ever instanciating the rootViewController explicitly - all other view are created by the storyboard flow.
|
|
24
|
+
|
|
25
|
+
* * *
|
|
26
|
+
|
|
27
|
+
### What you'll see
|
|
28
|
+
|
|
29
|
+
When you run the app you're presented with a view with a text field.
|
|
30
|
+
This is managed by *CustomViewController1* - the text you put in the text field will be passed the the subview.
|
|
31
|
+
When you press the *To Subview* button the storyboard will create a new *CustomViewController2* instance,
|
|
32
|
+
let the current view configure it (using *prepareForSegue:sender:*) and push it to the navigation controller.
|
|
33
|
+
|
|
34
|
+
*CustomViewController2* consist of a label showing the text from it's parent (the text you entered) and a loop-button.
|
|
35
|
+
When the *Push Loop* button is pressed the storyboard will create another *CustomViewController1* and push that on the navigation controller.
|
|
36
|
+
|
|
37
|
+
To make it easier to distinguish the views each one has a greyed out label at the to showing the vies ruby object.
|
|
38
|
+
In addition to this you can observe the creation of new views in the REPL console as each ViewController will do some puts messages.
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
* * *
|
|
42
|
+
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
class AppDelegate
|
|
2
|
+
def application(application, didFinishLaunchingWithOptions:launchOptions)
|
|
3
|
+
@window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds)
|
|
4
|
+
|
|
5
|
+
storyboard = UIStoryboard.storyboardWithName("Master", bundle:nil)
|
|
6
|
+
rootVC = storyboard.instantiateViewControllerWithIdentifier("Main")
|
|
7
|
+
|
|
8
|
+
@window.rootViewController = rootVC
|
|
9
|
+
@window.makeKeyAndVisible
|
|
10
|
+
true
|
|
11
|
+
end
|
|
12
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
class CustomViewController1 < UIViewController
|
|
2
|
+
TAG_IDLABEL = 1
|
|
3
|
+
TAG_TEXTBOX = 2
|
|
4
|
+
|
|
5
|
+
def viewDidLoad
|
|
6
|
+
puts "#{self.to_s}: CustomViewController1::viewDidLoad"
|
|
7
|
+
self.title = "CustomVC1"
|
|
8
|
+
|
|
9
|
+
@idlabel = retrieve_subview_with_tag(self, TAG_IDLABEL)
|
|
10
|
+
@idlabel.text = self.to_s
|
|
11
|
+
|
|
12
|
+
@textbox = retrieve_subview_with_tag(self, TAG_TEXTBOX)
|
|
13
|
+
@textbox.delegate = self
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def prepareForSegue(segue, sender:sender)
|
|
17
|
+
puts "#{self.to_s}: CustomViewController1::prepareForSegue '#{segue.identifier}'"
|
|
18
|
+
|
|
19
|
+
if segue.identifier == "Subview"
|
|
20
|
+
customVC2 = segue.destinationViewController
|
|
21
|
+
customVC2.set_parent_id(self.to_s)
|
|
22
|
+
customVC2.customtext.text = @textbox.text
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# UITextFieldDelegate protocol (required to dismiss the keyboard)
|
|
27
|
+
def textFieldShouldReturn(textfield)
|
|
28
|
+
textfield.resignFirstResponder
|
|
29
|
+
true
|
|
30
|
+
end
|
|
31
|
+
end
|