'*****************************
' TEXT FRAMES LIBRARY CODE
'*****************************
CONST True
= -1, False
= 0 CONST LeftJustify
= -1, CenterJustify
= -2, RightJustify
= -3, NoJustify
= 0 CONST OnLine
= 0, CenterLine
= -1, TopLine
= 1, BottomLine
= -2 CONST NoUpdate
= 0, DoUpdate
= 1, NewLine
= 2
'**********************************
'* PROGRAM CODE
'**********************************
CONST FileName$
= "tt.txt"
SearchTerms(0) = "TRICK": SearchTerms(1) = "TREAT"
SCREEN _NEWIMAGE(1280, 720, 32) '720p HD just cause I like it as a standard
LeftFrame
= NewTextArea
(0, 0, 400, _HEIGHT - 1, False
)ColorTextArea LeftFrame
, _RGB32(255, 255, 255), _RGB32(0, 0, 128)DrawTextArea LeftFrame
ColorTextArea RightFrame
, _RGB32(255, 255, 255), _RGB32(0, 0, 0)DrawTextArea RightFrame
LoadWordGrid
MakeDirectional
ShowGrid
FindWords
PrintOut RightFrame, "SEARCHING FOR " + SearchTerms(j)
PrintOut RightFrame, ""
PrintOut RightFrame, "Finding Left to Right Matches"
foundone = 0
foundone
= INSTR(foundone
+ 1, YLines
(1, i
), SearchTerms
(j
)) out$
= out$
+ "(Line" + STR$(i
) + ", Position" + STR$(foundone
) + "), " tc = tc + 1
PrintOut RightFrame
, out$
PrintOut RightFrame, ""
PrintOut RightFrame, "Finding Right to Left Matches"
foundone = 0
foundone
= INSTR(foundone
+ 1, YLines
(2, i
), SearchTerms
(j
)) out$
= out$
+ "(Line" + STR$(i
) + ", Position" + STR$(X
- foundone
+ 1) + "), " tc = tc + 1
PrintOut RightFrame
, out$
PrintOut RightFrame, ""
PrintOut RightFrame, "Finding Up to Down Matches"
foundone = 0
foundone
= INSTR(foundone
+ 1, XLines
(1, i
), SearchTerms
(j
)) out$
= out$
+ "(Line" + STR$(foundone
) + ", Position" + STR$(i
) + "), " tc = tc + 1
PrintOut RightFrame
, out$
PrintOut RightFrame, ""
PrintOut RightFrame, "Finding Down to Up Matches"
foundone = 0
foundone
= INSTR(foundone
+ 1, XLines
(2, i
), SearchTerms
(j
)) out$
= out$
+ "(Line" + STR$(foundone
) + ", Position" + STR$(i
) + "), " tc = tc + 1
PrintOut RightFrame
, out$
PrintOut RightFrame, ""
PrintOut RightFrame, ""
PrintOut RightFrame
, STR$(tc
) + " total matches found." PrintOut RightFrame, ""
PrintOut RightFrame, ""
tc = 0
'Print the words in the grid
SetTextColor LeftFrame
, _RGB32(255, 255, 0), 0 PrintOut LeftFrame, ""
PrintOut LeftFrame, " WORD GRID"
PrintOut LeftFrame, ""
SetTextColor LeftFrame
, _RGB32(255, 255, 255), 0 PrintOut LeftFrame, " " + YLines(1, i)
Y = Y + 1
WordGrid
(j
, i
) = MID$(junk$
, j
) 'Fill in the grid with the letters
YLines(1, i) = YLines(1, i) + WordGrid(j, i) 'Left to Right Lines
YLines(2, i) = YLines(2, i) + WordGrid(j, i) 'Right to Left Lines
XLines(1, i) = XLines(1, i) + WordGrid(j, i) 'Up to Down Lines
XLines(2, i) = XLines(1, i) + WordGrid(j, i) 'Right to Left Lines
'*****************************
' TEXT FRAMES LIBRARY CODE
'*****************************
Handle = WhichHandle
Where = TextHandles(Handle).VerticalAlignment
How = TextHandles(Handle).Justification
UpdatePrintPosition = TextHandles(Handle).UpdateMethod
PlaceText Handle, Where, How, What, UpdatePrintPosition
'WhichHandle is the handle which designates which text area we want to use
'Where is where we want it to go in that text area
' -- Online prints the text to the current print position line in that text area.
' -- CenterLine centers the text to the center of that text area.
' -- any other value will print to that line positon in that particular box.
'How tells us how we want to place that text (LeftJustified, RightJustified,CenterJustified, or NoJustify)
'What is the text that we want to print in our text area
'UpdatePrintPosition lets us know if we need to move to a newline or stay on the same line. (Think PRINT with a semicolon vs PRINT without a semicolon).
Handle = WhichHandle
IF TextHandles
(Handle
).HideFrame
THEN _DEST TextHandles
(Handle
).SavedBackground
_SOURCE TextHandles
(Handle
).SavedBackground
h = TextHandles(Handle).h - 4
w = TextHandles(Handle).w - 4
TextFrameY = h \ fh
TextFrameY = TextHandles(Handle).Ypos
IF TextFrameY
= 0 THEN TextFrameY
= 1 linesused = 0
tpw = pw: tw = w: tWhat$ = What
linesused = linesused + 1
tWhat$
= MID$(tWhat$
, textallowed
+ 1) linesused = linesused + 1
py = (h - linesused * fh) \ 2
TextFrameY = py \ fh + 1
IF TextFrameY
< 1 THEN TextFrameY
= 1 TextFrameY = Where
DO UNTIL TextFrameY
* fh
< h
'We need to scroll the text area up, if someone is trying to print below it. 'first let's get a temp image handle for the existing area of the screen.
x1 = TextHandles(Handle).x1 + 2
y1 = TextHandles(Handle).y1 + 2
x2 = TextHandles(Handle).x1 + w
y2 = TextHandles(Handle).y1 + h
nh = y2 - y1 + 1 - fh
nw = x2 - x1 + 1
tempimage
= _NEWIMAGE(nw
, nh
, 32) 'Really, I should swap this to a routine to pick which screen mode the user is in, but I'll come back to that later. _PUTIMAGE , , tempimage
, (x1
, y1
+ fh
)-(x2
, y2
) DrawTextArea Handle
TextFrameY = TextFrameY - 1
COLOR TextHandles
(Handle
).TextColor
, TextHandles
(Handle
).TextBackgroundColor
TextFrameX = 0
_PRINTSTRING (TextFrameX
+ 2 + TextHandles
(Handle
).x1
, (TextFrameY
- 1) * fh
+ TextHandles
(Handle
).y1
+ 2), text$
PlaceText Handle
, TextFrameY
+ 1, LeftJustify
, MID$(What
, textallowed
+ 1), 0 _PRINTSTRING (TextFrameX
+ 2 + TextHandles
(Handle
).x1
, (TextFrameY
- 1) * fh
+ TextHandles
(Handle
).y1
+ 2), What
finished = -1
_PRINTSTRING (TextFrameX
+ 2 + TextHandles
(Handle
).x1
, (TextFrameY
- 1) * fh
+ TextHandles
(Handle
).y1
+ 2), text$
PlaceText Handle
, TextFrameY
+ 1, CenterJustify
, MID$(What
, textallowed
+ 1), NoUpdate
TextFrameX = (w - pw) \ 2
_PRINTSTRING (TextFrameX
+ 2 + TextHandles
(Handle
).x1
, (TextFrameY
- 1) * fh
+ TextHandles
(Handle
).y1
+ 2), What
finished = -1
_PRINTSTRING (TextFrameX
+ 2 + TextHandles
(Handle
).x1
, (TextFrameY
- 1) * fh
+ TextHandles
(Handle
).y1
+ 2), text$
PlaceText Handle
, TextFrameY
+ 1, RightJustify
, MID$(What
, textallowed
+ 1), 0 TextFrameX = w - pw
_PRINTSTRING (TextFrameX
+ 2 + TextHandles
(Handle
).x1
, (TextFrameY
- 1) * fh
+ TextHandles
(Handle
).y1
+ 2), What
finished = -1
TextFrameX = TextHandles(Handle).Xpos
firstlinelimit
= (w
- TextFrameX
) \
_FONTWIDTH 'the limit of characters on the first line textallowed
= WordBreak
(LEFT$(What
, firstlinelimit
)) _PRINTSTRING (TextFrameX
+ 2 + TextHandles
(Handle
).x1
, (TextFrameY
- 1) * fh
+ TextHandles
(Handle
).y1
+ 2), text$
PlaceText Handle
, TextFrameY
+ 1, LeftJustify
, MID$(What
, textallowed
+ 1), 0 'After the first line we start printing over on the left, after a line break _PRINTSTRING (TextFrameX
+ 2 + TextHandles
(Handle
).x1
, (TextFrameY
- 1) * fh
+ TextHandles
(Handle
).y1
+ 2), What
finished = -1
CASE NoUpdate
'We don't update the position at all. TextHandles(Handle).Xpos = TextFrameX + pw
TextHandles(Handle).Ypos = TextFrameY
TextHandles(Handle).Ypos = TextFrameY + 1
TextHandles(Handle).Xpos = 1
TextHandles(Handle).TextColor = Foreground
TextHandles(Handle).TextBackgroundColor = Background
TextHandles(Handle).TextColor = Foreground
TextHandles(Handle).TextBackgroundColor = Background
TextHandles(Handle).UpdateMethod = Method
TextHandles(Handle).VerticalAlignment = -2
TextHandles(Handle).VerticalAlignment = -1
TextHandles(Handle).VerticalAlignment = 0
TextHandles(Handle).Justification = TextFrameX
TextHandles(Handle).Xpos = TextFrameX
TextHandles(Handle).Ypos = TextFrameY
TextHandles(Handle).Justification = TextFrameX
TextHandles(Handle).Xpos = TextFrameX
TextHandles(Handle).VerticalAlignment = -2
TextHandles(Handle).VerticalAlignment = -1
TextHandles(Handle).VerticalAlignment = 0
TextHandles(Handle).Ypos = TextFrameY
GetPrintPositionY = TextHandles(Handle).Ypos
GetPrintPositionX = TextHandles(Handle).Xpos
loopcount = loopcount + 1
WordBreak = i
IF TextHandles
(Handle
).SavedBackground
THEN w = TextHandles(Handle).w
h = TextHandles(Handle).h
x1 = TextHandles(Handle).ScreenX
y1 = TextHandles(Handle).ScreenY
x2 = x1 + w - 1
y2 = y1 + h - 1
_PUTIMAGE (x1
, y1
)-(x2
, y2
), TextHandles
(Handle
).SavedBackground
DrawTextArea Handle
w = TextHandles(Handle).w
h = TextHandles(Handle).h
x1 = TextHandles(Handle).ScreenX
y1 = TextHandles(Handle).ScreenY
x2 = x1 + w - 1
y2 = y1 + h - 1
LINE (x1
, y1
)-(x2
, y2
), TextHandles
(Handle
).BackColor
, BF
LINE (x1
, y1
)-(x2
, y2
), TextHandles
(Handle
).FrameColor
, B
TextHandles(Handle).FrameColor = FrameColor
TextHandles(Handle).BackColor = BackColor
x1 = tx1: y1 = ty1 'We pass temp variables to the function so we can swap values if needed without altering user variables
x2 = tx2: y2 = ty2
w = x2 - x1 + 1
h = y2 - y1 + 1
'Error checking for if the user sends coordinates which are off the screen
FOR i
= 1 TO u
'First let's check to see if we have an open handle from where one was freed earlier IF Handle
= 0 THEN 'We didn't have an open spot, so we need to add one to our list Handle = u + 1
TextHandles(Handle).x1 = x1
TextHandles(Handle).y1 = y1
TextHandles(Handle).w = w: TextHandles(Handle).h = h
TextHandles(Handle).InUse = True
TextHandles(Handle).Xpos = 0
TextHandles(Handle).Ypos = 1
TextHandles(Handle).UpdateMethod = NewLine
TextHandles
(Handle
).TextColor
= _RGB32(255, 255, 255) 'White text TextHandles
(Handle
).TextBackgroundColor
= _RGB32(0, 0, 0) 'Black background
_PUTIMAGE , 0, imagehandle
, (x1
, y1
)-(x2
, y2
) TextHandles(Handle).SavedBackground = imagehandle
TextHandles(Handle).ScreenX = x1
TextHandles(Handle).ScreenY = y1
NewTextArea% = Handle
IF TextHandles
(Handle
).InUse
THEN TextHandles(Handle).InUse = False
IF TextHandles
(Handle
).SavedBackground
THEN IF TextHandles
(Handle
).HideFrame
= 0 THEN 'If the frame isn't hidden, then restore what's supposed to be beneath it w = TextHandles(Handle).w
h = TextHandles(Handle).h
x1 = TextHandles(Handle).ScreenX
y1 = TextHandles(Handle).ScreenY
x2 = x1 + w - 1
y2 = y1 + h - 1
_PUTIMAGE (x1
, y1
)-(x2
, y2
), TextHandles
(Handle
).SavedBackground
'Even if it is hidden though, if we're going to free that frame, we need to free the stored image held with it to reduce memory usage.
ERROR 258 'Invalid handle if the user tries to free a handle which has already been freed. ERROR 5 'Illegal function call if the user tries to free a handle that doesn't exist at all.
IF TextHandles
(Handle
).HideFrame
= 0 THEN 'only if the frame isn't hidden, can we hide it. TextHandles(Handle).HideFrame = -1
w = TextHandles(Handle).w
h = TextHandles(Handle).h
x1 = TextHandles(Handle).ScreenX
y1 = TextHandles(Handle).ScreenY
x2 = x1 + w - 1
y2 = y1 + h - 1
imagehandle
= _NEWIMAGE(TextHandles
(Handle
).w
, TextHandles
(Handle
).h
, 32) _PUTIMAGE , 0, imagehandle
, (x1
, y1
)-(x2
, y2
) IF TextHandles
(Handle
).SavedBackground
THEN _PUTIMAGE (x1
, y1
)-(x2
, y2
), TextHandles
(Handle
).SavedBackground
TextHandles(Handle).SavedBackground = imagehandle
TextHandles(Handle).x1 = 0 'When the frames are hidden, we calculate our print position based off the hidden image
TextHandles(Handle).y1 = 0 'So we'd start at point (0,0) as being top left
IF TextHandles
(Handle
).HideFrame
THEN 'only if we have a hidden frame do we have to worry about restoring it TextHandles(Handle).HideFrame = 0
w = TextHandles(Handle).w
h = TextHandles(Handle).h
x1 = TextHandles(Handle).ScreenX
y1 = TextHandles(Handle).ScreenY
x2 = x1 + w - 1
y2 = y1 + h - 1
imagehandle
= _NEWIMAGE(TextHandles
(Handle
).w
, TextHandles
(Handle
).h
, 32) _PUTIMAGE , 0, imagehandle
, (x1
, y1
)-(x2
, y2
) _PUTIMAGE (x1
, y1
)-(x2
, y2
), TextHandles
(Handle
).SavedBackground
', 0, (0, 0)-(w, h) TextHandles(Handle).SavedBackground = imagehandle
TextHandles(Handle).x1 = x1 'When the frames are frames are restored, we need to recalculate our print position
TextHandles(Handle).y1 = y1 'as we're no longer going over the image cooridinates, but the screen location of the top left corner instead.
'Only two coordinates here, so we'll be positioning our frames new movement by the top left corner.
HideFrame Handle
TextHandles(Handle).ScreenX = x1
TextHandles(Handle).ScreenY = y1
RestoreFrame Handle