Class: Opine::Dark::Window::TitleView

Inherits:
Cocoa::NSView
  • Object
show all
Defined in:
lib/opine/widgets/window_dark_osx.rb

Instance Method Summary collapse

Instance Method Details

#drawRect(rect) ⇒ Object



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
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/opine/widgets/window_dark_osx.rb', line 4

def drawRect rect
  width = frame[:size][:width]
  height = frame[:size][:height]

  # rounded corners
  NSColor.clearColor.set
  NSRectFill(NSMakeRect(0, height-1, 4, 1))
  NSRectFill(NSMakeRect(0, height-2, 2, 1))
  NSRectFill(NSMakeRect(0, height-4, 1, 2))
  NSRectFill(NSMakeRect(width-4, height-1, 4, 1))
  NSRectFill(NSMakeRect(width-2, height-2, 2, 1))
  NSRectFill(NSMakeRect(width-1, height-4, 1, 2))

  # NSRectFill(NSMakeRect(fw - 2, 22, 2, 1))
  # NSRectFill(NSMakeRect(fw - 1, 21, 1, 1))

  context = NSGraphicsContext.currentContext.graphicsPort

  Cocoa::CGContextTranslateCTM(context, 0.0, rect[:size][:height])
  Cocoa::CGContextScaleCTM(context, 1.0, -1.0)

  Cairo::QuartzSurface.new(context, rect[:size][:width], rect[:size][:height]) do |surface|
    cr = Cairo::Context.new(surface)
    cr.push_group

    # clip path
    cr.move_to(0, height)
    cr.line_to(0, 5)
    cr.curve_to(0, 2, 2, 0, 5, 0)
    cr.line_to(width-5, 0)
    cr.curve_to(width-2, 0, width, 2, width, 5)
    cr.line_to(width, height)
    cr.clip
    cr.new_path

    # gradients in heading
    pat = Cairo::LinearPattern.new(0.0, 0.0, 0.0, height/2.0)
    pat.add_color_stop(0, 0.0, 0.0, 0.0)
    pat.add_color_stop(1, 0.2, 0.2, 0.2)
    cr.rectangle(0, 0, width, (height/2.0))
    cr.set_source(pat)
    cr.fill

    pat = Cairo::LinearPattern.new(0.0, 0.0, 0.0, height/2.0)
    pat.add_color_stop(0, :black)
    pat.add_color_stop(1, :black)
    cr.rectangle(0, height/2.0-1, width, height/2.0)
    cr.set_source(pat)
    cr.fill

    # specular rim
    cr.set_source_color([0.4,0.4,0.4])
    cr.set_line_width(3)

    cr.move_to(0, 5)
    cr.curve_to(0, 2, 2, 0, 5, 0)
    cr.line_to(width-5, 0)
    cr.curve_to(width-2, 0, width, 2, width, 5)
    cr.stroke

    # outer rim
    cr.set_source_color(:black)
    cr.set_line_width(2)

    cr.move_to(0, height-1)
    cr.line_to(0, 5)
    cr.curve_to(0, 2, 2, 0, 5, 0)
    cr.line_to(width-5, 0)
    cr.curve_to(width-2, 0, width, 2, width, 5)
    cr.line_to(width, height-1)
    cr.stroke

    cr.pop_group_to_source
    cr.paint
  end
end

#isOpaqueObject



86
87
88
# File 'lib/opine/widgets/window_dark_osx.rb', line 86

def isOpaque
  true
end

#mouseDragged(theEvent) ⇒ Object



81
82
83
84
# File 'lib/opine/widgets/window_dark_osx.rb', line 81

def mouseDragged theEvent
  origin = window.frame[:origin]
  window.setFrameOrigin NSMakePoint(origin[:x] + theEvent.deltaX, origin[:y] - theEvent.deltaY)
end