Go up one levelGo to Previous Go to Next

CanvasDraw(n)

NAME

 
 CanvasDraw - Add interactive drawing capabilities to a Tk canvas.

NAMESPACE

 
 util

PARENT CLASS

 
 util::TopLevelWidget

SYNOPSIS

 
 CanvasDraw <path> ?options?

DESCRIPTION

 
 CanvasDraw is an [incrTcl] widget class that an application can use to
 add interactive drawing capabilities to any Tk canvas.  Since it is a
 subclass of TopLevelWidget, it creates its own toplevel window
 containing a drawing mode selection section and an option section for
 setting colors, fonts, line thickness, arrow types, etc. The window can
 be hidden on startup by specifying the "-withdraw 1" option inherited
 from TopLevelWidget.


ITK COMPONENTS

 
 bot
        Button frame at bottom of window.

 clear
        Clear button.

 close
        Close button.

 delete
        Delete button.

 drawmodes
        Frame containing drawing mode buttons.

 options
        Frame containing option menubuttons for graphic items.

 $drawing_mode
        Drawing mode buttons (anyselect, region, line, rectangle, oval,
        polyline, polygon, text).

 $menu
        LabelMenu(n) items for changing options on graphic objects.
        (Width Arrow ArrowShape Fill Outline Stipple Font Smooth).

WIDGET OPTIONS

 
 -arrowshape
        Default arrow shape for lines.

 -arrowtype
        Default arrow type for lines.

 -bbox
        Specify bounding box of interactive drawing area as a list {x0 y0
        x1 y1}.

 -canvas
        Canvas window.

 -clipping
        Flag: if true, keep graphics within the specified bounding box
        (-bbox option).

 -colors
        List of colors for menu.

 -defaultcursor
        Default cursor when not drawing.

 -drawcursor
        Cursor when drawing graphics.

 -fillcolor
        Default fill color for drawing.

 -fonts
        Default list of fonts for font menu.

 -gripfill
        Fill color of selection grips.

 -gripoutline
        Outline color of selection grips.

 -gripwidth
        Size of selection grips.

 -linecursor
        Cursor displayed over simple lines for resizing.

 -linestipple
        Default stipple for lines.

 -linewidth
        Default line width for drawing.

 -outlinecolor
        Default color for outlines.

 -regioncommand
        Tcl command to evaluate whenever a "region" object is created, if
        no specific "create" command was specified.

 -regioncursor
        Cursor when creating region items (dashed box marking a region).

 -show_object_menu
        Flag: if true, display menus over graphic objects when selected
        with <3>.

 -show_selection_grips
        Flag: if true, display selection grips when an item is selected.

 -smooth
        Default value for smooth option.

 -stipplepattern
        Default stipple pattern for drawing.

 -textcursor
        Cursor when creating text items.

 -textfont
        Default text item font.

 -withrotate
        If true (default) use polygons for rectangles to support rotation
        in Tcl (Tk doesn't support rotating, but polygons can be rotated
        in Tcl code).  Subclasses that define rotation by adding new
        canvas objects can set this option to 0.

 -withtoolbox
        If true (default) create the GUI interface (toolbox), otherwise
        don't.

PUBLIC METHODS

 
 add_menuitems {m}
        Create the menu items in the given menu.

 add_notify_cmd {id cmd {update_flag 0}}
        Arrange to have cmd evaluated whenever the given object is moved
        or resized. id is the canvas id of the object, If update_flag is
        1, $cmd is also evaluated while the item is being moved or
        resized, otherwise only when the operation is done.

 add_object_bindings {id {target_id ""}}
        Set up the canvas object bindings. target_id defaults to id.  If
        target_id is specified, it will receive the events instead of id.

 adjust_line_selection {id}
        Adjust the selection handles for the given simple line.

 adjust_object_selection {id}
        Adjust the selection handles for the given object to fit the new
        size/pos.

 check_deselect {}
        If the mouse is not over an object, deselect all objects.

 clear {}
        Delete all canvas items.

 clip {px py}
        Clip the given point to keep it over the drawing area.

 config_selected {option value}
        Apply the given option to the selected canvas items.

 create_done {x y}
        Finish creation of the current object and call the "create"
        command, if one was specified, otherwise, for region items, call
        the region command, if defined.

 create_object {x y}
        Create a new object in the canvas.

 delete_object {id}
        Delete the given canvas item.

 delete_selected_objects {}
        Delete the selected canvas items.

 deselect_object {id}
        Deselect the given object.

 deselect_objects {}
        Deselect all canvas objects.

 flipx {item maxx}
        Flip the named item(s) on the X axis by subtracting the x
        coordinates from $maxx.

 flipy {item maxy}
        Flip the named item(s) on the Y axis by subtracting the y
        coordinates from $maxy.

 item_has_tag {item tag}
        Return 1 if the given item has the given tag.

 item_is_selected {item}
        Return 1 if the given item is currently selected.

 remove_notify_cmd {id}
        Remove the notify command for the given canvas id.

 reset_cursor {}
        Set the cursor for the canvas window back to the previous one,
        unless we are in the middle of a resize operation.

 rotate {item}
        Exchange the X and Y coords for the given item (not really
        rotate...).

 rotate_point {x y cx cy angle}
        Rotate the given point about the given center point by the given
        angle (in radians) and return a list {x y} as the result.

 select_object {id {any 0}}
        Select the given object by drawing 8 little grips on it, or for
        text objects, if any==1 and the selection type is "anyselect",
        select the text in the object.  The grips have the tag "grip" and
        the object gets the tag "$w_.selected".

 select_only_object {id x y}
        Select only the given object.

 select_region {x0 y0 x1 y1}
        This method is called when a region object has been created to
        select a region of the canvas.  All objects in the region are
        selected and if a region command option was specified, the command
        is evaluated with the bounding box of the region.

 selected_items {}
        Return a list of all of the currently selected items.

 set_arrowshape {list}
        Set the arrow shape default and for any selected objects.

 set_arrowtype {t}
        Set the arrow type default and for any selected objects.

 set_cursor {cursor}
        Set the cursor for the canvas window and save the previous cursor
        for later restoration.

 set_drawing_mode {type {create_cmd ""}}
        Set the type of object to draw (line, oval, ...) If create_cmd is
        specified, it is called with the coordinates of the new object
        when its creation is completed.

 set_fillcolor {c}
        Set the fill color default and for any selected objects note: if
        the stipple is invisible (see through), make it solid to make sure
        fill is visible.

 set_linewidth {w}
        Set the line width default and for any selected objects.

 set_menu_state {state}
        Enable or disable the drawing items in the menu (enable is state
        is "normal", disable if "disabled".

 set_outlinecolor {c}
        Set the outline color default and for any selected objects.

 set_smooth {bool}
        Set the smooth option for drawing .

 set_stipplepattern {index}
        Set the stipple pattern default and for any selected objects index
        is the pattern number (corresponding to pat$index.xbm).

 set_textfont {f}
        Set the text font  default and for any selected objects.

PROTECTED METHODS

 
 add_poly_point {x y}
        Add a point to the curent polygon/polyline.

 check_done {x y {update_method "update_object"}}
        Check if object creation is done: if the button has moved since it
        was pressed, we are done, otherwise dragging continues without the
        button pressed.

        update_method is the method to call to update the object, if
        needed.

 create_arc {x y}
        Create  and return a new arc object.

 create_freehand {x y}
        Create  and return a new freehand object.

 create_label {x y}
        Create and return a new label (entry) object.

 create_line {x y}
        Create  and return a new line object.

 create_oval {x y}
        Create  and return a new oval object.

 create_polygon {x y}
        Create  and return a new polygon object.

 create_polyline {x y}
        Create  and return a new polyline object.

 create_rectangle {x y}
        Create and return a new rectangle object (actually create a
        polygon object in the shape of a rectangle, since it is more
        flexible and can be rotated).

 create_region {x y}
        Create and return a new region (dashed rectangle marking a region
        of the canvas).

 create_text {x y}
        Create  and return a new text object.

 create_text_done {x y}
        Finish creation of the current text object.

 draw_line_selection_grips {id}
        Draw the selection grips for a simple line.  Lines get one grip at
        each end.

 draw_selection_grips {id {type ""}}
        Draw the object selection grips (small boxes similar to those used
        by FrameMaker and used to move and resize the object).  Lines (see
        above) get one at each end, other objects (here) get one at each
        corner and side of the object's bounding box. If type is "polygon"
        or "line", rotation bindings are also enabled (with
        <Control-...>).

 end_move {id}
        This method is called when a move operation is done.

 end_resize {id}
        Stop resizing the selected object.

 end_resize_line {id}
        Stop resizing the selected line.

 end_rotate {id}
        Stop rotating the selected object.

 get_line_color {}
        Return a color for a line that will be visible.

 init {}
        This method is called after the constructor have completed.

 make_drawmode_frame {}
        Create the frame for selecting draw types  (line, oval, ...) in
        the given frame.

 make_object_menu {}
        Create the canvas item menu.

 make_options_frame {}
        Create the draw options frame (line width, color, etc...).

 mark {x y}
        Mark (remember) the current position.

 move_object {id x y}
        Move the given object.

 post_object_menu {x y}
        Post the object menu at the mouse cursor position.  If an item is
        selected, post the menu with the items enabled.

 resize_label {text rect tag}
        Resize the rectangle for a label to fit the text.

 resize_line {id x y side constrain}
        Resize the given line.

 start_resize {id x y side}
        Start resizing the selected object (19.9.96: added changes from
        pbiereic).

 start_rotate {id x y}
        Start rotating the selected object.

 toggle_select_object {id x y}
        If the object is selected, deselect it, otherwise select it.

 update_display_from_object {id}
        Update the display to show the options for the given canvas item.

 update_freehand {x y}
        Update the current  freehand object in the canvas with the new x,
        y end points.

 update_line {x y {constrain 0}}
        Update the current line object in the canvas with the new x, y end
        points.

 update_object {x y {constrain 0}}
        Update the current object in the canvas with the new x, y end
        points.

 update_poly_object {x y}
        Update the current polygon/polyline object in the canvas with the
        new x, y end points.

 update_rectangle {x y {constrain 0}}
        Update the current rectangle (or polygon, so we can rotate it)
        object in the canvas with the new x, y end points.

 update_region {x y {constrain 0}}
        Update the current region object (dashed rectangle used for
        marking a region on the canvas).

 update_resize {id x y side constrain}
        Update the resizing of the selected object (updated with changes
        from pbiereic, 19.9.96).

 update_rotate {id x y}
        Update the rotating of the selected object.

PROTECTED VARIABLES

 
 arrowshapes_
        Available arrow shapes for canvas lines (corresponds to bitmaps
        named ar$1_$2_$3).

 canvasX_
        Strings used in bindings to translate %x to canvas coords.

 canvasY_
        Strings used in bindings to translate %y to canvas coords.

 canvas_
        Canvas widget.

 create_cmd_
        Command to evaluate when the current item has been created.

 dragx_
        Flag: true if resizing on X axis.

 dragy_
        Flag: true if resizing on Y axis.

 drawing_
        Flag, true if drawing currently.

 drawing_mode_
        Current draw type.

 drawing_modes_
        List of drawing types .

 endx_
        Ending x coord of object being drawn.

 endy_
        Ending y coord of object being drawn.

 menu_
        Saved menu (optional, from caller's menubar) with drawing commands
        for setting the state of the menu items.

 moved_
        Array(id) of flag: set if object with id was moved.

 notify_
        Array(id) of tcl command to evaluate when object given by canvas
        id is moved or scaled.

 notify_update_
        Same as notify_ above, but indicates command should be evaluated
        while item is being moved or resized.

 obj_coords_
        List of coords for current object being created.

 obj_id_
        Canvas id of the current canvas item.

 object_menu_
        Popup menu for canvas items.

 option_map_
        Array(canvasID,option) of option to use instead for that id.

 posx2_
        X2 pos for resize operations.

 posx_
        X pos for resize operations.

 posy2_
        Y2 pos for resize operations.

 posy_
        Y pos for resize operations.

 prev_cursor_
        Saved previous cursor for canvas.

 regions_
        Array(canvasId) of region ids, used to keep these from rotating.

 resizing_
        Flag: true if currently resizing an item.

 rotate_angle_
        Current rotation angle of object.

 rotate_cursor_
        Cursor to use in rotate mode.

 rotate_cx_
        Center X coordinate of object being rotated.

 rotate_cy_
        Center Y coordinate of object being rotated.

 startx_
        Starting x coord of object being drawn.

 starty_
        Starting y coord of object being drawn.

 stipple_index_
        Index of stipple bitmap (0 .. 15, 7 is see through, see
        -stipplepattern).

 tag_count_
        Counter used for compound objects to generate canvas tags.

 x0_
        X0 of bounding box of interactive drawing area.

 x1_
        X1 of bounding box of interactive drawing area.

 xoffset_
        X offset for move operations.

 y0_
        Y0 of bounding box of interactive drawing area.

 y1_
        Y1 of bounding box of interactive drawing area.

 yoffset_
        Y offsets for move operations.

COMMON CLASS VARIABLES

 
 cursors_
        Array(direction={n,w,e,s,nw,ne,sw,se}) of cursor names for
        selection handles.

 pi_
        Const PI.

 rad_
        Const PI/180.

SEE ALSO

 
 TopLevelWidget(n)

 


- - - - - -
Last change: 07 May 99

 


Go up one levelGo to Previous Go to Next

Please send questions or comments to abrighto@eso.org.
Copyright © 1998 ESO - European Southern Observatory