Showing the changes to libraries/entities/src/EntityScriptingInterface.cpp (1 of 4 files). Show all
Unified · Split
| @@ -2706,17 +2706,60 @@ void EntityScriptingInterface::canvasPushImage(const QUuid& entityID, const Canv · 2705 unmodified lines | |||
| 2706 | auto canvas = std::dynamic_pointer_cast<CanvasEntityItem>(entity); | 2706 | auto canvas = std::dynamic_pointer_cast<CanvasEntityItem>(entity); |
| 2707 | 2707 | ||
| 2708 | if (image.buffer.length() != (int)(4 * image.width * image.height)) { | 2708 | if (image.buffer.length() != (int)(4 * image.width * image.height)) { |
| 2709 | qCWarning(entities) << "canvasPushImage: \"image\" has invalid buffer size, expected " << (4 * image.width * image.height) << ", got " << image.buffer.length(); | 2709 | qCCritical(entities) << "canvasPushImage: \"image\" has invalid buffer size, expected " << (4 * image.width * image.height) << ", got " << image.buffer.length(); |
| 2710 | return; | 2710 | return; |
| 2711 | } | 2711 | } |
| 2712 | 2712 | ||
| 2713 | if (image.width != canvas->getWidth() || image.height != canvas->getHeight()) { | 2713 | if (image.width != canvas->getWidth() || image.height != canvas->getHeight()) { |
| 2714 | qCWarning(entities) << "canvasPushImage: \"image\" dimensions don't match canvas, expected " << canvas->getWidth() << "x" << canvas->getHeight() << ", got " << image.width << "x" << image.height; | 2714 | qCCritical(entities) << "canvasPushImage: \"image\" dimensions don't match canvas, expected " << canvas->getWidth() << "x" << canvas->getHeight() << ", got " << image.width << "x" << image.height; |
| 2715 | return; | 2715 | return; |
| 2716 | } | 2716 | } |
| 2717 | 2717 | ||
| 2718 | canvas->setImageData(image); | 2718 | canvas->setImageData(image); |
| 2719 | } else { | 2719 | } else { |
| 2720 | qCWarning(entities) << "canvasSubmitImage called on a non-canvas entity " << entityID; | 2720 | qCWarning(entities) << "canvasPushImage called on a non-canvas entity " << entityID; |
| 2721 | } | ||
| 2722 | } | ||
| 2723 | |||
| 2724 | void EntityScriptingInterface::canvasPushCommands(const QUuid& entityID, const QVector<CanvasCommand>& commands) { | ||
| 2725 | EntityItemPointer entity = _entityTree->findEntityByEntityItemID(EntityItemID(entityID)); | ||
| 2726 | if (!entity) { | ||
| 2727 | return; | ||
| 2728 | } | ||
| 2729 | |||
| 2730 | if (entity->getType() == EntityTypes::Canvas) { | ||
| 2731 | auto canvas = std::dynamic_pointer_cast<CanvasEntityItem>(entity); | ||
| 2732 | canvas->pushCommands(commands); | ||
| 2733 | } else { | ||
| 2734 | qCWarning(entities) << "canvasPushCommands called on a non-canvas entity " << entityID; | ||
| 2735 | } | ||
| 2736 | } | ||
| 2737 | |||
| 2738 | CanvasImage EntityScriptingInterface::canvasGetImage(const QUuid& entityID) { | ||
| 2739 | EntityItemPointer entity = _entityTree->findEntityByEntityItemID(EntityItemID(entityID)); | ||
| 2740 | if (!entity) { | ||
| 2741 | return CanvasImage(); | ||
| 2742 | } | ||
| 2743 | |||
| 2744 | if (entity->getType() == EntityTypes::Canvas) { | ||
| 2745 | auto canvas = std::dynamic_pointer_cast<CanvasEntityItem>(entity); | ||
| 2746 | return CanvasImage { canvas->getImageData(), canvas->getWidth(), canvas->getHeight() }; | ||
| 2747 | } else { | ||
| 2748 | qCWarning(entities) << "canvasCommit called on a non-canvas entity " << entityID; | ||
| 2749 | return CanvasImage(); | ||
| 2750 | } | ||
| 2751 | } | ||
| 2752 | |||
| 2753 | void EntityScriptingInterface::canvasCommit(const QUuid& entityID) { | ||
| 2754 | EntityItemPointer entity = _entityTree->findEntityByEntityItemID(EntityItemID(entityID)); | ||
| 2755 | if (!entity) { | ||
| 2756 | return; | ||
| 2757 | } | ||
| 2758 | |||
| 2759 | if (entity->getType() == EntityTypes::Canvas) { | ||
| 2760 | auto canvas = std::dynamic_pointer_cast<CanvasEntityItem>(entity); | ||
| 2761 | canvas->commit(); | ||
| 2762 | } else { | ||
| 2763 | qCWarning(entities) << "canvasCommit called on a non-canvas entity " << entityID; | ||
| 2721 | } | 2764 | } |
| 2722 | } | 2765 | } |