Canvas Object

Synopsis

Class Name: Canvas
Valid Parents: Panel (Gsharp)
Valid Children: Popup
See Also:

displayoption and gridoption

Description

A scrolled drawing canvas for displaying graphics.

  • Only one instance of Canvas is allowed per application and it must belong to the main window (the panel).

Inherited Resources

New Resources

Name Type Default
XuNguiCallback string undef
XuNguiCallbackData string undef
  • XuNguiCallback specifies the name of the function to call whenever the user clicks or drags on the canvas or whenever a repaint occurs.
  • If XuNguiCallbackData is specified then the value is used as the second argument to the callback function.
  • For more details - see Callback Functions
Name Type Options
XuNguiObjectInteraction string "full", "none","moveAndResize" and "edit"
XuNguiSelectionModel string "stacked" or "topMost"
  • XuNguiObjectInteraction controls whether the graphic objects on the canvas can be moved, resized, probed, rotated and edited.
  • XuNguiSelectionModel specifies the model used for selecting graphic objects in the canvas.
    • "stacked" - Gsharp will click through overlapping objects, selecting each item in turn
    • "topMost" - it is only possible to select the object on top.
Name Type Default
XuNguiSelectedObject string undef
XuNguiSelection1 float[1,2] (0,0)
XuNguiSelection2 float[1,2] (0,0)
  • XuNguiSelectedObject contains the last object selected with the mouse. N.B. This could be different from the current_object().
  • XuNguiSelection1 contains the location of the most recent mouse-click or the starting point of the most recent mouse-drag. The position is given in percentages of the canvas width and height (including any margins).
  • XuNguiSelection2 contains the location of the end point of the most recent mouse-drag.
  • For more information on writing canvas callbacks, see Canvas Callbacks.
  • N.B. It is very easy to move the mouse during a single click. You may want to treat a very short mouse-drag as a mouse-click.

Callback Information

Reason Event
XuCR_POINT_SELECTED MB1 clicked on canvas
XuCR_DOUBLE_CLICK MB1 double clicked on canvas
XuCR_START_DRAG MB1 pressed and drag started
XuCR_RECTANGLE_DRAG MB1 drag in progress
XuCR_RECTANGLE_SELECTED MB1 drag complete
XuCR_PRE_RENDER Gsharp has completed the pre-render process
XuCR_RENDER Gsharp has completed the render
XuCR_POST_RENDER Gsharp has completed the post-render process
XuCR_RESIZE Canvas was resized

 

Example Code - canvas.gsa

function MyCanvasCB(string o, string d, float r)
  if (r=XuCR_POINT_SELECTED) then
    echo("Point Selected: ");
    echo($(o).XuNguiSelection1);
  endif
endfunction

  create Menubar gsharp_1.MenuBar;
  create Menu gsharp_1.MenuBar.FileMenu
   ( XuNguiLabel = "File"
   );
  create Button gsharp_1.MenuBar.FileMenu.Exit
   ( XuNguiCallback = "GuiFileExit",
     XuNguiLabel = "Exit ..."
   );

  create Canvas gsharp_1.scrolledcanvas
   ( XuNguiCallback = "MyCanvasCB"
   );
  create Command gsharp_1.command;

Return to Gsharp Applications Reference Manual