qtmypaint is an interface to help integrate the libmypaint brush engine library within your QT based applications. (The example's GUI is based on a demo application made by Sebastien Leon)
The main code of this interface is stored in the sub-folder "src"
Please feel free to fork and modify this project.
License: Modified BSD License, see LICENSE for details
Build dependencies:
cd qtmypaint
qmake
make
On Linux, you can then run the demo with
./demo/demo
Note that on Mac and Windows, the path to the demo binary may be different.
A global object is used for the communication with libmypaint
MPHandler *mypaint = MPHandler::handler();
QSize size = ...;
mypaint->setSurfaceSize(size);
QByteArray jsonData = ...;
mypaint->loadBrush(jsonData);
QColor color = ...;
mypaint->setBrushColor(color);
Note that the alpha value is not handled by this method as the opacity of the stroke is part of the brush settings. _If you wish to force the color opacity, you should use MPHandler::setBrushValue() with MYPAINT_BRUSH_SETTINGOPAQUE.
float value = ...;
mypaint->setBrushValue(MYPAINT_BRUSH_SETTING_RADIUS_LOGARITHMIC, value);
value = mypaint->getBrushValue(MYPAINT_BRUSH_SETTING_RADIUS_LOGARITHMIC)
Note that the setting type is defined by libmypaint's MyPaintBrushSetting enum.
// Call this once on press event
mypaint->startStroke();
// Call this on each move event
mypaint->strokeTo(x, y); // Basic call
mypaint->strokeTo(x, y, pressure, xTilt, yTilt); // Call with tablet handling
A signal/slot mecanism is used to handle stroke events :
MPTile inherits from QGraphicsItem and should be added to a QGraphicsScene object on the newTile() event.
QImage image = mypaint->renderImage();
mypaint->clearSurface();
Note that in order to optimize the output of the final UI, when a surface is cleared, all the MPtiles (QGraphicsItem) that represent this surface are automatically removed from their QGraphicsScene. You don't need to worry about that.
QImage image = ...;
mypaint->loadImage(image);