From c0632cfb8ea2d8be47f72b35f1ca6c3abed4c27c Mon Sep 17 00:00:00 2001 From: lveyou <1339484752@qq.com> Date: Sat, 13 Jan 2024 14:46:32 +0800 Subject: [PATCH] =?UTF-8?q?*=20=E6=B6=88=E9=99=A4=E7=BC=96=E8=AF=91?= =?UTF-8?q?=E8=AD=A6=E5=91=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dl/CMakeLists.txt | 4 +++ dl/io/dl_json.h | 2 +- dl/io/dl_qr.cpp | 2 +- dl/misc/dl_locator.cpp | 14 ++++++----- dl/misc/dl_timer.h | 4 +-- dl/render/dl_free_type.h | 8 +++--- dl/render/dl_graphics.h | 2 +- dl/render/dl_text.cpp | 45 ++++++++++++++++++---------------- dl/script/dl_script_variable.h | 4 +++ dl/system/dl_audio.cpp | 2 +- dl/tool/dl_tool_debug_info.h | 2 +- dl/ui/dl_ui_button_base.cpp | 8 +++--- dl/ui/dl_ui_list_box.h | 8 +++--- dl/ui/dl_ui_msg_box.h | 4 +-- dl/vk/dl_vk.cpp | 4 +-- dltest/ui_audio.h | 2 +- 16 files changed, 64 insertions(+), 51 deletions(-) diff --git a/dl/CMakeLists.txt b/dl/CMakeLists.txt index ca4ecc39..a3a92818 100644 --- a/dl/CMakeLists.txt +++ b/dl/CMakeLists.txt @@ -5,6 +5,10 @@ add_compile_options("$<$:/execution-charset:utf-8>") # 禁用windows min max宏 add_definitions(-DNOMINMAX) +# 关闭windows相关警告 +add_definitions(-D_CRT_SECURE_NO_WARNINGS) +# windows +add_definitions(-D_WIN32_WINNT=0x0601) # dl源文件 aux_source_directory(${CMAKE_SOURCE_DIR}/dl SRC_LIST) diff --git a/dl/io/dl_json.h b/dl/io/dl_json.h index dcc1bce9..298dfcef 100644 --- a/dl/io/dl_json.h +++ b/dl/io/dl_json.h @@ -39,7 +39,7 @@ bool Get(const json& j, const std::string& name, T& t) t = *iter; return true; } - catch (nlohmann::detail::exception& e) + catch (nlohmann::detail::exception&) { } return false; diff --git a/dl/io/dl_qr.cpp b/dl/io/dl_qr.cpp index db11ef65..433e4d31 100644 --- a/dl/io/dl_qr.cpp +++ b/dl/io/dl_qr.cpp @@ -19,7 +19,7 @@ namespace dl::QR { for (size_t x = 0; x < qr.getSize(); ++x) { - if (qr.getModule(x, y)) + if (qr.getModule((int)x, (int)y)) ret->Set(y, x, 0xff000000); else ret->Set(y, x, 0xffffffff); diff --git a/dl/misc/dl_locator.cpp b/dl/misc/dl_locator.cpp index 33189a30..958d6bb0 100644 --- a/dl/misc/dl_locator.cpp +++ b/dl/misc/dl_locator.cpp @@ -22,7 +22,7 @@ dl::Position Locator::_get_direct(std::size_t i) return { i * _sl._dt[0], 0 }; else { - std::ldiv_t d = std::ldiv(i, _sl._num); + std::ldiv_t d = std::ldiv((long)i, (long)_sl._num); return { d.rem * _sl._dt[0], d.quot * _sl._dt[1] }; } } @@ -32,7 +32,7 @@ dl::Position Locator::_get_direct(std::size_t i) return { 0, i * _sl._dt[1] }; else { - std::ldiv_t d = std::ldiv(i, _sl._num); + std::ldiv_t d = std::ldiv((long)i, (long)_sl._num); return { d.quot * _sl._dt[0], d.rem * _sl._dt[1] }; } } @@ -46,6 +46,7 @@ dl::Position Locator::_get_direct(std::size_t i) } else assert(0); + return {}; } dl::Position Locator::_get_adapt(const Size& size) @@ -53,7 +54,7 @@ dl::Position Locator::_get_adapt(const Size& size) assert(_sl._mode == Mode::ADAPT); if (_sl._layout == Layout::X) { - unsigned dx = (Float)size[0] / std::abs(_sl._dt[0]); + unsigned dx = (unsigned)(size[0] / std::abs(_sl._dt[0])); ++dx; if (_sl._num && dx + _x > _sl._num) {//需要换行 @@ -70,7 +71,7 @@ dl::Position Locator::_get_adapt(const Size& size) } else if (_sl._layout == Layout::Y) { - unsigned dy = (Float)size[1] / std::abs(_sl._dt[1]); + unsigned dy = (unsigned)(size[1] / std::abs(_sl._dt[1])); ++dy; if (_sl._num && dy + _y > _sl._num) {//需要换行 @@ -87,8 +88,8 @@ dl::Position Locator::_get_adapt(const Size& size) } else if (_sl._layout == Layout::XY) { - unsigned dx = (Float)size[0] / std::abs(_sl._dt[0]); - unsigned dy = (Float)size[1] / std::abs(_sl._dt[1]); + unsigned dx = (unsigned)(size[0] / std::abs(_sl._dt[0])); + unsigned dy = (unsigned)(size[1] / std::abs(_sl._dt[1])); Position ret = _sl._start + (_sl._dt * toPosition(_x, _y)); _x += dx; _y += dy; @@ -100,6 +101,7 @@ dl::Position Locator::_get_adapt(const Size& size) } else assert(0); + return {}; } } diff --git a/dl/misc/dl_timer.h b/dl/misc/dl_timer.h index c9964643..04cb5722 100644 --- a/dl/misc/dl_timer.h +++ b/dl/misc/dl_timer.h @@ -62,10 +62,10 @@ public: _cur += dt; if (_cur < _t) return false; - if (_cur < _t * 2.0) + if (_cur < _t * 2.0_f) return true; - _cur -= _t * 2.0; + _cur -= _t * 2.0_f; return false; } diff --git a/dl/render/dl_free_type.h b/dl/render/dl_free_type.h index 0c1b9dd7..a42f4319 100644 --- a/dl/render/dl_free_type.h +++ b/dl/render/dl_free_type.h @@ -250,8 +250,8 @@ public: { for (int w = 0; w < s._w; ++w) { - size_t y = img_h - 1 - (s._y - rect._yMin); - size_t index = y * img_w + s._x - rect._xMin + w; + size_t y = (size_t)(img_h - 1 - (s._y - rect._yMin)); + size_t index = (size_t)(y * img_w + s._x - rect._xMin + w); p_lock[index] = uint32_t(s._coverage) << 24 | 0x00ffffff; } } @@ -261,8 +261,8 @@ public: { for (int w = 0; w < s._w; ++w) { - size_t y = img_h - 1 - (s._y - rect._yMin); - size_t index = y * img_w + s._x - rect._xMin + w; + size_t y = (size_t)(img_h - 1 - (s._y - rect._yMin)); + size_t index = (size_t)(y * img_w + s._x - rect._xMin + w); p_lock[index] = uint32_t(s._coverage) << 24 | 0x00ffffff; } } diff --git a/dl/render/dl_graphics.h b/dl/render/dl_graphics.h index 66d48f54..674c6798 100644 --- a/dl/render/dl_graphics.h +++ b/dl/render/dl_graphics.h @@ -86,7 +86,7 @@ public: { //f(x)=(0.64*sqrt(abs(x))-0.8+1.2^abs(x)*cos(200*x))*sqrt(cos(x)) std::vector vec; - constexpr float pi_2 = Math::PI(1, 2); + constexpr float pi_2 = (float)Math::PI(1, 2); for (float x = -pi_2; x < pi_2; x += 0.001f) { float y = (0.64f * sqrtf(std::abs(x)) - 0.8f + std::pow(1.2f, std::abs(x)) * cosf(64 * x)) * sqrtf(cosf(x)); diff --git a/dl/render/dl_text.cpp b/dl/render/dl_text.cpp index e6a9f640..3761c2ac 100644 --- a/dl/render/dl_text.cpp +++ b/dl/render/dl_text.cpp @@ -44,7 +44,7 @@ void Text::SetFontSize(unsigned size) if (_fontSize[TextParam::NORMAL] == size) return; _fontSize[TextParam::NORMAL] = size; - _fontSizeReal[TextParam::NORMAL] = size / _coor->GetScale()[0]; + _fontSizeReal[TextParam::NORMAL] = (unsigned)(size / _coor->GetScale()[0]); _refresh_string(); } @@ -53,7 +53,7 @@ void Text::SetFontSize(unsigned size) void Text::SetOutline(unsigned outline, const Color& color) { _fontSize[TextParam::OUTLINE] = outline; - _fontSizeReal[TextParam::OUTLINE] = outline / _coor->GetScale()[0]; + _fontSizeReal[TextParam::OUTLINE] = (unsigned)(outline / _coor->GetScale()[0]); _col[TextParam::OUTLINE] = color; _refresh_string(); @@ -63,7 +63,7 @@ void Text::SetOutline(unsigned outline, const Color& color) void Text::SetShadow(unsigned shadow, const Color& color /*= ColorDef::BLACK*/) { _fontSize[TextParam::SHADOW] = shadow; - _fontSizeReal[TextParam::SHADOW] = shadow / _coor->GetScale()[0]; + _fontSizeReal[TextParam::SHADOW] = (unsigned)(shadow / _coor->GetScale()[0]); _col[TextParam::SHADOW] = color; _refresh_string(); @@ -186,8 +186,8 @@ void Text::_refresh_string() { TextNode node; node._ch = ch; - node._lineH = size; - node._ascent = size; + node._lineH = (Float)size; + node._ascent = (Float)size; node._advance = (Float)(size / 2); _allNode.push_back(node); return; @@ -196,8 +196,8 @@ void Text::_refresh_string() {//此处advance为几个字体宽度 TextNode node; node._ch = ch; - node._lineH = size; - node._ascent = size; + node._lineH = (Float)size; + node._ascent = (Float)size; node._advance = 2; _allNode.push_back(node); return; @@ -206,8 +206,8 @@ void Text::_refresh_string() { TextNode node; node._ch = ch; - node._lineH = size; - node._ascent = size; + node._lineH = (Float)size; + node._ascent = (Float)size; node._advance = 0; _allNode.push_back(node); return; @@ -326,9 +326,9 @@ void Text::_refresh_string() if (str_flag[0] == L'f') { cur_font_id = _fontId; - cur_font_size = _fontId; - cur_font_ouline = _fontId; - cur_font_shadow = _fontId; + cur_font_size = _fontSizeReal[TextParam::NORMAL]; + cur_font_ouline = _fontSizeReal[TextParam::OUTLINE]; + cur_font_shadow = _fontSizeReal[TextParam::SHADOW]; } else if (str_flag[0] == L'c') { @@ -377,11 +377,11 @@ void Text::_refresh_string() split_no_empty(str_flag, L'_', vec); if (vec.size() > 1) - cur_font_size = stoi(vec[1]) * s; + cur_font_size = (unsigned)(stoi(vec[1]) * s); if (vec.size() > 2) - cur_font_ouline = stoi(vec[2]) * s; + cur_font_ouline = (unsigned)(stoi(vec[2]) * s); if (vec.size() > 3) - cur_font_shadow = stoi(vec[3]) * s; + cur_font_shadow = (unsigned)(stoi(vec[3]) * s); } else if (str_flag[0] == L'c') { @@ -418,7 +418,7 @@ void Text::_refresh_string() //指定宽度 写入\t TextNode node; node._ch = U'\t'; - node._advance = stoi(vec[1]); + node._advance = (Float)(stoi(vec[1])); node._lineH = g_freetype->GetProperty(cur_font_id, cur_font_size).GetLinespace(); _allNode.push_back(node); } @@ -429,7 +429,10 @@ void Text::_refresh_string() str_flag.clear(); } else - str_flag.push_back(ch);//TODO utf_char转wchar_t + { + assert(ch < 65536);//TODO utf_char转wchar_t + str_flag.push_back((wchar_t)ch); + } break; default: log_err0("错误的标签!"); @@ -498,7 +501,7 @@ void Text::_update_layout() //对齐后任在原地,则步进advance if (x == sx) { - node._advance1 = advance; + node._advance1 = (Float)advance; sx += advance; } else @@ -660,9 +663,9 @@ bool Text::_update_scale() if (std::abs(s_inv - s_cur) > 0.01f) { - _fontSizeReal[TextParam::NORMAL] = _fontSize[TextParam::NORMAL] * s; - _fontSizeReal[TextParam::OUTLINE] = _fontSize[TextParam::OUTLINE] * s; - _fontSizeReal[TextParam::SHADOW] = _fontSize[TextParam::SHADOW] * s; + _fontSizeReal[TextParam::NORMAL] = (unsigned)(_fontSize[TextParam::NORMAL] * s); + _fontSizeReal[TextParam::OUTLINE] = (unsigned)(_fontSize[TextParam::OUTLINE] * s); + _fontSizeReal[TextParam::SHADOW] = (unsigned)(_fontSize[TextParam::SHADOW] * s); _coor->SetScale(s_inv); return true; } diff --git a/dl/script/dl_script_variable.h b/dl/script/dl_script_variable.h index b81d9ff4..522ae3c0 100644 --- a/dl/script/dl_script_variable.h +++ b/dl/script/dl_script_variable.h @@ -64,6 +64,10 @@ public: { _copy(b); } + Variable(const std::string& str) : + _type{ Type::STRING }, + _val{ str } + {} Variable(std::string_view str) : _type{ Type::STRING }, _val{ std::string{str} } diff --git a/dl/system/dl_audio.cpp b/dl/system/dl_audio.cpp index 7d8c710d..dd1f9ad7 100644 --- a/dl/system/dl_audio.cpp +++ b/dl/system/dl_audio.cpp @@ -1,6 +1,6 @@ #include "dl_audio.h" -#define AL_LIBTYPE_STATIC +//#define AL_LIBTYPE_STATIC #include #include diff --git a/dl/tool/dl_tool_debug_info.h b/dl/tool/dl_tool_debug_info.h index d62737ea..849471cb 100644 --- a/dl/tool/dl_tool_debug_info.h +++ b/dl/tool/dl_tool_debug_info.h @@ -11,7 +11,7 @@ #pragma once #include -#include ] +#include namespace dl::Tool { diff --git a/dl/ui/dl_ui_button_base.cpp b/dl/ui/dl_ui_button_base.cpp index b0360091..f76ae5ae 100644 --- a/dl/ui/dl_ui_button_base.cpp +++ b/dl/ui/dl_ui_button_base.cpp @@ -1,5 +1,7 @@ #include "dl_ui_button_base.h" +#include "system/dl_audio.h" + namespace dl::UI { @@ -147,8 +149,6 @@ void Button::_update_radio() } } -#define snd_play - void Button::Update() { if (_bDisable) @@ -174,10 +174,10 @@ void Button::Update() } if (!_strSndClick.empty() && IsClick()) - snd_play(_strSndClick.c_str()); + snd_play(_strSndClick); if (!_strSndOver.empty() && IsThrough()) - snd_play(_strSndOver.c_str()); + snd_play(_strSndOver); UpdateChild(_statePre, _state); } diff --git a/dl/ui/dl_ui_list_box.h b/dl/ui/dl_ui_list_box.h index ae248203..85ea13ea 100644 --- a/dl/ui/dl_ui_list_box.h +++ b/dl/ui/dl_ui_list_box.h @@ -179,11 +179,11 @@ public: private: ListBox() : _cpt{ this }, - _curSelect{ -1_zu }, + _curSelect{ std::string::npos }, _selectLimit{ 1 }, _scroll{ 0 }, _scrollK{ 1.0f }, - _num{ -1_zu } + _num{ std::string::npos } { _init_cpt(); _coorItem = Coor::Create(); @@ -235,9 +235,9 @@ private: void _limit_select(std::size_t i_select); // 计算滚轮位置 - std::size_t _calc_scroll() + size_t _calc_scroll() { - return (_scroll + 1.0_f) / _locItem.GetDy(); + return (size_t)((_scroll + 1.0_f) / _locItem.GetDy()); } void _limit_scroll() { diff --git a/dl/ui/dl_ui_msg_box.h b/dl/ui/dl_ui_msg_box.h index cfe559c1..06a8d3f3 100644 --- a/dl/ui/dl_ui_msg_box.h +++ b/dl/ui/dl_ui_msg_box.h @@ -115,7 +115,7 @@ public: //整体宽度为 按钮宽度 + 间隔(多一个) Float w = w_btn * _numBtn + _dxBtn * (1 + _numBtn); - _txt->SetMaxW(w);//设置文本宽度 + _txt->SetMaxW((unsigned)w);//设置文本宽度 Float h_txt = _txt->GetSize()[1]; //文本高度 Float h_title = _txtTitle->GetSize()[1];//标题高度 @@ -134,7 +134,7 @@ public: if (_numBtn > 0) { //偏移为 负的 按钮总宽度的一半(间隔少一个) + 半个按钮 - Float sx_btn = (w_btn * _numBtn + _dxBtn * (_numBtn - 1)) * -0.5 + w_btn * 0.5; + Float sx_btn = (w_btn * _numBtn + _dxBtn * (_numBtn - 1)) * -0.5_f + w_btn * 0.5_f; for (std::size_t i = 0; i < _numBtn; ++i) { _allBtn[i]->GetCoor()->SetPosition({ sx_btn + i * (w_btn + _dxBtn), size_half[1] }); diff --git a/dl/vk/dl_vk.cpp b/dl/vk/dl_vk.cpp index 7912e41d..10433cc3 100644 --- a/dl/vk/dl_vk.cpp +++ b/dl/vk/dl_vk.cpp @@ -1134,7 +1134,7 @@ void VK::_record_command_buffer(VkCommandBuffer command_buffer, uint32_t index_i //绘制 // 绘制 - vkCmdDraw(command_buffer, vb._index, 1, 0, 0); + vkCmdDraw(command_buffer, (uint32_t)vb._index, 1, 0, 0); } //--------------------2d 透明---------------------- if (!list_dc_translucent.empty()) @@ -1168,7 +1168,7 @@ void VK::_record_command_buffer(VkCommandBuffer command_buffer, uint32_t index_i vkCmdBindVertexBuffers(command_buffer, 0, 1, vertexBuffers, offsets); //绘制 - vkCmdDraw(command_buffer, vb._index, 1, 0, 0); + vkCmdDraw(command_buffer, (uint32_t)vb._index, 1, 0, 0); } //结束 diff --git a/dltest/ui_audio.h b/dltest/ui_audio.h index dc95e8c5..f8916502 100644 --- a/dltest/ui_audio.h +++ b/dltest/ui_audio.h @@ -92,5 +92,5 @@ private: UI::Panel* _panelMenu; Coor* _coorRender; gcSound _snd; - int _selectidx = -1; + size_t _selectidx = -1; }; \ No newline at end of file