Skip to content

Commit

Permalink
Allow usage of both TiledBuffer and Mypaint
Browse files Browse the repository at this point in the history
This allows us to use TiledBuffer for Vector now and Mypaint for bitmap.
Right now it's just to get things working again. Next i'll try to make a proper interface for the drawing buffers, so we can get rid of so much manual branching.
  • Loading branch information
MrStevns committed Oct 15, 2023
1 parent 663c7b9 commit d7fd6b5
Show file tree
Hide file tree
Showing 26 changed files with 155 additions and 582 deletions.
5 changes: 1 addition & 4 deletions 3rdlib/paint_lib/src/paintlib-pch.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#ifndef PAINTLIBPCH_H
#define PAINTLIBPCH_H

/* Add C includes here */

#if defined __cplusplus
Expand All @@ -10,4 +7,4 @@
#include <QString>
#include <QList>

#endif // PAINTLIBPCH_H
#endif
1 change: 0 additions & 1 deletion 3rdlib/paint_lib/src/qtmypaint/mphandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ void
MPHandler::endStroke()
{
mypaint_brush_reset(mBrush->brush);
mSurface->clear();
}

float MPHandler::getBrushSettingBaseValue(MyPaintBrushSetting setting)
Expand Down
21 changes: 12 additions & 9 deletions core_lib/src/canvaspainter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ GNU General Public License for more details.
#include "vectorimage.h"

#include "painterutils.h"
#include "mptile.h"
#include "tiledbuffer.h"

CanvasPainter::CanvasPainter(QPixmap& canvas) : mCanvas(canvas)
{
Expand Down Expand Up @@ -157,16 +159,17 @@ void CanvasPainter::renderPostLayers(QPainter& painter, const QRect& blitRect)
}
}

void CanvasPainter::setPaintSettings(const Object* object, int currentLayer, int frame, QHash<QString, MPTile*> tiledBuffer, const QRect& tilesBounds)
void CanvasPainter::setPaintSettings(const Object* object, int currentLayer, int frame, QHash<QString, MPTile*> tiledHash, const QRect& tilesBounds, const TiledBuffer* tiledBuffer)
{
Q_ASSERT(object);
mObject = object;

CANVASPAINTER_LOG("Set CurrentLayerIndex = %d", currentLayer);
mCurrentLayerIndex = currentLayer;
mFrameNumber = frame;
mTiledBuffer = tiledBuffer;
mTiledHash = tiledHash;
mTilesRect = tilesBounds;
mTiledBuffer = tiledBuffer;
}

void CanvasPainter::paint(const QRect& blitRect)
Expand Down Expand Up @@ -289,15 +292,15 @@ void CanvasPainter::paintCurrentBitmapFrame(QPainter& painter, const QRect& blit
if (paintedImage == nullptr) { return; }
paintedImage->loadFile(); // Critical! force the BitmapImage to load the image

const bool isDrawing = !mTiledBuffer.isEmpty();
const bool isDrawing = !mTiledHash.isEmpty();

QPainter currentBitmapPainter;
initializePainter(currentBitmapPainter, mCurrentLayerPixmap, blitRect);

painter.setOpacity(paintedImage->getOpacity() - (1.0-painter.opacity()));
painter.setWorldMatrixEnabled(false);

if (isCurrentLayer && isDrawing)
if ((isCurrentLayer && isDrawing) || (mOptions.bIgnoreCanvasBuffer))
{
// Certain tools require being painted continuously, for example, the Polyline tool.
// The tiled buffer does not update the area outside which it paints,
Expand All @@ -309,7 +312,7 @@ void CanvasPainter::paintCurrentBitmapFrame(QPainter& painter, const QRect& blit
currentBitmapPainter.drawImage(paintedImage->topLeft(), *paintedImage->image());
}

const auto tilesMap = mTiledBuffer;
const auto tilesMap = mTiledHash;
for (const MPTile* tile : tilesMap) {
currentBitmapPainter.drawImage(tile->pos(), tile->image());
}
Expand Down Expand Up @@ -340,7 +343,7 @@ void CanvasPainter::paintCurrentVectorFrame(QPainter& painter, const QRect& blit
QPainter currentVectorPainter;
initializePainter(currentVectorPainter, mCurrentLayerPixmap, blitRect);

const bool isDrawing = !mTiledBuffer.isEmpty();
const bool isDrawing = mTiledBuffer->isValid();

// Paint existing vector image to the painter
vectorImage->paintImage(currentVectorPainter, mOptions.bOutlines, mOptions.bThinLines, mOptions.bAntiAlias);
Expand All @@ -349,9 +352,9 @@ void CanvasPainter::paintCurrentVectorFrame(QPainter& painter, const QRect& blit
if (isDrawing) {
currentVectorPainter.setCompositionMode(mOptions.cmBufferBlendMode);

const auto tiles = mTiledBuffer;
for (const MPTile* tile : tiles) {
currentVectorPainter.drawImage(tile->pos(), tile->image());
const auto tiles = mTiledBuffer->tiles();
for (const Tile* tile : tiles) {
currentVectorPainter.drawPixmap(tile->posF(), tile->pixmap());
}
} else if (mRenderTransform) {
vectorImage->setSelectionTransformation(mSelectionTransform);
Expand Down
10 changes: 6 additions & 4 deletions core_lib/src/canvaspainter.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ GNU General Public License for more details.
#include "onionskinpainteroptions.h"
#include "onionskinsubpainter.h"

#include "mpsurface.h"

class MPTile;
class TiledBuffer;
class Object;
class BitmapImage;
class ViewManager;
Expand Down Expand Up @@ -67,7 +67,7 @@ class CanvasPainter
void setTransformedSelection(QRect selection, QTransform transform);
void ignoreTransformedSelection();

void setPaintSettings(const Object* object, int currentLayer, int frame, QHash<QString, MPTile*> tilesBuffer, const QRect& tilesBounds);
void setPaintSettings(const Object* object, int currentLayer, int frame, QHash<QString, MPTile*> tiledHash, const QRect& tilesBounds, const TiledBuffer* tiledBuffer);
void paint(const QRect& blitRect);
void paintCached(const QRect& blitRect);
void resetLayerCache();
Expand Down Expand Up @@ -108,9 +108,11 @@ class CanvasPainter

int mCurrentLayerIndex = 0;
int mFrameNumber = 0;
QHash<QString, MPTile*> mTiledBuffer;
QHash<QString, MPTile*> mTiledHash;
QRect mTilesRect;

const TiledBuffer* mTiledBuffer;

QImage mScaledBitmap;

// Handle selection transformation
Expand Down
3 changes: 1 addition & 2 deletions core_lib/src/graphics/bitmap/bitmapimage.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ GNU General Public License for more details.
#include <QtMath>
#include <QHash>

class MPTile;

#include "mptile.h"

class BitmapImage : public KeyFrame
{
Expand Down
47 changes: 0 additions & 47 deletions core_lib/src/graphics/bitmap/tile.cpp

This file was deleted.

50 changes: 0 additions & 50 deletions core_lib/src/graphics/bitmap/tile.h

This file was deleted.

Loading

0 comments on commit d7fd6b5

Please sign in to comment.