Design critique question - UI performance
Posted on 2005-04-26
Maybe somebody can suggest some improvements for me.
I have a CStatic derived class called CDisplay and a CCamera base class that pushes frames, around 10fps to the display. CCamera also has a CViewFinder base class that can alpahblend into the camera display, one of many "menus" implemented in CViewfinderMenu each containing "widgets" that I've implemented as CWidget.
So we have what amounts to menus and buttons, but they are graphical and blended directly into the video feed, as opposed to MFC dialogs and CButton's as they aren't static, they are painted (and the menu background alphablended) into a video stream.
So in my CDisplay::PreTranslateMessage() (the only CStatic that can grab the messages) I check for mouse movement, and I forward the MSG* into CViewFinder. The CViewFinder will then forward the MSG* into each of its CViewfinderMenu instances, and the CViewFinderMenu will forward the MSG* into each of its CWidget instances. CWidget implements it's UI type stuff just like any button would, with normal, glow and pressed states.
Everything uses a CPtrList as the collection. the viewfinder has a CPtrList of menus, each menu has a CPtrList of widgets.
Each time I "forward the MSG pointer" it's just a matter of looping through, for example:
POSITION pos = NULL;
for( pos = m_pWidgets->GetHeadPosition(); pos != NULL; )
Anyway, everything does work as I'd expect, but it's a bit "sluggish" - not the video frame rate, rather, the speed at which my elements respond to the mouse messages. I roll my mouse into the camera's video area, and the alphablended menus appear and my widgets glow and unglow as the mouse enters/leaves them, but rather than a widget glowing immediately upon mouse entry, there is a delay, perhaps 1/2 a second (at most, but it's not immediate, and UI/visual responses need to be immediate)
At first I thought "well maybe it's because repaints are happening at the cameras frame rate" - but this model is implemented against two hardware devices, one at 10fps the other running at 30fps.. I don't perceive any difference in UI response regardless which feed is running, so I'm not sure if it's that.
Perhaps CPtrList is not the right container? would switching to a vector or deque improve performance? Maybe some kind of global lookup table of widgets so rather than constantly looping through everything I can look directly to a mouse postion? Any suggestions on designs to improve UI performance here?