First short example of RTML : Rich Text Markup Language. (RTF - HTML)
Please let me know, if anybody is interested in further development.
I plan to add <b> <i> <u> <font=xyz> etc...
Right know the only command is <color=name> where a color with this name has to be added to the colortable using RTML_AddColor(name.s, color.i)
I chose <color=red> instead of just <red> because some lazy programmer would name his blue color just "b" and that would interfere with the planned bold-command <b>
Maybe I'll add a shortcut-tag for colors like {red} which would equal <color=red>, but would not interfere with any other commands, since these would use only < brackets >
Also in the future I plan to add any color without using a predefined color.
<color=$0000FF>, <color=#FF0000> would both equal red (first one is BGR like in PB and second one is RGB like in html) so PB users and other users who may write text scripts for an application don't need to adapt to the other in most cases unfamiliar color noting system.
Also planned is another command to add lines where one can use \n or other commands to create new lines without using another command or line.
Code: Select all
Structure structure_RTML_Colors
name.s
color.i
colorID.i
EndStructure
Define index_RTML_ColorID.i
NewList RTML_Colors.structure_RTML_Colors()
Procedure RTML_AddColor(name.s, color.i)
Shared index_RTML_ColorID
Shared RTML_Colors()
ForEach RTML_Colors()
If RTML_Colors()\name = name
ProcedureReturn #False
EndIf
Next
AddElement(RTML_Colors())
index_RTML_ColorID + 1
RTML_Colors()\name = name
RTML_Colors()\color = color
RTML_Colors()\colorID = index_RTML_ColorID
ProcedureReturn #True
EndProcedure
Procedure RTML_ReplaceColor(name.s, color.i)
Shared RTML_Colors()
ForEach RTML_Colors()
If RTML_Colors()\name = name
RTML_Colors()\color = color
ProcedureReturn #True
EndIf
Next
ProcedureReturn #False
EndProcedure
Procedure.s RTML_Parse(input.s)
input + "<color=black>" ;Add commands for standardstyle at the end of each line
input + " " ;Add Space at the end of each line. Otherwise above commands won't work.
Protected head.s, foot.s
Shared RTML_Colors()
;Sort Colors. Shouldn't be necessary if nothing is deleted. Thus commented out for speed.
;SortStructuredList(RTML_Colors(), #PB_Sort_Ascending, OffsetOf(structure_RTML_Colors\colorID), #PB_Sort_Integer )
head.s = "{\rtf {\colortbl;"
ResetList(RTML_Colors())
ForEach RTML_Colors()
head + "\red"+Str(Red(RTML_Colors()\color))+""
head + "\green"+Str(Green(RTML_Colors()\color))+""
head + "\blue"+Str(Blue(RTML_Colors()\color))+";"
Next
head + "}{"
foot.s = "}}"
ForEach RTML_Colors()
input = ReplaceString(input, "<color=" + RTML_Colors()\name + ">", "\cf" + Str(RTML_Colors()\colorID) + " " )
Next
ProcedureReturn head + input + foot
EndProcedure
;-
;-Programm start
;-OpenWindow etc...
OpenWindow(0, 0, 0, 400, 400, "", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
EditorGadget(0, 0, 0, 400, 400, #PB_Editor_ReadOnly)
;-Add colors to color table
RTML_AddColor("black", $000000) ;Add colors at runtime
RTML_AddColor("red", $0000FF)
RTML_AddColor("green", $009900)
RTML_AddColor("blue", $FF0000)
RTML_AddColor("orange", $0099FF)
;-Add Lines to the editor gadget
AddGadgetItem(0, -1, RTML_Parse("<color=blue>Zelda: <color=black>Aren't you the boy from the <color=green>Forrest<color=black>?"))
AddGadgetItem(0, -1, RTML_Parse("<color=blue>Zelda: <color=black>This is <color=red>Ganondorf <color=black>, king of the <color=orange>Gerudos!"))
;-Replace some colors
RTML_ReplaceColor("red", $000099) ;Replace Colors at runtime.
RTML_ReplaceColor("blue", $660000) ;e.g use a darker shade at night or if the player is in a dungeon...
RTML_ReplaceColor("orange", $003399)
;-Add more lines to the gadget using the replaced colors
AddGadgetItem(0, -1, "Replace Colors at runtime. e.g use a darker shade at night or if the player is in a dungeon...")
AddGadgetItem(0, -1, RTML_Parse("<color=blue>Zelda: <color=black>This is <color=red>Ganondorf <color=black>, king of the <color=orange>Gerudos!"))
;-Mainloop
Repeat
event = WaitWindowEvent(20)
Until event = #PB_Event_CloseWindow