Entschuldigung, wenn ich mich zu doof anstelle, aber bitte nochmal erklären.
Beide (oder auch mehrere) gedrehte Textzeilen sollen sich in dem Rechteck drehen. Momentan ist es so, dass nur die erste mit Sicherheit immer im Rechteck ist. (Was müsste ich außerdem machen, wenn ich bereits feste Werte für die einzelnen Zeilen habe?)
Zur Veranschaulichung habe ich es nochmal in mein Beispiel eingefügt:
Code: Alles auswählen
;EnableExplicit
Enumeration
#Window
#ImageGadget
#Image
#Timer
EndEnumeration
Global Width, Height
Global Text.s, TextFontID
Global NBoxX, NBoxY, GBoxX, GBoxY, GAngle.f
Procedure RotatedTextX(Text.s, Angle.f)
Protected Result
If Cos(Radian(Angle)) < 0
Result + (Cos(Radian(Angle)) * TextWidth(Text))
EndIf
If Sin(Radian(Angle)) < 0
Result + (Sin(Radian(Angle)) * TextHeight(Text))
EndIf
ProcedureReturn Result
EndProcedure
Procedure RotatedTextY(Text.s, Angle.f)
Protected Result
If Sin(Radian(Angle)) > 0
Result - (Sin(Radian(Angle)) * TextWidth(Text))
EndIf
If Cos(Radian(Angle)) < 0
Result + (Cos(Radian(Angle)) * TextHeight(Text))
EndIf
ProcedureReturn Result
EndProcedure
Procedure RotatedTextWidth(Text.s, Angle.f)
ProcedureReturn Abs(Cos(Radian(Angle)) * TextWidth(Text)) + Abs(Sin(Radian(Angle)) * TextHeight(Text))
EndProcedure
Procedure RotatedTextHeight(Text.s, Angle.f)
ProcedureReturn Abs(Sin(Radian(Angle)) * TextWidth(Text)) + Abs(Cos(Radian(Angle)) * TextHeight(Text))
EndProcedure
Procedure CreateTestImage()
Protected X, Y, W, H
Protected X2, Y2
Protected RadSin.f, RadCos.f
CreateImage(#Image, Width, Height)
StartDrawing(ImageOutput(#Image))
DrawingFont(TextFontID)
Box(0, 0, Width, Height, $000000)
DrawingMode(#PB_2DDrawing_Transparent | #PB_2DDrawing_Outlined)
; Normal Gedreht:
X = NBoxX - RotatedTextX(Text, GAngle)
Y = NBoxY - RotatedTextY(Text, GAngle)
W = RotatedTextWidth(Text, GAngle)
H = RotatedTextHeight(Text, GAngle)
DrawRotatedText(X, Y, Text, GAngle, $FF00FF)
Box(NBoxX - 1, NBoxY - 1, W + 2, H + 2, $800080)
Circle(NBoxX, NBoxY, 3, $800080)
RadSin = Sin(Radian(GAngle))
RadCos = Cos(Radian(GAngle))
; Gedreht Kombi:
X = GBoxX
Y = GBoxY
W = Abs(RadCos * TextWidth(Text)) + Abs(RadSin * (TextHeight(Text)+40))
H = Abs(RadSin * TextWidth(Text)) + Abs(RadCos * (TextHeight(Text)+40))
DrawRotatedText(X - RotatedTextX(Text, GAngle), Y - RotatedTextY(Text, GAngle), Text, GAngle, $FFFFFF)
; Gedreht Kombi Nr. 2:
X2 = GBoxX + (RadCos*0 + RadSin*40)
Y2 = GBoxY + (-RadSin*0 + RadCos*40)
DrawRotatedText(X2 - RotatedTextX(Text, GAngle), Y2 - RotatedTextY(Text, GAngle), Text, GAngle, $FFFFFF)
Box(GBoxX - 1, GBoxY - 1, W + 2, H + 2, $808080)
Circle(GBoxX, GBoxY, 3, $808080)
StopDrawing()
EndProcedure
Width = 500 : Height = 200
Text = "| test |"
TextFontID = FontID(LoadFont(#PB_Any, "Arial", 20, #PB_Font_Bold | #PB_Font_HighQuality | #PB_Font_Italic | #PB_Font_StrikeOut))
NBoxX = 50 : NBoxY = 50
GBoxX = 300 : GBoxY = 50 : GAngle = 45
If OpenWindow(#Window, 0, 0, Width + 20, Height + 20, "DrawRotatedText Test", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ImageGadget(#ImageGadget, 10, 10, Width, Height, 0)
AddWindowTimer(#Window, #Timer, 50)
Repeat
Select WaitWindowEvent()
Case #PB_Event_Timer
If EventTimer() = #Timer
GAngle + 4 ; Text drehen
CreateTestImage()
SetGadgetState(#ImageGadget, ImageID(#Image))
EndIf
Case #PB_Event_CloseWindow
Break
EndSelect
ForEver
EndIf