Well, as some of you may or may not know, I've been trying to make a function to create a text field but have been having alot of problems here and there. After a few days of messing around with this, I've decided to ask for some help.
This is my code currently. I'm trying to make it so whenever the mouse is over the text field, it lights up and if they left click on it, it lights up. How would I make that work with my current code? Tips and Tricks are welcomed, I'm learning :)
Fixed the fact that it didnt light up I just inversed Draw() and Update(). (was edited in the code above, but it still doesnt light up.
This is my code currently. I'm trying to make it so whenever the mouse is over the text field, it lights up and if they left click on it, it lights up. How would I make that work with my current code? Tips and Tricks are welcomed, I'm learning :)
SuperStrict AppTitle$="Textfield" Graphics 800,600,0 ' Global VARIABLES Global gRoom:Int=0 Global gExit:Int=False Global TextfieldList:TList=CreateList() ' Main Loop Repeat If KeyHit(KEY_ESCAPE) Or AppTerminate() Then gExit=True Local test1:TTextfield cTextfield( test1:TTextfield, 10, 10, 100, 15 ) Flip; Cls Until gExit=True End Type TTextfield Field x:Int, y:Int, w:Int, h:Int Field text:String, length:Int Field mouseover:Int=False Field selected:Int=False Method Draw() If mouseover=True Or selected=True Then SetColor(0,255,200) Else SetColor(0,130,130) EndIf DrawLine( x, y, x+w, y) ' top DrawLine( x, y+h, x+w, y+h) ' bottom DrawLine( x, y, x, y+h) ' left DrawLine( x+w, y, x+w, y+h) ' right DrawText( text, x+2, y+1 ) End Method Method Update() If(MouseX()>x)And(MouseX()<(x+w))And(MouseY()>y)And(MouseY()<(y+h)) mouseover=True If(MouseHit(1)) selected=True EndIf Else mouseover=False EndIf End Method End Type Function cTextfield( handler:TTextfield Var, x:Int, y:Int, w:Int, h:Int ) If Not TextfieldList.Contains( handler ) Then handler= New TTextfield handler.x=x; handler.y=y handler.w=w; handler.h=h TextfieldList.AddLast( handler ) EndIf handler.Update() handler.Draw() End Function
Fixed the fact that it didnt light up I just inversed Draw() and Update(). (was edited in the code above, but it still doesnt light up.