Is it possible to write C++ functions that include Juce paint() method statements?

gui
#1

Hi everybody. I can write simple C++ functions that are called from within the paint() method code block. But… what if your function must contain exclusive paint statements? - I mean, those statements starting with g. ? You can certainly not define a function inside paint(). So, what is the solution? Is there a way to do this? Thank you (!)

#2

Maybe I’m misunderstanding the question but you can just pass g as a reference to the functions like so…

void paintSomething (Graphics& g)
{
    ...
}

void paintSomethingElse (Graphics& g)
{
    ...
}


void paint (Graphics& g)
{
    paintSomething (g);
    paintSomethingElse (g);
}

Also if you do want to define functions inside the paint method…

 void paint (Graphics& g)
{
    auto paintSomething [&]()
    {
        ...
    };

    auto paintSomethingElse [&]()
    {
        ...
    };

    paintSomething();
    paintSomethingElse();
}
1 Like
#3

The paint is a so called callback, so you define what should happen, if the OS needs to paint the component’s content.
If you want to trigger a paint (i.e. letting the OS know, that it needs to paint), you do so by calling repaint().

If you want the paint to end up somewhere else, you can either use

auto image = component.createSnapshot();

or you can call methods to paint on a background image:

Image image (Image::ARGB, 600, 400, true);
Graphics g (image);
g.fillAll (Colours::green);

But you cannot paint directly on the screen, the OS will decide, when it wants to call paint.

#4

Hello Anthony Nicholls,

thank you for your valuable answer (!) You certainly understood my question. I will try out your suggestions.

By the way, I am developing an app which takes advantage of a 10-point touch display. The idea is to play musical instruments by way of playing two hands and ten fingers on a large touch screen monitor. What type of apps do you develop?

Greetings from Germany,

Hugo

#5

Hello Daniel,

thank you for your valuable answer (!)

By the way, I am developing an app which takes advantage of a 10-point touch display. The idea is to play musical instruments by way of playing two hands and ten fingers on a large touch screen monitor. What type of apps do you develop?

Greetings from Germany,

Hugo

#6

If you click on a users icon, you get often a link this user identifies themselves with. I don’t want to spam other readers with my personal history.

But be invited to some discord chats, where people are sharing their personal stories and give each other help, quite juce-relevant even though not exclusively:

discord: theAudioProgrammer and discord: JUCE

Greetings to my home country :slight_smile:

1 Like