Code: Select all
Function s_Buttons:HandlerFunc(msg) /* handlerfunc doesnt take into account donothing option yet*/
msg.action = LowerStr(msg.action)
Local mousexpos = MouseX()
Local mouseypos = MouseY()
ForEach(self.buttonslist, Function (ID, button)
If mousexpos > button.x And mousexpos < button.x + button.width And mouseypos > button.y And mouseypos < button.y + button.height And button.status <> msg.action
If msg.action = "onmousedown" Or msg.action = "onmouseup" Or msg.action = "onrightmousedown" Or msg.action = "onrightmouseup"
Or msg.action = "onwheeldown" Or msg.action = "onwheelup" Or msg.action = "onmidmousedown" Or msg.action = "onmidmouseup"
button.status = msg.action
If HaveItem(button.evttable, "changeto"..msg.action) Then button.evttable["changeto"..msg.action](button.userdata)
Else
button.status = "onmouseover"
If HaveItem(button.evttable, "changetoonmouseover") Then button.evttable["changetoonmouseover"](button.userdata)
EndIf
ElseIf button.status <> "onmouseout" And button.status <> "idle"
If HaveItem(button.evttable, "changetoonmouseout") = True Then button.evttable["changetoonmouseout"](button.userdata)
If HaveItem(button.evttable, "changetoonmouseout") = True Or HaveItem(button.evttable, "onmouseover") = True Or HaveItem(button, "GFX") And HaveItem(button.gfx, "onmouseover")
button.status = "onmouseout"
Else
buttons.status = "idle"
EndIf
ElseIf button.status = "onmouseout"
button.status = "idle"
If HaveItem(button.evttable, "changetoidle") = True Then button.evttable["changetoidle"](button.userdata)
EndIf
If HaveItem(button.evttable, button.status) = True Then button.evttable[buttons.status](button.userdata)
EndFunction
)
EndFunction
With only 5 buttons on screen, i was already able to move mouse quickly out of button, and if i stopped moving mouse at that point, button would stay as "OnMouseOver" state, since it didnt wake up next "OnMouseMove" event as execution of previous one took so long.
So any tips on optimizing my code? Like is RawGet faster than HaveItem or some other similar ideas? Or do I have to go back to using the official #SIMPLEBUTTONS?