Canvas commands very nearly working, build broken

This commit is contained in:
Ada 2025-02-28 06:04:31 +10:00
parent d502a292b7
commit 9701dce201
3 changed files with 25 additions and 7 deletions

View file

@ -134,8 +134,9 @@ void CanvasEntityItem::paintCommands(const QVector<CanvasCommand>& queue) {
case V::SetColor: { case V::SetColor: {
auto props = cmd._setColor; auto props = cmd._setColor;
pen.setColor(props.color); auto color = QColor(props.color[0], props.color[1], props.color[2], 255);
brush.setColor(props.color); pen.setColor(color);
brush.setColor(color);
p.setPen(pen); p.setPen(pen);
p.setBrush(brush); p.setBrush(brush);
break; break;

View file

@ -52,7 +52,7 @@ ScriptValue canvasCommandToScriptValue(ScriptEngine* engine, const CanvasCommand
case Variant::SetColor: { case Variant::SetColor: {
auto props = cmd._setColor; auto props = cmd._setColor;
obj.setProperty("color", u8vec3ColorToScriptValue(engine, glm::u8vec3(props.color.red(), props.color.green(), props.color.blue()))); obj.setProperty("color", u8vec3ColorToScriptValue(engine, props.color));
return obj; return obj;
} }
@ -195,7 +195,7 @@ bool canvasCommandFromScriptValue(const ScriptValue& object, CanvasCommand& cmd)
if (!u8vec3FromScriptValue(object.property("color"), c)) { return false; } if (!u8vec3FromScriptValue(object.property("color"), c)) { return false; }
// FIXME: we have a script RGB color type but not an RGBA one // FIXME: we have a script RGB color type but not an RGBA one
cmd.set(CanvasCommand::SetColor { QColor(c[0], c[1], c[2], 255) }); cmd.set(CanvasCommand::SetColor { c });
} else if (type == static_cast<uint>(Variant::SetHints)) { } else if (type == static_cast<uint>(Variant::SetHints)) {
cmd.set(CanvasCommand::SetHints { cmd.set(CanvasCommand::SetHints {
static_cast<CanvasCommand::RenderHint>(object.property("hints").toVariant().toUInt()) static_cast<CanvasCommand::RenderHint>(object.property("hints").toVariant().toUInt())
@ -368,8 +368,7 @@ ScriptValue canvasImageToScriptValue(ScriptEngine* engine, const CanvasImage& im
bool canvasImageFromScriptValue(const ScriptValue& object, CanvasImage& img) { bool canvasImageFromScriptValue(const ScriptValue& object, CanvasImage& img) {
img.width = object.property(IMG_WIDTH_PROP_NAME).toVariant().toUInt(); img.width = object.property(IMG_WIDTH_PROP_NAME).toVariant().toUInt();
img.height = object.property(IMG_HEIGHT_PROP_NAME).toVariant().toUInt(); img.height = object.property(IMG_HEIGHT_PROP_NAME).toVariant().toUInt();
img.buffer = object.property(IMG_BUFFER_PROP_NAME).toVariant().toByteArray(); return qBytearrayFromScriptValue(object.property(IMG_BUFFER_PROP_NAME), img.buffer);
return true;
} }
CanvasImage canvasImageFromScriptValue(const ScriptValue& object) { CanvasImage canvasImageFromScriptValue(const ScriptValue& object) {

View file

@ -17,6 +17,7 @@
#define hifi_CanvasCommand_h #define hifi_CanvasCommand_h
#include "ScriptValue.h" #include "ScriptValue.h"
#include "ScriptValueUtils.h"
#include <QColor> #include <QColor>
#include <QPainter> #include <QPainter>
@ -63,7 +64,7 @@ public:
struct Invalid {}; struct Invalid {};
struct SetStrokeWidth { qreal width; }; struct SetStrokeWidth { qreal width; };
struct SetColor { QColor color; }; struct SetColor { glm::u8vec3 color; };
struct SetHints { RenderHint hints; }; struct SetHints { RenderHint hints; };
struct SetBlendMode { QPainter::CompositionMode mode; }; struct SetBlendMode { QPainter::CompositionMode mode; };
struct SetFont { QString family; int size; int weight; bool italic; }; struct SetFont { QString family; int size; int weight; bool italic; };
@ -242,6 +243,23 @@ private:
Variant _tag; Variant _tag;
}; };
class CanvasCommandFactory : public QObject {
Q_OBJECT
public:
static CanvasCommand setStrokeWidth(qreal width) {
return CanvasCommand(CanvasCommand::SetStrokeWidth { width });
}
static CanvasCommand setColor(glm::u8vec3 color) {
return CanvasCommand(CanvasCommand::SetColor { color });
}
static CanvasCommand setHints(uint hints) {
return CanvasCommand(CanvasCommand::SetHints { static_cast<CanvasCommand::RenderHint>(hints) });
}
};
void registerCanvasMetaTypes(ScriptEngine *engine); void registerCanvasMetaTypes(ScriptEngine *engine);
Q_DECLARE_METATYPE(CanvasCommand) Q_DECLARE_METATYPE(CanvasCommand)