/* TEACH GO_DRAG                             Ben Rabau, 27th Aug 1993

This file shows a few examples of objects which can be dragged around
without losing their respective depth. To make sure the dragged object
does not dissappear completely under other objects a bounding box is
visible at all time.

For more general detailed information see

HELP * GO
REF * GO

Other basic objects for GO include:
    - points    explained in TEACH * GO_POINT
    - lines     explained in TEACH * GO_POLYLINE
    - polygons  explained in TEACH * GO_MAKE_EDITABLE, * GO_POLYGON

         CONTENTS - (Use <ENTER> g to access required sections)

 -- Requirements
 -- EXAMPLE
 -- DRAGGING
 -- OPTIMISATIONS
 -- PROGRAMATICAL MOTION
 -- CLEARING THE EXAMPLE

 */


/*
-- Requirements -------------------------------------------------------
 */
;;; Requires the following files to be loaded:
uses go;
uses go_point;
uses go_polygon;

;;; It also requires the GO window to be active (see TEACH * GO_PANE and
;;; TEACH * GO_RC_WINDOW):
go_init_rc();

/*
-- EXAMPLE ------------------------------------------------------------
 */
;;; Create some objects (3 polygons and 1 go_rectangle)
vars poly1, poly2, poly3, rect;

define check_redraw();
    instance go_polygon;
        go_npoints  = 4;
        go_bgcolour = 'yellow';
        go_filled   = true;
        go_xcentre  = -30;
    endinstance -> poly1;
    instance go_polygon;
        go_npoints  = 5;
        go_bgcolour = 'aquamarine';
        go_filled   = true;
        go_xcentre  = 0;
    endinstance -> poly2;
    instance go_polygon;
        go_npoints  = 8;
        go_bgcolour = 'red';
        go_filled   = true;
        go_xcentre  = 30;
    endinstance -> poly3;

    go_add_to(poly1, go_default_pane );
    go_add_to(poly2, go_default_pane );
    go_add_to(poly3, go_default_pane );

    newgo_rectangle() -> rect;
    go_add_to( rect , go_default_pane );
enddefine;

check_redraw();

;;; Note: the rectangle is filled with a transparent colour!

/*
-- DRAGGING -----------------------------------------------------------
 */
;;; Now try dragging any of the objects around by clicking the LEFT mouse
;;; button. The object which appears under the mouse is the object which
;;; will be dragged.
;;; NOTE: if the mouse is moved to quickly after the button is clicked,
;;;       the object will jump as soon as possible to the correct location...

/*
-- OPTIMISATIONS ------------------------------------------------------
 */

/*  If the objects cannot follow the mouse at all times, then ensure that
    the following holds:
        true -> go_motionhint( go_default_pane );
    It can be turned off with:
        false -> go_motionhint( go_default_pane );
    If the mouse is moved rapidly with the latter option, then the object
    might not be able to follow and lag behind. When the mouse stops the
    object will alwyas catch up. The draging itself will however be slightly
    smoother since the object will not jump to catch up with the mouse.
    This is explained in more detail in TEACH * GO_XDRAG.
 */

;;; There are three options which can be used to optimise the dragging of
;;; go_filled polygons (go_regular or irregular shapes).
;;; 1. The go_drag_filled flag can turn the filling of the dragged object
;;;    off which provides a smoother go_drag motion. Try:

false -> go_drag_filled;

;;; 2. The go_drag_outline flag can turn the drawing of the object
;;;    completely off and only showes the bounding box of the object. Try:

true  -> go_drag_outline;

;;;    Both options can be reversed at all time by doing (equal to default):

true  -> go_drag_filled;
false -> go_drag_outline;

;;; 3. The image represented by the object or go_group of objects can be
;;;    turned into a fixed opaque image. Internally this is stored as
;;;    a bitmap, which can be dragged faster because it never has to be
;;;    redrawn (= recreated). This mode is set with the go_fixed_image()
;;;    method.
;;;    NOTE: - this always results in a rectangular opaque  bitmap!
;;;          - the image is always drawn on go_top of every other object!

true -> go_fixed_image( poly2 );

;;;    This option is reversed with:

false -> go_fixed_image( poly2 );

/*
-- PROGRAMATICAL MOTION -----------------------------------------------
 */
;;; You can also move the objects programatically with commands:
;;;        go_position_of_centre( <object> ) -> (<x>, <y>);
;;;        (<new x>, <new y>) -> go_position_of_centre( <object> );
;;;        go_position_of_origin( <object> ) -> (<x>, <y>);
;;;        (<new x>, <new y>) -> go_position_of_origin( <object> );
;;;        go_centre_to( <new x>, <new y>, <object> );
vars n = 0;
vars obj = poly2;

define check_redraw2();
    ;;; continuously move from -100 to +100 by steps of 5 units (world)
    (n + 5) mod 200 -> n;
    go_centre_to(go_xcentre(obj), n - 100, obj);
    1e5 -> sys_timer( check_redraw2 );
enddefine;

;;; To programmatically move the middle go_polygon (defaults to green) the
;;; following command can be used:
poly2 -> obj;

;;; To start the movement:
1e5 -> sys_timer( check_redraw2 );
;;; To stop the movement:
false -> sys_timer( check_redraw2 );

;;; Note: This flashes a bit too much to be good...
;;; This is due to the combination go_clear/go_redraw which makes a
;;; clean rectangular area first. This can be avoided with go_batch_mode:

define check_redraw3();
    procedure;
    dlocal 1 % go_batch_mode( go_default_pane ) % = true;
        ;;; continuously move from -100 to +100 by steps of 5 units (world)
        (n + 5) mod 200 -> n;
        go_centre_to(go_xcentre(obj), n - 100, obj);
    endprocedure();
    5e5 -> sys_timer( check_redraw3 );
enddefine;

;;; To start the movement:
5e5 -> sys_timer( check_redraw3 );
;;; To stop the movement:
false -> sys_timer( check_redraw3 );


/*
-- CLEARING THE EXAMPLE -----------------------------------------------
 */
;;; To get rid of the objects...
define clear_redraw();
    go_destroy_object(poly1);
    go_destroy_object(poly2);
    go_destroy_object(poly3);
    go_destroy_object(rect);
enddefine;

clear_redraw();

;;; eof

--- C.all/lib/proto/go/teach/go_drag
--- Copyright University of Sussex 1993. All rights reserved.
