I'm working on a UI library powered by
D2D
,DWrite
andWic
for (SDK API) Native C++ Desktop Applications (as in no XAML, no WinRT, just old school C++). I'm all set to write a windowless UI to give a more modern (as in this century look) to myC++
tools.
I'm a backender at heart so I've spent minimal time in the UI and mostly interacted with the Windows Standard & Common Controls and some custom drawn GDI stuff. Anyways, nothing fancy.
I'm currently experimenting with D2D
and I'm interested to learn what's the standard way for UI animations. Like when you hover over a button making the border glow a bit, or an UI element moving smoothly as a result of interaction, or something fading from the screen. (think jQuery fade, slide and such short but meaningful animations in the economy of UX)
Thinking of this, two ways of handling animations in UI come to my mind:
- A standalone Thread handles the calculations for an animation queue while the UI thread draws the results. Each interaction would put animation jobs in the queue and the thread calculates stuff and repositions the elements before they get drawn.
- Use same-thread Timers to schedule and iterate through the animations.
The alternate Thread Worker method seems like a good method... but requires a bit of interlocking when visual properties are updated so it does not happen while actually drawing, to keep things consistent.
Now, for a single-thread UI... timers seem to be the solution. This makes sure drawing cannot overlap with animation calculations. But to me it feels so awkward. I'm very not used to the single thread way of life. :)
Is there another way? Or which method is recommended? I'd appreciate any information on existing implementations details or reading material.
PS: I'd appreciate if downvoters or those who request close would actually give a reason. (1) If you don't know what I'm asking, just carry on... this is definitely not a question for you. (2) If this seems too obvious/simple for you, answer it. --- I don't see a third reason, unless you're trolls. --- Or this is a really silly question, but as I said, I'm a decade+ backender so I can get away with it.