修复若干bug
This commit is contained in:
@@ -2,19 +2,19 @@
|
||||
#include "Timeline_Stream.h"
|
||||
#include <algorithm>
|
||||
namespace renderive {
|
||||
std::shared_ptr<const Timeline_Stream_Snapshot> Plot_Render_Snapshot::timeline_snapshot(const std::shared_ptr<Timeline_Stream>& stream, int time_point_size, int tick_space, bool start_coord_to_end_coord) const {
|
||||
std::shared_ptr<const Timeline_Stream_Snapshot> Plot_Render_Snapshot::timeline_snapshot(const std::shared_ptr<Timeline_Stream>& stream, int time_point_size, int label_tick_interval, bool start_coord_to_end_coord) const {
|
||||
if (!stream)
|
||||
return {};
|
||||
time_point_size = std::max(1, time_point_size);
|
||||
tick_space = std::max(1, tick_space);
|
||||
label_tick_interval = std::max(1, label_tick_interval);
|
||||
if (!timeline_cache)
|
||||
timeline_cache = std::make_shared<Timeline_Stream_Frame_Cache>();
|
||||
for (auto& item : timeline_cache->items) {
|
||||
if (item.stream.lock() == stream && item.time_point_size == time_point_size && item.tick_space == tick_space && item.start_coord_to_end_coord == start_coord_to_end_coord)
|
||||
if (item.stream.lock() == stream && item.time_point_size == time_point_size && item.tick_space == label_tick_interval && item.start_coord_to_end_coord == start_coord_to_end_coord)
|
||||
return item.snapshot;
|
||||
}
|
||||
auto snapshot = std::make_shared<Timeline_Stream_Snapshot>(stream->capture(time_point_size, tick_space, start_coord_to_end_coord));
|
||||
timeline_cache->items.push_back({stream, time_point_size, tick_space, start_coord_to_end_coord, snapshot});
|
||||
auto snapshot = std::make_shared<Timeline_Stream_Snapshot>(stream->capture(time_point_size, label_tick_interval, start_coord_to_end_coord));
|
||||
timeline_cache->items.push_back({stream, time_point_size, label_tick_interval, start_coord_to_end_coord, snapshot});
|
||||
return snapshot;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ struct Plot_Render_Snapshot {
|
||||
bool destroying() const {
|
||||
return !context || context->destroying.load(std::memory_order_acquire);
|
||||
}
|
||||
std::shared_ptr<const Timeline_Stream_Snapshot> timeline_snapshot(const std::shared_ptr<Timeline_Stream>& stream, int time_point_size, int tick_space, bool start_coord_to_end_coord) const;
|
||||
std::shared_ptr<const Timeline_Stream_Snapshot> timeline_snapshot(const std::shared_ptr<Timeline_Stream>& stream, int time_point_size, int label_tick_interval, bool start_coord_to_end_coord) const;
|
||||
};
|
||||
|
||||
} // namespace renderive
|
||||
|
||||
@@ -20,12 +20,9 @@
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
#include <vector>
|
||||
|
||||
namespace renderive {
|
||||
|
||||
class Plot_Core;
|
||||
class Renderable;
|
||||
|
||||
struct Renderable_Tree_Node {
|
||||
std::shared_ptr<Renderable> renderable;
|
||||
std::size_t subtree_end{};
|
||||
@@ -34,9 +31,7 @@ struct Renderable_Tree_Node {
|
||||
std::string cache_parent_object_name;
|
||||
int cache_tree_depth{};
|
||||
};
|
||||
|
||||
using Renderable_Tree_Snapshot = std::vector<Renderable_Tree_Node>;
|
||||
|
||||
template <typename T>
|
||||
concept Render_State_Type = std::derived_from<T, Render_State> && std::is_copy_assignable_v<T>;
|
||||
template <typename T>
|
||||
@@ -46,8 +41,7 @@ concept Render_Data_Type = std::derived_from<T, Render_Data>;
|
||||
template <typename Owner, Render_Data_Type Data, Render_State_Type State, Input_Data_Type Input>
|
||||
struct Renderable_Binding;
|
||||
template <typename That>
|
||||
struct Hover_Info_Renderable;
|
||||
|
||||
struct Hover_Tooltip_Mixin;
|
||||
class Renderable : public std::enable_shared_from_this<Renderable> {
|
||||
public:
|
||||
virtual Render_Object_Owner create_render_data() {
|
||||
@@ -59,23 +53,18 @@ public:
|
||||
virtual Render_Object_Owner create_input_data() {
|
||||
return make_render_object<Input_Data>();
|
||||
}
|
||||
|
||||
virtual void init(const std::shared_ptr<Renderable>& parent);
|
||||
virtual void init_root(Plot_Core* plot);
|
||||
|
||||
void add_child(const std::shared_ptr<Renderable>& child);
|
||||
void remove_child(const std::shared_ptr<Renderable>& child);
|
||||
|
||||
std::vector<std::shared_ptr<Renderable>> children_snapshot() const;
|
||||
std::vector<std::shared_ptr<Renderable>> hit_renderables(const PointF& pos);
|
||||
void append_tree_snapshot(Renderable_Tree_Snapshot& snapshot, const std::string& parent_object_name = {}, int render_tree_depth = 0, const std::string& cache_parent_object_name = {}, int cache_tree_depth = 0);
|
||||
|
||||
void render(Canvas& canvas, const Plot_Render_Snapshot& snapshot);
|
||||
void render_tree_snapshot(Canvas& canvas, const Plot_Render_Snapshot& snapshot, const Renderable_Tree_Snapshot& tree, std::size_t index);
|
||||
void draw(Canvas& canvas, const Plot_Render_Snapshot& snapshot);
|
||||
void prepare_data(const Plot_Render_Snapshot& snapshot);
|
||||
bool select_test(const PointF& pos);
|
||||
|
||||
void plot_event(const Event& event);
|
||||
void mouse_press_event(const Pointer_Event& event);
|
||||
void mouse_move_event(const Pointer_Event& event);
|
||||
@@ -85,7 +74,6 @@ public:
|
||||
void key_release_event(const Key_Event& event);
|
||||
void resize_event(const Resize_Event& event);
|
||||
void wheel_event(const Wheel_Event& event);
|
||||
|
||||
Renderable_Cache_Mode get_cache_mode() const;
|
||||
void set_cache_mode(Renderable_Cache_Mode mode);
|
||||
[[nodiscard]] bool attached_to_plot() const;
|
||||
@@ -96,24 +84,19 @@ public:
|
||||
void set_visible(bool value);
|
||||
[[nodiscard]] bool should_prepare() const;
|
||||
void detach_from_parent();
|
||||
|
||||
std::string cache_parent_object_name() const;
|
||||
int cache_tree_depth() const;
|
||||
std::string render_parent_object_name() const;
|
||||
int render_tree_depth() const;
|
||||
|
||||
void mark_render_dirty();
|
||||
|
||||
[[nodiscard]] bool ok() const;
|
||||
[[nodiscard]] bool get_retiring() const;
|
||||
virtual ~Renderable();
|
||||
|
||||
private:
|
||||
template <typename Owner, Render_Data_Type Data, Render_State_Type State, Input_Data_Type Input>
|
||||
friend struct Renderable_Binding;
|
||||
template <typename That>
|
||||
friend struct Hover_Info_Renderable;
|
||||
|
||||
friend struct Hover_Tooltip_Mixin;
|
||||
Render_Object_Owner d_owner;
|
||||
Render_Data* d_ptr{};
|
||||
Plot_Core* plot{};
|
||||
@@ -131,7 +114,6 @@ private:
|
||||
Rect cache_bounds;
|
||||
std::atomic_bool retiring{true};
|
||||
std::atomic_bool initialized{false};
|
||||
|
||||
void init_common(Plot_Core* plot);
|
||||
void render_direct(Canvas& canvas, const Plot_Render_Snapshot& snapshot);
|
||||
void render_cached(Canvas& canvas, const Plot_Render_Snapshot& snapshot);
|
||||
@@ -146,5 +128,4 @@ private:
|
||||
void append_hit_renderables(std::vector<std::shared_ptr<Renderable>>& hits, const PointF& pos);
|
||||
void detach_from_plot_tree();
|
||||
};
|
||||
|
||||
} // namespace renderive
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include <memory_resource>
|
||||
namespace renderive {
|
||||
int Timeline_Stream_Snapshot::coordinate_end() const {
|
||||
return coordinate_begin + time_point_size - 1;
|
||||
return coordinate_begin + visible_time_point_count - 1;
|
||||
}
|
||||
bool Timeline_Stream_Snapshot::coord_by_stream_tick(int stream_tick, int& coord) const {
|
||||
if (times.empty())
|
||||
@@ -15,13 +15,13 @@ bool Timeline_Stream_Snapshot::coord_by_stream_tick(int stream_tick, int& coord)
|
||||
if (newest_at_axis_start)
|
||||
coord = coordinate_begin + (last_stream_tick - stream_tick);
|
||||
else
|
||||
coord = coordinate_begin + (time_point_size - count) + (stream_tick - first_stream_tick);
|
||||
coord = coordinate_begin + (visible_time_point_count - count) + (stream_tick - first_stream_tick);
|
||||
return coord >= coordinate_begin && coord <= coordinate_end();
|
||||
}
|
||||
Time_Of_Day Timeline_Stream_Snapshot::time_by_tick(int tick) const {
|
||||
int offset = tick - coordinate_begin;
|
||||
int count = static_cast<int>(times.size());
|
||||
int index = newest_at_axis_start ? count - 1 - offset : offset - (time_point_size - count);
|
||||
int index = newest_at_axis_start ? count - 1 - offset : offset - (visible_time_point_count - count);
|
||||
if (index < 0 || index >= count)
|
||||
return {};
|
||||
return times[static_cast<std::size_t>(index)];
|
||||
@@ -59,7 +59,7 @@ Timeline_Stream_Snapshot Timeline_Stream::capture(int time_point_size, int label
|
||||
captured.push_back(*it);
|
||||
}
|
||||
snapshot.newest_at_axis_start = start_coord_to_end_coord;
|
||||
snapshot.time_point_size = time_point_size;
|
||||
snapshot.visible_time_point_count = time_point_size;
|
||||
if (captured.empty()) {
|
||||
snapshot.coordinate_begin = 0;
|
||||
return snapshot;
|
||||
|
||||
@@ -16,7 +16,7 @@ struct LIB_DECL Timeline_Stream_Snapshot {
|
||||
std::uint64_t version{};
|
||||
bool newest_at_axis_start = false; // 当前 true 时 代表最新时间映射到起始坐标
|
||||
int coordinate_begin{};
|
||||
int time_point_size = 1;
|
||||
int visible_time_point_count = 1;
|
||||
int first_stream_tick{};
|
||||
int last_stream_tick = -1;
|
||||
std::vector<Time_Of_Day> times;
|
||||
|
||||
Reference in New Issue
Block a user