lib/ctioga2/graphics/styles/drawable.rb in ctioga2-0.3 vs lib/ctioga2/graphics/styles/drawable.rb in ctioga2-0.4
- old
+ new
@@ -15,35 +15,43 @@
require 'ctioga2/log'
# This module contains all the classes used by ctioga
module CTioga2
- Version::register_svn_info('$Revision$', '$Date$')
+ Version::register_svn_info('$Revision: 350 $', '$Date: 2012-12-25 22:23:35 +0100 (Tue, 25 Dec 2012) $')
module Graphics
# All the styles
module Styles
# This class represents all the stylistic information to stroke
# a Tioga path.
class StrokeStyle < BasicStyle
# The color
- attr_accessor :color
+ typed_attribute :color, 'color-or-false'
# The line style
- attr_accessor :style
+ typed_attribute :style, 'line-style'
# The line width
- attr_accessor :width
+ typed_attribute :width, 'float'
# Sets the stroke style to a FigureMaker object, _t_.
def set_stroke_style(t)
t.stroke_color = @color if @color
t.line_type = @style if @style
t.line_width = @width if @width
end
+
+ # Draws a line according with this style
+ def draw_line(t, x1, y1, x2, y2)
+ t.context do
+ set_stroke_style(t)
+ t.stroke_line(x1, y1, x2, y2)
+ end
+ end
end
# This class represents all the stylistic information to draw a
# Marker.
#
@@ -52,17 +60,17 @@
# * in particular, angles could be handled here, and they could
# be handled directly in the marker specification...
class MarkerStyle < BasicStyle
# The color
- attr_accessor :color
+ typed_attribute :color, 'color'
# The marker
- attr_accessor :marker
+ typed_attribute :marker, 'marker'
# The marker scale
- attr_accessor :scale
+ typed_attribute :scale, 'float'
# Shows the marker at a given location/set of locations.
#
# \p override is a hash that can override part of the
# dictionnary specification.
@@ -95,20 +103,25 @@
# A style that handles drawing a fill.
#
# \todo add ways to specify complex fills, such as patterned
# fills and so on. Those would use clipping the path and base
- # themselves on the coordinates of the current frame.
+ # themselves on the coordinates of the current frame -- or more
+ # nicely use dimensions ? (which would allow to mix both to some
+ # extent ?)
#
# \todo more attributes ?
+ #
+ # @todo This class should also provide image-based fills, with
+ # CSS-like capacities (scaling, tiling, centering, and so on...)
class FillStyle < BasicStyle
# The color.
- attr_accessor :color
+ typed_attribute :color, "color"
# The transparency
- attr_accessor :transparency
+ typed_attribute :transparency, 'float'
# Sets up the parameters for the fill. Must be called before
# any path drawing.
#
# \warning You *must* call FillStyle#do_fill for
@@ -134,10 +147,10 @@
# At which Y value we should draw the horizontal line for the
# fill ? A float, or:
# * :top, :bottom
# * false, nil to disable filling altogether
- attr_accessor :y0
+ typed_attribute :y0, 'fill-until'
end
end
end