六边形平铺绘制机制
This commit is contained in:
commit
cb9d386647
|
|
@ -0,0 +1,2 @@
|
|||
.vs/
|
||||
x64/
|
||||
|
|
@ -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
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
#include "ActWorld.h"
|
||||
|
||||
ActWorld::ActWorld(QWidget *parent)
|
||||
: QMainWindow(parent)
|
||||
{
|
||||
ui.setupUi(this);
|
||||
}
|
||||
|
||||
ActWorld::~ActWorld()
|
||||
{}
|
||||
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
#pragma once
|
||||
|
||||
#include <QtWidgets/QMainWindow>
|
||||
#include "ui_ActWorld.h"
|
||||
|
||||
class ActWorld : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ActWorld(QWidget *parent = nullptr);
|
||||
~ActWorld();
|
||||
|
||||
private:
|
||||
Ui::ActWorldClass ui;
|
||||
};
|
||||
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
<RCC>
|
||||
<qresource prefix="ActWorld">
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<UI version="4.0" >
|
||||
<class>ActWorldClass</class>
|
||||
<widget class="QMainWindow" name="ActWorldClass" >
|
||||
<property name="objectName" >
|
||||
<string notr="true">ActWorldClass</string>
|
||||
</property>
|
||||
<property name="geometry" >
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>600</width>
|
||||
<height>400</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle" >
|
||||
<string>ActWorld</string>
|
||||
</property> <widget class="QMenuBar" name="menuBar" />
|
||||
<widget class="QToolBar" name="mainToolBar" />
|
||||
<widget class="QWidget" name="centralWidget" />
|
||||
<widget class="QStatusBar" name="statusBar" />
|
||||
</widget>
|
||||
<layoutDefault spacing="6" margin="11" />
|
||||
<pixmapfunction></pixmapfunction>
|
||||
<resources>
|
||||
<include location="ActWorld.qrc"/>
|
||||
</resources>
|
||||
<connections/>
|
||||
</UI>
|
||||
|
|
@ -0,0 +1,114 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="17.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{EF07AD89-B0C9-4910-B391-8816294A39C6}</ProjectGuid>
|
||||
<Keyword>QtVS_v304</Keyword>
|
||||
<WindowsTargetPlatformVersion Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">10.0</WindowsTargetPlatformVersion>
|
||||
<WindowsTargetPlatformVersion Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">10.0</WindowsTargetPlatformVersion>
|
||||
<QtMsBuild Condition="'$(QtMsBuild)'=='' OR !Exists('$(QtMsBuild)\qt.targets')">$(MSBuildProjectDirectory)\QtMsBuild</QtMsBuild>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Condition="Exists('$(QtMsBuild)\qt_defaults.props')">
|
||||
<Import Project="$(QtMsBuild)\qt_defaults.props" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'" Label="QtSettings">
|
||||
<QtInstall>5.12.11_msvc2017_64</QtInstall>
|
||||
<QtModules>core;gui;widgets</QtModules>
|
||||
<QtBuildConfig>debug</QtBuildConfig>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'" Label="QtSettings">
|
||||
<QtInstall>5.12.11_msvc2017_64</QtInstall>
|
||||
<QtModules>core;gui;widgets</QtModules>
|
||||
<QtBuildConfig>release</QtBuildConfig>
|
||||
</PropertyGroup>
|
||||
<Target Name="QtMsBuildNotFound" BeforeTargets="CustomBuild;ClCompile" Condition="!Exists('$(QtMsBuild)\qt.targets') or !Exists('$(QtMsBuild)\qt.props')">
|
||||
<Message Importance="High" Text="QtMsBuild: could not locate qt.targets, qt.props; project may not build correctly." />
|
||||
</Target>
|
||||
<ImportGroup Label="ExtensionSettings" />
|
||||
<ImportGroup Label="Shared" />
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
<Import Project="$(QtMsBuild)\Qt.props" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
<Import Project="$(QtMsBuild)\Qt.props" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
|
||||
<IncludePath>$(SolutionDir)MapPresent;$(IncludePath)</IncludePath>
|
||||
<LibraryPath>$(SolutionDir)$(Platform)\$(Configuration);$(LibraryPath)</LibraryPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<Link>
|
||||
<AdditionalDependencies>MapPresent.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'" Label="Configuration">
|
||||
<ClCompile>
|
||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'" Label="Configuration">
|
||||
<ClCompile>
|
||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<GenerateDebugInformation>false</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<QtRcc Include="ActWorld.qrc" />
|
||||
<QtUic Include="ActWorld.ui" />
|
||||
<QtMoc Include="ActWorld.h" />
|
||||
<ClCompile Include="ActWorld.cpp" />
|
||||
<ClCompile Include="main.cpp" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Condition="Exists('$(QtMsBuild)\qt.targets')">
|
||||
<Import Project="$(QtMsBuild)\qt.targets" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Source Files">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>qml;cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Header Files">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Resource Files">
|
||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||
<Extensions>qrc;rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Form Files">
|
||||
<UniqueIdentifier>{99349809-55BA-4b9d-BF79-8FDBB0286EB3}</UniqueIdentifier>
|
||||
<Extensions>ui</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Translation Files">
|
||||
<UniqueIdentifier>{639EADAA-A684-42e4-A9AD-28FC9BCB8F7C}</UniqueIdentifier>
|
||||
<Extensions>ts</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<QtRcc Include="ActWorld.qrc">
|
||||
<Filter>Resource Files</Filter>
|
||||
</QtRcc>
|
||||
<QtUic Include="ActWorld.ui">
|
||||
<Filter>Form Files</Filter>
|
||||
</QtUic>
|
||||
<QtMoc Include="ActWorld.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</QtMoc>
|
||||
<ClCompile Include="ActWorld.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="main.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup />
|
||||
<PropertyGroup Label="QtSettings" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<QtTouchProperty>
|
||||
</QtTouchProperty>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Label="QtSettings" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<QtTouchProperty>
|
||||
</QtTouchProperty>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
#include "ActWorld.h"
|
||||
#include <QtWidgets/QApplication>
|
||||
#include <MapPresent.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication app(argc, argv);
|
||||
|
||||
//ActWorld window;
|
||||
//window.show();
|
||||
|
||||
MapPresent p;
|
||||
p.show();
|
||||
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
|
|
@ -0,0 +1,167 @@
|
|||
#include "MapPresent.h"
|
||||
|
||||
MapPresent::MapPresent(QWidget* parent /*= nullptr*/)
|
||||
:QWidget(parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
#include <QVector2D>
|
||||
#include <cmath>
|
||||
PresentIndex MapPresent::indexGet(const QPointF& pos) const
|
||||
{
|
||||
|
||||
return PresentIndex();
|
||||
}
|
||||
|
||||
#include <QVector3D>
|
||||
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 <QPainter>
|
||||
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<PresentIndex> MapPresent::siblingsGet(const PresentIndex& center, uint16_t dist) const
|
||||
{
|
||||
QList<PresentIndex> 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<PresentIndex> 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<PresentIndex> MapPresent::itemFills(const PresentIndex& a, const PresentIndex& b) const
|
||||
{
|
||||
QList<PresentIndex> 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<QPointF> points = endPointsGet(rect);
|
||||
|
||||
QVector<QLineF> 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<QPointF> BasicUnitDelegate::endPointsGet(const QRectF& rect)
|
||||
{
|
||||
auto center = rect.center();
|
||||
auto alen = rect.width() / 2;
|
||||
const float xspan = alen * sqrt(3) / 2;
|
||||
|
||||
QList<QPointF> 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;
|
||||
}
|
||||
|
|
@ -0,0 +1,110 @@
|
|||
#pragma once
|
||||
|
||||
#include "mappresent_global.h"
|
||||
#include <QWidget>
|
||||
|
||||
/// <summary>
|
||||
/// 绘制索引
|
||||
/// </summary>
|
||||
struct PresentIndex {
|
||||
/// <summary>
|
||||
/// 行号
|
||||
/// </summary>
|
||||
int row = 0;
|
||||
/// <summary>
|
||||
/// 列号
|
||||
/// </summary>
|
||||
int col = 0;
|
||||
|
||||
PresentIndex& operator+=(const PresentIndex& other);
|
||||
bool operator!=(const PresentIndex& other) const;
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// 绘制选项
|
||||
/// </summary>
|
||||
struct PresentOption {
|
||||
/// <summary>
|
||||
/// 当前所绘制索引
|
||||
/// </summary>
|
||||
PresentIndex selfIndex;
|
||||
/// <summary>
|
||||
/// 当前绘制外缘
|
||||
/// </summary>
|
||||
QRectF selfOutline;
|
||||
|
||||
bool isMouseOver = false;
|
||||
bool isSelected = false;
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// 单元绘制委托
|
||||
/// </summary>
|
||||
class UnitPresentDelegate {
|
||||
public:
|
||||
virtual ~UnitPresentDelegate() = default;
|
||||
/// <summary>
|
||||
/// 匹配单元类型
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
virtual int unitType() const = 0;
|
||||
/// <summary>
|
||||
/// 绘制本单元瓦片
|
||||
/// </summary>
|
||||
/// <param name="p"></param>
|
||||
/// <param name="option"></param>
|
||||
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<QPointF> endPointsGet(const QRectF &rect);
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// 基础地图绘制
|
||||
/// </summary>
|
||||
class MAPPRESENT_EXPORT MapPresent : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
private:
|
||||
/// <summary>
|
||||
/// 初级区域矩形变长
|
||||
/// </summary>
|
||||
const float _primitive_region_square_len = 100;
|
||||
/// <summary>
|
||||
/// 缩放倍数
|
||||
/// </summary>
|
||||
short _scale_times = 1;
|
||||
/// <summary>
|
||||
/// 当前瓦片地图中心索引
|
||||
/// </summary>
|
||||
PresentIndex _center_index;
|
||||
|
||||
public:
|
||||
MapPresent(QWidget* parent = nullptr);
|
||||
|
||||
/// <summary>
|
||||
/// 通过widget上定位获取绘制索引
|
||||
/// </summary>
|
||||
/// <param name="pos"></param>
|
||||
/// <returns></returns>
|
||||
PresentIndex indexGet(const QPointF& pos) const;
|
||||
/// <summary>
|
||||
/// 通过绘制索引获取指定单元外接矩形
|
||||
/// </summary>
|
||||
/// <param name="idx"></param>
|
||||
/// <returns></returns>
|
||||
QRectF outlineGet(const PresentIndex& idx) const;
|
||||
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent* ev) override;
|
||||
|
||||
private:
|
||||
QList<PresentIndex> siblingsGet(const PresentIndex ¢er, uint16_t dist=1) const;
|
||||
QList<PresentIndex> itemFills(const PresentIndex &a, const PresentIndex &b) const;
|
||||
};
|
||||
|
|
@ -0,0 +1,107 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="17.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{61427621-6536-4CFF-BEA7-94D3F1A7E657}</ProjectGuid>
|
||||
<Keyword>QtVS_v304</Keyword>
|
||||
<WindowsTargetPlatformVersion Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">10.0</WindowsTargetPlatformVersion>
|
||||
<WindowsTargetPlatformVersion Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">10.0</WindowsTargetPlatformVersion>
|
||||
<QtMsBuild Condition="'$(QtMsBuild)'=='' OR !Exists('$(QtMsBuild)\qt.targets')">$(MSBuildProjectDirectory)\QtMsBuild</QtMsBuild>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Condition="Exists('$(QtMsBuild)\qt_defaults.props')">
|
||||
<Import Project="$(QtMsBuild)\qt_defaults.props" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'" Label="QtSettings">
|
||||
<QtInstall>5.12.11_msvc2017_64</QtInstall>
|
||||
<QtModules>core;sql;gui;widgets</QtModules>
|
||||
<QtBuildConfig>debug</QtBuildConfig>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'" Label="QtSettings">
|
||||
<QtInstall>5.12.11_msvc2017_64</QtInstall>
|
||||
<QtModules>core</QtModules>
|
||||
<QtBuildConfig>release</QtBuildConfig>
|
||||
</PropertyGroup>
|
||||
<Target Name="QtMsBuildNotFound" BeforeTargets="CustomBuild;ClCompile" Condition="!Exists('$(QtMsBuild)\qt.targets') or !Exists('$(QtMsBuild)\qt.props')">
|
||||
<Message Importance="High" Text="QtMsBuild: could not locate qt.targets, qt.props; project may not build correctly." />
|
||||
</Target>
|
||||
<ImportGroup Label="ExtensionSettings" />
|
||||
<ImportGroup Label="Shared" />
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
<Import Project="$(QtMsBuild)\Qt.props" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
<Import Project="$(QtMsBuild)\Qt.props" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'" Label="Configuration">
|
||||
<ClCompile>
|
||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
<PreprocessorDefinitions>MAPPRESENT_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'" Label="Configuration">
|
||||
<ClCompile>
|
||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
<PreprocessorDefinitions>MAPPRESENT_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<GenerateDebugInformation>false</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="mappresent_global.h" />
|
||||
<QtMoc Include="MapPresent.h" />
|
||||
<ClCompile Include="MapPresent.cpp" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Condition="Exists('$(QtMsBuild)\qt.targets')">
|
||||
<Import Project="$(QtMsBuild)\qt.targets" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Source Files">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>qml;cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Header Files">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Resource Files">
|
||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||
<Extensions>qrc;rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Form Files">
|
||||
<UniqueIdentifier>{99349809-55BA-4b9d-BF79-8FDBB0286EB3}</UniqueIdentifier>
|
||||
<Extensions>ui</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Translation Files">
|
||||
<UniqueIdentifier>{639EADAA-A684-42e4-A9AD-28FC9BCB8F7C}</UniqueIdentifier>
|
||||
<Extensions>ts</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="mappresent_global.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClCompile Include="MapPresent.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<QtMoc Include="MapPresent.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</QtMoc>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup />
|
||||
<PropertyGroup Label="QtSettings" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<QtTouchProperty>
|
||||
</QtTouchProperty>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Label="QtSettings" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<QtTouchProperty>
|
||||
</QtTouchProperty>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
#pragma once
|
||||
|
||||
#include <QtCore/qglobal.h>
|
||||
|
||||
#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
|
||||
Loading…
Reference in New Issue