#! /usr/bin/env ruby # # gexebutton - a tool to create a flash-based sounding button # # Copyright (C) 2003-2004 Satoru Takabayashi # All rights reserved. # This is free software with ABSOLUTELY NO WARRANTY. # # You can redistribute it and/or modify it under the terms of # the GNU General Public License version 2. # require 'ming/ming' include Ming class GexeButtonCreator def initialize (released_filename, pressed_filename, mp3_filename) @released_bitmap = SWFBitmap.new(released_filename) @pressed_bitmap = SWFBitmap.new(pressed_filename) @mp3_filename = mp3_filename @width = @released_bitmap.get_width @height = @released_bitmap.get_height raise "image sizes unmatched" if @width != @pressed_bitmap.get_width or @height != @pressed_bitmap.get_height end def create_image (bitmap) shape = SWFShape.new shape.set_right_fill(shape.add_fill(bitmap)) shape.draw_line(@width, 0) shape.draw_line(0, @height) shape.draw_line(-@width, 0) shape.draw_line(0, -@height) return shape end def create_anim (released_image, pressed_image) sprite = SWFSprite.new item = sprite.add(released_image) item = sprite.add(pressed_image) nframes = 4 make_frame = lambda {|i| item.mult_color(1.0, 1.0, 1.0, i.to_f / nframes) sprite.next_frame } 1.upto(nframes) {|i| make_frame.call(i) } nframes.downto(1) {|i| make_frame.call(i) } return sprite end def create (flash_filename) movie = SWFMovie.new movie.set_dimension(@width, @height) movie.set_rate(30.0) released_image = create_image(@released_bitmap) pressed_image = create_image(@pressed_bitmap) anim = create_anim(released_image, pressed_image) button = SWFButton.new button.set_hit(released_image) button.set_up(released_image) button.set_over(released_image) button.set_down(anim) sound = movie.add_sound(@mp3_filename, SWFSOUND_MP3_COMPRESSED | SWFSOUND_44KHZ | SWFSOUND_16BITS | SWFSOUND_STEREO) i = movie.add(button) # button, up, over, down, hit movie.set_button_sound(i, nil, nil, sound, nil) movie.save(flash_filename) end end def show_help puts "Usage: gexebutton RELEASED PRESSED MP3 FLASH" exit end def main show_help if ARGV.length != 4 released_filename = ARGV[0] pressed_filename = ARGV[1] mp3_filename = ARGV[2] flash_filename = ARGV[3] creator = GexeButtonCreator.new(released_filename, pressed_filename, mp3_filename) creator.create(flash_filename) end main