Class: Nyle::Screen
- Inherits:
-
Gtk::DrawingArea
- Object
- Gtk::DrawingArea
- Nyle::Screen
- Defined in:
- lib/nyle/screen.rb
Overview
Screen
Defined Under Namespace
Classes: Layer
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.
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 |, 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.
40 41 42 |
# File 'lib/nyle/screen.rb', line 40 def height @height end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
40 41 42 |
# File 'lib/nyle/screen.rb', line 40 def status @status end |
#width ⇒ Object (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_screen ⇒ Object
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 |
#draw ⇒ Object
131 |
# File 'lib/nyle/screen.rb', line 131 def draw ; end |
#resume ⇒ Object
133 |
# File 'lib/nyle/screen.rb', line 133 def resume ; end |
#setup ⇒ Object
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 |
#suspend ⇒ Object
132 |
# File 'lib/nyle/screen.rb', line 132 def suspend ; end |
#update ⇒ Object
Abstract methods to be overriden
130 |
# File 'lib/nyle/screen.rb', line 130 def update ; end |