too much white space
It's a waste of drive space.
This commit is contained in:
parent
1e43bd8614
commit
b6ed340f81
1 changed files with 56 additions and 76 deletions
|
|
@ -2,12 +2,10 @@ function textinput$ (x as integer, y as integer, w as integer, h as integer, __t
|
|||
dim text as string, keyin as string
|
||||
dim cursor as integer, done as integer
|
||||
text=__text
|
||||
' Initial Hover Check
|
||||
if not (_mousex>x and _mousey>y AND _mousex<x+w AND _mousey<y+h) then
|
||||
drawtextinput x,y,w,h,__text,0
|
||||
exit function
|
||||
end if
|
||||
|
||||
drawtextinput x,y,w,h,__text,1
|
||||
if not mouseclicked then exit function
|
||||
text=""
|
||||
|
|
@ -15,8 +13,6 @@ function textinput$ (x as integer, y as integer, w as integer, h as integer, __t
|
|||
dim relativeX as integer
|
||||
do
|
||||
keyin=inkey$
|
||||
|
||||
' Handle Extended Keys (Arrows, Home, End, Delete)
|
||||
if len(keyin)=2 then
|
||||
select case asc(right$(keyin,1))
|
||||
case 75 ' Left Arrow
|
||||
|
|
@ -52,24 +48,18 @@ function textinput$ (x as integer, y as integer, w as integer, h as integer, __t
|
|||
done=-1
|
||||
end select
|
||||
end if
|
||||
|
||||
' Send the cursor position to your drawing routine
|
||||
drawtextinput x, y, w, h, text, cursor
|
||||
|
||||
' Check for clicks inside the box to reposition cursor
|
||||
while _mouseinput: wend
|
||||
if _mousebutton(1) then
|
||||
IF (_mousex>x and _mousey>y AND _mousex<x+w AND _mousey<y+h) THEN
|
||||
relativeX=_mousex-x
|
||||
cursor=(relativeX\8)+1
|
||||
|
||||
' Constrain cursor to text boundaries
|
||||
if cursor<1 then cursor=1
|
||||
if cursor>len(text)+1 then cursor=len(text)+1
|
||||
else
|
||||
done=-1 ' Clicked outside, exit focus
|
||||
end if
|
||||
end if
|
||||
drawtextinput x,y,w,h,text,cursor
|
||||
_limit 60
|
||||
_display
|
||||
loop until done
|
||||
|
|
@ -80,39 +70,29 @@ sub drawtextinput (x as integer, y as integer, w as integer, h as integer, text
|
|||
dim outtext as string
|
||||
dim charWidth as integer:charWidth = 8
|
||||
dim cursorX as integer,textX as integer,textY as integer
|
||||
|
||||
if state>0 then
|
||||
color backgroundcolor1
|
||||
else
|
||||
color backgroundcolor2
|
||||
end if
|
||||
line(x,y)-(x+w,y+h),,bf
|
||||
|
||||
if state>0 then
|
||||
color highlightcolor
|
||||
ELSE
|
||||
color textcolor
|
||||
end if
|
||||
line (x, y)-(x + w, y + h), , B
|
||||
line(x,y)-(x+w,y+h),,b
|
||||
_printmode _keepbackground
|
||||
outtext=right$(text,min(w/charWidth,len(text)))
|
||||
textX=2+x
|
||||
textY=1+y+h/2-8
|
||||
_printstring(textX,textY),outtext
|
||||
' --- Cursor Logic ---
|
||||
if state>0 then
|
||||
' Calculate cursor position relative to the visible text
|
||||
' We use (TIMER * 2) to make it blink
|
||||
if int(timer*2) mod 2=0 then
|
||||
' state is the cursor index (1-based)
|
||||
' We need to find where that character is relative to our clipped outtext
|
||||
dim relativeCursor as integer
|
||||
relativeCursor=state-(len(text)-len(outtext))
|
||||
|
||||
' Only draw if the cursor is actually within the visible box
|
||||
if relativeCursor>=1 and relativeCursor<=len(outtext)+1 then
|
||||
cursorX=textX+(relativeCursor-1)*charWidth
|
||||
' Draw a vertical line for the cursor
|
||||
line(cursorX,textY)-(cursorX,textY+14),highlightcolor
|
||||
end if
|
||||
end if
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue