This package provides an interactive canvas, on which the user can put items, move them with the mouse, etc. The items can be connected together, and the connections remain active while the items are moved.
It also supports scrolling if put in a Gtk_Scrolled_Window.
All items put in this canvas must inherit from the type Canvas_Item_Record. However, it is your responsability, as a programmer, to provide drawing routines. In fact, all these items should draw in a pixmap, which is then copied automatically to the screen whenever the canvas needs to redraw itself.
The items can also react to mouse events: mouse clicks are transmitted to the item if the mouse did not move more than a given amount of pixels. To decide what their reaction should be, you should override the On_Button_Click subprogram.
This canvas is not intended for cases where you want to put hundreds of items on the screen. For instance, it does not provide any smart double-buffering, and thus you would get some flicker if there are too many items.
Signals |
---|
Types |
---|
type Arrow_Type is (No_Arrow, -- the link does not have an arrow Start_Arrow, -- the link has an arrow at its beginning End_Arrow, -- the link has an arrow at the end Both_Arrow -- the link has an arrow on both sides ); | |
Indicate whether the links have an arrow or not.
| |
type Item_Processor is access function (Canvas : access Interactive_Canvas_Record'Class; | |
| |
type Link_Processor is access function (Canvas : access Interactive_Canvas_Record'Class; | |
|
Subprograms |
---|
Creating a canvas | ||
procedure Gtk_New (Canvas : out Interactive_Canvas); | ||
Create a new empty Canvas. | ||
procedure Configure (Canvas : access Interactive_Canvas_Record; Grid_Size : Glib.Guint := Default_Grid_Size; Annotation_Font : String := Default_Annotation_Font; Annotation_Height : Glib.Gint := Default_Annotation_Height; Arc_Link_Offset : Glib.Gint := Default_Arc_Link_Offset; Arrow_Angle : Glib.Gint := Default_Arrow_Angle; Arrow_Length : Glib.Gint := Default_Arrow_Length; Motion_Threshold : Glib.Gint := Default_Motion_Threshold); | ||
Change the parameters for the canvas. | ||
procedure Align_On_Grid (Canvas : access Interactive_Canvas_Record; Align : Boolean := True); | ||
Choose whether the items should be aligned on the grid when moved. | ||
function Get_Align_On_Grid (Canvas : access Interactive_Canvas_Record) return Boolean; | ||
Return True if items are currently aligned on grid.
| ||
procedure Move_To (Canvas : access Interactive_Canvas_Record; Item : access Canvas_Item_Record'Class; X, Y : Glib.Gint := Glib.Gint'First); | ||
Move the item in the canvas. | ||
procedure Put (Canvas : access Interactive_Canvas_Record; Item : access Canvas_Item_Record'Class; X, Y : Glib.Gint := Glib.Gint'First); | ||
Add a new item to the canvas. | ||
procedure Remove (Canvas : access Interactive_Canvas_Record; Item : access Canvas_Item_Record'Class); | ||
Remove an item and all the links to and from it from the canvas. | ||
procedure Item_Updated (Canvas : access Interactive_Canvas_Record; Item : access Canvas_Item_Record'Class); | ||
This should be called when Item has changed the contents of its | ||
procedure Refresh_Canvas (Canvas : access Interactive_Canvas_Record); | ||
Redraw the whole canvas (both in the double buffer and on the screen).
| ||
procedure For_Each_Item (Canvas : access Interactive_Canvas_Record; Execute : Item_Processor); | ||
Execute an action on each of the items contained in the canvas. | ||
function Has_Link (Canvas : access Interactive_Canvas_Record; From, To : access Canvas_Item_Record'Class; Name : String := "") return Boolean; | ||
Test whether there is a link from From to To, with the same name. | ||
procedure Raise_Item (Canvas : access Interactive_Canvas_Record; Item : access Canvas_Item_Record'Class); | ||
Raise the item so that it is displayed on top of all the others | ||
procedure Lower_Item (Canvas : access Interactive_Canvas_Record; Item : access Canvas_Item_Record'Class); | ||
Lower the item so that it is displayed below all the others. | ||
function Is_On_Top (Canvas : access Interactive_Canvas_Record; Item : access Canvas_Item_Record'Class) return Boolean; | ||
Return True if Item is displayed on top of all the others in the canvas.
| ||
procedure Show_Item (Canvas : access Interactive_Canvas_Record; Item : access Canvas_Item_Record'Class); | ||
Scroll the canvas so that Item is visible.
| ||
procedure Zoom (Canvas : access Interactive_Canvas_Record; Percent : Glib.Guint := 100; Steps : Glib.Guint := 1); | ||
Zoom in or out in the canvas. All items are resized, and their contents Steps is the number of successive zooms that will be done to provide smooth scrolling.
Note that one possible use for this function is to refresh the canvas
and emit the "zoomed" signal, which might redraw all the items. This can
be accomplished by keeping the default 100 value for Percent.
| ||
function Get_Zoom (Canvas : access Interactive_Canvas_Record) return Glib.Guint; | ||
Return the current zoom level
| ||
function To_Canvas_Coordinates (Canvas : access Interactive_Canvas_Record'Class; X : Glib.Gint) return Glib.Gint; | ||
Scale the scalar X depending by the zoom level (map from world | ||
function To_World_Coordinates (Canvas : access Interactive_Canvas_Record'Class; X : Glib.Gint) return Glib.Gint; | ||
Scale the scalar X depending by the zoom level (map from canvas | ||
Links | ||
procedure Configure (Link : access Canvas_Link_Record; Src : access Canvas_Item_Record'Class; Dest : access Canvas_Item_Record'Class; Arrow : in Arrow_Type := End_Arrow; Descr : in String := ""); | ||
Configure a link. | ||
function Get_Src (Link : access Canvas_Link_Record) return Canvas_Item; | ||
Return the source item for the link
| ||
function Get_Dest (Link : access Canvas_Link_Record) return Canvas_Item; | ||
Return the destination item for the link
| ||
function Get_Descr (Link : access Canvas_Link_Record) return String; | ||
Return the description for the link, or "" if there is none
| ||
procedure Set_Src_Pos (Link : access Canvas_Link_Record; X_Pos, Y_Pos : Glib.Gfloat := 0.5); | ||
Set the position of the link's attachment in its source item. | ||
procedure Set_Dest_Pos (Link : access Canvas_Link_Record; X_Pos, Y_Pos : Glib.Gfloat := 0.5); | ||
Same as Set_Src_Pos for the destination item
| ||
procedure Add_Link (Canvas : access Interactive_Canvas_Record; Link : access Canvas_Link_Record'Class); | ||
Add a link to the canvas. The link must have been created first.
| ||
procedure Add_Link (Canvas : access Interactive_Canvas_Record; Src : access Canvas_Item_Record'Class; Dest : access Canvas_Item_Record'Class; Arrow : in Arrow_Type := End_Arrow; Descr : in String := ""); | ||
Create and add a link between two items. | ||
procedure Remove_Link (Canvas : access Interactive_Canvas_Record; Link : access Canvas_Link_Record'Class); | ||
Remove a link from the canvas. | ||
procedure For_Each_Link (Canvas : access Interactive_Canvas_Record; Execute : Link_Processor); | ||
Execute an action on each of the links contained in the canvas. | ||
procedure Destroy (Link : access Canvas_Link_Record); | ||
Method called every time a link is destroyed. You should override this | ||
Selection | ||
procedure Clear_Selection (Canvas : access Interactive_Canvas_Record); | ||
Clear the list of currently selected items.
| ||
procedure Add_To_Selection (Canvas : access Interactive_Canvas_Record; Item : access Canvas_Item_Record'Class); | ||
Add Item to the selection. This is only meaningful during a drag | ||
procedure Remove_From_Selection (Canvas : access Interactive_Canvas_Record; Item : access Canvas_Item_Record'Class); | ||
Remove Item from the selection.
| ||
Items manipulation | ||
procedure Set_Screen_Size (Item : access Canvas_Item_Record; Width : Glib.Gint; Height : Glib.Gint); | ||
Set the size that the items occupies on the screen. You must call this | ||
procedure Draw (Item : access Canvas_Item_Record; Canvas : access Interactive_Canvas_Record'Class; Dest : Gdk.Pixmap.Gdk_Pixmap; Xdest, Ydest : Glib.Gint); | ||
This subprogram, that must be overridden, should draw the item on | ||
procedure Destroy (Item : access Canvas_Item_Record); | ||
Free the memory occupied by the item (not the item itself). You should | ||
procedure On_Button_Click (Item : access Canvas_Item_Record; Event : Gdk.Event.Gdk_Event_Button); | ||
Function called whenever the item was clicked on. | ||
function Get_Coord (Item : access Canvas_Item_Record) return Gdk.Rectangle.Gdk_Rectangle; | ||
Return the coordinates and size of the item.
| ||
procedure Set_Visibility (Item : access Canvas_Item_Record; Visible : Boolean); | ||
Set the visibility status of the item. | ||
function Is_Visible (Item : access Canvas_Item_Record) return Boolean; | ||
Return True if the item is currently visible.
| ||
Buffered items | ||
procedure Draw (Item : access Buffered_Item_Record; Canvas : access Interactive_Canvas_Record'Class; Dest : Gdk.Pixmap.Gdk_Pixmap; Xdest, Ydest : Glib.Gint); | ||
Draw the item's double-buffer onto Dest.
| ||
procedure Destroy (Item : access Buffered_Item_Record); | ||
Free the double-buffer allocated for the item
| ||
procedure Set_Screen_Size_And_Pixmap (Item : access Buffered_Item_Record; Win : Gdk.Window.Gdk_Window; Width, Height : Glib.Gint); | ||
Sets the size used on the screen by item, and reallocate the pixmap | ||
function Pixmap (Item : access Buffered_Item_Record) return Gdk.Pixmap.Gdk_Pixmap; | ||
Return the double-buffer that must be updated every time the canvas |