sugarcube 1.3.4 → 1.3.5
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/Gemfile.lock +1 -1
- data/lib/sugarcube-attributedstring/nsattributedstring.rb +8 -1
- data/lib/sugarcube-events.rb +5 -0
- data/lib/sugarcube-gestures.rb +4 -0
- data/lib/sugarcube-image/uiimage.rb +2 -1
- data/lib/sugarcube-uikit/uiview.rb +2 -2
- data/lib/sugarcube/version.rb +1 -1
- data/spec/uiimage_spec.rb +34 -0
- data/spec/uiview_spec.rb +48 -0
- metadata +2 -2
data/Gemfile.lock
CHANGED
@@ -23,7 +23,10 @@ class NSString
|
|
23
23
|
def nsattributedstring(attributes={})
|
24
24
|
NSAttributedString.alloc.initWithString(self, attributes: attributes)
|
25
25
|
end
|
26
|
-
|
26
|
+
|
27
|
+
def attrd
|
28
|
+
self.nsattributedstring
|
29
|
+
end
|
27
30
|
|
28
31
|
end
|
29
32
|
|
@@ -147,6 +150,10 @@ class NSAttributedString
|
|
147
150
|
self
|
148
151
|
end
|
149
152
|
|
153
|
+
def attrd
|
154
|
+
self.nsattributedstring
|
155
|
+
end
|
156
|
+
|
150
157
|
def +(attributedstring)
|
151
158
|
NSMutableAttributedString.alloc.initWithAttributedString(self) + attributedstring.nsattributedstring
|
152
159
|
end
|
data/lib/sugarcube-events.rb
CHANGED
@@ -12,4 +12,9 @@ Motion::Project::App.setup do |app|
|
|
12
12
|
Dir.glob(File.join(File.dirname(__FILE__), 'sugarcube-events/**/*.rb')).reverse.each do |file|
|
13
13
|
app.files.insert(insert_point, file)
|
14
14
|
end
|
15
|
+
|
16
|
+
cleanup = File.join(File.dirname(__FILE__), 'sugarcube/sugarcube_cleanup.rb')
|
17
|
+
uicontrol = File.join(File.dirname(__FILE__), 'sugarcube-events/uicontrol.rb')
|
18
|
+
uitextview = File.join(File.dirname(__FILE__), 'sugarcube-events/uitextview.rb')
|
19
|
+
app.files_dependencies uicontrol => [cleanup], uitextview => [cleanup]
|
15
20
|
end
|
data/lib/sugarcube-gestures.rb
CHANGED
@@ -12,4 +12,8 @@ Motion::Project::App.setup do |app|
|
|
12
12
|
Dir.glob(File.join(File.dirname(__FILE__), 'sugarcube-gestures/**/*.rb')).reverse.each do |file|
|
13
13
|
app.files.insert(insert_point, file)
|
14
14
|
end
|
15
|
+
|
16
|
+
cleanup = File.join(File.dirname(__FILE__), 'sugarcube/sugarcube_cleanup.rb')
|
17
|
+
gestures = File.join(File.dirname(__FILE__), 'sugarcube-gestures/gestures.rb')
|
18
|
+
app.files_dependencies gestures => [cleanup]
|
15
19
|
end
|
@@ -431,6 +431,7 @@ class UIImage
|
|
431
431
|
# image.overlay(UIColor.redColor)
|
432
432
|
def overlay(color)
|
433
433
|
image_rect = CGRectMake(0, 0, self.size.width, self.size.height)
|
434
|
+
new_image = nil
|
434
435
|
|
435
436
|
UIImage.canvas(size: self.size, scale: self.scale) do |ctx|
|
436
437
|
self.drawInRect(image_rect)
|
@@ -623,7 +624,7 @@ class UIImage
|
|
623
624
|
end
|
624
625
|
|
625
626
|
unless options[:scale]
|
626
|
-
options =
|
627
|
+
options[:scale] = self.scale
|
627
628
|
end
|
628
629
|
|
629
630
|
self.class.canvas(options) do |context|
|
@@ -52,9 +52,9 @@ class UIView
|
|
52
52
|
# up the responder chain until the nextResponder is a UIViewController
|
53
53
|
# subclass, or returns nil if none is found.
|
54
54
|
def controller
|
55
|
-
if nextResponder
|
55
|
+
if nextResponder.is_a?(UIViewController)
|
56
56
|
nextResponder
|
57
|
-
elsif nextResponder
|
57
|
+
elsif nextResponder.is_a?(UIView)
|
58
58
|
nextResponder.controller
|
59
59
|
else
|
60
60
|
nil
|
data/lib/sugarcube/version.rb
CHANGED
data/spec/uiimage_spec.rb
CHANGED
@@ -468,4 +468,38 @@ describe 'UIImage' do
|
|
468
468
|
|
469
469
|
end
|
470
470
|
|
471
|
+
describe '`overlay` should add shading to an image' do
|
472
|
+
|
473
|
+
it 'should return an image' do
|
474
|
+
red = UIImage.canvas(size: [10, 10]) do |context|
|
475
|
+
:red.uicolor.set
|
476
|
+
CGContextAddRect(context, [[0, 0], [10, 10]])
|
477
|
+
CGContextFillPath(context)
|
478
|
+
end
|
479
|
+
red.overlay(:white).should.is_a?(UIImage)
|
480
|
+
end
|
481
|
+
|
482
|
+
it 'should return an image that is the same size' do
|
483
|
+
red = UIImage.canvas(size: [10, 10]) do |context|
|
484
|
+
:red.uicolor.set
|
485
|
+
CGContextAddRect(context, [[0, 0], [10, 10]])
|
486
|
+
CGContextFillPath(context)
|
487
|
+
end
|
488
|
+
overlay = red.overlay(:white)
|
489
|
+
overlay.size.width.should == red.size.width
|
490
|
+
overlay.size.height.should == red.size.height
|
491
|
+
end
|
492
|
+
|
493
|
+
it 'should return an image that is a different color' do
|
494
|
+
red = UIImage.canvas(size: [10, 10]) do |context|
|
495
|
+
:red.uicolor.set
|
496
|
+
CGContextAddRect(context, [[0, 0], [10, 10]])
|
497
|
+
CGContextFillPath(context)
|
498
|
+
end
|
499
|
+
overlay = red.overlay(:white)
|
500
|
+
overlay.color_at([0, 0]).should != red.color_at([0, 0])
|
501
|
+
end
|
502
|
+
|
503
|
+
end
|
504
|
+
|
471
505
|
end
|
data/spec/uiview_spec.rb
CHANGED
@@ -2,20 +2,66 @@ describe "UIView" do
|
|
2
2
|
|
3
3
|
it "should convert to a UIImage" do
|
4
4
|
test = UIView.alloc.initWithFrame([[0, 0], [10, 10]])
|
5
|
+
test.backgroundColor = :black.uicolor
|
6
|
+
|
7
|
+
red = UIView.alloc.initWithFrame([[0, 0], [2, 2]])
|
8
|
+
red.backgroundColor = :red.uicolor
|
9
|
+
test << red
|
10
|
+
|
5
11
|
image = test.uiimage
|
6
12
|
image.class.should == UIImage
|
7
13
|
CGSizeEqualToSize(image.size, [10, 10]).should == true
|
8
14
|
image.scale.should == UIScreen.mainScreen.scale
|
15
|
+
# file = 'uiview_uiimage_test.png'.document
|
16
|
+
# image.nsdata.write_to(file)
|
9
17
|
end
|
10
18
|
|
11
19
|
it "should convert a UIScrollView to a UIImage" do
|
20
|
+
# scrollview has to be in the active window, or screen shot doesn't work
|
21
|
+
# (doesn't apply to other views)
|
22
|
+
window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds)
|
23
|
+
window.makeKeyAndVisible
|
24
|
+
|
12
25
|
test = UIScrollView.alloc.initWithFrame([[0, 0], [10, 10]])
|
13
26
|
test.contentSize = [20, 20]
|
27
|
+
test.contentOffset = [2.5, 2.5]
|
28
|
+
test.backgroundColor = :black.uicolor
|
29
|
+
window << test
|
30
|
+
|
31
|
+
red = UIView.alloc.initWithFrame([[0, 0], [8, 8]])
|
32
|
+
red.backgroundColor = :red.uicolor(0.5)
|
33
|
+
test << red
|
34
|
+
# file = 'uiview_uiimage_red.png'.document
|
35
|
+
# red.uiimage.nsdata.write_to(file)
|
36
|
+
|
37
|
+
green = UIView.alloc.initWithFrame([[10, 0], [10, 10]])
|
38
|
+
green.backgroundColor = :green.uicolor(0.5)
|
39
|
+
test << green
|
40
|
+
# file = 'uiview_uiimage_green.png'.document
|
41
|
+
# green.uiimage.nsdata.write_to(file)
|
42
|
+
|
43
|
+
blue = UIView.alloc.initWithFrame([[0, 10], [10, 10]])
|
44
|
+
blue.backgroundColor = :blue.uicolor(0.5)
|
45
|
+
test << blue
|
46
|
+
# file = 'uiview_uiimage_blue.png'.document
|
47
|
+
# blue.uiimage.nsdata.write_to(file)
|
48
|
+
|
49
|
+
white = UIView.alloc.initWithFrame([[10, 10], [10, 10]])
|
50
|
+
white.backgroundColor = :white.uicolor(0.5)
|
51
|
+
test << white
|
52
|
+
# file = 'uiview_uiimage_white.png'.document
|
53
|
+
# white.uiimage.nsdata.write_to(file)
|
54
|
+
|
55
|
+
gray = UIView.alloc.initWithFrame([[18, 18], [2, 2]])
|
56
|
+
gray.backgroundColor = :gray.uicolor(0.5)
|
57
|
+
test << gray
|
14
58
|
|
15
59
|
image = test.uiimage
|
16
60
|
image.class.should == UIImage
|
17
61
|
CGSizeEqualToSize(image.size, [10, 10]).should == true
|
18
62
|
image.scale.should == UIScreen.mainScreen.scale
|
63
|
+
# file = 'uiview_uiimage_small.png'.document
|
64
|
+
# image.nsdata.write_to(file)
|
19
65
|
|
20
66
|
image = test.uiimage(:all)
|
21
67
|
image.class.should == UIImage
|
@@ -26,6 +72,8 @@ describe "UIView" do
|
|
26
72
|
image.class.should == UIImage
|
27
73
|
CGSizeEqualToSize(image.size, [20, 20]).should == true
|
28
74
|
image.scale.should == UIScreen.mainScreen.scale
|
75
|
+
# file = 'uiview_uiimage_big.png'.document
|
76
|
+
# image.nsdata.write_to(file)
|
29
77
|
end
|
30
78
|
|
31
79
|
describe "should convert bounds" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sugarcube
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -12,7 +12,7 @@ authors:
|
|
12
12
|
autorequire:
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
|
-
date: 2013-
|
15
|
+
date: 2013-11-01 00:00:00.000000000 Z
|
16
16
|
dependencies: []
|
17
17
|
description: ! '== Description
|
18
18
|
|