Files
Renderive/YSGraphic_Core/plottable/Hover_Info.h
T
2026-07-23 18:14:44 +08:00

133 lines
4.7 KiB
C++

#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() {
hover_info_brush = QBrush(Qt::white);
}
int hover_info_left = 4, hover_info_top = 4, hover_info_right = 4, hover_info_bottom = 4;
QBrush hover_info_brush;
QFont hover_info_font;
QPen hover_info_pen;
bool use_hover_info = true;
bool hover_info_active = false;
QPoint hover_info_pos;
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->hover_info_font = font;
finish_hover_edit();
}
QFont hover_info_font(SRC src = SRC::Edit) {
return hover_state(src)->hover_info_font;
}
QBrush hover_info_background_brush(SRC src = SRC::Edit) {
return hover_state(src)->hover_info_brush;
}
void set_hover_info_background_brush(const QBrush& brush) {
Hover_Info_Render_State* sc = begin_hover_edit();
sc->hover_info_brush = 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->hover_info_left;
top = s->hover_info_top;
right = s->hover_info_right;
bottom = s->hover_info_bottom;
}
void set_hover_info_contents_margins(int left, int top, int right, int bottom) {
Hover_Info_Render_State* sc = begin_hover_edit();
sc->hover_info_left = left;
sc->hover_info_top = top;
sc->hover_info_right = right;
sc->hover_info_bottom = 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 = {};
}
};
}