载入中...
搜索中...
未找到
PcgDraggableWindow.cpp
浏览该文件的文档.
2#include <algorithm>
3#include <cmath>
4#include <simplesquirrel/simplesquirrel.hpp>
5
7
8namespace eve::ui {
9 // namespace
10
11Result<void> PcgDraggableWindow::configure(float x, float y, float width, float height, float screenWidth,
12 float screenHeight, float scale) {
13 if (!std::isfinite(x) || !std::isfinite(y) || !std::isfinite(width) || !std::isfinite(height) ||
14 !std::isfinite(screenWidth) || !std::isfinite(screenHeight) || !std::isfinite(scale) || width <= 0 ||
15 height <= 0 || screenWidth < width || screenHeight < height || scale <= 0)
17 Diagnostic::error(DiagnosticCode::InvalidArgument, "invalid draggable-window geometry", "ui.pcgDraggableWindow"));
18 x_ = resetX_ = x;
19 y_ = resetY_ = y;
20 width_ = width;
21 height_ = height;
22 screenWidth_ = screenWidth;
23 screenHeight_ = screenHeight;
24 scale_ = scale;
25 configured_ = true;
26 bringToFront_ = false;
27 return Result<void>::success();
28}
29
31 if (!configured_) return Result<void>::failure(
32 Diagnostic::error(DiagnosticCode::InvalidArgument, "draggable window is not configured", "ui.pcgDraggableWindow"));
33 if (!std::isfinite(dx) || !std::isfinite(dy)) return Result<void>::failure(
34 Diagnostic::error(DiagnosticCode::InvalidArgument, "pointer delta must be finite", "ui.pcgDraggableWindow"));
35 const float x = x_ + dx / scale_;
36 const float y = y_ + dy / scale_;
37 x_ = -std::clamp(std::abs(x), width_ * .5f, screenWidth_ - width_ * .5f);
38 y_ = std::clamp(std::abs(y), height_ * .5f, screenHeight_ - height_ * .5f);
39 return Result<void>::success();
40}
41
42void PcgDraggableWindow::pointerDown(bool middle) noexcept {
43 bringToFront_ = true;
44 if (middle && configured_) {
45 x_ = resetX_;
46 y_ = resetY_;
47 }
48}
49
52 bringToFront_ = false;
53 return value;
54}
55
56void exposePcgDraggableWindowBindings(ssq::Table& table) {
57 auto cls = table.addClass("PcgDraggableWindow", ssq::Class::Ctor<PcgDraggableWindow()>());
58 auto vm = table.getHandle();
59 cls.addFunc("configure", [vm](PcgDraggableWindow* self, float x, float y, float width, float height,
60 float screenWidth, float screenHeight, float scale) {
62 vm, self->configure(x, y, width, height, screenWidth, screenHeight, scale));
63 });
64 cls.addFunc("drag", [vm](PcgDraggableWindow* self, float x, float y) {
65 return eve::script::projectResult(vm, self->drag(x, y));
66 });
67 cls.addFunc("pointerDown", [](PcgDraggableWindow* self, bool middle) { self->pointerDown(middle); });
68 cls.addFunc("consumeBringToFront", [](PcgDraggableWindow* self) {
70 });
71 cls.addFunc("getX", [](const PcgDraggableWindow* self) { return self->getX(); });
72 cls.addFunc("getY", [](const PcgDraggableWindow* self) { return self->getY(); });
73}
74} // namespace eve::ui
double y
double x
HSQUIRRELVM vm
Definition ECS.cpp:38
HSQOBJECT cls
Definition ECS.cpp:39
std::uint32_t height
std::uint32_t width
std::array< float, 3 > scale
glm::dvec3 dx
Object::Ptr value
float dy
Definition Shadow.cpp:151
The single Squirrel projection for common Result, Status and Value.
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={})
Construct an error diagnostic with the standard error severity.
Move-only operation result carrying either a value or Status.
Definition Result.h:176
static Result success(T value)
Construct a successful result owning value.
Definition Result.h:185
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:196
Caller-owned state for Pcg's draggable photo-mode window.
Result< void > configure(float x, float y, float width, float height, float screenWidth, float screenHeight, float canvasScale)
Configure geometry and remember the exact reset position atomically.
float getY() const noexcept
Return current anchored Y.
float getX() const noexcept
Return current anchored X.
Result< void > drag(float deltaX, float deltaY)
Apply one pointer delta divided by canvas scale and clamp to Pcg bounds.
PcgUiRequestStatus consumeBringToFront() noexcept
Consume the request to move the window to the front.
void pointerDown(bool middleButtonDown) noexcept
Process pointer-down; middleButtonDown restores the initial position.
ssq::Table projectResult(HSQUIRRELVM vm, Result< void > &&result)
Consume and project a void native Result using the common schema.
void exposePcgDraggableWindowBindings(ssq::Table &table)
Register Pcg draggable-window bindings.
PcgUiRequestStatus
Explicit status returned when consuming a one-shot Pcg UI request.
Definition PcgUiStatus.h:4