From bad78945ceba425f6a80e3b8dca2414d592970eb Mon Sep 17 00:00:00 2001 From: chai Date: Fri, 2 Aug 2019 20:51:00 +0800 Subject: =?UTF-8?q?*=E4=BF=AE=E6=94=B9=E6=96=87=E4=BB=B6=E5=90=8D=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/Asura.Editor/Config.h | 0 source/Asura.Editor/Controls/GUIButton.cpp | 11 + source/Asura.Editor/Controls/GUIButton.h | 14 + source/Asura.Editor/Controls/GUIContent.cpp | 8 + source/Asura.Editor/Controls/GUIContent.h | 17 + source/Asura.Editor/Controls/GUILabel.cpp | 8 + source/Asura.Editor/Controls/GUILabel.h | 14 + source/Asura.Editor/Controls/GUIPanel.cpp | 6 + source/Asura.Editor/Controls/GUIPanel.h | 16 + source/Asura.Editor/Controls/GUISlider.cpp | 8 + source/Asura.Editor/Controls/GUISlider.h | 14 + source/Asura.Editor/Controls/GUIToggle.cpp | 1 + source/Asura.Editor/Controls/GUIToggle.h | 16 + source/Asura.Editor/Controls/TextUtil.cpp | 0 source/Asura.Editor/Controls/TextUtil.h | 37 ++ source/Asura.Editor/Core/GUIState.h | 27 ++ source/Asura.Editor/Editor.cpp | 5 + source/Asura.Editor/Editor.h | 37 ++ source/Asura.Editor/Editor/asset_view.lua | 0 source/Asura.Editor/Editor/compile.bat | 0 source/Asura.Editor/Editor/compile.sh | 0 source/Asura.Editor/Editor/idea.txt | 0 source/Asura.Editor/Editor/main.lua | 4 + source/Asura.Editor/Editor/scene_view.lua | 4 + source/Asura.Editor/Graphics/Brush.cpp | 0 source/Asura.Editor/Graphics/Brush.h | 20 + source/Asura.Editor/Graphics/DrawInfo.cpp | 0 source/Asura.Editor/Graphics/DrawInfo.h | 16 + source/Asura.Editor/Graphics/Drawer.cpp | 16 + source/Asura.Editor/Graphics/Drawer.h | 40 ++ source/Asura.Editor/Graphics/Pen.cpp | 0 source/Asura.Editor/Graphics/Pen.h | 7 + source/Asura.Editor/Graphics/Shader.h | 18 + source/Asura.Editor/Graphics/Style.cpp | 0 source/Asura.Editor/Graphics/Style.h | 15 + .../Asura.Editor/Graphics/shaders/image.shader.h | 35 ++ .../Asura.Editor/Graphics/shaders/polygon.shader.h | 29 ++ source/Asura.Editor/Layout/HorizontalLayout.cpp | 0 source/Asura.Editor/Layout/HorizontalLayout.h | 0 source/Asura.Editor/Layout/VerticalLayout.cpp | 0 source/Asura.Editor/Layout/VerticalLayout.h | 0 source/Asura.Editor/Main.cpp | 30 ++ source/Asura.Editor/System/ContainerWindow.cpp | 0 source/Asura.Editor/System/ContainerWindow.h | 62 +++ source/Asura.Editor/System/FileWatcher.cpp | 0 source/Asura.Editor/System/FileWatcher.h | 517 +++++++++++++++++++++ source/Asura.Editor/System/MenuController.cpp | 0 source/Asura.Editor/System/MenuController.h | 15 + source/Asura.Editor/Type.h | 30 ++ source/Asura.Editor/controls/button.cpp | 8 - source/Asura.Editor/controls/button.h | 14 - source/Asura.Editor/controls/content.cpp | 8 - source/Asura.Editor/controls/content.h | 17 - source/Asura.Editor/controls/label.cpp | 8 - source/Asura.Editor/controls/label.h | 14 - source/Asura.Editor/controls/panel.cpp | 16 - source/Asura.Editor/controls/panel.h | 16 - source/Asura.Editor/controls/toggle.cpp | 8 - source/Asura.Editor/controls/toggle.h | 14 - source/Asura.Editor/core/gui_state.h | 17 - source/Asura.Editor/editor.h | 6 +- source/Asura.Editor/graphics/brush.h | 4 +- source/Asura.Editor/graphics/draw_info.cpp | 0 source/Asura.Editor/graphics/draw_info.h | 14 - source/Asura.Editor/graphics/drawer.cpp | 2 +- source/Asura.Editor/graphics/drawer.h | 10 +- source/Asura.Editor/graphics/pen.h | 17 +- source/Asura.Editor/graphics/shader.h | 4 +- .../Asura.Editor/graphics/shaders/image.shader.h | 2 +- .../Asura.Editor/graphics/shaders/polygon.shader.h | 2 +- source/Asura.Editor/graphics/slider.cpp | 0 source/Asura.Editor/graphics/slider.h | 14 - source/Asura.Editor/graphics/style.h | 8 +- source/Asura.Editor/layout/horizontal_layout.cpp | 0 source/Asura.Editor/layout/horizontal_layout.h | 0 source/Asura.Editor/layout/vertical_layout.cpp | 0 source/Asura.Editor/layout/vertical_layout.h | 0 source/Asura.Editor/main.cpp | 8 +- source/Asura.Editor/system/editor_window.cpp | 6 - source/Asura.Editor/system/editor_window.h | 62 --- source/Asura.Editor/system/file_watcher.cpp | 0 source/Asura.Editor/system/file_watcher.h | 517 --------------------- source/Asura.Editor/type.h | 4 +- 83 files changed, 1124 insertions(+), 793 deletions(-) create mode 100644 source/Asura.Editor/Config.h create mode 100644 source/Asura.Editor/Controls/GUIButton.cpp create mode 100644 source/Asura.Editor/Controls/GUIButton.h create mode 100644 source/Asura.Editor/Controls/GUIContent.cpp create mode 100644 source/Asura.Editor/Controls/GUIContent.h create mode 100644 source/Asura.Editor/Controls/GUILabel.cpp create mode 100644 source/Asura.Editor/Controls/GUILabel.h create mode 100644 source/Asura.Editor/Controls/GUIPanel.cpp create mode 100644 source/Asura.Editor/Controls/GUIPanel.h create mode 100644 source/Asura.Editor/Controls/GUISlider.cpp create mode 100644 source/Asura.Editor/Controls/GUISlider.h create mode 100644 source/Asura.Editor/Controls/GUIToggle.cpp create mode 100644 source/Asura.Editor/Controls/GUIToggle.h create mode 100644 source/Asura.Editor/Controls/TextUtil.cpp create mode 100644 source/Asura.Editor/Controls/TextUtil.h create mode 100644 source/Asura.Editor/Core/GUIState.h create mode 100644 source/Asura.Editor/Editor.cpp create mode 100644 source/Asura.Editor/Editor.h create mode 100644 source/Asura.Editor/Editor/asset_view.lua create mode 100644 source/Asura.Editor/Editor/compile.bat create mode 100644 source/Asura.Editor/Editor/compile.sh create mode 100644 source/Asura.Editor/Editor/idea.txt create mode 100644 source/Asura.Editor/Editor/main.lua create mode 100644 source/Asura.Editor/Editor/scene_view.lua create mode 100644 source/Asura.Editor/Graphics/Brush.cpp create mode 100644 source/Asura.Editor/Graphics/Brush.h create mode 100644 source/Asura.Editor/Graphics/DrawInfo.cpp create mode 100644 source/Asura.Editor/Graphics/DrawInfo.h create mode 100644 source/Asura.Editor/Graphics/Drawer.cpp create mode 100644 source/Asura.Editor/Graphics/Drawer.h create mode 100644 source/Asura.Editor/Graphics/Pen.cpp create mode 100644 source/Asura.Editor/Graphics/Pen.h create mode 100644 source/Asura.Editor/Graphics/Shader.h create mode 100644 source/Asura.Editor/Graphics/Style.cpp create mode 100644 source/Asura.Editor/Graphics/Style.h create mode 100644 source/Asura.Editor/Graphics/shaders/image.shader.h create mode 100644 source/Asura.Editor/Graphics/shaders/polygon.shader.h create mode 100644 source/Asura.Editor/Layout/HorizontalLayout.cpp create mode 100644 source/Asura.Editor/Layout/HorizontalLayout.h create mode 100644 source/Asura.Editor/Layout/VerticalLayout.cpp create mode 100644 source/Asura.Editor/Layout/VerticalLayout.h create mode 100644 source/Asura.Editor/Main.cpp create mode 100644 source/Asura.Editor/System/ContainerWindow.cpp create mode 100644 source/Asura.Editor/System/ContainerWindow.h create mode 100644 source/Asura.Editor/System/FileWatcher.cpp create mode 100644 source/Asura.Editor/System/FileWatcher.h create mode 100644 source/Asura.Editor/System/MenuController.cpp create mode 100644 source/Asura.Editor/System/MenuController.h create mode 100644 source/Asura.Editor/Type.h delete mode 100644 source/Asura.Editor/controls/button.cpp delete mode 100644 source/Asura.Editor/controls/button.h delete mode 100644 source/Asura.Editor/controls/content.cpp delete mode 100644 source/Asura.Editor/controls/content.h delete mode 100644 source/Asura.Editor/controls/label.cpp delete mode 100644 source/Asura.Editor/controls/label.h delete mode 100644 source/Asura.Editor/controls/panel.cpp delete mode 100644 source/Asura.Editor/controls/panel.h delete mode 100644 source/Asura.Editor/controls/toggle.cpp delete mode 100644 source/Asura.Editor/controls/toggle.h delete mode 100644 source/Asura.Editor/core/gui_state.h delete mode 100644 source/Asura.Editor/graphics/draw_info.cpp delete mode 100644 source/Asura.Editor/graphics/draw_info.h delete mode 100644 source/Asura.Editor/graphics/slider.cpp delete mode 100644 source/Asura.Editor/graphics/slider.h delete mode 100644 source/Asura.Editor/layout/horizontal_layout.cpp delete mode 100644 source/Asura.Editor/layout/horizontal_layout.h delete mode 100644 source/Asura.Editor/layout/vertical_layout.cpp delete mode 100644 source/Asura.Editor/layout/vertical_layout.h delete mode 100644 source/Asura.Editor/system/editor_window.cpp delete mode 100644 source/Asura.Editor/system/editor_window.h delete mode 100644 source/Asura.Editor/system/file_watcher.cpp delete mode 100644 source/Asura.Editor/system/file_watcher.h (limited to 'source/Asura.Editor') diff --git a/source/Asura.Editor/Config.h b/source/Asura.Editor/Config.h new file mode 100644 index 0000000..e69de29 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..ece60ca --- /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 + +namespace_begin(AsuraEditor) + +bool GUIButton(); + + + +namespace_end + +#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..c70a03c --- /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 + +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..c5741c1 --- /dev/null +++ b/source/Asura.Editor/Controls/GUILabel.cpp @@ -0,0 +1,8 @@ +#include "gui_button.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..172a329 --- /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 + +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..6bcd00d --- /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 + +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..8d91e85 --- /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 + +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..b26e919 --- /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 + +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 diff --git a/source/Asura.Editor/Controls/TextUtil.h b/source/Asura.Editor/Controls/TextUtil.h new file mode 100644 index 0000000..24fb1e1 --- /dev/null +++ b/source/Asura.Editor/Controls/TextUtil.h @@ -0,0 +1,37 @@ +#ifndef _ASURA_EDITOR_TEXTUTIL_H_ +#define _ASURA_EDITOR_TEXTUTIL_H_ + +#include + +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..88c9891 --- /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 + +namespace_begin(AsuraEditor) + +/// GUI widgets uniqueID +class GUIState +{ +public: + + inline int GetDepth() { return m_Depth; }; + +private: + + int m_Depth; + bool m_Changed; + +}; + + +namespace_end + + +#endif + diff --git a/source/Asura.Editor/Editor.cpp b/source/Asura.Editor/Editor.cpp new file mode 100644 index 0000000..38e7c26 --- /dev/null +++ b/source/Asura.Editor/Editor.cpp @@ -0,0 +1,5 @@ + +int main(int argc, char *argv[]) +{ + +} \ 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..2f5f8ca --- /dev/null +++ b/source/Asura.Editor/Editor.h @@ -0,0 +1,37 @@ +#ifndef _ASURA_EDITOR_H_ +#define _ASURA_EDITOR_H_ + +#include + +namespace AsuraEditor +{ + + /// + /// 编辑器实例。 + /// + class Editor + { + public: + + /// + /// 获得界面的lua State + /// + Luax::LuaxState& GetLuaxState(); + + private: + + /// + /// 界面和逻辑运行的虚拟机。 + /// + Luax::LuaxVM* mEditorVM; + + /// + /// 游戏运行时的虚拟机。 + /// + Luax::LuaxVM* mRunnerVM; + + }; + +} + +#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 diff --git a/source/Asura.Editor/Editor/compile.bat b/source/Asura.Editor/Editor/compile.bat new file mode 100644 index 0000000..e69de29 diff --git a/source/Asura.Editor/Editor/compile.sh b/source/Asura.Editor/Editor/compile.sh new file mode 100644 index 0000000..e69de29 diff --git a/source/Asura.Editor/Editor/idea.txt b/source/Asura.Editor/Editor/idea.txt new file mode 100644 index 0000000..e69de29 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 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 diff --git a/source/Asura.Editor/Graphics/DrawInfo.h b/source/Asura.Editor/Graphics/DrawInfo.h new file mode 100644 index 0000000..ee38319 --- /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 + +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..638ce08 --- /dev/null +++ b/source/Asura.Editor/Graphics/Drawer.h @@ -0,0 +1,40 @@ +#ifndef _ASURA_EDITOR_PAINTER_H_ +#define _ASURA_EDITOR_PAINTER_H_ + +#include +#include +#include + +namespace AsuraEditor +{ + namespace Graphics + { + + /// + /// 基于AsuraEngine的渲染部分的绘画类,用于绘制控件和文字。之所以不直接用引擎部分的渲染, + /// 是因为引擎的渲染在framework中实现,有更高级的抽象,而控件的渲染不需要复杂的pass。在 + /// 编辑器下,引擎的渲染和编辑器的渲染可以混编。 + /// + class Drawer + : public AsuraEngine::Singleton + , public AEScripting::Portable + { + 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 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 diff --git a/source/Asura.Editor/Graphics/Style.h b/source/Asura.Editor/Graphics/Style.h new file mode 100644 index 0000000..b6ed2c5 --- /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 + +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 diff --git a/source/Asura.Editor/Layout/HorizontalLayout.h b/source/Asura.Editor/Layout/HorizontalLayout.h new file mode 100644 index 0000000..e69de29 diff --git a/source/Asura.Editor/Layout/VerticalLayout.cpp b/source/Asura.Editor/Layout/VerticalLayout.cpp new file mode 100644 index 0000000..e69de29 diff --git a/source/Asura.Editor/Layout/VerticalLayout.h b/source/Asura.Editor/Layout/VerticalLayout.h new file mode 100644 index 0000000..e69de29 diff --git a/source/Asura.Editor/Main.cpp b/source/Asura.Editor/Main.cpp new file mode 100644 index 0000000..207474b --- /dev/null +++ b/source/Asura.Editor/Main.cpp @@ -0,0 +1,30 @@ +/** + * Copyright (c) 2018-2019 AsuraEngine Team + * + * This software is provided 'as-is', without any express or implied + * warranty. In no event will the authors be held liable for any damages + * arising from the use of this software. + * + * Permission is granted to anyone to use this software for any purpose, + * including commercial applications, and to alter it and redistribute it + * freely, subject to the following restrictions: + * + * 1. The origin of this software m_ust not be m_isrepresented; you m_ust not + * claim that you wrote the original software. If you use this software + * in a product, an acknowledgment in the product documentation would be + * appreciated but is not required. + * 2. Altered source versions m_ust be plainly m_arked as such, and m_ust not be + * m_isrepresented as being the original software. + * 3. This notice m_ay not be removed or altered from any source distribution. + **/ + +/// +/// 编辑器的界面通过directUI实现,界面耳朵渲染构建在asura-lib上,事件的响应通过win32API实现。 +/// + +int main(int argn, char* args[]) +{ + + + +} \ 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 diff --git a/source/Asura.Editor/System/ContainerWindow.h b/source/Asura.Editor/System/ContainerWindow.h new file mode 100644 index 0000000..ee72b72 --- /dev/null +++ b/source/Asura.Editor/System/ContainerWindow.h @@ -0,0 +1,62 @@ +#ifndef _ASURA_EDITOR_WINDOW_H_ +#define _ASURA_EDITOR_WINDOW_H_ + +#include +#include + +#include +#include + +#include "../Type.h" + +namespace_begin(AsuraEditor) + +/// +/// 包含编辑器窗口的native窗口 +/// +class ContainerWindow : public AEScripting::Portable +{ +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 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 +#include +#include +#include +#include +#include +#endif // WIN32 + +#if __unix__ +#include +#include +#include +#include +#include +#include +#include +#endif // __unix__ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +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 FileWatch + { + typedef std::basic_string> UnderpinningString; + typedef std::basic_regex> UnderpinningRegex; + + public: + + FileWatch(T path, UnderpinningRegex pattern, std::function callback) : + _path(path), + _pattern(pattern), + _callback(callback), + _directory(get_directory(path)) + { + init(); + } + +#if defined _WIN32 && (defined UNICODE || defined _UNICODE) + FileWatch(T path, std::function callback) : + FileWatch(path, UnderpinningRegex(L".*"), callback) {} +#else // _WIN32 && (UNICODE || _UNICODE) + FileWatch(T path, std::function callback) : + FileWatch(path, UnderpinningRegex(".*"), callback) {} +#endif + + ~FileWatch() { + destroy(); + } + + FileWatch(const FileWatch& other) : FileWatch(other._path, other._callback) {} + + FileWatch& operator=(const FileWatch& 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(FileWatch&&) = delete; + FileWatch& operator=(FileWatch&&) & = 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 _destory = { false }; + std::function _callback; + + std::thread _watch_thread; + + std::condition_variable _cv; + std::mutex _callback_mutex; + std::vector> _callback_information; + std::thread _callback_thread; + + std::promise _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 _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 future = _running.get_future(); + future.get(); //block until the monitor_directory is up and running + } + + void destroy() + { + _destory = true; + _running = std::promise(); +#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 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 handles{ overlapped_buffer.hEvent, _close_event }; + + auto async_pending = false; + _running.set_value(); + do { + std::vector> 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(&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(reinterpret_cast(file_information) + file_information->NextEntryOffset); + } while (true); + break; + } + case WAIT_OBJECT_0 + 1: + // quit + break; + case WAIT_FAILED: + break; + } + //dispatch callbacks + { + std::lock_guard 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 buffer(_buffer_size); + + _running.set_value(); + while (_destory == false) + { + const auto length = read(_directory.folder, static_cast(buffer.data()), buffer.size()); + if (length > 0) + { + int i = 0; + std::vector> parsed_information; + while (i < length) + { + struct inotify_event *event = reinterpret_cast(&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 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 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/MenuController.cpp b/source/Asura.Editor/System/MenuController.cpp new file mode 100644 index 0000000..e69de29 diff --git a/source/Asura.Editor/System/MenuController.h b/source/Asura.Editor/System/MenuController.h new file mode 100644 index 0000000..591cbd9 --- /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 + +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 +#include + +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 diff --git a/source/Asura.Editor/controls/button.cpp b/source/Asura.Editor/controls/button.cpp deleted file mode 100644 index c5741c1..0000000 --- a/source/Asura.Editor/controls/button.cpp +++ /dev/null @@ -1,8 +0,0 @@ -#include "gui_button.h" - -namespace_begin(AsuraEditor) - - - - -namespace_end diff --git a/source/Asura.Editor/controls/button.h b/source/Asura.Editor/controls/button.h deleted file mode 100644 index edfa7b7..0000000 --- a/source/Asura.Editor/controls/button.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef __ASURA_EDITOR_GUI_BUTTON_H__ -#define __ASURA_EDITOR_GUI_BUTTON_H__ - -#include - -namespace_begin(AsuraEditor) - -bool Button(); - - - -namespace_end - -#endif diff --git a/source/Asura.Editor/controls/content.cpp b/source/Asura.Editor/controls/content.cpp deleted file mode 100644 index c5741c1..0000000 --- a/source/Asura.Editor/controls/content.cpp +++ /dev/null @@ -1,8 +0,0 @@ -#include "gui_button.h" - -namespace_begin(AsuraEditor) - - - - -namespace_end diff --git a/source/Asura.Editor/controls/content.h b/source/Asura.Editor/controls/content.h deleted file mode 100644 index 230bfa9..0000000 --- a/source/Asura.Editor/controls/content.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef __ASURA_EDITOR_GUI_BUTTON_H__ -#define __ASURA_EDITOR_GUI_BUTTON_H__ - -#include - -namespace_begin(AsuraEditor) - -/// IMGUI content -class Content -{ - -}; - - -namespace_end - -#endif diff --git a/source/Asura.Editor/controls/label.cpp b/source/Asura.Editor/controls/label.cpp deleted file mode 100644 index c5741c1..0000000 --- a/source/Asura.Editor/controls/label.cpp +++ /dev/null @@ -1,8 +0,0 @@ -#include "gui_button.h" - -namespace_begin(AsuraEditor) - - - - -namespace_end diff --git a/source/Asura.Editor/controls/label.h b/source/Asura.Editor/controls/label.h deleted file mode 100644 index 7cc6e3d..0000000 --- a/source/Asura.Editor/controls/label.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef __ASURA_EDITOR_GUI_BUTTON_H__ -#define __ASURA_EDITOR_GUI_BUTTON_H__ - -#include - -namespace_begin(AsuraEditor) - -bool Label(); - - - -namespace_end - -#endif diff --git a/source/Asura.Editor/controls/panel.cpp b/source/Asura.Editor/controls/panel.cpp deleted file mode 100644 index 2e6e2cc..0000000 --- a/source/Asura.Editor/controls/panel.cpp +++ /dev/null @@ -1,16 +0,0 @@ -#include "gui_button.h" - -namespace_begin(AsuraEditor) - -class GUIWindow -{ -public: - - GUIWindow(); - ~GUIWindow(); - -}; - - - -namespace_end diff --git a/source/Asura.Editor/controls/panel.h b/source/Asura.Editor/controls/panel.h deleted file mode 100644 index b485635..0000000 --- a/source/Asura.Editor/controls/panel.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef __ASURA_EDITOR_GUI_BUTTON_H__ -#define __ASURA_EDITOR_GUI_BUTTON_H__ - -#include - -namespace_begin(AsuraEditor) - -/// IMGUI panel -class Panel -{ - -}; - -namespace_end - -#endif diff --git a/source/Asura.Editor/controls/toggle.cpp b/source/Asura.Editor/controls/toggle.cpp deleted file mode 100644 index 40d2043..0000000 --- a/source/Asura.Editor/controls/toggle.cpp +++ /dev/null @@ -1,8 +0,0 @@ -#include "gui_button.h" - -namespace_begin(AsuraEditor) - -bool GUIToggle(); - - -namespace_end diff --git a/source/Asura.Editor/controls/toggle.h b/source/Asura.Editor/controls/toggle.h deleted file mode 100644 index 19e9379..0000000 --- a/source/Asura.Editor/controls/toggle.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef __ASURA_EDITOR_GUI_BUTTON_H__ -#define __ASURA_EDITOR_GUI_BUTTON_H__ - -#include - -namespace_begin(AsuraEditor) - -bool Toggle(); - - - -namespace_end - -#endif diff --git a/source/Asura.Editor/core/gui_state.h b/source/Asura.Editor/core/gui_state.h deleted file mode 100644 index 9e7e91c..0000000 --- a/source/Asura.Editor/core/gui_state.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef _ASURA_EDITOR_GUI_STATE_H_ -#define _ASURA_EDITOR_GUI_STATE_H_ - -#include - -namespace_begin(AsuraEditor) - -/// GUI widgets uniqueID - - - - -namespace_end - - -#endif - diff --git a/source/Asura.Editor/editor.h b/source/Asura.Editor/editor.h index fbcfb62..2f5f8ca 100644 --- a/source/Asura.Editor/editor.h +++ b/source/Asura.Editor/editor.h @@ -1,7 +1,7 @@ -#ifndef __ASURA_EDITOR_H__ -#define __ASURA_EDITOR_H__ +#ifndef _ASURA_EDITOR_H_ +#define _ASURA_EDITOR_H_ -#include +#include namespace AsuraEditor { diff --git a/source/Asura.Editor/graphics/brush.h b/source/Asura.Editor/graphics/brush.h index 5ffdba4..4290926 100644 --- a/source/Asura.Editor/graphics/brush.h +++ b/source/Asura.Editor/graphics/brush.h @@ -1,5 +1,5 @@ -#ifndef __ASURA_EDITOR_BRUSH_H__ -#define __ASURA_EDITOR_BRUSH_H__ +#ifndef _ASURA_EDITOR_BRUSH_H_ +#define _ASURA_EDITOR_BRUSH_H_ namespace AsuraEditor { diff --git a/source/Asura.Editor/graphics/draw_info.cpp b/source/Asura.Editor/graphics/draw_info.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/source/Asura.Editor/graphics/draw_info.h b/source/Asura.Editor/graphics/draw_info.h deleted file mode 100644 index 442b92d..0000000 --- a/source/Asura.Editor/graphics/draw_info.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef __ASURA_EDITOR_DRAW_INFO_H__ -#define __ASURA_EDITOR_DRAW_INFO_H__ - -namespace AsuraEditor -{ - namespace Graphics - { - - - - } -} - -#endif \ No newline at end of file diff --git a/source/Asura.Editor/graphics/drawer.cpp b/source/Asura.Editor/graphics/drawer.cpp index f2fca31..6482aeb 100644 --- a/source/Asura.Editor/graphics/drawer.cpp +++ b/source/Asura.Editor/graphics/drawer.cpp @@ -1,4 +1,4 @@ -#include "drawer.h" +#include "Drawer.h" using namespace AEGraphics; diff --git a/source/Asura.Editor/graphics/drawer.h b/source/Asura.Editor/graphics/drawer.h index 85cc88a..638ce08 100644 --- a/source/Asura.Editor/graphics/drawer.h +++ b/source/Asura.Editor/graphics/drawer.h @@ -1,9 +1,9 @@ -#ifndef __ASURA_EDITOR_PAINTER_H__ -#define __ASURA_EDITOR_PAINTER_H__ +#ifndef _ASURA_EDITOR_PAINTER_H_ +#define _ASURA_EDITOR_PAINTER_H_ -#include -#include -#include +#include +#include +#include namespace AsuraEditor { diff --git a/source/Asura.Editor/graphics/pen.h b/source/Asura.Editor/graphics/pen.h index 87a031c..b949d14 100644 --- a/source/Asura.Editor/graphics/pen.h +++ b/source/Asura.Editor/graphics/pen.h @@ -1,20 +1,7 @@ -#ifndef __ASURA_EDITOR_PEN_H__ -#define __ASURA_EDITOR_PEN_H__ +#ifndef _ASURA_EDITOR_PEN_H_ +#define _ASURA_EDITOR_PEN_H_ -namespace AsuraEditor -{ - namespace Graphics - { - /// - /// 画笔,用来指定绘制的线条格式 - /// - class Pen - { - }; - - } -} #endif \ No newline at end of file diff --git a/source/Asura.Editor/graphics/shader.h b/source/Asura.Editor/graphics/shader.h index 6f5a8cc..a3abec1 100644 --- a/source/Asura.Editor/graphics/shader.h +++ b/source/Asura.Editor/graphics/shader.h @@ -1,5 +1,5 @@ -#ifndef __ASURA_EDITOR_SHADER_H__ -#define __ASURA_EDITOR_SHADER_H__ +#ifndef _ASURA_EDITOR_SHADER_H_ +#define _ASURA_EDITOR_SHADER_H_ namespace AsuraEditor { diff --git a/source/Asura.Editor/graphics/shaders/image.shader.h b/source/Asura.Editor/graphics/shaders/image.shader.h index ee6be43..cbdd542 100644 --- a/source/Asura.Editor/graphics/shaders/image.shader.h +++ b/source/Asura.Editor/graphics/shaders/image.shader.h @@ -1,4 +1,4 @@ -#ifndef __ASURA_EDITOR_SHADER_H__ +#ifndef _ASURA_EDITOR_SHADER_H_ #include "../shader.h" #endif diff --git a/source/Asura.Editor/graphics/shaders/polygon.shader.h b/source/Asura.Editor/graphics/shaders/polygon.shader.h index eed4f5a..a92e9a6 100644 --- a/source/Asura.Editor/graphics/shaders/polygon.shader.h +++ b/source/Asura.Editor/graphics/shaders/polygon.shader.h @@ -1,4 +1,4 @@ -#ifndef __ASURA_EDITOR_SHADER_H__ +#ifndef _ASURA_EDITOR_SHADER_H_ #include "../shader.h" #endif diff --git a/source/Asura.Editor/graphics/slider.cpp b/source/Asura.Editor/graphics/slider.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/source/Asura.Editor/graphics/slider.h b/source/Asura.Editor/graphics/slider.h deleted file mode 100644 index 28ea77f..0000000 --- a/source/Asura.Editor/graphics/slider.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef __ASURA_EDITOR_GUI_SLIDER_H__ -#define __ASURA_EDITOR_GUI_SLIDER_H__ - -#include - -namespace_begin(AsuraEditor) - -void Slider(); - - -namespace_end - - -#endif diff --git a/source/Asura.Editor/graphics/style.h b/source/Asura.Editor/graphics/style.h index fca3c37..b6ed2c5 100644 --- a/source/Asura.Editor/graphics/style.h +++ b/source/Asura.Editor/graphics/style.h @@ -1,11 +1,11 @@ -#ifndef __ASURA_EDITOR_GUI_STYLE_H__ -#define __ASURA_EDITOR_GUI_STYLE_H__ +#ifndef _ASURA_EDITOR_GUI_STYLE_H_ +#define _ASURA_EDITOR_GUI_STYLE_H_ -#include +#include namespace_begin(AsuraEditor) -class Style +class GUIStyle { }; diff --git a/source/Asura.Editor/layout/horizontal_layout.cpp b/source/Asura.Editor/layout/horizontal_layout.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/source/Asura.Editor/layout/horizontal_layout.h b/source/Asura.Editor/layout/horizontal_layout.h deleted file mode 100644 index e69de29..0000000 diff --git a/source/Asura.Editor/layout/vertical_layout.cpp b/source/Asura.Editor/layout/vertical_layout.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/source/Asura.Editor/layout/vertical_layout.h b/source/Asura.Editor/layout/vertical_layout.h deleted file mode 100644 index e69de29..0000000 diff --git a/source/Asura.Editor/main.cpp b/source/Asura.Editor/main.cpp index ed055cf..207474b 100644 --- a/source/Asura.Editor/main.cpp +++ b/source/Asura.Editor/main.cpp @@ -9,13 +9,13 @@ * including commercial applications, and to alter it and redistribute it * freely, subject to the following restrictions: * - * 1. The origin of this software must not be misrepresented; you must not + * 1. The origin of this software m_ust not be m_isrepresented; you m_ust not * claim that you wrote the original software. If you use this software * in a product, an acknowledgment in the product documentation would be * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. + * 2. Altered source versions m_ust be plainly m_arked as such, and m_ust not be + * m_isrepresented as being the original software. + * 3. This notice m_ay not be removed or altered from any source distribution. **/ /// diff --git a/source/Asura.Editor/system/editor_window.cpp b/source/Asura.Editor/system/editor_window.cpp deleted file mode 100644 index 0e2d4f4..0000000 --- a/source/Asura.Editor/system/editor_window.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include "editor_window.h" - -namespace AsuraEditor -{ - -} // AsruaEditor \ No newline at end of file diff --git a/source/Asura.Editor/system/editor_window.h b/source/Asura.Editor/system/editor_window.h deleted file mode 100644 index 50c9cb3..0000000 --- a/source/Asura.Editor/system/editor_window.h +++ /dev/null @@ -1,62 +0,0 @@ -#ifndef __ASURA_EDITOR_WINDOW_H__ -#define __ASURA_EDITOR_WINDOW_H__ - -#include -#include - -#include - -#include "../type.h" - -namespace AsuraEditor -{ - - /// - /// 包含编辑器窗口的native窗口 - /// - class ContainerWindow : public AEScripting::Portable - { - 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); - - }; - -} // AsuraEditor - -#endif \ No newline at end of file diff --git a/source/Asura.Editor/system/file_watcher.cpp b/source/Asura.Editor/system/file_watcher.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/source/Asura.Editor/system/file_watcher.h b/source/Asura.Editor/system/file_watcher.h deleted file mode 100644 index 43821da..0000000 --- a/source/Asura.Editor/system/file_watcher.h +++ /dev/null @@ -1,517 +0,0 @@ -// 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 -#include -#include -#include -#include -#include -#endif // WIN32 - -#if __unix__ -#include -#include -#include -#include -#include -#include -#include -#endif // __unix__ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -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 FileWatch - { - typedef std::basic_string> UnderpinningString; - typedef std::basic_regex> UnderpinningRegex; - - public: - - FileWatch(T path, UnderpinningRegex pattern, std::function callback) : - _path(path), - _pattern(pattern), - _callback(callback), - _directory(get_directory(path)) - { - init(); - } - -#if defined _WIN32 && (defined UNICODE || defined _UNICODE) - FileWatch(T path, std::function callback) : - FileWatch(path, UnderpinningRegex(L".*"), callback) {} -#else // _WIN32 && (UNICODE || _UNICODE) - FileWatch(T path, std::function callback) : - FileWatch(path, UnderpinningRegex(".*"), callback) {} -#endif - - ~FileWatch() { - destroy(); - } - - FileWatch(const FileWatch& other) : FileWatch(other._path, other._callback) {} - - FileWatch& operator=(const FileWatch& 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(FileWatch&&) = delete; - FileWatch& operator=(FileWatch&&) & = 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 _destory = { false }; - std::function _callback; - - std::thread _watch_thread; - - std::condition_variable _cv; - std::mutex _callback_mutex; - std::vector> _callback_information; - std::thread _callback_thread; - - std::promise _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 _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 future = _running.get_future(); - future.get(); //block until the monitor_directory is up and running - } - - void destroy() - { - _destory = true; - _running = std::promise(); -#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 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 handles{ overlapped_buffer.hEvent, _close_event }; - - auto async_pending = false; - _running.set_value(); - do { - std::vector> 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(&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(reinterpret_cast(file_information) + file_information->NextEntryOffset); - } while (true); - break; - } - case WAIT_OBJECT_0 + 1: - // quit - break; - case WAIT_FAILED: - break; - } - //dispatch callbacks - { - std::lock_guard 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 buffer(_buffer_size); - - _running.set_value(); - while (_destory == false) - { - const auto length = read(_directory.folder, static_cast(buffer.data()), buffer.size()); - if (length > 0) - { - int i = 0; - std::vector> parsed_information; - while (i < length) - { - struct inotify_event *event = reinterpret_cast(&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 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 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/type.h b/source/Asura.Editor/type.h index d58cf87..f21b376 100644 --- a/source/Asura.Editor/type.h +++ b/source/Asura.Editor/type.h @@ -1,5 +1,5 @@ -#ifndef __ASURA_EDITOR_TYPE_H__ -#define __ASURA_EDITOR_TYPE_H__ +#ifndef _ASURA_EDITOR_TYPE_H_ +#define _ASURA_EDITOR_TYPE_H_ #include #include -- cgit v1.1-26-g67d0