载入中...
搜索中...
未找到
CanvasScriptBindings.cpp
浏览该文件的文档.
2#include "graphics/Canvas.h"
3#include "graphics/Texture.h"
4#include "image/ImageData.h"
6#include <simplesquirrel/simplesquirrel.hpp>
7#include <memory>
8#include <exception>
9namespace eve::graphics {
10void exposeCanvasScriptBindings(ssq::Table& table) {
11 const auto vm = table.getHandle();
12 auto cls = table.addClass<Canvas>("Canvas", std::function<Canvas*()>([]() -> Canvas* { return nullptr; }), true);
13 cls.addFunc("getWidth", &Canvas::getWidth);
14 cls.addFunc("getHeight", &Canvas::getHeight);
15 cls.addFunc("getTexture", &Canvas::getTexture);
16 cls.addFunc("newHDRImageData", &Canvas::newHDRImageData);
17 // Synchronous owner-thread snapshot; script owns the resulting ImageData.
18 cls.addFunc("readPixels", [vm](Canvas* self) {
19 try {
20 if (!self) throw std::runtime_error("canvas must not be null");
21 std::unique_ptr<image::ImageData> pixels(self->newImageData());
22 if (!pixels) throw std::runtime_error("canvas has no readable RGBA8 pixels");
24 auto result = eve::script::projectStatusResult(vm, status.status());
25 result.set("value", pixels.get());
27 result.set("ownership", std::string("script-owned"));
28 pixels.release();
29 return result;
30 } catch (const std::exception& error) {
32 Diagnostic::error(DiagnosticCode::Failed, error.what(), "canvas.readPixels")));
33 }
34 });
35}
36} // namespace eve::graphics
HSQUIRRELVM vm
Definition ECS.cpp:20
HSQOBJECT cls
Definition ECS.cpp:21
wgpu::PopErrorScopeStatus status
std::string error
Definition Package.cpp:60
uint8_t * pixels
The single Squirrel projection for common Result, Status and Value.
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={}, DiagnosticDetails details={}, std::string source={})
Construct an error diagnostic with the standard error severity.
Definition Diagnostic.h:125
Move-only operation result carrying either a value or Status.
Definition Result.h:155
static Result success(T value)
Construct a successful result owning value.
Definition Result.h:164
Canvas public API.
Definition Canvas.h:17
virtual int getWidth() const =0
Returns the width.
virtual image::ImageData * newImageData()=0
Creates a image data. @ownership Caller deletes unless documented otherwise.
virtual image::ImageData * newHDRImageData()
Copy an HDR Canvas as linear RGBA16F without tone mapping.
Definition Canvas.h:53
virtual Texture * getTexture()=0
Sampleable color buffer; screen Canvas returns nullptr.
virtual int getHeight() const =0
Returns the height.
卡牌游戏 UI 工具模块:工厂 + 脚本绑定入口。 功能参考 ycarowr/UiCard:扇形手牌布局、抽牌/洗牌、悬浮放大、拖拽到落牌区、 敌方手牌(背面/偷看)、费用不足置灰,以及可实时调节的布局...
Definition Animation.h:25
void exposeCanvasScriptBindings(ssq::Table &table)
Register canvas bindings on the VM owner thread; retains no table reference.
void markResultHasValue(ssq::Table &result)
Declare that a projected table received a payload the caller attached itself.
ssq::Table projectStatusResult(HSQUIRRELVM vm, const Status &status)
Project a checked native status that carries no payload.
ssq::Table projectResult(HSQUIRRELVM vm, Result< void > &&result)
Consume and project a void native Result using the common schema.