Hello everyone!
This time I’ve created a gauge, which works, but I need help with redrawing.
Link to the code: https://pastebin.com/BeQAv3fc
My goal was to make such a structure:
- Create a Frame
- Inside of a Frame create a panel called “GaugeBackground” which contains a clock face (scale for indicator)
- Inside of a “GaugeBackground” create a animated panel “AnimationPanel” which draws an indicator.
The thing is I have to redraw only the AnimationPanel which is responsible of drawing an indicator. I don’t want to redraw a “GaugeBackground” because the clock face is built of many lines, and redrawing it has a big performance impact on my low power PC.
The Refresh() documentation says: “Causes this window, and all of its children recursively, to be repainted.”
That means that using Refresh() in my “AnimationPanel” should repaint only the indicator! The “GaugeBackground” is not a child of “AnimationPanel”.
Unfortunately my “GaugeBackground” still gets repainted and this slows down my computer…
The clock face doesn’t change, so it’s not needed to repaint it every time…
Question: How to fix it? What should i do to repaint the indicator ONLY?
Btw. I wanted to make a workaround and store a clock face in a bitmap in memory, it should be way faster to display a stored bitmap than draw the clock face over again, but I couldn’t manage to do it (but it would be still just a workaround which would require to redraw this bitmap)
Disclaimers:
-
I use Linux - this may be important, I found some info, that GTK may cause something like this, but I’m not sure. Even if that’s the case I still would like to manage it somehow… Every class has a print(“Called: OnPaint X”) so it’s printed when the OnPaint is called.
In my case I get:
Called: OnPaint Frame
Called: OnPaint GaugeBackground
Called: OnPaint AnimationPanel -
I wanted to provide simple and easy to verify code, that’s why “clock face” is only a text “clock face”. In real example i just draw elements like in a clock.
-
The timeout in example is set to 250ms, in real example I refresh a with higher refresh rate. I set it to 250ms so it doesn’t print so often.
Thank you in advance