Class: Wx::SF::SquareShape
- Defined in:
- lib/wx/shapes/shapes/square_shape.rb
Direct Known Subclasses
Defined Under Namespace
Modules: DEFAULT
Instance Method Summary collapse
-
#do_on_handle(handle) ⇒ Object
protected
Handle’s shape specific actions on handling handle events.
-
#get_center ⇒ Wx::RealPoint
Get shape’s center.
-
#initialize(pos = Shape::DEFAULT::POSITION, size = DEFAULT::SIZE, diagram: nil) ⇒ SquareShape
constructor
Constructor.
-
#scale_rectangle(x, y) ⇒ Object
protected
Scale the rectangle size for this shape.
Methods inherited from RectShape
#create_handles, #do_begin_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, #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?, #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_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, size = DEFAULT::SIZE, diagram: nil) ⇒ SquareShape
Constructor.
21 22 23 |
# File 'lib/wx/shapes/shapes/square_shape.rb', line 21 def initialize(pos = Shape::DEFAULT::POSITION, size = DEFAULT::SIZE, diagram: nil) super(pos, Wx::RealPoint.new(size, size), diagram: diagram) end |
Instance Method Details
#do_on_handle(handle) ⇒ Object (protected)
Handle’s shape specific actions on handling handle events. The function can be overridden if necessary.
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/wx/shapes/shapes/square_shape.rb', line 55 def do_on_handle(handle) prev_x, prev_y = @rect_size # perform standard operations case handle.type when Shape::Handle::TYPE::LEFTTOP, Shape::Handle::TYPE::LEFT, Shape::Handle::TYPE::LEFTBOTTOM on_left_handle(handle) when Shape::Handle::TYPE::RIGHTTOP, Shape::Handle::TYPE::RIGHT, Shape::Handle::TYPE::RIGHTBOTTOM on_right_handle(handle) when Shape::Handle::TYPE::TOP on_top_handle(handle) when Shape::Handle::TYPE::BOTTOM on_bottom_handle(handle) end # calculate common size and some auxiliary values if (prev_x < @rect_size.x) || (prev_y < @rect_size.y) if @rect_size.x >= @rect_size.y maxsize = @rect_size.x else maxsize = @rect_size.y end else if @rect_size.x <= @rect_size.y maxsize = @rect_size.x else maxsize = @rect_size.y end end dx = maxsize - @rect_size.x dy = maxsize - @rect_size.y # normalize rect sizes @rect_size.x = @rect_size.y = maxsize # move rect if necessary case handle.type when Shape::Handle::TYPE::LEFT move_by(-dx, -dy / 2) when Shape::Handle::TYPE::LEFTTOP move_by(-dx, -dy) when Shape::Handle::TYPE::LEFTBOTTOM move_by(-dx, 0) when Shape::Handle::TYPE::RIGHT move_by(0, -dy / 2) when Shape::Handle::TYPE::RIGHTTOP move_by(0, -dy) when Shape::Handle::TYPE::TOP move_by(-dx / 2, -dy) when Shape::Handle::TYPE::BOTTOM move_by(-dx / 2, 0) end end |
#get_center ⇒ Wx::RealPoint
Get shape’s center. Default implementation does nothing. The function can be overridden if necessary.
27 28 29 30 |
# File 'lib/wx/shapes/shapes/square_shape.rb', line 27 def get_center # Optimize get_absolute_position + [@rect_size.x/2, @rect_size.y/2] end |
#scale_rectangle(x, y) ⇒ Object (protected)
Scale the rectangle size for this shape.
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/wx/shapes/shapes/square_shape.rb', line 37 def scale_rectangle(x, y) if x == 1.0 s = y elsif y == 1.0 s = x elsif x >= y s = x else s = y end set_rect_size(@rect_size.x * s, @rect_size.y * s) end |