Textbox for DBPro by motran7th Nov 2009 10:58
|
---|
Summary Enter one or more textbox in your project with these functions Description Enter one or more textbox in your project with these functions Code ` This code was downloaded from The Game Creators ` It is reproduced here with full permission ` http://www.thegamecreators.com set display mode 1280,960,32 sync on : sync rate 40 TYPE Dettagli_TextBox ID as integer X as integer Y as integer length as integer height as integer txt as string ENDTYPE Dim TextBox(0) As Dettagli_TextBox GLOBAL id_TextBox_enabled AS integer = -1 GLOBAL cursor as integer = 0 txtName = NewTextBox(10,30,27,100,"txtName...") txtSurname = NewTextBox(10,60,27,100,"txtSurname...") Set Current Bitmap 0 clear entry buffer rem MAIN LOOP do cls rgb(255,255,255) Ink 0,0 id_TextBox_enabled = UpdateTextbox(id_TextBox_enabled) sync loop end function UpdateTextbox(id as integer) local i as integer local car$ as string local temp as integer if cursor = 25 and id > -1 NewImageTextBox(id) endif if cursor < 50 and id > -1 inc cursor endif if cursor = 50 and id > -1 cursor = 0 NewImageTextBox(id) endif if scancode() > 0 and id > -1 car$ = right$(entry$(),1) : clear entry buffer if asc(car$) > 31 TextBox(id).txt = TextBox(id).txt + car$ NewImageTextBox(id) else if asc(car$) = 8 and len(TextBox(id).txt) > 0 TextBox(id).txt = left$( TextBox(id).txt , len(TextBox(id).txt)-1) NewImageTextBox(id) endif endif endif if mouseclick()=1 temp = -1 for i = 0 to Array Count( TextBox(0) ) - 1 If MouseX() > Sprite X(TextBox(i).ID+1) And MouseX() < Sprite X(TextBox(i).ID+1) + Sprite Width(TextBox(i).ID+1) And Mousey() > Sprite y(TextBox(i).ID+1) And MouseY() < Sprite Y(TextBox(i).ID+1) + Sprite Height(TextBox(i).ID+1) temp = i cursor = 0 endif cursor = 0 next i for i= 0 to Array Count( TextBox(0) ) - 1 NewImageTextBox(i) next i id = temp endif for i = 0 to Array Count( TextBox(0) ) - 1 sprite TextBox(i).ID + 1 , TextBox(i).X , TextBox(i).Y , TextBox(i).ID + 1 next i endfunction id FUNCTION NewTextBox(X as integer,Y as integer,H as integer,L as integer,text$ as string) local temp$ as string Id = Array Count( TextBox(0) ) Add To Stack TextBox() TextBox(Id).ID = Id TextBox(Id).X = X TextBox(Id).Y = Y TextBox(Id).length = L TextBox(Id).height = H TextBox(Id).txt = text$ NewImageTextBox(Id) endfunction Id function NewImageTextBox(Id as integer) local temp$ as string Create Bitmap 1 , TextBox(Id).length , TextBox(Id).height Set Current Bitmap 1 ink RGB(197,205,226),0 BOX 0 , 0 , TextBox(Id).length , TextBox(Id).height ink RGB(229,236,245),0 BOX 1 , 1 , TextBox(Id).length -1 , TextBox(Id).height -1 if Id = id_TextBox_enabled ink RGB(255,249,189),0 else ink RGB(255,255,255),0 endif BOX 2 , 2 , TextBox(Id).length -2 , TextBox(Id).height -2 Ink 0,0 Set Text Size 16 Set Text Font "tahoma" set cursor 5,Bitmap Height(1) / 2 - (Text Height(TextBox(Id).txt) / 2) temp$ = TextBox(Id).txt If Text Width(temp$) => TextBox(Id).length - 10 Repeat temp$ = right$(temp$,Len(temp$) - 1) Until Text Width(temp$) <= TextBox(Id).length - 10 EndIf print temp$ if cursor > 24 ink RGB(1,1,1),0 line 5 + Text Width(temp$) , Bitmap Height(1) / 2 - (Text Height(temp$) / 2), 5 + Text Width(temp$), Bitmap Height(1) / 2 + (Text Height(temp$) / 2) endif Get Image TextBox(Id).ID+1 ,0,0,TextBox(Id).length,TextBox(Id).height , 1 Set Current Bitmap 0 Delete Bitmap 1 ENDFUNCTION |