Restored UI Label support
This commit is contained in:
		
							
								
								
									
										6
									
								
								assets/dawnrpg/CMakeLists.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								assets/dawnrpg/CMakeLists.txt
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,6 @@
 | 
			
		||||
# Copyright (c) 2024 Dominic Masters
 | 
			
		||||
# 
 | 
			
		||||
# This software is released under the MIT License.
 | 
			
		||||
# https://opensource.org/licenses/MIT
 | 
			
		||||
 | 
			
		||||
tool_truetype(font_silver "${CMAKE_CURRENT_LIST_DIR}/Silver.ttf")
 | 
			
		||||
							
								
								
									
										
											BIN
										
									
								
								assets/dawnrpg/Silver.ttf
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								assets/dawnrpg/Silver.ttf
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							@@ -9,6 +9,7 @@ if(DAWN_TARGET STREQUAL "linux-x64-glfw")
 | 
			
		||||
  add_subdirectory(glad)
 | 
			
		||||
  add_subdirectory(glfw)
 | 
			
		||||
  add_subdirectory(libarchive)
 | 
			
		||||
  add_subdirectory(freetype)
 | 
			
		||||
else()
 | 
			
		||||
  message(FATAL_ERROR "Unknown target: ${DAWN_TARGET}")
 | 
			
		||||
endif()
 | 
			
		||||
 
 | 
			
		||||
@@ -14,7 +14,7 @@ if(DAWN_TARGET STREQUAL "linux-x64-glfw")
 | 
			
		||||
  add_subdirectory(dawnlinux)
 | 
			
		||||
  add_subdirectory(dawnglfw)
 | 
			
		||||
  add_subdirectory(dawnopengl)
 | 
			
		||||
  # add_subdirectory(dawnpoker)
 | 
			
		||||
  add_subdirectory(dawnrpg)
 | 
			
		||||
else()
 | 
			
		||||
  message(FATAL_ERROR "You need to define an entry target")
 | 
			
		||||
endif()
 | 
			
		||||
 
 | 
			
		||||
@@ -5,6 +5,7 @@
 | 
			
		||||
 | 
			
		||||
#include "AssetManager.hpp"
 | 
			
		||||
#include "loaders/TextureLoader.hpp"
 | 
			
		||||
#include "loaders/TrueTypeLoader.hpp"
 | 
			
		||||
 | 
			
		||||
using namespace Dawn;
 | 
			
		||||
 | 
			
		||||
@@ -59,6 +60,27 @@ bool_t AssetManager::isLoaded(const std::string filename) {
 | 
			
		||||
  return false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
template<>
 | 
			
		||||
std::shared_ptr<TrueTypeTexture> AssetManager::get<TrueTypeTexture>(
 | 
			
		||||
  const std::string filename,
 | 
			
		||||
  const uint32_t fontSize
 | 
			
		||||
) {
 | 
			
		||||
  auto existing = this->getExisting<TrueTypeLoader>(filename);
 | 
			
		||||
  if(existing) {
 | 
			
		||||
    // Check pointer hasn't gone stale, if it has remove it and create new.
 | 
			
		||||
    auto texture = existing->getTexture(fontSize);
 | 
			
		||||
    if(texture) return texture;
 | 
			
		||||
    this->removeExisting(filename);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  std::shared_ptr<TrueTypeLoader> loader = std::make_shared<TrueTypeLoader>(
 | 
			
		||||
    filename
 | 
			
		||||
  );
 | 
			
		||||
  pendingAssetLoaders.push_back(std::static_pointer_cast<AssetLoader>(loader));
 | 
			
		||||
  return loader->getTexture(fontSize);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
AssetManager::~AssetManager() {
 | 
			
		||||
  
 | 
			
		||||
}
 | 
			
		||||
@@ -7,4 +7,5 @@
 | 
			
		||||
target_sources(${DAWN_TARGET_NAME}
 | 
			
		||||
  PRIVATE
 | 
			
		||||
    TextureLoader.cpp
 | 
			
		||||
    TrueTypeLoader.cpp
 | 
			
		||||
)
 | 
			
		||||
							
								
								
									
										97
									
								
								src/dawn/asset/loaders/TrueTypeLoader.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										97
									
								
								src/dawn/asset/loaders/TrueTypeLoader.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,97 @@
 | 
			
		||||
// Copyright (c) 2023 Dominic Masters
 | 
			
		||||
// 
 | 
			
		||||
// This software is released under the MIT License.
 | 
			
		||||
// https://opensource.org/licenses/MIT
 | 
			
		||||
 | 
			
		||||
#include "TrueTypeLoader.hpp"
 | 
			
		||||
#include "assert/assert.hpp"
 | 
			
		||||
 | 
			
		||||
using namespace Dawn;
 | 
			
		||||
 | 
			
		||||
TrueTypeLoader::TrueTypeLoader(const std::string name) :
 | 
			
		||||
  AssetLoader(name),
 | 
			
		||||
  loader(name + ".ttf")
 | 
			
		||||
{
 | 
			
		||||
  // Init the font.
 | 
			
		||||
  auto ret = FT_Init_FreeType(&fontLibrary);
 | 
			
		||||
  assertTrue(ret == 0, "Failed to initialize FreeType library.");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void TrueTypeLoader::updateSync() {
 | 
			
		||||
  if(state != TrueTypeLoaderState::ASYNC_DONE) return;
 | 
			
		||||
  state = TrueTypeLoaderState::SYNC_LOADING;
 | 
			
		||||
 | 
			
		||||
  // Init all the textures.
 | 
			
		||||
  auto it = textures.begin();
 | 
			
		||||
  while(it != textures.end()) {
 | 
			
		||||
    auto texture = it->second.lock();
 | 
			
		||||
 | 
			
		||||
    if(texture) {
 | 
			
		||||
      texture->setFace(face);
 | 
			
		||||
      it++;
 | 
			
		||||
      continue;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    it = textures.erase(it);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  // Done
 | 
			
		||||
  state = TrueTypeLoaderState::SYNC_DONE;
 | 
			
		||||
  this->loaded = true;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void TrueTypeLoader::updateAsync() {
 | 
			
		||||
  if(state != TrueTypeLoaderState::INITIAL) return;
 | 
			
		||||
  state = TrueTypeLoaderState::ASYNC_LOADING;
 | 
			
		||||
 | 
			
		||||
  // Load the data.
 | 
			
		||||
  this->loader.open();
 | 
			
		||||
  size_t size = loader.getSize();
 | 
			
		||||
  buffer = new uint8_t[size];
 | 
			
		||||
 | 
			
		||||
  // Read the data.
 | 
			
		||||
  size_t readSize = loader.read(buffer, size);
 | 
			
		||||
  assertTrue(readSize == size, "Failed to read all data from TrueTypeLoader.");
 | 
			
		||||
 | 
			
		||||
  // Init the font.
 | 
			
		||||
  auto ret = FT_New_Memory_Face(fontLibrary, buffer, size, 0, &face);
 | 
			
		||||
  assertTrue(ret == 0, "Failed to load font face.");
 | 
			
		||||
 | 
			
		||||
  // Now close the asset loader
 | 
			
		||||
  loader.close();
 | 
			
		||||
  state = TrueTypeLoaderState::ASYNC_DONE;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
std::shared_ptr<TrueTypeTexture> TrueTypeLoader::getTexture(
 | 
			
		||||
  const uint32_t fontSize
 | 
			
		||||
) {
 | 
			
		||||
  // Check if we have the texture already and it hasn't gone stale.
 | 
			
		||||
  auto it = textures.find(fontSize);
 | 
			
		||||
  if(it != textures.end()) {
 | 
			
		||||
    if(!it->second.expired()) return it->second.lock();
 | 
			
		||||
    textures.erase(it);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  // Create the texture.
 | 
			
		||||
  auto texture = std::make_shared<TrueTypeTexture>(fontSize);
 | 
			
		||||
  textures[fontSize] = texture;
 | 
			
		||||
  if(this->loaded) texture->setFace(face);
 | 
			
		||||
  return texture;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
TrueTypeLoader::~TrueTypeLoader() {
 | 
			
		||||
  if(
 | 
			
		||||
    this->state == TrueTypeLoaderState::SYNC_DONE ||
 | 
			
		||||
    this->state == TrueTypeLoaderState::SYNC_LOADING ||
 | 
			
		||||
    this->state == TrueTypeLoaderState::ASYNC_DONE
 | 
			
		||||
  ) {
 | 
			
		||||
    FT_Done_Face(face);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  FT_Done_FreeType(fontLibrary);
 | 
			
		||||
 | 
			
		||||
  if(buffer != nullptr) {
 | 
			
		||||
    delete[] buffer;
 | 
			
		||||
    buffer = nullptr;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										57
									
								
								src/dawn/asset/loaders/TrueTypeLoader.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										57
									
								
								src/dawn/asset/loaders/TrueTypeLoader.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,57 @@
 | 
			
		||||
// Copyright (c) 2023 Dominic Masters
 | 
			
		||||
// 
 | 
			
		||||
// This software is released under the MIT License.
 | 
			
		||||
// https://opensource.org/licenses/MIT
 | 
			
		||||
 | 
			
		||||
#pragma once
 | 
			
		||||
#include "asset/AssetLoader.hpp"
 | 
			
		||||
#include "asset/AssetDataLoader.hpp"
 | 
			
		||||
#include "display/font/TrueTypeTexture.hpp"
 | 
			
		||||
 | 
			
		||||
namespace Dawn {
 | 
			
		||||
  enum class TrueTypeLoaderState {
 | 
			
		||||
    INITIAL,
 | 
			
		||||
    ASYNC_LOADING,
 | 
			
		||||
    ASYNC_DONE,
 | 
			
		||||
    SYNC_LOADING,
 | 
			
		||||
    SYNC_DONE
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  class TrueTypeLoader : public AssetLoader {
 | 
			
		||||
    protected:
 | 
			
		||||
      FT_Library fontLibrary;
 | 
			
		||||
      FT_Face face;
 | 
			
		||||
      AssetDataLoader loader;
 | 
			
		||||
      std::unordered_map<uint32_t, std::weak_ptr<TrueTypeTexture>> textures;
 | 
			
		||||
      enum TrueTypeLoaderState state = TrueTypeLoaderState::INITIAL;
 | 
			
		||||
      uint8_t *buffer = nullptr;
 | 
			
		||||
 | 
			
		||||
    public:
 | 
			
		||||
      /**
 | 
			
		||||
       * Constructs a TrueTypeLoader. You should instead use the parent
 | 
			
		||||
       * asset managers' abstracted load method
 | 
			
		||||
       * 
 | 
			
		||||
       * @param name File name asset to load, omitting the extension.
 | 
			
		||||
       */
 | 
			
		||||
      TrueTypeLoader(const std::string name);
 | 
			
		||||
 | 
			
		||||
      void updateSync() override;
 | 
			
		||||
      void updateAsync() override;
 | 
			
		||||
 | 
			
		||||
      /**
 | 
			
		||||
       * Returns the texture for the given font size.
 | 
			
		||||
       * 
 | 
			
		||||
       * @param fontSize Font size to get the texture for.
 | 
			
		||||
       * @return Texture for the given character.
 | 
			
		||||
       */
 | 
			
		||||
      std::shared_ptr<TrueTypeTexture> getTexture(
 | 
			
		||||
        const uint32_t fontSize
 | 
			
		||||
      );
 | 
			
		||||
 | 
			
		||||
      /**
 | 
			
		||||
       * Dispose / Cleanup the truetype asset. Will also dispose the underlying
 | 
			
		||||
       * truetype itself.
 | 
			
		||||
       */
 | 
			
		||||
      ~TrueTypeLoader();
 | 
			
		||||
  };
 | 
			
		||||
}
 | 
			
		||||
@@ -12,5 +12,6 @@ target_sources(${DAWN_TARGET_NAME}
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
# Subdirs
 | 
			
		||||
add_subdirectory(font)
 | 
			
		||||
add_subdirectory(mesh)
 | 
			
		||||
add_subdirectory(shader)
 | 
			
		||||
@@ -5,5 +5,6 @@
 | 
			
		||||
 | 
			
		||||
target_sources(${DAWN_TARGET_NAME}
 | 
			
		||||
  PRIVATE
 | 
			
		||||
    UILabel.cpp
 | 
			
		||||
    UIRectangle.cpp
 | 
			
		||||
)
 | 
			
		||||
							
								
								
									
										175
									
								
								src/dawn/ui/elements/UILabel.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										175
									
								
								src/dawn/ui/elements/UILabel.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,175 @@
 | 
			
		||||
// Copyright (c) 2023 Dominic Masters
 | 
			
		||||
// 
 | 
			
		||||
// This software is released under the MIT License.
 | 
			
		||||
// https://opensource.org/licenses/MIT
 | 
			
		||||
 | 
			
		||||
#include "UILabel.hpp"
 | 
			
		||||
 | 
			
		||||
using namespace Dawn;
 | 
			
		||||
 | 
			
		||||
void UILabel::getSelfQuads(UICanvas &ctx) {
 | 
			
		||||
  std::vector<struct UIShaderQuad> quads;
 | 
			
		||||
  if(this->texture == nullptr || this->text.empty()) return;
 | 
			
		||||
 | 
			
		||||
  glm::vec4 quad;
 | 
			
		||||
  glm::vec2 pos = glm::vec2(0, this->texture->fontSize);
 | 
			
		||||
  bool_t lastCharWasSpace = false;
 | 
			
		||||
 | 
			
		||||
  for(size_t i = 0; i < text.size(); i++) {
 | 
			
		||||
    wchar_t c = text[i];
 | 
			
		||||
    auto info = texture->getCharacterData(c);
 | 
			
		||||
 | 
			
		||||
    // Newline(s)
 | 
			
		||||
    if(c == L'\n') {
 | 
			
		||||
      pos.x = 0;
 | 
			
		||||
      pos.y += this->texture->fontSize;
 | 
			
		||||
      continue;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // Spaces
 | 
			
		||||
    if(c == L' ') {
 | 
			
		||||
      pos.x += info.advance.x;
 | 
			
		||||
      lastCharWasSpace = true;
 | 
			
		||||
      continue;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // Word Wrap
 | 
			
		||||
    if(wordWrap) {
 | 
			
		||||
      if(lastCharWasSpace) {
 | 
			
		||||
        // Scan ahead to next space
 | 
			
		||||
        float_t wordWidth = pos.x;// Start at current position and scan ahead.
 | 
			
		||||
        for(size_t j = i; j < text.size(); j++) {
 | 
			
		||||
          wchar_t c2 = text[j];
 | 
			
		||||
          if(c2 == L' ' || c2 == L'\n') {
 | 
			
		||||
            break;// If we hit another space, we are OK.
 | 
			
		||||
          }
 | 
			
		||||
 | 
			
		||||
          // Will this character fit on the row? If not the whole word will wrap.
 | 
			
		||||
          auto info2 = texture->getCharacterData(c);
 | 
			
		||||
          wordWidth += info.advance.x;
 | 
			
		||||
          if(wordWidth > size.x) {
 | 
			
		||||
            pos.x = 0;
 | 
			
		||||
            pos.y += this->texture->fontSize;
 | 
			
		||||
            break;
 | 
			
		||||
          }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        lastCharWasSpace = false;
 | 
			
		||||
      }
 | 
			
		||||
    // } else if(pos.x + info.size.x > subAlignedPosition.x + size.x) {
 | 
			
		||||
    //   // Not word wrap, but instead just overflow characters.
 | 
			
		||||
    //   pos.x = 0;
 | 
			
		||||
    //   pos.y += this->texture->fontSize;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    ctx.addQuad(
 | 
			
		||||
      {
 | 
			
		||||
        subAlignedPosition.x + pos.x + info.offset.x,
 | 
			
		||||
        subAlignedPosition.y + pos.y + info.offset.y,
 | 
			
		||||
        subAlignedPosition.x + pos.x + info.size.x + info.offset.x,
 | 
			
		||||
        subAlignedPosition.y + pos.y + info.size.y + info.offset.y
 | 
			
		||||
      },
 | 
			
		||||
      {
 | 
			
		||||
        info.quad.x,
 | 
			
		||||
        info.quad.y,
 | 
			
		||||
        info.quad.z,
 | 
			
		||||
        info.quad.w
 | 
			
		||||
      },
 | 
			
		||||
      this->color,
 | 
			
		||||
      UIShaderQuadStyle::FONT,
 | 
			
		||||
      texture->texture
 | 
			
		||||
    );
 | 
			
		||||
    pos += info.advance;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
float_t UILabel::getContentWidth() {
 | 
			
		||||
  if(this->texture == nullptr || this->text.empty()) return 0.0f;
 | 
			
		||||
 | 
			
		||||
  float_t lineWidth = 0.0f;
 | 
			
		||||
  float_t width = 0.0f;
 | 
			
		||||
  for(wchar_t c : text) {
 | 
			
		||||
    if(c == L'\n') {
 | 
			
		||||
      width = Math::max<float_t>(width, lineWidth);
 | 
			
		||||
      lineWidth = 0.0f;
 | 
			
		||||
      continue;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    auto info = texture->getCharacterData(c);
 | 
			
		||||
    lineWidth += info.advance.x;
 | 
			
		||||
    if(
 | 
			
		||||
      this->hasExplicitWidth() &&
 | 
			
		||||
      lineWidth >= size.x
 | 
			
		||||
    ) return size.x;
 | 
			
		||||
  }
 | 
			
		||||
  width = Math::max<float_t>(width, lineWidth);
 | 
			
		||||
  return width;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
float_t UILabel::getContentHeight() {
 | 
			
		||||
  if(this->texture == nullptr || this->text.empty()) return 0.0f;
 | 
			
		||||
 | 
			
		||||
  float_t height = this->texture->fontSize;
 | 
			
		||||
  float_t lineWidth = 0.0f;
 | 
			
		||||
  bool_t lastCharWasSpace = false;
 | 
			
		||||
 | 
			
		||||
  for(wchar_t c : text) {
 | 
			
		||||
    if(c == L'\n') {
 | 
			
		||||
      height += this->texture->fontSize;
 | 
			
		||||
      continue;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    auto info = texture->getCharacterData(c);
 | 
			
		||||
 | 
			
		||||
    if(c == L' ') {
 | 
			
		||||
      lineWidth += info.advance.x;
 | 
			
		||||
      lastCharWasSpace = true;
 | 
			
		||||
      continue;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if(wordWrap) {
 | 
			
		||||
      if(lastCharWasSpace) {
 | 
			
		||||
        // Scan ahead to next space
 | 
			
		||||
        float_t wordWidth = lineWidth;// Start at current position and scan ahead.
 | 
			
		||||
        for(size_t j = 0; j < text.size(); j++) {
 | 
			
		||||
          wchar_t c2 = text[j];
 | 
			
		||||
          if(c2 == L' ' || c2 == L'\n') {
 | 
			
		||||
            break;// If we hit another space, we are OK.
 | 
			
		||||
          }
 | 
			
		||||
 | 
			
		||||
          // Will this character fit on the row? If not the whole word will wrap.
 | 
			
		||||
          auto info2 = texture->getCharacterData(c);
 | 
			
		||||
          wordWidth += info.advance.x;
 | 
			
		||||
          if(wordWidth > size.x) {
 | 
			
		||||
            height += this->texture->fontSize;
 | 
			
		||||
            lineWidth = 0.0f;
 | 
			
		||||
            break;
 | 
			
		||||
          }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        lastCharWasSpace = false;
 | 
			
		||||
      }
 | 
			
		||||
    // } else if(lineWidth + info.size.x > size.x) {
 | 
			
		||||
    //   height += this->texture->fontSize;
 | 
			
		||||
    //   lineWidth = 0.0f;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  return height;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
std::shared_ptr<TrueTypeTexture> UILabel::getFont() {
 | 
			
		||||
  return this->texture;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
std::wstring UILabel::getText() {
 | 
			
		||||
  return this->text;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void UILabel::setFont(std::shared_ptr<TrueTypeTexture> texture) {
 | 
			
		||||
  this->texture = texture;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void UILabel::setText(const std::wstring &text) {
 | 
			
		||||
  this->text = text;
 | 
			
		||||
}
 | 
			
		||||
@@ -1,17 +1,54 @@
 | 
			
		||||
// Copyright (c) 2024 Dominic Masters
 | 
			
		||||
// Copyright (c) 2023 Dominic Masters
 | 
			
		||||
// 
 | 
			
		||||
// This software is released under the MIT License.
 | 
			
		||||
// https://opensource.org/licenses/MIT
 | 
			
		||||
 | 
			
		||||
#pragma once
 | 
			
		||||
#include "ui/UIAlignableElement.hpp"
 | 
			
		||||
#include "ui/UISubAlignableElement.hpp"
 | 
			
		||||
#include "display/font/TrueTypeTexture.hpp"
 | 
			
		||||
 | 
			
		||||
namespace Dawn {
 | 
			
		||||
  class UILabel final : public UIAlignableElement {
 | 
			
		||||
  class UILabel final : public UISubAlignableElement {
 | 
			
		||||
    private:
 | 
			
		||||
      std::shared_ptr<TrueTypeTexture> texture = nullptr;
 | 
			
		||||
      std::wstring text = L"Hello World";
 | 
			
		||||
 | 
			
		||||
    protected:
 | 
			
		||||
      void getSelfQuads(UICanvas &ctx) override;
 | 
			
		||||
 | 
			
		||||
    public:
 | 
			
		||||
      std::shared_ptr<TrueTypeTexture> font;
 | 
			
		||||
      bool_t wordWrap = true;
 | 
			
		||||
      struct Color color = COLOR_WHITE;
 | 
			
		||||
 | 
			
		||||
      float_t getContentWidth() override;
 | 
			
		||||
      float_t getContentHeight() override;
 | 
			
		||||
 | 
			
		||||
      /**
 | 
			
		||||
       * Returns the font used for this label.
 | 
			
		||||
       * 
 | 
			
		||||
       * @return The font used for this label.
 | 
			
		||||
       */
 | 
			
		||||
      std::shared_ptr<TrueTypeTexture> getFont();
 | 
			
		||||
 | 
			
		||||
      /**
 | 
			
		||||
       * Returns the text used for this label.
 | 
			
		||||
       * 
 | 
			
		||||
       * @return The text used for this label.
 | 
			
		||||
       */
 | 
			
		||||
      std::wstring getText();
 | 
			
		||||
 | 
			
		||||
      /**
 | 
			
		||||
       * Sets the font to use for this label.
 | 
			
		||||
       * 
 | 
			
		||||
       * @param texture TrueType texture to use for this label.
 | 
			
		||||
       */
 | 
			
		||||
      void setFont(std::shared_ptr<TrueTypeTexture> texture);
 | 
			
		||||
 | 
			
		||||
      /**
 | 
			
		||||
       * Sets the text to use for this label.
 | 
			
		||||
       * 
 | 
			
		||||
       * @param text The text to use for this label.
 | 
			
		||||
       */
 | 
			
		||||
      void setText(const std::wstring &text);
 | 
			
		||||
  };
 | 
			
		||||
}
 | 
			
		||||
@@ -12,12 +12,11 @@ target_include_directories(${DAWN_TARGET_NAME}
 | 
			
		||||
# Sources
 | 
			
		||||
target_sources(${DAWN_TARGET_NAME}
 | 
			
		||||
  PRIVATE
 | 
			
		||||
    dawnpoker.cpp
 | 
			
		||||
    dawnrpg.cpp
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
# Subdirs
 | 
			
		||||
add_subdirectory(poker)
 | 
			
		||||
add_subdirectory(scenes)
 | 
			
		||||
 | 
			
		||||
# Assets
 | 
			
		||||
# include("${DAWN_ASSETS_SOURCE_DIR}/games/dawnpoker/CMakeLists.txt")
 | 
			
		||||
include("${DAWN_ASSETS_SOURCE_DIR}/dawnrpg/CMakeLists.txt")
 | 
			
		||||
@@ -12,7 +12,7 @@
 | 
			
		||||
 | 
			
		||||
#include "component/ui/UICanvas.hpp"
 | 
			
		||||
#include "ui/elements/UIRectangle.hpp"
 | 
			
		||||
// #include "ui/elements/UILabel.hpp"
 | 
			
		||||
#include "ui/elements/UILabel.hpp"
 | 
			
		||||
#include "ui/UIMenu.hpp"
 | 
			
		||||
#include "ui/container/UIRowContainer.hpp"
 | 
			
		||||
#include "ui/container/UIPaddingContainer.hpp"
 | 
			
		||||
@@ -52,6 +52,19 @@ void Dawn::testScene(Scene &s) {
 | 
			
		||||
  rect->color = COLOR_MAGENTA;
 | 
			
		||||
  container->appendChild(rect);
 | 
			
		||||
 | 
			
		||||
  auto texture = s.getGame()->assetManager.get<TrueTypeTexture>("font_silver", 128);
 | 
			
		||||
  while(!s.getGame()->assetManager.isEverythingLoaded()) {
 | 
			
		||||
    s.getGame()->assetManager.update();
 | 
			
		||||
  }
 | 
			
		||||
  
 | 
			
		||||
  auto label = std::make_shared<UILabel>();
 | 
			
		||||
  label->align = { 0, 0, UI_ALIGN_SIZE_AUTO, UI_ALIGN_SIZE_AUTO };
 | 
			
		||||
  label->alignX = UIAlignmentType::START;
 | 
			
		||||
  label->alignY = UIAlignmentType::START;
 | 
			
		||||
  label->setFont(texture);
 | 
			
		||||
  label->setText(L"Hello World!");
 | 
			
		||||
  container->appendChild(label);
 | 
			
		||||
  
 | 
			
		||||
  // auto game = std::make_shared<PokerGame>();
 | 
			
		||||
  // auto player0 = game->addNewPlayer();
 | 
			
		||||
  // auto player1 = game->addNewPlayer();
 | 
			
		||||
		Reference in New Issue
	
	Block a user