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.
-
#has_thread ⇒ Object
readonly
Returns the value of attribute has_thread.
-
#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.
-
#thread ⇒ Object
Returns the value of attribute thread.
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
- #fileSelected(selection) ⇒ Object
- #global_view ⇒ Object
- #goto_slide(next_slide) ⇒ Object
-
#init ⇒ Object
no Border.
- #init_cameras ⇒ Object
- #init_player ⇒ Object
-
#initialize(screen_id) ⇒ SobyPlayer
constructor
A new instance of SobyPlayer.
- #key_pressed ⇒ Object
- #mouse_dragged ⇒ Object
- #mouseWheel(event) ⇒ Object
- #movieEvent(m) ⇒ Object
- #next_slide ⇒ Object
- #presentation_path ⇒ Object
- #prev_slide ⇒ Object
- #ready? ⇒ Boolean
- #run_slide_code ⇒ Object
- #running? ⇒ Boolean
- #set_prez(prez) ⇒ Object
- #settings ⇒ Object
- #setup ⇒ Object
- #slide_change ⇒ Object
- #slide_view(slide_no) ⇒ Object
- #update_cam ⇒ Object
Constructor Details
#initialize(screen_id) ⇒ SobyPlayer
Returns a new instance of SobyPlayer.
41 42 43 44 |
# File 'lib/soby.rb', line 41 def initialize(screen_id) @screen_id = screen_id super() end |
Instance Attribute Details
#cam ⇒ Object
attr_accessor :background_max_color, :background_min_color, :background_constrain
35 36 37 |
# File 'lib/soby.rb', line 35 def cam @cam end |
#current_slide_no ⇒ Object (readonly)
Returns the value of attribute current_slide_no.
30 31 32 |
# File 'lib/soby.rb', line 30 def @current_slide_no end |
#has_thread ⇒ Object (readonly)
Returns the value of attribute has_thread.
32 33 34 |
# File 'lib/soby.rb', line 32 def has_thread @has_thread end |
#is_moving ⇒ Object (readonly)
Returns the value of attribute is_moving.
30 31 32 |
# File 'lib/soby.rb', line 30 def is_moving @is_moving end |
#next_cam ⇒ Object
Returns the value of attribute next_cam.
29 30 31 |
# File 'lib/soby.rb', line 29 def next_cam @next_cam end |
#prev_cam ⇒ Object
Returns the value of attribute prev_cam.
29 30 31 |
# File 'lib/soby.rb', line 29 def prev_cam @prev_cam end |
#prez ⇒ Object
Returns the value of attribute prez.
29 30 31 |
# File 'lib/soby.rb', line 29 def prez @prez end |
#slides ⇒ Object
Returns the value of attribute slides.
29 30 31 |
# File 'lib/soby.rb', line 29 def @slides end |
#thread ⇒ Object
Returns the value of attribute thread.
33 34 35 |
# File 'lib/soby.rb', line 33 def thread @thread end |
Instance Method Details
#compute_view(view, slide_number) ⇒ Object
281 282 283 284 285 286 287 288 289 290 291 292 293 |
# File 'lib/soby.rb', line 281 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
105 106 107 |
# File 'lib/soby.rb', line 105 def custom_post_draw end |
#custom_pre_draw ⇒ Object
101 102 103 |
# File 'lib/soby.rb', line 101 def custom_pre_draw background(255) end |
#custom_setup ⇒ Object
To be overriden by the Presentation Code.
97 98 99 |
# File 'lib/soby.rb', line 97 def custom_setup end |
#display_slide_number ⇒ Object Also known as: default_display_slide_number
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/soby.rb', line 149 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) if @current_slide_no < 10 translate 2, 0 else translate -3.5, 0 end text(@current_slide_no.to_s, 10, 30) pop_matrix end |
#draw ⇒ Object
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 135 |
# File 'lib/soby.rb', line 109 def draw rect 0, 0, 100, millis / 1000 if not @custom_setup_done custom_setup @custom_setup_done = true end custom_pre_draw 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 |
#fileSelected(selection) ⇒ Object
235 236 |
# File 'lib/soby.rb', line 235 def fileSelected selection end |
#global_view ⇒ Object
449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 |
# File 'lib/soby.rb', line 449 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
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 |
# File 'lib/soby.rb', line 343 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
51 52 53 54 |
# File 'lib/soby.rb', line 51 def init super getSurface.getNative.setUndecorated true end |
#init_cameras ⇒ Object
84 85 86 87 88 89 90 91 92 93 |
# File 'lib/soby.rb', line 84 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
77 78 79 80 81 82 |
# File 'lib/soby.rb', line 77 def init_player @prez = nil @current_slide_no = 0 @is_running = false init_cameras end |
#key_pressed ⇒ Object
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 |
# File 'lib/soby.rb', line 177 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 if key == 'l' # selectInput("Select a file to process:", # "fileSelected", # Java::JavaIo::File.new(SKETCH_ROOT)) folder = Java::JavaIo::File.new(SKETCH_ROOT) fc = Java::javax::swing::JFileChooser.new("Soby Loader") fc.set_dialog_title "Select your presentation" fc.setFileFilter AppFilter.new fc.setCurrentDirectory folder success = fc.show_open_dialog(nil) if success == Java::javax::swing::JFileChooser::APPROVE_OPTION path = fc.get_selected_file.get_absolute_path puts "User selected " + path presentation = Soby::load_presentation path Soby::start_presentation presentation else puts "No file" end end if key == 'a' return if @has_thread puts "Thread starting" Soby::auto_update self @has_thread = true end if key == 'c' @frame_number = 1 if @frame_number == nil saveFrame "frame-" + @frame_number.to_s + ".png" @frame_number = @frame_number + 1 end if key == 's' Thread::kill @thread if @has_thread end # puts "slide #{@current_slide_no} " end |
#mouse_dragged ⇒ Object
240 241 242 243 244 245 246 247 248 |
# File 'lib/soby.rb', line 240 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
250 251 252 253 254 255 256 257 258 259 |
# File 'lib/soby.rb', line 250 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 |
#movieEvent(m) ⇒ Object
46 47 48 |
# File 'lib/soby.rb', line 46 def movieEvent(m) m.read end |
#next_slide ⇒ Object
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 |
# File 'lib/soby.rb', line 296 def = @current_slide_no >= @prez. = == 0 # Gloal view if (@current_slide_no + 1) return end if @slides[@current_slide_no] == nil p "ERROR invalid slide" p "Try to go to next slide" (@current_slide_no + 1) unless 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) return end (@current_slide_no + 1) unless end |
#presentation_path ⇒ Object
170 171 172 |
# File 'lib/soby.rb', line 170 def presentation_path File.dirname(@prez.url) end |
#prev_slide ⇒ Object
325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 |
# File 'lib/soby.rb', line 325 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
73 74 75 |
# File 'lib/soby.rb', line 73 def ready? @ready end |
#run_slide_code ⇒ Object
137 138 139 140 141 142 143 144 145 146 |
# File 'lib/soby.rb', line 137 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
37 |
# File 'lib/soby.rb', line 37 def running? () @is_running end |
#set_prez(prez) ⇒ Object
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 |
# File 'lib/soby.rb', line 262 def set_prez (prez) = @current_slide_no # PShape.loadedImages.clear @prez = prez @slides = 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 |
#settings ⇒ Object
56 57 58 59 |
# File 'lib/soby.rb', line 56 def settings # todo: fullscreen ? fullScreen P3D, @screen_id end |
#setup ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/soby.rb', line 61 def setup @ready = false @width = self.width @height = self.height init_player @custom_setup_done = true @ready = true @has_thread = false end |
#slide_change ⇒ Object
373 374 375 |
# File 'lib/soby.rb', line 373 def end |
#slide_view(slide_no) ⇒ Object
402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 |
# File 'lib/soby.rb', line 402 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
378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 |
# File 'lib/soby.rb', line 378 def update_cam return unless @is_moving return if @slides.size == 0 elapsed_time = millis - @transition_start_time @current_time_ratio = elapsed_time.to_f / @transition_duration.to_f @current_ratio = @slides[@current_slide_no].transition @current_time_ratio unless @current_slide_no == 0 if (@current_ratio > 1 || @current_time_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 |