08-30-2022, 03:23 PM
I tend to do this type of thing by converting my text to an image and then I can scale that image it as needed:
Code: (Select All)
Screen _NewImage(800, 700, 32)
_ScreenMove 250, 0
For i = 1 To 4
HW(i) = TextToImage("Hello World", 16, &HFFFFFF00, 0, i)
Next
Cls
Print "The first thing to showcase with these two routines is just how simple it is to turn"
Print "text into an image with TextToImage."
Sleep
Print
Print "First, let's print it forwards:"
_PutImage (250, 48), HW(1)
Sleep
Print
Print "Then, let's print it backwards:"
_PutImage (250, 80), HW(2)
Sleep
Print
Print "Then, let's print it up to down:"
_PutImage (270, 112), HW(3)
Sleep
Locate 8, 40: Print "And let's finish with down to up:"
_PutImage (580, 112), HW(4)
Sleep
Locate 20, 1
Print
Print
Print "TextToImage simply transforms text into an image for us, with a few built in options"
Print "to it for the direction we want we text to print."
Print "It's as simple as a call with:"
Print " Handle = TextToImage(text$, fonthandle, fontcolor, backgroundcolor, mode"
Print
Print " text$ is the string which we want to print. (In this case 'Hello World'"
Print " fonthandle is the handle of the font which we _LOADFONT for use."
Print " (In this case, I choose the default _FONT 16.)"
Print " fontcolor is the color which we want our text in. (Here, it's YELLOW.)"
Print " backgroundcolor is the background which we want for the text time. (Clear this time.)"
Print " mode is how we decide to print forwards, backwards, up to down, or down to up."
Print
Print "Once we have an image handle, we can use that image just the same as we can with any other."
Print "For those who don't need to do anything more than display the text as an image,"
Print "feel free to use it as I have in the first part of this program with _PUTIMAGE."
Print
Print "Trust me -- TextToImage works just fine with _PUTIMAGE."
Print
Print "But.... If you need more..."
Sleep
Cls , 0
Print "There's always DisplayImage to help you out!"
DisplayImage HW(1), 300, 30, 1, 1, 0, 1
Print
Print "Display your image at a scale!"
Sleep
Print
Print "Twice as wide! ";
DisplayImage HW(1), 300, 60, 2, 1, 0, 1
Sleep
Print "Twice as tall! "
DisplayImage HW(1), 500, 60, 1, 2, 0, 1
Sleep
Print
Print "At an angle!"
DisplayImage HW(1), 280, 90, 1, 1, -45, 1
Sleep
Print: Print: Print: Print: Print
Print "Make it rotate!"
_Delay .2
_KeyClear
Do
Line (355, 155)-Step(100, 100), &HFF000000, BF
DisplayImage HW(1), 400, 200, 1, 1, angle, 0
angle = (angle + 1) Mod 360
_Limit 30
_Display
Loop Until _KeyHit
_AutoDisplay
Print
Print
Print
Print
Print "You can basically use DisplayImage just as you'd normally use RotoZoom, EXCEPT..."
Sleep
Print "You can choose which CORNER of the image you want to display at your coordinates."
Print
Line (350, 350)-Step(100, 100), -1, B
Circle (400, 400), 10, -1
Sleep
Print "Top Left corner! ";
DisplayImage HW(1), 400, 400, 2, 2, 0, 1
Sleep
Print "Bottom Left corner! ";
DisplayImage HW(1), 400, 400, 2, 2, 0, 2
Sleep
Print "Top Right corner! ";
DisplayImage HW(1), 400, 400, 2, 2, 0, 3
Sleep
Print "Bottom Right corner! "
DisplayImage HW(1), 400, 400, 2, 2, 0, 4
Sleep
_FreeImage HW(1)
HW(1) = TextToImage("Hello World", 16, &HFFFF0000, &HFF0000FF, 1)
Print "Or Centered!"
DisplayImage HW(1), 400, 400, 2, 2, 0, 0
Circle (400, 400), 10, -1
Sleep
Cls
Print "With TextToImage, you can turn text into an image... It's that simple!"
Print
Print "With DisplayImage, you have a ton of options for how to display ANY image"
Print " (NOT just for use with text images!!)"
Print
Print "Scale them, stretch them, rotate them, position them by various corners..."
Print
Print "Between these two routines, I generally don't need anything else when working"
Print " with images in my programs. ;)"
Print
Print
Print "And that's THE END of this demo. Post any questions you have on the forums for me!"
' (Image As Long, x As Integer, y As Integer, xscale As Single, yscale As Single,
' angle As Single, mode As _Byte)
Function TextToImage& (text$, font&, fc&, bfc&, mode As _Byte)
'text$ is the text that we wish to transform into an image.
'font& is the handle of the font we want to use.
'fc& is the color of the font we want to use.
'bfc& is the background color of the font.
'Mode 1 is print forwards
'Mode 2 is print backwards
'Mode 3 is print from top to bottom
'Mode 4 is print from bottom up
'Mode 0 got lost somewhere, but it's OK. We check to see if our mode is < 1 or > 4 and compensate automatically if it is to make it one (default).
If mode < 1 Or mode > 4 Then mode = 1
dc& = _DefaultColor: bgc& = _BackgroundColor
D = _Dest
F = _Font
T2Idown = CsrLin: T2Iright = Pos(0)
If font& <> 0 Then _Font font&
If mode < 3 Then
'print the text lengthwise
w& = _PrintWidth(text$): h& = _FontHeight
Else
'print the text vertically
For i = 1 To Len(text$)
If w& < _PrintWidth(Mid$(text$, i, 1)) Then w& = _PrintWidth(Mid$(text$, i, 1))
Next
h& = _FontHeight * (Len(text$))
End If
TextToImage_temp& = _NewImage(w&, h&, 32)
TextToImage = TextToImage_temp&
_Dest TextToImage_temp&
If font& <> 0 Then _Font font&
Color fc&, bfc&
Select Case mode
Case 1
'Print text forward
_PrintString (0, 0), text$
Case 2
'Print text backwards
temp$ = ""
For i = 0 To Len(text$) - 1
temp$ = temp$ + Mid$(text$, Len(text$) - i, 1)
Next
_PrintString (0, 0), temp$
Case 4
'Print text upwards
'first lets reverse the text, so it's easy to place
temp$ = ""
For i = 0 To Len(text$) - 1
temp$ = temp$ + Mid$(text$, Len(text$) - i, 1)
Next
'then put it where it belongs
For i = 1 To Len(text$)
fx = (w& - _PrintWidth(Mid$(temp$, i, 1))) / 2 + .99 'This is to center any non-monospaced letters so they look better
_PrintString (fx, _FontHeight * (i - 1)), Mid$(temp$, i, 1)
Next
Case 3
'Print text downwards
For i = 1 To Len(text$)
fx = (w& - _PrintWidth(Mid$(text$, i, 1))) / 2 + .99 'This is to center any non-monospaced letters so they look better
_PrintString (fx, _FontHeight * (i - 1)), Mid$(text$, i, 1)
Next
End Select
_Dest D
Color dc&, bgc&
_Font F
Locate T2Idown, T2Iright
End Function
Sub DisplayImage (Image As Long, x As Integer, y As Integer, xscale As Single, yscale As Single, angle As Single, mode As _Byte)
'Image is the image handle which we use to reference our image.
'x,y is the X/Y coordinates where we want the image to be at on the screen.
'angle is the angle which we wish to rotate the image.
'mode determines HOW we place the image at point X,Y.
'Mode 0 we center the image at point X,Y
'Mode 1 we place the Top Left corner of oour image at point X,Y
'Mode 2 is Bottom Left
'Mode 3 is Top Right
'Mode 4 is Bottom Right
Dim px(3) As Integer, py(3) As Integer, w As Integer, h As Integer
Dim sinr As Single, cosr As Single, i As _Byte
w = _Width(Image): h = _Height(Image)
Select Case mode
Case 0 'center
px(0) = -w \ 2: py(0) = -h \ 2: px(3) = w \ 2: py(3) = -h \ 2
px(1) = -w \ 2: py(1) = h \ 2: px(2) = w \ 2: py(2) = h \ 2
Case 1 'top left
px(0) = 0: py(0) = 0: px(3) = w: py(3) = 0
px(1) = 0: py(1) = h: px(2) = w: py(2) = h
Case 2 'bottom left
px(0) = 0: py(0) = -h: px(3) = w: py(3) = -h
px(1) = 0: py(1) = 0: px(2) = w: py(2) = 0
Case 3 'top right
px(0) = -w: py(0) = 0: px(3) = 0: py(3) = 0
px(1) = -w: py(1) = h: px(2) = 0: py(2) = h
Case 4 'bottom right
px(0) = -w: py(0) = -h: px(3) = 0: py(3) = -h
px(1) = -w: py(1) = 0: px(2) = 0: py(2) = 0
End Select
sinr = Sin(angle / 57.2957795131): cosr = Cos(angle / 57.2957795131)
For i = 0 To 3
x2 = xscale * (px(i) * cosr + sinr * py(i)) + x: y2 = yscale * (py(i) * cosr - px(i) * sinr) + y
px(i) = x2: py(i) = y2
Next
_MapTriangle (0, 0)-(0, h - 1)-(w - 1, h - 1), Image To(px(0), py(0))-(px(1), py(1))-(px(2), py(2))
_MapTriangle (0, 0)-(w - 1, 0)-(w - 1, h - 1), Image To(px(0), py(0))-(px(3), py(3))-(px(2), py(2))
End Sub