motion-meter 1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +73 -0
- data/lib/motion-meter.rb +7 -0
- data/lib/motion/meter/threshold_meter.rb +36 -0
- data/lib/motion/meter/version.rb +5 -0
- metadata +49 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a73dbc2e89c3dc3e86692b1ea7439ae35f1f8180
|
4
|
+
data.tar.gz: 7146eb4a49718dc49102d61a8a0dea75683bf331
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 60c8e04a162e98c5e5f0977f2cf61bc435b158f5ab32c1bc2e88a2a39f1d8c503a5511c82b3138c286c8104245c06187aa9455183f1baa200dd87ca081169347
|
7
|
+
data.tar.gz: e9900b8c2a860d8ebd5a199d77f973c50946274b0c9f3e6890c91ecbb242e05db139aa04193d1152bfa8aadeb832045bcab4caaf4aff1a3866cf857626f2d22e
|
data/README.md
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
# motion-meter
|
2
|
+
|
3
|
+
A simple bar meter control with color based thresholds, useful for displaying a value such as an audio level according to whatever threshold and color rules you want to setup.
|
4
|
+
|
5
|
+
## Requirements
|
6
|
+
|
7
|
+
* RubyMotion
|
8
|
+
* RubyGems
|
9
|
+
|
10
|
+
## Setup
|
11
|
+
|
12
|
+
Add to your Gemfile:
|
13
|
+
|
14
|
+
``` shell
|
15
|
+
gem 'motion-meter'
|
16
|
+
```
|
17
|
+
|
18
|
+
Or install manually:
|
19
|
+
|
20
|
+
* gem install motion-meter
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
To setup the control, you can do the following:
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
@audio_level = Motion::Meter::ThresholdMeter.alloc.initWithFrame([[0, @mainWindow.contentView.bounds.size.height / 2.0], [@mainWindow.contentView.bounds.size.width, 30]])
|
28
|
+
@audio_level.add_threshold(-20, -5, NSColor.greenColor)
|
29
|
+
@audio_level.add_threshold(-5, 3, NSColor.yellowColor)
|
30
|
+
@audio_level.add_threshold(3, 10, NSColor.redColor)
|
31
|
+
@audio_level.min_value = -20
|
32
|
+
@audio_level.max_value = 10
|
33
|
+
@mainWindow.contentView.addSubview(@audio_level)
|
34
|
+
```
|
35
|
+
|
36
|
+
You can then simple update the value to see it change in real-time:
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
@audio_level.value = value
|
40
|
+
```
|
41
|
+
|
42
|
+
## TODO
|
43
|
+
|
44
|
+
* Optionally displaying the value
|
45
|
+
* Optionally displaying the values of the thresholds along the top or bottom
|
46
|
+
* Additional display options/controls for meters, such as a needle display or something more fancy
|
47
|
+
|
48
|
+
## Contributors
|
49
|
+
|
50
|
+
* Elliott Draper
|
51
|
+
|
52
|
+
## License
|
53
|
+
|
54
|
+
Copyright 2015 Elliott Draper <el@kickcode.com>
|
55
|
+
|
56
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
57
|
+
a copy of this software and associated documentation files (the
|
58
|
+
"Software"), to deal in the Software without restriction, including
|
59
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
60
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
61
|
+
permit persons to whom the Software is furnished to do so, subject to
|
62
|
+
the following conditions:
|
63
|
+
|
64
|
+
The above copyright notice and this permission notice shall be
|
65
|
+
included in all copies or substantial portions of the Software.
|
66
|
+
|
67
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
68
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
69
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
70
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
71
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
72
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
73
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/lib/motion-meter.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
class Motion::Meter::ThresholdMeter < NSView
|
2
|
+
Threshold = Struct.new(:start, :finish, :color)
|
3
|
+
|
4
|
+
attr_accessor :min_value, :max_value, :value, :thresholds
|
5
|
+
|
6
|
+
def add_threshold(start, finish, color)
|
7
|
+
self.thresholds ||= []
|
8
|
+
self.thresholds << Threshold.new(start, finish, color)
|
9
|
+
end
|
10
|
+
|
11
|
+
def range
|
12
|
+
self.max_value - self.min_value
|
13
|
+
end
|
14
|
+
|
15
|
+
def draw_width
|
16
|
+
(self.bounds.size.width / self.range.to_f) * ((self.value || 0) - self.min_value)
|
17
|
+
end
|
18
|
+
|
19
|
+
def value=(value)
|
20
|
+
@value = value
|
21
|
+
self.needsDisplay = true
|
22
|
+
end
|
23
|
+
|
24
|
+
def drawRect(frame)
|
25
|
+
frame.size = [self.draw_width, frame.size.height]
|
26
|
+
|
27
|
+
if (self.thresholds || []).any?
|
28
|
+
threshold = self.thresholds.detect { |threshold| threshold.start < (self.value || 0) && threshold.finish > (self.value || 0) }
|
29
|
+
color = threshold.color unless threshold.nil?
|
30
|
+
end
|
31
|
+
|
32
|
+
(color || NSColor.greenColor).setFill
|
33
|
+
|
34
|
+
NSRectFill(frame)
|
35
|
+
end
|
36
|
+
end
|
metadata
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: motion-meter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '1.0'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Elliott Draper
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-05-07 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: motion-meter is a simple bar meter control with color based thresholds,
|
14
|
+
useful for displaying a value such as an audio level according to whatever threshold
|
15
|
+
and color rules you want to setup.
|
16
|
+
email: el@kickcode.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- README.md
|
22
|
+
- lib/motion-meter.rb
|
23
|
+
- lib/motion/meter/threshold_meter.rb
|
24
|
+
- lib/motion/meter/version.rb
|
25
|
+
homepage:
|
26
|
+
licenses:
|
27
|
+
- MIT
|
28
|
+
metadata: {}
|
29
|
+
post_install_message:
|
30
|
+
rdoc_options: []
|
31
|
+
require_paths:
|
32
|
+
- lib
|
33
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - '>='
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0'
|
43
|
+
requirements: []
|
44
|
+
rubyforge_project:
|
45
|
+
rubygems_version: 2.2.2
|
46
|
+
signing_key:
|
47
|
+
specification_version: 4
|
48
|
+
summary: Simple visual meter control with color based thresholds
|
49
|
+
test_files: []
|