Class: Wx::SF::Shape::Handle

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent = nil, type = TYPE::UNDEF, id = -1)) ⇒ Handle

Constructor

Parameters:

  • parent (Wx::Shape) (defaults to: nil)

    Parent shape

  • type (TYPE) (defaults to: TYPE::UNDEF)

    Handle type

  • id (Integer) (defaults to: -1))

    Handle ID (useful only for line controls handles)



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

#idObject

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_brushObject



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.

Parameters:

Returns:

  • (Boolean)

    true if the point is inside the handle, otherwise false



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.

Parameters:

  • dc (Wx::DC)

    Device context where the handle will be drawn



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).

Parameters:

  • dc (Wx::DC)

    Device context where the handle will be drawn



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.

Parameters:

  • dc (Wx::DC)

    Device context where the handle will be drawn



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_deltaWx::Point Also known as: delta

Get current handle delta (difference between current and previous position).

Returns:



88
89
90
# File 'lib/wx/shapes/shape_handle.rb', line 88

def get_delta
  @curr_pos - @prev_pos
end

#get_parent_shapeWx::Shape Also known as: parent_shape

Get parent shape.

Returns:

  • (Wx::Shape)

    parent shape



74
75
76
# File 'lib/wx/shapes/shape_handle.rb', line 74

def get_parent_shape
  @parent_shape
end

#get_positionWx::Point Also known as: position

Get current handle position.

Returns:



81
82
83
# File 'lib/wx/shapes/shape_handle.rb', line 81

def get_position
  @curr_pos
end

#get_total_deltaWx::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).

Returns:



96
97
98
# File 'lib/wx/shapes/shape_handle.rb', line 96

def get_total_delta
  @curr_pos - @start_pos
end

#get_typeTYPE Also known as: type

Get Handle type

Returns:

  • (TYPE)

    Handle type



60
61
62
# File 'lib/wx/shapes/shape_handle.rb', line 60

def get_type
  @type
end

#handle_rectWx::Rect (protected)

Get handle rectangle.

Returns:



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

#refreshvoid

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.

Parameters:

  • parent (Wx::Shape)

    parent shape to set



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

Parameters:

  • type (TYPE)

    Handle type to set



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

Parameters:

  • show (Boolean) (defaults to: true)

    true if the handle should be visible (active), otherwise false



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

Returns:

  • (Boolean)


108
109
110
# File 'lib/wx/shapes/shape_handle.rb', line 108

def visible?
  @visible
end