Page 1 of 1
[Implemented] DrawText Rotated
Posted: Tue Nov 08, 2005 11:54 pm
by TerryHough
Somebody probably has a better way that I do to make this happen.
But it would be nice if it were native to the 2D Drawing command, eg.
DrawText(Text$,DegreesToRotate)
I have found the need to do this routinely, but my solution is awkward at
best.
Maybe there should be a way to LoadFont rotated, and then just use it.
Posted: Wed Nov 09, 2005 1:29 am
by fsw
I had the same request ages ago.
In the meantime here some old Windows OS code I used to use with PB:
Code: Select all
; Rotate Font - example for text API
;
Declare WndProc (hwnd, msg, wParam, lParam)
Declare DrawCustomFontText (hDC, fontName$, pointSize, weight, italic, underline, angle, x, y, text$, lineSpace)
Procedure WndProc (hWnd, msg, wParam, lParam)
Result = #PB_ProcessPureBasicEvents
spacing = 35
Select msg
Case #WM_PAINT
hDC = StartDrawing(WindowOutput())
; draw rotated text, angle# is degrees counterclockwise direction text should be rotated
x = 240
y = 40
angle = 300
DrawCustomFontText (hDC, "arial", 16, #FW_NORMAL, #False, #False, angle, x, y, "Arial, 16pt, 300 Degree Rotation", spacing)
StopDrawing()
EndSelect
ProcedureReturn Result
EndProcedure
Procedure DrawCustomFontText (hDC, fontName$, pointSize, weight, italic, underline, angle, x, y, text$, lineSpace)
lf.LOGFONT
DesktophDC = GetDC_(#HWND_DESKTOP)
hFont = GetStockObject_(#DEFAULT_GUI_FONT) ; get a font handle
bytes = GetObject_(hFont, SizeOf(lf), @lf) ; fill LOGFONT struct lf
PokeS (@lf\lffaceName, fontName$)
lf\lfitalic = italic ; set italic
lf\lfweight = weight ; set weight
lf\lfunderline = underline ; set underlined
lf\lfescapement = angle * 10 ; set text rotation
lf\lfheight = -1 * pointSize * GetDeviceCaps_(hDC, #LOGPIXELSY) / 72
ReleaseDC_(#HWND_DESKTOP, DesktophDC)
hCustFont = CreateFontIndirect_(@lf) ; create a new font and get handle
hOldFont = SelectObject_(hDC, hCustFont)
tm.TEXTMETRIC
GetTextMetrics_(hDC, @tm)
lineSpace = tm\tmheight + tm\tmexternalLeading
pixels = tm\tmheight
leading = tm\tmexternalLeading
Locate(x,y)
TextOut_(hDC, x, y, @text$, Len(text$))
SelectObject_(hDC, hOldFont)
DeleteObject_(hCustFont)
EndProcedure
; main
winMain = OpenWindow (0, 0, 0, 550, 350, #PB_Window_SystemMenu | #PB_Window_ScreenCentered, "Font Demo")
SetWindowCallback(@WndProc ())
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
End
It's pretty straight forward.

Posted: Wed Nov 09, 2005 6:28 am
by netmaestro
Why not draw the text to an image, grab that to a 3d sprite, (you can do this without ever showing it to the user) and then you can zoom and rotate to your heart's content. You need a screen or windowed screen as opposed to a straight window is the only requirement.
Posted: Wed Nov 09, 2005 9:05 am
by Dr. Dri
netmaestro wrote:Why not draw the text to an image, grab that to a 3d sprite, (you can do this without ever showing it to the user) and then you can zoom and rotate to your heart's content. You need a screen or windowed screen as opposed to a straight window is the only requirement.
fonts are vector objects but 3D sprites aren't, so if you you zoom you will lose quality...
Dri