#!ruby -Ks
# 簡易インストーラ

require 'rbconfig'
require 'fileutils'
include Config

if CONFIG["ruby_version"] != "1.9.1" then
  puts "1.9.1以降じゃないと動かせません"
  exit
end

FileUtils.mkdir_p(CONFIG["sitearchdir"])
file = CONFIG["sitearchdir"] + "/" + "dxruby.so"
FileUtils.install("dxruby.so" , file, :preserve => true)
file = CONFIG["sitearchdir"] + "/" + "dxrubyex.so"
FileUtils.install("dxrubyex.so" , file, :preserve => true)

puts "DXRubyのインストールに成功しました"

require 'dxruby'

image = Image.load('logo.png')

Window.bgcolor=[255,255,255]
Window.create

x = Window.width / 2 - image.width / 2
y = Window.height / 2 - image.height / 2

(1..100).each do |z|
  break if Input.update
  break if Input.key_push?(K_ESCAPE)
  Window.drawEx(x, y, image, :scalex=>(100.0 / z), :scaley=>(100.0 / z), :angle=>-(z-100)*5)
  Window.update
  Window.sync
end

60.times do
  break if Input.update
  break if Input.key_push?(K_ESCAPE)
  Window.draw(x, y, image)
  Window.update
  Window.sync
end

keys = Input.keys
font = Font.new(48)

(0..63).each do |i|
  break if Input.update
  break if Input.key_push?(K_ESCAPE)
  Window.draw(x, y, image)
  Window.drawFontEx(100, 380, "Installation completed.", font, :color=>[0,0,0], :edge_color=>[0,0,255], :edge=>true, :alpha=>i*4+3)
  Window.update
  Window.sync
end

keys = Input.keys
loop do
  break if Input.update
  break if Input.keys != keys
  Window.draw(x, y, image)
  Window.drawFontEx(100, 380, "Installation completed.", font, :color=>[0,0,0], :edge_color=>[0,0,255], :edge=>true)
  Window.update
  Window.sync
end


