From 4b31864b2f79b0769bbd43afd001d8975c27ab47 Mon Sep 17 00:00:00 2001 From: John McCardle Date: Thu, 7 Mar 2024 12:35:07 -0500 Subject: [PATCH] Adding text functionality to Caption (why was that missing???) --- src/Resources.cpp | 7 ++++--- src/Resources.h | 5 +++-- src/UI.h | 12 ++++++++++-- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/Resources.cpp b/src/Resources.cpp index e8eb64c..46b10db 100644 --- a/src/Resources.cpp +++ b/src/Resources.cpp @@ -1,7 +1,8 @@ #include "Resources.h" -#include -#include "UI.h" +//#include +//#include "UI.h" // Resources class members memory allocation sf::Font Resources::font; -GameEngine* Resources::game; \ No newline at end of file +GameEngine* Resources::game; +std::string Resources::caption_buffer; diff --git a/src/Resources.h b/src/Resources.h index f636dd7..215dbbb 100644 --- a/src/Resources.h +++ b/src/Resources.h @@ -1,7 +1,7 @@ #pragma once #include "Common.h" -#include -#include "UI.h" +//#include +//#include "UI.h" class GameEngine; // forward declared @@ -10,4 +10,5 @@ class Resources public: static sf::Font font; static GameEngine* game; + static std::string caption_buffer; }; diff --git a/src/UI.h b/src/UI.h index b5ed0a1..83f63c1 100644 --- a/src/UI.h +++ b/src/UI.h @@ -3,6 +3,7 @@ #include "Python.h" #include "structmember.h" #include "IndexTexture.h" +#include "Resources.h" #include enum PyObjectsEnum : int @@ -657,12 +658,19 @@ static int PyUIDrawable_set_click(PyUIGridObject* self, PyObject* value, void* c static PyObject* PyUICaption_get_text(PyUICaptionObject* self, void* closure) { - return PyUnicode_FromString("Test String, Please Ignore"); + Resources::caption_buffer = self->data->text.getString(); + return PyUnicode_FromString(Resources::caption_buffer.c_str()); } static int PyUICaption_set_text(PyUICaptionObject* self, PyObject* value, void* closure) { - // asdf + PyObject* s = PyObject_Str(value); + PyObject * temp_bytes = PyUnicode_AsEncodedString(s, "UTF-8", "strict"); // Owned reference + if (temp_bytes != NULL) { + Resources::caption_buffer = PyBytes_AS_STRING(temp_bytes); // Borrowed pointer + Py_DECREF(temp_bytes); + } + self->data->text.setString(Resources::caption_buffer); return 0; }