This commit is contained in:
2026-08-21 00:41:36 +08:00
parent 81204fc188
commit 6c59997c88
101 changed files with 2656 additions and 1140 deletions
@@ -375,5 +375,11 @@ struct Root::Builder {
std::expected<void, Dependency_Graph_Error> validate() const {
return dependency_graph_storage.validate();
}
protected:
/* 派生 Builder 在完成 build 后绑定协作对象时,按 Tag 访问其 Private 层;不公开内部指针。 */
template <Attached Target>
[[nodiscard]] static Private_Access<typename Target::Private> private_access(Target* target) noexcept {
return Private_Access<typename Target::Private>{static_cast<typename Target::Private&>(*target->d)};
}
};
}
+18 -24
View File
@@ -17,14 +17,10 @@ enum class Event_Type : std::uint8_t {
};
/* 所有输入事件的公共业务基类。 */
struct Event {
explicit Event(Event_Type value) : type(value) {}
virtual ~Event() = default;
void accept() const noexcept {
accepted = true;
}
[[nodiscard]] bool is_accepted() const noexcept {
return accepted;
}
explicit Event(Event_Type value);
virtual ~Event();
void accept() const noexcept;
[[nodiscard]] bool is_accepted() const noexcept;
Event_Type type; /* 事件种类;构造后保持不变。 */
private:
mutable bool accepted{}; /* 处理链是否已经消费事件。 */
@@ -50,10 +46,7 @@ enum class Keyboard_Modifier : std::uint8_t {
alt = 1 << 2,
meta = 1 << 3
};
[[nodiscard]] constexpr Keyboard_Modifier operator|(Keyboard_Modifier left,
Keyboard_Modifier right) noexcept {
return static_cast<Keyboard_Modifier>(static_cast<std::uint8_t>(left) | static_cast<std::uint8_t>(right));
}
[[nodiscard]] constexpr Keyboard_Modifier operator|(Keyboard_Modifier left, Keyboard_Modifier right) noexcept;
/* 不依赖具体坐标类型的指针事件查询能力。 */
struct Pointer_Event_Capability {
virtual ~Pointer_Event_Capability() = default;
@@ -73,34 +66,34 @@ struct Wheel_Event_Capability {
/* 带局部位置、全局位置、按键和修饰键的指针事件。 */
template <Event_Point Point>
struct Basic_Pointer_Event : Event, Pointer_Event_Capability {
explicit Basic_Pointer_Event(Event_Type value = Event_Type::pointer_move) : Event(value) {}
explicit Basic_Pointer_Event(Event_Type value = Event_Type::pointer_move);
Point position{}; /* 事件接收对象局部坐标。 */
Point global_position{}; /* 全局窗口坐标。 */
Mouse_Button button{Mouse_Button::none}; /* 本次按下或释放的按键。 */
Mouse_Button_Mask buttons{}; /* 事件发生时保持按下的按键集合。 */
Keyboard_Modifier modifiers{Keyboard_Modifier::none}; /* 事件发生时的键盘修饰键集合。 */
[[nodiscard]] double position_x() const noexcept override { return static_cast<double>(position.x); }
[[nodiscard]] double position_y() const noexcept override { return static_cast<double>(position.y); }
[[nodiscard]] Mouse_Button pointer_button() const noexcept override { return button; }
[[nodiscard]] Keyboard_Modifier keyboard_modifiers() const noexcept override { return modifiers; }
[[nodiscard]] double position_x() const noexcept override;
[[nodiscard]] double position_y() const noexcept override;
[[nodiscard]] Mouse_Button pointer_button() const noexcept override;
[[nodiscard]] Keyboard_Modifier keyboard_modifiers() const noexcept override;
};
/* 带角度增量和像素增量的滚轮事件。 */
template <Event_Point Point>
struct Basic_Wheel_Event : Basic_Pointer_Event<Point>, Wheel_Event_Capability {
Basic_Wheel_Event() : Basic_Pointer_Event<Point>(Event_Type::wheel) {}
Basic_Wheel_Event();
double angle_delta_x{}; /* 水平方向滚轮角度增量。 */
double angle_delta_y{}; /* 垂直方向滚轮角度增量。 */
double pixel_delta_x{}; /* 水平方向高精度像素增量。 */
double pixel_delta_y{}; /* 垂直方向高精度像素增量。 */
[[nodiscard]] double pixel_delta_x_value() const noexcept override { return pixel_delta_x; }
[[nodiscard]] double pixel_delta_y_value() const noexcept override { return pixel_delta_y; }
[[nodiscard]] double angle_delta_x_value() const noexcept override { return angle_delta_x; }
[[nodiscard]] double angle_delta_y_value() const noexcept override { return angle_delta_y; }
[[nodiscard]] double pixel_delta_x_value() const noexcept override;
[[nodiscard]] double pixel_delta_y_value() const noexcept override;
[[nodiscard]] double angle_delta_x_value() const noexcept override;
[[nodiscard]] double angle_delta_y_value() const noexcept override;
};
/* 带旧尺寸和新尺寸的调整事件。 */
template <Event_Size Size>
struct Basic_Resize_Event : Event {
Basic_Resize_Event() : Event(Event_Type::resize) {}
Basic_Resize_Event();
Size old_size{}; /* 调整前尺寸。 */
Size new_size{}; /* 调整后尺寸。 */
};
@@ -118,10 +111,11 @@ enum class Key : std::uint16_t {
};
/* 键盘按下或释放事件。 */
struct Key_Event : Event {
explicit Key_Event(Event_Type value) : Event(value) {}
explicit Key_Event(Event_Type value);
Key key{Key::unknown}; /* 标准化按键。 */
std::uint32_t native_key{}; /* 平台原生按键编码。 */
Keyboard_Modifier modifiers{Keyboard_Modifier::none}; /* 事件发生时的修饰键集合。 */
bool auto_repeat{}; /* 是否由系统自动重复产生。 */
};
}
#include "event.ipp"
+28
View File
@@ -0,0 +1,28 @@
#pragma once
#include <cstdint>
namespace aethera {
/* 与绘制维度和后端无关的非预乘 RGBA 颜色。 */
struct Color {
std::uint8_t red{}; /* 红色通道,范围为 0 到 255。 */
std::uint8_t green{}; /* 绿色通道,范围为 0 到 255。 */
std::uint8_t blue{}; /* 蓝色通道,范围为 0 到 255。 */
std::uint8_t alpha{255}; /* 不透明度通道,范围为 0 到 255。 */
[[nodiscard]] static constexpr Color transparent() noexcept;
[[nodiscard]] static constexpr Color black() noexcept;
[[nodiscard]] static constexpr Color white() noexcept;
[[nodiscard]] static constexpr Color red_color() noexcept;
[[nodiscard]] static constexpr Color green_color() noexcept;
[[nodiscard]] static constexpr Color yellow() noexcept;
bool operator==(const Color&) const = default;
};
using Duration_Milliseconds = std::uint64_t;
/* 返回进程内单调时钟的毫秒刻度,只用于计算持续时间。 */
[[nodiscard]] Duration_Milliseconds monotonic_milliseconds() noexcept;
/* 一天内的墙钟时间;不携带时区和日期。 */
struct Time_Of_Day {
std::int64_t milliseconds{-1}; /* 自当天零点起的毫秒数;负值表示无效。 */
[[nodiscard]] bool valid() const noexcept;
bool operator==(const Time_Of_Day&) const = default;
};
}
#include "visual_common.ipp"
+12
View File
@@ -0,0 +1,12 @@
#pragma once
#include <chrono>
namespace aethera {
constexpr Color Color::transparent() noexcept { return {0, 0, 0, 0}; }
constexpr Color Color::black() noexcept { return {0, 0, 0, 255}; }
constexpr Color Color::white() noexcept { return {255, 255, 255, 255}; }
constexpr Color Color::red_color() noexcept { return {255, 0, 0, 255}; }
constexpr Color Color::green_color() noexcept { return {0, 255, 0, 255}; }
constexpr Color Color::yellow() noexcept { return {255, 255, 0, 255}; }
inline Duration_Milliseconds monotonic_milliseconds() noexcept { return static_cast<Duration_Milliseconds>(std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now().time_since_epoch()).count()); }
inline bool Time_Of_Day::valid() const noexcept { return milliseconds >= 0 && milliseconds < 24LL * 60LL * 60LL * 1000LL; }
}