Method FindBest:Int()
If Selected=0 Return 0
If Search(ID-1)
If Search(ID-1).Selected=True
If Search(ID+1).Selected=True
Return 4
EndIf
Return 2
EndIf
EndIf
If Search(ID+1)
If Search(ID+1).Selected=True
Return 1
EndIf
EndIf
Return 3
End Method
Method Search:TButton(SearchId:Int)
For Local loc:TButton=EachIn All
If loc.ID=SearchID
Return loc
EndIf
Next
Return Null
End Method
SuperStrict
Graphics 500,200
For Local i:Int= 0 To 5
New TButton(i+1,30+i*66,30,66,122, 0)
Next
SetClsColor 0,155,155
Global MouseState:Int
Repeat
Cls
MouseState = MouseHit(1)
TButton.DrawAll
Local Which:TButton = TButton.CheckAll()
If Which
If Which.Selected=1
Print "Button " + Which.ID + " selected"
Else
Print "Button " + Which.ID + " un-selected"
EndIf
EndIf
Flip
Until AppTerminate()
Type TButton
Global All:TList = New TList
Field ID:Int, X:Int, Y:Int, W:Int, H:Int
Field Selected:Int, RadioGroup:Int
Global Images:TImage
Method New (id:Int, x:Int, y:Int, w:Int, h:Int, group:Int)
If Images=Null
Images=LoadAnimImage("VintageButtonBetter.png",66,122,0,5)
EndIf
Self.ID = id
Self.X = x
Self.Y = y
Self.W = w
Self.H = h
Self.RadioGroup = group
All.Addlast Self
End Method
Function DrawAll()
For Local loc:TButton = EachIn All
loc.Draw
Next
SetColor 255,255,255
End Function
Method Draw()
SetColor 255,255,255
Local ImageNr:Int = FindBest()
DrawImage Images,X,Y,ImageNr
End Method
Method FindBest:Int()
If Selected=0 Return 0
If Search(ID-1)
If Search(ID-1).Selected=True
If Search(ID+1).Selected=True
Return 4
EndIf
Return 2
EndIf
EndIf
If Search(ID+1)
If Search(ID+1).Selected=True
Return 1
EndIf
EndIf
Return 3
End Method
Method Search:TButton(SearchId:Int)
For Local loc:TButton=EachIn All
If loc.ID=SearchID
Return loc
EndIf
Next
Return Null
End Method
Function CheckAll:TButton ()
If MouseState=0 Return Null
For Local loc:TButton = EachIn All
Local result:Int = loc.Check()
If result>0 Return loc
Next
Return Null
End Function
Method Check:Int()
Local mX:Int = MouseX() - X
Local mY:Int = MouseY() - Y
If mX<0 Or mX>W Return 0
If mY<0 Or mY>H Return 0
Selected=1-Selected
If Selected=1
Deselect RadioGroup
EndIf
Return ID
End Method
Method DeSelect(Group:Int)
If RadioGroup=0 Return
For Local loc:TButton=EachIn All
If loc=Self Continue
If loc.RadioGroup=Group
loc.Selected=0
EndIf
Next
End Method
End Type
Local mouseGotHit:Int = MouseHit(1)
Local mouseHitHandled:Int = False
If mouseGotHit and not mouseHitHandled then CheckButtons(mousex(), mousey(), mouseHitHandled (as var) )
If mouseGotHit and not mouseHitHandled then CheckOtherStuff_MouseHitStillNotHandled(mouseHitHandled)
QuoteThats a cool little gameTnx, this little game gave me a new "big" idea...
QuoteI must confess that Unity is really starting to grow on meTook me a while too.
SuperStrict
Graphics 800,300
New TButton(1,100,200,120,80)
New TButton(2,234, 45,222,33)
New TButton(3,600, 100,50,180)
SetClsColor 0,155,155
Global MouseState:Int
Repeat
Cls
MouseState = MouseHit(1)
TButton.DrawAll
Local Which:TButton = TButton.CheckAll()
If Which
If Which.Selected=1
Print "Button " + Which.ID + " selected"
Else
Print "Button " + Which.ID + " un-selected"
EndIf
EndIf
Flip
Until AppTerminate()
Type TButton
Global All:TList = New TList
Field ID:Int, X:Int, Y:Int, W:Int, H:Int
Field Selected:Int
Method New (id:Int, x:Int, y:Int, w:Int, h:Int)
Self.ID = id
Self.X = x
Self.Y = y
Self.W = w
Self.H = h
All.Addlast Self
End Method
Function DrawAll()
For Local loc:TButton = EachIn All
loc.Draw
Next
End Function
Method Draw()
SetColor 1,1,1
DrawRect X, Y, W, H
SetColor 111,111,111
DrawRect X+1, Y+1, W-2, H-2
SetColor 155,155,155
If Selected=1
SetColor 155,255,155
EndIf
DrawRect X+4, Y+4, W-7, H-7
SetColor 1,1,1
DrawText id, x + (w-TextWidth(id))/2,y + (h-TextHeight("T"))/2+2
End Method
Function CheckAll:TButton ()
If MouseState=0 Return Null
For Local loc:TButton = EachIn All
Local result:Int = loc.Check()
If result>0 Return loc
Next
Return Null
End Function
Method Check:Int()
Local mX:Int = MouseX() - X
Local mY:Int = MouseY() - Y
If mX<0 Or mX>W Return 0
If mY<0 Or mY>H Return 0
Selected=1-Selected
Return ID
End Method
End Type
Method Check:Int()
Local mX:Int = MouseX() - X
Local mY:Int = MouseY() - Y
If mX<0 Or mX>W Return 0
If mY<0 Or mY>H Return 0
Selected=1-Selected
If Selected=1
Deselect RadioGroup
EndIf
Return ID
End Method
Method DeSelect(Group:Int)
If Group=0 Return
For Local loc:TButton=EachIn All
If loc=Self Continue
If loc.RadioGroup=Group
loc.Selected=0
EndIf
Next
End Method
SuperStrict
Graphics 800,400
For Local i:Int= 0 To 5
New TButton(i+1,100+i*66,200,66,122, 1)
Next
SetClsColor 0,155,155
Global MouseState:Int
Repeat
Cls
MouseState = MouseHit(1)
TButton.DrawAll
Local Which:TButton = TButton.CheckAll()
If Which
If Which.Selected=1
Print "Button " + Which.ID + " selected"
Else
Print "Button " + Which.ID + " un-selected"
EndIf
EndIf
Flip
Until AppTerminate()
Type TButton
Global All:TList = New TList
Field ID:Int, X:Int, Y:Int, W:Int, H:Int
Field Selected:Int, RadioGroup:Int
Global Images:TImage
Method New (id:Int, x:Int, y:Int, w:Int, h:Int, group:Int)
If Images=Null
Images=LoadAnimImage("VintageButton.png",66,122,0,4)
EndIf
Self.ID = id
Self.X = x
Self.Y = y
Self.W = w
Self.H = h
Self.RadioGroup = group
All.Addlast Self
End Method
Function DrawAll()
For Local loc:TButton = EachIn All
loc.Draw
Next
SetColor 255,255,255
DrawImage Images,0,0,0
End Function
Method Draw()
SetColor 255,255,255
Local ImageNr:Int = FindBest()
DrawImage Images,X,Y,ImageNr
End Method
Method FindBest:Int()
If Selected=0 Return 0
Return 3
End Method
Function CheckAll:TButton ()
If MouseState=0 Return Null
For Local loc:TButton = EachIn All
Local result:Int = loc.Check()
If result>0 Return loc
Next
Return Null
End Function
Method Check:Int()
Local mX:Int = MouseX() - X
Local mY:Int = MouseY() - Y
If mX<0 Or mX>W Return 0
If mY<0 Or mY>H Return 0
Selected=1-Selected
If Selected=1
Deselect RadioGroup
EndIf
Return ID
End Method
Method DeSelect(Group:Int)
If RadioGroup=0 Return
For Local loc:TButton=EachIn All
If loc=Self Continue
If loc.RadioGroup=Group
loc.Selected=0
EndIf
Next
End Method
End Type
SuperStrict
Graphics 800,300
Global MouseState:Int
Repeat
Cls
MouseState = MouseHit(1)
DrawRect 100,200,120,80
If CheckButton()>0 Then
Print "Button pressed"
EndIf
Flip
Until AppTerminate()
Function CheckButton:Int()
If MouseState=0 Return 0
Local mX:Int = MouseX()-100
Local mY:Int = MouseY()-200
If mX<0 Or mX>120 Return 0
If mY<0 Or mY>80 Return 0
Return 1
End Function
SuperStrict
Graphics 800,300
Global MouseState:Int
Repeat
Cls
MouseState = MouseHit(1)
For Local I:Int=0 Until 5
DrawRect 100+i*120+1, 200,118,80
Next
Local Pressed:Int = CheckButton()
If Pressed>0 Then
Print "Button " + Pressed + " pressed"
EndIf
Flip
Until AppTerminate()
Function CheckButton:Int()
If MouseState=0 Return 0
Local mX:Int = MouseX() - 100
Local mY:Int = MouseY() - 200
If mX<0 Or mX>5*120 Return 0
If mY<0 Or mY>80 Return 0
Return Int(mX/120) + 1
End Function
SuperStrict
Graphics 800,300
Global MyButton:TButton= New TButton(1,100,200,120,80)
Global MouseState:Int
Repeat
Cls
MouseState = MouseHit(1)
MyButton.Draw
Local Pressed:Int = MyButton.Check()
If Pressed>0 Then
Print "Button " + Pressed + " pressed"
EndIf
Flip
Until AppTerminate()
Type TButton
Field ID:Int, X:Int, Y:Int, W:Int, H:Int
Method New (id:Int, x:Int, y:Int, w:Int, h:Int)
Self.ID = id
Self.X = x
Self.Y = y
Self.W = w
Self.H = h
End Method
Method Draw()
DrawRect X, Y, W, H
End Method
Method Check:Int()
If MouseState=0 Return 0
Local mX:Int = MouseX() - X
Local mY:Int = MouseY() - Y
If mX<0 Or mX>W Return 0
If mY<0 Or mY>H Return 0
Return ID
End Method
End Type
SuperStrict
Graphics 800,300
New TButton(1,100,200,120,80)
New TButton(2,234, 45,222,33)
New TButton(3,600, 100,50,180)
Global MouseState:Int
Repeat
Cls
MouseState = MouseHit(1)
TButton.DrawAll
Local Pressed:Int = TButton.CheckAll()
If Pressed>0 Then
Print "Button " + Pressed + " pressed"
EndIf
Flip
Until AppTerminate()
Type TButton
Global All:TList = New TList
Field ID:Int, X:Int, Y:Int, W:Int, H:Int
Method New (id:Int, x:Int, y:Int, w:Int, h:Int)
Self.ID = id
Self.X = x
Self.Y = y
Self.W = w
Self.H = h
All.Addlast Self
End Method
Function DrawAll()
For Local loc:TButton = EachIn All
loc.Draw
Next
End Function
Method Draw()
DrawRect X, Y, W, H
DrawText id, x,y-30
End Method
Function CheckAll:Int ()
If MouseState=0 Return 0
For Local loc:TButton = EachIn All
Local result:Int = loc.Check()
If result>0 Return result
Next
Return 0
End Function
Method Check:Int()
Local mX:Int = MouseX() - X
Local mY:Int = MouseY() - Y
If mX<0 Or mX>W Return 0
If mY<0 Or mY>H Return 0
Return ID
End Method
End Type
Page created in 0.107 seconds with 22 queries.