code was shouting

This commit is contained in:
visionmercer 2026-05-01 12:23:46 +02:00
commit 1e43bd8614

View file

@ -1,136 +1,128 @@
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 ' 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$
' Handle Extended Keys (Arrows, Home, End, Delete) ' Handle Extended Keys (Arrows, Home, End, Delete)
IF LEN(keyin) = 2 THEN if len(keyin) = 2 then
SELECT CASE ASC(RIGHT$(keyin, 1)) 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 ' Send the cursor position to your drawing routine
drawtextinput x, y, w, h, text, cursor drawtextinput x, y, w, h, text, cursor
' Check for clicks inside the box to reposition 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 _MOUSEX <= x + w AND _MOUSEY >= y 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
' Constrain cursor to text boundaries ' Constrain cursor to text boundaries
IF cursor < 1 THEN cursor = 1 if cursor < 1 then cursor = 1
IF cursor > LEN(text) + 1 THEN cursor = LEN(text) + 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
_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 ' Standard font width 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
' Background Drawing if state > 0 then
IF state > 0 THEN ' If state is cursor pos, it's "active" color backgroundcolor1
COLOR backgroundcolor1 else
color backgroundcolor2
end if
line (x, y)-(x + w, y + h), , bf
if state > 0 then
color highlightcolor
ELSE ELSE
COLOR backgroundcolor2 color textcolor
END IF end if
LINE (x, y)-(x + w, y + h), , BF line (x, y)-(x + w, y + h), , B
_printmode _keepbackground
' Border Drawing outtext = right$(text, min(w / charWidth, len(text)))
IF state > 0 THEN textX = 2 + x
COLOR highlightcolor
ELSE
COLOR textcolor
END IF
LINE (x, y)-(x + w, y + h), , B
' Text Alignment Calculation
_PRINTMODE _KEEPBACKGROUND
' We keep your original logic for scrolling/clipping text
outtext = RIGHT$(text, MIN(w / charWidth, LEN(text)))
' Calculate the starting X/Y for the text to center it
textX = 2 + x' + w / 2 - LEN(outtext) * charWidth / 2
textY = 1 + y + h / 2 - 8 textY = 1 + y + h / 2 - 8
_printstring (textX, textY), outtext
_PRINTSTRING (textX, textY), outtext
' --- Cursor Logic --- ' --- Cursor Logic ---
IF state > 0 THEN if state > 0 then
' Calculate cursor position relative to the visible text ' Calculate cursor position relative to the visible text
' We use (TIMER * 2) to make it blink ' We use (TIMER * 2) to make it blink
IF INT(TIMER * 2) MOD 2 = 0 THEN if int(timer * 2) mod 2 = 0 then
' state is the cursor index (1-based) ' state is the cursor index (1-based)
' We need to find where that character is relative to our clipped outtext ' 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))
' Only draw if the cursor is actually within the visible box ' Only draw if the cursor is actually within the visible box
IF relativeCursor >= 1 AND relativeCursor <= LEN(outtext) + 1 THEN if relativeCursor >= 1 and relativeCursor <= len(outtext) + 1 then
cursorX = textX + (relativeCursor - 1) * charWidth cursorX = textX + (relativeCursor - 1) * charWidth
' Draw a vertical line for the cursor ' Draw a vertical line for the cursor
LINE (cursorX, textY)-(cursorX, textY + 14), highlightcolor line (cursorX, textY)-(cursorX, textY + 14), highlightcolor
END IF end if
END IF end if
END IF end if
END SUB end sub
function min(a,b) function min(a,b)
if a<=b then min=a else min=b if a<=b then min=a else min=b
end function end function
function button (x as integer,y as integer,w as integer,h as integer,caption as string) function button (x as integer,y as integer,w as integer,h as integer,caption as string)
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
drawbutton x,y,w,h,caption,1 drawbutton x,y,w,h,caption,1