diff options
Diffstat (limited to 'Source/Asura.Editor')
53 files changed, 1216 insertions, 0 deletions
diff --git a/Source/Asura.Editor/Configure/BuildConfigure.h b/Source/Asura.Editor/Configure/BuildConfigure.h new file mode 100644 index 0000000..6fd3aad --- /dev/null +++ b/Source/Asura.Editor/Configure/BuildConfigure.h @@ -0,0 +1,8 @@ +// Copy to asura-configure folder + +#ifndef _ASURA_EDITOR_CONFIGURE_H_ +#define _ASURA_EDITOR_CONFIGURE_H_ + +#define ASURA_EDITOR 1 + +#endif
\ No newline at end of file diff --git a/Source/Asura.Editor/Controls/GUIButton.cpp b/Source/Asura.Editor/Controls/GUIButton.cpp new file mode 100644 index 0000000..f168982 --- /dev/null +++ b/Source/Asura.Editor/Controls/GUIButton.cpp @@ -0,0 +1,11 @@ +#include "GUIButton.h" + +namespace_begin(AsuraEditor) + +bool GUIButton() +{ + return false; +} + + +namespace_end diff --git a/Source/Asura.Editor/Controls/GUIButton.h b/Source/Asura.Editor/Controls/GUIButton.h new file mode 100644 index 0000000..e1199db --- /dev/null +++ b/Source/Asura.Editor/Controls/GUIButton.h @@ -0,0 +1,14 @@ +#ifndef _ASURA_EDITOR_GUI_BUTTON_H_ +#define _ASURA_EDITOR_GUI_BUTTON_H_ + +#include <asura-base/Classes.h> + +namespace_begin(AsuraEditor) + +bool GUIButton(); + + + +namespace_end + +#endif diff --git a/Source/Asura.Editor/Controls/GUIClip.cpp b/Source/Asura.Editor/Controls/GUIClip.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Source/Asura.Editor/Controls/GUIClip.cpp diff --git a/Source/Asura.Editor/Controls/GUIClip.h b/Source/Asura.Editor/Controls/GUIClip.h new file mode 100644 index 0000000..38b6094 --- /dev/null +++ b/Source/Asura.Editor/Controls/GUIClip.h @@ -0,0 +1,6 @@ +#ifndef _ASURA_GUICLIP_H_ +#define _ASURA_GUICLIP_H_ + + + +#endif diff --git a/Source/Asura.Editor/Controls/GUIContent.cpp b/Source/Asura.Editor/Controls/GUIContent.cpp new file mode 100644 index 0000000..c5741c1 --- /dev/null +++ b/Source/Asura.Editor/Controls/GUIContent.cpp @@ -0,0 +1,8 @@ +#include "gui_button.h" + +namespace_begin(AsuraEditor) + + + + +namespace_end diff --git a/Source/Asura.Editor/Controls/GUIContent.h b/Source/Asura.Editor/Controls/GUIContent.h new file mode 100644 index 0000000..88213f4 --- /dev/null +++ b/Source/Asura.Editor/Controls/GUIContent.h @@ -0,0 +1,17 @@ +#ifndef _ASURA_EDITOR_GUI_CONTENT_H_ +#define _ASURA_EDITOR_GUI_CONTENT_H_ + +#include <asura-base/Classes.h> + +namespace_begin(AsuraEditor) + +/// IMGUI content +class GUIContent +{ + +}; + + +namespace_end + +#endif diff --git a/Source/Asura.Editor/Controls/GUILabel.cpp b/Source/Asura.Editor/Controls/GUILabel.cpp new file mode 100644 index 0000000..90b277b --- /dev/null +++ b/Source/Asura.Editor/Controls/GUILabel.cpp @@ -0,0 +1,8 @@ +#include "GUIButton.h" + +namespace_begin(AsuraEditor) + + + + +namespace_end diff --git a/Source/Asura.Editor/Controls/GUILabel.h b/Source/Asura.Editor/Controls/GUILabel.h new file mode 100644 index 0000000..d4e2d28 --- /dev/null +++ b/Source/Asura.Editor/Controls/GUILabel.h @@ -0,0 +1,14 @@ +#ifndef _ASURA_EDITOR_GUI_LABEL_H_ +#define _ASURA_EDITOR_GUI_LABEL_H_ + +#include <asura-base/Classes.h> + +namespace_begin(AsuraEditor) + +bool GUILabel(); + + + +namespace_end + +#endif diff --git a/Source/Asura.Editor/Controls/GUIPanel.cpp b/Source/Asura.Editor/Controls/GUIPanel.cpp new file mode 100644 index 0000000..3a78af7 --- /dev/null +++ b/Source/Asura.Editor/Controls/GUIPanel.cpp @@ -0,0 +1,6 @@ +#include "GUIPanel.h" + +namespace_begin(AsuraEditor) + + +namespace_end diff --git a/Source/Asura.Editor/Controls/GUIPanel.h b/Source/Asura.Editor/Controls/GUIPanel.h new file mode 100644 index 0000000..105edde --- /dev/null +++ b/Source/Asura.Editor/Controls/GUIPanel.h @@ -0,0 +1,16 @@ +#ifndef _ASURA_EDITOR_GUI_PANEL_H_ +#define _ASURA_EDITOR_GUI_PANEL_H_ + +#include <asura-base/Classes.h> + +namespace_begin(AsuraEditor) + +/// IMGUI panel +class GUIPanel +{ + +}; + +namespace_end + +#endif diff --git a/Source/Asura.Editor/Controls/GUISlider.cpp b/Source/Asura.Editor/Controls/GUISlider.cpp new file mode 100644 index 0000000..9c20d5f --- /dev/null +++ b/Source/Asura.Editor/Controls/GUISlider.cpp @@ -0,0 +1,8 @@ +#include "GUISlider.h" + +namespace_begin(AsuraEditor) + + + + +namespace_end diff --git a/Source/Asura.Editor/Controls/GUISlider.h b/Source/Asura.Editor/Controls/GUISlider.h new file mode 100644 index 0000000..94691c3 --- /dev/null +++ b/Source/Asura.Editor/Controls/GUISlider.h @@ -0,0 +1,14 @@ +#ifndef _ASURA_EDITOR_GUI_SLIDER_H_ +#define _ASURA_EDITOR_GUI_SLIDER_H_ + +#include <asura-base/Classes.h> + +namespace_begin(AsuraEditor) + +void GUISlider(); + + +namespace_end + + +#endif diff --git a/Source/Asura.Editor/Controls/GUIToggle.cpp b/Source/Asura.Editor/Controls/GUIToggle.cpp new file mode 100644 index 0000000..7871098 --- /dev/null +++ b/Source/Asura.Editor/Controls/GUIToggle.cpp @@ -0,0 +1 @@ +#include "GUIToggle.h" diff --git a/Source/Asura.Editor/Controls/GUIToggle.h b/Source/Asura.Editor/Controls/GUIToggle.h new file mode 100644 index 0000000..64632be --- /dev/null +++ b/Source/Asura.Editor/Controls/GUIToggle.h @@ -0,0 +1,16 @@ +#ifndef _ASURA_EDITOR_GUI_TOGGLE_H_ +#define _ASURA_EDITOR_GUI_TOGGLE_H_ + +#include <asura-base/Classes.h> + +namespace_begin(AsuraEditor) + +/// Radio button \ toggle button + +bool GUIToggle(); + + + +namespace_end + +#endif diff --git a/Source/Asura.Editor/Controls/TextUtil.cpp b/Source/Asura.Editor/Controls/TextUtil.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Source/Asura.Editor/Controls/TextUtil.cpp diff --git a/Source/Asura.Editor/Controls/TextUtil.h b/Source/Asura.Editor/Controls/TextUtil.h new file mode 100644 index 0000000..40c5114 --- /dev/null +++ b/Source/Asura.Editor/Controls/TextUtil.h @@ -0,0 +1,37 @@ +#ifndef _ASURA_EDITOR_TEXTUTIL_H_ +#define _ASURA_EDITOR_TEXTUTIL_H_ + +#include <asura-base/Classes.h> + +namespace_begin(AsuraEditor) + +enum TextAlignment { + kLeft, + kCenter, + kRight, + kAuto, +}; + +enum TextAnchor { + kUpperLeft, + kUpperCenter, + kUpperRight, + kMiddleLeft, + kMiddleCenter, + kMiddleRight, + kLowerLeft, + kLowerCenter, + kLowerRight, + kDontCare ///< Special case for getting text mesh generators: The anchoring used for the text doesn't modify the size of the generated text, so if you just want to query for it you don't care about anchoring +}; + +enum TextClipping { + /// Text flows freely outside the element. + kOverflow = 0, + /// Text gets clipped to be inside the element. + kClip = 1, +}; + +namespace_end + +#endif
\ No newline at end of file diff --git a/Source/Asura.Editor/Core/GUIState.h b/Source/Asura.Editor/Core/GUIState.h new file mode 100644 index 0000000..b4fce49 --- /dev/null +++ b/Source/Asura.Editor/Core/GUIState.h @@ -0,0 +1,27 @@ +#ifndef _ASURA_EDITOR_GUI_STATE_H_ +#define _ASURA_EDITOR_GUI_STATE_H_ + +#include <asura-base/Classes.h> + +namespace_begin(AsuraEditor) + +/// GUI widgets uniqueID +class GUIState +{ +public: + + inline int GetDepth() { return m_Depth; }; + +private: + + int m_Depth; + bool m_Changed; + +}; + +extern GUIState g_GUIState; + +namespace_end + + +#endif
\ No newline at end of file diff --git a/Source/Asura.Editor/Editor.cpp b/Source/Asura.Editor/Editor.cpp new file mode 100644 index 0000000..6ffd789 --- /dev/null +++ b/Source/Asura.Editor/Editor.cpp @@ -0,0 +1,51 @@ +#include "Editor.h" + +#include <vector> + +namespace_begin(AsuraEditor) + +void TranslateAndDispatch(MSG& msg) +{ + //if (g_BatchMode || !TranslateAccelerator(gMainWindow, GetMainMenuAccelerators(), &msg)) + //{ + // ResetGfxDeviceIfNeeded(); + // TranslateMessage(&msg); + // DispatchMessage(&msg); + //} +} + +int MainMessageLoop() +{ + MSG msg, lastMsg; + msg.message = WM_NULL; + std::vector<MSG> messages; + PeekMessage(&msg, NULL, 0U, 0U, PM_NOREMOVE); + bool isQuit = msg.message == WM_QUIT; + while (!isQuit) + { + messages.clear(); + while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) + { + if (msg.message == WM_INPUT || msg.message == WM_PAINT) + { + + } + + if (msg.message == WM_QUIT) + isQuit = true; + + messages.push_back(msg); + + if (messages.size() > 100) + break; + } + + for (unsigned i = 0; i < messages.size(); ++i) + { + msg = messages[i]; + } + } +} + + +namespace_end
\ No newline at end of file diff --git a/Source/Asura.Editor/Editor.h b/Source/Asura.Editor/Editor.h new file mode 100644 index 0000000..01a5b37 --- /dev/null +++ b/Source/Asura.Editor/Editor.h @@ -0,0 +1,16 @@ +#ifndef _ASURA_EDITOR_H_ +#define _ASURA_EDITOR_H_ + +#include <asura-base/Scripting/Scripting.h> +#include <asura-base/Classes.h> + +#include <windows.h> + +namespace_begin(AsuraEditor) + +int MainMessageLoop(); +void TranslateAndDispatch(MSG& msg); + +namespace_end + +#endif
\ No newline at end of file diff --git a/Source/Asura.Editor/Editor/asset_view.lua b/Source/Asura.Editor/Editor/asset_view.lua new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Source/Asura.Editor/Editor/asset_view.lua diff --git a/Source/Asura.Editor/Editor/compile.bat b/Source/Asura.Editor/Editor/compile.bat new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Source/Asura.Editor/Editor/compile.bat diff --git a/Source/Asura.Editor/Editor/compile.sh b/Source/Asura.Editor/Editor/compile.sh new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Source/Asura.Editor/Editor/compile.sh diff --git a/Source/Asura.Editor/Editor/idea.txt b/Source/Asura.Editor/Editor/idea.txt new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Source/Asura.Editor/Editor/idea.txt diff --git a/Source/Asura.Editor/Editor/main.lua b/Source/Asura.Editor/Editor/main.lua new file mode 100644 index 0000000..76fab7a --- /dev/null +++ b/Source/Asura.Editor/Editor/main.lua @@ -0,0 +1,4 @@ + +--༭ +--༭Asura.Editor/scriptsʵ + diff --git a/Source/Asura.Editor/Editor/scene_view.lua b/Source/Asura.Editor/Editor/scene_view.lua new file mode 100644 index 0000000..b6097f3 --- /dev/null +++ b/Source/Asura.Editor/Editor/scene_view.lua @@ -0,0 +1,4 @@ +-- 场景窗口 +local scene = AsuraEditor.Window.New("Window/Scene View") + + diff --git a/Source/Asura.Editor/Graphics/Brush.cpp b/Source/Asura.Editor/Graphics/Brush.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Source/Asura.Editor/Graphics/Brush.cpp diff --git a/Source/Asura.Editor/Graphics/Brush.h b/Source/Asura.Editor/Graphics/Brush.h new file mode 100644 index 0000000..4290926 --- /dev/null +++ b/Source/Asura.Editor/Graphics/Brush.h @@ -0,0 +1,20 @@ +#ifndef _ASURA_EDITOR_BRUSH_H_ +#define _ASURA_EDITOR_BRUSH_H_ + +namespace AsuraEditor +{ + namespace Graphics + { + + /// + /// ˢָģʽ + /// + class Brush + { + + }; + + } +} + +#endif
\ No newline at end of file diff --git a/Source/Asura.Editor/Graphics/DrawInfo.cpp b/Source/Asura.Editor/Graphics/DrawInfo.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Source/Asura.Editor/Graphics/DrawInfo.cpp diff --git a/Source/Asura.Editor/Graphics/DrawInfo.h b/Source/Asura.Editor/Graphics/DrawInfo.h new file mode 100644 index 0000000..f399b41 --- /dev/null +++ b/Source/Asura.Editor/Graphics/DrawInfo.h @@ -0,0 +1,16 @@ +#ifndef _ASURA_EDITOR_DRAW_INFO_H_ +#define _ASURA_EDITOR_DRAW_INFO_H_ + +#include <asura-base/Classes.h> + +namespace_begin(AsuraEditor) + +class DrawInfo +{ + +}; + + +namespace_end + +#endif
\ No newline at end of file diff --git a/Source/Asura.Editor/Graphics/Drawer.cpp b/Source/Asura.Editor/Graphics/Drawer.cpp new file mode 100644 index 0000000..6482aeb --- /dev/null +++ b/Source/Asura.Editor/Graphics/Drawer.cpp @@ -0,0 +1,16 @@ +#include "Drawer.h" + +using namespace AEGraphics; + +namespace AsuraEditor +{ + namespace Graphics + { + + void Drawer::DrawImage(Image* img) + { + + } + + } +}
\ No newline at end of file diff --git a/Source/Asura.Editor/Graphics/Drawer.h b/Source/Asura.Editor/Graphics/Drawer.h new file mode 100644 index 0000000..4adfa3f --- /dev/null +++ b/Source/Asura.Editor/Graphics/Drawer.h @@ -0,0 +1,40 @@ +#ifndef _ASURA_EDITOR_PAINTER_H_ +#define _ASURA_EDITOR_PAINTER_H_ + +#include <asura-base/Scripting/Scripting.h> +#include <asura-base/Singleton.hpp> +#include <asura-core/Graphics/Image.h> + +namespace AsuraEditor +{ + namespace Graphics + { + + /// + /// AsuraEngineȾֵĻ滭࣬ڻƿؼ֮֡Բֱ沿ֵȾ + /// ΪȾframeworkʵ֣иijؼȾҪӵpass + /// ༭£Ⱦͱ༭ȾԻࡣ + /// + class Drawer + : public AsuraEngine::Singleton<Drawer> + , public AEScripting::Portable<Drawer> + { + public: + + void DrawLine(int x1, int y1, int x2, int y2); + void DrawImage(AEGraphics::Image* img, int x, int y, float sx, float sy, float r, int ox, int oy); + void DrawTexts(); + void DrawCircle(int x, int y, float d); + void DrawPoint(int x, int y); + void DrawPolyline(); + + private: + + LUAX_DECL_SINGLETON(Drawer); + + }; + + } +} + +#endif
\ No newline at end of file diff --git a/Source/Asura.Editor/Graphics/Pen.cpp b/Source/Asura.Editor/Graphics/Pen.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Source/Asura.Editor/Graphics/Pen.cpp diff --git a/Source/Asura.Editor/Graphics/Pen.h b/Source/Asura.Editor/Graphics/Pen.h new file mode 100644 index 0000000..b949d14 --- /dev/null +++ b/Source/Asura.Editor/Graphics/Pen.h @@ -0,0 +1,7 @@ +#ifndef _ASURA_EDITOR_PEN_H_ +#define _ASURA_EDITOR_PEN_H_ + + + + +#endif
\ No newline at end of file diff --git a/Source/Asura.Editor/Graphics/Shader.h b/Source/Asura.Editor/Graphics/Shader.h new file mode 100644 index 0000000..a3abec1 --- /dev/null +++ b/Source/Asura.Editor/Graphics/Shader.h @@ -0,0 +1,18 @@ +#ifndef _ASURA_EDITOR_SHADER_H_ +#define _ASURA_EDITOR_SHADER_H_ + +namespace AsuraEditor +{ + namespace Graphics + { + + struct ShaderProgram + { + const char* vert; + const char* frag; + }; + + } +} + +#endif
\ No newline at end of file diff --git a/Source/Asura.Editor/Graphics/Style.cpp b/Source/Asura.Editor/Graphics/Style.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Source/Asura.Editor/Graphics/Style.cpp diff --git a/Source/Asura.Editor/Graphics/Style.h b/Source/Asura.Editor/Graphics/Style.h new file mode 100644 index 0000000..2676c68 --- /dev/null +++ b/Source/Asura.Editor/Graphics/Style.h @@ -0,0 +1,15 @@ +#ifndef _ASURA_EDITOR_GUI_STYLE_H_ +#define _ASURA_EDITOR_GUI_STYLE_H_ + +#include <asura-base/Classes.h> + +namespace_begin(AsuraEditor) + +class GUIStyle +{ + +}; + +namespace_end + +#endif
\ No newline at end of file diff --git a/Source/Asura.Editor/Graphics/shaders/image.shader.h b/Source/Asura.Editor/Graphics/shaders/image.shader.h new file mode 100644 index 0000000..cbdd542 --- /dev/null +++ b/Source/Asura.Editor/Graphics/shaders/image.shader.h @@ -0,0 +1,35 @@ +#ifndef _ASURA_EDITOR_SHADER_H_ +#include "../shader.h" +#endif + +// +static AsuraEditor::Graphics::ShaderProgram image_shader = +{ +R"( +in vec2 asura_position; +in vec2 asura_texcoord0; + +uniform mat4 asura_model_matrix; +uniform mat4 asura_view_matrix; +uniform mat4 asura_projection_matrix; + +void main() +{ + gl_Position = asura_projection_matrix * asura_view_matrix * asura_model_matrix * vec4(asura_position, 0, 1); + uv = asura_texcoord0; +} + +)", + +R"( +in vec2 uv; + +uniform sampler2D asura_maintex; + +void main() +{ + +} + +)" +};
\ No newline at end of file diff --git a/Source/Asura.Editor/Graphics/shaders/polygon.shader.h b/Source/Asura.Editor/Graphics/shaders/polygon.shader.h new file mode 100644 index 0000000..a92e9a6 --- /dev/null +++ b/Source/Asura.Editor/Graphics/shaders/polygon.shader.h @@ -0,0 +1,29 @@ +#ifndef _ASURA_EDITOR_SHADER_H_ +#include "../shader.h" +#endif + +// +static AsuraEditor::Graphics::ShaderProgram polygon_shader = +{ + R"( +in vec2 position; + +uniform mat4 mvp_matrix; + +void main() +{ + gl_Position = mvp_matrix * vec4(position, 0, 1); +} + +)", + +R"( +uniform vec4 color; + +void main() +{ + gl_FragColor = color; +} + +)" +};
\ No newline at end of file diff --git a/Source/Asura.Editor/Layout/HorizontalLayout.cpp b/Source/Asura.Editor/Layout/HorizontalLayout.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Source/Asura.Editor/Layout/HorizontalLayout.cpp diff --git a/Source/Asura.Editor/Layout/HorizontalLayout.h b/Source/Asura.Editor/Layout/HorizontalLayout.h new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Source/Asura.Editor/Layout/HorizontalLayout.h diff --git a/Source/Asura.Editor/Layout/VerticalLayout.cpp b/Source/Asura.Editor/Layout/VerticalLayout.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Source/Asura.Editor/Layout/VerticalLayout.cpp diff --git a/Source/Asura.Editor/Layout/VerticalLayout.h b/Source/Asura.Editor/Layout/VerticalLayout.h new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Source/Asura.Editor/Layout/VerticalLayout.h diff --git a/Source/Asura.Editor/Main.cpp b/Source/Asura.Editor/Main.cpp new file mode 100644 index 0000000..87207f0 --- /dev/null +++ b/Source/Asura.Editor/Main.cpp @@ -0,0 +1,33 @@ +#include <windows.h> + + + +int main(int argn, char* args[]) +{ + bool gotMsg; + MSG msg; + msg.message = WM_NULL; + PeekMessage(&msg, NULL, 0U, 0U, PM_NOREMOVE); + HANDLE hevent = (HANDLE)CreateEvent(NULL, FALSE, FALSE, NULL); + while (WM_QUIT != msg.message) + { + // Use PeekMessage() if the app is active, so we can use idle time to + // render the scene. Else, use GetMessage() to avoid eating CPU time. + //bool dontWaitForMessages = gAppActive || (!gAlreadyClosing && GetPlayerRunInBackground()) || (kPlayerPausing == GetPlayerPause()); + bool dontWaitForMessages = false; + if (dontWaitForMessages) + gotMsg = (PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE) != 0); + else + gotMsg = (GetMessage(&msg, NULL, 0U, 0U) != 0); + + if (gotMsg) { + TranslateMessage(&msg); + DispatchMessage(&msg); + } + else { + // perform main loop + //PerformMainLoop(); + } + + } +}
\ No newline at end of file diff --git a/Source/Asura.Editor/System/ContainerWindow.cpp b/Source/Asura.Editor/System/ContainerWindow.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Source/Asura.Editor/System/ContainerWindow.cpp diff --git a/Source/Asura.Editor/System/ContainerWindow.h b/Source/Asura.Editor/System/ContainerWindow.h new file mode 100644 index 0000000..5893aff --- /dev/null +++ b/Source/Asura.Editor/System/ContainerWindow.h @@ -0,0 +1,62 @@ +#ifndef _ASURA_EDITOR_WINDOW_H_ +#define _ASURA_EDITOR_WINDOW_H_ + +#include <windows.h> +#include <string.h> + +#include <asura-base/Scripting/Scripting.h> +#include <asura-base/Classes.h> + +#include "../Type.h" + +namespace_begin(AsuraEditor) + +/// +/// ༭ڵnative +/// +class ContainerWindow : public AEScripting::Portable<ContainerWindow> +{ +public: + + enum WindowStyle + { + WINDOW_STYLE_BASIC, ///< + WINDOW_STYLE_TOOL, ///< + WINDOW_STYLE_CONFIRM, ///< ȷϴ + }; + + struct WindowConfig + { + std::string title; ///< + uint x, y; ///< + uint width, height; ///< С + WindowStyle style; ///< + }; + + ContainerWindow(); + ~ContainerWindow(); + + bool Init(WindowConfig& config); + +private: + + ContainerWindow* mParent; + WindowStyle mStyle; + HWND mHWND; + HDC mHDC; + +luaxport: + + LUAX_DECL_FACTORY(ContainerWindow); + + LUAX_DECL_ENUM(WindowStyle); + + LUAX_DECL_METHOD(_New); + LUAX_DECL_METHOD(_Init); + LUAX_DECL_METHOD(_SetPosition); + +}; + +namespace_end + +#endif
\ No newline at end of file diff --git a/Source/Asura.Editor/System/FileWatcher.cpp b/Source/Asura.Editor/System/FileWatcher.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Source/Asura.Editor/System/FileWatcher.cpp diff --git a/Source/Asura.Editor/System/FileWatcher.h b/Source/Asura.Editor/System/FileWatcher.h new file mode 100644 index 0000000..43821da --- /dev/null +++ b/Source/Asura.Editor/System/FileWatcher.h @@ -0,0 +1,517 @@ +// MIT License +// +// Copyright(c) 2017 Thomas Monkman +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files(the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions : +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +#ifndef FILEWATCHER_H +#define FILEWATCHER_H + +#ifdef _WIN32 +#define WIN32_LEAN_AND_MEAN +#define NOMINMAX +#include <windows.h> +#include <stdlib.h> +#include <stdio.h> +#include <tchar.h> +#include <Pathcch.h> +#include <shlwapi.h> +#endif // WIN32 + +#if __unix__ +#include <stdio.h> +#include <stdlib.h> +#include <errno.h> +#include <sys/types.h> +#include <sys/inotify.h> +#include <sys/stat.h> +#include <unistd.h> +#endif // __unix__ + +#include <functional> +#include <atomic> +#include <thread> +#include <mutex> +#include <condition_variable> +#include <utility> +#include <vector> +#include <array> +#include <map> +#include <system_error> +#include <string> +#include <algorithm> +#include <type_traits> +#include <future> +#include <regex> + +namespace filewatch { + enum class Event { + added, + removed, + modified, + renamed_old, + renamed_new + }; + + /** + * \class FileWatch + * + * \brief Watches a folder or file, and will notify of changes via function callback. + * + * \author Thomas Monkman + * + */ + template<class T> + class FileWatch + { + typedef std::basic_string<typename T::value_type, std::char_traits<typename T::value_type>> UnderpinningString; + typedef std::basic_regex<typename T::value_type, std::regex_traits<typename T::value_type>> UnderpinningRegex; + + public: + + FileWatch(T path, UnderpinningRegex pattern, std::function<void(const T& file, const Event event_type)> callback) : + _path(path), + _pattern(pattern), + _callback(callback), + _directory(get_directory(path)) + { + init(); + } + +#if defined _WIN32 && (defined UNICODE || defined _UNICODE) + FileWatch(T path, std::function<void(const T& file, const Event event_type)> callback) : + FileWatch<T>(path, UnderpinningRegex(L".*"), callback) {} +#else // _WIN32 && (UNICODE || _UNICODE) + FileWatch(T path, std::function<void(const T& file, const Event event_type)> callback) : + FileWatch<T>(path, UnderpinningRegex(".*"), callback) {} +#endif + + ~FileWatch() { + destroy(); + } + + FileWatch(const FileWatch<T>& other) : FileWatch<T>(other._path, other._callback) {} + + FileWatch<T>& operator=(const FileWatch<T>& other) + { + if (this == &other) { return *this; } + + destroy(); + _path = other._path; + _callback = other._callback; + _directory = get_directory(other._path); + init(); + return *this; + } + + // Const memeber varibles don't let me implent moves nicely, if moves are really wanted std::unique_ptr should be used and move that. + FileWatch<T>(FileWatch<T>&&) = delete; + FileWatch<T>& operator=(FileWatch<T>&&) & = delete; + + private: + struct PathParts + { + PathParts(T directory, T filename) : directory(directory), filename(filename) {} + T directory; + T filename; + }; + const T _path; + + UnderpinningRegex _pattern; + + static constexpr std::size_t _buffer_size = { 1024 * 256 }; + + // only used if watch a single file + bool _watching_single_file = { false }; + T _filename; + + std::atomic<bool> _destory = { false }; + std::function<void(const T& file, const Event event_type)> _callback; + + std::thread _watch_thread; + + std::condition_variable _cv; + std::mutex _callback_mutex; + std::vector<std::pair<T, Event>> _callback_information; + std::thread _callback_thread; + + std::promise<void> _running; +#ifdef _WIN32 + HANDLE _directory = { nullptr }; + HANDLE _close_event = { nullptr }; + + const DWORD _listen_filters = + FILE_NOTIFY_CHANGE_SECURITY | + FILE_NOTIFY_CHANGE_CREATION | + FILE_NOTIFY_CHANGE_LAST_ACCESS | + FILE_NOTIFY_CHANGE_LAST_WRITE | + FILE_NOTIFY_CHANGE_SIZE | + FILE_NOTIFY_CHANGE_ATTRIBUTES | + FILE_NOTIFY_CHANGE_DIR_NAME | + FILE_NOTIFY_CHANGE_FILE_NAME; + + const std::map<DWORD, Event> _event_type_mapping = { + { FILE_ACTION_ADDED, Event::added }, + { FILE_ACTION_REMOVED, Event::removed }, + { FILE_ACTION_MODIFIED, Event::modified }, + { FILE_ACTION_RENAMED_OLD_NAME, Event::renamed_old }, + { FILE_ACTION_RENAMED_NEW_NAME, Event::renamed_new } + }; +#endif // WIN32 + +#if __unix__ + struct FolderInfo { + int folder; + int watch; + }; + + FolderInfo _directory; + + const std::uint32_t _listen_filters = IN_MODIFY | IN_CREATE | IN_DELETE; + + const static std::size_t event_size = (sizeof(struct inotify_event)); +#endif // __unix__ + + void init() + { +#ifdef _WIN32 + _close_event = CreateEvent(NULL, TRUE, FALSE, NULL); + if (!_close_event) { + throw std::system_error(GetLastError(), std::system_category()); + } +#endif // WIN32 + _callback_thread = std::move(std::thread([this]() { + try { + callback_thread(); + } + catch (...) { + try { + _running.set_exception(std::current_exception()); + } + catch (...) {} // set_exception() may throw too + } + })); + _watch_thread = std::move(std::thread([this]() { + try { + monitor_directory(); + } + catch (...) { + try { + _running.set_exception(std::current_exception()); + } + catch (...) {} // set_exception() may throw too + } + })); + + std::future<void> future = _running.get_future(); + future.get(); //block until the monitor_directory is up and running + } + + void destroy() + { + _destory = true; + _running = std::promise<void>(); +#ifdef _WIN32 + SetEvent(_close_event); +#elif __unix__ + inotify_rm_watch(_directory.folder, _directory.watch); +#endif // __unix__ + _cv.notify_all(); + _watch_thread.join(); + _callback_thread.join(); +#ifdef _WIN32 + CloseHandle(_directory); +#elif __unix__ + close(_directory.folder); +#endif // __unix__ + } + + const PathParts split_directory_and_file(const T& path) const + { + const auto predict = [](typename T::value_type character) { +#ifdef _WIN32 + return character == _T('\\') || character == _T('/'); +#elif __unix__ + return character == '/'; +#endif // __unix__ + }; +#ifdef _WIN32 +#define _UNICODE + const UnderpinningString this_directory = _T("./"); +#elif __unix__ + const UnderpinningString this_directory = "./"; +#endif // __unix__ + + const auto pivot = std::find_if(path.rbegin(), path.rend(), predict).base(); + //if the path is something like "test.txt" there will be no directoy part, however we still need one, so insert './' + const T directory = [&]() { + const auto extracted_directory = UnderpinningString(path.begin(), pivot); + return (extracted_directory.size() > 0) ? extracted_directory : this_directory; + }(); + const T filename = UnderpinningString(pivot, path.end()); + return PathParts(directory, filename); + } + + bool pass_filter(const UnderpinningString& file_path) + { + if (_watching_single_file) { + const UnderpinningString extracted_filename = { split_directory_and_file(file_path).filename }; + //if we are watching a single file, only that file should trigger action + return extracted_filename == _filename; + } + return std::regex_match(file_path, _pattern); + } + +#ifdef _WIN32 + HANDLE get_directory(const T& path) + { + auto file_info = GetFileAttributes(path.c_str()); + + if (file_info == INVALID_FILE_ATTRIBUTES) + { + throw std::system_error(GetLastError(), std::system_category()); + } + _watching_single_file = (file_info & FILE_ATTRIBUTE_DIRECTORY) == false; + + const T watch_path = [this, &path]() { + if (_watching_single_file) + { + const auto parsed_path = split_directory_and_file(path); + _filename = parsed_path.filename; + return parsed_path.directory; + } + else + { + return path; + } + }(); + + HANDLE directory = ::CreateFile( + watch_path.c_str(), // pointer to the file name + FILE_LIST_DIRECTORY, // access (read/write) mode + FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, // share mode + NULL, // security descriptor + OPEN_EXISTING, // how to create + FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OVERLAPPED, // file attributes + NULL); // file with attributes to copy + + if (directory == INVALID_HANDLE_VALUE) + { + throw std::system_error(GetLastError(), std::system_category()); + } + return directory; + } + void monitor_directory() + { + std::vector<BYTE> buffer(_buffer_size); + DWORD bytes_returned = 0; + OVERLAPPED overlapped_buffer{ 0 }; + + overlapped_buffer.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL); + if (!overlapped_buffer.hEvent) { + std::cerr << "Error creating monitor event" << std::endl; + } + + std::array<HANDLE, 2> handles{ overlapped_buffer.hEvent, _close_event }; + + auto async_pending = false; + _running.set_value(); + do { + std::vector<std::pair<T, Event>> parsed_information; + ReadDirectoryChangesW( + _directory, + buffer.data(), buffer.size(), + TRUE, + _listen_filters, + &bytes_returned, + &overlapped_buffer, NULL); + + async_pending = true; + + switch (WaitForMultipleObjects(2, handles.data(), FALSE, INFINITE)) + { + case WAIT_OBJECT_0: + { + if (!GetOverlappedResult(_directory, &overlapped_buffer, &bytes_returned, TRUE)) { + throw std::system_error(GetLastError(), std::system_category()); + } + async_pending = false; + + if (bytes_returned == 0) { + break; + } + + FILE_NOTIFY_INFORMATION *file_information = reinterpret_cast<FILE_NOTIFY_INFORMATION*>(&buffer[0]); + do + { + UnderpinningString changed_file{ file_information->FileName, file_information->FileNameLength / 2 }; + if (pass_filter(changed_file)) + { + parsed_information.emplace_back(T{ changed_file }, _event_type_mapping.at(file_information->Action)); + } + + if (file_information->NextEntryOffset == 0) { + break; + } + + file_information = reinterpret_cast<FILE_NOTIFY_INFORMATION*>(reinterpret_cast<BYTE*>(file_information) + file_information->NextEntryOffset); + } while (true); + break; + } + case WAIT_OBJECT_0 + 1: + // quit + break; + case WAIT_FAILED: + break; + } + //dispatch callbacks + { + std::lock_guard<std::mutex> lock(_callback_mutex); + _callback_information.insert(_callback_information.end(), parsed_information.begin(), parsed_information.end()); + } + _cv.notify_all(); + } while (_destory == false); + + if (async_pending) + { + //clean up running async io + CancelIo(_directory); + GetOverlappedResult(_directory, &overlapped_buffer, &bytes_returned, TRUE); + } + } +#endif // WIN32 + +#if __unix__ + + bool is_file(const T& path) const + { + struct stat statbuf = {}; + if (stat(path.c_str(), &statbuf) != 0) + { + throw std::system_error(errno, std::system_category()); + } + return S_ISREG(statbuf.st_mode); + } + + FolderInfo get_directory(const T& path) + { + const auto folder = inotify_init(); + if (folder < 0) + { + throw std::system_error(errno, std::system_category()); + } + const auto listen_filters = _listen_filters; + + _watching_single_file = is_file(path); + + const T watch_path = [this, &path]() { + if (_watching_single_file) + { + const auto parsed_path = split_directory_and_file(path); + _filename = parsed_path.filename; + return parsed_path.directory; + } + else + { + return path; + } + }(); + + const auto watch = inotify_add_watch(folder, watch_path.c_str(), IN_MODIFY | IN_CREATE | IN_DELETE); + if (watch < 0) + { + throw std::system_error(errno, std::system_category()); + } + return { folder, watch }; + } + + void monitor_directory() + { + std::vector<char> buffer(_buffer_size); + + _running.set_value(); + while (_destory == false) + { + const auto length = read(_directory.folder, static_cast<void*>(buffer.data()), buffer.size()); + if (length > 0) + { + int i = 0; + std::vector<std::pair<T, Event>> parsed_information; + while (i < length) + { + struct inotify_event *event = reinterpret_cast<struct inotify_event *>(&buffer[i]); // NOLINT + if (event->len) + { + const UnderpinningString changed_file{ event->name }; + if (pass_filter(changed_file)) + { + if (event->mask & IN_CREATE) + { + parsed_information.emplace_back(T{ changed_file }, Event::added); + } + else if (event->mask & IN_DELETE) + { + parsed_information.emplace_back(T{ changed_file }, Event::removed); + } + else if (event->mask & IN_MODIFY) + { + parsed_information.emplace_back(T{ changed_file }, Event::modified); + } + } + } + i += event_size + event->len; + } + //dispatch callbacks + { + std::lock_guard<std::mutex> lock(_callback_mutex); + _callback_information.insert(_callback_information.end(), parsed_information.begin(), parsed_information.end()); + } + _cv.notify_all(); + } + } + } +#endif // __unix__ + + void callback_thread() + { + while (_destory == false) { + std::unique_lock<std::mutex> lock(_callback_mutex); + if (_callback_information.empty() && _destory == false) { + _cv.wait(lock, [this] { return _callback_information.size() > 0 || _destory; }); + } + decltype(_callback_information) callback_information = {}; + std::swap(callback_information, _callback_information); + lock.unlock(); + + for (const auto& file : callback_information) { + if (_callback) { + try + { + _callback(file.first, file.second); + } + catch (const std::exception&) + { + } + } + } + } + } + }; +} +#endif
\ No newline at end of file diff --git a/Source/Asura.Editor/System/Input.cpp b/Source/Asura.Editor/System/Input.cpp new file mode 100644 index 0000000..c10eb3b --- /dev/null +++ b/Source/Asura.Editor/System/Input.cpp @@ -0,0 +1,61 @@ +#include "Input.h" + +namespace_begin(AsuraEditor) + + +Input::Input() +{ +} + +Input::~Input() +{ +} + +bool Input::Open(HWND window) +{ +} + +void Input::Close(void) +{ +} + +bool Input::GetJoystickNames(std::vector<std::string> &names) +{ +} + + +bool Input::Activate(bool active) +{ +} + +bool Input::ToggleFullscreen(bool fullscreen, HWND window) +{ +} + + +bool Input::Process(bool discard) +{ +} + +LRESULT Input::OnKey(HWND window, UINT message, WPARAM wParam, LPARAM lParam) +{ +} + +LRESULT Input::OnInput(HWND window, UINT message, WPARAM wParam, LPARAM lParam) +{ +} + +LRESULT Input::OnDeviceChange(LPCWSTR name, bool add) +{ +} + +bool Input::ConvertPositionToClientAreaCoord(HWND activeWindow, POINT position, AEMath::Vector2f& newPos) +{ +} + +bool Input::UpdateState() +{ + +} + +namespace_end diff --git a/Source/Asura.Editor/System/Input.h b/Source/Asura.Editor/System/Input.h new file mode 100644 index 0000000..9401981 --- /dev/null +++ b/Source/Asura.Editor/System/Input.h @@ -0,0 +1,16 @@ +#ifndef _ASRUA_EDITOR_INPUT_H_ +#define _ASRUA_EDITOR_INPUT_H_ + +#include <windows.h> + +#include <asura-base/Classes.h> +#include <asura-base/Math/Vector2.hpp> +#include <asura-core/Input/InputDevice.h> + +namespace_begin(AsuraEditor) + + + +namespace_end + +#endif
\ No newline at end of file diff --git a/Source/Asura.Editor/System/MenuController.cpp b/Source/Asura.Editor/System/MenuController.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Source/Asura.Editor/System/MenuController.cpp diff --git a/Source/Asura.Editor/System/MenuController.h b/Source/Asura.Editor/System/MenuController.h new file mode 100644 index 0000000..2deb21e --- /dev/null +++ b/Source/Asura.Editor/System/MenuController.h @@ -0,0 +1,15 @@ +#ifndef _ASURA_EDITOR_MENU_CONTROLLER_H_ +#define _ASURA_EDITOR_MENU_CONTROLLER_H_ + +#include <asura-base/Classes.h> + +namespace_begin(AsuraEditor) + +struct MenuItem; + + + + +namespace_end + +#endif diff --git a/Source/Asura.Editor/Type.h b/Source/Asura.Editor/Type.h new file mode 100644 index 0000000..f21b376 --- /dev/null +++ b/Source/Asura.Editor/Type.h @@ -0,0 +1,30 @@ +#ifndef _ASURA_EDITOR_TYPE_H_ +#define _ASURA_EDITOR_TYPE_H_ + +#include <cstdlib> +#include <stdint.h> + +namespace AsuraEditor +{ + + typedef int8_t int8; + typedef uint8_t uint8; + //typedef uint8 byte; + typedef char byte; + typedef int16_t int16; + typedef uint16_t uint16; + typedef int32_t int32; + typedef uint32_t uint32; + typedef int64_t int64; + typedef uint64_t uint64; + + typedef uint32_t uint; + typedef int32_t sint; + + typedef std::size_t size_t; + + typedef const char cc8; + +} + +#endif
\ No newline at end of file |