'Just some basic SCREEN 0 stuff to show that we're not messing with our background at all
CLS , 1 'dark blue in screen 0
InBox_Size 150, 150
result$ = InBox$("Input Box", "Generic User Input Goes Here") 'And here's a generic input box!
PRINT "YOU ENTERED ==> "; result$
'And you can see the screen itself was maintained 100% as we had it before, except for the result$
'which we printed after closing the InBox
InBox_Place -1, -1
InBox_Size 300, 300
InBox_Backgrounds
_LOADIMAGE("cemetery.jpg", 32), 0InBox_Frame 3, Gold
InBox_Title
_LOADFONT("courbd.ttf", 32, "monospace"), SkyBlue
, -1, Red
, Blue
InBox_Message
_LOADFONT("courbd.ttf", 24, "monospace"), _LOADIMAGE("marble.jpg", 32), -1, &HFFFF0000&&
, 0InBox_Input
_LOADFONT("courbd.ttf", 18, "monospace"), LightGray
, -1, Red
, Blue
result$ = InBox$("Math Box For Dummies", "Enter some maths!")
PRINT "YOU ENTERED ==> "; result$
AS INTEGER X
, Y
, Wide
, High
, ErrorCode
, Box_Justify_Hort
, Box_Justify_Vert
AS INTEGER TitleFont
, FrameSize
, Title_Xoffset
AS INTEGER InputFont
, Input_Xoffset
, Inbox_Init
AS _INTEGER64 Screen_Background
, Box_Background
, Title_Background
, Message_Background
, Input_Background
AS _UNSIGNED LONG FrameColor
, Title_Font_TextColor
, Title_Font_TextBackColor
'Default Inbox values
InBox_Info.Inbox_Init = -1
InBox_Place -1, -1
InBox_Size 400, 200
InBox_Backgrounds 0, &HFF000000&&
InBox_Frame 3, &HFFFFFFFF&&
InBox_Title 16, &HFF000000&&, -1, &HFFFFFFFF&&, &HFF000000&&
InBox_Message 16, &HFF000000&&, -1, &HFFFFFFFF&&, &HFF000000&&
InBox_Input 16, &HFFD3D3D3&&, -1, &HFF000000&&, 0
IF InBox_Info.Inbox_Init
= 0 THEN Inbox_reset
'InBox_Info.ErrorCode
'1 = Attempting to make box wider than current screen allows.
'2 = Attempting to make box taller than current screen allows.
'3 = Attempting to place box off the left side of the allowable screen.
'4 = Attempting to place box above the top of the allowable screen.
'5 = Attempting to place box off the right side of the allowable screen.
'6 = Attempting to place box below the bottom of the allowable screen.
'7 = Invalid screen background image
'8 = Invalid box background image
'9 = Invalid box frame color
'10 = Invalid title font handle
'11 = Invalid title Xoffset (probably trying to print off the box)
'12 = Invalid message font handle
STATIC AS LONG W
, H
, BPP
, InBox_Software_Handle
'These are defined as STATIC as they're common variable STATIC AS LONG D
, S
' names, and like this they won't interfer with any dummies
REDIM WordWrap
(0) AS STRING ' Redimmable array to hold properly formated word wrap text
InBox_Software_Handle
= _NEWIMAGE(W
, H
, 32) ' Image size for our whole screen
IF InBox_Info.Wide
> W
THEN InBox_Info.ErrorCode
= 1:
GOTO clean_exit
IF InBox_Info.High
> H
THEN InBox_Info.ErrorCode
= 2:
GOTO clean_exit
IF InBox_Info.X
< 0 THEN InBox_Info.ErrorCode
= 3:
GOTO clean_exit
IF InBox_Info.Y
< 0 THEN InBox_Info.ErrorCode
= 4:
GOTO clean_exit
IF InBox_Info.X
> W
- InBox_Info.Wide
THEN InBox_Info.ErrorCode
= 5:
GOTO clean_exit
IF InBox_Info.Y
> H
- InBox_Info.High
THEN InBox_Info.ErrorCode
= 6:
GOTO clean_exit
IF InBox_Info.Screen_Background
= -1 OR InBox_Info.Screen_Background
> &HFFFFFFFF&&
THEN InBox_Info.ErrorCode
= 7:
GOTO clean_exit
IF InBox_Info.Box_Background
= -1 OR InBox_Info.Box_Background
> &HFFFFFFFF&&
THEN InBox_Info.ErrorCode
= 8:
GOTO clean_exit
IF InBox_Info.FrameColor
< 0 OR InBox_Info.FrameColor
> &HFFFFFFFF&&
THEN InBox_Info.ErrorCode
= 9:
GOTO clean_exit
IF InBox_Info.TitleFont
<= 0 THEN InBox_Info.ErrorCode
= 10:
GOTO clean_exit
IF InBox_Info.MessageFont
<= 0 THEN InBox_Info.ErrorCode
= 12:
GOTO clean_exit
IF InBox_Info.Box_Justify_Hort
THEN InBox_Info.X
= (W
- InBox_Info.Wide
) \
2 IF InBox_Info.Box_Justify_Vert
THEN InBox_Info.Y
= (H
- InBox_Info.High
) \
2 InBox_Info.Title = Title: InBox_Info.Message = Prompt
'Stuff which we only draw once
'This is the background for the whole screen, which we can use to cover up the original
IF InBox_Info.Screen_Background
< -1 THEN _PUTIMAGE (0, 0)-(W
, H
), InBox_Info.Screen_Background
CLS , InBox_Info.Screen_Background
'This is the background for the box itself. Color or image, it doesn't matter.
IF InBox_Info.Box_Background
< -1 THEN _PUTIMAGE (InBox_Info.X
, InBox_Info.Y
)-STEP(InBox_Info.Wide
, InBox_Info.High
), InBox_Info.Box_Background
LINE (InBox_Info.X
, InBox_Info.Y
)-STEP(InBox_Info.Wide
, InBox_Info.High
), InBox_Info.Box_Background
, BF
'This draws the frame around the whole box.
FOR I
= 0 TO InBox_Info.FrameSize
- 1 LINE (InBox_Info.X
+ I
, InBox_Info.Y
+ I
)-STEP(InBox_Info.Wide
- 2 * I
, InBox_Info.High
- 2 * I
), InBox_Info.FrameColor
, B
'and here we gather our information on what parts of the box is left for us to draw/write inside.
top = InBox_Info.Y + I: left = InBox_Info.X + I: right = left + InBox_Info.Wide - 2 * I: bottom = top + InBox_Info.High - 2 * I
'***************************************** START TITLE *****************************************
'This checks to make certain that our title is short enough to fit onto the screen
_FONT InBox_Info.TitleFont
T2WWA InBox_Info.Title, right - left, WordWrap()
'I'm only allowing for the title to use up to a maximum of 1/3 of our total display area.
IF totalprintarea
> (bottom
- top
) / 3 THEN 'more than that, and we toss an error. InBox_Info.ErrorCode
= 11:
GOTO clean_exit
'This is the background for the title area. Color or image, it doesn't matter.
IF InBox_Info.Title_Background
< -1 THEN _PUTIMAGE (left
, top
)-(right
, top
+ totalprintarea
), InBox_Info.Title_Background
LINE (left
, top
)-(right
, top
+ totalprintarea
), InBox_Info.Title_Background
, BF
'and here, we print the title, depending on its offset/justification
COLOR InBox_Info.Title_Font_TextColor
, InBox_Info.Title_Font_TextBackColor
Xoffset = InBox_Info.Title_Xoffset
'****************************************** END TITLE ******************************************
'************************************************************************************************
'**************************************** START MESSAGE ****************************************
'This checks to make certain that our message is short enough to fit onto the screen
_FONT InBox_Info.MessageFont
T2WWA InBox_Info.Message, right - left, WordWrap()
'I'm only allowing for the prompt message to use up to a maximum of 1/2 of our remaining display area.
IF totalprintarea
> (bottom
- top
) / 2 THEN 'more than that, and we toss an error. InBox_Info.ErrorCode
= 11:
GOTO clean_exit
'This is the background for the message area. Color or image, it doesn't matter.
IF InBox_Info.Message_Background
< -1 THEN _PUTIMAGE (left
, top
)-(right
, bottom
), InBox_Info.Message_Background
LINE (left
, top
)-(right
, bottom
), InBox_Info.Message_Background
, BF
'and here, we print the message prompt, depending on its offset/justification
COLOR InBox_Info.Message_Font_TextColor
, InBox_Info.Message_Font_TextBackColor
Xoffset = InBox_Info.Message_Xoffset: EE = -1
'***************************************** END MESSAGE *****************************************
'************************************************************************************************
'***************************************** START INPUT *****************************************
left = left + 5: right = right - 5 '5 pixel area all around
'This is the background for the input area. Color or image, it doesn't matter.
maxrows = (bottom - top - 20) \ fh
maxcolumns = (right - left) \ fw
maxcharacters = maxrows * maxcolumns - 1 'for cursor
maxcharacters = 65534
absolutemax = (65535 \ fh) * maxcolumns
IF absolutemax
< maxcharacters
THEN maxcharacters
= absolutemax
left_right_offset = (right - left - maxcolumns * fw) \ 2
left = left + left_right_offset
right = right - left_right_offset
top = bottom - (maxrows + 1) * fh - 2
IF InBox_Info.Input_Background
< -1 THEN _PUTIMAGE (left
, top
)-(right
, bottom
- 20), InBox_Info.Input_Background
LINE (left
, top
)-(right
, bottom
- 20), InBox_Info.Input_Background
, BF
Inbox_Software_Handle2
= _NEWIMAGE(right
- left
, bottom
- top
, 32) Inbox_Software_Handle3
= _NEWIMAGE(right
- left
, 65535, 32) Inbox_Software_Handle4
= _NEWIMAGE(right
- left
, 20, 32) _DEST Inbox_Software_Handle3:
_SOURCE Inbox_Software_Handle3
'****************************************** END INPUT ******************************************
Inbox_Hardware_Handle
= _COPYIMAGE(InBox_Software_Handle
, 33)
SELECT CASE k
'ignore all keypresses except ALT-number presses CASE 48 TO 57: AltWasDown
= -1: alt$
= alt$
+ CHR$(k
) SELECT CASE k
'without alt, add any keypresses to our input oldin$ = in$
IF CP
> 0 THEN OldCP
= CP: CP
= CP
- 1 in$
= LEFT$(in$
, CP
) + MID$(in$
, CP
+ 2) 'backspace to erase input oldin$ = in$
in$
= LEFT$(in$
, CP
) + SPACE$(4) + MID$(in$
, CP
+ 1) 'four spaces for any TAB entered OldCP = CP
CP = CP + 4
oldin$ = in$
'CTRL-V leaves cursor in position before the paste, without moving it after.
'Feel free to modify that behavior here, if you want it to move to after the paste.
oldin$ = in$
in$
= LEFT$(in$
, CP
) + CHR$(k
) + MID$(in$
, CP
+ 1) 'add input to our string OldCP = CP
CP = CP + 1
CP = 0
oldin$ = in$
CP = CP - 1
CP = CP + 1
alt$ = "": AltWasDown = 0
blink
= (blink
+ 1) MOD 30
in$
= LEFT$(in$
, maxcharacters
) ' a limit, for now, of no more characters than the screen can hold IF CP
>= maxcharacters
THEN CP
= maxcharacters
'part of the temporary limit _DEST Inbox_Software_Handle2:
_SOURCE Inbox_Software_Handle2
_DEST Inbox_Software_Handle3:
_SOURCE Inbox_Software_Handle3
COLOR InBox_Info.Input_Font_TextColor
, InBox_Info.Input_Font_TextBackColor
_FONT InBox_Info.InputFont
IF blink \
15 THEN blinker$
= " " ELSE blinker$
= "_"
_DEST Inbox_Software_Handle4:
_SOURCE Inbox_Software_Handle4
COLOR &HAAFFFFFF&&
, &H77000000&&
Inbox_Hardware_Handle3
= _COPYIMAGE(Inbox_Software_Handle4
, 33)
top_visible = CP \ maxcolumns - maxrows + 1
top_visible = (CP + 1) \ maxcolumns - maxrows + 1
IF top_visible
< 0 THEN top_visible
= 0
_PUTIMAGE (0, 0)-(right
, bottom
), Inbox_Software_Handle3
,_
Inbox_Software_Handle2
, (0, top_visible
* fh
)-STEP(right
, bottom
) Inbox_Hardware_Handle2
= _COPYIMAGE(Inbox_Software_Handle2
, 33) _PUTIMAGE (left
, top
)-(right
, bottom
), Inbox_Hardware_Handle2
_PUTIMAGE (right
- _WIDTH(Inbox_Software_Handle4
), bottom
- 18)-STEP(_WIDTH(Inbox_Software_Handle4
), 20), Inbox_Hardware_Handle3
clean_exit:
InBox$ = in$
Printout:
'This is where we print actual lines to the inbox display
'update the available screen positions
IF EE
THEN EE
= 0:
RETURN 'Exit Early code to avoid drawing the frame
'draw the frame again, below the title
LINE (left
, top
)-(right
, top
+ InBox_Info.FrameSize
), InBox_Info.FrameColor
, BF
'update the available screen positons once again
top = top + InBox_Info.FrameSize
IF InBox_Info.Inbox_Init
= 0 THEN Inbox_reset
InBox_Info.X = 0
InBox_Info.Box_Justify_Hort = -1
InBox_Info.X = x
InBox.Box_Justify_Hort = 0
InBox_Info.Y = 0
InBox_Info.Box_Justify_Vert = -1
InBox_Info.Y = y
InBox_Info.Box_Justify_Vert = 0
IF InBox_Info.Inbox_Init
= 0 THEN Inbox_reset
InBox_Info.Wide = wide
InBox_Info.High = high
IF InBox_Info.Inbox_Init
= 0 THEN Inbox_reset
InBox_Info.Screen_Background = Screen_background
InBox_Info.Box_Background = Box_background
IF InBox_Info.Inbox_Init
= 0 THEN Inbox_reset
InBox_Info.FrameColor = kolor
InBox_Info.FrameSize = size
SUB InBox_Title
(font%
, background&&
, xOffset%
, fc~&
, fbg~&
) IF InBox_Info.Inbox_Init
= 0 THEN Inbox_reset
InBox_Info.TitleFont = font%
InBox_Info.Title_Background = background&&
InBox_Info.Title_Xoffset = xOffset%
InBox_Info.Title_Font_TextColor = fc~&
InBox_Info.Title_Font_TextBackColor = fbg~&
SUB InBox_Message
(font%
, background&&
, xOffset%
, fc~&
, fbg~&
) IF InBox_Info.Inbox_Init
= 0 THEN Inbox_reset
InBox_Info.MessageFont = font%
InBox_Info.Message_Background = background&&
InBox_Info.Message_Xoffset = xOffset%
InBox_Info.Message_Font_TextColor = fc~&
InBox_Info.Message_Font_TextBackColor = fbg~&
SUB InBox_Input
(font%
, background&&
, xOffset%
, fc~&
, fbg~&
) IF InBox_Info.Inbox_Init
= 0 THEN Inbox_reset
InBox_Info.InputFont = font%
InBox_Info.Input_Background = background&&
InBox_Info.Input_Xoffset = xOffset%
InBox_Info.Input_Font_TextColor = fc~&
InBox_Info.Input_Font_TextBackColor = fbg~&
SUB T2WWA
(temp$
, wide%
, result
() AS STRING) 'Text To Word Wrap Array BreakPoint = ",./- ;:!" 'I consider all these to be valid breakpoints. If you want something else, change them.
'first find the natural length of the line
lineend = i - 1
t$
= RTRIM$(LEFT$(text$
, lineend
)) 'at most, our line can't be any longer than what fits the screen. count = count + 1
clean_exit: