Class: Wx::SF::Shape::Handle
- Inherits:
-
Object
- Object
- Wx::SF::Shape::Handle
- Defined in:
- lib/wx/shapes/shape_handle.rb
Overview
Class encapsulates shape’s handle. The class shouldn’t be used separately; see Wx::Shape class for more detailed information about functions used for managing of shape handles and handling their events
Defined Under Namespace
Classes: TYPE
Instance Attribute Summary collapse
-
#id ⇒ Object
Set or get handle’s ID.
Class Method Summary collapse
Instance Method Summary collapse
-
#contains(pos) ⇒ Boolean
(also: #contains?)
Find out whether given point is inside the handle.
-
#draw(dc) ⇒ Object
protected
Draw handle.
-
#draw_hover(dc) ⇒ Object
protected
Draw handle in the “hover” way (the mouse pointer is above the handle area).
-
#draw_normal(dc) ⇒ Object
protected
Draw handle in the normal way.
-
#get_delta ⇒ Wx::Point
(also: #delta)
Get current handle delta (difference between current and previous position).
-
#get_parent_shape ⇒ Wx::Shape
(also: #parent_shape)
Get parent shape.
-
#get_position ⇒ Wx::Point
(also: #position)
Get current handle position.
-
#get_total_delta ⇒ Wx::Point
(also: #total_delta)
Get current total handle delta (difference between current and starting position stored at the beginning of the dragging process).
-
#get_type ⇒ TYPE
(also: #type)
Get Handle type.
-
#handle_rect ⇒ Wx::Rect
protected
Get handle rectangle.
-
#initialize(parent = nil, type = TYPE::UNDEF, id = -1)) ⇒ Handle
constructor
Constructor.
-
#refresh ⇒ void
Refresh (repaint) the handle.
-
#set_parent_shape(parent) ⇒ Object
protected
Set parent shape.
-
#set_type(type) ⇒ Object
(also: #type=)
Set Handle type.
-
#show(show = true) ⇒ Object
Show/hide handle.
-
#visible? ⇒ Boolean
Returns true if the handle is visible, otherwise false.
Constructor Details
#initialize(parent = nil, type = TYPE::UNDEF, id = -1)) ⇒ Handle
Constructor
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/wx/shapes/shape_handle.rb', line 43 def initialize(parent=nil, type=TYPE::UNDEF, id=-1) @parent_shape = parent @type = type @id = id @start_pos = Wx::Point.new @prev_pos = Wx::Point.new @curr_pos = Wx::Point.new @visible = false @mouse_over = false end |
Instance Attribute Details
#id ⇒ Object
Set or get handle’s ID.
56 57 58 |
# File 'lib/wx/shapes/shape_handle.rb', line 56 def id @id end |
Class Method Details
.handle_brush ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/wx/shapes/shape_handle.rb', line 30 def handle_brush if ShapeCanvas.gc_enabled? @gc_brush ||= Wx::Brush.new(Wx::Colour.new(0, 0, 0, 128)) else @dc_brush ||= Wx::BLACK_BRUSH.dup end end |
Instance Method Details
#contains(pos) ⇒ Boolean Also known as: contains?
Find out whether given point is inside the handle.
121 122 123 |
# File 'lib/wx/shapes/shape_handle.rb', line 121 def contains(pos) handle_rect.contains?(pos) end |
#draw(dc) ⇒ Object (protected)
Draw handle.
130 131 132 133 134 135 136 137 138 |
# File 'lib/wx/shapes/shape_handle.rb', line 130 def draw(dc) if @visible && @parent_shape if @mouse_over draw_hover(dc) else draw_normal(dc) end end end |
#draw_hover(dc) ⇒ Object (protected)
Draw handle in the “hover” way (the mouse pointer is above the handle area).
157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/wx/shapes/shape_handle.rb', line 157 def draw_hover(dc) if @parent_shape.contains_style(Shape::STYLE::SIZE_CHANGE) dc.with_pen(Wx::BLACK_PEN) do dc.with_brush(Wx::Brush.new(@parent_shape.hover_colour)) do dc.draw_rectangle(handle_rect) end end else draw_normal(dc) end end |
#draw_normal(dc) ⇒ Object (protected)
Draw handle in the normal way.
142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/wx/shapes/shape_handle.rb', line 142 def draw_normal(dc) dc.with_pen(Wx::PLATFORM == 'WXGTK' ? Wx::TRANSPARENT_PEN : Wx::BLACK_PEN) do dc.with_brush(Handle.handle_brush) do # unless ShapeCanvas::gc_enabled? # dc.logical_function = Wx::RasterOperationMode::INVERT # end dc.draw_rectangle(handle_rect) # dc.logical_function = Wx::RasterOperationMode::COPY end end end |
#get_delta ⇒ Wx::Point Also known as: delta
Get current handle delta (difference between current and previous position).
88 89 90 |
# File 'lib/wx/shapes/shape_handle.rb', line 88 def get_delta @curr_pos - @prev_pos end |
#get_parent_shape ⇒ Wx::Shape Also known as: parent_shape
Get parent shape.
74 75 76 |
# File 'lib/wx/shapes/shape_handle.rb', line 74 def get_parent_shape @parent_shape end |
#get_position ⇒ Wx::Point Also known as: position
Get current handle position.
81 82 83 |
# File 'lib/wx/shapes/shape_handle.rb', line 81 def get_position @curr_pos end |
#get_total_delta ⇒ Wx::Point Also known as: total_delta
Get current total handle delta (difference between current and starting position stored at the beginning of the dragging process).
96 97 98 |
# File 'lib/wx/shapes/shape_handle.rb', line 96 def get_total_delta @curr_pos - @start_pos end |
#get_type ⇒ TYPE Also known as: type
Get Handle type
60 61 62 |
# File 'lib/wx/shapes/shape_handle.rb', line 60 def get_type @type end |
#handle_rect ⇒ Wx::Rect (protected)
Get handle rectangle.
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 |
# File 'lib/wx/shapes/shape_handle.rb', line 177 def handle_rect if @parent_shape brct = @parent_shape.get_bounding_box case @type when TYPE::LEFTTOP hrct = Wx::Rect.new(brct.top_left, Wx::Size.new(7,7)) when TYPE::TOP hrct = Wx::Rect.new(Wx::Point.new(brct.left + brct.width/2, brct.top), Wx::Size.new(7,7)) when TYPE::RIGHTTOP hrct = Wx::Rect.new(brct.top_right, Wx::Size.new(7,7)) when TYPE::RIGHT hrct = Wx::Rect.new(Wx::Point.new(brct.right, brct.top + brct.height/2), Wx::Size.new(7,7)) when TYPE::RIGHTBOTTOM hrct = Wx::Rect.new(brct.bottom_right, Wx::Size.new(7,7)) when TYPE::BOTTOM hrct = Wx::Rect.new(Wx::Point.new(brct.left + brct.width/2, brct.bottom), Wx::Size.new(7,7)) when TYPE::LEFTBOTTOM hrct = Wx::Rect.new(brct.bottom_left, Wx::Size.new(7,7)) when TYPE::LEFT hrct = Wx::Rect.new(Wx::Point.new(brct.left, brct.top + brct.height/2), Wx::Size.new(7,7)) when TYPE::LINECTRL pt = @parent_shape.get_control_points[@id] hrct = Wx::Rect.new(Wx::Point.new(pt.x.to_i, pt.y.to_i), Wx::Size.new(7,7)) when TYPE::LINEEND, TYPE::LINESTART pt = @type == TYPE::LINESTART ? @parent_shape.src_point : @parent_shape.trg_point hrct = Wx::Rect.new(Wx::Point.new(pt.x.to_i, pt.y.to_i), Wx::Size.new(7,7)) else hrct = Wx::Rect.new end hrct.offset!(-3, -3) else Wx::Rect.new end end |
#refresh ⇒ void
This method returns an undefined value.
Refresh (repaint) the handle
114 115 116 |
# File 'lib/wx/shapes/shape_handle.rb', line 114 def refresh @parent_shape.refresh(DELAYED) if @parent_shape end |
#set_parent_shape(parent) ⇒ Object (protected)
Set parent shape.
171 172 173 |
# File 'lib/wx/shapes/shape_handle.rb', line 171 def set_parent_shape(parent) @parent_shape = parent end |
#set_type(type) ⇒ Object Also known as: type=
Set Handle type
67 68 69 |
# File 'lib/wx/shapes/shape_handle.rb', line 67 def set_type(type) @type = type end |
#show(show = true) ⇒ Object
Show/hide handle
103 104 105 |
# File 'lib/wx/shapes/shape_handle.rb', line 103 def show(show = true) @visible = !!show end |
#visible? ⇒ Boolean
Returns true if the handle is visible, otherwise false
108 109 110 |
# File 'lib/wx/shapes/shape_handle.rb', line 108 def visible? @visible end |