ebmDevMag.com home
ebm Developer's Magazine
links

developer's mag
main page

article
part 1
part 2
part 3
part 4
part 5
part 6
part 7
part 8
part 9


7 - Dirty Rectangles

'Dirty rectangle' is a reference to the area of the screen that needs been updating. Obviously, if you erase and redraw two lines close together, there is no need to redraw the whole window - only a small section has actually been altered. For that reason, the CWindow drawing calls maintain a rectangle of changes to the display (the 'dirtied' part of the window), which encompasses the rectanglular area of each individual change into one large one. This rectangle is the only section copied from our buffer to the actual LCD display by the operating system. When you consider that a complete display is about 24k, you can imagine the savings provided by this approach. In our case, most changes will never involve more than 500 bytes or so, so our updating routines will be about 50 times faster, well worth the code overhead used to manage it.

This updating rectangle accumulates drawing sections until you reach the end of your function, and then exits from your MsgHandler() function (which presumably called your drawing function). It is at this point that all drawing is copied to the display. For this reason, we can draw the white line and black in the same call without flickering, a common problem for many Windows programs.

You could get the flashing effect by inserting the call GUI_UpdateNow() between the two line drawings; this call updates the screen immediately. It can be handy for small animations, but should be avoided for longer ones as it means your function doesn't return to the message loop for a time, and so doesn't get to process various messages (such as pen or button presses).

Another point to keep in mind about updating; consider adding the line drawing to your Draw() routine as well. If for some reason your display does need to get updated, your Draw() routine will get called. In this example program the line will be erased, but by adding the lines
  if ( m_timerOn )
    DrawAnimation(m_position);
the line will be redrawn if Draw() is called.

Previous Section
Next Section

Copyright © 2001-2006 ebmDevMag.com - Legal Notice