This commit is contained in:
2026-08-12 08:09:16 +08:00
parent b51833499f
commit b34c0d31b1
8 changed files with 422 additions and 427 deletions
+15 -39
View File
@@ -1,4 +1,5 @@
#include "Web_Event_Adapter.h"
#include "Gallery_Enum.h"
#include <algorithm>
#include <cmath>
@@ -28,27 +29,13 @@ Keyboard_Modifier modifiers(const Json::Value& root) {
Mouse_Button mouse_button(const Json::Value& root) {
const std::string value = root["button"].isString() ? root["button"].asString() : "none";
if (value == "left")
return Mouse_Button::Left;
if (value == "right")
return Mouse_Button::Right;
if (value == "middle")
return Mouse_Button::Middle;
return Mouse_Button::None;
return gallery_enum_cast<Mouse_Button>(value).value_or(Mouse_Button::None);
}
Key key(const Json::Value& root) {
const std::string value = root["key"].isString() ? root["key"].asString() : "";
if (value == "Escape")
return Key::Escape;
if (value == "Enter")
return Key::Enter;
if (value == "Space")
return Key::Space;
if (value == "Delete")
return Key::Delete;
if (value == "Backspace")
return Key::Backspace;
if (const auto direct = magic_enum::enum_cast<Key>(value))
return *direct;
if (value == "ArrowLeft")
return Key::Left;
if (value == "ArrowRight")
@@ -136,20 +123,14 @@ std::optional<Web_Transport_Events> Web_Transport_Event_Decoder::decode(
return Viewport_Resize{{static_cast<int>(std::clamp(*width, 240.0, 1920.0)),
static_cast<int>(std::clamp(*height, 180.0, 1200.0))}};
}
Gallery_Request_Kind kind;
if (type == "gallery_catalog")
kind = Gallery_Request_Kind::Catalog;
else if (type == "gallery_open")
kind = Gallery_Request_Kind::Open;
else if (type == "gallery_patch")
kind = Gallery_Request_Kind::Patch;
else if (type == "gallery_action")
kind = Gallery_Request_Kind::Action;
else if (type == "gallery_observe")
kind = Gallery_Request_Kind::Observe;
else
constexpr std::string_view gallery_prefix = "gallery_";
if (!std::string_view(type).starts_with(gallery_prefix))
return std::nullopt;
return Gallery_Request{kind, std::string(source)};
const auto kind = gallery_enum_cast<Gallery_Request_Kind>(
std::string_view(type).substr(gallery_prefix.size()));
return kind ? std::optional<Web_Transport_Events>(
Gallery_Request{*kind, std::string(source)})
: std::nullopt;
}
std::optional<Render_2D_Web_Events> Render_2D_Web_Event_Decoder::decode(
@@ -183,15 +164,10 @@ std::optional<Web_Demo_Control_Events> Web_Demo_Control_Decoder::decode(
const std::string control = root["control"].asString();
if (control == "mode" && root["value"].isString()) {
const std::string value = root["value"].asString();
if (value == "AM")
return Set_Demo_Mode{Demo_Mode::Am};
if (value == "FM")
return Set_Demo_Mode{Demo_Mode::Fm};
if (value == "USB")
return Set_Demo_Mode{Demo_Mode::Usb};
if (value == "LSB")
return Set_Demo_Mode{Demo_Mode::Lsb};
return std::nullopt;
const auto mode = magic_enum::enum_cast<Demo_Mode>(
value, magic_enum::case_insensitive);
return mode ? std::optional<Web_Demo_Control_Events>(Set_Demo_Mode{*mode})
: std::nullopt;
}
if (control == "center_frequency_mhz") {
const auto value = finite_number(root, "value");