From 90c0bcc3b028eb67316c831c37a9906bb67afae5 Mon Sep 17 00:00:00 2001 From: Nomango <569629550@qq.com> Date: Sun, 18 Aug 2019 22:49:44 +0800 Subject: [PATCH] [deploy] Add numeric types alias --- appveyor.yml | 3 +- projects/kiwano-audio.vcxproj | 4 +- projects/kiwano-imgui.vcxproj | 4 +- projects/kiwano-network.vcxproj | 4 +- projects/kiwano.vcxproj | 1 + projects/kiwano.vcxproj.filters | 3 + .../appveyor/clear_project_configuration.ps1 | 8 + src/kiwano-audio/src/Player.cpp | 22 +-- src/kiwano-audio/src/Player.h | 24 +-- src/kiwano-audio/src/Sound.cpp | 12 +- src/kiwano-audio/src/Sound.h | 8 +- src/kiwano-audio/src/Transcoder.cpp | 10 +- src/kiwano-audio/src/Transcoder.h | 6 +- src/kiwano-audio/src/audio-modules.h | 4 +- src/kiwano-imgui/src/ImGuiModule.cpp | 18 +- src/kiwano-imgui/src/ImGuiModule.h | 2 +- src/kiwano-network/src/HttpClient.cpp | 12 +- src/kiwano/2d/Actor.cpp | 52 +++--- src/kiwano/2d/Actor.h | 98 +++++------ src/kiwano/2d/Canvas.cpp | 16 +- src/kiwano/2d/Canvas.h | 20 +-- src/kiwano/2d/Frame.h | 4 +- src/kiwano/2d/FrameSequence.cpp | 2 +- src/kiwano/2d/FrameSequence.h | 2 +- src/kiwano/2d/GifSprite.cpp | 4 +- src/kiwano/2d/GifSprite.h | 10 +- src/kiwano/2d/Layer.cpp | 2 +- src/kiwano/2d/Layer.h | 10 +- src/kiwano/2d/ShapeActor.cpp | 8 +- src/kiwano/2d/ShapeActor.h | 16 +- src/kiwano/2d/Text.cpp | 11 +- src/kiwano/2d/Text.h | 10 +- src/kiwano/2d/TextStyle.hpp | 12 +- src/kiwano/2d/Transform.hpp | 2 +- src/kiwano/2d/Transition.cpp | 16 +- src/kiwano/2d/Transition.h | 26 ++- src/kiwano/2d/action/Action.h | 8 +- src/kiwano/2d/action/ActionHelper.h | 38 ++--- src/kiwano/2d/action/ActionManager.cpp | 4 +- src/kiwano/2d/action/ActionManager.h | 2 +- src/kiwano/2d/action/ActionTween.cpp | 58 +++---- src/kiwano/2d/action/ActionTween.h | 72 ++++---- src/kiwano/2d/action/ActionWalk.cpp | 14 +- src/kiwano/2d/action/ActionWalk.h | 18 +- src/kiwano/2d/action/Animation.cpp | 4 +- src/kiwano/2d/action/Animation.h | 2 +- src/kiwano/base/AsyncTask.cpp | 4 +- src/kiwano/base/Component.h | 2 +- src/kiwano/base/Event.hpp | 40 ++--- src/kiwano/base/EventDispatcher.cpp | 8 +- src/kiwano/base/EventDispatcher.h | 8 +- src/kiwano/base/EventListener.cpp | 2 +- src/kiwano/base/EventListener.h | 4 +- src/kiwano/base/Input.cpp | 34 ++-- src/kiwano/base/Input.h | 22 +-- src/kiwano/base/Logger.cpp | 14 +- src/kiwano/base/Logger.h | 26 +-- src/kiwano/base/ObjectBase.cpp | 2 +- src/kiwano/base/ObjectBase.h | 6 +- src/kiwano/base/Resource.cpp | 4 +- src/kiwano/base/Resource.h | 8 +- src/kiwano/base/Timer.cpp | 2 +- src/kiwano/base/Timer.h | 6 +- src/kiwano/base/Window.cpp | 58 +++---- src/kiwano/base/Window.h | 16 +- src/kiwano/base/keys.hpp | 4 +- src/kiwano/base/time.cpp | 70 ++++---- src/kiwano/base/time.h | 52 +++--- src/kiwano/base/types.h | 14 +- src/kiwano/core/basic_json.hpp | 80 ++++----- src/kiwano/core/core.h | 4 +- src/kiwano/core/function.hpp | 66 ++++---- src/kiwano/core/intrusive_list.hpp | 3 +- src/kiwano/core/string.hpp | 159 +++++++++--------- src/kiwano/core/types.h | 45 +++++ src/kiwano/core/vector.hpp | 13 +- src/kiwano/math/Matrix.hpp | 14 +- src/kiwano/math/Rect.hpp | 2 +- src/kiwano/math/Vec2.hpp | 4 +- src/kiwano/math/ease.hpp | 68 ++++---- src/kiwano/math/rand.h | 30 ++-- src/kiwano/math/scalar.hpp | 52 +++--- src/kiwano/platform/Application.cpp | 24 +-- src/kiwano/platform/Application.h | 14 +- src/kiwano/renderer/Color.cpp | 20 +-- src/kiwano/renderer/Color.h | 33 ++-- src/kiwano/renderer/Font.cpp | 2 +- src/kiwano/renderer/Font.h | 10 +- src/kiwano/renderer/Geometry.cpp | 18 +- src/kiwano/renderer/Geometry.h | 10 +- src/kiwano/renderer/GifImage.cpp | 26 +-- src/kiwano/renderer/GifImage.h | 14 +- src/kiwano/renderer/Image.cpp | 24 +-- src/kiwano/renderer/Image.h | 10 +- src/kiwano/renderer/ImageCache.cpp | 4 +- src/kiwano/renderer/ImageCache.h | 4 +- src/kiwano/renderer/LayerArea.h | 6 +- src/kiwano/renderer/RenderTarget.cpp | 14 +- src/kiwano/renderer/RenderTarget.h | 18 +- src/kiwano/renderer/Renderer.cpp | 16 +- src/kiwano/renderer/Renderer.h | 6 +- src/kiwano/renderer/TextLayout.cpp | 2 +- src/kiwano/renderer/TextLayout.h | 2 +- src/kiwano/renderer/win32/ComPtr.hpp | 2 +- .../renderer/win32/D2DDeviceResources.cpp | 4 +- .../renderer/win32/D2DDeviceResources.h | 4 +- .../renderer/win32/D3D10DeviceResources.cpp | 32 ++-- .../renderer/win32/D3D11DeviceResources.cpp | 24 +-- .../renderer/win32/D3DDeviceResourcesBase.h | 2 +- .../renderer/win32/FontCollectionLoader.cpp | 40 ++--- .../renderer/win32/FontCollectionLoader.h | 4 +- src/kiwano/renderer/win32/TextRenderer.cpp | 48 +++--- src/kiwano/renderer/win32/TextRenderer.h | 4 +- src/kiwano/ui/Button.cpp | 8 +- src/kiwano/ui/Menu.cpp | 2 +- src/kiwano/ui/Menu.h | 2 +- src/kiwano/utils/DataUtil.cpp | 22 +-- src/kiwano/utils/DataUtil.h | 32 ++-- src/kiwano/utils/Path.cpp | 10 +- src/kiwano/utils/ResourceCache.cpp | 28 +-- src/kiwano/utils/ResourceCache.h | 6 +- 121 files changed, 1125 insertions(+), 1058 deletions(-) create mode 100644 scripts/appveyor/clear_project_configuration.ps1 create mode 100644 src/kiwano/core/types.h diff --git a/appveyor.yml b/appveyor.yml index 073bdfc0..e876db8b 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -71,7 +71,8 @@ platform: install: - ps: .\scripts\appveyor\install_coapp.ps1 -# before_build: +before_build: +- ps: .\scripts\appveyor\clear_project_configuration.ps1 # - ps: nuget restore projects/Kiwano.sln build: diff --git a/projects/kiwano-audio.vcxproj b/projects/kiwano-audio.vcxproj index f3593c1a..0deda3e8 100644 --- a/projects/kiwano-audio.vcxproj +++ b/projects/kiwano-audio.vcxproj @@ -75,7 +75,7 @@ Level3 Disabled true - None + EditAndContinue true ../src/ false @@ -93,7 +93,7 @@ true false true - None + EditAndContinue true ../src/ false diff --git a/projects/kiwano-imgui.vcxproj b/projects/kiwano-imgui.vcxproj index 1ece0103..5416cc13 100644 --- a/projects/kiwano-imgui.vcxproj +++ b/projects/kiwano-imgui.vcxproj @@ -84,7 +84,7 @@ Level3 Disabled true - None + EditAndContinue true ../src/ false @@ -102,7 +102,7 @@ true false true - None + EditAndContinue true ../src/ false diff --git a/projects/kiwano-network.vcxproj b/projects/kiwano-network.vcxproj index bf1c120c..1568fb4e 100644 --- a/projects/kiwano-network.vcxproj +++ b/projects/kiwano-network.vcxproj @@ -73,7 +73,7 @@ Level3 Disabled true - None + EditAndContinue true ../src/ false @@ -91,7 +91,7 @@ true false true - None + EditAndContinue true ../src/ false diff --git a/projects/kiwano.vcxproj b/projects/kiwano.vcxproj index 39a9021c..6284642f 100644 --- a/projects/kiwano.vcxproj +++ b/projects/kiwano.vcxproj @@ -21,6 +21,7 @@ + diff --git a/projects/kiwano.vcxproj.filters b/projects/kiwano.vcxproj.filters index 8995881e..7dadb0ef 100644 --- a/projects/kiwano.vcxproj.filters +++ b/projects/kiwano.vcxproj.filters @@ -306,6 +306,9 @@ renderer + + core + diff --git a/scripts/appveyor/clear_project_configuration.ps1 b/scripts/appveyor/clear_project_configuration.ps1 new file mode 100644 index 00000000..04be8f36 --- /dev/null +++ b/scripts/appveyor/clear_project_configuration.ps1 @@ -0,0 +1,8 @@ +$replace = "EditAndContinue" +$replaceTo = "None" + +Get-ChildItem -Path 'projects\' *.vcxproj | ForEach-Object { + $filePath = 'projects\' + $_ + Copy-Item -Path $filePath -Destination ($filePath + '.template') + Get-Content ($filePath + '.template') | ForEach-Object { $_ -replace $replace, $replaceTo } > $filePath +} diff --git a/src/kiwano-audio/src/Player.cpp b/src/kiwano-audio/src/Player.cpp index a7a862bf..5e696ec0 100644 --- a/src/kiwano-audio/src/Player.cpp +++ b/src/kiwano-audio/src/Player.cpp @@ -34,9 +34,9 @@ namespace kiwano ClearCache(); } - size_t Player::Load(String const& file_path) + UInt32 Player::Load(String const& file_path) { - size_t hash_code = file_path.hash(); + UInt32 hash_code = file_path.hash(); if (sound_cache_.end() != sound_cache_.find(hash_code)) return true; @@ -54,9 +54,9 @@ namespace kiwano return false; } - size_t Player::Load(Resource const& res) + UInt32 Player::Load(Resource const& res) { - size_t hash_code = res.GetId(); + UInt32 hash_code = res.GetId(); if (sound_cache_.end() != sound_cache_.find(hash_code)) return true; @@ -74,35 +74,35 @@ namespace kiwano return false; } - void Player::Play(size_t id, int loop_count) + void Player::Play(UInt32 id, Int32 loop_count) { auto iter = sound_cache_.find(id); if (sound_cache_.end() != iter) iter->second->Play(loop_count); } - void Player::Pause(size_t id) + void Player::Pause(UInt32 id) { auto iter = sound_cache_.find(id); if (sound_cache_.end() != iter) iter->second->Pause(); } - void Player::Resume(size_t id) + void Player::Resume(UInt32 id) { auto iter = sound_cache_.find(id); if (sound_cache_.end() != iter) iter->second->Resume(); } - void Player::Stop(size_t id) + void Player::Stop(UInt32 id) { auto iter = sound_cache_.find(id); if (sound_cache_.end() != iter) iter->second->Stop(); } - bool Player::IsPlaying(size_t id) + bool Player::IsPlaying(UInt32 id) { auto iter = sound_cache_.find(id); if (sound_cache_.end() != iter) @@ -110,12 +110,12 @@ namespace kiwano return false; } - float Player::GetVolume() const + Float32 Player::GetVolume() const { return volume_; } - void Player::SetVolume(float volume) + void Player::SetVolume(Float32 volume) { volume_ = std::min(std::max(volume, -224.f), 224.f); for (const auto& pair : sound_cache_) diff --git a/src/kiwano-audio/src/Player.h b/src/kiwano-audio/src/Player.h index 8ad90766..7e33e2d0 100644 --- a/src/kiwano-audio/src/Player.h +++ b/src/kiwano-audio/src/Player.h @@ -39,47 +39,47 @@ namespace kiwano ~Player(); // 加载本地音频文件, 返回该资源标识符 - size_t Load( + UInt32 Load( String const& file_path ); // 加载音乐资源, 返回该资源标识符 - size_t Load( + UInt32 Load( Resource const& res /* 音乐资源 */ ); // 播放音乐 void Play( - size_t id, /* 标识符 */ - int loop_count = 0 /* 播放循环次数 (-1 为循环播放) */ + UInt32 id, /* 标识符 */ + Int32 loop_count = 0 /* 播放循环次数 (-1 为循环播放) */ ); // 暂停音乐 void Pause( - size_t id /* 标识符 */ + UInt32 id /* 标识符 */ ); // 继续播放音乐 void Resume( - size_t id /* 标识符 */ + UInt32 id /* 标识符 */ ); // 停止音乐 void Stop( - size_t id /* 标识符 */ + UInt32 id /* 标识符 */ ); // 获取音乐播放状态 bool IsPlaying( - size_t id /* 标识符 */ + UInt32 id /* 标识符 */ ); // 获取音量 - float GetVolume() const; + Float32 GetVolume() const; // 设置音量 void SetVolume( - float volume /* 1.0 为原始音量 */ + Float32 volume /* 1.0 为原始音量 */ ); // 暂停所有音乐 @@ -95,9 +95,9 @@ namespace kiwano void ClearCache(); protected: - float volume_; + Float32 volume_; - using MusicMap = Map; + using MusicMap = Map; MusicMap sound_cache_; }; } diff --git a/src/kiwano-audio/src/Sound.cpp b/src/kiwano-audio/src/Sound.cpp index cf2c9c2e..04bc7920 100644 --- a/src/kiwano-audio/src/Sound.cpp +++ b/src/kiwano-audio/src/Sound.cpp @@ -121,7 +121,7 @@ namespace kiwano return true; } - void Sound::Play(int loop_count) + void Sound::Play(Int32 loop_count) { if (!opened_) { @@ -144,7 +144,7 @@ namespace kiwano buffer.pAudioData = wave_data_; buffer.Flags = XAUDIO2_END_OF_STREAM; buffer.AudioBytes = size_; - buffer.LoopCount = static_cast(loop_count); + buffer.LoopCount = static_cast(loop_count); HRESULT hr = voice_->SubmitSourceBuffer(&buffer); if (SUCCEEDED(hr)) @@ -221,7 +221,7 @@ namespace kiwano XAUDIO2_VOICE_STATE state; voice_->GetState(&state); - UINT32 buffers_queued = state.BuffersQueued; + UInt32 buffers_queued = state.BuffersQueued; if (buffers_queued && playing_) return true; @@ -229,16 +229,16 @@ namespace kiwano return false; } - float Sound::GetVolume() const + Float32 Sound::GetVolume() const { KGE_ASSERT(voice_ != nullptr && "IXAudio2SourceVoice* is NULL"); - float volume = 0.0f; + Float32 volume = 0.0f; voice_->GetVolume(&volume); return volume; } - void Sound::SetVolume(float volume) + void Sound::SetVolume(Float32 volume) { KGE_ASSERT(voice_ != nullptr && "IXAudio2SourceVoice* is NULL"); diff --git a/src/kiwano-audio/src/Sound.h b/src/kiwano-audio/src/Sound.h index d39f457f..bff2118c 100644 --- a/src/kiwano-audio/src/Sound.h +++ b/src/kiwano-audio/src/Sound.h @@ -59,7 +59,7 @@ namespace kiwano // 播放 void Play( - int loop_count = 0 /* 播放循环次数 (-1 为循环播放) */ + Int32 loop_count = 0 /* 播放循环次数 (-1 为循环播放) */ ); // 暂停 @@ -78,17 +78,17 @@ namespace kiwano bool IsPlaying() const; // 获取音量 - float GetVolume() const; + Float32 GetVolume() const; // 设置音量 void SetVolume( - float volume /* 1 为原始音量, 大于 1 为放大音量, 0 为最小音量 */ + Float32 volume /* 1 为原始音量, 大于 1 为放大音量, 0 为最小音量 */ ); protected: bool opened_; bool playing_; - UINT32 size_; + UInt32 size_; BYTE* wave_data_; IXAudio2SourceVoice* voice_; }; diff --git a/src/kiwano-audio/src/Transcoder.cpp b/src/kiwano-audio/src/Transcoder.cpp index 0e38305e..a07dca56 100644 --- a/src/kiwano-audio/src/Transcoder.cpp +++ b/src/kiwano-audio/src/Transcoder.cpp @@ -55,7 +55,7 @@ namespace kiwano return wave_format_; } - HRESULT Transcoder::LoadMediaFile(String const& file_path, BYTE** wave_data, UINT32* wave_data_size) + HRESULT Transcoder::LoadMediaFile(String const& file_path, BYTE** wave_data, UInt32* wave_data_size) { HRESULT hr = S_OK; @@ -75,7 +75,7 @@ namespace kiwano return hr; } - HRESULT Transcoder::LoadMediaResource(Resource const& res, BYTE** wave_data, UINT32* wave_data_size) + HRESULT Transcoder::LoadMediaResource(Resource const& res, BYTE** wave_data, UInt32* wave_data_size) { HRESULT hr = S_OK; @@ -88,7 +88,7 @@ namespace kiwano stream = kiwano::modules::Shlwapi::Get().SHCreateMemStream( static_cast(data.buffer), - static_cast(data.size) + static_cast(data.size) ); if (stream == nullptr) @@ -119,7 +119,7 @@ namespace kiwano return hr; } - HRESULT Transcoder::ReadSource(IMFSourceReader* reader, BYTE** wave_data, UINT32* wave_data_size) + HRESULT Transcoder::ReadSource(IMFSourceReader* reader, BYTE** wave_data, UInt32* wave_data_size) { HRESULT hr = S_OK; DWORD max_stream_size = 0; @@ -170,7 +170,7 @@ namespace kiwano // 获取 WAVEFORMAT 数据 if (SUCCEEDED(hr)) { - UINT32 size = 0; + UInt32 size = 0; hr = modules::MediaFoundation::Get().MFCreateWaveFormatExFromMFMediaType( uncompressed_type.get(), &wave_format_, diff --git a/src/kiwano-audio/src/Transcoder.h b/src/kiwano-audio/src/Transcoder.h index 3b96b498..9bc02cb4 100644 --- a/src/kiwano-audio/src/Transcoder.h +++ b/src/kiwano-audio/src/Transcoder.h @@ -40,19 +40,19 @@ namespace kiwano HRESULT LoadMediaFile( String const& file_path, BYTE** wave_data, - UINT32* wave_data_size + UInt32* wave_data_size ); HRESULT LoadMediaResource( Resource const& res, BYTE** wave_data, - UINT32* wave_data_size + UInt32* wave_data_size ); HRESULT ReadSource( IMFSourceReader* reader, BYTE** wave_data, - UINT32* wave_data_size + UInt32* wave_data_size ); private: diff --git a/src/kiwano-audio/src/audio-modules.h b/src/kiwano-audio/src/audio-modules.h index 689ba0dd..90c95773 100644 --- a/src/kiwano-audio/src/audio-modules.h +++ b/src/kiwano-audio/src/audio-modules.h @@ -37,7 +37,7 @@ namespace kiwano HMODULE xaudio2; // XAudio2 functions - typedef HRESULT(WINAPI* PFN_XAudio2Create)(IXAudio2**, UINT32, XAUDIO2_PROCESSOR); + typedef HRESULT(WINAPI* PFN_XAudio2Create)(IXAudio2**, UInt32, XAUDIO2_PROCESSOR); public: static inline XAudio2& Get() @@ -61,7 +61,7 @@ namespace kiwano typedef HRESULT(WINAPI* PFN_MFStartup)(ULONG, DWORD); typedef HRESULT(WINAPI* PFN_MFShutdown)(); typedef HRESULT(WINAPI* PFN_MFCreateMediaType)(IMFMediaType**); - typedef HRESULT(WINAPI* PFN_MFCreateWaveFormatExFromMFMediaType)(IMFMediaType*, WAVEFORMATEX**, UINT32*, UINT32); + typedef HRESULT(WINAPI* PFN_MFCreateWaveFormatExFromMFMediaType)(IMFMediaType*, WAVEFORMATEX**, UInt32*, UInt32); typedef HRESULT(WINAPI* PFN_MFCreateSourceReaderFromURL)(LPCWSTR, IMFAttributes*, IMFSourceReader**); typedef HRESULT(WINAPI* PFN_MFCreateSourceReaderFromByteStream)(IMFByteStream*, IMFAttributes*, IMFSourceReader**); typedef HRESULT(WINAPI* PFN_MFCreateMFByteStreamOnStream)(IStream*, IMFByteStream**); diff --git a/src/kiwano-imgui/src/ImGuiModule.cpp b/src/kiwano-imgui/src/ImGuiModule.cpp index cd8eca18..7a571cdd 100644 --- a/src/kiwano-imgui/src/ImGuiModule.cpp +++ b/src/kiwano-imgui/src/ImGuiModule.cpp @@ -119,7 +119,7 @@ namespace kiwano Render(); } - void ImGuiModule::HandleMessage(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) + void ImGuiModule::HandleMessage(HWND hwnd, UInt32 msg, WPARAM wparam, LPARAM lparam) { if (ImGui::GetCurrentContext() == NULL) return; @@ -132,7 +132,7 @@ namespace kiwano case WM_MBUTTONDOWN: case WM_MBUTTONDBLCLK: case WM_XBUTTONDOWN: case WM_XBUTTONDBLCLK: { - int button = 0; + Int32 button = 0; if (msg == WM_LBUTTONDOWN || msg == WM_LBUTTONDBLCLK) { button = 0; } if (msg == WM_RBUTTONDOWN || msg == WM_RBUTTONDBLCLK) { button = 1; } if (msg == WM_MBUTTONDOWN || msg == WM_MBUTTONDBLCLK) { button = 2; } @@ -148,7 +148,7 @@ namespace kiwano case WM_MBUTTONUP: case WM_XBUTTONUP: { - int button = 0; + Int32 button = 0; if (msg == WM_LBUTTONUP) { button = 0; } if (msg == WM_RBUTTONUP) { button = 1; } if (msg == WM_MBUTTONUP) { button = 2; } @@ -160,12 +160,12 @@ namespace kiwano } case WM_MOUSEWHEEL: { - io.MouseWheel += (float)GET_WHEEL_DELTA_WPARAM(wparam) / (float)WHEEL_DELTA; + io.MouseWheel += (Float32)GET_WHEEL_DELTA_WPARAM(wparam) / (Float32)WHEEL_DELTA; break; } case WM_MOUSEHWHEEL: { - io.MouseWheelH += (float)GET_WHEEL_DELTA_WPARAM(wparam) / (float)WHEEL_DELTA; + io.MouseWheelH += (Float32)GET_WHEEL_DELTA_WPARAM(wparam) / (Float32)WHEEL_DELTA; break; } case WM_KEYDOWN: @@ -185,7 +185,7 @@ namespace kiwano case WM_CHAR: { // You can also use ToAscii()+GetKeyboardState() to retrieve characters. - io.AddInputCharacter((unsigned int)wparam); + io.AddInputCharacter((UInt32)wparam); break; } case WM_SETCURSOR: @@ -198,7 +198,7 @@ namespace kiwano } case WM_DEVICECHANGE: { - if ((UINT)wparam == DBT_DEVNODES_CHANGED) + if ((UInt32)wparam == DBT_DEVNODES_CHANGED) want_update_has_gamepad_ = true; break; } @@ -233,7 +233,7 @@ namespace kiwano // Set OS mouse position if requested (rarely used, only when ImGuiConfigFlags_NavEnableSetMousePos is enabled by user) if (io.WantSetMousePos) { - POINT pos = { (int)io.MousePos.x, (int)io.MousePos.y }; + POINT pos = { (Int32)io.MousePos.x, (Int32)io.MousePos.y }; ::ClientToScreen(target_window_, &pos); ::SetCursorPos(pos.x, pos.y); } @@ -286,7 +286,7 @@ namespace kiwano io.BackendFlags |= ImGuiBackendFlags_HasGamepad; #define MAP_BUTTON(NAV_NO, BUTTON_ENUM) { io.NavInputs[NAV_NO] = (gamepad.wButtons & BUTTON_ENUM) ? 1.0f : 0.0f; } -#define MAP_ANALOG(NAV_NO, VALUE, V0, V1) { float vn = (float)(VALUE - V0) / (float)(V1 - V0); if (vn > 1.0f) vn = 1.0f; if (vn > 0.0f && io.NavInputs[NAV_NO] < vn) io.NavInputs[NAV_NO] = vn; } +#define MAP_ANALOG(NAV_NO, VALUE, V0, V1) { Float32 vn = (Float32)(VALUE - V0) / (Float32)(V1 - V0); if (vn > 1.0f) vn = 1.0f; if (vn > 0.0f && io.NavInputs[NAV_NO] < vn) io.NavInputs[NAV_NO] = vn; } MAP_BUTTON(ImGuiNavInput_Activate, XINPUT_GAMEPAD_A); // Cross / A MAP_BUTTON(ImGuiNavInput_Cancel, XINPUT_GAMEPAD_B); // Circle / B MAP_BUTTON(ImGuiNavInput_Menu, XINPUT_GAMEPAD_X); // Square / X diff --git a/src/kiwano-imgui/src/ImGuiModule.h b/src/kiwano-imgui/src/ImGuiModule.h index 553afc11..6883edcc 100644 --- a/src/kiwano-imgui/src/ImGuiModule.h +++ b/src/kiwano-imgui/src/ImGuiModule.h @@ -52,7 +52,7 @@ namespace kiwano void AfterRender() override; - void HandleMessage(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) override; + void HandleMessage(HWND hwnd, UInt32 msg, WPARAM wparam, LPARAM lparam) override; void UpdateMousePos(); diff --git a/src/kiwano-network/src/HttpClient.cpp b/src/kiwano-network/src/HttpClient.cpp index e175d539..97f2d66f 100644 --- a/src/kiwano-network/src/HttpClient.cpp +++ b/src/kiwano-network/src/HttpClient.cpp @@ -35,10 +35,10 @@ namespace using namespace kiwano; using namespace kiwano::network; - size_t write_data(void* buffer, size_t size, size_t nmemb, void* userp) + UInt32 write_data(void* buffer, UInt32 size, UInt32 nmemb, void* userp) { kiwano::string* recv_buffer = (kiwano::string*)userp; - size_t total = size * nmemb; + UInt32 total = size * nmemb; // add data to the end of recv_buffer // write data maybe called more than once in a single request @@ -49,7 +49,7 @@ namespace kiwano::string convert_to_utf8(kiwano::wstring const& str) { - std::wstring_convert> utf8_conv; + std::wstring_convert> utf8_conv; kiwano::string result; try @@ -66,7 +66,7 @@ namespace kiwano::wstring convert_from_utf8(kiwano::string const& str) { - kiwano::string_convert> utf8_conv; + kiwano::string_convert> utf8_conv; kiwano::wstring result; try @@ -256,7 +256,7 @@ namespace kiwano { ::curl_global_init(CURL_GLOBAL_ALL); - std::thread thread(bind_func(this, &HttpClient::NetworkThread)); + std::thread thread(Closure(this, &HttpClient::NetworkThread)); thread.detach(); } @@ -299,7 +299,7 @@ namespace kiwano response_queue_.push(response); response_mutex_.unlock(); - Application::PreformInMainThread(bind_func(this, &HttpClient::DispatchResponseCallback)); + Application::PreformInMainThread(Closure(this, &HttpClient::DispatchResponseCallback)); } } diff --git a/src/kiwano/2d/Actor.cpp b/src/kiwano/2d/Actor.cpp index 8ef488f5..15518e7a 100644 --- a/src/kiwano/2d/Actor.cpp +++ b/src/kiwano/2d/Actor.cpp @@ -27,11 +27,11 @@ namespace kiwano { namespace { - float default_anchor_x = 0.f; - float default_anchor_y = 0.f; + Float32 default_anchor_x = 0.f; + Float32 default_anchor_y = 0.f; } - void Actor::SetDefaultAnchor(float anchor_x, float anchor_y) + void Actor::SetDefaultAnchor(Float32 anchor_x, Float32 anchor_y) { default_anchor_x = anchor_x; default_anchor_y = anchor_y; @@ -314,7 +314,7 @@ namespace kiwano } } - void Actor::SetZOrder(int zorder) + void Actor::SetZOrder(Int32 zorder) { if (z_order_ != zorder) { @@ -323,7 +323,7 @@ namespace kiwano } } - void Actor::SetOpacity(float opacity) + void Actor::SetOpacity(Float32 opacity) { if (opacity_ == opacity) return; @@ -341,17 +341,17 @@ namespace kiwano UpdateOpacity(); } - void Actor::SetAnchorX(float anchor_x) + void Actor::SetAnchorX(Float32 anchor_x) { this->SetAnchor(anchor_x, anchor_.y); } - void Actor::SetAnchorY(float anchor_y) + void Actor::SetAnchorY(Float32 anchor_y) { this->SetAnchor(anchor_.x, anchor_y); } - void Actor::SetAnchor(float anchor_x, float anchor_y) + void Actor::SetAnchor(Float32 anchor_x, Float32 anchor_y) { if (anchor_.x == anchor_x && anchor_.y == anchor_y) return; @@ -366,12 +366,12 @@ namespace kiwano this->SetAnchor(anchor.x, anchor.y); } - void Actor::SetWidth(float width) + void Actor::SetWidth(Float32 width) { this->SetSize(width, size_.y); } - void Actor::SetHeight(float height) + void Actor::SetHeight(Float32 height) { this->SetSize(size_.x, height); } @@ -381,7 +381,7 @@ namespace kiwano this->SetSize(size.x, size.y); } - void Actor::SetSize(float width, float height) + void Actor::SetSize(Float32 width, Float32 height) { if (size_.x == width && size_.y == height) return; @@ -412,12 +412,12 @@ namespace kiwano } } - void Actor::SetPositionX(float x) + void Actor::SetPositionX(Float32 x) { this->SetPosition(x, transform_.position.y); } - void Actor::SetPositionY(float y) + void Actor::SetPositionY(Float32 y) { this->SetPosition(transform_.position.x, y); } @@ -427,7 +427,7 @@ namespace kiwano this->SetPosition(p.x, p.y); } - void Actor::SetPosition(float x, float y) + void Actor::SetPosition(Float32 x, Float32 y) { if (transform_.position.x == x && transform_.position.y == y) return; @@ -437,7 +437,7 @@ namespace kiwano dirty_transform_ = true; } - void Actor::Move(float x, float y) + void Actor::Move(Float32 x, Float32 y) { this->SetPosition(transform_.position.x + x, transform_.position.y + y); } @@ -447,22 +447,22 @@ namespace kiwano this->Move(v.x, v.y); } - void Actor::SetScaleX(float scale_x) + void Actor::SetScaleX(Float32 scale_x) { this->SetScale(scale_x, transform_.scale.y); } - void Actor::SetScaleY(float scale_y) + void Actor::SetScaleY(Float32 scale_y) { this->SetScale(transform_.scale.x, scale_y); } - void Actor::SetScale(float scale) + void Actor::SetScale(Float32 scale) { this->SetScale(scale, scale); } - void Actor::SetScale(float scale_x, float scale_y) + void Actor::SetScale(Float32 scale_x, Float32 scale_y) { if (transform_.scale.x == scale_x && transform_.scale.y == scale_y) return; @@ -478,17 +478,17 @@ namespace kiwano this->SetScale(scale.x, scale.y); } - void Actor::SetSkewX(float skew_x) + void Actor::SetSkewX(Float32 skew_x) { this->SetSkew(skew_x, transform_.skew.y); } - void Actor::SetSkewY(float skew_y) + void Actor::SetSkewY(Float32 skew_y) { this->SetSkew(transform_.skew.x, skew_y); } - void Actor::SetSkew(float skew_x, float skew_y) + void Actor::SetSkew(Float32 skew_x, Float32 skew_y) { if (transform_.skew.x == skew_x && transform_.skew.y == skew_y) return; @@ -504,7 +504,7 @@ namespace kiwano this->SetSkew(skew.x, skew.y); } - void Actor::SetRotation(float angle) + void Actor::SetRotation(Float32 angle) { if (transform_.rotation == angle) return; @@ -561,7 +561,7 @@ namespace kiwano Vector Actor::GetChildren(String const& name) const { Vector children; - size_t hash_code = std::hash{}(name); + UInt32 hash_code = std::hash{}(name); for (Actor* child = children_.first_item().get(); child; child = child->next_item().get()) { @@ -575,7 +575,7 @@ namespace kiwano ActorPtr Actor::GetChild(String const& name) const { - size_t hash_code = std::hash{}(name); + UInt32 hash_code = std::hash{}(name); for (Actor* child = children_.first_item().get(); child; child = child->next_item().get()) { @@ -627,7 +627,7 @@ namespace kiwano return; } - size_t hash_code = std::hash{}(child_name); + UInt32 hash_code = std::hash{}(child_name); Actor* next; for (Actor* child = children_.first_item().get(); child; child = next) diff --git a/src/kiwano/2d/Actor.h b/src/kiwano/2d/Actor.h index e8764689..ccad06d9 100644 --- a/src/kiwano/2d/Actor.h +++ b/src/kiwano/2d/Actor.h @@ -64,55 +64,55 @@ namespace kiwano bool IsCascadeOpacityEnabled() const { return cascade_opacity_; } // 获取名称的 Hash 值 - size_t GetHashName() const { return hash_name_; } + UInt32 GetHashName() const { return hash_name_; } // 获取 Z 轴顺序 - int GetZOrder() const { return z_order_; } + Int32 GetZOrder() const { return z_order_; } // 获取坐标 Point GetPosition() const { return transform_.position; } // 获取 x 坐标 - float GetPositionX() const { return transform_.position.x; } + Float32 GetPositionX() const { return transform_.position.x; } // 获取 y 坐标 - float GetPositionY() const { return transform_.position.y; } + Float32 GetPositionY() const { return transform_.position.y; } // 获取缩放比例 Point GetScale() const { return transform_.scale; } // 获取横向缩放比例 - float GetScaleX() const { return transform_.scale.x; } + Float32 GetScaleX() const { return transform_.scale.x; } // 获取纵向缩放比例 - float GetScaleY() const { return transform_.scale.y; } + Float32 GetScaleY() const { return transform_.scale.y; } // 获取错切角度 Point GetSkew() const { return transform_.skew; } // 获取横向错切角度 - float GetSkewX() const { return transform_.skew.x; } + Float32 GetSkewX() const { return transform_.skew.x; } // 获取纵向错切角度 - float GetSkewY() const { return transform_.skew.y; } + Float32 GetSkewY() const { return transform_.skew.y; } // 获取旋转角度 - float GetRotation() const { return transform_.rotation; } + Float32 GetRotation() const { return transform_.rotation; } // 获取宽度 - float GetWidth() const { return size_.x; } + Float32 GetWidth() const { return size_.x; } // 获取高度 - float GetHeight() const { return size_.y; } + Float32 GetHeight() const { return size_.y; } // 获取大小 Size GetSize() const { return size_; } // 获取缩放后的宽度 - float GetScaledWidth() const { return size_.x * transform_.scale.x; } + Float32 GetScaledWidth() const { return size_.x * transform_.scale.x; } // 获取缩放后的高度 - float GetScaledHeight() const { return size_.y * transform_.scale.y; } + Float32 GetScaledHeight() const { return size_.y * transform_.scale.y; } // 获取缩放后的大小 Size GetScaledSize() const { return Size{ GetScaledWidth(), GetScaledHeight() }; } @@ -121,16 +121,16 @@ namespace kiwano Point GetAnchor() const { return anchor_; } // 获取 x 方向锚点 - float GetAnchorX() const { return anchor_.x; } + Float32 GetAnchorX() const { return anchor_.x; } // 获取 y 方向锚点 - float GetAnchorY() const { return anchor_.y; } + Float32 GetAnchorY() const { return anchor_.y; } // 获取透明度 - float GetOpacity() const { return opacity_; } + Float32 GetOpacity() const { return opacity_; } // 获取显示透明度 - float GetDisplayedOpacity() const { return displayed_opacity_; } + Float32 GetDisplayedOpacity() const { return displayed_opacity_; } // 获取变换 Transform GetTransform() const { return transform_; } @@ -165,12 +165,12 @@ namespace kiwano // 设置横坐标 void SetPositionX( - float x + Float32 x ); // 设置纵坐标 void SetPositionY( - float y + Float32 y ); // 设置坐标 @@ -180,14 +180,14 @@ namespace kiwano // 设置坐标 void SetPosition( - float x, - float y + Float32 x, + Float32 y ); // 移动 void Move( - float x, - float y + Float32 x, + Float32 y ); // 移动 @@ -198,20 +198,20 @@ namespace kiwano // 设置横向缩放比例 // 默认为 1.0 void SetScaleX( - float scale_x + Float32 scale_x ); // 设置纵向缩放比例 // 默认为 1.0 void SetScaleY( - float scale_y + Float32 scale_y ); // 设置缩放比例 // 默认为 (1.0, 1.0) void SetScale( - float scale_x, - float scale_y + Float32 scale_x, + Float32 scale_y ); // 设置缩放比例 @@ -223,26 +223,26 @@ namespace kiwano // 设置缩放比例 // 默认为 1.0 void SetScale( - float scale + Float32 scale ); // 设置横向错切角度 // 默认为 0 void SetSkewX( - float skew_x + Float32 skew_x ); // 设置纵向错切角度 // 默认为 0 void SetSkewY( - float skew_y + Float32 skew_y ); // 设置错切角度 // 默认为 (0, 0) void SetSkew( - float skew_x, - float skew_y + Float32 skew_x, + Float32 skew_y ); // 设置错切角度 @@ -254,26 +254,26 @@ namespace kiwano // 设置旋转角度 // 默认为 0 void SetRotation( - float rotation + Float32 rotation ); // 设置锚点的横向位置 // 默认为 0, 范围 [0, 1] void SetAnchorX( - float anchor_x + Float32 anchor_x ); // 设置锚点的纵向位置 // 默认为 0, 范围 [0, 1] void SetAnchorY( - float anchor_y + Float32 anchor_y ); // 设置锚点位置 // 默认为 (0, 0), 范围 [0, 1] void SetAnchor( - float anchor_x, - float anchor_y + Float32 anchor_x, + Float32 anchor_y ); // 设置锚点位置 @@ -284,18 +284,18 @@ namespace kiwano // 修改宽度 void SetWidth( - float width + Float32 width ); // 修改高度 void SetHeight( - float height + Float32 height ); // 修改大小 void SetSize( - float width, - float height + Float32 width, + Float32 height ); // 修改大小 @@ -311,7 +311,7 @@ namespace kiwano // 设置透明度 // 默认为 1.0, 范围 [0, 1] void SetOpacity( - float opacity + Float32 opacity ); // 启用或禁用级联透明度 @@ -322,7 +322,7 @@ namespace kiwano // 设置 Z 轴顺序 // 默认为 0 void SetZOrder( - int zorder + Int32 zorder ); // 是否可响应 (鼠标 Hover | Out | Click 消息) @@ -403,8 +403,8 @@ namespace kiwano // 设置默认锚点 static void SetDefaultAnchor( - float anchor_x, - float anchor_y + Float32 anchor_x, + Float32 anchor_y ); protected: @@ -432,12 +432,12 @@ namespace kiwano bool update_pausing_; bool cascade_opacity_; bool show_border_; - int z_order_; - float opacity_; - float displayed_opacity_; + Int32 z_order_; + Float32 opacity_; + Float32 displayed_opacity_; Actor* parent_; Stage* stage_; - size_t hash_name_; + UInt32 hash_name_; Point anchor_; Size size_; Children children_; diff --git a/src/kiwano/2d/Canvas.cpp b/src/kiwano/2d/Canvas.cpp index cef8a6fb..0e2d506f 100644 --- a/src/kiwano/2d/Canvas.cpp +++ b/src/kiwano/2d/Canvas.cpp @@ -34,7 +34,7 @@ namespace kiwano Renderer::GetInstance()->CreateImageRenderTarget(rt_); } - Canvas::Canvas(float width, float height) + Canvas::Canvas(Float32 width, Float32 height) : Canvas() { this->SetSize(width, height); @@ -83,7 +83,7 @@ namespace kiwano fill_color_ = color; } - void Canvas::SetStrokeWidth(float width) + void Canvas::SetStrokeWidth(Float32 width) { stroke_width_ = std::max(width, 0.f); } @@ -103,7 +103,7 @@ namespace kiwano text_style_ = text_style; } - void Canvas::SetBrushOpacity(float opacity) + void Canvas::SetBrushOpacity(Float32 opacity) { rt_.SetOpacity(opacity); } @@ -118,12 +118,12 @@ namespace kiwano return fill_color_; } - float Canvas::GetStrokeWidth() const + Float32 Canvas::GetStrokeWidth() const { return stroke_width_; } - float Canvas::GetBrushOpacity() const + Float32 Canvas::GetBrushOpacity() const { return rt_.GetOpacity(); } @@ -156,7 +156,7 @@ namespace kiwano cache_expired_ = true; } - void Canvas::DrawCircle(Point const& center, float radius) + void Canvas::DrawCircle(Point const& center, Float32 radius) { rt_.DrawEllipse( center, @@ -203,7 +203,7 @@ namespace kiwano cache_expired_ = true; } - void Canvas::FillCircle(Point const& center, float radius) + void Canvas::FillCircle(Point const& center, Float32 radius) { rt_.FillEllipse( center, @@ -286,7 +286,7 @@ namespace kiwano geo_sink_.AddBezier(point1, point2, point3); } - void Canvas::AddArc(Point const & point, Point const & radius, float rotation, bool clockwise, bool is_small) + void Canvas::AddArc(Point const & point, Point const & radius, Float32 rotation, bool clockwise, bool is_small) { geo_sink_.AddArc(point, radius, rotation, clockwise, is_small); } diff --git a/src/kiwano/2d/Canvas.h b/src/kiwano/2d/Canvas.h index 6508ebd0..8b636ad0 100644 --- a/src/kiwano/2d/Canvas.h +++ b/src/kiwano/2d/Canvas.h @@ -40,8 +40,8 @@ namespace kiwano ); Canvas( - float width, - float height + Float32 width, + Float32 height ); virtual ~Canvas(); @@ -61,7 +61,7 @@ namespace kiwano // 画圆形边框 void DrawCircle( Point const& center, - float radius + Float32 radius ); // 画椭圆形边框 @@ -84,7 +84,7 @@ namespace kiwano // 填充圆形 void FillCircle( Point const& center, - float radius + Float32 radius ); // 填充椭圆形 @@ -148,7 +148,7 @@ namespace kiwano void AddArc( Point const& point, /* 终点 */ Point const& radius, /* 椭圆半径 */ - float rotation, /* 椭圆旋转角度 */ + Float32 rotation, /* 椭圆旋转角度 */ bool clockwise = true, /* 顺时针 or 逆时针 */ bool is_small = true /* 是否取小于 180° 的弧 */ ); @@ -179,7 +179,7 @@ namespace kiwano // 设置线条宽度 void SetStrokeWidth( - float width + Float32 width ); // 设置线条样式 @@ -199,7 +199,7 @@ namespace kiwano // 设置画笔透明度 void SetBrushOpacity( - float opacity + Float32 opacity ); // 获取填充颜色 @@ -209,10 +209,10 @@ namespace kiwano Color GetStrokeColor() const; // 获取线条宽度 - float GetStrokeWidth() const; + Float32 GetStrokeWidth() const; // 获取画笔透明度 - float GetBrushOpacity() const; + Float32 GetBrushOpacity() const; // 画笔二维变换 void SetBrushTransform( @@ -233,7 +233,7 @@ namespace kiwano void UpdateCache() const; protected: - float stroke_width_; + Float32 stroke_width_; Color fill_color_; Color stroke_color_; Font text_font_; diff --git a/src/kiwano/2d/Frame.h b/src/kiwano/2d/Frame.h index 9f13d4f0..bbe845d2 100644 --- a/src/kiwano/2d/Frame.h +++ b/src/kiwano/2d/Frame.h @@ -61,10 +61,10 @@ namespace kiwano ); // 获取宽度 - float GetWidth() const { return crop_rect_.size.x; } + Float32 GetWidth() const { return crop_rect_.size.x; } // 获取高度 - float GetHeight() const { return crop_rect_.size.y; } + Float32 GetHeight() const { return crop_rect_.size.y; } // 获取大小 Size GetSize() const { return crop_rect_.size; } diff --git a/src/kiwano/2d/FrameSequence.cpp b/src/kiwano/2d/FrameSequence.cpp index 4957e1f0..1546fd0a 100644 --- a/src/kiwano/2d/FrameSequence.cpp +++ b/src/kiwano/2d/FrameSequence.cpp @@ -59,7 +59,7 @@ namespace kiwano } } - FramePtr FrameSequence::GetFrame(size_t index) const + FramePtr FrameSequence::GetFrame(UInt32 index) const { KGE_ASSERT(index < frames_.size()); return frames_[index]; diff --git a/src/kiwano/2d/FrameSequence.h b/src/kiwano/2d/FrameSequence.h index 09c0ccde..582f32cd 100644 --- a/src/kiwano/2d/FrameSequence.h +++ b/src/kiwano/2d/FrameSequence.h @@ -47,7 +47,7 @@ namespace kiwano ); // 获取关键帧 - FramePtr GetFrame(size_t index) const; + FramePtr GetFrame(UInt32 index) const; // 获取关键帧 Vector const& GetFrames() const; diff --git a/src/kiwano/2d/GifSprite.cpp b/src/kiwano/2d/GifSprite.cpp index 08c9c471..66eb6fc4 100644 --- a/src/kiwano/2d/GifSprite.cpp +++ b/src/kiwano/2d/GifSprite.cpp @@ -73,8 +73,8 @@ namespace kiwano disposal_type_ = DisposalType::None; SetSize( - static_cast(image_.GetWidthInPixels()), - static_cast(image_.GetHeightInPixels()) + static_cast(image_.GetWidthInPixels()), + static_cast(image_.GetHeightInPixels()) ); if (!frame_rt_.IsValid()) diff --git a/src/kiwano/2d/GifSprite.h b/src/kiwano/2d/GifSprite.h index 6fec6a03..6a875591 100644 --- a/src/kiwano/2d/GifSprite.h +++ b/src/kiwano/2d/GifSprite.h @@ -32,7 +32,7 @@ namespace kiwano { public: using DisposalType = GifImage::DisposalType; - using LoopDoneCallback = Function; + using LoopDoneCallback = Function; using DoneCallback = Function; GifSprite(); @@ -62,7 +62,7 @@ namespace kiwano ); // 设置 GIF 动画循环次数 - inline void SetLoopCount(int loops) { total_loop_count_ = loops; } + inline void SetLoopCount(Int32 loops) { total_loop_count_ = loops; } // 设置 GIF 动画每次循环结束回调函数 inline void SetLoopDoneCallback(LoopDoneCallback const& cb) { loop_cb_ = cb; } @@ -100,9 +100,9 @@ namespace kiwano protected: bool animating_; - int total_loop_count_; - int loop_count_; - UINT next_index_; + Int32 total_loop_count_; + Int32 loop_count_; + UInt32 next_index_; Duration frame_delay_; Duration frame_elapsed_; DisposalType disposal_type_; diff --git a/src/kiwano/2d/Layer.cpp b/src/kiwano/2d/Layer.cpp index 2b709eac..a4218f99 100644 --- a/src/kiwano/2d/Layer.cpp +++ b/src/kiwano/2d/Layer.cpp @@ -29,7 +29,7 @@ namespace kiwano { SetSize(Renderer::GetInstance()->GetOutputSize()); - auto handler = bind_func(this, &Layer::HandleMessages); + auto handler = Closure(this, &Layer::HandleMessages); AddListener(Event::MouseBtnDown, handler); AddListener(Event::MouseBtnUp, handler); diff --git a/src/kiwano/2d/Layer.h b/src/kiwano/2d/Layer.h index 1b48a530..6bcdd43b 100644 --- a/src/kiwano/2d/Layer.h +++ b/src/kiwano/2d/Layer.h @@ -31,13 +31,13 @@ namespace kiwano virtual ~Layer(); - virtual void OnMouseButtonDown(int btn, Point const& p) {} - virtual void OnMouseButtonUp(int btn, Point const& p) {} + virtual void OnMouseButtonDown(Int32 btn, Point const& p) {} + virtual void OnMouseButtonUp(Int32 btn, Point const& p) {} virtual void OnMouseMoved(Point const& p) {} - virtual void OnMouseWheel(float wheel) {} + virtual void OnMouseWheel(Float32 wheel) {} - virtual void OnKeyDown(int key) {} - virtual void OnKeyUp(int key) {} + virtual void OnKeyDown(Int32 key) {} + virtual void OnKeyUp(Int32 key) {} virtual void OnChar(char c) {} // 吞没消息 diff --git a/src/kiwano/2d/ShapeActor.cpp b/src/kiwano/2d/ShapeActor.cpp index cd6963b3..dafeffd0 100644 --- a/src/kiwano/2d/ShapeActor.cpp +++ b/src/kiwano/2d/ShapeActor.cpp @@ -68,7 +68,7 @@ namespace kiwano stroke_color_ = color; } - void ShapeActor::SetStrokeWidth(float width) + void ShapeActor::SetStrokeWidth(Float32 width) { stroke_width_ = std::max(width, 0.f); } @@ -201,7 +201,7 @@ namespace kiwano { } - CircleActor::CircleActor(float radius) + CircleActor::CircleActor(Float32 radius) { SetRadius(radius); } @@ -210,7 +210,7 @@ namespace kiwano { } - void CircleActor::SetRadius(float radius) + void CircleActor::SetRadius(Float32 radius) { geo_ = Geometry::CreateCircle(Point{}, radius); @@ -287,7 +287,7 @@ namespace kiwano sink_.AddBezier(point1, point2, point3); } - void PathActor::AddArc(Point const& point, Size const& radius, float rotation, bool clockwise, bool is_small) + void PathActor::AddArc(Point const& point, Size const& radius, Float32 rotation, bool clockwise, bool is_small) { sink_.AddArc(point, radius, rotation, clockwise, is_small); } diff --git a/src/kiwano/2d/ShapeActor.h b/src/kiwano/2d/ShapeActor.h index 7ba2a3c4..d643914d 100644 --- a/src/kiwano/2d/ShapeActor.h +++ b/src/kiwano/2d/ShapeActor.h @@ -44,7 +44,7 @@ namespace kiwano Color GetStrokeColor() const { return stroke_color_; } // 获取线条宽度 - float GetStrokeWidth() const { return stroke_width_; } + Float32 GetStrokeWidth() const { return stroke_width_; } // 获取线条样式 StrokeStyle SetStrokeStyle() const { return stroke_style_; } @@ -67,7 +67,7 @@ namespace kiwano // 设置线条宽度 void SetStrokeWidth( - float width + Float32 width ); // 设置线条样式 @@ -86,7 +86,7 @@ namespace kiwano protected: Color fill_color_; Color stroke_color_; - float stroke_width_; + Float32 stroke_width_; StrokeStyle stroke_style_; Geometry geo_; }; @@ -183,17 +183,17 @@ namespace kiwano CircleActor(); CircleActor( - float radius + Float32 radius ); virtual ~CircleActor(); - inline float GetRadius() const { return radius_; } + inline Float32 GetRadius() const { return radius_; } - void SetRadius(float radius); + void SetRadius(Float32 radius); protected: - float radius_; + Float32 radius_; }; @@ -261,7 +261,7 @@ namespace kiwano void AddArc( Point const& point, /* 终点 */ Size const& radius, /* 椭圆半径 */ - float rotation, /* 椭圆旋转角度 */ + Float32 rotation, /* 椭圆旋转角度 */ bool clockwise = true, /* 顺时针 or 逆时针 */ bool is_small = true /* 是否取小于 180° 的弧 */ ); diff --git a/src/kiwano/2d/Text.cpp b/src/kiwano/2d/Text.cpp index dc460d0b..2a9c814d 100644 --- a/src/kiwano/2d/Text.cpp +++ b/src/kiwano/2d/Text.cpp @@ -68,6 +68,7 @@ namespace kiwano , style_(style) , text_(text) , layout_dirty_(true) + , format_dirty_(true) { } @@ -102,7 +103,7 @@ namespace kiwano } } - void Text::SetFontSize(float size) + void Text::SetFontSize(Float32 size) { if (font_.size != size) { @@ -111,7 +112,7 @@ namespace kiwano } } - void Text::SetFontWeight(unsigned int weight) + void Text::SetFontWeight(UInt32 weight) { if (font_.weight != weight) { @@ -134,7 +135,7 @@ namespace kiwano } } - void Text::SetWrapWidth(float wrap_width) + void Text::SetWrapWidth(Float32 wrap_width) { if (style_.wrap_width != wrap_width) { @@ -143,7 +144,7 @@ namespace kiwano } } - void Text::SetLineSpacing(float line_spacing) + void Text::SetLineSpacing(Float32 line_spacing) { if (style_.line_spacing != line_spacing) { @@ -189,7 +190,7 @@ namespace kiwano style_.outline_color = outline_color; } - void Text::SetOutlineWidth(float outline_width) + void Text::SetOutlineWidth(Float32 outline_width) { style_.outline_width = outline_width; } diff --git a/src/kiwano/2d/Text.h b/src/kiwano/2d/Text.h index 1877b711..ddc48b17 100644 --- a/src/kiwano/2d/Text.h +++ b/src/kiwano/2d/Text.h @@ -87,12 +87,12 @@ namespace kiwano // 设置字号(默认值为 18) void SetFontSize( - float size + Float32 size ); // 设置字体粗细值(默认值为 FontWeight::Normal) void SetFontWeight( - unsigned int weight + UInt32 weight ); // 设置文字颜色(默认值为 Color::White) @@ -107,12 +107,12 @@ namespace kiwano // 设置文本自动换行的宽度(默认为 0) void SetWrapWidth( - float wrap_width + Float32 wrap_width ); // 设置行间距(默认为 0) void SetLineSpacing( - float line_spacing + Float32 line_spacing ); // 设置对齐方式(默认为 TextAlign::Left) @@ -142,7 +142,7 @@ namespace kiwano // 设置描边线宽 void SetOutlineWidth( - float outline_width + Float32 outline_width ); // 设置描边线相交样式 diff --git a/src/kiwano/2d/TextStyle.hpp b/src/kiwano/2d/TextStyle.hpp index 1e5a299d..b11c4c61 100644 --- a/src/kiwano/2d/TextStyle.hpp +++ b/src/kiwano/2d/TextStyle.hpp @@ -37,13 +37,13 @@ namespace kiwano public: Color color; // 颜色 TextAlign alignment; // 对齐方式 - float wrap_width; // 自动换行宽度 - float line_spacing; // 行间距 + Float32 wrap_width; // 自动换行宽度 + Float32 line_spacing; // 行间距 bool underline; // 下划线 bool strikethrough; // 删除线 bool outline; // 显示描边 Color outline_color; // 描边颜色 - float outline_width; // 描边线宽 + Float32 outline_width; // 描边线宽 StrokeStyle outline_stroke; // 描边线相交样式 public: @@ -63,13 +63,13 @@ namespace kiwano TextStyle( Color color, TextAlign alignment = TextAlign::Left, - float wrap_width = 0.f, - float line_spacing = 0.f, + Float32 wrap_width = 0.f, + Float32 line_spacing = 0.f, bool underline = false, bool strikethrough = false, bool outline = true, Color outline_color = Color(Color::Black, 0.5), - float outline_width = 1.f, + Float32 outline_width = 1.f, StrokeStyle outline_stroke = StrokeStyle::Round ) : color(color) diff --git a/src/kiwano/2d/Transform.hpp b/src/kiwano/2d/Transform.hpp index db928c97..64c8824e 100644 --- a/src/kiwano/2d/Transform.hpp +++ b/src/kiwano/2d/Transform.hpp @@ -26,7 +26,7 @@ namespace kiwano class Transform { public: - float rotation; // 旋转 + Float32 rotation; // 旋转 Point position; // 坐标 Point scale; // 缩放 Point skew; // 错切角度 diff --git a/src/kiwano/2d/Transition.cpp b/src/kiwano/2d/Transition.cpp index 8fe41b9c..dfa6dd2f 100644 --- a/src/kiwano/2d/Transition.cpp +++ b/src/kiwano/2d/Transition.cpp @@ -235,9 +235,9 @@ namespace kiwano // MoveTransition //------------------------------------------------------- - MoveTransition::MoveTransition(Duration duration, Direction direction) + MoveTransition::MoveTransition(Duration duration, Type type) : Transition(duration) - , direction_(direction) + , type_(type) { } @@ -245,21 +245,21 @@ namespace kiwano { Transition::Init(prev, next); - switch (direction_) + switch (type_) { - case Direction::Up: + case Type::Up: pos_delta_ = Point(0, -window_size_.y); start_pos_ = Point(0, window_size_.y); break; - case Direction::Down: + case Type::Down: pos_delta_ = Point(0, window_size_.y); start_pos_ = Point(0, -window_size_.y); break; - case Direction::Left: + case Type::Left: pos_delta_ = Point(-window_size_.x, 0); start_pos_ = Point(window_size_.x, 0); break; - case Direction::Right: + case Type::Right: pos_delta_ = Point(window_size_.x, 0); start_pos_ = Point(-window_size_.x, 0); break; @@ -314,7 +314,7 @@ namespace kiwano // RotationTransition //------------------------------------------------------- - RotationTransition::RotationTransition(Duration duration, float rotation) + RotationTransition::RotationTransition(Duration duration, Float32 rotation) : Transition(duration) , rotation_(rotation) { diff --git a/src/kiwano/2d/Transition.h b/src/kiwano/2d/Transition.h index a70b89cd..af0a0fe9 100644 --- a/src/kiwano/2d/Transition.h +++ b/src/kiwano/2d/Transition.h @@ -58,7 +58,7 @@ namespace kiwano protected: bool done_; - float process_; + Float32 process_; Duration duration_; Duration delta_; Size window_size_; @@ -132,9 +132,17 @@ namespace kiwano : public Transition { public: + enum class Type : Int32 + { + Up, /* 上移 */ + Down, /* 下移 */ + Left, /* 左移 */ + Right /* 右移 */ + }; + explicit MoveTransition( - Duration moveDuration, /* 动画持续时长 */ - Direction direction /* 移动方向 */ + Duration duration, /* 动画持续时长 */ + Type type /* 移动方式 */ ); protected: @@ -148,9 +156,9 @@ namespace kiwano void Reset() override; protected: - Direction direction_; - Point pos_delta_; - Point start_pos_; + Type type_; + Point pos_delta_; + Point start_pos_; }; @@ -160,8 +168,8 @@ namespace kiwano { public: explicit RotationTransition( - Duration moveDuration, /* 动画持续时长 */ - float rotation = 360 /* 旋转度数 */ + Duration duration, /* 动画持续时长 */ + Float32 rotation = 360 /* 旋转度数 */ ); protected: @@ -175,6 +183,6 @@ namespace kiwano void Reset() override; protected: - float rotation_; + Float32 rotation_; }; } diff --git a/src/kiwano/2d/action/Action.h b/src/kiwano/2d/action/Action.h index ce7eb0c2..6becb2e3 100644 --- a/src/kiwano/2d/action/Action.h +++ b/src/kiwano/2d/action/Action.h @@ -62,7 +62,7 @@ namespace kiwano inline void SetDelay(Duration delay) { delay_ = delay; } // 设置循环次数 (-1 为永久循环) - inline void SetLoops(int loops) { loops_ = loops; } + inline void SetLoops(Int32 loops) { loops_ = loops; } // 动作结束时移除目标角色 inline void RemoveTargetWhenDone() { detach_target_ = true; } @@ -89,7 +89,7 @@ namespace kiwano inline bool IsRemoveable() const { return status_ == Status::Removeable; } - inline int GetLoops() const { return loops_; } + inline Int32 GetLoops() const { return loops_; } inline Duration GetDelay() const { return delay_; } @@ -114,8 +114,8 @@ namespace kiwano Status status_; bool running_; bool detach_target_; - int loops_; - int loops_done_; + Int32 loops_; + Int32 loops_done_; Duration delay_; Duration elapsed_; ActionCallback cb_done_; diff --git a/src/kiwano/2d/action/ActionHelper.h b/src/kiwano/2d/action/ActionHelper.h index c8d396f3..b44bfd41 100644 --- a/src/kiwano/2d/action/ActionHelper.h +++ b/src/kiwano/2d/action/ActionHelper.h @@ -30,7 +30,7 @@ namespace kiwano struct ActionHelper { // 设置循环次数 - inline ActionHelper& SetLoops(int loops) { base->SetLoops(loops); return (*this); } + inline ActionHelper& SetLoops(Int32 loops) { base->SetLoops(loops); return (*this); } // 设置动作延迟 inline ActionHelper& SetDelay(Duration delay) { base->SetDelay(delay); return (*this); } @@ -64,7 +64,7 @@ namespace kiwano inline TweenHelper& SetDuration(Duration dur) { base->SetDuration(dur); return (*this); } // 设置循环次数 - inline TweenHelper& SetLoops(int loops) { base->SetLoops(loops); return (*this); } + inline TweenHelper& SetLoops(Int32 loops) { base->SetLoops(loops); return (*this); } // 设置缓动函数 inline TweenHelper& SetEaseFunc(EaseFunc ease) { base->SetEaseFunc(ease); return (*this); } @@ -117,8 +117,8 @@ namespace kiwano JumpBy( Duration dur, Point const& pos, /* 目的坐标 */ - float height, /* 跳跃高度 */ - int jumps = 1) /* 跳跃次数 */ + Float32 height, /* 跳跃高度 */ + Int32 jumps = 1) /* 跳跃次数 */ { return TweenHelper(new kiwano::ActionJumpBy(dur, pos, height, jumps)); } @@ -127,38 +127,38 @@ namespace kiwano JumpTo( Duration dur, Point const& pos, /* 目的坐标 */ - float height, /* 跳跃高度 */ - int jumps = 1) /* 跳跃次数 */ + Float32 height, /* 跳跃高度 */ + Int32 jumps = 1) /* 跳跃次数 */ { return TweenHelper(new kiwano::ActionJumpTo(dur, pos, height, jumps)); } static inline TweenHelper - ScaleBy(Duration dur, float scale) + ScaleBy(Duration dur, Float32 scale) { return TweenHelper(new kiwano::ActionScaleBy(dur, scale)); } static inline TweenHelper - ScaleBy(Duration dur, float scale_x, float scale_y) + ScaleBy(Duration dur, Float32 scale_x, Float32 scale_y) { return TweenHelper(new kiwano::ActionScaleBy(dur, scale_x, scale_y)); } static inline TweenHelper - ScaleTo(Duration dur, float scale) + ScaleTo(Duration dur, Float32 scale) { return TweenHelper(new kiwano::ActionScaleTo(dur, scale)); } static inline TweenHelper - ScaleTo(Duration dur, float scale_x, float scale_y) + ScaleTo(Duration dur, Float32 scale_x, Float32 scale_y) { return TweenHelper(new kiwano::ActionScaleTo(dur, scale_x, scale_y)); } static inline TweenHelper - FadeTo(Duration dur, float opacity) + FadeTo(Duration dur, Float32 opacity) { return TweenHelper(new kiwano::ActionFadeTo(dur, opacity)); } @@ -176,13 +176,13 @@ namespace kiwano } static inline TweenHelper - RotateBy(Duration dur, float rotation) + RotateBy(Duration dur, Float32 rotation) { return TweenHelper(new kiwano::ActionRotateBy(dur, rotation)); } static inline TweenHelper - RotateTo(Duration dur, float rotation) + RotateTo(Duration dur, Float32 rotation) { return TweenHelper(new kiwano::ActionRotateTo(dur, rotation)); } @@ -192,8 +192,8 @@ namespace kiwano Duration duration, /* 持续时长 */ Geometry const& geo, /* 路线 */ bool rotating = false, /* 沿路线切线方向旋转 */ - float start = 0.f, /* 起点 */ - float end = 1.f, /* 终点 */ + Float32 start = 0.f, /* 起点 */ + Float32 end = 1.f, /* 终点 */ EaseFunc func = nullptr /* 速度变化 */ ) { @@ -205,8 +205,8 @@ namespace kiwano Duration duration, /* 持续时长 */ GeometrySink& sink, /* 路线生成器 */ bool rotating = false, /* 沿路线切线方向旋转 */ - float start = 0.f, /* 起点 */ - float end = 1.f, /* 终点 */ + Float32 start = 0.f, /* 起点 */ + Float32 end = 1.f, /* 终点 */ EaseFunc func = nullptr /* 速度变化 */ ) { @@ -248,7 +248,7 @@ namespace kiwano KGE_DEPRECATED("Tween::OpacityBy has been removed, use Tween::FadeTo instead") static inline TweenHelper - OpacityBy(float opacity) + OpacityBy(Float32 opacity) { KGE_ASSERT("Tween::OpacityBy has been removed, use Tween::FadeTo instead"); return TweenHelper(nullptr); @@ -256,7 +256,7 @@ namespace kiwano KGE_DEPRECATED("Tween::OpacityTo is deprecated, use Tween::FadeTo instead") static inline TweenHelper - OpacityTo(Duration dur, float opacity) + OpacityTo(Duration dur, Float32 opacity) { return TweenHelper(new kiwano::ActionFadeTo(dur, opacity)); } diff --git a/src/kiwano/2d/action/ActionManager.cpp b/src/kiwano/2d/action/ActionManager.cpp index 2a0c5ac5..186c717f 100644 --- a/src/kiwano/2d/action/ActionManager.cpp +++ b/src/kiwano/2d/action/ActionManager.cpp @@ -42,7 +42,7 @@ namespace kiwano } } - ActionPtr ActionManager::AddAction(ActionPtr action) + Action* ActionManager::AddAction(ActionPtr action) { KGE_ASSERT(action && "AddAction failed, NULL pointer exception"); @@ -50,7 +50,7 @@ namespace kiwano { actions_.push_back_item(action); } - return action; + return action.get(); } ActionPtr ActionManager::GetAction(String const & name) diff --git a/src/kiwano/2d/action/ActionManager.h b/src/kiwano/2d/action/ActionManager.h index 27e3c092..36ea6b10 100644 --- a/src/kiwano/2d/action/ActionManager.h +++ b/src/kiwano/2d/action/ActionManager.h @@ -29,7 +29,7 @@ namespace kiwano public: // 添加动作 - ActionPtr AddAction( + Action* AddAction( ActionPtr action ); diff --git a/src/kiwano/2d/action/ActionTween.cpp b/src/kiwano/2d/action/ActionTween.cpp index b78c8720..360f507a 100644 --- a/src/kiwano/2d/action/ActionTween.cpp +++ b/src/kiwano/2d/action/ActionTween.cpp @@ -27,12 +27,12 @@ namespace kiwano // Ease Functions //------------------------------------------------------- - inline EaseFunc MakeEaseIn(float rate) { return std::bind(math::EaseIn, std::placeholders::_1, rate); } - inline EaseFunc MakeEaseOut(float rate) { return std::bind(math::EaseOut, std::placeholders::_1, rate); } - inline EaseFunc MakeEaseInOut(float rate) { return std::bind(math::EaseInOut, std::placeholders::_1, rate); } - inline EaseFunc MakeEaseElasticIn(float period) { return std::bind(math::EaseElasticIn, std::placeholders::_1, period); } - inline EaseFunc MakeEaseElasticOut(float period) { return std::bind(math::EaseElasticOut, std::placeholders::_1, period); } - inline EaseFunc MakeEaseElasticInOut(float period) { return std::bind(math::EaseElasticInOut, std::placeholders::_1, period); } + inline EaseFunc MakeEaseIn(Float32 rate) { return std::bind(math::EaseIn, std::placeholders::_1, rate); } + inline EaseFunc MakeEaseOut(Float32 rate) { return std::bind(math::EaseOut, std::placeholders::_1, rate); } + inline EaseFunc MakeEaseInOut(Float32 rate) { return std::bind(math::EaseInOut, std::placeholders::_1, rate); } + inline EaseFunc MakeEaseElasticIn(Float32 period) { return std::bind(math::EaseElasticIn, std::placeholders::_1, period); } + inline EaseFunc MakeEaseElasticOut(Float32 period) { return std::bind(math::EaseElasticOut, std::placeholders::_1, period); } + inline EaseFunc MakeEaseElasticInOut(Float32 period) { return std::bind(math::EaseElasticInOut, std::placeholders::_1, period); } KGE_API EaseFunc Ease::Linear = math::Linear; KGE_API EaseFunc Ease::EaseIn = MakeEaseIn(2.f); @@ -99,7 +99,7 @@ namespace kiwano void ActionTween::Update(ActorPtr target, Duration dt) { - float percent; + Float32 percent; if (dur_.IsZero()) { @@ -109,14 +109,14 @@ namespace kiwano else { Duration elapsed = elapsed_ - delay_; - float loops_done = elapsed / dur_; + Float32 loops_done = elapsed / dur_; - while (loops_done_ < static_cast(loops_done)) + while (loops_done_ < static_cast(loops_done)) { Complete(target); // loops_done_++ } - percent = (status_ == Status::Done) ? 1.f : (loops_done - static_cast(loops_done_)); + percent = (status_ == Status::Done) ? 1.f : (loops_done - static_cast(loops_done_)); } if (ease_func_) @@ -149,7 +149,7 @@ namespace kiwano } } - void ActionMoveBy::UpdateTween(ActorPtr target, float percent) + void ActionMoveBy::UpdateTween(ActorPtr target, Float32 percent) { Point diff = target->GetPosition() - prev_pos_; start_pos_ = start_pos_ + diff; @@ -192,7 +192,7 @@ namespace kiwano // Jump Action //------------------------------------------------------- - ActionJumpBy::ActionJumpBy(Duration duration, Point const& vec, float height, int jumps, EaseFunc func) + ActionJumpBy::ActionJumpBy(Duration duration, Point const& vec, Float32 height, Int32 jumps, EaseFunc func) : ActionTween(duration, func) , delta_pos_(vec) , height_(height) @@ -218,11 +218,11 @@ namespace kiwano } } - void ActionJumpBy::UpdateTween(ActorPtr target, float percent) + void ActionJumpBy::UpdateTween(ActorPtr target, Float32 percent) { - float frac = fmod(percent * jumps_, 1.f); - float x = delta_pos_.x * percent; - float y = height_ * 4 * frac * (1 - frac); + Float32 frac = fmod(percent * jumps_, 1.f); + Float32 x = delta_pos_.x * percent; + Float32 y = height_ * 4 * frac * (1 - frac); y += delta_pos_.y * percent; Point diff = target->GetPosition() - prev_pos_; @@ -234,7 +234,7 @@ namespace kiwano prev_pos_ = new_pos; } - ActionJumpTo::ActionJumpTo(Duration duration, Point const& pos, float height, int jumps, EaseFunc func) + ActionJumpTo::ActionJumpTo(Duration duration, Point const& pos, Float32 height, Int32 jumps, EaseFunc func) : ActionJumpBy(duration, Point(), height, jumps, func) , end_pos_(pos) { @@ -256,12 +256,12 @@ namespace kiwano // Scale Action //------------------------------------------------------- - ActionScaleBy::ActionScaleBy(Duration duration, float scale, EaseFunc func) + ActionScaleBy::ActionScaleBy(Duration duration, Float32 scale, EaseFunc func) : ActionScaleBy(duration, scale, scale, func) { } - ActionScaleBy::ActionScaleBy(Duration duration, float scale_x, float scale_y, EaseFunc func) + ActionScaleBy::ActionScaleBy(Duration duration, Float32 scale_x, Float32 scale_y, EaseFunc func) : ActionTween(duration, func) , delta_x_(scale_x) , delta_y_(scale_y) @@ -279,7 +279,7 @@ namespace kiwano } } - void ActionScaleBy::UpdateTween(ActorPtr target, float percent) + void ActionScaleBy::UpdateTween(ActorPtr target, Float32 percent) { target->SetScale(start_scale_x_ + delta_x_ * percent, start_scale_y_ + delta_y_ * percent); } @@ -294,14 +294,14 @@ namespace kiwano return new (std::nothrow) ActionScaleBy(dur_, -delta_x_, -delta_y_, ease_func_); } - ActionScaleTo::ActionScaleTo(Duration duration, float scale, EaseFunc func) + ActionScaleTo::ActionScaleTo(Duration duration, Float32 scale, EaseFunc func) : ActionScaleBy(duration, 0, 0, func) { end_scale_x_ = scale; end_scale_y_ = scale; } - ActionScaleTo::ActionScaleTo(Duration duration, float scale_x, float scale_y, EaseFunc func) + ActionScaleTo::ActionScaleTo(Duration duration, Float32 scale_x, Float32 scale_y, EaseFunc func) : ActionScaleBy(duration, 0, 0, func) { end_scale_x_ = scale_x; @@ -325,7 +325,7 @@ namespace kiwano // Opacity Action //------------------------------------------------------- - ActionFadeTo::ActionFadeTo(Duration duration, float opacity, EaseFunc func) + ActionFadeTo::ActionFadeTo(Duration duration, Float32 opacity, EaseFunc func) : ActionTween(duration, func) , delta_val_(0.f) , start_val_(0.f) @@ -342,7 +342,7 @@ namespace kiwano } } - void ActionFadeTo::UpdateTween(ActorPtr target, float percent) + void ActionFadeTo::UpdateTween(ActorPtr target, Float32 percent) { target->SetOpacity(start_val_ + delta_val_ * percent); } @@ -367,7 +367,7 @@ namespace kiwano // Rotate Action //------------------------------------------------------- - ActionRotateBy::ActionRotateBy(Duration duration, float rotation, EaseFunc func) + ActionRotateBy::ActionRotateBy(Duration duration, Float32 rotation, EaseFunc func) : ActionTween(duration, func) , start_val_() , delta_val_(rotation) @@ -382,9 +382,9 @@ namespace kiwano } } - void ActionRotateBy::UpdateTween(ActorPtr target, float percent) + void ActionRotateBy::UpdateTween(ActorPtr target, Float32 percent) { - float rotation = start_val_ + delta_val_ * percent; + Float32 rotation = start_val_ + delta_val_ * percent; if (rotation > 360.f) rotation -= 360.f; @@ -401,7 +401,7 @@ namespace kiwano return new (std::nothrow) ActionRotateBy(dur_, -delta_val_, ease_func_); } - ActionRotateTo::ActionRotateTo(Duration duration, float rotation, EaseFunc func) + ActionRotateTo::ActionRotateTo(Duration duration, Float32 rotation, EaseFunc func) : ActionRotateBy(duration, 0, func) { end_val_ = rotation; @@ -440,7 +440,7 @@ namespace kiwano this->Done(); } - void ActionCustom::UpdateTween(ActorPtr target, float percent) + void ActionCustom::UpdateTween(ActorPtr target, Float32 percent) { if (tween_func_) tween_func_(target, percent); diff --git a/src/kiwano/2d/action/ActionTween.h b/src/kiwano/2d/action/ActionTween.h index bb4d3b56..4b52f091 100644 --- a/src/kiwano/2d/action/ActionTween.h +++ b/src/kiwano/2d/action/ActionTween.h @@ -25,7 +25,7 @@ namespace kiwano { // 缓动函数 - using EaseFunc = Function; + using EaseFunc = Function; // 缓动函数枚举 // See https://easings.net for more information @@ -91,7 +91,7 @@ namespace kiwano protected: void Update(ActorPtr target, Duration dt) override; - virtual void UpdateTween(ActorPtr target, float percent) = 0; + virtual void UpdateTween(ActorPtr target, Float32 percent) = 0; protected: Duration dur_; @@ -119,7 +119,7 @@ namespace kiwano protected: void Init(ActorPtr target) override; - void UpdateTween(ActorPtr target, float percent) override; + void UpdateTween(ActorPtr target, Float32 percent) override; protected: Point start_pos_; @@ -165,8 +165,8 @@ namespace kiwano ActionJumpBy( Duration duration, /* 持续时长 */ Point const& vec, /* 跳跃距离 */ - float height, /* 跳跃高度 */ - int jumps = 1, /* 跳跃次数 */ + Float32 height, /* 跳跃高度 */ + Int32 jumps = 1, /* 跳跃次数 */ EaseFunc func = nullptr /* 速度变化 */ ); @@ -179,13 +179,13 @@ namespace kiwano protected: void Init(ActorPtr target) override; - void UpdateTween(ActorPtr target, float percent) override; + void UpdateTween(ActorPtr target, Float32 percent) override; protected: Point start_pos_; Point delta_pos_; - float height_; - int jumps_; + Float32 height_; + Int32 jumps_; Point prev_pos_; }; @@ -198,8 +198,8 @@ namespace kiwano ActionJumpTo( Duration duration, /* 持续时长 */ Point const& pos, /* 目的坐标 */ - float height, /* 跳跃高度 */ - int jumps = 1, /* 跳跃次数 */ + Float32 height, /* 跳跃高度 */ + Int32 jumps = 1, /* 跳跃次数 */ EaseFunc func = nullptr /* 速度变化 */ ); @@ -228,14 +228,14 @@ namespace kiwano public: ActionScaleBy( Duration duration, /* 持续时长 */ - float scale, /* 相对变化值 */ + Float32 scale, /* 相对变化值 */ EaseFunc func = nullptr /* 速度变化 */ ); ActionScaleBy( Duration duration, /* 持续时长 */ - float scale_x, /* 横向缩放相对变化值 */ - float scale_y, /* 纵向缩放相对变化值 */ + Float32 scale_x, /* 横向缩放相对变化值 */ + Float32 scale_y, /* 纵向缩放相对变化值 */ EaseFunc func = nullptr /* 速度变化 */ ); @@ -248,13 +248,13 @@ namespace kiwano protected: void Init(ActorPtr target) override; - void UpdateTween(ActorPtr target, float percent) override; + void UpdateTween(ActorPtr target, Float32 percent) override; protected: - float start_scale_x_; - float start_scale_y_; - float delta_x_; - float delta_y_; + Float32 start_scale_x_; + Float32 start_scale_y_; + Float32 delta_x_; + Float32 delta_y_; }; @@ -265,14 +265,14 @@ namespace kiwano public: ActionScaleTo( Duration duration, /* 持续时长 */ - float scale, /* 目标值 */ + Float32 scale, /* 目标值 */ EaseFunc func = nullptr /* 速度变化 */ ); ActionScaleTo( Duration duration, /* 持续时长 */ - float scale_x, /* 横向缩放目标值 */ - float scale_y, /* 纵向缩放目标值 */ + Float32 scale_x, /* 横向缩放目标值 */ + Float32 scale_y, /* 纵向缩放目标值 */ EaseFunc func = nullptr /* 速度变化 */ ); @@ -290,8 +290,8 @@ namespace kiwano void Init(ActorPtr target) override; protected: - float end_scale_x_; - float end_scale_y_; + Float32 end_scale_x_; + Float32 end_scale_y_; }; @@ -302,7 +302,7 @@ namespace kiwano public: ActionFadeTo( Duration duration, /* 持续时长 */ - float opacity, /* 目标值 */ + Float32 opacity, /* 目标值 */ EaseFunc func = nullptr /* 速度变化 */ ); @@ -319,12 +319,12 @@ namespace kiwano protected: void Init(ActorPtr target) override; - void UpdateTween(ActorPtr target, float percent) override; + void UpdateTween(ActorPtr target, Float32 percent) override; protected: - float start_val_; - float delta_val_; - float end_val_; + Float32 start_val_; + Float32 delta_val_; + Float32 end_val_; }; @@ -361,7 +361,7 @@ namespace kiwano public: ActionRotateBy( Duration duration, /* 持续时长 */ - float rotation, /* 相对变化值 */ + Float32 rotation, /* 相对变化值 */ EaseFunc func = nullptr /* 速度变化 */ ); @@ -374,11 +374,11 @@ namespace kiwano protected: void Init(ActorPtr target) override; - void UpdateTween(ActorPtr target, float percent) override; + void UpdateTween(ActorPtr target, Float32 percent) override; protected: - float start_val_; - float delta_val_; + Float32 start_val_; + Float32 delta_val_; }; @@ -389,7 +389,7 @@ namespace kiwano public: ActionRotateTo( Duration duration, /* 持续时长 */ - float rotation, /* 目标值 */ + Float32 rotation, /* 目标值 */ EaseFunc func = nullptr /* 速度变化 */ ); @@ -407,7 +407,7 @@ namespace kiwano void Init(ActorPtr target) override; protected: - float end_val_; + Float32 end_val_; }; @@ -416,7 +416,7 @@ namespace kiwano : public ActionTween { public: - using TweenFunc = Function; + using TweenFunc = Function; ActionCustom( Duration duration, /* 持续时长 */ @@ -437,7 +437,7 @@ namespace kiwano protected: void Init(ActorPtr target) override; - void UpdateTween(ActorPtr target, float percent) override; + void UpdateTween(ActorPtr target, Float32 percent) override; protected: TweenFunc tween_func_; diff --git a/src/kiwano/2d/action/ActionWalk.cpp b/src/kiwano/2d/action/ActionWalk.cpp index 3a4c77aa..c6153ce5 100644 --- a/src/kiwano/2d/action/ActionWalk.cpp +++ b/src/kiwano/2d/action/ActionWalk.cpp @@ -23,7 +23,7 @@ namespace kiwano { - ActionWalk::ActionWalk(Duration duration, bool rotating, float start, float end, EaseFunc func) + ActionWalk::ActionWalk(Duration duration, bool rotating, Float32 start, Float32 end, EaseFunc func) : ActionTween(duration, func) , start_(start) , end_(end) @@ -32,7 +32,7 @@ namespace kiwano { } - ActionWalk::ActionWalk(Duration duration, Geometry const& path, bool rotating, float start, float end, EaseFunc func) + ActionWalk::ActionWalk(Duration duration, Geometry const& path, bool rotating, Float32 start, Float32 end, EaseFunc func) : ActionWalk(duration, rotating, start, end, func) { path_ = path; @@ -70,9 +70,9 @@ namespace kiwano length_ = path_.GetLength(); } - void ActionWalk::UpdateTween(ActorPtr target, float percent) + void ActionWalk::UpdateTween(ActorPtr target, Float32 percent) { - float distance = length_ * std::min(std::max((end_ - start_) * percent + start_, 0.f), 1.f); + Float32 distance = length_ * std::min(std::max((end_ - start_) * percent + start_, 0.f), 1.f); Point point, tangent; if (path_.ComputePointAtLength(distance, point, tangent)) @@ -81,8 +81,8 @@ namespace kiwano if (rotating_) { - float ac = math::Acos(tangent.x); - float rotation = (tangent.y < 0.f) ? 360.f - ac : ac; + Float32 ac = math::Acos(tangent.x); + Float32 rotation = (tangent.y < 0.f) ? 360.f - ac : ac; target->SetRotation(rotation); } } @@ -114,7 +114,7 @@ namespace kiwano sink_.AddBezier(point1, point2, point3); } - void ActionWalk::AddArc(Point const& point, Size const& radius, float rotation, bool clockwise, bool is_small) + void ActionWalk::AddArc(Point const& point, Size const& radius, Float32 rotation, bool clockwise, bool is_small) { sink_.AddArc(point, radius, rotation, clockwise, is_small); } diff --git a/src/kiwano/2d/action/ActionWalk.h b/src/kiwano/2d/action/ActionWalk.h index f9747556..9d05c893 100644 --- a/src/kiwano/2d/action/ActionWalk.h +++ b/src/kiwano/2d/action/ActionWalk.h @@ -32,8 +32,8 @@ namespace kiwano ActionWalk( Duration duration, /* 持续时长 */ bool rotating = false, /* 沿路线切线方向旋转 */ - float start = 0.f, /* 起点 */ - float end = 1.f, /* 终点 */ + Float32 start = 0.f, /* 起点 */ + Float32 end = 1.f, /* 终点 */ EaseFunc func = nullptr /* 速度变化 */ ); @@ -41,8 +41,8 @@ namespace kiwano Duration duration, /* 持续时长 */ Geometry const& path, /* 路线 */ bool rotating = false, /* 沿路线切线方向旋转 */ - float start = 0.f, /* 起点 */ - float end = 1.f, /* 终点 */ + Float32 start = 0.f, /* 起点 */ + Float32 end = 1.f, /* 终点 */ EaseFunc func = nullptr /* 速度变化 */ ); @@ -81,7 +81,7 @@ namespace kiwano void AddArc( Point const& point, /* 终点 */ Size const& radius, /* 椭圆半径 */ - float rotation, /* 椭圆旋转角度 */ + Float32 rotation, /* 椭圆旋转角度 */ bool clockwise = true, /* 顺时针 or 逆时针 */ bool is_small = true /* 是否取小于 180° 的弧 */ ); @@ -98,13 +98,13 @@ namespace kiwano protected: void Init(ActorPtr target) override; - void UpdateTween(ActorPtr target, float percent) override; + void UpdateTween(ActorPtr target, Float32 percent) override; protected: bool rotating_; - float start_; - float end_; - float length_; + Float32 start_; + Float32 end_; + Float32 length_; Point start_pos_; Geometry path_; GeometrySink sink_; diff --git a/src/kiwano/2d/action/Animation.cpp b/src/kiwano/2d/action/Animation.cpp index 60c68f50..12869a4b 100644 --- a/src/kiwano/2d/action/Animation.cpp +++ b/src/kiwano/2d/action/Animation.cpp @@ -65,7 +65,7 @@ namespace kiwano } } - void Animation::UpdateTween(ActorPtr target, float percent) + void Animation::UpdateTween(ActorPtr target, Float32 percent) { auto sprite_target = dynamic_cast(target.get()); @@ -73,7 +73,7 @@ namespace kiwano const auto& frames = frame_seq_->GetFrames(); auto size = frames.size(); - auto index = std::min(static_cast(math::Floor(size * percent)), size - 1); + auto index = std::min(static_cast(math::Floor(size * percent)), size - 1); sprite_target->SetFrame(frames[index]); } diff --git a/src/kiwano/2d/action/Animation.h b/src/kiwano/2d/action/Animation.h index 09bab568..6b3f2048 100644 --- a/src/kiwano/2d/action/Animation.h +++ b/src/kiwano/2d/action/Animation.h @@ -55,7 +55,7 @@ namespace kiwano protected: void Init(ActorPtr target) override; - void UpdateTween(ActorPtr target, float percent) override; + void UpdateTween(ActorPtr target, Float32 percent) override; protected: FrameSequencePtr frame_seq_; diff --git a/src/kiwano/base/AsyncTask.cpp b/src/kiwano/base/AsyncTask.cpp index 66d94f6e..9235235c 100644 --- a/src/kiwano/base/AsyncTask.cpp +++ b/src/kiwano/base/AsyncTask.cpp @@ -24,7 +24,7 @@ namespace kiwano { AsyncTask::AsyncTask() - : thread_(bind_func(this, &AsyncTask::TaskThread)) + : thread_(Closure(this, &AsyncTask::TaskThread)) { } @@ -74,7 +74,7 @@ namespace kiwano func_mutex_.unlock(); } - Application::PreformInMainThread(bind_func(this, &AsyncTask::Complete)); + Application::PreformInMainThread(Closure(this, &AsyncTask::Complete)); } void AsyncTask::Complete() diff --git a/src/kiwano/base/Component.h b/src/kiwano/base/Component.h index 0628e93e..f68116a2 100644 --- a/src/kiwano/base/Component.h +++ b/src/kiwano/base/Component.h @@ -42,6 +42,6 @@ namespace kiwano virtual void AfterRender() {} virtual void HandleEvent(Event&) {} - virtual void HandleMessage(HWND, UINT, WPARAM, LPARAM) {} + virtual void HandleMessage(HWND, UInt32, WPARAM, LPARAM) {} }; } diff --git a/src/kiwano/base/Event.hpp b/src/kiwano/base/Event.hpp index 36dc8b9f..88eb4d4b 100644 --- a/src/kiwano/base/Event.hpp +++ b/src/kiwano/base/Event.hpp @@ -27,8 +27,8 @@ namespace kiwano // 鼠标事件 struct MouseEvent { - float x; - float y; + Float32 x; + Float32 y; bool left_btn_down; // 左键是否按下 bool right_btn_down; // 右键是否按下 @@ -36,27 +36,27 @@ namespace kiwano { struct // Events::MouseDown | Events::MouseUp | Events::MouseClick { - int button; + Int32 button; }; struct // Events::MouseWheel { - float wheel; + Float32 wheel; }; }; - static bool Check(UINT type); + static bool Check(UInt32 type); }; // 键盘事件 struct KeyboardEvent { - int count; + Int32 count; union { struct // Events::KeyDown | Events::KeyUp { - int code; // enum KeyCode + Int32 code; // enum KeyCode }; struct // Events::Char @@ -65,7 +65,7 @@ namespace kiwano }; }; - static bool Check(UINT type); + static bool Check(UInt32 type); }; // 窗口事件 @@ -75,14 +75,14 @@ namespace kiwano { struct // Events::WindowMoved { - int x; - int y; + Int32 x; + Int32 y; }; struct // Events::WindowResized { - int width; - int height; + Int32 width; + Int32 height; }; struct // Events::WindowFocusChanged @@ -92,11 +92,11 @@ namespace kiwano struct // Events::WindowTitleChanged { - const wchar_t* title; + const WChar* title; }; }; - static bool Check(UINT type); + static bool Check(UInt32 type); }; // 自定义事件 @@ -110,7 +110,7 @@ namespace kiwano // 事件 struct KGE_API Event { - enum Type : UINT + enum Type : UInt32 { First, @@ -144,7 +144,7 @@ namespace kiwano Last }; - UINT type; + UInt32 type; Actor* target; union @@ -155,23 +155,23 @@ namespace kiwano CustomEvent custom; }; - Event(UINT type = Type::First) : type(type), target(nullptr) {} + Event(UInt32 type = Type::First) : type(type), target(nullptr) {} }; // Check-functions - inline bool MouseEvent::Check(UINT type) + inline bool MouseEvent::Check(UInt32 type) { return type > Event::MouseFirst && type < Event::MouseLast; } - inline bool KeyboardEvent::Check(UINT type) + inline bool KeyboardEvent::Check(UInt32 type) { return type > Event::KeyFirst && type < Event::KeyLast; } - inline bool WindowEvent::Check(UINT type) + inline bool WindowEvent::Check(UInt32 type) { return type > Event::WindowFirst && type < Event::WindowLast; } diff --git a/src/kiwano/base/EventDispatcher.cpp b/src/kiwano/base/EventDispatcher.cpp index d46fbb3b..4626598c 100644 --- a/src/kiwano/base/EventDispatcher.cpp +++ b/src/kiwano/base/EventDispatcher.cpp @@ -51,7 +51,7 @@ namespace kiwano return listener; } - void EventDispatcher::AddListener(UINT type, EventCallback callback, String const& name) + void EventDispatcher::AddListener(UInt32 type, EventCallback callback, String const& name) { EventListenerPtr listener = new EventListener(type, callback, name); if (listener) @@ -96,7 +96,7 @@ namespace kiwano } } - void EventDispatcher::StartListeners(UINT type) + void EventDispatcher::StartListeners(UInt32 type) { for (auto listener = listeners_.first_item(); listener; listener = listener->next_item()) { @@ -107,7 +107,7 @@ namespace kiwano } } - void EventDispatcher::StopListeners(UINT type) + void EventDispatcher::StopListeners(UInt32 type) { for (auto listener = listeners_.first_item(); listener; listener = listener->next_item()) { @@ -118,7 +118,7 @@ namespace kiwano } } - void EventDispatcher::RemoveListeners(UINT type) + void EventDispatcher::RemoveListeners(UInt32 type) { EventListenerPtr next; for (auto listener = listeners_.first_item(); listener; listener = next) diff --git a/src/kiwano/base/EventDispatcher.h b/src/kiwano/base/EventDispatcher.h index a742421f..02581f8c 100644 --- a/src/kiwano/base/EventDispatcher.h +++ b/src/kiwano/base/EventDispatcher.h @@ -35,7 +35,7 @@ namespace kiwano // 添加监听器 void AddListener( - UINT type, + UInt32 type, EventCallback callback, String const& name = L"" ); @@ -57,17 +57,17 @@ namespace kiwano // 启动监听器 void StartListeners( - UINT type + UInt32 type ); // 停止监听器 void StopListeners( - UINT type + UInt32 type ); // 移除监听器 void RemoveListeners( - UINT type + UInt32 type ); virtual void Dispatch(Event& evt); diff --git a/src/kiwano/base/EventListener.cpp b/src/kiwano/base/EventListener.cpp index 1b5c1f81..336be7a5 100644 --- a/src/kiwano/base/EventListener.cpp +++ b/src/kiwano/base/EventListener.cpp @@ -23,7 +23,7 @@ namespace kiwano { - EventListener::EventListener(UINT type, EventCallback const & callback, String const & name) + EventListener::EventListener(UInt32 type, EventCallback const & callback, String const & name) : type_(type) , callback_(callback) , running_(true) diff --git a/src/kiwano/base/EventListener.h b/src/kiwano/base/EventListener.h index f07e83f3..8764eec3 100644 --- a/src/kiwano/base/EventListener.h +++ b/src/kiwano/base/EventListener.h @@ -42,7 +42,7 @@ namespace kiwano public: EventListener( - UINT type, + UInt32 type, EventCallback const& callback, String const& name = L"" ); @@ -57,7 +57,7 @@ namespace kiwano protected: bool running_; - UINT type_; + UInt32 type_; EventCallback callback_; }; } diff --git a/src/kiwano/base/Input.cpp b/src/kiwano/base/Input.cpp index 6d4f86af..e38dde26 100644 --- a/src/kiwano/base/Input.cpp +++ b/src/kiwano/base/Input.cpp @@ -38,7 +38,7 @@ namespace kiwano { } - void Input::UpdateKey(int key, bool down) + void Input::UpdateKey(Int32 key, bool down) { if (down && !keys_[key]) keys_pressed_[key] = true; @@ -50,7 +50,7 @@ namespace kiwano want_update_ = true; } - void Input::UpdateMousePos(float x, float y) + void Input::UpdateMousePos(Float32 x, Float32 y) { mouse_pos_x_ = x; mouse_pos_y_ = y; @@ -67,7 +67,7 @@ namespace kiwano } } - void Input::HandleMessage(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) + void Input::HandleMessage(HWND hwnd, UInt32 msg, WPARAM wparam, LPARAM lparam) { switch (msg) { @@ -86,7 +86,7 @@ namespace kiwano if (msg == WM_LBUTTONDOWN || msg == WM_LBUTTONUP) { UpdateKey(VK_LBUTTON, (msg == WM_LBUTTONDOWN) ? true : false); } else if (msg == WM_RBUTTONDOWN || msg == WM_RBUTTONUP) { UpdateKey(VK_RBUTTON, (msg == WM_RBUTTONDOWN) ? true : false); } else if (msg == WM_MBUTTONDOWN || msg == WM_MBUTTONUP) { UpdateKey(VK_MBUTTON, (msg == WM_MBUTTONDOWN) ? true : false); } - else if (msg == WM_MOUSEMOVE) { UpdateMousePos(static_cast(GET_X_LPARAM(lparam)), static_cast(GET_Y_LPARAM(lparam))); } + else if (msg == WM_MOUSEMOVE) { UpdateMousePos(static_cast(GET_X_LPARAM(lparam)), static_cast(GET_Y_LPARAM(lparam))); } break; } @@ -97,35 +97,41 @@ namespace kiwano case WM_SYSKEYUP: { bool down = msg == WM_KEYDOWN || msg == WM_SYSKEYDOWN; - UpdateKey((int)wparam, down); + UpdateKey((Int32)wparam, down); } } } - bool Input::IsDown(int key_or_btn) + bool Input::IsDown(Int32 key_or_btn) { KGE_ASSERT(key_or_btn >= 0 && key_or_btn < KEY_NUM); - return keys_[key_or_btn]; + if (key_or_btn >= 0 && key_or_btn < KEY_NUM) + return keys_[key_or_btn]; + return false; } - bool Input::WasPressed(int key_or_btn) + bool Input::WasPressed(Int32 key_or_btn) { KGE_ASSERT(key_or_btn >= 0 && key_or_btn < KEY_NUM); - return keys_pressed_[key_or_btn]; + if (key_or_btn >= 0 && key_or_btn < KEY_NUM) + return keys_pressed_[key_or_btn]; + return false; } - bool Input::WasReleased(int key_or_btn) + bool Input::WasReleased(Int32 key_or_btn) { KGE_ASSERT(key_or_btn >= 0 && key_or_btn < KEY_NUM); - return keys_released_[key_or_btn]; + if (key_or_btn >= 0 && key_or_btn < KEY_NUM) + return keys_released_[key_or_btn]; + return false; } - float Input::GetMouseX() + Float32 Input::GetMouseX() { return mouse_pos_x_; } - float Input::GetMouseY() + Float32 Input::GetMouseY() { return mouse_pos_y_; } @@ -134,4 +140,4 @@ namespace kiwano { return Point{ mouse_pos_x_, mouse_pos_y_ }; } -} \ No newline at end of file +} diff --git a/src/kiwano/base/Input.h b/src/kiwano/base/Input.h index 2cbc24bc..3ae61dbf 100644 --- a/src/kiwano/base/Input.h +++ b/src/kiwano/base/Input.h @@ -36,24 +36,24 @@ namespace kiwano public: // 检测键盘或鼠标按键是否正被按下 bool IsDown( - int key_or_btn + Int32 key_or_btn ); // 检测键盘或鼠标按键是否刚被点击 bool WasPressed( - int key_or_btn + Int32 key_or_btn ); // 检测键盘或鼠标按键是否刚抬起 bool WasReleased( - int key_or_btn + Int32 key_or_btn ); // 获得鼠标 x 坐标 - float GetMouseX(); + Float32 GetMouseX(); // 获得鼠标 y 坐标 - float GetMouseY(); + Float32 GetMouseY(); // 获得鼠标坐标 Point GetMousePos(); @@ -65,11 +65,11 @@ namespace kiwano void AfterUpdate() override; - void HandleMessage(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) override; + void HandleMessage(HWND hwnd, UInt32 msg, WPARAM wparam, LPARAM lparam) override; - void UpdateKey(int, bool); + void UpdateKey(Int32, bool); - void UpdateMousePos(float, float); + void UpdateMousePos(Float32, Float32); protected: Input(); @@ -77,13 +77,13 @@ namespace kiwano ~Input(); protected: - static const int KEY_NUM = 256; + static const Int32 KEY_NUM = 256; bool want_update_; bool keys_[KEY_NUM]; bool keys_pressed_[KEY_NUM]; bool keys_released_[KEY_NUM]; - float mouse_pos_x_; - float mouse_pos_y_; + Float32 mouse_pos_x_; + Float32 mouse_pos_y_; }; } diff --git a/src/kiwano/base/Logger.cpp b/src/kiwano/base/Logger.cpp index 7f72fc9e..02cb9fed 100644 --- a/src/kiwano/base/Logger.cpp +++ b/src/kiwano/base/Logger.cpp @@ -216,7 +216,7 @@ namespace kiwano return error_stream_.rdbuf(buf); } - void Logger::Printf(const wchar_t* format, ...) + void Logger::Printf(const WChar* format, ...) { va_list args = nullptr; va_start(args, format); @@ -226,7 +226,7 @@ namespace kiwano va_end(args); } - void Logger::Messagef(const wchar_t* format, ...) + void Logger::Messagef(const WChar* format, ...) { using namespace __console_colors; @@ -238,7 +238,7 @@ namespace kiwano va_end(args); } - void Logger::Warningf(const wchar_t* format, ...) + void Logger::Warningf(const WChar* format, ...) { using namespace __console_colors; @@ -250,7 +250,7 @@ namespace kiwano va_end(args); } - void Logger::Errorf(const wchar_t* format, ...) + void Logger::Errorf(const WChar* format, ...) { using namespace __console_colors; @@ -262,7 +262,7 @@ namespace kiwano va_end(args); } - void Logger::Outputf(std::wostream& os, std::wostream& (*color)(std::wostream&), const wchar_t* prompt, const wchar_t* format, va_list args) const + void Logger::Outputf(std::wostream& os, std::wostream& (*color)(std::wostream&), const WChar* prompt, const WChar* format, va_list args) const { if (enabled_) { @@ -275,9 +275,9 @@ namespace kiwano } } - std::wstring Logger::MakeOutputStringf(const wchar_t* prompt, const wchar_t* format, va_list args) const + std::wstring Logger::MakeOutputStringf(const WChar* prompt, const WChar* format, va_list args) const { - static wchar_t temp_buffer[1024 * 3 + 1]; + static WChar temp_buffer[1024 * 3 + 1]; std::wstringstream ss; ss << Logger::OutPrefix; diff --git a/src/kiwano/base/Logger.h b/src/kiwano/base/Logger.h index af05f629..b4934b97 100644 --- a/src/kiwano/base/Logger.h +++ b/src/kiwano/base/Logger.h @@ -66,13 +66,13 @@ namespace kiwano // 禁用 Logger void Disable(); - void Printf(const wchar_t* format, ...); + void Printf(const WChar* format, ...); - void Messagef(const wchar_t * format, ...); + void Messagef(const WChar * format, ...); - void Warningf(const wchar_t* format, ...); + void Warningf(const WChar* format, ...); - void Errorf(const wchar_t* format, ...); + void Errorf(const WChar* format, ...); template void Print(_Args&& ... args); @@ -109,18 +109,18 @@ namespace kiwano ~Logger(); - void Outputf(std::wostream& os, std::wostream&(*color)(std::wostream&), const wchar_t* prompt, const wchar_t* format, va_list args) const; + void Outputf(std::wostream& os, std::wostream&(*color)(std::wostream&), const WChar* prompt, const WChar* format, va_list args) const; - std::wstring MakeOutputStringf(const wchar_t* prompt, const wchar_t* format, va_list args) const; + std::wstring MakeOutputStringf(const WChar* prompt, const WChar* format, va_list args) const; template - void OutputLine(std::wostream& os, std::wostream& (*color)(std::wostream&), const wchar_t* prompt, _Args&& ... args) const; + void OutputLine(std::wostream& os, std::wostream& (*color)(std::wostream&), const WChar* prompt, _Args&& ... args) const; template - void Output(std::wostream& os, std::wostream& (*color)(std::wostream&), const wchar_t* prompt, _Args&& ... args) const; + void Output(std::wostream& os, std::wostream& (*color)(std::wostream&), const WChar* prompt, _Args&& ... args) const; template - std::wstring MakeOutputString(const wchar_t* prompt, _Args&& ... args) const; + std::wstring MakeOutputString(const WChar* prompt, _Args&& ... args) const; void ResetConsoleColor() const; @@ -235,7 +235,7 @@ namespace kiwano } template - void Logger::OutputLine(std::wostream& os, std::wostream& (*color)(std::wostream&), const wchar_t* prompt, _Args&& ... args) const + void Logger::OutputLine(std::wostream& os, std::wostream& (*color)(std::wostream&), const WChar* prompt, _Args&& ... args) const { if (enabled_) { @@ -247,7 +247,7 @@ namespace kiwano } template - void Logger::Output(std::wostream& os, std::wostream& (*color)(std::wostream&), const wchar_t* prompt, _Args&& ... args) const + void Logger::Output(std::wostream& os, std::wostream& (*color)(std::wostream&), const WChar* prompt, _Args&& ... args) const { if (enabled_) { @@ -261,7 +261,7 @@ namespace kiwano } template - std::wstring Logger::MakeOutputString(const wchar_t* prompt, _Args&& ... args) const + std::wstring Logger::MakeOutputString(const WChar* prompt, _Args&& ... args) const { std::wstringstream ss; ss << Logger::OutPrefix; @@ -269,7 +269,7 @@ namespace kiwano if (prompt) ss << prompt; - (void)std::initializer_list{((ss << ' ' << args), 0)...}; + (void)std::initializer_list{((ss << ' ' << args), 0)...}; return ss.str(); } diff --git a/src/kiwano/base/ObjectBase.cpp b/src/kiwano/base/ObjectBase.cpp index b3020125..28e1bb61 100644 --- a/src/kiwano/base/ObjectBase.cpp +++ b/src/kiwano/base/ObjectBase.cpp @@ -30,7 +30,7 @@ namespace kiwano Vector tracing_objects; } - unsigned int ObjectBase::last_object_id = 0; + UInt32 ObjectBase::last_object_id = 0; ObjectBase::ObjectBase() : tracing_leak_(false) diff --git a/src/kiwano/base/ObjectBase.h b/src/kiwano/base/ObjectBase.h index e527fbf3..3737d9d5 100644 --- a/src/kiwano/base/ObjectBase.h +++ b/src/kiwano/base/ObjectBase.h @@ -46,7 +46,7 @@ namespace kiwano inline bool IsName(String const& name) const { return name_ ? (*name_ == name) : name.empty(); } - inline unsigned int GetObjectID() const { return id_; } + inline UInt32 GetObjectID() const { return id_; } String DumpObject(); @@ -71,7 +71,7 @@ namespace kiwano void* user_data_; String* name_; - const unsigned int id_; - static unsigned int last_object_id; + const UInt32 id_; + static UInt32 last_object_id; }; } diff --git a/src/kiwano/base/Resource.cpp b/src/kiwano/base/Resource.cpp index 1ea7ee67..a6b2e336 100644 --- a/src/kiwano/base/Resource.cpp +++ b/src/kiwano/base/Resource.cpp @@ -31,7 +31,7 @@ namespace kiwano } - Resource::Resource(UINT id, LPCWSTR type) + Resource::Resource(UInt32 id, LPCWSTR type) : id_(id) , type_(type) { @@ -75,7 +75,7 @@ namespace kiwano } data_.buffer = static_cast(buffer); - data_.size = static_cast(size); + data_.size = static_cast(size); } while (0); return data_; diff --git a/src/kiwano/base/Resource.h b/src/kiwano/base/Resource.h index 32f990d3..0b5acb61 100644 --- a/src/kiwano/base/Resource.h +++ b/src/kiwano/base/Resource.h @@ -39,7 +39,7 @@ namespace kiwano struct Data { void* buffer; - UINT32 size; + UInt32 size; inline Data() : buffer(nullptr), size(0) {} @@ -49,19 +49,19 @@ namespace kiwano Resource(); Resource( - UINT id, /* 资源名称 */ + UInt32 id, /* 资源名称 */ LPCWSTR type /* 资源类型 */ ); // 获取二进制数据 Resource::Data GetData() const; - inline UINT GetId() const { return id_; } + inline UInt32 GetId() const { return id_; } inline LPCWSTR GetType() const { return type_; } private: - UINT id_; + UInt32 id_; LPCWSTR type_; mutable Resource::Data data_; }; diff --git a/src/kiwano/base/Timer.cpp b/src/kiwano/base/Timer.cpp index 1da92c81..cc34b2a9 100644 --- a/src/kiwano/base/Timer.cpp +++ b/src/kiwano/base/Timer.cpp @@ -27,7 +27,7 @@ namespace kiwano { } - Timer::Timer(Callback const& func, Duration delay, int times, String const& name) + Timer::Timer(Callback const& func, Duration delay, Int32 times, String const& name) : running_(true) , run_times_(0) , total_times_(times) diff --git a/src/kiwano/base/Timer.h b/src/kiwano/base/Timer.h index e82211dd..20d066af 100644 --- a/src/kiwano/base/Timer.h +++ b/src/kiwano/base/Timer.h @@ -48,7 +48,7 @@ namespace kiwano explicit Timer( Callback const& func, /* 执行函数 */ Duration delay, /* 时间间隔(秒) */ - int times = -1, /* 执行次数(设 -1 为永久执行) */ + Int32 times = -1, /* 执行次数(设 -1 为永久执行) */ String const& name = L"" /* 任务名称 */ ); @@ -68,8 +68,8 @@ namespace kiwano protected: bool running_; - int run_times_; - int total_times_; + Int32 run_times_; + Int32 total_times_; Duration delay_; Duration delta_; Callback callback_; diff --git a/src/kiwano/base/Window.cpp b/src/kiwano/base/Window.cpp index 00afa86c..c2027c29 100644 --- a/src/kiwano/base/Window.cpp +++ b/src/kiwano/base/Window.cpp @@ -31,9 +31,9 @@ namespace kiwano { MONITORINFOEX GetMoniterInfoEx(HWND hwnd); - void AdjustWindow(UINT width, UINT height, DWORD style, UINT* win_width, UINT* win_height); + void AdjustWindow(UInt32 width, UInt32 height, DWORD style, UInt32* win_width, UInt32* win_height); - void ChangeFullScreenResolution(int width, int height, WCHAR* device_name); + void ChangeFullScreenResolution(Int32 width, Int32 height, WCHAR* device_name); void RestoreResolution(WCHAR* device_name); } @@ -66,7 +66,7 @@ namespace kiwano } } - void Window::Init(String const& title, int width, int height, LPCWSTR icon, bool fullscreen, WNDPROC proc) + void Window::Init(String const& title, Int32 width, Int32 height, LPCWSTR icon, bool fullscreen, WNDPROC proc) { HINSTANCE hinst = GetModuleHandleW(nullptr); WNDCLASSEX wcex = { 0 }; @@ -99,12 +99,12 @@ namespace kiwano ::GetMonitorInfoW(monitor, &monitor_info_ex); // Save the device name - int len = lstrlenW(monitor_info_ex.szDevice); + Int32 len = lstrlenW(monitor_info_ex.szDevice); device_name_ = new WCHAR[len + 1]; lstrcpyW(device_name_, monitor_info_ex.szDevice); - int left = -1; - int top = -1; + Int32 left = -1; + Int32 top = -1; is_fullscreen_ = fullscreen; @@ -121,10 +121,10 @@ namespace kiwano } else { - UINT screenw = monitor_info_ex.rcWork.right - monitor_info_ex.rcWork.left; - UINT screenh = monitor_info_ex.rcWork.bottom - monitor_info_ex.rcWork.top; + UInt32 screenw = monitor_info_ex.rcWork.right - monitor_info_ex.rcWork.left; + UInt32 screenh = monitor_info_ex.rcWork.bottom - monitor_info_ex.rcWork.top; - UINT win_width, win_height; + UInt32 win_width, win_height; AdjustWindow( width, height, @@ -185,7 +185,7 @@ namespace kiwano { if (handle_) { - wchar_t title[256]; + WChar title[256]; ::GetWindowTextW(handle_, title, 256); return title; } @@ -201,19 +201,19 @@ namespace kiwano Size Window::GetSize() const { return Size{ - static_cast(width_), - static_cast(height_) + static_cast(width_), + static_cast(height_) }; } - float Window::GetWidth() const + Float32 Window::GetWidth() const { - return static_cast(width_); + return static_cast(width_); } - float Window::GetHeight() const + Float32 Window::GetHeight() const { - return static_cast(height_); + return static_cast(height_); } void Window::SetIcon(LPCWSTR icon_resource) @@ -235,11 +235,11 @@ namespace kiwano } } - void Window::Resize(int width, int height) + void Window::Resize(Int32 width, Int32 height) { if (handle_ && !is_fullscreen_) { - RECT rc = { 0, 0, int(width), int(height) }; + RECT rc = { 0, 0, Int32(width), Int32(height) }; ::AdjustWindowRect(&rc, GetWindowStyle(), false); width = rc.right - rc.left; @@ -248,7 +248,7 @@ namespace kiwano } } - void Window::SetFullscreen(bool fullscreen, int width, int height) + void Window::SetFullscreen(bool fullscreen, Int32 width, Int32 height) { if (is_fullscreen_ != fullscreen || width != width_ || height != height_) { @@ -275,14 +275,14 @@ namespace kiwano MONITORINFOEX info = GetMoniterInfoEx(handle_); - UINT screenw = info.rcWork.right - info.rcWork.left; - UINT screenh = info.rcWork.bottom - info.rcWork.top; + UInt32 screenw = info.rcWork.right - info.rcWork.left; + UInt32 screenh = info.rcWork.bottom - info.rcWork.top; - UINT win_width, win_height; + UInt32 win_width, win_height; AdjustWindow(width, height, GetWindowStyle(), &win_width, &win_height); - int left = screenw > win_width ? ((screenw - win_width) / 2) : 0; - int top = screenh > win_height ? ((screenh - win_height) / 2) : 0; + Int32 left = screenw > win_width ? ((screenw - win_width) / 2) : 0; + Int32 top = screenh > win_height ? ((screenh - win_height) / 2) : 0; ::SetWindowLongPtr(handle_, GWL_STYLE, GetWindowStyle()); ::SetWindowPos(handle_, HWND_NOTOPMOST, left, top, win_width, win_height, SWP_DRAWFRAME | SWP_FRAMECHANGED); @@ -376,10 +376,10 @@ namespace kiwano return monitor_info; } - void AdjustWindow(UINT width, UINT height, DWORD style, UINT* win_width, UINT* win_height) + void AdjustWindow(UInt32 width, UInt32 height, DWORD style, UInt32* win_width, UInt32* win_height) { RECT rc; - ::SetRect(&rc, 0, 0, (int)width, (int)height); + ::SetRect(&rc, 0, 0, (Int32)width, (Int32)height); ::AdjustWindowRect(&rc, style, false); *win_width = rc.right - rc.left; @@ -387,8 +387,8 @@ namespace kiwano MONITORINFOEX info = GetMoniterInfoEx(NULL); - UINT screenw = info.rcWork.right - info.rcWork.left; - UINT screenh = info.rcWork.bottom - info.rcWork.top; + UInt32 screenw = info.rcWork.right - info.rcWork.left; + UInt32 screenh = info.rcWork.bottom - info.rcWork.top; if (*win_width > screenw) *win_width = screenw; @@ -396,7 +396,7 @@ namespace kiwano *win_height = screenh; } - void ChangeFullScreenResolution(int width, int height, WCHAR* device_name) + void ChangeFullScreenResolution(Int32 width, Int32 height, WCHAR* device_name) { DEVMODE mode; diff --git a/src/kiwano/base/Window.h b/src/kiwano/base/Window.h index 19cf280a..8c649f74 100644 --- a/src/kiwano/base/Window.h +++ b/src/kiwano/base/Window.h @@ -39,10 +39,10 @@ namespace kiwano Size GetSize() const; // 获取窗口宽度 - float GetWidth() const; + Float32 GetWidth() const; // 获取窗口高度 - float GetHeight() const; + Float32 GetHeight() const; // 设置标题 void SetTitle(String const& title); @@ -51,10 +51,10 @@ namespace kiwano void SetIcon(LPCWSTR icon_resource); // 重设窗口大小 - void Resize(int width, int height); + void Resize(Int32 width, Int32 height); // 设置全屏模式 - void SetFullscreen(bool fullscreen, int width, int height); + void SetFullscreen(bool fullscreen, Int32 width, Int32 height); // 设置鼠标指针 void SetMouseCursor(MouseCursor cursor); @@ -62,8 +62,8 @@ namespace kiwano public: void Init( String const& title, - int width, - int height, + Int32 width, + Int32 height, LPCWSTR icon, bool fullscreen, WNDPROC proc @@ -87,8 +87,8 @@ namespace kiwano private: HWND handle_; bool is_fullscreen_; - int width_; - int height_; + Int32 width_; + Int32 height_; WCHAR* device_name_; MouseCursor mouse_cursor_; }; diff --git a/src/kiwano/base/keys.hpp b/src/kiwano/base/keys.hpp index 6d668554..e37dadbd 100644 --- a/src/kiwano/base/keys.hpp +++ b/src/kiwano/base/keys.hpp @@ -26,7 +26,7 @@ namespace kiwano // 鼠标按键 struct MouseButton { - typedef int Value; + typedef Int32 Value; enum : Value { @@ -40,7 +40,7 @@ namespace kiwano // 按键键值 struct KeyCode { - typedef int Value; + typedef Int32 Value; enum : Value { diff --git a/src/kiwano/base/time.cpp b/src/kiwano/base/time.cpp index eba6b604..bf97e79e 100644 --- a/src/kiwano/base/time.cpp +++ b/src/kiwano/base/time.cpp @@ -119,25 +119,25 @@ namespace kiwano { } - float Duration::Seconds() const + Float32 Duration::Seconds() const { long sec = milliseconds_ / Sec.milliseconds_; long ms = milliseconds_ % Sec.milliseconds_; - return static_cast(sec) + static_cast(ms) / 1000.f; + return static_cast(sec) + static_cast(ms) / 1000.f; } - float Duration::Minutes() const + Float32 Duration::Minutes() const { long min = milliseconds_ / Min.milliseconds_; long ms = milliseconds_ % Min.milliseconds_; - return static_cast(min) + static_cast(ms) / (60 * 1000.f); + return static_cast(min) + static_cast(ms) / (60 * 1000.f); } - float Duration::Hours() const + Float32 Duration::Hours() const { long hour = milliseconds_ / Hour.milliseconds_; long ms = milliseconds_ % Hour.milliseconds_; - return static_cast(hour) + static_cast(ms) / (60 * 60 * 1000.f); + return static_cast(hour) + static_cast(ms) / (60 * 60 * 1000.f); } String kiwano::time::Duration::ToString() const @@ -172,14 +172,14 @@ namespace kiwano if (ms != 0) { - auto float_to_str = [](float val) -> String + auto float_to_str = [](Float32 val) -> String { - wchar_t buf[10] = {}; + WChar buf[10] = {}; ::swprintf_s(buf, L"%g", val); return String(buf); }; - result.append(float_to_str(static_cast(sec) + static_cast(ms) / 1000.f)) + result.append(float_to_str(static_cast(sec) + static_cast(ms) / 1000.f)) .append(L"s"); } else if (sec != 0) @@ -219,9 +219,9 @@ namespace kiwano return milliseconds_ <= other.milliseconds_; } - float kiwano::time::Duration::operator/(const Duration & other) const + Float32 kiwano::time::Duration::operator/(const Duration & other) const { - return static_cast(milliseconds_) / other.milliseconds_; + return static_cast(milliseconds_) / other.milliseconds_; } const Duration Duration::operator+(const Duration & other) const @@ -239,7 +239,7 @@ namespace kiwano return Duration(-milliseconds_); } - const Duration Duration::operator*(int val) const + const Duration Duration::operator*(Int32 val) const { return Duration(milliseconds_ * val); } @@ -249,12 +249,12 @@ namespace kiwano return Duration(static_cast(milliseconds_ * val)); } - const Duration Duration::operator*(float val) const + const Duration Duration::operator*(Float32 val) const { return Duration(static_cast(milliseconds_ * val)); } - const Duration Duration::operator*(double val) const + const Duration Duration::operator*(Float64 val) const { return Duration(static_cast(milliseconds_ * val)); } @@ -264,17 +264,17 @@ namespace kiwano return Duration(static_cast(milliseconds_ * val)); } - const Duration Duration::operator/(int val) const + const Duration Duration::operator/(Int32 val) const { return Duration(milliseconds_ / val); } - const Duration Duration::operator/(float val) const + const Duration Duration::operator/(Float32 val) const { return Duration(static_cast(milliseconds_ / val)); } - const Duration Duration::operator/(double val) const + const Duration Duration::operator/(Float64 val) const { return Duration(static_cast(milliseconds_ / val)); } @@ -291,68 +291,68 @@ namespace kiwano return (*this); } - Duration & Duration::operator*=(int val) + Duration & Duration::operator*=(Int32 val) { milliseconds_ *= val; return (*this); } - Duration & Duration::operator/=(int val) + Duration & Duration::operator/=(Int32 val) { milliseconds_ = static_cast(milliseconds_ / val); return (*this); } - Duration & Duration::operator*=(float val) + Duration & Duration::operator*=(Float32 val) { milliseconds_ = static_cast(milliseconds_ * val); return (*this); } - Duration & Duration::operator/=(float val) + Duration & Duration::operator/=(Float32 val) { milliseconds_ = static_cast(milliseconds_ / val); return (*this); } - Duration & Duration::operator*=(double val) + Duration & Duration::operator*=(Float64 val) { milliseconds_ = static_cast(milliseconds_ * val); return (*this); } - Duration & Duration::operator/=(double val) + Duration & Duration::operator/=(Float64 val) { milliseconds_ = static_cast(milliseconds_ / val); return (*this); } - const Duration kiwano::time::operator*(int val, const Duration & dur) + const Duration kiwano::time::operator*(Int32 val, const Duration & dur) { return dur * val; } - const Duration kiwano::time::operator/(int val, const Duration & dur) + const Duration kiwano::time::operator/(Int32 val, const Duration & dur) { return dur / val; } - const Duration kiwano::time::operator*(float val, const Duration & dur) + const Duration kiwano::time::operator*(Float32 val, const Duration & dur) { return dur * val; } - const Duration kiwano::time::operator/(float val, const Duration & dur) + const Duration kiwano::time::operator/(Float32 val, const Duration & dur) { return dur / val; } - const Duration kiwano::time::operator*(double val, const Duration & dur) + const Duration kiwano::time::operator*(Float64 val, const Duration & dur) { return dur * val; } - const Duration kiwano::time::operator/(double val, const Duration & dur) + const Duration kiwano::time::operator/(Float64 val, const Duration & dur) { return dur / val; } @@ -364,8 +364,8 @@ namespace kiwano Duration Duration::Parse(const String& str) { - size_t len = str.length(); - size_t pos = 0; + UInt32 len = str.length(); + UInt32 pos = 0; bool negative = false; Duration d; @@ -387,10 +387,10 @@ namespace kiwano while (pos < len) { // 数值 - size_t i = pos; + UInt32 i = pos; for (; i < len; ++i) { - wchar_t ch = str[i]; + WChar ch = str[i]; if (!(ch == L'.' || L'0' <= ch && ch <= L'9')) { break; @@ -409,7 +409,7 @@ namespace kiwano // 单位 for (; i < len; ++i) { - wchar_t ch = str[i]; + WChar ch = str[i]; if (ch == L'.' || L'0' <= ch && ch <= L'9') { break; @@ -425,7 +425,7 @@ namespace kiwano return Duration(); } - double num = std::wcstod(num_str.c_str(), nullptr); + Float64 num = std::wcstod(num_str.c_str(), nullptr); Duration unit = unit_map.at(unit_str); d += unit * num; } diff --git a/src/kiwano/base/time.h b/src/kiwano/base/time.h index 877366e7..16c40b06 100644 --- a/src/kiwano/base/time.h +++ b/src/kiwano/base/time.h @@ -51,24 +51,24 @@ namespace kiwano inline long Milliseconds() const { return milliseconds_; } // 转化为秒 - float Seconds() const; + Float32 Seconds() const; // 转化为分钟 - float Minutes() const; + Float32 Minutes() const; // 转化为小时 - float Hours() const; + Float32 Hours() const; // 时长是否是零 inline bool IsZero() const { return milliseconds_ == 0LL; } inline void SetMilliseconds(long ms) { milliseconds_ = ms; } - inline void SetSeconds(float seconds) { milliseconds_ = static_cast(seconds * 1000.f); } + inline void SetSeconds(Float32 seconds) { milliseconds_ = static_cast(seconds * 1000.f); } - inline void SetMinutes(float minutes) { milliseconds_ = static_cast(minutes * 60 * 1000.f); } + inline void SetMinutes(Float32 minutes) { milliseconds_ = static_cast(minutes * 60 * 1000.f); } - inline void SetHours(float hours) { milliseconds_ = static_cast(hours * 60 * 60 * 1000.f); } + inline void SetHours(Float32 hours) { milliseconds_ = static_cast(hours * 60 * 60 * 1000.f); } // 转为字符串 String ToString() const; @@ -82,36 +82,36 @@ namespace kiwano bool operator< (const Duration &) const; bool operator<= (const Duration &) const; - float operator / (const Duration &) const; + Float32 operator / (const Duration &) const; const Duration operator + (const Duration &) const; const Duration operator - (const Duration &) const; const Duration operator - () const; - const Duration operator * (int) const; + const Duration operator * (Int32) const; const Duration operator * (unsigned long long) const; - const Duration operator * (float) const; - const Duration operator * (double) const; + const Duration operator * (Float32) const; + const Duration operator * (Float64) const; const Duration operator * (long double) const; - const Duration operator / (int) const; - const Duration operator / (float) const; - const Duration operator / (double) const; + const Duration operator / (Int32) const; + const Duration operator / (Float32) const; + const Duration operator / (Float64) const; Duration& operator += (const Duration &); Duration& operator -= (const Duration &); - Duration& operator *= (int); - Duration& operator *= (float); - Duration& operator *= (double); - Duration& operator /= (int); - Duration& operator /= (float); - Duration& operator /= (double); + Duration& operator *= (Int32); + Duration& operator *= (Float32); + Duration& operator *= (Float64); + Duration& operator /= (Int32); + Duration& operator /= (Float32); + Duration& operator /= (Float64); - friend const Duration operator* (int, const Duration &); - friend const Duration operator* (float, const Duration &); - friend const Duration operator* (double, const Duration &); + friend const Duration operator* (Int32, const Duration &); + friend const Duration operator* (Float32, const Duration &); + friend const Duration operator* (Float64, const Duration &); friend const Duration operator* (long double, const Duration &); - friend const Duration operator/ (int, const Duration &); - friend const Duration operator/ (float, const Duration &); - friend const Duration operator/ (double, const Duration &); + friend const Duration operator/ (Int32, const Duration &); + friend const Duration operator/ (Float32, const Duration &); + friend const Duration operator/ (Float64, const Duration &); public: // 时间段格式化 @@ -154,7 +154,7 @@ namespace kiwano // 获取当前时间: Time now = Time::Now(); // 两时间相减, 得到一个 Duration 对象, 例如: // Time t1, t2; - // int ms = (t2 - t1).Milliseconds(); // 获取两时间相差的毫秒数 + // Int32 ms = (t2 - t1).Milliseconds(); // 获取两时间相差的毫秒数 // struct KGE_API Time { diff --git a/src/kiwano/base/types.h b/src/kiwano/base/types.h index b3045ffb..0066700c 100644 --- a/src/kiwano/base/types.h +++ b/src/kiwano/base/types.h @@ -19,29 +19,19 @@ // THE SOFTWARE. #pragma once -#include "../math/Rect.hpp" namespace kiwano { // 线条样式 - enum class StrokeStyle : int + enum class StrokeStyle : Int32 { Miter = 0, /* 斜切 */ Bevel = 1, /* 斜角 */ Round = 2 /* 圆角 */ }; - // 方向 - enum class Direction : int - { - Up, /* 上 */ - Down, /* 下 */ - Left, /* 左 */ - Right /* 右 */ - }; - // 鼠标指针 - enum class MouseCursor : int + enum class MouseCursor : Int32 { Arrow, /* 指针 */ TextInput, /* 输入文本 */ diff --git a/src/kiwano/core/basic_json.hpp b/src/kiwano/core/basic_json.hpp index 5579c3a0..5bf68a4a 100644 --- a/src/kiwano/core/basic_json.hpp +++ b/src/kiwano/core/basic_json.hpp @@ -19,7 +19,7 @@ // THE SOFTWARE. #pragma once -#include +#include "types.h" #include #include #include @@ -365,10 +365,10 @@ namespace __json_detail inline primitive_iterator& operator++() { ++it_; return *this; } - inline primitive_iterator operator++(int) { primitive_iterator old(it_); ++(*this); return old; } + inline primitive_iterator operator++(Int32) { primitive_iterator old(it_); ++(*this); return old; } inline primitive_iterator& operator--() { --it_; return (*this); } - inline primitive_iterator operator--(int) { primitive_iterator old = (*this); --(*this); return old; } + inline primitive_iterator operator--(Int32) { primitive_iterator old = (*this); --(*this); return old; } inline bool operator==(primitive_iterator const& other) const { return it_ == other.it_; } inline bool operator!=(primitive_iterator const& other) const { return !(*this == other); } @@ -534,7 +534,7 @@ namespace __json_detail } } - inline iterator_impl operator++(int) { iterator_impl old = (*this); ++(*this); return old; } + inline iterator_impl operator++(Int32) { iterator_impl old = (*this); ++(*this); return old; } inline iterator_impl& operator++() { check_data(); @@ -560,7 +560,7 @@ namespace __json_detail return *this; } - inline iterator_impl operator--(int) { iterator_impl old = (*this); --(*this); return old; } + inline iterator_impl operator--(Int32) { iterator_impl old = (*this); --(*this); return old; } inline iterator_impl& operator--() { check_data(); @@ -732,11 +732,11 @@ namespace __json_detail using char_traits = ::std::char_traits; virtual void write(const _CharTy ch) = 0; - virtual void write(const _CharTy* str, ::std::size_t size) = 0; + virtual void write(const _CharTy* str, UInt32 size) = 0; virtual void write(const _CharTy* str) { const auto size = char_traits::length(str); - write(str, static_cast<::std::size_t>(size)); + write(str, static_cast(size)); } }; @@ -755,7 +755,7 @@ namespace __json_detail str_.push_back(ch); } - virtual void write(const char_type* str, ::std::size_t size) override + virtual void write(const char_type* str, UInt32 size) override { str_.append(str, static_cast(size)); } @@ -779,7 +779,7 @@ namespace __json_detail stream_.put(ch); } - virtual void write(const char_type* str, ::std::size_t size) override + virtual void write(const char_type* str, UInt32 size) override { stream_.write(str, static_cast(size)); } @@ -806,7 +806,7 @@ namespace __json_detail using array_type = typename _BasicJsonTy::array_type; using object_type = typename _BasicJsonTy::object_type; - json_serializer(output_adapter* out, const wchar_t indent_char) + json_serializer(output_adapter* out, const WChar indent_char) : out(out) , indent_char(indent_char) , indent_string(32, indent_char) @@ -816,8 +816,8 @@ namespace __json_detail void dump( const _BasicJsonTy& json, const bool pretty_print, - const unsigned int indent_step, - const unsigned int current_indent = 0) + const UInt32 indent_step, + const UInt32 current_indent = 0) { switch (json.type()) { @@ -843,7 +843,7 @@ namespace __json_detail auto iter = object.cbegin(); const auto size = object.size(); - for (::std::size_t i = 0; i < size; ++i, ++iter) + for (UInt32 i = 0; i < size; ++i, ++iter) { out->write(indent_string.c_str(), new_indent); out->write('\"'); @@ -866,7 +866,7 @@ namespace __json_detail auto iter = object.cbegin(); const auto size = object.size(); - for (::std::size_t i = 0; i < size; ++i, ++iter) + for (UInt32 i = 0; i < size; ++i, ++iter) { out->write('\"'); out->write(iter->first.c_str()); @@ -906,7 +906,7 @@ namespace __json_detail auto iter = vector.cbegin(); const auto size = vector.size(); - for (::std::size_t i = 0; i < size; ++i, ++iter) + for (UInt32 i = 0; i < size; ++i, ++iter) { out->write(indent_string.c_str(), new_indent); dump(*iter, true, indent_step, new_indent); @@ -926,7 +926,7 @@ namespace __json_detail auto iter = vector.cbegin(); const auto size = vector.size(); - for (::std::size_t i = 0; i < size; ++i, ++iter) + for (UInt32 i = 0; i < size; ++i, ++iter) { dump(*iter, false, indent_step, current_indent); // not last element @@ -999,7 +999,7 @@ namespace __json_detail do { - *(++next) = static_cast('0' + uval % 10); + *(++next) = static_cast('0' + uval % 10); uval /= 10; } while (uval != 0); @@ -1085,7 +1085,7 @@ namespace __json_detail } else { - wchar_t escaped[7] = { 0 }; + WChar escaped[7] = { 0 }; ::swprintf_s(escaped, 7, L"\\u%04x", char_byte); out->write(escaped); } @@ -1205,7 +1205,7 @@ namespace __json_detail private: const char_type* str; - ::std::size_t index; + UInt32 index; }; } // end of namespace __json_detail @@ -1339,7 +1339,7 @@ namespace __json_detail token_type scan_literal(const char_type* text, token_type result) { - for (::std::size_t i = 0; text[i] != '\0'; ++i) + for (UInt32 i = 0; text[i] != '\0'; ++i) { if (text[i] != char_traits::to_char_type(current)) { @@ -1614,10 +1614,10 @@ namespace __json_detail read_next(); } - unsigned int exponent = static_cast(current - '0'); + UInt32 exponent = static_cast(current - '0'); while (::std::isdigit(read_next())) { - exponent = (exponent * 10) + static_cast(current - '0'); + exponent = (exponent * 10) + static_cast(current - '0'); } float_type power = 1; @@ -1819,7 +1819,7 @@ namespace __json_detail template < typename _IntegerTy, - typename ::std::enable_if<::std::is_integral<_IntegerTy>::value, int>::type = 0> + typename ::std::enable_if<::std::is_integral<_IntegerTy>::value, Int32>::type = 0> static inline void assign(const _BasicJsonTy& json, _IntegerTy& value) { if (!json.is_integer()) throw json_type_error("json value type must be integer"); @@ -1828,16 +1828,16 @@ namespace __json_detail static inline void assign(const _BasicJsonTy& json, float_type& value) { - if (!json.is_float()) throw json_type_error("json value type must be float"); + if (!json.is_float()) throw json_type_error("json value type must be Float32"); value = json.value_.data.number_float; } template < typename _FloatingTy, - typename ::std::enable_if<::std::is_floating_point<_FloatingTy>::value, int>::type = 0> + typename ::std::enable_if<::std::is_floating_point<_FloatingTy>::value, Int32>::type = 0> static inline void assign(const _BasicJsonTy& json, _FloatingTy& value) { - if (!json.is_float()) throw json_type_error("json value type must be float"); + if (!json.is_float()) throw json_type_error("json value type must be Float32"); value = static_cast<_FloatingTy>(json.value_.data.number_float); } }; @@ -1859,7 +1859,7 @@ class basic_json public: template using allocator_type = _Allocator<_Ty>; - using size_type = ::std::size_t; + using size_type = UInt32; using difference_type = ::std::ptrdiff_t; using string_type = _StringTy; using char_type = typename _StringTy::value_type; @@ -1895,7 +1895,7 @@ public: template < typename _CompatibleTy, - typename ::std::enable_if<::std::is_constructible::value, int>::type = 0> + typename ::std::enable_if<::std::is_constructible::value, Int32>::type = 0> basic_json(const _CompatibleTy& value) { value_.type = JsonType::String; @@ -1919,7 +1919,7 @@ public: template < typename _IntegerTy, - typename ::std::enable_if<::std::is_integral<_IntegerTy>::value, int>::type = 0> + typename ::std::enable_if<::std::is_integral<_IntegerTy>::value, Int32>::type = 0> basic_json(_IntegerTy value) : value_(static_cast(value)) { @@ -1932,7 +1932,7 @@ public: template < typename _FloatingTy, - typename ::std::enable_if<::std::is_floating_point<_FloatingTy>::value, int>::type = 0> + typename ::std::enable_if<::std::is_floating_point<_FloatingTy>::value, Int32>::type = 0> basic_json(_FloatingTy value) : value_(static_cast(value)) { @@ -2027,7 +2027,7 @@ public: case JsonType::Integer: return string_type(L"integer"); case JsonType::Float: - return string_type(L"float"); + return string_type(L"Float32"); case JsonType::Boolean: return string_type(L"boolean"); case JsonType::Null: @@ -2123,7 +2123,7 @@ public: class _IteratorTy, typename ::std::enable_if< ::std::is_same<_IteratorTy, iterator>::value || - ::std::is_same<_IteratorTy, const_iterator>::value, int + ::std::is_same<_IteratorTy, const_iterator>::value, Int32 >::type = 0> inline _IteratorTy erase(_IteratorTy pos) { @@ -2154,7 +2154,7 @@ public: class _IteratorTy, typename ::std::enable_if< ::std::is_same<_IteratorTy, iterator>::value || - ::std::is_same<_IteratorTy, const_iterator>::value, int + ::std::is_same<_IteratorTy, const_iterator>::value, Int32 >::type = 0> inline _IteratorTy erase(_IteratorTy first, _IteratorTy last) { @@ -2282,7 +2282,7 @@ public: template < typename _IntegerTy, - typename ::std::enable_if<::std::is_integral<_IntegerTy>::value, int>::type = 0> + typename ::std::enable_if<::std::is_integral<_IntegerTy>::value, Int32>::type = 0> inline bool get_value(_IntegerTy& val) const { if (is_integer()) @@ -2295,7 +2295,7 @@ public: template < typename _FloatingTy, - typename ::std::enable_if<::std::is_floating_point<_FloatingTy>::value, int>::type = 0> + typename ::std::enable_if<::std::is_floating_point<_FloatingTy>::value, Int32>::type = 0> inline bool get_value(_FloatingTy& val) const { if (is_float()) @@ -2350,7 +2350,7 @@ public: float_type as_float() const { - if (!is_float()) throw json_type_error("json value must be float"); + if (!is_float()) throw json_type_error("json value must be Float32"); return value_.data.number_float; } @@ -2545,12 +2545,12 @@ public: out.width(0); __json_detail::stream_output_adapter adapter(out); - __json_detail::json_serializer(&adapter, out.fill()).dump(json, pretty_print, static_cast(indentation)); + __json_detail::json_serializer(&adapter, out.fill()).dump(json, pretty_print, static_cast(indentation)); return out; } string_type dump( - const int indent = -1, + const Int32 indent = -1, const char_type indent_char = ' ') const { string_type result; @@ -2561,12 +2561,12 @@ public: void dump( __json_detail::output_adapter* adapter, - const int indent = -1, + const Int32 indent = -1, const char_type indent_char = ' ') const { if (indent >= 0) { - __json_detail::json_serializer(adapter, indent_char).dump(*this, true, static_cast(indent)); + __json_detail::json_serializer(adapter, indent_char).dump(*this, true, static_cast(indent)); } else { diff --git a/src/kiwano/core/core.h b/src/kiwano/core/core.h index 418ddcaf..ea5f63d8 100644 --- a/src/kiwano/core/core.h +++ b/src/kiwano/core/core.h @@ -25,7 +25,7 @@ #include "intrusive_ptr.hpp" #include "noncopyable.hpp" #include "singleton.hpp" -#include "Function.hpp" +#include "function.hpp" #include "basic_json.hpp" #include #include @@ -68,7 +68,7 @@ namespace kiwano using Function = kiwano::core::function<_FuncTy>; using Json = kiwano::core::basic_json; + Int32, Float64, bool, std::allocator>; } namespace std diff --git a/src/kiwano/core/function.hpp b/src/kiwano/core/function.hpp index 8e720186..a6764fbc 100644 --- a/src/kiwano/core/function.hpp +++ b/src/kiwano/core/function.hpp @@ -42,7 +42,7 @@ namespace __function_detail template struct helper { - template static int test(...); + template static Int32 test(...); template struct class_mem; template static char test(class_mem<_Uty, &_Uty::operator()>*); @@ -54,7 +54,7 @@ namespace __function_detail typename _Uty, typename _Uret = typename ::std::decay().operator()(::std::declval<_Args>()...))>::type, typename = typename ::std::enable_if<::std::is_convertible<_Ret, _Uret>::value>::type> - static char test(int); + static char test(Int32); static constexpr bool value = sizeof(test<_Ty>(0)) == sizeof(char); }; @@ -76,9 +76,9 @@ namespace __function_detail public: virtual ~callable() {} - virtual void AddRef() = 0; - virtual void Release() = 0; - virtual _Ret Invoke(_Args... args) const = 0; + virtual void retain() = 0; + virtual void release() = 0; + virtual _Ret invoke(_Args... args) const = 0; }; template @@ -88,12 +88,12 @@ namespace __function_detail public: ref_count_callable() : ref_count_(0) {} - virtual void AddRef() override + virtual void retain() override { ++ref_count_; } - virtual void Release() override + virtual void release() override { --ref_count_; if (ref_count_ <= 0) @@ -103,7 +103,7 @@ namespace __function_detail } private: - int ref_count_; + Int32 ref_count_; }; template @@ -116,12 +116,12 @@ namespace __function_detail { } - virtual _Ret Invoke(_Args... args) const override + virtual _Ret invoke(_Args... args) const override { return callee_(::std::forward<_Args&&>(args)...); } - static inline callable<_Ret, _Args...>* Make(_Ty&& val) + static inline callable<_Ret, _Args...>* make(_Ty&& val) { return new (::std::nothrow) proxy_callable<_Ty, _Ret, _Args...>(::std::move(val)); } @@ -137,12 +137,12 @@ namespace __function_detail public: typedef _Ret(_Ty::* _FuncType)(_Args...); - virtual _Ret Invoke(_Args... args) const override + virtual _Ret invoke(_Args... args) const override { return (static_cast<_Ty*>(ptr_)->*func_)(::std::forward<_Args>(args)...); } - static inline callable<_Ret, _Args...>* Make(void* ptr, _FuncType func) + static inline callable<_Ret, _Args...>* make(void* ptr, _FuncType func) { return new (::std::nothrow) proxy_mem_callable<_Ty, _Ret, _Args...>(ptr, func); } @@ -166,12 +166,12 @@ namespace __function_detail public: typedef _Ret(_Ty::* _FuncType)(_Args...) const; - virtual _Ret Invoke(_Args... args) const override + virtual _Ret invoke(_Args... args) const override { return (static_cast<_Ty*>(ptr_)->*func_)(::std::forward<_Args>(args)...); } - static inline callable<_Ret, _Args...>* Make(void* ptr, _FuncType func) + static inline callable<_Ret, _Args...>* make(void* ptr, _FuncType func) { return new (::std::nothrow) proxy_const_mem_callable<_Ty, _Ret, _Args...>(ptr, func); } @@ -227,7 +227,7 @@ public: function(const function& rhs) : callable_(rhs.callable_) { - if (callable_) callable_->AddRef(); + if (callable_) callable_->retain(); } function(function&& rhs) noexcept @@ -238,35 +238,35 @@ public: function(_Ret(*func)(_Args...)) { - callable_ = __function_detail::proxy_callable<_Ret(*)(_Args...), _Ret, _Args...>::Make(::std::move(func)); - if (callable_) callable_->AddRef(); + callable_ = __function_detail::proxy_callable<_Ret(*)(_Args...), _Ret, _Args...>::make(::std::move(func)); + if (callable_) callable_->retain(); } template< typename _Ty, - typename = typename ::std::enable_if<__function_detail::is_callable<_Ty, _Ret, _Args...>::value, int>::type> + typename = typename ::std::enable_if<__function_detail::is_callable<_Ty, _Ret, _Args...>::value, Int32>::type> function(_Ty val) { - callable_ = __function_detail::proxy_callable<_Ty, _Ret, _Args...>::Make(::std::move(val)); - if (callable_) callable_->AddRef(); + callable_ = __function_detail::proxy_callable<_Ty, _Ret, _Args...>::make(::std::move(val)); + if (callable_) callable_->retain(); } template::value || ::std::is_base_of<_Ty, _Uty>::value, int>::type> + typename = typename ::std::enable_if<::std::is_same<_Ty, _Uty>::value || ::std::is_base_of<_Ty, _Uty>::value, Int32>::type> function(_Uty* ptr, _Ret(_Ty::* func)(_Args...)) { - callable_ = __function_detail::proxy_mem_callable<_Ty, _Ret, _Args...>::Make(ptr, func); - if (callable_) callable_->AddRef(); + callable_ = __function_detail::proxy_mem_callable<_Ty, _Ret, _Args...>::make(ptr, func); + if (callable_) callable_->retain(); } template::value || ::std::is_base_of<_Ty, _Uty>::value, int>::type> + typename = typename ::std::enable_if<::std::is_same<_Ty, _Uty>::value || ::std::is_base_of<_Ty, _Uty>::value, Int32>::type> function(_Uty* ptr, _Ret(_Ty::* func)(_Args...) const) { - callable_ = __function_detail::proxy_const_mem_callable<_Ty, _Ret, _Args...>::Make(ptr, func); - if (callable_) callable_->AddRef(); + callable_ = __function_detail::proxy_const_mem_callable<_Ty, _Ret, _Args...>::make(ptr, func); + if (callable_) callable_->retain(); } ~function() @@ -283,7 +283,7 @@ public: { if (!callable_) throw bad_function_call(); - return callable_->Invoke(::std::forward<_Args>(args)...); + return callable_->invoke(::std::forward<_Args>(args)...); } inline operator bool() const @@ -295,7 +295,7 @@ public: { tidy(); callable_ = rhs.callable_; - if (callable_) callable_->AddRef(); + if (callable_) callable_->retain(); return (*this); } @@ -312,7 +312,7 @@ private: { if (callable_) { - callable_->Release(); + callable_->release(); callable_ = nullptr; } } @@ -330,11 +330,11 @@ namespace kiwano template::value || std::is_base_of<_Ty, _Uty>::value, int + std::is_same<_Ty, _Uty>::value || std::is_base_of<_Ty, _Uty>::value, Int32 >::type, typename _Ret, typename... _Args> - inline function<_Ret(_Args...)> bind_func(_Uty* ptr, _Ret(_Ty::* func)(_Args...)) + inline function<_Ret(_Args...)> Closure(_Uty* ptr, _Ret(_Ty::* func)(_Args...)) { return function<_Ret(_Args...)>(ptr, func); } @@ -342,11 +342,11 @@ namespace kiwano template::value || std::is_base_of<_Ty, _Uty>::value, int + std::is_same<_Ty, _Uty>::value || std::is_base_of<_Ty, _Uty>::value, Int32 >::type, typename _Ret, typename... _Args> - inline function<_Ret(_Args...)> bind_func(_Uty* ptr, _Ret(_Ty::* func)(_Args...) const) + inline function<_Ret(_Args...)> Closure(_Uty* ptr, _Ret(_Ty::* func)(_Args...) const) { return function<_Ret(_Args...)>(ptr, func); } diff --git a/src/kiwano/core/intrusive_list.hpp b/src/kiwano/core/intrusive_list.hpp index 76e0053d..cfbaa93a 100644 --- a/src/kiwano/core/intrusive_list.hpp +++ b/src/kiwano/core/intrusive_list.hpp @@ -20,6 +20,7 @@ #pragma once #include "../macros.h" +#include "types.h" // #define KGE_DEBUG_ENABLE_LIST_CHECK @@ -230,7 +231,7 @@ private: if (!first_) return; - int pos = 0; + Int32 pos = 0; T p = first_; T tmp = p; do diff --git a/src/kiwano/core/string.hpp b/src/kiwano/core/string.hpp index 5378858f..46cc587c 100644 --- a/src/kiwano/core/string.hpp +++ b/src/kiwano/core/string.hpp @@ -19,6 +19,7 @@ // THE SOFTWARE. #pragma once +#include "types.h" #include #include #include @@ -35,7 +36,7 @@ inline namespace core // // basic_string<> // Lightweight ::std::basic_string<>-like class -// When using basic_string<> with a c-style string (char* or wchar_t*), constructor and operator=() just hold +// When using basic_string<> with a c-style string (char* or WChar*), constructor and operator=() just hold // a pointer to the character array but don't copy its content, considering performance issues. // Use assign() and basic_string<>::cstr() to work fine with c-style strings. // @@ -62,10 +63,10 @@ public: inline pointer base() const { return base_; } inline iterator_impl& operator++() { ++base_; return (*this); } - inline iterator_impl operator++(int) { iterator_impl old = (*this); ++(*this); return old; } + inline iterator_impl operator++(Int32) { iterator_impl old = (*this); ++(*this); return old; } inline iterator_impl& operator--() { --base_; return (*this); } - inline iterator_impl operator--(int) { iterator_impl old = (*this); --(*this); return old; } + inline iterator_impl operator--(Int32) { iterator_impl old = (*this); --(*this); return old; } inline const iterator_impl operator+(difference_type off) const { return iterator_impl(base_ + off); } inline const iterator_impl operator-(difference_type off) const { return iterator_impl(base_ - off); } @@ -95,7 +96,7 @@ public: public: using value_type = _CharTy; using char_type = value_type; - using size_type = size_t; + using size_type = UInt32; using reference = value_type &; using const_reference = const value_type &; using iterator = iterator_impl; @@ -120,7 +121,7 @@ public: inline const char_type* c_str() const { return empty() ? empty_cstr : const_str_; } inline const char_type* data() const { return empty() ? empty_cstr : const_str_; } - inline char_type at(size_t i) const { return (*this)[i]; } + inline char_type at(UInt32 i) const { return (*this)[i]; } inline size_type size() const { return size_; } inline size_type length() const { return size(); } inline size_type capacity() const { return capacity_; } @@ -131,8 +132,8 @@ public: void reserve(const size_type new_cap = 0); inline void resize(const size_type new_size, const char_type ch = value_type()) { check_operability(); if (new_size < size_) str_[size_ = new_size] = value_type(); else append(new_size - size_, ch); } - int compare(const char_type* const str) const; - inline int compare(basic_string const& str) const { return compare(str.c_str()); } + Int32 compare(const char_type* const str) const; + inline Int32 compare(basic_string const& str) const { return compare(str.c_str()); } basic_string& append(size_type count, char_type ch); basic_string& append(const char_type* cstr, size_type count); @@ -195,17 +196,17 @@ public: size_type copy(char_type* cstr, size_type count, size_type pos = 0) const; void swap(basic_string& rhs) noexcept; - size_t hash() const; + UInt32 hash() const; public: - static basic_string parse(int val); - static basic_string parse(unsigned int val); + static basic_string parse(Int32 val); + static basic_string parse(UInt32 val); static basic_string parse(long val); static basic_string parse(unsigned long val); static basic_string parse(long long val); static basic_string parse(unsigned long long val); - static basic_string parse(float val); - static basic_string parse(double val); + static basic_string parse(Float32 val); + static basic_string parse(Float64 val); static basic_string parse(long double val); template @@ -384,10 +385,10 @@ template // template -basic_string<_CharTy> to_basic_string(int val); +basic_string<_CharTy> to_basic_string(Int32 val); template -basic_string<_CharTy> to_basic_string(unsigned int val); +basic_string<_CharTy> to_basic_string(UInt32 val); template basic_string<_CharTy> to_basic_string(long val); @@ -402,10 +403,10 @@ template basic_string<_CharTy> to_basic_string(unsigned long long val); template -basic_string<_CharTy> to_basic_string(float val); +basic_string<_CharTy> to_basic_string(Float32 val); template -basic_string<_CharTy> to_basic_string(double val); +basic_string<_CharTy> to_basic_string(Float64 val); template basic_string<_CharTy> to_basic_string(long double val); @@ -418,14 +419,14 @@ template basic_string format_string(const char* const fmt, _Args&&... args); template -basic_string format_string(const wchar_t* const fmt, _Args&& ... args); +basic_string format_string(const WChar* const fmt, _Args&& ... args); // // string && wstring // using string = ::kiwano::core::basic_string; -using wstring = ::kiwano::core::basic_string; +using wstring = ::kiwano::core::basic_string; } // inline namespace core } // namespace kiwano @@ -439,13 +440,13 @@ namespace kiwano namespace __string_details { template - size_t TraitsFind( - const typename _Traits::char_type* first, size_t first_size, size_t offset, - const typename _Traits::char_type* second, size_t count) + UInt32 TraitsFind( + const typename _Traits::char_type* first, UInt32 first_size, UInt32 offset, + const typename _Traits::char_type* second, UInt32 count) { if (count > first_size || offset > first_size - count) { - return static_cast(-1); + return static_cast(-1); } if (count == 0) @@ -456,23 +457,23 @@ namespace __string_details const auto matches_end = first + (first_size - count) + 1; for (auto iter = first + offset; ; ++iter) { - iter = typename _Traits::find(iter, static_cast(matches_end - iter), *second); + iter = typename _Traits::find(iter, static_cast(matches_end - iter), *second); if (!iter) { - return static_cast(-1); + return static_cast(-1); } if (typename _Traits::compare(iter, second, count) == 0) { - return static_cast(iter - first); + return static_cast(iter - first); } } } template - size_t TraitsFindLastOf( - const typename _Traits::char_type* first, const size_t first_size, const size_t pos, - const typename _Traits::char_type* second, const size_t count) + UInt32 TraitsFindLastOf( + const typename _Traits::char_type* first, const UInt32 first_size, const UInt32 pos, + const typename _Traits::char_type* second, const UInt32 count) { if (count != 0 && first_size != 0) { @@ -480,7 +481,7 @@ namespace __string_details { if (typename _Traits::find(second, count, *iter)) { - return static_cast(iter - first); + return static_cast(iter - first); } if (iter == first) { @@ -488,7 +489,7 @@ namespace __string_details } } } - return static_cast(-1); + return static_cast(-1); } } @@ -592,7 +593,7 @@ inline namespace core size_ = count; traits_type::assign(str_, size_, ch); - traits_type::assign(str_[size_], value_type()); + traits_type::assign(*(str_ + size_), value_type()); } else { @@ -805,8 +806,8 @@ inline namespace core { check_operability(); - size_t new_size = size_ + count; - size_t new_cap = new_size + 1; + UInt32 new_size = size_ + count; + UInt32 new_cap = new_size + 1; char_type* new_str = allocate(new_cap); traits_type::move(new_str, str_, size_); @@ -826,8 +827,8 @@ inline namespace core { check_operability(); - size_t new_size = size_ + count; - size_t new_cap = new_size + 1; + UInt32 new_size = size_ + count; + UInt32 new_cap = new_size + 1; char_type* new_str = allocate(new_cap); traits_type::move(new_str, str_, size_); @@ -852,8 +853,8 @@ inline namespace core count = other.clamp_suffix_size(pos, count); - size_t new_size = size_ + count; - size_t new_cap = new_size + 1; + UInt32 new_size = size_ + count; + UInt32 new_cap = new_size + 1; char_type* new_str = allocate(new_cap); traits_type::move(new_str, str_, size_); @@ -886,27 +887,27 @@ inline namespace core } template - inline size_t basic_string<_CharTy>::hash() const + inline UInt32 basic_string<_CharTy>::hash() const { - static size_t fnv_prime = 16777619U; - size_t fnv_offset_basis = 2166136261U; + static UInt32 fnv_prime = 16777619U; + UInt32 fnv_offset_basis = 2166136261U; - for (size_t index = 0; index < size_; ++index) + for (UInt32 index = 0; index < size_; ++index) { - fnv_offset_basis ^= static_cast(const_str_[index]); + fnv_offset_basis ^= static_cast(const_str_[index]); fnv_offset_basis *= fnv_prime; } return fnv_offset_basis; } template - inline int basic_string<_CharTy>::compare(const char_type* const str) const + inline Int32 basic_string<_CharTy>::compare(const char_type* const str) const { size_type count1 = size(); size_type count2 = traits_type::length(str); size_type rlen = ::std::min(count1, count2); - int ret = traits_type::compare(const_str_, str, rlen); + Int32 ret = traits_type::compare(const_str_, str, rlen); if (ret != 0) return ret; @@ -1136,10 +1137,10 @@ inline namespace core // template - inline basic_string<_CharTy> basic_string<_CharTy>::parse(int val) { return ::kiwano::to_basic_string(val); } + inline basic_string<_CharTy> basic_string<_CharTy>::parse(Int32 val) { return ::kiwano::to_basic_string(val); } template - inline basic_string<_CharTy> basic_string<_CharTy>::parse(unsigned int val) { return ::kiwano::to_basic_string(val); } + inline basic_string<_CharTy> basic_string<_CharTy>::parse(UInt32 val) { return ::kiwano::to_basic_string(val); } template inline basic_string<_CharTy> basic_string<_CharTy>::parse(long val) { return ::kiwano::to_basic_string(val); } @@ -1154,10 +1155,10 @@ inline namespace core inline basic_string<_CharTy> basic_string<_CharTy>::parse(unsigned long long val) { return ::kiwano::to_basic_string(val); } template - inline basic_string<_CharTy> basic_string<_CharTy>::parse(float val) { return ::kiwano::to_basic_string(val); } + inline basic_string<_CharTy> basic_string<_CharTy>::parse(Float32 val) { return ::kiwano::to_basic_string(val); } template - inline basic_string<_CharTy> basic_string<_CharTy>::parse(double val) { return ::kiwano::to_basic_string(val); } + inline basic_string<_CharTy> basic_string<_CharTy>::parse(Float64 val) { return ::kiwano::to_basic_string(val); } template inline basic_string<_CharTy> basic_string<_CharTy>::parse(long double val) { return ::kiwano::to_basic_string(val); } @@ -1312,13 +1313,13 @@ inline namespace core } template - inline basic_string<_CharTy> to_basic_string(int val) + inline basic_string<_CharTy> to_basic_string(Int32 val) { return (__to_string_detail::IntegralToString<_CharTy>::convert(val)); } template - inline basic_string<_CharTy> to_basic_string(unsigned int val) + inline basic_string<_CharTy> to_basic_string(UInt32 val) { return (__to_string_detail::IntegralToString<_CharTy>::convert(val)); } @@ -1348,13 +1349,13 @@ inline namespace core } template - inline basic_string<_CharTy> to_basic_string(float val) + inline basic_string<_CharTy> to_basic_string(Float32 val) { return (__to_string_detail::FloatingToString<_CharTy>::convert(val)); } template - inline basic_string<_CharTy> to_basic_string(double val) + inline basic_string<_CharTy> to_basic_string(Float64 val) { return (__to_string_detail::FloatingToString<_CharTy>::convert(val)); } @@ -1380,9 +1381,9 @@ inline namespace core } template - inline basic_string format_string(const wchar_t* const fmt, _Args&& ... args) + inline basic_string format_string(const WChar* const fmt, _Args&& ... args) { - using string_type = basic_string; + using string_type = basic_string; const auto len = static_cast(::_scwprintf(fmt, ::std::forward<_Args>(args)...)); if (len) { @@ -1437,37 +1438,37 @@ inline namespace core }; template <> - struct IntegralToString + struct IntegralToString { template - static basic_string convert(const _Ty val) + static basic_string convert(const _Ty val) { static_assert(::std::is_integral<_Ty>::value, "_Ty must be integral"); - using _Elem = typename basic_string::traits_type::char_type; + using _Elem = typename basic_string::traits_type::char_type; _Elem buffer[21]; _Elem* const buffer_end = ::std::end(buffer); _Elem* buffer_begin = __IntegerToStringBufferEnd(val, buffer_end); - return basic_string(buffer_begin, buffer_end); + return basic_string(buffer_begin, buffer_end); } }; template<> - struct FloatingToString + struct FloatingToString { - static inline basic_string convert(const float val) + static inline basic_string convert(const Float32 val) { return format_string(L"%g", val); } - static inline basic_string convert(const double val) + static inline basic_string convert(const Float64 val) { return format_string(L"%g", val); } - static inline basic_string convert(const long double val) + static inline basic_string convert(const long double val) { return format_string(L"%Lg", val); } @@ -1476,12 +1477,12 @@ inline namespace core template<> struct FloatingToString { - static inline basic_string convert(const float val) + static inline basic_string convert(const Float32 val) { return format_string("%g", val); } - static inline basic_string convert(const double val) + static inline basic_string convert(const Float64 val) { return format_string("%g", val); } @@ -1498,7 +1499,7 @@ inline namespace core namespace kiwano { -template +template class string_convert { enum { BUFFER_INCREASE = 8, BUFFER_MAX = 16 }; @@ -1526,7 +1527,7 @@ public: virtual ~string_convert() { } - size_t converted() const noexcept { return conv_num_; } + UInt32 converted() const noexcept { return conv_num_; } state_type state() const { return state_; } @@ -1553,8 +1554,8 @@ public: state_ = state_type{}; - wbuf.append((::std::size_t) BUFFER_INCREASE, (_Elem) '\0'); - for (conv_num_ = 0; first != last; conv_num_ = static_cast(first - first_save)) + wbuf.append((UInt32) BUFFER_INCREASE, (_Elem) '\0'); + for (conv_num_ = 0; first != last; conv_num_ = static_cast(first - first_save)) { _Elem* dest = &*wbuf.begin(); _Elem* dnext; @@ -1566,11 +1567,11 @@ public: { if (dest < dnext) { - wstr.append(dest, static_cast(dnext - dest)); + wstr.append(dest, static_cast(dnext - dest)); } else if (wbuf.size() < BUFFER_MAX) { - wbuf.append(static_cast(BUFFER_INCREASE), '\0'); + wbuf.append(static_cast(BUFFER_INCREASE), '\0'); } else { @@ -1583,7 +1584,7 @@ public: { // no conversion, just copy code values for (; first != last; ++first) { - wstr.push_back((_Elem)(unsigned char)* first); + wstr.push_back((_Elem)(UChar)* first); } break; } @@ -1621,8 +1622,8 @@ public: state_ = state_type{}; - bbuf.append((::std::size_t) BUFFER_INCREASE, '\0'); - for (conv_num_ = 0; first != last; conv_num_ = static_cast(first - first_save)) + bbuf.append((UInt32) BUFFER_INCREASE, '\0'); + for (conv_num_ = 0; first != last; conv_num_ = static_cast(first - first_save)) { char* dest = &*bbuf.begin(); char* dnext; @@ -1634,11 +1635,11 @@ public: { if (dest < dnext) { - bstr.append(dest, (::std::size_t)(dnext - dest)); + bstr.append(dest, (UInt32)(dnext - dest)); } else if (bbuf.size() < BUFFER_MAX) { - bbuf.append((::std::size_t) BUFFER_INCREASE, '\0'); + bbuf.append((UInt32) BUFFER_INCREASE, '\0'); } else { @@ -1670,11 +1671,11 @@ private: const codecvt_type* cvt_; ::std::locale loc_; state_type state_; - size_t conv_num_; + UInt32 conv_num_; }; class chs_codecvt - : public ::std::codecvt_byname + : public ::std::codecvt_byname { public: chs_codecvt() : codecvt_byname("chs") {} @@ -1709,7 +1710,7 @@ namespace std template<> struct hash<::kiwano::core::string> { - inline size_t operator()(const ::kiwano::core::string& key) const + inline std::size_t operator()(const ::kiwano::core::string& key) const { return key.hash(); } @@ -1718,7 +1719,7 @@ namespace std template<> struct hash<::kiwano::core::wstring> { - inline size_t operator()(const ::kiwano::core::wstring& key) const + inline std::size_t operator()(const ::kiwano::core::wstring& key) const { return key.hash(); } diff --git a/src/kiwano/core/types.h b/src/kiwano/core/types.h new file mode 100644 index 00000000..85f23f2a --- /dev/null +++ b/src/kiwano/core/types.h @@ -0,0 +1,45 @@ +// Copyright (c) 2016-2018 Kiwano - Nomango +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +#pragma once +#include + +#define KGE_DEFINE_NUMERIC_TYPE(TYPE, OLD_TYPE) using TYPE = OLD_TYPE; + +namespace kiwano +{ + KGE_DEFINE_NUMERIC_TYPE(Char, signed char); + KGE_DEFINE_NUMERIC_TYPE(UChar, unsigned char); + KGE_DEFINE_NUMERIC_TYPE(WChar, wchar_t); + + KGE_DEFINE_NUMERIC_TYPE(Int8, std::int8_t); + KGE_DEFINE_NUMERIC_TYPE(Int16, std::int16_t); + KGE_DEFINE_NUMERIC_TYPE(Int32, std::int32_t); + KGE_DEFINE_NUMERIC_TYPE(Int64, std::int64_t); + + KGE_DEFINE_NUMERIC_TYPE(UInt8, std::uint8_t); + KGE_DEFINE_NUMERIC_TYPE(UInt16, std::uint16_t); + KGE_DEFINE_NUMERIC_TYPE(UInt32, std::uint32_t); + KGE_DEFINE_NUMERIC_TYPE(UInt64, std::uint64_t); + + KGE_DEFINE_NUMERIC_TYPE(Float32, float); + KGE_DEFINE_NUMERIC_TYPE(Float64, double); + +} diff --git a/src/kiwano/core/vector.hpp b/src/kiwano/core/vector.hpp index b8a7a2fd..785e3bf4 100644 --- a/src/kiwano/core/vector.hpp +++ b/src/kiwano/core/vector.hpp @@ -19,6 +19,7 @@ // THE SOFTWARE. #pragma once +#include "types.h" #include #include #include @@ -51,7 +52,7 @@ class vector { public: using value_type = _Ty; - using size_type = std::size_t; + using size_type = UInt32; using iterator = value_type * ; using const_iterator = const value_type*; using reference = value_type & ; @@ -217,12 +218,12 @@ namespace __vector_details struct vector_memory_manager<_Ty, _Alloc, false> { using value_type = _Ty; - using size_type = size_t; + using size_type = UInt32; using allocator_type = typename _Alloc; - static void copy_data(value_type* dest, const value_type* src, size_type count) { if (src == dest) return; ::memcpy(dest, src, (size_t)count * sizeof(value_type)); } - static void copy_data(value_type* dest, size_type count, const value_type& val) { ::memset(dest, (int)val, (size_t)count * sizeof(value_type)); } - static void move_data(value_type* dest, const value_type* src, size_type count) { if (src == dest) return; ::memmove(dest, src, (size_t)count * sizeof(value_type)); } + static void copy_data(value_type* dest, const value_type* src, size_type count) { if (src == dest) return; ::memcpy(dest, src, (UInt32)count * sizeof(value_type)); } + static void copy_data(value_type* dest, size_type count, const value_type& val) { ::memset(dest, (Int32)val, (UInt32)count * sizeof(value_type)); } + static void move_data(value_type* dest, const value_type* src, size_type count) { if (src == dest) return; ::memmove(dest, src, (UInt32)count * sizeof(value_type)); } static value_type* allocate(size_type count) { return get_allocator().allocate(count); } static void deallocate(value_type*& ptr, size_type count) { if (ptr) { get_allocator().deallocate(ptr, count); ptr = nullptr; } } @@ -246,7 +247,7 @@ namespace __vector_details struct vector_memory_manager<_Ty, _Alloc, true> { using value_type = _Ty; - using size_type = size_t; + using size_type = UInt32; using allocator_type = typename _Alloc; static void copy_data(value_type* dest, const value_type* src, size_type count) { if (src == dest) return; while (count--) (*dest++) = (*src++); } diff --git a/src/kiwano/math/Matrix.hpp b/src/kiwano/math/Matrix.hpp index b13e5391..6c6b94ec 100644 --- a/src/kiwano/math/Matrix.hpp +++ b/src/kiwano/math/Matrix.hpp @@ -67,7 +67,7 @@ namespace kiwano explicit Matrix3x2T(const value_type* p) { - for (int i = 0; i < 6; i++) + for (Int32 i = 0; i < 6; i++) m[i] = p[i]; } @@ -81,23 +81,23 @@ namespace kiwano template Matrix3x2T(_MTy const& other) { - for (int i = 0; i < 6; i++) + for (Int32 i = 0; i < 6; i++) m[i] = other[i]; } - inline value_type operator [](unsigned int index) const + inline value_type operator [](UInt32 index) const { return m[index]; } - inline value_type& operator [](unsigned int index) + inline value_type& operator [](UInt32 index) { return m[index]; } inline Matrix3x2T& operator= (Matrix3x2T const& other) { - for (int i = 0; i < 6; i++) + for (Int32 i = 0; i < 6; i++) m[i] = other[i]; return (*this); } @@ -285,7 +285,7 @@ namespace kiwano , rhs(rhs) {} - inline _Ty operator [](unsigned int index) const + inline _Ty operator [](UInt32 index) const { switch (index) { @@ -327,5 +327,5 @@ namespace kiwano namespace kiwano { - using Matrix3x2 = kiwano::math::Matrix3x2T; + using Matrix3x2 = kiwano::math::Matrix3x2T; } diff --git a/src/kiwano/math/Rect.hpp b/src/kiwano/math/Rect.hpp index c45480ae..f37b3fe3 100644 --- a/src/kiwano/math/Rect.hpp +++ b/src/kiwano/math/Rect.hpp @@ -120,5 +120,5 @@ namespace kiwano namespace kiwano { - using Rect = kiwano::math::RectT; + using Rect = kiwano::math::RectT; } diff --git a/src/kiwano/math/Vec2.hpp b/src/kiwano/math/Vec2.hpp index 1be13ff1..75fd778c 100644 --- a/src/kiwano/math/Vec2.hpp +++ b/src/kiwano/math/Vec2.hpp @@ -41,7 +41,7 @@ namespace kiwano inline value_type Length() const { - return static_cast(math::Sqrt(static_cast(x * x + y * y))); + return static_cast(math::Sqrt(static_cast(x * x + y * y))); } inline bool IsOrigin() const @@ -123,5 +123,5 @@ namespace kiwano namespace kiwano { - using Vec2 = kiwano::math::Vec2T; + using Vec2 = kiwano::math::Vec2T; } diff --git a/src/kiwano/math/ease.hpp b/src/kiwano/math/ease.hpp index ae125067..f1062f6d 100644 --- a/src/kiwano/math/ease.hpp +++ b/src/kiwano/math/ease.hpp @@ -25,7 +25,7 @@ namespace kiwano { namespace math { - inline float Linear(float step) + inline Float32 Linear(Float32 step) { return step; } @@ -33,17 +33,17 @@ namespace kiwano // Ease - inline float EaseIn(float step, float rate) + inline Float32 EaseIn(Float32 step, Float32 rate) { return math::Pow(step, rate); } - inline float EaseOut(float step, float rate) + inline Float32 EaseOut(Float32 step, Float32 rate) { return math::Pow(step, 1.f / rate); } - inline float EaseInOut(float step, float rate) + inline Float32 EaseInOut(Float32 step, Float32 rate) { if (step < .5f) return .5f * math::Pow(2 * step, rate); @@ -53,17 +53,17 @@ namespace kiwano // Exponential Ease - inline float EaseExponentialIn(float step) + inline Float32 EaseExponentialIn(Float32 step) { return math::Pow(2.f, 10 * (step - 1)); } - inline float EaseExponentialOut(float step) + inline Float32 EaseExponentialOut(Float32 step) { return 1.f - math::Pow(2.f, -10 * step); } - inline float EaseExponentialInOut(float step) + inline Float32 EaseExponentialInOut(Float32 step) { if (step < .5f) return .5f * math::Pow(2.f, 10 * (2 * step - 1)); @@ -73,7 +73,7 @@ namespace kiwano // Bounce Ease - inline float EaseBounceOut(float step) + inline Float32 EaseBounceOut(Float32 step) { if (step < 1 / 2.75f) { @@ -94,12 +94,12 @@ namespace kiwano return 7.5625f * step * step + 0.984375f; } - inline float EaseBounceIn(float step) + inline Float32 EaseBounceIn(Float32 step) { return 1 - EaseBounceOut(1 - step); } - inline float EaseBounceInOut(float step) + inline Float32 EaseBounceInOut(Float32 step) { if (step < 0.5f) { @@ -114,7 +114,7 @@ namespace kiwano // Elastic Ease - inline float EaseElasticIn(float step, float period) + inline Float32 EaseElasticIn(Float32 step, Float32 period) { if (step == 0 || step == 1) return step; @@ -123,7 +123,7 @@ namespace kiwano return -math::Pow(2, 10 * step) * math::Sin((step - period / 4) * 360.f / period); } - inline float EaseElasticOut(float step, float period) + inline Float32 EaseElasticOut(Float32 step, Float32 period) { if (step == 0 || step == 1) return step; @@ -131,7 +131,7 @@ namespace kiwano return math::Pow(2, -10 * step) * math::Sin((step - period / 4) * 360.f / period) + 1; } - inline float EaseElasticInOut(float step, float period) + inline Float32 EaseElasticInOut(Float32 step, Float32 period) { if (step == 0 || step == 1) return step; @@ -147,22 +147,22 @@ namespace kiwano // Back Ease - inline float EaseBackIn(float step) + inline Float32 EaseBackIn(Float32 step) { - const float overshoot = 1.70158f; + const Float32 overshoot = 1.70158f; return step * step * ((overshoot + 1) * step - overshoot); } - inline float EaseBackOut(float step) + inline Float32 EaseBackOut(Float32 step) { - const float overshoot = 1.70158f; + const Float32 overshoot = 1.70158f; step = step - 1; return step * step * ((overshoot + 1) * step + overshoot) + 1; } - inline float EaseBackInOut(float step) + inline Float32 EaseBackInOut(Float32 step) { - const float overshoot = 1.70158f * 1.525f; + const Float32 overshoot = 1.70158f * 1.525f; step = step * 2; if (step < 1) @@ -177,17 +177,17 @@ namespace kiwano // Sine Ease - inline float EaseSineIn(float step) + inline Float32 EaseSineIn(Float32 step) { return 1.f - math::Cos(step * 90); } - inline float EaseSineOut(float step) + inline Float32 EaseSineOut(Float32 step) { return math::Sin(step * 90); } - inline float EaseSineInOut(float step) + inline Float32 EaseSineInOut(Float32 step) { return -0.5f * (math::Cos(step * 180) - 1); } @@ -195,17 +195,17 @@ namespace kiwano // Quad Ease - inline float EaseQuadIn(float step) + inline Float32 EaseQuadIn(Float32 step) { return step * step; } - inline float EaseQuadOut(float step) + inline Float32 EaseQuadOut(Float32 step) { return -1 * step * (step - 2); } - inline float EaseQuadInOut(float step) + inline Float32 EaseQuadInOut(Float32 step) { step = step * 2; if (step < 1) @@ -217,18 +217,18 @@ namespace kiwano // Cubic Ease - inline float EaseCubicIn(float step) + inline Float32 EaseCubicIn(Float32 step) { return step * step * step; } - inline float EaseCubicOut(float step) + inline Float32 EaseCubicOut(Float32 step) { step -= 1; return (step * step * step + 1); } - inline float EaseCubicInOut(float step) + inline Float32 EaseCubicInOut(Float32 step) { step = step * 2; if (step < 1) @@ -240,18 +240,18 @@ namespace kiwano // Quart Ease - inline float EaseQuartIn(float step) + inline Float32 EaseQuartIn(Float32 step) { return step * step * step * step; } - inline float EaseQuartOut(float step) + inline Float32 EaseQuartOut(Float32 step) { step -= 1; return -(step * step * step * step - 1); } - inline float EaseQuartInOut(float step) + inline Float32 EaseQuartInOut(Float32 step) { step = step * 2; if (step < 1) @@ -263,18 +263,18 @@ namespace kiwano // Quint Ease - inline float EaseQuintIn(float step) + inline Float32 EaseQuintIn(Float32 step) { return step * step * step * step * step; } - inline float EaseQuintOut(float step) + inline Float32 EaseQuintOut(Float32 step) { step -= 1; return (step * step * step * step * step + 1); } - inline float EaseQuintInOut(float step) + inline Float32 EaseQuintInOut(Float32 step) { step = step * 2; if (step < 1) diff --git a/src/kiwano/math/rand.h b/src/kiwano/math/rand.h index 1547c5bb..eb356c89 100644 --- a/src/kiwano/math/rand.h +++ b/src/kiwano/math/rand.h @@ -29,14 +29,14 @@ namespace kiwano // 随机数 // // 获取指定范围内的一个随机数, 如: - // int n = math::Rand(1, 5); // 获取 1~5 内的随机整数, 包含 1 和 5 + // Int32 n = math::Rand(1, 5); // 获取 1~5 内的随机整数, 包含 1 和 5 // 产生的随机数类型取决于参数的类型, 如获取随机浮点数: - // double d = math::Rand(1.2, 1.5); + // Float64 d = math::Rand(1.2, 1.5); // - int Rand(int min, int max); + Int32 Rand(Int32 min, Int32 max); - unsigned int Rand(unsigned int min, unsigned int max); + UInt32 Rand(UInt32 min, UInt32 max); long Rand(long min, long max); @@ -44,11 +44,11 @@ namespace kiwano char Rand(char min, char max); - unsigned char Rand(unsigned char min, unsigned char max); + UChar Rand(UChar min, UChar max); - float Rand(float min, float max); + Float32 Rand(Float32 min, Float32 max); - double Rand(double min, double max); + Float64 Rand(Float64 min, Float64 max); // @@ -79,12 +79,12 @@ namespace kiwano } } - inline int Rand(int min, int max) + inline Int32 Rand(Int32 min, Int32 max) { return __rand_detail::RandomInt(min, max); } - inline unsigned int Rand(unsigned int min, unsigned int max) + inline UInt32 Rand(UInt32 min, UInt32 max) { return __rand_detail::RandomInt(min, max); } @@ -102,23 +102,23 @@ namespace kiwano inline char Rand(char min, char max) { return static_cast( - __rand_detail::RandomInt(static_cast(min), static_cast(max)) + __rand_detail::RandomInt(static_cast(min), static_cast(max)) ); } - inline unsigned char Rand(unsigned char min, unsigned char max) + inline UChar Rand(UChar min, UChar max) { - return static_cast( - __rand_detail::RandomInt(static_cast(min), static_cast(max)) + return static_cast( + __rand_detail::RandomInt(static_cast(min), static_cast(max)) ); } - inline float Rand(float min, float max) + inline Float32 Rand(Float32 min, Float32 max) { return __rand_detail::RandomReal(min, max); } - inline double Rand(double min, double max) + inline Float64 Rand(Float64 min, Float64 max) { return __rand_detail::RandomReal(min, max); } diff --git a/src/kiwano/math/scalar.hpp b/src/kiwano/math/scalar.hpp index f41a8027..ef62cb95 100644 --- a/src/kiwano/math/scalar.hpp +++ b/src/kiwano/math/scalar.hpp @@ -27,56 +27,56 @@ namespace kiwano { namespace math { - inline int Abs(int val) { return ::abs(val); } + inline Int32 Abs(Int32 val) { return ::abs(val); } - inline float Abs(float val) { return ::fabsf(val); } + inline Float32 Abs(Float32 val) { return ::fabsf(val); } - inline double Abs(double val) { return ::fabs(val); } + inline Float64 Abs(Float64 val) { return ::fabs(val); } - inline float Sqrt(float val) { return ::sqrtf(val); } + inline Float32 Sqrt(Float32 val) { return ::sqrtf(val); } - inline double Sqrt(double val) { return ::sqrt(val); } + inline Float64 Sqrt(Float64 val) { return ::sqrt(val); } - inline float Pow(float base, float exponent) { return ::powf(base, exponent); } + inline Float32 Pow(Float32 base, Float32 exponent) { return ::powf(base, exponent); } - inline double Pow(double base, double exponent) { return ::pow(base, exponent); } + inline Float64 Pow(Float64 base, Float64 exponent) { return ::pow(base, exponent); } - inline int Sign(int val) { return val < 0 ? -1 : 1; } + inline Int32 Sign(Int32 val) { return val < 0 ? -1 : 1; } - inline float Sign(float val) { return val < 0 ? -1.f : 1.f; } + inline Float32 Sign(Float32 val) { return val < 0 ? -1.f : 1.f; } - inline double Sign(double val) { return val < 0 ? -1.0 : 1.0; } + inline Float64 Sign(Float64 val) { return val < 0 ? -1.0 : 1.0; } - inline float Sin(float val) { return ::sinf(val * constants::PI_F / 180.f); } + inline Float32 Sin(Float32 val) { return ::sinf(val * constants::PI_F / 180.f); } - inline double Sin(double val) { return ::sin(val * constants::PI_D / 180.0); } + inline Float64 Sin(Float64 val) { return ::sin(val * constants::PI_D / 180.0); } - inline float Cos(float val) { return ::cosf(val * constants::PI_F / 180.f); } + inline Float32 Cos(Float32 val) { return ::cosf(val * constants::PI_F / 180.f); } - inline double Cos(double val) { return ::cos(val * constants::PI_D / 180.0); } + inline Float64 Cos(Float64 val) { return ::cos(val * constants::PI_D / 180.0); } - inline float Tan(float val) { return ::tanf(val * constants::PI_F / 180.f); } + inline Float32 Tan(Float32 val) { return ::tanf(val * constants::PI_F / 180.f); } - inline double Tan(double val) { return ::tan(val * constants::PI_D / 180.0); } + inline Float64 Tan(Float64 val) { return ::tan(val * constants::PI_D / 180.0); } - inline float Asin(float val) { return ::asinf(val) * 180.f / constants::PI_F; } + inline Float32 Asin(Float32 val) { return ::asinf(val) * 180.f / constants::PI_F; } - inline double Asin(double val) { return ::asin(val) * 180.f / constants::PI_F; } + inline Float64 Asin(Float64 val) { return ::asin(val) * 180.f / constants::PI_F; } - inline float Acos(float val) { return ::acosf(val) * 180.f / constants::PI_F; } + inline Float32 Acos(Float32 val) { return ::acosf(val) * 180.f / constants::PI_F; } - inline double Acos(double val) { return ::acos(val) * 180.f / constants::PI_F; } + inline Float64 Acos(Float64 val) { return ::acos(val) * 180.f / constants::PI_F; } - inline float Atan(float val) { return ::atanf(val) * 180.f / constants::PI_F; } + inline Float32 Atan(Float32 val) { return ::atanf(val) * 180.f / constants::PI_F; } - inline double Atan(double val) { return ::atan(val) * 180.f / constants::PI_F; } + inline Float64 Atan(Float64 val) { return ::atan(val) * 180.f / constants::PI_F; } - inline float Ceil(float val) { return ::ceil(val); } + inline Float32 Ceil(Float32 val) { return ::ceil(val); } - inline double Ceil(double val) { return ::ceil(val); } + inline Float64 Ceil(Float64 val) { return ::ceil(val); } - inline float Floor(float val) { return ::floor(val); } + inline Float32 Floor(Float32 val) { return ::floor(val); } - inline double Floor(double val) { return ::floor(val); } + inline Float64 Floor(Float64 val) { return ::floor(val); } } } diff --git a/src/kiwano/platform/Application.cpp b/src/kiwano/platform/Application.cpp index 31f2997c..0fe4bd50 100644 --- a/src/kiwano/platform/Application.cpp +++ b/src/kiwano/platform/Application.cpp @@ -43,7 +43,7 @@ namespace kiwano Queue functions_to_perform_; } - Options::Options(String const& title, int width, int height, LPCWSTR icon, Color clear_color, bool vsync, bool fullscreen, bool debug) + Options::Options(String const& title, Int32 width, Int32 height, LPCWSTR icon, Color clear_color, bool vsync, bool fullscreen, bool debug) : title(title) , width(width) , height(height) @@ -205,7 +205,7 @@ namespace kiwano } } - void Application::SetTimeScale(float scale_factor) + void Application::SetTimeScale(Float32 scale_factor) { time_scale_ = scale_factor; } @@ -295,7 +295,7 @@ namespace kiwano functions_to_perform_.push(Function); } - LRESULT CALLBACK Application::WndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) + LRESULT CALLBACK Application::WndProc(HWND hwnd, UInt32 msg, WPARAM wparam, LPARAM lparam) { Application * app = reinterpret_cast(static_cast(::GetWindowLongPtrW(hwnd, GWLP_USERDATA))); @@ -327,8 +327,8 @@ namespace kiwano { bool down = msg == WM_KEYDOWN || msg == WM_SYSKEYDOWN; Event evt(down ? Event::KeyDown : Event::KeyUp); - evt.key.code = static_cast(wparam); - evt.key.count = static_cast(lparam & 0xFF); + evt.key.code = static_cast(wparam); + evt.key.count = static_cast(lparam & 0xFF); app->DispatchEvent(evt); } @@ -338,7 +338,7 @@ namespace kiwano { Event evt(Event::Char); evt.key.c = static_cast(wparam); - evt.key.count = static_cast(lparam & 0xFF); + evt.key.count = static_cast(lparam & 0xFF); app->DispatchEvent(evt); } @@ -358,15 +358,15 @@ namespace kiwano { Event evt; - evt.mouse.x = static_cast(GET_X_LPARAM(lparam)); - evt.mouse.y = static_cast(GET_Y_LPARAM(lparam)); + evt.mouse.x = static_cast(GET_X_LPARAM(lparam)); + evt.mouse.y = static_cast(GET_Y_LPARAM(lparam)); evt.mouse.left_btn_down = !!(wparam & MK_LBUTTON); evt.mouse.left_btn_down = !!(wparam & MK_RBUTTON); if (msg == WM_MOUSEMOVE) { evt.type = Event::MouseMove; } else if (msg == WM_LBUTTONDOWN || msg == WM_RBUTTONDOWN || msg == WM_MBUTTONDOWN) { evt.type = Event::MouseBtnDown; } else if (msg == WM_LBUTTONUP || msg == WM_RBUTTONUP || msg == WM_MBUTTONUP) { evt.type = Event::MouseBtnUp; } - else if (msg == WM_MOUSEWHEEL) { evt.type = Event::MouseWheel; evt.mouse.wheel = GET_WHEEL_DELTA_WPARAM(wparam) / (float)WHEEL_DELTA; } + else if (msg == WM_MOUSEWHEEL) { evt.type = Event::MouseWheel; evt.mouse.wheel = GET_WHEEL_DELTA_WPARAM(wparam) / (Float32)WHEEL_DELTA; } if (msg == WM_LBUTTONDOWN || msg == WM_LBUTTONUP) { evt.mouse.button = MouseButton::Left; } else if (msg == WM_RBUTTONDOWN || msg == WM_RBUTTONUP) { evt.mouse.button = MouseButton::Right; } @@ -398,8 +398,8 @@ namespace kiwano case WM_MOVE: { - int x = (int)(short)LOWORD(lparam); - int y = (int)(short)HIWORD(lparam); + Int32 x = (Int32)(short)LOWORD(lparam); + Int32 y = (Int32)(short)HIWORD(lparam); Event evt(Event::WindowMoved); evt.win.x = x; @@ -425,7 +425,7 @@ namespace kiwano KGE_LOG(L"Window title changed"); Event evt(Event::WindowTitleChanged); - evt.win.title = reinterpret_cast(lparam); + evt.win.title = reinterpret_cast(lparam); app->DispatchEvent(evt); } break; diff --git a/src/kiwano/platform/Application.h b/src/kiwano/platform/Application.h index bb8804ee..d42cb0b0 100644 --- a/src/kiwano/platform/Application.h +++ b/src/kiwano/platform/Application.h @@ -30,8 +30,8 @@ namespace kiwano struct Options { String title; // 标题 - int width; // 宽度 - int height; // 高度 + Int32 width; // 宽度 + Int32 height; // 高度 LPCWSTR icon; // 图标 Color clear_color; // 清屏颜色 bool vsync; // 垂直同步 @@ -40,8 +40,8 @@ namespace kiwano Options( String const& title = L"Kiwano Game", - int width = 640, - int height = 480, + Int32 width = 640, + Int32 height = 480, LPCWSTR icon = nullptr, Color clear_color = Color::Black, bool vsync = true, @@ -95,7 +95,7 @@ namespace kiwano // 设置时间缩放因子 void SetTimeScale( - float scale_factor + Float32 scale_factor ); // 分发事件 @@ -112,12 +112,12 @@ namespace kiwano void Update(); - static LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); + static LRESULT CALLBACK WndProc(HWND, UInt32, WPARAM, LPARAM); protected: bool end_; bool inited_; - float time_scale_; + Float32 time_scale_; Vector components_; }; diff --git a/src/kiwano/renderer/Color.cpp b/src/kiwano/renderer/Color.cpp index a6de069d..5c35a0e7 100644 --- a/src/kiwano/renderer/Color.cpp +++ b/src/kiwano/renderer/Color.cpp @@ -24,13 +24,13 @@ namespace kiwano { namespace { - const unsigned int RED_SHIFT = 16; - const unsigned int GREEN_SHIFT = 8; - const unsigned int BLUE_SHIFT = 0; + const UInt32 RED_SHIFT = 16; + const UInt32 GREEN_SHIFT = 8; + const UInt32 BLUE_SHIFT = 0; - const unsigned int RED_MASK = 0xff << RED_SHIFT; - const unsigned int GREEN_MASK = 0xff << GREEN_SHIFT; - const unsigned int BLUE_MASK = 0xff << BLUE_SHIFT; + const UInt32 RED_MASK = 0xff << RED_SHIFT; + const UInt32 GREEN_MASK = 0xff << GREEN_SHIFT; + const UInt32 BLUE_MASK = 0xff << BLUE_SHIFT; } Color::Color() @@ -41,7 +41,7 @@ namespace kiwano { } - Color::Color(float r, float g, float b) + Color::Color(Float32 r, Float32 g, Float32 b) : r(r) , g(g) , b(b) @@ -49,7 +49,7 @@ namespace kiwano { } - Color::Color(float r, float g, float b, float alpha) + Color::Color(Float32 r, Float32 g, Float32 b, Float32 alpha) : r(r) , g(g) , b(b) @@ -57,7 +57,7 @@ namespace kiwano { } - Color::Color(unsigned int rgb) + Color::Color(UInt32 rgb) : r(((rgb & RED_MASK) >> RED_SHIFT) / 255.f) , g(((rgb & GREEN_MASK) >> GREEN_SHIFT) / 255.f) , b(((rgb & BLUE_MASK) >> BLUE_SHIFT) / 255.f) @@ -65,7 +65,7 @@ namespace kiwano { } - Color::Color(unsigned int rgb, float alpha) + Color::Color(UInt32 rgb, Float32 alpha) : r(((rgb & RED_MASK) >> RED_SHIFT) / 255.f) , g(((rgb & GREEN_MASK) >> GREEN_SHIFT) / 255.f) , b(((rgb & BLUE_MASK) >> BLUE_SHIFT) / 255.f) diff --git a/src/kiwano/renderer/Color.h b/src/kiwano/renderer/Color.h index 717eec07..6761b9e6 100644 --- a/src/kiwano/renderer/Color.h +++ b/src/kiwano/renderer/Color.h @@ -20,6 +20,7 @@ #pragma once #include "../macros.h" +#include "../core/core.h" namespace kiwano { @@ -28,7 +29,7 @@ namespace kiwano // 使用枚举表示颜色: Color blue = Color::Blue; // 使用 RGB 表示一个颜色: Color red(1.0f, 0.0f, 0.0f); // 使用 RGBA 表示一个带透明度的颜色: Color not_black(1.0f, 1.0f, 1.0f, 0.5f); - // 使用一个 unsigned int 类型的值表示 RGB: Color black(0x000000); + // 使用一个 UInt32 类型的值表示 RGB: Color black(0x000000); // class KGE_API Color { @@ -36,29 +37,29 @@ namespace kiwano Color(); Color( - float r, - float g, - float b + Float32 r, + Float32 g, + Float32 b ); Color( - float r, - float g, - float b, - float alpha + Float32 r, + Float32 g, + Float32 b, + Float32 alpha ); Color( - unsigned int rgb + UInt32 rgb ); Color( - unsigned int rgb, - float alpha + UInt32 rgb, + Float32 alpha ); public: - enum Value : unsigned int + enum Value : UInt32 { Black = 0x000000, Blue = 0x0000FF, @@ -102,9 +103,9 @@ namespace kiwano }; public: - float r; - float g; - float b; - float a; + Float32 r; + Float32 g; + Float32 b; + Float32 a; }; } diff --git a/src/kiwano/renderer/Font.cpp b/src/kiwano/renderer/Font.cpp index 1c0016c3..24958349 100644 --- a/src/kiwano/renderer/Font.cpp +++ b/src/kiwano/renderer/Font.cpp @@ -22,7 +22,7 @@ namespace kiwano { - Font::Font(const String& family, float size, unsigned int weight, bool italic, FontCollection collection) + Font::Font(const String& family, Float32 size, UInt32 weight, bool italic, FontCollection collection) : family(family) , size(size) , weight(weight) diff --git a/src/kiwano/renderer/Font.h b/src/kiwano/renderer/Font.h index f389df68..d9e01df1 100644 --- a/src/kiwano/renderer/Font.h +++ b/src/kiwano/renderer/Font.h @@ -24,7 +24,7 @@ namespace kiwano { // 字体粗细值 - enum FontWeight : unsigned int + enum FontWeight : UInt32 { Thin = 100, ExtraLight = 200, @@ -42,16 +42,16 @@ namespace kiwano { public: String family; // 字体族 - float size; // 字号 - unsigned int weight; // 粗细值 + Float32 size; // 字号 + UInt32 weight; // 粗细值 bool italic; // 是否斜体 FontCollection collection; // 字体集 public: Font( const String& family = L"", - float size = 18, - unsigned int weight = FontWeight::Normal, + Float32 size = 18, + UInt32 weight = FontWeight::Normal, bool italic = false, FontCollection collection = FontCollection() ); diff --git a/src/kiwano/renderer/Geometry.cpp b/src/kiwano/renderer/Geometry.cpp index f56de2ce..0d211b87 100644 --- a/src/kiwano/renderer/Geometry.cpp +++ b/src/kiwano/renderer/Geometry.cpp @@ -49,9 +49,9 @@ namespace kiwano return Rect{ rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top }; } - float Geometry::GetLength() + Float32 Geometry::GetLength() { - float length = 0.f; + Float32 length = 0.f; if (geo_) { // no matter it failed or not @@ -60,7 +60,7 @@ namespace kiwano return length; } - bool Geometry::ComputePointAtLength(float length, Point& point, Vec2& tangent) + bool Geometry::ComputePointAtLength(Float32 length, Point& point, Vec2& tangent) { if (geo_) { @@ -108,7 +108,7 @@ namespace kiwano sink.Init(); sink.OpenSink(); - for (size_t i = 0; i < geos.size() - 1; i++) + for (UInt32 i = 0; i < geos.size() - 1; i++) { CombineMode mode = (modes.size() == 1) ? modes[0] : modes[i]; const Matrix3x2& matrix = (matrixs.size() == 1) ? matrixs[0] : matrixs[i]; @@ -129,12 +129,12 @@ namespace kiwano return Geometry(); } - float Geometry::ComputeArea() + Float32 Geometry::ComputeArea() { if (!geo_) return 0.f; - float area = 0.f; + Float32 area = 0.f; // no matter it failed or not geo_->ComputeArea(D2D1::Matrix3x2F::Identity(), &area); return area; @@ -176,7 +176,7 @@ namespace kiwano return output; } - Geometry Geometry::CreateCircle(Point const& center, float radius) + Geometry Geometry::CreateCircle(Point const& center, Float32 radius) { Geometry output; Renderer::GetInstance()->CreateEllipseGeometry(output, center, Vec2{ radius, radius }); @@ -236,7 +236,7 @@ namespace kiwano sink_->AddLines( reinterpret_cast(&points[0]), - static_cast(points.size()) + static_cast(points.size()) ); return (*this); } @@ -255,7 +255,7 @@ namespace kiwano return (*this); } - GeometrySink& GeometrySink::AddArc(Point const& point, Size const& radius, float rotation, bool clockwise, bool is_small) + GeometrySink& GeometrySink::AddArc(Point const& point, Size const& radius, Float32 rotation, bool clockwise, bool is_small) { if (!sink_) BeginPath(); diff --git a/src/kiwano/renderer/Geometry.h b/src/kiwano/renderer/Geometry.h index be611d73..961d340a 100644 --- a/src/kiwano/renderer/Geometry.h +++ b/src/kiwano/renderer/Geometry.h @@ -53,14 +53,14 @@ namespace kiwano ); // 获取图形展开成一条直线的长度 - float GetLength(); + Float32 GetLength(); // 计算面积 - float ComputeArea(); + Float32 ComputeArea(); // 计算图形路径上点的位置和切线向量 bool ComputePointAtLength( - float length, + Float32 length, Point& point, Vec2& tangent ); @@ -100,7 +100,7 @@ namespace kiwano // 创建圆形 static Geometry CreateCircle( Point const& center, - float radius + Float32 radius ); // 创建椭圆形 @@ -159,7 +159,7 @@ namespace kiwano GeometrySink& AddArc( Point const& point, /* 终点 */ Size const& radius, /* 椭圆半径 */ - float rotation, /* 椭圆旋转角度 */ + Float32 rotation, /* 椭圆旋转角度 */ bool clockwise = true, /* 顺时针 or 逆时针 */ bool is_small = true /* 是否取小于 180° 的弧 */ ); diff --git a/src/kiwano/renderer/GifImage.cpp b/src/kiwano/renderer/GifImage.cpp index a057a663..e4b6655e 100644 --- a/src/kiwano/renderer/GifImage.cpp +++ b/src/kiwano/renderer/GifImage.cpp @@ -82,8 +82,8 @@ namespace kiwano HRESULT GifImage::GetGlobalMetadata() { - unsigned int width = 0; - unsigned int height = 0; + UInt32 width = 0; + UInt32 height = 0; PROPVARIANT prop_val; ::PropVariantInit(&prop_val); @@ -160,17 +160,17 @@ namespace kiwano { // 需要计算比率 // 最高像素 1:4,最宽像素 4:1,增量为 1/64 - float pixel_asp_ratio = (prop_val.bVal + 15.f) / 64.f; + Float32 pixel_asp_ratio = (prop_val.bVal + 15.f) / 64.f; // 根据像素长宽比计算像素中的图像宽度和高度,只缩小图像 if (pixel_asp_ratio > 1.f) { width_in_pixels_ = width; - height_in_pixels_ = static_cast(height / pixel_asp_ratio); + height_in_pixels_ = static_cast(height / pixel_asp_ratio); } else { - width_in_pixels_ = static_cast(width * pixel_asp_ratio); + width_in_pixels_ = static_cast(width * pixel_asp_ratio); height_in_pixels_ = height; } } @@ -193,7 +193,7 @@ namespace kiwano { BYTE bg_index = 0; WICColor bgcolors[256]; - UINT colors_copied = 0; + UInt32 colors_copied = 0; ComPtr wic_palette; PROPVARIANT prop_val; @@ -249,13 +249,13 @@ namespace kiwano if (SUCCEEDED(hr)) { // 转换为 ARGB 格式 - float alpha = (bgcolors[bg_index] >> 24) / 255.f; + Float32 alpha = (bgcolors[bg_index] >> 24) / 255.f; bg_color_ = Color(bgcolors[bg_index], alpha); } return hr; } - HRESULT GifImage::GetRawFrame(UINT frame_index, Image& raw_frame, Rect& frame_rect, Duration& delay, DisposalType& disposal_type) + HRESULT GifImage::GetRawFrame(UInt32 frame_index, Image& raw_frame, Rect& frame_rect, Duration& delay, DisposalType& disposal_type) { ComPtr converter; ComPtr wic_frame; @@ -317,7 +317,7 @@ namespace kiwano hr = (prop_val.vt == VT_UI2 ? S_OK : E_FAIL); if (SUCCEEDED(hr)) { - frame_rect.origin.x = static_cast(prop_val.uiVal); + frame_rect.origin.x = static_cast(prop_val.uiVal); } PropVariantClear(&prop_val); } @@ -331,7 +331,7 @@ namespace kiwano hr = (prop_val.vt == VT_UI2 ? S_OK : E_FAIL); if (SUCCEEDED(hr)) { - frame_rect.origin.y = static_cast(prop_val.uiVal); + frame_rect.origin.y = static_cast(prop_val.uiVal); } PropVariantClear(&prop_val); } @@ -345,7 +345,7 @@ namespace kiwano hr = (prop_val.vt == VT_UI2 ? S_OK : E_FAIL); if (SUCCEEDED(hr)) { - frame_rect.size.x = static_cast(prop_val.uiVal); + frame_rect.size.x = static_cast(prop_val.uiVal); } PropVariantClear(&prop_val); } @@ -359,7 +359,7 @@ namespace kiwano hr = (prop_val.vt == VT_UI2 ? S_OK : E_FAIL); if (SUCCEEDED(hr)) { - frame_rect.size.y = static_cast(prop_val.uiVal); + frame_rect.size.y = static_cast(prop_val.uiVal); } PropVariantClear(&prop_val); } @@ -375,7 +375,7 @@ namespace kiwano if (SUCCEEDED(hr)) { - UINT udelay = 0; + UInt32 udelay = 0; hr = UIntMult(prop_val.uiVal, 10, &udelay); if (SUCCEEDED(hr)) { diff --git a/src/kiwano/renderer/GifImage.h b/src/kiwano/renderer/GifImage.h index 30538924..1e05bc38 100644 --- a/src/kiwano/renderer/GifImage.h +++ b/src/kiwano/renderer/GifImage.h @@ -39,11 +39,11 @@ namespace kiwano bool IsValid() const; - inline UINT GetWidthInPixels() const { return width_in_pixels_; } + inline UInt32 GetWidthInPixels() const { return width_in_pixels_; } - inline UINT GetHeightInPixels() const { return height_in_pixels_; } + inline UInt32 GetHeightInPixels() const { return height_in_pixels_; } - inline UINT GetFramesCount() const { return frames_count_; } + inline UInt32 GetFramesCount() const { return frames_count_; } inline Color GetBackgroundColor() const { return bg_color_; } @@ -57,7 +57,7 @@ namespace kiwano }; HRESULT GetRawFrame( - UINT frame_index, + UInt32 frame_index, Image& raw_frame, Rect& frame_rect, Duration& delay, @@ -76,9 +76,9 @@ namespace kiwano ); protected: - UINT frames_count_; - UINT width_in_pixels_; - UINT height_in_pixels_; + UInt32 frames_count_; + UInt32 width_in_pixels_; + UInt32 height_in_pixels_; Color bg_color_; ComPtr decoder_; diff --git a/src/kiwano/renderer/Image.cpp b/src/kiwano/renderer/Image.cpp index ef001ad6..39d9f253 100644 --- a/src/kiwano/renderer/Image.cpp +++ b/src/kiwano/renderer/Image.cpp @@ -64,7 +64,7 @@ namespace kiwano return bitmap_ != nullptr; } - float Image::GetWidth() const + Float32 Image::GetWidth() const { if (bitmap_) { @@ -73,7 +73,7 @@ namespace kiwano return 0; } - float Image::GetHeight() const + Float32 Image::GetHeight() const { if (bitmap_) { @@ -92,7 +92,7 @@ namespace kiwano return Size{}; } - UINT32 Image::GetWidthInPixels() const + UInt32 Image::GetWidthInPixels() const { if (bitmap_) { @@ -101,7 +101,7 @@ namespace kiwano return 0; } - UINT32 Image::GetHeightInPixels() const + UInt32 Image::GetHeightInPixels() const { if (bitmap_) { @@ -110,14 +110,14 @@ namespace kiwano return 0; } - math::Vec2T Image::GetSizeInPixels() const + math::Vec2T Image::GetSizeInPixels() const { if (bitmap_) { auto bitmap_size = bitmap_->GetPixelSize(); - return math::Vec2T{ bitmap_size.width, bitmap_size.height }; + return math::Vec2T{ bitmap_size.width, bitmap_size.height }; } - return math::Vec2T{}; + return math::Vec2T{}; } void Image::CopyFrom(Image const& copy_from) @@ -135,13 +135,13 @@ namespace kiwano if (IsValid() && copy_from.IsValid()) { HRESULT hr = bitmap_->CopyFromBitmap( - &D2D1::Point2U(UINT(dest_point.x), UINT(dest_point.y)), + &D2D1::Point2U(UInt32(dest_point.x), UInt32(dest_point.y)), copy_from.GetBitmap().get(), &D2D1::RectU( - UINT(src_rect.GetLeft()), - UINT(src_rect.GetTop()), - UINT(src_rect.GetRight()), - UINT(src_rect.GetBottom())) + UInt32(src_rect.GetLeft()), + UInt32(src_rect.GetTop()), + UInt32(src_rect.GetRight()), + UInt32(src_rect.GetBottom())) ); ThrowIfFailed(hr); diff --git a/src/kiwano/renderer/Image.h b/src/kiwano/renderer/Image.h index ec3aa193..86900c60 100644 --- a/src/kiwano/renderer/Image.h +++ b/src/kiwano/renderer/Image.h @@ -57,22 +57,22 @@ namespace kiwano bool IsValid() const; // 获取位图宽度 - float GetWidth() const; + Float32 GetWidth() const; // 获取位图高度 - float GetHeight() const; + Float32 GetHeight() const; // 获取位图大小 Size GetSize() const; // 获取位图像素宽度 - UINT32 GetWidthInPixels() const; + UInt32 GetWidthInPixels() const; // 获取位图像素高度 - UINT32 GetHeightInPixels() const; + UInt32 GetHeightInPixels() const; // 获取位图像素大小 - math::Vec2T GetSizeInPixels() const; + math::Vec2T GetSizeInPixels() const; // 拷贝位图内存 void CopyFrom(Image const& copy_from); diff --git a/src/kiwano/renderer/ImageCache.cpp b/src/kiwano/renderer/ImageCache.cpp index 3437c6c4..7ec0ea39 100644 --- a/src/kiwano/renderer/ImageCache.cpp +++ b/src/kiwano/renderer/ImageCache.cpp @@ -25,7 +25,7 @@ namespace kiwano { template - _Ty CreateOrGetCache(_CacheTy& cache, _PathTy const& path, size_t hash) + _Ty CreateOrGetCache(_CacheTy& cache, _PathTy const& path, UInt32 hash) { auto iter = cache.find(hash); if (iter != cache.end()) @@ -42,7 +42,7 @@ namespace kiwano } template - void RemoveCache(_CacheTy& cache, size_t hash) + void RemoveCache(_CacheTy& cache, UInt32 hash) { auto iter = cache.find(hash); if (iter != cache.end()) diff --git a/src/kiwano/renderer/ImageCache.h b/src/kiwano/renderer/ImageCache.h index 25076f12..e4a07abe 100644 --- a/src/kiwano/renderer/ImageCache.h +++ b/src/kiwano/renderer/ImageCache.h @@ -48,10 +48,10 @@ namespace kiwano virtual ~ImageCache(); protected: - using ImageMap = UnorderedMap; + using ImageMap = UnorderedMap; ImageMap image_cache_; - using GifImageMap = UnorderedMap; + using GifImageMap = UnorderedMap; GifImageMap gif_image_cache_; }; } diff --git a/src/kiwano/renderer/LayerArea.h b/src/kiwano/renderer/LayerArea.h index 59122a2c..802e9960 100644 --- a/src/kiwano/renderer/LayerArea.h +++ b/src/kiwano/renderer/LayerArea.h @@ -37,9 +37,9 @@ namespace kiwano inline void SetAreaRect(Rect const& area) { area_ = area; } - inline float GetOpacity() const { return opacity_; } + inline Float32 GetOpacity() const { return opacity_; } - inline void SetOpacity(float opacity) { opacity_ = opacity; } + inline void SetOpacity(Float32 opacity) { opacity_ = opacity; } inline Geometry const& GetMaskGeometry() const { return mask_; } @@ -52,7 +52,7 @@ namespace kiwano protected: Rect area_; - float opacity_; + Float32 opacity_; Geometry mask_; ComPtr layer_; }; diff --git a/src/kiwano/renderer/RenderTarget.cpp b/src/kiwano/renderer/RenderTarget.cpp index 1403d109..af0557cf 100644 --- a/src/kiwano/renderer/RenderTarget.cpp +++ b/src/kiwano/renderer/RenderTarget.cpp @@ -106,7 +106,7 @@ namespace kiwano void RenderTarget::DrawGeometry( Geometry const& geometry, Color const& stroke_color, - float stroke_width, + Float32 stroke_width, StrokeStyle stroke ) const { @@ -153,7 +153,7 @@ namespace kiwano ThrowIfFailed(hr); } - void RenderTarget::DrawLine(Point const& point1, Point const& point2, Color const& stroke_color, float stroke_width, StrokeStyle stroke) const + void RenderTarget::DrawLine(Point const& point1, Point const& point2, Color const& stroke_color, Float32 stroke_width, StrokeStyle stroke) const { HRESULT hr = S_OK; if (!solid_color_brush_ || !render_target_) @@ -179,7 +179,7 @@ namespace kiwano ThrowIfFailed(hr); } - void RenderTarget::DrawRectangle(Rect const& rect, Color const& stroke_color, float stroke_width, StrokeStyle stroke) const + void RenderTarget::DrawRectangle(Rect const& rect, Color const& stroke_color, Float32 stroke_width, StrokeStyle stroke) const { HRESULT hr = S_OK; if (!solid_color_brush_ || !render_target_) @@ -224,7 +224,7 @@ namespace kiwano ThrowIfFailed(hr); } - void RenderTarget::DrawRoundedRectangle(Rect const& rect, Vec2 const& radius, Color const& stroke_color, float stroke_width, StrokeStyle stroke) const + void RenderTarget::DrawRoundedRectangle(Rect const& rect, Vec2 const& radius, Color const& stroke_color, Float32 stroke_width, StrokeStyle stroke) const { HRESULT hr = S_OK; if (!solid_color_brush_ || !render_target_) @@ -277,7 +277,7 @@ namespace kiwano ThrowIfFailed(hr); } - void RenderTarget::DrawEllipse(Point const& center, Vec2 const& radius, Color const& stroke_color, float stroke_width, StrokeStyle stroke) const + void RenderTarget::DrawEllipse(Point const& center, Vec2 const& radius, Color const& stroke_color, Float32 stroke_width, StrokeStyle stroke) const { HRESULT hr = S_OK; if (!solid_color_brush_ || !render_target_) @@ -516,7 +516,7 @@ namespace kiwano ThrowIfFailed(hr); } - float RenderTarget::GetOpacity() const + Float32 RenderTarget::GetOpacity() const { return opacity_; } @@ -537,7 +537,7 @@ namespace kiwano ThrowIfFailed(hr); } - void RenderTarget::SetOpacity(float opacity) + void RenderTarget::SetOpacity(Float32 opacity) { HRESULT hr = S_OK; if (!solid_color_brush_) diff --git a/src/kiwano/renderer/RenderTarget.h b/src/kiwano/renderer/RenderTarget.h index 308f8778..1582504c 100644 --- a/src/kiwano/renderer/RenderTarget.h +++ b/src/kiwano/renderer/RenderTarget.h @@ -44,7 +44,7 @@ namespace kiwano void DrawGeometry( Geometry const& geometry, Color const& stroke_color, - float stroke_width, + Float32 stroke_width, StrokeStyle stroke = StrokeStyle::Miter ) const; @@ -57,14 +57,14 @@ namespace kiwano Point const& point1, Point const& point2, Color const& stroke_color, - float stroke_width, + Float32 stroke_width, StrokeStyle stroke = StrokeStyle::Miter ) const; void DrawRectangle( Rect const& rect, Color const& stroke_color, - float stroke_width, + Float32 stroke_width, StrokeStyle stroke = StrokeStyle::Miter ) const; @@ -77,7 +77,7 @@ namespace kiwano Rect const& rect, Vec2 const& radius, Color const& stroke_color, - float stroke_width, + Float32 stroke_width, StrokeStyle stroke = StrokeStyle::Miter ) const; @@ -91,7 +91,7 @@ namespace kiwano Point const& center, Vec2 const& radius, Color const& stroke_color, - float stroke_width, + Float32 stroke_width, StrokeStyle stroke = StrokeStyle::Miter ) const; @@ -136,10 +136,10 @@ namespace kiwano Color const& clear_color ); - float GetOpacity() const; + Float32 GetOpacity() const; void SetOpacity( - float opacity + Float32 opacity ); void SetTransform( @@ -159,7 +159,7 @@ namespace kiwano public: struct Status { - int primitives; + Int32 primitives; Time start; Duration duration; }; @@ -183,7 +183,7 @@ namespace kiwano bool IsValid() const; protected: - float opacity_; + Float32 opacity_; bool antialias_; mutable bool collecting_status_; mutable Status status_; diff --git a/src/kiwano/renderer/Renderer.cpp b/src/kiwano/renderer/Renderer.cpp index 74bb8f18..d63623f7 100644 --- a/src/kiwano/renderer/Renderer.cpp +++ b/src/kiwano/renderer/Renderer.cpp @@ -191,14 +191,14 @@ namespace kiwano ThrowIfFailed(hr); } - void Renderer::HandleMessage(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) + void Renderer::HandleMessage(HWND hwnd, UInt32 msg, WPARAM wparam, LPARAM lparam) { switch (msg) { case WM_SIZE: { - UINT width = LOWORD(lparam); - UINT height = HIWORD(lparam); + UInt32 width = LOWORD(lparam); + UInt32 height = HIWORD(lparam); Resize(width, height); break; @@ -390,7 +390,7 @@ namespace kiwano if (SUCCEEDED(hr)) { LPVOID collection_key = nullptr; - UINT32 collection_key_size = 0; + UInt32 collection_key_size = 0; hr = font_collection_loader_->AddFilePaths(file_paths, &collection_key, &collection_key_size); @@ -428,7 +428,7 @@ namespace kiwano if (SUCCEEDED(hr)) { LPVOID collection_key = nullptr; - UINT32 collection_key_size = 0; + UInt32 collection_key_size = 0; hr = res_font_collection_loader_->AddResources(res_arr, &collection_key, &collection_key_size); @@ -667,7 +667,7 @@ namespace kiwano vsync_ = enabled; } - void Renderer::Resize(UINT width, UINT height) + void Renderer::Resize(UInt32 width, UInt32 height) { HRESULT hr = S_OK; if (!d3d_res_) @@ -677,8 +677,8 @@ namespace kiwano if (SUCCEEDED(hr)) { - output_size_.x = static_cast(width); - output_size_.y = static_cast(height); + output_size_.x = static_cast(width); + output_size_.y = static_cast(height); hr = d3d_res_->SetLogicalSize(output_size_); } diff --git a/src/kiwano/renderer/Renderer.h b/src/kiwano/renderer/Renderer.h index a0fc0d39..b28fcab5 100644 --- a/src/kiwano/renderer/Renderer.h +++ b/src/kiwano/renderer/Renderer.h @@ -132,8 +132,8 @@ namespace kiwano ); void Resize( - UINT width, - UINT height + UInt32 width, + UInt32 height ); bool CheckVisibility( @@ -150,7 +150,7 @@ namespace kiwano void AfterRender() override; - void HandleMessage(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) override; + void HandleMessage(HWND hwnd, UInt32 msg, WPARAM wparam, LPARAM lparam) override; public: inline HWND GetTargetWindow() const { return hwnd_; } diff --git a/src/kiwano/renderer/TextLayout.cpp b/src/kiwano/renderer/TextLayout.cpp index a18247d6..c4033479 100644 --- a/src/kiwano/renderer/TextLayout.cpp +++ b/src/kiwano/renderer/TextLayout.cpp @@ -81,7 +81,7 @@ namespace kiwano ); } - UINT32 TextLayout::GetLineCount() + UInt32 TextLayout::GetLineCount() { if (text_layout_) { diff --git a/src/kiwano/renderer/TextLayout.h b/src/kiwano/renderer/TextLayout.h index d6b23a92..f17ed2ca 100644 --- a/src/kiwano/renderer/TextLayout.h +++ b/src/kiwano/renderer/TextLayout.h @@ -56,7 +56,7 @@ namespace kiwano void Update(String const& text, TextStyle const& style); - UINT32 GetLineCount(); + UInt32 GetLineCount(); Size GetLayoutSize() const; diff --git a/src/kiwano/renderer/win32/ComPtr.hpp b/src/kiwano/renderer/win32/ComPtr.hpp index 10812639..72e80703 100644 --- a/src/kiwano/renderer/win32/ComPtr.hpp +++ b/src/kiwano/renderer/win32/ComPtr.hpp @@ -41,7 +41,7 @@ namespace kiwano // ComPtr<> is a smart pointer for COM template< typename _Ty, - typename = typename std::enable_if::value, int>::type> + typename = typename std::enable_if::value, Int32>::type> using ComPtr = intrusive_ptr<_Ty, ComPtrManager>; } diff --git a/src/kiwano/renderer/win32/D2DDeviceResources.cpp b/src/kiwano/renderer/win32/D2DDeviceResources.cpp index 9e5459f5..a4cf4834 100644 --- a/src/kiwano/renderer/win32/D2DDeviceResources.cpp +++ b/src/kiwano/renderer/win32/D2DDeviceResources.cpp @@ -84,7 +84,7 @@ namespace kiwano protected: unsigned long ref_count_; - float dpi_; + Float32 dpi_; ComPtr d2d_miter_stroke_style_; ComPtr d2d_bevel_stroke_style_; @@ -489,7 +489,7 @@ namespace kiwano HRESULT hr; ComPtr output; - UINT32 length = static_cast(text.length()); + UInt32 length = static_cast(text.length()); if (text_style.wrap_width > 0) { diff --git a/src/kiwano/renderer/win32/D2DDeviceResources.h b/src/kiwano/renderer/win32/D2DDeviceResources.h index c87bbfb6..52598120 100644 --- a/src/kiwano/renderer/win32/D2DDeviceResources.h +++ b/src/kiwano/renderer/win32/D2DDeviceResources.h @@ -157,9 +157,9 @@ namespace kiwano } // Converts a length in device-independent pixels (DIPs) to a length in physical pixels. - inline float ConvertDipsToPixels(float dips, float dpi) + inline Float32 ConvertDipsToPixels(Float32 dips, Float32 dpi) { - static const float dips_per_inch = 96.0f; + static const Float32 dips_per_inch = 96.0f; return math::Floor(dips * dpi / dips_per_inch + 0.5f); // Round to nearest integer. } } diff --git a/src/kiwano/renderer/win32/D3D10DeviceResources.cpp b/src/kiwano/renderer/win32/D3D10DeviceResources.cpp index ef5374d6..9278893c 100644 --- a/src/kiwano/renderer/win32/D3D10DeviceResources.cpp +++ b/src/kiwano/renderer/win32/D3D10DeviceResources.cpp @@ -29,7 +29,7 @@ namespace kiwano namespace DX { - HRESULT CreateD3DDevice(IDXGIAdapter *adapter, D3D10_DRIVER_TYPE driver_type, UINT flags, ID3D10Device1 **device) + HRESULT CreateD3DDevice(IDXGIAdapter *adapter, D3D10_DRIVER_TYPE driver_type, UInt32 flags, ID3D10Device1 **device) { HRESULT hr = S_OK; @@ -42,7 +42,7 @@ namespace kiwano D3D10_FEATURE_LEVEL_9_1, }; - for (UINT level = 0; level < ARRAYSIZE(levels); level++) + for (UInt32 level = 0; level < ARRAYSIZE(levels); level++) { hr = D3D10CreateDevice1( adapter, @@ -89,7 +89,7 @@ namespace kiwano HRESULT SetLogicalSize(Size logical_size); - HRESULT SetDpi(float dpi); + HRESULT SetDpi(Float32 dpi); void DiscardResources(); @@ -114,7 +114,7 @@ namespace kiwano public: HWND hwnd_; - float dpi_; + Float32 dpi_; Size logical_size_; Size output_size_; unsigned long ref_count_; @@ -127,7 +127,7 @@ namespace kiwano : ref_count_(0) , hwnd_(nullptr) { - dpi_ = 96.f; // dpi_ = (float)GetDpiForWindow(hwnd); + dpi_ = 96.f; // dpi_ = (Float32)GetDpiForWindow(hwnd); } D3D10DeviceResources::~D3D10DeviceResources() @@ -149,8 +149,8 @@ namespace kiwano res->hwnd_ = hwnd; res->d2d_res_ = d2d_device_res; - res->logical_size_.x = float(rc.right - rc.left); - res->logical_size_.y = float(rc.bottom - rc.top); + res->logical_size_.x = Float32(rc.right - rc.left); + res->logical_size_.y = Float32(rc.bottom - rc.top); hr = res->CreateDeviceResources(); @@ -193,7 +193,7 @@ namespace kiwano auto rt_view = rt_view_.get(); device_->OMSetRenderTargets(1, &rt_view, ds_view_.get()); - device_->ClearRenderTargetView(rt_view, reinterpret_cast(&clear_color)); + device_->ClearRenderTargetView(rt_view, reinterpret_cast(&clear_color)); return S_OK; } @@ -215,7 +215,7 @@ namespace kiwano // This flag adds support for surfaces with a different color channel ordering // than the API default. It is required for compatibility with Direct2D. - UINT creation_flags = D3D10_CREATE_DEVICE_BGRA_SUPPORT; + UInt32 creation_flags = D3D10_CREATE_DEVICE_BGRA_SUPPORT; #if defined(KGE_DEBUG) if (DX::SdkLayersAvailable()) @@ -383,8 +383,8 @@ namespace kiwano tex_desc.BindFlags = D3D10_BIND_DEPTH_STENCIL; tex_desc.CPUAccessFlags = 0; tex_desc.Format = DXGI_FORMAT_D16_UNORM; - tex_desc.Width = static_cast(output_size_.x); - tex_desc.Height = static_cast(output_size_.y); + tex_desc.Width = static_cast(output_size_.x); + tex_desc.Height = static_cast(output_size_.y); tex_desc.MipLevels = 1; tex_desc.MiscFlags = 0; tex_desc.SampleDesc.Count = 1; @@ -415,8 +415,8 @@ namespace kiwano { // Set a new viewport based on the new dimensions D3D10_VIEWPORT viewport; - viewport.Width = static_cast(output_size_.x); - viewport.Height = static_cast(output_size_.y); + viewport.Width = static_cast(output_size_.x); + viewport.Height = static_cast(output_size_.y); viewport.TopLeftX = 0; viewport.TopLeftY = 0; viewport.MinDepth = 0; @@ -478,7 +478,7 @@ namespace kiwano return S_OK; } - HRESULT D3D10DeviceResources::SetDpi(float dpi) + HRESULT D3D10DeviceResources::SetDpi(Float32 dpi) { if (dpi != dpi_) { @@ -487,8 +487,8 @@ namespace kiwano RECT rc; GetClientRect(hwnd_, &rc); - logical_size_.x = float(rc.right - rc.left); - logical_size_.y = float(rc.bottom - rc.top); + logical_size_.x = Float32(rc.right - rc.left); + logical_size_.y = Float32(rc.bottom - rc.top); d2d_res_->GetDeviceContext()->SetDpi(dpi_, dpi_); diff --git a/src/kiwano/renderer/win32/D3D11DeviceResources.cpp b/src/kiwano/renderer/win32/D3D11DeviceResources.cpp index 3eeadb82..801ce3bb 100644 --- a/src/kiwano/renderer/win32/D3D11DeviceResources.cpp +++ b/src/kiwano/renderer/win32/D3D11DeviceResources.cpp @@ -64,7 +64,7 @@ namespace kiwano HRESULT SetLogicalSize(Size logical_size) override; - HRESULT SetDpi(float dpi) override; + HRESULT SetDpi(Float32 dpi) override; void DiscardResources() override; @@ -89,7 +89,7 @@ namespace kiwano public: HWND hwnd_; - float dpi_; + Float32 dpi_; Size logical_size_; Size output_size_; unsigned long ref_count_; @@ -104,7 +104,7 @@ namespace kiwano , hwnd_(nullptr) , d3d_feature_level_(D3D_FEATURE_LEVEL_9_1) { - dpi_ = 96.f; // dpi_ = (float)GetDpiForWindow(hwnd); + dpi_ = 96.f; // dpi_ = (Float32)GetDpiForWindow(hwnd); } D3D11DeviceResources::~D3D11DeviceResources() @@ -126,8 +126,8 @@ namespace kiwano res->hwnd_ = hwnd; res->d2d_res_ = d2d_device_res; - res->logical_size_.x = float(rc.right - rc.left); - res->logical_size_.y = float(rc.bottom - rc.top); + res->logical_size_.x = Float32(rc.right - rc.left); + res->logical_size_.y = Float32(rc.bottom - rc.top); hr = res->CreateDeviceResources(); @@ -170,7 +170,7 @@ namespace kiwano auto rt_view = rt_view_.get(); device_context_->OMSetRenderTargets(1, &rt_view, ds_view_.get()); - device_context_->ClearRenderTargetView(rt_view, reinterpret_cast(&clear_color)); + device_context_->ClearRenderTargetView(rt_view, reinterpret_cast(&clear_color)); return S_OK; } @@ -207,7 +207,7 @@ namespace kiwano // This flag adds support for surfaces with a different color channel ordering // than the API default. It is required for compatibility with Direct2D. - UINT creation_flags = D3D11_CREATE_DEVICE_BGRA_SUPPORT; + UInt32 creation_flags = D3D11_CREATE_DEVICE_BGRA_SUPPORT; #if defined(KGE_DEBUG) if (DX::SdkLayersAvailable()) @@ -408,8 +408,8 @@ namespace kiwano CD3D11_TEXTURE2D_DESC tex_desc( DXGI_FORMAT_D24_UNORM_S8_UINT, - static_cast(output_size_.x), - static_cast(output_size_.y), + static_cast(output_size_.x), + static_cast(output_size_.y), 1, // This depth stencil view has only one texture. 1, // Use a single mipmap level. D3D11_BIND_DEPTH_STENCIL @@ -497,7 +497,7 @@ namespace kiwano return S_OK; } - HRESULT D3D11DeviceResources::SetDpi(float dpi) + HRESULT D3D11DeviceResources::SetDpi(Float32 dpi) { if (dpi != dpi_) { @@ -506,8 +506,8 @@ namespace kiwano RECT rc; GetClientRect(hwnd_, &rc); - logical_size_.x = float(rc.right - rc.left); - logical_size_.y = float(rc.bottom - rc.top); + logical_size_.x = Float32(rc.right - rc.left); + logical_size_.y = Float32(rc.bottom - rc.top); d2d_res_->GetDeviceContext()->SetDpi(dpi_, dpi_); diff --git a/src/kiwano/renderer/win32/D3DDeviceResourcesBase.h b/src/kiwano/renderer/win32/D3DDeviceResourcesBase.h index ca4631ff..e180425e 100644 --- a/src/kiwano/renderer/win32/D3DDeviceResourcesBase.h +++ b/src/kiwano/renderer/win32/D3DDeviceResourcesBase.h @@ -35,7 +35,7 @@ namespace kiwano virtual HRESULT SetLogicalSize(Size logical_size) = 0; - virtual HRESULT SetDpi(float dpi) = 0; + virtual HRESULT SetDpi(Float32 dpi) = 0; virtual void DiscardResources() = 0; }; diff --git a/src/kiwano/renderer/win32/FontCollectionLoader.cpp b/src/kiwano/renderer/win32/FontCollectionLoader.cpp index 304cd72d..d896e7ac 100644 --- a/src/kiwano/renderer/win32/FontCollectionLoader.cpp +++ b/src/kiwano/renderer/win32/FontCollectionLoader.cpp @@ -40,7 +40,7 @@ namespace kiwano STDMETHOD(AddFilePaths)( Vector const& filePaths, _Out_ LPVOID* pCollectionKey, - _Out_ UINT32* pCollectionKeySize + _Out_ UInt32* pCollectionKeySize ); // IUnknown methods @@ -52,7 +52,7 @@ namespace kiwano virtual HRESULT STDMETHODCALLTYPE CreateEnumeratorFromKey( IDWriteFactory* pFactory, void const* collectionKey, - UINT32 collectionKeySize, + UInt32 collectionKeySize, _Out_ IDWriteFontFileEnumerator** fontFileEnumerator ); @@ -61,7 +61,7 @@ namespace kiwano typedef Vector FileCollection; Vector filePaths_; - Vector collectionKeys_; + Vector collectionKeys_; }; HRESULT IFontCollectionLoader::Create(_Out_ IFontCollectionLoader** ppCollectionLoader) @@ -90,7 +90,7 @@ namespace kiwano STDMETHODIMP FontCollectionLoader::AddFilePaths( Vector const& filePaths, _Out_ LPVOID* pCollectionKey, - _Out_ UINT32* pCollectionKeySize + _Out_ UInt32* pCollectionKeySize ) { if (!pCollectionKey || !pCollectionKeySize) @@ -100,7 +100,7 @@ namespace kiwano try { - UINT32 collectionKey = filePaths_.size(); + UInt32 collectionKey = filePaths_.size(); collectionKeys_.push_back(collectionKey); filePaths_.push_back(filePaths); @@ -150,13 +150,13 @@ namespace kiwano HRESULT STDMETHODCALLTYPE FontCollectionLoader::CreateEnumeratorFromKey( IDWriteFactory* pFactory, void const* collectionKey, - UINT32 collectionKeySize, + UInt32 collectionKeySize, _Out_ IDWriteFontFileEnumerator** fontFileEnumerator ) { HRESULT hr = S_OK; - if (collectionKey == NULL || collectionKeySize % sizeof(UINT32) != 0) + if (collectionKey == NULL || collectionKeySize % sizeof(UInt32) != 0) hr = E_INVALIDARG; if (SUCCEEDED(hr)) @@ -166,7 +166,7 @@ namespace kiwano if (SUCCEEDED(hr)) { - const UINT32 fileIndex = *static_cast(collectionKey); + const UInt32 fileIndex = *static_cast(collectionKey); hr = pEnumerator->SetFilePaths(filePaths_[fileIndex]); } @@ -220,7 +220,7 @@ namespace kiwano IDWriteFactory* pFactory_; IDWriteFontFile* currentFile_; Vector filePaths_; - size_t nextIndex_; + UInt32 nextIndex_; }; HRESULT IFontFileEnumerator::Create(_Out_ IFontFileEnumerator** ppEnumerator, IDWriteFactory* pFactory) @@ -372,7 +372,7 @@ namespace kiwano STDMETHOD(AddResources)( Vector const& resources, _Out_ LPVOID* pCollectionKey, - _Out_ UINT32* pCollectionKeySize + _Out_ UInt32* pCollectionKeySize ); // IUnknown methods @@ -384,7 +384,7 @@ namespace kiwano virtual HRESULT STDMETHODCALLTYPE CreateEnumeratorFromKey( IDWriteFactory* pFactory, void const* collectionKey, - UINT32 collectionKeySize, + UInt32 collectionKeySize, _Out_ IDWriteFontFileEnumerator** fontFileEnumerator ); @@ -394,7 +394,7 @@ namespace kiwano typedef Vector ResourceCollection; Vector resources_; - Vector collectionKeys_; + Vector collectionKeys_; }; HRESULT IResourceFontCollectionLoader::Create(_Out_ IResourceFontCollectionLoader** ppCollectionLoader, IDWriteFontFileLoader* pFileLoader) @@ -423,7 +423,7 @@ namespace kiwano STDMETHODIMP ResourceFontCollectionLoader::AddResources( Vector const& resources, _Out_ LPVOID* pCollectionKey, - _Out_ UINT32* pCollectionKeySize + _Out_ UInt32* pCollectionKeySize ) { if (!pCollectionKey || !pCollectionKeySize) @@ -433,7 +433,7 @@ namespace kiwano try { - UINT32 collectionKey = resources_.size(); + UInt32 collectionKey = resources_.size(); collectionKeys_.push_back(collectionKey); resources_.push_back(resources); @@ -483,7 +483,7 @@ namespace kiwano HRESULT STDMETHODCALLTYPE ResourceFontCollectionLoader::CreateEnumeratorFromKey( IDWriteFactory* pFactory, void const* collectionKey, - UINT32 collectionKeySize, + UInt32 collectionKeySize, _Out_ IDWriteFontFileEnumerator** fontFileEnumerator ) { @@ -499,7 +499,7 @@ namespace kiwano if (SUCCEEDED(hr)) { - const UINT32 resourceIndex = *static_cast(collectionKey); + const UInt32 resourceIndex = *static_cast(collectionKey); hr = pEnumerator->SetResources(resources_[resourceIndex]); } @@ -536,7 +536,7 @@ namespace kiwano // IDWriteFontFileLoader methods virtual HRESULT STDMETHODCALLTYPE CreateStreamFromKey( void const* fontFileReferenceKey, - UINT32 fontFileReferenceKeySize, + UInt32 fontFileReferenceKeySize, _Out_ IDWriteFontFileStream** fontFileStream ); @@ -597,7 +597,7 @@ namespace kiwano HRESULT STDMETHODCALLTYPE ResourceFontFileLoader::CreateStreamFromKey( void const* fontFileReferenceKey, - UINT32 fontFileReferenceKeySize, + UInt32 fontFileReferenceKeySize, _Out_ IDWriteFontFileStream** fontFileStream ) { @@ -668,7 +668,7 @@ namespace kiwano IDWriteFontFile* currentFile_; IDWriteFontFileLoader* pLoader_; Vector resources_; - size_t nextIndex_; + UInt32 nextIndex_; }; HRESULT IResourceFontFileEnumerator::Create(_Out_ IResourceFontFileEnumerator** ppEnumerator, IDWriteFactory* pFactory, IDWriteFontFileLoader* pFileLoader) @@ -948,7 +948,7 @@ namespace kiwano if (fileOffset <= resourceSize_ && fragmentSize <= resourceSize_ - fileOffset) { - *fragmentStart = static_cast(resourcePtr_) + static_cast(fileOffset); + *fragmentStart = static_cast(resourcePtr_) + static_cast(fileOffset); *fragmentContext = NULL; return S_OK; } diff --git a/src/kiwano/renderer/win32/FontCollectionLoader.h b/src/kiwano/renderer/win32/FontCollectionLoader.h index c5e01c20..c64a61f4 100644 --- a/src/kiwano/renderer/win32/FontCollectionLoader.h +++ b/src/kiwano/renderer/win32/FontCollectionLoader.h @@ -34,7 +34,7 @@ namespace kiwano STDMETHOD(AddFilePaths)( Vector const& filePaths, _Out_ LPVOID * pCollectionKey, - _Out_ UINT32 * pCollectionKeySize + _Out_ UInt32 * pCollectionKeySize ) PURE; }; @@ -66,7 +66,7 @@ namespace kiwano STDMETHOD(AddResources)( Vector const& resources, _Out_ LPVOID * pCollectionKey, - _Out_ UINT32 * pCollectionKeySize + _Out_ UInt32 * pCollectionKeySize ) PURE; }; diff --git a/src/kiwano/renderer/win32/TextRenderer.cpp b/src/kiwano/renderer/win32/TextRenderer.cpp index 9c4e8aca..136138d5 100644 --- a/src/kiwano/renderer/win32/TextRenderer.cpp +++ b/src/kiwano/renderer/win32/TextRenderer.cpp @@ -35,18 +35,18 @@ namespace kiwano STDMETHOD(CreateDeviceResources)(); STDMETHOD_(void, SetTextStyle)( - _In_ FLOAT opacity, + _In_ Float32 opacity, _In_ CONST D2D1_COLOR_F &fillColor, _In_ BOOL outline, _In_ CONST D2D1_COLOR_F &outlineColor, - _In_ FLOAT outlineWidth, + _In_ Float32 outlineWidth, _In_ ID2D1StrokeStyle* outlineJoin ); STDMETHOD(DrawGlyphRun)( __maybenull void* clientDrawingContext, - FLOAT baselineOriginX, - FLOAT baselineOriginY, + Float32 baselineOriginX, + Float32 baselineOriginY, DWRITE_MEASURING_MODE measuringMode, __in DWRITE_GLYPH_RUN const* glyphRun, __in DWRITE_GLYPH_RUN_DESCRIPTION const* glyphRunDescription, @@ -55,24 +55,24 @@ namespace kiwano STDMETHOD(DrawUnderline)( __maybenull void* clientDrawingContext, - FLOAT baselineOriginX, - FLOAT baselineOriginY, + Float32 baselineOriginX, + Float32 baselineOriginY, __in DWRITE_UNDERLINE const* underline, IUnknown* clientDrawingEffect ); STDMETHOD(DrawStrikethrough)( __maybenull void* clientDrawingContext, - FLOAT baselineOriginX, - FLOAT baselineOriginY, + Float32 baselineOriginX, + Float32 baselineOriginY, __in DWRITE_STRIKETHROUGH const* strikethrough, IUnknown* clientDrawingEffect ); STDMETHOD(DrawInlineObject)( __maybenull void* clientDrawingContext, - FLOAT originX, - FLOAT originY, + Float32 originX, + Float32 originY, IDWriteInlineObject* inlineObject, BOOL IsSideways, BOOL IsRightToLeft, @@ -91,7 +91,7 @@ namespace kiwano STDMETHOD(GetPixelsPerDip)( __maybenull void* clientDrawingContext, - __out FLOAT* pixelsPerDip + __out Float32* pixelsPerDip ); public: @@ -106,7 +106,7 @@ namespace kiwano unsigned long cRefCount_; D2D1_COLOR_F sFillColor_; D2D1_COLOR_F sOutlineColor_; - FLOAT fOutlineWidth; + Float32 fOutlineWidth; BOOL bShowOutline_; ID2D1Factory* pFactory_; ID2D1RenderTarget* pRT_; @@ -188,11 +188,11 @@ namespace kiwano } STDMETHODIMP_(void) TextRenderer::SetTextStyle( - _In_ FLOAT opacity, + _In_ Float32 opacity, _In_ CONST D2D1_COLOR_F &fillColor, _In_ BOOL outline, _In_ CONST D2D1_COLOR_F &outlineColor, - _In_ FLOAT outlineWidth, + _In_ Float32 outlineWidth, _In_ ID2D1StrokeStyle* outlineJoin) { sFillColor_ = fillColor; @@ -206,8 +206,8 @@ namespace kiwano STDMETHODIMP TextRenderer::DrawGlyphRun( __maybenull void* clientDrawingContext, - FLOAT baselineOriginX, - FLOAT baselineOriginY, + Float32 baselineOriginX, + Float32 baselineOriginY, DWRITE_MEASURING_MODE measuringMode, __in DWRITE_GLYPH_RUN const* glyphRun, __in DWRITE_GLYPH_RUN_DESCRIPTION const* glyphRunDescription, @@ -299,8 +299,8 @@ namespace kiwano STDMETHODIMP TextRenderer::DrawUnderline( __maybenull void* clientDrawingContext, - FLOAT baselineOriginX, - FLOAT baselineOriginY, + Float32 baselineOriginX, + Float32 baselineOriginY, __in DWRITE_UNDERLINE const* underline, IUnknown* clientDrawingEffect) { @@ -368,8 +368,8 @@ namespace kiwano STDMETHODIMP TextRenderer::DrawStrikethrough( __maybenull void* clientDrawingContext, - FLOAT baselineOriginX, - FLOAT baselineOriginY, + Float32 baselineOriginX, + Float32 baselineOriginY, __in DWRITE_STRIKETHROUGH const* strikethrough, IUnknown* clientDrawingEffect) { @@ -437,8 +437,8 @@ namespace kiwano STDMETHODIMP TextRenderer::DrawInlineObject( __maybenull void* clientDrawingContext, - FLOAT originX, - FLOAT originY, + Float32 originX, + Float32 originY, IDWriteInlineObject* inlineObject, BOOL IsSideways, BOOL IsRightToLeft, @@ -476,11 +476,11 @@ namespace kiwano STDMETHODIMP TextRenderer::GetPixelsPerDip( __maybenull void* clientDrawingContext, - __out FLOAT* pixelsPerDip) + __out Float32* pixelsPerDip) { KGE_UNUSED(clientDrawingContext); - float x, yUnused; + Float32 x, yUnused; pRT_->GetDpi(&x, &yUnused); *pixelsPerDip = x / 96; diff --git a/src/kiwano/renderer/win32/TextRenderer.h b/src/kiwano/renderer/win32/TextRenderer.h index 604a232e..519cc577 100644 --- a/src/kiwano/renderer/win32/TextRenderer.h +++ b/src/kiwano/renderer/win32/TextRenderer.h @@ -33,11 +33,11 @@ namespace kiwano ); STDMETHOD_(void, SetTextStyle)( - _In_ FLOAT opacity, + _In_ Float32 opacity, _In_ CONST D2D1_COLOR_F &fillColor, _In_ BOOL outline, _In_ CONST D2D1_COLOR_F &outlineColor, - _In_ FLOAT outlineWidth, + _In_ Float32 outlineWidth, _In_ ID2D1StrokeStyle* outlineJoin ) PURE; }; diff --git a/src/kiwano/ui/Button.cpp b/src/kiwano/ui/Button.cpp index 9a8a841c..9108b090 100644 --- a/src/kiwano/ui/Button.cpp +++ b/src/kiwano/ui/Button.cpp @@ -32,10 +32,10 @@ namespace kiwano { SetResponsible(true); - AddListener(Event::MouseHover, bind_func(this, &Button::UpdateStatus)); - AddListener(Event::MouseOut, bind_func(this, &Button::UpdateStatus)); - AddListener(Event::MouseBtnDown, bind_func(this, &Button::UpdateStatus)); - AddListener(Event::MouseBtnUp, bind_func(this, &Button::UpdateStatus)); + AddListener(Event::MouseHover, Closure(this, &Button::UpdateStatus)); + AddListener(Event::MouseOut, Closure(this, &Button::UpdateStatus)); + AddListener(Event::MouseBtnDown, Closure(this, &Button::UpdateStatus)); + AddListener(Event::MouseBtnUp, Closure(this, &Button::UpdateStatus)); } Button::Button(const Callback& click) diff --git a/src/kiwano/ui/Menu.cpp b/src/kiwano/ui/Menu.cpp index 82827937..36c8aef0 100644 --- a/src/kiwano/ui/Menu.cpp +++ b/src/kiwano/ui/Menu.cpp @@ -41,7 +41,7 @@ namespace kiwano return enabled_; } - size_t Menu::GetButtonCount() const + UInt32 Menu::GetButtonCount() const { return buttons_.size(); } diff --git a/src/kiwano/ui/Menu.h b/src/kiwano/ui/Menu.h index e10cb389..0951b27c 100644 --- a/src/kiwano/ui/Menu.h +++ b/src/kiwano/ui/Menu.h @@ -38,7 +38,7 @@ namespace kiwano bool IsEnable() const; // 获取菜单中的按钮数量 - size_t GetButtonCount() const; + UInt32 GetButtonCount() const; // 设置菜单启用或禁用 void SetEnabled( diff --git a/src/kiwano/utils/DataUtil.cpp b/src/kiwano/utils/DataUtil.cpp index 81b6acb9..f7392a07 100644 --- a/src/kiwano/utils/DataUtil.cpp +++ b/src/kiwano/utils/DataUtil.cpp @@ -40,7 +40,7 @@ namespace kiwano bool DataUtil::Exists(String const& key) const { - wchar_t temp[256] = { 0 }; + WChar temp[256] = { 0 }; ::GetPrivateProfileStringW( field_name_.c_str(), key.c_str(), @@ -52,7 +52,7 @@ namespace kiwano return temp[0] == L'\0'; } - bool DataUtil::SaveInt(String const& key, int val) const + bool DataUtil::SaveInt(String const& key, Int32 val) const { BOOL ret = ::WritePrivateProfileStringW( field_name_.c_str(), @@ -63,7 +63,7 @@ namespace kiwano return ret == TRUE; } - bool DataUtil::SaveFloat(String const& key, float val) const + bool DataUtil::SaveFloat(String const& key, Float32 val) const { BOOL ret = ::WritePrivateProfileStringW( field_name_.c_str(), @@ -74,7 +74,7 @@ namespace kiwano return ret == TRUE; } - bool DataUtil::SaveDouble(String const& key, double val) const + bool DataUtil::SaveDouble(String const& key, Float64 val) const { BOOL ret = ::WritePrivateProfileStringW( field_name_.c_str(), @@ -107,7 +107,7 @@ namespace kiwano return ret == TRUE; } - int DataUtil::GetInt(String const & key, int default_value) const + Int32 DataUtil::GetInt(String const & key, Int32 default_value) const { return ::GetPrivateProfileIntW( field_name_.c_str(), @@ -117,17 +117,17 @@ namespace kiwano ); } - float DataUtil::GetFloat(String const & key, float default_value) const + Float32 DataUtil::GetFloat(String const & key, Float32 default_value) const { - wchar_t temp[32] = { 0 }; + WChar temp[32] = { 0 }; String default_str = String::parse(default_value); ::GetPrivateProfileStringW(field_name_.c_str(), key.c_str(), default_str.c_str(), temp, 31, file_path_.c_str()); return std::stof(temp); } - double DataUtil::GetDouble(String const & key, double default_value) const + Float64 DataUtil::GetDouble(String const & key, Float64 default_value) const { - wchar_t temp[32] = { 0 }; + WChar temp[32] = { 0 }; String default_str = String::parse(default_value); ::GetPrivateProfileStringW(field_name_.c_str(), key.c_str(), default_str.c_str(), temp, 31, file_path_.c_str()); return std::stod(temp); @@ -135,7 +135,7 @@ namespace kiwano bool DataUtil::GetBool(String const & key, bool default_value) const { - int nValue = ::GetPrivateProfileIntW( + Int32 nValue = ::GetPrivateProfileIntW( field_name_.c_str(), key.c_str(), default_value ? 1 : 0, @@ -145,7 +145,7 @@ namespace kiwano String DataUtil::GetString(String const & key, String const & default_value) const { - wchar_t temp[256] = { 0 }; + WChar temp[256] = { 0 }; ::GetPrivateProfileStringW( field_name_.c_str(), key.c_str(), diff --git a/src/kiwano/utils/DataUtil.h b/src/kiwano/utils/DataUtil.h index 4c2e4b38..22426c54 100644 --- a/src/kiwano/utils/DataUtil.h +++ b/src/kiwano/utils/DataUtil.h @@ -26,12 +26,12 @@ namespace kiwano { // // 数据存取工具 (.ini 格式) - // 一个 DataUtil 对象表示一个数据储存实体, 用于存取简单格式 (bool | int | float | double | String) 的数据 + // 一个 DataUtil 对象表示一个数据储存实体, 用于存取简单格式 (bool | Int32 | float | Float64 | String) 的数据 // 数据都采用 key-value (键-值) 的方式存取 // 例如, 保存一份游戏最高分, 以便下次进行游戏时读取: // DataUtil data; // 创建数据对象 // data.SaveInt(L"best score", 20); // 保存最高分 20 - // int best = data.GetInt(L"best score"); // 读取之前储存的最高分 + // Int32 best = data.GetInt(L"best score"); // 读取之前储存的最高分 // class KGE_API DataUtil @@ -63,22 +63,22 @@ namespace kiwano String const& key ) const; - // 保存 int 类型的值 + // 保存 Int32 类型的值 bool SaveInt( String const& key, - int val + Int32 val ) const; // 保存 float 类型的值 bool SaveFloat( String const& key, - float val + Float32 val ) const; - // 保存 double 类型的值 + // 保存 Float64 类型的值 bool SaveDouble( String const& key, - double val + Float64 val ) const; // 保存 bool 类型的值 @@ -93,22 +93,22 @@ namespace kiwano String const& val ) const; - // 获取 int 类型的值 - int GetInt( + // 获取 Int32 类型的值 + Int32 GetInt( String const& key, - int default_value = 0 + Int32 default_value = 0 ) const; // 获取 float 类型的值 - float GetFloat( + Float32 GetFloat( String const& key, - float default_value = 0.0f + Float32 default_value = 0.0f ) const; - // 获取 double 类型的值 - double GetDouble( + // 获取 Float64 类型的值 + Float64 GetDouble( String const& key, - double default_value = 0.0 + Float64 default_value = 0.0 ) const; // 获取 bool 类型的值 @@ -120,7 +120,7 @@ namespace kiwano // 获取 字符串 类型的值 String GetString( String const& key, - String const& default_value = L"" + String const& default_value = String() ) const; protected: diff --git a/src/kiwano/utils/Path.cpp b/src/kiwano/utils/Path.cpp index 66e0f715..b57fc460 100644 --- a/src/kiwano/utils/Path.cpp +++ b/src/kiwano/utils/Path.cpp @@ -32,10 +32,10 @@ namespace kiwano if (dir_path.empty() || dir_path.size() >= MAX_PATH) return false; - wchar_t tmp_dir_path[MAX_PATH] = { 0 }; - size_t length = dir_path.length(); + WChar tmp_dir_path[MAX_PATH] = { 0 }; + UInt32 length = dir_path.length(); - for (size_t i = 0; i < length; ++i) + for (UInt32 i = 0; i < length; ++i) { tmp_dir_path[i] = dir_path.at(i); if (tmp_dir_path[i] == L'\\' || tmp_dir_path[i] == L'/' || i == (length - 1)) @@ -59,7 +59,7 @@ namespace kiwano if (temp_path.empty()) { // 设置临时文件保存路径 - wchar_t path[_MAX_PATH]; + WChar path[_MAX_PATH]; if (0 != ::GetTempPath(_MAX_PATH, path)) { @@ -80,7 +80,7 @@ namespace kiwano if (local_app_data_path.empty()) { // 获取 AppData/Local 文件夹的路径 - wchar_t path[MAX_PATH] = { 0 }; + WChar path[MAX_PATH] = { 0 }; ::SHGetFolderPath(NULL, CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, path); local_app_data_path = path; } diff --git a/src/kiwano/utils/ResourceCache.cpp b/src/kiwano/utils/ResourceCache.cpp index 9340e3d1..b82d4ab2 100644 --- a/src/kiwano/utils/ResourceCache.cpp +++ b/src/kiwano/utils/ResourceCache.cpp @@ -196,7 +196,7 @@ namespace kiwano return false; } - size_t ResourceCache::AddFrameSequence(String const& id, Vector const& files) + UInt32 ResourceCache::AddFrameSequence(String const& id, Vector const& files) { if (files.empty()) return 0; @@ -224,7 +224,7 @@ namespace kiwano return 0; } - size_t ResourceCache::AddFrameSequence(String const & id, String const& file_path, int cols, int rows) + UInt32 ResourceCache::AddFrameSequence(String const & id, String const& file_path, Int32 cols, Int32 rows) { if (cols <= 0 || rows <= 0) return 0; @@ -233,17 +233,17 @@ namespace kiwano if (!raw || !raw->Load(file_path)) return false; - float raw_width = raw->GetWidth(); - float raw_height = raw->GetHeight(); - float width = raw_width / cols; - float height = raw_height / rows; + Float32 raw_width = raw->GetWidth(); + Float32 raw_height = raw->GetHeight(); + Float32 width = raw_width / cols; + Float32 height = raw_height / rows; Vector image_arr; image_arr.reserve(rows * cols); - for (int i = 0; i < rows; i++) + for (Int32 i = 0; i < rows; i++) { - for (int j = 0; j < cols; j++) + for (Int32 j = 0; j < cols; j++) { FramePtr ptr = new (std::nothrow) Frame(raw->GetImage()); if (ptr) @@ -258,7 +258,7 @@ namespace kiwano return AddFrameSequence(id, frames); } - size_t ResourceCache::AddFrameSequence(String const & id, FrameSequencePtr frames) + UInt32 ResourceCache::AddFrameSequence(String const & id, FrameSequencePtr frames) { if (frames) { @@ -310,7 +310,7 @@ namespace kiwano }; bool LoadImagesFromData(ResourceCache* loader, GlobalData* gdata, const String* id, const String* type, - const String* file, const Vector* files, int rows, int cols) + const String* file, const Vector* files, Int32 rows, Int32 cols) { if (!gdata || !id) return false; @@ -363,7 +363,7 @@ namespace kiwano for (const auto& image : json_data[L"images"]) { const String* id = nullptr, * type = nullptr, * file = nullptr; - int rows = 0, cols = 0; + Int32 rows = 0, cols = 0; if (image.count(L"id")) id = &image[L"id"].as_string(); if (image.count(L"type")) type = &image[L"type"].as_string(); @@ -373,7 +373,7 @@ namespace kiwano if (image.count(L"files")) { - Vector files; + Vector files; files.reserve(image[L"files"].size()); for (const auto& file : image[L"files"]) { @@ -405,7 +405,7 @@ namespace kiwano for (auto image = images->FirstChildElement(); image; image = image->NextSiblingElement()) { String id, type, file; - int rows = 0, cols = 0; + Int32 rows = 0, cols = 0; if (auto attr = image->Attribute(L"id")) id.assign(attr); // assign() copies attr content if (auto attr = image->Attribute(L"type")) type = attr; // operator=() just holds attr pointer @@ -415,7 +415,7 @@ namespace kiwano if (file.empty() && !image->NoChildren()) { - Vector files_arr; + Vector files_arr; for (auto file = image->FirstChildElement(); file; file = file->NextSiblingElement()) { if (auto path = file->Attribute(L"path")) diff --git a/src/kiwano/utils/ResourceCache.h b/src/kiwano/utils/ResourceCache.h index 76559d32..8a87c072 100644 --- a/src/kiwano/utils/ResourceCache.h +++ b/src/kiwano/utils/ResourceCache.h @@ -53,14 +53,14 @@ namespace kiwano bool AddFrame(String const& id, FramePtr frame); // 添加序列帧 - size_t AddFrameSequence(String const& id, Vector const& files); + UInt32 AddFrameSequence(String const& id, Vector const& files); // 添加序列帧 // 按行列数裁剪图片 - size_t AddFrameSequence(String const& id, String const& file_path, int cols, int rows = 1); + UInt32 AddFrameSequence(String const& id, String const& file_path, Int32 cols, Int32 rows = 1); // 添加序列帧 - size_t AddFrameSequence(String const& id, FrameSequencePtr frames); + UInt32 AddFrameSequence(String const& id, FrameSequencePtr frames); // 添加对象 bool AddObjectBase(String const& id, ObjectBasePtr obj);