Some musing on code optimization
When initially designing a new UI such as the Modern UI, I always work on the design first and then when I feel the code is mature enough, I go in and optimize to make sure the UI is as responsive and smoothly as I can make it.
Initial optimizations
My initial code included an icon-size caching system I designed years ago. I also calculated most of the layout math in advance to make the code more legible as I was coding it and to prevent silly things like repeating the same math over and over and over.
Don't repeat the math
Since drawing the volume/timeline bar graphics requires higher-level math, from the start I kept cached images of both bars in their two states. This means every volume/timeline updates only need to copy a bitmap rather than calculating anti-aliased curves.
Starting point
At this point, drawing the Modern UI took 1.8 milliseconds (using the screenshot's resolution). That's actually quite speedy, but I knew there was lots more to optimize.
Caching the background gradient
First thing, I cached the background gradient, if the window size is not changed, there's no reason to redraw it each time. This action alone reduced the draw time from 1.8ms to 1.2ms.
Buttons & Title text
The second optimization addressed the buttons and title text. Again, if the window is not resized, they stay the same and there's no need to update them. This reduced the draw time from 1.2ms to 0.7ms.
The volume bar
The third optimization addressed the volume bar. If you're just changing the volume, there's no need to update anything else, just clear the region by copying from the cached background image and draw the new volume bar. Changing the volume level alone now takes 0.25ms.
The timeline bar
The forth and final optimization addressed the timeline bar and text. Both elements are updated every second, but again, I just clear the region by copying from the cached background image and then draw the new timeline. Updating the current position now takes 0.35ms.
Conclusion
I'm sure if I spent more time on the code, I may be able to shave a few more microseconds, but as it stands now, I'm very satisfied with the 500-600% average draw speedup.