Skip to content

Latest commit

 

History

History
108 lines (58 loc) · 3.09 KB

README.md

File metadata and controls

108 lines (58 loc) · 3.09 KB

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:

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

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

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 :

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

Render the surface as an image :

QImage image = mypaint->renderImage();

Clear the surface :

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.

Load the surface with an existing image :

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