Class: Nyle::Screen
- Inherits:
-
Gtk::DrawingArea
- Object
- Gtk::DrawingArea
- Nyle::Screen
- Defined in:
- lib/nyle/screen.rb
Overview
Screen
Instance Attribute Summary collapse
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
Instance Method Summary collapse
-
#clear_screen ⇒ Object
Clear.
- #draw ⇒ Object
-
#initialize(width = DEFAULT_WIDTH, height = DEFAULT_HEIGHT, bgcolor: :WHITE, trace: false) ⇒ Screen
constructor
A new instance of Screen.
- #resume ⇒ Object
- #setup ⇒ Object
-
#show_all(title: nil, interval: nil) ⇒ Object
When single screen, create frame to show self.
-
#start(*args) ⇒ Object
Syntax sugar for starting Nyle aplication.
- #suspend ⇒ Object
-
#update ⇒ Object
Abstract methods to be overriden.
Constructor Details
#initialize(width = DEFAULT_WIDTH, height = DEFAULT_HEIGHT, bgcolor: :WHITE, trace: false) ⇒ Screen
Returns a new instance of Screen.
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/nyle/screen.rb', line 17 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 |, event| ; # For resizing and so on end self.signal_connect(:draw) do |, 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 |, event| Nyle.module_eval { _set_mouse_pos(event.x.to_i, event.y.to_i) } false end end |
Instance Attribute Details
#height ⇒ Object (readonly)
Returns the value of attribute height.
16 17 18 |
# File 'lib/nyle/screen.rb', line 16 def height @height end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
16 17 18 |
# File 'lib/nyle/screen.rb', line 16 def status @status end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
16 17 18 |
# File 'lib/nyle/screen.rb', line 16 def width @width end |
Instance Method Details
#clear_screen ⇒ Object
Clear
82 83 84 85 |
# File 'lib/nyle/screen.rb', line 82 def clear_screen Nyle.cr.set_operator(Cairo::Operator::CLEAR) Nyle.cr.paint end |
#draw ⇒ Object
105 |
# File 'lib/nyle/screen.rb', line 105 def draw ; end |
#resume ⇒ Object
107 |
# File 'lib/nyle/screen.rb', line 107 def resume ; end |
#setup ⇒ Object
108 |
# File 'lib/nyle/screen.rb', line 108 def setup ; end |
#show_all(title: nil, interval: nil) ⇒ Object
When single screen, create frame to show self
88 89 90 91 92 93 |
# File 'lib/nyle/screen.rb', line 88 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
96 97 98 99 100 |
# File 'lib/nyle/screen.rb', line 96 def start(*args) self.setup self.show_all(*args) Nyle.main end |
#suspend ⇒ Object
106 |
# File 'lib/nyle/screen.rb', line 106 def suspend ; end |
#update ⇒ Object
Abstract methods to be overriden
104 |
# File 'lib/nyle/screen.rb', line 104 def update ; end |