瀏覽代碼

small polish on window hiding

vlod 3 年之前
父節點
當前提交
cf1c6ef1ed

+ 7 - 1
Pika/core/pikaEditor/editShortcuts/editShortcuts.cpp

@@ -39,9 +39,15 @@ void pika::EditShortcutsWindow::update(pika::ShortcutManager &shortcutManager, b
 				char input[256] = {};
 				char input[256] = {};
 				std::strncpy(input, shortcut.second.shortcut.c_str(), sizeof(input));
 				std::strncpy(input, shortcut.second.shortcut.c_str(), sizeof(input));
 				
 				
+				int flags = ImGuiInputTextFlags_EnterReturnsTrue;
+				if (!shortcut.second.editable)
+				{
+					flags = flags | ImGuiInputTextFlags_ReadOnly;
+				}
+
 				if (
 				if (
 					ImGui::InputText(("##" + shortcut.first).c_str(),
 					ImGui::InputText(("##" + shortcut.first).c_str(),
-					input, sizeof(input), ImGuiInputTextFlags_EnterReturnsTrue)
+					input, sizeof(input), flags)
 					)
 					)
 				{
 				{
 					shortcut.second.shortcut = pika::normalizeShortcutName(input);
 					shortcut.second.shortcut = pika::normalizeShortcutName(input);

+ 88 - 64
Pika/core/pikaEditor/editor/editor.cpp

@@ -4,14 +4,14 @@
 #include "shortcutApi/shortcutApi.h"
 #include "shortcutApi/shortcutApi.h"
 #include <editShortcuts/editShortcuts.h>
 #include <editShortcuts/editShortcuts.h>
 
 
-#define DOCK_MAIN_WINDOW_SHORTCUT "Dock main window"
+#define DOCK_MAIN_WINDOW_SHORTCUT ICON_FK_EYE_SLASH " Hide main window"
 #define LOGS_SHORTCUT "Logs window"
 #define LOGS_SHORTCUT "Logs window"
 #define EDIT_SHORTCUTS "Edit shortcuts window"
 #define EDIT_SHORTCUTS "Edit shortcuts window"
 
 
 void pika::Editor::init(pika::ShortcutManager &shortcutManager)
 void pika::Editor::init(pika::ShortcutManager &shortcutManager)
 {
 {
 
 
-	shortcutManager.registerShortcut(DOCK_MAIN_WINDOW_SHORTCUT, "Ctrl+Alt+D", &optionsFlags.dockMainWindow);
+	shortcutManager.registerShortcut(DOCK_MAIN_WINDOW_SHORTCUT, "Ctrl+Alt+D", &optionsFlags.hideMainWindow);
 	shortcutManager.registerShortcut(LOGS_SHORTCUT, "Ctrl+L", &windowFlags.logsWindow);
 	shortcutManager.registerShortcut(LOGS_SHORTCUT, "Ctrl+L", &windowFlags.logsWindow);
 	shortcutManager.registerShortcut(EDIT_SHORTCUTS, "", &windowFlags.editShortcutsWindow);
 	shortcutManager.registerShortcut(EDIT_SHORTCUTS, "", &windowFlags.editShortcutsWindow);
 
 
@@ -27,100 +27,124 @@ void pika::Editor::update(const pika::Input &input,
 	pika::ShortcutManager &shortcutManager, pika::LogManager &logs)
 	pika::ShortcutManager &shortcutManager, pika::LogManager &logs)
 {
 {
 
 
-#pragma region docking space init
-	ImGuiWindowFlags mainWindowFlags = ImGuiWindowFlags_MenuBar;
-	if (optionsFlags.dockMainWindow)
+#pragma region push notification if hide window
+
+	if (lastHideWindowState == 0 && optionsFlags.hideMainWindow)
 	{
 	{
-		mainWindowFlags = ImGuiWindowFlags_MenuBar |
-			ImGuiWindowFlags_NoResize |
-			ImGuiWindowFlags_NoMove |
-			ImGuiWindowFlags_NoCollapse |
-			ImGuiWindowFlags_NoBringToFrontOnFocus |
-			ImGuiWindowFlags_NoBackground |
-			ImGuiWindowFlags_NoTitleBar;
-
-		ImVec2 vWindowSize = ImGui::GetMainViewport()->Size;
-		ImVec2 vPos0 = ImGui::GetMainViewport()->Pos;
-		ImGui::SetNextWindowPos(ImVec2((float)vPos0.x, (float)vPos0.y), ImGuiCond_Always);
-		ImGui::SetNextWindowSize(ImVec2((float)vWindowSize.x, (float)vWindowSize.y), 0);
+		std::string message = "Press ";
+		message += shortcutManager.getShortcut(DOCK_MAIN_WINDOW_SHORTCUT);
+		message += " to restore the main window.";
+
+		pushNotificationManager.pushNotification(message.c_str());
 	}
 	}
+
+	lastHideWindowState = optionsFlags.hideMainWindow;
 #pragma endregion
 #pragma endregion
 
 
-#pragma region main editor window
 
 
-	
-	//ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(0.2f, 0.2f, 0.3f, 1.0f));
-	
-	//todo imgui push pop id for main window
-	if (ImGui::Begin(
-		"Main window",
-		/*p_open=*/nullptr,
-		mainWindowFlags
-		)
-		)
+	if (!optionsFlags.hideMainWindow)
 	{
 	{
-		//ImGui::PopStyleColor();
 
 
-
-		if (optionsFlags.dockMainWindow)
+#pragma region docking space init
+		ImGuiWindowFlags mainWindowFlags = ImGuiWindowFlags_MenuBar;
+		//if (optionsFlags.hideMainWindow)
 		{
 		{
-			static const ImGuiDockNodeFlags dockspaceFlags = ImGuiDockNodeFlags_None;
-			ImGuiID dockSpace = ImGui::GetID("MainWindowDockspace");
-			ImGui::DockSpace(dockSpace, ImVec2(0.0f, 0.0f), dockspaceFlags);
+			mainWindowFlags = ImGuiWindowFlags_MenuBar |
+				ImGuiWindowFlags_NoResize |
+				ImGuiWindowFlags_NoMove |
+				ImGuiWindowFlags_NoCollapse |
+				ImGuiWindowFlags_NoBringToFrontOnFocus |
+				ImGuiWindowFlags_NoBackground |
+				ImGuiWindowFlags_NoTitleBar;
+
+			ImVec2 vWindowSize = ImGui::GetMainViewport()->Size;
+			ImVec2 vPos0 = ImGui::GetMainViewport()->Pos;
+			ImGui::SetNextWindowPos(ImVec2((float)vPos0.x, (float)vPos0.y), ImGuiCond_Always);
+			ImGui::SetNextWindowSize(ImVec2((float)vWindowSize.x, (float)vWindowSize.y), 0);
 		}
 		}
+#pragma endregion
 
 
-	#pragma region menu
-		if (ImGui::BeginMenuBar())
-		{
+#pragma region main editor window
 
 
-			if (ImGui::BeginMenu("Open..."))
-			{
+		//ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(0.2f, 0.2f, 0.3f, 1.0f));
+	
+	
+
+		//todo imgui push pop id for main window
+		if (ImGui::Begin(
+			"Main window",
+			/*p_open=*/nullptr,
+			mainWindowFlags
+			)
+			)
+		{
+			//ImGui::PopStyleColor();
 
 
-				ImGui::Text("menu text");
 
 
-				ImGui::EndMenu();
+			//if (optionsFlags.dockMainWindow)
+			{
+				static const ImGuiDockNodeFlags dockspaceFlags = ImGuiDockNodeFlags_None;
+				ImGuiID dockSpace = ImGui::GetID("MainWindowDockspace");
+				ImGui::DockSpace(dockSpace, ImVec2(0.0f, 0.0f), dockspaceFlags);
 			}
 			}
 
 
-			if (ImGui::BeginMenu("Options"))
+		#pragma region menu
+			if (ImGui::BeginMenuBar())
 			{
 			{
 
 
+				if (ImGui::BeginMenu("Open..."))
+				{
 
 
-				ImGui::MenuItem(ICON_FK_WINDOW_RESTORE " " DOCK_MAIN_WINDOW_SHORTCUT,
-					shortcutManager.getShortcut(DOCK_MAIN_WINDOW_SHORTCUT), &optionsFlags.dockMainWindow);
+					ImGui::Text("menu text");
 
 
-				ImGui::EndMenu();
-			}
+					ImGui::EndMenu();
+				}
 
 
-			if (ImGui::BeginMenu(ICON_FK_WINDOW_MAXIMIZE " Windows"))
-			{
-				ImGui::MenuItem(pika::LogWindow::ICON_NAME, 
-					shortcutManager.getShortcut(LOGS_SHORTCUT), &windowFlags.logsWindow);
+				if (ImGui::BeginMenu("Options"))
+				{
 
 
 
 
-				ImGui::EndMenu();
+					ImGui::MenuItem(DOCK_MAIN_WINDOW_SHORTCUT,
+						shortcutManager.getShortcut(DOCK_MAIN_WINDOW_SHORTCUT), &optionsFlags.hideMainWindow);
 
 
-			}
+					ImGui::EndMenu();
+				}
+
+				if (ImGui::BeginMenu(ICON_FK_WINDOW_MAXIMIZE " Windows"))
+				{
+					ImGui::MenuItem(pika::LogWindow::ICON_NAME,
+						shortcutManager.getShortcut(LOGS_SHORTCUT), &windowFlags.logsWindow);
+
+
+					ImGui::EndMenu();
+
+				}
+
+				if (ImGui::BeginMenu(ICON_FK_COG " Settings"))
+				{
+					ImGui::MenuItem(pika::EditShortcutsWindow::ICON_NAME,
+						shortcutManager.getShortcut(EDIT_SHORTCUTS), &windowFlags.editShortcutsWindow);
 
 
-			if (ImGui::BeginMenu(ICON_FK_COG " Settings"))
-			{
-				ImGui::MenuItem(pika::EditShortcutsWindow::ICON_NAME ,
-					shortcutManager.getShortcut(EDIT_SHORTCUTS), &windowFlags.editShortcutsWindow);
 
 
+					ImGui::EndMenu();
+				}
 
 
-				ImGui::EndMenu();
+				ImGui::EndMenuBar();
 			}
 			}
+		#pragma endregion
 
 
-			ImGui::EndMenuBar();
 		}
 		}
+		else
+		{
+			//ImGui::PopStyleColor();
+		}
+		ImGui::End();
+
+
 	#pragma endregion
 	#pragma endregion
 
 
 	}
 	}
-	else
-	{
-		//ImGui::PopStyleColor();
-	}
-	ImGui::End();
-#pragma endregion
+
 
 
 #pragma region log window
 #pragma region log window
 
 

+ 4 - 2
Pika/core/pikaEditor/editor/editor.h

@@ -20,7 +20,7 @@ namespace pika
 
 
 		struct
 		struct
 		{
 		{
-			bool dockMainWindow = 1;
+			bool hideMainWindow = 0;
 		}optionsFlags;
 		}optionsFlags;
 
 
 		struct
 		struct
@@ -31,7 +31,9 @@ namespace pika
 
 
 		pika::LogWindow logWindow;
 		pika::LogWindow logWindow;
 		pika::EditShortcutsWindow editShortcutsWindow;
 		pika::EditShortcutsWindow editShortcutsWindow;
-		pika::PushNotificationManager pushNotificationManager;
+		pika::PushNotificationManager pushNotificationManager; //todo move this from editor so we can have it in the game without the editor
+	
+		bool lastHideWindowState = optionsFlags.hideMainWindow;
 	};
 	};
 
 
 
 

+ 1 - 2
Pika/core/pikaRuntime/containerManager/containerManager.cpp

@@ -17,7 +17,7 @@ bool pika::ContainerManager::createContainer
 	pika::RuntimeContainer container;
 	pika::RuntimeContainer container;
 	container.arena.allocateStaticMemory(containerInformation); //this just allocates the memory
 	container.arena.allocateStaticMemory(containerInformation); //this just allocates the memory
 
 
-	container.allocator.init(malloc(100000), 100000); //todo 
+	container.allocator.init(malloc(10000), 10000); //todo 
 
 
 	dllLoader.bindAllocatorDllRealm(&container.allocator);
 	dllLoader.bindAllocatorDllRealm(&container.allocator);
 	 //this calls the constructors (from the dll realm)
 	 //this calls the constructors (from the dll realm)
@@ -88,6 +88,5 @@ void pika::ContainerManager::destroyAllContainers(pika::DllLoader &dllLoader)
 	for (auto &c : runningContainers)
 	for (auto &c : runningContainers)
 	{
 	{
 		destroyContainer(c.first, dllLoader);
 		destroyContainer(c.first, dllLoader);
-
 	}
 	}
 }
 }

+ 2 - 5
Pika/core/pikaRuntime/pikaMain.cpp

@@ -82,6 +82,8 @@ int main()
 #pragma region editor
 #pragma region editor
 	pika::Editor editor;
 	pika::Editor editor;
 	editor.init(shortcutManager);
 	editor.init(shortcutManager);
+
+	logs.pushNotificationManager = &editor.pushNotificationManager;
 #pragma endregion
 #pragma endregion
 
 
 	
 	
@@ -128,11 +130,6 @@ int main()
 		window.update();
 		window.update();
 		shortcutManager.update(window.input);
 		shortcutManager.update(window.input);
 
 
-		if (window.input.buttons[pika::Button::Q].released())
-		{
-			editor.pushNotificationManager.pushNotification("hello");
-		}
-
 	}
 	}
 
 
 	containerManager.destroyAllContainers(dllLoader);
 	containerManager.destroyAllContainers(dllLoader);

+ 12 - 2
Pika/core/pikaSTD/logs/log.cpp

@@ -21,11 +21,12 @@ void pika::LogManager::log(const char *l, int type)
 #ifdef PIKA_DEVELOPMENT
 #ifdef PIKA_DEVELOPMENT
 	logInternally(l, type);
 	logInternally(l, type);
 	logToFile(l, type);
 	logToFile(l, type);
+	logToPushNotification(l, type);
 #endif
 #endif
 
 
 #ifdef PIKA_PRODUCTION
 #ifdef PIKA_PRODUCTION
-	logToFile(l, type); //todo enum settings
-
+	logToFile(l, type); //todo enum settings flags (what to keep to logs)
+	logToPushNotification(l, type);
 #endif
 #endif
 
 
 }
 }
@@ -58,3 +59,12 @@ void pika::LogManager::logInternally(const char *l, int type)
 {
 {
 	internalLogs.push_back(formatLog(l, type).str());
 	internalLogs.push_back(formatLog(l, type).str());
 }
 }
+
+void pika::LogManager::logToPushNotification(const char *l, int type)
+{
+	if (pushNotificationManager)
+	{
+		pushNotificationManager->pushNotification(l);
+	}
+
+}

+ 5 - 1
Pika/core/pikaSTD/logs/log.h

@@ -2,6 +2,7 @@
 #include <string>
 #include <string>
 #include <vector>
 #include <vector>
 #include <sstream>
 #include <sstream>
+#include <pushNotification/pushNotification.h>
 
 
 namespace pika
 namespace pika
 {
 {
@@ -27,13 +28,16 @@ namespace pika
 		std::string name = "";
 		std::string name = "";
 		bool firstLog = 0;
 		bool firstLog = 0;
 
 
-		std::vector<std::string> internalLogs; //todo reing buffer here
+		std::vector<std::string> internalLogs; //todo ring buffer here
 
 
+		//todo flag to remove this in release build
+		PushNotificationManager *pushNotificationManager = 0;
 	private:
 	private:
 		//used only interally.
 		//used only interally.
 		std::stringstream formatLog(const char *l, int type = logNormal);
 		std::stringstream formatLog(const char *l, int type = logNormal);
 		void logToFile(const char *l, int type = logNormal);
 		void logToFile(const char *l, int type = logNormal);
 		void logInternally(const char *l, int type = logNormal);
 		void logInternally(const char *l, int type = logNormal);
+		void logToPushNotification(const char *l, int type = logNormal);
 
 
 	};
 	};
 
 

+ 1 - 1
Pika/core/sharedRuntime/pushNotification/pushNotification.h

@@ -17,7 +17,7 @@ namespace pika
 		Notification() {};
 		Notification() {};
 	};
 	};
 
 
-
+	//todo flag to remove this in release build
 	struct PushNotificationManager
 	struct PushNotificationManager
 	{
 	{
 
 

+ 2 - 2
Pika/core/sharedRuntime/shortcutApi/shortcutApi.cpp

@@ -208,7 +208,7 @@ void ShortcutManager::update(const pika::Input &input)
 
 
 }
 }
 
 
-bool ShortcutManager::registerShortcut(const char *name, const char *s, bool *toggle)
+bool ShortcutManager::registerShortcut(const char *name, const char *s, bool *toggle, bool editable)
 {
 {
 
 
 	if (registeredShortcuts.find(name) != registeredShortcuts.end())
 	if (registeredShortcuts.find(name) != registeredShortcuts.end())
@@ -219,7 +219,7 @@ bool ShortcutManager::registerShortcut(const char *name, const char *s, bool *to
 	else
 	else
 	{
 	{
 		registeredShortcuts[name] 
 		registeredShortcuts[name] 
-			= Shortcut{std::move(normalizeShortcutName(s)), toggle};
+			= Shortcut{std::move(normalizeShortcutName(s)), toggle, editable};
 		return 1;
 		return 1;
 	}
 	}
 
 

+ 2 - 1
Pika/core/sharedRuntime/shortcutApi/shortcutApi.h

@@ -11,13 +11,14 @@ namespace pika
 		{
 		{
 			std::string shortcut = "";
 			std::string shortcut = "";
 			bool *toggle = 0;
 			bool *toggle = 0;
+			bool editable = true;
 		};
 		};
 
 
 		void update(const pika::Input &input);
 		void update(const pika::Input &input);
 
 
 		std::unordered_map<std::string, Shortcut> registeredShortcuts;
 		std::unordered_map<std::string, Shortcut> registeredShortcuts;
 
 
-		bool registerShortcut(const char *name, const char *s, bool *toggle);
+		bool registerShortcut(const char *name, const char *s, bool *toggle, bool editable = 1);
 
 
 		const char *getShortcut(const char *name);
 		const char *getShortcut(const char *name);
 	};
 	};