From 5975c4ab4c74c6da1fbacedf800aa8b52bf8bb71 Mon Sep 17 00:00:00 2001 From: ducphamhong Date: Wed, 10 Mar 2021 09:18:56 +0700 Subject: [PATCH] #119 Refactor ListFSController & TreeFSController, fix warning size_t(64bit) --- .../Editor/Space/Assets/CListFSController.cpp | 145 +++++++++ .../Editor/Space/Assets/CListFSController.h | 61 ++++ .../Editor/Space/Assets/CSpaceAssets.cpp | 294 ++---------------- .../Source/Editor/Space/Assets/CSpaceAssets.h | 41 +-- .../Editor/Space/Assets/CTreeFSController.cpp | 196 ++++++++++++ .../Editor/Space/Assets/CTreeFSController.h | 68 ++++ .../Editor/Source/GUI/Controls/CTabControl.h | 2 +- Projects/Editor/Source/GUI/Controls/CText.h | 4 +- .../Source/GUI/Controls/CTextContainer.h | 4 +- .../Audio/Source/Decoder/CAudioDecoderMp3.cpp | 4 +- .../Audio/Source/Engine/CAudioEmiter.cpp | 2 +- .../Audio/Source/Engine/CAudioEngine.cpp | 4 +- .../Audio/Source/Stream/CFileStream.cpp | 3 +- .../Skylicht/Client/Source/CApplication.cpp | 4 +- .../ParticleSystem/Particles/CGroup.cpp | 4 +- .../Particles/Systems/CParticleSystem.cpp | 2 +- .../Engine/Source/Animation/CAnimation.cpp | 2 +- .../Engine/Source/Camera/CFpsMoveCamera.cpp | 2 +- .../Engine/Source/ConsoleLog/CConsoleLog.h | 2 +- .../Engine/Source/GameObject/CGameObject.cpp | 6 +- .../Engine/Source/Graphics2D/Atlas/CAtlas.cpp | 4 +- .../Engine/Source/Graphics2D/CGraphics2D.cpp | 4 +- .../Engine/Source/Graphics2D/GUI/CGUIText.cpp | 2 +- .../Graphics2D/Glyph/CGlyphFreetype.cpp | 2 +- .../Graphics2D/SpriteFrame/CSpriteFont.cpp | 4 +- .../Importer/Collada/CColladaLoader.cpp | 10 +- .../Engine/Source/Material/CMaterial.cpp | 4 +- .../Source/Material/CMaterialManager.cpp | 6 +- .../Engine/Source/Material/Shader/CShader.cpp | 2 +- .../Source/Material/Shader/CShaderManager.cpp | 8 +- .../Source/Serializable/CObjectSerizable.h | 2 +- .../Source/TextureManager/CTextureManager.cpp | 8 +- .../Engine/Source/Utils/CActivator.cpp | 2 +- .../Engine/Source/Utils/CMemoryStream.cpp | 2 +- .../Skylicht/Engine/Source/Utils/CPath.cpp | 4 +- .../Utils/XMLSpreadsheet/CXMLSpreadsheet.cpp | 4 +- .../Utils/XMLSpreadsheet/CXMLSpreadsheet.h | 2 +- .../Utils/XMLSpreadsheet/CXMLTableData.h | 6 +- .../Source/Lightmapper/CLightmapper.cpp | 4 +- .../Lightmapping/Source/CViewBakeLightmap.cpp | 2 +- .../Source/CViewBakeLightmap.cpp | 4 +- Samples/LuckyDraw/Source/CList.cpp | 12 +- .../LuckyDraw/Source/CScrollerController.cpp | 10 +- 43 files changed, 577 insertions(+), 381 deletions(-) create mode 100644 Projects/Editor/Source/Editor/Space/Assets/CListFSController.cpp create mode 100644 Projects/Editor/Source/Editor/Space/Assets/CListFSController.h create mode 100644 Projects/Editor/Source/Editor/Space/Assets/CTreeFSController.cpp create mode 100644 Projects/Editor/Source/Editor/Space/Assets/CTreeFSController.h diff --git a/Projects/Editor/Source/Editor/Space/Assets/CListFSController.cpp b/Projects/Editor/Source/Editor/Space/Assets/CListFSController.cpp new file mode 100644 index 000000000..45bbbcf74 --- /dev/null +++ b/Projects/Editor/Source/Editor/Space/Assets/CListFSController.cpp @@ -0,0 +1,145 @@ +/* +!@ +MIT License + +CopyRight (c) 2020 Skylicht Technology CO., LTD + +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. + +This file is part of the "Skylicht Engine". +https://github.com/skylicht-lab/skylicht-engine +!# +*/ + +#include "pch.h" +#include "CListFSController.h" +#include "Utils/CPath.h" + +namespace Skylicht +{ + namespace Editor + { + CListFSController::CListFSController(GUI::CListBox* list) : + m_renameItem(NULL) + { + m_assetManager = CAssetManager::getInstance(); + + m_listFS = list; + m_listFS->OnKeyPress = std::bind( + &CListFSController::OnKeyPress, + this, + std::placeholders::_1, + std::placeholders::_2, + std::placeholders::_3 + ); + + std::vector files; + m_assetManager->getRoot(files); + add("", files); + } + + CListFSController::~CListFSController() + { + + } + + void CListFSController::OnKeyPress(GUI::CBase* control, int key, bool press) + { + GUI::CListBox* list = dynamic_cast(control); + if (list == NULL) + return; + + if (key == GUI::KEY_F2) + { + GUI::CListRowItem* node = list->getSelected(); + if (node != NULL) + { + m_renameItem = node; + + node->getTextEditHelper()->beginEdit( + BIND_LISTENER(&CListFSController::OnRename, this), + BIND_LISTENER(&CListFSController::OnCancelRename, this) + ); + } + } + } + + void CListFSController::OnRename(GUI::CBase* control) + { + m_listFS->focus(); + } + + void CListFSController::OnCancelRename(GUI::CBase* control) + { + m_listFS->focus(); + } + + void CListFSController::add(const std::string& currentFolder, std::vector& files) + { + m_listFS->removeAllItem(); + + if (currentFolder.size() > 0 && + currentFolder != m_assetManager->getAssetFolder()) + { + GUI::CListRowItem* item = m_listFS->addItem(L"..", GUI::ESystemIcon::Folder); + + std::string parent = CPath::getFolderPath(currentFolder); + item->tagString(parent); + item->tagBool(true); + item->OnDoubleLeftMouseClick = BIND_LISTENER(&CListFSController::OnFileOpen, this); + } + + for (SFileInfo& f : files) + { + GUI::CListRowItem* item; + + if (f.IsFolder) + item = m_listFS->addItem(f.NameW.c_str(), GUI::ESystemIcon::Folder); + else + item = m_listFS->addItem(f.NameW.c_str(), GUI::ESystemIcon::File); + + item->tagString(f.FullPath); + item->tagBool(f.IsFolder); + item->OnDoubleLeftMouseClick = BIND_LISTENER(&CListFSController::OnFileOpen, this); + } + + m_listFS->setScrollVertical(0.0f); + } + + void CListFSController::OnFileOpen(GUI::CBase* node) + { + GUI::CListRowItem* rowNode = dynamic_cast(node); + if (rowNode != NULL) + { + const std::string& fullPath = rowNode->getTagString(); + + bool isFolder = rowNode->getTagBool(); + if (isFolder == true) + { + // browse folder + std::vector files; + m_assetManager->getFolder(fullPath.c_str(), files); + + add(fullPath, files); + + // expandTreeFolder(fullPath); + } + else + { + // shell open the file + } + } + } + } +} \ No newline at end of file diff --git a/Projects/Editor/Source/Editor/Space/Assets/CListFSController.h b/Projects/Editor/Source/Editor/Space/Assets/CListFSController.h new file mode 100644 index 000000000..64995a8c0 --- /dev/null +++ b/Projects/Editor/Source/Editor/Space/Assets/CListFSController.h @@ -0,0 +1,61 @@ +/* +!@ +MIT License + +CopyRight (c) 2020 Skylicht Technology CO., LTD + +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. + +This file is part of the "Skylicht Engine". +https://github.com/skylicht-lab/skylicht-engine +!# +*/ + +#pragma once + +#include "GUI/GUI.h" +#include "AssetManager/CAssetManager.h" + +namespace Skylicht +{ + namespace Editor + { + class CListFSController + { + protected: + GUI::CListBox* m_listFS; + + GUI::CListRowItem* m_renameItem; + + CAssetManager* m_assetManager; + + public: + CListFSController(GUI::CListBox* list); + + virtual ~CListFSController(); + + void OnKeyPress(GUI::CBase* control, int key, bool press); + + void OnRename(GUI::CBase* control); + + void OnCancelRename(GUI::CBase* control); + + void OnFileOpen(GUI::CBase* node); + + protected: + + void add(const std::string& currentFolder, std::vector& files); + }; + } +} \ No newline at end of file diff --git a/Projects/Editor/Source/Editor/Space/Assets/CSpaceAssets.cpp b/Projects/Editor/Source/Editor/Space/Assets/CSpaceAssets.cpp index 35ad3f424..83e211439 100644 --- a/Projects/Editor/Source/Editor/Space/Assets/CSpaceAssets.cpp +++ b/Projects/Editor/Source/Editor/Space/Assets/CSpaceAssets.cpp @@ -34,10 +34,11 @@ namespace Skylicht { CSpaceAssets::CSpaceAssets(GUI::CWindow* window, CEditor* editor) : CSpace(window, editor), - m_renameNode(NULL), m_contextMenuOwner(NULL), m_selectedItem(NULL) { + m_assetManager = CAssetManager::getInstance(); + GUI::CToolbar* toolbar = new GUI::CToolbar(window); toolbar->addButton(L"Add", GUI::ESystemIcon::Plus); @@ -53,50 +54,16 @@ namespace Skylicht spliter->dock(GUI::EPosition::Fill); spliter->setNumberRowCol(1, 2); - m_folder = new GUI::CTreeControl(spliter); - m_folder->OnKeyPress = std::bind( - &CSpaceAssets::OnTreeKeyPress, - this, - std::placeholders::_1, - std::placeholders::_2, - std::placeholders::_3 - ); - - m_folder->OnItemContextMenu = BIND_LISTENER(&CSpaceAssets::OnTreeContextMenu, this); - - m_assetManager = CAssetManager::getInstance(); - - m_root = m_folder->addNode(L"Assets", GUI::ESystemIcon::OpenFolder); - m_root->tagString(m_assetManager->getAssetFolder()); - m_root->OnExpand = BIND_LISTENER(&CSpaceAssets::OnTreeNodeExpand, this); - m_root->OnCollapse = BIND_LISTENER(&CSpaceAssets::OnTreeNodeCollapse, this); - m_root->OnSelectChange = BIND_LISTENER(&CSpaceAssets::OnTreeNodeSelected, this); - - m_root->setAlwayShowExpandButton(true); - m_root->expand(false); - - std::vector files; + m_treeFS = new GUI::CTreeControl(spliter); + m_treeFS->OnItemContextMenu = BIND_LISTENER(&CSpaceAssets::OnTreeContextMenu, this); + m_treeFSController = new CTreeFSController(m_treeFS); - // add root to tree folder - m_assetManager->getRoot(files); - addTreeFolder(m_root, files); + m_listFS = new GUI::CListBox(spliter); + m_listFS->OnItemContextMenu = BIND_LISTENER(&CSpaceAssets::OnListContextMenu, this); + m_listFSController = new CListFSController(m_listFS); - // column spliter - spliter->setControl(m_folder, 0, 0); - - m_listFiles = new GUI::CListBox(spliter); - m_listFiles->OnKeyPress = std::bind( - &CSpaceAssets::OnListKeyPress, - this, - std::placeholders::_1, - std::placeholders::_2, - std::placeholders::_3 - ); - m_listFiles->OnItemContextMenu = BIND_LISTENER(&CSpaceAssets::OnListContextMenu, this); - - spliter->setControl(m_listFiles, 0, 1); - - addListFolder("", files); + spliter->setControl(m_treeFS, 0, 0); + spliter->setControl(m_listFS, 0, 1); spliter->setColWidth(0, 300.0f); spliter->setWeakCol(1); @@ -105,7 +72,7 @@ namespace Skylicht m_contextMenu->setHidden(true); m_contextMenu->OnCommand = BIND_LISTENER(&CSpaceAssets::OnCommand, this); - m_openMenuItem = m_contextMenu->addItem(L"Open"); + m_menuOpen = m_contextMenu->addItem(L"Open"); m_contextMenu->addItem(L"Show in Explorer"); m_contextMenu->addSeparator(); m_contextMenu->addItem(L"Delete"); @@ -113,167 +80,14 @@ namespace Skylicht m_contextMenu->addItem(L"Copy path", L"SHIFT + C"); m_contextMenu->addItem(L"Duplicate", L"CTRL + D"); - m_listFiles->addAccelerator("SHIFT + C", BIND_LISTENER(&CSpaceAssets::OnCopyPath, this)); - m_folder->addAccelerator("SHIFT + C", BIND_LISTENER(&CSpaceAssets::OnCopyPath, this)); + m_listFS->addAccelerator("SHIFT + C", BIND_LISTENER(&CSpaceAssets::OnCopyPath, this)); + m_treeFS->addAccelerator("SHIFT + C", BIND_LISTENER(&CSpaceAssets::OnCopyPath, this)); } CSpaceAssets::~CSpaceAssets() { - - } - - void CSpaceAssets::addTreeFolder(GUI::CTreeNode* node, std::vector& files) - { - for (const SFileInfo& f : files) - { - if (f.IsFolder == true) - { - GUI::CTreeNode* childNode = node->addNode(f.NameW.c_str(), GUI::ESystemIcon::Folder); - childNode->tagString(f.FullPath); - childNode->OnExpand = BIND_LISTENER(&CSpaceAssets::OnTreeNodeExpand, this); - childNode->OnCollapse = BIND_LISTENER(&CSpaceAssets::OnTreeNodeCollapse, this); - childNode->OnSelectChange = BIND_LISTENER(&CSpaceAssets::OnTreeNodeSelected, this); - - if (m_assetManager->isFolderEmpty(f.FullPath.c_str()) == false) - childNode->setAlwayShowExpandButton(true); - } - } - } - - void CSpaceAssets::OnTreeNodeExpand(GUI::CBase* node) - { - GUI::CTreeNode* treeNode = dynamic_cast(node); - if (treeNode != NULL) - { - treeNode->setIcon(GUI::ESystemIcon::OpenFolder); - - const std::string& fullPath = treeNode->getTagString(); - - std::vector files; - m_assetManager->getFolder(fullPath.c_str(), files); - - addTreeFolder(treeNode, files); - } - } - - void CSpaceAssets::OnTreeNodeCollapse(GUI::CBase* node) - { - GUI::CTreeNode* treeNode = dynamic_cast(node); - if (treeNode != NULL) - { - treeNode->setIcon(GUI::ESystemIcon::Folder); - treeNode->removeAllTreeNode(); - } - } - - void CSpaceAssets::OnTreeNodeSelected(GUI::CBase* node) - { - GUI::CTreeNode* treeNode = dynamic_cast(node); - if (treeNode != NULL) - { - treeNode->setIcon(GUI::ESystemIcon::OpenFolder); - - const std::string& fullPath = treeNode->getTagString(); - - std::vector files; - m_assetManager->getFolder(fullPath.c_str(), files); - - addListFolder(fullPath, files); - } - } - - void CSpaceAssets::addListFolder(const std::string& currentFolder, std::vector& files) - { - m_listFiles->removeAllItem(); - - if (currentFolder.size() > 0 && - currentFolder != m_assetManager->getAssetFolder()) - { - GUI::CListRowItem* item = m_listFiles->addItem(L"..", GUI::ESystemIcon::Folder); - - std::string parent = CPath::getFolderPath(currentFolder); - item->tagString(parent); - item->tagBool(true); - item->OnDoubleLeftMouseClick = BIND_LISTENER(&CSpaceAssets::OnFileOpen, this); - } - - for (SFileInfo& f : files) - { - GUI::CListRowItem* item; - - if (f.IsFolder) - item = m_listFiles->addItem(f.NameW.c_str(), GUI::ESystemIcon::Folder); - else - item = m_listFiles->addItem(f.NameW.c_str(), GUI::ESystemIcon::File); - - item->tagString(f.FullPath); - item->tagBool(f.IsFolder); - item->OnDoubleLeftMouseClick = BIND_LISTENER(&CSpaceAssets::OnFileOpen, this); - } - - m_listFiles->setScrollVertical(0.0f); - } - - void CSpaceAssets::OnFileOpen(GUI::CBase* node) - { - GUI::CListRowItem* rowNode = dynamic_cast(node); - if (rowNode != NULL) - { - const std::string& fullPath = rowNode->getTagString(); - - bool isFolder = rowNode->getTagBool(); - if (isFolder == true) - { - // browse folder - std::vector files; - m_assetManager->getFolder(fullPath.c_str(), files); - - addListFolder(fullPath, files); - - expandTreeFolder(fullPath); - } - else - { - // shell open the file - } - } - } - - void CSpaceAssets::expandTreeFolder(const std::string& folder) - { - std::string shortPath = m_assetManager->getShortPath(folder.c_str()); - if (shortPath.size() > 0) - { - std::vector result; - CStringImp::splitString(shortPath.c_str(), "/", result); - - GUI::CTreeNode* node = m_root; - - wchar_t wname[512]; - - for (u32 i = 0, n = result.size(); i < n; i++) - { - const std::string name = result[i]; - CStringImp::convertUTF8ToUnicode(name.c_str(), wname); - - GUI::CTreeNode* child = node->getChildNodeByLabel(wname); - if (child == NULL) - break; - - if (child->haveChild()) - child->expand(false); - else - child->expand(true); - - node = child; - } - - if (node != NULL) - { - node->forceLayout(); - m_folder->getScrollControl()->scrollToItem(node); - } - } + delete m_treeFSController; + delete m_listFSController; } void CSpaceAssets::OnTreeContextMenu(GUI::CBase* row) @@ -287,7 +101,7 @@ namespace Skylicht m_contextMenuOwner = node->getRoot(); m_selectedItem = node; m_selectedPath = node->getTagString(); - m_openMenuItem->setHidden(true); + m_menuOpen->setHidden(true); m_contextMenu->open(GUI::CInput::getInput()->getMousePosition()); } } @@ -301,81 +115,19 @@ namespace Skylicht m_contextMenuOwner = rowItem->getListBox(); m_selectedItem = rowItem; m_selectedPath = rowItem->getTagString(); - m_openMenuItem->setHidden(false); + m_menuOpen->setHidden(false); m_contextMenu->open(GUI::CInput::getInput()->getMousePosition()); } } - void CSpaceAssets::OnTreeKeyPress(GUI::CBase* control, int key, bool press) - { - GUI::CTreeControl* tree = dynamic_cast(control); - if (tree == NULL) - return; - - if (key == GUI::KEY_F2) - { - GUI::CTreeNode* node = tree->getChildSelected(); - if (node != NULL) - { - m_renameNode = node; - - node->getTextEditHelper()->beginEdit( - BIND_LISTENER(&CSpaceAssets::OnTreeRename, this), - BIND_LISTENER(&CSpaceAssets::OnTreeCancelRename, this) - ); - } - } - } - - void CSpaceAssets::OnListKeyPress(GUI::CBase* control, int key, bool press) - { - GUI::CListBox* list = dynamic_cast(control); - if (list == NULL) - return; - - if (key == GUI::KEY_F2) - { - GUI::CListRowItem* node = list->getSelected(); - if (node != NULL) - { - m_renameItem = node; - - node->getTextEditHelper()->beginEdit( - BIND_LISTENER(&CSpaceAssets::OnListRename, this), - BIND_LISTENER(&CSpaceAssets::OnListCancelRename, this) - ); - } - } - } - - void CSpaceAssets::OnTreeRename(GUI::CBase* control) - { - m_folder->focus(); - } - - void CSpaceAssets::OnTreeCancelRename(GUI::CBase* control) - { - m_folder->focus(); - } - - void CSpaceAssets::OnListRename(GUI::CBase* control) - { - m_listFiles->focus(); - } - - void CSpaceAssets::OnListCancelRename(GUI::CBase* control) - { - m_listFiles->focus(); - } - void CSpaceAssets::OnCommand(GUI::CBase* item) { GUI::CMenuItem* menuItem = dynamic_cast(item); const std::wstring& label = menuItem->getLabel(); if (label == L"Open") { - if (m_contextMenuOwner == m_listFiles) - OnFileOpen(m_selectedItem); + if (m_contextMenuOwner == m_listFS) + m_listFSController->OnFileOpen(m_selectedItem); } else if (label == L"Show in Explorer") { @@ -406,9 +158,9 @@ namespace Skylicht { wchar_t* text = NULL; - if (m_listFiles->isFocussed()) + if (m_listFS->isFocussed()) { - GUI::CListRowItem* row = m_listFiles->getSelected(); + GUI::CListRowItem* row = m_listFS->getSelected(); std::string path = row->getTagString(); if (path.empty() == false) { @@ -416,9 +168,9 @@ namespace Skylicht CStringImp::convertUTF8ToUnicode(path.c_str(), text); } } - else if (m_folder->isFocussed()) + else if (m_treeFS->isFocussed()) { - GUI::CTreeNode* node = m_folder->getChildSelected(); + GUI::CTreeNode* node = m_treeFS->getChildSelected(); std::string path = node->getTagString(); if (path.empty() == false) { diff --git a/Projects/Editor/Source/Editor/Space/Assets/CSpaceAssets.h b/Projects/Editor/Source/Editor/Space/Assets/CSpaceAssets.h index b4ea74b1d..fb6c91f4e 100644 --- a/Projects/Editor/Source/Editor/Space/Assets/CSpaceAssets.h +++ b/Projects/Editor/Source/Editor/Space/Assets/CSpaceAssets.h @@ -25,8 +25,10 @@ This file is part of the "Skylicht Engine". #pragma once #include "SkylichtEngine.h" -#include "AssetManager/CAssetManager.h" #include "Editor/Space/CSpace.h" +#include "AssetManager/CAssetManager.h" +#include "CTreeFSController.h" +#include "CListFSController.h" namespace Skylicht { @@ -35,19 +37,17 @@ namespace Skylicht class CSpaceAssets : public CSpace { protected: - GUI::CTreeControl* m_folder; + GUI::CTreeControl* m_treeFS; - GUI::CTreeNode* m_root; + CTreeFSController* m_treeFSController; - GUI::CTreeNode* m_renameNode; + GUI::CListBox* m_listFS; - GUI::CListBox* m_listFiles; + CListFSController* m_listFSController; GUI::CTextBox* m_search; - GUI::CListRowItem* m_renameItem; - - GUI::CMenuItem* m_openMenuItem; + GUI::CMenuItem* m_menuOpen; GUI::CMenu* m_contextMenu; @@ -64,41 +64,16 @@ namespace Skylicht virtual ~CSpaceAssets(); - void OnTreeNodeExpand(GUI::CBase* node); - - void OnTreeNodeCollapse(GUI::CBase* node); - - void OnTreeNodeSelected(GUI::CBase* node); - - void OnFileOpen(GUI::CBase* node); - void OnTreeContextMenu(GUI::CBase* row); - void OnTreeKeyPress(GUI::CBase* control, int key, bool press); - - void OnTreeRename(GUI::CBase* control); - - void OnTreeCancelRename(GUI::CBase* control); - void OnListContextMenu(GUI::CBase* row); - void OnListKeyPress(GUI::CBase* control, int key, bool press); - - void OnListRename(GUI::CBase* control); - - void OnListCancelRename(GUI::CBase* control); - void OnCommand(GUI::CBase* item); void OnCopyPath(GUI::CBase* item); protected: - void expandTreeFolder(const std::string& folder); - - void addTreeFolder(GUI::CTreeNode* node, std::vector& files); - - void addListFolder(const std::string& currentFolder, std::vector& files); }; } } \ No newline at end of file diff --git a/Projects/Editor/Source/Editor/Space/Assets/CTreeFSController.cpp b/Projects/Editor/Source/Editor/Space/Assets/CTreeFSController.cpp new file mode 100644 index 000000000..0b0387491 --- /dev/null +++ b/Projects/Editor/Source/Editor/Space/Assets/CTreeFSController.cpp @@ -0,0 +1,196 @@ +/* +!@ +MIT License + +CopyRight (c) 2020 Skylicht Technology CO., LTD + +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. + +This file is part of the "Skylicht Engine". +https://github.com/skylicht-lab/skylicht-engine +!# +*/ + +#include "pch.h" +#include "CTreeFSController.h" + +#include "Utils/CStringImp.h" + +namespace Skylicht +{ + namespace Editor + { + CTreeFSController::CTreeFSController(GUI::CTreeControl* treeFS) : + m_treeFS(treeFS), + m_renameNode(NULL), + m_nodeAssets(NULL) + { + m_assetManager = CAssetManager::getInstance(); + + m_treeFS->OnKeyPress = std::bind( + &CTreeFSController::OnKeyPress, + this, + std::placeholders::_1, + std::placeholders::_2, + std::placeholders::_3 + ); + + m_nodeAssets = m_treeFS->addNode(L"Assets", GUI::ESystemIcon::OpenFolder); + m_nodeAssets->tagString(m_assetManager->getAssetFolder()); + m_nodeAssets->OnExpand = BIND_LISTENER(&CTreeFSController::OnExpand, this); + m_nodeAssets->OnCollapse = BIND_LISTENER(&CTreeFSController::OnCollapse, this); + m_nodeAssets->OnSelectChange = BIND_LISTENER(&CTreeFSController::OnSelected, this); + + m_nodeAssets->setAlwayShowExpandButton(true); + m_nodeAssets->expand(false); + + std::vector files; + m_assetManager->getRoot(files); + add(m_nodeAssets, files); + } + + CTreeFSController::~CTreeFSController() + { + + } + + void CTreeFSController::add(GUI::CTreeNode* node, std::vector& files) + { + for (const SFileInfo& f : files) + { + if (f.IsFolder == true) + { + GUI::CTreeNode* childNode = node->addNode(f.NameW.c_str(), GUI::ESystemIcon::Folder); + childNode->tagString(f.FullPath); + childNode->OnExpand = BIND_LISTENER(&CTreeFSController::OnExpand, this); + childNode->OnCollapse = BIND_LISTENER(&CTreeFSController::OnCollapse, this); + childNode->OnSelectChange = BIND_LISTENER(&CTreeFSController::OnSelected, this); + + if (m_assetManager->isFolderEmpty(f.FullPath.c_str()) == false) + childNode->setAlwayShowExpandButton(true); + } + } + } + + void CTreeFSController::OnExpand(GUI::CBase* node) + { + GUI::CTreeNode* treeNode = dynamic_cast(node); + if (treeNode != NULL) + { + treeNode->setIcon(GUI::ESystemIcon::OpenFolder); + + const std::string& fullPath = treeNode->getTagString(); + + std::vector files; + m_assetManager->getFolder(fullPath.c_str(), files); + + add(treeNode, files); + } + } + + void CTreeFSController::OnCollapse(GUI::CBase* node) + { + GUI::CTreeNode* treeNode = dynamic_cast(node); + if (treeNode != NULL) + { + treeNode->setIcon(GUI::ESystemIcon::Folder); + treeNode->removeAllTreeNode(); + } + } + + void CTreeFSController::OnSelected(GUI::CBase* node) + { + GUI::CTreeNode* treeNode = dynamic_cast(node); + if (treeNode != NULL) + { + treeNode->setIcon(GUI::ESystemIcon::OpenFolder); + + const std::string& fullPath = treeNode->getTagString(); + + std::vector files; + m_assetManager->getFolder(fullPath.c_str(), files); + + // addListFolder(fullPath, files); + } + } + + void CTreeFSController::expand(const std::string& folder) + { + std::string shortPath = m_assetManager->getShortPath(folder.c_str()); + if (shortPath.size() > 0) + { + std::vector result; + CStringImp::splitString(shortPath.c_str(), "/", result); + + GUI::CTreeNode* node = m_nodeAssets; + + wchar_t wname[512]; + + for (u32 i = 0, n = result.size(); i < n; i++) + { + const std::string name = result[i]; + CStringImp::convertUTF8ToUnicode(name.c_str(), wname); + + GUI::CTreeNode* child = node->getChildNodeByLabel(wname); + if (child == NULL) + break; + + if (child->haveChild()) + child->expand(false); + else + child->expand(true); + + node = child; + } + + if (node != NULL) + { + node->forceLayout(); + m_treeFS->getScrollControl()->scrollToItem(node); + } + } + } + + void CTreeFSController::OnKeyPress(GUI::CBase* control, int key, bool press) + { + GUI::CTreeControl* tree = dynamic_cast(control); + if (tree == NULL) + return; + + if (key == GUI::KEY_F2) + { + GUI::CTreeNode* node = tree->getChildSelected(); + if (node != NULL) + { + m_renameNode = node; + + node->getTextEditHelper()->beginEdit( + BIND_LISTENER(&CTreeFSController::OnRename, this), + BIND_LISTENER(&CTreeFSController::OnCancelRename, this) + ); + } + } + } + + void CTreeFSController::OnRename(GUI::CBase* control) + { + m_treeFS->focus(); + } + + void CTreeFSController::OnCancelRename(GUI::CBase* control) + { + m_treeFS->focus(); + } + } +} \ No newline at end of file diff --git a/Projects/Editor/Source/Editor/Space/Assets/CTreeFSController.h b/Projects/Editor/Source/Editor/Space/Assets/CTreeFSController.h new file mode 100644 index 000000000..8e66f7b8b --- /dev/null +++ b/Projects/Editor/Source/Editor/Space/Assets/CTreeFSController.h @@ -0,0 +1,68 @@ +/* +!@ +MIT License + +CopyRight (c) 2020 Skylicht Technology CO., LTD + +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. + +This file is part of the "Skylicht Engine". +https://github.com/skylicht-lab/skylicht-engine +!# +*/ + +#pragma once + +#include "GUI/GUI.h" +#include "AssetManager/CAssetManager.h" + +namespace Skylicht +{ + namespace Editor + { + class CTreeFSController + { + protected: + GUI::CTreeControl* m_treeFS; + + CAssetManager* m_assetManager; + + GUI::CTreeNode* m_nodeAssets; + + GUI::CTreeNode* m_renameNode; + + public: + CTreeFSController(GUI::CTreeControl* treeFS); + + virtual ~CTreeFSController(); + + void OnExpand(GUI::CBase* node); + + void OnCollapse(GUI::CBase* node); + + void OnSelected(GUI::CBase* node); + + void OnKeyPress(GUI::CBase* control, int key, bool press); + + void OnRename(GUI::CBase* control); + + void OnCancelRename(GUI::CBase* control); + + public: + void expand(const std::string& folder); + + void add(GUI::CTreeNode* node, std::vector& files); + }; + } +} \ No newline at end of file diff --git a/Projects/Editor/Source/GUI/Controls/CTabControl.h b/Projects/Editor/Source/GUI/Controls/CTabControl.h index 5f85d2c6f..878957c8a 100644 --- a/Projects/Editor/Source/GUI/Controls/CTabControl.h +++ b/Projects/Editor/Source/GUI/Controls/CTabControl.h @@ -82,7 +82,7 @@ namespace Skylicht inline u32 getNumTabButton() { - return m_tabButtons.size(); + return (u32)m_tabButtons.size(); } CTabButton* getCurrentTab() diff --git a/Projects/Editor/Source/GUI/Controls/CText.h b/Projects/Editor/Source/GUI/Controls/CText.h index 8dbdbbb74..93e12c7a1 100644 --- a/Projects/Editor/Source/GUI/Controls/CText.h +++ b/Projects/Editor/Source/GUI/Controls/CText.h @@ -53,12 +53,12 @@ namespace Skylicht inline u32 getLength() { - return m_string.size(); + return (u32)m_string.size(); } u32 getLengthNoNewLine() { - u32 length = m_string.size(); + u32 length = (u32)m_string.size(); if (length > 0) { if (m_string[length - 1] == '\n') diff --git a/Projects/Editor/Source/GUI/Controls/CTextContainer.h b/Projects/Editor/Source/GUI/Controls/CTextContainer.h index 410ce572c..9ae380d67 100644 --- a/Projects/Editor/Source/GUI/Controls/CTextContainer.h +++ b/Projects/Editor/Source/GUI/Controls/CTextContainer.h @@ -91,7 +91,7 @@ namespace Skylicht inline u32 getNumLine() { - return m_lines.size(); + return (u32)m_lines.size(); } CText* getLine(u32 line) @@ -138,7 +138,7 @@ namespace Skylicht inline u32 getLength() { - return m_string.size(); + return (u32)m_string.size(); } inline void setTextAlignment(ETextAlign align) diff --git a/Projects/Skylicht/Audio/Source/Decoder/CAudioDecoderMp3.cpp b/Projects/Skylicht/Audio/Source/Decoder/CAudioDecoderMp3.cpp index 340c35c7a..c3e33e67b 100644 --- a/Projects/Skylicht/Audio/Source/Decoder/CAudioDecoderMp3.cpp +++ b/Projects/Skylicht/Audio/Source/Decoder/CAudioDecoderMp3.cpp @@ -261,7 +261,7 @@ namespace SkylichtAudio { if (m_bitPerSample == 32) { - int numSample = bytes / 4; + int numSample = (int)(bytes / 4); resultDataSize = numSample * 2; resizeData(resultDataSize); @@ -273,7 +273,7 @@ namespace SkylichtAudio { if (m_bitPerSample == 16) { - resultDataSize = bytes; + resultDataSize = (int)bytes; resizeData(resultDataSize); memcpy(m_sampleDecodeBuffer, audio, bytes); diff --git a/Projects/Skylicht/Audio/Source/Engine/CAudioEmiter.cpp b/Projects/Skylicht/Audio/Source/Engine/CAudioEmiter.cpp index dff6f9602..189da416e 100644 --- a/Projects/Skylicht/Audio/Source/Engine/CAudioEmiter.cpp +++ b/Projects/Skylicht/Audio/Source/Engine/CAudioEmiter.cpp @@ -43,7 +43,7 @@ namespace SkylichtAudio IAudioDecoder::EDecoderType CAudioEmitter::getDecode(const char *fileName) { char ext[512] = { 0 }; - int len = strlen(fileName); + int len = (int)strlen(fileName); for (int i = len; i >= 0; i--) { if (fileName[i] == '.') diff --git a/Projects/Skylicht/Audio/Source/Engine/CAudioEngine.cpp b/Projects/Skylicht/Audio/Source/Engine/CAudioEngine.cpp index 0c6ccfd26..9977aff7e 100644 --- a/Projects/Skylicht/Audio/Source/Engine/CAudioEngine.cpp +++ b/Projects/Skylicht/Audio/Source/Engine/CAudioEngine.cpp @@ -230,7 +230,7 @@ namespace SkylichtAudio IStream *CAudioEngine::createStreamFromMemory(unsigned char *buffer, int size, bool takeOwnerShip) { - int numFactory = m_streamFactorys.size(); + int numFactory = (int)m_streamFactorys.size(); for (int i = numFactory - 1; i >= 0; i--) { IStream* s = m_streamFactorys[i]->createStreamFromMemory(buffer, size, takeOwnerShip); @@ -242,7 +242,7 @@ namespace SkylichtAudio IStream *CAudioEngine::createStreamFromFile(const char *fileName) { - int numFactory = m_streamFactorys.size(); + int numFactory = (int)m_streamFactorys.size(); for (int i = numFactory - 1; i >= 0; i--) { IStream* s = m_streamFactorys[i]->createStreamFromFile(fileName); diff --git a/Projects/Skylicht/Audio/Source/Stream/CFileStream.cpp b/Projects/Skylicht/Audio/Source/Stream/CFileStream.cpp index 5a7601c02..893c049a5 100644 --- a/Projects/Skylicht/Audio/Source/Stream/CFileStream.cpp +++ b/Projects/Skylicht/Audio/Source/Stream/CFileStream.cpp @@ -195,8 +195,7 @@ namespace SkylichtAudio return outBytes; } - int result = fread(m_buffer, readSize, 1, m_file); - + int result = (int)fread(m_buffer, readSize, 1, m_file); if (result == 0) { m_pos += outBytes; diff --git a/Projects/Skylicht/Client/Source/CApplication.cpp b/Projects/Skylicht/Client/Source/CApplication.cpp index f712443bb..1cb4e3389 100644 --- a/Projects/Skylicht/Client/Source/CApplication.cpp +++ b/Projects/Skylicht/Client/Source/CApplication.cpp @@ -436,7 +436,7 @@ namespace Skylicht char mac[512] = { 0 }; CStringImp::convertUnicodeToUTF8(string, mac); - for (int i = 0, n = strlen(mac); i < n; i++) + for (int i = 0, n = (int)strlen(mac); i < n; i++) { char c = mac[i]; bool isAnsi = (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '_'; @@ -462,7 +462,7 @@ namespace Skylicht char mac[512] = { 0 }; strcpy(mac, string); - for (int i = 0, n = strlen(mac); i < n; i++) + for (int i = 0, n = (int)strlen(mac); i < n; i++) { char c = mac[i]; bool isAnsi = (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '_'; diff --git a/Projects/Skylicht/Components/Source/ParticleSystem/Particles/CGroup.cpp b/Projects/Skylicht/Components/Source/ParticleSystem/Particles/CGroup.cpp index 632c045ef..893e2de3b 100644 --- a/Projects/Skylicht/Components/Source/ParticleSystem/Particles/CGroup.cpp +++ b/Projects/Skylicht/Components/Source/ParticleSystem/Particles/CGroup.cpp @@ -344,7 +344,7 @@ namespace Skylicht { int id = -1; - for (u32 i = 0, n = m_models.size(); i < n; i++) + for (u32 i = 0, n = (u32)m_models.size(); i < n; i++) { if (m_models[i]->getType() == param) { @@ -368,7 +368,7 @@ namespace Skylicht { int id = -1; - for (u32 i = 0, n = m_interpolators.size(); i < n; i++) + for (u32 i = 0, n = (u32)m_interpolators.size(); i < n; i++) { if (m_interpolators[i] == interpolator) { diff --git a/Projects/Skylicht/Components/Source/ParticleSystem/Particles/Systems/CParticleSystem.cpp b/Projects/Skylicht/Components/Source/ParticleSystem/Particles/Systems/CParticleSystem.cpp index b446ed933..bb8850e96 100644 --- a/Projects/Skylicht/Components/Source/ParticleSystem/Particles/Systems/CParticleSystem.cpp +++ b/Projects/Skylicht/Components/Source/ParticleSystem/Particles/Systems/CParticleSystem.cpp @@ -86,7 +86,7 @@ namespace Skylicht } // list model and param - u32 numModels = listModel.size(); + u32 numModels = (u32)listModel.size(); CModel** models = listModel.data(); EParticleParams* paramTypes = listParams.data(); CInterpolator** modelInterpolators = listModelInterpolators.data(); diff --git a/Projects/Skylicht/Engine/Source/Animation/CAnimation.cpp b/Projects/Skylicht/Engine/Source/Animation/CAnimation.cpp index 22f40076f..6118c1903 100644 --- a/Projects/Skylicht/Engine/Source/Animation/CAnimation.cpp +++ b/Projects/Skylicht/Engine/Source/Animation/CAnimation.cpp @@ -48,7 +48,7 @@ namespace Skylicht { m_clipName.clear(); - u32 numAnim = m_clips.size(); + u32 numAnim = (u32)m_clips.size(); for (u32 i = 0; i < numAnim - 1; i++) { for (u32 j = i + 1; j < numAnim; j++) diff --git a/Projects/Skylicht/Engine/Source/Camera/CFpsMoveCamera.cpp b/Projects/Skylicht/Engine/Source/Camera/CFpsMoveCamera.cpp index 90dae7931..7c1fca24c 100644 --- a/Projects/Skylicht/Engine/Source/Camera/CFpsMoveCamera.cpp +++ b/Projects/Skylicht/Engine/Source/Camera/CFpsMoveCamera.cpp @@ -87,7 +87,7 @@ namespace Skylicht switch (evt.EventType) { case EET_KEY_INPUT_EVENT: - for (u32 i = 0, n = m_keyMap.size(); i < n; ++i) + for (u32 i = 0, n = (u32)m_keyMap.size(); i < n; ++i) { if (m_keyMap[i].KeyCode == evt.KeyInput.Key) { diff --git a/Projects/Skylicht/Engine/Source/ConsoleLog/CConsoleLog.h b/Projects/Skylicht/Engine/Source/ConsoleLog/CConsoleLog.h index 6b8bb92c3..af1d7e3ad 100644 --- a/Projects/Skylicht/Engine/Source/ConsoleLog/CConsoleLog.h +++ b/Projects/Skylicht/Engine/Source/ConsoleLog/CConsoleLog.h @@ -70,7 +70,7 @@ namespace Skylicht inline u32 getLogCount() { - return m_logs.size(); + return (u32)m_logs.size(); } inline std::list& getLogs() diff --git a/Projects/Skylicht/Engine/Source/GameObject/CGameObject.cpp b/Projects/Skylicht/Engine/Source/GameObject/CGameObject.cpp index a7f0b7e06..b95edaa73 100644 --- a/Projects/Skylicht/Engine/Source/GameObject/CGameObject.cpp +++ b/Projects/Skylicht/Engine/Source/GameObject/CGameObject.cpp @@ -175,7 +175,7 @@ namespace Skylicht void CGameObject::updateObject() { - int numComponents = m_components.size(); + int numComponents = (int)m_components.size(); CComponentSystem** components = m_components.data(); for (int i = 0; i < numComponents; i++) @@ -187,7 +187,7 @@ namespace Skylicht void CGameObject::postUpdateObject() { - int numComponents = m_components.size(); + int numComponents = (int)m_components.size(); CComponentSystem** components = m_components.data(); for (int i = 0; i < numComponents; i++) @@ -199,7 +199,7 @@ namespace Skylicht void CGameObject::endUpdate() { - int numComponents = m_components.size(); + int numComponents = (int)m_components.size(); CComponentSystem** components = m_components.data(); for (int i = 0; i < numComponents; i++) diff --git a/Projects/Skylicht/Engine/Source/Graphics2D/Atlas/CAtlas.cpp b/Projects/Skylicht/Engine/Source/Graphics2D/Atlas/CAtlas.cpp index f972d97d9..91a2c5454 100644 --- a/Projects/Skylicht/Engine/Source/Graphics2D/Atlas/CAtlas.cpp +++ b/Projects/Skylicht/Engine/Source/Graphics2D/Atlas/CAtlas.cpp @@ -76,7 +76,7 @@ namespace Skylicht { core::recti ret(0, 0, 0, 0); - for (int i = 0, n = m_rects.size(); i < n; i++) + for (int i = 0, n = (int)m_rects.size(); i < n; i++) { if (m_rects[i].getWidth() >= w && m_rects[i].getHeight() >= h) @@ -141,7 +141,7 @@ namespace Skylicht bool add = false; int h = r.getHeight(); - for (int i = m_rects.size() - 1; i >= 0; i--) + for (int i = (int)m_rects.size() - 1; i >= 0; i--) { if (h > m_rects[i].getHeight()) { diff --git a/Projects/Skylicht/Engine/Source/Graphics2D/CGraphics2D.cpp b/Projects/Skylicht/Engine/Source/Graphics2D/CGraphics2D.cpp index 0c5c34e79..3678c1c4f 100644 --- a/Projects/Skylicht/Engine/Source/Graphics2D/CGraphics2D.cpp +++ b/Projects/Skylicht/Engine/Source/Graphics2D/CGraphics2D.cpp @@ -1242,12 +1242,12 @@ namespace Skylicht if (m_2dMaterial.getTexture(0) != frame->Image->Texture || m_2dMaterial.MaterialType != materialID || material != NULL) flush(); - int numSpriteVertex = frame->ModuleOffset.size() * 4; + int numSpriteVertex = (int)frame->ModuleOffset.size() * 4; int numVertices = m_vertices->getVertexCount(); int vertexUse = numVertices + numSpriteVertex; - int numSpriteIndex = frame->ModuleOffset.size() * 6; + int numSpriteIndex = (int)frame->ModuleOffset.size() * 6; int numIndices = m_indices->getIndexCount(); int indexUse = numIndices + numSpriteIndex; diff --git a/Projects/Skylicht/Engine/Source/Graphics2D/GUI/CGUIText.cpp b/Projects/Skylicht/Engine/Source/Graphics2D/GUI/CGUIText.cpp index 679c78900..d4ff63c53 100644 --- a/Projects/Skylicht/Engine/Source/Graphics2D/GUI/CGUIText.cpp +++ b/Projects/Skylicht/Engine/Source/Graphics2D/GUI/CGUIText.cpp @@ -434,7 +434,7 @@ namespace Skylicht m_font->updateFontTexture(); // calc multiline height - int textHeight = m_arrayCharRender.size() * (m_textHeight + m_linePadding); + int textHeight = (int)m_arrayCharRender.size() * (m_textHeight + m_linePadding); textHeight -= m_linePadding; int y = 0; diff --git a/Projects/Skylicht/Engine/Source/Graphics2D/Glyph/CGlyphFreetype.cpp b/Projects/Skylicht/Engine/Source/Graphics2D/Glyph/CGlyphFreetype.cpp index 9258573ba..1c3a04108 100644 --- a/Projects/Skylicht/Engine/Source/Graphics2D/Glyph/CGlyphFreetype.cpp +++ b/Projects/Skylicht/Engine/Source/Graphics2D/Glyph/CGlyphFreetype.cpp @@ -318,7 +318,7 @@ namespace Skylicht int atlasID = -1; core::recti region; - for (u32 i = 0, n = m_atlas.size(); i < n; i++) + for (u32 i = 0, n = (u32)m_atlas.size(); i < n; i++) { region = m_atlas[i]->createRect(cellW, cellH); diff --git a/Projects/Skylicht/Engine/Source/Graphics2D/SpriteFrame/CSpriteFont.cpp b/Projects/Skylicht/Engine/Source/Graphics2D/SpriteFrame/CSpriteFont.cpp index 2fd8c54d1..29a2de590 100644 --- a/Projects/Skylicht/Engine/Source/Graphics2D/SpriteFrame/CSpriteFont.cpp +++ b/Projects/Skylicht/Engine/Source/Graphics2D/SpriteFrame/CSpriteFont.cpp @@ -230,8 +230,8 @@ namespace Skylicht return NULL; - u32 index = p - m_moduleMap; - if (m_frames.size() < index) + u32 index = (u32)(p - m_moduleMap); + if ((u32)m_frames.size() < index) return NULL; SFrame& frame = *std::next(m_frames.begin(), index); diff --git a/Projects/Skylicht/Engine/Source/Importer/Collada/CColladaLoader.cpp b/Projects/Skylicht/Engine/Source/Importer/Collada/CColladaLoader.cpp index d6121c52d..66c190e8e 100644 --- a/Projects/Skylicht/Engine/Source/Importer/Collada/CColladaLoader.cpp +++ b/Projects/Skylicht/Engine/Source/Importer/Collada/CColladaLoader.cpp @@ -1217,7 +1217,7 @@ namespace Skylicht mesh->Joints[boneId].Weights.push_back(weightParam); mesh->JointIndex.push_back(boneId); - mesh->JointIndex.push_back(mesh->Joints[boneId].Weights.size() - 1); + mesh->JointIndex.push_back((int)mesh->Joints[boneId].Weights.size() - 1); } } @@ -1483,7 +1483,7 @@ namespace Skylicht void CColladaLoader::loadEffectTexture() { - for (u32 i = 0, n = m_listEffects.size(); i < n; i++) + for (u32 i = 0, n = (u32)m_listEffects.size(); i < n; i++) { SEffect& effect = m_listEffects[i]; ITexture *tex = NULL; @@ -2165,7 +2165,7 @@ namespace Skylicht int nJoint = (int)meshParam->Joints.size(); // setup joint name - int len = meshParam->ListJointName.size() + 1; + int len = (int)meshParam->ListJointName.size() + 1; wchar_t *listJointName = new wchar_t[len + 1]; CStringImp::copy(listJointName, meshParam->ListJointName.c_str()); @@ -2250,7 +2250,7 @@ namespace Skylicht memset(nBoneCount, 0, sizeof(int)*numVertex); // apply joint to vertex - for (u32 i = 0, n = meshParam->JointIndex.size(); i < n; i += 2) + for (u32 i = 0, n = (u32)meshParam->JointIndex.size(); i < n; i += 2) { int boneID = meshParam->JointIndex[i]; int weightID = meshParam->JointIndex[i + 1]; @@ -2280,7 +2280,7 @@ namespace Skylicht map.vertexId = weight.VertexID; std::vector& arrayVertexId = m_meshVertexIndex[map]; - u32 numVertexAffect = arrayVertexId.size(); + u32 numVertexAffect = (u32)arrayVertexId.size(); for (u32 j = 0; j < numVertexAffect; j++) { diff --git a/Projects/Skylicht/Engine/Source/Material/CMaterial.cpp b/Projects/Skylicht/Engine/Source/Material/CMaterial.cpp index 99e6a6887..c33f484d0 100644 --- a/Projects/Skylicht/Engine/Source/Material/CMaterial.cpp +++ b/Projects/Skylicht/Engine/Source/Material/CMaterial.cpp @@ -664,7 +664,7 @@ namespace Skylicht for (std::string &s : ui->AutoReplace) { found = false; - for (u32 i = 0, n = paths.size(); i < n; i++) + for (u32 i = 0, n = (u32)paths.size(); i < n; i++) { char t[512] = { 0 }; CStringImp::replaceText( @@ -693,7 +693,7 @@ namespace Skylicht { for (std::string &s : ui->AutoReplace) { - for (u32 i = 0, n = texNamePaths.size(); i < n; i++) + for (u32 i = 0, n = (u32)texNamePaths.size(); i < n; i++) { std::string fileName = texNamePaths[i]; fileName += s; diff --git a/Projects/Skylicht/Engine/Source/Material/CMaterialManager.cpp b/Projects/Skylicht/Engine/Source/Material/CMaterialManager.cpp index e87050978..59661dd99 100644 --- a/Projects/Skylicht/Engine/Source/Material/CMaterialManager.cpp +++ b/Projects/Skylicht/Engine/Source/Material/CMaterialManager.cpp @@ -47,7 +47,7 @@ namespace Skylicht while (i != end) { ArrayMaterial &list = (*i).second; - for (int j = 0, n = list.size(); j < n; j++) + for (int j = 0, n = (int)list.size(); j < n; j++) { delete list[j]; } @@ -341,7 +341,7 @@ namespace Skylicht } buffer += ""; - writeFile->write(buffer.c_str(), buffer.size()); + writeFile->write(buffer.c_str(), (u32)buffer.size()); writeFile->drop(); } @@ -441,7 +441,7 @@ namespace Skylicht } buffer += ""; - writeFile->write(buffer.c_str(), buffer.size()); + writeFile->write(buffer.c_str(), (u32)buffer.size()); writeFile->drop(); } diff --git a/Projects/Skylicht/Engine/Source/Material/Shader/CShader.cpp b/Projects/Skylicht/Engine/Source/Material/Shader/CShader.cpp index 8c2a89d29..eb3ba5157 100644 --- a/Projects/Skylicht/Engine/Source/Material/Shader/CShader.cpp +++ b/Projects/Skylicht/Engine/Source/Material/Shader/CShader.cpp @@ -406,7 +406,7 @@ namespace Skylicht std::vector listValue; CStringImp::splitString(text, ",", listValue); - int numValue = listValue.size(); + int numValue = (int)listValue.size(); if (numValue > uniform->FloatSize) numValue = uniform->FloatSize; diff --git a/Projects/Skylicht/Engine/Source/Material/Shader/CShaderManager.cpp b/Projects/Skylicht/Engine/Source/Material/Shader/CShaderManager.cpp index b1c82f526..594fdce1e 100644 --- a/Projects/Skylicht/Engine/Source/Material/Shader/CShaderManager.cpp +++ b/Projects/Skylicht/Engine/Source/Material/Shader/CShaderManager.cpp @@ -45,7 +45,7 @@ namespace Skylicht void CShaderManager::releaseAll() { - for (u32 i = 0, n = m_listShader.size(); i < n; i++) + for (u32 i = 0, n = (u32)m_listShader.size(); i < n; i++) m_listShader[i]->drop(); m_listShader.clear(); @@ -239,7 +239,7 @@ namespace Skylicht CShader* CShaderManager::getShaderByName(const char *name) { - for (u32 i = 0, n = m_listShader.size(); i < n; i++) + for (u32 i = 0, n = (u32)m_listShader.size(); i < n; i++) { if (m_listShader[i]->getName() == name) return m_listShader[i]; @@ -250,7 +250,7 @@ namespace Skylicht CShader* CShaderManager::getShaderByPath(const char *path) { - for (u32 i = 0, n = m_listShader.size(); i < n; i++) + for (u32 i = 0, n = (u32)m_listShader.size(); i < n; i++) { if (m_listShader[i]->getShaderPath() == path) return m_listShader[i]; @@ -261,7 +261,7 @@ namespace Skylicht CShader* CShaderManager::getShaderByID(int id) { - for (u32 i = 0, n = m_listShader.size(); i < n; i++) + for (u32 i = 0, n = (u32)m_listShader.size(); i < n; i++) { if (m_listShader[i]->getMaterialRenderID() == id) return m_listShader[i]; diff --git a/Projects/Skylicht/Engine/Source/Serializable/CObjectSerizable.h b/Projects/Skylicht/Engine/Source/Serializable/CObjectSerizable.h index 31eb6318a..d92e9d281 100644 --- a/Projects/Skylicht/Engine/Source/Serializable/CObjectSerizable.h +++ b/Projects/Skylicht/Engine/Source/Serializable/CObjectSerizable.h @@ -49,7 +49,7 @@ namespace Skylicht inline u32 getNumProperty() { - return m_value.size(); + return (u32)m_value.size(); } inline CValueProperty* getPropertyID(int i) diff --git a/Projects/Skylicht/Engine/Source/TextureManager/CTextureManager.cpp b/Projects/Skylicht/Engine/Source/TextureManager/CTextureManager.cpp index 05d614fe3..6e33d9e6e 100644 --- a/Projects/Skylicht/Engine/Source/TextureManager/CTextureManager.cpp +++ b/Projects/Skylicht/Engine/Source/TextureManager/CTextureManager.cpp @@ -219,7 +219,7 @@ namespace Skylicht io::IFileSystem *fs = getIrrlichtDevice()->getFileSystem(); - for (u32 i = 0, n = textureFolder.size(); i < n; i++) + for (u32 i = 0, n = (u32)textureFolder.size(); i < n; i++) { std::string s = textureFolder[i]; s += "/"; @@ -335,7 +335,7 @@ namespace Skylicht core::array paths; - for (u32 i = 0, n = listTexture.size(); i < n; i++) + for (u32 i = 0, n = (u32)listTexture.size(); i < n; i++) { std::string fixPath = CPath::normalizePath(listTexture[i]); paths.push_back(fixPath.c_str()); @@ -465,7 +465,7 @@ namespace Skylicht } else { - texture = driver->getTextureArray(listImage.data(), listImage.size()); + texture = driver->getTextureArray(listImage.data(), (u32)listImage.size()); // register the texture if (texture) @@ -479,7 +479,7 @@ namespace Skylicht } // release - for (u32 i = 0, n = listImage.size(); i < n; i++) + for (u32 i = 0, n = (u32)listImage.size(); i < n; i++) { if (listImage[i] != NULL) listImage[i]->drop(); diff --git a/Projects/Skylicht/Engine/Source/Utils/CActivator.cpp b/Projects/Skylicht/Engine/Source/Utils/CActivator.cpp index 2174610d9..7faf3cfba 100644 --- a/Projects/Skylicht/Engine/Source/Utils/CActivator.cpp +++ b/Projects/Skylicht/Engine/Source/Utils/CActivator.cpp @@ -36,7 +36,7 @@ namespace Skylicht IActivatorObject* CActivator::createInstance(const char *type) { - for (u32 i = 0, n = m_factoryName.size(); i < n; i++) + for (u32 i = 0, n = (u32)m_factoryName.size(); i < n; i++) { if (m_factoryName[i] == type) { diff --git a/Projects/Skylicht/Engine/Source/Utils/CMemoryStream.cpp b/Projects/Skylicht/Engine/Source/Utils/CMemoryStream.cpp index 54ce5215b..42c71287b 100644 --- a/Projects/Skylicht/Engine/Source/Utils/CMemoryStream.cpp +++ b/Projects/Skylicht/Engine/Source/Utils/CMemoryStream.cpp @@ -162,7 +162,7 @@ namespace Skylicht void CMemoryStream::writeString(const std::string& s) { - int size = s.size() + 1; + int size = (int)s.size() + 1; autoGrow(size); // write num char diff --git a/Projects/Skylicht/Engine/Source/Utils/CPath.cpp b/Projects/Skylicht/Engine/Source/Utils/CPath.cpp index b8ea8b7bc..d80e49e19 100644 --- a/Projects/Skylicht/Engine/Source/Utils/CPath.cpp +++ b/Projects/Skylicht/Engine/Source/Utils/CPath.cpp @@ -81,7 +81,7 @@ namespace Skylicht listFolder.push_back(resultPath); } - for (u32 i = 0, n = listFolder.size(); i < n; i++) + for (u32 i = 0, n = (u32)listFolder.size(); i < n; i++) { if (listFolder[i] != ".." || finalFolder.size() == 0) finalFolder.push_back(listFolder[i]); @@ -94,7 +94,7 @@ namespace Skylicht std::string finalPath; - for (u32 i = 0, n = finalFolder.size(); i < n; i++) + for (u32 i = 0, n = (u32)finalFolder.size(); i < n; i++) { finalPath += finalFolder[i]; if (i + 1 < n) diff --git a/Projects/Skylicht/Engine/Source/Utils/XMLSpreadsheet/CXMLSpreadsheet.cpp b/Projects/Skylicht/Engine/Source/Utils/XMLSpreadsheet/CXMLSpreadsheet.cpp index 0e8c295a6..e1379e54f 100644 --- a/Projects/Skylicht/Engine/Source/Utils/XMLSpreadsheet/CXMLSpreadsheet.cpp +++ b/Projects/Skylicht/Engine/Source/Utils/XMLSpreadsheet/CXMLSpreadsheet.cpp @@ -341,7 +341,7 @@ namespace Skylicht row = 0; col = 0; - int n = strlen(cellName); + int n = (int)strlen(cellName); if (n > 64) return false; @@ -374,7 +374,7 @@ namespace Skylicht int rangeValue = 25; // 'Z' - 'A'; int base = 1; - for (int i = strlen(colName) - 1; i >= 0; i--) + for (int i = (int)strlen(colName) - 1; i >= 0; i--) { col += (colName[i] - 'A') * base; base = base * rangeValue; diff --git a/Projects/Skylicht/Engine/Source/Utils/XMLSpreadsheet/CXMLSpreadsheet.h b/Projects/Skylicht/Engine/Source/Utils/XMLSpreadsheet/CXMLSpreadsheet.h index 32c5c5271..cc996b0ea 100644 --- a/Projects/Skylicht/Engine/Source/Utils/XMLSpreadsheet/CXMLSpreadsheet.h +++ b/Projects/Skylicht/Engine/Source/Utils/XMLSpreadsheet/CXMLSpreadsheet.h @@ -112,7 +112,7 @@ namespace Skylicht inline u32 getSheetCount() { - return m_sheets.size(); + return (u32)m_sheets.size(); } SSheet* getSheet(int i) diff --git a/Projects/Skylicht/Engine/Source/Utils/XMLSpreadsheet/CXMLTableData.h b/Projects/Skylicht/Engine/Source/Utils/XMLSpreadsheet/CXMLTableData.h index 146f15277..b962eb918 100644 --- a/Projects/Skylicht/Engine/Source/Utils/XMLSpreadsheet/CXMLTableData.h +++ b/Projects/Skylicht/Engine/Source/Utils/XMLSpreadsheet/CXMLTableData.h @@ -54,12 +54,12 @@ namespace Skylicht u32 getNumColumn() { - return m_column.size(); + return (u32)m_column.size(); } u32 getNumRow() { - return m_sheet->Rows.size(); + return (u32)m_sheet->Rows.size(); } template @@ -137,7 +137,7 @@ namespace Skylicht ++i; } - return data.size(); + return (u32)data.size(); } }; } \ No newline at end of file diff --git a/Projects/Skylicht/Lightmapper/Source/Lightmapper/CLightmapper.cpp b/Projects/Skylicht/Lightmapper/Source/Lightmapper/CLightmapper.cpp index 1c6d1af93..6903216bf 100644 --- a/Projects/Skylicht/Lightmapper/Source/Lightmapper/CLightmapper.cpp +++ b/Projects/Skylicht/Lightmapper/Source/Lightmapper/CLightmapper.cpp @@ -153,7 +153,7 @@ namespace Skylicht core::array normals; core::array tangents; core::array binormals; - for (u32 i = 0, n = probes.size(); i < n; i++) + for (u32 i = 0, n = (u32)probes.size(); i < n; i++) { CLightProbe* probe = probes[i]; @@ -183,7 +183,7 @@ namespace Skylicht (int)probes.size()); // apply sh - for (u32 i = 0, n = probes.size(); i < n; i++) + for (u32 i = 0, n = (u32)probes.size(); i < n; i++) probes[i]->setSH(out[i]); } diff --git a/Samples/Lightmapping/Source/CViewBakeLightmap.cpp b/Samples/Lightmapping/Source/CViewBakeLightmap.cpp index 3e7b1ef0a..d97181653 100644 --- a/Samples/Lightmapping/Source/CViewBakeLightmap.cpp +++ b/Samples/Lightmapping/Source/CViewBakeLightmap.cpp @@ -487,7 +487,7 @@ void CViewBakeLightmap::saveProgress() stream->writeUInt(m_numIndices); stream->writeUInt(m_numVertices); stream->writeUInt(m_lightmapSize); - stream->writeUInt(m_meshBuffers.size()); + stream->writeUInt((u32)m_meshBuffers.size()); stream->writeInt(m_lightBounce); stream->writeInt(m_currentPass); diff --git a/Samples/LightmappingVertex/Source/CViewBakeLightmap.cpp b/Samples/LightmappingVertex/Source/CViewBakeLightmap.cpp index 5660d55de..d620ee61c 100644 --- a/Samples/LightmappingVertex/Source/CViewBakeLightmap.cpp +++ b/Samples/LightmappingVertex/Source/CViewBakeLightmap.cpp @@ -134,7 +134,7 @@ void CViewBakeLightmap::onUpdate() numLightBounce = CDirectionalLight::getCurrentDirectionLight()->getBounce(); // bake lightmap - u32 numMB = m_neshBuffers.size(); + u32 numMB = (u32)m_neshBuffers.size(); if (m_currentMeshBuffer < numMB && numLightBounce > 0) { if (m_lightBounce == 0) @@ -221,7 +221,7 @@ void CViewBakeLightmap::onUpdate() void CViewBakeLightmap::copyColorBufferToMeshBuffer() { // copy baked color buffer to mesh buffer - for (u32 i = 0, n = m_neshBuffers.size(); i < n; i++) + for (u32 i = 0, n = (u32)m_neshBuffers.size(); i < n; i++) { IMeshBuffer *mb = m_neshBuffers[i]; SColorBuffer *cb = m_colorBuffers[i]; diff --git a/Samples/LuckyDraw/Source/CList.cpp b/Samples/LuckyDraw/Source/CList.cpp index e93a53477..8749a76a0 100644 --- a/Samples/LuckyDraw/Source/CList.cpp +++ b/Samples/LuckyDraw/Source/CList.cpp @@ -83,7 +83,7 @@ bool CList::OnEvent(const SEvent& gameEvent) { m_mousePress = true; m_drag = 0.0f; - m_mousePosY = gameEvent.MouseInput.Y; + m_mousePosY = (float)gameEvent.MouseInput.Y; m_mousePressPosY = m_mousePosY; m_sendSelectEvent = false; return true; @@ -91,9 +91,9 @@ bool CList::OnEvent(const SEvent& gameEvent) else if (gameEvent.MouseInput.Event == EMIE_MOUSE_MOVED && m_mousePress) { // drag - m_drag = gameEvent.MouseInput.Y - m_mousePressPosY; - m_dragSpeed = gameEvent.MouseInput.Y - m_mousePosY; - m_mousePosY = gameEvent.MouseInput.Y; + m_drag = (float)(gameEvent.MouseInput.Y - m_mousePressPosY); + m_dragSpeed = (float)(gameEvent.MouseInput.Y - m_mousePosY); + m_mousePosY = (float)gameEvent.MouseInput.Y; // do not send select event if (fabsf(m_drag) > 30) @@ -165,7 +165,7 @@ void CList::updateItemMovement() { itemHeight = m_items[0]->getHeight(); - int numRow = m_element->getHeight() / itemHeight; + int numRow = (int)(m_element->getHeight() / itemHeight); m_maxOffset = itemHeight * 0.5f; @@ -224,7 +224,7 @@ void CList::calcTargetOffset() { float itemHeight = (float)m_items[0]->getHeight(); - int selectItem = m_offset / itemHeight; + int selectItem = (int)(m_offset / itemHeight); if (-m_offset - (-selectItem * itemHeight) > itemHeight * 0.5f) selectItem--; diff --git a/Samples/LuckyDraw/Source/CScrollerController.cpp b/Samples/LuckyDraw/Source/CScrollerController.cpp index 9c000b3a8..b2446ac52 100644 --- a/Samples/LuckyDraw/Source/CScrollerController.cpp +++ b/Samples/LuckyDraw/Source/CScrollerController.cpp @@ -131,7 +131,7 @@ void CScrollerController::beginScroll() { m_stopPosition = 0; - for (u32 i = 0, n = m_scrollers.size(); i < n; i++) + for (u32 i = 0, n = (u32)m_scrollers.size(); i < n; i++) { SScrollerInfo& s = m_scrollers[i]; s.TargetSpeed = MAX_SPEED; @@ -143,7 +143,7 @@ void CScrollerController::beginScroll() bool CScrollerController::stopReady() { - for (u32 i = 0, n = m_scrollers.size(); i < n; i++) + for (u32 i = 0, n = (u32)m_scrollers.size(); i < n; i++) { if (m_scrollers[i].Speed <= READY_TARGET_SPEED || m_scrollers[i].State != Scrolling) @@ -155,7 +155,7 @@ bool CScrollerController::stopReady() void CScrollerController::newRound() { - for (u32 i = 0, n = m_scrollers.size(); i < n; i++) + for (u32 i = 0, n = (u32)m_scrollers.size(); i < n; i++) { m_scrollers[i].State = NewRound; } @@ -163,7 +163,7 @@ void CScrollerController::newRound() bool CScrollerController::isFinished() { - for (u32 i = 0, n = m_scrollers.size(); i < n; i++) + for (u32 i = 0, n = (u32)m_scrollers.size(); i < n; i++) { if (m_scrollers[i].State != Finish) return false; @@ -174,7 +174,7 @@ bool CScrollerController::isFinished() bool CScrollerController::isLastStopPosition() { - int scroll = m_scrollers.size() - 1; + int scroll = (int)m_scrollers.size() - 1; if (scroll < 0) scroll = 0;