diff --git a/dl/base/dl_array.h b/dl/base/dl_array.h index 53c745ad..aa368812 100644 --- a/dl/base/dl_array.h +++ b/dl/base/dl_array.h @@ -45,14 +45,6 @@ public: for (; i < N; ++i) _data[i] = {}; } - constexpr Array& operator=(const std::array& b) - { - for (size_t i = 0; i < N; ++i) - { - _data[i] = b[i]; - } - return *this; - } constexpr T& operator[](size_t i) { assert(i < N); @@ -116,14 +108,6 @@ public: for (size_t i = 0; i < 2; ++i) _data[i] = i < N_LIST ? *(data.begin() + i) : T{}; } - constexpr Array& operator=(const std::array& b) - { - for (size_t i = 0; i < 2; ++i) - { - _data[i] = b[i]; - } - return *this; - } constexpr const T& Get(size_t i) const { assert(i < 2); @@ -192,14 +176,6 @@ public: size_t N_LIST = std::size(data); for (size_t i = 0; i < 3; ++i) _data[i] = i < N_LIST ? *(data.begin() + i) : T{}; - } - constexpr Array& operator=(const std::array& b) - { - for (size_t i = 0; i < 3; ++i) - { - _data[i] = b[i]; - } - return *this; } constexpr const T& Get(size_t i) const { @@ -286,14 +262,6 @@ public: for (size_t i = 0; i < 4; ++i) _data[i] = i < N_LIST ? *(data.begin() + i) : T{}; } - constexpr Array& operator=(const std::array& b) - { - for (size_t i = 0; i < 4; ++i) - { - _data[i] = b[i]; - } - return *this; - } constexpr const T& Get(size_t i) const { assert(i < 4); @@ -350,10 +318,6 @@ public: constexpr Array(std::initializer_list data) { } - constexpr Array& operator=(const std::array& b) - { - return *this; - } constexpr T& operator[](size_t i) { return *begin(); diff --git a/dl/base/dl_type_convert.h b/dl/base/dl_type_convert.h index 76a15aa0..1253cf66 100644 --- a/dl/base/dl_type_convert.h +++ b/dl/base/dl_type_convert.h @@ -30,6 +30,16 @@ constexpr Array toArray(const Array& a) } return ret; } +template +constexpr Array toArray(const std::array& a) +{ + Array ret; + for (std::size_t i = 0; i < N; ++i) + { + ret[i] = a[i]; + } + return ret; +} /** * @brief 转换到Position,已知长度 */ diff --git a/dl/render/dl_particle.h b/dl/render/dl_particle.h index e287b407..8fea6493 100644 --- a/dl/render/dl_particle.h +++ b/dl/render/dl_particle.h @@ -46,7 +46,7 @@ namespace dl _radin[0] = Math::Angle2Radin(_config.node.angle[0]); _radin[1] = Math::Angle2Radin(_config.node.angle[1]); - _gravity = _config.system.gravity; + _gravity = toArray(_config.system.gravity); } }; diff --git a/dl/render/dl_sprite.h b/dl/render/dl_sprite.h index 635c866a..3ed1bd40 100644 --- a/dl/render/dl_sprite.h +++ b/dl/render/dl_sprite.h @@ -73,8 +73,9 @@ class Sprite public: enum class Sampler { - NORMAL, - PIXEL + NORMAL, // 线性采样(写实画风使用) + PIXEL, // 点采样(像素风使用) + UI, // 线性采样、无mipmap }; enum class Blend { diff --git a/dl/ui/dl_ui_background.cpp b/dl/ui/dl_ui_background.cpp index fd1a6ede..67d21df4 100644 --- a/dl/ui/dl_ui_background.cpp +++ b/dl/ui/dl_ui_background.cpp @@ -59,6 +59,8 @@ namespace dl::UI _ui._spr->SetUI(true); _ui._spr->SetCoor(_coor); + + _cptElemData._size = _ui._spr->GetSize(); } void Background::Set(Sprite9* spr9) @@ -69,6 +71,8 @@ namespace dl::UI _ui._spr9->SetUI(true); _ui._spr9->GetCoor()->SetParent(_coor); + + _cptElemData._size = toPosition(_ui._spr9->GetSize()); } void Background::Clear() diff --git a/dl/ui/dl_ui_button_sprite.h b/dl/ui/dl_ui_button_sprite.h index b986c325..c577152c 100644 --- a/dl/ui/dl_ui_button_sprite.h +++ b/dl/ui/dl_ui_button_sprite.h @@ -26,7 +26,7 @@ public: /** * @brief 精灵组成的按钮 * @param[in] mul_spr 多个精灵,浅拷贝 - * @note 最多五个精灵,普通、经过、按下、禁用(普通)、禁用(按下) + * @note 最多6个精灵,普通、经过、按下、禁用(普通)、经过(按下)、禁用(按下) * 最少3个,缺少的禁用状态叠加灰度,4个时用一样的禁用状态。 * 可以额外拥有文本 */ diff --git a/dl/ui/dl_ui_panel.cpp b/dl/ui/dl_ui_panel.cpp index ddcfbb01..f625ef34 100644 --- a/dl/ui/dl_ui_panel.cpp +++ b/dl/ui/dl_ui_panel.cpp @@ -173,7 +173,7 @@ void Panel::Update() if (_bNeedRefreshPos) { _bNeedRefreshPos = false; - _refresh_pos(GetParent()->GetSize()); + _refresh_pos(GetParentSize()); } // 后优先级组件 @@ -294,6 +294,9 @@ void Panel::_render_child() void Panel::_refresh_size() { + if(_align != Align::LT) + _bNeedRefreshPos = true; // 修改大小会影响自己的对齐,即Align + if (_bSizeFull) { // 父节点大小 @@ -634,6 +637,28 @@ RectF Panel::GetRect() return ret; } +dl::Position Panel::GetParentSize() +{ + auto parent = GetParent(); + if (parent && parent->GetSize()!= Position{}) + { + return parent->GetSize(); + } + + return toPosition(g_system->GetWindowSize()) / g_ui->GetScale(); +} + +dl::Position Panel::GetSize() +{ + if (_bSizeAuto) + return _locator.GetSize(); + if (_size == Position{}) + { + return GetParentSize(); + } + return _size; +} + } #endif \ No newline at end of file diff --git a/dl/ui/dl_ui_panel.h b/dl/ui/dl_ui_panel.h index 4ad65ad6..2f8702fa 100644 --- a/dl/ui/dl_ui_panel.h +++ b/dl/ui/dl_ui_panel.h @@ -501,13 +501,15 @@ public: /** * @brief 返回大小 + * @note 自动大小则使用定位器自动大小 + * 若坐标为0,则使用父节点大小,直到窗口大小 */ - Position GetSize() - { - if (_bSizeAuto) - return _locator.GetSize(); - return _size; - } + Position GetSize(); + /** + * @brief 返回父节点大小 + * @note 父节点不存在或为0时,返回窗口大小 + */ + Position GetParentSize(); /** * @brief 返回所有元素和子节点组成的包围盒 */ @@ -710,14 +712,14 @@ private: NTree::Node* _node; // location - Align::Direction2 _align; // 在父节点的对齐 + Align::Direction2 _align; // 自己大小对齐 Position _posPixel; Position _posScale; // locator Locator _locator; - Position _size; // 指定大小 + Position _size; // 指定大小(0表示跟随父节点大小) bool _bSizeFull;// 与父节点同大小 bool _bSizeAuto; // 自动大小 diff --git a/dl/vk/dl_vk.cpp b/dl/vk/dl_vk.cpp index 3d79f46f..779b5930 100644 --- a/dl/vk/dl_vk.cpp +++ b/dl/vk/dl_vk.cpp @@ -3726,25 +3726,26 @@ void VK::_create_2d() // 3.纹理采样器 VkSamplerCreateInfo samplerInfo{}; samplerInfo.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; - samplerInfo.magFilter = VK_FILTER_NEAREST;// VK_FILTER_LINEAR; - samplerInfo.minFilter = VK_FILTER_NEAREST; + samplerInfo.magFilter = VK_FILTER_LINEAR; + samplerInfo.minFilter = VK_FILTER_LINEAR; samplerInfo.addressModeU = VK_SAMPLER_ADDRESS_MODE_REPEAT; samplerInfo.addressModeV = VK_SAMPLER_ADDRESS_MODE_REPEAT; samplerInfo.addressModeW = VK_SAMPLER_ADDRESS_MODE_REPEAT; samplerInfo.anisotropyEnable = VK_TRUE; - VkPhysicalDeviceProperties properties{}; - vkGetPhysicalDeviceProperties(_physicalDevice, &properties); + //VkPhysicalDeviceProperties properties{}; + //vkGetPhysicalDeviceProperties(_physicalDevice, &properties); - if (true) - { - samplerInfo.maxAnisotropy = properties.limits.maxSamplerAnisotropy; - } - else - { - samplerInfo.anisotropyEnable = VK_FALSE; - samplerInfo.maxAnisotropy = 1.0f; - } + //// 2d不应该开启各向异性采样 + //if (false) + //{ + // samplerInfo.maxAnisotropy = properties.limits.maxSamplerAnisotropy; + //} + //else + //{ + samplerInfo.anisotropyEnable = VK_FALSE; + samplerInfo.maxAnisotropy = 1.0f; + //} samplerInfo.borderColor = VK_BORDER_COLOR_INT_OPAQUE_BLACK; samplerInfo.unnormalizedCoordinates = VK_FALSE; samplerInfo.compareEnable = VK_FALSE; @@ -3756,7 +3757,22 @@ void VK::_create_2d() if (vkCreateSampler(_device, &samplerInfo, nullptr, &_2d._textureSampler) != VK_SUCCESS) { - log_damage0("创建纹理采样器失败!"); + log_damage0("创建2d纹理采样器失败!"); + return; + } + samplerInfo.magFilter = VK_FILTER_NEAREST; + samplerInfo.minFilter = VK_FILTER_NEAREST; + samplerInfo.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST; + if (vkCreateSampler(_device, &samplerInfo, nullptr, &_2d._textureSamplerPixel) != VK_SUCCESS) + { + log_damage0("创建2d纹理采样器(pixel)失败!"); + return; + } + // 关闭mipmap + samplerInfo.maxLod = 0; + if (vkCreateSampler(_device, &samplerInfo, nullptr, &_2d._textureSamplerUI) != VK_SUCCESS) + { + log_damage0("创建2d纹理采样器(ui)失败!"); return; } //3.5 索引缓冲 @@ -3849,6 +3865,8 @@ void VK::_delete_2d() } vkDestroySampler(_device, _2d._textureSampler, nullptr); + vkDestroySampler(_device, _2d._textureSamplerPixel, nullptr); + vkDestroySampler(_device, _2d._textureSamplerUI, nullptr); for (auto& iter : _2d._allCanvas) { iter.second->Delete(_device); diff --git a/dl/vk/dl_vk.h b/dl/vk/dl_vk.h index 63fa864b..6124aee9 100644 --- a/dl/vk/dl_vk.h +++ b/dl/vk/dl_vk.h @@ -414,7 +414,9 @@ public: std::vector _descriptorSets; // 所有描述符集 VkBuffer _indexBuffer; // 索引缓冲(注意是32位) VkDeviceMemory _indexBufferMemory; // 索引缓冲内存 - VkSampler _textureSampler; // 纹理采样器 + VkSampler _textureSampler; // 2d纹理采样器 + VkSampler _textureSamplerPixel; // 2d纹理采样器 + VkSampler _textureSamplerUI; // 2d纹理采样器 std::array _allCBO; // 常量缓冲 size_t _curPushConstant; // 当前使用 常量缓冲 下标 std::array _allRootCoor; // 所有根坐标系 diff --git a/project/project.cmake b/project/project.cmake index 74fcea6d..e1accb24 100644 --- a/project/project.cmake +++ b/project/project.cmake @@ -12,7 +12,7 @@ endif() if (NOT DEFINED USE_CONSOLE) set(USE_CONSOLE true) endif() -if(NOT DEFINED USE_CRASH_RPT) +if(WIN32 AND (NOT DEFINED USE_CRASH_RPT)) set(USE_CRASH_RPT true) endif() if(USE_CRASH_RPT)