Browse Source

added more sizing options to sushi

meemknight 2 years ago
parent
commit
fdc1330667

+ 3 - 3
Pika/gameplay/containers.h

@@ -25,7 +25,7 @@ Container *getContainer(const char* name, pika::memory::MemoryArena *memoryArena
 //#include "containers/mario/marioEditor.h"
 //#include "containers/mario/marioNeuralVizualizer.h"
 //#include "containers/mario/marioNeuralTrainer.h"
-//#include "containers/minecraftDungeons/mcDungeonsEditor.h"
+#include "containers/minecraftDungeons/mcDungeonsEditor.h"
 //#include "containers/minecraftDungeons/mcDungeonsgameplay.h"
 //#include "containers/minecraftDungeons/mcDungeonsMenu.h"
 //#include "containers/hollowknight/hollowknight.h"
@@ -46,13 +46,13 @@ Container *getContainer(const char* name, pika::memory::MemoryArena *memoryArena
 	PIKA_DECLARE_CONTAINER(ImmageViewer) \
 	PIKA_DECLARE_CONTAINER(ThreeDTest) \
 	PIKA_DECLARE_CONTAINER(ThreeDEditor) \
-	PIKA_DECLARE_CONTAINER(PikaTextEditor) 
+	PIKA_DECLARE_CONTAINER(PikaTextEditor) \
+	PIKA_DECLARE_CONTAINER(McDungeonsEditor)
 	//PIKA_DECLARE_CONTAINER(Holloknight)\
 	//PIKA_DECLARE_CONTAINER(Mario) \
 	//PIKA_DECLARE_CONTAINER(MarioEditor) \
 	//PIKA_DECLARE_CONTAINER(MarioNeuralTrainer) \
 	//PIKA_DECLARE_CONTAINER(MarioNeuralVizualizer) \
-	//PIKA_DECLARE_CONTAINER(McDungeonsEditor) \
 	//PIKA_DECLARE_CONTAINER(McDungeonsGameplay) \
 	//PIKA_DECLARE_CONTAINER(McDungeonsMenu) 
 

+ 42 - 4
Pika/pluggins/pluggins/sushiViewer/sushiViewer.cpp

@@ -88,8 +88,45 @@ void SushiViewer::displaySushiTransformImgui(::sushi::Transform & e, glm::vec4 p
 		ImGui::DragFloat2("Pos pixels", &e.positionPixels[0]);
 		ImGui::DragFloat2("Pos percentage", &e.positionPercentage[0], 0.01);
 
-		ImGui::DragFloat2("Size pixels", &e.sizePixels[0]);
-		ImGui::DragFloat2("Size percentage", &e.sizePercentage[0], 0.01);
+		
+
+		ImGui::Combo("Size calculation", &e.sizeCalculationType, "normal"
+			"\0aspect ratio on x"
+			"\0aspect ratio on y"
+			"\0aspect ratio on X keep minimum"
+			"\0aspect ratio on y keep minimum"
+			"\0");
+
+		if (e.sizeCalculationType == sushi::Transform::normalSize)
+		{
+			ImGui::DragFloat2("Size pixels", &copy.sizePixels[0]);
+			ImGui::DragFloat2("Size percentage", &e.sizePercentage[0], 0.01);
+		}
+		else if (e.sizeCalculationType == sushi::Transform::useAspectRatioOnY)
+		{
+			ImGui::DragFloat("Size pixels", &e.sizePixels[0]);
+			ImGui::DragFloat("Size percentage x", &e.sizePercentage[0], 0.01);
+			ImGui::DragFloat("Aspect ratio", &e.aspectRation, 0.01, 0);
+		}
+		else if (e.sizeCalculationType == sushi::Transform::useAspectRatioOnX)
+		{
+			ImGui::DragFloat("Size pixels", &e.sizePixels[1]);
+			ImGui::DragFloat("Size percentage y", &e.sizePercentage[1], 0.01);
+			ImGui::DragFloat("Aspect ratio", &e.aspectRation, 0.01, 0);
+		}
+		else if (e.sizeCalculationType == sushi::Transform::useAspectRatioOnXKeepMinimum)
+		{
+			ImGui::DragFloat2("Size pixels", &e.sizePixels[0]);
+			ImGui::DragFloat2("Size percentage", &e.sizePercentage[0], 0.01);
+			ImGui::DragFloat("Aspect ratio", &e.aspectRation, 0.01, 0);
+		}
+		else if (e.sizeCalculationType == sushi::Transform::useAspectRatioOnYKeepMinimum)
+		{
+			ImGui::DragFloat2("Size pixels", &e.sizePixels[0]);
+			ImGui::DragFloat2("Size percentage", &e.sizePercentage[0], 0.01);
+			ImGui::DragFloat("Aspect ratio", &e.aspectRation, 0.01, 0);
+		}
+
 
 		e.changeSettings(copy, parent);
 
@@ -377,8 +414,8 @@ bool SushiViewer::update(pika::Input input, pika::WindowState windowState, Reque
 			if (parentOfParent)
 			{
 				parentRect = parentOfParent->outData.absTransform;
-
-				if (ImGui::Button("Select parent"))
+				
+				if (::pika::pikaImgui::blueButton("Select parent"))
 				{
 					img.elementId = parentOfParent->id;
 				}
@@ -566,6 +603,7 @@ bool SushiViewer::update(pika::Input input, pika::WindowState windowState, Reque
 		img.dragBegin = {};
 	}
 
+
 	renderer.flush();
 
 	return true;

+ 2 - 1
Pika/pluggins/pluggins/threeDEditor.h

@@ -62,7 +62,7 @@ struct ThreeDEditor: public Container
 			false, 10);
 
 		//helmetModel = renderer.loadModel(PIKA_RESOURCES_PATH "helmet/helmet.obj");
-		model = renderer.loadModel(PIKA_RESOURCES_PATH "rave.glb", 0.5, gl3d::TextureLoadQuality::maxQuality);
+		model = renderer.loadModel(PIKA_RESOURCES_PATH "rave.glb", gl3d::TextureLoadQuality::maxQuality, 1);
 		
 		gl3d::Transform t;
 		t.position = {0, -1, -4};
@@ -101,6 +101,7 @@ struct ThreeDEditor: public Container
 			
 		editor.update(requestedInfo.requestedImguiIds, renderer, input, 4, requestedInfo, {windowState.windowW,windowState.windowH});
 
+		renderer.setEntityAnimate(entity, true);
 
 		renderer.render(input.deltaTime);
 		glDisable(GL_DEPTH_TEST);

BIN
Pika/resources/image_2023-09-19_154022178.png


+ 5 - 10
Pika/resources/logs.txt

@@ -1,10 +1,5 @@
-#2023-09-09 21:32:24: Created container: SushiViewer
-#2023-09-09 21:37:11[warning]: Couldn't reloaded dll
-#2023-09-09 21:37:12: Reloaded dll
-#2023-09-09 21:38:23: Reloaded dll
-#2023-09-09 21:38:40: Reloaded dll
-#2023-09-09 21:45:04: Reloaded dll
-#2023-09-09 21:47:01: Reloaded dll
-#2023-09-09 21:47:59: Reloaded dll
-#2023-09-09 21:48:08: Reloaded dll
-#2023-09-09 21:48:43: Destroyed continer: SushiViewer #1
+#2023-10-17 21:03:44: Created container: SushiViewer
+#2023-10-17 21:05:21[warning]: Couldn't reloaded dll
+#2023-10-17 21:05:23[warning]: Couldn't reloaded dll
+#2023-10-17 21:05:24: Reloaded dll
+#2023-10-17 21:07:31: Destroyed continer: SushiViewer #1

BIN
Pika/resources/sushi/test.sushi


BIN
Pika/resources/sushi/test2.sushi


+ 14 - 24
Pika/thirdparty/sushi/include/sushi/sushiPrimitives.h

@@ -20,30 +20,6 @@ namespace sushi
 
 	struct Transform
 	{
-		//enum
-		//{
-		//	RelativeTransform = 0,
-		//	AbsoluteTransform,
-		//};
-		//
-		//enum
-		//{
-		//	DimensionsPercentage = 0,
-		//	DimensionsPixelsAbsolute,
-		//};
-		//
-		//union
-		//{
-		//	glm::vec4 dimensions = {0,0,1,1};
-		//	struct
-		//	{
-		//		glm::vec2 pos;
-		//		glm::vec2 size;
-		//	};
-		//};
-		//
-		//int placementType = RelativeTransform;
-		//int dimensionsType = DimensionsPercentage;
 
 		glm::vec2 sizePixels = {0,0};
 		glm::vec2 sizePercentage = {1,1};
@@ -51,6 +27,20 @@ namespace sushi
 		glm::vec2 positionPixels = {};
 		glm::vec2 positionPercentage = {};
 
+		float aspectRation = 1.f;
+
+		enum sizeCalculation
+		{
+			normalSize = 0,
+			useAspectRatioOnX,
+			useAspectRatioOnY,
+			useAspectRatioOnXKeepMinimum,
+			useAspectRatioOnYKeepMinimum,
+
+		};
+
+		int sizeCalculationType = 0;
+
 		enum anchor
 		{
 			topLeft = 0,

+ 44 - 39
Pika/thirdparty/sushi/src/sushiPrimitives.cpp

@@ -48,6 +48,49 @@ namespace sushi
 		glm::vec2 pos = {};
 		glm::vec2 size = parentSize * sizePercentage + sizePixels;
 
+		if (sizeCalculationType == Transform::normalSize)
+		{
+
+		}else if(sizeCalculationType == Transform::useAspectRatioOnY)
+		{
+			size.y = size.x * aspectRation;
+		}else if (sizeCalculationType == Transform::useAspectRatioOnX)
+		{
+			size.x = size.y * aspectRation;
+		}
+		else if (sizeCalculationType == Transform::useAspectRatioOnYKeepMinimum)
+		{
+			float newSize = size.x * aspectRation;
+			if(newSize > size.y)
+			{
+				float minimizeFactor = newSize / size.y;
+				size.y = newSize;
+				size /= minimizeFactor;
+			}
+			else
+			{
+				size.y = newSize;
+			}
+		}
+		else if (sizeCalculationType == Transform::useAspectRatioOnXKeepMinimum)
+		{
+			float newSize = size.y * aspectRation;
+			if (newSize > size.x)
+			{
+				float minimizeFactor = newSize / size.x;
+				size.x = newSize;
+				size /= minimizeFactor;
+			}
+			else
+			{
+				size.x = newSize;
+			}
+		}
+		else
+		{
+			//toto error
+		}
+
 		auto leftAlign = [&]()
 		{
 			pos.x = parentPos.x;
@@ -155,46 +198,8 @@ namespace sushi
 			return {};
 		}
 
-		pos += positionPixels + parentSize * positionPercentage;
-		//switch (dimensionsType)
-		//{
-		//case DimensionsPercentage:
-		//{
-		//	size = glm::vec2(dimensions.z, dimensions.w) * parentSize;
-		//}
-		//break;
-		//
-		//case DimensionsPixelsAbsolute:
-		//{
-		//	size = glm::vec2(dimensions.z, dimensions.w);
-		//}
-		//break;
-		//
-		//default:
-		//return {};
-		////todo special error functions
-		//};
-		//
-		////determine position;
-		//switch (placementType)
-		//{
-		//case RelativeTransform:
-		//{
-		//	pos = parentPos + glm::vec2(dimensions);
-		//}
-		//break;
-		//
-		//case AbsoluteTransform:
-		//{
-		//	pos = glm::vec2(dimensions);
-		//}
-		//break;
-		//
-		//default:
-		//return {};
-		////todo special error functions
-		//};
 
+		pos += positionPixels + parentSize * positionPercentage;
 
 		return {pos, size};
 	}