策略抽离

This commit is contained in:
2026-08-02 14:20:27 +08:00
parent 6d000f43b4
commit 2df8959ed6
87 changed files with 2454 additions and 1390 deletions
+23 -25
View File
@@ -2,7 +2,7 @@
#include <algorithm>
#include <string>
#include <vector>
#include "../architecture/Render_Lease.h"
#include "../flow/low_latency/Render_Lease.h"
#include "../render/Canvas.h"
#include "Abs_Axis.h"
#include "blend2d/blend2d.h"
@@ -19,7 +19,7 @@ struct Abs_Axis_Input_Data : Input_Data {};
struct Abs_Axis_Private : Typed_Render_Data<Abs_Axis, Abs_Axis_Render_State, Abs_Axis_Input_Data> {
int tick_count = 2;
[[nodiscard]] Abs_Axis_Render_State* edit_axis_state() {
return state_data(State_Role::State_Edit);
return edit_state();
}
[[nodiscard]] Abs_Axis_Render_State* render_axis_state() {
return render_state();
@@ -30,11 +30,11 @@ struct Abs_Axis_Private : Typed_Render_Data<Abs_Axis, Abs_Axis_Render_State, Abs
double get_mantissa(double input, double* magnitude = nullptr);
[[nodiscard]] double clean_mantissa(double input);
[[nodiscard]] double pick_closest(double target, const std::vector<double>& candidates);
void prepare_data(const Plot_Render_Snapshot&) override {
void prepare_data(const Render_Frame_Snapshot&) override {
sync_state_pipeline();
}
void draw(Canvas& canvas, const Plot_Render_Snapshot&) override {
Abs_Axis_Render_State* s = render_state();
void draw(Canvas& canvas, const Render_Frame_Snapshot&) override {
Abs_Axis_Render_State* s = render_axis_state();
const int pixel_start = pixel_start_of(s);
Range range = {s->coord_start, s->coord_start + s->coord_length};
double tick_step = get_tick_step(range);
@@ -47,7 +47,7 @@ struct Abs_Axis_Private : Typed_Render_Data<Abs_Axis, Abs_Axis_Render_State, Abs
while (!sub_ticks.empty() && !range.contains(sub_ticks.back())) {
sub_ticks.pop_back();
}
std::vector<std::string> labels = create_label_vector(ticks, State_Render);
std::vector<std::string> labels = render_label_vector(ticks);
Text_Metrics tm = canvas.measure_text(!s->unit_text_font.valid() ? "0" : " ");
double h = tm.line_height();
canvas.set_pen(Pen{.color = s->color});
@@ -56,7 +56,7 @@ struct Abs_Axis_Private : Typed_Render_Data<Abs_Axis, Abs_Axis_Render_State, Abs
int n = (int)ticks.size();
for (int i = 0; i < n; ++i) {
double tick = ticks[i];
double x = coord_to_pixel(tick, State_Render);
double x = render_coord_to_pixel(tick);
canvas.draw_line({x, (double)s->y}, {x, (double)(s->y + s->tick_length)});
const std::string& label = labels[i];
PointF start{x, (double)(s->y + s->tick_length)};
@@ -67,7 +67,7 @@ struct Abs_Axis_Private : Typed_Render_Data<Abs_Axis, Abs_Axis_Render_State, Abs
canvas.restore();
}
for (double tick : sub_ticks) {
double x = coord_to_pixel(tick, State_Render);
double x = render_coord_to_pixel(tick);
canvas.draw_line({x, (double)s->y}, {x, (double)(s->y + s->sub_tick_length)});
}
}
@@ -76,7 +76,7 @@ struct Abs_Axis_Private : Typed_Render_Data<Abs_Axis, Abs_Axis_Render_State, Abs
int n = (int)ticks.size();
for (int i = 0; i < n; ++i) {
double tick = ticks[i];
double y = coord_to_pixel(tick, State_Render);
double y = render_coord_to_pixel(tick);
const std::string& label = labels[i];
canvas.draw_line({(double)s->x, y}, {(double)(s->x + s->tick_length), y});
PointF start{(double)(s->x + s->tick_length * 2), y + h / 2.0};
@@ -87,7 +87,7 @@ struct Abs_Axis_Private : Typed_Render_Data<Abs_Axis, Abs_Axis_Render_State, Abs
canvas.restore();
}
for (double tick : sub_ticks) {
double y = coord_to_pixel(tick, State_Render);
double y = render_coord_to_pixel(tick);
canvas.draw_line({(double)s->x, y}, {(double)(s->x + s->sub_tick_length), y});
}
}
@@ -116,12 +116,10 @@ struct Abs_Axis_Private : Typed_Render_Data<Abs_Axis, Abs_Axis_Render_State, Abs
canvas.draw_text(area, Text_Align::Center, s->unit_text);
}
}
[[nodiscard]] virtual double pixel_to_coord(double pixel, State_Role State_Role) {
auto s = static_cast<Abs_Axis_Render_State*>(state(State_Role));
[[nodiscard]] virtual double pixel_to_coord(double pixel, Abs_Axis_Render_State* s) {
return s->coord_start + s->coord_length * (pixel - (double)pixel_start_of(s)) / (double)s->pixel_length;
}
[[nodiscard]] virtual double coord_to_pixel(double coord, State_Role State_Role) {
auto s = static_cast<Abs_Axis_Render_State*>(state(State_Role));
[[nodiscard]] virtual double coord_to_pixel(double coord, Abs_Axis_Render_State* s) {
return pixel_start_of(s) + (double)s->pixel_length * (coord - s->coord_start) / s->coord_length;
}
virtual double get_tick_step(const Range& range) {
@@ -131,19 +129,19 @@ struct Abs_Axis_Private : Typed_Render_Data<Abs_Axis, Abs_Axis_Render_State, Abs
virtual int get_sub_tick_count(double tick_step);
virtual std::vector<double> create_tick_vector(double tick_step, const Range& range);
virtual std::vector<double> create_sub_tick_vector(int sub_tick_count, const std::vector<double>& ticks, const Range& range);
virtual std::string get_tick_label(double tick, State_Role);
virtual std::vector<std::string> create_label_vector(const std::vector<double>& ticks, State_Role);
virtual std::string get_tick_label(double tick, Abs_Axis_Render_State* state);
virtual std::vector<std::string> create_label_vector(const std::vector<double>& ticks, Abs_Axis_Render_State* state);
[[nodiscard]] double edit_pixel_to_coord(double pixel) {
return pixel_to_coord(pixel, State_Role::State_Edit);
return pixel_to_coord(pixel, edit_axis_state());
}
[[nodiscard]] double render_pixel_to_coord(double pixel) {
return pixel_to_coord(pixel, State_Render);
return pixel_to_coord(pixel, render_axis_state());
}
[[nodiscard]] double edit_coord_to_pixel(double coord) {
return coord_to_pixel(coord, State_Role::State_Edit);
return coord_to_pixel(coord, edit_axis_state());
}
[[nodiscard]] double render_coord_to_pixel(double coord) {
return coord_to_pixel(coord, State_Render);
return coord_to_pixel(coord, render_axis_state());
}
[[nodiscard]] Range edit_coord_range() {
const auto* s = edit_axis_state();
@@ -157,16 +155,16 @@ struct Abs_Axis_Private : Typed_Render_Data<Abs_Axis, Abs_Axis_Render_State, Abs
return std::abs(static_cast<int>(render_axis_state()->pixel_length));
}
[[nodiscard]] std::string edit_tick_label(double tick) {
return get_tick_label(tick, State_Role::State_Edit);
return get_tick_label(tick, edit_axis_state());
}
[[nodiscard]] std::string render_tick_label(double tick) {
return get_tick_label(tick, State_Render);
return get_tick_label(tick, render_axis_state());
}
[[nodiscard]] std::vector<std::string> edit_label_vector(const std::vector<double>& ticks) {
return create_label_vector(ticks, State_Role::State_Edit);
return create_label_vector(ticks, edit_axis_state());
}
[[nodiscard]] std::vector<std::string> render_label_vector(const std::vector<double>& ticks) {
return create_label_vector(ticks, State_Render);
return create_label_vector(ticks, render_axis_state());
}
};
struct Axis_Frame_Snapshot {
@@ -268,7 +266,7 @@ template <typename That>
void Abs_Axis::Builder_T<That>::set(Abs_Axis* ret) {
ret->init(parent);
Abs_Axis_Private* pd = ret->d();
Abs_Axis_Render_State* sc = reinterpret_cast<Abs_Axis_Render_State*>(pd->state(State_Edit));
Abs_Axis_Render_State* sc = reinterpret_cast<Abs_Axis_Render_State*>(pd->edit_state());
sc->x = this->x;
sc->y = this->y;
sc->orientation = this->orientation;