sugarcube 0.13.7 → 0.14.0

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/README.md CHANGED
@@ -475,6 +475,10 @@ image.tileable
475
475
  image.tileable(insets)
476
476
  image.stretchable
477
477
  image.stretchable(insets)
478
+
479
+ # Apply a mask to an image. The mask should be a grayscale image. White areas
480
+ # will be made transparent, and black opaque.
481
+ image.masked(mask_image)
478
482
  ```
479
483
 
480
484
  UIAlertView
@@ -19,4 +19,4 @@ class NSData
19
19
  end
20
20
  end
21
21
 
22
- end
22
+ end
@@ -64,6 +64,9 @@ class Symbol
64
64
 
65
65
  attr_accessor :ca_timingfunctions
66
66
 
67
+ attr_accessor :cg_linecapstyles
68
+ attr_accessor :cg_linejoinstyles
69
+
67
70
  attr_accessor :gesture_recognizer_states
68
71
  end
69
72
 
@@ -415,6 +418,18 @@ class Symbol
415
418
  default: KCAMediaTimingFunctionDefault,
416
419
  }
417
420
 
421
+ @cg_linecapstyles = {
422
+ butt: KCGLineCapButt,
423
+ round: KCGLineCapRound,
424
+ square: KCGLineCapSquare,
425
+ }
426
+
427
+ @cg_linejoinstyles = {
428
+ miter: KCGLineJoinMiter,
429
+ round: KCGLineJoinRound,
430
+ bevel: KCGLineJoinBevel,
431
+ }
432
+
418
433
  @gesture_recognizer_states = {
419
434
  possible: UIGestureRecognizerStatePossible,
420
435
  began: UIGestureRecognizerStateBegan,
@@ -583,6 +598,16 @@ class Symbol
583
598
  end
584
599
  alias catiming catimingfunction
585
600
 
601
+ def cglinecap
602
+ look_in(Symbol.cg_linecapstyles)
603
+ end
604
+ alias cglinecapstyle cglinecap
605
+
606
+ def cglinejoin
607
+ look_in(Symbol.cg_linejoinstyles)
608
+ end
609
+ alias cglinejoinstyle cglinejoin
610
+
586
611
  def uigesturerecognizerstate
587
612
  look_in(Symbol.gesture_recognizer_states)
588
613
  end
@@ -21,7 +21,22 @@ class UIColor
21
21
  _sugarcube_colors && _sugarcube_colors[:alpha]
22
22
  end
23
23
 
24
+ # returns the closest css name
25
+ def css_name
26
+ found = Symbol.css_colors.map { |key, val| [key, _sugarcube_color_compare(self, val.uicolor)] }.inject{|c1,c2| c1[1] < c2[1] ? c1 : c2 }
27
+ threshold = 0.03
28
+ if found[1] > 0.03
29
+ nil
30
+ else
31
+ found[0]
32
+ end
33
+ end
34
+
24
35
  private
36
+ def _sugarcube_color_compare(c1, c2)
37
+ return (c1.red - c2.red).abs + (c1.green - c2.green).abs + (c1.blue - c2.blue).abs
38
+ end
39
+
25
40
  def _sugarcube_colors
26
41
  @color ||= begin
27
42
  red = Pointer.new(:float)
@@ -197,4 +197,27 @@ class UIImage
197
197
  imageWithAlignmentRectInsets(insets)
198
198
  end
199
199
 
200
+ ##|
201
+ ##| CGImageCreateWithMask
202
+ ##|
203
+ ## The mask image cannot have ANY transparency.
204
+ ## Instead, transparent areas must be white or some value between black and white.
205
+ ## The closer towards black a pixel is the less transparent it becomes.
206
+ def masked(mask_image)
207
+ mask_image = mask_image.CGImage
208
+
209
+ width = CGImageGetWidth(mask_image)
210
+ height = CGImageGetHeight(mask_image)
211
+ component_bits = CGImageGetBitsPerComponent(mask_image)
212
+ pixel_bits = CGImageGetBitsPerPixel(mask_image)
213
+ row_bytes = CGImageGetBytesPerRow(mask_image)
214
+ data_provider = CGImageGetDataProvider(mask_image)
215
+
216
+ mask = CGImageMaskCreate(width, height, component_bits,
217
+ pixel_bits, row_bytes, data_provider,nil, false)
218
+
219
+ masked = CGImageCreateWithMask(self.CGImage, mask)
220
+ UIImage.imageWithCGImage(masked)
221
+ end
222
+
200
223
  end
@@ -1,3 +1,3 @@
1
1
  module SugarCube
2
- Version = '0.13.7'
2
+ Version = '0.14.0'
3
3
  end
data/sugarcube.gemspec CHANGED
@@ -5,7 +5,7 @@ Gem::Specification.new do |gem|
5
5
  gem.name = 'sugarcube'
6
6
  gem.version = SugarCube::Version
7
7
 
8
- gem.authors = ['Colin T.A. Gray', 'Thom Parkin', 'Katsuyoshi Ito', 'Fusionbox']
8
+ gem.authors = ['Colin T.A. Gray', 'Thom Parkin', 'Katsuyoshi Ito', 'Michael Erasmus', 'Fusionbox']
9
9
  gem.email = ['colinta@gmail.com']
10
10
  gem.summary = %{Extensions for Ruby to make Rubymotion development more enjoyable, and hopefully more rubyesque!}
11
11
  gem.description = <<-DESC
metadata CHANGED
@@ -1,18 +1,19 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sugarcube
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.7
4
+ version: 0.14.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Colin T.A. Gray
9
9
  - Thom Parkin
10
10
  - Katsuyoshi Ito
11
+ - Michael Erasmus
11
12
  - Fusionbox
12
13
  autorequire:
13
14
  bindir: bin
14
15
  cert_chain: []
15
- date: 2013-01-11 00:00:00.000000000 Z
16
+ date: 2013-01-15 00:00:00.000000000 Z
16
17
  dependencies: []
17
18
  description: ! '== Description
18
19