← Back to team overview

kicad-developers team mailing list archive

USE_WX_ZOOM recap.

 

I have just committed the removal of a the old scaling code from Kicad.
 This effectively means that wxDC is now used for all coordinate
conversion between drawing and screen units.  This transition is by no
means complete as there are still some issues that need to be addressed.
 I learned a great deal along the way and want to share some
observations into the Kicad drawing code so here it goes.

1) All coordinate conversions between logical (drawing) units and device
(screen, printer, etc.) should be done using the device context.  Use
LogicalToDevice and DeviceToLogical methods for all coordinate
conversions.  In order for this to work properly, the scroll bars must
be set to the correct position and DoPrepareDC must be called before
using the device context.

2) All drawing and clipping should be done in drawing coordinates.
There is no longer any need to convert to device coordinates before drawing.

3) Using wxBufferedDC now works properly on Windows.  Using a buffer DC
on GTK and OSX shouldn't be necessary as they both support double
buffering natively (according to the wxWidgets documentation).  Please
note that wxBuffedDC can currently only be used to redraw the entire
screen area.  This is due to the fact that drawing when editing does not
update the background.  Drawing when editing is accomplish by XORing
the current object to erase it and redrawing the edited object so using
a buffered DC will not work.  I added an INSTALL_UNBUFFER_DC for edit
drawing purposes.

4) You can experiment with turning the buffered DC on and off by setting
KICAD_USE_BUFFERED_PAINTDC and KICAD_USE_BUFFERED_DC to 1 or 0.  I
recommend reading the comments in kicad_device_context.h before changing
anything.  As of now, both paint and client DCs are buffered on Windows.
 I'm not sure this is the best combination.  I'm sure if there are any
performance regressions, I'll hear about it.  I don't notice much of a
difference on my machine.

5) I removed several places where the cursor and pointer positions
(which are not always the same position) were saved in object member
variables in both screen and drawing units which was extremely
confusing.  Please do not add another variable (object member or
otherwise) to save any position information.  Use the ones already
stored in the base screen object.

6) I had to disable the optimized bitmap version of the grid drawing
code.  I'll take a look at it as soon as get some time.  Although using
buffer drawing on Windows should help mitigate some of the performance
issues (maybe?).

There is still quite a bit of work to be done but this is a good first
pass.  There is a lot of legacy code which I'm sure can be removed
and/or simplified which I will continue to chip away at.  I'm not sure
the clipping is 100% correct but now that all the drawing is done in
drawing units it should be a lot easier to verify.  I need some help
from our OSX developers to verify I didn't break anything.

If anyone finds any drawing issues, please let me know and I'll do my
best to fix it promptly.

Thanks,

Wayne



Follow ups