November 25, 2020, 07:50:51 AM

Author Topic: [bb] Custom Input boxes by Eikon [ 1+ years ago ]  (Read 641 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bb] Custom Input boxes by Eikon [ 1+ years ago ]
« on: June 29, 2017, 12:28:38 AM »
Title : Custom Input boxes
Author : Eikon
Posted : 1+ years ago

Description : Very simple design features a blinking cursor, click detection, and tab support. Arrow key movement inside the boxes would make a good addition.

Code :
Code: BlitzBasic
  1. AppTitle "Rpg Input Example by Eikon"
  2. Graphics 640, 320, 16, 2
  3. SetBuffer BackBuffer()
  4.  
  5. Font = LoadFont("Lucida Console", 16, 0, 0) ; Inputbox Font
  6. SetFont Font
  7.  
  8. Local name$, class$, gender$
  9. Global itotal% = 3  ; 3 Inputboxes
  10. Global aInbox% = 0, inTime%, inB% = 0 ; Active Inputbox and blink timer
  11.  
  12. Dim InputBox$(itotal) ; Strings to hold input
  13.  
  14. ClsColor 212, 208, 200
  15. While Not KeyDown(1)
  16.  
  17. DrawInputBoxes 50, 50
  18.  
  19. Delay 5
  20. Flip: Cls
  21. Wend: End
  22.  
  23. Function DrawInputBoxes(x, y)
  24. MX = MouseX(): MY = MouseY(): MH = MouseHit(1)
  25. inkey% = GetKey() ; Grab Input
  26.  
  27. If inkey > 31 And inkey < 128 Then ; Filter out unwanted keys
  28.         ; Add input to string
  29.         If Len(InputBox$(aInbox)) < 9 Then InputBox$(aInbox) = InputBox$(aInbox) + Chr$(inkey)
  30. EndIf
  31.  
  32. If inkey = 8 Or inkey = 4 ; Delete
  33.         If Len(InputBox$(aInbox)) > 0 Then InputBox$(aInbox) = Left$(InputBox$(aInbox), Len(InputBox$(aInbox)) - 1)
  34. EndIf
  35.  
  36. i = 0
  37. For b = y To y + ((itotal - 1) * 64) Step 64
  38.         Color 128, 128, 128: Rect x, b, 100, 28, 0     ; Draw Inputbox
  39.         Color 64, 64, 64: Rect x + 1, b + 1, 98, 26, 0
  40.         Color 212, 208, 200: Rect x + 1, b + 26, 98, 1: Rect x + 98, b + 1, 1, 26
  41.         Color 255, 255, 255: Rect x, b + 27, 100, 1: Rect x + 99, b, 1, 27: Rect x + 2, b + 2, 96, 24
  42.         If i = 0 Then Color 0, 128, 0 ElseIf i = 1 Then Color 0, 0, 128 Else Color 0, 0, 0
  43.         Text x + 4, b + 8, InputBox$(i)
  44.        
  45.         Color 0, 0, 0:
  46.         If aInbox% = i ; Draw Cursor in active inbox
  47.                 If inB = True Then Color 0, 0, 0: Rect x + 4 + (Len(InputBox$(aInbox)) * 10), b + 4, 2, 20, 1
  48.                 If MilliSecs() >= inTime + 500 Then ; Blink
  49.                         If inB = 0 Then inB = 1 Else inB = 0
  50.                         inTime = MilliSecs()
  51.                 EndIf
  52.         EndIf
  53.  
  54.         ; Mouse click Detection to change active inputbox
  55.         If MH = 1 And RectsOverlap(MX, MY, 1, 1, x, b, 100, 28) Then aInbox = i
  56.  
  57.         Select i ; Draw Captions
  58.                 Case 0: Text x, b - 20, "Name:"   ; Name
  59.                 Case 1: Text x, b - 20, "Class:"  ; Class
  60.                 Case 2: Text x, b - 20, "Gender:" ; Gender
  61.  
  62.         End Select
  63.  
  64.         i = i + 1
  65. Next
  66.  
  67. If KeyHit(15) Then aInbox = aInbox + 1 ; Tab support
  68. If aInbox >= 3 Then aInbox = 0
  69.  
  70. End Function


Comments :


Ked(Posted 1+ years ago)

 Nicely done.


vivaigiochi(Posted 1+ years ago)

 change If inB = True Then Color 0, 0, 0: Rect x + 4 + (Len(InputBox$(aInbox)) * 10), b + 4, 2, 20, 1with this:If inB = True Then Color 0, 0, 0: Rect x + 4 + stringwidth(InputBox$(aInbox), b + 4, 2, 20, 1This make the right position of cursor after input...


 

SimplePortal 2.3.6 © 2008-2014, SimplePortal