X-Git-Url: http://git.code-monkey.de/?a=blobdiff_plain;f=lib%2Fredact%2Fpart.rb;h=b1b99786a179513975f302b1d6f17b9272b6c1df;hb=04b09aeb9b490ef5f1dcf2e4aa04f7d5cc766752;hp=6b0b53696594223af9ac5991cd4e7f2d26d20417;hpb=2c25c90e2aaf57a7508a7988f58b2784d5071a7e;p=redact.git diff --git a/lib/redact/part.rb b/lib/redact/part.rb index 6b0b536..b1b9978 100644 --- a/lib/redact/part.rb +++ b/lib/redact/part.rb @@ -1,5 +1,5 @@ #-- -# $Id: part.rb 1 2005-03-26 01:32:38Z tilman $ +# $Id: part.rb 20 2005-04-02 22:15:29Z tilman $ # # Copyright (c) 2005 Tilman Sauerbeck (tilman at code-monkey de) # @@ -58,18 +58,16 @@ module Redact end def clip=(part) - if self == part + if part == self raise(ArgumentError, "cannot clip part to itself") - elsif part.nil? - @clip = nil - elsif part.collection != @collection - raise(ArgumentError, "parts' collections not identical") + elsif !part.nil? && part.collection != @collection + raise(ArgumentError, "items not in the same collection") else @clip = part end end - def description(name = "default", value = 0.0) + def description(name = "default", value = 0.0) # :yields: desc d = @descriptions[desc_key(name, value)] block_given? ? (yield d) : d @@ -178,10 +176,10 @@ module Redact end def confine=(part) - if part == self + if part == @part raise(ArgumentError, "cannot confine part to itself") elsif !part.nil? && part.collection != @part.collection - raise(ArgumentError, "parts' collections not identical") + raise(ArgumentError, "items not in the same collection") else @confine = part end @@ -211,8 +209,8 @@ module Redact end class Description - attr_reader :rel - attr_accessor :visible + attr_reader :rel, :aspect, :step + attr_accessor :visible, :aspect_preference, :color_class def initialize(name = "default", value = 0.0) @name = name.to_str.dup.freeze @@ -221,13 +219,22 @@ module Redact @align = [0.5, 0.5] @min = [0, 0] @max = [-1, -1] - @step_x = 0 - @step_y = 0 + @step = [0, 0] + @aspect = [0.0, 0.0] + @aspect_preference = :none @rel = [Relation.new(0.0, 0), Relation.new(1.0, -1)] @color = [].fill(255, 0..3) @color_class = "" end + def set_step(x = 0, y = 0) + @step = [x, y] + end + + def set_aspect(x = 0.0, y = 0.0) + @aspect = [x, y] + end + def set_align(x = 0.5, y = 0.5) @align = [x, y] end @@ -266,6 +273,22 @@ module Redact pairs.map { |p| p.hex } end + def map_aspect_preference + case @aspect_preference + when :none + 0 + when :vertical + 1 + when :horizontal + 2 + when :both + 3 + else + raise(RedactError, "invalid aspect preference value - " + + @aspect_preference.to_s) + end + end + def to_eet_name "Edje_Part_Description" end @@ -280,11 +303,11 @@ module Redact "min.h" => [@min[1]], "max.w" => [@max[0]], "max.h" => [@max[1]], - "step.x" => [@step_x], - "step.y" => [@step_y], - "aspect.min" => [0.0, :double], - "aspect.max" => [0.0, :double], - "aspect.prefer" => [0, :char], + "step.x" => [@step[0]], + "step.y" => [@step[1]], + "aspect.min" => [@aspect[0], :double], + "aspect.max" => [@aspect[1], :double], + "aspect.prefer" => [map_aspect_preference, :char], "rel1.relative_x" => [@rel[0].rel[0], :double], "rel1.relative_y" => [@rel[0].rel[1], :double], "rel1.offset_x" => [@rel[0].offset[0]], @@ -429,7 +452,7 @@ module Redact class TextDescription < Description attr_reader :font - attr_accessor :text, :font_size + attr_accessor :text, :font_size, :text_class def initialize(name = "default", value = 0.0) super