2007-03-10 21:33:49 +01:00
|
|
|
#include Aegisub
|
2007-02-07 22:07:03 +01:00
|
|
|
|
|
|
|
class Object
|
|
|
|
def deep_clone
|
|
|
|
Marshal.load(Marshal.dump(self))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
module Aegisub
|
|
|
|
|
|
|
|
class ScriptCfg
|
|
|
|
def initialize # constructor
|
|
|
|
@opt = []
|
|
|
|
@x = 0
|
|
|
|
@y = 0
|
|
|
|
@labels = true
|
|
|
|
@width = 1 # TODO
|
|
|
|
@height = 1
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
def control(type, name, opt = {})
|
|
|
|
@opt << {:class => type, :name => name, :x => @x, :y => @y,
|
|
|
|
:width => 1, :height => 1}.merge!(opt)
|
|
|
|
end
|
|
|
|
|
|
|
|
# some meta-programming :]
|
|
|
|
def self.create_functions(*arr)
|
|
|
|
arr.each do |a|
|
|
|
|
class_eval(%Q[
|
|
|
|
def #{a.to_s}(name, text, opt = {})
|
|
|
|
if @labels; label text, opt; @x += 1; end
|
|
|
|
control "#{a.to_s}", name, opt
|
|
|
|
@y += 1
|
|
|
|
@x = 0
|
|
|
|
end
|
|
|
|
])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
public
|
|
|
|
create_functions *[:edit, :intedit, :floatedit, :textbox,
|
|
|
|
:dropdown, :checkbox, :color, :coloralpha, :alpha ]
|
|
|
|
|
|
|
|
def no_labels; @labels = false; end
|
|
|
|
|
|
|
|
def label(text, opt = {})
|
|
|
|
control :label, text, opt.merge({:label => text})
|
|
|
|
end
|
|
|
|
|
|
|
|
def header(text, opt = {})
|
|
|
|
label text, opt.merge!({:width => 2})
|
|
|
|
@y += 1
|
|
|
|
end
|
|
|
|
|
|
|
|
def to_ary # conversion to array
|
|
|
|
@opt
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2007-02-08 19:29:50 +01:00
|
|
|
# inserts lines with options into [Script Info] section
|
|
|
|
def write_options(subs, opt, sep = "~~")
|
|
|
|
subs.collect! do |l|
|
|
|
|
if l[:class] == :info
|
|
|
|
info = true
|
|
|
|
value = opt.delete(l[:key])
|
|
|
|
l[:value] = value.instance_of?(Hash) ? value.to_a.flatten!.join(sep) : value.to_s if value
|
|
|
|
l
|
2007-03-10 21:33:49 +01:00
|
|
|
elsif info
|
2007-02-08 19:29:50 +01:00
|
|
|
r = [l]
|
|
|
|
opt.each do |key, val|
|
|
|
|
r << {:class => :info, :key => key,
|
|
|
|
:value => value.instance_of?(Hash) ? value.to_a.flatten!.join(sep) : value.to_s,
|
|
|
|
:section => "[Script Info]"}
|
|
|
|
end
|
2007-03-10 21:33:49 +01:00
|
|
|
info = false
|
|
|
|
r
|
|
|
|
else
|
|
|
|
l
|
2007-02-08 19:29:50 +01:00
|
|
|
end
|
|
|
|
end
|
2007-02-07 22:07:03 +01:00
|
|
|
end
|
|
|
|
|
2007-02-08 19:29:50 +01:00
|
|
|
# returns a hash with options from [Script Info] section
|
|
|
|
def read_options(subs, name, sep = "~~")
|
|
|
|
opt = {}
|
|
|
|
subs.each { |l| opt[l[:key].to_sym] = l[:value] if l[:class] == :info }
|
|
|
|
n_sym = name.to_sym
|
|
|
|
if opt[n_sym] # parsing of script specific options
|
|
|
|
a = opt[n_sym].split(sep)
|
|
|
|
h = {}
|
|
|
|
(a.size/2).times { |j| h[a[2*j].to_sym] = a[2*j+1] }
|
|
|
|
opt[n_sym] = h
|
2007-02-07 22:07:03 +01:00
|
|
|
end
|
2007-02-08 19:29:50 +01:00
|
|
|
return opt
|
2007-02-07 22:07:03 +01:00
|
|
|
end
|
2007-03-10 21:33:49 +01:00
|
|
|
|
|
|
|
def rgb_to_ssa(*c)
|
|
|
|
res = "&H"
|
|
|
|
c.reverse_each {|v| res << "%02X" % v}
|
|
|
|
res << "&"
|
|
|
|
return res
|
|
|
|
end
|
|
|
|
|
|
|
|
def ssa_to_rgb(col)
|
|
|
|
res = []
|
|
|
|
col.scan(/[0-9a-fA-F]{2}/) { res.unshift $1.to_i(16) }
|
|
|
|
res
|
|
|
|
end
|
2007-02-07 22:07:03 +01:00
|
|
|
end
|
|
|
|
|