motion-popup 1.0

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: 956fa4f7b20fe96de2493b8e49229b05c25e171c
4
+ data.tar.gz: 8df7870f25b784728a4794c8d60a6db51f742cb6
5
+ SHA512:
6
+ metadata.gz: 61cc869b3b688cb2c3f7e6ea51dd27aa86c51e9331dae9ca713313639308eed8ed1fc214db582b8cbde1e195757ef20f3faaa72329e100f67aecaed5e400a534
7
+ data.tar.gz: 1919d1f5bb96c7324fc7ee81312e91ac0fa370f2e115aba0faffaaf7adc436b5867132137c868ea3345344eaa02356dfa953f9fb92bc2e6cf3760470829d0f15
data/README.md ADDED
@@ -0,0 +1,88 @@
1
+ # motion-popup
2
+
3
+ Customisable fancy popup window for your Mac OS X status bar apps
4
+
5
+ ## Requirements
6
+
7
+ * RubyMotion
8
+ * RubyGems
9
+
10
+ ## Setup
11
+
12
+ Add to your Gemfile:
13
+
14
+ ``` shell
15
+ gem 'motion-popup'
16
+ ```
17
+
18
+ Or install manually:
19
+
20
+ * gem install motion-popup
21
+
22
+ ## Usage
23
+
24
+ You can create a popup window within your app like this:
25
+
26
+ ``` ruby
27
+ @window = Motion::Popup::Panel.alloc.initPopup(POPUP_WIDTH, POPUP_HEIGHT)
28
+ ```
29
+
30
+ You can customise how the background panel is drawn by setting the following values (the values shown here are the defaults):
31
+
32
+ ``` ruby
33
+ @window.background.arrow_height = 12
34
+ @window.background.arrow_width = 15
35
+ @window.background.line_thickness = 1
36
+ @window.background.corner_radius = 20
37
+ ```
38
+
39
+ arrow_height and arrow_width refer to the arrow pointer on the top of the panel that'll point to the status bar menu item. line_thickness is the outer border for the panel, and corner_radius affects the drawing of the rounded corners for the panel.
40
+
41
+ You can then fill the window with additional views using:
42
+
43
+ ``` ruby
44
+ @window.contentView.addSubview(my_other_view)
45
+ ```
46
+
47
+ Lastly, you can toggle showing the window using:
48
+
49
+ ``` ruby
50
+ @window.toggle
51
+ ```
52
+
53
+ For example, you can set the window as the delegate for your status menu item, and set the action to toggle so it triggers the window:
54
+
55
+ ``` ruby
56
+ @status_item = NSStatusBar.systemStatusBar.statusItemWithLength(NSVariableStatusItemLength).init
57
+ @status_item.setTarget(@window)
58
+ @status_item.setAction('toggle')
59
+ ```
60
+
61
+ This handles updating the windows position to sit under the menu item, with the arrow pointer directly in the middle. The window itself handles hiding itself when it loses focus, and ensuring the toggle then allows it to be reshown when the menu is clicked again.
62
+
63
+ ## Contributors
64
+
65
+ * Elliott Draper
66
+
67
+ ## License
68
+
69
+ Copyright 2014 Elliott Draper <el@kickcode.com>
70
+
71
+ Permission is hereby granted, free of charge, to any person obtaining
72
+ a copy of this software and associated documentation files (the
73
+ "Software"), to deal in the Software without restriction, including
74
+ without limitation the rights to use, copy, modify, merge, publish,
75
+ distribute, sublicense, and/or sell copies of the Software, and to
76
+ permit persons to whom the Software is furnished to do so, subject to
77
+ the following conditions:
78
+
79
+ The above copyright notice and this permission notice shall be
80
+ included in all copies or substantial portions of the Software.
81
+
82
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
83
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
84
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
85
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
86
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
87
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
88
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,7 @@
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
+ app.files = [Dir.glob(File.join(File.dirname(__FILE__), "motion/**/*.rb")), app.files].flatten
7
+ end
@@ -0,0 +1,64 @@
1
+ # Drawing code for the popup panel background ported from this excellent Obj-C popup demo code
2
+ # https://github.com/shpakovski/Popup / http://blog.shpakovski.com/2011/07/cocoa-popup-window-in-status-bar.html
3
+ class Motion::Popup::Background < NSView
4
+ attr_accessor :arrow_height, :arrow_width, :line_thickness, :corner_radius
5
+
6
+ def initWithFrame(frame)
7
+ self.arrow_height = 12
8
+ self.arrow_width = 15
9
+ self.line_thickness = 1
10
+ self.corner_radius = 20
11
+
12
+ super(frame)
13
+ end
14
+
15
+ def drawRect(rect)
16
+ return unless @arrow_x
17
+ content_rect = NSInsetRect(self.bounds, self.line_thickness, self.line_thickness)
18
+ path = NSBezierPath.bezierPath
19
+
20
+ path.moveToPoint(NSMakePoint(@arrow_x, NSMaxY(content_rect)))
21
+ path.lineToPoint(NSMakePoint(@arrow_x + self.arrow_width / 2, NSMaxY(content_rect) - self.arrow_height))
22
+ path.lineToPoint(NSMakePoint(NSMaxX(content_rect) - self.corner_radius, NSMaxY(content_rect) - self.arrow_height))
23
+
24
+ top_right_corner = NSMakePoint(NSMaxX(content_rect), NSMaxY(content_rect) - self.arrow_height)
25
+ path.curveToPoint(NSMakePoint(NSMaxX(content_rect), NSMaxY(content_rect) - self.arrow_height - self.corner_radius), controlPoint1: top_right_corner, controlPoint2: top_right_corner)
26
+
27
+ path.lineToPoint(NSMakePoint(NSMaxX(content_rect), NSMinY(content_rect) + self.corner_radius))
28
+
29
+ bottom_right_corner = NSMakePoint(NSMaxX(content_rect), NSMinY(content_rect))
30
+ path.curveToPoint(NSMakePoint(NSMaxX(content_rect) - self.corner_radius, NSMinY(content_rect)), controlPoint1: bottom_right_corner, controlPoint2: bottom_right_corner)
31
+
32
+ path.lineToPoint(NSMakePoint(NSMinX(content_rect) + self.corner_radius, NSMinY(content_rect)))
33
+
34
+ path.curveToPoint(NSMakePoint(NSMinX(content_rect), NSMinY(content_rect) + self.corner_radius), controlPoint1: content_rect.origin, controlPoint2: content_rect.origin)
35
+
36
+ path.lineToPoint(NSMakePoint(NSMinX(content_rect), NSMaxY(content_rect) - self.arrow_height - self.corner_radius))
37
+
38
+ top_left_corner = NSMakePoint(NSMinX(content_rect), NSMaxY(content_rect) - self.arrow_height)
39
+ path.curveToPoint(NSMakePoint(NSMinX(content_rect) + self.corner_radius, NSMaxY(content_rect) - self.arrow_height), controlPoint1: top_left_corner, controlPoint2: top_left_corner)
40
+
41
+ path.lineToPoint(NSMakePoint(@arrow_x - self.arrow_width / 2, NSMaxY(content_rect) - self.arrow_height))
42
+ path.closePath
43
+
44
+ NSColor.whiteColor.setFill
45
+ path.fill
46
+
47
+ NSGraphicsContext.saveGraphicsState
48
+
49
+ clip = NSBezierPath.bezierPathWithRect(self.bounds)
50
+ clip.appendBezierPath(path)
51
+ clip.addClip
52
+
53
+ path.setLineWidth(self.line_thickness * 2)
54
+ NSColor.lightGrayColor.setStroke
55
+ path.stroke
56
+
57
+ NSGraphicsContext.restoreGraphicsState
58
+ end
59
+
60
+ def setArrowX(value)
61
+ @arrow_x = value
62
+ self.setNeedsDisplay(true)
63
+ end
64
+ end
@@ -0,0 +1,43 @@
1
+ class Motion::Popup::Panel < NSPanel
2
+ attr_accessor :background
3
+
4
+ def initPopup(width, height)
5
+ self.initWithContentRect([[0, 0], [width, height]],
6
+ styleMask: NSBorderlessWindowMask,
7
+ backing: NSBackingStoreBuffered,
8
+ defer: false)
9
+ self.title = NSBundle.mainBundle.infoDictionary['CFBundleName']
10
+ self.delegate = self
11
+ self.setBackgroundColor(NSColor.clearColor)
12
+ self.setOpaque(false)
13
+
14
+ self.background = Motion::Popup::Background.alloc.initWithFrame(self.frame)
15
+ self.setContentView(self.background)
16
+
17
+ self
18
+ end
19
+
20
+ def toggle
21
+ if self.isVisible
22
+ self.orderOut(false)
23
+ else
24
+ event_frame = NSApp.currentEvent.window.frame
25
+ window_frame = self.frame
26
+ window_top_left_position = CGPointMake(event_frame.origin.x + (event_frame.size.width / 2) - (window_frame.size.width / 2), event_frame.origin.y)
27
+ self.setFrameTopLeftPoint(window_top_left_position)
28
+
29
+ self.background.setArrowX(window_frame.size.width / 2)
30
+
31
+ NSApp.activateIgnoringOtherApps(true)
32
+ self.makeKeyAndOrderFront(self)
33
+ end
34
+ end
35
+
36
+ def canBecomeKeyWindow
37
+ true
38
+ end
39
+
40
+ def windowDidResignKey(sender)
41
+ self.orderOut(false)
42
+ end
43
+ end
@@ -0,0 +1,5 @@
1
+ module Motion
2
+ module Popup
3
+ VERSION = 1.0
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,49 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: motion-popup
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: 2014-01-03 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: motion-popup provides an easy to use popup window with customisable nice
14
+ looking background panel to use in Mac OS X status bar apps.
15
+ email: el@kickcode.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/motion/popup/background.rb
21
+ - lib/motion/popup/panel.rb
22
+ - lib/motion/popup/version.rb
23
+ - lib/motion-popup.rb
24
+ - README.md
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.0.3
46
+ signing_key:
47
+ specification_version: 4
48
+ summary: Customisable fancy popup window for your Mac OS X status bar apps
49
+ test_files: []