From cb9d386647c027671d54fd45ba1f9bc1e1b5f3d6 Mon Sep 17 00:00:00 2001 From: codeboss <2422523675@qq.com> Date: Sat, 11 Oct 2025 00:56:47 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=AD=E8=BE=B9=E5=BD=A2=E5=B9=B3=E9=93=BA?= =?UTF-8?q?=E7=BB=98=E5=88=B6=E6=9C=BA=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 + ActWorld.sln | 34 ++++++ ActWorld/ActWorld.cpp | 11 ++ ActWorld/ActWorld.h | 17 +++ ActWorld/ActWorld.qrc | 4 + ActWorld/ActWorld.ui | 29 +++++ ActWorld/ActWorld.vcxproj | 114 ++++++++++++++++++ ActWorld/ActWorld.vcxproj.filters | 44 +++++++ ActWorld/ActWorld.vcxproj.user | 12 ++ ActWorld/main.cpp | 17 +++ MapPresent/MapPresent.cpp | 167 ++++++++++++++++++++++++++ MapPresent/MapPresent.h | 110 +++++++++++++++++ MapPresent/MapPresent.vcxproj | 107 +++++++++++++++++ MapPresent/MapPresent.vcxproj.filters | 38 ++++++ MapPresent/MapPresent.vcxproj.user | 12 ++ MapPresent/mappresent_global.h | 13 ++ 16 files changed, 731 insertions(+) create mode 100644 .gitignore create mode 100644 ActWorld.sln create mode 100644 ActWorld/ActWorld.cpp create mode 100644 ActWorld/ActWorld.h create mode 100644 ActWorld/ActWorld.qrc create mode 100644 ActWorld/ActWorld.ui create mode 100644 ActWorld/ActWorld.vcxproj create mode 100644 ActWorld/ActWorld.vcxproj.filters create mode 100644 ActWorld/ActWorld.vcxproj.user create mode 100644 ActWorld/main.cpp create mode 100644 MapPresent/MapPresent.cpp create mode 100644 MapPresent/MapPresent.h create mode 100644 MapPresent/MapPresent.vcxproj create mode 100644 MapPresent/MapPresent.vcxproj.filters create mode 100644 MapPresent/MapPresent.vcxproj.user create mode 100644 MapPresent/mappresent_global.h diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8fe9ac3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.vs/ +x64/ diff --git a/ActWorld.sln b/ActWorld.sln new file mode 100644 index 0000000..22ee870 --- /dev/null +++ b/ActWorld.sln @@ -0,0 +1,34 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.14.36429.23 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ActWorld", "ActWorld\ActWorld.vcxproj", "{EF07AD89-B0C9-4910-B391-8816294A39C6}" + ProjectSection(ProjectDependencies) = postProject + {61427621-6536-4CFF-BEA7-94D3F1A7E657} = {61427621-6536-4CFF-BEA7-94D3F1A7E657} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MapPresent", "MapPresent\MapPresent.vcxproj", "{61427621-6536-4CFF-BEA7-94D3F1A7E657}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Release|x64 = Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {EF07AD89-B0C9-4910-B391-8816294A39C6}.Debug|x64.ActiveCfg = Debug|x64 + {EF07AD89-B0C9-4910-B391-8816294A39C6}.Debug|x64.Build.0 = Debug|x64 + {EF07AD89-B0C9-4910-B391-8816294A39C6}.Release|x64.ActiveCfg = Release|x64 + {EF07AD89-B0C9-4910-B391-8816294A39C6}.Release|x64.Build.0 = Release|x64 + {61427621-6536-4CFF-BEA7-94D3F1A7E657}.Debug|x64.ActiveCfg = Debug|x64 + {61427621-6536-4CFF-BEA7-94D3F1A7E657}.Debug|x64.Build.0 = Debug|x64 + {61427621-6536-4CFF-BEA7-94D3F1A7E657}.Release|x64.ActiveCfg = Release|x64 + {61427621-6536-4CFF-BEA7-94D3F1A7E657}.Release|x64.Build.0 = Release|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {20577454-ED29-4095-A977-A5830520C5E3} + EndGlobalSection +EndGlobal diff --git a/ActWorld/ActWorld.cpp b/ActWorld/ActWorld.cpp new file mode 100644 index 0000000..5357891 --- /dev/null +++ b/ActWorld/ActWorld.cpp @@ -0,0 +1,11 @@ +#include "ActWorld.h" + +ActWorld::ActWorld(QWidget *parent) + : QMainWindow(parent) +{ + ui.setupUi(this); +} + +ActWorld::~ActWorld() +{} + diff --git a/ActWorld/ActWorld.h b/ActWorld/ActWorld.h new file mode 100644 index 0000000..79fe355 --- /dev/null +++ b/ActWorld/ActWorld.h @@ -0,0 +1,17 @@ +#pragma once + +#include +#include "ui_ActWorld.h" + +class ActWorld : public QMainWindow +{ + Q_OBJECT + +public: + ActWorld(QWidget *parent = nullptr); + ~ActWorld(); + +private: + Ui::ActWorldClass ui; +}; + diff --git a/ActWorld/ActWorld.qrc b/ActWorld/ActWorld.qrc new file mode 100644 index 0000000..9c2dd98 --- /dev/null +++ b/ActWorld/ActWorld.qrc @@ -0,0 +1,4 @@ + + + + diff --git a/ActWorld/ActWorld.ui b/ActWorld/ActWorld.ui new file mode 100644 index 0000000..3d30225 --- /dev/null +++ b/ActWorld/ActWorld.ui @@ -0,0 +1,29 @@ + + + ActWorldClass + + + ActWorldClass + + + + 0 + 0 + 600 + 400 + + + + ActWorld + + + + + + + + + + + + diff --git a/ActWorld/ActWorld.vcxproj b/ActWorld/ActWorld.vcxproj new file mode 100644 index 0000000..f46daa1 --- /dev/null +++ b/ActWorld/ActWorld.vcxproj @@ -0,0 +1,114 @@ + + + + + Debug + x64 + + + Release + x64 + + + + {EF07AD89-B0C9-4910-B391-8816294A39C6} + QtVS_v304 + 10.0 + 10.0 + $(MSBuildProjectDirectory)\QtMsBuild + + + + Application + v143 + true + Unicode + + + Application + v143 + false + true + Unicode + + + + + + + 5.12.11_msvc2017_64 + core;gui;widgets + debug + + + 5.12.11_msvc2017_64 + core;gui;widgets + release + + + + + + + + + + + + + + + + + $(SolutionDir)MapPresent;$(IncludePath) + $(SolutionDir)$(Platform)\$(Configuration);$(LibraryPath) + + + + + + MapPresent.lib;%(AdditionalDependencies) + + + + + true + Level3 + true + true + + + Windows + true + + + + + true + Level3 + true + true + true + true + + + Windows + false + true + true + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ActWorld/ActWorld.vcxproj.filters b/ActWorld/ActWorld.vcxproj.filters new file mode 100644 index 0000000..20a2089 --- /dev/null +++ b/ActWorld/ActWorld.vcxproj.filters @@ -0,0 +1,44 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + qml;cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + qrc;rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + {99349809-55BA-4b9d-BF79-8FDBB0286EB3} + ui + + + {639EADAA-A684-42e4-A9AD-28FC9BCB8F7C} + ts + + + + + Resource Files + + + Form Files + + + Header Files + + + Source Files + + + + + Source Files + + + \ No newline at end of file diff --git a/ActWorld/ActWorld.vcxproj.user b/ActWorld/ActWorld.vcxproj.user new file mode 100644 index 0000000..41a709a --- /dev/null +++ b/ActWorld/ActWorld.vcxproj.user @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/ActWorld/main.cpp b/ActWorld/main.cpp new file mode 100644 index 0000000..e1be194 --- /dev/null +++ b/ActWorld/main.cpp @@ -0,0 +1,17 @@ +#include "ActWorld.h" +#include +#include + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + + //ActWorld window; + //window.show(); + + MapPresent p; + p.show(); + + + return app.exec(); +} diff --git a/MapPresent/MapPresent.cpp b/MapPresent/MapPresent.cpp new file mode 100644 index 0000000..de44899 --- /dev/null +++ b/MapPresent/MapPresent.cpp @@ -0,0 +1,167 @@ +#include "MapPresent.h" + +MapPresent::MapPresent(QWidget* parent /*= nullptr*/) + :QWidget(parent) +{ + +} + +#include +#include +PresentIndex MapPresent::indexGet(const QPointF& pos) const +{ + + return PresentIndex(); +} + +#include +QRectF MapPresent::outlineGet(const PresentIndex& idx) const +{ + auto widget_rect = this->rect(); + auto widget_center = widget_rect.center(); + + const float ap_len = _primitive_region_square_len / 2; + auto a2_vec = ap_len * sqrt(3) / 2; + auto n_yinc = QVector3D(a2_vec, ap_len * 3 / 2, 0); + auto n_xinc = QVector3D(a2_vec, -ap_len * 3 / 2, 0); + + auto xinc = idx.row - _center_index.row; + auto yinc = idx.col - _center_index.col; + auto target_center = QVector3D(widget_center) + n_yinc * yinc + n_xinc * xinc; + target_center -= QVector3D(ap_len, ap_len, 0); + + return QRectF(target_center.toPointF(), QSizeF(ap_len * 2, ap_len * 2)); +} + +#include +void MapPresent::paintEvent(QPaintEvent* ev) +{ + QWidget::paintEvent(ev); + + QPainter p(this); + + BasicUnitDelegate t; + + p.save(); + p.setPen(Qt::red); + auto rect = outlineGet(_center_index); + p.translate(rect.topLeft()); + rect.moveTo(0, 0); + PresentOption opt; + opt.selfIndex = _center_index; + opt.selfOutline = rect; + t.paint(&p, opt); + p.restore(); + + for (auto idx = 1; idx < 10; ++idx) { + auto siblings = siblingsGet(_center_index, idx); + p.setPen(Qt::green); + for (auto item : siblings) { + auto rect = outlineGet(item); + p.save(); + p.translate(rect.topLeft()); + rect.moveTo(0, 0); + //p.drawRect(rect); + + opt.selfIndex = item; + opt.selfOutline = rect; + t.paint(&p, opt); + + p.restore(); + } + } +} + +QList MapPresent::siblingsGet(const PresentIndex& center, uint16_t dist) const +{ + QList e6_points; + e6_points << PresentIndex{ center.row, center.col - dist }; + e6_points << PresentIndex{ center.row + dist, center.col }; + e6_points << PresentIndex{ center.row + dist, center.col + dist }; + e6_points << PresentIndex{ center.row, center.col + dist }; + e6_points << PresentIndex{ center.row - dist, center.col }; + e6_points << PresentIndex{ center.row - dist, center.col - dist }; + e6_points << PresentIndex{ center.row, center.col - dist }; + + QList values; + for (auto idx = 0; idx < 6; ++idx) { + auto ap = e6_points[idx]; + auto bp = e6_points[idx + 1]; + values << itemFills(ap, bp); + } + return values; +} + +QList MapPresent::itemFills(const PresentIndex& a, const PresentIndex& b) const +{ + QList items; + auto sign_row = (a.row == b.row) ? 0 : ((b.row - a.row) / std::abs(a.row - b.row)); + auto sign_col = (a.col == b.col) ? 0 : ((b.col - a.col) / std::abs(a.col - b.col)); + + auto temp_pt = a; + while (temp_pt != b) { + items << temp_pt; + temp_pt += PresentIndex{ sign_row, sign_col }; + } + + return items; +} + +PresentIndex& PresentIndex::operator+=(const PresentIndex& other) +{ + row += other.row; + col += other.col; + return *this; +} + +bool PresentIndex::operator!=(const PresentIndex& other) const +{ + return row != other.row || col != other.col; +} + +int BasicUnitDelegate::unitType() const +{ + return 0; +} + +void BasicUnitDelegate::paint(QPainter* p, const PresentOption& option) +{ + auto rect = option.selfOutline; + auto center = rect.center(); + auto alen = rect.width() / 2; + const float xspan = alen * sqrt(3) / 2; + + QList points = endPointsGet(rect); + + QVector lines; + for (auto idx = 0; idx < 6; ++idx) { + lines << QLineF(points[idx], points[idx + 1]); + } + p->drawLines(lines); + + auto ft = p->font(); + ft.setPixelSize(alen * 0.3); + p->setFont(ft); + + auto text_rect = QRectF(center.x() - xspan, center.y() - alen / 2, xspan * 2, alen); + auto text_str = QString("(%1,%2)").arg(option.selfIndex.row).arg(option.selfIndex.col); + p->drawText(text_rect, Qt::AlignCenter, text_str); +} + +QList BasicUnitDelegate::endPointsGet(const QRectF& rect) +{ + auto center = rect.center(); + auto alen = rect.width() / 2; + const float xspan = alen * sqrt(3) / 2; + + QList points; + points << QPointF(center.x() - xspan, center.y() - alen / 2); + points << QPointF(center.x(), 0); + points << QPointF(center.x() + xspan, center.y() - alen / 2); + points << QPointF(center.x() + xspan, center.y() + alen / 2); + points << QPointF(center.x(), rect.height()); + points << QPointF(center.x() - xspan, center.y() + alen / 2); + points << QPointF(center.x() - xspan, center.y() - alen / 2); + + return points; +} diff --git a/MapPresent/MapPresent.h b/MapPresent/MapPresent.h new file mode 100644 index 0000000..0a48f3a --- /dev/null +++ b/MapPresent/MapPresent.h @@ -0,0 +1,110 @@ +#pragma once + +#include "mappresent_global.h" +#include + +/// +/// »æÖÆË÷Òý +/// +struct PresentIndex { + /// + /// ÐкŠ+ /// + int row = 0; + /// + /// ÁкŠ+ /// + int col = 0; + + PresentIndex& operator+=(const PresentIndex& other); + bool operator!=(const PresentIndex& other) const; +}; + +/// +/// »æÖÆÑ¡Ïî +/// +struct PresentOption { + /// + /// µ±Ç°Ëù»æÖÆË÷Òý + /// + PresentIndex selfIndex; + /// + /// µ±Ç°»æÖÆÍâÔµ + /// + QRectF selfOutline; + + bool isMouseOver = false; + bool isSelected = false; +}; + +/// +/// µ¥Ôª»æÖÆÎ¯ÍÐ +/// +class UnitPresentDelegate { +public: + virtual ~UnitPresentDelegate() = default; + /// + /// Æ¥Åäµ¥ÔªÀàÐÍ + /// + /// + virtual int unitType() const = 0; + /// + /// »æÖƱ¾µ¥ÔªÍ߯¬ + /// + /// + /// + virtual void paint(QPainter* p, const PresentOption& option) = 0; +}; + +class BasicUnitDelegate : public UnitPresentDelegate { +public: + int unitType() const override; + + void paint(QPainter* p, const PresentOption& option) override; + QList endPointsGet(const QRectF &rect); +}; + +/// +/// »ù´¡µØÍ¼»æÖÆ +/// +class MAPPRESENT_EXPORT MapPresent : public QWidget +{ + Q_OBJECT +private: + /// + /// ³õ¼¶ÇøÓò¾ØÐα䳤 + /// + const float _primitive_region_square_len = 100; + /// + /// Ëõ·Å±¶Êý + /// + short _scale_times = 1; + /// + /// µ±Ç°Í߯¬µØÍ¼ÖÐÐÄË÷Òý + /// + PresentIndex _center_index; + +public: + MapPresent(QWidget* parent = nullptr); + + /// + /// ͨ¹ýwidgetÉ϶¨Î»»ñÈ¡»æÖÆË÷Òý + /// + /// + /// + PresentIndex indexGet(const QPointF& pos) const; + /// + /// ͨ¹ý»æÖÆË÷Òý»ñȡָ¶¨µ¥ÔªÍâ½Ó¾ØÐÎ + /// + /// + /// + QRectF outlineGet(const PresentIndex& idx) const; + + +protected: + void paintEvent(QPaintEvent* ev) override; + +private: + QList siblingsGet(const PresentIndex ¢er, uint16_t dist=1) const; + QList itemFills(const PresentIndex &a, const PresentIndex &b) const; +}; diff --git a/MapPresent/MapPresent.vcxproj b/MapPresent/MapPresent.vcxproj new file mode 100644 index 0000000..45a9b62 --- /dev/null +++ b/MapPresent/MapPresent.vcxproj @@ -0,0 +1,107 @@ + + + + + Debug + x64 + + + Release + x64 + + + + {61427621-6536-4CFF-BEA7-94D3F1A7E657} + QtVS_v304 + 10.0 + 10.0 + $(MSBuildProjectDirectory)\QtMsBuild + + + + DynamicLibrary + v143 + true + Unicode + + + DynamicLibrary + v143 + false + true + Unicode + + + + + + + 5.12.11_msvc2017_64 + core;sql;gui;widgets + debug + + + 5.12.11_msvc2017_64 + core + release + + + + + + + + + + + + + + + + + + + + + + true + MAPPRESENT_LIB;%(PreprocessorDefinitions) + Level3 + true + true + + + Windows + true + + + + + true + MAPPRESENT_LIB;%(PreprocessorDefinitions) + Level3 + true + true + true + true + + + Windows + false + true + true + + + + + + + + + + + + + + \ No newline at end of file diff --git a/MapPresent/MapPresent.vcxproj.filters b/MapPresent/MapPresent.vcxproj.filters new file mode 100644 index 0000000..bead507 --- /dev/null +++ b/MapPresent/MapPresent.vcxproj.filters @@ -0,0 +1,38 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + qml;cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + qrc;rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + {99349809-55BA-4b9d-BF79-8FDBB0286EB3} + ui + + + {639EADAA-A684-42e4-A9AD-28FC9BCB8F7C} + ts + + + + + Header Files + + + Source Files + + + + + Header Files + + + \ No newline at end of file diff --git a/MapPresent/MapPresent.vcxproj.user b/MapPresent/MapPresent.vcxproj.user new file mode 100644 index 0000000..41a709a --- /dev/null +++ b/MapPresent/MapPresent.vcxproj.user @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/MapPresent/mappresent_global.h b/MapPresent/mappresent_global.h new file mode 100644 index 0000000..a26d5cc --- /dev/null +++ b/MapPresent/mappresent_global.h @@ -0,0 +1,13 @@ +#pragma once + +#include + +#ifndef BUILD_STATIC +# if defined(MAPPRESENT_LIB) +# define MAPPRESENT_EXPORT Q_DECL_EXPORT +# else +# define MAPPRESENT_EXPORT Q_DECL_IMPORT +# endif +#else +# define MAPPRESENT_EXPORT +#endif