Explorar o código

a basic setup sushi

meemknight %!s(int64=2) %!d(string=hai) anos
pai
achega
e24de41a6a

+ 21 - 21
Pika/CMakeLists.txt

@@ -21,7 +21,7 @@ set(BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE) #under no circumstance we want th
 #declare projects
 project(pikaCore)
 project(pikaGameplay)
-project(pikaProduction)
+#project(pikaProduction)
 
 
 #add third party libraries
@@ -104,26 +104,26 @@ target_link_libraries(pikaGameplay PRIVATE glad glfw gl2d gl3d glui glm stb_imag
 
 
 #pikaProduction ###########################################
-add_executable(pikaProduction)
-
-target_compile_definitions(pikaProduction PUBLIC PIKA_PRODUCTION)
-set_property(TARGET pikaProduction PROPERTY CXX_STANDARD 17)
-
-target_sources(pikaProduction PRIVATE 
-	"${PIKA_SOURCES_CORE_CONFIG}" "${PIKA_SOURCES_CORE_EDITOR}" "${PIKA_SOURCES_PLUGGINS}"
-	"${PIKA_SOURCES_CORE_RUNTIME}" "${PIKA_SOURCES_CORE_STD}" "${PIKA_SOURCES_GAMEPLAY}" "${PIKA_SOURCES_CORE_SHARED_RUNTIME}")
-target_include_directories(pikaProduction PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/core/coreConfig/")
-target_include_directories(pikaProduction PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/core/pikaEditor/")
-target_include_directories(pikaProduction PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/core/pikaRuntime/")
-target_include_directories(pikaProduction PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/core/pikaSTD/")
-target_include_directories(pikaProduction PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/gameplay/")
-target_include_directories(pikaProduction PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/core/sharedRuntime/")
-target_include_directories(pikaProduction PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/pluggins/")
-
-target_link_libraries(pikaProduction PRIVATE glad glfw gl2d gl3d glui glm stb_image 
-	stb_truetype imgui safeSave profilerLib box2d sushi)
-
-
+#add_executable(pikaProduction)
+#
+#target_compile_definitions(pikaProduction PUBLIC PIKA_PRODUCTION)
+#set_property(TARGET pikaProduction PROPERTY CXX_STANDARD 17)
+#
+#target_sources(pikaProduction PRIVATE 
+#	"${PIKA_SOURCES_CORE_CONFIG}" "${PIKA_SOURCES_CORE_EDITOR}" "${PIKA_SOURCES_PLUGGINS}"
+#	"${PIKA_SOURCES_CORE_RUNTIME}" "${PIKA_SOURCES_CORE_STD}" "${PIKA_SOURCES_GAMEPLAY}" "${PIKA_SOURCES_CORE_SHARED_RUNTIME}")
+#target_include_directories(pikaProduction PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/core/coreConfig/")
+#target_include_directories(pikaProduction PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/core/pikaEditor/")
+#target_include_directories(pikaProduction PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/core/pikaRuntime/")
+#target_include_directories(pikaProduction PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/core/pikaSTD/")
+#target_include_directories(pikaProduction PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/gameplay/")
+#target_include_directories(pikaProduction PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/core/sharedRuntime/")
+#target_include_directories(pikaProduction PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/pluggins/")
+#
+#target_link_libraries(pikaProduction PRIVATE glad glfw gl2d gl3d glui glm stb_image 
+#	stb_truetype imgui safeSave profilerLib box2d sushi)
+#
+#
 
 #################^^^^^^^^^^^^^^############################
 

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

@@ -536,8 +536,23 @@ void pika::ContainerManager::update(pika::LoadedDll &loadedDll, pika::PikaWindow
 				auto s = ImGui::GetContentRegionMax();
 
 				//todo try set borders here at 0,0, easiest thing to do probably
-				ImGui::Image((void *)c.second.requestedContainerInfo.requestedFBO.texture, s, {0, 1}, {1, 0},
-					{1,1,1,1}, {0,0,0,1});
+				ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.f);
+				//ImGui::Image((void *)c.second.requestedContainerInfo.requestedFBO.texture, s, {0, 1}, {1, 0},
+				//	{1,1,1,1}, {0,0,0,0});
+
+				ImVec2 pos = ImGui::GetCursorScreenPos();
+				ImVec2 maxPos = {ImGui::GetWindowPos().x + ImGui::GetWindowSize().x,
+					ImGui::GetWindowPos().y + ImGui::GetWindowSize().y};
+				unsigned texId = c.second.requestedContainerInfo.requestedFBO.texture;
+
+				ImGui::GetWindowDrawList()->AddImage(
+					(void *)texId,
+					ImVec2(pos.x, pos.y),
+					ImVec2(maxPos),
+					ImVec2(0, 1), ImVec2(1, 0)
+				);
+
+				ImGui::PopStyleVar();
 
 				ImGui::End();
 

+ 213 - 6
Pika/pluggins/pluggins/sushiViewer/sushiViewer.cpp

@@ -9,9 +9,8 @@ ContainerStaticInfo SushiViewer::containerInfo()
 	ContainerStaticInfo info = {};
 	info.defaultHeapMemorySize = pika::MB(10);
 
-	info.requestImguiFbo = true; //todo this should not affect the compatibility of input recording
-
-
+	info.requestImguiFbo = true;
+	info.pushAnImguiIdForMe = true;
 
 	return info;
 }
@@ -20,22 +19,230 @@ bool SushiViewer::create(RequestedContainerInfo &requestedInfo, pika::StaticStri
 {
 	renderer.create(requestedInfo.requestedFBO.fbo);
 
+
 	sushi::SushiUiElement element;
-	element.color = Colors_Magenta;
+	element.background.color = Colors_Magenta;
 	element.transform.absoluteTransformPixelSize({100,100,200,100});
+	element.id = 2;
 
-	sushiContext.allUiElements.push_back(element);
+	sushiContext.root.allUiElements.push_back(element);
 
 	return true;
 }
 
+void displaySushiBackgroundImgui(::sushi::Background &e)
+{
+	if (ImGui::BeginChildFrame(11, {0, 100}, true))
+	{
+		ImGui::Text("Background element editor");
+
+		ImGui::ColorEdit4("Background color", &e.color[0]);
+
+		//todo texture stuff
+	}
+	ImGui::EndChildFrame();
+}
+
+void displaySushiTransformImgui(::sushi::Transform &e)
+{
+	if (ImGui::BeginChildFrame(12, {0, 100}, true))
+	{
+		ImGui::Text("Transform element editor");
+
+
+
+	}
+	ImGui::EndChildFrame();
+}
+
+void displaySushiUiElementImgui(::sushi::SushiUiElement &e)
+{
+	if (ImGui::BeginChildFrame(13, {0, 500}, true))
+	{
+		ImGui::Text("Ui element editor: %s, id: %u", e.name, e.id);
+
+		displaySushiTransformImgui(e.transform);
+		ImGui::Separator();
+		displaySushiBackgroundImgui(e.background);
+
+	}
+	ImGui::EndChildFrame();
+}
+
+void displaySushiParentElementImgui(::sushi::SushiParent &e)
+{
+	if (ImGui::BeginChildFrame(14, {0, 700}, true))
+	{
+		ImGui::Text("Parent editor: %s, id: %u", e.name, e.id);
+
+		displaySushiTransformImgui(e.transform);
+		ImGui::Separator();
+		displaySushiBackgroundImgui(e.background);
+
+		ImGui::Separator();
+		for (auto &i : e.allUiElements)
+		{
+			displaySushiUiElementImgui(i);
+		}
+
+	}
+	ImGui::EndChildFrame();
+}
+
+void visit(sushi::SushiParent &parent, unsigned int id, sushi::SushiUiElement* &selectedElement,
+sushi::SushiParent* &selectedParent
+	)
+{
+	if (parent.id == id)
+	{
+		selectedParent = &parent;
+		return;
+	}
+
+	for (auto &i : parent.allUiElements)
+	{
+		if (i.id == id)
+		{
+			selectedElement = &i;
+			selectedParent = &parent;
+			return;
+		}
+	}
+
+	for (auto &i : parent.subElements)
+	{
+		visit(i, id, selectedElement, selectedParent);
+	}
+
+	return;
+};
+
+void visitSelect(sushi::SushiParent &parent, unsigned int &id, sushi::SushiUiElement *&selectedElement,
+	sushi::SushiParent *&selectedParent, glm::vec2 mousePos
+)
+{
+	if (sushi::pointInBox(mousePos, parent.outData.absTransform))
+	{
+		id = parent.id;
+	}
+
+	if (parent.id == id)
+	{
+		selectedParent = &parent;
+	}
+
+	for (auto &i : parent.allUiElements)
+	{
+		if (sushi::pointInBox(mousePos, i.outData.absTransform))
+		{
+			id = i.id;
+		}
+
+		if (i.id == id)
+		{
+			selectedElement = &i;
+			selectedParent = &parent;
+		}
+	}
+
+	for (auto &i : parent.subElements)
+	{
+		visitSelect(i, id, selectedElement, selectedParent, mousePos);
+	}
+
+	return;
+};
+
+
 bool SushiViewer::update(pika::Input input, pika::WindowState windowState, RequestedContainerInfo &requestedInfo)
 {
+	bool leftCtrlHeld = input.buttons[pika::Button::LeftCtrl].held();
+
+#pragma region update stuff
 	glClear(GL_COLOR_BUFFER_BIT);
 	renderer.updateWindowMetrics(windowState.windowW, windowState.windowH);
 
+	if (leftCtrlHeld)
+	{
+		sushi::SushiInput in;
+		in.mouseX = input.mouseX;
+		in.mouseY = input.mouseY;
+		sushiContext.update(renderer, in);
+	}
+	else
+	{
+		sushiContext.update(renderer, pika::toSushi(input));
+	}
+#pragma endregion
+
+	
+
+	sushi::SushiUiElement *selectedElement = 0;
+	sushi::SushiParent *selectedParent = 0;
+
+	ImGui::Begin("Sushi editor");
+	{
+		ImGui::Text("Current selected id: %u", img.elementId);
+
+		auto &c = sushiContext;
+		
+
+		if (img.elementId == 0)
+		{
+			img.elementId = c.root.id;
+		}
+		
+		if (leftCtrlHeld && input.lMouse.held())
+		{		
+			visitSelect(sushiContext.root, img.elementId, selectedElement, selectedParent,
+				{input.mouseX, input.mouseY});
+		}
+		else
+		{
+			visit(sushiContext.root, img.elementId, selectedElement, selectedParent);
+		}
+
+		//ImGui::InputInt("Element: ", &img.elementSelected);
+		//
+		//size_t elementsSize = c.root.allUiElements.size();
+		//img.elementSelected = glm::clamp(img.elementSelected, -1, (int)(elementsSize - 1));
+		//
+
+		if (selectedElement)
+		{
+			if (selectedParent)
+			{
+				if (ImGui::Button("Select parent"))
+				{
+					img.elementId = selectedParent->id;
+				}
+			}
+
+			displaySushiUiElementImgui(*selectedElement);
+		}else
+		if (selectedParent)
+		{
+			displaySushiParentElementImgui(*selectedParent);
+		}
+
+
+	
+	}
+	ImGui::End();
+
+
+	if (selectedParent)
+	{
+		//todo add alias render box
+		renderer.renderRectangleOutline(selectedParent->outData.absTransform, 
+			{1,0,0,0.5}, 4.0f);
+	}
 
-	sushiContext.update(renderer, pika::toSushi(input));
+	if (selectedElement)
+	{
+		renderer.renderRectangleOutline(selectedElement->outData.absTransform,
+			{1,0,0,0.5}, 4.0f);
+	}
 
 
 	renderer.flush();

+ 6 - 0
Pika/pluggins/pluggins/sushiViewer/sushiViewer.h

@@ -24,5 +24,11 @@ struct SushiViewer: public Container
 
 	void destruct(RequestedContainerInfo &requestedInfo);
 
+	struct ImGuiStuff
+	{
+		unsigned int elementId = 0;
+
+	}img;
+
 };
 

+ 2 - 2
Pika/resources/logs.txt

@@ -1,2 +1,2 @@
-#2023-09-06 13:46:12: Created container: SushiViewer
-#2023-09-06 13:46:25: Destroyed continer: SushiViewer #1
+#2023-09-06 16:23:07: Created container: SushiViewer
+#2023-09-06 16:23:14: Destroyed continer: SushiViewer #1

+ 59 - 7
Pika/thirdparty/sushi/include/sushi/sushi.h

@@ -8,31 +8,83 @@ namespace sushi
 
 	struct SushiUiElement;
 
+	struct OutData
+	{
+		glm::vec4 absTransform = {};
+
+		void set(glm::vec4 absTransform)
+		{
+			this->absTransform = absTransform;
+
+		}
+	};
+
+	struct SushiParent
+	{
+		SushiParent() {};
+		SushiParent(const char *name, int id)
+		{
+			this->id = id;
+			std::strncpy(this->name, name, sizeof(name) - 1);
+		};
+		SushiParent(const char *name, int id, Background b)
+		{
+			this->id = id;
+			std::strncpy(this->name, name, sizeof(name) - 1);
+			background = b;
+		};
+
+		Transform transform;
+		Background background;
+		char name[16] = {};
+		unsigned int id = 0;
+
+		std::vector<SushiUiElement> allUiElements;
+
+		std::vector<SushiParent> subElements;
+
+		void update(gl2d::Renderer2D &renderer,
+			sushi::SushiInput &input, glm::vec4 parentTransform);
+		
+		OutData outData;
+
+	};
+
 	//this is a sushi context. Holds all the windows and manages stuff
 	struct SushyContext
 	{
+		void createBasicSchene(int baseId = 1, const char *name = "Main Parent");
 
-		std::vector<SushiUiElement> allUiElements;
+		SushiParent root = SushiParent{"Main Parent", 1, sushi::Background(glm::vec4{0,0,0,1}, 
+			gl2d::Texture{})};
+		unsigned int currentIdCounter = 2;
 
 		//draw regions are like this: x, y, w, h
 		void update(gl2d::Renderer2D &renderer, 
 			sushi::SushiInput &input);
 
-		glm::vec4 background = {0,0,0,1};
-
 	};
 
 	
-
 	//this can also be a window or a button or whatever you want
 	struct SushiUiElement
 	{
-
+		SushiUiElement() {};
+		SushiUiElement(const char *name, int id) 
+		{
+			this->id = id;
+			std::strncpy(this->name, name, sizeof(name)-1);
+		};
+
+		char name[16] = {};
+		unsigned int id = 0;
 		Transform transform;
-		glm::vec4 color = {1,1,1,1};
-
+		Background background;
 
+		void update(gl2d::Renderer2D &renderer,
+			sushi::SushiInput &input, glm::vec4 parentTransform);
 
+		OutData outData;
 	};
 
 

+ 20 - 5
Pika/thirdparty/sushi/include/sushi/sushiPrimitives.h

@@ -1,28 +1,29 @@
 #pragma once
 #include <glm/glm.hpp>
+#include <gl2d/gl2d.h>
 
 namespace sushi
 {
 
+	bool pointInBox(glm::vec2 p, glm::vec4 box);
+
 	struct Transform
 	{
 		enum
 		{
-			NoTransformErr = 0,
 			RelativeTransform,
 			AbsoluteTransform,
 		};
 
 		enum
 		{
-			NoDimensionsErr = 0,
 			DimensionsPercentage,
 			DimensionsPixelsAbsolute,
 		};
 
 		union
 		{
-			glm::vec4 dimensions = {};
+			glm::vec4 dimensions = {0,0,1,1};
 			struct
 			{
 				glm::vec2 pos;
@@ -30,14 +31,28 @@ namespace sushi
 			};
 		};
 
-		int placementType = 0;
-		int dimensionsType = 0;
+		int placementType = RelativeTransform;
+		int dimensionsType = DimensionsPercentage;
 
 		void absoluteTransformPixelSize(glm::vec4 dimensions);
 		void relativeTransformPixelSize(glm::vec4 dimensions);
+		void relativeTransformDimensionsPercentage(glm::vec4 dimensions);
 
 		glm::vec4 applyTransform(glm::vec4 parent);
 	};
 
+	Transform defaultTransform();
+
+	struct Background
+	{
+		Background() {};
+		Background(glm::vec4 color):color(color) {};
+		Background(glm::vec4 color, gl2d::Texture texture):color(color), texture(texture) {};
+
+		glm::vec4 color = {1,1,1,1};
+		gl2d::Texture texture = {};
+
+		void render(gl2d::Renderer2D &renderer, glm::vec4 pos);
+	};
 
 };

+ 39 - 10
Pika/thirdparty/sushi/src/sushi.cpp

@@ -3,6 +3,15 @@
 namespace sushi
 {
 
+	void SushyContext::createBasicSchene(int baseId, const char *name)
+	{
+		*this = {};
+		root.id = baseId;
+		currentIdCounter = baseId + 1;
+		std::strncpy(root.name, name, sizeof(root.name)-1);
+
+	
+	}
 
 	void sushi::SushyContext::update(gl2d::Renderer2D &renderer,
 		sushi::SushiInput &input)
@@ -17,25 +26,45 @@ namespace sushi
 
 		renderer.pushCamera();
 		{
-			//backgrouund
-			renderer.renderRectangle(drawRegion, background);
+			root.update(renderer, input, drawRegion);
 
+		}
+		renderer.popCamera();
+	}
+
+	void sushi::SushiParent::update(gl2d::Renderer2D &renderer,
+		sushi::SushiInput &input, glm::vec4 parentTransform)
+	{
 
-			auto uiElSize = allUiElements.size();
-			for (int i = 0; i < uiElSize; i++)
-			{
-				glm::vec4 rectRez = allUiElements[i].transform.applyTransform(drawRegion);
+		glm::vec4 drawRegion = transform.applyTransform(parentTransform);
+		outData.set(drawRegion);
 
-				renderer.renderRectangle(rectRez, allUiElements[i].color);
 
-			}
+		//backgrouund
+		background.render(renderer, drawRegion);
 
+		auto uiElSize = allUiElements.size();
+		for (int i = 0; i < uiElSize; i++)
+		{
+			allUiElements[i].update(renderer, input, drawRegion);
+		}
+
+		auto subUiElSize = subElements.size();
+		for (int i = 0; i < subUiElSize; i++)
+		{
+			subElements[i].update(renderer, input, drawRegion);
 		}
-		renderer.popCamera();
-	}
 
+	}
 
+	void SushiUiElement::update(gl2d::Renderer2D &renderer, 
+		sushi::SushiInput &input, glm::vec4 parentTransform)
+	{
+		glm::vec4 rectRez = transform.applyTransform(parentTransform);
+		outData.set(rectRez);
 
+		background.render(renderer, rectRez);
+	}
 
 };
 

+ 33 - 1
Pika/thirdparty/sushi/src/sushiPrimitives.cpp

@@ -2,6 +2,22 @@
 
 namespace sushi
 {
+	bool pointInBox(glm::vec2 p, glm::vec4 box)
+	{
+		if 
+			(
+				(p.x >= box.x && p.x <= (box.x + box.z)) &&
+				(p.y >= box.y && p.y <= (box.y + box.w))
+			)
+		{
+			return true;
+		}
+		else
+		{
+			return false;
+		}
+	}
+
 	void Transform::absoluteTransformPixelSize(glm::vec4 dimensions)
 	{
 		this->dimensions = dimensions;
@@ -15,6 +31,13 @@ namespace sushi
 		placementType = RelativeTransform;
 		dimensionsType = DimensionsPixelsAbsolute;
 	}
+	
+	void Transform::relativeTransformDimensionsPercentage(glm::vec4 dimensions)
+	{
+		this->dimensions = dimensions;
+		placementType = RelativeTransform;
+		dimensionsType = DimensionsPercentage;
+	}
 
 	glm::vec4 Transform::applyTransform(glm::vec4 parent)
 	{
@@ -69,6 +92,15 @@ namespace sushi
 		return {pos, size};
 	}
 
+	void Background::render(::gl2d::Renderer2D &renderer, glm::vec4 pos)
+	{
+		renderer.renderRectangle(pos, color);
+	}
 
-
+	Transform defaultTransform()
+	{
+		Transform t;
+		t.relativeTransformDimensionsPercentage({0,0,1,1});
+		return Transform();
+	}
 };