Class: SlideField::Viewer
- Inherits:
-
Gosu::Window
- Object
- Gosu::Window
- SlideField::Viewer
- Defined in:
- lib/slidefield/viewer.rb
Constant Summary collapse
- LOAD_AROUND =
preloader settings
4
- LOAD_DELAY =
1000
Instance Method Summary collapse
- #button_down(id) ⇒ Object
- #change_slide(index) ⇒ Object
- #draw ⇒ Object
-
#initialize(project) ⇒ Viewer
constructor
A new instance of Viewer.
- #needs_redraw? ⇒ Boolean
- #update ⇒ Object
Constructor Details
#initialize(project) ⇒ Viewer
Returns a new instance of Viewer.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/slidefield/viewer.rb', line 6 def initialize(project) layout = project[:layout].first layout_size = layout.get :size fullscreen = layout.get :fullscreen super *layout_size, fullscreen @time = 0 @animator = SlideField::Animator.new layout_size @slides = [] project[:slide].each {|| manager = SlideField::ObjectManager.new , self @slides << manager } 0 end |
Instance Method Details
#button_down(id) ⇒ Object
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 |
# File 'lib/slidefield/viewer.rb', line 58 def (id) case id when Gosu::KbHome 0 when Gosu::KbEnd @slides.length-1 when Gosu::KbReturn, Gosu::KbSpace, Gosu::KbTab, Gosu::KbRight, Gosu::KbDown, Gosu::KbPageDown, Gosu::KbNumpadAdd @current+1 when Gosu::KbBackspace, Gosu::KbLeft, Gosu::KbUp, Gosu::KbPageUp, Gosu::KbNumpadSubtract @current-1 when Gosu::KbEscape, Gosu::KbQ close end end |
#change_slide(index) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/slidefield/viewer.rb', line 87 def (index) return if @current == index || index < 0 || index > @slides.length-1 @previous = @current @current = index if @previous @slides[@previous].deactivate @forward = @previous < @current else @forward = true end @slides[@current].load unless @slides[@current].loaded? @slides[@current].activate @animator.reset end |
#draw ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/slidefield/viewer.rb', line 41 def draw # animate the previous slide if @previous && @animator.need_redraw? @animator.frame @time, false, @forward do @slides[@previous].draw @animator end end @animator.frame @time, true, @forward do @slides[@current].draw @animator end end |
#needs_redraw? ⇒ Boolean
54 55 56 |
# File 'lib/slidefield/viewer.rb', line 54 def needs_redraw? @animator.need_redraw? end |
#update ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/slidefield/viewer.rb', line 25 def update now = Gosu::milliseconds unless needs_redraw? if now - @time > LOAD_DELAY && @can_preload smart_loader @can_preload = false end return end @time = now @can_preload = true end |