September 28, 2021, 17:29:03

Author Topic: [bmx] button library by Telemental [ 1+ years ago ]  (Read 699 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bmx] button library by Telemental [ 1+ years ago ]
« on: June 29, 2017, 00:28:40 »
Title : button library
Author : Telemental
Posted : 1+ years ago

Description : A simple button class

Code :
Code: BlitzMax
  1. ' Button Include
  2. ' button.x, y: button location
  3. ' button.txoff, tyoff: x&y offset for text.
  4. ' button.overlay: whether text appears on button or not.
  5. ' button.hover: whether there is a hover image.
  6. ' button.alpha: the alpha of the hover image.
  7. ' button.text: Text for button.
  8. ' button.zorder: What screen layer the button is on. Only the highest ZOrder buttons will activate.
  9. ' button.image and button.himage: image and hoverimage. Need to add a down image
  10. ' methods
  11. ' button.draw: draws button
  12. ' button.checkover: sees whether mouse is over button.
  13.  
  14.  
  15.  
  16. Global buttonlist:TList = New TList
  17. Global stat_leftbutton 'leftbutton
  18. Global stat_rightbutton 'rightbutton
  19.  
  20. Type button
  21.         Field x#, y#, h#, w#, zorder#
  22.         Field txoff# = 5
  23.         Field tyoff# = 5
  24.         Field overlay = 0
  25.         Field hover# = 0
  26.         Field alpha# = 1
  27.         Field text$ = Null
  28.         Field image:TImage
  29.         Field himage:TImage
  30.        
  31.        
  32.         Method Set(bimage:TImage, bx, by, bz=0)
  33.                 x = bx
  34.                 y = by
  35.                 w = ImageWidth(bimage)
  36.                 h = ImageHeight(bimage)
  37.                 image = bimage
  38.                 zorder = bz
  39.         End Method
  40.        
  41.         Method New()
  42.                 buttonlist.addlast Self
  43.         End Method
  44.        
  45.         Method Draw(collisionlayer = 1)
  46.                 DrawImage image, x, y
  47.                 If Not himage Then hover = 0
  48.                 If CheckOver() And hover Then
  49.                         SetAlpha(alpha)
  50.                         SetBlend(ALPHABLEND)
  51.                         DrawImage(himage, x, y)
  52.                         SetAlpha(1)
  53.                 EndIf
  54.                
  55.                 If Not text = Null Then
  56.                         If TextWidth(text) > w And overlay = 0 Then
  57.                                 DrawText text, x+w+txoff, y
  58.                         Else
  59.                                 DrawText text, x+txoff, y+tyoff
  60.                         EndIf
  61.                 EndIf
  62.  
  63.                 CollideImage(image, x, y, 0, 0, collisionlayer)
  64.         End Method
  65.        
  66.         Method CheckOver()
  67.                 If HighestZ() > z Then Return False
  68.                 If MouseX() < x Or MouseX() > x+w Then Return False
  69.                 If MouseY() < y Or MouseY() > y+h Then Return False
  70.                 Return True
  71.         End Method
  72.        
  73.         Method HighestZ()
  74.                 tempz = 0
  75.                 For temp:button = EachIn buttonlist
  76.                         tempz = Max(temp.zorder, tempz)
  77.                 Next
  78.                 Return tempz
  79.         End Method
  80. End Type
  81.  
  82.  
  83. Function getmousestatus()
  84.         stat_leftbutton = MouseHit(1)
  85.         stat_rightbutton = MouseHit(2)
  86. End Function


Comments :


matt!(Posted 1+ years ago)

 Thanks for this.


 

SimplePortal 2.3.6 © 2008-2014, SimplePortal