Custom code at random location


#1

I have a code like this and would like to manually overwrite the font selection made by Jucer (see my ‘custom’ tags):

void AboutPage::paint (Graphics& g)
{
    //[UserPrePaint] Add your own custom painting code here..
    Font font (mainWindow->getCustomFont (myFont, 18.0f));
    //[/UserPrePaint]

    g.setColour (Colours::black);
    g.setFont (Font (18.0000f, Font::plain));
    //[MyCustomCodeTag] 
    g.setFont (font);
    //[/MyCustomCodeTag] 
    g.drawText (T("Some text..."),
                196, 12, 404, 30,
                Justification::centredLeft, true);


    //[UserPaint] Add your own custom painting code here..
    //[/UserPaint]
}

I can prepare my embedded fonts in UserPrePaint, but can I use something like the above to cheat the Jucer?

Thanks,
LB


#2

No, that won’t work I’m afraid. You should probably just write the whole paint method manually, I guess.


#3

Yeah, I figured that out a minute after I posted.

I’m pulling on straws here, so please be gentle :slight_smile:

How about having an extra text field in Jucer for each graphic element and component for a line of custom code / function call)? If used, Jucer would simply add that piece of code right after they’re created in the parent constructor or in the paint method. Which I could use for my embedded fonts :slight_smile:


#4

Possibly… Feels like there’s a neater way than that, though. I’ll have a think next time I’m in that bit of the code.


#5

eventually, one could specify fonts as resources, and embed them in jucer components like the other images… when you create a text field, it have a combobox to let you select your embedded font.

maybe that’s neater :slight_smile:


#6

I like spiderman’s suggestion though.
We use the Jucer a lot, and quite a few times we have similar problems.
We just want to add a little bit of code inside Jucer generated code.

Offering a tag like //[UserCode] which you can everywhere you want would be a nice addition.


#7

don’t think that’d be possible - if a tag is in the middle of a pile of auto-generated code, and then that generated code changes, how could it figure out where to replace the tag?


#8

[quote=“jules”]
don’t think that’d be possible - if a tag is in the middle of a pile of auto-generated code, and then that generated code changes, how could it figure out where to replace the tag?[/quote]

Yes, that’s exactly the problem. And that’s why I decided to subclass the LookAndFeel class and do as much as I can there (about embedded fonts, I mean). I think it’ a fairly clean and Juce-friendly way of doing this. But the problem with the Jucer generated graphics still remains.