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
122
include/ui.bm
122
include/ui.bm
|
|
@ -1,119 +1,99 @@
|
||||||
function textinput$ (x as integer, y as integer, w as integer, h as integer, __text as string)
|
function textinput$ (x as integer,y as integer,w as integer,h as integer,__text as string)
|
||||||
dim text as string, keyin as string
|
dim text as string, keyin as string
|
||||||
dim cursor as integer, done as integer
|
dim cursor as integer, done as integer
|
||||||
text = __text
|
text=__text
|
||||||
' Initial Hover Check
|
if not (_mousex>x and _mousey>y AND _mousex<x+w AND _mousey<y+h) then
|
||||||
if not (_mousex > x and _mousey > y AND _mousex < x + w AND _mousey < y + h) then
|
drawtextinput x,y,w,h,__text,0
|
||||||
drawtextinput x, y, w, h, __text, 0
|
|
||||||
exit function
|
exit function
|
||||||
end if
|
end if
|
||||||
|
drawtextinput x,y,w,h,__text,1
|
||||||
drawtextinput x, y, w, h, __text, 1
|
|
||||||
if not mouseclicked then exit function
|
if not mouseclicked then exit function
|
||||||
text=""
|
text=""
|
||||||
cursor = len(text) + 1
|
cursor=len(text)+1
|
||||||
dim relativeX as integer
|
dim relativeX as integer
|
||||||
do
|
do
|
||||||
keyin = inkey$
|
keyin=inkey$
|
||||||
|
if len(keyin)=2 then
|
||||||
' Handle Extended Keys (Arrows, Home, End, Delete)
|
select case asc(right$(keyin,1))
|
||||||
if len(keyin) = 2 then
|
|
||||||
select case asc(right$(keyin, 1))
|
|
||||||
case 75 ' Left Arrow
|
case 75 ' Left Arrow
|
||||||
if cursor > 1 then cursor = cursor - 1
|
if cursor>1 then cursor=cursor-1
|
||||||
case 77 ' Right Arrow
|
case 77 ' Right Arrow
|
||||||
if cursor <= len(text) then cursor = cursor + 1
|
if cursor<=len(text) then cursor=cursor+1
|
||||||
case 71 ' Home Key
|
case 71 ' Home Key
|
||||||
cursor = 1
|
cursor=1
|
||||||
case 79 ' End Key
|
case 79 ' End Key
|
||||||
cursor = len(text) + 1
|
cursor=len(text)+1
|
||||||
case 83 ' Delete Key
|
case 83 ' Delete Key
|
||||||
if cursor <= len(text) then
|
if cursor<=len(text) then
|
||||||
text = left$(text, cursor - 1) + mid$(text, cursor + 1)
|
text=left$(text,cursor-1)+mid$(text,cursor+1)
|
||||||
end if
|
end if
|
||||||
end select
|
end select
|
||||||
elseif LEN(keyin) = 1 then
|
elseif LEN(keyin)=1 then
|
||||||
select case asc(keyin)
|
select case asc(keyin)
|
||||||
case 22 ' Ctrl + V (Paste)
|
case 22 ' Ctrl + V (Paste)
|
||||||
text = left$(text, cursor - 1) + _clipboard$ + mid$(text, cursor)
|
text=left$(text,cursor-1)+_clipboard$+mid$(text,cursor)
|
||||||
cursor = cursor + len(pasteData)
|
cursor=cursor+len(pasteData)
|
||||||
case 32 to 126 ' Regular Typing
|
case 32 to 126 ' Regular Typing
|
||||||
text = left$(text, cursor - 1) + keyin + mid$(text, cursor)
|
text=left$(text,cursor-1)+keyin+mid$(text,cursor)
|
||||||
cursor = cursor + 1
|
cursor=cursor+1
|
||||||
case 8 ' Backspace
|
case 8 ' Backspace
|
||||||
if cursor > 1 THEN
|
if cursor>1 THEN
|
||||||
text = left$(text, cursor - 2) + mid$(text, cursor)
|
text=left$(text,cursor-2)+mid$(text,cursor)
|
||||||
cursor = cursor - 1
|
cursor=cursor-1
|
||||||
end if
|
end if
|
||||||
case 13 ' Enter
|
case 13 ' Enter
|
||||||
done = -1
|
done=-1
|
||||||
case 27 ' Escape (Cancel)
|
case 27 ' Escape (Cancel)
|
||||||
text = __text
|
text=__text
|
||||||
done = -1
|
done=-1
|
||||||
end select
|
end select
|
||||||
end if
|
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
|
while _mouseinput: wend
|
||||||
if _mousebutton(1) then
|
if _mousebutton(1) then
|
||||||
IF (_mousex > x and _mousey > y AND _mousex < x + w AND _mousey < y + h) THEN
|
IF (_mousex>x and _mousey>y AND _mousex<x+w AND _mousey<y+h) THEN
|
||||||
relativeX = _mousex - x
|
relativeX=_mousex-x
|
||||||
cursor = (relativeX \ 8) + 1
|
cursor=(relativeX\8)+1
|
||||||
|
if cursor<1 then cursor=1
|
||||||
' Constrain cursor to text boundaries
|
if cursor>len(text)+1 then cursor=len(text)+1
|
||||||
if cursor < 1 then cursor = 1
|
|
||||||
if cursor > len(text) + 1 then cursor = len(text) + 1
|
|
||||||
else
|
else
|
||||||
done = -1 ' Clicked outside, exit focus
|
done=-1 ' Clicked outside, exit focus
|
||||||
end if
|
end if
|
||||||
end if
|
end if
|
||||||
|
drawtextinput x,y,w,h,text,cursor
|
||||||
_limit 60
|
_limit 60
|
||||||
_display
|
_display
|
||||||
loop until done
|
loop until done
|
||||||
textinput = text
|
textinput=text
|
||||||
end function
|
end function
|
||||||
|
|
||||||
sub drawtextinput (x as integer, y as integer, w as integer, h as integer, text as string, state as integer)
|
sub drawtextinput (x as integer,y as integer,w as integer,h as integer,text as string,state as integer)
|
||||||
dim outtext as string
|
dim outtext as string
|
||||||
dim charWidth as integer: charWidth = 8
|
dim charWidth as integer:charWidth = 8
|
||||||
dim cursorX as integer, textX as integer, textY as integer
|
dim cursorX as integer,textX as integer,textY as integer
|
||||||
|
if state>0 then
|
||||||
if state > 0 then
|
|
||||||
color backgroundcolor1
|
color backgroundcolor1
|
||||||
else
|
else
|
||||||
color backgroundcolor2
|
color backgroundcolor2
|
||||||
end if
|
end if
|
||||||
line (x, y)-(x + w, y + h), , bf
|
line(x,y)-(x+w,y+h),,bf
|
||||||
|
if state>0 then
|
||||||
if state > 0 then
|
|
||||||
color highlightcolor
|
color highlightcolor
|
||||||
ELSE
|
ELSE
|
||||||
color textcolor
|
color textcolor
|
||||||
end if
|
end if
|
||||||
line (x, y)-(x + w, y + h), , B
|
line(x,y)-(x+w,y+h),,b
|
||||||
_printmode _keepbackground
|
_printmode _keepbackground
|
||||||
outtext = right$(text, min(w / charWidth, len(text)))
|
outtext=right$(text,min(w/charWidth,len(text)))
|
||||||
textX = 2 + x
|
textX=2+x
|
||||||
textY = 1 + y + h / 2 - 8
|
textY=1+y+h/2-8
|
||||||
_printstring (textX, textY), outtext
|
_printstring(textX,textY),outtext
|
||||||
' --- Cursor Logic ---
|
if state>0 then
|
||||||
if state > 0 then
|
if int(timer*2) mod 2=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
|
dim relativeCursor as integer
|
||||||
relativeCursor = state - (len(text) - len(outtext))
|
relativeCursor=state-(len(text)-len(outtext))
|
||||||
|
if relativeCursor>=1 and relativeCursor<=len(outtext)+1 then
|
||||||
' Only draw if the cursor is actually within the visible box
|
cursorX=textX+(relativeCursor-1)*charWidth
|
||||||
if relativeCursor >= 1 and relativeCursor <= len(outtext) + 1 then
|
line(cursorX,textY)-(cursorX,textY+14),highlightcolor
|
||||||
cursorX = textX + (relativeCursor - 1) * charWidth
|
|
||||||
' Draw a vertical line for the cursor
|
|
||||||
line (cursorX, textY)-(cursorX, textY + 14), highlightcolor
|
|
||||||
end if
|
end if
|
||||||
end if
|
end if
|
||||||
end if
|
end if
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue