Part one - removed references and smart pointers

This commit is contained in:
2022-11-11 19:08:46 -08:00
parent e892224900
commit e6d475d170
76 changed files with 3899 additions and 3707 deletions

View File

@ -1,34 +1,72 @@
/**
* Copyright (c) 2022 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "display/mesh/Mesh.hpp"
#include "util/mathutils.hpp"
#include "display/Texture.hpp"
#include "display/mesh/QuadMesh.hpp"
#include "FontMeasure.hpp"
#define FONT_NEWLINE '\n'
#define FONT_SPACE ' '
namespace Dawn {
class Font {
public:
virtual void buffer(
std::string text,
float_t fontSize,
float_t maxWidth,
Mesh &mesh,
struct FontMeasure *info
) = 0;
virtual Texture & getTexture() = 0;
virtual void draw(Mesh &mesh, int32_t startCharacter, int32_t length) = 0;
virtual float_t getLineHeight(float_t fontSize) = 0;
virtual float_t getDefaultFontSize() = 0;
};
/**
* Copyright (c) 2022 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "display/mesh/Mesh.hpp"
#include "util/mathutils.hpp"
#include "display/Texture.hpp"
#include "display/mesh/QuadMesh.hpp"
#include "FontMeasure.hpp"
#define FONT_NEWLINE '\n'
#define FONT_SPACE ' '
namespace Dawn {
class Font {
public:
/**
* Buffer the characters of a string onto a primitive and get the result of the
* buffer back as a resulting generic measurement information structure. Note
* that measure is REQUIRED, and must be DISPOSED after it has been calculated.
*
* @param text String to buffer.
* @param fontSize Font size to use for the buffer operation.
* @param maxWidth Maximum width (in pixels) to use to textwrap. -1 for no wrap.
* @param mesh Mesh to buffer the string on to.
* @param info Pointer to where you want to store resulting measurements.
*/
virtual void buffer(
std::string text,
float_t fontSize,
float_t maxWidth,
Mesh *mesh,
struct FontMeasure *info
) = 0;
/**
* Returns the texture that is used for a given font.
*
* @return Pointer to the texture used by this font.
*/
virtual Texture * getTexture() = 0;
/**
* Draw a previously buffered font primitive.
*
* @param mesh Mesh to draw.
* @param start Start character to draw.
* @param length Count of characters to draw, set to -1 to draw all.
*/
virtual void draw(Mesh *mesh, int32_t startCharacter, int32_t length) = 0;
/**
* Returns the line height of a given font and font size combination.
*
* @param fontSize Font size to get the line height for.
* @return The line height of this font at this font size.
*/
virtual float_t getLineHeight(float_t fontSize) = 0;
/**
* Retreive the default font size of a given font. Useful if you want to use
* the original font's font size for pixel-perfect rendering.
*
* @return The font size fo that font item.
*/
virtual float_t getDefaultFontSize() = 0;
};
}

View File

@ -1,43 +1,50 @@
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "FontMeasure.hpp"
using namespace Dawn;
float_t FontMeasure::getWidth() {
return this->width;
}
float_t FontMeasure::getHeight() {
return this->height;
}
int32_t FontMeasure::getQuadCount() {
return this->realLength;
}
float_t FontMeasure::getHeightOfLineCount(int32_t lineCount) {
return this->lineHeight * lineCount;
}
size_t FontMeasure::getLineCount() {
return this->lines.size();
}
int32_t FontMeasure::getQuadsOnLine(int32_t line) {
return this->lines[line].length;
}
int32_t FontMeasure::getQuadIndexOnLine(int32_t line) {
return this->lines[line].start;
}
void FontMeasure::addLine(int32_t start, int32_t len) {
struct FontLineMeasure info;
info.start = start;
info.length = len;
this->lines.push_back(info);
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "FontMeasure.hpp"
using namespace Dawn;
float_t FontMeasure::getWidth() {
return this->width;
}
float_t FontMeasure::getHeight() {
return this->height;
}
int32_t FontMeasure::getQuadCount() {
return this->realLength;
}
float_t FontMeasure::getHeightOfLineCount(int32_t lineCount) {
assertTrue(lineCount > 0);
return this->lineHeight * lineCount;
}
size_t FontMeasure::getLineCount() {
return this->lines.size();
}
int32_t FontMeasure::getQuadsOnLine(int32_t line) {
assertTrue(line >= 0);
assertTrue(line < this->lines.size());
return this->lines[line].length;
}
int32_t FontMeasure::getQuadIndexOnLine(int32_t line) {
assertTrue(line >= 0);
assertTrue(line < this->lines.size());
return this->lines[line].start;
}
void FontMeasure::addLine(int32_t start, int32_t len) {
assertTrue(start >= 0);
assertTrue(len >= 0);
struct FontLineMeasure info;
info.start = start;
info.length = len;
this->lines.push_back(info);
}

View File

@ -1,50 +1,51 @@
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "dawnlibs.hpp"
namespace Dawn {
struct FontLineMeasure {
/** What (real character) index the line starts at */
int32_t start;
/** How many (real) characters the line is in length */
int32_t length;
};
struct FontMeasure {
public:
/** How many raw chars are in the string */
int32_t length;
/** How many real characters (non whitespace) are in the string */
int32_t realLength;
/** The real character info for each line */
std::vector<struct FontLineMeasure> lines;
/** Dimensions of the string */
float_t width, height;
/** Height of a single line */
float_t lineHeight;
/**
* Internal method that adds a line to the text buffer process.
*
* @param start Start character index for the next line.
* @param len Length of the next line.
*/
void addLine(int32_t start, int32_t length);
float_t getWidth();
float_t getHeight();
int32_t getQuadsOnLine(int32_t line);
int32_t getQuadIndexOnLine(int32_t line);
float_t getHeightOfLineCount(int32_t lineCount);
size_t getLineCount();
int32_t getQuadCount();
};
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "dawnlibs.hpp"
#include "assert/assert.hpp"
namespace Dawn {
struct FontLineMeasure {
/** What (real character) index the line starts at */
int32_t start;
/** How many (real) characters the line is in length */
int32_t length;
};
struct FontMeasure {
public:
/** How many raw chars are in the string */
int32_t length;
/** How many real characters (non whitespace) are in the string */
int32_t realLength;
/** The real character info for each line */
std::vector<struct FontLineMeasure> lines;
/** Dimensions of the string */
float_t width, height;
/** Height of a single line */
float_t lineHeight;
/**
* Internal method that adds a line to the text buffer process.
*
* @param start Start character index for the next line.
* @param len Length of the next line.
*/
void addLine(int32_t start, int32_t length);
float_t getWidth();
float_t getHeight();
int32_t getQuadsOnLine(int32_t line);
int32_t getQuadIndexOnLine(int32_t line);
float_t getHeightOfLineCount(int32_t lineCount);
size_t getLineCount();
int32_t getQuadCount();
};
}

View File

@ -13,6 +13,12 @@
using namespace Dawn;
void TrueTypeFont::bakeQuad(truetypequad_t *quad,float_t *x,float_t *y,char c){
assertNotNull(quad);
assertNotNull(x);
assertNotNull(y);
assertTrue(c >= TRUETYPE_FIRST_CHAR);
assertTrue(c < (TRUETYPE_FIRST_CHAR+TRUETYPE_NUM_CHARS));
stbtt_GetBakedQuad(
this->characterData,
this->texture.getWidth(), this->texture.getHeight(),
@ -40,11 +46,15 @@ void TrueTypeFont::buffer(
std::string text,
float_t fontSize,
float_t maxWidth,
Mesh &mesh,
Mesh *mesh,
struct FontMeasure *info
) {
auto stringLength = text.length();
assertNotNull(mesh);
assertNotNull(info);
assertTrue(fontSize > 0);
assertTrue(maxWidth == -1 || maxWidth > 0);
auto stringLength = text.length();
if(stringLength == 0) {
info->length = 0;
info->realLength = 0;
@ -53,15 +63,18 @@ void TrueTypeFont::buffer(
info->width = 0;
info->height = 0.0f;
info->lineHeight = 0.0f;
mesh.createBuffers(0, 0);
mesh->createBuffers(0, 0);
return;
}
auto quads = new truetypequad_t[stringLength];
assertNotNull(quads);
// Get the font scale
auto scale = this->getScale(fontSize);
assertTrue(scale > 0);
// Adjust the max width to match the scale, and allow "no max width".
maxWidth = maxWidth == -1 ? 9999999 : maxWidth * (1 / scale);
@ -143,7 +156,7 @@ void TrueTypeFont::buffer(
}
// Initialize primitive
mesh.createBuffers(
mesh->createBuffers(
QUAD_VERTICE_COUNT * info->realLength,
QUAD_INDICE_COUNT * info->realLength
);
@ -163,7 +176,7 @@ void TrueTypeFont::buffer(
info->height = mathMax<float_t>(info->height, quad->y1);
// Buffer the quad.
QuadMesh::bufferQuadMesh(&mesh,
QuadMesh::bufferQuadMesh(mesh,
glm::vec2(quad->x0, quad->y0), glm::vec2(quad->s0, quad->t0),
glm::vec2(quad->x1, quad->y1), glm::vec2(quad->s1, quad->t1),
j * QUAD_VERTICE_COUNT, j * QUAD_INDICE_COUNT
@ -173,12 +186,14 @@ void TrueTypeFont::buffer(
delete quads;
}
Texture & TrueTypeFont::getTexture() {
return this->texture;
Texture * TrueTypeFont::getTexture() {
return &this->texture;
}
void TrueTypeFont::draw(Mesh &mesh, int32_t startchar, int32_t length) {
mesh.draw(
void TrueTypeFont::draw(Mesh *mesh, int32_t startchar, int32_t length) {
assertNotNull(mesh);
mesh->draw(
MESH_DRAW_MODE_TRIANGLES,
startchar * QUAD_INDICE_COUNT,
length == -1 ? length : length * QUAD_INDICE_COUNT
@ -186,10 +201,10 @@ void TrueTypeFont::draw(Mesh &mesh, int32_t startchar, int32_t length) {
}
float_t TrueTypeFont::getLineHeight(float_t fontSize) {
assertTrue(fontSize > 0);
return 13.0f;
}
float_t TrueTypeFont::getDefaultFontSize() {
return (float_t)this->fontSize;
}
}

View File

@ -71,12 +71,11 @@ namespace Dawn {
std::string text,
float_t fontSize,
float_t maxWidth,
Mesh &mesh,
Mesh *mesh,
struct FontMeasure *info
) override;
Texture & getTexture() override;
void draw(Mesh &mesh, int32_t startCharacter, int32_t length) override;
Texture * getTexture() override;
void draw(Mesh *mesh, int32_t startCharacter, int32_t length) override;
float_t getLineHeight(float_t fontSize) override;
float_t getDefaultFontSize() override;
};