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
-
#initialize(w, h) ⇒ SobyPlayer
constructor
A new instance of SobyPlayer.
- #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
Constructor Details
#initialize(w, h) ⇒ SobyPlayer
Returns a new instance of SobyPlayer.
36 37 38 39 40 |
# File 'lib/soby.rb', line 36 def initialize(w, h) @w = w @h = h super() end |
Instance Attribute Details
#cam ⇒ Object
attr_accessor :background_max_color, :background_min_color, :background_constrain
29 30 31 |
# File 'lib/soby.rb', line 29 def cam @cam end |
#current_slide_no ⇒ Object (readonly)
Returns the value of attribute current_slide_no.
26 27 28 |
# File 'lib/soby.rb', line 26 def end |
#is_moving ⇒ Object (readonly)
Returns the value of attribute is_moving.
26 27 28 |
# File 'lib/soby.rb', line 26 def is_moving @is_moving end |
#next_cam ⇒ Object
Returns the value of attribute next_cam.
25 26 27 |
# File 'lib/soby.rb', line 25 def next_cam @next_cam end |
#prev_cam ⇒ Object
Returns the value of attribute prev_cam.
25 26 27 |
# File 'lib/soby.rb', line 25 def prev_cam @prev_cam end |
#prez ⇒ Object
Returns the value of attribute prez.
25 26 27 |
# File 'lib/soby.rb', line 25 def prez @prez end |
#slides ⇒ Object
Returns the value of attribute slides.
25 26 27 |
# File 'lib/soby.rb', line 25 def end |
Instance Method Details
#compute_view(view, slide_number) ⇒ Object
229 230 231 232 233 234 235 236 237 238 239 240 241 |
# File 'lib/soby.rb', line 229 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
100 101 102 |
# File 'lib/soby.rb', line 100 def custom_post_draw end |
#custom_pre_draw ⇒ Object
96 97 98 |
# File 'lib/soby.rb', line 96 def custom_pre_draw background(255) end |
#custom_setup ⇒ Object
To be overriden by the Presentation Code.
92 93 94 |
# File 'lib/soby.rb', line 92 def custom_setup end |
#display_slide_number ⇒ Object Also known as: default_display_slide_number
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/soby.rb', line 148 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(.to_s, 10, 30) pop_matrix end |
#draw ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/soby.rb', line 105 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
389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 |
# File 'lib/soby.rb', line 389 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
283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 |
# File 'lib/soby.rb', line 283 def () = 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 = if use_global_view @transition_duration = TRANSITION_DURATION.to_f else @transition_duration = [].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
43 44 45 46 |
# File 'lib/soby.rb', line 43 def init super removeFrameBorder end |
#init_cameras ⇒ Object
79 80 81 82 83 84 85 86 87 88 |
# File 'lib/soby.rb', line 79 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
72 73 74 75 76 77 |
# File 'lib/soby.rb', line 72 def init_player @prez = nil = 0 @is_running = false init_cameras end |
#key_pressed ⇒ Object
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
# File 'lib/soby.rb', line 167 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
187 188 189 190 191 192 193 194 195 |
# File 'lib/soby.rb', line 187 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
197 198 199 200 201 202 203 204 205 206 |
# File 'lib/soby.rb', line 197 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
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 |
# File 'lib/soby.rb', line 244 def = >= @prez. = == 0 # Gloal view if ( + 1) return end # animation if [].has_next_animation? puts "Animation Next " anim = [].next_animation anim.pshape_elem.setVisible(true) else ( + 1) unless end end |
#prev_slide ⇒ Object
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 |
# File 'lib/soby.rb', line 265 def return if <= 0 if == 0 ( - 1) return end if [].has_previous_animation? puts "Animation Previous " anim = [].previous_animation anim.pshape_elem.setVisible(false) else ( - 1) end end |
#ready? ⇒ Boolean
68 69 70 |
# File 'lib/soby.rb', line 68 def ready? @ready end |
#removeFrameBorder ⇒ Object
48 49 50 51 52 |
# File 'lib/soby.rb', line 48 def removeFrameBorder frame.removeNotify frame.setUndecorated true frame.addNotify end |
#run_slide_code ⇒ Object
136 137 138 139 140 141 142 143 144 145 |
# File 'lib/soby.rb', line 136 def translate 0, 0, 1 if not @is_moving and != 0 desc = @prez.[].description if(desc != nil) # puts "EVAL #{desc}" eval desc end end end |
#running? ⇒ Boolean
32 |
# File 'lib/soby.rb', line 32 def running? () @is_running end |
#set_prez(prez) ⇒ Object
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 |
# File 'lib/soby.rb', line 209 def set_prez (prez) = # PShape.loadedImages.clear @prez = prez = prez. @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
55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/soby.rb', line 55 def setup @ready = false size @w, @h, OPENGL ## Some bugs with this. ## frame.setResizable true if frame != nil init_player @custom_setup_done = true @ready = true end |
#slide_change ⇒ Object
313 314 315 |
# File 'lib/soby.rb', line 313 def end |
#slide_view(slide_no) ⇒ Object
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 373 374 375 376 377 378 379 380 381 382 383 384 385 386 |
# File 'lib/soby.rb', line 342 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
318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 |
# File 'lib/soby.rb', line 318 def update_cam return unless @is_moving return if .size == 0 elapsed_time = millis - @transition_start_time @current_ratio = elapsed_time.to_f / @transition_duration.to_f @current_ratio = [].transition @current_ratio unless == 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 |