Class: Wx::SF::RoundRectShape

Inherits:
RectShape show all
Defined in:
lib/wx/shapes/shapes/round_rect_shape.rb

Overview

Class encapsulating rounded rectangle. It extends the basic rectangular shape.

Defined Under Namespace

Modules: DEFAULT

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from RectShape

#create_handles, #do_begin_handle, #do_on_handle, #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_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_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, size = RectShape::DEFAULT::SIZE, radius: DEFAULT::RADIUS, diagram: nil) ⇒ RoundRectShape

Constructor.

Parameters:



22
23
24
25
# File 'lib/wx/shapes/shapes/round_rect_shape.rb', line 22

def initialize(pos = Shape::DEFAULT::POSITION, size = RectShape::DEFAULT::SIZE, radius: DEFAULT::RADIUS, diagram: nil)
  super(pos, size, diagram: diagram)
  @radius = radius
end

Instance Attribute Details

#radiusObject

Access (get/set) radius.



28
29
30
# File 'lib/wx/shapes/shapes/round_rect_shape.rb', line 28

def radius
  @radius
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



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/wx/shapes/shapes/round_rect_shape.rb', line 34

def contains?(pos)
  return super if @radius == 0.0

  pos = pos.to_point
  # get original bounding box
  shp_bb = get_bounding_box

  # calculate modified boxes
  hr = shp_bb.deflate(0, @radius.to_i)
  vr = shp_bb.deflate(@radius.to_i, 0)

  # test whether given position is inside body rect or rounded corners
  if hr.contains?(pos)
    return true
  elsif vr.contains?(pos)
    return true
  elsif in_circle?(pos, shp_bb.top_left + [@radius, @radius.to_i])
    return true
  elsif in_circle?(pos, shp_bb.bottom_left + [@radius.to_i, -@radius.to_i])
    return true
  elsif in_circle?(pos, shp_bb.top_right + [-@radius.to_i, @radius.to_i])
    return true
  elsif in_circle?(pos, shp_bb.bottom_right + [-@radius.to_i, -@radius.to_i])
    return true
  end

  return false
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



98
99
100
101
102
103
104
105
106
107
108
# File 'lib/wx/shapes/shapes/round_rect_shape.rb', line 98

def draw_highlighted(dc)
  if @radius == 0.0
    super
    return
  end
  dc.with_pen(Wx::Pen.new(hover_colour, 2)) do
    dc.with_brush(fill) do
      dc.draw_rounded_rectangle(get_absolute_position.to_point, @rect_size.to_size, @radius)
    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



82
83
84
85
86
87
88
89
90
91
92
# File 'lib/wx/shapes/shapes/round_rect_shape.rb', line 82

def draw_hover(dc)
  if @radius == 0.0
    super
    return
  end
  dc.with_pen(Wx::Pen.new(hover_colour, 1)) do
    dc.with_brush(fill) do
      dc.draw_rounded_rectangle(get_absolute_position.to_point, @rect_size.to_size, @radius)
    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



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

def draw_normal(dc)
  if @radius == 0.0
    super
    return
  end
  dc.with_pen(border) do
    dc.with_brush(fill) do
      dc.draw_rounded_rectangle(get_absolute_position.to_point, @rect_size.to_size, @radius)
    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



112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/wx/shapes/shapes/round_rect_shape.rb', line 112

def draw_shadow(dc)
  if @radius == 0.0
    super
    return
  end
  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_rounded_rectangle((get_absolute_position + get_parent_canvas.get_shadow_offset).to_point,
                                  @rect_size.to_size, @radius)
      end
    end
  end
end

#in_circle?(pos, center) ⇒ Boolean (protected)

Auxiliary function. Checks whether the point is inside a circle with given center. The circle’s radius is the rounded rect corner radius.

Parameters:

Returns:

  • (Boolean)


132
133
134
# File 'lib/wx/shapes/shapes/round_rect_shape.rb', line 132

def in_circle?(pos, center)
  center.to_real_point.distance_to(pos.to_real_point) <= @radius
end