Class: Presentation
Defined Under Namespace
Classes: MyVideo
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.
-
#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.
-
#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) ⇒ Presentation
constructor
A new instance of Presentation.
- #load_animations ⇒ Object
- #load_frames ⇒ Object
- #load_videos ⇒ Object
- #to_s ⇒ Object
Methods included from Soby
#create_mat4x4, #get_angle, #get_global_transform, #read_transform
Constructor Details
#initialize(app, url) ⇒ Presentation
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/soby/presentation.rb', line 16 def initialize (app, url) @app = app xml = app.loadXML(url) @pshape = PShapeSVG.new(xml) @svg = Nokogiri::XML(open(url)).children[1]; @graphics = @app.g 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 |
#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 |
#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
112 113 114 115 116 117 118 119 120 121 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 |
# File 'lib/soby/presentation.rb', line 112 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
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/soby/presentation.rb', line 89 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
80 81 82 83 84 85 86 |
# File 'lib/soby/presentation.rb', line 80 def () puts "Add slide, id " << .title << " numero " << .sequence [.sequence] = [.title] = = +1 end |
#build_internal ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/soby/presentation.rb', line 31 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
255 256 257 258 259 260 261 262 263 264 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 |
# File 'lib/soby/presentation.rb', line 255 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
46 47 48 49 |
# File 'lib/soby/presentation.rb', line 46 def draw @graphics.shape pshape, 0, 0 # display_videos end |
#load_animations ⇒ Object
213 214 215 216 217 218 219 220 221 222 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 |
# File 'lib/soby/presentation.rb', line 213 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_frames ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/soby/presentation.rb', line 52 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
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 |
# File 'lib/soby/presentation.rb', line 172 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 |
#to_s ⇒ Object
338 339 340 |
# File 'lib/soby/presentation.rb', line 338 def to_s "Slides #{@slides.size}" end |