Class: Presentation
Defined Under Namespace
Classes: MyVideo
Constant Summary
Constants included from Soby
Instance Attribute Summary collapse
-
#debug ⇒ Object
readonly
Returns the value of attribute debug.
-
#geometry ⇒ Object
Returns the value of attribute geometry.
-
#graphics ⇒ Object
Returns the value of attribute graphics.
-
#height ⇒ Object
Returns the value of attribute height.
-
#matrix ⇒ Object
Returns the value of attribute matrix.
-
#nb_slides ⇒ Object
readonly
Returns the value of attribute nb_slides.
-
#program ⇒ Object
readonly
Returns the value of attribute program.
-
#pshape ⇒ Object
Returns the value of attribute pshape.
-
#slides ⇒ Object
Returns the value of attribute slides.
-
#svg ⇒ Object
Returns the value of attribute svg.
-
#transform ⇒ Object
Returns the value of attribute transform.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
-
#videos ⇒ Object
Returns the value of attribute videos.
-
#width ⇒ Object
Returns the value of attribute width.
Instance Method Summary collapse
- #add_group(group, slide) ⇒ Object
- #add_rect_or_image_frame(element, slide) ⇒ Object
- #add_slide(new_slide) ⇒ Object
- #build_internal ⇒ Object
- #display_videos ⇒ Object
- #draw ⇒ Object
-
#initialize(app, url, program) ⇒ Presentation
constructor
A new instance of Presentation.
- #load_animations ⇒ Object
- #load_files ⇒ Object
- #load_frames ⇒ Object
- #load_videos ⇒ Object
- #reset ⇒ Object
- #to_s ⇒ Object
Methods included from Soby
auto_update, #create_mat4x4, find_files, find_files_except, #get_angle, #get_global_transform, load_presentation, #read_transform, reload_presentation, start_presentation
Constructor Details
#initialize(app, url, program) ⇒ Presentation
Returns a new instance of Presentation.
16 17 18 19 20 21 22 23 24 |
# File 'lib/soby/presentation.rb', line 16 def initialize (app, url, program) @app = app @url = url @program = program @graphics = @app.g load_files build_internal end |
Instance Attribute Details
#debug ⇒ Object (readonly)
Returns the value of attribute debug.
12 13 14 |
# File 'lib/soby/presentation.rb', line 12 def debug @debug end |
#geometry ⇒ Object
Returns the value of attribute geometry.
10 11 12 |
# File 'lib/soby/presentation.rb', line 10 def geometry @geometry end |
#graphics ⇒ Object
Returns the value of attribute graphics.
14 15 16 |
# File 'lib/soby/presentation.rb', line 14 def graphics @graphics end |
#height ⇒ Object
Returns the value of attribute height.
11 12 13 |
# File 'lib/soby/presentation.rb', line 11 def height @height end |
#matrix ⇒ Object
Returns the value of attribute matrix.
11 12 13 |
# File 'lib/soby/presentation.rb', line 11 def matrix @matrix end |
#nb_slides ⇒ Object (readonly)
Returns the value of attribute nb_slides.
12 13 14 |
# File 'lib/soby/presentation.rb', line 12 def end |
#program ⇒ Object (readonly)
Returns the value of attribute program.
12 13 14 |
# File 'lib/soby/presentation.rb', line 12 def program @program end |
#pshape ⇒ Object
Returns the value of attribute pshape.
10 11 12 |
# File 'lib/soby/presentation.rb', line 10 def pshape @pshape end |
#slides ⇒ Object
Returns the value of attribute slides.
10 11 12 |
# File 'lib/soby/presentation.rb', line 10 def end |
#svg ⇒ Object
Returns the value of attribute svg.
10 11 12 |
# File 'lib/soby/presentation.rb', line 10 def svg @svg end |
#transform ⇒ Object
Returns the value of attribute transform.
10 11 12 |
# File 'lib/soby/presentation.rb', line 10 def transform @transform end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
12 13 14 |
# File 'lib/soby/presentation.rb', line 12 def url @url end |
#videos ⇒ Object
Returns the value of attribute videos.
11 12 13 |
# File 'lib/soby/presentation.rb', line 11 def videos @videos end |
#width ⇒ Object
Returns the value of attribute width.
11 12 13 |
# File 'lib/soby/presentation.rb', line 11 def width @width end |
Instance Method Details
#add_group(group, slide) ⇒ Object
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/soby/presentation.rb', line 122 def add_group(group, ) id = .title refid = .refid () # TODO: Find the bounding box of any group.. # TODO: Hide the whole group ? surf_max = 0 biggest_rect = nil ## biggest_rect surface.. group.css("rect").each do |rect| # (group.css("rect") + group.css("image")).each do |rect| if biggest_rect == nil biggest_rect = rect end surf_rect = rect.attributes["width"].value.to_i \ * rect.attributes["height"].value.to_i if(surf_rect > surf_max) biggest_rect = rect surf_max = surf_rect end end # rect.each rect_id = biggest_rect.attributes["id"].value transform = get_global_transform biggest_rect [id].set_geometry(biggest_rect, transform[0]) # The description (code to excute) might be in the group and not in the rect. ## TODO: check if it should really be the first ? desc = group.css("desc").first title = group.css("title").first if desc != nil if title == nil || (title.text.match(/animation/) == nil and title.text.match(/video/) == nil) puts "Group Description read #{desc.text}" [id].description = desc.text end end e = @pshape.getChild(rect_id) # hide the rect if e == nil puts "Error: rect ID: #{rect_id} not found " else @pshape.getChild(rect_id).setVisible(![id].hide) end puts "Slide #{id} created from a group, and the rectangle: #{rect_id}" end |
#add_rect_or_image_frame(element, slide) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/soby/presentation.rb', line 99 def add_rect_or_image_frame(element, ) id = .title refid = .refid () # set the geometry & transformation transform = get_global_transform element [id].set_geometry(element, transform[0]) pshape_element = @pshape.getChild(refid) # hide the element if pshape_element == nil puts "Error: rect or Image ID: #{refid} not found. CHECK THE PROCESSING VERSION." else pshape_element.setVisible(![id].hide) if element.name == "rect" end puts "Slide #{id} created from a rect : #{refid}" if element.name == "rect" puts "Slide #{id} created from an image: #{refid}" if element.name == "image" end |
#add_slide(new_slide) ⇒ Object
90 91 92 93 94 95 96 |
# File 'lib/soby/presentation.rb', line 90 def () puts "Add slide, id " << .title << " numero " << .sequence [.sequence] = [.title] = = +1 end |
#build_internal ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/soby/presentation.rb', line 41 def build_internal # Create the frames.. = {} = 0 = [] puts "Svg null, look for the error... !" if @svg == nil return if @svg == nil load_frames load_videos load_animations end |
#display_videos ⇒ Object
265 266 267 268 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 298 299 300 301 302 303 304 305 |
# File 'lib/soby/presentation.rb', line 265 def display_videos if not @app.is_moving = @app. # # Display the videos if > 0 and [].has_videos? # draw the object @graphics.imageMode(Processing::App::CORNER) [].videos.each do |my_video| @graphics.push_matrix @graphics.modelview.apply(my_video.matrix) # when the video is loaded it is saved... so that the memory can # hopefully be freed << my_video if my_video.play # my_video.video.read if my_video.video.available? # my_video.video.read @graphics.image(my_video.video, 0, 0, my_video.width, my_video.height) @graphics.pop_matrix end # videos.each else # has_videos ## no video, free some memory .each do |my_video| puts "Saving memory. " my_video.video.stop my_video.video = nil System.gc end = [] end end end |
#draw ⇒ Object
56 57 58 59 |
# File 'lib/soby/presentation.rb', line 56 def draw @graphics.shape pshape, 0, 0 # display_videos end |
#load_animations ⇒ Object
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 |
# File 'lib/soby/presentation.rb', line 223 def load_animations puts "Loading the animations..." @svg.css("*").each do |elem| valid = false elem.children.each do |child| valid = true if child.name == "title" && child.text.match(/animation/) end next unless valid id = elem.attributes["id"].value # Get the animation information t = elem.css("desc").text.split("\n") # 1. which slide # 2. when = t[0] anim_id = t[1].to_i animation = OpenStruct.new animation.pshape_elem = @pshape.getChild(id) puts "Animation found on slide #{slide_id} with element #{animation.pshape_elem}" if [] == nil puts "Error -> The animation #{id} is linked to the slide #{slide_id} which is not found !" else # add the animation [].add_animation(anim_id, animation) # hide the group ! animation.pshape_elem.setVisible(false) unless animation.pshape_elem == nil puts "Animation #{id} loaded with #{slide_id}" end end end |
#load_files ⇒ Object
26 27 28 29 30 |
# File 'lib/soby/presentation.rb', line 26 def load_files xml = @app.loadXML(@url) @pshape = PShapeSVG.new(xml) @svg = Nokogiri::XML(open(@url)).children[1]; end |
#load_frames ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/soby/presentation.rb', line 62 def load_frames puts "Loading the frames..." @svg.children.each do |child| next unless child.name =~ /frame/ ## ignore if it references nothing. attr = child.attributes next if attr["refid"] == nil = Slide.new(child) # get the element associated with each slide... @svg.search("[id=" + .refid + "]").each do |elem| case elem.name when "rect", "image" add_rect_or_image_frame(elem, ) when "g" add_group(elem, ) else puts "Slide type not supported ! " + elem.name end # end case end # search end # frame end |
#load_videos ⇒ Object
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 |
# File 'lib/soby/presentation.rb', line 182 def load_videos # Load the videos... puts "Loading the videos..." @svg.css("rect").each do |rect| return if rect.attributes["id"] == nil id = rect.attributes["id"].value #get the id title = rect.css("title") next if title == nil is_video = title.text.match(/video/) != nil next unless is_video t = rect.css("desc").text.split("\n") = t[0] path = t[1] puts ("Loading the video : " + path) # Get the transformation tr = get_global_transform rect video = MyVideo.new(path, [], tr[0], tr[1], tr[2]) if [] == nil puts "Error -> The video #{id} is linked to the slide #{slide_id} which is not found !" else [].add_video(video) puts "Video #{id} loaded with #{slide_id}" end # Hide the rect, and ... TODO replace it with a special object # @pshape.getChild(id).setVisible(false) end end |
#reset ⇒ Object
32 33 34 35 |
# File 'lib/soby/presentation.rb', line 32 def reset load_files build_internal end |
#to_s ⇒ Object
348 349 350 |
# File 'lib/soby/presentation.rb', line 348 def to_s "Slides #{@slides.size}" end |