Files
z-bar-qt/Plugins/ZShell/Blobs/blobshape2.cpp
T
zach c5608dc9b9
C++ / fmt (pull_request) Failing after 5s
C++ / build (pull_request) Failing after 10s
C++ / clang-tidy (pull_request) Failing after 10s
JS/TS / fmt (pull_request) Successful in 9s
JS/TS / lint (pull_request) Successful in 25s
Python / static (pull_request) Successful in 34s
Rust / build (pull_request) Successful in 51s
Python / verify (pull_request) Failing after 1m25s
Rust / fmt (pull_request) Successful in 39s
Rust / clippy (pull_request) Successful in 59s
fix: blobs now allow to be drawn in device pixels to stay sharp
2026-10-30 01:52:33 +01:00

74 lines
1.8 KiB
C++

#include "blobshape2.hpp"
#include "blobgroup2.hpp"
#include <algorithm>
#include <cmath>
BlobShape2::BlobShape2(QQuickItem* parent) : QQuickItem(parent) {}
void BlobShape2::setGroup(BlobGroup2* g) {
if (m_group == g) return;
if (m_group && isComponentComplete()) unregisterFromGroup();
if (m_group) resetDeformMatrix();
m_group = g;
if (m_group && isComponentComplete()) registerWithGroup();
emit groupChanged();
if (m_group) m_group->markDirty();
}
void BlobShape2::setRadius(qreal r) {
if (qFuzzyCompare(m_radius, r)) return;
m_radius = r;
emit radiusChanged();
if (m_group) m_group->markDirty();
}
void BlobShape2::componentComplete() {
QQuickItem::componentComplete();
if (m_group) registerWithGroup();
}
void BlobShape2::geometryChange(
const QRectF& newGeometry, const QRectF& oldGeometry) {
QQuickItem::geometryChange(newGeometry, oldGeometry);
updateCenteredDeformMatrix();
if (m_group) m_group->markDirty();
}
void BlobShape2::updateCenteredDeformMatrix() {
const auto cx = static_cast<float>(width()) * 0.5f;
const auto cy = static_cast<float>(height()) * 0.5f;
QMatrix4x4 result;
result.translate(cx, cy);
result *= m_deformMatrix;
result.translate(-cx, -cy);
if (m_centeredDeformMatrix != result) {
m_centeredDeformMatrix = result;
emit deformMatrixChanged();
}
}
void BlobShape2::resetDeformMatrix() {
m_deformMatrix = QMatrix4x4();
emit rawDeformMatrixChanged();
updateCenteredDeformMatrix();
}
void BlobShape2::cornerRadii(float out[4]) const {
const auto maxR = static_cast<float>(std::min(width(), height())) * 0.5f;
const auto r = std::min(static_cast<float>(m_radius), maxR);
out[0] = r;
out[1] = r;
out[2] = r;
out[3] = r;
}
void BlobShape2::registerWithGroup() {
if (m_group) m_group->addShape(this);
}
void BlobShape2::unregisterFromGroup() {
if (m_group) m_group->removeShape(this);
}