18#include "camerapainter.h"
23#include "layercamera.h"
29#include "painterutils.h"
31CameraPainter::CameraPainter(
QPixmap& canvas) : mCanvas(canvas)
36void CameraPainter::reset()
43void CameraPainter::resetCache()
45 mCameraCacheValid =
false;
48void CameraPainter::preparePainter(
const Object*
object,
53 LayerVisibility layerVisibility,
54 float relativeLayerOpacityThreshold,
58 mCurrentLayerIndex = layerIndex;
59 mFrameIndex = frameIndex;
60 mViewTransform = transform;
61 mIsPlaying = isPlaying;
62 mLayerVisibility = layerVisibility;
63 mRelativeLayerOpacityThreshold = relativeLayerOpacityThreshold;
64 mViewScale = viewScale;
67void CameraPainter::paint(
const QRect& blitRect)
70 initializePainter(painter, mCanvas, blitRect,
false);
71 paintVisuals(painter, blitRect);
73 mCameraCacheValid =
true;
76void CameraPainter::paintCached(
const QRect& blitRect)
82 initializePainter(painter, mCanvas, blitRect,
false);
83 if (!mCameraCacheValid) {
84 paintVisuals(painter, blitRect);
86 mCameraCacheValid =
true;
95void CameraPainter::initializePainter(
QPainter& painter,
QPixmap& pixmap,
const QRect& blitRect,
bool blitEnabled)
97 painter.
begin(&pixmap);
111void CameraPainter::paintVisuals(
QPainter& painter,
const QRect& blitRect)
113 LayerCamera* cameraLayerBelow =
static_cast<LayerCamera*
>(mObject->getLayerBelow(mCurrentLayerIndex, Layer::CAMERA));
115 if (cameraLayerBelow ==
nullptr) {
return; }
117 const Layer* currentLayer = mObject->getLayer(mCurrentLayerIndex);
119 if (mLayerVisibility == LayerVisibility::CURRENTONLY && currentLayer->type() != Layer::CAMERA) {
return; }
122 initializePainter(visualsPainter, mCameraPixmap, blitRect,
true);
124 if (!mIsPlaying || mOnionSkinOptions.enabledWhilePlaying) {
127 int endLayerI = mObject->getLayerCount() - 1;
128 for (
int i = startLayerI; i <= endLayerI; i++) {
129 Layer* layer = mObject->getLayer(i);
130 if (layer->type() != Layer::CAMERA) {
continue; }
134 bool isCurrentLayer = cameraLayer == cameraLayerBelow;
136 visualsPainter.
save();
138 if (mLayerVisibility == LayerVisibility::RELATED && !isCurrentLayer) {
139 visualsPainter.
setOpacity(calculateRelativeOpacityForLayer(mCurrentLayerIndex, i, mRelativeLayerOpacityThreshold));
142 paintOnionSkinning(visualsPainter, cameraLayer);
148 if (!cameraLayerBelow->visible()) {
return; }
150 QTransform camTransform = cameraLayerBelow->getViewAtFrame(mFrameIndex);
151 QRect cameraRect = cameraLayerBelow->getViewRect();
152 paintBorder(visualsPainter, camTransform, cameraRect);
155 painter.
drawPixmap(mZeroPoint, mCameraPixmap);
173 QPolygon boundingRectPoly = boundingRect;
189 onionSkinPen.
setStyle(Qt::PenStyle::DashLine);
190 mOnionSkinPainter.paint(painter, cameraLayer, mOnionSkinOptions, mFrameIndex, [&] (OnionSkinPaintState state,
int onionSkinNumber) {
192 const QTransform& cameraTransform = cameraLayer->getViewAtFrame(onionSkinNumber);
193 const QPolygonF& cameraPolygon = Transform::mapToWorldPolygon(cameraTransform, mViewTransform, cameraLayer->getViewRect());
194 if (state == OnionSkinPaintState::PREV) {
196 if (mOnionSkinOptions.colorizePrevFrames) {
200 painter.
setPen(onionSkinPen);
202 }
else if (state == OnionSkinPaintState::NEXT) {
203 if (mOnionSkinOptions.colorizeNextFrames) {
207 painter.
setPen(onionSkinPen);
209 }
else if (state == OnionSkinPaintState::CURRENT) {
qreal devicePixelRatioF() const const
bool begin(QPaintDevice *device)
void drawPixmap(const QRectF &target, const QPixmap &pixmap, const QRectF &source)
void drawPolygon(const QPointF *points, int pointCount, Qt::FillRule fillRule)
void fillRect(const QRectF &rectangle, const QBrush &brush)
void setBrush(const QBrush &brush)
void setClipRect(const QRectF &rectangle, Qt::ClipOperation operation)
void setCompositionMode(QPainter::CompositionMode mode)
void setOpacity(qreal opacity)
void setPen(const QColor &color)
void setWorldMatrixEnabled(bool enable)
QRect viewport() const const
void setColor(const QColor &color)
void setStyle(Qt::PenStyle style)
void fill(const QColor &color)
void setDevicePixelRatio(qreal scaleFactor)
QPolygon subtracted(const QPolygon &r) const const
QTextStream & reset(QTextStream &stream)