home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
AmigActive 6
/
AACD06.ISO
/
AACD
/
System
/
3.5_addons
/
Snap2Grid.WB
< prev
Wrap
Text File
|
2000-01-30
|
3KB
|
127 lines
/* snaps icons like Mac */
/*
TODO:
backdrop oberoende
mjuk flytt
spärr för för många ikoner
spärr för stora ikoner
help ger output
tooltypes:
icon_spacing
icon_max_height
icon_max_width
*/
ADDRESS workbench
OPTIONS RESULTS
debug=0
IF debug THEN SAY "*****************"
GETATTR application.version VAR version_number
IF debug THEN SAY version_number
GETATTR windows STEM window_list
/* How many icons do we have ? */
GETATTR window.icons.all.count NAME root VAR total
IF debug THEN SAY total "icons"
/* Find the largest height and width of icons */
w=0
h=0
name_w=0
DO i=0 TO total-1
GETATTR window.icons.all.i NAME root STEM root
/*IF debug THEN SAY root.left root.top root.name*/
IF w< root.width THEN w= root.width
IF h< root.height THEN h= root.height
full_name='"'|| root.name ||'"'
GETATTR application.font.icon.size NAME full_name
temp=RESULT
IF w<temp THEN w=temp
END
IF debug THEN SAY w h "Largest"
/* Get height of icon font */
GETATTR application.font.icon.height VAR font_h
IF debug THEN SAY font_h "font"
font_h=font_h+2
/* calculate total height of icon including name and space */
h=h+font_h+4
w=w+4
/* Get size of workbench */
GETATTR window.width NAME root VAR win_w
GETATTR window.height NAME root VAR win_h
IF debug THEN SAY win_w win_h
win_h=win_h
/* Calculate grid , EXIT if to many icons to fit.*/
DO l=win_w TO w BY -1
DO i=w TO 200
IF (l/i)=TRUNC(l/i) THEN LEAVE l
END
END
colums= l/i
gridx= l/colums
win_w=l
DO l=win_h TO w BY -1
DO i=h TO 200
IF (l/i)=TRUNC(l/i) THEN LEAVE l
END
END
rows= l/i
gridy= l/rows
win_h=l
IF debug THEN SAY gridx gridy "Grid"
IF debug THEN SAY win_w win_h "WB"
IF debug THEN SAY colums rows "c/r"
IF total>(rows*colums) THEN DO
Say "Snap2Grid problem:"
SAY "To many Icons to fit in Grid!"
EXIT 10
END
/* Clear the matrix for vacant grids */
Do i=0 TO colums-1
DO l=0 TO rows-1
free.l.i=0
END
END
/* Get on with the snapping */
DO i=0 TO total-1
GETATTR window.icons.all.i NAME root STEM root
icongridx= TRUNC(root.left/gridx)
icongridy= TRUNC(root.top/gridy)
IF free.icongridx.icongridy =1 THEN CALL FIND
IF free.icongridx.icongridy =1 THEN SAY "ERROR"
move_x=TRUNC(icongridx*gridx)
move_y=TRUNC(icongridy*gridy)
center_x=TRUNC((gridx-root.width)/2)
move_x=move_x+center_x
lock_y=gridy-root.height-font_h-1
move_y=move_y+lock_y
full_name='"'||root.name||'"'
ICON WINDOW root NAMES full_name X move_x Y move_y
free.icongridx.icongridy =1
END
EXIT
/* -------THE END------------ */
/* Function to find a vacant grid */
FIND:
DO x1=icongridx TO colums-1
DO y1=icongridy TO rows-1
IF free.x1.y1=0 THEN leave x1
END
icongridy=0
END
icongridx= x1
icongridy= y1
RETURN