Class: CTioga2::Graphics::Styles::CurveStyle

Inherits:
Object
  • Object
show all
Defined in:
lib/ctioga2/graphics/styles/curve.rb

Overview

A class holding all the styles for a curve.

TODO: maybe for objects different than Curve2D, a subclass of CurveStyle could be used ? This way, we could have clearly separated legends and the like ?

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#legendObject

The text of the legend, if there is one.



40
41
42
# File 'lib/ctioga2/graphics/styles/curve.rb', line 40

def legend
  @legend
end

#lineObject

The style of the line that is drawn, as a StrokeStyle.



34
35
36
# File 'lib/ctioga2/graphics/styles/curve.rb', line 34

def line
  @line
end

#markerObject

The style of markers that should be drawn, as a MarkerStyle.



37
38
39
# File 'lib/ctioga2/graphics/styles/curve.rb', line 37

def marker
  @marker
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates a CurveStyle object straight from a hash description. See #set_from_hash for more information.



72
73
74
75
76
# File 'lib/ctioga2/graphics/styles/curve.rb', line 72

def self.from_hash(hash)
  a = CurveStyle.new
  a.set_from_hash(hash)
  return a
end

Instance Method Details

#draw_legend_pictogram(t) ⇒ Object

Draws a legend pictogram that fills up the whole current frame.

TODO: add more elements to the pictogram in case of more complex things.



84
85
86
87
88
89
90
91
92
93
94
# File 'lib/ctioga2/graphics/styles/curve.rb', line 84

def draw_legend_pictogram(t)
  t.context do
    if has_line?
      @line.set_stroke_style(t)
      t.stroke_line(0.0, 0.5, 1.0, 0.5)
    end
    if has_marker?
      @marker.draw_markers_at(t, [0.5], [0.5])
    end
  end
end

#has_legend?Boolean

True if there is one legend to be drawn for this object.

Returns:

  • (Boolean)


53
54
55
# File 'lib/ctioga2/graphics/styles/curve.rb', line 53

def has_legend?
  return @legend
end

#has_line?Boolean

True if a line should be drawn.

Returns:

  • (Boolean)


43
44
45
# File 'lib/ctioga2/graphics/styles/curve.rb', line 43

def has_line?
  return @line && @line.style
end

#has_marker?Boolean

True if markers should be drawn

Returns:

  • (Boolean)


48
49
50
# File 'lib/ctioga2/graphics/styles/curve.rb', line 48

def has_marker?
  return @marker && @marker.marker
end

#set_from_hash(hash) ⇒ Object

Sets the values of the different sub-objects from a ‘flat’ hash. Keys have the following meaning:

  • ‘line_…’: a StrokeStyle for the drawing the line

  • ‘marker_…’: a MarkerStyle for the drawing of markers

  • ‘legend’: the legend of the curve

TODO: make @legend another object derived from BasicStyle ?



64
65
66
67
68
# File 'lib/ctioga2/graphics/styles/curve.rb', line 64

def set_from_hash(hash)
  @line = StrokeStyle.from_hash(hash, 'line_%s')
  @marker = MarkerStyle.from_hash(hash, 'marker_%s')
  @legend = hash['legend']
end