Added initial implementation of arc painter.
This commit is contained in:
parent
5d74463bc9
commit
5bcd894429
4 changed files with 173 additions and 0 deletions
|
|
@ -69,6 +69,8 @@ PRIVATE
|
|||
ui/layers/layer_manager.h
|
||||
ui/layers/layer_widget.cpp
|
||||
ui/layers/layer_widget.h
|
||||
ui/paint/arcs.cpp
|
||||
ui/paint/arcs.h
|
||||
ui/paint/blob.cpp
|
||||
ui/paint/blob.h
|
||||
ui/paint/blobs.cpp
|
||||
|
|
|
|||
92
ui/paint/arcs.cpp
Normal file
92
ui/paint/arcs.cpp
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
// This file is part of Desktop App Toolkit,
|
||||
// a set of libraries for developing nice desktop applications.
|
||||
//
|
||||
// For license and copyright information please follow this link:
|
||||
// https://github.com/desktop-app/legal/blob/master/LEGAL
|
||||
//
|
||||
#include "ui/paint/arcs.h"
|
||||
|
||||
#include "ui/painter.h"
|
||||
|
||||
namespace Ui::Paint {
|
||||
|
||||
ArcsAnimation::ArcsAnimation(
|
||||
const style::ArcsAnimation &st,
|
||||
int count,
|
||||
VerticalDirection direction,
|
||||
int centerX,
|
||||
int startY)
|
||||
: _st(st)
|
||||
, _center(centerX)
|
||||
, _start(startY)
|
||||
, _horizontalDirection(HorizontalDirection::None)
|
||||
, _verticalDirection(direction)
|
||||
, _startAngle((st.deltaAngle
|
||||
+ ((direction == VerticalDirection::Up) ? 90 : 270)) * 16)
|
||||
, _spanAngle(-st.deltaAngle * 2 * 16) {
|
||||
initArcs(count);
|
||||
}
|
||||
|
||||
ArcsAnimation::ArcsAnimation(
|
||||
const style::ArcsAnimation &st,
|
||||
int count,
|
||||
HorizontalDirection direction,
|
||||
int startX,
|
||||
int centerY)
|
||||
: _st(st)
|
||||
, _center(centerY)
|
||||
, _start(startX)
|
||||
, _horizontalDirection(direction)
|
||||
, _verticalDirection(VerticalDirection::None)
|
||||
, _startAngle((st.deltaAngle
|
||||
+ ((direction == HorizontalDirection::Left) ? 180 : 0)) * 16)
|
||||
, _spanAngle(-st.deltaAngle * 2 * 16) {
|
||||
initArcs(count);
|
||||
}
|
||||
|
||||
void ArcsAnimation::initArcs(int count) {
|
||||
_arcs.reserve(count);
|
||||
|
||||
for (auto i = 0; i < count; i++) {
|
||||
auto arc = Arc{ .rect = computeArcRect(i) };
|
||||
_arcs.push_back(std::move(arc));
|
||||
}
|
||||
}
|
||||
|
||||
QRectF ArcsAnimation::computeArcRect(int index) const {
|
||||
const auto w = _st.startWidth + _st.deltaWidth * index;
|
||||
const auto h = _st.startHeight + _st.deltaHeight * index;
|
||||
if (_horizontalDirection != HorizontalDirection::None) {
|
||||
auto rect = QRectF(0, _center - h / 2.0, w, h);
|
||||
if (_horizontalDirection == HorizontalDirection::Right) {
|
||||
rect.moveRight(_start + index * _st.space);
|
||||
} else {
|
||||
rect.moveLeft(_start - index * _st.space);
|
||||
}
|
||||
return rect;
|
||||
} else if (_verticalDirection != VerticalDirection::None) {
|
||||
auto rect = QRectF(_center - w / 2.0, 0, w, h);
|
||||
if (_verticalDirection == VerticalDirection::Up) {
|
||||
rect.moveTop(_start - index * _st.space);
|
||||
} else {
|
||||
rect.moveBottom(_start + index * _st.space);
|
||||
}
|
||||
return rect;
|
||||
}
|
||||
return QRectF();
|
||||
}
|
||||
|
||||
void ArcsAnimation::paint(Painter &p, std::optional<QColor> colorOverride) {
|
||||
PainterHighQualityEnabler hq(p);
|
||||
QPen pen;
|
||||
pen.setWidth(_st.stroke);
|
||||
pen.setCapStyle(Qt::RoundCap);
|
||||
pen.setColor(colorOverride ? (*colorOverride) : _st.fg->c);
|
||||
p.setPen(pen);
|
||||
for (const auto &arc : _arcs) {
|
||||
p.drawArc(arc.rect, _startAngle, _spanAngle);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} // namespace Ui::Paint
|
||||
68
ui/paint/arcs.h
Normal file
68
ui/paint/arcs.h
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
// This file is part of Desktop App Toolkit,
|
||||
// a set of libraries for developing nice desktop applications.
|
||||
//
|
||||
// For license and copyright information please follow this link:
|
||||
// https://github.com/desktop-app/legal/blob/master/LEGAL
|
||||
//
|
||||
#pragma once
|
||||
|
||||
#include "styles/style_widgets.h"
|
||||
|
||||
class Painter;
|
||||
|
||||
namespace Ui::Paint {
|
||||
|
||||
class ArcsAnimation {
|
||||
public:
|
||||
|
||||
enum class HorizontalDirection {
|
||||
Left,
|
||||
Right,
|
||||
None,
|
||||
};
|
||||
|
||||
enum class VerticalDirection {
|
||||
Up,
|
||||
Down,
|
||||
None,
|
||||
};
|
||||
|
||||
ArcsAnimation(
|
||||
const style::ArcsAnimation &st,
|
||||
int count,
|
||||
VerticalDirection direction,
|
||||
int centerX,
|
||||
int startY);
|
||||
|
||||
ArcsAnimation(
|
||||
const style::ArcsAnimation &st,
|
||||
int count,
|
||||
HorizontalDirection direction,
|
||||
int startX,
|
||||
int centerY);
|
||||
|
||||
void paint(
|
||||
Painter &p,
|
||||
std::optional<QColor> colorOverride = std::nullopt);
|
||||
|
||||
private:
|
||||
struct Arc {
|
||||
QRectF rect;
|
||||
};
|
||||
|
||||
void initArcs(int count);
|
||||
QRectF computeArcRect(int index) const;
|
||||
|
||||
const style::ArcsAnimation &_st;
|
||||
const int _center;
|
||||
const int _start;
|
||||
const HorizontalDirection _horizontalDirection;
|
||||
const VerticalDirection _verticalDirection;
|
||||
const int _startAngle;
|
||||
const int _spanAngle;
|
||||
|
||||
std::vector<Arc> _arcs;
|
||||
|
||||
};
|
||||
|
||||
} // namespace Ui::Paint
|
||||
|
|
@ -410,6 +410,17 @@ CrossLineAnimation {
|
|||
stroke: pixels;
|
||||
}
|
||||
|
||||
ArcsAnimation {
|
||||
fg: color;
|
||||
stroke: pixels;
|
||||
space: pixels;
|
||||
deltaAngle: int;
|
||||
deltaHeight: pixels;
|
||||
deltaWidth: pixels;
|
||||
startHeight: pixels;
|
||||
startWidth: pixels;
|
||||
}
|
||||
|
||||
MultiSelectItem {
|
||||
padding: margins;
|
||||
maxWidth: pixels;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue