Class: Wx::SF::CircleShape

Inherits:
SquareShape show all
Defined in:
lib/wx/shapes/shapes/circle_shape.rb

Overview

Class encapsulating the circle shape.

Defined Under Namespace

Modules: DEFAULT

Instance Method Summary collapse

Methods inherited from SquareShape

#do_on_handle, #get_center, #scale_rectangle

Methods inherited from RectShape

#create_handles, #do_begin_handle, #do_on_handle, #fit_to_children, #get_border, #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_selected, #fit_to_children, #get_absolute_position, #get_accepted_children, #get_accepted_connections, #get_accepted_src_neighbours, #get_accepted_trg_neighbours, #get_assigned_connections, #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, radius = DEFAULT::RADIUS, diagram: nil) ⇒ CircleShape

Constructor.

Parameters:

  • pos (Wx::RealPoint) (defaults to: Shape::DEFAULT::POSITION)

    Initial position

  • radius (Float) (defaults to: DEFAULT::RADIUS)

    Initial circle radius

  • diagram (Wx::SF::Diagram) (defaults to: nil)

    parent diagram



21
22
23
# File 'lib/wx/shapes/shapes/circle_shape.rb', line 21

def initialize(pos = Shape::DEFAULT::POSITION, radius = DEFAULT::RADIUS, diagram: nil)
  super(pos, radius*2, diagram: diagram)
end

Instance Method Details

#contains?(pos) ⇒ Boolean

can be overridden if necessary.

Parameters:

Returns:

  • (Boolean)

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



39
40
41
# File 'lib/wx/shapes/shapes/circle_shape.rb', line 39

def contains?(pos)
  get_center.distance_to(pos) <= radius
end

#draw_highlighted(dc) ⇒ Object (protected)

Draw the shape in the highlighted mode (another shape is dragged over this shape and this shape will accept the dragged one if it will be dropped on it). The function can be overridden if necessary.

Parameters:

  • dc (Wx::DC)

    Reference to device context where the shape will be drawn to



101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/wx/shapes/shapes/circle_shape.rb', line 101

def draw_highlighted(dc)
  # HINT: overload it for custom actions...
  pos = get_absolute_position

  dc.with_pen(Wx::Pen.new(hover_colour, 2)) do
    dc.with_brush(fill) do
      dc.draw_circle((pos.x + @rect_size.x/2).to_i,
                     (pos.y + @rect_size.y/2).to_i,
                     (@rect_size.x/2).to_i)
    end
  end
end

#draw_hover(dc) ⇒ Object (protected)

Draw the shape in the hover mode (the mouse cursor is above the shape). The function can be overridden if necessary.

Parameters:

  • dc (Wx::DC)

    Reference to device context where the shape will be drawn to



84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/wx/shapes/shapes/circle_shape.rb', line 84

def draw_hover(dc)
  # HINT: overload it for custom actions...
  pos = get_absolute_position

  dc.with_pen(Wx::Pen.new(hover_colour, 1)) do
    dc.with_brush(fill) do
      dc.draw_circle((pos.x + @rect_size.x/2).to_i,
                     (pos.y + @rect_size.y/2).to_i,
                     (@rect_size.x/2).to_i)
    end
  end
end

#draw_normal(dc) ⇒ Object (protected)

Draw the shape in the normal way. The function can be overridden if necessary.

Parameters:

  • dc (Wx::DC)

    Reference to device context where the shape will be drawn to



68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/wx/shapes/shapes/circle_shape.rb', line 68

def draw_normal(dc)
  # HINT: overload it for custom actions...
  pos = get_absolute_position

  dc.with_pen(border) do
    dc.with_brush(fill) do
      dc.draw_circle((pos.x + @rect_size.x/2).to_i,
                     (pos.y + @rect_size.y/2).to_i,
                     (@rect_size.x/2).to_i)
    end
  end
end

#draw_shadow(dc) ⇒ Object (protected)

Draw shadow under the shape. The function can be overridden if necessary.

Parameters:

  • dc (Wx::DC)

    Reference to device context where the shadow will be drawn to



116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/wx/shapes/shapes/circle_shape.rb', line 116

def draw_shadow(dc)
  # HINT: overload it for custom actions...
  pos = get_absolute_position

  if fill.style != Wx::BrushStyle::BRUSHSTYLE_TRANSPARENT
    dc.with_pen(Wx::TRANSPARENT_PEN) do
      dc.with_brush(get_parent_canvas.get_shadow_fill) do
        dc.draw_circle((pos.x + @rect_size.x/2 + get_parent_canvas.get_shadow_offset.x).to_i,
                       (pos.y + @rect_size.y/2 + get_parent_canvas.get_shadow_offset.y).to_i,
                       (@rect_size.x/2).to_i)
      end
    end
  end
end

#get_border_point(start, end_pt) ⇒ Wx::RealPoint

Get intersection point of the shape border and a line leading from ‘start’ point to ‘end’ point. The function can be overridden if necessary.

Parameters:

  • start (Wx::RealPoint)

    Starting point of the virtual intersection line

  • end_pt (Wx::RealPoint)

    Ending point of the virtual intersection line

Returns:



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/wx/shapes/shapes/circle_shape.rb', line 48

def get_border_point(start, end_pt)
  start = start.to_real_point; end_pt.to_real_point
  dist = start.distance_to(end_pt)
  center = get_center

  if dist != 0.0
    rad = radius
    src_dx = rad*(end_pt.x-start.x)/dist - (start.x-center.x)
    src_dy = rad*(end_pt.y-start.y)/dist - (start.y-center.y)

    Wx::RealPoint.new(start.x + src_dx, start.y + src_dy)
  else
    center
  end
end

#get_radiusObject Also known as: radius



25
26
27
# File 'lib/wx/shapes/shapes/circle_shape.rb', line 25

def get_radius
  @rect_size.x/2
end

#set_radius(rad) ⇒ Object Also known as: radius=



30
31
32
# File 'lib/wx/shapes/shapes/circle_shape.rb', line 30

def set_radius(rad)
  set_rect_size(rad*2, rad*2)
end