1 /** 2 * Copyright: Copyright (C) 2018 Gabriel Gheorghe, All Rights Reserved 3 * Authors: $(Gabriel Gheorghe) 4 * License: $(LINK2 https://www.gnu.org/licenses/gpl-3.0.txt, GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007) 5 * Source: $(LINK2 https://github.com/GabyForceQ/LibertyEngine/blob/master/source/liberty/text/character.d) 6 * Documentation: 7 * Coverage: 8 **/ 9 module liberty.text.character; 10 11 import liberty.math.vector; 12 13 /** 14 * Holds information about a certain glyph in the font texture atlas. 15 * All sizes are defined for a font-size of 1 point. 16 **/ 17 final class Character { 18 private { 19 // getASCIIValue 20 int id; 21 22 // getTexCoords 23 Vector2F texCoords; 24 // getMaxTexCoords 25 Vector2F maxTexCoords; 26 // getOffset 27 Vector2F offset; 28 // getSize 29 Vector2F size; 30 // getAdvance 31 Vector2F advance; 32 } 33 34 /** 35 * $(D_PARAM id): 36 * - stores the ASCII value of the character. 37 * $(D_PARAM texCoords): 38 * - x: stores the texture x-coordinate for the top left corner of the character in texture atlas. 39 * - y: stores the texture y-coordinate for the top left corner of the character in texture atlas. 40 * $(D_PARAM texSize): 41 * - x: stores the width of the character in the texture atlas. 42 * - y: stores the height of the character in the texture atlas. 43 * $(D_PARAM offset): 44 * - x: stores the x distance from the curser to the left edge of the character's quad. 45 * - y: stores the y distance from the curser to the top edge of the character's quad. 46 * $(D_PARAM size): 47 * - x: stores the width of the character's quad in screen space. 48 * - y: stores the height of the character's quad in screen space. 49 * $(D_PARAM advance): 50 * - x: stores how far in pixels the cursor should advance after adding this character on x-axis. 51 * - y: stores how far in pixels the cursor should advance after adding this character on y-axis. 52 **/ 53 this(int id, Vector2F texCoords, Vector2F texSize, Vector2F offset, Vector2F size, Vector2F advance) { 54 this.id = id; 55 this.texCoords = texCoords; 56 this.offset = offset; 57 this.size = size; 58 this.advance = advance; 59 maxTexCoords = texSize + texCoords; 60 } 61 62 /** 63 * Returns the ASCII value of the character. 64 **/ 65 int getASCIIValue() const { 66 return id; 67 } 68 69 /** 70 * Returns the character texture coordinates. 71 **/ 72 Vector2F getTexCoords() const { 73 return texCoords; 74 } 75 76 /** 77 * Returns the character maximum texture coordinates. 78 **/ 79 Vector2F getMaxTexCoords() const { 80 return maxTexCoords; 81 } 82 83 /** 84 * Returns the character offset. 85 **/ 86 Vector2F getOffset() const { 87 return offset; 88 } 89 90 /** 91 * Returns the dimension of the character's quad in screen space. 92 **/ 93 Vector2F getSize() const { 94 return size; 95 } 96 97 /** 98 * Returns how far in pixels the cursor should advance after adding this character. 99 **/ 100 Vector2F getAdvance() const { 101 return advance; 102 } 103 }