初步重构

This commit is contained in:
2026-07-23 18:11:07 +08:00
parent aa243e3d97
commit 700dab6c56
213 changed files with 20352 additions and 22136 deletions
+132
View File
@@ -0,0 +1,132 @@
#pragma once
#include "../Renderable.h"
#include "../Axis/Abs_Axis.h"
namespace YSG {
struct Hover_Info_Render_State;
struct Hover_Info_Render_Able_InterFace;
struct LIB_DECL Hover_Info_Render_State {
virtual ~Hover_Info_Render_State() = default;
Hover_Info_Render_State() {
hoverInfoBrush = QBrush(Qt::white);
}
int hoverInfoLeft = 4, hoverInfoTop = 4, hoverInfoRight = 4, hoverInfoBottom = 4;
QBrush hoverInfoBrush;
QFont hoverInfoFont;
QPen hover_info_pen;
bool use_hover_info = true;
bool hoverInfoActive = false;
QPoint hoverInfoPos;
Hover_Info_Render_Able_InterFace* renderAble{};
void draw_hover(QPainter* painter, Abs_Axis* h, Abs_Axis* v);
bool hover_ok(Renderable* able) const;
};
struct LIB_DECL Hover_Info_Render_Able_InterFace {
virtual QVector<QString> create_hover_string(Abs_Axis* h, Abs_Axis* v, QPoint pos);
virtual ~Hover_Info_Render_Able_InterFace() = default;
virtual void draw_hover(QPainter* painter, Abs_Axis* h, Abs_Axis* v) {
return hover_state(SRC::Render)->draw_hover(painter, h, v);
}
virtual bool hover_ok(Renderable* able) {
return hover_state(SRC::Render)->hover_ok(able);
}
virtual bool hover_test(QPoint pos) {
return true;
}
bool use_hover_info(SRC src = SRC::Edit) {
return hover_state(src)->use_hover_info;
}
void set_use_hover_info(bool use) {
Hover_Info_Render_State* sc = begin_hover_edit();
sc->use_hover_info = use;
finish_hover_edit();
}
void set_hover_info_font(const QFont& font) {
Hover_Info_Render_State* sc = begin_hover_edit();
sc->hoverInfoFont = font;
finish_hover_edit();
}
QFont hover_info_font(SRC src = SRC::Edit) {
return hover_state(src)->hoverInfoFont;
}
QBrush hover_info_background_brush(SRC src = SRC::Edit) {
return hover_state(src)->hoverInfoBrush;
}
void set_hover_info_background_brush(const QBrush& brush) {
Hover_Info_Render_State* sc = begin_hover_edit();
sc->hoverInfoBrush = brush.color().isValid() ? brush : Qt::NoBrush;
finish_hover_edit();
}
QPen hover_info_pen(SRC src = SRC::Edit) {
return hover_state(src)->hover_info_pen;
}
void set_hover_info_pen(const QPen& pen) {
Hover_Info_Render_State* sc = begin_hover_edit();
sc->hover_info_pen = pen.color().isValid() ? pen : Qt::NoPen;
finish_hover_edit();
}
void get_hover_info_contents_margins(int& left, int& top, int& right, int& bottom, SRC src) {
auto s = hover_state(src);
left = s->hoverInfoLeft;
top = s->hoverInfoTop;
right = s->hoverInfoRight;
bottom = s->hoverInfoBottom;
}
void set_hover_info_contents_margins(int left, int top, int right, int bottom) {
Hover_Info_Render_State* sc = begin_hover_edit();
sc->hoverInfoLeft = left;
sc->hoverInfoTop = top;
sc->hoverInfoRight = right;
sc->hoverInfoBottom = bottom;
finish_hover_edit();
}
protected:
virtual Hover_Info_Render_State* hover_state(SRC src) = 0;
virtual Hover_Info_Render_State* begin_hover_edit() = 0;
virtual void finish_hover_edit() = 0;
};
struct LIB_DECL Hover_Info_Independ_Render_Able : Hover_Info_Render_Able_InterFace {
private:
Hover_Info_Render_State s, sc;
Hover_Info_Render_State* hover_state(SRC src) override {
if (src == SRC::Edit) {
return &sc;
}
return &s;
}
Hover_Info_Render_State* begin_hover_edit() override {
return &sc;
}
void finish_hover_edit() override {}
public:
void draw_hover(QPainter* painter, Abs_Axis* h, Abs_Axis* v) override {
s.renderAble = this;
sc.renderAble = this;
s = sc;
Hover_Info_Render_Able_InterFace::draw_hover(painter, h, v);
}
};
template <typename That>
struct LIB_DECL Hover_Info_Render_Able : Hover_Info_Render_Able_InterFace {
private:
That* that() {
return static_cast<That*>(this);
}
Triple_Buffer_Lease mHoverLease{};
Hover_Info_Render_State* hover_state(SRC src) override {
auto t = that();
return dynamic_cast<Hover_Info_Render_State*>(t->dPtr->state(src));
}
Hover_Info_Render_State* begin_hover_edit() override {
auto t = that();
mHoverLease = t->dPtr->mStateControl.wait_mark_use_role(State_Edit);
return dynamic_cast<Hover_Info_Render_State*>(t->dPtr->state_by_index(mHoverLease.index));
}
void finish_hover_edit() override {
auto t = that();
++t->dPtr->state_by_index(mHoverLease.index)->version;
t->mark_render_dirty();
t->dPtr->mStateControl.unmark_use(mHoverLease);
mHoverLease = {};
}
};
}