3 ms·
If you wanted to be able to test your MS Paint clone, you might implement your drawing core without being dependent on a window existing. An off-the-cuff approa
by codebje 6y ago
If you wanted to be able to test your MS Paint clone, you might implement your drawing core without being dependent on a window existing. An off-the-cuff approach might be to have the core define a canvas interface with the rendering primitives it desires, and provide a suite of functions that will translate user input actions to canvas rendering primitives.
A purely functional approach would involve a core of functions taking in a current state and returning an updated state and a list of canvas actions to take.
Functions might include "select ellipse tool" and "set pen width to 5" and "click on canvas at point (3,15)" and return canvas primitives like "render ellipsis from (3,15) to (47,99) with stroke width 5, stroke colour black, and no fill".
Unit testing of the core should obviously be quite simple to do, being totally independent of the GUI system.