16 #ifndef hifi_CanvasCommand_h
17 #define hifi_CanvasCommand_h
19 #include "ScriptValue.h"
20 #include "ScriptValueUtils.h"
21 #include "Scriptable.h"
24 #include <QPainterPath>
41 CanvasImage() : buffer(QByteArray()), width(0), height(0), _ownsData(true) {}
42 CanvasImage(QByteArray buffer,
int width,
int height) : buffer(buffer), width(width), height(height), _ownsData(true) {}
55 struct CanvasPathElement {
57 qreal x, y, c1x, c1y, c2x, c2y;
59 CanvasPathElement(
int type, qreal x, qreal y) : type(type), x(x), y(y), c1x(0), c1y(0), c2x(0), c2y(0) {}
60 CanvasPathElement(
int type, qreal x, qreal y, qreal c1x, qreal c1y, qreal c2x, qreal c2y) : type(type), x(x), y(y), c1x(c1x), c1y(c1y), c2x(c2x), c2y(c2y) {}
61 CanvasPathElement() : type(0), x(0), y(0), c1x(0), c1y(0), c2x(0), c2y(0) {}
330 struct CanvasCommand {
353 NoPrimitiveAntialiasing = (1 << 0),
354 NoTextAntialiasing = (1 << 1),
355 NearestImageScaling = (1 << 2),
358 static CanvasCommand none() {
359 return CanvasCommand {};
362 static CanvasCommand setStrokeWidth(qreal width) {
364 cmd.kind = SetStrokeWidth;
365 cmd._float[0] = width;
369 static CanvasCommand setColor(
const QColor& color) {
376 static CanvasCommand setHints(
int hints) {
383 static CanvasCommand setBlendMode(
int mode) {
385 cmd.kind = SetBlendMode;
390 static CanvasCommand setFont(
const QString& family,
int size,
int weight,
bool italic) {
395 cmd._int[1] = weight;
396 cmd._int[2] = italic;
400 static CanvasCommand clearRect(
int x,
int y,
int w,
int h) {
402 cmd.kind = ClearRect;
410 static CanvasCommand fillPath(
const QPainterPath& path) {
413 cmd._paintPath = path;
417 static CanvasCommand fillRect(
const QRectF& rect) {
420 return CanvasCommand { .kind = FillRect, ._rect = rect };
423 static CanvasCommand fillEllipse(
const QRectF& rect) {
425 cmd.kind = FillEllipse;
430 static CanvasCommand fillText(
const QString& text,
const QRectF& rect,
int flag) {
439 static CanvasCommand strokePath(
const QPainterPath& path) {
441 cmd.kind = StrokePath;
442 cmd._paintPath = path;
446 static CanvasCommand strokeRect(
const QRectF& rect) {
448 cmd.kind = StrokeRect;
453 static CanvasCommand strokeArc(
const QRectF& rect, qreal startAngle, qreal spanAngle) {
455 cmd.kind = StrokeArc;
457 cmd._float[0] = startAngle;
458 cmd._float[1] = spanAngle;
462 static CanvasCommand strokeEllipse(
const QRectF& rect) {
464 cmd.kind = StrokeEllipse;
469 static CanvasCommand point(qreal x, qreal y) {
472 cmd._point = QPointF(x, y);
476 static CanvasCommand line(qreal x1, qreal y1, qreal x2, qreal y2) {
479 cmd._line = QLineF(x1, y1, x2, y2);
483 static CanvasCommand imageCopy(
const CanvasImage& image,
const QRectF& src,
const QRectF& dst) {
485 cmd.kind = ImageCopy;
492 Variant kind = Invalid;
494 QRectF _rect = QRectF();
495 QRectF _rect2 = QRectF();
496 QString _text = QString();
497 QPointF _point = QPointF();
498 QLineF _line = QLineF();
499 qreal _float[4] = {};
502 QPainterPath _paintPath = QPainterPath();
503 CanvasImage _image = {};
508 Q_DECLARE_METATYPE(CanvasCommand)
510 bool canvasCommandFromScriptValue(
const ScriptValue&
object, CanvasCommand& cmd);
511 CanvasCommand canvasCommandFromScriptValue(
const ScriptValue&
object);
513 Q_DECLARE_METATYPE(QPainterPath)
515 bool qPainterPathFromScriptValue(
const ScriptValue&
object, QPainterPath& path);
516 QPainterPath qPainterPathFromScriptValue(
const ScriptValue&
object);
518 Q_DECLARE_METATYPE(QVector<CanvasCommand>)
520 bool qVectorCanvasCommandFromScriptValue(
const ScriptValue&
object, QVector<CanvasCommand>& list);
521 QVector<CanvasCommand> qVectorCanvasCommandFromScriptValue(
const ScriptValue&
object);
523 Q_DECLARE_METATYPE(CanvasImage)
525 bool canvasImageFromScriptValue(
const ScriptValue&
object, CanvasImage& img);
526 CanvasImage canvasImageFromScriptValue(
const ScriptValue&
object);
528 Q_DECLARE_METATYPE(CanvasPathElement)
530 bool canvasPathElementFromScriptValue(
const ScriptValue&
object, CanvasPathElement& elem);
531 CanvasPathElement canvasPathElementFromScriptValue(
const ScriptValue&
object);
Provides an engine-independent interface for a scripting engine.
Definition: ScriptEngine.h:93
[ScriptInterface] Provides an engine-independent interface for QScriptValue
Definition: ScriptValue.h:40