ethiccinema / qtmypaint

libmypaint integration for QT based applications
BSD 3-Clause "New" or "Revised" License
16 stars 10 forks source link

qtmypaint

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

Prerequisites

Build dependencies:

Compile

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.

Usage

A global object is used for the communication with libmypaint

MPHandler *mypaint = MPHandler::handler();

Set the size of your drawing surface :

QSize size = ...;
mypaint->setSurfaceSize(size);

Load a brush from json data :

QByteArray jsonData = ...;
mypaint->loadBrush(jsonData);

Set a brush color :

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.

Get and set a brush specific setting value :

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.

Draw a stroke :

// 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.

Render the surface as an image :

QImage image = mypaint->renderImage();

Clear the surface :

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.

Load the surface with an existing image :

QImage image = ...;
mypaint->loadImage(image);