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
- #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.
42 43 44 45 |
# File 'lib/soby.rb', line 42 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
36 37 38 |
# File 'lib/soby.rb', line 36 def cam @cam end |
#current_slide_no ⇒ Object (readonly)
Returns the value of attribute current_slide_no.
31 32 33 |
# File 'lib/soby.rb', line 31 def end |
#has_thread ⇒ Object (readonly)
Returns the value of attribute has_thread.
33 34 35 |
# File 'lib/soby.rb', line 33 def has_thread @has_thread end |
#is_moving ⇒ Object (readonly)
Returns the value of attribute is_moving.
31 32 33 |
# File 'lib/soby.rb', line 31 def is_moving @is_moving end |
#next_cam ⇒ Object
Returns the value of attribute next_cam.
30 31 32 |
# File 'lib/soby.rb', line 30 def next_cam @next_cam end |
#prev_cam ⇒ Object
Returns the value of attribute prev_cam.
30 31 32 |
# File 'lib/soby.rb', line 30 def prev_cam @prev_cam end |
#prez ⇒ Object
Returns the value of attribute prez.
30 31 32 |
# File 'lib/soby.rb', line 30 def prez @prez end |
#slides ⇒ Object
Returns the value of attribute slides.
30 31 32 |
# File 'lib/soby.rb', line 30 def end |
#thread ⇒ Object
Returns the value of attribute thread.
34 35 36 |
# File 'lib/soby.rb', line 34 def thread @thread end |
Instance Method Details
#compute_view(view, slide_number) ⇒ Object
269 270 271 272 273 274 275 276 277 278 279 280 281 |
# File 'lib/soby.rb', line 269 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
103 104 105 |
# File 'lib/soby.rb', line 103 def custom_post_draw end |
#custom_pre_draw ⇒ Object
99 100 101 |
# File 'lib/soby.rb', line 99 def custom_pre_draw background(255) end |
#custom_setup ⇒ Object
To be overriden by the Presentation Code.
95 96 97 |
# File 'lib/soby.rb', line 95 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
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 107 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
223 224 |
# File 'lib/soby.rb', line 223 def fileSelected selection end |
#global_view ⇒ Object
437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 |
# File 'lib/soby.rb', line 437 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
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 |
# File 'lib/soby.rb', line 331 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
49 50 51 52 |
# File 'lib/soby.rb', line 49 def init super getSurface.getNative.setUndecorated true end |
#init_cameras ⇒ Object
82 83 84 85 86 87 88 89 90 91 |
# File 'lib/soby.rb', line 82 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
75 76 77 78 79 80 |
# File 'lib/soby.rb', line 75 def init_player @prez = nil = 0 @is_running = false init_cameras end |
#key_pressed ⇒ Object
171 172 173 174 175 176 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 |
# File 'lib/soby.rb', line 171 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 == 's' Thread::kill @thread if @has_thread end # puts "slide #{@current_slide_no} " end |
#mouse_dragged ⇒ Object
228 229 230 231 232 233 234 235 236 |
# File 'lib/soby.rb', line 228 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
238 239 240 241 242 243 244 245 246 247 |
# File 'lib/soby.rb', line 238 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
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 284 def = >= @prez. = == 0 # Gloal view if ( + 1) return end if [] == nil p "ERROR invalid slide" p "Try to go to next slide" ( + 1) unless return end # animation if [].has_next_animation? puts "Animation Next " anim = [].next_animation anim.pshape_elem.setVisible(true) return end ( + 1) unless end |
#presentation_path ⇒ Object
164 165 166 |
# File 'lib/soby.rb', line 164 def presentation_path File.dirname(@prez.url) end |
#prev_slide ⇒ Object
313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 |
# File 'lib/soby.rb', line 313 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
71 72 73 |
# File 'lib/soby.rb', line 71 def ready? @ready 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
38 |
# File 'lib/soby.rb', line 38 def running? () @is_running end |
#set_prez(prez) ⇒ Object
250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 |
# File 'lib/soby.rb', line 250 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 |
#settings ⇒ Object
54 55 56 57 |
# File 'lib/soby.rb', line 54 def settings # todo: fullscreen ? fullScreen P3D, @screen_id end |
#setup ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/soby.rb', line 59 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
361 362 363 |
# File 'lib/soby.rb', line 361 def end |
#slide_view(slide_no) ⇒ Object
390 391 392 393 394 395 396 397 398 399 400 401 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 |
# File 'lib/soby.rb', line 390 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
366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 |
# File 'lib/soby.rb', line 366 def update_cam return unless @is_moving return if .size == 0 elapsed_time = millis - @transition_start_time @current_time_ratio = elapsed_time.to_f / @transition_duration.to_f @current_ratio = [].transition @current_time_ratio unless == 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 |