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
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
class TransformableTableViewCell < UITableViewCell
|
|
2
|
+
attr_accessor :finishedHeight, :tintColor
|
|
3
|
+
|
|
4
|
+
def self.transformableTableViewCellWithStyle(style, reuseIdentifier: reuseIdentifier)
|
|
5
|
+
case style
|
|
6
|
+
when :pullDown
|
|
7
|
+
PullDownTableViewCell.alloc.initWithStyle(UITableViewCellStyleDefault, reuseIdentifier: reuseIdentifier)
|
|
8
|
+
when :unfolding
|
|
9
|
+
UnfoldingTableViewCell.alloc.initWithStyle(UITableViewCellStyleSubtitle, reuseIdentifier: reuseIdentifier)
|
|
10
|
+
else
|
|
11
|
+
raise ArgumentError, "Style must be :pullDown or :unfolding"
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
class UnfoldingTableViewCell < TransformableTableViewCell
|
|
17
|
+
def initWithStyle(style, reuseIdentifier: reuseIdentifier)
|
|
18
|
+
if super
|
|
19
|
+
transform = CATransform3DIdentity
|
|
20
|
+
transform.m34 = -1 / 500.to_f
|
|
21
|
+
contentView.layer.setSublayerTransform(transform)
|
|
22
|
+
|
|
23
|
+
textLabel.layer.anchorPoint = CGPointMake(0.5, 0.0)
|
|
24
|
+
detailTextLabel.layer.anchorPoint = CGPointMake(0.5, 1.0)
|
|
25
|
+
|
|
26
|
+
textLabel.autoresizingMask = UIViewAutoresizingFlexibleHeight
|
|
27
|
+
detailTextLabel.autoresizingMask = UIViewAutoresizingFlexibleHeight
|
|
28
|
+
|
|
29
|
+
self.selectionStyle = UITableViewCellSelectionStyleNone
|
|
30
|
+
self.tintColor = UIColor.whiteColor
|
|
31
|
+
end
|
|
32
|
+
self
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def layoutSubviews
|
|
36
|
+
super
|
|
37
|
+
|
|
38
|
+
fraction = self.frame.size.height / @finishedHeight.to_f
|
|
39
|
+
fraction = [[1, fraction].min, 0].max
|
|
40
|
+
|
|
41
|
+
angle = (Math::PI / 2) - Math.asin(fraction)
|
|
42
|
+
transform = CATransform3DMakeRotation(angle, -1, 0, 0)
|
|
43
|
+
textLabel.layer.setTransform(transform)
|
|
44
|
+
detailTextLabel.layer.setTransform(CATransform3DMakeRotation(angle, 1, 0, 0))
|
|
45
|
+
|
|
46
|
+
textLabel.backgroundColor = @tintColor.colorWithBrightness(0.3 + 0.7*fraction)
|
|
47
|
+
detailTextLabel.backgroundColor = @tintColor.colorWithBrightness(0.5 + 0.5*fraction)
|
|
48
|
+
|
|
49
|
+
contentViewSize = contentView.frame.size
|
|
50
|
+
contentViewMidY = contentViewSize.height / 2.0
|
|
51
|
+
labelHeight = @finishedHeight / 2.0
|
|
52
|
+
|
|
53
|
+
textLabel.frame = [[0, contentViewMidY - (labelHeight * fraction)], [contentViewSize.width, labelHeight + 1]]
|
|
54
|
+
detailTextLabel.frame = [[0, contentViewMidY - (labelHeight * (1 - fraction))], [contentViewSize.width, labelHeight]]
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
class PullDownTableViewCell < TransformableTableViewCell
|
|
59
|
+
def initWithStyle(style, reuseIdentifier: reuseIdentifier)
|
|
60
|
+
if super
|
|
61
|
+
transform = CATransform3DIdentity
|
|
62
|
+
transform.m34 = -1 / 500.to_f
|
|
63
|
+
contentView.layer.setSublayerTransform(transform)
|
|
64
|
+
|
|
65
|
+
textLabel.layer.anchorPoint = CGPointMake(0.5, 1.0)
|
|
66
|
+
textLabel.autoresizingMask = UIViewAutoresizingFlexibleHeight
|
|
67
|
+
|
|
68
|
+
self.selectionStyle = UITableViewCellSelectionStyleNone
|
|
69
|
+
|
|
70
|
+
@tintColor = UIColor.whiteColor
|
|
71
|
+
end
|
|
72
|
+
self
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def layoutSubviews
|
|
76
|
+
super
|
|
77
|
+
|
|
78
|
+
fraction = self.frame.size.height / @finishedHeight.to_f
|
|
79
|
+
fraction = [[1, fraction].min, 0].max
|
|
80
|
+
|
|
81
|
+
angle = (Math::PI / 2) - Math.asin(fraction)
|
|
82
|
+
transform = CATransform3DMakeRotation(angle, 1, 0, 0)
|
|
83
|
+
textLabel.layer.setTransform(transform)
|
|
84
|
+
|
|
85
|
+
textLabel.backgroundColor = @tintColor.colorWithBrightness(0.3 + 0.7*fraction)
|
|
86
|
+
|
|
87
|
+
contentViewSize = self.contentView.frame.size
|
|
88
|
+
labelHeight = @finishedHeight
|
|
89
|
+
|
|
90
|
+
self.textLabel.frame = [[0, contentViewSize.height - labelHeight], [contentViewSize.width, labelHeight]]
|
|
91
|
+
end
|
|
92
|
+
end
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
class ViewController < UITableViewController
|
|
2
|
+
AddingCell = 'Continue...'
|
|
3
|
+
DoneCell = 'Done'
|
|
4
|
+
DummyCell = 'Dummy'
|
|
5
|
+
CommittingCreateCellHeight = 60
|
|
6
|
+
NormalCellFinishingHeight = 60
|
|
7
|
+
|
|
8
|
+
def loadView
|
|
9
|
+
self.tableView = UITableView.new
|
|
10
|
+
|
|
11
|
+
@rows = ['Swipe to the right to complete', 'Swipe to left to delete', 'Drag down to create a new cell', 'Pinch two rows apart to create cell', 'Long hold to start reorder cell']
|
|
12
|
+
@grabbedObject = nil
|
|
13
|
+
@tableViewRecognizer = GestureRecognizer.alloc.initWithTableView(self.tableView, delegate:self)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def viewWillAppear(animated)
|
|
17
|
+
navigationController.setNavigationBarHidden(true, animated:false)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def viewDidLoad
|
|
21
|
+
tableView.backgroundColor = UIColor.blackColor
|
|
22
|
+
tableView.separatorStyle = UITableViewCellSeparatorStyleNone
|
|
23
|
+
tableView.rowHeight = NormalCellFinishingHeight
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def numberOfSectionsInTableView(tableView)
|
|
27
|
+
1
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def tableView(tableView, numberOfRowsInSection: section)
|
|
31
|
+
@rows.count
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def tableView(tableView, heightForRowAtIndexPath: indexPath)
|
|
35
|
+
NormalCellFinishingHeight
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def tableView(tableView, cellForRowAtIndexPath: indexPath)
|
|
39
|
+
object = @rows[indexPath.row]
|
|
40
|
+
backgroundColor = backgroundColorForIndexPath(indexPath)
|
|
41
|
+
|
|
42
|
+
if object == AddingCell
|
|
43
|
+
if indexPath.row == 0
|
|
44
|
+
cellIdentifier = 'PullDownTableViewCell'
|
|
45
|
+
cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier)
|
|
46
|
+
unless cell
|
|
47
|
+
cell = TransformableTableViewCell.transformableTableViewCellWithStyle(:pullDown, reuseIdentifier: cellIdentifier)
|
|
48
|
+
cell.textLabel.adjustsFontSizeToFitWidth = true
|
|
49
|
+
cell.textLabel.textColor = UIColor.whiteColor
|
|
50
|
+
cell.textLabel.textAlignment = UITextAlignmentCenter
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
cell.tintColor = backgroundColor
|
|
54
|
+
cell.finishedHeight = CommittingCreateCellHeight
|
|
55
|
+
cell.textLabel.text = cell.frame.size.height > CommittingCreateCellHeight ? 'Release to create cell...' : 'Continue Pulling...'
|
|
56
|
+
cell.contentView.backgroundColor = UIColor.clearColor
|
|
57
|
+
else
|
|
58
|
+
cellIdentifier = 'UnfoldingTableViewCell'
|
|
59
|
+
cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier)
|
|
60
|
+
unless cell
|
|
61
|
+
cell = TransformableTableViewCell.transformableTableViewCellWithStyle(:unfolding, reuseIdentifier: cellIdentifier)
|
|
62
|
+
cell.textLabel.adjustsFontSizeToFitWidth = true
|
|
63
|
+
cell.textLabel.textColor = UIColor.whiteColor
|
|
64
|
+
cell.textLabel.textAlignment = UITextAlignmentCenter
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
cell.tintColor = backgroundColor
|
|
68
|
+
cell.finishedHeight = CommittingCreateCellHeight
|
|
69
|
+
cell.textLabel.text = cell.frame.size.height > CommittingCreateCellHeight ? 'Release to create cell...' : 'Continue Pinching...'
|
|
70
|
+
cell.contentView.backgroundColor = UIColor.clearColor
|
|
71
|
+
cell.detailTextLabel.text = ' '
|
|
72
|
+
end
|
|
73
|
+
else
|
|
74
|
+
cellIdentifier = 'MyCell'
|
|
75
|
+
cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier)
|
|
76
|
+
unless cell
|
|
77
|
+
cell = UITableViewCell.alloc.initWithStyle(UITableViewCellStyleDefault, reuseIdentifier: cellIdentifier)
|
|
78
|
+
cell.textLabel.adjustsFontSizeToFitWidth = true
|
|
79
|
+
cell.textLabel.backgroundColor = UIColor.clearColor
|
|
80
|
+
cell.selectionStyle = UITableViewCellSelectionStyleNone
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
text = object.to_s
|
|
84
|
+
textColor = UIColor.whiteColor
|
|
85
|
+
if object == DoneCell
|
|
86
|
+
textColor = UIColor.grayColor
|
|
87
|
+
backgroundColor = UIColor.darkGrayColor
|
|
88
|
+
elsif object == DummyCell
|
|
89
|
+
text = ''
|
|
90
|
+
backgroundColor = UIColor.clearColor
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
cell.textLabel.text = text
|
|
94
|
+
cell.textLabel.textColor = textColor
|
|
95
|
+
cell.contentView.backgroundColor = backgroundColor
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
cell
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
def gestureRecognizer(gestureRecognizer, needsAddRowAtIndexPath: indexPath)
|
|
102
|
+
@rows.insert(indexPath.row, AddingCell)
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def gestureRecognizer(gestureRecognizer, needsCommitRowAtIndexPath: indexPath)
|
|
106
|
+
@rows[indexPath.row] = 'Added!'
|
|
107
|
+
cell = tableView.cellForRowAtIndexPath(indexPath)
|
|
108
|
+
cell.finishedHeight = NormalCellFinishingHeight
|
|
109
|
+
cell.textLabel.text = 'Just Added!'
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
def gestureRecognizer(gestureRecognizer, needsDiscardRowAtIndexPath: indexPath)
|
|
113
|
+
@rows.delete_at(indexPath.row)
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
def gestureRecognizer(gestureRecognizer, didEnterEditingState: state, forRowAtIndexPath: indexPath)
|
|
117
|
+
backgroundColor = case state
|
|
118
|
+
when :middle
|
|
119
|
+
backgroundColorForIndexPath(indexPath)
|
|
120
|
+
when :right
|
|
121
|
+
UIColor.greenColor
|
|
122
|
+
else
|
|
123
|
+
UIColor.darkGrayColor
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
cell = tableView.cellForRowAtIndexPath(indexPath)
|
|
127
|
+
cell.contentView.backgroundColor = backgroundColor
|
|
128
|
+
cell.tintColor = backgroundColor if cell.kind_of? TransformableTableViewCell
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
def gestureRecognizer(gestureRecognizer, canEditRowAtIndexPath: indexPath)
|
|
132
|
+
true
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
def gestureRecognizer(gestureRecognizer, commitEditingState: state, forRowAtIndexPath: indexPath)
|
|
136
|
+
tableView.beginUpdates
|
|
137
|
+
case state
|
|
138
|
+
when :left
|
|
139
|
+
@rows.delete_at(indexPath.row)
|
|
140
|
+
tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimationLeft)
|
|
141
|
+
when :right
|
|
142
|
+
@rows[indexPath.row] = DoneCell
|
|
143
|
+
tableView.reloadRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimationLeft)
|
|
144
|
+
end
|
|
145
|
+
tableView.endUpdates
|
|
146
|
+
|
|
147
|
+
tableView.performSelector(:"reloadVisibleRowsExceptIndexPath:", withObject: indexPath, afterDelay: GestureRecognizer::RowAnimationDuration)
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
def gestureRecognizer(gestureRecognizer, canMoveRowAtIndexPath: indexPath)
|
|
151
|
+
true
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
def gestureRecognizer(gestureRecognizer, needsCreatePlaceholderForRowAtIndexPath: indexPath)
|
|
155
|
+
@grabbedObject = @rows[indexPath.row]
|
|
156
|
+
@rows[indexPath.row] = DummyCell
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
def gestureRecognizer(gestureRecognizer, needsMoveRowAtIndexPath: sourceIndexPath, toIndexPath: destinationIndexPath)
|
|
160
|
+
object = @rows[sourceIndexPath.row]
|
|
161
|
+
@rows.delete_at(sourceIndexPath.row)
|
|
162
|
+
@rows.insert(destinationIndexPath.row, object)
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
def gestureRecognizer(gestureRecognizer, needsReplacePlaceholderForRowAtIndexPath: indexPath)
|
|
166
|
+
@rows[indexPath.row] = @grabbedObject
|
|
167
|
+
@grabbedObject = nil
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
def backgroundColorForIndexPath(indexPath)
|
|
171
|
+
UIColor.redColor.colorWithHueOffset(0.12 * indexPath.row / @rows.count)
|
|
172
|
+
end
|
|
173
|
+
end
|
|
File without changes
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
class AppDelegate
|
|
2
|
+
def application(application, didFinishLaunchingWithOptions:launchOptions)
|
|
3
|
+
@window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds)
|
|
4
|
+
@window.rootViewController = HelloViewController.alloc.init
|
|
5
|
+
@window.rootViewController.wantsFullScreenLayout = true
|
|
6
|
+
@window.makeKeyAndVisible
|
|
7
|
+
true
|
|
8
|
+
end
|
|
9
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
class HelloView < UIView
|
|
2
|
+
def drawRect(rect)
|
|
3
|
+
if @moved
|
|
4
|
+
bgcolor = begin
|
|
5
|
+
red, green, blue = rand(100), rand(100), rand(100)
|
|
6
|
+
UIColor.colorWithRed(red/100.0, green:green/100.0, blue:blue/100.0, alpha:1.0)
|
|
7
|
+
end
|
|
8
|
+
text = "ZOMG!"
|
|
9
|
+
else
|
|
10
|
+
bgcolor = UIColor.blackColor
|
|
11
|
+
text = @touches ? "Touched #{@touches} times!" : "Hello RubyMotion!"
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
bgcolor.set
|
|
15
|
+
UIBezierPath.bezierPathWithRect(frame).fill
|
|
16
|
+
|
|
17
|
+
font = UIFont.systemFontOfSize(24)
|
|
18
|
+
UIColor.whiteColor.set
|
|
19
|
+
text.drawAtPoint(CGPoint.new(10, 20), withFont:font)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def touchesMoved(touches, withEvent:event)
|
|
23
|
+
@moved = true
|
|
24
|
+
setNeedsDisplay
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def touchesEnded(touches, withEvent:event)
|
|
28
|
+
@moved = false
|
|
29
|
+
@touches ||= 0
|
|
30
|
+
@touches += 1
|
|
31
|
+
setNeedsDisplay
|
|
32
|
+
end
|
|
33
|
+
end
|
|
File without changes
|
|
Binary file
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
HelloGL.app
|
|
2
|
+
|
|
3
|
+
This sample demonstrates the following concepts: GLKit (OpenGL).
|
|
4
|
+
|
|
5
|
+
This sample has been contributed by Pete Schwamb. It's basically a port of
|
|
6
|
+
Ray Wenderlich's code in his nice GLKit tutorial.
|
|
7
|
+
|
|
8
|
+
https://github.com/ps2/MotionGL
|
|
9
|
+
http://www.raywenderlich.com/5223/beginning-opengl-es-2-0-with-glkit-part-1
|
|
@@ -0,0 +1,11 @@
|
|
|
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 = 'HelloGL'
|
|
7
|
+
|
|
8
|
+
app.frameworks << 'OpenGLES'
|
|
9
|
+
app.frameworks << 'QuartzCore'
|
|
10
|
+
app.frameworks << 'GLKit'
|
|
11
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
class AppDelegate
|
|
2
|
+
def application(application, didFinishLaunchingWithOptions:launchOptions)
|
|
3
|
+
@window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds)
|
|
4
|
+
|
|
5
|
+
@window.backgroundColor = UIColor.whiteColor
|
|
6
|
+
@window.makeKeyAndVisible()
|
|
7
|
+
|
|
8
|
+
viewController = MotionGLController.alloc.initWithNibName(nil, bundle:nil)
|
|
9
|
+
@window.addSubview(viewController.view)
|
|
10
|
+
viewController.preferredFramesPerSecond = 60
|
|
11
|
+
@window.rootViewController = viewController
|
|
12
|
+
true
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
class IndexData
|
|
2
|
+
attr_accessor :ptr
|
|
3
|
+
|
|
4
|
+
def initialize(data)
|
|
5
|
+
@num_indices = data.count
|
|
6
|
+
@ptr = Pointer.new(:uchar, @num_indices)
|
|
7
|
+
set_data(data)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def set_data(indices)
|
|
11
|
+
indices.each_with_index do |index,offset|
|
|
12
|
+
@ptr[offset] = index
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def size
|
|
17
|
+
@num_indices
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
class MotionGLController < GLKViewController
|
|
2
|
+
|
|
3
|
+
def loadView
|
|
4
|
+
self.view = GLKView.alloc.initWithFrame(UIScreen.mainScreen.bounds)
|
|
5
|
+
@increasing = true
|
|
6
|
+
@curRed = 0.0
|
|
7
|
+
#self.view.delegate = self
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def setupGL
|
|
11
|
+
EAGLContext.setCurrentContext(@context)
|
|
12
|
+
|
|
13
|
+
@effect = GLKBaseEffect.alloc.init
|
|
14
|
+
|
|
15
|
+
options = {GLKTextureLoaderOriginBottomLeft => true}
|
|
16
|
+
|
|
17
|
+
path = NSBundle.mainBundle.pathForResource("rubymotion", ofType:"png")
|
|
18
|
+
perror = Pointer.new(:object)
|
|
19
|
+
info = GLKTextureLoader.textureWithContentsOfFile(path, options:options, error:perror)
|
|
20
|
+
|
|
21
|
+
if (info == nil)
|
|
22
|
+
puts("Error loading file: %@", perror[0].localizedDescription)
|
|
23
|
+
end
|
|
24
|
+
@effect.texture2d0.name = info.name
|
|
25
|
+
@effect.texture2d0.enabled = true
|
|
26
|
+
|
|
27
|
+
@vertices = VertexData.new([
|
|
28
|
+
[ 1.0, -1.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0],
|
|
29
|
+
[ 1.0, 1.0, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 1.0],
|
|
30
|
+
[-1.0, 1.0, 0.0, 0.0, 0.0, 1.0, 1.0, 0.0, 1.0],
|
|
31
|
+
[-1.0, -1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0]
|
|
32
|
+
])
|
|
33
|
+
|
|
34
|
+
@indices = IndexData.new(
|
|
35
|
+
[0, 1, 2,
|
|
36
|
+
2, 3, 0]
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
vertexBufferPtr = Pointer.new(:uchar)
|
|
40
|
+
glGenBuffers(1, vertexBufferPtr)
|
|
41
|
+
@vertexBuffer = vertexBufferPtr[0]
|
|
42
|
+
glBindBuffer(GL_ARRAY_BUFFER, @vertexBuffer)
|
|
43
|
+
glBufferData(GL_ARRAY_BUFFER, @vertices.size*4, @vertices.ptr, GL_STATIC_DRAW)
|
|
44
|
+
|
|
45
|
+
indexBufferPtr = Pointer.new(:uchar)
|
|
46
|
+
glGenBuffers(1, indexBufferPtr)
|
|
47
|
+
@indexBuffer = indexBufferPtr[0]
|
|
48
|
+
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, @indexBuffer)
|
|
49
|
+
glBufferData(GL_ELEMENT_ARRAY_BUFFER, @indices.size*4, @indices.ptr, GL_STATIC_DRAW)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def tearDownGL
|
|
53
|
+
EAGLContext.setCurrentContext(@context)
|
|
54
|
+
|
|
55
|
+
tmpPtr = Pointer.new(:uchar)
|
|
56
|
+
|
|
57
|
+
tmpPtr.value = @vertexBuffer
|
|
58
|
+
glDeleteBuffers(1, tmpPtr)
|
|
59
|
+
|
|
60
|
+
tmpPtr.value = @indexBuffer
|
|
61
|
+
glDeleteBuffers(1, tmpPtr)
|
|
62
|
+
|
|
63
|
+
@effect = nil
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def viewDidLoad
|
|
67
|
+
super
|
|
68
|
+
|
|
69
|
+
@context = EAGLContext.alloc.initWithAPI(KEAGLRenderingAPIOpenGLES2)
|
|
70
|
+
|
|
71
|
+
if (!@context)
|
|
72
|
+
puts "Failed to create ES context"
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
self.view.context = @context
|
|
76
|
+
@rotation = 0
|
|
77
|
+
setupGL
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def viewDidUnload
|
|
81
|
+
super
|
|
82
|
+
tearDownGL
|
|
83
|
+
if (EAGLContext.currentContext == @context)
|
|
84
|
+
EAGLContext.setCurrentContext(nil)
|
|
85
|
+
end
|
|
86
|
+
@context = nil
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def glkView(view, drawInRect:rect)
|
|
90
|
+
glClearColor(@curRed, 0.0, 0.0, 1.0);
|
|
91
|
+
glClear(GL_COLOR_BUFFER_BIT);
|
|
92
|
+
|
|
93
|
+
@effect.prepareToDraw
|
|
94
|
+
|
|
95
|
+
glBindBuffer(GL_ARRAY_BUFFER, @vertexBuffer)
|
|
96
|
+
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, @indexBuffer)
|
|
97
|
+
|
|
98
|
+
glEnableVertexAttribArray(GLKVertexAttribPosition)
|
|
99
|
+
glVertexAttribPointer(GLKVertexAttribPosition, 3, GL_FLOAT, GL_FALSE, 9*4, Pointer.magic_cookie(0))
|
|
100
|
+
|
|
101
|
+
glEnableVertexAttribArray(GLKVertexAttribColor)
|
|
102
|
+
glVertexAttribPointer(GLKVertexAttribColor, 4, GL_FLOAT, GL_FALSE, 9*4, Pointer.magic_cookie(3*4))
|
|
103
|
+
|
|
104
|
+
glEnableVertexAttribArray(GLKVertexAttribTexCoord0);
|
|
105
|
+
glVertexAttribPointer(GLKVertexAttribTexCoord0, 2, GL_FLOAT, GL_FALSE, 9*4, Pointer.magic_cookie(7*4));
|
|
106
|
+
|
|
107
|
+
glDrawElements(GL_TRIANGLES, @indices.size, GL_UNSIGNED_BYTE, Pointer.magic_cookie(0))
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
def update
|
|
111
|
+
if (@increasing)
|
|
112
|
+
@curRed += 1.0 * self.timeSinceLastUpdate
|
|
113
|
+
else
|
|
114
|
+
@curRed -= 1.0 * self.timeSinceLastUpdate
|
|
115
|
+
end
|
|
116
|
+
if (@curRed >= 1.0)
|
|
117
|
+
@curRed = 1.0
|
|
118
|
+
@increasing = false
|
|
119
|
+
end
|
|
120
|
+
if (@curRed <= 0.0)
|
|
121
|
+
@curRed = 0.0
|
|
122
|
+
@increasing = true
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
aspect = (view.bounds.size.width / view.bounds.size.height).abs
|
|
126
|
+
projectionMatrix = GLKMatrix4MakePerspective(GLKMathDegreesToRadians(65.0), aspect, 4.0, 10.0)
|
|
127
|
+
@effect.transform.projectionMatrix = projectionMatrix
|
|
128
|
+
|
|
129
|
+
modelViewMatrix = GLKMatrix4MakeTranslation(0.0, 0.0, -6.0)
|
|
130
|
+
@rotation += 90.0 * self.timeSinceLastUpdate
|
|
131
|
+
modelViewMatrix = GLKMatrix4Rotate(modelViewMatrix, GLKMathDegreesToRadians(@rotation), 0, 0, 1)
|
|
132
|
+
@effect.transform.modelviewMatrix = modelViewMatrix
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
def touchesBegan(touches, withEvent:event)
|
|
136
|
+
self.paused = !self.isPaused
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
end
|