├── .gitignore ├── .gitmodules ├── CMakeLists.txt ├── Editor └── res ├── External ├── CMakeLists.txt └── PrebuiltLibs │ └── x86 │ ├── Debug │ └── readme.txt │ └── Release │ └── readme.txt ├── LICENSE ├── Platform └── Windows │ ├── Common │ ├── Base │ │ ├── DoubleBufferedWindow.cpp │ │ ├── DoubleBufferedWindow.h │ │ ├── EventDispatcher.cpp │ │ ├── EventDispatcher.h │ │ ├── Window.cpp │ │ ├── Window.h │ │ ├── WindowContainer.cpp │ │ └── WindowContainer.h │ ├── Control │ │ ├── Button │ │ │ ├── ImageButton.cpp │ │ │ ├── ImageButton.h │ │ │ ├── TabButton.cpp │ │ │ ├── TabButton.h │ │ │ ├── TwoStateButton.cpp │ │ │ └── TwoStateButton.h │ │ ├── Image │ │ │ ├── SelectableImage.cpp │ │ │ ├── SelectableImage.h │ │ │ ├── SimpleImage.cpp │ │ │ └── SimpleImage.h │ │ ├── Text │ │ │ ├── StaticText.cpp │ │ │ └── StaticText.h │ │ ├── UINode.cpp │ │ └── UINode.h │ ├── CursorManager.cpp │ ├── CursorManager.h │ ├── MainWindow.cpp │ ├── MainWindow.h │ ├── PlatformWindowsSeriallizer.pb.cc │ ├── PlatformWindowsSeriallizer.pb.h │ ├── TabWindow.cpp │ ├── TabWindow.h │ ├── ViewWindow.cpp │ ├── ViewWindow.h │ ├── WinEnviroment.cpp │ ├── WinEnviroment.h │ ├── WinResources.cpp │ └── WinResources.h │ ├── Editor │ ├── CMakeLists.txt │ ├── EditorMainWindow.cpp │ ├── EditorMainWindow.h │ ├── HierarchyWindow │ │ ├── HierarchyWindow.cpp │ │ └── HierarchyWindow.h │ ├── InspectorWindow │ │ ├── InspectorWindow.cpp │ │ └── InspectorWindow.h │ ├── Menu │ │ ├── MenuItemDefine.h │ │ ├── PopupMenuButton.cpp │ │ └── PopupMenuButton.h │ ├── ProjectWindow │ │ ├── ProjectWindow.cpp │ │ └── ProjectWindow.h │ ├── SceneWindow │ │ ├── SceneWindow.cpp │ │ └── SceneWindow.h │ ├── TopMenuWindow │ │ ├── TopMenuWindow.cpp │ │ └── TopMenuWindow.h │ ├── TopToolsWindow │ │ ├── TopToolsWindow.cpp │ │ └── TopToolsWindow.h │ └── main.cpp │ └── Player │ ├── CMakeLists.txt │ └── main.cpp ├── README.md ├── Resources ├── CMakeLists.txt ├── Raw │ ├── AliceTab.png │ ├── HierarchyWindowIcon.png │ ├── InspectorWindowIcon.png │ ├── PlayDown.png │ ├── PlayNormal.png │ ├── ProjectWindowIcon.png │ ├── SceneViewIcon.png │ └── close_btn.png ├── res └── src │ └── main.cpp ├── Runtime ├── Allocator │ ├── AliceMemory.h │ ├── DefaultAllocator.cpp │ ├── DefaultAllocator.h │ ├── MemoryLabel.h │ └── tlsf │ │ ├── tlsf.c │ │ ├── tlsf.h │ │ └── tlsfbits.h ├── Base │ ├── Object.cpp │ └── Object.h ├── BattleFirePrefix.h ├── Debugger │ ├── Logger.cpp │ └── Logger.h ├── IO │ ├── AliceData.cpp │ ├── AliceData.h │ ├── FileItem.cpp │ ├── FileItem.h │ ├── FileSystem.cpp │ ├── FileSystem.h │ ├── ResourceManager.cpp │ └── ResourceManager.h ├── String │ ├── FixedString.cpp │ ├── FixedString.h │ ├── StringUtils.cpp │ └── StringUtils.h └── Utils │ ├── LinkedList.h │ ├── SmartPtr.h │ ├── TTree.cpp │ └── TTree.h ├── ScreenShot ├── 1.jpg ├── 1.png ├── 2.jpg ├── 3.jpg └── 4.jpg └── Tools ├── PlatformWindowsSeriallizer.proto ├── buildSerillizer.bat └── protoc.exe /.gitignore: -------------------------------------------------------------------------------- 1 | **/*.vs 2 | **/*build 3 | **/*Project 4 | /External/PrebuiltLibs/x86/Debug/libprotobuf.lib 5 | /External/PrebuiltLibs/x86/Release/libprotobuf.lib 6 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "External/Box2D"] 2 | path = External/Box2D 3 | url = https://github.com/erincatto/box2d.git 4 | [submodule "External/PBC"] 5 | path = External/PBC 6 | url = https://github.com/BattleFireLTD/PBC.git 7 | [submodule "External/Lua5.1.4"] 8 | path = External/Lua5.1.4 9 | url = https://github.com/BattleFireLTD/Lua5.1.4.git 10 | [submodule "External/PhysX3.4"] 11 | path = External/PhysX3.4 12 | url = https://github.com/NVIDIAGameWorks/PhysX-3.4.git 13 | [submodule "External/zlib"] 14 | path = External/zlib 15 | url = https://github.com/madler/zlib.git 16 | [submodule "External/LuaSocket"] 17 | path = External/LuaSocket 18 | url = https://github.com/BattleFireLTD/LuaSocket.git 19 | [submodule "External/LibZipRel"] 20 | path = External/LibZipRel 21 | url = https://github.com/BattleFireLTD/LibZipRel.git 22 | [submodule "External/LibCurl"] 23 | path = External/LibCurl 24 | url = https://github.com/BattleFireLTD/LibCurl.git 25 | [submodule "External/FreeType"] 26 | path = External/FreeType 27 | url = https://github.com/BattleFireLTD/FreeType.git -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | CMAKE_MINIMUM_REQUIRED(VERSION 2.6) 2 | Project(BattleFireEngine) 3 | 4 | function(GroupDirectories dirPrefix groupPrefix targetDir sources) 5 | get_filename_component(currentDirName ${targetDir} NAME) 6 | string(CONCAT currentDirFullName "${dirPrefix}${currentDirName}/") 7 | string(CONCAT currentDirGroupName "${groupPrefix}${currentDirName}") 8 | file(GLOB allFiles "${targetDir}/*") 9 | file(GLOB allCFiles "${targetDir}/*.c") 10 | file(GLOB allHFiles "${targetDir}/*.h*") 11 | file(GLOB allCXXFiles "${targetDir}/*.c*") 12 | 13 | list(LENGTH allFiles argv_len) 14 | list(LENGTH allCFiles lenC) 15 | list(LENGTH allCXXFiles lenCXX) 16 | list(LENGTH allHFiles lenH) 17 | 18 | set(allUsefulFileCount 0) 19 | math(EXPR allUsefulFileCount "${lenC}+${lenCXX}+${lenH}") 20 | if(0 LESS allUsefulFileCount) 21 | set(mGroups ${allCFiles} ${allCXXFiles} ${allHFiles}) 22 | source_group(${currentDirGroupName} FILES ${mGroups}) 23 | message(STATUS "${currentDirGroupName} c:${lenC} cxx:${lenCXX} h:${lenH} total:${argv_len}") 24 | endif() 25 | set(i 0) 26 | while( i LESS ${argv_len}) 27 | list(GET allFiles ${i} argv_value) 28 | if(IS_DIRECTORY ${argv_value}) 29 | #deal with directory 30 | #message(STATUS "${argv_value}") 31 | string(CONCAT currentGroupPrefix "${groupPrefix}${currentDirName}\\") 32 | GroupDirectories(${currentDirFullName} ${currentGroupPrefix} ${argv_value} subGroups) 33 | list(APPEND mGroups ${subGroups}) 34 | else() 35 | #deal with files 36 | #message(STATUS "file ${argv_value}") 37 | endif() 38 | math(EXPR i "${i} + 1") 39 | endwhile() 40 | set(${sources} ${mGroups} PARENT_SCOPE) 41 | endfunction() 42 | 43 | if(WIN32) 44 | include_directories(${PROJECT_SOURCE_DIR}) 45 | include_directories(${PROJECT_SOURCE_DIR}/External/Box2D/include) 46 | include_directories(${PROJECT_SOURCE_DIR}/External/PBC/src) 47 | include_directories(${PROJECT_SOURCE_DIR}/External/ProtoBuffer3.13/src) 48 | include_directories(${PROJECT_SOURCE_DIR}/External/Lua5.1.4/src) 49 | include_directories(${PROJECT_SOURCE_DIR}/External/PhysX3.4/PhysX_3.4/Include) 50 | include_directories(${PROJECT_SOURCE_DIR}/External/PhysX3.4/PxShared/include) 51 | include_directories(${PROJECT_SOURCE_DIR}/External/zlib) 52 | include_directories(${PROJECT_SOURCE_DIR}/External/LuaSocket/src) 53 | include_directories(${PROJECT_SOURCE_DIR}/External/LibZipRel/lib) 54 | include_directories(${PROJECT_SOURCE_DIR}/External/LibZipRel/build) 55 | include_directories(${PROJECT_SOURCE_DIR}/External/LibCurl/include) 56 | include_directories(${PROJECT_SOURCE_DIR}/External/FreeType/include) 57 | add_subdirectory(${PROJECT_SOURCE_DIR}/Platform/Windows/Editor) 58 | add_subdirectory(${PROJECT_SOURCE_DIR}/Platform/Windows/Player) 59 | ENDIF() -------------------------------------------------------------------------------- /Editor/res: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BattleFireLTD/Engine/eae9aae7dc63aec341c0bbc0a33ba7f9a136df19/Editor/res -------------------------------------------------------------------------------- /External/CMakeLists.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BattleFireLTD/Engine/eae9aae7dc63aec341c0bbc0a33ba7f9a136df19/External/CMakeLists.txt -------------------------------------------------------------------------------- /External/PrebuiltLibs/x86/Debug/readme.txt: -------------------------------------------------------------------------------- 1 | 把所有第三方库的Debug版编译好了之后,放这里 -------------------------------------------------------------------------------- /External/PrebuiltLibs/x86/Release/readme.txt: -------------------------------------------------------------------------------- 1 | 把所有第三方库的Release版编译好了之后,放这里 -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 battlefireopen 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Platform/Windows/Common/Base/DoubleBufferedWindow.cpp: -------------------------------------------------------------------------------- 1 | #include "DoubleBufferedWindow.h" 2 | #include "Runtime/Debugger/Logger.h" 3 | namespace Editor{ 4 | DoubleBufferedWindow::DoubleBufferedWindow():mBKGDC(nullptr),mBKGBMP(nullptr){ 5 | mBufferWidth = 0; 6 | mChild = nullptr; 7 | } 8 | void DoubleBufferedWindow::OnPaint(const Gdiplus::Rect & rect_need_update){ 9 | if (mBufferWidth != mRect.Width || mBufferHeight != mRect.Height){ 10 | InitDoubleBuffer(); 11 | } 12 | //Debug("DoubleBufferedWindow::OnPaint %s rect[%d,%d,%d,%d] wrect[%d,%d,%d,%d]", mName, 13 | // rect_need_update.X, rect_need_update.Y, rect_need_update.Width, rect_need_update.Height, 14 | // mRect.X, mRect.Y, mRect.Width, mRect.Height); 15 | Gdiplus::Graphics painter(mBKGDC); 16 | OnClearBKG(painter); 17 | DrawContent(painter); 18 | RenderChildren(painter,rect_need_update); 19 | OnEndPaint(); 20 | } 21 | void DoubleBufferedWindow::OnPaintNoUpdateRect() { 22 | } 23 | void DoubleBufferedWindow::OnEndPaint(){ 24 | BitBlt(mHDC, 0, 0, mBufferWidth, mBufferHeight, mBKGDC, 0, 0, SRCCOPY); 25 | } 26 | LRESULT DoubleBufferedWindow::OnNCPAINT(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam, void*reserved /* = nullptr */) { 27 | return 0; 28 | } 29 | void DoubleBufferedWindow::InitDoubleBuffer(){ 30 | if (mBufferWidth == 0) {//first time come here 31 | mBKGDC = CreateCompatibleDC(mHDC); 32 | } 33 | if (mBKGBMP != nullptr){ 34 | DeleteObject(mBKGBMP); 35 | } 36 | mBufferWidth = mRect.Width; 37 | mBufferHeight = mRect.Height; 38 | mBKGBMP = CreateCompatibleBitmap(mHDC, mBufferWidth, mBufferHeight); 39 | SelectObject(mBKGDC, mBKGBMP); 40 | } 41 | } -------------------------------------------------------------------------------- /Platform/Windows/Common/Base/DoubleBufferedWindow.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Window.h" 3 | namespace Editor{ 4 | class DoubleBufferedWindow :public BaseWindow{ 5 | protected: 6 | HDC mBKGDC; 7 | HBITMAP mBKGBMP; 8 | int mBufferWidth, mBufferHeight; 9 | protected: 10 | virtual void OnPaint(const Gdiplus::Rect & rect_need_update); 11 | void OnPaintNoUpdateRect(); 12 | virtual void OnEndPaint(); 13 | virtual LRESULT OnNCPAINT(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam, void*reserved = nullptr); 14 | public: 15 | BaseWindow * mChild; 16 | DoubleBufferedWindow(); 17 | void InitDoubleBuffer(); 18 | }; 19 | } -------------------------------------------------------------------------------- /Platform/Windows/Common/Base/EventDispatcher.cpp: -------------------------------------------------------------------------------- 1 | #include "EventDispatcher.h" 2 | #include "Runtime/Debugger/Logger.h" 3 | namespace Editor 4 | { 5 | EventDispatcher::EventDispatcher() :mbMouseLeaved(false) 6 | { 7 | mbIsIMEInput = false; 8 | } 9 | 10 | void EventDispatcher::OnLButtonDown(WPARAM wParam, LPARAM lParam, void*reserved /* = nullptr */) 11 | { 12 | 13 | } 14 | 15 | void EventDispatcher::OnLButtonUp(WPARAM wParam, LPARAM lParam, void*reserved /* = nullptr */) 16 | { 17 | 18 | } 19 | 20 | void EventDispatcher::OnLButtonDoubleClick(WPARAM wParam, LPARAM lParam, void*reserved /* = nullptr */) 21 | { 22 | 23 | } 24 | 25 | void EventDispatcher::OnKeyDown(WPARAM wParam, LPARAM lParam, void*reserved /* = nullptr */) 26 | { 27 | 28 | } 29 | void EventDispatcher::OnKeyUp(WPARAM wParam, LPARAM lParam, void*reserved /* = nullptr */) 30 | { 31 | 32 | } 33 | void EventDispatcher::OnChar(WPARAM wParam, LPARAM lParam, void*reserved /* = nullptr */) 34 | { 35 | 36 | } 37 | void EventDispatcher::OnIMEChar(WPARAM wParam, LPARAM lParam, void*reserved /* = nullptr */) 38 | { 39 | 40 | } 41 | void EventDispatcher::OnMouseWheel(WPARAM wParam, LPARAM lParam, void*reserved /* = nullptr */) 42 | { 43 | 44 | } 45 | void EventDispatcher::OnCloseWindow(WPARAM wParam, LPARAM lParam, void*reserved /* = nullptr */) 46 | { 47 | 48 | } 49 | 50 | void EventDispatcher::OnFocus(WPARAM wParam, LPARAM lParam, void*reserved /* = nullptr */) 51 | { 52 | 53 | } 54 | 55 | void EventDispatcher::OnSize(WPARAM wParam, LPARAM lParam, void*reserved) 56 | { 57 | 58 | } 59 | 60 | LRESULT EventDispatcher::OnSizing(WPARAM wParam, LPARAM lParam, void*reserved) 61 | { 62 | return DefWindowProc(mhWnd, WM_SIZING, wParam, lParam); 63 | } 64 | 65 | void EventDispatcher::OnMove(WPARAM wParam, LPARAM lParam, void*reserved) 66 | { 67 | } 68 | 69 | void EventDispatcher::OnMoving(WPARAM wParam, LPARAM lParam, void*reserved) 70 | { 71 | } 72 | 73 | void EventDispatcher::OnGetMinMaxInfo(WPARAM wParam, LPARAM lParam, void*reserved /* = nullptr */) 74 | { 75 | 76 | } 77 | 78 | void EventDispatcher::OnPaint(const Gdiplus::Rect & rect_need_update){ 79 | } 80 | 81 | void EventDispatcher::OnTimer(WPARAM wParam, LPARAM lParam, void*reserved /* = nullptr */) 82 | { 83 | 84 | } 85 | 86 | void EventDispatcher::OnCommand(WPARAM wParam, LPARAM lParam, void*reserved /* = nullptr */) 87 | { 88 | 89 | } 90 | 91 | 92 | void EventDispatcher::OnRButtonDown(WPARAM wParam, LPARAM lParam, void*reserved /* = nullptr */) 93 | { 94 | 95 | } 96 | 97 | void EventDispatcher::OnRButtonUp(WPARAM wParam, LPARAM lParam, void*reserved /* = nullptr */) 98 | { 99 | 100 | } 101 | 102 | void EventDispatcher::OnMiddleButtonDown(WPARAM wParam, LPARAM lParam, void*reserved /* = nullptr */) 103 | { 104 | 105 | } 106 | 107 | void EventDispatcher::OnMiddleButtonUp(WPARAM wParam, LPARAM lParam, void*reserved /* = nullptr */) 108 | { 109 | 110 | } 111 | 112 | void EventDispatcher::OnDropFiles(WPARAM wParam, LPARAM lParam, void*reserved /* = nullptr */) 113 | { 114 | 115 | } 116 | 117 | void EventDispatcher::OnMouseMove(WPARAM wParam, LPARAM lParam, void*reserved /* = nullptr */) 118 | { 119 | if (!mbMouseLeaved) 120 | { 121 | TRACKMOUSEEVENT csTME; 122 | csTME.cbSize = sizeof(csTME); 123 | csTME.dwFlags = TME_LEAVE | TME_HOVER; 124 | csTME.hwndTrack = mhWnd; 125 | csTME.dwHoverTime = 10; 126 | TrackMouseEvent(&csTME); 127 | mbMouseLeaved = true; 128 | } 129 | } 130 | 131 | void EventDispatcher::OnMouseLeave(WPARAM wParam, LPARAM lParam, void*reserved /* = nullptr */) 132 | { 133 | mbMouseLeaved = false; 134 | } 135 | 136 | LRESULT EventDispatcher::OnNCPAINT(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam, void*reserved /* = nullptr */) 137 | { 138 | return DefWindowProc(hWnd, message, wParam, lParam); 139 | } 140 | 141 | LRESULT EventDispatcher::OnNCACTIVATE(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam, void*reserved /* = nullptr */) 142 | { 143 | return DefWindowProc(hWnd, message, wParam, lParam); 144 | } 145 | 146 | LRESULT EventDispatcher::OnNCCALCSIZE(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam, void*reserved /* = nullptr */) 147 | { 148 | return DefWindowProc(hWnd, message, wParam, lParam); 149 | } 150 | 151 | LRESULT EventDispatcher::OnNCHITTEST(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam, void*reserved /* = nullptr */) 152 | { 153 | return DefWindowProc(hWnd, message, wParam, lParam); 154 | } 155 | 156 | LRESULT EventDispatcher::OnNCLBUTTONUP(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam, void*reserved /* = nullptr */) 157 | { 158 | return DefWindowProc(hWnd, message, wParam, lParam); 159 | } 160 | 161 | LRESULT EventDispatcher::OnNCLBUTTONDOWN(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam, void*reserved /* = nullptr */) 162 | { 163 | return DefWindowProc(hWnd, message, wParam, lParam); 164 | } 165 | 166 | LRESULT EventDispatcher::OnNCLBUTTONDBLCLK(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam, void*reserved /* = nullptr */) 167 | { 168 | return DefWindowProc(hWnd, message, wParam, lParam); 169 | } 170 | 171 | LRESULT EventDispatcher::OnNCMOUSEMOVE(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam, void*reserved /* = nullptr */) 172 | { 173 | return DefWindowProc(hWnd, message, wParam, lParam); 174 | } 175 | 176 | LRESULT EventDispatcher::OnNCRBUTTONUP(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam, void*reserved /* = nullptr */) 177 | { 178 | return DefWindowProc(hWnd, message, wParam, lParam); 179 | } 180 | 181 | LRESULT EventDispatcher::OnNCRBUTTONDOWN(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam, void*reserved /* = nullptr */) 182 | { 183 | return DefWindowProc(hWnd, message, wParam, lParam); 184 | } 185 | 186 | LRESULT EventDispatcher::WindowEventProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){ 187 | EventDispatcher*self = (EventDispatcher*)GetWindowLongPtr(hWnd,GWLP_USERDATA); 188 | if (self==nullptr){ 189 | return DefWindowProc(hWnd, message, wParam, lParam); 190 | } 191 | switch (message){ 192 | case WM_MOUSEMOVE:{ 193 | POINT pos; 194 | GetCursorPos(&pos); 195 | RECT rect; 196 | GetWindowRect(hWnd, &rect); 197 | self->OnMouseMove(wParam, MAKELPARAM(pos.x - rect.left, pos.y - rect.top)); 198 | } 199 | return 0; 200 | case WM_MOUSELEAVE: 201 | self->OnMouseLeave(wParam, lParam); 202 | return 0; 203 | case WM_LBUTTONDOWN:{ 204 | POINT pos; 205 | GetCursorPos(&pos); 206 | RECT rect; 207 | GetWindowRect(hWnd, &rect); 208 | self->OnLButtonDown(wParam, MAKELPARAM(pos.x - rect.left, pos.y - rect.top)); 209 | } 210 | return 0; 211 | case WM_LBUTTONUP:{ 212 | POINT pos; 213 | GetCursorPos(&pos); 214 | RECT rect; 215 | GetWindowRect(hWnd, &rect); 216 | self->OnLButtonUp(wParam, MAKELPARAM(pos.x - rect.left, pos.y - rect.top)); 217 | } 218 | return 0; 219 | case WM_LBUTTONDBLCLK: 220 | self->OnLButtonDoubleClick(wParam, lParam); 221 | return 0; 222 | case WM_RBUTTONDOWN: 223 | self->OnRButtonDown(wParam, lParam); 224 | return 0; 225 | case WM_RBUTTONUP: 226 | self->OnRButtonUp(wParam, lParam); 227 | return 0; 228 | case WM_MBUTTONDOWN: 229 | self->OnMiddleButtonDown(wParam, lParam); 230 | return 0; 231 | case WM_MBUTTONUP: 232 | self->OnMiddleButtonUp(wParam, lParam); 233 | return 0; 234 | case WM_MOUSEWHEEL: 235 | self->OnMouseWheel(wParam, lParam); 236 | return 0; 237 | case WM_KEYDOWN: 238 | //debug("WM_KEYDOWN"); 239 | self->OnKeyDown(wParam, lParam); 240 | return 0; 241 | case WM_KEYUP: 242 | //debug("WM_KEYUP"); 243 | self->OnKeyUp(wParam, lParam); 244 | return 0; 245 | case WM_CHAR: 246 | //debug("WM_CHAR"); 247 | self->OnChar(wParam, lParam); 248 | return 0; 249 | /*case WM_IME_COMPOSITION: 250 | debug("WM_IME_COMPOSITION"); 251 | break; 252 | case WM_IME_COMPOSITIONFULL: 253 | debug("WM_IME_COMPOSITIONFULL"); 254 | break; 255 | case WM_IME_CONTROL: 256 | debug("WM_IME_CONTROL"); 257 | break; 258 | case WM_IME_KEYDOWN: 259 | debug("WM_IME_KEYDOWN"); 260 | break; 261 | case WM_IME_KEYUP: 262 | debug("WM_IME_KEYUP"); 263 | break; 264 | case WM_IME_NOTIFY: 265 | debug("WM_IME_NOTIFY"); 266 | break; 267 | case WM_IME_REQUEST: 268 | debug("WM_IME_REQUEST"); 269 | return 0; 270 | case WM_IME_SELECT: 271 | debug("WM_IME_SELECT"); 272 | break; 273 | case WM_IME_SETCONTEXT: 274 | debug("WM_IME_SETCONTEXT"); 275 | break;*/ 276 | case WM_IME_STARTCOMPOSITION: 277 | //debug("WM_IME_STARTCOMPOSITION"); 278 | self->mbIsIMEInput = true; 279 | break; 280 | case WM_IME_ENDCOMPOSITION: 281 | //debug("WM_IME_ENDCOMPOSITION"); 282 | self->mbIsIMEInput = false; 283 | break; 284 | case WM_IME_CHAR: 285 | //debug("WM_IME_CHAR"); 286 | self->OnIMEChar(wParam, lParam); 287 | return 0; 288 | case WM_COMMAND: 289 | self->OnCommand(wParam, lParam); 290 | return 0; 291 | case WM_DROPFILES: 292 | self->OnDropFiles(wParam, lParam); 293 | return 0; 294 | case WM_CLOSE: 295 | self->OnCloseWindow(wParam, lParam); 296 | return 0; 297 | case WM_SETFOCUS: 298 | self->OnFocus(wParam, lParam); 299 | return 0; 300 | case WM_ACTIVATE: 301 | return 0; 302 | case WM_ACTIVATEAPP: 303 | return 0; 304 | case WM_SIZE: 305 | self->OnSize(wParam, lParam); 306 | return 0; 307 | case WM_SIZING: 308 | return self->OnSizing(wParam, lParam); 309 | case WM_MOVE: 310 | self->OnMove(wParam, lParam); 311 | return 0; 312 | case WM_MOVING: 313 | self->OnMoving(wParam, lParam); 314 | return TRUE; 315 | case WM_GETMINMAXINFO: 316 | self->OnGetMinMaxInfo(wParam, lParam); 317 | return 0; 318 | case WM_TIMER: 319 | self->OnTimer(wParam, lParam); 320 | return 0; 321 | case WM_ERASEBKGND: 322 | self->OnEraseBKG(); 323 | return 1; 324 | case WM_PAINT:{ 325 | RECT invalid_rect; 326 | if (GetUpdateRect(hWnd, &invalid_rect, true)) { 327 | PAINTSTRUCT ps; 328 | HDC hdc = BeginPaint(hWnd, &ps); 329 | self->OnPaint(Gdiplus::Rect(invalid_rect.left,invalid_rect.top,invalid_rect.right-invalid_rect.left,invalid_rect.bottom-invalid_rect.top)); 330 | EndPaint(hWnd, &ps); 331 | self->OnPostPaint(); 332 | } 333 | } 334 | return 0; 335 | case WM_NCPAINT: 336 | return self->OnNCPAINT(hWnd, message, wParam, lParam); 337 | case WM_NCACTIVATE: 338 | return self->OnNCACTIVATE(hWnd, message, wParam, lParam); 339 | case WM_NCCALCSIZE: 340 | return self->OnNCCALCSIZE(hWnd, message, wParam, lParam); 341 | case WM_NCHITTEST: 342 | return self->OnNCHITTEST(hWnd, message, wParam, lParam); 343 | case WM_NCLBUTTONUP: 344 | return self->OnNCLBUTTONUP(hWnd, message, wParam, lParam); 345 | case WM_NCLBUTTONDOWN: 346 | return self->OnNCLBUTTONDOWN(hWnd, message, wParam, lParam); 347 | case WM_NCLBUTTONDBLCLK: 348 | return self->OnNCLBUTTONDBLCLK(hWnd, message, wParam, lParam); 349 | case WM_NCMOUSEMOVE: 350 | return self->OnNCMOUSEMOVE(hWnd, message, wParam, lParam); 351 | case WM_NCRBUTTONUP: 352 | return self->OnNCRBUTTONUP(hWnd, message, wParam, lParam); 353 | case WM_NCRBUTTONDOWN: 354 | return self->OnNCRBUTTONDOWN(hWnd, message, wParam, lParam); 355 | } 356 | return DefWindowProc(hWnd, message, wParam, lParam); 357 | } 358 | } -------------------------------------------------------------------------------- /Platform/Windows/Common/Base/EventDispatcher.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Runtime/BattleFirePrefix.h" 3 | #include "Runtime/Utils/LinkedList.h" 4 | namespace Editor 5 | { 6 | class EventDispatcher : public Alice::LinkedList 7 | { 8 | protected: 9 | bool mbMouseLeaved; 10 | bool mbIsIMEInput; 11 | HWND mhWnd; 12 | protected: 13 | virtual void OnLButtonUp(WPARAM wParam, LPARAM lParam, void*reserved = nullptr); 14 | virtual void OnLButtonDown(WPARAM wParam, LPARAM lParam, void*reserved = nullptr); 15 | virtual void OnMiddleButtonDown(WPARAM wParam, LPARAM lParam, void*reserved = nullptr); 16 | virtual void OnMiddleButtonUp(WPARAM wParam, LPARAM lParam, void*reserved = nullptr); 17 | virtual void OnRButtonUp(WPARAM wParam, LPARAM lParam, void*reserved = nullptr); 18 | virtual void OnRButtonDown(WPARAM wParam, LPARAM lParam, void*reserved = nullptr); 19 | virtual void OnMouseMove(WPARAM wParam, LPARAM lParam, void*reserved = nullptr); 20 | virtual void OnMouseLeave(WPARAM wParam, LPARAM lParam, void*reserved = nullptr); 21 | virtual void OnLButtonDoubleClick(WPARAM wParam, LPARAM lParam, void*reserved = nullptr); 22 | virtual void OnKeyDown(WPARAM wParam, LPARAM lParam, void*reserved = nullptr); 23 | virtual void OnKeyUp(WPARAM wParam, LPARAM lParam, void*reserved = nullptr); 24 | virtual void OnChar(WPARAM wParam, LPARAM lParam, void*reserved = nullptr); 25 | virtual void OnIMEChar(WPARAM wParam, LPARAM lParam, void*reserved = nullptr); 26 | virtual void OnMouseWheel(WPARAM wParam, LPARAM lParam, void*reserved = nullptr); 27 | 28 | virtual void OnCloseWindow(WPARAM wParam, LPARAM lParam, void*reserved = nullptr); 29 | virtual void OnFocus(WPARAM wParam, LPARAM lParam, void*reserved = nullptr); 30 | virtual void OnSize(WPARAM wParam, LPARAM lParam, void*reserved = nullptr); 31 | virtual LRESULT OnSizing(WPARAM wParam, LPARAM lParam, void*reserved = nullptr); 32 | virtual void OnMove(WPARAM wParam, LPARAM lParam, void*reserved = nullptr); 33 | virtual void OnMoving(WPARAM wParam, LPARAM lParam, void*reserved = nullptr); 34 | virtual void OnGetMinMaxInfo(WPARAM wParam, LPARAM lParam, void*reserved = nullptr); 35 | virtual void OnPaint(const Gdiplus::Rect& rect_need_update); 36 | virtual void OnPaintNoUpdateRect() {} 37 | virtual void OnPostPaint() {} 38 | virtual void OnEraseBKG() {} 39 | virtual void OnClearBKG(Gdiplus::Graphics&painter) {}; 40 | virtual void OnTimer(WPARAM wParam, LPARAM lParam, void*reserved = nullptr); 41 | virtual void OnCommand(WPARAM wParam, LPARAM lParam, void*reserved = nullptr); 42 | virtual void OnDropFiles(WPARAM wParam, LPARAM lParam, void*reserved = nullptr); 43 | virtual LRESULT OnNCPAINT(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam, void*reserved = nullptr); 44 | virtual LRESULT OnNCACTIVATE(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam, void*reserved = nullptr); 45 | virtual LRESULT OnNCCALCSIZE(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam, void*reserved = nullptr); 46 | virtual LRESULT OnNCHITTEST(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam, void*reserved = nullptr); 47 | virtual LRESULT OnNCLBUTTONUP(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam, void*reserved = nullptr); 48 | virtual LRESULT OnNCLBUTTONDOWN(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam, void*reserved = nullptr); 49 | virtual LRESULT OnNCLBUTTONDBLCLK(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam, void*reserved = nullptr); 50 | virtual LRESULT OnNCMOUSEMOVE(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam, void*reserved = nullptr); 51 | virtual LRESULT OnNCRBUTTONUP(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam, void*reserved = nullptr); 52 | virtual LRESULT OnNCRBUTTONDOWN(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam, void*reserved = nullptr); 53 | public: 54 | EventDispatcher(); 55 | static LRESULT CALLBACK WindowEventProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); 56 | }; 57 | } -------------------------------------------------------------------------------- /Platform/Windows/Common/Base/Window.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "EventDispatcher.h" 3 | namespace Editor { 4 | enum ChildWindowLocation { 5 | kChildWindowLocationUnkown, 6 | kChildWindowLocationLeftEdge, 7 | kChildWindowLocationRightEdge, 8 | kChildWindowLocationTopEdge, 9 | kChildWindowLocationBottomEdge 10 | }; 11 | enum SiblingWindowLocation { 12 | kSiblingWindowLocationAtUnkown, 13 | kSiblingWindowLocationAtLeft, 14 | kSiblingWindowLocationAtRight, 15 | kSiblingWindowLocationAtTop, 16 | kSiblingWindowLocationAtBottom 17 | }; 18 | class WindowHolder; 19 | class WindowContainer; 20 | class BaseWindow:public EventDispatcher{ 21 | protected: 22 | HDC mHDC; 23 | BaseWindow*mParent; 24 | Gdiplus::Color mBKGColor; 25 | Gdiplus::Rect mRect, mMinRect, mMaxRect, mPredefinedRect; 26 | int mTopNCSize, mBottomNCSize, mLeftNCSize, mRightNCSize; 27 | bool mbEnableCornerResizing; 28 | int mSizingBorderSize; 29 | char mName[64]; 30 | protected: 31 | virtual void DrawContent(Gdiplus::Graphics&painter); 32 | virtual void OnEraseBKG(); 33 | virtual void OnPaint(const Gdiplus::Rect & rect_need_update); 34 | virtual void OnPostPaint(); 35 | virtual void RenderChildren(Gdiplus::Graphics&painter,const Gdiplus::Rect & rect_need_update){} 36 | virtual void OnSize(WPARAM wParam, LPARAM lParam, void*reserved = nullptr); 37 | virtual void OnMoving(WPARAM wParam, LPARAM lParam, void*reserved = nullptr); 38 | virtual void OnGetMinMaxInfo(WPARAM wParam, LPARAM lParam, void*reserved = nullptr); 39 | virtual LRESULT OnNCACTIVATE(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam, void*reserved = nullptr); 40 | virtual LRESULT OnNCHITTEST(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam, void*reserved = nullptr); 41 | virtual LRESULT OnNCCALCSIZE(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam, void*reserved = nullptr); 42 | virtual LRESULT OnNCPAINT(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam, void*reserved = nullptr); 43 | public: 44 | WindowHolder *mLeftSiblingWindows, *mRightSiblingWindows, *mTopSiblingWindows, *mBottomSiblingWindows; 45 | WindowContainer*mParentContainer; 46 | std::unordered_set mChildren; 47 | BaseWindow(); 48 | virtual ~BaseWindow(); 49 | virtual void OnWindowMove(BaseWindow*movedWindow); 50 | virtual void OnEditControlLoseFocus(BaseWindow*editControl); 51 | 52 | void SetMinRect(int x, int y, int width, int height); 53 | void SetMaxRect(int x, int y, int width, int height); 54 | void SetBkgColor(Gdiplus::Color &color); 55 | void SetParent(BaseWindow*parent); 56 | void SetRect(int x, int y, int width, int height); 57 | void SetRect(Gdiplus::Rect &rect); 58 | void SetSize(int width, int height, HWND param); 59 | void SetNCSize(int left, int right, int bottom, int top); 60 | void EnableCornerResizing(bool enable); 61 | void SetSizingBorderSize(int size); 62 | void SetWindowName(const char*name); 63 | void GetRelativeWindowRect(Gdiplus::Rect &rect); 64 | int GetUILocationL(int size, int distance); 65 | int GetUILocationR(int size, int distance); 66 | int GetUILocationT(int size, int distance); 67 | int GetUILocationB(int size, int distance); 68 | public://rect 69 | Gdiplus::Rect GetRect(); 70 | int GetWidth(); 71 | int GetHeight(); 72 | Gdiplus::Rect &GetMinRect(); 73 | int GetMinWidth(); 74 | int GetMinHeight(); 75 | int GenerateMinWidth(); 76 | int GenerateMinHeight(); 77 | int GenerateMaxWidth(); 78 | int GenerateMaxHeight(); 79 | 80 | void ScheduleUpdate(); 81 | void CancelUpdate(); 82 | void Update(); 83 | virtual void MarkDirty(); 84 | virtual void MoveWindow(int x, int y, int width, int height); 85 | virtual void OnParentResized(int width, int height) {} 86 | virtual void ExtentWindowFromLeft(int & deltaX, const Gdiplus::Rect * left_rect = nullptr, const Gdiplus::Rect * container_rect = nullptr); 87 | virtual void ReduceWindowFromLeft(int & deltaX, const Gdiplus::Rect * left_rect = nullptr, const Gdiplus::Rect * container_rect = nullptr); 88 | virtual void ExtentWindowFromRight(int & deltaX, const Gdiplus::Rect * right_rect = nullptr); 89 | virtual void ReduceWindowFromRight(int & deltaX, int shiftX, const Gdiplus::Rect * container_rect = nullptr); 90 | virtual void ExtentWindowFromTop(int & deltaY, const Gdiplus::Rect * top_rect = nullptr, const Gdiplus::Rect * container_rect = nullptr); 91 | virtual void ReduceWindowFromTop(int & deltaY, const Gdiplus::Rect * top_rect = nullptr, const Gdiplus::Rect * container_rect = nullptr); 92 | virtual void ExtentWindowFromBottom(int & deltaY, const Gdiplus::Rect * bottom_rect = nullptr); 93 | virtual void ReduceWindowFromBottom(int & deltaY, int shiftY, const Gdiplus::Rect * container_rect = nullptr); 94 | virtual void OnParentPaint(Gdiplus::Graphics&painter) {} 95 | int GetX(); 96 | int GetY(); 97 | BaseWindow*GetParent(); 98 | HWND GetHwnd(); 99 | const char*GetWindowName(); 100 | HDC GetDC(); 101 | bool IsVisiable(); 102 | void Show(); 103 | virtual void OnShow(); 104 | void Hide(); 105 | virtual void OnHide(); 106 | template 107 | static T* WindowInstance(HWND hWnd) { 108 | return (T*)GetWindowLongPtr(hWnd, GWLP_USERDATA); 109 | } 110 | public: 111 | static ATOM RegisterWindowClass(UINT style, LPCTSTR pWndClassName, WNDPROC wndProc); 112 | static std::unordered_set mScheduledWindows; 113 | static void SetRootWindow(BaseWindow*window); 114 | }; 115 | class WindowHolder : public Alice::LinkedList { 116 | public: 117 | BaseWindow*mWindow; 118 | WindowHolder(BaseWindow*window = nullptr) { 119 | mWindow = window; 120 | } 121 | }; 122 | } -------------------------------------------------------------------------------- /Platform/Windows/Common/Base/WindowContainer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Window.h" 3 | namespace Editor { 4 | class WindowContainerHolder; 5 | class WindowContainer { 6 | protected: 7 | WindowHolder * mLeftMostChildren, *mRightMostChildren, *mTopMostChildren, *mBottomMostChildren; 8 | public: 9 | char mName[64]; 10 | Gdiplus::Rect mRect, mMinRect, mMaxRect, mPredefinedRect; 11 | WindowContainer * mParentContainer; 12 | WindowContainerHolder *mLeftMostContainer, *mRightMostContainer, *mTopMostContainer, *mBottomMostContainer; 13 | WindowContainerHolder *mLeftSiblingContainers, *mRightSiblingContainers, *mTopSiblingContainers, *mBottomSiblingContainers; 14 | WindowContainer(const char * name); 15 | virtual ~WindowContainer(); 16 | void SetName(const char * name); 17 | void SetMinRect(int x, int y, int width, int height); 18 | void SetMaxRect(int x, int y, int width, int height); 19 | Gdiplus::Rect GetMinRect() const { return mMinRect; } 20 | 21 | void AddLeftEdgeChildContainer(WindowContainer*container); 22 | void AddRightEdgeChildContainer(WindowContainer*container); 23 | void AddBottomEdgeChildContainer(WindowContainer*container); 24 | void AddTopEdgeChildContainer(WindowContainer*container); 25 | 26 | void AddSiblingContainerAtLeft(WindowContainer*container); 27 | void AddSiblingContainerAtRight(WindowContainer*container); 28 | void AddSiblingContainerAtTop(WindowContainer*container); 29 | void AddSiblingContainerAtBottom(WindowContainer*container); 30 | 31 | void AddChildWindowAt(ChildWindowLocation location, BaseWindow*window); 32 | void RemoveChildWindowAt(ChildWindowLocation location, BaseWindow*window); 33 | void Complete(); 34 | int GenerateMinWidthViaChildWindows(); 35 | int GenerateMinHeightViaChildWindows(); 36 | int GenerateMaxWidthViaChildWindows(); 37 | int GenerateMaxHeightViaChildWindows(); 38 | 39 | int GenerateMinWidthViaChildContainers(); 40 | int GenerateMinHeightViaChilContainers(); 41 | int GenerateMaxWidthViaChildContainers(); 42 | int GenerateMaxHeightViaChilContainers(); 43 | int GenerateMinWidth(); 44 | int GenerateMinHeight(); 45 | int GenerateMaxWidth(); 46 | int GenerateMaxHeight(); 47 | int GenerateWidth(); 48 | int GenerateHeight(); 49 | public: 50 | void ExtentContainerFromLeft(int &deltaX, const Gdiplus::Rect *left_rect = nullptr); 51 | void ExtentChildContainersFromLeft(int &deltaX, const Gdiplus::Rect *left_rect = nullptr); 52 | void ExtentChildWindowsFromLeft(int &deltaX, const Gdiplus::Rect *left_rect = nullptr); 53 | void ReduceContainerFromLeft(int &deltaX, const Gdiplus::Rect *left_rect = nullptr); 54 | void ReduceChildContainersFromLeft(int &deltaX, const Gdiplus::Rect *left_rect = nullptr); 55 | void ReduceChildWindowsFromLeft(int &deltaX, const Gdiplus::Rect *left_rect = nullptr); 56 | 57 | void ExtentContainerFromRight(int &deltaX, const Gdiplus::Rect *right_rect = nullptr); 58 | void ExtentChildContainersFromRight(int &deltaX, const Gdiplus::Rect *right_rect = nullptr); 59 | void ExtentChildWindowsFromRight(int &deltaX, const Gdiplus::Rect *right_rect = nullptr); 60 | void ReduceContainerFromRight(int &deltaX, const Gdiplus::Rect *right_rect = nullptr); 61 | void ReduceChildContainersFromRight(int &deltaX, const Gdiplus::Rect *right_rect = nullptr); 62 | void ReduceChildWindowsFromRight(int &deltaX,int shiftX, const Gdiplus::Rect *right_rect = nullptr); 63 | 64 | void ExtentContainerFromBottom(int &deltaY, const Gdiplus::Rect *bottom_rect = nullptr); 65 | void ExtentChildContainersFromBottom(int &deltaY, const Gdiplus::Rect *bottom_rect = nullptr); 66 | void ExtentChildWindowsFromBottom(int &deltaY, const Gdiplus::Rect *bottom_rect = nullptr); 67 | void ReduceContainerFromBottom(int &deltaY, const Gdiplus::Rect *bottom_rect = nullptr); 68 | void ReduceChildContainersFromBottom(int &deltaY, const Gdiplus::Rect *bottom_rect = nullptr); 69 | void ReduceChildWindowsFromBottom(int &deltaY, int shiftY, const Gdiplus::Rect *bottom_rect = nullptr); 70 | 71 | void ExtentContainerFromTop(int &deltaY, const Gdiplus::Rect *top_rect = nullptr); 72 | void ExtentChildContainersFromTop(int &deltaX, const Gdiplus::Rect *top_rect = nullptr); 73 | void ExtentChildWindowsFromTop(int &deltaX, const Gdiplus::Rect *top_rect = nullptr); 74 | void ReduceContainerFromTop(int &deltaY, const Gdiplus::Rect *top_rect = nullptr); 75 | void ReduceChildContainersFromTop(int &deltaY, const Gdiplus::Rect *top_rect = nullptr); 76 | void ReduceChildWindowsFromTop(int &deltaY, const Gdiplus::Rect *top_rect = nullptr); 77 | }; 78 | class WindowContainerHolder : public Alice::LinkedList{ 79 | public: 80 | WindowContainer*mContainer; 81 | WindowContainerHolder(WindowContainer*container) { 82 | mContainer = container; 83 | } 84 | }; 85 | } -------------------------------------------------------------------------------- /Platform/Windows/Common/Control/Button/ImageButton.cpp: -------------------------------------------------------------------------------- 1 | #include "ImageButton.h" 2 | #include "Runtime/Debugger/Logger.h" 3 | namespace Editor{ 4 | ImageButton::ImageButton(){ 5 | mOriginalPos.X = 0; 6 | mOriginalPos.Y = 0; 7 | } 8 | void ImageButton::SetImage(const char * path) { 9 | mImage.SetImagePath(path); 10 | } 11 | void ImageButton::SetImageData(StreamImageData*data) { 12 | mImage.SetImageData(data); 13 | } 14 | void ImageButton::SetRect(int x, int y, int width, int height) { 15 | mImage.SetRect(x, y, width, height); 16 | UINode::SetRect(x, y, width, height); 17 | } 18 | void ImageButton::Draw(Gdiplus::Graphics&painter) { 19 | mImage.Draw(painter); 20 | } 21 | void ImageButton::OnTouchBegin(int x, int y, int touch_id/* =0 */) { 22 | Gdiplus::Rect original_rect = mImage.GetRect(); 23 | mOriginalPos.X = original_rect.X; 24 | mOriginalPos.Y = original_rect.Y; 25 | mImage.SetRect(mOriginalPos.X, mOriginalPos.Y + 2, original_rect.Width, original_rect.Height); 26 | } 27 | void ImageButton::OnTouchEnd(int x, int y, int touch_id /* = 0 */) { 28 | Gdiplus::Rect original_rect = mImage.GetRect(); 29 | mImage.SetRect(mOriginalPos.X, mOriginalPos.Y, original_rect.Width, original_rect.Height); 30 | if (mRect.Contains(x, y)) { 31 | OnClicked(x, y); 32 | } 33 | } 34 | void ImageButton::OnTouchCanceled(int x, int y, int touch_id /* = 0 */) { 35 | Gdiplus::Rect original_rect = mImage.GetRect(); 36 | mImage.SetRect(mOriginalPos.X, mOriginalPos.Y, original_rect.Width, original_rect.Height); 37 | } 38 | void ImageButton::OnTouchMove(int x, int y, int touch_id /* = 0 */) { 39 | 40 | } 41 | void ImageButton::OnClicked(int x, int y, int touch_id /* = 0 */) { 42 | if (mOnClicked != nullptr) { 43 | mOnClicked(this); 44 | } 45 | } 46 | } -------------------------------------------------------------------------------- /Platform/Windows/Common/Control/Button/ImageButton.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Platform/Windows/Common/Control/Image/SimpleImage.h" 3 | #include 4 | namespace Editor{ 5 | class ImageButton :public UINode { 6 | protected: 7 | Gdiplus::Point mOriginalPos; 8 | SimpleImage mImage; 9 | public: 10 | ImageButton(); 11 | void SetImage(const char * path); 12 | void SetImageData(StreamImageData*data); 13 | void SetRect(int x, int y, int width, int height); 14 | virtual void Draw(Gdiplus::Graphics&painter); 15 | virtual void OnTouchBegin(int x, int y, int touch_id = 0); 16 | virtual void OnTouchEnd(int x, int y, int touch_id = 0); 17 | virtual void OnTouchMove(int x, int y, int touch_id = 0); 18 | virtual void OnTouchCanceled(int x, int y, int touch_id = 0); 19 | virtual void OnClicked(int x, int y, int touch_id = 0); 20 | }; 21 | } -------------------------------------------------------------------------------- /Platform/Windows/Common/Control/Button/TabButton.cpp: -------------------------------------------------------------------------------- 1 | #include "TabButton.h" 2 | #include "Runtime/Debugger/Logger.h" 3 | namespace Editor{ 4 | TabButton::TabButton(){ 5 | mOriginalPos.X = 0; 6 | mOriginalPos.Y = 0; 7 | } 8 | void TabButton::SetImage(const char * path) { 9 | mImage.SetImagePath(path); 10 | } 11 | void TabButton::SetImageData(StreamImageData*data) { 12 | mImage.SetImageData(data); 13 | } 14 | void TabButton::SetIconImageData(StreamImageData*data) { 15 | mIcon.SetImageData(data); 16 | } 17 | void TabButton::SetRect(int x, int y, int width, int height) { 18 | mImage.SetRect(x, y, width, height); 19 | mIcon.SetRect(x + 2, y + 2, 16, 16); 20 | mTitle.SetRect(x + 20, y+2, width - 20, height); 21 | UINode::SetRect(x, y, width, height); 22 | } 23 | void TabButton::Init(StreamImageData*bkg_image, StreamImageData*icon_image, const char *text) { 24 | SetImageData(bkg_image); 25 | SetIconImageData(icon_image); 26 | mTitle.SetAligning(Editor::AligningModeLeft); 27 | mTitle.SetText(text); 28 | } 29 | void TabButton::Draw(Gdiplus::Graphics&painter) { 30 | mImage.Draw(painter); 31 | mIcon.Draw(painter); 32 | mTitle.Draw(painter); 33 | } 34 | void TabButton::OnTouchBegin(int x, int y, int touch_id/* =0 */) { 35 | Gdiplus::Rect original_rect = mImage.GetRect(); 36 | mOriginalPos.X = original_rect.X; 37 | mOriginalPos.Y = original_rect.Y; 38 | mImage.SetRect(mOriginalPos.X, mOriginalPos.Y + 2, original_rect.Width, original_rect.Height); 39 | } 40 | void TabButton::OnTouchEnd(int x, int y, int touch_id /* = 0 */) { 41 | Gdiplus::Rect original_rect = mImage.GetRect(); 42 | mImage.SetRect(mOriginalPos.X, mOriginalPos.Y, original_rect.Width, original_rect.Height); 43 | if (mRect.Contains(x, y)) { 44 | OnClicked(x, y); 45 | } 46 | } 47 | void TabButton::OnTouchCanceled(int x, int y, int touch_id /* = 0 */) { 48 | Gdiplus::Rect original_rect = mImage.GetRect(); 49 | mImage.SetRect(mOriginalPos.X, mOriginalPos.Y, original_rect.Width, original_rect.Height); 50 | } 51 | void TabButton::OnTouchMove(int x, int y, int touch_id /* = 0 */) { 52 | 53 | } 54 | void TabButton::OnClicked(int x, int y, int touch_id /* = 0 */) { 55 | if (mOnClicked != nullptr) { 56 | mOnClicked(this); 57 | } 58 | } 59 | } -------------------------------------------------------------------------------- /Platform/Windows/Common/Control/Button/TabButton.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Platform/Windows/Common/Control/Image/SimpleImage.h" 3 | #include "../Text/StaticText.h" 4 | #include 5 | namespace Editor{ 6 | class TabButton :public UINode { 7 | protected: 8 | Gdiplus::Point mOriginalPos; 9 | SimpleImage mImage,mIcon; 10 | public: 11 | StaticText mTitle; 12 | TabButton(); 13 | void SetImage(const char * path); 14 | void SetImageData(StreamImageData*data); 15 | void SetIconImageData(StreamImageData*data); 16 | void SetRect(int x, int y, int width, int height); 17 | void Init(StreamImageData*bkg_image, StreamImageData*icon_image,const char *text); 18 | virtual void Draw(Gdiplus::Graphics&painter); 19 | virtual void OnTouchBegin(int x, int y, int touch_id = 0); 20 | virtual void OnTouchEnd(int x, int y, int touch_id = 0); 21 | virtual void OnTouchMove(int x, int y, int touch_id = 0); 22 | virtual void OnTouchCanceled(int x, int y, int touch_id = 0); 23 | virtual void OnClicked(int x, int y, int touch_id = 0); 24 | }; 25 | } -------------------------------------------------------------------------------- /Platform/Windows/Common/Control/Button/TwoStateButton.cpp: -------------------------------------------------------------------------------- 1 | #include "TwoStateButton.h" 2 | #include "Runtime/Debugger/Logger.h" 3 | namespace Editor{ 4 | TwoStateButton::TwoStateButton(){ 5 | mOriginalPos.X = 0; 6 | mOriginalPos.Y = 0; 7 | mState = kTwoStateButtonStateOne; 8 | } 9 | void TwoStateButton::SetImage(const char * path1, const char * path2) { 10 | mImage[0].SetImagePath(path1); 11 | mImage[1].SetImagePath(path2); 12 | } 13 | void TwoStateButton::SetImageData(StreamImageData*data1, StreamImageData*data2) { 14 | mImage[0].SetImageData(data1); 15 | mImage[1].SetImageData(data2); 16 | } 17 | void TwoStateButton::SetRect(int x, int y, int width, int height) { 18 | mImage[0].SetRect(x, y, width, height); 19 | mImage[1].SetRect(x, y, width, height); 20 | UINode::SetRect(x, y, mImage[0].GetRect().Width, mImage[0].GetRect().Height); 21 | } 22 | void TwoStateButton::Draw(Gdiplus::Graphics&painter) { 23 | mImage[mState].Draw(painter); 24 | } 25 | void TwoStateButton::OnTouchBegin(int x, int y, int touch_id/* =0 */) { 26 | Gdiplus::Rect original_rect=mImage[mState].GetRect(); 27 | mOriginalPos.X = original_rect.X; 28 | mOriginalPos.Y = original_rect.Y; 29 | mImage[mState].SetRect(mOriginalPos.X, mOriginalPos.Y + 2, original_rect.Width, original_rect.Height); 30 | } 31 | void TwoStateButton::OnTouchEnd(int x, int y, int touch_id /* = 0 */) { 32 | Gdiplus::Rect original_rect = mImage[mState].GetRect(); 33 | mImage[mState].SetRect(mOriginalPos.X, mOriginalPos.Y, original_rect.Width, original_rect.Height); 34 | if (mRect.Contains(x, y)) { 35 | mState = (TwoStateButtonState)((mState + 1) % 2); 36 | OnClicked(x, y); 37 | } 38 | } 39 | void TwoStateButton::OnTouchCanceled(int x, int y, int touch_id /* = 0 */) { 40 | Gdiplus::Rect original_rect = mImage[mState].GetRect(); 41 | mImage[mState].SetRect(mOriginalPos.X, mOriginalPos.Y, original_rect.Width, original_rect.Height); 42 | } 43 | void TwoStateButton::OnTouchMove(int x, int y, int touch_id /* = 0 */) { 44 | 45 | } 46 | void TwoStateButton::OnClicked(int x, int y, int touch_id /* = 0 */) { 47 | if (mOnClicked != nullptr) { 48 | mOnClicked(this); 49 | } 50 | } 51 | void TwoStateButton::OnContainerSizeChanged(int width, int height) { 52 | UINode::OnContainerSizeChanged(width, height); 53 | mImage[0].SetRect(mRect.X, mRect.Y, mRect.Width, mRect.Height); 54 | mImage[1].SetRect(mRect.X, mRect.Y, mRect.Width, mRect.Height); 55 | } 56 | } -------------------------------------------------------------------------------- /Platform/Windows/Common/Control/Button/TwoStateButton.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Platform/Windows/Common/Control/Image/SimpleImage.h" 3 | #include 4 | namespace Editor{ 5 | class TwoStateButton :public UINode { 6 | public: 7 | enum TwoStateButtonState { 8 | kTwoStateButtonStateOne, 9 | kTwoStateButtonStateTwo, 10 | kTwoStateButtonStateCount 11 | }; 12 | protected: 13 | Gdiplus::Point mOriginalPos; 14 | SimpleImage mImage[2]; 15 | TwoStateButtonState mState; 16 | public: 17 | TwoStateButton(); 18 | void SetImage(const char * path1,const char *path2); 19 | void SetImageData(StreamImageData*data1, StreamImageData*data2); 20 | void SetRect(int x, int y, int width, int height); 21 | TwoStateButtonState GetState() const { return mState; } 22 | virtual void Draw(Gdiplus::Graphics&painter); 23 | virtual void OnTouchBegin(int x, int y, int touch_id = 0); 24 | virtual void OnTouchEnd(int x, int y, int touch_id = 0); 25 | virtual void OnTouchMove(int x, int y, int touch_id = 0); 26 | virtual void OnTouchCanceled(int x, int y, int touch_id = 0); 27 | virtual void OnClicked(int x, int y, int touch_id = 0); 28 | virtual void OnContainerSizeChanged(int width, int height); 29 | }; 30 | } -------------------------------------------------------------------------------- /Platform/Windows/Common/Control/Image/SelectableImage.cpp: -------------------------------------------------------------------------------- 1 | #include "SelectableImage.h" 2 | namespace Editor{ 3 | SelectableImage::SelectableImage(SelectedMaskType t) :mbSelected(false), mSelectedMaskType(t){ 4 | mSelectedBKGColor = Gdiplus::Color(0, 100, 150); 5 | mIlluminationNormal = 1.0f; 6 | mIlluminationSelected = 1.2f; 7 | } 8 | bool SelectableImage::IsSelected(){ 9 | return mbSelected; 10 | } 11 | void SelectableImage::SetSelectedMaskType(SelectedMaskType t){ 12 | mSelectedMaskType = t; 13 | } 14 | void SelectableImage::SetSelectedBKGColor(Gdiplus::Color&color){ 15 | mSelectedBKGColor = color; 16 | } 17 | void SelectableImage::Draw(Gdiplus::Graphics&painter){ 18 | if (mbSelected){ 19 | if (mSelectedMaskType == kSelectedMaskTypeChangeBackgroundColor) { 20 | Gdiplus::SolidBrush brush(mSelectedBKGColor); 21 | painter.FillRectangle(&brush, mRect); 22 | }else if (mSelectedMaskType==kSelectedMaskTypeChangeImageIllumination){ 23 | mIllumination = mIlluminationSelected; 24 | } 25 | SimpleImage::Draw(painter); 26 | } 27 | else { 28 | if (mSelectedMaskType == kSelectedMaskTypeChangeImageIllumination) { 29 | mIllumination = mIlluminationNormal; 30 | SimpleImage::Draw(painter); 31 | } 32 | } 33 | } 34 | void SelectableImage::OnTouchBegin(int x, int y, int touch_id/* =0 */) { 35 | 36 | } 37 | void SelectableImage::OnTouchEnd(int x, int y, int touch_id /* = 0 */) { 38 | 39 | } 40 | void SelectableImage::OnTouchCanceled(int x, int y, int touch_id /* = 0 */) { 41 | 42 | } 43 | void SelectableImage::OnTouchMove(int x, int y, int touch_id /* = 0 */) { 44 | 45 | } 46 | void SelectableImage::OnClicked(int x, int y, int touch_id /* = 0 */) { 47 | 48 | } 49 | } -------------------------------------------------------------------------------- /Platform/Windows/Common/Control/Image/SelectableImage.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "SimpleImage.h" 3 | #include 4 | namespace Editor{ 5 | enum SelectedMaskType{ 6 | kSelectedMaskTypeChangeImageIllumination, 7 | kSelectedMaskTypeChangeBackgroundColor 8 | }; 9 | class SelectableImage :public SimpleImage{ 10 | protected: 11 | Gdiplus::Color mSelectedBKGColor; 12 | float mIlluminationSelected, mIlluminationNormal; 13 | SelectedMaskType mSelectedMaskType; 14 | bool mbSelected; 15 | public: 16 | SelectableImage(SelectedMaskType t= kSelectedMaskTypeChangeImageIllumination); 17 | bool IsSelected(); 18 | void SetSelectedMaskType(SelectedMaskType t); 19 | void SetSelectedBKGColor(Gdiplus::Color&color); 20 | public: 21 | virtual void Draw(Gdiplus::Graphics&painter); 22 | virtual void OnTouchBegin(int x, int y, int touch_id = 0); 23 | virtual void OnTouchEnd(int x, int y, int touch_id = 0); 24 | virtual void OnTouchMove(int x, int y, int touch_id = 0); 25 | virtual void OnTouchCanceled(int x, int y, int touch_id = 0); 26 | virtual void OnClicked(int x, int y, int touch_id = 0); 27 | }; 28 | } -------------------------------------------------------------------------------- /Platform/Windows/Common/Control/Image/SimpleImage.cpp: -------------------------------------------------------------------------------- 1 | #include "SimpleImage.h" 2 | #include "Runtime/IO/AliceData.h" 3 | #include "Runtime/IO/FileSystem.h" 4 | namespace Editor{ 5 | SimpleImage::SimpleImage():mRenderMode(ImageRenderModeFill),mStreamImageData(nullptr){ 6 | mIllumination = 1.0f; 7 | } 8 | SimpleImage::~SimpleImage(){ 9 | if (mStreamImageData !=nullptr){ 10 | delete mStreamImageData; 11 | } 12 | } 13 | Gdiplus::Image* SimpleImage::SetImageData(StreamImageData*data){ 14 | mStreamImageData = data; 15 | return mStreamImageData->mImage; 16 | } 17 | Gdiplus::Image*SimpleImage::GetImageData(){ 18 | return mStreamImageData->mImage; 19 | } 20 | Gdiplus::Image* SimpleImage::SetImagePath(const char*imagePath) { 21 | if (mStreamImageData != nullptr) { 22 | delete mStreamImageData; 23 | mStreamImageData = nullptr; 24 | } 25 | Alice::Data data; 26 | if (Alice::FileSystem::LoadDataFromPath(imagePath, data)) { 27 | mStreamImageData = WinResources::Singleton()->InitStreamImageDataFromRawBuffer(data.mData, data.mDataLen); 28 | } 29 | return mStreamImageData==nullptr?nullptr:mStreamImageData->mImage; 30 | } 31 | void SimpleImage::SetRenderMode(ImageRenderMode mode){ 32 | mRenderMode = mode; 33 | } 34 | void SimpleImage::SetRect(int x, int y, int width, int height){ 35 | if (width == 0||height==0){ 36 | if (mStreamImageData!=nullptr){ 37 | width = mStreamImageData->mImage->GetWidth(); 38 | height = mStreamImageData->mImage->GetHeight(); 39 | } 40 | } 41 | UINode::SetRect(x, y, width, height); 42 | } 43 | void SimpleImage::Draw(Gdiplus::Graphics&painter){ 44 | if (mStreamImageData != nullptr){ 45 | switch (mRenderMode){ 46 | case Editor::ImageRenderModeFill: 47 | DrawImage(painter, mRect.X, mRect.Y, mRect.Width, mRect.Height, 0, 0, mStreamImageData->mImage->GetWidth(), mStreamImageData->mImage->GetHeight()); 48 | break; 49 | case Editor::ImageRenderModeAutoAdjust: 50 | DrawRenderModeAutoAdjust(painter); 51 | break; 52 | case Editor::ImageRenderModeCenterNoScale: 53 | DrawRenderModeCenterNoScale(painter); 54 | break; 55 | default: 56 | break; 57 | } 58 | } 59 | UINode::Draw(painter); 60 | } 61 | void SimpleImage::DrawRenderModeAutoAdjust(Gdiplus::Graphics&painter) { 62 | Gdiplus::ImageAttributes current_image_attributes; 63 | InitIllumination(current_image_attributes); 64 | UINT width = mStreamImageData->mImage->GetWidth(); 65 | UINT height = mStreamImageData->mImage->GetHeight(); 66 | if (width != height){ 67 | if (width > height){ 68 | INT rh = (INT)(mRect.Height * height / width); 69 | DrawImage(painter, mRect.X, mRect.Y + (mRect.Height - rh) / 2, mRect.Width, rh, 0, 0, width, height); 70 | }else { 71 | INT rw = (INT)(mRect.Width * width / height); 72 | DrawImage(painter, mRect.X + (mRect.Width - rw) / 2, mRect.Y, rw, mRect.Height, 0, 0, width, height); 73 | } 74 | } 75 | else { 76 | DrawImage(painter, mRect.X, mRect.Y, mRect.Width, mRect.Height, 0, 0, width, height); 77 | } 78 | } 79 | void SimpleImage::DrawRenderModeCenterNoScale(Gdiplus::Graphics&painter) { 80 | Gdiplus::ImageAttributes current_image_attributes; 81 | InitIllumination(current_image_attributes); 82 | int width = mStreamImageData->mImage->GetWidth(); 83 | int height = mStreamImageData->mImage->GetHeight(); 84 | int xPos = mRect.X + mRect.Width / 2 - width / 2; 85 | int yPos = mRect.Y + mRect.Height / 2 - height / 2; 86 | DrawImage(painter, xPos, yPos, width, height, 0, 0, width, height); 87 | } 88 | void SimpleImage::InitIllumination(Gdiplus::ImageAttributes&attributes) { 89 | Gdiplus::ColorMatrix colorMatrix = { 90 | mIllumination,0.0f,0.0f,0.0f,0.0f, 91 | 0.0f,mIllumination,0.0f,0.0f,0.0f, 92 | 0.0f,0.0f,mIllumination,0.0f,0.0f, 93 | 0.0f,0.0f,0.0f,1.0f,0.0f, 94 | 0.0f,0.0f,0.0f,0.0f,1.0f 95 | }; 96 | attributes.SetColorMatrix(&colorMatrix, Gdiplus::ColorMatrixFlagsDefault, Gdiplus::ColorAdjustTypeBitmap); 97 | } 98 | void SimpleImage::DrawImage(Gdiplus::Graphics&painter, int dst_x, int dst_y, int dst_width, int dst_height, int src_x, int src_y, int src_width, int src_height) { 99 | Gdiplus::ImageAttributes current_image_attributes; 100 | InitIllumination(current_image_attributes); 101 | Gdiplus::Rect target_rect(dst_x, dst_y, dst_width, dst_height); 102 | painter.DrawImage(mStreamImageData->mImage, target_rect, src_x, src_y, src_width, src_height, Gdiplus::UnitPixel, ¤t_image_attributes); 103 | } 104 | } -------------------------------------------------------------------------------- /Platform/Windows/Common/Control/Image/SimpleImage.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Platform/Windows/Common/Control/UINode.h" 3 | #include "Platform/Windows/Common/WinResources.h" 4 | namespace Editor{ 5 | enum ImageRenderMode{ 6 | ImageRenderModeFill,//fill the full rect of the control 7 | ImageRenderModeAutoAdjust,//auto scale width & height 8 | ImageRenderModeCenterNoScale//no width & height 9 | }; 10 | class SimpleImage :public UINode { 11 | protected: 12 | ImageRenderMode mRenderMode; 13 | StreamImageData*mStreamImageData; 14 | float mIllumination; 15 | public: 16 | std::string mImagePath; 17 | SimpleImage(); 18 | ~SimpleImage(); 19 | void SetRenderMode(ImageRenderMode mode); 20 | Gdiplus::Image* SetImageData(StreamImageData*data); 21 | Gdiplus::Image* SetImagePath(const char*imagePath); 22 | Gdiplus::Image* GetImageData(); 23 | public: 24 | virtual void Draw(Gdiplus::Graphics&painter); 25 | virtual void SetRect(int x,int y,int width,int height); 26 | protected: 27 | void DrawRenderModeAutoAdjust(Gdiplus::Graphics&painter); 28 | void DrawRenderModeCenterNoScale(Gdiplus::Graphics&painter); 29 | void InitIllumination(Gdiplus::ImageAttributes&attributes); 30 | void DrawImage(Gdiplus::Graphics&painter, int dst_x, int dst_y, int dst_width, int dst_height, int src_x, int src_y, int src_width, int src_height); 31 | }; 32 | } -------------------------------------------------------------------------------- /Platform/Windows/Common/Control/Text/StaticText.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BattleFireLTD/Engine/eae9aae7dc63aec341c0bbc0a33ba7f9a136df19/Platform/Windows/Common/Control/Text/StaticText.cpp -------------------------------------------------------------------------------- /Platform/Windows/Common/Control/Text/StaticText.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "../UINode.h" 3 | 4 | namespace Editor 5 | { 6 | enum AligningMode 7 | { 8 | AligningModeLeft, 9 | AligningModeMiddle 10 | }; 11 | class StaticText:public UINode 12 | { 13 | protected: 14 | char mText[128]; 15 | TCHAR mWText[128]; 16 | Gdiplus::Rect mBkgColorRect; 17 | Gdiplus::Color mBkgColor; 18 | bool mbDrawBkgColor; 19 | Gdiplus::Color mTextColor; 20 | AligningMode mAligning; 21 | public: 22 | StaticText(); 23 | void SetAligning(AligningMode aligning); 24 | void SetText(const char* text); 25 | const char* GetText(); 26 | LPCTSTR GetWText(); 27 | void SetTextColor(BYTE r,BYTE g,BYTE b); 28 | Gdiplus::Color&GetTextColor(); 29 | void SetBkgColor(BYTE r, BYTE g, BYTE b); 30 | bool ShowBkgColor(bool bShow); 31 | bool IsShowBkgColor(); 32 | void SetBkgColorRect(int x,int y,int width,int height); 33 | void AdjustRect(int x,int y,int width,int height); 34 | 35 | bool operator==(StaticText&right); 36 | bool operator==(const char*text); 37 | bool operator!=(const char*text); 38 | void operator=(const char*text); 39 | void operator=(LPCTSTR text); 40 | public: 41 | virtual void Draw(Gdiplus::Graphics&painter); 42 | public: 43 | static Gdiplus::Font *SharedFont; 44 | static Gdiplus::StringFormat*SharedStringFormat; 45 | }; 46 | } -------------------------------------------------------------------------------- /Platform/Windows/Common/Control/UINode.cpp: -------------------------------------------------------------------------------- 1 | #include "UINode.h" 2 | namespace Editor{ 3 | UINode::UINode(){ 4 | mLeftMargin = 0; 5 | mRightMargin = 0; 6 | mTopMargin = 0; 7 | mBottomMargin = 0; 8 | mIntersectPos = UINodeIntersectPosNone; 9 | mHorizontalLocationCatagory = kUILocationCatagoryNone; 10 | mVerticalLocationCatagory = kUILocationCatagoryNone; 11 | mOnTouchBegin = nullptr; 12 | mOnTouchEnd = nullptr; 13 | mOnTouchCanceled = nullptr; 14 | mOnTouchMove = nullptr; 15 | mOnClicked = nullptr; 16 | } 17 | bool UINode::TestIntersect(int x, int y){ 18 | mIntersectPos = UINodeIntersectPosNone; 19 | if (mRect.Contains(x,y)){ 20 | mIntersectPos = UINodeIntersectPosMiddle; 21 | if (y <= mRect.Y + mTopMargin){ 22 | mIntersectPos = UINodeIntersectPosUpper; 23 | }else if (y >= mRect.Y + mRect.Height - mBottomMargin){ 24 | mIntersectPos = UINodeIntersectPosBottom; 25 | } 26 | return true; 27 | } 28 | return false; 29 | } 30 | UINode*UINode::Intersect(int x, int y){ 31 | UINode*ret = nullptr; 32 | if (((UINode*)mLastChild) != nullptr) { 33 | ret = ((UINode*)mLastChild)->Intersect(x,y); 34 | } 35 | if (ret != nullptr) { 36 | return ret; 37 | } 38 | if (TestIntersect(x,y)){ 39 | return this; 40 | } 41 | if (mLeftSibling != nullptr) { 42 | ret = LeftSibling()->Intersect(x, y); 43 | } 44 | return ret; 45 | } 46 | void UINode::DrawRecursively(Gdiplus::Graphics&painter) { 47 | Draw(painter); 48 | if (mChild != nullptr) { 49 | Child()->DrawRecursively(painter); 50 | } 51 | if (mRightSibling != nullptr) { 52 | RightSibling()->DrawRecursively(painter); 53 | } 54 | } 55 | void UINode::Draw(Gdiplus::Graphics&painter){ 56 | } 57 | void UINode::SetAnchor(float centerX, float centerY) { 58 | mCenterPosX = centerX; 59 | mCenterPosY = centerY; 60 | } 61 | void UINode::SetRect(Gdiplus::Rect &rect){ 62 | mRect = rect; 63 | } 64 | void UINode::SetPos(int x, int y){ 65 | mRect.X = x; 66 | mRect.Y = y; 67 | } 68 | void UINode::SetRect(int x, int y, int width, int height){ 69 | mRect.X = x; 70 | mRect.Y = y; 71 | mRect.Width = width; 72 | mRect.Height = height; 73 | } 74 | Gdiplus::Rect & UINode::GetRect(){ 75 | return mRect; 76 | } 77 | void UINode::SetOnTouchBeginHandler(VOID_VOID_PTR foo) { 78 | mOnTouchBegin = foo; 79 | } 80 | void UINode::SetOnTouchEndHandler(VOID_VOID_PTR foo) { 81 | mOnTouchEnd = foo; 82 | } 83 | void UINode::SetOnTouchCanceledHandler(VOID_VOID_PTR foo) { 84 | mOnTouchCanceled = foo; 85 | } 86 | void UINode::SetOnTouchMoveHandler(VOID_VOID_PTR foo) { 87 | mOnTouchMove = foo; 88 | } 89 | void UINode::SetOnClickedHandler(VOID_VOID_PTR foo) { 90 | mOnClicked = foo; 91 | } 92 | void UINode::OnTouchBegin(int x, int y, int touch_id/* =0 */) { 93 | 94 | } 95 | void UINode::OnTouchEnd(int x, int y, int touch_id /* = 0 */) { 96 | 97 | } 98 | void UINode::OnTouchCanceled(int x, int y, int touch_id /* = 0 */) { 99 | 100 | } 101 | void UINode::OnTouchMove(int x, int y, int touch_id /* = 0 */) { 102 | 103 | } 104 | void UINode::OnClicked(int x, int y, int touch_id /* = 0 */) { 105 | 106 | } 107 | void UINode::OnTouchEnter(int x, int y, int touch_id /* = 0 */) { 108 | 109 | } 110 | void UINode::OnTouchLeave(int x, int y, int touch_id /* = 0 */) { 111 | 112 | } 113 | void UINode::OnContainerSizeChanged(int width, int height) { 114 | int new_x_pos = mRect.X; 115 | int new_y_pos = mRect.Y; 116 | switch (mHorizontalLocationCatagory){ 117 | case Editor::UINode::kUILocationCatagoryRelativeToRight: 118 | new_x_pos = width - int(mCenterPosX) - mRect.Width/2; 119 | break; 120 | case Editor::UINode::kUILocationCatagoryPercentageAbsolute: 121 | case Editor::UINode::kUILocationCatagoryPercentageRelativeToLeft: 122 | case Editor::UINode::kUILocationCatagoryPercentageRelativeToRight: 123 | new_x_pos = int(width * mCenterPosX) - mRect.Width / 2; 124 | break; 125 | } 126 | switch (mVerticalLocationCatagory){ 127 | case Editor::UINode::kUILocationCatagoryRelativeToBottom: 128 | new_y_pos = height - int(mCenterPosY) - mRect.Height / 2; 129 | break; 130 | case Editor::UINode::kUILocationCatagoryPercentageAbsolute: 131 | case Editor::UINode::kUILocationCatagoryPercentageRelativeToTop: 132 | case Editor::UINode::kUILocationCatagoryPercentageRelativeToBottom: 133 | new_y_pos = int(height * mCenterPosY) - mRect.Height / 2; 134 | break; 135 | } 136 | mRect.X = new_x_pos; 137 | mRect.Y = new_y_pos; 138 | } 139 | void UINode::OnContainerSizeChangedRecursively(int width, int height) { 140 | OnContainerSizeChanged(width, height); 141 | if (mChild != nullptr) { 142 | Child()->OnContainerSizeChangedRecursively(width, height); 143 | } 144 | if (mRightSibling != nullptr) { 145 | RightSibling()->OnContainerSizeChangedRecursively(width, height); 146 | } 147 | } 148 | } -------------------------------------------------------------------------------- /Platform/Windows/Common/Control/UINode.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Runtime/BattleFirePrefix.h" 3 | #include "Runtime/Utils/TTree.h" 4 | namespace Editor{ 5 | enum UINodeIntersectPos{ 6 | UINodeIntersectPosUpper, 7 | UINodeIntersectPosMiddle, 8 | UINodeIntersectPosBottom, 9 | UINodeIntersectPosNone 10 | }; 11 | class UINode : public Alice::TTree { 12 | public: 13 | enum UILocationCatagory { 14 | kUILocationCatagoryNone, 15 | kUILocationCatagoryAbsolute, 16 | kUILocationCatagoryRelativeToLeft, 17 | kUILocationCatagoryRelativeToRight, 18 | kUILocationCatagoryRelativeToTop, 19 | kUILocationCatagoryRelativeToBottom, 20 | kUILocationCatagoryPercentageAbsolute, 21 | kUILocationCatagoryPercentageRelativeToLeft, 22 | kUILocationCatagoryPercentageRelativeToRight, 23 | kUILocationCatagoryPercentageRelativeToTop, 24 | kUILocationCatagoryPercentageRelativeToBottom, 25 | lUILocationCatagoryCount 26 | }; 27 | public: 28 | UINode(); 29 | UINodeIntersectPos mIntersectPos; 30 | UILocationCatagory mHorizontalLocationCatagory, mVerticalLocationCatagory; 31 | float mCenterPosX, mCenterPosY; 32 | public: 33 | void DrawRecursively(Gdiplus::Graphics&painter); 34 | void SetHorizontalLocationCatagory(UILocationCatagory catagory) { mHorizontalLocationCatagory = catagory; } 35 | void SetVerticalLocationCatagory(UILocationCatagory catagory) { mVerticalLocationCatagory = catagory; } 36 | void SetLocationCatagory(UILocationCatagory h, UILocationCatagory v) { mHorizontalLocationCatagory = h; mVerticalLocationCatagory = v; } 37 | void SetAnchor(float centerX,float centerY); 38 | virtual void Draw(Gdiplus::Graphics&painter); 39 | virtual void SetRect(Gdiplus::Rect &rect); 40 | virtual void SetPos(int x,int y); 41 | virtual void SetRect(int x, int y, int width, int height); 42 | virtual Gdiplus::Rect&GetRect(); 43 | virtual bool TestIntersect(int x, int y); 44 | virtual UINode*Intersect(int x, int y); 45 | virtual void OnTouchBegin(int x, int y,int touch_id=0); 46 | virtual void OnTouchEnd(int x, int y, int touch_id = 0); 47 | virtual void OnTouchMove(int x, int y, int touch_id = 0); 48 | virtual void OnTouchCanceled(int x, int y, int touch_id = 0); 49 | virtual void OnTouchEnter(int x, int y, int touch_id = 0); 50 | virtual void OnTouchLeave(int x, int y, int touch_id = 0); 51 | virtual void OnClicked(int x, int y, int touch_id = 0); 52 | virtual void ProcessEvent(int nCommandID) {} 53 | virtual void OnContainerSizeChanged(int width, int height); 54 | virtual void OnContainerSizeChangedRecursively(int width, int height); 55 | void SetOnTouchBeginHandler(VOID_VOID_PTR foo); 56 | void SetOnTouchEndHandler(VOID_VOID_PTR foo); 57 | void SetOnTouchMoveHandler(VOID_VOID_PTR foo); 58 | void SetOnTouchCanceledHandler(VOID_VOID_PTR foo); 59 | void SetOnClickedHandler(VOID_VOID_PTR foo); 60 | protected: 61 | Gdiplus::Rect mRect; 62 | int mLeftMargin,mRightMargin,mTopMargin,mBottomMargin; 63 | VOID_VOID_PTR mOnTouchBegin, mOnTouchEnd, mOnTouchCanceled, mOnTouchMove,mOnClicked; 64 | }; 65 | } -------------------------------------------------------------------------------- /Platform/Windows/Common/CursorManager.cpp: -------------------------------------------------------------------------------- 1 | #include "CursorManager.h" 2 | namespace Editor { 3 | CursorManager*CursorManager::mSingleton = nullptr; 4 | CursorManager::CursorManager() { 5 | mbCursorLocked = false; 6 | } 7 | CursorManager*CursorManager::Singleton() { 8 | if (mSingleton==nullptr){ 9 | mSingleton = new CursorManager; 10 | } 11 | return mSingleton; 12 | } 13 | HCURSOR CursorManager::GetCursor(const char * cursor_name) { 14 | std::unordered_map::iterator iter = mCursors.find(cursor_name); 15 | if (iter != mCursors.end()){ 16 | return iter->second; 17 | } 18 | return mCursors["arrow"]; 19 | } 20 | void CursorManager::Init() { 21 | HCURSOR cursor = LoadCursor(NULL, IDC_SIZEWE); 22 | //<-> left right arrow 23 | mCursors.insert(std::pair("hslide", cursor)); 24 | cursor = LoadCursor(NULL, IDC_SIZENS); 25 | //up-down direction arrow 26 | mCursors.insert(std::pair("vslide", cursor)); 27 | //cross arrow 28 | cursor = LoadCursor(NULL, IDC_CROSS); 29 | mCursors.insert(std::pair("drag", cursor)); 30 | //normal arrow 31 | cursor = LoadCursor(NULL, IDC_ARROW); 32 | mCursors.insert(std::pair("arrow", cursor)); 33 | cursor = LoadCursor(NULL, IDC_IBEAM); 34 | mCursors.insert(std::pair("edit", cursor)); 35 | } 36 | void CursorManager::ShowCursor(const char * cursor_name) { 37 | if (mbCursorLocked){ 38 | return; 39 | } 40 | ::SetCursor(GetCursor(cursor_name)); 41 | } 42 | bool CursorManager::IsCursorLocked() { 43 | return mbCursorLocked; 44 | } 45 | void CursorManager::LockCursor() { 46 | mbCursorLocked = true; 47 | } 48 | void CursorManager::UnlockCursor() { 49 | mbCursorLocked = false; 50 | } 51 | } -------------------------------------------------------------------------------- /Platform/Windows/Common/CursorManager.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | namespace Editor{ 6 | class CursorManager { 7 | protected: 8 | static CursorManager * mSingleton; 9 | bool mbCursorLocked; 10 | std::unordered_map mCursors; 11 | protected: 12 | HCURSOR GetCursor(const char * cursor_name); 13 | public: 14 | CursorManager(); 15 | void Init(); 16 | void ShowCursor(const char * cursor_name); 17 | void LockCursor(); 18 | void UnlockCursor(); 19 | bool IsCursorLocked(); 20 | static CursorManager * Singleton(); 21 | }; 22 | } -------------------------------------------------------------------------------- /Platform/Windows/Common/MainWindow.cpp: -------------------------------------------------------------------------------- 1 | #include "MainWindow.h" 2 | #include "Runtime/Debugger/Logger.h" 3 | #include "ViewWindow.h" 4 | namespace Editor { 5 | MainWindow::MainWindow() { 6 | mbDraging = false; 7 | mUIRoot = nullptr; 8 | mLastTouchObject = nullptr; 9 | mTitleBKGColor = Gdiplus::Color(200, 200, 200); 10 | mContainer = nullptr; 11 | SetWindowName("MainWindow"); 12 | } 13 | void MainWindow::OnSize(WPARAM wParam, LPARAM lParam, void*reserved) { 14 | RECT rect; 15 | GetWindowRect(mhWnd, &rect); 16 | mRect = {rect.left,rect.top,rect.right-rect.left,rect.bottom-rect.top}; 17 | RECT*ptr_rect = ▭ 18 | } 19 | LRESULT MainWindow::OnSizing(WPARAM wParam, LPARAM lParam, void*reserved /* = nullptr */) { 20 | RECT * ptr_new_rect = (RECT*)lParam; 21 | RECT current_rect; 22 | GetWindowRect(mhWnd, ¤t_rect); 23 | int new_width = ptr_new_rect->right - ptr_new_rect->left; 24 | int new_height = ptr_new_rect->bottom - ptr_new_rect->top; 25 | int last_width = current_rect.right - current_rect.left; 26 | int last_height = current_rect.bottom - current_rect.top; 27 | switch (wParam){ 28 | case WMSZ_LEFT:{ 29 | int deltaX = new_width - last_width; 30 | if (deltaX > 0) { 31 | ExtentWindowFromLeft(deltaX); 32 | } 33 | else if (deltaX < 0) { 34 | ReduceWindowFromLeft(deltaX); 35 | } 36 | } 37 | break; 38 | case WMSZ_RIGHT: { 39 | int deltaX = new_width - last_width; 40 | if (deltaX > 0) { 41 | ExtentWindowFromRight(deltaX); 42 | } 43 | else if (deltaX < 0) { 44 | ReduceWindowFromRight(deltaX); 45 | } 46 | } 47 | break; 48 | case WMSZ_TOP: { 49 | int deltaY = new_height - last_height; 50 | if (deltaY > 0) { 51 | ExtentWindowFromTop(deltaY); 52 | } 53 | else if (deltaY < 0) { 54 | ReduceWindowFromTop(deltaY); 55 | } 56 | } 57 | break; 58 | case WMSZ_TOPLEFT: { 59 | int deltaX = new_width - last_width; 60 | if (deltaX > 0) { 61 | ExtentWindowFromLeft(deltaX); 62 | } 63 | else if (deltaX < 0) { 64 | ReduceWindowFromLeft(deltaX); 65 | } 66 | int deltaY = new_height - last_height; 67 | if (deltaY > 0) { 68 | ExtentWindowFromTop(deltaY); 69 | } 70 | else if (deltaY < 0) { 71 | ReduceWindowFromTop(deltaY); 72 | } 73 | } 74 | break; 75 | case WMSZ_TOPRIGHT: { 76 | int deltaX = new_width - last_width; 77 | if (deltaX > 0) { 78 | ExtentWindowFromRight(deltaX); 79 | } 80 | else if (deltaX < 0) { 81 | ReduceWindowFromRight(deltaX); 82 | } 83 | int deltaY = new_height - last_height; 84 | if (deltaY > 0) { 85 | ExtentWindowFromTop(deltaY); 86 | } 87 | else if (deltaY < 0) { 88 | ReduceWindowFromTop(deltaY); 89 | } 90 | } 91 | break; 92 | case WMSZ_BOTTOM: { 93 | int deltaY = new_height - last_height; 94 | if (deltaY > 0) { 95 | ExtentWindowFromBottom(deltaY); 96 | } 97 | else if (deltaY < 0) { 98 | ReduceWindowFromBottom(deltaY); 99 | } 100 | } 101 | break; 102 | case WMSZ_BOTTOMLEFT: { 103 | int deltaX = new_width - last_width; 104 | if (deltaX > 0) { 105 | ExtentWindowFromLeft(deltaX); 106 | } 107 | else if (deltaX < 0) { 108 | ReduceWindowFromLeft(deltaX); 109 | } 110 | int deltaY = new_height - last_height; 111 | if (deltaY > 0) { 112 | ExtentWindowFromBottom(deltaY); 113 | } 114 | else if (deltaY < 0) { 115 | ReduceWindowFromBottom(deltaY); 116 | } 117 | } 118 | break; 119 | case WMSZ_BOTTOMRIGHT: { 120 | int deltaX = new_width - last_width; 121 | if (deltaX > 0) { 122 | ExtentWindowFromRight(deltaX); 123 | } 124 | else if (deltaX < 0) { 125 | ReduceWindowFromRight(deltaX); 126 | } 127 | int deltaY = new_height - last_height; 128 | if (deltaY > 0) { 129 | ExtentWindowFromBottom(deltaY); 130 | } 131 | else if (deltaY < 0) { 132 | ReduceWindowFromBottom(deltaY); 133 | } 134 | } 135 | break; 136 | } 137 | return TRUE; 138 | } 139 | void MainWindow::ExtentWindowFromLeft(int &deltaX) { 140 | mContainer->ExtentContainerFromLeft(deltaX); 141 | } 142 | void MainWindow::ExtentWindowFromRight(int &deltaX) { 143 | mContainer->ExtentContainerFromRight(deltaX); 144 | } 145 | void MainWindow::ExtentWindowFromBottom(int &deltaY) { 146 | mContainer->ExtentContainerFromBottom(deltaY); 147 | } 148 | void MainWindow::ExtentWindowFromTop(int &deltaY) { 149 | mContainer->ExtentContainerFromTop(deltaY); 150 | } 151 | void MainWindow::ReduceWindowFromLeft(int &deltaX) { 152 | mContainer->ReduceContainerFromLeft(deltaX); 153 | } 154 | void MainWindow::ReduceWindowFromRight(int &deltaX) { 155 | mContainer->ReduceContainerFromRight(deltaX); 156 | } 157 | void MainWindow::ReduceWindowFromBottom(int &deltaY) { 158 | mContainer->ReduceContainerFromBottom(deltaY); 159 | } 160 | void MainWindow::ReduceWindowFromTop(int &deltaY) { 161 | mContainer->ReduceContainerFromTop(deltaY); 162 | } 163 | void MainWindow::OnLButtonDown(WPARAM wParam, LPARAM lParam, void*reserved /* = nullptr */){ 164 | int x = LOWORD(lParam); 165 | int y = HIWORD(lParam); 166 | SetCapture(mhWnd); 167 | mbDraging = true; 168 | POINT pos; 169 | GetCursorPos(&pos); 170 | RECT windowRect; 171 | GetWindowRect(mhWnd, &windowRect); 172 | mDeltaWhenDrag.X = pos.x - windowRect.left; 173 | mDeltaWhenDrag.Y = pos.y - windowRect.top; 174 | } 175 | void MainWindow::OnLButtonUp(WPARAM wParam, LPARAM lParam, void*reserved /* = nullptr */){ 176 | int x = LOWORD(lParam); 177 | int y = HIWORD(lParam); 178 | ReleaseCapture(); 179 | mbDraging = false; 180 | } 181 | void MainWindow::OnMouseMove(WPARAM wParam, LPARAM lParam, void*reserved /* = nullptr */){ 182 | if (mbDraging){ 183 | POINT pos; 184 | GetCursorPos(&pos); 185 | SetRect(pos.x - mDeltaWhenDrag.X, pos.y - mDeltaWhenDrag.Y, mRect.Width, mRect.Height); 186 | MoveWindow(pos.x - mDeltaWhenDrag.X, pos.y - mDeltaWhenDrag.Y, mRect.Width, mRect.Height); 187 | } 188 | else { 189 | } 190 | DoubleBufferedWindow::OnMouseMove(wParam, lParam, reserved); 191 | } 192 | void MainWindow::DrawContent(Gdiplus::Graphics&painter) { 193 | if (mUIRoot!=nullptr){ 194 | mUIRoot->DrawRecursively(painter); 195 | } 196 | } 197 | void MainWindow::RenderChildren(Gdiplus::Graphics&painter, const Gdiplus::Rect & rect_need_update) { 198 | HWND cWnd = GetWindow(mhWnd, GW_CHILD); 199 | while (cWnd != nullptr) { 200 | BaseWindow*vw = WindowInstance(cWnd); 201 | vw->OnParentPaint(painter); 202 | cWnd = GetNextWindow(cWnd, GW_HWNDNEXT); 203 | } 204 | } 205 | void MainWindow::OnClearBKG(Gdiplus::Graphics&painter) { 206 | //painter.ExcludeClip(Gdiplus::Rect(mLeftNCSize, mTopNCSize, mBufferWidth - mLeftNCSize - mRightNCSize, mBufferHeight - mTopNCSize - mBottomNCSize)); 207 | painter.Clear(mBKGColor); 208 | //painter.ResetClip(); 209 | } 210 | 211 | void MainWindow::Init() { 212 | DWORD windowStyle = WS_OVERLAPPED | WS_CLIPCHILDREN; 213 | mhWnd = CreateWindowEx(NULL, L"MainWindow", NULL, 214 | windowStyle, 0, 0, CW_USEDEFAULT, CW_USEDEFAULT, 215 | NULL, NULL, GetModuleHandle(NULL), nullptr); 216 | SetWindowLongPtr(mhWnd, GWL_USERDATA, (LONG_PTR)this); 217 | mHDC = GetWindowDC(mhWnd); 218 | SetNCSize(6, 6, 6, 26); 219 | } 220 | void MainWindow::SetContainer(WindowContainer *container) { 221 | mContainer = container; 222 | Gdiplus::Rect container_min_rect = container->GetMinRect(); 223 | SetMinRect(0, 0, container_min_rect.Width+mLeftNCSize+mRightNCSize, container_min_rect.Height+mTopNCSize+mBottomNCSize); 224 | Debug("%s MainWindow::SetContainer min rect[%dx%d]",mName,mMinRect.Width,mMinRect.Height); 225 | } 226 | void MainWindow::RemoveChildWindowAt(ChildWindowLocation location, BaseWindow*window) { 227 | } 228 | void MainWindow::InitWindowClasses() { 229 | RegisterWindowClass(CS_VREDRAW | CS_HREDRAW | CS_DROPSHADOW | CS_DBLCLKS , L"MainWindow", WindowEventProc); 230 | } 231 | } -------------------------------------------------------------------------------- /Platform/Windows/Common/MainWindow.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Base/DoubleBufferedWindow.h" 3 | #include "Control/UINode.h" 4 | #include "Base/WindowContainer.h" 5 | namespace Editor { 6 | class MainWindow :public DoubleBufferedWindow { 7 | protected: 8 | Gdiplus::Point mDeltaWhenDrag; 9 | Gdiplus::Color mTitleBKGColor; 10 | bool mbDraging; 11 | UINode * mUIRoot, *mLastTouchObject; 12 | WindowContainer *mContainer; 13 | protected: 14 | virtual void OnLButtonDown(WPARAM wParam, LPARAM lParam, void*reserved = nullptr); 15 | virtual void OnLButtonUp(WPARAM wParam, LPARAM lParam, void*reserved = nullptr); 16 | virtual void OnMouseMove(WPARAM wParam, LPARAM lParam, void*reserved = nullptr); 17 | virtual void OnSize(WPARAM wParam, LPARAM lParam, void*reserved = nullptr); 18 | virtual LRESULT OnSizing(WPARAM wParam, LPARAM lParam, void*reserved = nullptr); 19 | virtual void DrawContent(Gdiplus::Graphics&painter); 20 | virtual void RenderChildren(Gdiplus::Graphics&painter, const Gdiplus::Rect & rect_need_update); 21 | virtual void OnClearBKG(Gdiplus::Graphics&painter); 22 | void ExtentWindowFromLeft(int &deltaX); 23 | void ReduceWindowFromLeft(int &deltaX); 24 | void ExtentWindowFromRight(int &deltaX); 25 | void ReduceWindowFromRight(int &deltaX); 26 | void ExtentWindowFromTop(int &deltaY); 27 | void ReduceWindowFromTop(int &deltaY); 28 | void ExtentWindowFromBottom(int &deltaY); 29 | void ReduceWindowFromBottom(int &deltaY); 30 | public: 31 | MainWindow(); 32 | void SetContainer(WindowContainer *container); 33 | void RemoveChildWindowAt(ChildWindowLocation location, BaseWindow*window); 34 | void Init(); 35 | static void InitWindowClasses(); 36 | }; 37 | } -------------------------------------------------------------------------------- /Platform/Windows/Common/PlatformWindowsSeriallizer.pb.cc: -------------------------------------------------------------------------------- 1 | // Generated by the protocol buffer compiler. DO NOT EDIT! 2 | // source: PlatformWindowsSeriallizer.proto 3 | 4 | #include "PlatformWindowsSeriallizer.pb.h" 5 | 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | // @@protoc_insertion_point(includes) 16 | #include 17 | extern PROTOBUF_INTERNAL_EXPORT_PlatformWindowsSeriallizer_2eproto ::PROTOBUF_NAMESPACE_ID::internal::SCCInfo<0> scc_info_WinResources_ResEntry_DoNotUse_PlatformWindowsSeriallizer_2eproto; 18 | namespace PlatformWindowsSeriallizer { 19 | class WinResources_ResEntry_DoNotUseDefaultTypeInternal { 20 | public: 21 | ::PROTOBUF_NAMESPACE_ID::internal::ExplicitlyConstructed _instance; 22 | } _WinResources_ResEntry_DoNotUse_default_instance_; 23 | class WinResourcesDefaultTypeInternal { 24 | public: 25 | ::PROTOBUF_NAMESPACE_ID::internal::ExplicitlyConstructed _instance; 26 | } _WinResources_default_instance_; 27 | } // namespace PlatformWindowsSeriallizer 28 | static void InitDefaultsscc_info_WinResources_PlatformWindowsSeriallizer_2eproto() { 29 | GOOGLE_PROTOBUF_VERIFY_VERSION; 30 | 31 | { 32 | void* ptr = &::PlatformWindowsSeriallizer::_WinResources_default_instance_; 33 | new (ptr) ::PlatformWindowsSeriallizer::WinResources(); 34 | ::PROTOBUF_NAMESPACE_ID::internal::OnShutdownDestroyMessage(ptr); 35 | } 36 | ::PlatformWindowsSeriallizer::WinResources::InitAsDefaultInstance(); 37 | } 38 | 39 | ::PROTOBUF_NAMESPACE_ID::internal::SCCInfo<1> scc_info_WinResources_PlatformWindowsSeriallizer_2eproto = 40 | {{ATOMIC_VAR_INIT(::PROTOBUF_NAMESPACE_ID::internal::SCCInfoBase::kUninitialized), 1, 0, InitDefaultsscc_info_WinResources_PlatformWindowsSeriallizer_2eproto}, { 41 | &scc_info_WinResources_ResEntry_DoNotUse_PlatformWindowsSeriallizer_2eproto.base,}}; 42 | 43 | static void InitDefaultsscc_info_WinResources_ResEntry_DoNotUse_PlatformWindowsSeriallizer_2eproto() { 44 | GOOGLE_PROTOBUF_VERIFY_VERSION; 45 | 46 | { 47 | void* ptr = &::PlatformWindowsSeriallizer::_WinResources_ResEntry_DoNotUse_default_instance_; 48 | new (ptr) ::PlatformWindowsSeriallizer::WinResources_ResEntry_DoNotUse(); 49 | } 50 | ::PlatformWindowsSeriallizer::WinResources_ResEntry_DoNotUse::InitAsDefaultInstance(); 51 | } 52 | 53 | ::PROTOBUF_NAMESPACE_ID::internal::SCCInfo<0> scc_info_WinResources_ResEntry_DoNotUse_PlatformWindowsSeriallizer_2eproto = 54 | {{ATOMIC_VAR_INIT(::PROTOBUF_NAMESPACE_ID::internal::SCCInfoBase::kUninitialized), 0, 0, InitDefaultsscc_info_WinResources_ResEntry_DoNotUse_PlatformWindowsSeriallizer_2eproto}, {}}; 55 | 56 | static ::PROTOBUF_NAMESPACE_ID::Metadata file_level_metadata_PlatformWindowsSeriallizer_2eproto[2]; 57 | static constexpr ::PROTOBUF_NAMESPACE_ID::EnumDescriptor const** file_level_enum_descriptors_PlatformWindowsSeriallizer_2eproto = nullptr; 58 | static constexpr ::PROTOBUF_NAMESPACE_ID::ServiceDescriptor const** file_level_service_descriptors_PlatformWindowsSeriallizer_2eproto = nullptr; 59 | 60 | const ::PROTOBUF_NAMESPACE_ID::uint32 TableStruct_PlatformWindowsSeriallizer_2eproto::offsets[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = { 61 | PROTOBUF_FIELD_OFFSET(::PlatformWindowsSeriallizer::WinResources_ResEntry_DoNotUse, _has_bits_), 62 | PROTOBUF_FIELD_OFFSET(::PlatformWindowsSeriallizer::WinResources_ResEntry_DoNotUse, _internal_metadata_), 63 | ~0u, // no _extensions_ 64 | ~0u, // no _oneof_case_ 65 | ~0u, // no _weak_field_map_ 66 | PROTOBUF_FIELD_OFFSET(::PlatformWindowsSeriallizer::WinResources_ResEntry_DoNotUse, key_), 67 | PROTOBUF_FIELD_OFFSET(::PlatformWindowsSeriallizer::WinResources_ResEntry_DoNotUse, value_), 68 | 0, 69 | 1, 70 | ~0u, // no _has_bits_ 71 | PROTOBUF_FIELD_OFFSET(::PlatformWindowsSeriallizer::WinResources, _internal_metadata_), 72 | ~0u, // no _extensions_ 73 | ~0u, // no _oneof_case_ 74 | ~0u, // no _weak_field_map_ 75 | PROTOBUF_FIELD_OFFSET(::PlatformWindowsSeriallizer::WinResources, res_), 76 | }; 77 | static const ::PROTOBUF_NAMESPACE_ID::internal::MigrationSchema schemas[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = { 78 | { 0, 7, sizeof(::PlatformWindowsSeriallizer::WinResources_ResEntry_DoNotUse)}, 79 | { 9, -1, sizeof(::PlatformWindowsSeriallizer::WinResources)}, 80 | }; 81 | 82 | static ::PROTOBUF_NAMESPACE_ID::Message const * const file_default_instances[] = { 83 | reinterpret_cast(&::PlatformWindowsSeriallizer::_WinResources_ResEntry_DoNotUse_default_instance_), 84 | reinterpret_cast(&::PlatformWindowsSeriallizer::_WinResources_default_instance_), 85 | }; 86 | 87 | const char descriptor_table_protodef_PlatformWindowsSeriallizer_2eproto[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = 88 | "\n PlatformWindowsSeriallizer.proto\022\032Plat" 89 | "formWindowsSeriallizer\"z\n\014WinResources\022>" 90 | "\n\003res\030\001 \003(\01321.PlatformWindowsSeriallizer" 91 | ".WinResources.ResEntry\032*\n\010ResEntry\022\013\n\003ke" 92 | "y\030\001 \001(\t\022\r\n\005value\030\002 \001(\014:\0028\001b\006proto3" 93 | ; 94 | static const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable*const descriptor_table_PlatformWindowsSeriallizer_2eproto_deps[1] = { 95 | }; 96 | static ::PROTOBUF_NAMESPACE_ID::internal::SCCInfoBase*const descriptor_table_PlatformWindowsSeriallizer_2eproto_sccs[2] = { 97 | &scc_info_WinResources_PlatformWindowsSeriallizer_2eproto.base, 98 | &scc_info_WinResources_ResEntry_DoNotUse_PlatformWindowsSeriallizer_2eproto.base, 99 | }; 100 | static ::PROTOBUF_NAMESPACE_ID::internal::once_flag descriptor_table_PlatformWindowsSeriallizer_2eproto_once; 101 | const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable descriptor_table_PlatformWindowsSeriallizer_2eproto = { 102 | false, false, descriptor_table_protodef_PlatformWindowsSeriallizer_2eproto, "PlatformWindowsSeriallizer.proto", 194, 103 | &descriptor_table_PlatformWindowsSeriallizer_2eproto_once, descriptor_table_PlatformWindowsSeriallizer_2eproto_sccs, descriptor_table_PlatformWindowsSeriallizer_2eproto_deps, 2, 0, 104 | schemas, file_default_instances, TableStruct_PlatformWindowsSeriallizer_2eproto::offsets, 105 | file_level_metadata_PlatformWindowsSeriallizer_2eproto, 2, file_level_enum_descriptors_PlatformWindowsSeriallizer_2eproto, file_level_service_descriptors_PlatformWindowsSeriallizer_2eproto, 106 | }; 107 | 108 | // Force running AddDescriptors() at dynamic initialization time. 109 | static bool dynamic_init_dummy_PlatformWindowsSeriallizer_2eproto = (static_cast(::PROTOBUF_NAMESPACE_ID::internal::AddDescriptors(&descriptor_table_PlatformWindowsSeriallizer_2eproto)), true); 110 | namespace PlatformWindowsSeriallizer { 111 | 112 | // =================================================================== 113 | 114 | WinResources_ResEntry_DoNotUse::WinResources_ResEntry_DoNotUse() {} 115 | WinResources_ResEntry_DoNotUse::WinResources_ResEntry_DoNotUse(::PROTOBUF_NAMESPACE_ID::Arena* arena) 116 | : SuperType(arena) {} 117 | void WinResources_ResEntry_DoNotUse::MergeFrom(const WinResources_ResEntry_DoNotUse& other) { 118 | MergeFromInternal(other); 119 | } 120 | ::PROTOBUF_NAMESPACE_ID::Metadata WinResources_ResEntry_DoNotUse::GetMetadata() const { 121 | return GetMetadataStatic(); 122 | } 123 | void WinResources_ResEntry_DoNotUse::MergeFrom( 124 | const ::PROTOBUF_NAMESPACE_ID::Message& other) { 125 | ::PROTOBUF_NAMESPACE_ID::Message::MergeFrom(other); 126 | } 127 | 128 | 129 | // =================================================================== 130 | 131 | void WinResources::InitAsDefaultInstance() { 132 | } 133 | class WinResources::_Internal { 134 | public: 135 | }; 136 | 137 | WinResources::WinResources(::PROTOBUF_NAMESPACE_ID::Arena* arena) 138 | : ::PROTOBUF_NAMESPACE_ID::Message(arena), 139 | res_(arena) { 140 | SharedCtor(); 141 | RegisterArenaDtor(arena); 142 | // @@protoc_insertion_point(arena_constructor:PlatformWindowsSeriallizer.WinResources) 143 | } 144 | WinResources::WinResources(const WinResources& from) 145 | : ::PROTOBUF_NAMESPACE_ID::Message() { 146 | _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); 147 | res_.MergeFrom(from.res_); 148 | // @@protoc_insertion_point(copy_constructor:PlatformWindowsSeriallizer.WinResources) 149 | } 150 | 151 | void WinResources::SharedCtor() { 152 | ::PROTOBUF_NAMESPACE_ID::internal::InitSCC(&scc_info_WinResources_PlatformWindowsSeriallizer_2eproto.base); 153 | } 154 | 155 | WinResources::~WinResources() { 156 | // @@protoc_insertion_point(destructor:PlatformWindowsSeriallizer.WinResources) 157 | SharedDtor(); 158 | _internal_metadata_.Delete<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(); 159 | } 160 | 161 | void WinResources::SharedDtor() { 162 | GOOGLE_DCHECK(GetArena() == nullptr); 163 | } 164 | 165 | void WinResources::ArenaDtor(void* object) { 166 | WinResources* _this = reinterpret_cast< WinResources* >(object); 167 | (void)_this; 168 | } 169 | void WinResources::RegisterArenaDtor(::PROTOBUF_NAMESPACE_ID::Arena*) { 170 | } 171 | void WinResources::SetCachedSize(int size) const { 172 | _cached_size_.Set(size); 173 | } 174 | const WinResources& WinResources::default_instance() { 175 | ::PROTOBUF_NAMESPACE_ID::internal::InitSCC(&::scc_info_WinResources_PlatformWindowsSeriallizer_2eproto.base); 176 | return *internal_default_instance(); 177 | } 178 | 179 | 180 | void WinResources::Clear() { 181 | // @@protoc_insertion_point(message_clear_start:PlatformWindowsSeriallizer.WinResources) 182 | ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; 183 | // Prevent compiler warnings about cached_has_bits being unused 184 | (void) cached_has_bits; 185 | 186 | res_.Clear(); 187 | _internal_metadata_.Clear<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(); 188 | } 189 | 190 | const char* WinResources::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) { 191 | #define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure 192 | ::PROTOBUF_NAMESPACE_ID::Arena* arena = GetArena(); (void)arena; 193 | while (!ctx->Done(&ptr)) { 194 | ::PROTOBUF_NAMESPACE_ID::uint32 tag; 195 | ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); 196 | CHK_(ptr); 197 | switch (tag >> 3) { 198 | // map res = 1; 199 | case 1: 200 | if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 10)) { 201 | ptr -= 1; 202 | do { 203 | ptr += 1; 204 | ptr = ctx->ParseMessage(&res_, ptr); 205 | CHK_(ptr); 206 | if (!ctx->DataAvailable(ptr)) break; 207 | } while (::PROTOBUF_NAMESPACE_ID::internal::ExpectTag<10>(ptr)); 208 | } else goto handle_unusual; 209 | continue; 210 | default: { 211 | handle_unusual: 212 | if ((tag & 7) == 4 || tag == 0) { 213 | ctx->SetLastTag(tag); 214 | goto success; 215 | } 216 | ptr = UnknownFieldParse(tag, 217 | _internal_metadata_.mutable_unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(), 218 | ptr, ctx); 219 | CHK_(ptr != nullptr); 220 | continue; 221 | } 222 | } // switch 223 | } // while 224 | success: 225 | return ptr; 226 | failure: 227 | ptr = nullptr; 228 | goto success; 229 | #undef CHK_ 230 | } 231 | 232 | ::PROTOBUF_NAMESPACE_ID::uint8* WinResources::_InternalSerialize( 233 | ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { 234 | // @@protoc_insertion_point(serialize_to_array_start:PlatformWindowsSeriallizer.WinResources) 235 | ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; 236 | (void) cached_has_bits; 237 | 238 | // map res = 1; 239 | if (!this->_internal_res().empty()) { 240 | typedef ::PROTOBUF_NAMESPACE_ID::Map< std::string, std::string >::const_pointer 241 | ConstPtr; 242 | typedef ConstPtr SortItem; 243 | typedef ::PROTOBUF_NAMESPACE_ID::internal::CompareByDerefFirst Less; 244 | struct Utf8Check { 245 | static void Check(ConstPtr p) { 246 | ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::VerifyUtf8String( 247 | p->first.data(), static_cast(p->first.length()), 248 | ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::SERIALIZE, 249 | "PlatformWindowsSeriallizer.WinResources.ResEntry.key"); 250 | } 251 | }; 252 | 253 | if (stream->IsSerializationDeterministic() && 254 | this->_internal_res().size() > 1) { 255 | ::std::unique_ptr items( 256 | new SortItem[this->_internal_res().size()]); 257 | typedef ::PROTOBUF_NAMESPACE_ID::Map< std::string, std::string >::size_type size_type; 258 | size_type n = 0; 259 | for (::PROTOBUF_NAMESPACE_ID::Map< std::string, std::string >::const_iterator 260 | it = this->_internal_res().begin(); 261 | it != this->_internal_res().end(); ++it, ++n) { 262 | items[static_cast(n)] = SortItem(&*it); 263 | } 264 | ::std::sort(&items[0], &items[static_cast(n)], Less()); 265 | for (size_type i = 0; i < n; i++) { 266 | target = WinResources_ResEntry_DoNotUse::Funcs::InternalSerialize(1, items[static_cast(i)]->first, items[static_cast(i)]->second, target, stream); 267 | Utf8Check::Check(&(*items[static_cast(i)])); 268 | } 269 | } else { 270 | for (::PROTOBUF_NAMESPACE_ID::Map< std::string, std::string >::const_iterator 271 | it = this->_internal_res().begin(); 272 | it != this->_internal_res().end(); ++it) { 273 | target = WinResources_ResEntry_DoNotUse::Funcs::InternalSerialize(1, it->first, it->second, target, stream); 274 | Utf8Check::Check(&(*it)); 275 | } 276 | } 277 | } 278 | 279 | if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { 280 | target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::InternalSerializeUnknownFieldsToArray( 281 | _internal_metadata_.unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(::PROTOBUF_NAMESPACE_ID::UnknownFieldSet::default_instance), target, stream); 282 | } 283 | // @@protoc_insertion_point(serialize_to_array_end:PlatformWindowsSeriallizer.WinResources) 284 | return target; 285 | } 286 | 287 | size_t WinResources::ByteSizeLong() const { 288 | // @@protoc_insertion_point(message_byte_size_start:PlatformWindowsSeriallizer.WinResources) 289 | size_t total_size = 0; 290 | 291 | ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; 292 | // Prevent compiler warnings about cached_has_bits being unused 293 | (void) cached_has_bits; 294 | 295 | // map res = 1; 296 | total_size += 1 * 297 | ::PROTOBUF_NAMESPACE_ID::internal::FromIntSize(this->_internal_res_size()); 298 | for (::PROTOBUF_NAMESPACE_ID::Map< std::string, std::string >::const_iterator 299 | it = this->_internal_res().begin(); 300 | it != this->_internal_res().end(); ++it) { 301 | total_size += WinResources_ResEntry_DoNotUse::Funcs::ByteSizeLong(it->first, it->second); 302 | } 303 | 304 | if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { 305 | return ::PROTOBUF_NAMESPACE_ID::internal::ComputeUnknownFieldsSize( 306 | _internal_metadata_, total_size, &_cached_size_); 307 | } 308 | int cached_size = ::PROTOBUF_NAMESPACE_ID::internal::ToCachedSize(total_size); 309 | SetCachedSize(cached_size); 310 | return total_size; 311 | } 312 | 313 | void WinResources::MergeFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) { 314 | // @@protoc_insertion_point(generalized_merge_from_start:PlatformWindowsSeriallizer.WinResources) 315 | GOOGLE_DCHECK_NE(&from, this); 316 | const WinResources* source = 317 | ::PROTOBUF_NAMESPACE_ID::DynamicCastToGenerated( 318 | &from); 319 | if (source == nullptr) { 320 | // @@protoc_insertion_point(generalized_merge_from_cast_fail:PlatformWindowsSeriallizer.WinResources) 321 | ::PROTOBUF_NAMESPACE_ID::internal::ReflectionOps::Merge(from, this); 322 | } else { 323 | // @@protoc_insertion_point(generalized_merge_from_cast_success:PlatformWindowsSeriallizer.WinResources) 324 | MergeFrom(*source); 325 | } 326 | } 327 | 328 | void WinResources::MergeFrom(const WinResources& from) { 329 | // @@protoc_insertion_point(class_specific_merge_from_start:PlatformWindowsSeriallizer.WinResources) 330 | GOOGLE_DCHECK_NE(&from, this); 331 | _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); 332 | ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; 333 | (void) cached_has_bits; 334 | 335 | res_.MergeFrom(from.res_); 336 | } 337 | 338 | void WinResources::CopyFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) { 339 | // @@protoc_insertion_point(generalized_copy_from_start:PlatformWindowsSeriallizer.WinResources) 340 | if (&from == this) return; 341 | Clear(); 342 | MergeFrom(from); 343 | } 344 | 345 | void WinResources::CopyFrom(const WinResources& from) { 346 | // @@protoc_insertion_point(class_specific_copy_from_start:PlatformWindowsSeriallizer.WinResources) 347 | if (&from == this) return; 348 | Clear(); 349 | MergeFrom(from); 350 | } 351 | 352 | bool WinResources::IsInitialized() const { 353 | return true; 354 | } 355 | 356 | void WinResources::InternalSwap(WinResources* other) { 357 | using std::swap; 358 | _internal_metadata_.Swap<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(&other->_internal_metadata_); 359 | res_.Swap(&other->res_); 360 | } 361 | 362 | ::PROTOBUF_NAMESPACE_ID::Metadata WinResources::GetMetadata() const { 363 | return GetMetadataStatic(); 364 | } 365 | 366 | 367 | // @@protoc_insertion_point(namespace_scope) 368 | } // namespace PlatformWindowsSeriallizer 369 | PROTOBUF_NAMESPACE_OPEN 370 | template<> PROTOBUF_NOINLINE ::PlatformWindowsSeriallizer::WinResources_ResEntry_DoNotUse* Arena::CreateMaybeMessage< ::PlatformWindowsSeriallizer::WinResources_ResEntry_DoNotUse >(Arena* arena) { 371 | return Arena::CreateMessageInternal< ::PlatformWindowsSeriallizer::WinResources_ResEntry_DoNotUse >(arena); 372 | } 373 | template<> PROTOBUF_NOINLINE ::PlatformWindowsSeriallizer::WinResources* Arena::CreateMaybeMessage< ::PlatformWindowsSeriallizer::WinResources >(Arena* arena) { 374 | return Arena::CreateMessageInternal< ::PlatformWindowsSeriallizer::WinResources >(arena); 375 | } 376 | PROTOBUF_NAMESPACE_CLOSE 377 | 378 | // @@protoc_insertion_point(global_scope) 379 | #include 380 | -------------------------------------------------------------------------------- /Platform/Windows/Common/PlatformWindowsSeriallizer.pb.h: -------------------------------------------------------------------------------- 1 | // Generated by the protocol buffer compiler. DO NOT EDIT! 2 | // source: PlatformWindowsSeriallizer.proto 3 | 4 | #ifndef GOOGLE_PROTOBUF_INCLUDED_PlatformWindowsSeriallizer_2eproto 5 | #define GOOGLE_PROTOBUF_INCLUDED_PlatformWindowsSeriallizer_2eproto 6 | 7 | #include 8 | #include 9 | 10 | #include 11 | #if PROTOBUF_VERSION < 3013000 12 | #error This file was generated by a newer version of protoc which is 13 | #error incompatible with your Protocol Buffer headers. Please update 14 | #error your headers. 15 | #endif 16 | #if 3013000 < PROTOBUF_MIN_PROTOC_VERSION 17 | #error This file was generated by an older version of protoc which is 18 | #error incompatible with your Protocol Buffer headers. Please 19 | #error regenerate this file with a newer version of protoc. 20 | #endif 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include // IWYU pragma: export 33 | #include // IWYU pragma: export 34 | #include // IWYU pragma: export 35 | #include 36 | #include 37 | #include 38 | // @@protoc_insertion_point(includes) 39 | #include 40 | #define PROTOBUF_INTERNAL_EXPORT_PlatformWindowsSeriallizer_2eproto 41 | PROTOBUF_NAMESPACE_OPEN 42 | namespace internal { 43 | class AnyMetadata; 44 | } // namespace internal 45 | PROTOBUF_NAMESPACE_CLOSE 46 | 47 | // Internal implementation detail -- do not use these members. 48 | struct TableStruct_PlatformWindowsSeriallizer_2eproto { 49 | static const ::PROTOBUF_NAMESPACE_ID::internal::ParseTableField entries[] 50 | PROTOBUF_SECTION_VARIABLE(protodesc_cold); 51 | static const ::PROTOBUF_NAMESPACE_ID::internal::AuxiliaryParseTableField aux[] 52 | PROTOBUF_SECTION_VARIABLE(protodesc_cold); 53 | static const ::PROTOBUF_NAMESPACE_ID::internal::ParseTable schema[2] 54 | PROTOBUF_SECTION_VARIABLE(protodesc_cold); 55 | static const ::PROTOBUF_NAMESPACE_ID::internal::FieldMetadata field_metadata[]; 56 | static const ::PROTOBUF_NAMESPACE_ID::internal::SerializationTable serialization_table[]; 57 | static const ::PROTOBUF_NAMESPACE_ID::uint32 offsets[]; 58 | }; 59 | extern const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable descriptor_table_PlatformWindowsSeriallizer_2eproto; 60 | namespace PlatformWindowsSeriallizer { 61 | class WinResources; 62 | class WinResourcesDefaultTypeInternal; 63 | extern WinResourcesDefaultTypeInternal _WinResources_default_instance_; 64 | class WinResources_ResEntry_DoNotUse; 65 | class WinResources_ResEntry_DoNotUseDefaultTypeInternal; 66 | extern WinResources_ResEntry_DoNotUseDefaultTypeInternal _WinResources_ResEntry_DoNotUse_default_instance_; 67 | } // namespace PlatformWindowsSeriallizer 68 | PROTOBUF_NAMESPACE_OPEN 69 | template<> ::PlatformWindowsSeriallizer::WinResources* Arena::CreateMaybeMessage<::PlatformWindowsSeriallizer::WinResources>(Arena*); 70 | template<> ::PlatformWindowsSeriallizer::WinResources_ResEntry_DoNotUse* Arena::CreateMaybeMessage<::PlatformWindowsSeriallizer::WinResources_ResEntry_DoNotUse>(Arena*); 71 | PROTOBUF_NAMESPACE_CLOSE 72 | namespace PlatformWindowsSeriallizer { 73 | 74 | // =================================================================== 75 | 76 | class WinResources_ResEntry_DoNotUse : public ::PROTOBUF_NAMESPACE_ID::internal::MapEntry { 81 | public: 82 | typedef ::PROTOBUF_NAMESPACE_ID::internal::MapEntry SuperType; 87 | WinResources_ResEntry_DoNotUse(); 88 | explicit WinResources_ResEntry_DoNotUse(::PROTOBUF_NAMESPACE_ID::Arena* arena); 89 | void MergeFrom(const WinResources_ResEntry_DoNotUse& other); 90 | static const WinResources_ResEntry_DoNotUse* internal_default_instance() { return reinterpret_cast(&_WinResources_ResEntry_DoNotUse_default_instance_); } 91 | static bool ValidateKey(std::string* s) { 92 | return ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::VerifyUtf8String(s->data(), static_cast(s->size()), ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::PARSE, "PlatformWindowsSeriallizer.WinResources.ResEntry.key"); 93 | } 94 | static bool ValidateValue(void*) { return true; } 95 | void MergeFrom(const ::PROTOBUF_NAMESPACE_ID::Message& other) final; 96 | ::PROTOBUF_NAMESPACE_ID::Metadata GetMetadata() const final; 97 | private: 98 | static ::PROTOBUF_NAMESPACE_ID::Metadata GetMetadataStatic() { 99 | ::PROTOBUF_NAMESPACE_ID::internal::AssignDescriptors(&::descriptor_table_PlatformWindowsSeriallizer_2eproto); 100 | return ::descriptor_table_PlatformWindowsSeriallizer_2eproto.file_level_metadata[0]; 101 | } 102 | 103 | public: 104 | }; 105 | 106 | // ------------------------------------------------------------------- 107 | 108 | class WinResources PROTOBUF_FINAL : 109 | public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:PlatformWindowsSeriallizer.WinResources) */ { 110 | public: 111 | inline WinResources() : WinResources(nullptr) {} 112 | virtual ~WinResources(); 113 | 114 | WinResources(const WinResources& from); 115 | WinResources(WinResources&& from) noexcept 116 | : WinResources() { 117 | *this = ::std::move(from); 118 | } 119 | 120 | inline WinResources& operator=(const WinResources& from) { 121 | CopyFrom(from); 122 | return *this; 123 | } 124 | inline WinResources& operator=(WinResources&& from) noexcept { 125 | if (GetArena() == from.GetArena()) { 126 | if (this != &from) InternalSwap(&from); 127 | } else { 128 | CopyFrom(from); 129 | } 130 | return *this; 131 | } 132 | 133 | static const ::PROTOBUF_NAMESPACE_ID::Descriptor* descriptor() { 134 | return GetDescriptor(); 135 | } 136 | static const ::PROTOBUF_NAMESPACE_ID::Descriptor* GetDescriptor() { 137 | return GetMetadataStatic().descriptor; 138 | } 139 | static const ::PROTOBUF_NAMESPACE_ID::Reflection* GetReflection() { 140 | return GetMetadataStatic().reflection; 141 | } 142 | static const WinResources& default_instance(); 143 | 144 | static void InitAsDefaultInstance(); // FOR INTERNAL USE ONLY 145 | static inline const WinResources* internal_default_instance() { 146 | return reinterpret_cast( 147 | &_WinResources_default_instance_); 148 | } 149 | static constexpr int kIndexInFileMessages = 150 | 1; 151 | 152 | friend void swap(WinResources& a, WinResources& b) { 153 | a.Swap(&b); 154 | } 155 | inline void Swap(WinResources* other) { 156 | if (other == this) return; 157 | if (GetArena() == other->GetArena()) { 158 | InternalSwap(other); 159 | } else { 160 | ::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other); 161 | } 162 | } 163 | void UnsafeArenaSwap(WinResources* other) { 164 | if (other == this) return; 165 | GOOGLE_DCHECK(GetArena() == other->GetArena()); 166 | InternalSwap(other); 167 | } 168 | 169 | // implements Message ---------------------------------------------- 170 | 171 | inline WinResources* New() const final { 172 | return CreateMaybeMessage(nullptr); 173 | } 174 | 175 | WinResources* New(::PROTOBUF_NAMESPACE_ID::Arena* arena) const final { 176 | return CreateMaybeMessage(arena); 177 | } 178 | void CopyFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) final; 179 | void MergeFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) final; 180 | void CopyFrom(const WinResources& from); 181 | void MergeFrom(const WinResources& from); 182 | PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; 183 | bool IsInitialized() const final; 184 | 185 | size_t ByteSizeLong() const final; 186 | const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; 187 | ::PROTOBUF_NAMESPACE_ID::uint8* _InternalSerialize( 188 | ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; 189 | int GetCachedSize() const final { return _cached_size_.Get(); } 190 | 191 | private: 192 | inline void SharedCtor(); 193 | inline void SharedDtor(); 194 | void SetCachedSize(int size) const final; 195 | void InternalSwap(WinResources* other); 196 | friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; 197 | static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() { 198 | return "PlatformWindowsSeriallizer.WinResources"; 199 | } 200 | protected: 201 | explicit WinResources(::PROTOBUF_NAMESPACE_ID::Arena* arena); 202 | private: 203 | static void ArenaDtor(void* object); 204 | inline void RegisterArenaDtor(::PROTOBUF_NAMESPACE_ID::Arena* arena); 205 | public: 206 | 207 | ::PROTOBUF_NAMESPACE_ID::Metadata GetMetadata() const final; 208 | private: 209 | static ::PROTOBUF_NAMESPACE_ID::Metadata GetMetadataStatic() { 210 | ::PROTOBUF_NAMESPACE_ID::internal::AssignDescriptors(&::descriptor_table_PlatformWindowsSeriallizer_2eproto); 211 | return ::descriptor_table_PlatformWindowsSeriallizer_2eproto.file_level_metadata[kIndexInFileMessages]; 212 | } 213 | 214 | public: 215 | 216 | // nested types ---------------------------------------------------- 217 | 218 | 219 | // accessors ------------------------------------------------------- 220 | 221 | enum : int { 222 | kResFieldNumber = 1, 223 | }; 224 | // map res = 1; 225 | int res_size() const; 226 | private: 227 | int _internal_res_size() const; 228 | public: 229 | void clear_res(); 230 | private: 231 | const ::PROTOBUF_NAMESPACE_ID::Map< std::string, std::string >& 232 | _internal_res() const; 233 | ::PROTOBUF_NAMESPACE_ID::Map< std::string, std::string >* 234 | _internal_mutable_res(); 235 | public: 236 | const ::PROTOBUF_NAMESPACE_ID::Map< std::string, std::string >& 237 | res() const; 238 | ::PROTOBUF_NAMESPACE_ID::Map< std::string, std::string >* 239 | mutable_res(); 240 | 241 | // @@protoc_insertion_point(class_scope:PlatformWindowsSeriallizer.WinResources) 242 | private: 243 | class _Internal; 244 | 245 | template friend class ::PROTOBUF_NAMESPACE_ID::Arena::InternalHelper; 246 | typedef void InternalArenaConstructable_; 247 | typedef void DestructorSkippable_; 248 | ::PROTOBUF_NAMESPACE_ID::internal::MapField< 249 | WinResources_ResEntry_DoNotUse, 250 | std::string, std::string, 251 | ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::TYPE_STRING, 252 | ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::TYPE_BYTES, 253 | 0 > res_; 254 | mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_; 255 | friend struct ::TableStruct_PlatformWindowsSeriallizer_2eproto; 256 | }; 257 | // =================================================================== 258 | 259 | 260 | // =================================================================== 261 | 262 | #ifdef __GNUC__ 263 | #pragma GCC diagnostic push 264 | #pragma GCC diagnostic ignored "-Wstrict-aliasing" 265 | #endif // __GNUC__ 266 | // ------------------------------------------------------------------- 267 | 268 | // WinResources 269 | 270 | // map res = 1; 271 | inline int WinResources::_internal_res_size() const { 272 | return res_.size(); 273 | } 274 | inline int WinResources::res_size() const { 275 | return _internal_res_size(); 276 | } 277 | inline void WinResources::clear_res() { 278 | res_.Clear(); 279 | } 280 | inline const ::PROTOBUF_NAMESPACE_ID::Map< std::string, std::string >& 281 | WinResources::_internal_res() const { 282 | return res_.GetMap(); 283 | } 284 | inline const ::PROTOBUF_NAMESPACE_ID::Map< std::string, std::string >& 285 | WinResources::res() const { 286 | // @@protoc_insertion_point(field_map:PlatformWindowsSeriallizer.WinResources.res) 287 | return _internal_res(); 288 | } 289 | inline ::PROTOBUF_NAMESPACE_ID::Map< std::string, std::string >* 290 | WinResources::_internal_mutable_res() { 291 | return res_.MutableMap(); 292 | } 293 | inline ::PROTOBUF_NAMESPACE_ID::Map< std::string, std::string >* 294 | WinResources::mutable_res() { 295 | // @@protoc_insertion_point(field_mutable_map:PlatformWindowsSeriallizer.WinResources.res) 296 | return _internal_mutable_res(); 297 | } 298 | 299 | #ifdef __GNUC__ 300 | #pragma GCC diagnostic pop 301 | #endif // __GNUC__ 302 | // ------------------------------------------------------------------- 303 | 304 | 305 | // @@protoc_insertion_point(namespace_scope) 306 | 307 | } // namespace PlatformWindowsSeriallizer 308 | 309 | // @@protoc_insertion_point(global_scope) 310 | 311 | #include 312 | #endif // GOOGLE_PROTOBUF_INCLUDED_GOOGLE_PROTOBUF_INCLUDED_PlatformWindowsSeriallizer_2eproto 313 | -------------------------------------------------------------------------------- /Platform/Windows/Common/TabWindow.cpp: -------------------------------------------------------------------------------- 1 | #include "TabWindow.h" 2 | #include "Platform/Windows/Common/Control/Button/TabButton.h" 3 | #include "Runtime/Debugger/Logger.h" 4 | namespace Editor { 5 | TabWindow::TabWindow() { 6 | mTabUIRoot = nullptr; 7 | } 8 | void TabWindow::DrawContent(Gdiplus::Graphics&painter) { 9 | mTabUIRoot->DrawRecursively(painter); 10 | Gdiplus::Pen p(Gdiplus::Color(30,30,30)); 11 | painter.DrawLine(&p, Gdiplus::Point(0,20), Gdiplus::Point(mRect.Width,20)); 12 | } 13 | void TabWindow::InitTab(const char * icon, const char * text) { 14 | TabButton *tab_button = new TabButton; 15 | tab_button->Init(WinResources::Singleton()->GetImageData("AliceTab.png"), WinResources::Singleton()->GetImageData(icon), text); 16 | tab_button->SetRect(GetUILocationL(96, 0) - 48, GetUILocationT(20, 0) - 10, 96, 20); 17 | mTabUIRoot = tab_button; 18 | } 19 | } -------------------------------------------------------------------------------- /Platform/Windows/Common/TabWindow.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "ViewWindow.h" 3 | namespace Editor { 4 | class TabWindow :public ViewWindow { 5 | UINode*mTabUIRoot; 6 | protected: 7 | virtual void DrawContent(Gdiplus::Graphics&painter); 8 | public: 9 | TabWindow(); 10 | void InitTab(const char * icon,const char * text); 11 | }; 12 | } -------------------------------------------------------------------------------- /Platform/Windows/Common/ViewWindow.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Base/DoubleBufferedWindow.h" 3 | #include "Control/UINode.h" 4 | #include "Base/WindowContainer.h" 5 | namespace Editor { 6 | class ViewWindow :public DoubleBufferedWindow { 7 | protected: 8 | bool mbDraging,mbFixedPos,mbFixedWidth,mbFixedHeight; 9 | Gdiplus::Rect mFixedRect; 10 | Gdiplus::Point mDeltaWhenDrag; 11 | UINode * mUIRoot, *mLastTouchObject, *mLastHoverObject; 12 | WindowContainer *mContainer; 13 | protected: 14 | virtual void OnLButtonDown(WPARAM wParam, LPARAM lParam, void*reserved = nullptr); 15 | virtual void OnLButtonUp(WPARAM wParam, LPARAM lParam, void*reserved = nullptr); 16 | virtual void OnMouseMove(WPARAM wParam, LPARAM lParam, void*reserved = nullptr); 17 | virtual void OnMouseLeave(WPARAM wParam, LPARAM lParam, void*reserved = nullptr); 18 | virtual void OnSize(WPARAM wParam, LPARAM lParam, void*reserved = nullptr); 19 | virtual void OnCommand(WPARAM wParam, LPARAM lParam, void*reserved = nullptr); 20 | virtual void DrawContent(Gdiplus::Graphics&painter); 21 | virtual void OnClearBKG(Gdiplus::Graphics&painter); 22 | virtual void OnPaint(const Gdiplus::Rect &rect_need_update) {} 23 | virtual void OnParentPaint(Gdiplus::Graphics&painter); 24 | virtual LRESULT OnSizing(WPARAM wParam, LPARAM lParam, void*reserved = nullptr); 25 | void ExtentWindowFromLeft(int &deltaX); 26 | void ReduceWindowFromLeft(int &deltaX); 27 | void ExtentWindowFromRight(int &deltaX); 28 | void ReduceWindowFromRight(int &deltaX); 29 | void ExtentWindowFromTop(int &deltaY); 30 | void ReduceWindowFromTop(int &deltaY); 31 | void ExtentWindowFromBottom(int &deltaY); 32 | void ReduceWindowFromBottom(int &deltaY); 33 | public: 34 | ViewWindow(); 35 | virtual void OnParentResized(int width, int height); 36 | 37 | virtual void MarkDirty(); 38 | void AddWindowAtLeft(BaseWindow*window); 39 | void AddWindowAtRight(BaseWindow*window); 40 | void AddWindowAtTop(BaseWindow*window); 41 | void AddWindowAtBottom(BaseWindow*window); 42 | void Init(BaseWindow*parent); 43 | void AppendUI(UINode*node); 44 | void FixedWindow(int x, int y,int width,int height); 45 | static void InitWindowClasses(); 46 | }; 47 | } -------------------------------------------------------------------------------- /Platform/Windows/Common/WinEnviroment.cpp: -------------------------------------------------------------------------------- 1 | #include "WinEnviroment.h" 2 | namespace Editor { 3 | HINSTANCE WinEnviroment::mInstance = nullptr; 4 | void WinEnviroment::Init(HINSTANCE instance) { 5 | static Gdiplus::GdiplusStartupInput sGdiplusStartupInput; 6 | static ULONG_PTR sGdiplusToken; 7 | mInstance = instance; 8 | GdiplusStartup(&sGdiplusToken, &sGdiplusStartupInput, NULL); 9 | CoInitialize(NULL); 10 | } 11 | HINSTANCE WinEnviroment::Instance() { 12 | return mInstance; 13 | } 14 | HACCEL WinEnviroment::InitAccel() { 15 | ACCEL accel[] = { 16 | { FCONTROL | FVIRTKEY, 'C', kAccelKeyCombinationCTRL_C }, 17 | { FCONTROL | FVIRTKEY, 'V', kAccelKeyCombinationCTRL_V } 18 | }; 19 | int accel_key_count = sizeof(accel); 20 | return CreateAcceleratorTable(accel, accel_key_count); 21 | } 22 | } -------------------------------------------------------------------------------- /Platform/Windows/Common/WinEnviroment.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Runtime/BattleFirePrefix.h" 3 | namespace Editor{ 4 | enum kAccelKeyCombination { 5 | kAccelKeyCombinationUnkown, 6 | kAccelKeyCombinationCTRL_C, 7 | kAccelKeyCombinationCTRL_V, 8 | kAccelKeyCombinationCount 9 | }; 10 | class WinEnviroment { 11 | protected: 12 | static HINSTANCE mInstance; 13 | public: 14 | static void Init(HINSTANCE instance); 15 | static HINSTANCE Instance(); 16 | static HACCEL InitAccel(); 17 | }; 18 | } -------------------------------------------------------------------------------- /Platform/Windows/Common/WinResources.cpp: -------------------------------------------------------------------------------- 1 | #include "WinResources.h" 2 | #include "Runtime/Allocator/AliceMemory.h" 3 | #include "Runtime/IO/ResourceManager.h" 4 | namespace Editor { 5 | WinResources*WinResources::mSelf = nullptr; 6 | WinResources*WinResources::Singleton() { 7 | if (mSelf == nullptr) { 8 | mSelf = new WinResources; 9 | } 10 | return mSelf; 11 | } 12 | void WinResources::Init(const char * path) { 13 | Alice::Data data; 14 | if (Alice::ResourceManager::LoadData(path,data)){ 15 | mWinRes = new PlatformWindowsSeriallizer::WinResources; 16 | mWinRes->ParseFromArray(data.mData, data.mDataLen); 17 | } 18 | } 19 | StreamImageData*WinResources::GetImageData(const char * path) { 20 | if (mCachedImages.find(path)!=mCachedImages.end()){ 21 | return mCachedImages[path]; 22 | } 23 | if (mWinRes->res().contains(path)) { 24 | const std::string & original_binary_data = mWinRes->res().at(path); 25 | StreamImageData *sid = InitStreamImageDataFromRawBuffer((unsigned char*)original_binary_data.c_str(), original_binary_data.length()); 26 | sid->mbShared = true; 27 | mCachedImages.insert(std::pair(path,sid)); 28 | return sid; 29 | } 30 | return nullptr; 31 | } 32 | StreamImageData*WinResources::InitStreamImageDataFromRawBuffer(const unsigned char * data, int len) { 33 | HGLOBAL hMem = GlobalAlloc(GMEM_FIXED, len); 34 | BYTE* pMem = (BYTE*)GlobalLock(hMem); 35 | memcpy(pMem, data, len); 36 | IStream *stream = nullptr; 37 | HRESULT hr = CreateStreamOnHGlobal(pMem, TRUE, &stream); 38 | Gdiplus::Image*image = Gdiplus::Image::FromStream(stream); 39 | GlobalUnlock(hMem); 40 | return new(kMemEditorId)StreamImageData(stream, image); 41 | } 42 | } -------------------------------------------------------------------------------- /Platform/Windows/Common/WinResources.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Runtime/BattleFirePrefix.h" 3 | #include "PlatformWindowsSeriallizer.pb.h" 4 | #include "google/protobuf/text_format.h" 5 | namespace Editor{ 6 | struct StreamImageData{ 7 | StreamImageData(IStream*stream, Gdiplus::Image*image) :mStream(stream), mImage(image),mbShared(false){ 8 | } 9 | ~StreamImageData(){ 10 | if (mbShared) { 11 | if (mImage != nullptr) { 12 | delete mImage; 13 | } 14 | if (mStream != nullptr) { 15 | mStream->Release(); 16 | } 17 | } 18 | } 19 | IStream *mStream; 20 | Gdiplus::Image*mImage; 21 | bool mbShared; 22 | }; 23 | class WinResources { 24 | protected: 25 | static WinResources*mSelf; 26 | PlatformWindowsSeriallizer::WinResources *mWinRes; 27 | std::unordered_map mCachedImages; 28 | public: 29 | static WinResources*Singleton(); 30 | void Init(const char * path); 31 | StreamImageData*GetImageData(const char * path); 32 | StreamImageData*InitStreamImageDataFromRawBuffer(const unsigned char * data, int len); 33 | }; 34 | } -------------------------------------------------------------------------------- /Platform/Windows/Editor/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(PROJECT_NAME "BattleFireEditor") 2 | GroupDirectories("" "" ${PROJECT_SOURCE_DIR}/Runtime common_runtime_sources) 3 | GroupDirectories("" "" ${PROJECT_SOURCE_DIR}/Platform/Windows/Editor win_editor_sources) 4 | GroupDirectories("" "" ${PROJECT_SOURCE_DIR}/Platform/Windows/Common win_common_sources) 5 | 6 | set(WinEditorSources ${common_runtime_sources} ${win_editor_sources} ${win_common_sources}) 7 | 8 | add_compile_definitions(ALICE_WIN_PLAYER _DEBUG UNICODE _UNICODE _SCL_SECURE_NO_WARNINGS _CRT_SECURE_NO_WARNINGS) 9 | 10 | set(CMAKE_CXX_FLAGS_RELEASE "/MT /O2 /Ob2 /DNDEBUG") 11 | set(CMAKE_CXX_FLAGS_DEBUG "/MTd /Zi /Ob0 /Od /RTC1") 12 | set(CMAKE_CXX_FLAGS "/DWIN32 /D_WINDOWS /W3 /GR /EHsc") 13 | set(CMAKE_C_FLAGS_RELEASE "/MT /O2 /Ob2 /DNDEBUG") 14 | set(CMAKE_C_FLAGS_DEBUG "/MTd /Zi /Ob0 /Od /RTC1") 15 | set(CMAKE_C_FLAGS "/DWIN32 /D_WINDOWS /W3") 16 | set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SUBSYSTEM:WINDOWS") 17 | 18 | link_directories(${PROJECT_SOURCE_DIR}/External/PrebuiltLibs/x86) 19 | add_executable(${PROJECT_NAME} ${WinEditorSources}) 20 | target_link_libraries(${PROJECT_NAME} gdiplus libprotobuf Imm32) 21 | set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME "Editor") 22 | set_target_properties(${PROJECT_NAME} PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}/Editor") -------------------------------------------------------------------------------- /Platform/Windows/Editor/EditorMainWindow.cpp: -------------------------------------------------------------------------------- 1 | #include "EditorMainWindow.h" 2 | #include "Platform/Windows/Common/WinEnviroment.h" 3 | #include "Platform/Windows/Common/ViewWindow.h" 4 | #include "Platform/Windows/Common/Control/Button/TwoStateButton.h" 5 | #include "Platform/Windows/Editor/Menu/MenuItemDefine.h" 6 | #include 7 | #include "Runtime/Debugger/Logger.h" 8 | #include "Runtime/String/StringUtils.h" 9 | #include "Runtime/IO/FileSystem.h" 10 | #include "TopMenuWindow/TopMenuWindow.h" 11 | #include "TopToolsWindow/TopToolsWindow.h" 12 | #include "HierarchyWindow/HierarchyWindow.h" 13 | #include "ProjectWindow/ProjectWindow.h" 14 | #include "SceneWindow/SceneWindow.h" 15 | #include "InspectorWindow/InspectorWindow.h" 16 | #pragma comment(lib,"dwmapi.lib") 17 | namespace Editor { 18 | void EditorMainWindow::OnMouseWheel(WPARAM wParam, LPARAM lParam, void*reserved /* = nullptr */) { 19 | } 20 | void EditorMainWindow::OnSize(WPARAM wParam, LPARAM lParam, void*reserved) { 21 | MainWindow::OnSize(wParam, lParam, reserved); 22 | if (mCloseBtn != nullptr) mCloseBtn->SetRect(mRect.Width - 32, 2, 24, 24); 23 | } 24 | void EditorMainWindow::OnLButtonDown(WPARAM wParam, LPARAM lParam, void*reserved /* = nullptr */){ 25 | int x = LOWORD(lParam); 26 | int y = HIWORD(lParam); 27 | if (yIntersect(x, y); 29 | if (node != nullptr && node == mCloseBtn) { 30 | node->OnTouchBegin(x,y); 31 | mLastTouchObject = node; 32 | //Debug("EditorMainWindow::OnLButtonDown OnTouchBegin InvalidateRect"); 33 | InvalidateRect(mhWnd, nullptr, false); 34 | SetCapture(mhWnd); 35 | } 36 | else { 37 | MainWindow::OnLButtonDown(wParam, lParam, reserved); 38 | } 39 | } 40 | } 41 | void EditorMainWindow::OnLButtonUp(WPARAM wParam, LPARAM lParam, void*reserved /* = nullptr */) { 42 | int x = LOWORD(lParam); 43 | int y = HIWORD(lParam); 44 | UINode*node = mUIRoot->Intersect(x, y); 45 | if (node != nullptr&&node==mLastTouchObject) { 46 | node->OnTouchEnd(x, y); 47 | //Debug("EditorMainWindow::OnLButtonUp OnTouchEnd InvalidateRect"); 48 | InvalidateRect(mhWnd, nullptr, false); 49 | ReleaseCapture(); 50 | } 51 | else { 52 | if (mLastTouchObject != nullptr) { 53 | mLastTouchObject->OnTouchCanceled(x, y); 54 | mLastTouchObject = nullptr; 55 | //Debug("EditorMainWindow::OnLButtonUp OnTouchCanceled InvalidateRect"); 56 | InvalidateRect(mhWnd, nullptr, false); 57 | ReleaseCapture(); 58 | } 59 | else { 60 | MainWindow::OnLButtonUp(wParam, lParam, reserved); 61 | } 62 | } 63 | } 64 | void EditorMainWindow::OnMouseMove(WPARAM wParam, LPARAM lParam, void*reserved /* = nullptr */) { 65 | int x = LOWORD(lParam); 66 | int y = HIWORD(lParam); 67 | UINode*node = mUIRoot->Intersect(x, y); 68 | if (node!=nullptr){ 69 | if (mLastHoverObject !=node){ 70 | if (mLastHoverObject != nullptr) { 71 | mLastHoverObject->OnTouchLeave(x, y); 72 | } 73 | mLastHoverObject = node; 74 | mLastHoverObject->OnTouchEnter(x, y); 75 | //Debug("EditorMainWindow::OnMouseMove mLastHoverObject->OnTouchEnter"); 76 | RECT rect = { 77 | 0, 78 | 0, 79 | mRect.Width, 80 | mTopNCSize 81 | }; 82 | //InvalidateRect(mhWnd, &rect, false); 83 | InvalidateRect(mhWnd, nullptr, false); 84 | } 85 | } 86 | else { 87 | if (mLastHoverObject!=nullptr){ 88 | mLastHoverObject->OnTouchLeave(x, y); 89 | mLastHoverObject = nullptr; 90 | //Debug("EditorMainWindow::OnMouseMove mLastHoverObject->OnTouchLeave"); 91 | InvalidateRect(mhWnd, nullptr, false); 92 | } 93 | } 94 | MainWindow::OnMouseMove(wParam, lParam, reserved); 95 | } 96 | void EditorMainWindow::OnMouseLeave(WPARAM wParam, LPARAM lParam, void*reserved /* = nullptr */) { 97 | if (mLastHoverObject != nullptr) { 98 | int x = LOWORD(lParam); 99 | int y = HIWORD(lParam); 100 | mLastHoverObject->OnTouchLeave(x, y); 101 | mLastHoverObject = nullptr; 102 | //Debug("EditorMainWindow::OnMouseLeave OnMouseLeave InvalidateRect 2"); 103 | InvalidateRect(mhWnd, nullptr, false); 104 | } 105 | MainWindow::OnMouseLeave(wParam, lParam, reserved); 106 | } 107 | void EditorMainWindow::OnKeyDown(WPARAM wParam, LPARAM lParam, void*reserved /* = nullptr */) { 108 | } 109 | void EditorMainWindow::OnKeyUp(WPARAM wParam, LPARAM lParam, void*reserved /* = nullptr */) { 110 | } 111 | void EditorMainWindow::OnChar(WPARAM wParam, LPARAM lParam, void*reserved){ 112 | } 113 | void EditorMainWindow::OnIMEChar(WPARAM wParam, LPARAM lParam, void*reserved){ 114 | WCHAR temp[2] = { 0 }; 115 | temp[0] = wParam; 116 | char szBuffer[8] = { 0 }; 117 | Alice::StringUtils::UnicodeToUTF8(temp, szBuffer); 118 | } 119 | void EditorMainWindow::OnCompositionIMEString(WPARAM wParam, LPARAM lParam, void*reserved /* = nullptr */) { 120 | HIMC himc = ImmGetContext(mhWnd); 121 | if (himc) { 122 | ImmReleaseContext(mhWnd, himc); 123 | } 124 | } 125 | void EditorMainWindow::OnCommand(WPARAM wParam, LPARAM lParam, void*reserved /* = nullptr */) { 126 | UINT nNotify = HIWORD(wParam); 127 | UINT commandID = LOWORD(wParam); 128 | switch (commandID){ 129 | case kAccelKeyCombinationCTRL_C: 130 | break; 131 | case kAccelKeyCombinationCTRL_V: 132 | break; 133 | default: 134 | Debug("unprocessed command %d",commandID); 135 | break; 136 | } 137 | } 138 | void EditorMainWindow::Init() { 139 | SetWindowName("EditorMainWindow"); 140 | DWORD windowStyle = WS_OVERLAPPED;// | WS_CLIPCHILDREN; 141 | mhWnd = CreateWindowEx(NULL, L"MainWindow", L"BattleFire Editor", windowStyle, 0, 0, 32, 32, NULL, NULL, WinEnviroment::Instance(), NULL); 142 | SetWindowLongPtr(mhWnd, GWL_USERDATA, (LONG_PTR)this); 143 | mHDC = GetWindowDC(mhWnd); 144 | SetRect(0, 0, 32, 32); 145 | mBKGColor = Gdiplus::Color(30, 30, 30); 146 | mTitle = new Editor::StaticText; 147 | mTitle->SetAligning(Editor::AligningModeLeft); 148 | mTitle->SetRect(12, 3, 1286-mLeftNCSize-mRightNCSize, mTopNCSize); 149 | mTitle->SetText("Engine - None"); 150 | mTitle->SetTextColor(0, 150, 200); 151 | mUIRoot = mTitle; 152 | mCloseBtn = new Editor::ImageButton; 153 | mCloseBtn->SetImageData(WinResources::Singleton()->GetImageData("close_btn.png")); 154 | mCloseBtn->SetRect(1248, 2, 24, 24); 155 | mCloseBtn->SetOnClickedHandler([](void*)->void { 156 | Debug("quit"); 157 | PostQuitMessage(0); 158 | }); 159 | mUIRoot->AppendChild(mCloseBtn); 160 | mAccel = WinEnviroment::InitAccel(); 161 | mLastHoverObject = nullptr; 162 | TopMenuWindow::Singleton()->Init(this); 163 | TopToolsWindow::Singleton()->Init(this); 164 | HierarchyWindow::Singleton()->Init(this); 165 | ProjectWindow::Singleton()->Init(this); 166 | SceneWindow::Singleton()->Init(this); 167 | InspectorWindow::Singleton()->Init(this); 168 | InitSubWindows(); 169 | } 170 | void EditorMainWindow::InitSubWindows() { 171 | ViewWindow*top_menu_window = TopMenuWindow::Singleton()->GetViewWindow(); 172 | ViewWindow*tools_window = TopToolsWindow::Singleton()->GetViewWindow(); 173 | ViewWindow*hierarchy_window = HierarchyWindow::Singleton()->GetViewWindow(); 174 | ViewWindow*project_window = ProjectWindow::Singleton()->GetViewWindow(); 175 | ViewWindow*scene_window = SceneWindow::Singleton()->GetViewWindow(); 176 | ViewWindow*inspector_window = InspectorWindow::Singleton()->GetViewWindow(); 177 | 178 | //view window relationship 179 | top_menu_window->AddWindowAtBottom(tools_window); 180 | tools_window->AddWindowAtTop(top_menu_window); 181 | 182 | hierarchy_window->AddWindowAtRight(scene_window); 183 | scene_window->AddWindowAtLeft(hierarchy_window); 184 | /* 185 | _________________________________________________________________ 186 | | | 187 | | Top Container | 188 | |________________________________________________________________| 189 | | | | 190 | | | | 191 | | | | 192 | | | | 193 | | Left | Right | 194 | | | | 195 | | | | 196 | | | | 197 | | | | 198 | | | | 199 | |_______________________________________________|________________| 200 | */ 201 | //level 0 202 | WindowContainer*main_container = new WindowContainer("MainContainer"); 203 | //level 1 204 | WindowContainer*top_container = new WindowContainer("TopContainer"); 205 | WindowContainer*bottom_container = new WindowContainer("BottomContainer"); 206 | //level 2 207 | WindowContainer*left_container = new WindowContainer("BottomLeftContainer"); 208 | WindowContainer*right_container = new WindowContainer("BottomRightContainer"); 209 | //level 3 210 | WindowContainer*left_container_top = new WindowContainer("BottomLeftTopContainer"); 211 | WindowContainer*left_container_bottom = new WindowContainer("BottomLeftBottomContainer"); 212 | 213 | //level 0 -> level 1 214 | main_container->AddTopEdgeChildContainer(top_container); 215 | main_container->AddLeftEdgeChildContainer(top_container); 216 | main_container->AddLeftEdgeChildContainer(bottom_container); 217 | main_container->AddRightEdgeChildContainer(top_container); 218 | main_container->AddRightEdgeChildContainer(bottom_container); 219 | main_container->AddBottomEdgeChildContainer(bottom_container); 220 | 221 | top_container->AddSiblingContainerAtBottom(bottom_container); 222 | bottom_container->AddSiblingContainerAtTop(top_container); 223 | 224 | //level 1 -> level 2 225 | bottom_container->AddTopEdgeChildContainer(left_container); 226 | bottom_container->AddTopEdgeChildContainer(right_container); 227 | bottom_container->AddLeftEdgeChildContainer(left_container); 228 | bottom_container->AddRightEdgeChildContainer(right_container); 229 | bottom_container->AddBottomEdgeChildContainer(left_container); 230 | bottom_container->AddBottomEdgeChildContainer(right_container); 231 | left_container->AddSiblingContainerAtRight(right_container); 232 | right_container->AddSiblingContainerAtLeft(left_container); 233 | //level 1 top_container content 234 | top_container->AddChildWindowAt(kChildWindowLocationTopEdge, top_menu_window); 235 | top_container->AddChildWindowAt(kChildWindowLocationBottomEdge, tools_window); 236 | top_container->AddChildWindowAt(kChildWindowLocationLeftEdge, top_menu_window); 237 | top_container->AddChildWindowAt(kChildWindowLocationLeftEdge, tools_window); 238 | top_container->AddChildWindowAt(kChildWindowLocationRightEdge, top_menu_window); 239 | top_container->AddChildWindowAt(kChildWindowLocationRightEdge, tools_window); 240 | top_container->SetMaxRect(0, 0, -1, 70); 241 | top_container->Complete(); 242 | //level 2 right_container content 243 | right_container->AddChildWindowAt(kChildWindowLocationLeftEdge, inspector_window); 244 | right_container->AddChildWindowAt(kChildWindowLocationRightEdge, inspector_window); 245 | right_container->AddChildWindowAt(kChildWindowLocationBottomEdge, inspector_window); 246 | right_container->AddChildWindowAt(kChildWindowLocationTopEdge, inspector_window); 247 | right_container->Complete(); 248 | //level 2 -> level 3 249 | left_container->AddTopEdgeChildContainer(left_container_top); 250 | left_container->AddLeftEdgeChildContainer(left_container_top); 251 | left_container->AddLeftEdgeChildContainer(left_container_bottom); 252 | left_container->AddRightEdgeChildContainer(left_container_top); 253 | left_container->AddRightEdgeChildContainer(left_container_bottom); 254 | left_container->AddBottomEdgeChildContainer(left_container_bottom); 255 | left_container_top->AddSiblingContainerAtBottom(left_container_bottom); 256 | left_container_bottom->AddSiblingContainerAtTop(left_container_top); 257 | //level 3 left_container_bottom content 258 | left_container_bottom->AddChildWindowAt(kChildWindowLocationLeftEdge, project_window); 259 | left_container_bottom->AddChildWindowAt(kChildWindowLocationRightEdge, project_window); 260 | left_container_bottom->AddChildWindowAt(kChildWindowLocationBottomEdge, project_window); 261 | left_container_bottom->AddChildWindowAt(kChildWindowLocationTopEdge, project_window); 262 | left_container_bottom->Complete(); 263 | //level 3 left_container_top content 264 | left_container_top->AddChildWindowAt(kChildWindowLocationLeftEdge, hierarchy_window); 265 | left_container_top->AddChildWindowAt(kChildWindowLocationRightEdge, scene_window); 266 | left_container_top->AddChildWindowAt(kChildWindowLocationTopEdge, hierarchy_window); 267 | left_container_top->AddChildWindowAt(kChildWindowLocationTopEdge, scene_window); 268 | left_container_top->AddChildWindowAt(kChildWindowLocationBottomEdge, hierarchy_window); 269 | left_container_top->AddChildWindowAt(kChildWindowLocationBottomEdge, scene_window); 270 | left_container_top->Complete(); 271 | left_container->Complete(); 272 | bottom_container->Complete(); 273 | main_container->Complete(); 274 | SetContainer(main_container); 275 | } 276 | } -------------------------------------------------------------------------------- /Platform/Windows/Editor/EditorMainWindow.h: -------------------------------------------------------------------------------- 1 | #include "Platform/Windows/Common/MainWindow.h" 2 | #include "Platform/Windows/Common/Control/Button/ImageButton.h" 3 | #include "Platform/Windows/Common/Control/Image/SimpleImage.h" 4 | #include "Platform/Windows/Common/Control/Text/StaticText.h" 5 | #include "Menu/PopupMenuButton.h" 6 | 7 | namespace Editor { 8 | class EditorMainWindow :public MainWindow { 9 | protected: 10 | StaticText*mTitle; 11 | ImageButton*mCloseBtn; 12 | UINode*mLastHoverObject; 13 | protected: 14 | void OnLButtonDown(WPARAM wParam, LPARAM lParam, void*reserved = nullptr); 15 | void OnLButtonUp(WPARAM wParam, LPARAM lParam, void*reserved = nullptr); 16 | void OnMouseMove(WPARAM wParam, LPARAM lParam, void*reserved = nullptr); 17 | void OnMouseLeave(WPARAM wParam, LPARAM lParam, void*reserved = nullptr); 18 | void OnKeyDown(WPARAM wParam, LPARAM lParam, void*reserved = nullptr); 19 | void OnKeyUp(WPARAM wParam, LPARAM lParam, void*reserved = nullptr); 20 | void OnChar(WPARAM wParam, LPARAM lParam, void*reserved = nullptr); 21 | void OnIMEChar(WPARAM wParam, LPARAM lParam, void*reserved = nullptr); 22 | void OnCompositionIMEString(WPARAM wParam, LPARAM lParam, void*reserved = nullptr); 23 | void OnMouseWheel(WPARAM wParam, LPARAM lParam, void*reserved = nullptr); 24 | void OnSize(WPARAM wParam, LPARAM lParam, void*reserved = nullptr); 25 | void OnCommand(WPARAM wParam, LPARAM lParam, void*reserved = nullptr); 26 | void InitSubWindows(); 27 | public: 28 | HACCEL mAccel; 29 | void Init(); 30 | }; 31 | } -------------------------------------------------------------------------------- /Platform/Windows/Editor/HierarchyWindow/HierarchyWindow.cpp: -------------------------------------------------------------------------------- 1 | #include "HierarchyWindow.h" 2 | #include "Platform/Windows/Common/WinEnviroment.h" 3 | #include "Platform/Windows/Common/TabWindow.h" 4 | #include "Platform/Windows/Common/Control/Button/TabButton.h" 5 | #include "Platform/Windows/Editor/Menu/MenuItemDefine.h" 6 | #include "Runtime/Debugger/Logger.h" 7 | #include "Runtime/String/StringUtils.h" 8 | #include "Runtime/IO/FileSystem.h" 9 | namespace Editor { 10 | HierarchyWindow*HierarchyWindow::mSingleton = nullptr; 11 | void HierarchyWindow::Init(BaseWindow*parent) { 12 | TabWindow*view_window = new TabWindow; 13 | view_window->SetWindowName("HierarchyWindow"); 14 | view_window->SetNCSize(0, 3, 0, 0); 15 | view_window->SetMinRect(0, 0, 200, 200); 16 | view_window->Init(parent); 17 | //view_window->SetBkgColor(Gdiplus::Color(200, 255, 200)); 18 | view_window->MoveWindow(0, 70, 300, 400); 19 | view_window->Show(); 20 | view_window->InitTab("HierarchyWindowIcon.png", "Hierarchy"); 21 | mViewWindow = view_window; 22 | } 23 | ViewWindow*HierarchyWindow::GetViewWindow() { 24 | return mViewWindow; 25 | } 26 | HierarchyWindow*HierarchyWindow::Singleton() { 27 | if (mSingleton == nullptr) { 28 | mSingleton = new HierarchyWindow; 29 | } 30 | return mSingleton; 31 | } 32 | } -------------------------------------------------------------------------------- /Platform/Windows/Editor/HierarchyWindow/HierarchyWindow.h: -------------------------------------------------------------------------------- 1 | #include "Platform/Windows/Common/ViewWindow.h" 2 | namespace Editor { 3 | class HierarchyWindow { 4 | protected: 5 | static HierarchyWindow * mSingleton; 6 | protected: 7 | ViewWindow * mViewWindow; 8 | public: 9 | void Init(BaseWindow*parent); 10 | ViewWindow*GetViewWindow(); 11 | static HierarchyWindow * Singleton(); 12 | }; 13 | } -------------------------------------------------------------------------------- /Platform/Windows/Editor/InspectorWindow/InspectorWindow.cpp: -------------------------------------------------------------------------------- 1 | #include "InspectorWindow.h" 2 | #include "Platform/Windows/Common/WinEnviroment.h" 3 | #include "Platform/Windows/Common/TabWindow.h" 4 | #include "Platform/Windows/Editor/Menu/MenuItemDefine.h" 5 | #include "Runtime/Debugger/Logger.h" 6 | #include "Runtime/String/StringUtils.h" 7 | #include "Runtime/IO/FileSystem.h" 8 | namespace Editor { 9 | InspectorWindow*InspectorWindow::mSingleton = nullptr; 10 | void InspectorWindow::Init(BaseWindow*parent) { 11 | TabWindow*view_window = new TabWindow; 12 | view_window->SetWindowName("InspectorWindow"); 13 | view_window->SetNCSize(3, 0, 0, 0); 14 | view_window->SetMinRect(0, 0, 200, 200); 15 | view_window->Init(parent); 16 | //view_window->SetBkgColor(Gdiplus::Color(0, 255, 255)); 17 | view_window->MoveWindow(974, 70, 300, 650); 18 | view_window->Show(); 19 | view_window->InitTab("InspectorWindowIcon.png", "Inspector"); 20 | mViewWindow = view_window; 21 | } 22 | ViewWindow*InspectorWindow::GetViewWindow() { 23 | return mViewWindow; 24 | } 25 | InspectorWindow*InspectorWindow::Singleton() { 26 | if (mSingleton == nullptr) { 27 | mSingleton = new InspectorWindow; 28 | } 29 | return mSingleton; 30 | } 31 | } -------------------------------------------------------------------------------- /Platform/Windows/Editor/InspectorWindow/InspectorWindow.h: -------------------------------------------------------------------------------- 1 | #include "Platform/Windows/Common/ViewWindow.h" 2 | namespace Editor { 3 | class InspectorWindow { 4 | protected: 5 | static InspectorWindow * mSingleton; 6 | protected: 7 | ViewWindow * mViewWindow; 8 | public: 9 | void Init(BaseWindow*parent); 10 | ViewWindow*GetViewWindow(); 11 | static InspectorWindow * Singleton(); 12 | }; 13 | } -------------------------------------------------------------------------------- /Platform/Windows/Editor/Menu/MenuItemDefine.h: -------------------------------------------------------------------------------- 1 | 2 | #define DEF_MENU_OPTION(n,id) static int Menu_Option_##n=id; 3 | DEF_MENU_OPTION(Window_Animation, 1) 4 | DEF_MENU_OPTION(Window_Animator,2) 5 | DEF_MENU_OPTION(Window_Atlas, 3) 6 | DEF_MENU_OPTION(Window_Profiler, 4) 7 | DEF_MENU_OPTION(Window_Physics, 5) 8 | 9 | DEF_MENU_OPTION(File_NewProject, 100) 10 | DEF_MENU_OPTION(File_OpenProject, 101) 11 | DEF_MENU_OPTION(File_Build, 102) 12 | DEF_MENU_OPTION(File_Exit, 103) 13 | DEF_MENU_OPTION(File_SaveCurrentScene, 104) 14 | DEF_MENU_OPTION(File_NewScene, 105) 15 | DEF_MENU_OPTION(Edit_Duplicate, 200) 16 | DEF_MENU_OPTION(Edit_Undo, 201) 17 | 18 | DEF_MENU_OPTION(Component_ImageSprite, 300) 19 | DEF_MENU_OPTION(Component_Camera, 301) 20 | DEF_MENU_OPTION(Component_Label, 302) 21 | DEF_MENU_OPTION(Component_Animator, 303) 22 | DEF_MENU_OPTION(Component_ImageSprite9, 304) 23 | DEF_MENU_OPTION(Component_Button, 305) 24 | DEF_MENU_OPTION(Component_Particle, 306) 25 | DEF_MENU_OPTION(Component_AudioSource, 307) 26 | DEF_MENU_OPTION(Component_AudioListener, 308) 27 | DEF_MENU_OPTION(Component_Physic2DComponent, 309) 28 | -------------------------------------------------------------------------------- /Platform/Windows/Editor/Menu/PopupMenuButton.cpp: -------------------------------------------------------------------------------- 1 | #include "PopupMenuButton.h" 2 | #include "Runtime/Debugger/Logger.h" 3 | namespace Editor{ 4 | PopupMenuButton::PopupMenuButton(HWND hWnd){ 5 | mParentWnd = hWnd; 6 | SetTextColor(0, 0, 0); 7 | SetBkgColor(200, 200, 200); 8 | mMenu = nullptr; 9 | } 10 | HMENU PopupMenuButton::GetMenuHandle() { 11 | if (mMenu==nullptr){ 12 | mMenu = CreatePopupMenu(); 13 | } 14 | return mMenu; 15 | } 16 | void PopupMenuButton::AppendMenuOption(int commandID, LPCWSTR menu_name, VOID_NO_ARG foo) { 17 | AppendMenu(GetMenuHandle(), MF_STRING, commandID, menu_name); 18 | AddEventProcesser(commandID, foo); 19 | } 20 | void PopupMenuButton::AddEventProcesser(int nCommandID, VOID_NO_ARG foo){ 21 | auto iter = mMenuEventProcessers.find(nCommandID); 22 | if (iter == mMenuEventProcessers.end()){ 23 | mMenuEventProcessers.insert(std::pair(nCommandID, foo)); 24 | } 25 | } 26 | void PopupMenuButton::ProcessEvent(int nCommandID){ 27 | auto iter = mMenuEventProcessers.find(nCommandID); 28 | if (iter != mMenuEventProcessers.end()){ 29 | iter->second(); 30 | return; 31 | } 32 | if (mRightSibling != nullptr){ 33 | RightSibling()->ProcessEvent(nCommandID); 34 | } 35 | } 36 | void PopupMenuButton::OnTouchBegin(int x, int y, int touch_id/* =0 */) { 37 | 38 | } 39 | void PopupMenuButton::OnTouchEnd(int x, int y, int touch_id /* = 0 */) { 40 | OnClicked(x, y, touch_id); 41 | } 42 | void PopupMenuButton::OnTouchCanceled(int x, int y, int touch_id /* = 0 */) { 43 | 44 | } 45 | void PopupMenuButton::OnTouchMove(int x, int y, int touch_id /* = 0 */) { 46 | 47 | } 48 | void PopupMenuButton::OnClicked(int x, int y, int touch_id /* = 0 */) { 49 | POINT point; 50 | point.x = mRect.X; 51 | point.y = mRect.Y+mRect.Height; 52 | ClientToScreen(mParentWnd, &point); 53 | TrackPopupMenu(mMenu, TPM_LEFTALIGN, point.x, point.y, 0, mParentWnd, NULL); 54 | } 55 | void PopupMenuButton::OnTouchEnter(int x, int y, int touch_id /* = 0 */) { 56 | ShowBkgColor(true); 57 | } 58 | void PopupMenuButton::OnTouchLeave(int x, int y, int touch_id /* = 0 */) { 59 | ShowBkgColor(false); 60 | } 61 | } -------------------------------------------------------------------------------- /Platform/Windows/Editor/Menu/PopupMenuButton.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Platform/Windows/Common/Control/Text/StaticText.h" 3 | namespace Editor{ 4 | class PopupMenuButton :public StaticText{ 5 | protected: 6 | HMENU mMenu; 7 | HWND mParentWnd; 8 | Gdiplus::Point mOriginalPos; 9 | std::unordered_map mMenuEventProcessers; 10 | public: 11 | PopupMenuButton(HWND hWnd); 12 | void AddEventProcesser(int nCommandID, VOID_NO_ARG foo); 13 | void ProcessEvent(int nCommandID); 14 | HMENU GetMenuHandle(); 15 | void AppendMenuOption(int commandID, LPCWSTR menu_name, VOID_NO_ARG foo); 16 | virtual void OnTouchBegin(int x, int y, int touch_id = 0); 17 | virtual void OnTouchEnd(int x, int y, int touch_id = 0); 18 | virtual void OnTouchMove(int x, int y, int touch_id = 0); 19 | virtual void OnTouchCanceled(int x, int y, int touch_id = 0); 20 | virtual void OnClicked(int x, int y, int touch_id = 0); 21 | virtual void OnTouchEnter(int x, int y, int touch_id = 0); 22 | virtual void OnTouchLeave(int x, int y, int touch_id = 0); 23 | }; 24 | } -------------------------------------------------------------------------------- /Platform/Windows/Editor/ProjectWindow/ProjectWindow.cpp: -------------------------------------------------------------------------------- 1 | #include "ProjectWindow.h" 2 | #include "Platform/Windows/Common/WinEnviroment.h" 3 | #include "Platform/Windows/Common/TabWindow.h" 4 | #include "Platform/Windows/Editor/Menu/MenuItemDefine.h" 5 | #include "Runtime/Debugger/Logger.h" 6 | #include "Runtime/String/StringUtils.h" 7 | #include "Runtime/IO/FileSystem.h" 8 | namespace Editor { 9 | ProjectWindow*ProjectWindow::mSingleton = nullptr; 10 | void ProjectWindow::Init(BaseWindow*parent) { 11 | TabWindow*view_window = new TabWindow; 12 | view_window->SetWindowName("ProjectWindow"); 13 | view_window->SetNCSize(0, 3,0, 3); 14 | view_window->EnableCornerResizing(false); 15 | view_window->SetMinRect(0, 0, 200, 200); 16 | view_window->Init(parent); 17 | //view_window->SetBkgColor(Gdiplus::Color(255, 255, 200)); 18 | view_window->MoveWindow(0, 470, 974, 250); 19 | view_window->Show(); 20 | view_window->InitTab("ProjectWindowIcon.png", "Project"); 21 | mViewWindow = view_window; 22 | } 23 | ViewWindow*ProjectWindow::GetViewWindow() { 24 | return mViewWindow; 25 | } 26 | ProjectWindow*ProjectWindow::Singleton() { 27 | if (mSingleton == nullptr) { 28 | mSingleton = new ProjectWindow; 29 | } 30 | return mSingleton; 31 | } 32 | } -------------------------------------------------------------------------------- /Platform/Windows/Editor/ProjectWindow/ProjectWindow.h: -------------------------------------------------------------------------------- 1 | #include "Platform/Windows/Common/ViewWindow.h" 2 | namespace Editor { 3 | class ProjectWindow { 4 | protected: 5 | static ProjectWindow * mSingleton; 6 | protected: 7 | ViewWindow * mViewWindow; 8 | public: 9 | void Init(BaseWindow*parent); 10 | ViewWindow*GetViewWindow(); 11 | static ProjectWindow * Singleton(); 12 | }; 13 | } -------------------------------------------------------------------------------- /Platform/Windows/Editor/SceneWindow/SceneWindow.cpp: -------------------------------------------------------------------------------- 1 | #include "SceneWindow.h" 2 | #include "Platform/Windows/Common/WinEnviroment.h" 3 | #include "Platform/Windows/Common/TabWindow.h" 4 | #include "Platform/Windows/Editor/Menu/MenuItemDefine.h" 5 | #include "Runtime/Debugger/Logger.h" 6 | #include "Runtime/String/StringUtils.h" 7 | #include "Runtime/IO/FileSystem.h" 8 | namespace Editor { 9 | SceneWindow*SceneWindow::mSingleton = nullptr; 10 | void SceneWindow::Init(BaseWindow*parent) { 11 | TabWindow*view_window = new TabWindow; 12 | view_window->SetWindowName("SceneWindow"); 13 | view_window->SetMinRect(0, 0, 400, 320); 14 | view_window->SetNCSize(3, 3, 0, 0); 15 | view_window->Init(parent); 16 | //view_window->SetBkgColor(Gdiplus::Color(41, 77, 121)); 17 | view_window->MoveWindow(300, 70, 674, 400); 18 | view_window->Show(); 19 | view_window->InitTab("SceneViewIcon.png", "Scene"); 20 | mViewWindow = view_window; 21 | } 22 | ViewWindow*SceneWindow::GetViewWindow() { 23 | return mViewWindow; 24 | } 25 | SceneWindow*SceneWindow::Singleton() { 26 | if (mSingleton == nullptr) { 27 | mSingleton = new SceneWindow; 28 | } 29 | return mSingleton; 30 | } 31 | } -------------------------------------------------------------------------------- /Platform/Windows/Editor/SceneWindow/SceneWindow.h: -------------------------------------------------------------------------------- 1 | #include "Platform/Windows/Common/ViewWindow.h" 2 | namespace Editor { 3 | class SceneWindow { 4 | protected: 5 | static SceneWindow * mSingleton; 6 | protected: 7 | ViewWindow * mViewWindow; 8 | public: 9 | void Init(BaseWindow*parent); 10 | ViewWindow*GetViewWindow(); 11 | static SceneWindow * Singleton(); 12 | }; 13 | } -------------------------------------------------------------------------------- /Platform/Windows/Editor/TopMenuWindow/TopMenuWindow.cpp: -------------------------------------------------------------------------------- 1 | #include "TopMenuWindow.h" 2 | #include "Platform/Windows/Common/WinEnviroment.h" 3 | #include "Platform/Windows/Common/ViewWindow.h" 4 | #include "Platform/Windows/Common/Control/Button/TwoStateButton.h" 5 | #include "Platform/Windows/Editor/Menu/MenuItemDefine.h" 6 | #include "Runtime/Debugger/Logger.h" 7 | #include "Runtime/String/StringUtils.h" 8 | #include "Runtime/IO/FileSystem.h" 9 | #include "Platform/Windows/Editor/Menu/PopupMenuButton.h" 10 | namespace Editor { 11 | TopMenuWindow*TopMenuWindow::mSingleton = nullptr; 12 | void TopMenuWindow::OnSize(WPARAM wParam, LPARAM lParam, void*reserved /* = nullptr */) { 13 | 14 | } 15 | void TopMenuWindow::Init(BaseWindow*parent) { 16 | ViewWindow*view_window = new ViewWindow; 17 | view_window->SetWindowName("TopMenuWindow"); 18 | view_window->SetNCSize(0, 0, 0, 0); 19 | view_window->SetMinRect(0, 0, -1, 20); 20 | view_window->SetMaxRect(0, 0, -1, 20); 21 | view_window->Init(parent); 22 | view_window->SetBkgColor(Gdiplus::Color(255, 255, 255)); 23 | 24 | PopupMenuButton*popupmenu = new (kMemEditorId)PopupMenuButton(view_window->GetHwnd()); 25 | popupmenu->SetText("File"); 26 | popupmenu->SetAligning(AligningModeMiddle); 27 | popupmenu->SetRect(0, 0, 50, 20); 28 | popupmenu->SetBkgColorRect(0, 0, 50, 20); 29 | view_window->AppendUI(popupmenu); 30 | popupmenu->AppendMenuOption(Menu_Option_File_NewProject, TEXT("New Project"), []()->void { Debug("new project"); }); 31 | popupmenu->AppendMenuOption(Menu_Option_File_OpenProject, TEXT("Open Project"), []()->void { Debug("open project"); }); 32 | popupmenu->AppendMenuOption(Menu_Option_File_NewScene, TEXT("New Scene"), []()->void { Debug("new scene"); }); 33 | popupmenu->AppendMenuOption(Menu_Option_File_SaveCurrentScene, TEXT("Save Scene"), []()->void { Debug("save scene"); }); 34 | popupmenu->AppendMenuOption(Menu_Option_File_Build, TEXT("Build Run"), []()->void { Debug("build run"); }); 35 | popupmenu->AppendMenuOption(Menu_Option_File_Exit, TEXT("Exit"), []()->void { Debug("exit"); }); 36 | popupmenu = new (kMemEditorId)PopupMenuButton(view_window->GetHwnd()); 37 | popupmenu->SetText("Edit"); 38 | popupmenu->SetAligning(AligningModeMiddle); 39 | popupmenu->SetRect(50, 0, 50, 20); 40 | popupmenu->SetBkgColorRect(50, 0, 50, 20); 41 | view_window->AppendUI(popupmenu); 42 | popupmenu->AppendMenuOption(Menu_Option_Edit_Duplicate, TEXT("Duplicate"), []()->void { Debug("Duplicate"); }); 43 | popupmenu->AppendMenuOption(Menu_Option_Edit_Undo, TEXT("Undo"), []()->void { Debug("Undo"); }); 44 | popupmenu = new (kMemEditorId)PopupMenuButton(view_window->GetHwnd()); 45 | popupmenu->SetText("Component"); 46 | popupmenu->SetAligning(AligningModeMiddle); 47 | popupmenu->SetRect(100, 0, 80, 20); 48 | popupmenu->SetBkgColorRect(100, 0, 80, 20); 49 | view_window->AppendUI(popupmenu); 50 | 51 | popupmenu->AppendMenuOption(Menu_Option_Component_ImageSprite, TEXT("ImageSprite"), []()->void { Debug("ImageSprite"); }); 52 | popupmenu->AppendMenuOption(Menu_Option_Component_Camera, TEXT("Camera"), []()->void { Debug("Camera"); }); 53 | popupmenu->AppendMenuOption(Menu_Option_Component_Label, TEXT("Label"), []()->void { Debug("Label"); }); 54 | popupmenu->AppendMenuOption(Menu_Option_Component_Animator, TEXT("Animator"), []()->void { Debug("Animator"); }); 55 | popupmenu->AppendMenuOption(Menu_Option_Component_ImageSprite9, TEXT("ImageSprite9"), []()->void { Debug("ImageSprite9"); }); 56 | popupmenu->AppendMenuOption(Menu_Option_Component_Button, TEXT("Button"), []()->void { Debug("Button"); }); 57 | popupmenu->AppendMenuOption(Menu_Option_Component_Particle, TEXT("Particle"), []()->void { Debug("Particle"); }); 58 | popupmenu->AppendMenuOption(Menu_Option_Component_AudioSource, TEXT("AudioSource"), []()->void { Debug("AudioSource"); }); 59 | popupmenu->AppendMenuOption(Menu_Option_Component_Physic2DComponent, TEXT("Physic2DComponent"), []()->void { Debug("Physic2DComponent"); }); 60 | popupmenu = new (kMemEditorId)PopupMenuButton(view_window->GetHwnd()); 61 | popupmenu->SetText("Window"); 62 | popupmenu->SetAligning(AligningModeMiddle); 63 | popupmenu->SetRect(180, 0, 60, 20); 64 | popupmenu->SetBkgColorRect(180, 0, 60, 20); 65 | view_window->AppendUI(popupmenu); 66 | popupmenu->AppendMenuOption(Menu_Option_Window_Animation, TEXT("Animation"), []()->void { Debug("Animation"); }); 67 | popupmenu->AppendMenuOption(Menu_Option_Window_Animator, TEXT("Animator"), []()->void { Debug("Animator"); }); 68 | popupmenu->AppendMenuOption(Menu_Option_Window_Atlas, TEXT("Atlas"), []()->void { Debug("Atlas"); }); 69 | popupmenu->AppendMenuOption(Menu_Option_Window_Profiler, TEXT("Profiler"), []()->void { Debug("Profiler"); }); 70 | popupmenu->AppendMenuOption(Menu_Option_Window_Physics, TEXT("Physics"), []()->void { Debug("Physics"); }); 71 | 72 | view_window->MoveWindow(0, 0, 1274, 20); 73 | view_window->Show(); 74 | mViewWindow = view_window; 75 | } 76 | ViewWindow*TopMenuWindow::GetViewWindow() { 77 | return mViewWindow; 78 | } 79 | TopMenuWindow*TopMenuWindow::Singleton() { 80 | if (mSingleton == nullptr) { 81 | mSingleton = new TopMenuWindow; 82 | } 83 | return mSingleton; 84 | } 85 | } -------------------------------------------------------------------------------- /Platform/Windows/Editor/TopMenuWindow/TopMenuWindow.h: -------------------------------------------------------------------------------- 1 | #include "Platform/Windows/Common/ViewWindow.h" 2 | namespace Editor { 3 | class TopMenuWindow { 4 | protected: 5 | static TopMenuWindow * mSingleton; 6 | protected: 7 | ViewWindow * mViewWindow; 8 | void OnSize(WPARAM wParam, LPARAM lParam, void*reserved = nullptr); 9 | public: 10 | void Init(BaseWindow*parent); 11 | ViewWindow*GetViewWindow(); 12 | static TopMenuWindow * Singleton(); 13 | }; 14 | } -------------------------------------------------------------------------------- /Platform/Windows/Editor/TopToolsWindow/TopToolsWindow.cpp: -------------------------------------------------------------------------------- 1 | #include "TopToolsWindow.h" 2 | #include "Platform/Windows/Common/WinEnviroment.h" 3 | #include "Platform/Windows/Common/ViewWindow.h" 4 | #include "Platform/Windows/Common/Control/Button/TwoStateButton.h" 5 | #include "Platform/Windows/Editor/Menu/MenuItemDefine.h" 6 | #include "Runtime/Debugger/Logger.h" 7 | #include "Runtime/String/StringUtils.h" 8 | #include "Runtime/IO/FileSystem.h" 9 | namespace Editor { 10 | TopToolsWindow*TopToolsWindow::mSingleton = nullptr; 11 | void TopToolsWindow::Init(BaseWindow*parent) { 12 | ViewWindow*view_window = new ViewWindow; 13 | view_window->SetWindowName("TopToolsWindow"); 14 | view_window->SetBkgColor(Gdiplus::Color(30, 30, 30)); 15 | view_window->SetNCSize(0, 0, 0, 0); 16 | view_window->Init(parent); 17 | view_window->MoveWindow(0, 20, 1274, 50); 18 | view_window->SetMinRect(0, 0, -1, 50); 19 | view_window->SetMaxRect(0, 0, -1, 50); 20 | view_window->Show(); 21 | mPlayStopButton = new TwoStateButton; 22 | mPlayStopButton->SetImageData(WinResources::Singleton()->GetImageData("PlayNormal.png"), WinResources::Singleton()->GetImageData("PlayDown.png")); 23 | mPlayStopButton->SetRect(view_window->GetUILocationL(32, 1274 / 2) - 16, view_window->GetUILocationT(32, 9) - 16, 0, 0); 24 | mPlayStopButton->SetLocationCatagory(UINode::kUILocationCatagoryPercentageAbsolute, UINode::kUILocationCatagoryRelativeToTop); 25 | mPlayStopButton->SetAnchor(0.5f, 9.0f); 26 | mPlayStopButton->SetOnClickedHandler([](void*ptr)->void { 27 | TwoStateButton * btn = (TwoStateButton*)ptr; 28 | switch (btn->GetState()) { 29 | case TwoStateButton::kTwoStateButtonStateOne: 30 | Debug("play stop button state : stopped"); 31 | break; 32 | case TwoStateButton::kTwoStateButtonStateTwo: 33 | Debug("play stop button state : playing"); 34 | break; 35 | } 36 | }); 37 | view_window->AppendUI(mPlayStopButton); 38 | mViewWindow = view_window; 39 | } 40 | ViewWindow*TopToolsWindow::GetViewWindow() { 41 | return mViewWindow; 42 | } 43 | TopToolsWindow*TopToolsWindow::Singleton() { 44 | if (mSingleton==nullptr){ 45 | mSingleton = new TopToolsWindow; 46 | } 47 | return mSingleton; 48 | } 49 | } -------------------------------------------------------------------------------- /Platform/Windows/Editor/TopToolsWindow/TopToolsWindow.h: -------------------------------------------------------------------------------- 1 | #include "Platform/Windows/Common/ViewWindow.h" 2 | namespace Editor { 3 | class TwoStateButton; 4 | class TopToolsWindow { 5 | protected: 6 | static TopToolsWindow * mSingleton; 7 | protected: 8 | ViewWindow * mViewWindow; 9 | TwoStateButton*mPlayStopButton; 10 | public: 11 | void Init(BaseWindow*parent); 12 | ViewWindow*GetViewWindow(); 13 | static TopToolsWindow * Singleton(); 14 | }; 15 | } -------------------------------------------------------------------------------- /Platform/Windows/Editor/main.cpp: -------------------------------------------------------------------------------- 1 | #include "Platform/Windows/Common/WinEnviroment.h" 2 | #include "Platform/Windows/Common/WinResources.h" 3 | #include "Platform/Windows/Common/ViewWindow.h" 4 | #include "Platform/Windows/Editor/EditorMainWindow.h" 5 | #include "Platform/Windows/Common/CursorManager.h" 6 | #include "Runtime/IO/ResourceManager.h" 7 | #if _DEBUG 8 | #pragma comment( linker, "/subsystem:\"console\" /entry:\"WinMainCRTStartup\"") 9 | #endif 10 | Editor::EditorMainWindow * gEditorMainWindow = nullptr; 11 | void ProcessingMessage(MSG&msg) { 12 | if (!TranslateAccelerator(msg.hwnd, gEditorMainWindow->mAccel, &msg)) { 13 | TranslateMessage(&msg); 14 | DispatchMessage(&msg); 15 | } 16 | } 17 | void MessageLoop() { 18 | MSG msg; 19 | bool isQuit = false; 20 | std::vector msgs; 21 | int nIndex = 0; 22 | int nMsgCount = 0; 23 | while (!isQuit) { 24 | while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { 25 | if (msg.message == WM_KEYDOWN || msg.message == WM_KEYUP) { 26 | ProcessingMessage(msg); 27 | } 28 | else { 29 | msgs.push_back(msg); 30 | if (msgs.size() == 100) { 31 | break; 32 | } 33 | } 34 | } 35 | nIndex = 0; 36 | nMsgCount = (int)msgs.size(); 37 | while (nIndex < nMsgCount) { 38 | if (WM_QUIT == msgs[nIndex].message){ 39 | isQuit = true; 40 | }else{ 41 | ProcessingMessage(msgs[nIndex]); 42 | } 43 | nIndex++; 44 | } 45 | msgs.clear(); 46 | Sleep(10); 47 | } 48 | } 49 | INT WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPSTR lpCmdLine, _In_ int nShowCmd) { 50 | Editor::WinEnviroment::Init(hInstance); 51 | Alice::ResourceManager::Init(); 52 | Editor::CursorManager::Singleton()->Init(); 53 | Editor::WinResources::Singleton()->Init("res"); 54 | Editor::MainWindow::InitWindowClasses(); 55 | Editor::ViewWindow::InitWindowClasses(); 56 | gEditorMainWindow = new Editor::EditorMainWindow; 57 | gEditorMainWindow->Init(); 58 | gEditorMainWindow->MoveWindow(0, 0, 1286, 752); 59 | gEditorMainWindow->Show(); 60 | MessageLoop(); 61 | return 0; 62 | } -------------------------------------------------------------------------------- /Platform/Windows/Player/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(PROJECT_NAME "BattleFirePlayer") 2 | include_directories(${PROJECT_SOURCE_DIR}) 3 | include_directories(${PROJECT_SOURCE_DIR}/External/Box2D/include) 4 | include_directories(${PROJECT_SOURCE_DIR}/External/PBC/src) 5 | include_directories(${PROJECT_SOURCE_DIR}/External/Lua5.1.4/src) 6 | include_directories(${PROJECT_SOURCE_DIR}/External/PhysX3.4/PhysX_3.4/Include) 7 | include_directories(${PROJECT_SOURCE_DIR}/External/PhysX3.4/PxShared/include) 8 | include_directories(${PROJECT_SOURCE_DIR}/External/zlib) 9 | include_directories(${PROJECT_SOURCE_DIR}/External/LuaSocket/src) 10 | include_directories(${PROJECT_SOURCE_DIR}/External/LibZipRel/lib) 11 | include_directories(${PROJECT_SOURCE_DIR}/External/LibZipRel/build) 12 | include_directories(${PROJECT_SOURCE_DIR}/External/LibCurl/include) 13 | include_directories(${PROJECT_SOURCE_DIR}/External/FreeType/include) 14 | GroupDirectories("" "" ${PROJECT_SOURCE_DIR}/Runtime common_runtime_sources) 15 | GroupDirectories("" "" ${PROJECT_SOURCE_DIR}/Platform/Windows/Player winplayer_sources) 16 | GroupDirectories("" "" ${PROJECT_SOURCE_DIR}/Platform/Windows/Common win_common_sources) 17 | 18 | set(WinPlayerSources ${common_runtime_sources} ${winplayer_sources} ${win_common_sources}) 19 | 20 | add_compile_definitions(ALICE_WIN_PLAYER _DEBUG UNICODE _UNICODE _SCL_SECURE_NO_WARNINGS _CRT_SECURE_NO_WARNINGS) 21 | 22 | set(CMAKE_CXX_FLAGS_RELEASE "/MT /O2 /Ob2 /DNDEBUG") 23 | set(CMAKE_CXX_FLAGS_DEBUG "/MTd /Zi /Ob0 /Od /RTC1") 24 | set(CMAKE_CXX_FLAGS "/DWIN32 /D_WINDOWS /W3 /GR /EHsc") 25 | set(CMAKE_C_FLAGS_RELEASE "/MT /O2 /Ob2 /DNDEBUG") 26 | set(CMAKE_C_FLAGS_DEBUG "/MTd /Zi /Ob0 /Od /RTC1") 27 | set(CMAKE_C_FLAGS "/DWIN32 /D_WINDOWS /W3") 28 | set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SUBSYSTEM:WINDOWS") 29 | 30 | link_directories(${PROJECT_SOURCE_DIR}/External/PrebuiltLibs/x86) 31 | add_executable(${PROJECT_NAME} ${WinPlayerSources}) 32 | set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME "WinPlayer") 33 | target_link_libraries(${PROJECT_NAME} gdiplus libprotobuf Imm32) -------------------------------------------------------------------------------- /Platform/Windows/Player/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #if _DEBUG 3 | #pragma comment( linker, "/subsystem:\"console\" /entry:\"WinMainCRTStartup\"") 4 | #endif 5 | INT WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPSTR lpCmdLine, _In_ int nShowCmd) { 6 | return 0; 7 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Engine 2 | BattleFire Engine OpenSource Version 3 | 4 | # Compiling Tool 5 | 6 | [CMake 3.18.1](https://cmake.org/ "CMake3.18.1") 7 | 8 | Visual Studio 2017 9 | 10 | # Compile Step 11 | 1.mkdir build 12 | 13 | 2.cd build 14 | 15 | 3.cmake .. 16 | 17 | # Screen Shot 18 | ![编辑器截图](https://i.postimg.cc/xd67WC5j/2.jpg "编辑器截图") 19 | -------------------------------------------------------------------------------- /Resources/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | CMAKE_MINIMUM_REQUIRED(VERSION 2.6) 2 | Project(ResourcePacker) 3 | 4 | function(GroupDirectories dirPrefix groupPrefix targetDir sources) 5 | get_filename_component(currentDirName ${targetDir} NAME) 6 | string(CONCAT currentDirFullName "${dirPrefix}${currentDirName}/") 7 | string(CONCAT currentDirGroupName "${groupPrefix}${currentDirName}") 8 | file(GLOB allFiles "${targetDir}/*") 9 | file(GLOB allCFiles "${targetDir}/*.c") 10 | file(GLOB allHFiles "${targetDir}/*.h*") 11 | file(GLOB allCXXFiles "${targetDir}/*.c*") 12 | 13 | list(LENGTH allFiles argv_len) 14 | list(LENGTH allCFiles lenC) 15 | list(LENGTH allCXXFiles lenCXX) 16 | list(LENGTH allHFiles lenH) 17 | 18 | set(allUsefulFileCount 0) 19 | math(EXPR allUsefulFileCount "${lenC}+${lenCXX}+${lenH}") 20 | if(0 LESS allUsefulFileCount) 21 | set(mGroups ${allCFiles} ${allCXXFiles} ${allHFiles}) 22 | source_group(${currentDirGroupName} FILES ${mGroups}) 23 | message(STATUS "${currentDirGroupName} c:${lenC} cxx:${lenCXX} h:${lenH} total:${argv_len}") 24 | endif() 25 | set(i 0) 26 | while( i LESS ${argv_len}) 27 | list(GET allFiles ${i} argv_value) 28 | if(IS_DIRECTORY ${argv_value}) 29 | #deal with directory 30 | #message(STATUS "${argv_value}") 31 | string(CONCAT currentGroupPrefix "${groupPrefix}${currentDirName}\\") 32 | GroupDirectories(${currentDirFullName} ${currentGroupPrefix} ${argv_value} subGroups) 33 | list(APPEND mGroups ${subGroups}) 34 | else() 35 | #deal with files 36 | #message(STATUS "file ${argv_value}") 37 | endif() 38 | math(EXPR i "${i} + 1") 39 | endwhile() 40 | set(${sources} ${mGroups} PARENT_SCOPE) 41 | endfunction() 42 | 43 | if(WIN32) 44 | include_directories(${PROJECT_SOURCE_DIR}/../) 45 | include_directories(${PROJECT_SOURCE_DIR}/../External/Box2D/include) 46 | include_directories(${PROJECT_SOURCE_DIR}/../External/PBC/src) 47 | include_directories(${PROJECT_SOURCE_DIR}/../External/ProtoBuffer3.13/src) 48 | include_directories(${PROJECT_SOURCE_DIR}/../External/Lua5.1.4/src) 49 | include_directories(${PROJECT_SOURCE_DIR}/../External/PhysX3.4/PhysX_3.4/Include) 50 | include_directories(${PROJECT_SOURCE_DIR}/../External/PhysX3.4/PxShared/include) 51 | include_directories(${PROJECT_SOURCE_DIR}/../External/zlib) 52 | include_directories(${PROJECT_SOURCE_DIR}/../External/LuaSocket/src) 53 | include_directories(${PROJECT_SOURCE_DIR}/../External/LibZipRel/lib) 54 | include_directories(${PROJECT_SOURCE_DIR}/../External/LibZipRel/build) 55 | include_directories(${PROJECT_SOURCE_DIR}/../External/LibCurl/include) 56 | include_directories(${PROJECT_SOURCE_DIR}/../External/FreeType/include) 57 | 58 | set(ResourcePackerSrcs ${PROJECT_SOURCE_DIR}/../Platform/Windows/Common/PlatformWindowsSeriallizer.pb.cc) 59 | list(APPEND ResourcePackerSrcs ${PROJECT_SOURCE_DIR}/src/main.cpp) 60 | 61 | add_compile_definitions(ALICE_WIN_PLAYER _DEBUG UNICODE _UNICODE _SCL_SECURE_NO_WARNINGS _CRT_SECURE_NO_WARNINGS) 62 | 63 | set(CMAKE_CXX_FLAGS_RELEASE "/MT /O2 /Ob2 /DNDEBUG") 64 | set(CMAKE_CXX_FLAGS_DEBUG "/MTd /Zi /Ob0 /Od /RTC1") 65 | set(CMAKE_CXX_FLAGS "/DWIN32 /D_WINDOWS /W3 /GR /EHsc") 66 | set(CMAKE_C_FLAGS_RELEASE "/MT /O2 /Ob2 /DNDEBUG") 67 | set(CMAKE_C_FLAGS_DEBUG "/MTd /Zi /Ob0 /Od /RTC1") 68 | set(CMAKE_C_FLAGS "/DWIN32 /D_WINDOWS /W3") 69 | 70 | link_directories(${PROJECT_SOURCE_DIR}/../External/PrebuiltLibs/x86) 71 | add_executable(${PROJECT_NAME} ${ResourcePackerSrcs}) 72 | target_link_libraries(${PROJECT_NAME} gdiplus libprotobuf Imm32) 73 | set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME "ResourcePacker") 74 | set_target_properties(${PROJECT_NAME} PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}") 75 | ENDIF() -------------------------------------------------------------------------------- /Resources/Raw/AliceTab.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BattleFireLTD/Engine/eae9aae7dc63aec341c0bbc0a33ba7f9a136df19/Resources/Raw/AliceTab.png -------------------------------------------------------------------------------- /Resources/Raw/HierarchyWindowIcon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BattleFireLTD/Engine/eae9aae7dc63aec341c0bbc0a33ba7f9a136df19/Resources/Raw/HierarchyWindowIcon.png -------------------------------------------------------------------------------- /Resources/Raw/InspectorWindowIcon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BattleFireLTD/Engine/eae9aae7dc63aec341c0bbc0a33ba7f9a136df19/Resources/Raw/InspectorWindowIcon.png -------------------------------------------------------------------------------- /Resources/Raw/PlayDown.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BattleFireLTD/Engine/eae9aae7dc63aec341c0bbc0a33ba7f9a136df19/Resources/Raw/PlayDown.png -------------------------------------------------------------------------------- /Resources/Raw/PlayNormal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BattleFireLTD/Engine/eae9aae7dc63aec341c0bbc0a33ba7f9a136df19/Resources/Raw/PlayNormal.png -------------------------------------------------------------------------------- /Resources/Raw/ProjectWindowIcon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BattleFireLTD/Engine/eae9aae7dc63aec341c0bbc0a33ba7f9a136df19/Resources/Raw/ProjectWindowIcon.png -------------------------------------------------------------------------------- /Resources/Raw/SceneViewIcon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BattleFireLTD/Engine/eae9aae7dc63aec341c0bbc0a33ba7f9a136df19/Resources/Raw/SceneViewIcon.png -------------------------------------------------------------------------------- /Resources/Raw/close_btn.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BattleFireLTD/Engine/eae9aae7dc63aec341c0bbc0a33ba7f9a136df19/Resources/Raw/close_btn.png -------------------------------------------------------------------------------- /Resources/res: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BattleFireLTD/Engine/eae9aae7dc63aec341c0bbc0a33ba7f9a136df19/Resources/res -------------------------------------------------------------------------------- /Resources/src/main.cpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | #include "Platform/Windows/Common/PlatformWindowsSeriallizer.pb.h" 8 | #include "External/ProtoBuffer3.13/src/google/protobuf/text_format.h" 9 | int main(int argc, char **argv){ 10 | PlatformWindowsSeriallizer::WinResources *editorResources = new PlatformWindowsSeriallizer::WinResources; 11 | _chdir("Raw"); 12 | long hFile; 13 | _finddata_t fileinfo; 14 | if ((hFile = _findfirst("*.*", &fileinfo)) != -1){ 15 | do{ 16 | if (!(fileinfo.attrib & _A_SUBDIR)){ 17 | FILE *pFile = NULL; 18 | pFile = fopen(fileinfo.name, "rb"); 19 | if (pFile != NULL){ 20 | fseek(pFile, 0, SEEK_END); 21 | int mDataLen = ftell(pFile); 22 | rewind(pFile); 23 | if (mDataLen > 0){ 24 | char*data=new char[sizeof(char) *mDataLen]; 25 | mDataLen = fread(data, sizeof(char), mDataLen, pFile); 26 | editorResources->mutable_res()->insert(google::protobuf::MapPair(fileinfo.name,std::string(data,mDataLen))); 27 | } 28 | fclose(pFile); 29 | } 30 | } 31 | } while (_findnext(hFile, &fileinfo) == 0); 32 | _findclose(hFile); 33 | cout << "total size "<ByteSizeLong()/1024<<"KB" << endl; 34 | 35 | char *szBuffer=new char[editorResources->ByteSizeLong()]; 36 | editorResources->SerializeToArray(szBuffer, editorResources->ByteSizeLong()); 37 | FILE *pFile = NULL; 38 | pFile = fopen("../res", "wb"); 39 | if (pFile != NULL){ 40 | fwrite(szBuffer,1,editorResources->ByteSizeLong(),pFile); 41 | fclose(pFile); 42 | } 43 | } 44 | return 0; 45 | } -------------------------------------------------------------------------------- /Runtime/Allocator/AliceMemory.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Runtime/BattleFirePrefix.h" 3 | #include "DefaultAllocator.h" 4 | #include "MemoryLabel.h" 5 | extern "C" void InitMemory(); 6 | extern "C" void OnQuitMemory(); 7 | unsigned long GetTotalReservedMemory(); -------------------------------------------------------------------------------- /Runtime/Allocator/DefaultAllocator.cpp: -------------------------------------------------------------------------------- 1 | #include "DefaultAllocator.h" 2 | #include 3 | #include 4 | #include "AliceMemory.h" 5 | #include "tlsf/tlsf.h" 6 | #include 7 | #include 8 | 9 | //1024 1KB 10 | //1024x1024 1MB 1048576 11 | //1024x1024x1024 1GB 1073741824 12 | static unsigned long sReservedTotalMemory = 50485760; 13 | static unsigned int mReservedSize = 504857600;//500MB 14 | static tlsf_t sTLSF=nullptr; 15 | void AllocateMemoryFromSystem(std::size_t size){ 16 | void*buffer = malloc(mReservedSize); 17 | tlsf_add_pool(sTLSF, buffer, mReservedSize); 18 | sReservedTotalMemory += 50485760; 19 | } 20 | unsigned long GetTotalReservedMemory(){ 21 | return sReservedTotalMemory; 22 | } 23 | static bool sbAppQuit = false; 24 | void InitMemory(){ 25 | #if USE_POOL 26 | void*buffer = malloc(mReservedSize); 27 | sTLSF = tlsf_create_with_pool(buffer, mReservedSize); 28 | #endif 29 | } 30 | //on windows platform the min memory block is 12 bytes 31 | static void*GetMemory(size_t size){ 32 | void * ptrMemory = nullptr; 33 | ptrMemory = tlsf_malloc(sTLSF, size); 34 | while (ptrMemory==nullptr){ 35 | AllocateMemoryFromSystem(mReservedSize); 36 | ptrMemory = tlsf_malloc(sTLSF, size); 37 | } 38 | return ptrMemory; 39 | } 40 | void OnQuitMemory(){ 41 | sbAppQuit = true; 42 | } 43 | static void Recycle(void*ptr){ 44 | if (sbAppQuit){ 45 | return; 46 | } 47 | #if USE_POOL 48 | if (Alice::Profiler::OnFreeObject(ptr)){ 49 | tlsf_free(sTLSF, ptr); 50 | }else{ 51 | free(ptr); 52 | #else 53 | //Debug("delete %p",ptr); 54 | free(ptr); 55 | #endif 56 | #if USE_POOL 57 | } 58 | #endif 59 | } 60 | 61 | void*operator new(std::size_t size) { 62 | size_t alloc_size = ALICE_ADJUST_MEMORY_SIZE(size); 63 | void* ptr = malloc(alloc_size); 64 | return ptr; 65 | } 66 | 67 | void*operator new(std::size_t size, MemoryLabel memID){ 68 | #if USE_POOL 69 | if (memID==kMemEditorId){ 70 | void*ptr = malloc(size); 71 | return ptr; 72 | } 73 | void*ptr = GetMemory(size); 74 | Alice::Profiler::OnNewObject(ptr, memID); 75 | return ptr; 76 | #else 77 | size_t alloc_size = ALICE_ADJUST_MEMORY_SIZE(size); 78 | void* ptr = malloc(alloc_size); 79 | return ptr; 80 | #endif 81 | } 82 | 83 | void*operator new[](std::size_t size, MemoryLabel memID){ 84 | #if USE_POOL 85 | if (memID == kMemEditorId){ 86 | void*ptr = malloc(size); 87 | return ptr; 88 | } 89 | void*ptr = GetMemory(size); 90 | Alice::Profiler::OnNewObject(ptr, memID); 91 | return ptr; 92 | #else 93 | size_t alloc_size = ALICE_ADJUST_MEMORY_SIZE(size); 94 | void* ptr = malloc(alloc_size); 95 | return ptr; 96 | #endif 97 | } 98 | 99 | void operator delete(void*ptr,MemoryLabel memID){ 100 | //Error("un implemented method"); 101 | } 102 | 103 | void operator delete[](void*ptr, MemoryLabel memID){ 104 | //Error("un implemented method"); 105 | } 106 | #if ALICE_ANDROID 107 | void operator delete(void*ptr)noexcept(true){ 108 | Recycle(ptr); 109 | } 110 | 111 | void operator delete [](void*ptr)noexcept(true){ 112 | Recycle(ptr); 113 | } 114 | #else 115 | void operator delete(void*ptr){ 116 | Recycle(ptr); 117 | } 118 | 119 | void operator delete [](void*ptr){ 120 | Recycle(ptr); 121 | } 122 | #endif 123 | -------------------------------------------------------------------------------- /Runtime/Allocator/DefaultAllocator.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include "MemoryLabel.h" 4 | #define ALICE_ALIGN 4 5 | #define ALICE_ADJUST_MEMORY_SIZE(size) ((size + (ALICE_ALIGN - 1)) & ~(ALICE_ALIGN - 1)) 6 | void*operator new(std::size_t size); 7 | void*operator new(std::size_t size, MemoryLabel memID); 8 | void*operator new[](std::size_t size, MemoryLabel memID); 9 | 10 | #if ALICE_ANDROID||ALICE_IPHONE 11 | void operator delete[](void*ptr)noexcept(true); 12 | void operator delete(void*ptr) noexcept(true); 13 | #else 14 | void operator delete[](void*ptr); 15 | void operator delete(void*ptr); 16 | #endif 17 | void operator delete(void*ptr, MemoryLabel memID); 18 | void operator delete[](void*ptr, MemoryLabel memID); -------------------------------------------------------------------------------- /Runtime/Allocator/MemoryLabel.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | enum MemoryLabel{ 4 | #define MEMORY_LABEL(Name) kMem##Name##Id , 5 | MEMORY_LABEL(Default) 6 | MEMORY_LABEL(VertexData) 7 | MEMORY_LABEL(IndexData) 8 | MEMORY_LABEL(Geometry) 9 | MEMORY_LABEL(Texture) 10 | MEMORY_LABEL(Shader) 11 | MEMORY_LABEL(GfxDevice) 12 | MEMORY_LABEL(GfxThread) 13 | MEMORY_LABEL(Animation) 14 | MEMORY_LABEL(Mesh) 15 | MEMORY_LABEL(Audio) 16 | MEMORY_LABEL(AudioData) 17 | MEMORY_LABEL(AudioProcessing) 18 | MEMORY_LABEL(Font) 19 | MEMORY_LABEL(Serialization) 20 | MEMORY_LABEL(IO) 21 | MEMORY_LABEL(IO2) 22 | MEMORY_LABEL(ThreadStack) 23 | MEMORY_LABEL(Renderer) 24 | MEMORY_LABEL(Transform) 25 | MEMORY_LABEL(Editor) 26 | MEMORY_LABEL(Profiler) 27 | MEMORY_LABEL(MemoryAllocator) 28 | MEMORY_LABEL(Particle) 29 | MEMORY_LABEL(System) 30 | MEMORY_LABEL(Material) 31 | MEMORY_LABEL(Script) 32 | MEMORY_LABEL(AssetBundle) 33 | #undef MEMORY_LABEL 34 | kMemNormalLabelCount, 35 | kMemLabelCount 36 | }; -------------------------------------------------------------------------------- /Runtime/Allocator/tlsf/tlsf.h: -------------------------------------------------------------------------------- 1 | #ifndef INCLUDED_tlsf 2 | #define INCLUDED_tlsf 3 | 4 | /* 5 | ** Two Level Segregated Fit memory allocator, version 3.0. 6 | ** Written by Matthew Conte, and placed in the Public Domain. 7 | ** http://tlsf.baisoku.org 8 | ** 9 | ** Based on the original documentation by Miguel Masmano: 10 | ** http://rtportal.upv.es/rtmalloc/allocators/tlsf/index.shtml 11 | ** 12 | ** Please see the accompanying Readme.txt for implementation 13 | ** notes and caveats. 14 | ** 15 | ** This implementation was written to the specification 16 | ** of the document, therefore no GPL restrictions apply. 17 | */ 18 | 19 | #include 20 | 21 | #if defined(__cplusplus) 22 | extern "C" { 23 | #endif 24 | 25 | /* tlsf_t: a TLSF structure. Can contain 1 to N pools. */ 26 | /* pool_t: a block of memory that TLSF can manage. */ 27 | typedef void* tlsf_t; 28 | typedef void* pool_t; 29 | 30 | /* Create/destroy a memory pool. */ 31 | tlsf_t tlsf_create(void* mem); 32 | tlsf_t tlsf_create_with_pool(void* mem, size_t bytes); 33 | void tlsf_destroy(tlsf_t tlsf); 34 | pool_t tlsf_get_pool(tlsf_t tlsf); 35 | 36 | /* Add/remove memory pools. */ 37 | pool_t tlsf_add_pool(tlsf_t tlsf, void* mem, size_t bytes); 38 | void tlsf_remove_pool(tlsf_t tlsf, pool_t pool); 39 | 40 | /* malloc/memalign/realloc/free replacements. */ 41 | void* tlsf_malloc(tlsf_t tlsf, size_t bytes); 42 | void* tlsf_memalign(tlsf_t tlsf, size_t align, size_t bytes); 43 | void* tlsf_realloc(tlsf_t tlsf, void* ptr, size_t size); 44 | void tlsf_free(tlsf_t tlsf, void* ptr); 45 | 46 | /* Returns internal block size, not original request size */ 47 | size_t tlsf_block_size(void* ptr); 48 | 49 | /* Overheads/limits of internal structures. */ 50 | size_t tlsf_size(); 51 | size_t tlsf_align_size(); 52 | size_t tlsf_block_size_min(); 53 | size_t tlsf_block_size_max(); 54 | size_t tlsf_pool_overhead(); 55 | size_t tlsf_alloc_overhead(); 56 | 57 | /* Debugging. */ 58 | typedef void (*tlsf_walker)(void* ptr, size_t size, int used, void* user); 59 | void tlsf_walk_pool(pool_t pool, tlsf_walker walker, void* user); 60 | /* Returns nonzero if any internal consistency check fails. */ 61 | int tlsf_check(tlsf_t tlsf); 62 | int tlsf_check_pool(pool_t pool); 63 | 64 | #if defined(__cplusplus) 65 | }; 66 | #endif 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /Runtime/Allocator/tlsf/tlsfbits.h: -------------------------------------------------------------------------------- 1 | #ifndef INCLUDED_tlsfbits 2 | #define INCLUDED_tlsfbits 3 | 4 | #if defined(__cplusplus) 5 | #define tlsf_decl inline 6 | #else 7 | #define tlsf_decl static 8 | #endif 9 | 10 | /* 11 | ** Architecture-specific bit manipulation routines. 12 | ** 13 | ** TLSF achieves O(1) cost for malloc and free operations by limiting 14 | ** the search for a free block to a free list of guaranteed size 15 | ** adequate to fulfill the request, combined with efficient free list 16 | ** queries using bitmasks and architecture-specific bit-manipulation 17 | ** routines. 18 | ** 19 | ** Most modern processors provide instructions to count leading zeroes 20 | ** in a word, find the lowest and highest set bit, etc. These 21 | ** specific implementations will be used when available, falling back 22 | ** to a reasonably efficient generic implementation. 23 | ** 24 | ** NOTE: TLSF spec relies on ffs/fls returning value 0..31. 25 | ** ffs/fls return 1-32 by default, returning 0 for error. 26 | */ 27 | 28 | /* 29 | ** Detect whether or not we are building for a 32- or 64-bit (LP/LLP) 30 | ** architecture. There is no reliable portable method at compile-time. 31 | */ 32 | #if defined (__alpha__) || defined (__ia64__) || defined (__x86_64__) \ 33 | || defined (_WIN64) || defined (__LP64__) || defined (__LLP64__) 34 | #define TLSF_64BIT 35 | #endif 36 | 37 | /* 38 | ** gcc 3.4 and above have builtin support, specialized for architecture. 39 | ** Some compilers masquerade as gcc; patchlevel test filters them out. 40 | */ 41 | #if defined (__GNUC__) && (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) \ 42 | && defined (__GNUC_PATCHLEVEL__) 43 | 44 | tlsf_decl int tlsf_ffs(unsigned int word) 45 | { 46 | return __builtin_ffs(word) - 1; 47 | } 48 | 49 | tlsf_decl int tlsf_fls(unsigned int word) 50 | { 51 | const int bit = word ? 32 - __builtin_clz(word) : 0; 52 | return bit - 1; 53 | } 54 | 55 | #elif defined (_MSC_VER) && (_MSC_VER >= 1400) && (defined (_M_IX86) || defined (_M_X64)) 56 | /* Microsoft Visual C++ support on x86/X64 architectures. */ 57 | 58 | #include 59 | 60 | #pragma intrinsic(_BitScanReverse) 61 | #pragma intrinsic(_BitScanForward) 62 | 63 | tlsf_decl int tlsf_fls(unsigned int word) 64 | { 65 | unsigned long index; 66 | return _BitScanReverse(&index, word) ? index : -1; 67 | } 68 | 69 | tlsf_decl int tlsf_ffs(unsigned int word) 70 | { 71 | unsigned long index; 72 | return _BitScanForward(&index, word) ? index : -1; 73 | } 74 | 75 | #elif defined (_MSC_VER) && defined (_M_PPC) 76 | /* Microsoft Visual C++ support on PowerPC architectures. */ 77 | 78 | #include 79 | 80 | tlsf_decl int tlsf_fls(unsigned int word) 81 | { 82 | const int bit = 32 - _CountLeadingZeros(word); 83 | return bit - 1; 84 | } 85 | 86 | tlsf_decl int tlsf_ffs(unsigned int word) 87 | { 88 | const unsigned int reverse = word & (~word + 1); 89 | const int bit = 32 - _CountLeadingZeros(reverse); 90 | return bit - 1; 91 | } 92 | 93 | #elif defined (__ARMCC_VERSION) 94 | /* RealView Compilation Tools for ARM */ 95 | 96 | tlsf_decl int tlsf_ffs(unsigned int word) 97 | { 98 | const unsigned int reverse = word & (~word + 1); 99 | const int bit = 32 - __clz(reverse); 100 | return bit - 1; 101 | } 102 | 103 | tlsf_decl int tlsf_fls(unsigned int word) 104 | { 105 | const int bit = word ? 32 - __clz(word) : 0; 106 | return bit - 1; 107 | } 108 | 109 | #elif defined (__ghs__) 110 | /* Green Hills support for PowerPC */ 111 | 112 | #include 113 | 114 | tlsf_decl int tlsf_ffs(unsigned int word) 115 | { 116 | const unsigned int reverse = word & (~word + 1); 117 | const int bit = 32 - __CLZ32(reverse); 118 | return bit - 1; 119 | } 120 | 121 | tlsf_decl int tlsf_fls(unsigned int word) 122 | { 123 | const int bit = word ? 32 - __CLZ32(word) : 0; 124 | return bit - 1; 125 | } 126 | 127 | #else 128 | /* Fall back to generic implementation. */ 129 | 130 | tlsf_decl int tlsf_fls_generic(unsigned int word) 131 | { 132 | int bit = 32; 133 | 134 | if (!word) bit -= 1; 135 | if (!(word & 0xffff0000)) { word <<= 16; bit -= 16; } 136 | if (!(word & 0xff000000)) { word <<= 8; bit -= 8; } 137 | if (!(word & 0xf0000000)) { word <<= 4; bit -= 4; } 138 | if (!(word & 0xc0000000)) { word <<= 2; bit -= 2; } 139 | if (!(word & 0x80000000)) { word <<= 1; bit -= 1; } 140 | 141 | return bit; 142 | } 143 | 144 | /* Implement ffs in terms of fls. */ 145 | tlsf_decl int tlsf_ffs(unsigned int word) 146 | { 147 | return tlsf_fls_generic(word & (~word + 1)) - 1; 148 | } 149 | 150 | tlsf_decl int tlsf_fls(unsigned int word) 151 | { 152 | return tlsf_fls_generic(word) - 1; 153 | } 154 | 155 | #endif 156 | 157 | /* Possibly 64-bit version of tlsf_fls. */ 158 | #if defined (TLSF_64BIT) 159 | tlsf_decl int tlsf_fls_sizet(size_t size) 160 | { 161 | int high = (int)(size >> 32); 162 | int bits = 0; 163 | if (high) 164 | { 165 | bits = 32 + tlsf_fls(high); 166 | } 167 | else 168 | { 169 | bits = tlsf_fls((int)size & 0xffffffff); 170 | 171 | } 172 | return bits; 173 | } 174 | #else 175 | #define tlsf_fls_sizet tlsf_fls 176 | #endif 177 | 178 | #undef tlsf_decl 179 | 180 | #endif 181 | -------------------------------------------------------------------------------- /Runtime/Base/Object.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BattleFireLTD/Engine/eae9aae7dc63aec341c0bbc0a33ba7f9a136df19/Runtime/Base/Object.cpp -------------------------------------------------------------------------------- /Runtime/Base/Object.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BattleFireLTD/Engine/eae9aae7dc63aec341c0bbc0a33ba7f9a136df19/Runtime/Base/Object.h -------------------------------------------------------------------------------- /Runtime/BattleFirePrefix.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #define ALICE_DEPRECATED __declspec(deprecated) 3 | #if defined(__GNUC__) 4 | #define ALIGN_OF(T) __alignof__(T) 5 | #define ALIGN_TYPE(val) __attribute__((aligned(val))) 6 | #define FORCE_INLINE inline __attribute__ ((always_inline)) 7 | #elif defined(_MSC_VER) 8 | #define ALIGN_OF(T) __alignof(T) 9 | #define ALIGN_TYPE(val) __declspec(align(val)) 10 | #define FORCE_INLINE __forceinline 11 | #else 12 | #define ALIGN_TYPE(size) 13 | #define FORCE_INLINE inline 14 | #endif 15 | //types 16 | #if ALICE_IPHONE || ALICE_ANDROID 17 | #define _MAX_PATH 256 18 | #endif 19 | 20 | #if ALICE_EDITOR || ALICE_WIN_PLAYER 21 | #define ALICE_PLATFORM_WIN 1 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #define NOMINMAX 34 | #define ALICE_STRICMP _stricmp 35 | #elif defined(ALICE_OSX_PLAYER) || defined(ALICE_ANDROID) || defined(ALICE_IPHONE) 36 | #define ALICE_PLATFORM_UNIX 1 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include 47 | #include 48 | #include 49 | #include 50 | #include 51 | #include 52 | #ifdef ALICE_IPHONE 53 | #include 54 | #endif//end of ALICE_IPHONE 55 | #ifdef ALICE_ANDROID 56 | #include 57 | #include 58 | #include 59 | #include 60 | #include 61 | #define JAVA_API(return_type) extern "C" JNIEXPORT return_type JNICALL 62 | #define JFOO(CLS,METHOD) Java_com_alice_battlefire_androidplayer_##CLS##_##METHOD 63 | #if defined(__arm64__)||defined(__aarch64__) 64 | #define ANDROID_ARCH "arm64-v8a" 65 | #elif defined(__arm__) 66 | #define ANDROID_ARCH "armeabi-v7a" 67 | #else 68 | #define ANDROID_ARCH "Unkown" 69 | #endif//end of defined(__arm64__)||defined(__aarch64__) 70 | #endif//end of ALICE_ANDROID 71 | #define ALICE_STRICMP strcasecmp 72 | #endif//end of ALICE_PLATFORM_UNIX 73 | #include 74 | #include 75 | #include 76 | #include 77 | #include 78 | #include 79 | #include 80 | #include 81 | #include 82 | typedef signed char AliceSInt8; 83 | typedef unsigned char AliceUInt8; 84 | typedef AliceUInt8 AliceUByte; 85 | typedef AliceSInt8 AliceByte; 86 | typedef signed short AliceSInt16; 87 | typedef unsigned short AliceUInt16; 88 | typedef int AliceSInt32; 89 | typedef unsigned int AliceUInt32; 90 | typedef unsigned long long AliceUInt64; 91 | typedef signed long long AliceSInt64; 92 | typedef AliceSInt32 LuaScriptHandle; 93 | typedef void* AliceAny; 94 | #ifndef _MAX_PATH 95 | #define _MAX_PATH 260 96 | #endif 97 | #define _00000000_00000000_00000000_00000001 1 98 | #define _00000000_00000000_00000000_00000010 2 99 | #define _00000000_00000000_00000000_00000100 4 100 | #define _00000000_00000000_00000000_00001000 8 101 | #define _00000000_00000000_00000000_00010000 16 102 | #define _00000000_00000000_00000000_00100000 32 103 | #define _00000000_00000000_00000000_01000000 64 104 | #define _00000000_00000000_00000000_10000000 128 105 | #define _00000000_00000000_00000001_00000000 256 106 | #define _00000000_00000000_00000010_00000000 512 107 | #define _00000000_00000000_00000100_00000000 1024 108 | #define _00000000_00000000_00001000_00000000 2048 109 | #define _00000000_00000000_00010000_00000000 4096 110 | #define _00000000_00000000_00100000_00000000 8192 111 | #define _00000000_00000000_01000000_00000000 16384 112 | #define _00000000_00000000_10000000_00000000 32768 113 | typedef void(*VOID_VOID_PTR)(void*); 114 | typedef void(*VOID_NO_ARG)(); -------------------------------------------------------------------------------- /Runtime/Debugger/Logger.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | #include "Logger.h" 8 | #if ALICE_ANDROID 9 | #define LOG_TAG "Alice" 10 | #endif 11 | char szEngineLog[MAX_PATH_FOR_LOG]; 12 | static void(*gEngineErrorReporter)(const char*msg) = nullptr; 13 | void SetEngineErrorReporter(void(*foo)(const char*msg)){ 14 | gEngineErrorReporter = foo; 15 | } 16 | void ReportEngineError(const char*msg){ 17 | if (gEngineErrorReporter!=nullptr){ 18 | gEngineErrorReporter(msg); 19 | }else{ 20 | Error("%s",msg); 21 | } 22 | } 23 | int FormatCurrDate(char *szTime,char *szDate){ 24 | time_t t; 25 | time(&t); 26 | struct tm *today; 27 | today=localtime(&t); 28 | strftime(szTime,32,"%H:%M:%S",today); 29 | strftime(szDate,32,"%y-%m-%d",today); 30 | return 0; 31 | } 32 | int InitEngineLog(const char *engineLog){ 33 | int nLen=strlen(engineLog); 34 | if ((nLen>=MAX_PATH_FOR_LOG)||(nLen<=0)) 35 | return -1; 36 | memset(szEngineLog,0,MAX_PATH_FOR_LOG); 37 | strcpy(szEngineLog, engineLog); 38 | return 0; 39 | } 40 | 41 | void WriteLog(const char* tag,const char*file,int nLine,const char* szLogContent){ 42 | char szTime[32]; 43 | char szDate[32]; 44 | memset(szTime,0,sizeof(szTime)); 45 | memset(szDate,0,sizeof(szDate)); 46 | FormatCurrDate(szTime, szDate); 47 | #if RELEASE && !ALICE_WIN_PREPUBLISH && !DEV_PUBLISH 48 | string fn; 49 | fn = szEngineLog; 50 | fn += "."; 51 | fn += szDate; 52 | ofstream fd; 53 | try{ 54 | fd.open(fn.c_str(), ios::app); 55 | fd << szTime << " : " << tag << " " << szLogContent << endl; 56 | fd.close(); 57 | }catch (...){ 58 | cerr << "open log file exception!" << endl; 59 | return; 60 | } 61 | #else 62 | printf("%s %s %s\n", szTime, tag, szLogContent); 63 | #endif 64 | } 65 | 66 | void DebugLog(const char*file,int nLine,const char*format,...){ 67 | if(strlen(format) == 0) 68 | return ; 69 | char szBuffer[MAX_LOG_LENGTH]; 70 | memset(szBuffer,0,MAX_LOG_LENGTH); 71 | va_list l_va; 72 | va_start(l_va,format); 73 | vsnprintf(szBuffer,sizeof(szBuffer),format,l_va); 74 | va_end(l_va); 75 | #if _DEBUG 76 | WriteLog("[debug] ",file,nLine,szBuffer); 77 | #endif 78 | } 79 | 80 | void InfoLog(const char*file,int nLine,const char*format,...){ 81 | if(strlen(format) == 0) 82 | return ; 83 | char szBuffer[MAX_LOG_LENGTH]; 84 | memset(szBuffer,0,MAX_LOG_LENGTH); 85 | va_list l_va; 86 | va_start(l_va, format); 87 | vsnprintf(szBuffer,sizeof(szBuffer),format,l_va); 88 | va_end(l_va); 89 | #if ALICE_PLATFORM_UNIX 90 | #if ALICE_ANDROID 91 | __android_log_print(ANDROID_LOG_INFO, LOG_TAG, " [info] %s %d %s\n", file, nLine, szBuffer); 92 | #elif ALICE_IPHONE 93 | printf(" [info] %s %d %s\n", file, nLine, szBuffer); 94 | #else 95 | #if ALICE_OSX_PLAYER_RELEASE_DEBUG 96 | printf(" [info] %s %d %s\n", file, nLine, szBuffer); 97 | #else 98 | WriteLog(" [info] ",file,nLine,szBuffer); 99 | #endif 100 | #endif 101 | #else 102 | WriteLog(" [info] ",file,nLine,szBuffer); 103 | #endif 104 | } 105 | 106 | void ErrorLog(const char*file,int nLine,const char*format,...) 107 | { 108 | if(strlen(format) == 0) 109 | return ; 110 | char szBuffer[MAX_LOG_LENGTH]; 111 | memset(szBuffer,0,MAX_LOG_LENGTH); 112 | 113 | va_list l_va; 114 | va_start(l_va,format); 115 | vsnprintf(szBuffer,sizeof(szBuffer),format,l_va); 116 | va_end(l_va); 117 | 118 | #if ALICE_PLATFORM_UNIX 119 | #if ALICE_ANDROID 120 | __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "[error] %s %d %s\n", file, nLine, szBuffer); 121 | #elif ALICE_IPHONE || ALICE_OSX_PLAYER 122 | printf("[error] %s %d %s\n", file, nLine, szBuffer); 123 | #endif 124 | #else 125 | WriteLog("[error]", file, nLine, szBuffer); 126 | #endif 127 | } 128 | 129 | void EditorErrorLog(const char*file, int nLine, const char*format, ...){ 130 | if (strlen(format) == 0) 131 | return; 132 | char szBuffer[MAX_LOG_LENGTH]; 133 | memset(szBuffer, 0, MAX_LOG_LENGTH); 134 | va_list l_va; 135 | va_start(l_va, format); 136 | vsnprintf(szBuffer, sizeof(szBuffer), format, l_va); 137 | va_end(l_va); 138 | if (gEngineErrorReporter) { 139 | char szTime[32]; 140 | char szDate[32]; 141 | string fn; 142 | memset(szTime, 0, sizeof(szTime)); 143 | memset(szDate, 0, sizeof(szDate)); 144 | FormatCurrDate(szTime, szDate); 145 | fn = szEngineLog; 146 | fn += "."; 147 | fn += szDate; 148 | gEngineErrorReporter(fn.c_str()); 149 | }else{ 150 | 151 | #if ALICE_PLATFORM_UNIX 152 | #if ALICE_ANDROID 153 | __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "[errorC] %s %d %s\n", file, nLine, szBuffer); 154 | #elif ALICE_IPHONE || ALICE_OSX_PLAYER 155 | printf("[errorC] %s %d %s\n", file, nLine, szBuffer); 156 | #endif 157 | #else 158 | WriteLog("[errorC]", file, nLine, szBuffer); 159 | #endif 160 | } 161 | } 162 | -------------------------------------------------------------------------------- /Runtime/Debugger/Logger.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Runtime/BattleFirePrefix.h" 3 | #include 4 | #define MAX_PATH_FOR_LOG 256 5 | #define MAX_LOG_LENGTH 10240 6 | int InitEngineLog(const char *engineLogFilePath); 7 | int FormatCurrDate(char *szTime,char *szDate); 8 | void DebugLog(const char*file,int nLine,const char*format,...);//debug log 9 | void InfoLog(const char*file,int nLine,const char*format,...);//info log 10 | void ErrorLog(const char*file, int nLine, const char*format, ...);//normal error,need not to be displayed to user 11 | void EditorErrorLog(const char*file, int nLine, const char*format, ...);//error log that need to display to the editor console window 12 | 13 | void SetEngineErrorReporter(void(*foo)(const char*msg)); 14 | void ReportEngineError(const char*msg); 15 | 16 | #if ALICE_PLATFORM_WIN && _DEBUG 17 | #define Debug(f,...) DebugLog(__FILE__,__LINE__,f,##__VA_ARGS__) 18 | #else 19 | #define Debug(f,...) 20 | #endif 21 | #define Error(f,...) ErrorLog(__FILE__,__LINE__,f,##__VA_ARGS__) 22 | #define Info(f,...) InfoLog(__FILE__,__LINE__,f,##__VA_ARGS__) 23 | #define errorC(f,...) EditorErrorLog(__FILE__,__LINE__,f,##__VA_ARGS__) 24 | -------------------------------------------------------------------------------- /Runtime/IO/AliceData.cpp: -------------------------------------------------------------------------------- 1 | #include "AliceData.h" 2 | namespace Alice{ 3 | Data::Data(int buffer_size) :mData(nullptr), mDataLen(0),mBufferSize(buffer_size) { 4 | if (buffer_size>0){ 5 | SetBufferSize(buffer_size); 6 | } 7 | } 8 | Data::~Data() { 9 | if (mBufferSize != 0) { 10 | delete[] mData; 11 | mDataLen = 0; 12 | mBufferSize = 0; 13 | mData = nullptr; 14 | } 15 | } 16 | void Data::Reset() { 17 | if (mData != nullptr) { 18 | delete[] mData; 19 | mDataLen = 0; 20 | mBufferSize = 0; 21 | mData = nullptr; 22 | } 23 | } 24 | void Data::SetBufferSize(int bufferSize) { 25 | if (mData!=nullptr){ 26 | Reset(); 27 | } 28 | mBufferSize = bufferSize; 29 | mData = new(kMemDefaultId)AliceUInt8[bufferSize]; 30 | mDataLen = 0; 31 | } 32 | void Data::MakeZero() { 33 | memset(mData, 0, mBufferSize); 34 | mDataLen = 0; 35 | } 36 | } -------------------------------------------------------------------------------- /Runtime/IO/AliceData.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Runtime/BattleFirePrefix.h" 3 | #include "Runtime/Allocator/AliceMemory.h" 4 | namespace Alice{ 5 | class Data{ 6 | public: 7 | Data(int buffer_size=0); 8 | virtual ~Data(); 9 | void Reset(); 10 | void SetBufferSize(int bufferSize); 11 | void MakeZero(); 12 | AliceUInt8 *mData; 13 | AliceSInt32 mDataLen; 14 | AliceSInt32 mBufferSize; 15 | }; 16 | } -------------------------------------------------------------------------------- /Runtime/IO/FileItem.cpp: -------------------------------------------------------------------------------- 1 | #include "FileItem.h" 2 | #include "Runtime/Allocator/AliceMemory.h" 3 | #include "Runtime/String/StringUtils.h" 4 | 5 | namespace Alice{ 6 | FileItem::FileItem() { 7 | } 8 | FileItem*FileItem::Get(const char*path){ 9 | FileItem*item = nullptr; 10 | #if ALICE_PLATFORM_WIN 11 | _finddata_t info; 12 | long hFile = _findfirst(path, &info); 13 | if (hFile){ 14 | item = new (kMemIOId)FileItem; 15 | memset(item->mRelativePath, 0, _MAX_PATH); 16 | strcpy(item->mRelativePath, path); 17 | item->mFileSize = info.size; 18 | item->mLastAccessTime = info.time_access; 19 | item->mLastWriteTime = info.time_write; 20 | item->mCreateTime = info.time_create; 21 | _findclose(hFile); 22 | } 23 | #else 24 | struct stat stbuf; 25 | int fd; 26 | fd = open(path, O_RDONLY); 27 | if (fd != -1) { 28 | if ((fstat(fd, &stbuf) != 0) || (!S_ISREG(stbuf.st_mode))) { 29 | close(fd); 30 | return nullptr; 31 | } 32 | item = new (kMemIOId)FileItem; 33 | memset(item->mRelativePath, 0, _MAX_PATH); 34 | strcpy(item->mRelativePath, path); 35 | item->mFileSize = stbuf.st_size; 36 | item->mLastAccessTime = stbuf.st_atime; 37 | item->mLastWriteTime = stbuf.st_mtime; 38 | item->mCreateTime = stbuf.st_ctime; 39 | close(fd); 40 | } 41 | #endif 42 | return item; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Runtime/IO/FileItem.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Runtime/BattleFirePrefix.h" 3 | namespace Alice{ 4 | class FileItem{ 5 | public: 6 | char mRelativePath[_MAX_PATH]; 7 | AliceSInt32 mFileSize; 8 | AliceSInt64 mLastWriteTime, mCreateTime, mLastAccessTime; 9 | FileItem(); 10 | static FileItem* Get(const char*path); 11 | }; 12 | } -------------------------------------------------------------------------------- /Runtime/IO/FileSystem.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BattleFireLTD/Engine/eae9aae7dc63aec341c0bbc0a33ba7f9a136df19/Runtime/IO/FileSystem.cpp -------------------------------------------------------------------------------- /Runtime/IO/FileSystem.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Runtime/BattleFirePrefix.h" 3 | #include "Runtime/IO/AliceData.h" 4 | #if ALICE_PLATFORM_WIN 5 | #include 6 | #endif 7 | #include 8 | #if ALICE_PLATFORM_UNIX 9 | #define TCHAR char 10 | #define LPCTSTR const char* 11 | #else 12 | #ifndef TCHAR 13 | #define WCHAR TCHAR 14 | #endif 15 | #endif 16 | #if ALICE_PLATFORM_UNIX 17 | typedef int64_t __int64; 18 | #endif 19 | 20 | namespace Alice 21 | { 22 | struct FileItemNode 23 | { 24 | #if ALICE_PLATFORM_WIN 25 | TCHAR mName[_MAX_PATH]; 26 | #elif ALICE_IPHONE || ALICE_ANDROID 27 | char mName[256]; 28 | #endif 29 | bool mbIsDir; 30 | __int64 mLastWriteTime; 31 | std::list mChildren; 32 | FileItemNode() 33 | { 34 | #if ALICE_PLATFORM_WIN 35 | wmemset(mName, 0, _MAX_PATH); 36 | #elif ALICE_IPHONE 37 | memset(mName,0,_MAX_PATH); 38 | #endif 39 | mbIsDir = false; 40 | } 41 | ~FileItemNode() 42 | { 43 | if (mbIsDir) 44 | { 45 | for (std::list::iterator iter=mChildren.begin();iter!=mChildren.end();iter++) 46 | { 47 | delete *iter; 48 | } 49 | } 50 | } 51 | }; 52 | 53 | class FileSystem 54 | { 55 | public: 56 | #if ALICE_PLATFORM_WIN 57 | static void GetFiles(LPCTSTR path, LPCTSTR filter, FileItemNode&root); 58 | static void GetFiles(LPCTSTR path, LPCTSTR relativeRootPath, LPCTSTR filter, FileItemNode&root); 59 | static bool DeleteDir(LPCTSTR path); 60 | #endif 61 | static bool SaveData(const char*filePath,Data&data); 62 | static AliceUInt32 FileSizeOf(const char* path); 63 | static bool CreateDir(std::string path); 64 | static bool CreateFile(std::string path); 65 | static bool MoveFile(const char*srcPath, const char*dstPath); 66 | static bool DeleteDir(std::string path); 67 | static bool DeleteFileWithPath(std::string path); 68 | static bool CopyFile(const char*srcPath,const char*dstPath); 69 | static bool MoveFileToTrash(const char*path); 70 | static bool isDirectoryExist(const std::string& dirPath); 71 | static bool Exists(const char*path); 72 | static bool isAbsolutePath(const std::string& path); 73 | static char* LoadFile(const char*path); 74 | static void CopyDir(const char*src,const char* dst); 75 | static bool LoadDataFromPath(const char*path,Data&data); 76 | }; 77 | } 78 | -------------------------------------------------------------------------------- /Runtime/IO/ResourceManager.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BattleFireLTD/Engine/eae9aae7dc63aec341c0bbc0a33ba7f9a136df19/Runtime/IO/ResourceManager.cpp -------------------------------------------------------------------------------- /Runtime/IO/ResourceManager.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "AliceData.h" 3 | #include "Runtime/String/FixedString.h" 4 | 5 | namespace Alice{ 6 | class ResourceManager{ 7 | public: 8 | static bool Exist(const char*path); 9 | static bool DeleteFileWithPath(const char*path); 10 | static bool CreateDir(const char*path); 11 | static bool DeleteDir(const char*path); 12 | static void CopyInternalFileOut(const char*internalPath); 13 | public: 14 | static bool ExistInternal(const char*path); 15 | static bool LoadInternalData(const char*path,Data&data); 16 | static bool RenameInternalFileName(const char*srcFile,const char*dstFile); 17 | static bool DeleteInternalFile(const char*targetFile); 18 | static bool CopyFileToInternal(const char*targetFile, const char*dstFile); 19 | static bool MoveInternalFile(const char*srcFile, const char*dstFile); 20 | static bool SaveInternalData(const char*targetPath, Data&data); 21 | static bool CreateInternalFile(const char*targetPath); 22 | 23 | static bool LoadOuterData(const char*path,Data&data); 24 | static bool LoadBuiltinData(const char*path,Data&data); 25 | //the caller is response to invoke the delete method to destroy the resource 26 | static bool LoadData(const char*path,Data&data,FixedString *realPath=nullptr); 27 | private: 28 | static bool LoadDataFromRuntimeDataPath(const char*path, Data&data, FixedString *realPath = nullptr); 29 | static bool LoadDataFromBuiltinDataPath(const char*path, Data&data, FixedString *realPath = nullptr); 30 | public: 31 | static void Init(); 32 | static FixedString*mAssetsDir; 33 | static FixedString*mDataDir; 34 | static FixedString*mDocumentDir; 35 | static FixedString*mDesktopDir; 36 | }; 37 | } 38 | -------------------------------------------------------------------------------- /Runtime/String/FixedString.cpp: -------------------------------------------------------------------------------- 1 | #include "FixedString.h" 2 | #include "Runtime/Allocator/AliceMemory.h" 3 | #include "StringUtils.h" 4 | 5 | namespace Alice{ 6 | FixedString::FixedString() :mText(nullptr), mLen(0),mBufferSize(0){ 7 | } 8 | FixedString::FixedString(int len):mLen(0), mBufferSize(len){ 9 | mText = new (kMemDefaultId)char[len]; 10 | memset(mText, 0, len); 11 | } 12 | FixedString::~FixedString(){ 13 | if (mText != nullptr){ 14 | delete [] mText; 15 | mText = nullptr; 16 | } 17 | mLen = 0; 18 | mBufferSize = 0; 19 | } 20 | void FixedString::Resize(int len){ 21 | if (mText!=nullptr){ 22 | delete [] mText; 23 | } 24 | mText = new (kMemDefaultId)char[len]; 25 | memset(mText, 0, len); 26 | mBufferSize = len; 27 | mLen = 0; 28 | } 29 | bool FixedString::operator==(const char*text){ 30 | return strcmp(text, mText) == 0; 31 | } 32 | bool FixedString::operator==(const FixedString&str){ 33 | return strcmp(str.mText, mText) == 0; 34 | } 35 | bool FixedString::operator==(const std::string&str){ 36 | return strcmp(str.c_str(), mText) == 0; 37 | } 38 | void FixedString::operator=(const char*text){ 39 | int nLen = strlen(text); 40 | if (nLen < mBufferSize) { 41 | memset(mText, 0, mBufferSize); 42 | strcpy(mText, text); 43 | mLen = nLen; 44 | }else{ 45 | memcpy(mText, text, mBufferSize-1); 46 | mLen = mBufferSize; 47 | mText[mBufferSize - 1] = '\0'; 48 | } 49 | } 50 | void FixedString::operator=(const FixedString&str) { 51 | *this = str.mText; 52 | } 53 | void FixedString::operator=(const std::string&str) { 54 | *this = str.c_str(); 55 | } 56 | void FixedString::Set(const char * str, int len) { 57 | if ((len+1) > mBufferSize) { 58 | Resize(len + 1); 59 | } 60 | memcpy(mText, str, len); 61 | mLen = len; 62 | mText[len] = '\0'; 63 | } 64 | bool FixedString::operator!=(const char*text){ 65 | return strcmp(text, mText) != 0; 66 | } 67 | bool FixedString::operator!=(const FixedString&str){ 68 | return strcmp(str.mText, mText) != 0; 69 | } 70 | bool FixedString::operator!=(const std::string&str){ 71 | return strcmp(str.c_str(), mText) != 0; 72 | } 73 | void FixedString::operator >> (char*buffer){ 74 | strcpy(buffer, mText); 75 | } 76 | void FixedString::operator<< (const char*buffer){ 77 | int nLen = strlen(buffer); 78 | if (nLen + mLen < mBufferSize) { 79 | strcat(mText, buffer); 80 | mLen += nLen; 81 | } 82 | else { 83 | memcpy(mText+mLen, buffer, mBufferSize - 1 - mLen); 84 | mLen = mBufferSize; 85 | mText[mBufferSize - 1] = '\0'; 86 | } 87 | } 88 | bool FixedString::StartWith(const char*start){ 89 | return StringUtils::StartWith(mText, start); 90 | } 91 | bool FixedString::EndWith(const char*end){ 92 | return StringUtils::EndWith(mText, end); 93 | } 94 | void FixedString::TrimEnd(const char*end){ 95 | StringUtils::TrimEnd(mText, end); 96 | } 97 | void FixedString::TrimEndWithByteCount(int nLen){ 98 | if (nLen<=mLen){ 99 | memset(mText + mLen - nLen, 0, nLen); 100 | mLen -= nLen; 101 | } 102 | } 103 | void FixedString::TrimExtension(){ 104 | StringUtils::TrimFileExtension(mText); 105 | } 106 | void FixedString::ToLuaPath(){ 107 | StringUtils::ToLuaPath(mText); 108 | } 109 | void FixedString::ToSTDPath(){ 110 | StringUtils::ToSTDPath(mText); 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /Runtime/String/FixedString.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | namespace Alice{ 4 | class FixedString{ 5 | public: 6 | char*mText; 7 | int mLen; 8 | int mBufferSize; 9 | private: 10 | FixedString(const FixedString&r) {} 11 | public: 12 | FixedString(); 13 | FixedString(int len); 14 | ~FixedString(); 15 | void Resize(int len); 16 | void Set(const char * str, int len); 17 | bool operator==(const char*text); 18 | bool operator==(const FixedString&str); 19 | bool operator==(const std::string&str); 20 | void operator=(const char*text); 21 | void operator=(const FixedString&str); 22 | void operator=(const std::string&str); 23 | bool operator!=(const char*text); 24 | bool operator!=(const FixedString&str); 25 | bool operator!=(const std::string&str); 26 | //copy fixed string text to buffer 27 | void operator >> (char*buffer); 28 | //append text to text 29 | void operator << (const char*buffer); 30 | bool StartWith(const char*start); 31 | bool EndWith(const char*end); 32 | void TrimEnd(const char*end); 33 | void TrimEndWithByteCount(int nLen); 34 | void TrimExtension(); 35 | void ToSTDPath(); 36 | void ToLuaPath(); 37 | }; 38 | } -------------------------------------------------------------------------------- /Runtime/String/StringUtils.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BattleFireLTD/Engine/eae9aae7dc63aec341c0bbc0a33ba7f9a136df19/Runtime/String/StringUtils.cpp -------------------------------------------------------------------------------- /Runtime/String/StringUtils.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Runtime/BattleFirePrefix.h" 3 | namespace Alice 4 | { 5 | struct UTF32Char 6 | { 7 | AliceUInt32 mCharCode; 8 | AliceUInt32 mByteCount; 9 | }; 10 | class StringUtils 11 | { 12 | public: 13 | static int UTF8ToUTF32(const unsigned char*src, int srcLen, UTF32Char *dst); 14 | static int UTF8ToUTF32(const unsigned char*src,int srcLen,AliceUInt32 *dst); 15 | static bool UTF32ToUTF8(const AliceUInt32*src, int srcLen, unsigned char*dst); 16 | static bool UTF32CharToUTF8(const AliceUInt32 src, unsigned char*dst, int &len); 17 | static bool UTF32CharToUTF16(const char32_t u32Ch, AliceSInt16 * u16Ch); 18 | static int UTF8CharLen(char ch); 19 | static bool IsUTF8Char(char ch); 20 | static int UTF82UTF32(const AliceUInt8 * src, AliceUInt32 & dst); 21 | #ifdef _WIN32 22 | static int UnicodeToUTF32(const wchar_t*src, AliceUInt32 *dst); 23 | static void UnicodeToUTF8(const wchar_t*src,char *dst); 24 | static void UnicodeToASCII(const wchar_t *wchar, char *chr, int length); 25 | static void ASCIIToUnicode(const char*pStr, LPTSTR pDst); 26 | static void UTF8ToUnicode(const char*pStr, LPTSTR pDst); 27 | static int GetStringLen(LPTSTR str); 28 | template 29 | static bool SortName(const T &l, const T &r) 30 | { 31 | char lName[64]; 32 | char rName[64]; 33 | memset(lName, 0, 64); 34 | memset(rName, 0, 64); 35 | StringUtils::UnicodeToASCII(l->mName, lName, 64); 36 | StringUtils::UnicodeToASCII(r->mName, rName, 64); 37 | if (strcmp(lName, rName) < 0) 38 | { 39 | return true; 40 | } 41 | return false; 42 | } 43 | #endif 44 | #if ALICE_EDITOR||ALICE_WIN_PLAYER 45 | static void TrimStart(LPTSTR original,LPCTSTR startToTrim); 46 | static void TrimEnd(LPTSTR original, LPCTSTR endToTrim); 47 | static bool EndWith(LPCTSTR original, LPCTSTR end); 48 | static LPCTSTR GetFileExtensionFromPathT(LPCTSTR path); 49 | #endif 50 | 51 | static void TrimStart(char* original, const char* startToTrim); 52 | static void TrimEnd(char* original, const char* endToTrim); 53 | static bool EndWith(const char * original, const char* end); 54 | static bool EndWithI(const char * original, const char* end); 55 | static bool StartWith(const char *original,const char*start); 56 | static void SplitPathToComponent(char*path,std::vector&components); 57 | //return the file type extension,etc .png .jpg 58 | static const char* GetFileExtensionFromPath(const char*path); 59 | //return the dir of the file 60 | static void GetDirFromFullPath(const char*path,char*dir); 61 | static void TrimFileExtension(char*path); 62 | static void GetFileNameWithOutExtension(const char*path,char *name); 63 | //convert '\' to '/' 64 | static void ToSTDPath(char*buffer); 65 | static void ToLuaPath(char*path); 66 | static void LuaPathToSTDPath(char*path); 67 | static void ToWindowsPath(char*path); 68 | // 69 | static int GetNextPosOf(const char*buffer, int len, char c); 70 | static int GetNextPosOfLine(char*buffer, int len, char c); 71 | static int GetNextPosOfInvert(const char*buffer, int len, char c); 72 | static void URLEncode(const char *input, int len, char *output); 73 | static int URLDecode(const char *input, int len, char *output); 74 | static bool IsNoneSymbol(char c); 75 | static void BytesToHexStr(const unsigned char *bytes,int len,char * buffer); 76 | }; 77 | } 78 | -------------------------------------------------------------------------------- /Runtime/Utils/LinkedList.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | namespace Alice 3 | { 4 | class LinkedList{ 5 | public: 6 | LinkedList() :mNext(nullptr){ 7 | } 8 | virtual void PushBack(LinkedList*node){ 9 | if (mNext==nullptr){ 10 | mNext = node; 11 | }else{ 12 | if (mNext==node){ 13 | return; 14 | } 15 | Next()->PushBack(node); 16 | } 17 | } 18 | virtual void Remove(LinkedList*node){ 19 | if (mNext!=nullptr){ 20 | if (node==mNext){ 21 | mNext = node->Next(); 22 | node->mNext = nullptr; 23 | }else{ 24 | Next()->Remove(node); 25 | } 26 | } 27 | } 28 | LinkedList*mNext; 29 | template 30 | T* Next(){ 31 | return (T*)mNext; 32 | } 33 | }; 34 | class DoubleLinkedList{ 35 | public: 36 | DoubleLinkedList() :mPrev(nullptr),mNext(nullptr){ 37 | } 38 | virtual ~DoubleLinkedList(){ 39 | LeaveList(); 40 | } 41 | //move up 42 | void operator<<(int nGAP){ 43 | DoubleLinkedList*nodeToShift = this; 44 | DoubleLinkedList*targetPos = Prev(); 45 | while (--nGAP){ 46 | targetPos = targetPos->Prev(); 47 | } 48 | nodeToShift->InsertBefore(targetPos); 49 | } 50 | //move down 51 | void operator>>(int nGAP){ 52 | DoubleLinkedList*nodeToShift = this; 53 | DoubleLinkedList*targetPos = Next(); 54 | while (--nGAP){ 55 | targetPos = targetPos->Next(); 56 | } 57 | nodeToShift->InsertAfter(targetPos); 58 | } 59 | void Append(DoubleLinkedList*node){ 60 | if (mNext!=nullptr){ 61 | mNext->Append(node); 62 | }else{ 63 | mNext = node; 64 | node->mPrev = this; 65 | } 66 | } 67 | void InsertBefore(DoubleLinkedList*node){ 68 | LeaveList(); 69 | if (node->mPrev!=nullptr){ 70 | node->mPrev->mNext = this; 71 | } 72 | mPrev = node->mPrev; 73 | node->mPrev = this; 74 | mNext = node; 75 | } 76 | void InsertAfter(DoubleLinkedList*node){ 77 | LeaveList(); 78 | if (node->mNext != nullptr){ 79 | node->mNext->mPrev = this; 80 | } 81 | mNext = node->mNext; 82 | node->mNext = this; 83 | mPrev = node; 84 | } 85 | void LeaveList(){ 86 | if (mPrev!=nullptr){ 87 | mPrev->mNext = mNext; 88 | } 89 | if (mNext!=nullptr){ 90 | mNext->mPrev = mPrev; 91 | } 92 | mPrev = nullptr; 93 | mNext = nullptr; 94 | } 95 | public: 96 | DoubleLinkedList*mPrev; 97 | DoubleLinkedList*mNext; 98 | public: 99 | template 100 | T* Next(){ 101 | return (T*)mNext; 102 | } 103 | template 104 | T* Prev(){ 105 | return (T*)mPrev; 106 | } 107 | }; 108 | } -------------------------------------------------------------------------------- /Runtime/Utils/SmartPtr.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | template 4 | class SmartPtr 5 | { 6 | public: 7 | SmartPtr(T*ptr=nullptr) :mPtr(ptr) { if (nullptr!=mPtr){ mPtr->retain(); }} 8 | ~SmartPtr() { if (mPtr != nullptr) { mPtr->release(); } } 9 | T*mPtr; 10 | T*Release() { if (mPtr != nullptr) { mPtr->release(); }return mPtr; } 11 | T* operator ->() { return mPtr; } 12 | T* operator ->() const { return mPtr; } 13 | T& operator*() { return *mPtr;} 14 | bool operator==(T*ptr) { return mPtr == ptr; } 15 | bool operator!=(T*ptr) { return mPtr != ptr; } 16 | bool operator==(SmartPtr&r) { return mPtr == r.mPtr; } 17 | void operator=(SmartPtr&r) { 18 | if (r.mPtr!=nullptr){ 19 | r.mPtr->retain(); 20 | } 21 | if (mPtr!=nullptr){ 22 | mPtr->release(); 23 | } 24 | mPtr = r.mPtr; 25 | } 26 | 27 | void operator=(T*ptr) { 28 | if (ptr != nullptr) { 29 | ptr->retain(); 30 | } 31 | if (mPtr != nullptr) 32 | mPtr->release(); 33 | mPtr = ptr; 34 | } 35 | }; 36 | -------------------------------------------------------------------------------- /Runtime/Utils/TTree.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BattleFireLTD/Engine/eae9aae7dc63aec341c0bbc0a33ba7f9a136df19/Runtime/Utils/TTree.cpp -------------------------------------------------------------------------------- /Runtime/Utils/TTree.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | namespace Alice{ 4 | class TTree{ 5 | public: 6 | TTree* mParent; 7 | TTree* mChild; 8 | TTree* mLeftSibling; 9 | TTree* mRightSibling; 10 | TTree* mLastChild; 11 | public: 12 | TTree(); 13 | virtual ~TTree(); 14 | bool AppendChild(TTree*node); 15 | bool InsertBefore(TTree*before); 16 | bool InsertAfter(TTree*after); 17 | void RemoveChild(TTree*node); 18 | bool IsParent(TTree*node); 19 | void Clean(); 20 | template 21 | T* LeftSibling(){ 22 | return (T*)mLeftSibling; 23 | } 24 | template 25 | T* RightSibling(){ 26 | return (T*)mRightSibling; 27 | } 28 | template 29 | T* Child(){ 30 | return (T*)mChild; 31 | } 32 | template 33 | T* Parent(){ 34 | return (T*)mParent; 35 | } 36 | template 37 | T* LastChild() { 38 | return (T*)mLastChild; 39 | } 40 | }; 41 | } -------------------------------------------------------------------------------- /ScreenShot/1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BattleFireLTD/Engine/eae9aae7dc63aec341c0bbc0a33ba7f9a136df19/ScreenShot/1.jpg -------------------------------------------------------------------------------- /ScreenShot/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BattleFireLTD/Engine/eae9aae7dc63aec341c0bbc0a33ba7f9a136df19/ScreenShot/1.png -------------------------------------------------------------------------------- /ScreenShot/2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BattleFireLTD/Engine/eae9aae7dc63aec341c0bbc0a33ba7f9a136df19/ScreenShot/2.jpg -------------------------------------------------------------------------------- /ScreenShot/3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BattleFireLTD/Engine/eae9aae7dc63aec341c0bbc0a33ba7f9a136df19/ScreenShot/3.jpg -------------------------------------------------------------------------------- /ScreenShot/4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BattleFireLTD/Engine/eae9aae7dc63aec341c0bbc0a33ba7f9a136df19/ScreenShot/4.jpg -------------------------------------------------------------------------------- /Tools/PlatformWindowsSeriallizer.proto: -------------------------------------------------------------------------------- 1 | syntax="proto3"; 2 | package PlatformWindowsSeriallizer; 3 | message WinResources{ 4 | map res=1; 5 | } 6 | -------------------------------------------------------------------------------- /Tools/buildSerillizer.bat: -------------------------------------------------------------------------------- 1 | protoc.exe PlatformWindowsSeriallizer.proto --cpp_out=../Platform/Windows/Common 2 | @pause -------------------------------------------------------------------------------- /Tools/protoc.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BattleFireLTD/Engine/eae9aae7dc63aec341c0bbc0a33ba7f9a136df19/Tools/protoc.exe --------------------------------------------------------------------------------