diff --git a/dl/math/dl_coor.h b/dl/math/dl_coor.h index b578919a..ae5c962d 100644 --- a/dl/math/dl_coor.h +++ b/dl/math/dl_coor.h @@ -60,6 +60,8 @@ public: /** * @brief 将点 从 自身坐标系 转到 父坐标系 + * + * @note 注意 coor->ThisToParent(pos)和 pos * coor->GetScale()的效果不同 */ Position ThisToParent(Position pos) const; @@ -77,24 +79,6 @@ public: * @brief 将点 从 自身坐标系 转到 根坐标系 */ Position ThisToRoot(Position pos) const; - - - /** - * @brief 将点 从 世界坐标系 转到 父坐标系 - */ - Position WorldToParent(Position pos) const - { - return _parent ? _parent->WorldToThis(pos) : WorldToThis(pos); - } - - /** - * @brief 将点 从 父坐标系 转到 世界坐标系 - */ - Position ParentToWorld(Position pos) const - { - return _parent ? _parent->ThisToWorld(pos) : ThisToWorld(pos); - } - /** * @brief 获取它的根坐标系 * @retval 返回对应根坐标系的指针,如果是窗口坐标系,返回nullptr diff --git a/dl/system/dl_system.h b/dl/system/dl_system.h index efd3a083..76a79f0b 100644 --- a/dl/system/dl_system.h +++ b/dl/system/dl_system.h @@ -108,6 +108,13 @@ public: */ Size GetWindowSize(); /** + * @brief 返回窗口中心 + */ + Position GetWindowCenter() + { + return toPosition(GetWindowSize()) * 0.5f; + } + /** * @brief 获取桌面大小,不包含任务栏 */ Size GetWorkArea(); diff --git a/dl/tool/dl_tool_ctrl_2d.cpp b/dl/tool/dl_tool_ctrl_2d.cpp index 6860b4c8..1e8fb5c3 100644 --- a/dl/tool/dl_tool_ctrl_2d.cpp +++ b/dl/tool/dl_tool_ctrl_2d.cpp @@ -93,5 +93,16 @@ void Controller2d::UpdateLimit(Coor* coor, const Size& map_size) coor->SetPosition(pos); } +void Controller2d::Center(Coor* coor, const Position& pos, size_t scale_level) +{ + // 先修改缩放 + _scaleLevelCur = std::clamp(scale_level, (size_t)0, _scaleLevel.size() - 1); + coor->SetScale(_scaleLevel[_scaleLevelCur]); + + Position p1 = pos * coor->GetScale(); + Position p2 = g_system->GetWindowCenter(); + coor->SetPosition(p2 - p1); +} + } #endif \ No newline at end of file diff --git a/dl/tool/dl_tool_ctrl_2d.h b/dl/tool/dl_tool_ctrl_2d.h index bd75d976..82fe4eb0 100644 --- a/dl/tool/dl_tool_ctrl_2d.h +++ b/dl/tool/dl_tool_ctrl_2d.h @@ -37,6 +37,8 @@ public: void Update(Coor* coor); // 传入地图大小,限制地图在窗口内 void UpdateLimit(Coor* coor, const Size& map_size); + // 将位置(地图坐标系)设为中心 + void Center(Coor* coor, const Position& pos, size_t scale_level); private: Cpt::Drag _drag; }; diff --git a/project/dl_config b/project/dl_config index 87e3d8ff..f7a8db5f 160000 --- a/project/dl_config +++ b/project/dl_config @@ -1 +1 @@ -Subproject commit 87e3d8fffeee486a5288814f8a224bfcef5a9696 +Subproject commit f7a8db5f48653b040ef2434b30902bb383f54cfc diff --git a/project/hs b/project/hs index 08eebd1b..7188310d 160000 --- a/project/hs +++ b/project/hs @@ -1 +1 @@ -Subproject commit 08eebd1bea9603f32d633f8ff56ffed8da74d34c +Subproject commit 7188310de32aceadd9230d97c304c17497aad1f0