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:
- json-c A copy of json-c is included in this project
- libmypaint A copy of libmypaint is included in this project. It has been modified to be built in a C++ environment. It may not be the best approach. "libmypaint.c" has to be included so we can't use the headers of a pre-built version of the C lib.
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_SETTING_OPAQUE.
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 :
- newTile(MPSurface*, MPTile*) is called when a tile is added to the surface (the brush is drawing on a blank area)
- updateTile(MPSurface*, MPTile*) is called when a tile is visually updated.
MPTile inherits from QGraphicsItem and should be added to a QGraphicsScene object on the newTile() event.
QImage image = mypaint->renderImage();
mypaint->clearSurface();
- clearedSurface(MPSurface*) is called when the surface has been cleared.
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);