home *** CD-ROM | disk | FTP | other *** search
/ The Best of Mecomp Multimedia 2 / MECOMP-CD-II.iso / amiga / programmieren / e / easyplugins / source / iconbox.e < prev    next >
Encoding:
Text File  |  1998-02-21  |  4.3 KB  |  216 lines

  1.  
  2. /*
  3.  
  4.     $VER: iconbox_plugin 1.4 (30.1.98)
  5.  
  6.     Author:         Ali Graham ($01)
  7.                     <agraham@hal9000.net.au>
  8.  
  9.     PLUGIN id:      $01
  10.  
  11.     Desc.:          A box to display icon images and accept icon drops.
  12.  
  13.     Tags:           PLA_IconBox_IconName            [ISG]
  14.                     PLA_IconBox_ShowSelected        [ISG]
  15.                     PLA_IconBox_Disabled            [ISG]
  16.  
  17. */
  18.  
  19. OPT MODULE, OSVERSION=37
  20.  
  21. ->> iconbox_plugin: Modules
  22. MODULE 'tools/easygui', 'graphics/text',
  23.        'intuition/intuition', 'graphics/rastport'
  24.  
  25. MODULE 'utility', 'utility/tagitem'
  26.  
  27. MODULE 'workbench/workbench', 'workbench/startup', 'icon'
  28.  
  29. MODULE 'tools/ghost'
  30.  
  31. -><
  32.  
  33. /* $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ */
  34.  
  35. ->> iconbox_plugin: Definitions
  36. EXPORT OBJECT iconbox_plugin OF plugin PRIVATE
  37.  
  38.     name
  39.     selected
  40.     disabled
  41.  
  42.     icon:PTR TO diskobject
  43.  
  44. ENDOBJECT
  45.  
  46. -> PROGRAMMER_ID | MODULE_ID
  47. ->      $01      |   $01
  48.  
  49. EXPORT ENUM PLA_IconBox_IconName=$81010001,
  50.             PLA_IconBox_ShowSelected,
  51.             PLA_IconBox_Disabled
  52.  
  53. -><
  54.  
  55. /* $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ */
  56.  
  57. ->> iconbox_plugin: iconbox() & end()
  58.  
  59. PROC iconbox(tags=NIL:PTR TO tagitem) OF iconbox_plugin
  60.  
  61.     IF (utilitybase AND iconbase)
  62.  
  63.         self.name     := self.set(PLA_IconBox_IconName, GetTagData(PLA_IconBox_IconName, '', tags))
  64.         self.selected := GetTagData(PLA_IconBox_ShowSelected, FALSE, tags)
  65.         self.disabled := GetTagData(PLA_IconBox_Disabled, FALSE, tags)
  66.  
  67.     ELSE
  68.  
  69.         Raise("iblb")
  70.  
  71.     ENDIF
  72.  
  73. ENDPROC
  74.  
  75. PROC end() OF iconbox_plugin IS self.set(PLA_IconBox_IconName, NIL)
  76.  
  77. -><
  78.  
  79. ->> iconbox_plugin: set() & get()
  80.  
  81. PROC set(attr, value) OF iconbox_plugin
  82.  
  83.     SELECT attr
  84.  
  85.         CASE PLA_IconBox_IconName
  86.  
  87.             IF self.name<>value
  88.  
  89.                 IF self.icon
  90.  
  91.                     FreeDiskObject(self.icon)
  92.                     self.icon:=NIL
  93.  
  94.                 ENDIF
  95.  
  96.                 IF value
  97.  
  98.                     IF StrLen(value)>0
  99.  
  100.                         self.name:=value
  101.                         self.icon:=GetDiskObject(self.name)
  102.  
  103.                     ENDIF
  104.  
  105.                 ENDIF
  106.  
  107.                 IF (self.disabled=FALSE) THEN  self.draw(self.gh.wnd)
  108.  
  109.             ENDIF
  110.  
  111.         CASE PLA_IconBox_ShowSelected
  112.  
  113.             IF self.selected<>value
  114.  
  115.                 self.selected:=value
  116.  
  117.                 IF (self.disabled=FALSE) THEN self.draw(self.gh.wnd)
  118.  
  119.             ENDIF
  120.  
  121.         CASE PLA_IconBox_Disabled
  122.  
  123.             IF self.disabled<>value
  124.  
  125.                 self.disabled:=value
  126.  
  127.                 self.draw(self.gh.wnd)
  128.  
  129.             ENDIF
  130.  
  131.     ENDSELECT
  132.  
  133. ENDPROC
  134.  
  135. PROC get(attr) OF iconbox_plugin
  136.  
  137.     SELECT attr
  138.  
  139.         CASE PLA_IconBox_IconName;      RETURN self.name, TRUE
  140.         CASE PLA_IconBox_ShowSelected;  RETURN self.selected, TRUE
  141.         CASE PLA_IconBox_Disabled;      RETURN self.disabled, TRUE
  142.  
  143.     ENDSELECT
  144.  
  145. ENDPROC -1, FALSE
  146.  
  147. -><
  148.  
  149. ->> iconbox_plugin: draw()
  150. PROC draw(win:PTR TO window) OF iconbox_plugin
  151.  
  152.     IF win
  153.  
  154.         SetStdRast(win.rport)
  155.  
  156.         Box(self.x, self.y, (self.x+(self.xs-1)), (self.y+(self.ys-1)), 0)
  157.  
  158.         IF self.icon AND (self.disabled=FALSE)
  159.  
  160.             IF (self.icon.gadget.width < self.xs) AND (self.icon.gadget.height < self.ys)
  161.  
  162.                 DrawImage(win.rport,
  163.                           IF self.selected THEN self.icon.gadget.selectrender ELSE self.icon.gadget.gadgetrender,
  164.                           self.x+((self.xs-self.icon.gadget.width)/2), self.y+((self.ys-self.icon.gadget.height)/2))
  165.  
  166.             ENDIF
  167.  
  168.         ENDIF
  169.  
  170.         IF self.disabled THEN ghost(win, self.x, self.y, self.xs, self.ys)
  171.  
  172.     ENDIF
  173.  
  174. ENDPROC
  175. -><
  176.  
  177. ->> easygui standard procs
  178. PROC min_size(ta:PTR TO textattr, fh) OF iconbox_plugin
  179.  
  180.     DEF width, height
  181.  
  182.     IF self.icon
  183.  
  184.         width:=self.icon.gadget.width + 16
  185.         height:=self.icon.gadget.height + 12
  186.  
  187.     ELSE
  188.  
  189.         width:=48
  190.         height:=32
  191.  
  192.     ENDIF
  193.  
  194. ENDPROC width, height
  195.  
  196. PROC will_resize() OF iconbox_plugin IS (RESIZEX OR RESIZEY)
  197.  
  198. PROC render(ta:PTR TO textattr, x, y, xs, ys, win:PTR TO window) OF iconbox_plugin
  199.  
  200.    self.draw(win)
  201.  
  202. ENDPROC
  203.  
  204. PROC appmessage(amsg:PTR TO appmessage, win:PTR TO window) OF iconbox_plugin
  205.  
  206.     DEF xok=FALSE, yok=FALSE
  207.  
  208.     xok:=(amsg.mousex>=(self.x)) AND (amsg.mousex<=(self.x+self.xs-1))
  209.     yok:=(amsg.mousey>=(self.y)) AND (amsg.mousey<=(self.y+self.ys-1))
  210.  
  211. ENDPROC ((xok AND yok) AND (self.disabled=FALSE))
  212.  
  213. -><
  214.  
  215.  
  216.