#-- # $Id: program.rb 71 2005-09-21 16:00:31Z tilman $ # # Copyright (c) 2005 Tilman Sauerbeck (tilman at code-monkey de) # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including # without limitation the rights to use, copy, modify, merge, publish, # distribute, sublicense, and/or sell copies of the Software, and to # permit persons to whom the Software is furnished to do so, subject to # the following conditions: # # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. module Redact class Program TYPE_BASE = 0 TYPE_SET_STATE = 1 TYPE_STOP_PROGRAM = 2 TYPE_EMIT_SIGNAL = 3 #TYPE_SET_DRAG_VAL = 4 #TYPE_STEP_DRAG_VAL = 5 #TYPE_PAGE_DRAG_VAL = 6 TYPE_EXEC_SCRIPT = 7 include Comparable attr_reader :collection, :id, :name, :after, :signal, :source, :in_from, :in_range def initialize(collection, id, name) @collection = collection @id = id @name = name.to_str.dup.freeze @type = TYPE_BASE @after = ProgramArgs.new(collection) @in_from = 0.0 @in_range = 0.0 @signal = "" @source = "" end def <=>(b) @id <=> b.id end def signal=(v) @signal = v.to_str.dup end def source=(v) @source = v.to_str.dup end def in_from=(v) unless v.is_a?(Float) raise(ArgumentError, "wrong argument type #{v.class.name} " + "(expected Float)") end @in_from = v end def in_range=(v) unless v.is_a?(Float) raise(ArgumentError, "wrong argument type #{v.class.name} " + "(expected Float)") end @in_range = v end protected def to_eet_name "Edje_Program" end def to_eet_properties {"id" => [@id], "name" => [@name], "action" => [@type], "signal" => [@signal], "source" => [@source], "in.from" => [@in_from, :double], "in.range" => [@in_range, :double], "after" => [@after]} end end class SetStateProgram < Program attr_reader :targets, :state, :value, :time attr_accessor :mode def initialize(collection, id, name) super @type = TYPE_SET_STATE @state = "default" @value = 0.0 @mode = :linear @time = 0.0 @targets = ProgramArgs.new(collection) end def state=(v) @state = v.to_str.dup end def value=(v) unless v.is_a?(Float) raise(ArgumentError, "wrong argument type #{v.class.name} " + "(expected Float)") end @value = v end def time=(v) unless v.is_a?(Float) raise(ArgumentError, "wrong argument type #{v.class.name} " + "(expected Float)") end @time = v end protected def to_eet_properties mode = case @mode when :linear: 1 when :sinusoidal: 2 when :accelerate: 3 when :decelerate: 4 else raise(RedactError, "invalid mode - #{@mode}") end super.merge!( {"state" => [@state], "value" => [@value, :double], "tween.mode" => [mode], "tween.time" => [@time, :double], "targets" => [@targets]}) end end class StopProgramProgram < Program def initialize(collection, id, name) super @type = TYPE_STOP_PROGRAM @targets = ProgramArgs.new(collection) end protected def to_eet_properties super.merge!({"targets" => [@targets]}) end end class EmitSignalProgram < Program attr_reader :emission_signal, :emission_source def initialize(collection, id, name) super @type = TYPE_EMIT_SIGNAL @emission_signal = "" @emission_source = "" end def emission_signal=(v) @emission_signal = v.to_str.dup end def emission_source=(v) @emission_source = v.to_str.dup end protected def to_eet_properties super.merge!( {"state" => [@emission_signal], "state2" => [@emission_source]}) end end class ExecScriptProgram < Program attr_reader :script def initialize(collection, id, name) super @type = TYPE_EXEC_SCRIPT @script = nil end def script=(v) v = v.to_str @script = (File.exist?(v) ? File.read(v) : v).dup end end class ProgramArgs < Array attr_reader :collection def initialize(collection) @collection = collection end def <<(v) if v.collection != @collection raise(ArgumentError, "items not in the same collection") end super end end class ProgramArg attr_reader :collection def initialize(v) @collection = v.collection @id = v.id end protected def to_eet_properties {"id" => [@id]} end end class ProgramAfter < ProgramArg protected def to_eet_name "Edje_Program_After" end end class ProgramTarget < ProgramArg protected def to_eet_name "Edje_Program_Target" end end end