Sutto / 88miles

Simple OSX client for 88miles built with MacRuby

This URL has Read+Write access

88miles / GradientView.rb
100644 35 lines (29 sloc) 0.838 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#
# GradientView.rb
#
# Simple view which draws a user-configurable gradient.
# Based off code from http://tr.im/hs7J (in Obj-C, ported
# to MacRuby)
#
# Created by Darcy Laycock on 17/03/09.
# Copyright (c) 2009 BrownBeagle. All rights reserved.
#
 
class GradientView < NSView
  
  attr_accessor :startColour, :endColour, :gradientAngle
 
  def initWithFrame(frame)
    super
    self.startColour = NSColor.colorWithCalibratedWhite(1.0, alpha: 1.0)
    self.endColour = nil
    self.gradientAngle = 90
    return self
  end
 
  def drawRect(rect)
    if endColour == nil || startColour == endColour
      startColour.set
      NSRectFill(rect)
    else
      gradient = NSGradient.alloc.initWithStartingColor(startColour, endingColor: endColour)
      gradient.drawInRect(self.bounds, angle: gradientAngle)
    end
  end
 
end