Class: Motion::Popup::Background
- Inherits:
-
NSView
- Object
- NSView
- Motion::Popup::Background
- Defined in:
- lib/motion/popup/background.rb
Overview
Drawing code for the popup panel background ported from this excellent Obj-C popup demo code github.com/shpakovski/Popup / blog.shpakovski.com/2011/07/cocoa-popup-window-in-status-bar.html
Instance Attribute Summary collapse
-
#arrow_height ⇒ Object
Returns the value of attribute arrow_height.
-
#arrow_width ⇒ Object
Returns the value of attribute arrow_width.
-
#corner_radius ⇒ Object
Returns the value of attribute corner_radius.
-
#line_thickness ⇒ Object
Returns the value of attribute line_thickness.
Instance Method Summary collapse
Instance Attribute Details
#arrow_height ⇒ Object
Returns the value of attribute arrow_height.
4 5 6 |
# File 'lib/motion/popup/background.rb', line 4 def arrow_height @arrow_height end |
#arrow_width ⇒ Object
Returns the value of attribute arrow_width.
4 5 6 |
# File 'lib/motion/popup/background.rb', line 4 def arrow_width @arrow_width end |
#corner_radius ⇒ Object
Returns the value of attribute corner_radius.
4 5 6 |
# File 'lib/motion/popup/background.rb', line 4 def corner_radius @corner_radius end |
#line_thickness ⇒ Object
Returns the value of attribute line_thickness.
4 5 6 |
# File 'lib/motion/popup/background.rb', line 4 def line_thickness @line_thickness end |
Instance Method Details
#drawRect(rect) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/motion/popup/background.rb', line 15 def drawRect(rect) content_rect = NSInsetRect(self.bounds, self.line_thickness, self.line_thickness) path = NSBezierPath.bezierPath top_left_corner = NSMakePoint(NSMinX(content_rect), NSMaxY(content_rect) - self.arrow_height) path.moveToPoint(NSMakePoint(top_left_corner.x + self.corner_radius, top_left_corner.y)) if @arrow_x path.lineToPoint(NSMakePoint(@arrow_x - self.arrow_width / 2, NSMaxY(content_rect) - self.arrow_height)) path.lineToPoint(NSMakePoint(@arrow_x, NSMaxY(content_rect))) path.lineToPoint(NSMakePoint(@arrow_x + self.arrow_width / 2, NSMaxY(content_rect) - self.arrow_height)) end path.lineToPoint(NSMakePoint(NSMaxX(content_rect) - self.corner_radius, NSMaxY(content_rect) - self.arrow_height)) top_right_corner = NSMakePoint(NSMaxX(content_rect), NSMaxY(content_rect) - self.arrow_height) path.curveToPoint(NSMakePoint(NSMaxX(content_rect), NSMaxY(content_rect) - self.arrow_height - self.corner_radius), controlPoint1: top_right_corner, controlPoint2: top_right_corner) path.lineToPoint(NSMakePoint(NSMaxX(content_rect), NSMinY(content_rect) + self.corner_radius)) bottom_right_corner = NSMakePoint(NSMaxX(content_rect), NSMinY(content_rect)) path.curveToPoint(NSMakePoint(NSMaxX(content_rect) - self.corner_radius, NSMinY(content_rect)), controlPoint1: bottom_right_corner, controlPoint2: bottom_right_corner) path.lineToPoint(NSMakePoint(NSMinX(content_rect) + self.corner_radius, NSMinY(content_rect))) path.curveToPoint(NSMakePoint(NSMinX(content_rect), NSMinY(content_rect) + self.corner_radius), controlPoint1: content_rect.origin, controlPoint2: content_rect.origin) path.lineToPoint(NSMakePoint(NSMinX(content_rect), NSMaxY(content_rect) - self.arrow_height - self.corner_radius)) path.curveToPoint(NSMakePoint(NSMinX(content_rect) + self.corner_radius, NSMaxY(content_rect) - self.arrow_height), controlPoint1: top_left_corner, controlPoint2: top_left_corner) path.closePath NSColor.whiteColor.setFill path.fill NSGraphicsContext.saveGraphicsState clip = NSBezierPath.bezierPathWithRect(self.bounds) clip.appendBezierPath(path) clip.addClip path.setLineWidth(self.line_thickness * 2) NSColor.lightGrayColor.setStroke path.stroke NSGraphicsContext.restoreGraphicsState end |
#initWithFrame(frame) ⇒ Object
6 7 8 9 10 11 12 13 |
# File 'lib/motion/popup/background.rb', line 6 def initWithFrame(frame) self.arrow_height = 12 self.arrow_width = 15 self.line_thickness = 1 self.corner_radius = 20 super(frame) end |
#setArrowX(value) ⇒ Object
66 67 68 69 |
# File 'lib/motion/popup/background.rb', line 66 def setArrowX(value) @arrow_x = value self.setNeedsDisplay(true) end |