Class: SobyPlayer
- Inherits:
-
Processing::App
- Object
- Processing::App
- SobyPlayer
- Defined in:
- lib/soby.rb
Constant Summary collapse
- TRANSITION_DURATION =
1000
Instance Attribute Summary collapse
-
#cam ⇒ Object
attr_accessor :background_max_color, :background_min_color, :background_constrain.
-
#current_slide_no ⇒ Object
readonly
Returns the value of attribute current_slide_no.
-
#is_moving ⇒ Object
readonly
Returns the value of attribute is_moving.
-
#next_cam ⇒ Object
Returns the value of attribute next_cam.
-
#prev_cam ⇒ Object
Returns the value of attribute prev_cam.
-
#prez ⇒ Object
Returns the value of attribute prez.
-
#slides ⇒ Object
Returns the value of attribute slides.
Instance Method Summary collapse
- #compute_view(view, slide_number) ⇒ Object
- #custom_post_draw ⇒ Object
- #custom_pre_draw ⇒ Object
-
#custom_setup ⇒ Object
To be overriden by the Presentation Code.
- #display_slide_number ⇒ Object (also: #default_display_slide_number)
- #draw ⇒ Object
- #global_view ⇒ Object
- #goto_slide(next_slide) ⇒ Object
-
#init ⇒ Object
no Border.
- #init_cameras ⇒ Object
- #init_player ⇒ Object
- #key_pressed ⇒ Object
- #mouse_dragged ⇒ Object
- #mouseWheel(event) ⇒ Object
- #next_slide ⇒ Object
- #prev_slide ⇒ Object
- #ready? ⇒ Boolean
- #removeFrameBorder ⇒ Object
- #run_slide_code ⇒ Object
- #running? ⇒ Boolean
- #set_prez(prez) ⇒ Object
- #setup ⇒ Object
- #slide_change ⇒ Object
- #slide_view(slide_no) ⇒ Object
- #update_cam ⇒ Object
Instance Attribute Details
#cam ⇒ Object
attr_accessor :background_max_color, :background_min_color, :background_constrain
26 27 28 |
# File 'lib/soby.rb', line 26 def cam @cam end |
#current_slide_no ⇒ Object (readonly)
Returns the value of attribute current_slide_no.
23 24 25 |
# File 'lib/soby.rb', line 23 def @current_slide_no end |
#is_moving ⇒ Object (readonly)
Returns the value of attribute is_moving.
23 24 25 |
# File 'lib/soby.rb', line 23 def is_moving @is_moving end |
#next_cam ⇒ Object
Returns the value of attribute next_cam.
22 23 24 |
# File 'lib/soby.rb', line 22 def next_cam @next_cam end |
#prev_cam ⇒ Object
Returns the value of attribute prev_cam.
22 23 24 |
# File 'lib/soby.rb', line 22 def prev_cam @prev_cam end |
#prez ⇒ Object
Returns the value of attribute prez.
22 23 24 |
# File 'lib/soby.rb', line 22 def prez @prez end |
#slides ⇒ Object
Returns the value of attribute slides.
22 23 24 |
# File 'lib/soby.rb', line 22 def @slides end |
Instance Method Details
#compute_view(view, slide_number) ⇒ Object
215 216 217 218 219 220 221 222 223 224 225 226 227 |
# File 'lib/soby.rb', line 215 def compute_view(view, ) # view = createGraphics(@width, @height, P3D) # @next_view = createGraphics(@width, @height) view.beginDraw cam = view.g.modelview.apply(cam) view.shapeMode(CORNER) view.shape(@prez.pshape, 0, 0) view.endDraw view end |
#custom_post_draw ⇒ Object
91 92 93 |
# File 'lib/soby.rb', line 91 def custom_post_draw end |
#custom_pre_draw ⇒ Object
87 88 89 |
# File 'lib/soby.rb', line 87 def custom_pre_draw background(255) end |
#custom_setup ⇒ Object
To be overriden by the Presentation Code.
83 84 85 |
# File 'lib/soby.rb', line 83 def custom_setup end |
#display_slide_number ⇒ Object Also known as: default_display_slide_number
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/soby.rb', line 139 def # Slide number push_matrix translate(@width - 40, @height - 45) fill(30) strokeWeight(3) stroke(190) ellipseMode(CENTER) ellipse(18, 22, 35, 35) fill(255) noStroke textSize(20) text(@current_slide_no.to_s, 10, 30) pop_matrix end |
#draw ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/soby.rb', line 96 def draw if not @custom_setup_done custom_setup @custom_setup_done = true end custom_pre_draw smooth(8) shapeMode(CORNER) imageMode(CORNER) if(running?) push_matrix update_cam self.g.modelview.apply(@cam) @prez.draw @prez.display_videos pop_matrix end custom_post_draw end |
#global_view ⇒ Object
375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 |
# File 'lib/soby.rb', line 375 def global_view # ortho(left, right, bottom, top) # frustum(left, right, bottom, top, near, far) my_scale = find_scale # centering dx = ((@width / my_scale) - @prez.width) * 0.5 dy = ((@height / my_scale) - @prez.height) * 0.5 cam = Cam.new cam.scale = my_scale # Not necessary : display from the center... cam.post_translation.set(dx, dy) cam.compute_mat cam end |
#goto_slide(next_slide) ⇒ Object
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 |
# File 'lib/soby.rb', line 269 def () = @current_slide_no use_global_view = == 0 || > @prez..size cam = global_view if use_global_view cam = () if > 0 # previous next is now old. @prev_cam = @next_cam @prev_cam.mat.set(@cam) @next_cam = cam @current_slide_no = if use_global_view @transition_duration = TRANSITION_DURATION.to_f else @transition_duration = @slides[@current_slide_no].transition_duration_ms end @transition_start_time = millis @is_moving = true @current_ratio = 0 ## trigger the slide_change function (user defined) end |
#init ⇒ Object
no Border
34 35 36 37 |
# File 'lib/soby.rb', line 34 def init super removeFrameBorder end |
#init_cameras ⇒ Object
70 71 72 73 74 75 76 77 78 79 |
# File 'lib/soby.rb', line 70 def init_cameras # current camera matrix @cam = PMatrix3D.new # Cameras for movement. @prev_cam = Cam.new @next_cam = Cam.new @is_moving = false @current_ratio = 0 end |
#init_player ⇒ Object
63 64 65 66 67 68 |
# File 'lib/soby.rb', line 63 def init_player @prez = nil @current_slide_no = 0 @is_running = false init_cameras end |
#key_pressed ⇒ Object
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/soby.rb', line 158 def key_pressed if key == 'g' puts "Garbage" Java::JavaLang::System.gc end return if @prez == nil if keyCode == LEFT end if keyCode == RIGHT end # puts "slide #{@current_slide_no} " end |
#mouse_dragged ⇒ Object
178 179 180 181 182 183 184 185 186 |
# File 'lib/soby.rb', line 178 def mouse_dragged if not @is_moving tr = PMatrix3D.new tr.translate(mouse_x - pmouse_x, mouse_y - pmouse_y) @cam.preApply(tr) @next_cam.mat.preApply(tr) end end |
#mouseWheel(event) ⇒ Object
188 189 190 191 192 193 194 195 196 197 |
# File 'lib/soby.rb', line 188 def mouseWheel(event) e = event.getAmount() if not @is_moving tr = PMatrix3D.new tr.translate(mouse_x, mouse_y) tr.scale(e < 0 ? 1.05 : 1 / 1.05) tr.translate(-mouse_x, -mouse_y) @cam.preApply(tr) end end |
#next_slide ⇒ Object
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 |
# File 'lib/soby.rb', line 230 def = @current_slide_no >= @prez. = == 0 # Gloal view if (@current_slide_no + 1) return end # animation if @slides[@current_slide_no].has_next_animation? puts "Animation Next " anim = @slides[@current_slide_no].next_animation anim.pshape_elem.setVisible(true) else (@current_slide_no + 1) unless end end |
#prev_slide ⇒ Object
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 |
# File 'lib/soby.rb', line 251 def return if @current_slide_no <= 0 if == 0 (@current_slide_no - 1) return end if @slides[@current_slide_no].has_previous_animation? puts "Animation Previous " anim = @slides[@current_slide_no].previous_animation anim.pshape_elem.setVisible(false) else (@current_slide_no - 1) end end |
#ready? ⇒ Boolean
59 60 61 |
# File 'lib/soby.rb', line 59 def ready? @ready end |
#removeFrameBorder ⇒ Object
39 40 41 42 43 |
# File 'lib/soby.rb', line 39 def removeFrameBorder frame.removeNotify frame.setUndecorated true frame.addNotify end |
#run_slide_code ⇒ Object
127 128 129 130 131 132 133 134 135 136 |
# File 'lib/soby.rb', line 127 def translate 0, 0, 1 if not @is_moving and @current_slide_no != 0 desc = @prez.[@current_slide_no].description if(desc != nil) # puts "EVAL #{desc}" eval desc end end end |
#running? ⇒ Boolean
29 |
# File 'lib/soby.rb', line 29 def running? () @is_running end |
#set_prez(prez) ⇒ Object
200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
# File 'lib/soby.rb', line 200 def set_prez (prez) # PShape.loadedImages.clear @prez = prez @slides = prez. 0 @is_running = true @prez_middle = PVector.new(@prez.width / 2.0, @prez.height / 2.0) puts "Presentation size " puts @prez.width puts @prez.height @custom_setup_done = false end |
#setup ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/soby.rb', line 46 def setup @ready = false size 1024, 768, OPENGL ## Some bugs with this. ## frame.setResizable true if frame != nil init_player @custom_setup_done = true @ready = true end |
#slide_change ⇒ Object
299 300 301 |
# File 'lib/soby.rb', line 299 def end |
#slide_view(slide_no) ⇒ Object
328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 |
# File 'lib/soby.rb', line 328 def () if > @prez..size puts "No more slides" return end return if @prez.[] == nil puts "slide view..." << .to_s # check slide number w = @prez.[].width h = @prez.[].height x = @prez.[].x y = @prez.[].y sc1 = @width.to_f / w.to_f sc2 = @height.to_f / h.to_f # scale sc = [sc1, sc2].min # translate dx = ((@width / sc) - w) * 0.5 dy = ((@height / sc) - h) * 0.5 cam = Cam.new m = PMatrix3D.new m.apply @prez.[].matrix m.invert # Scale tr = PMatrix3D.new tr.scale(sc) m.preApply(tr) m.translate(dx, dy) # center cam.mat = m cam end |
#update_cam ⇒ Object
304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 |
# File 'lib/soby.rb', line 304 def update_cam return unless @is_moving return if @slides.size == 0 elapsed_time = millis - @transition_start_time @current_ratio = elapsed_time.to_f / @transition_duration.to_f @current_ratio = @slides[@current_slide_no].transition @current_ratio unless @current_slide_no == 0 if @current_ratio > 1 && @is_moving @is_moving = false @cam = @prev_cam.lerp(@next_cam, 1) # save a copy @prev_cam.mat = @cam.get return end # puts @current_ratio @cam = @prev_cam.lerp(@next_cam, @current_ratio) end |