Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
askmeaboutlo0m committed Aug 15, 2023
1 parent 84507f9 commit 6fb6a45
Show file tree
Hide file tree
Showing 23 changed files with 594 additions and 420 deletions.
5 changes: 4 additions & 1 deletion src/desktop/dialogs/playbackdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,10 @@ void PlaybackDialog::exportFrame(int count)
Q_ASSERT(m_exporter);
count = qMax(1, count);

const QImage image = m_paintengine->getPixmap().toImage();
QImage image;
m_paintengine->withPixmap([&image](const QPixmap &pixmap) {
image = pixmap.toImage();
});
if(image.isNull()) {
qWarning("exportFrame: image is null!");
onExporterReady();
Expand Down
30 changes: 15 additions & 15 deletions src/desktop/docks/navigator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ NavigatorView::NavigatorView(QWidget *parent)
void NavigatorView::setCanvasModel(canvas::CanvasModel *model)
{
m_model = model;
connect(m_model->paintEngine(), &canvas::PaintEngine::areaChanged, this, &NavigatorView::onChange);
connect(m_model->paintEngine(), &canvas::PaintEngine::resized, this, &NavigatorView::onResize);
connect(m_model->paintEngine(), &canvas::PaintEngine::areaChanged, this, &NavigatorView::onChange, Qt::QueuedConnection);
connect(m_model->paintEngine(), &canvas::PaintEngine::resized, this, &NavigatorView::onResize, Qt::QueuedConnection);
connect(m_model->paintEngine(), &canvas::PaintEngine::cursorMoved, this, &NavigatorView::onCursorMove);

refreshCache();
Expand Down Expand Up @@ -157,22 +157,22 @@ void NavigatorView::onResize()

void NavigatorView::refreshCache()
{
if(!m_model)
return;

const QPixmap &canvas = m_model->paintEngine()->getPixmap();
if(canvas.isNull())
if(!m_model) {
return;

const QSize size = this->size();
if(size != m_cachedSize) {
m_cachedSize = size;
const QSize pixmapSize = canvas.size().scaled(size, Qt::KeepAspectRatio);
m_cache = QPixmap(pixmapSize);
}

QPainter painter(&m_cache);
painter.drawPixmap(m_cache.rect(), canvas);
m_model->paintEngine()->withPixmap([this](const QPixmap &pixmap) {
if(!pixmap.isNull()) {
QSize navigatorSize = size();
if(navigatorSize != m_cachedSize) {
m_cachedSize = navigatorSize;
m_cache = QPixmap{
pixmap.size().scaled(navigatorSize, Qt::KeepAspectRatio)};
}
QPainter painter(&m_cache);
painter.drawPixmap(m_cache.rect(), pixmap);
}
});

update();
}
Expand Down
4 changes: 3 additions & 1 deletion src/desktop/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2509,7 +2509,9 @@ void MainWindow::resizeCanvas()

const QSize size = m_doc->canvas()->size();
dialogs::ResizeDialog *dlg = new dialogs::ResizeDialog(size, this);
dlg->setPreviewImage(m_doc->canvas()->paintEngine()->getPixmap().scaled(300, 300, Qt::KeepAspectRatio).toImage());
m_doc->canvas()->paintEngine()->withPixmap([dlg](const QPixmap &pixmap) {
dlg->setPreviewImage(pixmap.scaled(300, 300, Qt::KeepAspectRatio).toImage());
});
dlg->setAttribute(Qt::WA_DeleteOnClose);

// Preset crop from selection if one exists
Expand Down
8 changes: 5 additions & 3 deletions src/desktop/scene/canvasitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ void CanvasItem::setPaintEngine(canvas::PaintEngine *pe)
{
m_image = pe;
if(m_image) {
connect(m_image, &canvas::PaintEngine::areaChanged, this, &CanvasItem::refreshImage);
connect(m_image, &canvas::PaintEngine::resized, this, &CanvasItem::canvasResize);
connect(m_image, &canvas::PaintEngine::areaChanged, this, &CanvasItem::refreshImage, Qt::QueuedConnection);
connect(m_image, &canvas::PaintEngine::resized, this, &CanvasItem::canvasResize, Qt::QueuedConnection);
}
canvasResize();
}
Expand Down Expand Up @@ -74,7 +74,9 @@ void CanvasItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option
{
if(m_image) {
QRect exposed = option->exposedRect.toAlignedRect();
painter->drawPixmap(exposed, m_image->getPixmapView(m_visibleArea), exposed);
m_image->withPixmap([&](const QPixmap &pixmap) {
painter->drawPixmap(exposed, pixmap, exposed);
});
if(m_pixelGrid) {
QPen pen(QColor(160, 160, 160));
pen.setCosmetic(true);
Expand Down
2 changes: 1 addition & 1 deletion src/desktop/scene/canvasscene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ void CanvasScene::initCanvas(canvas::CanvasModel *model)

connect(
m_model->paintEngine(), &canvas::PaintEngine::resized, this,
&CanvasScene::handleCanvasResize);
&CanvasScene::handleCanvasResize, Qt::QueuedConnection);
connect(
m_model->paintEngine(), &canvas::PaintEngine::annotationsChanged, this,
&CanvasScene::annotationsChanged);
Expand Down
2 changes: 2 additions & 0 deletions src/drawdance/libcommon/dpcommon/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,11 @@ DP_INLINE size_t DP_flex_size(size_t type_size, size_t flex_offset,
* member. Takes potential trailing padding being used as part of the flexible
* array member into account.
*/
// NOLINTBEGIN(bugprone-sizeof-expression)
#define DP_FLEX_SIZEOF(TYPE, FIELD, COUNT) \
DP_flex_size(sizeof(TYPE), offsetof(TYPE, FIELD), \
sizeof(((TYPE *)NULL)->FIELD[0]), COUNT)
// NOLINTEND(bugprone-sizeof-expression)


void *DP_malloc(size_t size) DP_MALLOC_ATTR;
Expand Down
2 changes: 2 additions & 0 deletions src/drawdance/libengine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ dp_target_sources(dpengine
dpengine/pixels.c
dpengine/player.c
dpengine/recorder.c
dpengine/renderer.c
dpengine/snapshots.c
dpengine/text.c
dpengine/tile.c
Expand Down Expand Up @@ -72,6 +73,7 @@ dp_target_sources(dpengine
dpengine/pixels.h
dpengine/player.h
dpengine/recorder.h
dpengine/renderer.h
dpengine/snapshots.h
dpengine/text.h
dpengine/tile.h
Expand Down
Loading

0 comments on commit 6fb6a45

Please sign in to comment.