Bläddra i källkod

working at adding text rendering to sushi

meemknight 2 år sedan
förälder
incheckning
46392e2e0d

+ 1 - 1
Pika/CMakeLists.txt

@@ -19,8 +19,8 @@ set(BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE) #under no circumstance we want th
 
 
 #declare projects
-project(pikaCore)
 project(pikaGameplay)
+project(pikaCore)
 #project(pikaProduction)
 
 

+ 7 - 1
Pika/core/pikaSTD/engineLibraresSupport/engineGL2DSupport.cpp

@@ -57,6 +57,7 @@
 	return t;
 }
 
+//todo make this use the default allocator or a temporary allocator
 ::gl2d::Font pika::gl2d::loadFont(const char *path, RequestedContainerInfo &info)
 {
 	::gl2d::Font f = {};
@@ -70,7 +71,10 @@
 		}
 		else
 		{
-			info.consoleWrite(std::string("error loading font: ") + path);
+			info.consoleWrite(std::string("error loading font, parsing file ") + path);
+			//todo
+			//info.log((std::string("error loading font, parsing file: ") + path).c_str(), pika::logError);
+			
 		}
 
 		delete[] data;
@@ -78,6 +82,8 @@
 	else
 	{
 		info.consoleWrite(std::string("error loading font: ") + path);
+		//todo
+		//info.log((std::string("error loading font, openning file: ") + path).c_str(), pika::logError);
 		return {};
 	}
 

+ 5 - 0
Pika/core/sharedRuntime/baseContainer.h

@@ -116,9 +116,14 @@ struct RequestedContainerInfo
 	{
 		//do not allocate memory here!
 		//log is from core realm
+		//todo test
 
 		if (!logManager) { return false; }
+		
+		::pika::memory::pushCustomAllocatorsToStandard();
 		logManager->log(l, type);
+		::pika::memory::popCustomAllocatorsToStandard();
+
 	}
 
 	//returns true if succeded (can return false if console is disabeled)

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

@@ -1,13 +1,15 @@
 #include <pluggins/sushiViewer/sushiViewer.h>
 #include <engineLibraresSupport/sushi/engineSushiSupport.h>
 #include <pikaImgui/pikaImgui.h>
+#include <imgui_stdlib.h>
+#include <engineLibraresSupport/engineGL2DSupport.h>
 
 //todo user can request imgui ids; shortcut manager context; allocators
 
 ContainerStaticInfo SushiViewer::containerInfo()
 {
 	ContainerStaticInfo info = {};
-	info.defaultHeapMemorySize = pika::MB(10);
+	info.defaultHeapMemorySize = pika::MB(50);
 
 	info.requestImguiFbo = true;
 	info.pushAnImguiIdForMe = true;
@@ -18,6 +20,7 @@ ContainerStaticInfo SushiViewer::containerInfo()
 bool SushiViewer::create(RequestedContainerInfo &requestedInfo, pika::StaticString<256> commandLineArgument)
 {
 	renderer.create(requestedInfo.requestedFBO.fbo);
+	font = pika::gl2d::loadFont(PIKA_RESOURCES_PATH "arial.ttf", requestedInfo);
 
 	return true;
 }
@@ -99,7 +102,7 @@ void SushiViewer::displaySushiTransformImgui(::sushi::Transform & e, glm::vec4 p
 
 		if (e.sizeCalculationType == sushi::Transform::normalSize)
 		{
-			ImGui::DragFloat2("Size pixels", &copy.sizePixels[0]);
+			ImGui::DragFloat2("Size pixels", &e.sizePixels[0]);
 			ImGui::DragFloat2("Size percentage", &e.sizePercentage[0], 0.01);
 		}
 		else if (e.sizeCalculationType == sushi::Transform::useAspectRatioOnY)
@@ -134,6 +137,22 @@ void SushiViewer::displaySushiTransformImgui(::sushi::Transform & e, glm::vec4 p
 	ImGui::EndChildFrame();
 }
 
+void SushiViewer::displaySushiTextElementImgui(::sushi::Text &e, glm::vec4 parent, int id)
+{
+	ImGui::PushID(id);
+
+	ImGui::Text("Text element:");
+
+	ImGui::InputText("text content", &e.text);
+
+	::pika::pikaImgui::ColorEdit4Swatches("Text color: ", &e.color[0]);
+
+	displaySushiTransformImgui(e.transform, parent, id);
+
+	ImGui::PopID();
+
+}
+
 void SushiViewer::displaySushiParentElementImgui(::sushi::SushiParent &e, glm::vec4 parent,
 	bool displayChildren)
 {
@@ -180,14 +199,20 @@ void SushiViewer::displaySushiParentElementImgui(::sushi::SushiParent &e, glm::v
 		displaySushiBackgroundImgui(e.background, e.id + 10000);
 		ImGui::Separator();
 
-		sushi::Transform transform;
-		transform.anchorPoint = sushi::Transform::center; 
-		transform.sizePercentage = glm::vec2(0.5f);
+		displaySushiTextElementImgui(e.text, e.outData.absTransform, e.id);
+
+		ImGui::Separator();
+
 
 		if (displayChildren)
 		{
+
 			if (pika::pikaImgui::greenButton("Add parent"))
 			{
+				sushi::Transform transform;
+				transform.anchorPoint = sushi::Transform::center;
+				transform.sizePercentage = glm::vec2(0.5f);
+
 				//img.elementId = sushiContext.addParent(e, "New Item", transform,
 				//	sushi::Background({0.5,0.2,0.2,1.f}));
 
@@ -289,7 +314,7 @@ bool SushiViewer::update(pika::Input input, pika::WindowState windowState, Reque
 		sushi::SushiInput in;
 		in.mouseX = input.mouseX;
 		in.mouseY = input.mouseY;
-		sushiContext.update(renderer, in);
+		sushiContext.update(renderer, in, font);
 	}
 	//else
 	//{

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

@@ -14,6 +14,7 @@ struct SushiViewer: public Container
 
 	gl2d::Renderer2D renderer;
 	sushi::SushyContext sushiContext;
+	gl2d::Font font;
 
 	static ContainerStaticInfo containerInfo();
 
@@ -38,6 +39,8 @@ struct SushiViewer: public Container
 		
 	}img;
 
+	void displaySushiTextElementImgui(::sushi::Text &e, glm::vec4 parent, int id);
+
 	void displaySushiParentElementImgui(::sushi::SushiParent &e, glm::vec4 parent, bool displayChildren);
 
 	void displaySushiTransformImgui(::sushi::Transform &e, glm::vec4 parent, int id);

+ 5 - 5
Pika/resources/logs.txt

@@ -1,5 +1,5 @@
-#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
+#2023-10-17 22:59:44: Created container: SushiViewer
+#2023-10-17 23:00:39[warning]: Couldn't reloaded dll
+#2023-10-17 23:00:41[warning]: Couldn't reloaded dll
+#2023-10-17 23:00:42: Reloaded dll
+#2023-10-17 23:04:28: Destroyed continer: SushiViewer #1

BIN
Pika/resources/sushi/menuItem.sushi


+ 32 - 1
Pika/thirdparty/gl2d/include/gl2d/gl2d.h

@@ -1,5 +1,5 @@
 //////////////////////////////////////////////////
-//gl2d.h				1.2.6
+//gl2d.h				1.5.0
 //Copyright(c) 2020 Luta Vlad
 //https://github.com/meemknight/gl2d
 //
@@ -413,6 +413,37 @@ namespace gl2d
 			const float spacing = 4, const float line_space = 3, bool showInCenter = 1, const Color4f ShadowColor = {0.1,0.1,0.1,1}
 		, const Color4f LightColor = {});
 
+		//determins the text size so that it fits in the given box,
+		//the x and y components of the transform are ignored
+		float determineTextRescaleFitSmaller(const std::string &str,
+			gl2d::Font &f, glm::vec4 transform, float maxSize);
+
+		//determins the text size so that it fits in the given box,
+		//the x and y components of the transform are ignored
+		float determineTextRescaleFit(const std::string &str,
+			gl2d::Font &f, glm::vec4 transform);
+
+		//returns number of lines
+		//out rez is optional
+		int wrap(const std::string &in, gl2d::Font &f,
+			float baseSize, float maxDimension, std::string *outRez);
+
+		// The origin will be the bottom left corner since it represents the line for the text to be drawn
+		//Pacing and lineSpace are influenced by size
+		//todo the function should returns the size of the text drawn also refactor
+		void renderTextWrapped(const std::string &text,
+			gl2d::Font f, glm::vec4 textPos, glm::vec4 color, float baseSize,
+			float spacing = 4, float lineSpacing = 3,
+			bool showInCenter = true, glm::vec4 shadowColor = {0.1,0.1,0.1,1}, glm::vec4 lightColor = {});
+
+		glm::vec2 getTextSizeWrapped(const std::string &text,
+			gl2d::Font f, float maxTextLenght, float baseSize, float spacing = 4, float lineSpacing = 3);
+
+		//determins the text size so that it fits in the given box,
+		//the x and y components of the transform are ignored
+		float determineTextRescaleFitBigger(const std::string &str,
+			gl2d::Font &f, glm::vec4 transform, float minSize);
+
 		void renderRectangle(const Rect transforms, const Texture texture, const Color4f colors[4], const glm::vec2 origin = {}, const float rotationDegrees = 0.f, const glm::vec4 textureCoords = GL2D_DefaultTextureCoords);
 		inline void renderRectangle(const Rect transforms, const Texture texture, const Color4f colors = {1,1,1,1}, const glm::vec2 origin = {}, const float rotationDegrees = 0, const glm::vec4 textureCoords = GL2D_DefaultTextureCoords)
 		{

+ 216 - 1
Pika/thirdparty/gl2d/src/gl2d.cpp

@@ -1,5 +1,5 @@
 //////////////////////////////////////////////////
-//gl2d.cpp				1.2.5
+//gl2d.cpp				1.5.0
 //Copyright(c) 2020 Luta Vlad
 //https://github.com/meemknight/gl2d
 // 
@@ -50,6 +50,10 @@
 // rect outline rendering
 // circle outline rendering
 // 
+// 1.5.0
+// started to add some more needed text functions
+// needed to be tested tho
+// 
 /////////////////////////////////////////////////////////
 
 
@@ -1336,6 +1340,192 @@ namespace gl2d
 
 	}
 
+	float Renderer2D::determineTextRescaleFitSmaller(const std::string &str,
+		gl2d::Font &f, glm::vec4 transform, float maxSize)
+	{
+		auto s = getTextSize(str.c_str(), f, maxSize);
+
+		float ratioX = transform.z / s.x;
+		float ratioY = transform.w / s.y;
+
+
+		if (ratioX > 1 && ratioY > 1)
+		{
+			return maxSize;
+		}
+		else
+		{
+			if (ratioX < ratioY)
+			{
+				return maxSize*ratioX;
+			}
+			else
+			{
+				return maxSize * ratioY;
+			}
+		}
+	}
+
+
+	float Renderer2D::determineTextRescaleFitBigger(const std::string &str,
+		gl2d::Font &f, glm::vec4 transform, float minSize)
+	{
+		auto s = getTextSize(str.c_str(), f, minSize);
+
+		float ratioX = transform.z / s.x;
+		float ratioY = transform.w / s.y;
+
+
+		if (ratioX > 1 && ratioY > 1)
+		{
+			if (ratioX > ratioY)
+			{
+				return minSize * ratioY;
+			}
+			else
+			{
+				return minSize * ratioX;
+			}
+		}
+		else
+		{
+			
+		}
+
+		return minSize;
+	
+	}
+
+	float Renderer2D::determineTextRescaleFit(const std::string &str,
+		gl2d::Font &f, glm::vec4 transform)
+	{
+		float ret = 1;
+
+		auto s = getTextSize(str.c_str(), f, ret);
+
+		float ratioX = transform.z / s.x;
+		float ratioY = transform.w / s.y;
+
+
+		if (ratioX > 1 && ratioY > 1)
+		{
+			if (ratioX > ratioY)
+			{
+				return ret * ratioY;
+			}
+			else
+			{
+				return ret * ratioX;
+			}
+		}
+		else
+		{
+			if (ratioX < ratioY)
+			{
+				return ret * ratioX;
+			}
+			else
+			{
+				return ret * ratioY;
+			}
+		}
+
+		return ret;
+	}
+
+	int  Renderer2D::wrap(const std::string &in, gl2d::Font &f,
+		float baseSize, float maxDimension, std::string *outRez)
+	{
+		if (outRez)
+		{
+			*outRez = "";
+			outRez->reserve(in.size() + 10);
+		}
+
+		std::string word = "";
+		std::string currentLine = "";
+		currentLine.reserve(in.size() + 10);
+
+		bool wrap = 0;
+		bool newLine = 1;
+		int newLineCounter = 0;
+
+		for (int i = 0; i < in.size(); i++)
+		{
+			word.push_back(in[i]);
+			currentLine.push_back(in[i]);
+
+			if (in[i] == ' ')
+			{
+				if (wrap)
+				{
+					if (outRez)
+					{
+						outRez->push_back('\n'); currentLine = "";
+					}
+					newLineCounter++;
+
+				}
+
+				if (outRez)
+				{
+					*outRez += word;
+				}
+				word = "";
+				wrap = 0;
+				newLine = false;
+			}
+			else if (in[i] == '\n')
+			{
+				if (wrap)
+				{
+					if (outRez)
+					{
+						outRez->push_back('\n');
+					}
+					newLineCounter++;
+				}
+
+				currentLine = "";
+
+				if (outRez)
+				{
+					*outRez += word;
+				}
+				word = "";
+				wrap = 0;
+				newLine = true;
+			}
+			else
+			{
+				//let's check, only if needed
+				if (!wrap && !newLine)
+				{
+					float size = baseSize;
+					auto textSize = getTextSize(currentLine.c_str(), f, size);
+
+					if (textSize.x >= maxDimension && !newLine)
+					{
+						//wrap last word
+						wrap = 1;
+					}
+				};
+			}
+
+		}
+
+		{
+			if (wrap) { if (outRez)outRez->push_back('\n'); newLineCounter++; }
+
+			if (outRez)
+			{
+				*outRez += word;
+			}
+		}
+
+		return newLineCounter + 1;
+	}
+
 	void Renderer2D::renderText(glm::vec2 position, const char *text, const Font font,
 		const Color4f color, const float size, const float spacing, const float line_space, bool showInCenter,
 		const Color4f ShadowColor
@@ -1486,6 +1676,29 @@ namespace gl2d
 		}
 	}
 
+	void Renderer2D::renderTextWrapped(const std::string &text,
+		gl2d::Font f, glm::vec4 textPos, glm::vec4 color, float baseSize,
+		float spacing, float lineSpacing,
+		bool showInCenter, glm::vec4 shadowColor, glm::vec4 lightColor)
+	{
+		std::string newText;
+		wrap(text, f, baseSize, textPos.z, &newText);
+		renderText(textPos,
+			newText.c_str(), f, color, baseSize, spacing, lineSpacing, showInCenter,
+			shadowColor, lightColor);
+	}
+
+	glm::vec2 Renderer2D::getTextSizeWrapped(const std::string &text,
+		gl2d::Font f, float maxTextLenght, float baseSize, float spacing, float lineSpacing)
+	{
+		std::string newText;
+		wrap(text, f, baseSize, maxTextLenght, &newText);
+		auto rez = getTextSize(
+			newText.c_str(), f, baseSize, spacing, lineSpacing);
+
+		return rez;
+	}
+
 	void Renderer2D::clearScreen(const Color4f color)
 	{
 		glBindFramebuffer(GL_FRAMEBUFFER, defaultFBO);
@@ -1870,6 +2083,8 @@ namespace gl2d
 			else
 			{
 				position += delta * speed;
+
+
 			}
 
 			glm::vec2 delta2 = pos - position;

+ 2 - 0
Pika/thirdparty/imgui-docking/CMakeLists.txt

@@ -9,12 +9,14 @@ target_sources(imgui PRIVATE
 "${CMAKE_CURRENT_SOURCE_DIR}/imgui/imgui_tables.cpp"
 "${CMAKE_CURRENT_SOURCE_DIR}/imgui/imgui_widgets.cpp"
 "${CMAKE_CURRENT_SOURCE_DIR}/imgui/imguiComboSearch.cpp"
+"${CMAKE_CURRENT_SOURCE_DIR}/imgui/misc/cpp/imgui_stdlib.cpp"
 "${CMAKE_CURRENT_SOURCE_DIR}/imgui/TextEditor.cpp"
 "${CMAKE_CURRENT_SOURCE_DIR}/imgui/backends/imgui_impl_glfw.cpp"
 "${CMAKE_CURRENT_SOURCE_DIR}/imgui/backends/imgui_impl_opengl3.cpp"
 )
 
 target_include_directories(imgui PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/imgui")
+target_include_directories(imgui PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/imgui/misc/cpp")
 
 
 target_link_libraries(imgui PUBLIC glfw glad)

+ 12 - 4
Pika/thirdparty/sushi/include/sushi/sushi.h

@@ -31,12 +31,15 @@ namespace sushi
 
 		Layout layout;
 
+		Text text;
+
 		std::vector<SushiParent> parents;
 
 		std::vector<unsigned int> orderedElementsIds;
 
 		void update(gl2d::Renderer2D &renderer,
-			sushi::SushiInput &input, glm::vec4 parentTransform);
+			sushi::SushiInput &input, glm::vec4 parentTransform, 
+			gl2d::Font &font);
 
 		OutData outData;
 
@@ -59,12 +62,16 @@ namespace sushi
 
 		void addTransformInternal(sushi::Transform &transform);
 
+		void addColorInternal(glm::vec4 &color);
+
 		void addBackgroundInternal(sushi::Background &background);
 		
 		void addParentPieceInternal(sushi::SushiParent &el);
 
 		void addMainParentInternal(sushi::SushiParent &el);
 
+		void addTextInternal(std::string &el);
+
 		void addParentInternal(sushi::SushiParent &el);
 
 		void addMarkerInternal(int marker);
@@ -75,6 +82,8 @@ namespace sushi
 
 		void addUIntArrayPieceInternal(std::vector<unsigned int> &arr);
 
+		void addTextInternal(sushi::Text &text);
+
 		void save(SushiParent &parent, bool isMainParent);
 
 		void traverseAddInternal(SushiParent &parent);
@@ -91,9 +100,10 @@ namespace sushi
 			gl2d::Texture{})};
 		unsigned int currentIdCounter = 2;
 
+		//todo option to use another rect than camera
 		//draw regions are like this: x, y, w, h
 		void update(gl2d::Renderer2D &renderer, 
-			sushi::SushiInput &input);
+			sushi::SushiInput &input, gl2d::Font &font);
 
 		unsigned int addParent(
 			SushiParent &parent,
@@ -144,6 +154,4 @@ namespace sushi
 
 
 
-
-
 };

+ 23 - 2
Pika/thirdparty/sushi/include/sushi/sushiPrimitives.h

@@ -1,6 +1,7 @@
 #pragma once
 #include <glm/glm.hpp>
 #include <gl2d/gl2d.h>
+#include <sushi/sushiInput.h>
 
 namespace sushi
 {
@@ -11,10 +12,17 @@ namespace sushi
 	{
 		glm::vec4 absTransform = {};
 
-		void set(glm::vec4 absTransform)
+		sushi::SushiButton lmouse;
+		sushi::SushiButton rmouse;
+
+		bool mouseIn = 0; 
+
+		void set(glm::vec4 absTransform, bool mouseIn, sushi::SushiButton lmouse, sushi::SushiButton rmouse)
 		{
 			this->absTransform = absTransform;
-
+			this->mouseIn = mouseIn;
+			this->lmouse = lmouse;
+			this->rmouse = rmouse;
 		}
 	};
 
@@ -97,4 +105,17 @@ namespace sushi
 		void render(gl2d::Renderer2D &renderer, glm::vec4 pos);
 	};
 
+	struct Text
+	{
+		std::string text;
+		Transform transform;
+		glm::vec4 color = {1,1,1,1};
+
+		void render(gl2d::Renderer2D &renderer, glm::vec4 box, gl2d::Font &f);
+
+	};
+
+	void renderSushiElement(gl2d::Renderer2D &renderer, glm::vec4 box, sushi::Background &background, 
+		Text &text, gl2d::Font &font);
+
 };

+ 100 - 12
Pika/thirdparty/sushi/src/sushi.cpp

@@ -18,6 +18,9 @@ namespace sushi
 		markerBackground,
 		markerId,
 		markerName,
+		markerText,
+		markerTextElement,
+		markerColor,
 	};
 
 	void SushyBinaryFormat::addTransformInternal(sushi::Transform &transform)
@@ -26,6 +29,12 @@ namespace sushi
 		addBinaryDataInternal(&transform, sizeof(transform));
 	}
 
+	void SushyBinaryFormat::addColorInternal(glm::vec4 &color)
+	{
+		addMarkerInternal(markerColor);
+		addBinaryDataInternal(&color, sizeof(color));
+	}
+
 	void SushyBinaryFormat::addBackgroundInternal(sushi::Background &background)
 	{
 		addMarkerInternal(markerBackground);
@@ -52,10 +61,34 @@ namespace sushi
 		addMarkerInternal(markerId);
 		addBinaryDataInternal(&el.id, sizeof(el.id));
 
+		addTextInternal(el.text);		
+
 		addMarkerInternal(markerChildrenIdList);
 		addUIntArrayPieceInternal(el.orderedElementsIds);
 	}
 
+	void  SushyBinaryFormat::addTextInternal(std::string &el)
+	{
+		addMarkerInternal(markerText);
+		size_t s = el.size();
+		addBinaryDataInternal((void *)&s, sizeof(size_t));
+		addBinaryDataInternal(el.data(), s);
+	}
+
+	void  SushyBinaryFormat::addTextInternal(sushi::Text &el)
+	{
+		addMarkerInternal(markerTextElement);
+		
+		if (!el.text.empty()) 
+		{
+			addTextInternal(el.text);
+		}
+		
+		addTransformInternal(el.transform);
+	
+		addColorInternal(el.color);
+	}
+
 	void SushyBinaryFormat::addMainParentInternal(sushi::SushiParent &el)
 	{
 		addMarkerInternal(markerMainParent);
@@ -265,7 +298,7 @@ namespace sushi
 	}
 
 	void sushi::SushyContext::update(gl2d::Renderer2D &renderer,
-		sushi::SushiInput &input)
+		sushi::SushiInput &input, gl2d::Font &font)
 	{
 
 		if (renderer.windowH == 0 || renderer.windowW == 0)
@@ -277,28 +310,41 @@ namespace sushi
 
 		renderer.pushCamera();
 		{
-			root.update(renderer, input, drawRegion);
-
+			root.update(renderer, input, drawRegion, font);
 		}
 		renderer.popCamera();
 	}
 
 	void sushi::SushiParent::update(gl2d::Renderer2D &renderer,
-		sushi::SushiInput &input, glm::vec4 parentTransform)
+		sushi::SushiInput &input, glm::vec4 parentTransform, gl2d::Font &font)
 	{
 
 		glm::vec4 drawRegion = transform.applyTransform(parentTransform);
-		outData.set(drawRegion);
+		{
+			bool mouseIn = pointInBox({input.mouseX, input.mouseY}, drawRegion);
+
+			auto lMouse = input.lMouse;
+			auto rMouse = input.rMouse;
+
+			if (!mouseIn)
+			{
+				lMouse.flags = 0;
+				rMouse.flags = 0;
+			}
+
+			outData.set(drawRegion, mouseIn, lMouse, rMouse);
+		}
+
+		renderSushiElement(renderer, drawRegion, background, text, font);
 
-		//backgrouund
-		background.render(renderer, drawRegion);
+	#pragma region update children
 		auto parentsSize = parents.size();
 		auto orderedElementsSize = orderedElementsIds.size();
 
 		//todo signal error here
 		assert(parentsSize == orderedElementsSize);
 
-		std::vector<sushi::SushiParent*> toDraw;
+		std::vector<sushi::SushiParent *> toDraw;
 		toDraw.reserve(orderedElementsSize);
 
 		for (int i = 0; i < orderedElementsSize; i++)
@@ -324,7 +370,7 @@ namespace sushi
 		{
 			for (int i = 0; i < toDrawSize; i++)
 			{
-				toDraw[i]->update(renderer, input, drawRegion);
+				toDraw[i]->update(renderer, input, drawRegion, font);
 			}
 		}
 		break;
@@ -337,7 +383,7 @@ namespace sushi
 				newPos.w /= toDrawSize;
 				newPos.y += newPos.w * i;
 
-				toDraw[i]->update(renderer, input, newPos);
+				toDraw[i]->update(renderer, input, newPos, font);
 			}
 		}
 		break;
@@ -350,7 +396,7 @@ namespace sushi
 				newPos.z /= toDrawSize;
 				newPos.x += newPos.z * i;
 
-				toDraw[i]->update(renderer, input, newPos);
+				toDraw[i]->update(renderer, input, newPos, font);
 			}
 		}
 		break;
@@ -359,7 +405,7 @@ namespace sushi
 		assert(0);
 		break;
 		}
-
+	#pragma endregion
 
 	}
 
@@ -521,6 +567,41 @@ namespace sushi
 			return readBinaryData(buff, sizeof(Background));
 		};
 
+		auto getNextTextElementPiece = [&](sushi::Text *text) -> bool
+		{
+
+			int m = getNextMarker();
+
+			switch (m)
+			{
+				case markerText:
+				{
+					size_t textSize = 0;
+					if (!readBinaryData(&textSize, sizeof(textSize))) { return 0; }
+					text->text.resize(textSize);
+					if (!readBinaryData(text->text.data(), textSize)) { return 0; }
+					break;
+				}
+
+				case markerTransform:
+				{
+					if (!getNextTransformPiece(&text->transform)) { return 0; }
+					break;
+				}
+
+				case markerColor:
+				{
+					if (!readBinaryData(&text->color,sizeof(text->color))) { return 0; }
+					break;
+				}
+
+				default:
+				return 0;
+			}
+
+			return true;
+		};
+
 		auto getNextUnsignedIntVector = [&](std::vector<unsigned int> &vec) -> bool
 		{
 			vec.clear();
@@ -598,6 +679,13 @@ namespace sushi
 				}
 				break;
 
+				case markerTextElement:
+				{
+					int _ = getNextMarker();
+					if (!getNextTextElementPiece(&parent.text)) { return 0; }
+				}
+				break;
+
 				default:
 				return 0;
 				}

+ 26 - 0
Pika/thirdparty/sushi/src/sushiPrimitives.cpp

@@ -209,4 +209,30 @@ namespace sushi
 		renderer.renderRectangle(pos, color);
 	}
 
+	void Text::render(gl2d::Renderer2D &renderer, glm::vec4 box, gl2d::Font &f)
+	{
+		if (!text.empty())
+		{
+			glm::vec4 finalPos = transform.applyTransform(box);
+			auto s = renderer.determineTextRescaleFit(text, f, box);
+
+			finalPos.x += finalPos.z / 2.f;
+			finalPos.y += finalPos.w / 2.f;
+
+			renderer.renderText(finalPos, text.c_str(), f, color, s);
+
+			renderer.renderRectangle({finalPos.x-2, finalPos.y-2, 4, 4}, Colors_Red);
+		}
+	}
+
+
+	void renderSushiElement(gl2d::Renderer2D &renderer, glm::vec4 box, sushi::Background &background, Text &text,
+		gl2d::Font &font)
+	{
+		//backgrouund
+		background.render(renderer, box);
+
+		text.render(renderer, box, font);
+	}
+
 };