[comp.sys.amiga] Animated icon question

bryce@COGSCI.BERKELEY.EDU.UUCP (05/20/87)

-> (Ignore the next 6 lines, please)
->
-> Note to rossi (CATS):
->   The response you wanted was mailed a long time ago. More mail was sent
-> Monday.  I get return-receipts, if you are not getting mail we will need
-> to find the broken link.  Please echo yeah or nae.
->

In article <8614152548.CA29410@rutgers.llc-arpa> rutgers!james writes:
>
> [...] How do animated icons work, and [how can] they be formed?
>

Simple, use the "merge" function in the tools directory of the V1.2
"Extras" disk.  But if you want to know how it works:
Icons contain within them a intuition 'gadget' structure. This is the same
one used for all gadgets, and has the same properties; including dual
selection.  Here is a program I wrote a long time ago to merge two icons.
In brief you need to change the gg_Flags to type 'double-image' and set the
next pointer to be non-zero.  The second image data goes after the first.
The program that follows makes a lot of
assumptions about the format of a DiskObject (icon), but so does everything
else.

# FLAME ON

AmigaBasic would be half-brearable if it had and edior, instead of a
frustrator.  If I wanted 1200 baud I would hook up a modem.
"See how slow the Amiga is-> just look at AmigaBASIC"

# FLAME OFF

---------- cut here ------------
GOSUB g1:	      'Get primary name
DEFLNG a-b:DEFINT c-z 'Define types
LET a=0:a$=""         'SHARED variables
GOSUB g2:GOSUB g3     'Get other names

ON ERROR GOTO handler:
which=1:in$=pi$:OPEN in$ FOR INPUT AS 1
which=2:in$=si$:OPEN in$ FOR INPUT AS 2
which=3:in$=oi$:OPEN in$ FOR OUTPUT AS 3 LEN=512

PRINT "Working (slowly)"
CALL copyn(16,1)  'Copy first 16 of primary icon
CALL readword(1)  'Get gadget gg_Flags word
b=a AND 65535&-3  'Mask bits to change
a=b OR 2	  'Set double image flag
CALL writeword(a) 'Write it back
CALL copyn(10,1)
CALL readword(1):a=1 'This may be any number
CALL writeword(a)    'Set secondary image pointer
CALL copyn(19,1)     'Variable a$ will have icon type
tp=ASC(a$+CHR$(0)) 'Save icon type
 t=29:IF tp<=2 OR tp=5 THEN t=t+56 'Skip Drawer data
CALL copyn(t,1)
PRINT:PRINT"Primary  : Type";tp;:CALL copyimage(1)
 IF tp=1 THEN
  COLOR 3:PRINT"NOTE:";:COLOR 1
  PRINT "Type 'disk' will not show until"
  PRINT "Workbench is loaded again":PRINT
 END IF
CALL skipn(48,2)     'Secondary icon
 ts=ASC(INPUT$(1,2)+CHR$(0))
 t=29:IF ts<=2 OR ts=5 THEN t=t+56 'Skip Drawer data
CALL skipn(t,2)
PRINT"Secondary: Type";ts;
CALL copyimage(2)

CALL copyrest(1)     'Primary icon
cleanup:CLOSE 1,2,3  'Not by Lotus...
KILL oi$+".info"     'Dump useless data icon
PRINT"end":END

SUB copyn(n,f) STATIC:SHARED a$
  FOR k=1 TO n:a$=INPUT$(1,f)
  PRINT#3,a$;:NEXT
END SUB

SUB skipn(n,f) STATIC
  a$=INPUT$(n,f)
END SUB

SUB copyrest(f) STATIC
  WHILE NOT EOF(1)  'until end-of-file
    a$=INPUT$(1,f):PRINT #3,a$;
  WEND
END SUB

SUB readword(f) STATIC:SHARED a
  a=CVI(INPUT$(2,f))
END SUB

SUB writeword(a) STATIC
  PRINT#3,MKI$(a);
END SUB

SUB copyword(f) STATIC:SHARED a
  a=CVI(INPUT$(2,f)):PRINT#3,MKI$(a);
END SUB

SUB copyimage(f) STATIC:SHARED a
  CALL copyn(4,f)
  CALL copyword(f):wide=a
  CALL copyword(f):tall=a
  CALL copyword(f):deep=a
  CALL copyn(10,f)
  PRINT "Width";wide:PRINT " Height";tall;" Depth";deep
  IF INT(wide/16)=wide/16 THEN wide=wide-1
  size=deep*tall*2*(INT(wide/16)+1)
  CALL copyn(size,f)
END SUB

handler: 'Handles 53 and 49(Device or Volume not mounted)
    IF ERR<>53 AND ERR<>49 THEN ON ERROR GOTO 0
    PRINT:COLOR 3:PRINT"ERROR";ERR;":";:COLOR 1:
    PRINT " File ";CHR$(34);in$;CHR$(34)
    PRINT "could NOT be opened.":BEEP:PRINT
    ON which GOSUB g1,g2,g3
    RESUME

g1: PRINT "Name and path of primary icon:"
    GOSUB getin:pi$=in$:RETURN
g2: PRINT "Name and path of secondary icon:"
    GOSUB getin:si$=in$:RETURN
g3: PRINT "Name and path of output icon:"
    GOSUB getin:oi$=in$:RETURN

getin: INPUT in$:IF in$=""THEN getin:
IF RIGHT$(in$,5)<>".info" THEN in$=in$+".info":RETURN
RETURN
---- end ---