Class: Wx::SF::ShapeCanvas
- Inherits:
-
Wx::ScrolledWindow
- Object
- Wx::ScrolledWindow
- Wx::SF::ShapeCanvas
- Defined in:
- lib/wx/shapes/shape_canvas.rb
Overview
Class encapsulating a Shape canvas. The shape canvas is window control which extends the Wx::ScrolledWindow and is responsible for displaying of shapes diagrams. It also supports clipboard and drag&drop operations, undo/redo operations, and graphics exporting functions.
This class is a core framework class and provides many member functions suitable for adding, removing, moving, resizing and drawing of shape objects. It can be used as it is or as a base class if necessary. In that case, the default class functionality can be enhanced by overriding its methods or by manual events handling. In both cases the user is responsible for invoking of default event handlers/virtual functions otherwise the built in functionality wont be available.
Defined Under Namespace
Modules: DEFAULT Classes: CHANGE, HALIGN, MODE, PRECON_FINISH_STATE, PRINTMODE, SEARCHMODE, SELECTIONMODE, SHADOWMODE, STYLE, Settings, VALIGN, Version
Instance Attribute Summary collapse
-
#settings ⇒ Object
readonly
Returns the value of attribute settings.
Print methods collapse
-
#page_setup ⇒ Object
Show page setup dialog for printing.
-
#print(*args) ⇒ Object
Print current canvas content.
-
#print_preview(*args) ⇒ Object
Show print preview.
Style accessors collapse
-
#add_style(style) ⇒ Object
Add new style flag.
-
#contains_style(style) ⇒ Object
(also: #contains_style?, #has_style?)
Check whether given style flag is used.
-
#get_style ⇒ Object
(also: #style)
Get current canvas style.
-
#remove_style(style) ⇒ Object
Remove given style flag.
-
#set_style(style) ⇒ Object
(also: #style=)
Set canvas style.
Public attribute accessors collapse
-
#get_canvas_colour ⇒ Wx::Colour
(also: #get_canvas_color, #canvas_colour, #canvas_color)
Get canvas background color.
-
#get_gradient_from ⇒ Wx::Colour
(also: #gradient_from)
Get starting gradient color.
-
#get_gradient_to ⇒ Wx::Colour
(also: #gradient_to)
Get ending gradient color.
-
#get_grid_colour ⇒ Wx::Colour
(also: #get_grid_color, #grid_colour, #grid_color)
Get grid color.
-
#get_grid_line_mult ⇒ Integer
(also: #grid_line_mult)
Get grid line multiple.
-
#get_grid_size ⇒ Integer
(also: #grid_size)
Get grid size (px).
-
#get_grid_style ⇒ Wx::PenStyle
(also: #grid_style)
Get grid line style.
-
#get_max_scale ⇒ FLOAT
(also: #max_scale)
Set maximal allowed scale (for mouse wheel scale change).
-
#get_min_scale ⇒ Float
(also: #min_scale)
Get minimal allowed scale (for mouse wheel scale change).
-
#get_print_h_align ⇒ HALIGN
(also: #print_h_align)
Get horizontal align of printed drawing.
-
#get_print_mode ⇒ PRINTMODE
(also: #print_mode)
Get printing mode for this canvas.
-
#get_print_v_align ⇒ VALIGN
(also: #print_v_align)
Get vertical align of printed drawing.
-
#get_scale ⇒ Float
(also: #scale)
Get the canvas scale.
-
#get_shadow_fill ⇒ Wx::Brush
(also: #shadow_fill)
Get shadow fill.
-
#get_shadow_offset ⇒ Wx::RealPoint
(also: #shadow_offset)
Get shadow offset.
-
#set_canvas_colour(col) ⇒ Object
(also: #set_canvas_color, #canvas_colour=, #canvas_color=)
Set canvas background color.
-
#set_gradient_from(col) ⇒ Object
(also: #gradient_from=)
Set starting gradient color.
-
#set_gradient_to(col) ⇒ Object
(also: #gradient_to=)
Set ending gradient color.
-
#set_grid_colour(col) ⇒ Object
(also: #set_grid_color, #grid_colour=, #grid_color=)
Set grid color.
-
#set_grid_line_mult(multiple) ⇒ Object
(also: #grid_line_mult=)
Set grid line multiple.
-
#set_grid_size(sz) ⇒ Object
(also: #grid_size=)
Set grid size (px).
-
#set_grid_style(style) ⇒ Object
(also: #grid_style=)
Set grid line style.
-
#set_max_scale(scale) ⇒ Object
(also: #max_scale=)
Set maximal allowed scale (for mouse wheel scale change).
-
#set_min_scale(scale) ⇒ Object
(also: #min_scale=)
Set minimal allowed scale (for mouse wheel scale change).
-
#set_print_h_align(val) ⇒ Object
(also: #print_h_align=)
Set horizontal align of printed drawing.
-
#set_print_mode(mode) ⇒ Object
(also: #print_mode=)
Set printing mode for this canvas.
-
#set_print_v_align(val) ⇒ Object
(also: #print_v_align=)
Set vertical align of printed drawing.
-
#set_scale(scale) ⇒ Object
(also: #scale=)
Set canvas scale.
-
#set_shadow_fill(*args) ⇒ Object
(also: #shadow_fill=)
Set shadow fill (used for shadows of non-text shapes only).
-
#set_shadow_offset(offset) ⇒ Object
(also: #shadow_offset=)
Set shadow offset.
Public event handlers collapse
-
#on_connection_finished(connection) ⇒ Object
Event handler called after (successful or cancelled) connection creation.
-
#on_drop(x, y, deflt, dropped) ⇒ Object
Event handler called by the framework after any dragged shapes are dropped to the canvas.
-
#on_key_down(event) ⇒ Object
Event handler called when any key is pressed.
-
#on_left_double_click(event) ⇒ Object
Event handler called when the canvas is double-clicked by the left mouse button.
-
#on_left_down(event) ⇒ Object
Event handler called when the canvas is clicked by the left mouse button.
-
#on_left_up(event) ⇒ Object
Event handler called when the left mouse button is released.
-
#on_mouse_move(event) ⇒ Object
Event handler called when the mouse pointer is moved.
-
#on_mouse_wheel(event) ⇒ Object
Event handler called when the mouse wheel position is changed.
-
#on_paste(pasted) ⇒ Object
Event handler called by the framework after pasting of shapes from the clipboard to the canvas.
-
#on_pre_connection_finished(connection) ⇒ PRECON_FINISH_STATE
Event handler called after successful connection creation in order to allow developer to perform some kind of checks before the connection is really added to the diagram.
-
#on_right_double_click(event) ⇒ Object
Event handler called when the canvas is double-clicked by the right mouse button.
-
#on_right_down(event) ⇒ Object
Event handler called when the canvas is clicked by the right mouse button.
-
#on_right_up(_event) ⇒ Object
Event handler called when the right mouse button is released.
-
#on_text_change(shape) ⇒ Object
Event handler called when any editable text shape is changed.
-
#on_update_virtual_size(_virtrct) ⇒ Object
Event handler called if canvas virtual size is going to be updated.
Class Method Summary collapse
- ._init_printing ⇒ Object
- .compat_loading? ⇒ Boolean
- .compat_loading_version ⇒ Object
- .enable_gc(f = true) ⇒ Object
- .gc_enabled? ⇒ Boolean
- .page_setup_data ⇒ Object
- .page_setup_data=(psd) ⇒ Object
- .print_data ⇒ Object
- .print_data=(pd) ⇒ Object
- .reset_compat_loading ⇒ Object
- .set_compat_loading(ver_info) ⇒ Object
Instance Method Summary collapse
-
#abort_interactive_connection ⇒ Object
Abort interactive connection creation process.
-
#align_selected(halign, valign) ⇒ Object
Align selected shapes in given directions.
-
#can_align_selected ⇒ Boolean
(also: #can_align_selected?)
Function returns true if align_selected function can be invoked (if more than.
-
#can_copy ⇒ Boolean
(also: #can_copy?)
Function returns true if some shapes can be copied to the clipboard (it means they are selected).
-
#can_cut ⇒ Boolean
(also: #can_cut?)
Function returns true if some shapes can be cut to the clipboard (it means they are selected).
-
#can_paste ⇒ Boolean
(also: #can_paste?)
Function returns true if some shapes can be copied from the clipboard to the canvas (it means the clipboard contains stored shapes).
-
#can_redo ⇒ Boolean
(also: #can_redo?)
Function returns TRUE if Redo operation can be done.
-
#can_undo ⇒ Boolean
(also: #can_undo?)
Function returns true if undo operation can be done.
-
#center_shapes ⇒ Object
Center diagram in accordance to the shape canvas extent.
-
#clear_canvas_history ⇒ Object
Clear all stored canvas states (no Undo/Redo operations will be available).
-
#copy ⇒ Object
Copy selected shapes to the clipboard.
-
#create(parent, id = -1,, pos = Wx::DEFAULT_POSITION, size = Wx::DEFAULT_SIZE, style = (Wx::HSCROLL | Wx::VSCROLL), name = "Wx::ScrolledWindow") ⇒ Object
Creates the window in two-step construction mode.
-
#cut ⇒ Object
Copy selected shapes to the clipboard and remove them from the canvas.
-
#deselect_all ⇒ Object
Deselect all shapes.
-
#do_drag_drop(shapes, start = Wx::Point.new(-1, -1)) ⇒ Wx::DragResult
Start Drag&Drop operation with shapes included in the given list.
-
#dp2lp(arg) ⇒ Object
Convert device position to logical position.
-
#draw_background(dc, _from_paint) ⇒ Object
implementation draws canvas background and grid.
-
#draw_content(dc, from_paint) ⇒ Object
implementation draws actual objects managed by assigned diagram manager.
-
#draw_foreground(_dc, _from_paint) ⇒ Object
do nothing.
-
#fit_position_to_grid(pos) ⇒ Wx::Point
Update given position so it will fit canvas grid (if enabled).
-
#get_arrow_fill ⇒ Wx::Brush
(also: #arrow_fill)
Get default arrow fill brush.
-
#get_border_pen ⇒ Wx::Pen
(also: #border_pen)
Get default border pen.
-
#get_control_border ⇒ Wx::Pen
(also: #control_border)
Get default control border.
-
#get_control_fill ⇒ Wx::Brush
(also: #control_fill)
Get default control fill brush.
-
#get_control_mod_border ⇒ Wx::Pen
(also: #control_mod_border)
Get default control modification border.
-
#get_control_mod_fill ⇒ Wx::Brush
(also: #control_mod_fill)
Get default control modification fill brush.
-
#get_diagram ⇒ Wx::SF::Diagram
(also: #diagram)
Returns the shape diagram which shapes are displayed on this canvas.
-
#get_fill_brush ⇒ Wx::Brush
(also: #fill_brush)
Get default fill brush.
-
#get_history_manager ⇒ Wx::SF::CanvasHistory
(also: #history_manager)
Get canvas history manager.
-
#get_hover_colour ⇒ Wx::Colour
(also: #get_hover_color, #hover_colour, #hover_color)
Get default hover colour.
-
#get_line_pen ⇒ Wx::Pen
(also: #line_pen)
Get default line pen.
-
#get_mode ⇒ MODE
(also: #mode)
Get canvas working mode.
-
#get_multiselection_box ⇒ Wx::SF::MultiSelRect
Get reference to multiselection box.
-
#get_selected_shapes(selection = []) ⇒ Array<Wx::SF::Shape>
Get list of selected shapes.
-
#get_selection_bb ⇒ Wx::Rect
Get bounding box of all selected shapes.
-
#get_shape_at_position(pos, zorder = 1, mode = SEARCHMODE::BOTH) ⇒ Wx::SF::Shape?
Get shape at given logical position at the given position).
-
#get_shape_under_cursor(mode = SEARCHMODE::BOTH) ⇒ Wx::SF::Shape?
Get shape under current mouse cursor position (fast implementation - use everywhere it is possible instead of much slower GetShapeAtPosition()).
-
#get_shapes_at_position(pos, shapes = []) ⇒ Array<Wx::SF::Shape>
Get list of all shapes located at given position.
-
#get_shapes_inside(rct, shapes = []) ⇒ Array<Wx::SF::Shape>
Get list of shapes located inside given rectangle.
-
#get_text_border ⇒ Wx::Pen
(also: #text_border)
Get default text border.
-
#get_text_colour ⇒ Wx::Colour
(also: #get_text_color, #text_colour, #text_color)
Get default text colour.
-
#get_text_fill ⇒ Wx::Brush
(also: #text_fill)
Get default text fill brush.
-
#get_text_font ⇒ Wx::Font
(also: #text_font)
Get default text font.
-
#get_topmost_handle_at_position(pos) ⇒ Wx::SF::Shape::Handle?
Get topmost handle at given position.
-
#get_total_bounding_box ⇒ Wx::Rect
Get box bounding all shapes in the canvas.
-
#hide_all_handles ⇒ Object
Hide handles of all shapes.
-
#initialize(diagram = nil, *mixed_args) ⇒ ShapeCanvas
constructor
A new instance of ShapeCanvas.
- #inspect ⇒ Object
-
#invalidate_rect(rct) ⇒ Object
Mark given rectangle as an invalidated one, i.e.
-
#invalidate_visible_rect ⇒ Object
Mark whole visible canvas portion as an invalidated rectangle.
-
#load_canvas(io, format: nil) ⇒ Object
Load serialized canvas content (diagrams).
-
#lp2dp(arg) ⇒ Object
Convert logical position to device position.
-
#move_shapes_from_negatives ⇒ Object
Move all shapes so none of it will be located in negative position.
-
#paste ⇒ Object
Paste shapes stored in the clipboard to the canvas.
-
#redo ⇒ Object
Perform Redo operation (if available).
-
#refresh_canvas(erase, rct) ⇒ Object
Repaint the shape canvas.
-
#refresh_invalidated_rect ⇒ Object
Refresh all canvas rectangles marked as invalidated.
-
#restore_canvas_state(state) ⇒ Object
protected
Restores given canvas state (unless nil given).
-
#restore_current_state ⇒ Object
protected
Restores current last saved canvas state.
-
#save_canvas(io, compact: true, format: nil) ⇒ Object
Save canvas content (diagrams).
-
#save_canvas_state ⇒ Object
Save current canvas state (for Undo/Redo operations).
- #save_canvas_to_image(file = nil, type: Wx::BITMAP_TYPE_BMP, background: true, scale: -1.0)) ⇒ Object
-
#scroll_to_shape(shape) ⇒ Object
Scroll the shape canvas so the given shape will be located in its center.
-
#select_all ⇒ Object
Select all shapes in the canvas.
-
#set_arrow_fill(*args) ⇒ Object
(also: #arrow_fill=)
Set default arrow fill brush.
-
#set_border_pen(*args) ⇒ Object
(also: #border_pen=)
Set default border pen.
-
#set_control_border(*args) ⇒ Object
(also: #control_border=)
Set default control border.
-
#set_control_fill(*args) ⇒ Object
(also: #control_fill=)
Set default control fill brush.
-
#set_control_mod_border(*args) ⇒ Object
(also: #control_mod_border=)
Set default control modification border.
-
#set_control_mod_fill(*args) ⇒ Object
(also: #control_mod_fill=)
Set default control modification fill brush.
-
#set_diagram(diagram) ⇒ Object
Set the shape diagram to display on this canvas.
-
#set_fill_brush(*args) ⇒ Object
(also: #fill_brush=)
Set default fill brush.
-
#set_hover_colour(col) ⇒ Object
(also: #set_hover_color, #hover_colour=, #hover_color=)
Set default hover color.
-
#set_line_pen(*args) ⇒ Object
(also: #line_pen=)
Set default line pen.
-
#set_scale_to_view_all ⇒ Object
Set the canvas scale so a whole diagram is visible.
-
#set_text_border(*args) ⇒ Object
(also: #text_border=)
Set default text border.
-
#set_text_colour(col) ⇒ Object
(also: #set_text_color=, #text_colour=, #text_color=)
Set default text color.
-
#set_text_fill(*args) ⇒ Object
(also: #text_fill=)
Set default text fill brush.
-
#set_text_font(*args) ⇒ Object
(also: #text_font=)
Set default text font.
-
#show_shadows(show, style) ⇒ Object
Show shapes shadows (only current diagram shapes are affected).
-
#start_interactive_connection(*args) ⇒ Object
Start interactive connection creation.
-
#undo ⇒ Object
Perform Undo operation (if available).
-
#update_multiedit_size ⇒ Object
Update size of multi selection rectangle.
-
#update_shape_under_cursor_cache(lpos) ⇒ Object
Search for any shape located at the (mouse cursor) position (result used by #get_shape_under_cursor).
-
#update_virtual_size ⇒ Object
Update scroll window virtual size so it can display all shape canvas.
-
#validate_selection(selection) ⇒ Object
Validate selection (remove redundantly selected shapes etc…).
Constructor Details
#initialize ⇒ ShapeCanvas #initialize(diagram, parent, id = Wx::ID_ANY, pos = Wx::DEFAULT_POSITION, size = Wx::DEFAULT_SIZE, style = Wx::HSCROLL|Wx::VSCROLL) ⇒ ShapeCanvas
Returns a new instance of ShapeCanvas.
450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 |
# File 'lib/wx/shapes/shape_canvas.rb', line 450 def initialize(diagram = nil, *mixed_args) super() @dnd_started_here = false @dnd_started_at = nil @can_save_state_on_mouse_up = false @working_mode = MODE::READY @selection_mode = SELECTIONMODE::NORMAL @selected_handle = nil @selection_start = Wx::RealPoint.new @new_line_shape = nil @unselected_shape_under_cursor = nil @selected_shape_under_cursor = nil @topmost_shape_under_cursor = nil @current_shapes = [] @invalidate_rect = nil @prev_mouse_pos = Wx::Point.new @prev_positions = {} @settings = Settings.new @canvas_history = CanvasHistory.new if diagram parent = mixed_args.first.is_a?(Wx::Window) ? mixed_args.shift : nil real_args = [] begin real_args = [parent] + Wx::ScrolledWindow.args_as_list(*mixed_args) create(*real_args) rescue => err msg = "Error initializing #{self.inspect}\n" + " : #{err.} \n" + "Provided are #{real_args} \n" + "Correct parameters for #{self.class.name}.new are:\n" + self.class.describe_constructor new_err = err.class.new(msg) new_err.set_backtrace(caller) Kernel.raise new_err end self.diagram = diagram save_canvas_state end # set up event handlers evt_paint :_on_paint evt_erase_background :_on_erase_background evt_left_down :_on_left_down evt_left_up :_on_left_up evt_right_down :_on_right_down evt_right_up :_on_right_up evt_left_dclick :_on_left_double_click evt_right_dclick :_on_right_double_click evt_motion :_on_mouse_move evt_mousewheel :_on_mouse_wheel evt_key_down :_on_key_down evt_enter_window :_on_enter_window evt_leave_window :_on_leave_window evt_size :_on_resize end |
Instance Attribute Details
#settings ⇒ Object (readonly)
Returns the value of attribute settings.
552 553 554 |
# File 'lib/wx/shapes/shape_canvas.rb', line 552 def settings @settings end |
Class Method Details
._init_printing ⇒ Object
312 313 314 315 316 317 318 319 320 321 322 323 |
# File 'lib/wx/shapes/shape_canvas.rb', line 312 def _init_printing @print_data = Wx::PRT::PrintData.new # You could set an initial paper size here # @print_data.set_paper_id(Wx::PaperSize::PAPER_LETTER) # for Americans @print_data.set_paper_id(Wx::PaperSize::PAPER_A4) # for everyone else # copy over initial paper size from print record @page_setup_data = Wx::PRT::PageSetupDialogData.new(@print_data) # Set some initial page margins in mm. @page_setup_data.set_margin_top_left([15, 15]) @page_setup_data.set_margin_bottom_right([15, 15]) end |
.compat_loading? ⇒ Boolean
278 279 280 |
# File 'lib/wx/shapes/shape_canvas.rb', line 278 def compat_loading? !!::Thread::current[TLS_LOADING_VERSION_KEY] end |
.compat_loading_version ⇒ Object
282 283 284 |
# File 'lib/wx/shapes/shape_canvas.rb', line 282 def compat_loading_version ::Thread::current[TLS_LOADING_VERSION_KEY] end |
.enable_gc(f = true) ⇒ Object
266 267 268 269 270 271 272 273 |
# File 'lib/wx/shapes/shape_canvas.rb', line 266 def enable_gc(f = true) if Wx.has_feature?(:USE_GRAPHICS_CONTEXT) @gc_enabled = f else @gc_enabled = false Wx.log_warning(%Q{Couldn't enable Graphics context due to missing USE_GRAPHICS_CONTEXT}) end end |
.gc_enabled? ⇒ Boolean
259 260 261 262 263 264 |
# File 'lib/wx/shapes/shape_canvas.rb', line 259 def gc_enabled? if @gc_enabled.nil? @gc_enabled = Wx.has_feature?(:USE_GRAPHICS_CONTEXT) end @gc_enabled end |
.page_setup_data ⇒ Object
303 304 305 306 |
# File 'lib/wx/shapes/shape_canvas.rb', line 303 def page_setup_data _init_printing unless @page_setup_data @page_setup_data end |
.page_setup_data=(psd) ⇒ Object
308 309 310 |
# File 'lib/wx/shapes/shape_canvas.rb', line 308 def page_setup_data=(psd) @page_setup_data = psd end |
.print_data ⇒ Object
294 295 296 297 |
# File 'lib/wx/shapes/shape_canvas.rb', line 294 def print_data _init_printing unless @print_data @print_data end |
.print_data=(pd) ⇒ Object
299 300 301 |
# File 'lib/wx/shapes/shape_canvas.rb', line 299 def print_data=(pd) @print_data = pd end |
.reset_compat_loading ⇒ Object
290 291 292 |
# File 'lib/wx/shapes/shape_canvas.rb', line 290 def reset_compat_loading ::Thread::current[TLS_LOADING_VERSION_KEY] = nil end |
.set_compat_loading(ver_info) ⇒ Object
286 287 288 |
# File 'lib/wx/shapes/shape_canvas.rb', line 286 def set_compat_loading(ver_info) ::Thread::current[TLS_LOADING_VERSION_KEY] = ver_info end |
Instance Method Details
#abort_interactive_connection ⇒ Object
Abort interactive connection creation process
889 890 891 892 893 894 895 896 897 898 899 |
# File 'lib/wx/shapes/shape_canvas.rb', line 889 def abort_interactive_connection return unless @diagram if @new_line_shape @diagram.remove_shape(@new_line_shape) @new_line_shape = nil on_connection_finished(nil) end @working_mode = MODE::READY refresh(false) end |
#add_style(style) ⇒ Object
Add new style flag.
1626 1627 1628 |
# File 'lib/wx/shapes/shape_canvas.rb', line 1626 def add_style(style) @settings.style |= style end |
#align_selected(halign, valign) ⇒ Object
Align selected shapes in given directions.
Shapes will be aligned according to most far shape in appropriate direction.
1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 |
# File 'lib/wx/shapes/shape_canvas.rb', line 1532 def align_selected(halign, valign) cnt = 0 min_pos = max_pos = nil lst_selection = get_selected_shapes upd_rct = get_selection_bb upd_rct.inflate!(DEFAULT_ME_OFFSET, DEFAULT_ME_OFFSET) # find most distant position lst_selection.each do |shape| unless shape.is_a?(LineShape) pos = shape.get_absolute_position shape_bb = shape.get_bounding_box if cnt == 0 min_pos = pos.dup max_pos = Wx::RealPoint.new(pos.x + shape_bb.width, pos.y + shape_bb.height) else min_pos.x = pos.x if pos.x < min_pos.x min_pos.y = pos.y if pos.y < min_pos.y max_pos.x = pos.x + shape_bb.width if (pos.x + shape_bb.width) > max_pos.x max_pos.y = pos.y + shape_bb.height if (pos.y + shape_bb.height) > max_pos.y end cnt += 1 end end # if only one non-line shape is in the selection then alignment has no sense so exit... return if cnt < 2 # set new positions lst_selection.each do |shape| unless shape.is_a?(LineShape) pos = shape.get_absolute_position shape_bb = shape.get_bounding_box case halign when HALIGN::LEFT shape.move_to(min_pos.x, pos.y) when HALIGN::RIGHT shape.move_to(max_pos.x - shape_bb.width, pos.y) when HALIGN::CENTER shape.move_to((max_pos.x + min_pos.x)/2 - shape_bb.width/2, pos.y) end case valign when VALIGN::TOP shape.move_to(pos.x, min_pos.y) when VALIGN::BOTTOM shape.move_to(pos.x, max_pos.y - shape_bb.height) when VALIGN::MIDDLE shape.move_to(pos.x, (max_pos.y + min_pos.y)/2 - shape_bb.height/2) end # update the shape and its parent shape.update parent = shape.get_parent_shape parent.update if parent end end unless upd_rct.empty? update_multiedit_size save_canvas_state refresh_canvas(false, upd_rct) end end |
#can_align_selected ⇒ Boolean Also known as: can_align_selected?
Function returns true if align_selected function can be invoked (if more than
1206 1207 1208 |
# File 'lib/wx/shapes/shape_canvas.rb', line 1206 def can_align_selected @shp_multi_edit.visible? && @working_mode == MODE::READY end |
#can_copy ⇒ Boolean Also known as: can_copy?
Function returns true if some shapes can be copied to the clipboard (it means they are selected)
1160 1161 1162 1163 1164 |
# File 'lib/wx/shapes/shape_canvas.rb', line 1160 def can_copy return false unless has_style?(STYLE::CLIPBOARD) !get_selected_shapes.empty? end |
#can_cut ⇒ Boolean Also known as: can_cut?
Function returns true if some shapes can be cut to the clipboard (it means they are selected)
1169 1170 1171 |
# File 'lib/wx/shapes/shape_canvas.rb', line 1169 def can_cut can_copy end |
#can_paste ⇒ Boolean Also known as: can_paste?
Function returns true if some shapes can be copied from the clipboard to the canvas (it means the clipboard contains stored shapes)
1177 1178 1179 1180 1181 1182 1183 |
# File 'lib/wx/shapes/shape_canvas.rb', line 1177 def can_paste return false unless has_style?(STYLE::CLIPBOARD) Wx::Clipboard.open do |clipboard| return clipboard.supported?(Wx::SF::ShapeDataObject::DataFormatID) end rescue false end |
#can_redo ⇒ Boolean Also known as: can_redo?
Function returns TRUE if Redo operation can be done
1197 1198 1199 1200 1201 |
# File 'lib/wx/shapes/shape_canvas.rb', line 1197 def can_redo return false unless has_style?(STYLE::UNDOREDO) @canvas_history.can_redo end |
#can_undo ⇒ Boolean Also known as: can_undo?
Function returns true if undo operation can be done
1188 1189 1190 1191 1192 |
# File 'lib/wx/shapes/shape_canvas.rb', line 1188 def can_undo return false unless has_style?(STYLE::UNDOREDO) @canvas_history.can_undo end |
#center_shapes ⇒ Object
Center diagram in accordance to the shape canvas extent.
2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 |
# File 'lib/wx/shapes/shape_canvas.rb', line 2301 def center_shapes rct_prev_bb = get_total_bounding_box rct_bb = rct_prev_bb.center_in(Wx::Rect.new(Wx::Point.new(0, 0), get_size)) dx = (rct_bb.left - rct_prev_bb.left).to_f dy = (rct_bb.top - rct_prev_bb.top).to_f @current_shapes.each do |shape| shape.move_by(dx, dy) unless shape.get_parent_shape end move_shapes_from_negatives end |
#clear_canvas_history ⇒ Object
Clear all stored canvas states (no Undo/Redo operations will be available)
1219 1220 1221 |
# File 'lib/wx/shapes/shape_canvas.rb', line 1219 def clear_canvas_history @canvas_history.clear end |
#contains_style(style) ⇒ Object Also known as: contains_style?, has_style?
Check whether given style flag is used.
1638 1639 1640 |
# File 'lib/wx/shapes/shape_canvas.rb', line 1638 def contains_style(style) (@settings.style & style) != 0 end |
#copy ⇒ Object
Copy selected shapes to the clipboard
1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 |
# File 'lib/wx/shapes/shape_canvas.rb', line 1066 def copy return unless has_style?(STYLE::CLIPBOARD) return unless @diagram # copy selected shapes to the clipboard Wx::Clipboard.open do |clipboard| lst_selection = get_selected_shapes validate_selection_for_clipboard(lst_selection,true) unless lst_selection.empty? data_obj = Wx::SF::ShapeDataObject.new(lst_selection) clipboard.place(data_obj) restore_prev_positions end end end |
#create(parent, id = -1,, pos = Wx::DEFAULT_POSITION, size = Wx::DEFAULT_SIZE, style = (Wx::HSCROLL | Wx::VSCROLL), name = "Wx::ScrolledWindow") ⇒ Object
Creates the window in two-step construction mode. set_diagram() function must also be called to complete the canvas initialization.
520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 |
# File 'lib/wx/shapes/shape_canvas.rb', line 520 def create(parent, id = -1, pos = Wx::DEFAULT_POSITION, size = Wx::DEFAULT_SIZE, style = (Wx::HSCROLL | Wx::VSCROLL), name = "Wx::ScrolledWindow") # NOTE: user must call Wx::SF::ShapeCanvas#set_diagram() to complete # canvas initialization! # perform basic window initialization super # set drop target if Wx.has_feature?(:USE_DRAG_AND_DROP) set_drop_target(Wx::SF::CanvasDropTarget.new(Wx::SF::ShapeDataObject.new, self)) end # initialize selection rectangle @shp_selection = MultiSelRect.new @shp_selection.create_handles @shp_selection.select(true) @shp_selection.show(false) @shp_selection.show_handles(true) # initialize multi-edit rectangle @shp_multi_edit = MultiSelRect.new @shp_multi_edit.create_handles @shp_multi_edit.select(true) @shp_multi_edit.show(false) @shp_multi_edit.show_handles(true) (5, 5, 100, 100) set_background_style(Wx::BG_STYLE_PAINT) true end |
#cut ⇒ Object
Copy selected shapes to the clipboard and remove them from the canvas
1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 |
# File 'lib/wx/shapes/shape_canvas.rb', line 1087 def cut return unless has_style?(STYLE::CLIPBOARD) return unless @diagram copy clear_temporaries # remove selected shapes lst_selection = get_selected_shapes validate_selection_for_clipboard(lst_selection,false) unless lst_selection.empty? @diagram.remove_shapes(lst_selection) @shp_multi_edit.show(false) save_canvas_state refresh(false) end end |
#deselect_all ⇒ Object
Deselect all shapes
922 923 924 925 926 927 928 |
# File 'lib/wx/shapes/shape_canvas.rb', line 922 def deselect_all return unless @diagram @diagram.get_all_shapes.each { |shape| shape.select(false) } @shp_multi_edit.show(false) end |
#do_drag_drop(shapes, start = Wx::Point.new(-1, -1)) ⇒ Wx::DragResult
Start Drag&Drop operation with shapes included in the given list.
1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 |
# File 'lib/wx/shapes/shape_canvas.rb', line 1018 def do_drag_drop(shapes, start = Wx::Point.new(-1, -1)) return Wx::DragNone unless has_style?(STYLE::DND) @working_mode = MODE::DND result = Wx::DragNone validate_selection_for_clipboard(shapes, true) unless shapes.empty? deselect_all @dnd_started_here = true @dnd_started_at = start.to_point data_obj = Wx::SF::ShapeDataObject.new(shapes) dnd_src = if Wx::PLATFORM == 'WXGTK' Wx::DropSource.new(data_obj, self, Wx::Icon(:page), Wx::Icon(:page), Wx::Icon(:page)) else Wx::DropSource.new(data_obj) end result = dnd_src.do_drag_drop(Wx::Drag_AllowMove) case result when Wx::DragResult::DragMove @diagram.remove_shapes(shapes) end @dnd_started_here = false restore_prev_positions move_shapes_from_negatives update_virtual_size save_canvas_state refresh(false) end @working_mode = MODE::READY result end |
#dp2lp(pos) ⇒ Wx::Point #dp2lp(rct) ⇒ Wx::Rect
Convert device position to logical position.
The function returns unscrolled unscaled canvas position.
1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 |
# File 'lib/wx/shapes/shape_canvas.rb', line 1334 def dp2lp(arg) if arg.is_a?(Wx::Rect) x, y = calc_unscrolled_position(arg.x, arg.y) Wx::Rect.new((x/@settings.scale).to_i, (y/@settings.scale).to_i, (arg.width/@settings.scale).to_i, (arg.height/@settings.scale).to_i) else arg = arg.to_point x, y = calc_unscrolled_position(arg.x, arg.y) Wx::Point.new((x/@settings.scale).to_i, (y/@settings.scale).to_i) end end |
#draw_background(dc, _from_paint) ⇒ Object
implementation draws canvas background and grid. or derived classes (i.e. the function is called as a response to Wx::EVT_PAINT event)
2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 |
# File 'lib/wx/shapes/shape_canvas.rb', line 2432 def draw_background(dc, _from_paint) # erase background if has_style?(STYLE::GRADIENT_BACKGROUND) bcg_size = get_virtual_size.to_size + @settings.grid_size if @settings.scale != 1.0 dc.gradient_fill_linear(Wx::Rect.new([0, 0], [(bcg_size.x/@settings.scale).to_i, (bcg_size.y/@settings.scale).to_i]), @settings.gradient_from, @settings.gradient_to, Wx::SOUTH) else dc.gradient_fill_linear(Wx::Rect.new(Wx::Point.new(0, 0), bcg_size), @settings.gradient_from, @settings.gradient_to, Wx::SOUTH) end else dc.set_background(Wx::Brush.new(@settings.background_color)) dc.clear end # show grid if has_style?(STYLE::GRID_SHOW) linedist = @settings.grid_size * @settings.grid_line_mult if (linedist * @settings.scale) > 3.0 grid_rct = Wx::Rect.new([0, 0], get_virtual_size.to_size + @settings.grid_size) max_x = (grid_rct.right/@settings.scale).to_i max_y = (grid_rct.bottom/@settings.scale).to_i dc.set_pen(Wx::Pen.new(@settings.grid_color, 1, @settings.grid_style)) (grid_rct.left..max_x).step(linedist) do |x| dc.draw_line(x, 0, x, max_y) end (grid_rct.top..max_y).step(linedist) do |y| dc.draw_line(0, y, max_x, y) end end end end |
#draw_content(dc, from_paint) ⇒ Object
implementation draws actual objects managed by assigned diagram manager. or derived classes (i.e. the function is called as a response to Wx::EVT_PAINT event)
2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 |
# File 'lib/wx/shapes/shape_canvas.rb', line 2380 def draw_content(dc, from_paint) return unless @diagram if from_paint # get all existing shapes lst_to_draw = @diagram.get_shapes(Shape, Shape::SEARCHMODE::DFS) upd_rct = nil # get the update rect list Wx::RegionIterator.for_region(get_update_region) do |region_it| # combine updated rectangles region_it.each do |rct| if upd_rct.nil? upd_rct = dp2lp(rct.inflate(5, 5)) else upd_rct.union!(dp2lp(rct.inflate(5, 5))) end end end upd_rct ||= Wx::Rect.new if @working_mode == MODE::SHAPEMOVE # draw unselected shapes first and filter and return selected shapes lst_selected = draw_shape_updates(dc, upd_rct, lst_to_draw, true) # ... and now draw the selected shapes being moved draw_shape_updates(dc, upd_rct, lst_selected) else draw_shape_updates(dc, upd_rct, lst_to_draw) end # draw multiselection if necessary @shp_selection.draw(dc) if @shp_selection.visible? @shp_multi_edit.draw(dc) if @shp_multi_edit.visible? else # draw parent shapes (children are processed by parent objects) @diagram.get_top_shapes.each do |shape| shape.draw(dc) if !shape.is_a?(LineShape) || shape.stand_alone? end # draw connections @diagram.get_top_shapes.each do |shape| shape.draw(dc) if shape.is_a?(LineShape) && !shape.stand_alone? end end end |
#draw_foreground(_dc, _from_paint) ⇒ Object
do nothing. or derived classes (i.e. the function is called as a response to Wx::EVT_PAINT event)
2473 2474 2475 |
# File 'lib/wx/shapes/shape_canvas.rb', line 2473 def draw_foreground(_dc, _from_paint) # do nothing here... end |
#fit_position_to_grid(pos) ⇒ Wx::Point
Update given position so it will fit canvas grid (if enabled).
2250 2251 2252 2253 2254 2255 2256 2257 2258 |
# File 'lib/wx/shapes/shape_canvas.rb', line 2250 def fit_position_to_grid(pos) pos = pos.to_point if has_style?(STYLE::GRID_USE) Wx::Point.new(pos.x / @settings.grid_size * @settings.grid_size, pos.y / @settings.grid_size * @settings.grid_size) else pos end end |
#get_arrow_fill ⇒ Wx::Brush Also known as: arrow_fill
Get default arrow fill brush.
2046 2047 2048 |
# File 'lib/wx/shapes/shape_canvas.rb', line 2046 def get_arrow_fill @settings.common_arrow_fill end |
#get_border_pen ⇒ Wx::Pen Also known as: border_pen
Get default border pen.
1999 2000 2001 |
# File 'lib/wx/shapes/shape_canvas.rb', line 1999 def get_border_pen @settings.common_border_pen end |
#get_canvas_colour ⇒ Wx::Colour Also known as: get_canvas_color, canvas_colour, canvas_color
Get canvas background color.
1659 1660 1661 |
# File 'lib/wx/shapes/shape_canvas.rb', line 1659 def get_canvas_colour @settings.background_color end |
#get_control_border ⇒ Wx::Pen Also known as: control_border
Get default control border.
2187 2188 2189 |
# File 'lib/wx/shapes/shape_canvas.rb', line 2187 def get_control_border @settings.common_control_border end |
#get_control_fill ⇒ Wx::Brush Also known as: control_fill
Get default control fill brush.
2164 2165 2166 |
# File 'lib/wx/shapes/shape_canvas.rb', line 2164 def get_control_fill @settings.common_control_fill end |
#get_control_mod_border ⇒ Wx::Pen Also known as: control_mod_border
Get default control modification border.
2234 2235 2236 |
# File 'lib/wx/shapes/shape_canvas.rb', line 2234 def get_control_mod_border @settings.common_control_mod_border end |
#get_control_mod_fill ⇒ Wx::Brush Also known as: control_mod_fill
Get default control modification fill brush.
2211 2212 2213 |
# File 'lib/wx/shapes/shape_canvas.rb', line 2211 def get_control_mod_fill @settings.common_control_mod_fill end |
#get_diagram ⇒ Wx::SF::Diagram Also known as: diagram
Returns the shape diagram which shapes are displayed on this canvas.
556 557 558 |
# File 'lib/wx/shapes/shape_canvas.rb', line 556 def get_diagram @diagram end |
#get_fill_brush ⇒ Wx::Brush Also known as: fill_brush
Get default fill brush.
1976 1977 1978 |
# File 'lib/wx/shapes/shape_canvas.rb', line 1976 def get_fill_brush @settings.common_fill_brush end |
#get_gradient_from ⇒ Wx::Colour Also known as: gradient_from
Get starting gradient color.
1675 1676 1677 |
# File 'lib/wx/shapes/shape_canvas.rb', line 1675 def get_gradient_from @settings.gradient_from end |
#get_gradient_to ⇒ Wx::Colour Also known as: gradient_to
Get ending gradient color.
1689 1690 1691 |
# File 'lib/wx/shapes/shape_canvas.rb', line 1689 def get_gradient_to @settings.gradient_to end |
#get_grid_colour ⇒ Wx::Colour Also known as: get_grid_color, grid_colour, grid_color
Get grid color.
1737 1738 1739 |
# File 'lib/wx/shapes/shape_canvas.rb', line 1737 def get_grid_colour @settings.grid_color end |
#get_grid_line_mult ⇒ Integer Also known as: grid_line_mult
Get grid line multiple.
1721 1722 1723 |
# File 'lib/wx/shapes/shape_canvas.rb', line 1721 def get_grid_line_mult @settings.grid_line_mult end |
#get_grid_size ⇒ Integer Also known as: grid_size
Get grid size (px).
1696 1697 1698 |
# File 'lib/wx/shapes/shape_canvas.rb', line 1696 def get_grid_size @settings.grid_size end |
#get_grid_style ⇒ Wx::PenStyle Also known as: grid_style
Get grid line style.
1753 1754 1755 |
# File 'lib/wx/shapes/shape_canvas.rb', line 1753 def get_grid_style @settings.grid_style end |
#get_history_manager ⇒ Wx::SF::CanvasHistory Also known as: history_manager
Get canvas history manager.
2242 2243 2244 |
# File 'lib/wx/shapes/shape_canvas.rb', line 2242 def get_history_manager @canvas_history end |
#get_hover_colour ⇒ Wx::Colour Also known as: get_hover_color, hover_colour, hover_color
Get default hover colour.
1950 1951 1952 |
# File 'lib/wx/shapes/shape_canvas.rb', line 1950 def get_hover_colour @settings.common_hover_color end |
#get_line_pen ⇒ Wx::Pen Also known as: line_pen
Get default line pen.
2022 2023 2024 |
# File 'lib/wx/shapes/shape_canvas.rb', line 2022 def get_line_pen @settings.common_line_pen end |
#get_max_scale ⇒ FLOAT Also known as: max_scale
Set maximal allowed scale (for mouse wheel scale change).
1890 1891 1892 |
# File 'lib/wx/shapes/shape_canvas.rb', line 1890 def get_max_scale @settings.max_scale end |
#get_min_scale ⇒ Float Also known as: min_scale
Get minimal allowed scale (for mouse wheel scale change).
1876 1877 1878 |
# File 'lib/wx/shapes/shape_canvas.rb', line 1876 def get_min_scale @settings.min_scale end |
#get_mode ⇒ MODE Also known as: mode
Get canvas working mode.
1934 1935 1936 |
# File 'lib/wx/shapes/shape_canvas.rb', line 1934 def get_mode @working_mode end |
#get_multiselection_box ⇒ Wx::SF::MultiSelRect
Get reference to multiselection box
2479 2480 2481 |
# File 'lib/wx/shapes/shape_canvas.rb', line 2479 def get_multiselection_box @shp_multi_edit end |
#get_print_h_align ⇒ HALIGN Also known as: print_h_align
Get horizontal align of printed drawing.
1807 1808 1809 |
# File 'lib/wx/shapes/shape_canvas.rb', line 1807 def get_print_h_align @settings.print_h_align end |
#get_print_mode ⇒ PRINTMODE Also known as: print_mode
Get printing mode for this canvas. #see PRINTMODE
1839 1840 1841 |
# File 'lib/wx/shapes/shape_canvas.rb', line 1839 def get_print_mode @settings.print_mode end |
#get_print_v_align ⇒ VALIGN Also known as: print_v_align
Get vertical align of printed drawing.
1823 1824 1825 |
# File 'lib/wx/shapes/shape_canvas.rb', line 1823 def get_print_v_align @settings.print_v_align end |
#get_scale ⇒ Float Also known as: scale
Get the canvas scale.
1897 1898 1899 |
# File 'lib/wx/shapes/shape_canvas.rb', line 1897 def get_scale @settings.scale end |
#get_selected_shapes(selection = []) ⇒ Array<Wx::SF::Shape>
Get list of selected shapes.
1487 1488 1489 1490 1491 1492 1493 1494 1495 |
# File 'lib/wx/shapes/shape_canvas.rb', line 1487 def get_selected_shapes(selection = []) return selection unless @diagram selection.clear @diagram.get_all_shapes.each do |shape| selection << shape if shape.selected? end selection end |
#get_selection_bb ⇒ Wx::Rect
Get bounding box of all selected shapes.
1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 |
# File 'lib/wx/shapes/shape_canvas.rb', line 1516 def get_selection_bb bb_rct = nil # get selected shapes get_selected_shapes.each do |shape| bb_rct = shape.get_complete_bounding_box(bb_rct, Shape::BBMODE::SELF | Shape::BBMODE::CHILDREN | Shape::BBMODE::CONNECTIONS | Shape::BBMODE::SHADOW) end bb_rct || Wx::Rect.new end |
#get_shadow_fill ⇒ Wx::Brush Also known as: shadow_fill
Get shadow fill.
1791 1792 1793 |
# File 'lib/wx/shapes/shape_canvas.rb', line 1791 def get_shadow_fill @settings.shadow_fill end |
#get_shadow_offset ⇒ Wx::RealPoint Also known as: shadow_offset
Get shadow offset.
1767 1768 1769 |
# File 'lib/wx/shapes/shape_canvas.rb', line 1767 def get_shadow_offset @settings.shadow_offset end |
#get_shape_at_position(pos, zorder = 1, mode = SEARCHMODE::BOTH) ⇒ Wx::SF::Shape?
Get shape at given logical position at the given position)
1431 1432 1433 1434 1435 |
# File 'lib/wx/shapes/shape_canvas.rb', line 1431 def get_shape_at_position(pos, zorder = 1, mode = SEARCHMODE::BOTH) return nil unless @diagram @diagram.get_shape_at_position(pos, zorder, mode) end |
#get_shape_under_cursor(mode = SEARCHMODE::BOTH) ⇒ Wx::SF::Shape?
Get shape under current mouse cursor position (fast implementation - use everywhere it is possible instead of much slower GetShapeAtPosition()).
1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 |
# File 'lib/wx/shapes/shape_canvas.rb', line 1411 def get_shape_under_cursor(mode = SEARCHMODE::BOTH) case mode when SEARCHMODE::BOTH @topmost_shape_under_cursor when SEARCHMODE::SELECTED @selected_shape_under_cursor when SEARCHMODE::UNSELECTED @unselected_shape_under_cursor else nil end end |
#get_shapes_at_position(pos, shapes = []) ⇒ Array<Wx::SF::Shape>
Get list of all shapes located at given position
1470 1471 1472 1473 |
# File 'lib/wx/shapes/shape_canvas.rb', line 1470 def get_shapes_at_position(pos, shapes = []) @diagram.get_shapes_at_position(pos, shapes) if @diagram shapes end |
#get_shapes_inside(rct, shapes = []) ⇒ Array<Wx::SF::Shape>
Get list of shapes located inside given rectangle
1479 1480 1481 1482 |
# File 'lib/wx/shapes/shape_canvas.rb', line 1479 def get_shapes_inside(rct, shapes = []) @diagram.get_shapes_inside(rct, shapes) if @diagram shapes end |
#get_style ⇒ Object Also known as: style
Get current canvas style.
1619 1620 1621 |
# File 'lib/wx/shapes/shape_canvas.rb', line 1619 def get_style @settings.style end |
#get_text_border ⇒ Wx::Pen Also known as: text_border
Get default text border.
2111 2112 2113 |
# File 'lib/wx/shapes/shape_canvas.rb', line 2111 def get_text_border @settings.common_text_border end |
#get_text_colour ⇒ Wx::Colour Also known as: get_text_color, text_colour, text_color
Get default text colour.
2062 2063 2064 |
# File 'lib/wx/shapes/shape_canvas.rb', line 2062 def get_text_colour @settings.common_text_color end |
#get_text_fill ⇒ Wx::Brush Also known as: text_fill
Get default text fill brush.
2088 2089 2090 |
# File 'lib/wx/shapes/shape_canvas.rb', line 2088 def get_text_fill @settings.common_text_fill end |
#get_text_font ⇒ Wx::Font Also known as: text_font
Get default text font.
2140 2141 2142 |
# File 'lib/wx/shapes/shape_canvas.rb', line 2140 def get_text_font @settings.common_text_font end |
#get_topmost_handle_at_position(pos) ⇒ Wx::SF::Shape::Handle?
Get topmost handle at given position
1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 |
# File 'lib/wx/shapes/shape_canvas.rb', line 1441 def get_topmost_handle_at_position(pos) return nil unless @diagram pos = pos.to_point # first test multiedit handles... if @shp_multi_edit.visible? @shp_multi_edit.handles.each do |handle| return handle if handle.visible? && handle.contains?(pos) end end # ... then test normal handles @diagram.get_all_shapes.each do |shape| # iterate through all shape's handles if shape.has_style?(Shape::STYLE::SIZE_CHANGE) shape.handles.each do |handle| return handle if handle.visible? && handle.contains?(pos) end end end nil end |
#get_total_bounding_box ⇒ Wx::Rect
Get box bounding all shapes in the canvas.
1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 |
# File 'lib/wx/shapes/shape_canvas.rb', line 1499 def get_total_bounding_box virt_rct = nil if @diagram # calculate total bounding box (includes all shapes) @diagram.get_all_shapes.each_with_index do |shape, ix| if ix == 0 virt_rct = shape.get_bounding_box else virt_rct.union!(shape.get_bounding_box) end end end virt_rct || Wx::Rect.new end |
#hide_all_handles ⇒ Object
Hide handles of all shapes
931 932 933 934 935 |
# File 'lib/wx/shapes/shape_canvas.rb', line 931 def hide_all_handles return unless @diagram @diagram.get_all_shapes.each { |shape| shape.show_handles(false) } end |
#inspect ⇒ Object
3246 3247 3248 |
# File 'lib/wx/shapes/shape_canvas.rb', line 3246 def inspect "#<Wx::SF::ShapeCanvas:#{object_id}>" end |
#invalidate_rect(rct) ⇒ Object
Mark given rectangle as an invalidated one, i.e. as a rectangle which should be refreshed (by using Wx::SF::ShapeCanvas::refresh_invalidated_rect).
956 957 958 959 960 961 962 |
# File 'lib/wx/shapes/shape_canvas.rb', line 956 def invalidate_rect(rct) if @invalidate_rect.nil? @invalidate_rect = rct.dup else @invalidate_rect.union!(rct) end end |
#invalidate_visible_rect ⇒ Object
Mark whole visible canvas portion as an invalidated rectangle.
965 966 967 |
# File 'lib/wx/shapes/shape_canvas.rb', line 965 def invalidate_visible_rect invalidate_rect(dp2lp(get_client_rect)) end |
#load_canvas(file) ⇒ self #load_canvas(io) ⇒ self
Load serialized canvas content (diagrams).
582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 |
# File 'lib/wx/shapes/shape_canvas.rb', line 582 def load_canvas(io, format: nil) # get IO stream to read from ios = if io.is_a?(::String) format ||= case File.extname(io) when '.json' then :json when '.yaml', '.yml' then :yaml when '.xml' then :xml else :json end File.open(io, 'r') else format ||= :json io end old_diagram = @diagram old_settings = @settings begin begin _, @settings, diagram = FIRM.deserialize(ios, format: format) rescue SFException ::Kernel.raise rescue ::Exception $stderr.puts "#{$!}\n#{$!.backtrace.join("\n")}\n" ::Kernel.raise SFException, "Failed to load canvas: #{$!.}" ensure ShapeCanvas.reset_compat_loading ios.close if io.is_a?(::String) && ios end set_diagram(diagram) clear_canvas_history save_canvas_state set_scale(@settings.scale) update_virtual_size refresh(false) rescue Exception $stderr.puts "#{$!}\n#{$!.backtrace.join("\n")}\n" # restore previous state @settings = old_settings set_diagram(old_diagram) clear_canvas_history save_canvas_state set_scale(@settings.scale) update_virtual_size refresh(false) # propagate exception ::Kernel.raise end @diagram.set_modified(false) self end |
#lp2dp(pos) ⇒ Wx::Point #lp2dp(rct) ⇒ Wx::Rect
Convert logical position to device position.
The function returns scrolled scaled canvas position.
1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 |
# File 'lib/wx/shapes/shape_canvas.rb', line 1355 def lp2dp(arg) if arg.is_a?(Wx::Rect) x, y = calc_scrolled_position(arg.x, arg.y) Wx::Rect.new((x*@settings.scale).to_i, (y*@settings.scale).to_i, (arg.width*@settings.scale).to_i, (arg.height*@settings.scale).to_i) else arg = arg.to_point x, y = calc_scrolled_position(arg.x, arg.y) Wx::Point.new((x*@settings.scale).to_i, (y*@settings.scale).to_i) end end |
#move_shapes_from_negatives ⇒ Object
Move all shapes so none of it will be located in negative position
2296 2297 2298 |
# File 'lib/wx/shapes/shape_canvas.rb', line 2296 def move_shapes_from_negatives @diagram.move_shapes_from_negatives if @diagram end |
#on_connection_finished(connection) ⇒ Object
Event handler called after (successful or cancelled) connection creation. The function can be overridden if necessary. The default implementation generates Wx::SF::EVT_SF_LINE_DONE event.
3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 |
# File 'lib/wx/shapes/shape_canvas.rb', line 3157 def on_connection_finished(connection) # HINT: override to perform user-defined actions... # ... standard implementation generates the Wx::SF::EVT_SF_LINE_DONE event. id = connection ? connection.object_id : -1 event = ShapeEvent.new(Wx::SF::EVT_SF_LINE_DONE, id) event.set_shape(connection) process_event(event) end |
#on_drop(x, y, deflt, dropped) ⇒ Object
Event handler called by the framework after any dragged shapes are dropped to the canvas. The default implementation generates Wx::SF::EVT_SF_ON_DROP event.
3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 |
# File 'lib/wx/shapes/shape_canvas.rb', line 3204 def on_drop(x, y, deflt, dropped) # HINT: override it for custom actions... # ... standard implementation generates the Wx::SF::EVT_SF_ON_DROP event. return unless has_style?(STYLE::DND) # create the drop event and process it event = ShapeDropEvent.new(Wx::SF::EVT_SF_ON_DROP, x, y, self, deflt, Wx::ID_ANY) event.set_dropped_shapes(dropped) process_event(event) end |
#on_key_down(event) ⇒ Object
Event handler called when any key is pressed. The function can be overridden if necessary.
The function is called by the framework and provides basic functionality needed for proper management of displayed shape. It is necessary to call this function from overridden methods if the default canvas behaviour should be preserved.
3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 |
# File 'lib/wx/shapes/shape_canvas.rb', line 3052 def on_key_down(event) # HINT: override it for custom actions... return unless @diagram lst_selection = get_selected_shapes case event.get_key_code when Wx::K_DELETE # send event to selected shapes lst_selection.delete_if do |shape| if shape.has_style?(Shape::STYLE::PROCESS_DEL) shape.send(:_on_key, event.get_key_code) true else false end end clear_temporaries # delete selected shapes @diagram.remove_shapes(lst_selection) @shp_multi_edit.show(false) save_canvas_state refresh(false) when Wx::K_ESCAPE case @working_mode when MODE::CREATECONNECTION abort_interactive_connection when MODE::HANDLEMOVE if @selected_handle && @selected_handle.get_parent_shape.is_a?(LineShape) @selected_handle.send(:_on_end_drag, Wx::Point.new(0, 0)) line = @selected_handle.get_parent_shape line.send(:set_line_mode, LineShape::LINEMODE::READY) @selected_handle = nil end restore_current_state when MODE::MULTIHANDLEMOVE restore_current_state when MODE::SHAPEMOVE restore_current_state else # send event to selected shapes lst_selection.each { |shape| shape.send(:_on_key, event.get_key_code) } end @working_mode = MODE::READY refresh(false) when Wx::K_LEFT, Wx::K_RIGHT, Wx::K_UP, Wx::K_DOWN lst_connections = [] lst_selection.each do |shape| shape.send(:_on_key, event.get_key_code) # inform also connections assigned to this shape lst_connections.clear append_assigned_connections(shape, lst_connections) lst_connections.each do |line| line.send(:_on_key, event.get_key_code) unless line.selected? end end # send the event to multiedit ctrl if displayed @shp_multi_edit.send(:_on_key, event.get_key_code) if @shp_multi_edit.visible? refresh_invalidated_rect save_canvas_state else lst_selection.each { |shape| shape.send(:_on_key, event.get_key_code) } update_multiedit_size if @shp_multi_edit.visible? end end |
#on_left_double_click(event) ⇒ Object
Event handler called when the canvas is double-clicked by the left mouse button. The function can be overridden if necessary.
The function is called by the framework and provides basic functionality needed for proper management of displayed shape. It is necessary to call this function from overridden methods if the default canvas behaviour should be preserved.
2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 |
# File 'lib/wx/shapes/shape_canvas.rb', line 2698 def on_left_double_click(event) # HINT: override it for custom actions... _notify_canvas_change(CHANGE::FOCUS) set_focus lpos = dp2lp(event.get_position) if @working_mode == MODE::READY shape = get_shape_under_cursor if shape shape.on_left_double_click(lpos) # double click onto a line shape always change its set of # control points so the canvas state should be saved now... save_canvas_state if shape.is_a?(LineShape) end end refresh_invalidated_rect end |
#on_left_down(event) ⇒ Object
Event handler called when the canvas is clicked by the left mouse button. The function can be overridden if necessary.
The function is called by the framework and provides basic functionality needed for proper management of displayed shape. It is necessary to call this function from overridden methods if the default canvas behaviour should be preserved.
2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 |
# File 'lib/wx/shapes/shape_canvas.rb', line 2494 def on_left_down(event) # HINT: override it for custom actions... return unless @diagram _notify_canvas_change(CHANGE::FOCUS) set_focus lpos = dp2lp(event.get_position) @can_save_state_on_mouse_up = false case @working_mode when MODE::READY @selected_handle = get_topmost_handle_at_position(lpos) if event.control_down && event.shift_down @selection_mode = SELECTIONMODE::REMOVE elsif event.shift_down @selection_mode = SELECTIONMODE::ADD else @selection_mode = SELECTIONMODE::NORMAL end if @selected_handle.nil? selected_shape = get_shape_at_position(lpos) selected_top_shape = selected_shape while selected_top_shape && selected_top_shape.has_style?(Shape::STYLE::PROPAGATE_SELECTION) selected_top_shape = selected_top_shape.get_parent_shape end if selected_shape # perform selection lst_selection = get_selected_shapes if @selection_mode == SELECTIONMODE::NORMAL save_canvas_state if @canvas_history.empty? end # cancel previous selections if necessary... if @selection_mode == SELECTIONMODE::NORMAL && (selected_top_shape.nil? || !lst_selection.include?(selected_top_shape)) deselect_all end selected_top_shape.select(@selection_mode != SELECTIONMODE::REMOVE) if selected_top_shape get_selected_shapes(lst_selection) # remove child shapes from the selection validate_selection(lst_selection) if lst_selection.size > 1 hide_all_handles elsif @selection_mode == SELECTIONMODE::REMOVE && lst_selection.size == 1 lst_selection.first.select(true) end fit_pos = fit_position_to_grid(lpos) # call user defined actions selected_shape.on_left_click(fit_pos) # inform selected shapes about begin of dragging... lst_connections = [] lst_selection.each do |shape| shape.send(:_on_begin_drag, fit_pos) # inform also connections assigned to the shape and its children lst_connections.clear append_assigned_connections(shape, lst_connections) lst_connections.each do |line| line.send(:_on_begin_drag, fit_pos) end end if @selection_mode == SELECTIONMODE::NORMAL @shp_multi_edit.show(false) @working_mode = MODE::SHAPEMOVE else if lst_selection.size > 1 @shp_multi_edit.show(true) @shp_multi_edit.show_handles(true) else @shp_multi_edit.show(false) end @working_mode = MODE::READY end else if has_style?(STYLE::MULTI_SELECTION) deselect_all if @selection_mode == SELECTIONMODE::NORMAL @selection_start = Wx::RealPoint.new(lpos.x, lpos.y) @shp_selection.show(true) @shp_selection.show_handles(false) @shp_selection.set_relative_position(@selection_start) @shp_selection.set_rect_size(Wx::RealPoint.new(0, 0)) @working_mode = MODE::MULTISELECTION else deselect_all @working_mode = MODE::READY end end # update canvas invalidate_visible_rect else save_canvas_state if @canvas_history.empty? if @selected_handle.get_parent_shape == @shp_multi_edit if has_style?(STYLE::MULTI_SIZE_CHANGE) @working_mode = MODE::MULTIHANDLEMOVE else @working_mode = MODE::READY end else @working_mode = MODE::HANDLEMOVE case @selected_handle.get_type when Shape::Handle::TYPE::LINESTART line = @selected_handle.get_parent_shape line.send(:set_line_mode, LineShape::LINEMODE::SRCCHANGE) line.send(:set_unfinished_point, lpos) when Shape::Handle::TYPE::LINEEND line = @selected_handle.get_parent_shape line.send(:set_line_mode, LineShape::LINEMODE::TRGCHANGE) line.send(:set_unfinished_point, lpos) end end @selected_handle.send(:_on_begin_drag, fit_position_to_grid(lpos)) end when MODE::CREATECONNECTION # update the line shape being created if @new_line_shape shape_under = get_shape_under_cursor # propagate request for interactive connection if requested while shape_under && shape_under.has_style?(Shape::STYLE::PROPAGATE_INTERACTIVE_CONNECTION) shape_under = shape_under.get_parent_shape end # finish connection's creation process if possible if shape_under && !event.control_down if @new_line_shape.get_trg_shape.nil? && (shape_under != @new_line_shape) && (shape_under.is_connection_accepted(@new_line_shape.class)) # find out whether the target shape can be connected to the source shape source_shape = @new_line_shape.get_src_shape if source_shape && shape_under.is_src_neighbour_accepted(source_shape.class) && source_shape.is_trg_neighbour_accepted(shape_under.class) @new_line_shape.set_trg_shape(shape_under) @new_line_shape.set_ending_connection_point(shape_under.get_nearest_connection_point(lpos.to_real)) # inform user that the line is completed case on_pre_connection_finished(@new_line_shape) when PRECON_FINISH_STATE::OK when PRECON_FINISH_STATE::FAILED_AND_CANCEL_LINE @new_line_shape.set_trg_shape(nil) @diagram.remove_shape(@new_line_shape) @working_mode = MODE::READY @new_line_shape = nil return when PRECON_FINISH_STATE::FAILED_AND_CONTINUE_EDIT @new_line_shape.set_trg_shape(nil) return end @new_line_shape.create_handles # switch off the "under-construction" mode @new_line_shape.send(:set_line_mode, LineShape::LINEMODE::READY) on_connection_finished(@new_line_shape) @new_line_shape.update @new_line_shape.refresh(DELAYED) @working_mode = MODE::READY @new_line_shape = nil save_canvas_state end end else if @new_line_shape.get_src_shape fit_pos = fit_position_to_grid(lpos) @new_line_shape.get_control_points << Wx::RealPoint.new(fit_pos.x, fit_pos.y) end end end else @working_mode = MODE::READY end refresh_invalidated_rect end |
#on_left_up(event) ⇒ Object
Event handler called when the left mouse button is released. The function can be overridden if necessary.
The function is called by the framework and provides basic functionality needed for proper management of displayed shape. It is necessary to call this function from overridden methods if the default canvas behaviour should be preserved.
2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 |
# File 'lib/wx/shapes/shape_canvas.rb', line 2729 def on_left_up(event) # HINT: override it for custom actions... lpos = dp2lp(event.get_position) case @working_mode when MODE::MULTIHANDLEMOVE, MODE::HANDLEMOVE # resize parent shape to fit all its children if necessary if @selected_handle.get_parent_shape.get_parent_shape @selected_handle.get_parent_shape.get_parent_shape.update end # if the handle is line handle then return the line to normal state # and re-assign line's source/target shape case @selected_handle.get_type when Shape::Handle::TYPE::LINESTART, Shape::Handle::TYPE::LINEEND line = @selected_handle.get_parent_shape line.send(:set_line_mode, LineShape::LINEMODE::READY) parent_shape = get_shape_under_cursor # propagate request for interactive connection if requested while parent_shape && parent_shape.has_style?(Shape::STYLE::PROPAGATE_INTERACTIVE_CONNECTION) parent_shape = parent_shape.get_parent_shape end if parent_shape && (parent_shape != line) && (parent_shape.is_connection_accepted(line.class)) if @selected_handle.get_type == Shape::Handle::TYPE::LINESTART trg_shape = line.get_trg_shape if trg_shape && parent_shape.is_trg_neighbour_accepted(trg_shape.class) line.set_src_shape(parent_shape) end else src_shape = line.get_src_shape if src_shape && parent_shape.is_src_neighbour_accepted(src_shape.class) line.set_trg_shape(parent_shape) end end end end @selected_handle.send(:_on_end_drag, lpos) @selected_handle = nil save_canvas_state if @can_save_state_on_mouse_up when MODE::SHAPEMOVE lst_selection = get_selected_shapes lst_selection.each do |shape| # notify shape shape.send(:_on_end_drag, lpos) # reparent based on new position reparent_dropped_shape(shape, lpos) end if lst_selection.size>1 @shp_multi_edit.show(true) @shp_multi_edit.show_handles(true) else @shp_multi_edit.show(false) end move_shapes_from_negatives save_canvas_state if @can_save_state_on_mouse_up when MODE::MULTISELECTION lst_selection = get_selected_shapes sel_rect = @shp_selection.get_bounding_box @current_shapes.each do |shape| if shape.active? && sel_rect.contains?(shape.get_bounding_box) shape = shape.get_parent_shape while shape && shape.has_style?(Shape::STYLE::PROPAGATE_SELECTION) if shape shape.select(@selection_mode != SELECTIONMODE::REMOVE) shape_pos = lst_selection.index(shape) if @selection_mode != SELECTIONMODE::REMOVE && shape_pos.nil? lst_selection << shape elsif @selection_mode == SELECTIONMODE::REMOVE && shape_pos lst_selection.delete_at(shape_pos) end end end end validate_selection(lst_selection) if lst_selection.empty? @shp_multi_edit.show(false) else hide_all_handles @shp_multi_edit.show(true) @shp_multi_edit.show_handles(true) end @shp_selection.show(false) end if @working_mode != MODE::CREATECONNECTION # update canvas @working_mode = MODE::READY update_multiedit_size update_virtual_size refresh(false) else refresh_invalidated_rect end end |
#on_mouse_move(event) ⇒ Object
Event handler called when the mouse pointer is moved. The function can be overridden if necessary.
The function is called by the framework and provides basic functionality needed for proper management of displayed shape. It is necessary to call this function from overridden methods if the default canvas behaviour should be preserved.
2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 |
# File 'lib/wx/shapes/shape_canvas.rb', line 2917 def on_mouse_move(event) # HINT: override it for custom actions... return unless @diagram lpos = dp2lp(event.get_position) case @working_mode when MODE::READY, MODE::CREATECONNECTION unless event.dragging # send event to multiedit shape @shp_multi_edit.send(:_on_mouse_move, lpos) if @shp_multi_edit.visible? # send event to all user shapes @current_shapes.each { |shape| shape.send(:_on_mouse_move, lpos) } # update unfinished line if any if @new_line_shape line_rct = @new_line_shape.get_complete_bounding_box(nil, Shape::BBMODE::SELF | Shape::BBMODE::CHILDREN) @new_line_shape.send(:set_unfinished_point, fit_position_to_grid(lpos)) @new_line_shape.update line_rct = @new_line_shape.get_complete_bounding_box(line_rct, Shape::BBMODE::SELF | Shape::BBMODE::CHILDREN) invalidate_rect(line_rct) end end when MODE::HANDLEMOVE, MODE::MULTIHANDLEMOVE, MODE::SHAPEMOVE if @working_mode != MODE::SHAPEMOVE if event.dragging @selected_handle.send(:_on_dragging, fit_position_to_grid(lpos)) if @selected_handle update_multiedit_size if @working_mode == MODE::MULTIHANDLEMOVE @can_save_state_on_mouse_up = true else @selected_handle.send(:_on_end_drag, lpos) if @selected_handle @selected_handle = nil @working_mode = MODE::READY end end unless @working_mode == MODE::MULTIHANDLEMOVE if event.dragging if has_style?(STYLE::GRID_USE) return if (event.get_position.x - @prev_mouse_pos.x).abs < @settings.grid_size && (event.get_position.y - @prev_mouse_pos.y).abs < @settings.grid_size end @prev_mouse_pos = event.get_position if event.control_down || event.shift_down lst_selection = get_selected_shapes deselect_all if Wx.has_feature?(:USE_DRAG_AND_DROP) do_drag_drop(lst_selection, lpos) end else lst_connections = [] @current_shapes.each do |shape| if shape.selected? && @working_mode == MODE::SHAPEMOVE shape.send(:_on_dragging, fit_position_to_grid(lpos)) # move also connections assigned to this shape and its children lst_connections.clear append_assigned_connections(shape, lst_connections) lst_connections.each { |line| line.send(:_on_dragging, fit_position_to_grid(lpos)) } # update connections assigned to this shape lst_connections = @diagram.get_assigned_connections(shape, LineShape, Shape::CONNECTMODE::BOTH) lst_connections.each { |line| line.update } else shape.send(:_on_mouse_move, lpos) end end @can_save_state_on_mouse_up = true end else @working_mode = MODE::READY end end when MODE::MULTISELECTION selection_pos = Wx::RealPoint.new(*@selection_start.to_ary) selection_size = Wx::RealPoint.new(lpos.x - @selection_start.x, lpos.y - @selection_start.y) if selection_size.x < 0 selection_pos.x += selection_size.x selection_size.x = -selection_size.x end if selection_size.y < 0 selection_pos.y += selection_size.y selection_size.y = -selection_size.y end @shp_selection.set_relative_position(selection_pos) @shp_selection.set_rect_size(selection_size) invalidate_visible_rect end refresh_invalidated_rect end |
#on_mouse_wheel(event) ⇒ Object
Event handler called when the mouse wheel position is changed. The function can be overridden if necessary.
The function is called by the framework and provides basic functionality needed for proper management of displayed shape. It is necessary to call this function from overridden methods if the default canvas behaviour should be preserved.
3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 |
# File 'lib/wx/shapes/shape_canvas.rb', line 3027 def on_mouse_wheel(event) # HINT: override it for custom actions... if event.control_down scale = get_scale scale += event.get_wheel_rotation.to_f/(event.get_wheel_delta*10) scale = @settings.min_scale if scale < @settings.min_scale scale = @settings.max_scale if scale > @settings.max_scale set_scale(scale) refresh(false) end event.skip end |
#on_paste(pasted) ⇒ Object
Event handler called by the framework after pasting of shapes from the clipboard to the canvas. The default implementation generates Wx::SF::EVT_SF_ON_PASTE event.
3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 |
# File 'lib/wx/shapes/shape_canvas.rb', line 3224 def on_paste(pasted) # HINT: override it for custom actions... # ... standard implementation generates the Wx::SF::EVT_SF_ON_PASTE event. return unless has_style?(STYLE::CLIPBOARD) # create the drop event and process it event = ShapePasteEvent.new(Wx::SF::EVT_SF_ON_PASTE, self, Wx::ID_ANY) event.set_pasted_shapes(pasted) process_event(event) end |
#on_pre_connection_finished(connection) ⇒ PRECON_FINISH_STATE
Event handler called after successful connection creation in order to allow developer to perform some kind of checks before the connection is really added to the diagram. The function can be overridden if necessary. The default implementation generates Wx::SF::EVT_SF_LINE_DONE event. if the generated event has been vetoed the connection creation is cancelled
3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 |
# File 'lib/wx/shapes/shape_canvas.rb', line 3178 def on_pre_connection_finished(connection) # HINT: override to perform user-defined actions... # ... standard implementation generates the Wx::SF::EVT_SF_LINE_DONE event. id = connection ? connection.object_id : -1 event = ShapeEvent.new(Wx::SF::EVT_SF_LINE_BEFORE_DONE, id) event.set_shape(connection) process_event(event) return PRECON_FINISH_STATE::FAILED_AND_CANCEL_LINE if event.vetoed? PRECON_FINISH_STATE::OK end |
#on_right_double_click(event) ⇒ Object
Event handler called when the canvas is double-clicked by the right mouse button. The function can be overridden if necessary.
The function is called by the framework and provides basic functionality needed for proper management of displayed shape. It is necessary to call this function from overridden methods if the default canvas behaviour should be preserved.
2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 |
# File 'lib/wx/shapes/shape_canvas.rb', line 2879 def on_right_double_click(event) # HINT: override it for custom actions... _notify_canvas_change(CHANGE::FOCUS) set_focus lpos = dp2lp(event.get_position) if @working_mode == MODE::READY shape = get_shape_under_cursor shape.on_right_double_click(lpos) if shape end refresh_invalidated_rect end |
#on_right_down(event) ⇒ Object
Event handler called when the canvas is clicked by the right mouse button. The function can be overridden if necessary.
The function is called by the framework and provides basic functionality needed for proper management of displayed shape. It is necessary to call this function from overridden methods if the default canvas behaviour should be preserved.
2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 |
# File 'lib/wx/shapes/shape_canvas.rb', line 2846 def on_right_down(event) # HINT: override it for custom actions... _notify_canvas_change(CHANGE::FOCUS) set_focus lpos = dp2lp(event.get_position) if @working_mode == MODE::READY deselect_all shape = get_shape_under_cursor while shape && shape.has_style?(Shape::STYLE::PROPAGATE_SELECTION) shape = shape.get_parent_shape end if shape shape.select(true) shape.on_right_click(lpos) end end refresh(false) end |
#on_right_up(_event) ⇒ Object
Event handler called when the right mouse button is released. The function can be overridden if necessary.
The function is called by the framework and provides basic functionality needed for proper management of displayed shape. It is necessary to call this function from overridden methods if the default canvas behaviour should be preserved.
2904 2905 2906 |
# File 'lib/wx/shapes/shape_canvas.rb', line 2904 def on_right_up(_event) # HINT: override it for custom actions... end |
#on_text_change(shape) ⇒ Object
Event handler called when any editable text shape is changed. The function can be overridden if necessary. The function is called by the framework and its default implementation generates Wx::SF::EVT_SF_TEXT_CHANGE event.
3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 |
# File 'lib/wx/shapes/shape_canvas.rb', line 3139 def on_text_change(shape) # HINT: override it for custom actions... # ... standard implementation generates the Wx::SF::EVT_SF_TEXT_CHANGE event. id = shape ? shape.object_id : nil event = ShapeTextEvent.new(Wx::SF::EVT_SF_TEXT_CHANGE, id) event.set_shape(shape) event.set_text(shape.get_text) process_event(event) end |
#on_update_virtual_size(_virtrct) ⇒ Object
Event handler called if canvas virtual size is going to be updated. The default implementation does nothing but the function can be overridden by a user to modify calculated virtual canvas size.
3240 3241 3242 |
# File 'lib/wx/shapes/shape_canvas.rb', line 3240 def on_update_virtual_size(_virtrct) # HINT: override it for custom actions... end |
#page_setup ⇒ Object
Show page setup dialog for printing.
1313 1314 1315 1316 1317 1318 1319 1320 1321 |
# File 'lib/wx/shapes/shape_canvas.rb', line 1313 def page_setup ShapeCanvas.page_setup_data.set_print_data(ShapeCanvas.print_data) Wx::PRT::PageSetupDialog(self, ShapeCanvas.page_setup_data) do |dlg| dlg.show_modal ShapeCanvas.print_data = dlg.get_page_setup_data.get_print_data ShapeCanvas.page_setup_data = dlg.get_page_setup_data end end |
#paste ⇒ Object
Paste shapes stored in the clipboard to the canvas
1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 |
# File 'lib/wx/shapes/shape_canvas.rb', line 1109 def paste return unless has_style?(STYLE::CLIPBOARD) return unless @diagram Wx::Clipboard.open do |clipboard| # read data object from the clipboard data_obj = Wx::SF::ShapeDataObject.new if clipboard.fetch(data_obj) new_shapes = data_obj.get_as_shapes # add new shapes to diagram and remove those that are not accepted new_shapes.select! do |shape| ERRCODE::OK == @diagram.add_shape(shape, nil, shape.get_relative_position, INITIALIZE, DONT_SAVE_STATE) end # verify newly added shapes (may remove shapes from list) @diagram.send(:on_import, new_shapes) update_virtual_size # update for new shapes # call user-defined handler on_paste(new_shapes) save_canvas_state refresh(false) end end end |
#print(prompt = PROMPT) ⇒ Object #print(printout, prompt = PROMPT) ⇒ Object
Print current canvas content.
1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 |
# File 'lib/wx/shapes/shape_canvas.rb', line 1254 def print(*args) if args.first.is_a?(Wx::PRT::Printout) printout, prompt = args else printout = Printout.new('wxRuby SF Printout', self) prompt = args.shift end prompt = PROMPT if prompt.nil? print_dialog_data = Wx::PRT::PrintDialogData.new(ShapeCanvas.print_data) printer = Wx::PRT::Printer.new(print_dialog_data) deselect_all if !printer.print(self, printout, prompt) if Wx::PRT::Printer.get_last_error == Wx::PRT::PrinterError::PRINTER_ERROR Wx.("There was a problem printing.\nPerhaps your current printer is not set correctly?", 'wxRuby SF Printing', Wx::OK | Wx::ICON_ERROR) end else ShapeCanvas.print_data = printer.get_print_dialog_data.get_print_data end end |
#print_preview ⇒ Object #print_preview(preview, printout = nil) ⇒ Object
Show print preview.
1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 |
# File 'lib/wx/shapes/shape_canvas.rb', line 1286 def print_preview(*args) if args.empty? preview = Printout.new('wxRuby SF Preview', self) printout = Printout.new('wxRuby SF Printout', self) else preview, printout = args end deselect_all # Pass two printout objects: for preview, and possible printing. print_dialog_data = Wx::PRT::PrintDialogData.new(ShapeCanvas.print_data) prn_preview = Wx::PRT::PrintPreview.new(preview, printout, print_dialog_data) unless prn_preview.ok? Wx.("There was a problem previewing.\nPerhaps your current printer is not set correctly?", 'wxRuby SF Previewing', Wx::OK | Wx::ICON_ERROR) return end frame = Wx::PRT::PreviewFrame.new(prn_preview, self, 'wxRuby SF Print Preview', [100, 100], [800, 700]) frame.centre(Wx::BOTH) frame.init frame.show end |
#redo ⇒ Object
Perform Redo operation (if available)
1149 1150 1151 1152 1153 1154 1155 1156 |
# File 'lib/wx/shapes/shape_canvas.rb', line 1149 def redo return unless has_style?(STYLE::UNDOREDO) clear_temporaries restore_canvas_state(@canvas_history.restore_newer_state) @shp_multi_edit.show(false) end |
#refresh_canvas(erase, rct) ⇒ Object
Repaint the shape canvas.
940 941 942 943 944 945 946 947 948 949 950 951 |
# File 'lib/wx/shapes/shape_canvas.rb', line 940 def refresh_canvas(erase, rct) lpos = dp2lp(Wx::Point.new(0, 0)) upd_rct = rct.inflate((20/@settings.scale).to_i, (20/@settings.scale).to_i) upd_rct.offset!(-lpos.x, -lpos.y) refresh_rect(Wx::Rect.new((upd_rct.x*@settings.scale).to_i, (upd_rct.y*@settings.scale).to_i, (upd_rct.width*@settings.scale).to_i, (upd_rct.height*@settings.scale).to_i), erase) end |
#refresh_invalidated_rect ⇒ Object
Refresh all canvas rectangles marked as invalidated.
971 972 973 974 975 976 |
# File 'lib/wx/shapes/shape_canvas.rb', line 971 def refresh_invalidated_rect unless @invalidate_rect.nil? || @invalidate_rect.empty? refresh_canvas(false, @invalidate_rect) @invalidate_rect = nil end end |
#remove_style(style) ⇒ Object
Remove given style flag.
1632 1633 1634 |
# File 'lib/wx/shapes/shape_canvas.rb', line 1632 def remove_style(style) @settings.style &= ~style end |
#restore_canvas_state(state) ⇒ Object (protected)
Restores given canvas state (unless nil given)
1225 1226 1227 1228 1229 1230 1231 |
# File 'lib/wx/shapes/shape_canvas.rb', line 1225 def restore_canvas_state(state) return unless state set_diagram(FIRM.deserialize(state)) update_virtual_size @diagram.set_modified refresh(false) end |
#restore_current_state ⇒ Object (protected)
Restores current last saved canvas state.
1235 1236 1237 1238 1239 1240 1241 1242 |
# File 'lib/wx/shapes/shape_canvas.rb', line 1235 def restore_current_state return unless has_style?(STYLE::UNDOREDO) clear_temporaries restore_canvas_state(@canvas_history.current_state) @shp_multi_edit.show(false) end |
#save_canvas(file, compact: true) ⇒ self #save_canvas(io, compact: true) ⇒ self
Save canvas content (diagrams).
648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 |
# File 'lib/wx/shapes/shape_canvas.rb', line 648 def save_canvas(io, compact: true, format: nil) return self unless @diagram # get IO stream to write to ios = if io.is_a?(::String) format ||= case File.extname(io) when '.json' then :json when '.yaml', '.yml' then :yaml when '.xml' then :xml else :json end Tempfile.new(File.basename(io, '.*')) else format ||= :json io end # write canvas data to temp file begin [Version.new, @settings, @diagram].serialize(ios, pretty: !compact, format: format) rescue SFException ::Kernel.raise rescue Exception ::Kernel.raise SFException, "Error writing canvas: #{$!.}" end if io.is_a?(::String) ios.close(false) # close but keep temp file full_path = File.absolute_path(io) if File.exist?(full_path) # create temporary backup ftmp = Tempfile.new(File.basename(io)) ftmp_name = ftmp.path.dup ftmp.close(true) # close AND unlink FileUtils::mv(full_path, ftmp_name) # backup existing file # replace original begin # rename newly generated file FileUtils.mv(ios.path, full_path) # preserve file mode FileUtils.chmod(File.lstat(ftmp_name).mode, full_path) rescue Exception # restore backup FileUtils.mv(ftmp_name, full_path) ::Kernel.raise SFException, "Unable to save canvas file #{io}: #{$!.}" end # remove backup FileUtils.rm_f(ftmp_name) else begin # rename newly generated file FileUtils.mv(ios.path, full_path) rescue Exception ::Kernel.raise SFException, "Unable to save canvas file #{io}: #{$!.}" end end end @diagram.set_modified(false) self end |
#save_canvas_state ⇒ Object
Save current canvas state (for Undo/Redo operations)
1212 1213 1214 1215 1216 |
# File 'lib/wx/shapes/shape_canvas.rb', line 1212 def save_canvas_state return unless has_style?(STYLE::UNDOREDO) @canvas_history.save_canvas_state(@diagram.serialize) end |
#save_canvas_to_image(type: Wx::BITMAP_TYPE_BMP, background: true, scale: -1.0) ⇒ Wx::Bitmap? #save_canvas_to_image(file, type: Wx::BITMAP_TYPE_BMP, background: true, scale: -1.0) ⇒ Boolean
722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 |
# File 'lib/wx/shapes/shape_canvas.rb', line 722 def save_canvas_to_image(file = nil, type: Wx::BITMAP_TYPE_BMP, background: true, scale: -1.0) # create memory DC a draw the canvas content into prev_scale = get_scale scale = prev_scale if scale == -1 bmp_bb = get_total_bounding_box bmp_bb.left = (bmp_bb.left * scale).to_i bmp_bb.top = (bmp_bb.top * scale).to_i bmp_bb.width = (bmp_bb.width * scale).to_i bmp_bb.height = (bmp_bb.height * scale).to_i bmp_bb.inflate!(Wx::Size.new(@settings.grid_size, @settings.grid_size) * scale) outbmp = Wx::Bitmap.new(bmp_bb.width, bmp_bb.height) Wx::MemoryDC.draw_on(outbmp) do |mdc| Wx::ScaledDC.draw_on(mdc, scale) do |outdc| if outdc.ok? set_scale(scale) if scale != prev_scale outdc.set_device_origin(-bmp_bb.left, -bmp_bb.top) prev_style = get_style prev_colour = get_canvas_colour unless background remove_style(STYLE::GRADIENT_BACKGROUND) remove_style(STYLE::GRID_SHOW) set_canvas_colour(Wx::WHITE) end draw_background(outdc, NOT_FROM_PAINT) draw_content(outdc, NOT_FROM_PAINT) draw_foreground( outdc, NOT_FROM_PAINT) unless background set_style(prev_style) set_canvas_colour(prev_colour) end set_scale(prev_scale) if scale != prev_scale if file return outbmp.save_file(file, type) else return outbmp end elsif file Wx.('Could not create output bitmap.', 'wxRuby ShapeFramework', Wx::OK | Wx::ICON_ERROR) end end end nil end |
#scroll_to_shape(shape) ⇒ Object
Scroll the shape canvas so the given shape will be located in its center.
1921 1922 1923 1924 1925 1926 1927 1928 1929 |
# File 'lib/wx/shapes/shape_canvas.rb', line 1921 def scroll_to_shape(shape) if shape ux, uy = get_scroll_pixels_per_unit sz_canvas = get_client_size pt_pos = shape.center scroll(((pt_pos.x * @settings.scale) - sz_canvas.x/2)/ux, ((pt_pos.y * @settings.scale) - sz_canvas.y/2)/uy) end end |
#select_all ⇒ Object
Select all shapes in the canvas
902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 |
# File 'lib/wx/shapes/shape_canvas.rb', line 902 def select_all return unless @diagram shapes = @diagram.get_all_shapes unless shapes.empty? shapes.each { |shape| shape.select(true) } validate_selection(get_selected_shapes) hide_all_handles update_multiedit_size @shp_multi_edit.show(true) @shp_multi_edit.show_handles(true) refresh(false) end end |
#set_arrow_fill(brush) ⇒ Object #set_arrow_fill(color, style = Wx::BrushStyle::BRUSHSTYLE_SOLID) ⇒ Object #set_arrow_fill(stipple_bitmap) ⇒ Object Also known as: arrow_fill=
Set default arrow fill brush.
2035 2036 2037 2038 2039 2040 2041 |
# File 'lib/wx/shapes/shape_canvas.rb', line 2035 def set_arrow_fill(*args) @settings.common_arrow_fill = if args.size == 1 && Wx::Brush === args.first args.first else Wx::Brush.new(*args) end end |
#set_border_pen(pen) ⇒ Object #set_border_pen(color, width = 1, style = Wx::PenStyle::PENSTYLE_SOLID) ⇒ Object Also known as: border_pen=
Set default border pen.
1988 1989 1990 1991 1992 1993 1994 |
# File 'lib/wx/shapes/shape_canvas.rb', line 1988 def set_border_pen(*args) @settings.common_border_pen = if args.size == 1 && Wx::Pen === args.first args.first else Wx::Pen.new(*args) end end |
#set_canvas_colour(col) ⇒ Object Also known as: set_canvas_color, canvas_colour=, canvas_color=
Set canvas background color.
1650 1651 1652 |
# File 'lib/wx/shapes/shape_canvas.rb', line 1650 def set_canvas_colour(col) @settings.background_color = col end |
#set_control_border(pen) ⇒ Object #set_control_border(color, width = 1, style = Wx::PenStyle::PENSTYLE_SOLID) ⇒ Object Also known as: control_border=
Set default control border.
2176 2177 2178 2179 2180 2181 2182 |
# File 'lib/wx/shapes/shape_canvas.rb', line 2176 def set_control_border(*args) @settings.common_control_border = if args.size == 1 && Wx::Pen === args.first args.first else Wx::Pen.new(*args) end end |
#set_control_fill(brush) ⇒ Object #set_control_fill(color, style = Wx::BrushStyle::BRUSHSTYLE_SOLID) ⇒ Object #set_control_fill(stipple_bitmap) ⇒ Object Also known as: control_fill=
Set default control fill brush.
2153 2154 2155 2156 2157 2158 2159 |
# File 'lib/wx/shapes/shape_canvas.rb', line 2153 def set_control_fill(*args) @settings.common_control_fill = if args.size == 1 && Wx::Brush === args.first args.first else Wx::Brush.new(*args) end end |
#set_control_mod_border(pen) ⇒ Object #set_control_mod_border(color, width = 1, style = Wx::PenStyle::PENSTYLE_SOLID) ⇒ Object Also known as: control_mod_border=
Set default control modification border.
2223 2224 2225 2226 2227 2228 2229 |
# File 'lib/wx/shapes/shape_canvas.rb', line 2223 def set_control_mod_border(*args) @settings.common_control_mod_border = if args.size == 1 && Wx::Pen === args.first args.first else Wx::Pen.new(*args) end end |
#set_control_mod_fill(brush) ⇒ Object #set_control_mod_fill(color, style = Wx::BrushStyle::BRUSHSTYLE_SOLID) ⇒ Object #set_control_mod_fill(stipple_bitmap) ⇒ Object Also known as: control_mod_fill=
Set default control modification fill brush.
2200 2201 2202 2203 2204 2205 2206 |
# File 'lib/wx/shapes/shape_canvas.rb', line 2200 def set_control_mod_fill(*args) @settings.common_control_mod_fill = if args.size == 1 && Wx::Brush === args.first args.first else Wx::Brush.new(*args) end end |
#set_diagram(diagram) ⇒ Object
Set the shape diagram to display on this canvas
563 564 565 566 567 568 569 570 |
# File 'lib/wx/shapes/shape_canvas.rb', line 563 def set_diagram(diagram) @diagram = diagram @shp_selection.set_diagram(@diagram) @shp_multi_edit.set_diagram(@diagram) @diagram.shape_canvas = self if @diagram clear_temporaries @diagram.update_all end |
#set_fill_brush(brush) ⇒ Object #set_fill_brush(color, style = Wx::BrushStyle::BRUSHSTYLE_SOLID) ⇒ Object #set_fill_brush(stipple_bitmap) ⇒ Object Also known as: fill_brush=
Set default fill brush.
1965 1966 1967 1968 1969 1970 1971 |
# File 'lib/wx/shapes/shape_canvas.rb', line 1965 def set_fill_brush(*args) @settings.common_fill_brush = if args.size == 1 && Wx::Brush === args.first args.first else Wx::Brush.new(*args) end end |
#set_gradient_from(col) ⇒ Object Also known as: gradient_from=
Set starting gradient color.
1668 1669 1670 |
# File 'lib/wx/shapes/shape_canvas.rb', line 1668 def set_gradient_from(col) @settings.gradient_from = col end |
#set_gradient_to(col) ⇒ Object Also known as: gradient_to=
Set ending gradient color.
1682 1683 1684 |
# File 'lib/wx/shapes/shape_canvas.rb', line 1682 def set_gradient_to(col) @settings.gradient_to = col end |
#set_grid_colour(col) ⇒ Object Also known as: set_grid_color, grid_colour=, grid_color=
Set grid color.
1728 1729 1730 |
# File 'lib/wx/shapes/shape_canvas.rb', line 1728 def set_grid_colour(col) @settings.grid_color = col end |
#set_grid_line_mult(multiple) ⇒ Object Also known as: grid_line_mult=
Set grid line multiple.
Grid lines will be drawn in a distance calculated as grid size multiplicated by this value. Default value is 1.
1714 1715 1716 |
# File 'lib/wx/shapes/shape_canvas.rb', line 1714 def set_grid_line_mult(multiple) @settings.grid_line_mult = multiple end |
#set_grid_size(sz) ⇒ Object Also known as: grid_size=
Set grid size (px).
1703 1704 1705 1706 |
# File 'lib/wx/shapes/shape_canvas.rb', line 1703 def set_grid_size(sz) raise ArgumentError, 'Grid size must be integer > 0' if sz.to_i <= 0 @settings.grid_size = sz.to_i end |
#set_grid_style(style) ⇒ Object Also known as: grid_style=
Set grid line style.
1746 1747 1748 |
# File 'lib/wx/shapes/shape_canvas.rb', line 1746 def set_grid_style(style) @settings.grid_style = style end |
#set_hover_colour(col) ⇒ Object Also known as: set_hover_color, hover_colour=, hover_color=
Set default hover color.
1941 1942 1943 |
# File 'lib/wx/shapes/shape_canvas.rb', line 1941 def set_hover_colour(col) @settings.common_hover_color = Wx::Colour === col ? col : Wx::Colour.new(col) end |
#set_line_pen(pen) ⇒ Object #set_line_pen(color, width = 1, style = Wx::PenStyle::PENSTYLE_SOLID) ⇒ Object Also known as: line_pen=
Set default line pen.
2011 2012 2013 2014 2015 2016 2017 |
# File 'lib/wx/shapes/shape_canvas.rb', line 2011 def set_line_pen(*args) @settings.common_line_pen = if args.size == 1 && Wx::Pen === args.first args.first else Wx::Pen.new(*args) end end |
#set_max_scale(scale) ⇒ Object Also known as: max_scale=
Set maximal allowed scale (for mouse wheel scale change).
1883 1884 1885 |
# File 'lib/wx/shapes/shape_canvas.rb', line 1883 def set_max_scale(scale) @settings.max_scale = scale end |
#set_min_scale(scale) ⇒ Object Also known as: min_scale=
Set minimal allowed scale (for mouse wheel scale change).
1869 1870 1871 |
# File 'lib/wx/shapes/shape_canvas.rb', line 1869 def set_min_scale(scale) @settings.min_scale = scale end |
#set_print_h_align(val) ⇒ Object Also known as: print_h_align=
Set horizontal align of printed drawing.
1799 1800 1801 |
# File 'lib/wx/shapes/shape_canvas.rb', line 1799 def set_print_h_align(val) @settings.print_h_align = val end |
#set_print_mode(mode) ⇒ Object Also known as: print_mode=
Set printing mode for this canvas.
1831 1832 1833 |
# File 'lib/wx/shapes/shape_canvas.rb', line 1831 def set_print_mode(mode) @settings.print_mode = mode end |
#set_print_v_align(val) ⇒ Object Also known as: print_v_align=
Set vertical align of printed drawing.
1815 1816 1817 |
# File 'lib/wx/shapes/shape_canvas.rb', line 1815 def set_print_v_align(val) @settings.print_v_align = val end |
#set_scale(scale) ⇒ Object Also known as: scale=
Set canvas scale.
1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 |
# File 'lib/wx/shapes/shape_canvas.rb', line 1846 def set_scale(scale) return unless @diagram if scale != 1.0 # query shapes msg = '' unless _query_canvas_change(CHANGE::SET_SCALE, msg) Wx.("Cannot change scale of shape canvas: #{msg}.", 'wxRuby ShapeFramework', Wx::ICON_WARNING | Wx::OK) scale = 1.0 end end @settings.scale = scale != 0.0 ? scale : 1.0 # inform shapes _notify_canvas_change(CHANGE::RESCALED) update_virtual_size end |
#set_scale_to_view_all ⇒ Object
Set the canvas scale so a whole diagram is visible.
1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 |
# File 'lib/wx/shapes/shape_canvas.rb', line 1905 def set_scale_to_view_all phys_rct = get_client_size virt_rct = get_total_bounding_box hz = phys_rct.width.to_f / virt_rct.right vz = phys_rct.height.to_f / virt_rct.bottom if hz < vz set_scale(hz < 1 ? hz : 1.0) else set_scale(vz < 1 ? vz : 1.0) end end |
#set_shadow_fill(brush) ⇒ Object #set_shadow_fill(color, style = Wx::BrushStyle::BRUSHSTYLE_SOLID) ⇒ Object #set_shadow_fill(stipple_bitmap) ⇒ Object Also known as: shadow_fill=
Set shadow fill (used for shadows of non-text shapes only).
1780 1781 1782 1783 1784 1785 1786 |
# File 'lib/wx/shapes/shape_canvas.rb', line 1780 def set_shadow_fill(*args) @settings.shadow_fill = if args.size == 1 && Wx::Brush === args.first args.first else Wx::Brush.new(*args) end end |
#set_shadow_offset(offset) ⇒ Object Also known as: shadow_offset=
Set shadow offset.
1760 1761 1762 |
# File 'lib/wx/shapes/shape_canvas.rb', line 1760 def set_shadow_offset(offset) @settings.shadow_offset = offset.to_real_point end |
#set_style(style) ⇒ Object Also known as: style=
Set canvas style.
Default value is STYLE::MULTI_SELECTION | STYLE::MULTI_SIZE_CHANGE | STYLE::DND | STYLE::UNDOREDO | STYLE::CLIPBOARD | STYLE::HOVERING | STYLE::HIGHLIGHTING
1613 1614 1615 |
# File 'lib/wx/shapes/shape_canvas.rb', line 1613 def set_style(style) @settings.style = style end |
#set_text_border(pen) ⇒ Object #set_text_border(color, width = 1, style = Wx::PenStyle::PENSTYLE_SOLID) ⇒ Object Also known as: text_border=
Set default text border.
2100 2101 2102 2103 2104 2105 2106 |
# File 'lib/wx/shapes/shape_canvas.rb', line 2100 def set_text_border(*args) @settings.common_text_border = if args.size == 1 && Wx::Pen === args.first args.first else Wx::Pen.new(*args) end end |
#set_text_colour(col) ⇒ Object Also known as: set_text_color=, text_colour=, text_color=
Set default text color.
2053 2054 2055 |
# File 'lib/wx/shapes/shape_canvas.rb', line 2053 def set_text_colour(col) @settings.common_text_color = Wx::Colour === col ? col : Wx::Colour.new(col) end |
#set_text_fill(brush) ⇒ Object #set_text_fill(color, style = Wx::BrushStyle::BRUSHSTYLE_SOLID) ⇒ Object #set_text_fill(stipple_bitmap) ⇒ Object Also known as: text_fill=
Set default text fill brush.
2077 2078 2079 2080 2081 2082 2083 |
# File 'lib/wx/shapes/shape_canvas.rb', line 2077 def set_text_fill(*args) @settings.common_text_fill = if args.size == 1 && Wx::Brush === args.first args.first else Wx::Brush.new(*args) end 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: text_font=
Set default text font.
2129 2130 2131 2132 2133 2134 2135 |
# File 'lib/wx/shapes/shape_canvas.rb', line 2129 def set_text_font(*args) @settings.common_text_font = if args.size == 1 && Wx::Font === args.first args.first else Wx::Font.new(*args) end end |
#show_shadows(show, style) ⇒ Object
Show shapes shadows (only current diagram shapes are affected).
The functions sets/unsets SHOW_SHADOW flag for all shapes currently included in the diagram.
984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 |
# File 'lib/wx/shapes/shape_canvas.rb', line 984 def show_shadows(show, style) return unless @diagram shapes = @diagram.get_all_shapes shapes.each do |shape| shape.remove_style(Shape::STYLE::SHOW_SHADOW) if show case style when SHADOWMODE::TOPMOST unless shape.get_parent_shape if show shape.add_style(Shape::STYLE::SHOW_SHADOW) else shape.remove_style(Shape::STYLE::SHOW_SHADOW) end end when SHADOWMODE::ALL if show shape.add_style(Shape::STYLE::SHOW_SHADOW) else shape.remove_style(Shape::STYLE::SHOW_SHADOW) end end end end |
#start_interactive_connection(shape_info, pos) ⇒ Wx::SF::ERRCODE #start_interactive_connection(shape, pos) ⇒ Wx::SF::ERRCODE #start_interactive_connection(shape, connection_point, pos) ⇒ Wx::SF::ERRCODE
Start interactive connection creation.
This function switches the canvas to a mode in which a new shape connection can be created interactively (by mouse operations). Every connection must start and finish in some shape object or another connection. At the end of the process the on_connection_finished event handler is invoked so the user can set needed connection properties immediately.
Function must be called from mouse event handler and the event must be passed to the function.
823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 |
# File 'lib/wx/shapes/shape_canvas.rb', line 823 def start_interactive_connection(*args) return ERRCODE::INVALID_INPUT unless @diagram shape_info = shape = pos = connection_point = nil shape_klass = nil case args.first when Wx::SF::LineShape shape = args.shift shape_klass = shape.class if args.first.is_a?(Wx::SF::ConnectionPoint) connection_point = args.shift end pos = args.shift.to_point when ::Class shape_info = args.shift pos = args.shift.to_point shape_klass = shape_info end ::Kernel.raise ArgumentError, "Invalid arguments #{args}" unless args.empty? return ERRCODE::INVALID_INPUT unless pos lpos = dp2lp(pos) if @working_mode == MODE::READY && ((shape_info && shape_info <= Wx::SF::LineShape) || (shape.is_a?(Wx::SF::LineShape))) if connection_point if @diagram.contains?(shape) @new_line_shape = shape else @new_line_shape = @diagram.add_shape(shape, nil, Wx::DEFAULT_POSITION, INITIALIZE, DONT_SAVE_STATE) end return _start_interactive_connection(lpos, connection_point.get_parent_shape, connection_point) else shape_under = get_shape_at_position(lpos) if shape_info # propagate request for interactive connection if requested shape_under = shape_under.get_parent_shape while shape_under && shape_under.has_style?(Shape::STYLE::PROPAGATE_INTERACTIVE_CONNECTION) end # start the connection's creation process if possible if shape_under && shape_under.is_connection_accepted(shape_klass) if shape && @diagram.contains?(shape) @new_line_shape = shape else if shape err = @diagram.add_shape(shape, nil, Wx::DEFAULT_POSITION, INITIALIZE, DONT_SAVE_STATE) else err, shape = @diagram.create_shape(shape_info, DONT_SAVE_STATE) end @new_line_shape = (err == ERRCODE::OK ? shape : nil) end return _start_interactive_connection(lpos, shape_under, shape_under.get_nearest_connection_point(lpos.to_real)) else return ERRCODE::NOT_ACCEPTED end end end ERRCODE::INVALID_INPUT end |
#undo ⇒ Object
Perform Undo operation (if available)
1139 1140 1141 1142 1143 1144 1145 1146 |
# File 'lib/wx/shapes/shape_canvas.rb', line 1139 def undo return unless has_style?(STYLE::UNDOREDO) clear_temporaries restore_canvas_state(@canvas_history.restore_older_state) @shp_multi_edit.show(false) end |
#update_multiedit_size ⇒ Object
Update size of multi selection rectangle
2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 |
# File 'lib/wx/shapes/shape_canvas.rb', line 2261 def update_multiedit_size # calculate bounding box union_rct = nil get_selected_shapes.each_with_index do |shape, ix| if ix == 0 union_rct = shape.get_bounding_box else union_rct.union!(shape.get_bounding_box) end end union_rct ||= Wx::Rect.new union_rct.inflate!([DEFAULT_ME_OFFSET, DEFAULT_ME_OFFSET]) # draw rectangle @shp_multi_edit.set_relative_position(Wx::RealPoint.new(union_rct.x.to_f, union_rct.y.to_f)) @shp_multi_edit.set_rect_size(Wx::RealPoint.new(union_rct.width.to_f, union_rct.height.to_f)) end |
#update_shape_under_cursor_cache(lpos) ⇒ Object
Search for any shape located at the (mouse cursor) position (result used by #get_shape_under_cursor)
1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 |
# File 'lib/wx/shapes/shape_canvas.rb', line 1369 def update_shape_under_cursor_cache(lpos) sel_shape = unsel_shape = top_shape = nil sel_line = unsel_line = top_line = nil lpos = lpos.to_point @topmost_shape_under_cursor = nil @current_shapes.replace(@diagram.get_all_shapes) if @diagram @current_shapes.reverse_each do |shape| if shape.visible? && shape.active? && shape.contains?(lpos) if shape.is_a?(Wx::SF::LineShape) top_line ||= shape if shape.selected? sel_line ||= shape else unsel_line ||= shape end else top_shape ||= shape if shape.selected? sel_shape ||= shape elsif !shape.has_selected_parent? unsel_shape ||= shape end end end end # set reference to logically topmost selected and unselected shape under the mouse cursor @topmost_shape_under_cursor = top_line ? top_line : top_shape @selected_shape_under_cursor = sel_line ? sel_line : sel_shape @unselected_shape_under_cursor = unsel_line ? unsel_line : unsel_shape end |
#update_virtual_size ⇒ Object
Update scroll window virtual size so it can display all shape canvas
2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 |
# File 'lib/wx/shapes/shape_canvas.rb', line 2280 def update_virtual_size virt_rct = get_total_bounding_box # allow user to modify calculated virtual canvas size on_update_virtual_size(virt_rct) # update virtual area of the scrolled window if necessary if virt_rct.empty? set_virtual_size(500, 500) else set_virtual_size((virt_rct.right*@settings.scale).to_i, (virt_rct.bottom*@settings.scale).to_i) end _notify_canvas_change(CHANGE::VIRTUAL_SIZE) end |
#validate_selection(selection) ⇒ Object
Validate selection (remove redundantly selected shapes etc…).
2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 |
# File 'lib/wx/shapes/shape_canvas.rb', line 2318 def validate_selection(selection) return unless @diagram # find child shapes that have parents in the list and deselect and remove those # so we only have regular toplevel shapes and orphaned child shapes selection.select! do |shape| if selection.include?(shape.get_parent_shape) shape.select(false) false else true end end # move selected (toplevel) shapes to the back of the shapes list in the diagram # this gives a higher Z-order so they will float on top of other shapes when dragging selection.each do |shape| # in case of child shapes find the toplevel parent it belongs to and move that one shape = shape.get_parent_shape while shape.get_parent_shape @diagram.move_to_end(shape) end end |