Class: Cosmos::CanvaslabelvalueWidget

Inherits:
CanvasvalueWidget show all
Defined in:
lib/cosmos/tools/tlm_viewer/widgets/canvaslabelvalue_widget.rb

Instance Attribute Summary

Attributes included from Widget

#item, #item_name, #limits_set, #limits_state, #packet, #packet_name, #polling_period, #screen, #settings, #target_name, #value, #value_type

Instance Method Summary collapse

Methods inherited from CanvasvalueWidget

#paint, #process_settings, #set_item_settings, takes_value?

Methods included from Widget

#context_menu, #get_tooltip_text, included, #process_settings, #set_setting, #set_subsetting, #shutdown, #update_widget

Constructor Details

#initialize(parent_layout, target_name, packet_name, item_name, x1, y1, font_size = 12, color = 'black', frame = true, frame_width = 3, value_type = :CONVERTED) ⇒ CanvaslabelvalueWidget

Returns a new instance of CanvaslabelvalueWidget.



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/cosmos/tools/tlm_viewer/widgets/canvaslabelvalue_widget.rb', line 18

def initialize(parent_layout, target_name, packet_name, item_name, x1, y1, font_size = 12, color = 'black', frame = true, frame_width = 3, value_type = :CONVERTED)
  super(parent_layout, target_name, packet_name, item_name, value_type)
  @x = x1.to_i
  @y = y1.to_i
  @color = Cosmos.getColor(color)
  @pen = Cosmos.getPen(color)
  @font = Cosmos.getFont("helvetica", font_size.to_i)
  @fm = Cosmos.getFontMetrics(@font)
  @frame = ConfigParser.handle_true_false(frame)
  @frame_width = frame_width.to_i
  @value = ''
end

Instance Method Details

#draw_widget(painter, on_state) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/cosmos/tools/tlm_viewer/widgets/canvaslabelvalue_widget.rb', line 38

def draw_widget(painter, on_state)
  painter.save
  painter.setPen(@pen)
  painter.setFont(@font)
  painter.drawText(@x, @y, @value.to_s)
  if @frame
    h = @fm.height
    w = @fm.width(@value.to_s)
    @pen.setWidth(@frame_width)
    painter.drawLine(@x-5, @y+5, @x+w+10, @y+5) # bottom line
    painter.drawLine(@x-5, @y+5, @x-5, @y-h-5) # left line
    painter.drawLine(@x-5, @y-h-5, @x+w+10, @y-h-5) # top line
    painter.drawLine(@x+w+10, @y+5, @x+w+10, @y-h-5) # right line
  end
  painter.restore
end

#value=(data) ⇒ Object



31
32
33
34
35
36
# File 'lib/cosmos/tools/tlm_viewer/widgets/canvaslabelvalue_widget.rb', line 31

def value=(data)
  if @value != data
    @value = data
    @parent_layout.update_widget
  end
end