home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 6 / AACD06.ISO / AACD / System / 3.5_addons / Snap2Grid.WB < prev   
Text File  |  2000-01-30  |  3KB  |  127 lines

  1. /* snaps icons like Mac */
  2. /*
  3. TODO:
  4.  backdrop oberoende
  5.  mjuk flytt
  6.  spärr för för många ikoner
  7.  spärr för stora ikoner
  8.  help ger output
  9.  
  10. tooltypes:
  11.  icon_spacing
  12.  icon_max_height
  13.  icon_max_width
  14. */
  15.  
  16. ADDRESS workbench
  17. OPTIONS RESULTS
  18. debug=0
  19. IF debug THEN SAY "*****************"
  20.  
  21. GETATTR application.version VAR version_number
  22. IF debug THEN SAY version_number
  23.  
  24. GETATTR windows STEM window_list
  25.  
  26. /* How many icons do we have ? */
  27. GETATTR window.icons.all.count NAME root VAR total
  28. IF debug THEN SAY total "icons"
  29.  
  30. /* Find the largest height and width of icons */
  31. w=0
  32. h=0
  33. name_w=0
  34. DO i=0 TO total-1
  35.     GETATTR window.icons.all.i NAME root STEM root
  36. /*IF debug THEN SAY  root.left root.top root.name*/
  37.     IF w< root.width THEN w= root.width
  38.     IF h< root.height THEN h= root.height
  39.     full_name='"'|| root.name ||'"'
  40.     GETATTR application.font.icon.size NAME full_name
  41.     temp=RESULT
  42.     IF w<temp THEN w=temp
  43. END
  44. IF debug THEN SAY w h "Largest"
  45.  
  46. /* Get height of icon font */
  47. GETATTR application.font.icon.height VAR font_h
  48. IF debug THEN SAY font_h "font"
  49. font_h=font_h+2
  50. /* calculate total height of icon including name and space */
  51. h=h+font_h+4
  52. w=w+4
  53.  
  54. /* Get size of workbench */
  55. GETATTR window.width NAME root VAR win_w
  56. GETATTR window.height NAME root VAR win_h
  57. IF debug THEN SAY win_w win_h
  58. win_h=win_h
  59.  
  60.  
  61. /* Calculate grid , EXIT if to many icons to fit.*/
  62.     DO l=win_w TO w BY -1
  63.         DO i=w TO 200
  64.             IF (l/i)=TRUNC(l/i) THEN LEAVE l
  65.         END
  66.     END
  67.     colums= l/i
  68.     gridx= l/colums
  69.     win_w=l
  70.     DO l=win_h TO w BY -1
  71.         DO i=h TO 200
  72.             IF (l/i)=TRUNC(l/i) THEN LEAVE l
  73.         END
  74.     END
  75.     rows= l/i
  76.     gridy= l/rows
  77.     win_h=l
  78.     IF debug THEN SAY gridx gridy "Grid" 
  79.     IF debug THEN SAY win_w win_h "WB"
  80.     IF debug THEN SAY colums rows "c/r"
  81.     IF total>(rows*colums) THEN DO
  82.         Say "Snap2Grid problem:"
  83.         SAY "To many Icons to fit in Grid!"
  84.         EXIT 10
  85.     END
  86.  
  87. /* Clear the matrix for vacant grids */
  88.     Do i=0 TO colums-1
  89.         DO l=0 TO rows-1
  90.             free.l.i=0
  91.         END
  92.     END
  93.  
  94. /* Get on with the snapping */
  95. DO i=0 TO total-1
  96.     GETATTR window.icons.all.i NAME root STEM root
  97.     icongridx= TRUNC(root.left/gridx) 
  98.     icongridy= TRUNC(root.top/gridy) 
  99.     IF free.icongridx.icongridy =1 THEN CALL FIND 
  100.     IF free.icongridx.icongridy =1 THEN SAY "ERROR"
  101.     move_x=TRUNC(icongridx*gridx)
  102.     move_y=TRUNC(icongridy*gridy)
  103.     center_x=TRUNC((gridx-root.width)/2)
  104.     move_x=move_x+center_x
  105.     lock_y=gridy-root.height-font_h-1
  106.     move_y=move_y+lock_y
  107.     full_name='"'||root.name||'"'
  108.     ICON WINDOW root NAMES full_name X move_x Y move_y
  109.     free.icongridx.icongridy =1
  110. END
  111. EXIT
  112.  
  113. /* -------THE END------------ */
  114.  
  115. /* Function to find a vacant grid */
  116. FIND:
  117.     DO x1=icongridx TO colums-1
  118.         DO y1=icongridy  TO rows-1
  119.             IF free.x1.y1=0 THEN leave x1
  120.         END
  121.         icongridy=0
  122.     END
  123.     icongridx= x1 
  124.     icongridy= y1 
  125. RETURN 
  126.  
  127.