Class: Wads::NodeIconWidget

Inherits:
Widget
  • Object
show all
Defined in:
lib/wads/widgets.rb

Overview

A graphical representation of a node in a graph using circular icons and adjacent text labels. The choice to use this display class is dictated by the use_icons attribute of the current theme. Like images, the size of node widgets can be scaled.

Instance Attribute Summary collapse

Attributes inherited from Widget

#base_z, #children, #gui_theme, #height, #is_selected, #layout, #overlay_widget, #override_color, #text_input_fields, #visible, #width, #x, #y

Instance Method Summary collapse

Methods inherited from Widget

#add, #add_axis_lines, #add_button, #add_child, #add_delete_button, #add_document, #add_graph_display, #add_image, #add_multi_select_table, #add_overlay, #add_panel, #add_plot, #add_single_select_table, #add_table, #add_text, #border_color, #bottom_edge, #button_down, #button_up, #center_children, #center_x, #center_y, #clear_children, #contains_click, #debug, #disable_background, #disable_border, #draw, #draw_background, #draw_border, #enable_background, #enable_border, #error, #get_layout, #get_theme, #graphics_color, #handle_key_held_down, #handle_key_press, #handle_key_up, #handle_mouse_down, #handle_mouse_up, #handle_right_mouse, #handle_update, #info, #intercept_widget_event, #left_edge, #move_recursive_absolute, #move_recursive_delta, #overlaps_with, #pad, #relative_x, #relative_y, #relative_z_order, #remove_child, #remove_children, #remove_children_by_type, #right_edge, #selection_color, #set_absolute_position, #set_dimensions, #set_layout, #set_selected, #set_theme, #text_color, #top_edge, #unset_selected, #update, #uses_layout, #warn, #x_pixel_to_screen, #y_pixel_to_screen, #z_order

Constructor Details

#initialize(x, y, node, color = nil, initial_scale = 1, is_explorer = false) ⇒ NodeIconWidget

Returns a new instance of NodeIconWidget.



2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
# File 'lib/wads/widgets.rb', line 2910

def initialize(x, y, node, color = nil, initial_scale = 1, is_explorer = false) 
    super(x, y) 
    @override_color = color
    @data_node = node
    @label = node.name
    circle_image = WadsConfig.instance.circle(color)
    if circle_image.nil?
        @image = WadsConfig.instance.circle(COLOR_BLUE)
    else 
        @image = circle_image 
    end
    @is_explorer = is_explorer
    set_scale(initial_scale, @is_explorer)
    disable_border
end

Instance Attribute Details

#data_nodeObject

Returns the value of attribute data_node.



2904
2905
2906
# File 'lib/wads/widgets.rb', line 2904

def data_node
  @data_node
end

#imageObject

Returns the value of attribute image.



2905
2906
2907
# File 'lib/wads/widgets.rb', line 2905

def image
  @image
end

#is_explorerObject

Returns the value of attribute is_explorer.



2908
2909
2910
# File 'lib/wads/widgets.rb', line 2908

def is_explorer
  @is_explorer
end

#labelObject

Returns the value of attribute label.



2907
2908
2909
# File 'lib/wads/widgets.rb', line 2907

def label
  @label
end

#scaleObject

Returns the value of attribute scale.



2906
2907
2908
# File 'lib/wads/widgets.rb', line 2906

def scale
  @scale
end

Instance Method Details

#get_text_widgetObject



2953
2954
2955
2956
2957
2958
2959
# File 'lib/wads/widgets.rb', line 2953

def get_text_widget
    if @children.size > 0
        return @children[0]
    end 
    #raise "No text widget for NodeIconWidget" 
    nil
end

#is_backgroundObject



2930
2931
2932
# File 'lib/wads/widgets.rb', line 2930

def is_background 
    @scale <= 0.1 and @is_explorer
end

#nameObject



2926
2927
2928
# File 'lib/wads/widgets.rb', line 2926

def name 
    @data_node.name 
end

#renderObject



2961
2962
2963
# File 'lib/wads/widgets.rb', line 2961

def render 
    @image.draw @x, @y, relative_z_order(Z_ORDER_FOCAL_ELEMENTS), @scale, @scale
end

#set_scale(value, is_explorer = false) ⇒ Object



2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
# File 'lib/wads/widgets.rb', line 2934

def set_scale(value, is_explorer = false)
    @is_explorer = is_explorer
    if value < 0.5
        value = 0.5
    end 
    @scale = value / 10.to_f
    #debug("In node widget Setting scale of #{@label} to #{value} = #{@scale}")
    @width = IMAGE_CIRCLE_SIZE * scale.to_f
    @height = IMAGE_CIRCLE_SIZE * scale.to_f
    # Only in explorer mode do we dull out nodes on the outer edge
    if is_background 
        @image = WadsConfig.instance.circle(COLOR_ALPHA)
    else
        text_pixel_width = @gui_theme.font.text_width(@label)
        clear_children  # the text widget is the only child, so we can remove all
        add_text(@label, (@width / 2) - (text_pixel_width / 2), -20)
    end
end

#widget_zObject



2965
2966
2967
# File 'lib/wads/widgets.rb', line 2965

def widget_z 
    Z_ORDER_TEXT
end