Class: Nyle::Screen

Inherits:
Gtk::DrawingArea
  • Object
show all
Defined in:
lib/nyle/screen.rb

Overview

Screen

Defined Under Namespace

Classes: Layer

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(width = DEFAULT_WIDTH, height = DEFAULT_HEIGHT, bgcolor: :WHITE, trace: false) ⇒ Screen

Returns a new instance of Screen.



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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/nyle/screen.rb', line 41

def initialize(width = DEFAULT_WIDTH, height = DEFAULT_HEIGHT, bgcolor: :WHITE, trace: false)
  super()
  @width         = width
  @height        = height
  @trace         = trace
  @bgcolor       = bgcolor
  @running_count = 0
  @status        = nil

  Nyle.module_eval {
    _set_screen_size(width, height)
  }

  # Draw to 'CairoContext' of ImageSurface once, and copy to 'CairoContext' of DrawingArea
  @canvas = Cairo::ImageSurface.new(@width, @height)

  self.signal_connect(:configure_event) do |widget, event|
    ;   # For resizing and so on
  end

  self.signal_connect(:draw) do |widget, cairo_context|
    Nyle.module_eval {
      _update_mouse_state
      _update_key_state
    }
    # Draw to 'CairoContext' of ImageSurface
    Cairo::Context.new(@canvas) do |cr|
      Nyle.module_eval {
        _set_cr(cr)
      }
      unless @trace                       # If not trace, clear screen each time
        Nyle.save do
          Nyle.cr.set_operator(Cairo::Operator::CLEAR)
          Nyle.cr.paint
        end
      end
      update
      draw
    end
    # Copy to 'CairoContext' of DrawingArea
    Nyle.module_eval {
      _set_cr(cairo_context)
    }
    Nyle.cr.set_source_color(@bgcolor)
    Nyle.cr.paint
    Nyle.cr.set_source(@canvas, 0, 0)
    Nyle.cr.paint
    @running_count += 1
  end

  # Need not only :pointer_motion but also :button_press and :button_release
  self.add_events([:button_press_mask,
                   :button_release_mask,
                   :pointer_motion_mask])

  # Signal handler for mouse position
  self.signal_connect(:motion_notify_event) do |widget, event|
    Nyle.module_eval {
      _set_mouse_pos(event.x.to_i, event.y.to_i)
    }
    false
  end
end

Instance Attribute Details

#heightObject (readonly)

Returns the value of attribute height.



40
41
42
# File 'lib/nyle/screen.rb', line 40

def height
  @height
end

#statusObject (readonly)

Returns the value of attribute status.



40
41
42
# File 'lib/nyle/screen.rb', line 40

def status
  @status
end

#widthObject (readonly)

Returns the value of attribute width.



40
41
42
# File 'lib/nyle/screen.rb', line 40

def width
  @width
end

Instance Method Details

#clear_screenObject

Clear



106
107
108
109
110
111
# File 'lib/nyle/screen.rb', line 106

def clear_screen
  Nyle.save do
    Nyle.cr.set_operator(Cairo::Operator::CLEAR)
    Nyle.cr.paint
  end
end

#drawObject



131
# File 'lib/nyle/screen.rb', line 131

def draw    ; end

#resumeObject



133
# File 'lib/nyle/screen.rb', line 133

def resume  ; end

#setupObject



134
# File 'lib/nyle/screen.rb', line 134

def setup   ; end

#show_all(title: nil, interval: nil) ⇒ Object

When single screen, create frame to show self



114
115
116
117
118
119
# File 'lib/nyle/screen.rb', line 114

def show_all(title: nil, interval: nil)
  f = Nyle::Frame.new(@width, @height)
  f.set_current(self)
  f.show_all({title: title, interval: interval})
  f
end

#start(*args) ⇒ Object

Syntax sugar for starting Nyle aplication



122
123
124
125
126
# File 'lib/nyle/screen.rb', line 122

def start(*args)
  self.setup
  self.show_all(*args)
  Nyle.main
end

#suspendObject



132
# File 'lib/nyle/screen.rb', line 132

def suspend ; end

#updateObject

Abstract methods to be overriden



130
# File 'lib/nyle/screen.rb', line 130

def update  ; end