GDICanvas is a petite library for doing basic graphics using WinAPI's GDI(Graphics Device Interface). This project is basically an attempt to replicate all the functionality in Tkinter's Canvas.
Make sure you have a compiler with C++11 support, and an MSYS/Cygwin installation,
then run make all
in the parent directory.
The necessary header files and binaries will be placed in the build
directory if the build ends successfully.
MSYS/Cygwin is needed because of the cp and rm commands used in the Makefile.
Git Bash, unfortunately, doesn't play well with CMD.exe's internal commands like del q.
You can also generate IDE specific project files by using cmake with a command like this:
cd build/cmake && cmake -G "CodeBlocks - MinGW Makefiles" ../..
Run cmake -G
to view a list of the supported IDEs. This is not a guarantee that the project
will build successfully in all of them. It can only build flawlessly with GNU's
compiler. I'll get around at some point to fixing the build issues in Visual Studio
2013
The obligatory 'hello world' looks something like this:
#include "Canvas.h"
int main() {
GC::Canvas canv;
canv.init();
canv.text(50, 50, "Hello world");
return canv.loop();
}
and is built like so:
g++ -o HelloWorld.exe HelloWorld.cxx -lGDICanvas -std=c++11 -mwindows -Lbuild/lib -Ibuild/include
You should try different optimization levels, e.g -Os
or use the gcc -lstdc++
combination in case the executable turns out to be huge.
Events are specified and bound the same way as in Tkinter, delimited by angle brackets. An example:
#include <Canvas.h>
struct Handler : GC::EventHandler {
virtual void handle(GCanvas::Mouse mouse) override {
char text[30];
snprintf(text, 30, "Pointer at (%i, %i)", mouse.x(), mouse.y());
MessageBox(0, text, "Mouse", 32);
}
};
int main() {
GC::Canvas canv(450, 450, "Hover test");
canv.init();
int pie = canv.arc(10, 10, 400, 400, GS::PIE);
canv.fillColor(pie, "Turquoise");
canv.bind("<hover>", Handler(), "all");
return canv.loop();
}
The handler will be called when the mouse is above that shape for a period of time(as the hinted in the event string). Omitting the last parameter will cause the handler to be called when the mouse is above the window/canvas.
Documentation can be generated using doxygen by running:
make docs
: generates documentation with my custom stylesheetmake doc1
: generates documentation with Doxygen's default layout/styling
Creating a turtle graphics library based on GDICanvas once I figure out how to draw fast enough without flickering