So, an dieser stelle möchte ich mal etwas "zurückgeben".
Hier mal ein Beispiel für das Darstellen von Texten mit StyleSheets (ähnlich dem RTF-Format).
Mit Hilfe des gDrawing-Includes ist es nun einfacher die Schrift on-the-fly zu ändern.
Hier mal ein Beispiel:
Syntax : "
\IA
\i\-Quadrat
\0 =
\B50
\b \C2cm
\+2
\c\0\n\Im
\i\-e
\0 =
\C19,109
\c×10
\u\+31
\0 \C2kg"
Code: Alles auswählen
EnableExplicit
XIncludeFile "gDrawing.pbi"
CompilerIf Defined(CharacterArray, #PB_Structure) = #False
Structure CharacterArray
c.c[0]
EndStructure
CompilerEndIf
Structure StyledTextFont
Name.s
Size.f
Style.i
Color.l
EndStructure
Structure StyledTextInclude
Name.s
Size.f
Style.i
Array Color.l(9)
EndStructure
Global StyledTextInclude.StyledTextInclude
Procedure SetStyledTextFont(Name.s, Size.f, Style.i=0, ColorList.s="$FF000000")
Protected Index.i, LastIndex.i
With StyledTextInclude
\Name = Name
\Size = Size
\Style = Style
For Index = 0 To 9
\Color(Index) = Val(StringField(ColorList, Index+1, ","))
Next
EndWith
EndProcedure
Procedure DrawStyledText(X.f, Y.f, Text.s)
Protected *Character.CharacterArray = @Text, String.s
Protected Font.StyledTextFont
Protected Start.i, Index.i = -1
Protected ShiftX.f, ShiftY.f, ShiftV.f
If Not *Character : ProcedureReturn #False : EndIf
Font\Name = StyledTextInclude\Name
Font\Size = StyledTextInclude\Size
Font\Style = StyledTextInclude\Style
Font\Color = StyledTextInclude\Color(0)
Repeat
With Font
gSetFont(\Name, \Size, \Style)
gSetPenColor(\Color)
Repeat
Index + 1
Select *Character\c[Index]
Case '\'
Select *Character\c[Index+1]
Case '\'
String = PeekS(@*Character\c[Start], Index-Start+1)
Default
String = PeekS(@*Character\c[Start], Index-Start)
EndSelect
gDrawText(X+ShiftX, Y+ShiftY+ShiftV, String)
ShiftX + gTextWidth(String)
Select *Character\c[Index+1]
Case 'C'
\Color = StyledTextInclude\Color(*Character\c[Index+2]-'0')
Index + 1
Case 'c'
\Color = StyledTextInclude\Color(0)
Case 'B'
\Style | #PB_Font_Bold
Case 'b'
\Style & ~#PB_Font_Bold
Case 'U'
\Style | #PB_Font_Underline
Case 'u'
\Style & ~#PB_Font_Underline
Case 'I'
\Style | #PB_Font_Italic
Case 'i'
\Style & ~#PB_Font_Italic
Case '+'
\Size = StyledTextInclude\Size * 0.7
ShiftV = -StyledTextInclude\Size * 0.1
Case '-'
\Size = StyledTextInclude\Size * 0.7
ShiftV = StyledTextInclude\Size * 0.4
Case '0'
\Size = StyledTextInclude\Size
ShiftV = 0
Case 'n'
ShiftY + gTextHeight("|")*1.1
ShiftX = 0
EndSelect
Index + 1
Start = Index+1
Break
Case #NUL
gDrawText(X+ShiftX, Y+ShiftY+ShiftV, PeekS(@*Character\c[Start], Index-Start))
Break 2
EndSelect
EndWith
ForEver
ForEver
EndProcedure
Enumeration
#Window
#Gadget
EndEnumeration
gInit()
OpenWindow(#Window, 0, 0, 250, 100, "StyledText", #PB_Window_MinimizeGadget|#PB_Window_ScreenCentered)
CanvasGadget(#Gadget, 0, 0, WindowWidth(#Window), WindowHeight(#Window))
gStartDrawing(CanvasOutput(#Gadget))
gSetTextAntialiasMode(#TextAntialiasMode_ClearTypeGridFit)
SetStyledTextFont("Arial", 24, #Null, "$FF000000,$FF008040,$FFC04000")
DrawStyledText(10, 10, "\IA\i\-Quadrat\0 = \B50\b \C2cm\+2\c\0\n\Im\i\-e\0 = \C19,109\c×10\u\+31\0 \C2kg")
gStopDrawing()
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
Funktionen wie StyledTextWidth() und StyledTextHeight() uvm. folgen später
