purplish-frame 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 603acf7477aaf80d1fcda3570ef0ed4491bd1841
4
+ data.tar.gz: 034823acf71aa46e3a18a02b38a6105cd89cb439
5
+ SHA512:
6
+ metadata.gz: 9590bd53d4a5a19b1756d60a70964c733b61460d6c0fecac3421ca7d2c922b294f8fa4dbfb534574921e1fc7e2e982ea5879a5142dfbbb24fd4d7dab2c4e64e9
7
+ data.tar.gz: fb6ab562a6ac52a4bdb299f2460e4546c403c75e6346d1b57340c0fd7a9af848302db2d40dd69e992cea756370739a9e885e673e61206acb4068b1526fc5d186
data/.gitignore ADDED
@@ -0,0 +1,6 @@
1
+ .rake_tasks~
2
+ pkg/*
3
+ build/
4
+ .DS_Store
5
+ .repl_history
6
+ 0
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,14 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ purplish-frame (0.0.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+
10
+ PLATFORMS
11
+ ruby
12
+
13
+ DEPENDENCIES
14
+ purplish-frame!
data/LICENSE ADDED
@@ -0,0 +1,10 @@
1
+ Copyright (c) 2015, Hwee-Boon Yar
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
5
+
6
+ 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7
+
8
+ 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
9
+
10
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md ADDED
@@ -0,0 +1,42 @@
1
+ #Make working with rects, sizes and points more convenient with [RubyMotion](http://rubymotion.com) for iOS & OS X
2
+
3
+ Usage
4
+ ---
5
+ For iOS & OS X:
6
+
7
+ ```ruby
8
+ CGSize.new(100, 100).scale_to_fit(CGSize.new(10, 10))
9
+ #CGSize.new(10, 10)
10
+
11
+ CGSize.new(200, 100).scale_to_fill(CGSize.new(15, 15))
12
+ #CGSize.new(30, 15)
13
+
14
+ CGSize.new(100, 100).scale_to_fit!
15
+ CGSize.new(200, 100).scale_to_fill!
16
+
17
+ CGPoint.new(100, 200)*10
18
+ #CGPoint.new(1000, 2000)
19
+
20
+ CGPoint.new(100, 200)/10
21
+ #CGPoint.new(10, 20)
22
+
23
+ CGRect.new(10, 20, 100, 100).scale(10)
24
+ #CGRect.new(100, 200, 1000, 1000)
25
+ ```
26
+
27
+ Similar usage for NSSize, NSPoint, NSRect on OS X.
28
+
29
+ Installation
30
+ ---
31
+ 1. Add this to your `Gemfile`: `gem 'purplish-frame'`
32
+ 2. Run `bundle install`
33
+
34
+ License
35
+ ---
36
+ BSD. See LICENSE file.
37
+
38
+ Questions
39
+ ---
40
+ * Email: [hboon@motionobj.com](mailto:hboon@motionobj.com)
41
+ * Web: [http://hboon.com/](http://hboon.com/)
42
+ * Twitter: [http://twitter.com/hboon](http://twitter.com/hboon)
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ # -*- coding: utf-8 -*-
2
+ $:.unshift("/Library/RubyMotion/lib")
3
+ #require 'motion/project/template/ios'
4
+ require 'motion/project/template/osx'
5
+ require "bundler/gem_tasks"
6
+ require "bundler/setup"
7
+ Bundler.require
8
+
9
+ Motion::Project::App.setup do |app|
10
+ app.name = 'purplish-red'
11
+ end
@@ -0,0 +1,5 @@
1
+ class AppDelegate
2
+ def application(application, didFinishLaunchingWithOptions:launchOptions)
3
+ true
4
+ end
5
+ end
@@ -0,0 +1,37 @@
1
+ module PurplishFrame
2
+ module CanScaleWidthHeight
3
+ def scale_to_fit(s)
4
+ s = self.class.to_native_size(s)
5
+ scaled = if s.width/s.height > width/height
6
+ [s.height/height * width, s.height]
7
+ else
8
+ [s.width, s.width/width * height]
9
+ end
10
+ self.class.to_native_size(scaled)
11
+ end
12
+
13
+ def scale_to_fill(s)
14
+ s = self.class.to_native_size(s)
15
+ scaled = if s.width/s.height > width/height
16
+ [s.width, s.width/width * height]
17
+ else
18
+ [s.height/height * width, s.height]
19
+ end
20
+ self.class.to_native_size(scaled)
21
+ end
22
+
23
+ def scale_to_fit!(s)
24
+ size = scale_to_fit(s)
25
+ self.width = size.width
26
+ self.height = size.height
27
+ self
28
+ end
29
+
30
+ def scale_to_fill!(s)
31
+ size = scale_to_fill(s)
32
+ self.width = size.width
33
+ self.height = size.height
34
+ self
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,3 @@
1
+ class CGPoint
2
+ include PurplishFrame::Point
3
+ end
@@ -0,0 +1,31 @@
1
+ class CGRect
2
+ include PurplishFrame::Rect
3
+
4
+ def top
5
+ origin.y
6
+ end
7
+
8
+ def top=(y)
9
+ origin.y = y
10
+ end
11
+
12
+ def bottom
13
+ origin.y+size.height
14
+ end
15
+
16
+ def bottom=(bottom)
17
+ origin.y = bottom - size.height
18
+ end
19
+
20
+ def center_y
21
+ top+size.height/2
22
+ end
23
+
24
+ def center_y=(center_y)
25
+ self.top = center_y-size.height/2
26
+ end
27
+
28
+ def height=(h)
29
+ size.height = h
30
+ end
31
+ end
@@ -0,0 +1,7 @@
1
+ class CGSize
2
+ include PurplishFrame::CanScaleWidthHeight
3
+
4
+ def self.to_native_size(anObject)
5
+ anObject.to_size
6
+ end
7
+ end
@@ -0,0 +1,43 @@
1
+ class NSArray
2
+ def to_rect
3
+ if PurplishFrame.ios?
4
+ CGRect.new([self[0][0], self[0][1]], [self[1][0], self[1][1]])
5
+ else
6
+ NSRect.new([self[0][0], self[0][1]], [self[1][0], self[1][1]])
7
+ end
8
+ end
9
+
10
+ def to_size
11
+ if PurplishFrame.ios?
12
+ CGSize.new(self[0], self[1])
13
+ else
14
+ NSSize.new(self[0], self[1])
15
+ end
16
+ end
17
+
18
+ def to_point
19
+ if PurplishFrame.ios?
20
+ CGPoint.new(self[0], self[1])
21
+ else
22
+ NSPoint.new(self[0], self[1])
23
+ end
24
+ end
25
+ end
26
+
27
+ class CGRect
28
+ def to_rect
29
+ self
30
+ end
31
+ end
32
+
33
+ class CGSize
34
+ def to_size
35
+ self
36
+ end
37
+ end
38
+
39
+ class CGPoint
40
+ def to_point
41
+ self
42
+ end
43
+ end
@@ -0,0 +1,17 @@
1
+ class NSRect
2
+ def to_rect
3
+ self
4
+ end
5
+ end
6
+
7
+ class NSSize
8
+ def to_size
9
+ self
10
+ end
11
+ end
12
+
13
+ class NSPoint
14
+ def to_point
15
+ self
16
+ end
17
+ end
@@ -0,0 +1,3 @@
1
+ class NSPoint
2
+ include PurplishFrame::Point
3
+ end
@@ -0,0 +1,31 @@
1
+ class NSRect
2
+ include PurplishFrame::Rect
3
+
4
+ def top
5
+ origin.y + size.height
6
+ end
7
+
8
+ def top=(y)
9
+ origin.y = y - size.height
10
+ end
11
+
12
+ def bottom
13
+ origin.y
14
+ end
15
+
16
+ def bottom=(bottom)
17
+ origin.y = bottom
18
+ end
19
+
20
+ def center_y
21
+ bottom+size.height/2
22
+ end
23
+
24
+ def center_y=(center_y)
25
+ self.bottom = center_y-size.height/2
26
+ end
27
+
28
+ def height=(h)
29
+ size.height = h
30
+ end
31
+ end
@@ -0,0 +1,7 @@
1
+ class NSSize
2
+ include PurplishFrame::CanScaleWidthHeight
3
+
4
+ def self.to_native_size(anObject)
5
+ anObject.to_size
6
+ end
7
+ end
@@ -0,0 +1,11 @@
1
+ module PurplishFrame
2
+ module Point
3
+ def *(aNumber)
4
+ self.class.new(x*aNumber, y*aNumber)
5
+ end
6
+
7
+ def /(aNumber)
8
+ self.class.new(x/aNumber, y/aNumber)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module PurplishFrame
2
+ module_function
3
+
4
+ def osx?
5
+ Kernel.const_defined?(:NSApplication)
6
+ end
7
+
8
+ def ios?
9
+ Kernel.const_defined?(:UIApplication)
10
+ end
11
+ end
@@ -0,0 +1,49 @@
1
+ module PurplishFrame
2
+ module Rect
3
+ def scale(num)
4
+ [[origin.x*num, origin.y*num], [size.width*num, size.height*num]].to_rect
5
+ end
6
+
7
+ def scale!(num)
8
+ self.origin = [origin.x*num, origin.y*num]
9
+ self.size = [size.width*num, size.height*num]
10
+ self
11
+ end
12
+
13
+ def left
14
+ origin.x
15
+ end
16
+
17
+ def left=(x)
18
+ origin.x = x
19
+ end
20
+
21
+ def right
22
+ origin.x+size.width
23
+ end
24
+
25
+ def right=(right)
26
+ origin.x = right - size.width
27
+ end
28
+
29
+ def center_x
30
+ left+size.width/2
31
+ end
32
+
33
+ def center_x=(center_x)
34
+ self.left = center_x-size.width/2
35
+ end
36
+
37
+ def width
38
+ size.width
39
+ end
40
+
41
+ def width=(w)
42
+ size.width = w
43
+ end
44
+
45
+ def height
46
+ size.height
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,3 @@
1
+ module PurplishFrame
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,9 @@
1
+ unless defined?(Motion::Project::Config)
2
+ raise "This file must be required within a RubyMotion project Rakefile."
3
+ end
4
+
5
+ Motion::Project::App.setup do |app|
6
+ Dir.glob(File.join(File.dirname(__FILE__), 'purplish-frame/**/*.rb')).each do |file|
7
+ app.files.unshift(file)
8
+ end
9
+ end
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/purplish-frame/version.rb', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.name = 'purplish-frame'
6
+ gem.version = PurplishFrame::VERSION
7
+ gem.licenses = ['BSD']
8
+
9
+ gem.authors = ['Hwee-Boon Yar']
10
+
11
+ gem.description = 'Make working with rects, sizes and points more convenient with RubyMotion for iOS & OS X'
12
+ gem.summary = gem.description
13
+ gem.homepage = 'https://github.com/hboon/purplish-frame'
14
+ gem.email = 'hboon@motionobj.com'
15
+
16
+ gem.files = `git ls-files`.split($\)
17
+ gem.require_paths = ['lib']
18
+ gem.test_files = gem.files.grep(%r{^spec/})
19
+ end
@@ -0,0 +1,6 @@
1
+ describe "Points" do
2
+ it "CGPoint scaling" do
3
+ (CGPoint.new(100, 200)*10).should.equal CGPoint.new(1000, 2000)
4
+ (CGPoint.new(100, 200)/10).should.equal CGPoint.new(10, 20)
5
+ end
6
+ end
@@ -0,0 +1,31 @@
1
+ class CGRect
2
+ def close?(to, delta)
3
+ origin.x.close?(to.origin.x, delta) && origin.y.close?(to.origin.y, delta) && size.width.close?(to.size.width, delta) && size.height.close?(to.size.height, delta)
4
+ end
5
+ end
6
+
7
+ describe "Rects" do
8
+ delta = 0.0001
9
+
10
+ it "CGRect scaling" do
11
+ CGRectMake(0, 0, 100, 100).scale(10).should.close CGRectMake(0, 0, 1000, 1000), delta
12
+ CGRectMake(10, 20, 100, 100).scale(10).should.close CGRectMake(100, 200, 1000, 1000), delta
13
+
14
+ rect = CGRectMake(10, 20, 100, 100)
15
+ rect.scale!(10)
16
+ rect.should.close CGRectMake(100, 200, 1000, 1000), delta
17
+ end
18
+
19
+ it "CGRect sides" do
20
+ rect = CGRectMake(10, -20, 100, 100)
21
+ rect.left.should.equal 10
22
+ rect.right.should.equal 110
23
+ rect.top.should.equal -20
24
+ rect.bottom.should.equal 80
25
+ rect.width.should.equal 100
26
+ rect.height.should.equal 100
27
+ rect.center_x.should.equal 60
28
+ rect.center_y.should.equal 30
29
+ end
30
+
31
+ end
@@ -0,0 +1,28 @@
1
+ class CGSize
2
+ def close?(to, delta)
3
+ width.close?(to.width, delta) && height.close?(to.height, delta)
4
+ end
5
+ end
6
+
7
+ describe "Sizes" do
8
+ delta = 0.0001
9
+
10
+ it "CGSize scaling" do
11
+ CGSizeMake(100, 100).scale_to_fit(CGSizeMake(10, 10)).should.close CGSizeMake(10, 10), delta
12
+ CGSizeMake(200, 100).scale_to_fit(CGSizeMake(15, 15)).should.close CGSizeMake(15, 7.5), delta
13
+ CGSizeMake(100, 100).scale_to_fill(CGSizeMake(10, 10)).should.close CGSizeMake(10, 10), delta
14
+ CGSizeMake(200, 100).scale_to_fill(CGSizeMake(15, 15)).should.close CGSizeMake(30, 15), delta
15
+ CGSizeMake(10, 10).scale_to_fit(CGSizeMake(100, 100)).should.close CGSizeMake(100, 100), delta
16
+ CGSizeMake(10, 5).scale_to_fit(CGSizeMake(100, 100)).should.close CGSizeMake(100, 50), delta
17
+ CGSizeMake(10, 10).scale_to_fill(CGSizeMake(100, 100)).should.close CGSizeMake(100, 100), delta
18
+ CGSizeMake(10, 5).scale_to_fill(CGSizeMake(100, 100)).should.close CGSizeMake(200, 100), delta
19
+
20
+ s = CGSizeMake(200, 100)
21
+ s.scale_to_fit!(CGSizeMake(15, 15))
22
+ s.should.close CGSizeMake(15, 7.5), delta
23
+
24
+ s = CGSizeMake(10, 5)
25
+ s.scale_to_fill!(CGSizeMake(100, 100))
26
+ s.should.close CGSizeMake(200, 100), delta
27
+ end
28
+ end
@@ -0,0 +1,8 @@
1
+ if PurplishFrame.osx?
2
+ describe "Points" do
3
+ it "NSPoint scaling" do
4
+ (NSPoint.new(100, 200)*10).should.equal NSPoint.new(1000, 2000)
5
+ (NSPoint.new(100, 200)/10).should.equal NSPoint.new(10, 20)
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,22 @@
1
+ class NSRect
2
+ def close?(to, delta)
3
+ origin.x.close?(to.origin.x, delta) && origin.y.close?(to.origin.y, delta) && size.width.close?(to.size.width, delta) && size.height.close?(to.size.height, delta)
4
+ end
5
+ end
6
+
7
+ if PurplishFrame.osx?
8
+ describe "Rects" do
9
+ it "NSRect sides" do
10
+ #Careful not to use NSMakeRect(). Somehow, it creates a CGRect instead
11
+ rect = NSRect.new([10, -20], [100, 100])
12
+ rect.left.should.equal 10
13
+ rect.right.should.equal 110
14
+ rect.top.should.equal 80
15
+ rect.bottom.should.equal -20
16
+ rect.width.should.equal 100
17
+ rect.height.should.equal 100
18
+ rect.center_x.should.equal 60
19
+ rect.center_y.should.equal 30
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,31 @@
1
+ class NSSize
2
+ def close?(to, delta)
3
+ width.close?(to.width, delta) && height.close?(to.height, delta)
4
+ end
5
+ end
6
+
7
+ if PurplishFrame.osx?
8
+ describe "Sizes" do
9
+ delta = 0.0001
10
+
11
+ it "NSSize scaling" do
12
+ #Careful not to use NSMakeSize(). Somehow, it creates a CGSize instead
13
+ NSSize.new(100, 100).scale_to_fit(NSSize.new(10, 10)).should.close NSSize.new(10, 10), delta
14
+ NSSize.new(200, 100).scale_to_fit(NSSize.new(15, 15)).should.close NSSize.new(15, 7.5), delta
15
+ NSSize.new(100, 100).scale_to_fill(NSSize.new(10, 10)).should.close NSSize.new(10, 10), delta
16
+ NSSize.new(200, 100).scale_to_fill(NSSize.new(15, 15)).should.close NSSize.new(30, 15), delta
17
+ NSSize.new(10, 10).scale_to_fit(NSSize.new(100, 100)).should.close NSSize.new(100, 100), delta
18
+ NSSize.new(10, 5).scale_to_fit(NSSize.new(100, 100)).should.close NSSize.new(100, 50), delta
19
+ NSSize.new(10, 10).scale_to_fill(NSSize.new(100, 100)).should.close NSSize.new(100, 100), delta
20
+ NSSize.new(10, 5).scale_to_fill(NSSize.new(100, 100)).should.close NSSize.new(200, 100), delta
21
+
22
+ s = NSSize.new(200, 100)
23
+ s.scale_to_fit!(NSSize.new(15, 15))
24
+ s.should.close NSSize.new(15, 7.5), delta
25
+
26
+ s = NSSize.new(10, 5)
27
+ s.scale_to_fill!(NSSize.new(100, 100))
28
+ s.should.close NSSize.new(200, 100), delta
29
+ end
30
+ end
31
+ end
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: purplish-frame
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Hwee-Boon Yar
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-12-03 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Make working with rects, sizes and points more convenient with RubyMotion
14
+ for iOS & OS X
15
+ email: hboon@motionobj.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".gitignore"
21
+ - Gemfile
22
+ - Gemfile.lock
23
+ - LICENSE
24
+ - README.md
25
+ - Rakefile
26
+ - app/app_delegate.rb
27
+ - lib/purplish-frame.rb
28
+ - lib/purplish-frame/can_scale_width_height.rb
29
+ - lib/purplish-frame/cg_point.rb
30
+ - lib/purplish-frame/cg_rect.rb
31
+ - lib/purplish-frame/cg_size.rb
32
+ - lib/purplish-frame/ns_array.rb
33
+ - lib/purplish-frame/osx/ns_array.rb
34
+ - lib/purplish-frame/osx/ns_point.rb
35
+ - lib/purplish-frame/osx/ns_rect.rb
36
+ - lib/purplish-frame/osx/ns_size.rb
37
+ - lib/purplish-frame/point.rb
38
+ - lib/purplish-frame/purplish_frame.rb
39
+ - lib/purplish-frame/rect.rb
40
+ - lib/purplish-frame/version.rb
41
+ - purplish-frame.gemspec
42
+ - spec/cg_point_spec.rb
43
+ - spec/cg_rect_spec.rb
44
+ - spec/cg_size.spec.rb
45
+ - spec/osx/ns_point_spec.rb
46
+ - spec/osx/ns_rect_spec.rb
47
+ - spec/osx/ns_size_spec.rb
48
+ homepage: https://github.com/hboon/purplish-frame
49
+ licenses:
50
+ - BSD
51
+ metadata: {}
52
+ post_install_message:
53
+ rdoc_options: []
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ requirements: []
67
+ rubyforge_project:
68
+ rubygems_version: 2.4.2
69
+ signing_key:
70
+ specification_version: 4
71
+ summary: Make working with rects, sizes and points more convenient with RubyMotion
72
+ for iOS & OS X
73
+ test_files:
74
+ - spec/cg_point_spec.rb
75
+ - spec/cg_rect_spec.rb
76
+ - spec/cg_size.spec.rb
77
+ - spec/osx/ns_point_spec.rb
78
+ - spec/osx/ns_rect_spec.rb
79
+ - spec/osx/ns_size_spec.rb
80
+ has_rdoc: