Best way to colourize text without using BBCode

0 favourites
  • 6 posts
From the Asset Store
OpenAI TTS
$10 USD
Text-to-Speech plugin.Allows your Construct 3 project to convert written text into spoken words
  • I'm working on a text/code editor for my 6502 Emulator and am looking for a way to be able to colour code elements of text for syntax highlighting and whatnot, but do not want to use BBCode, as it cancels out the use of [], which is something I don't want to do...

    I was thinking of using multiple text object overlaid on top of each other, with each using the "colour" property set to different colours, and then duplicating all the text from the main object, into the coloured ones, and possible replacing all the text that isn't what I want coloured with spaces?

    I'm feeling kinda lost on this one, so any suggestions are welcome...

    Once I have a basic code editor in place, and a simple display output, I'll gladly upload a version of this project for people to play with is they want. It's getting close to being something useable! (Even if only very basic and simple atm)

  • That’s an issue if you want to use [] and bbcode.

    You could utilize the bbcode for icons. Basically draw or copy the bracket graphics to a sprite and, and replace [] with [icon=0] and [icon=1]. That’s the simplest way I’d try.

    Second would be to maybe figuring out how to do it with html. Off hand it would just be a bunch of referencing developer docs.

    Placing the same text, just colored, over other text could work but in practice it’s a bit tricky depending on how you render text. For the text object and one line of text you can use the Text.TextWidth() expression to get the offset to place text after. Basically you’d split the line into three parts. The text before highlighting, the highlighted text, and the text after. The main complexity is textwidth won’t be updated till the text is drawn so you’ll have to wait a tick before positioning stuff. Also if there is any word wrapping things will be off.

    Spritefont is a bit better since you can get the width of individual characters without waiting a tick, but word warping is still an issue.

    Beyond that you could do text a character at a time and handle the word warping directly so you have full control of the positions and look of each character. The downside is it’s a slower with the loops and

    Instances per character.

  • I'm definitely using SpriteFonts as opposed to regular text objects. So I do know the dedicated character widths (monospaced fonts are king!)

    I suppose that given that I know the structure of the different types of "lines" that can exist in 6502 code, perhaps attacking at on a line-by-line basic might be best.

    Lines can contain: directives, opcodes, constant labels, address labels, variables, addresses in their various modes, etc, and comments of course. But proper formatting is required for the assembler to work properly, so I can always enforce that directly and have a much more predictable set of possibilities in terms of what each line might look like.

    I'll be implementing an actual blinking cursor at some point as well, plus text highlighting, copy/pasting, etc... So trying to solve the visualizationof these sooner than later I think is key.

    What would be nice, is if there was a way to return an XY position of a token within the spritefont's display box, and then send it over to a tilemap, as masking with a tilemap is something I've done in the past and can work quite well, assuming you know where the character location to mask is.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I didn't notice it in the docs about bbcodes. But if you use

    \.[.

    it will give you a [ character and it won't become a bbcode. Example:

    [color=red]red[/color] Text is done with [color=red]red[/color]

    edit:

    Bbcodes get messed up on the form, so here's a screenshot of what i meant:

  • This works perfectly!! Now I just need to find the best way to parse the text for each type of token I want to highlight.

    So far I'm looking at:

    - Directives (preceded by ".")

    - Labels (followed by ":" when set, but not when referenced)

    - Numbers: (preceded by "#" for a literal value, else its an address)

    - Binary (preceded by "%")

    - Decimal (no prefix or suffix)

    - Hex (preceded by "$")

    - Opcodes (56 unqiue 3 letter tokens)

    - Illegal Opcodes (20 unique 3 letter tokens + one 4 letter token)

    - Comments (preceded by ";" and continues for rest of the line)

  • Probably the best way to debug it is to be very verbose about displaying the raw text every step of the way. Aka line by line, text before replace, text after replace, and the regex expression used.

    The issue is bbcodes and regex both have special character combinations and you have to be careful. Even posting about it on the forum is problematic since it uses a form of bbcode too.

    If it becomes too unwieldy using regex you could utilize your parser you’re using to assemble the text maybe?

    Anyways, good luck

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)