 _________________________________________________________________________
/#########################################################################\
|#####...####..######..######......####...####..#####..##......##......###|
|####.....###..######..########..#####.....###...####..##..######..#######|
|###..###..##..######..########..####..###..##....###..##..######..#######|
|###..###..##..######..########..####..###..##..#...#..##..######......###|
|###.......##..######..########..####.......##..##.....##..######..#######|
|###..###..##..######..########..####..###..##..###....##..######..#######|
|###..###..##...#####...#######..####..###..##..####...##..######..#######|
|###..###..##......##......##......##..###..##..#####..##......##......###|
|#########################################################################|
|####################################################################{RB}#|
|=========================================================================|
|									  |
|		           ----> PRESENTS <----				  |
|									  |
|			THE ABACUS SERIES - VOLUME 2		          |
|									  |
|            AMIGA GRAPHICS INSIDE AND OUT - THE COMPLETE BOOK            |
|									  |
| Typed / Scanned / Edited By : RAZOR BLADE.			          |
| Additional Typing by        : GLITCH ( + 8 pages by Asterix ! ).	  |
| Menu Coded by 	      : RAISTLIN				  |
| Original Supplied by	      : VIPER					  |
|									  |
|-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-|
| 		CALL THE ALLIANCE WORLD HQ -> THE PLACE TO BE             |
|       UNKNOWN PLEASURES --> +44 (0) 823 322 891 --> SYSOP: BARBARIAN    |
|_________________________________________________________________________|


-----------------------------------------------------------------------------

3.3 FUNCTIONS OF THE INTUITION LIBRARY.

Now that we understand how intuition manages window we can look at the
intuition library. The following routines of the intuition library are
responsible for windows:

        SetPointer()
        ClearPointer()
        MoveWindow()
        SizeWindow()
        WindowLimits()
        WindowToBack()
        WindowToFront()

                ------------------------------------------------

3.3.1  A PERSONALISED MOUSE POINTER.

The SetPointer function makes it possible for you to create your own
personalised mouse pointer for your window. As soon as your window is
active the normal pointer will be replaced by yours.


This function requires six parameters:

        SetPointer(window,image,height,width,xOff,yOff)
        Window: Address of window data structure of that window.
        image : Address of sprite image block.
        height: Height of the sprite.
        width : Width of sprite (max.16)
        xOff  : Marks the "hot spot"
        yOff  : Marks the "hot spot"

The following is an example program which shows how to change the mouse
pointer.

        '######################################
        '#
        '# section: 3.3.1
        '# Program: SetPointer-ClearPointer.
        '# Date   : 04/05/87
        '# Author : tob
        '# Version: 1.0
        '#
        '#######################################

                                PAGE 106

----------------------------------------------------------------------------

        ' The Amiga standard mouse pointer is
        ' replaced by a user-defined pointer.

        PRINT "Searching for .bmap file...."

        'INTUITION-Library
        'SetPointer()
        'ClearPointer()
        LIBRARY "intuition.library"

        init:   image$=""
                sprite.height% = 14
                sprite.width% = 16
                sprite.xOff% = -7
                sprite.yOff% = -6

        image:  '* REad sprite data image.
                RESTORE sprite.data
                FOR loop% = 0 TO 31
                    READ info&
                    hi% = INT(info&/256)
                    lo% = info& - (256*hi%)
                    image$ = image$+CHR$(hi%)+CHR$(lo%)
                NEXT loop

        setpoint:  '* Build new image.
                   CALL SetPointer(WINDOW(7),SADD(image$),sprite.height%,
                        sprite.width%,sprite.xOff%,sprite.yOff%)
        maindemo:  '* Demonstration of the new pointer.
                   CLS
                   PRINT "Any key to exit."
                   PRINT "Left Mouse button to draw."

                   '* Draw with pattern.
                   area.pat%(0) = &h1111
                   area.pat%(1) = &h2222
                   area.pat%(2) = &h4444
                   area.pat%(3) = &h8888
                   PATTERN , area.pat%
                   COLOR 2,3

                   WHILE INKEY$=""
                      state% = MOUSE(0)
                      IF state%<0 THEN
                        mouseOldX% = mouseX%
                        mouseOldY% = mouseY%
                        mouseX% = MOUSE(1)
                        mouseY% = MOUSE(2)
                        IF lplot% = 0 THEN
                            lplot% = 1


                                PAGE 107

----------------------------------------------------------------------------

                            PSET(mouseX%,mouseY%)
                        ELSE
                          LINE(mouseOldX%,mouseOldY%)-(mouseX%,mouseY%),1,bf
                        END IF
                      ELSE
                        lplot% = 0
                      END IF
                   WEND

                   COLOR 1,0

        endprog:   '* End demo and restore old pointer.
                   CALL ClearPointer(WINDOW(7))
                   LIBRARY CLOSE
                   END

        sprite.data:    DATA 0,0   
                        DATA 256,256
                        DATA 256,256
                        DATA 256,256
                        DATA 896,0
                        DATA 3168,0
                        DATA 12312,0
                        DATA 256,49414
                        DATA 256,49414
                        DATA 12312,0
                        DATA 3168,0
                        DATA 896,0
                        DATA 256,256
                        DATA 256,256
                        DATA 256,256
                        DATA 0,0

PROGRAM DESCRIPTION:

Our new mouse pointer should be 16 pixels wide and 14 pixels high. The "hot
spot", the sensitive pixel of the pointer, is seven pixels to the right and
six pixels below the upper left hand corner of the sprite.

The program routine IMAGE defines the shape of the new pointer. The data
for the shape is stored in the section called SPRITE.DATA. Each row of a
sprite can be a maximum of 16 pixels wide. The data block is composed of
two 16 bit values per sprite row. Since our sample sprite is 14 rows high
there has to be 14*2 = 28 data elements (plus two zeros at the beginning
and emd to switch of DMA). For every possible pixel of the sprite there are
two bits. If neither bit is set the pixel will be transparent. The
remaining three combinations determine which of the three possible colours
the pixel will be.

The sprite data is stored in the string variable IMAGE$. To do this the
16bit values are first converted to two 8 bit values (lo and hi byte).

Finally we call SetPointer to activate the new pointer.

At the end of the program we use ClearPointer to restore the normal
pointer.

                                PAGE 108

----------------------------------------------------------------------------

3.3.2  MOVING WINDOWS MADE EASY.

Instead of using the mouse to drag windows around the screen, you can
program Intuition to do the same thing. You can use the intuition routine
"MoveWindow" which requires three parameters:

        MoveWindow(window,deltaX,deltaY)

        window: Address of the window data structure            
        deltaX: Number of pixels to move the window to the right.
                (left = negative)
        deltaY: Same in vertical direction.

These routines do not check your parameters for valid coordinates. If your
delta values set coordinates outside the screen, Intuition will try to move
your window off the monitor. Of course, this will not work. To prevent this
from happening we have added a small error check routine to the next
program. This routine will check your input with the data in the window
data structure (Section 2.2).

This program is a SUB named Move.

        '##############################
        '#
        '# Section: 3.3.2
        '# Program: Window Move.
        '# Date   : 04/10/87
        '# Author : tob
        '# Version: 1.0
        '#
        '###############################

        'Intuition can move selected windows under
        ' program control. This program demonstrates
        ' the WindowMove() command (including
        ' error checking.

        PRINT "Searching for .bmap file .... "

        'INTUITION-library
        'MoveWindow()

        LIBRARY "intuition.library"

                                PAGE 109

----------------------------------------------------------------------------

        demo:   CLS
                WINDOW 2,"Test Window",(10,10)-(400,100),16
                WINDOW OUTPUT 2

                PRINT "Original Position. Please Press a Key"
                WHILE INKEY$="": WEND

                Move 10,20  '10 right,20 down
                PRINT "New position! Press a Key."
                WHILE INKEY$ = "":WEND

                Move -10,-20 ' 10 left, 20 up
                PRINT "Returned!!"

                FOR t = 1 TO 3000: NEXT t

                Move 10000,10000
                ' Nothing happened thanks to the error check.

                WINDOW CLOSE 2
                LIBRARY CLOSE

        SUB Move(x%,y%) STATIC

                win&    = WINDOW(7)
                screen.width%   = 640
                screen.height%  = 200 'PAL systems can use 256 here.
                windo.x%        = PEEKW(win&+4)
                windo.y%        = PEEKW(win&+6)
                windo.width     = PEEKW(win&+8)
                windo.height%   = PEEKW(win&+10)
                min.x%          = windo.x%*(-1)
                min.y%          = windo.y%*(-1)
                max.x%          = screen.width%-windo.width%-windo.x%
                max.y%          = screen.height%-windo.height%-windo.y%
                IF x%<min.x% OR x%>max.x% THEN x% = 0
                IF y%<min.y% OR y%>max.y% THEN y% = 0
                CALL MoveWindow(win&,x%,y%)
        END SUB

                ---------------------------------------------

3.3.3 SETTING WINDOW LIMITS.

All windows that can be sized have a minimum and maximum size. The
Intuition routine WindowLimits sets the limits according to the input
values. The data fields at offset 16 (see section 2.2) are directly
manipulated by WindowLimits. This routine also checks for valid arguments.
When all parameters are OK, WindowLimits returns a TRUE (=1), if not, it
returns a FALSE (=0).

                                PAGE 110

------------------------------------------------------------------------------

WindowLimits requires 5 arguments and returns a result:

result% = WindowLimits%(window,minX,minY,maxX,maxY)

        result% = 1= all OK
                  0= Minimum size greater than maximim size etc.

        minX,minY:  Minimum size of window.
        maxX,maxY:  Maximum sixe of window.

A short example:

        REM 3.3.3 Window Limits.
        DECLARE FUNCTION WindowLimits% LIBRARY
        LIBRARY "intuition.library"
        minX%=5
        minY%=5
        maxX%=640
        maxY%=200
        res%=WindowLimits(WINDOW(7),minX%,minY%,maxX%,maxY%)

        IF res% = 0 THEN
                PRINT "Something is incorrect ......."
        END IF

        LIBRARY CLOSE
        END

                ---------------------------------------------

3.3.4 SIZING WINDOWS.

The Intuition function SizeWindow is used to shrink or enlarge a window.
SizeWindow requires three arguments:

        SizeWindow(window,deltaX,deltaY)

        window: Address of the window data structure.
        deltaX: Number of pixels to enlarge the window horizontally 
                (negative = shrink)
        deltaY: Same action, only vertically.

This routine does not check for incorrect parameters. If your delta values
make the window smaller than is possible or bigger than the screen, you
will encounter a system crash. To prevent this, the next program has a
routine the recognises false values and makes them safe. This SUB is named
Size:

                                PAGE 111

------------------------------------------------------------------------------

        '############################################
        '#
        '# Section: 3.3.4
        '# Program: Window Limits.
        '# Date   : 04/10/87
        '# Author : tob.
        '# Version: 1.0
        '#
        '#############################################

        'Demonstrate setting a window's maximum and
        'and minimum settings.

        PRINT "Searching for .bmap file ......"

        'INTUITION-library
        'WindowLimits

        DECLARE FUNCTION WindowLimits% LIBRARY

        LIBRARY "intuition.library"

        demo:   CLS         
                WINDOW 2,"Test Window",(10,10)-(400,100),16
                WINDOW OUTPUT 2

                '* Set window limits.
                r% = WindowLimits%(WINDOW(7),0,0,600,200)
                IF r% = 0 THEN ERROR 255

                PRINT "Original Size - Please press a key .... "
                WHILE INKEY$ = "": WEND

                Size 60,40      '60 right, 40 down
                PRINT "New size - press a key ......"
                WHILE INKEY$ = "":WEND

                Size -60,-40 ' 60 left, 40 up
                PRINT "Restored!"

                '* Wait
                FOR t=1 TO 3000: NEXT t

                '* Invalid arguments caught here
                Size 10000,10000 ' Error
                ' nothing happened thanks to the error check

                WINDOW CLOSE 2
                LIBRARY CLOSE

        SUB Size(x%,y%) STATIC
                
                win& =          WINDOW(7)
                windo.width%    = PEEKW(win& + 8)
                windo.height%   = PEEKW(win& + 10)
                windo.minX%     = PEEKW(win& + 16)
                windo.minY%     = PEEKW(win& + 18)
                windo.maxX%     = PEEKW(win& + 20)
                windo.maxY%     = PEEKW(win& + 22)
                min.x%          = windo.minX%-windo.width%
                min.y%          = windo.minY%-windo.height%
                max.x%          = windo.maxX%-windo.width%
                max.y%          = windo.maxY%-windo.height%
                IF x%<min.x% OR x%>max.x% THEN x%=0
                IF y%<min.y% OR y%>max.y% THEN y%=0
                CALL SizeWindow(win&,x%,y%)
        END SUB

                                PAGE 112

----------------------------------------------------------------------------

3.3.5 WINDOWTOFRONT AND WINDOWTOBACK.

A window can be moved to the background or foreground in relation to other
windows. These operations are normally performed with the mouse. However,
there are two intuition functions that can perform the same operation from
a program, WindowToFront and WindowToBack.

Here is a small demonstration:

        LIBRARY "intuition.library"

        FOR loop%= 1 TO 10
            CALL WindowToBack(WINDOW(7))
            PRINT "Behind!"
            FOR t = 1 TO 2000: NEXT t
            CALL WindowToFront(WINDOW(7))
            PRINT "In front!"
            FOR t = 1 TO 2000: NEXT t
        NEXT loop%
        END

                                PAGE 113

----------------------------------------------------------------------------
