Cleanup of some code
This commit is contained in:
@ -8,4 +8,5 @@ target_sources(${DAWN_TARGET_NAME}
|
||||
PRIVATE
|
||||
UILabel.cpp
|
||||
UIRichTextLabel.cpp
|
||||
UISimpleLabel.cpp
|
||||
)
|
49
src/dawn/scene/components/ui/text/UISimpleLabel.cpp
Normal file
49
src/dawn/scene/components/ui/text/UISimpleLabel.cpp
Normal file
@ -0,0 +1,49 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "UISimpleLabel.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
UISimpleLabel::UISimpleLabel(SceneItem *i) :
|
||||
UILabel(i),
|
||||
text("Hello World"),
|
||||
font(nullptr),
|
||||
size(12),
|
||||
style(0),
|
||||
decorations(0),
|
||||
color(COLOR_WHITE)
|
||||
{
|
||||
}
|
||||
|
||||
void UISimpleLabel::onStart() {
|
||||
UILabel::onStart();
|
||||
|
||||
useEffect([&] {
|
||||
if(this->font == nullptr) {
|
||||
this->rebufferQuads({ });
|
||||
return;
|
||||
}
|
||||
|
||||
struct UILabelText text;
|
||||
struct UILabelStyle style;
|
||||
style.font = this->font;
|
||||
style.size = this->size;
|
||||
style.style = this->style;
|
||||
style.decorations = this->decorations;
|
||||
style.color = this->color;
|
||||
|
||||
text.style = style;
|
||||
text.text = this->text;
|
||||
this->rebufferQuads({ text });
|
||||
}, {
|
||||
&this->text,
|
||||
&this->font,
|
||||
&this->size,
|
||||
&this->style,
|
||||
&this->decorations,
|
||||
&this->color
|
||||
})();
|
||||
}
|
29
src/dawn/scene/components/ui/text/UISimpleLabel.hpp
Normal file
29
src/dawn/scene/components/ui/text/UISimpleLabel.hpp
Normal file
@ -0,0 +1,29 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "UILabel.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class UISimpleLabel : public UILabel {
|
||||
public:
|
||||
// @optional
|
||||
StateProperty<std::string> text;
|
||||
// @optional
|
||||
StateProperty<TrueTypeAsset*> font;
|
||||
// @optional
|
||||
StateProperty<uint32_t> size;
|
||||
// @optional
|
||||
StateProperty<flag_t> style;
|
||||
// @optional
|
||||
StateProperty<flag_t> decorations;
|
||||
// @optional
|
||||
StateProperty<struct Color> color;
|
||||
|
||||
UISimpleLabel(SceneItem *item);
|
||||
|
||||
void onStart() override;
|
||||
};
|
||||
}
|
@ -142,7 +142,7 @@ namespace Dawn {
|
||||
parser = vec3Parser;
|
||||
} else if(type.find("vec4") != std::string::npos) {
|
||||
parser = vec4Parser;
|
||||
} else if(type == "int32_t" || type == "int") {
|
||||
} else if(type == "int32_t" || type == "int" || type == "uint32_t" || type == "uint") {
|
||||
parser = intParser;
|
||||
} else if(type == "bool_t") {
|
||||
parser = boolParser;
|
||||
|
@ -23,6 +23,7 @@ include(util/generator/CMakeLists.txt)
|
||||
|
||||
# Tools
|
||||
add_subdirectory(prefabtool)
|
||||
add_subdirectory(propertytool)
|
||||
add_subdirectory(scenetool)
|
||||
add_subdirectory(texturetool)
|
||||
add_subdirectory(truetypetool)
|
||||
|
@ -226,6 +226,39 @@ void File::setPosition(size_t n) {
|
||||
fseek(this->file, n, SEEK_CUR);
|
||||
}
|
||||
|
||||
std::string File::getFileName(bool_t withExt) {
|
||||
// Remove all but last slash
|
||||
std::string basename;
|
||||
size_t lastSlash = this->filename.find_last_of('/');
|
||||
if(lastSlash == std::string::npos) {
|
||||
basename = this->filename;
|
||||
} else {
|
||||
basename = this->filename.substr(lastSlash + 1);
|
||||
}
|
||||
|
||||
// Do we need to remove ext?
|
||||
if(withExt) return basename;
|
||||
size_t lastDot = basename.find_last_of('.');
|
||||
if(lastDot == std::string::npos) return basename;
|
||||
return basename.substr(0, lastDot);
|
||||
}
|
||||
|
||||
std::string File::getExtension() {
|
||||
// Remove all but last slash
|
||||
std::string basename;
|
||||
size_t lastSlash = this->filename.find_last_of('/');
|
||||
if(lastSlash == std::string::npos) {
|
||||
basename = this->filename;
|
||||
} else {
|
||||
basename = this->filename.substr(lastSlash + 1);
|
||||
}
|
||||
|
||||
size_t lastDot = basename.find_last_of('.');
|
||||
if(lastDot == std::string::npos) return "";
|
||||
return basename.substr(lastDot + 1);
|
||||
}
|
||||
|
||||
|
||||
File::~File() {
|
||||
if(this->file != nullptr) this->close();
|
||||
}
|
@ -160,6 +160,21 @@ namespace Dawn {
|
||||
*/
|
||||
void setPosition(size_t pos);
|
||||
|
||||
/**
|
||||
* Get the file name of this file, optionally with the extension.
|
||||
*
|
||||
* @param withExtension If true, the extension will be included.
|
||||
* @return The file name.
|
||||
*/
|
||||
std::string getFileName(bool_t withExtension = true);
|
||||
|
||||
/**
|
||||
* Returns the extension of this file.
|
||||
*
|
||||
* @return The extension of this file.
|
||||
*/
|
||||
std::string getExtension();
|
||||
|
||||
/**
|
||||
* Destruct the File manager.
|
||||
*/
|
||||
|
@ -34,8 +34,8 @@ void SceneAssetGenerator::generate(
|
||||
|
||||
case SCENE_ASSET_TYPE_TRUETYPE_FONT:
|
||||
assetType = "TrueTypeAsset";
|
||||
assetMap[asset->fileName] = "&" + asset->usageName + "->font";
|
||||
assetMap[asset->usageName] = "&" + asset->usageName + "->font";
|
||||
assetMap[asset->fileName] = asset->usageName;
|
||||
assetMap[asset->usageName] = asset->usageName;
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -14,6 +14,7 @@ set(
|
||||
${D}/SceneCodeParser.cpp
|
||||
${D}/SceneItemComponentParser.cpp
|
||||
${D}/SceneItemComponentRegistry.cpp
|
||||
${D}/ScenePropertyParser.cpp
|
||||
|
||||
CACHE INTERNAL
|
||||
${DAWN_CACHE_TARGET}
|
||||
|
Reference in New Issue
Block a user