Class: Wx::SF::TextShape
- Defined in:
- lib/wx/shapes/shapes/text_shape.rb
Direct Known Subclasses
Defined Under Namespace
Modules: DEFAULT
Instance Method Summary collapse
-
#deserialize_finalize ⇒ self
protected
Deserialize attributes and recalculate rectangle size afterwards.
-
#do_on_handle(handle) ⇒ Object
protected
Handle’s shape specific actions on handling handle events.
- #draw_highlighted(dc) ⇒ Object protected
- #draw_hover(dc) ⇒ Object protected
-
#draw_normal(dc) ⇒ Object
protected
Draw the shape in the normal way.
-
#draw_shadow(dc) ⇒ Object
protected
Draw shadow under the shape.
-
#draw_text_content(dc) ⇒ Object
protected
Draw text shape.
-
#get_border ⇒ Wx::Pen
(also: #border)
Get current border style.
-
#get_fill ⇒ Wx::Brush
(also: #fill)
Get current fill style.
-
#get_font ⇒ Wx::Font
(also: #font)
Get text font.
-
#get_text ⇒ String
(also: #text)
Get text.
-
#get_text_colour ⇒ Wx::Colour
(also: #text_colour)
Get text color.
-
#get_text_extent ⇒ Wx::Size
Returns size of current text using current font.
-
#initialize(pos = Shape::DEFAULT::POSITION, txt = DEFAULT::TEXT, diagram: nil) ⇒ TextShape
constructor
Constructor.
- #on_bottom_handle(handle) ⇒ Object protected
- #on_left_handle(handle) ⇒ Object protected
- #on_right_handle(handle) ⇒ Object protected
- #on_top_handle(handle) ⇒ Object protected
-
#scale_rectangle(x, y) ⇒ Object
protected
Scale the rectangle size for this shape.
-
#serialize_text_colour(*val) ⇒ Object
protected
(de-)serialize text colour; allows for nil values.
-
#serialize_text_font(*val) ⇒ Object
protected
(de-)serialize text colour; allows for nil values.
-
#set_font(*args) ⇒ Object
(also: #font=)
Set text font.
-
#set_text(txt) ⇒ Object
(also: #text=)
Set text.
-
#set_text_colour(col) ⇒ Object
(also: #text_colour=)
Set text color.
-
#update(recurse = true) ⇒ Object
Update shape (align all child shapes and resize it to fit them).
-
#update_rect_size ⇒ Object
Updates rectangle size for this shape.
Methods inherited from RectShape
#create_handles, #do_begin_handle, #fit_to_children, #get_border_point, #get_bounding_box, #get_rect_size, #on_begin_handle, #on_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_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, #visible?
Constructor Details
#initialize(pos = Shape::DEFAULT::POSITION, txt = DEFAULT::TEXT, diagram: nil) ⇒ TextShape
Constructor.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/wx/shapes/shapes/text_shape.rb', line 33 def initialize(pos = Shape::DEFAULT::POSITION, txt = DEFAULT::TEXT, diagram: nil) super(pos, Wx::RealPoint.new, diagram: diagram) @font = nil @scaled_font = nil @line_height = 12 @text_color = nil @text = txt @rect_size = Wx::RealPoint.new update_rect_size end |
Instance Method Details
#deserialize_finalize ⇒ self (protected)
Deserialize attributes and recalculate rectangle size afterwards.
357 358 359 360 |
# File 'lib/wx/shapes/shapes/text_shape.rb', line 357 def deserialize_finalize update_rect_size self end |
#do_on_handle(handle) ⇒ Object (protected)
Handle’s shape specific actions on handling handle events. The function can be overridden if necessary.
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 |
# File 'lib/wx/shapes/shapes/text_shape.rb', line 216 def do_on_handle(handle) # HINT: overload it for custom actions... prev_size = get_rect_size # perform standard operations case handle.get_type when Shape::Handle::TYPE::LEFT on_left_handle(handle) when Shape::Handle::TYPE::RIGHT on_right_handle(handle) when Shape::Handle::TYPE::TOP on_top_handle(handle) when Shape::Handle::TYPE::BOTTOM on_bottom_handle(handle) end new_size = @rect_size sx = new_size.x / prev_size.x sy = new_size.y / prev_size.y scale(sx, sy) case handle.get_type when Shape::Handle::TYPE::LEFT dx = @rect_size.x - prev_size.x move_by(-dx, 0) @child_shapes.each { |shape| shape.move_by(-dx, 0) } when Shape::Handle::TYPE::TOP dy = @rect_size.y - prev_size.y move_by(0, -dy) @child_shapes.each { |shape| shape.move_by(0, -dy) } end end |
#draw_highlighted(dc) ⇒ Object (protected)
270 271 272 273 |
# File 'lib/wx/shapes/shapes/text_shape.rb', line 270 def draw_highlighted(dc) super draw_text_content(dc) end |
#draw_hover(dc) ⇒ Object (protected)
261 262 263 264 |
# File 'lib/wx/shapes/shapes/text_shape.rb', line 261 def draw_hover(dc) super draw_text_content(dc) end |
#draw_normal(dc) ⇒ Object (protected)
Draw the shape in the normal way. The function can be overridden if necessary.
253 254 255 256 |
# File 'lib/wx/shapes/shapes/text_shape.rb', line 253 def draw_normal(dc) super draw_text_content(dc) end |
#draw_shadow(dc) ⇒ Object (protected)
Draw shadow under the shape. The function can be overridden if necessary.
277 278 279 280 281 282 283 284 285 286 287 288 289 |
# File 'lib/wx/shapes/shapes/text_shape.rb', line 277 def draw_shadow(dc) # HINT: overload it for custom actions... curr_color = @text_color @text_color = get_parent_canvas.get_shadow_fill.get_colour offset = get_parent_canvas.get_shadow_offset move_by(offset) draw_text_content(dc) move_by(-offset.x, -offset.y) @text_color = curr_color end |
#draw_text_content(dc) ⇒ Object (protected)
Draw text shape.
329 330 331 332 333 334 335 336 337 338 339 340 341 |
# File 'lib/wx/shapes/shapes/text_shape.rb', line 329 def draw_text_content(dc) dc.with_brush(fill) do dc.set_background_mode(Wx::BrushStyle::BRUSHSTYLE_TRANSPARENT.to_i) dc.set_text_foreground(text_colour) dc.with_font(@scaled_font || font) do pos = get_absolute_position # draw all text lines @text.split("\n").each_with_index do |line, i| dc.draw_text(line, pos.x.to_i, pos.y.to_i + i*@line_height) end end end end |
#get_border ⇒ Wx::Pen Also known as: border
Get current border style.
102 103 104 |
# File 'lib/wx/shapes/shapes/text_shape.rb', line 102 def get_border @border || (@diagram&.shape_canvas ? @diagram.shape_canvas.text_border : DEFAULT.text_border) end |
#get_fill ⇒ Wx::Brush Also known as: fill
Get current fill style.
95 96 97 |
# File 'lib/wx/shapes/shapes/text_shape.rb', line 95 def get_fill @fill || (@diagram&.shape_canvas ? @diagram.shape_canvas.text_fill : DEFAULT.text_fill) end |
#get_font ⇒ Wx::Font Also known as: font
Get text font.
73 74 75 |
# File 'lib/wx/shapes/shapes/text_shape.rb', line 73 def get_font @font || (@diagram&.shape_canvas ? @diagram.shape_canvas.text_font : DEFAULT.font) end |
#get_text ⇒ String Also known as: text
Get text.
88 89 90 |
# File 'lib/wx/shapes/shapes/text_shape.rb', line 88 def get_text @text end |
#get_text_colour ⇒ Wx::Colour Also known as: text_colour
Get text color.
116 117 118 |
# File 'lib/wx/shapes/shapes/text_shape.rb', line 116 def get_text_colour @text_color || (@diagram&.shape_canvas ? @diagram.shape_canvas.text_colour : DEFAULT.text_color) end |
#get_text_extent ⇒ Wx::Size
Returns size of current text using current font.
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/wx/shapes/shapes/text_shape.rb', line 129 def get_text_extent w = -1 h = -1 if get_parent_canvas cur_font = @scaled_font || font if ShapeCanvas.gc_enabled? Wx::GraphicsContext.draw_on(get_parent_canvas) do |gc| # calculate text extent hd = -1 e = 0 gc.set_font(cur_font, Wx::BLACK) # we must use split string to inspect all lines of possible multiline text h = 0 @text.split("\n").each do |line| wd, hd, d, e = gc.get_text_extent(line) h += (hd + e).to_i w = (wd + d).to_i if (wd + d) > w end @line_height = (hd + e).to_i gc.set_font(Wx::NULL_FONT, Wx::BLACK) end else get_parent_canvas.paint do |dc| dc.set_font(cur_font) w, h, @line_height = dc.get_multi_line_text_extent(@text) dc.set_font(Wx::NULL_FONT) end end else w = @rect_size.x.to_i h = @rect_size.y.to_i @line_height = (@rect_size.y/@text.split("\n").size).to_i end Wx::Size.new(w, h) end |
#on_bottom_handle(handle) ⇒ Object (protected)
321 322 323 324 325 |
# File 'lib/wx/shapes/shapes/text_shape.rb', line 321 def on_bottom_handle(handle) # HINT: overload it for custom actions... @rect_size.y = (handle.get_position.y - get_absolute_position.y) end |
#on_left_handle(handle) ⇒ Object (protected)
294 295 296 297 298 |
# File 'lib/wx/shapes/shapes/text_shape.rb', line 294 def on_left_handle(handle) # HINT: overload it for custom actions... @rect_size.x -= (handle.get_position.x - get_absolute_position.x) end |
#on_right_handle(handle) ⇒ Object (protected)
312 313 314 315 316 |
# File 'lib/wx/shapes/shapes/text_shape.rb', line 312 def on_right_handle(handle) # HINT: overload it for custom actions... @rect_size.x = (handle.get_position.x - get_absolute_position.x) end |
#on_top_handle(handle) ⇒ Object (protected)
303 304 305 306 307 |
# File 'lib/wx/shapes/shapes/text_shape.rb', line 303 def on_top_handle(handle) # HINT: overload it for custom actions... @rect_size.y -= (handle.get_position.y - get_absolute_position.y) end |
#scale_rectangle(x, y) ⇒ Object (protected)
Scale the rectangle size for this shape.
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 |
# File 'lib/wx/shapes/shapes/text_shape.rb', line 187 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 cur_font = @scaled_font || font size = cur_font.get_point_size * s size = 5 if size < 5 if size == font.point_size @scaled_font = nil else @scaled_font ||= font.dup @scaled_font.set_point_size(size.to_i) unless size == @scaled_font.get_point_size end update_rect_size end |
#serialize_text_colour(*val) ⇒ Object (protected)
(de-)serialize text colour; allows for nil values
344 345 346 347 |
# File 'lib/wx/shapes/shapes/text_shape.rb', line 344 def serialize_text_colour(*val) @text_color = val.first unless val.empty? @text_color end |
#serialize_text_font(*val) ⇒ Object (protected)
(de-)serialize text colour; allows for nil values
350 351 352 353 |
# File 'lib/wx/shapes/shapes/text_shape.rb', line 350 def serialize_text_font(*val) @font = val.first unless val.empty? @font end |
#set_text_font(font) ⇒ Object #set_text_font(font_info) ⇒ Object #set_text_font(pointSize, family, style, weight, underline = false, faceName = (''), encoding = Wx::FontEncoding::FONTENCODING_DEFAULT) ⇒ Object Also known as: font=
Set text font.
61 62 63 64 65 66 67 68 |
# File 'lib/wx/shapes/shapes/text_shape.rb', line 61 def set_font(*args) @font = if args.size == 1 && Wx::Font === args.first args.first else Wx::Font.new(*args) end update_rect_size end |
#set_text(txt) ⇒ Object Also known as: text=
Set text.
80 81 82 83 |
# File 'lib/wx/shapes/shapes/text_shape.rb', line 80 def set_text(txt) @text = txt update_rect_size end |
#set_text_colour(col) ⇒ Object Also known as: text_colour=
Set text color.
109 110 111 |
# File 'lib/wx/shapes/shapes/text_shape.rb', line 109 def set_text_colour(col) @text_color = Wx::Colour === col ? col : Wx::Colour.new(col) end |
#update(recurse = true) ⇒ Object
Update shape (align all child shapes and resize it to fit them)
122 123 124 125 |
# File 'lib/wx/shapes/shapes/text_shape.rb', line 122 def update(recurse = true) update_rect_size super end |
#update_rect_size ⇒ Object
Updates rectangle size for this shape.
170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/wx/shapes/shapes/text_shape.rb', line 170 def update_rect_size tsize = get_text_extent if tsize.is_fully_specified tsize.width = 1 if tsize.width <= 0 tsize.height = 1 if tsize.height <= 0 @rect_size.x = tsize.width.to_f @rect_size.y = tsize.height.to_f end end |