Class: Wx::SF::DiamondShape

Inherits:
PolygonShape show all
Defined in:
lib/wx/shapes/shapes/diamond_shape.rb

Defined Under Namespace

Modules: DEFAULT

Instance Method Summary collapse

Methods inherited from PolygonShape

#deserialize_finalize, #draw_highlighted, #draw_hover, #draw_normal, #draw_polygon_shape, #draw_shadow, #fit_bounding_box_to_vertices, #fit_to_children, #fit_vertices_to_bounding_box, #get_border_point, #get_extents, #get_translated_vertice_points, #get_translated_vertices, #is_connected_to_vertex, #normalize_vertices, #on_handle, #scale_rectangle, #set_connect_to_vertex, #set_vertices

Methods inherited from RectShape

#create_handles, #do_begin_handle, #do_on_handle, #draw_highlighted, #draw_hover, #draw_normal, #draw_shadow, #fit_to_children, #get_border, #get_border_point, #get_bounding_box, #get_fill, #get_rect_size, #on_begin_handle, #on_bottom_handle, #on_handle, #on_left_handle, #on_right_handle, #on_top_handle, #scale, #scale_rectangle, #set_border, #set_fill, #set_rect_size

Methods inherited from Shape

#accept_child, #accept_connection, #accept_currently_dragged_shapes, #accept_src_neighbour, #accept_trg_neighbour, #activate, #active?, #add_child_shape, #add_connection_point, #add_handle, #add_style, #ancestor?, #clear_accepted_childs, #clear_accepted_connections, #clear_accepted_src_neighbours, #clear_accepted_trg_neighbours, component, component_shapes, #contains_style, #create_handles, #descendant?, #do_alignment, #does_not_accept_children?, #draw, #draw_highlighted, #draw_hover, #draw_normal, #draw_selected, #draw_shadow, #fit_to_children, #get_absolute_position, #get_accepted_children, #get_accepted_connections, #get_accepted_src_neighbours, #get_accepted_trg_neighbours, #get_assigned_connections, #get_border_point, #get_bounding_box, #get_center, #get_child_shapes, #get_children, #get_children_recursively, #get_complete_bounding_box, #get_connection_point, #get_connection_points, #get_custom_dock_point, #get_diagram, #get_grand_parent_shape, #get_h_align, #get_h_border, #get_handle, #get_handles, #get_hover_colour, #get_nearest_connection_point, #get_neighbours, #get_parent_absolute_position, #get_parent_canvas, #get_parent_shape, #get_relative_position, #get_shape_canvas, #get_style, #get_user_data, #get_v_align, #get_v_border, #has_children, #has_selected_parent?, #include_child_shape?, #inside?, #inspect, #intersects?, #is_child_accepted, #is_connection_accepted, #is_managed, #is_manager, #is_src_neighbour_accepted, #is_trg_neighbour_accepted, lines_intersection, #lines_intersection, #move_by, #move_to, #on_begin_drag, #on_begin_handle, #on_child_dropped, #on_dragging, #on_end_drag, #on_end_handle, #on_handle, #on_import, #on_key, #on_left_click, #on_left_double_click, #on_mouse_enter, #on_mouse_leave, #on_mouse_over, #on_right_click, #on_right_double_click, #refresh, #refresh_rect, #remove_connection_point, #remove_handle, #remove_style, #scale, #scale_children, #select, #selected?, #set_custom_dock_point, #set_diagram, #set_h_align, #set_h_border, #set_hover_colour, #set_parent_shape, #set_relative_position, #set_style, #set_user_data, #set_v_align, #set_v_border, #show, #show_handles, #to_s, #update, #visible?

Constructor Details

#initialize(pos = Shape::DEFAULT::POSITION, diagram: nil) ⇒ DiamondShape

Constructor.

Parameters:



20
21
22
# File 'lib/wx/shapes/shapes/diamond_shape.rb', line 20

def initialize(pos = Shape::DEFAULT::POSITION, diagram: nil)
  super(pos, vertices: DEFAULT::DIAMOND, diagram: diagram)
end

Instance Method Details

#contains?(pos) ⇒ Boolean

Test whether the given point is inside the shape. The function can be overridden if necessary.

Parameters:

Returns:

  • (Boolean)

    true if the point is inside the shape area, otherwise false



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/wx/shapes/shapes/diamond_shape.rb', line 28

def contains?(pos)
  bb_rct = get_bounding_box
  return false unless bb_rct.contains?(pos)

  center = get_center
  k = (bb_rct.height/2).to_f/(bb_rct.width/2).to_f

  if pos.x <= center.x
    # test left-top quadrant
    return true if (pos.y <= center.y) && (pos.y >= (center.y - (pos.x - bb_rct.left)*k))
    # test left-bottom quadrant
    return true if (pos.y >= center.y) && (pos.y <= (center.y + (pos.x - bb_rct.left)*k))
  else
    # test right-top quadrant
    return true if (pos.y <= center.y) && (pos.y >= (bb_rct.top + (pos.x - center.x)*k))
    # test left-bottom quadrant
    return true if (pos.y >= center.y) && (pos.y <= (bb_rct.bottom - (pos.x - center.x)*k))
  end

  false
end