text2 class converted to writer class

This commit is contained in:
2021-08-28 12:57:13 +02:00
parent a54d71c990
commit 13be9df131
3 changed files with 199 additions and 221 deletions

View File

@@ -1,194 +1,194 @@
# box width # box width
8 10
# box height # box height
8 10
# 32 espacio ( ) # 32 espacio ( )
2 3
# 33 ! # 33 !
2 4
# 34 " # 34 "
5 5
# 35 # # 35 #
6 7
# 36 $ # 36 $
6 7
# 37 % # 37 %
6 8
# 38 & # 38 &
6 8
# 39 ' # 39 '
2 3
# 40 ( # 40 (
3 5
# 41 ) # 41 )
3 5
# 42 * # 42 *
4 7
# 43 + # 43 +
3 7
# 44 , # 44 ,
2 4
# 45 - # 45 -
3 6
# 46 . # 46 .
2 4
# 47 / # 47 /
4 5
# 48 0 # 48 0
6 7
# 49 1 # 49 1
3 5
# 50 2 # 50 2
6 7
# 51 3 # 51 3
6 7
# 52 4 # 52 4
6 7
# 53 5 # 53 5
6 7
# 54 6 # 54 6
6 7
# 55 7 # 55 7
6 7
# 56 8 # 56 8
6 7
# 57 9 # 57 9
6 7
# 58 : # 58 :
2 4
# 59 ; # 59 ;
2 4
# 60 < # 60 <
4
# 61 =
3
# 62 >
4
# 63 ?
6 6
# 61 =
6
# 62 >
6
# 63 ?
7
# 64 @ # 64 @
8 8
# 65 A # 65 A
6 7
# 66 B # 66 B
6 7
# 67 C # 67 C
6 7
# 68 D # 68 D
6 7
# 69 E # 69 E
6 7
# 70 F # 70 F
6 7
# 71 G # 71 G
6 7
# 72 H # 72 H
6 7
# 73 I # 73 I
6 4
# 74 J # 74 J
6 6
# 75 K # 75 K
6 8
# 76 L # 76 L
6 6
# 77 M # 77 M
6 9
# 78 N # 78 N
6 8
# 79 O # 79 O
6 8
# 80 P # 80 P
6 7
# 81 Q # 81 Q
6 8
# 82 R # 82 R
6 7
# 83 S # 83 S
6 6
# 84 T # 84 T
6 8
# 85 U # 85 U
6 7
# 86 V # 86 V
5 8
# 87 W # 87 W
6 9
# 88 X # 88 X
6 8
# 89 Y # 89 Y
6 8
# 90 Z # 90 Z
6 7
# 91 [ # 91 [
3 4
# 92 \ # 92 \
5 5
# 93 ] # 93 ]
3
# 94 ^
4 4
# 94 ^
5
# 95 _ # 95 _
6 8
# 96 ` # 96 `
2 4
# 97 a # 97 a
5 7
# 98 b # 98 b
5 7
# 99 c # 99 c
5 6
# 100 d # 100 d
5 7
# 101 e # 101 e
5 7
# 102 f # 102 f
5 5
# 103 g # 103 g
5 7
# 104 h # 104 h
5 7
# 105 i # 105 i
4 4
# 106 j # 106 j
5 5
# 107 k # 107 k
5 7
# 108 l # 108 l
5 4
# 109 m # 109 m
6 10
# 110 n # 110 n
5 7
# 111 o # 111 o
5 7
# 112 p # 112 p
5 7
# 113 q # 113 q
5 7
# 114 r # 114 r
5
# 115 s
5
# 116 t
4
# 117 u
5
# 118 v
5
# 119 w
6 6
# 120 x # 115 s
4 6
# 121 y # 116 t
4
# 122 z
5 5
# 123 { # 117 u
3 7
# 124 | # 118 v
2 7
# 119 w
9
# 120 x
7
# 121 y
7
# 122 z
7
# 123 { -> ñ
7
# 124 | -> ç
7
# 125 } # 125 }
3 0
# 126 ~ # 126 ~
3 0

View File

@@ -1,18 +1,18 @@
#include "const.h" #include "const.h"
#include "text2.h" #include "writer.h"
// Constructor // Constructor
Text2::Text2(std::string file, LTexture *texture, SDL_Renderer *renderer) : Text(file, texture, renderer) Writer::Writer(std::string file, LTexture *texture, SDL_Renderer *renderer)
{ {
} }
// Destructor // Destructor
Text2::~Text2() Writer::~Writer()
{ {
} }
// Inicializador // Inicializador
void Text2::init() void Writer::init()
{ {
Text::init(); Text::init();
mPosX = 0; mPosX = 0;
@@ -31,63 +31,63 @@ void Text2::init()
} }
// Establece el valor de la variable // Establece el valor de la variable
void Text2::setPosX(int value) void Writer::setPosX(int value)
{ {
mPosX = value; mPosX = value;
} }
// Establece el valor de la variable // Establece el valor de la variable
void Text2::setPosY(int value) void Writer::setPosY(int value)
{ {
mPosY = value; mPosY = value;
} }
// Establece el valor de la variable // Establece el valor de la variable
void Text2::setKerning(int value) void Writer::setKerning(int value)
{ {
mKerning = value; mKerning = value;
} }
// Establece el valor de la variable // Establece el valor de la variable
void Text2::setCaption(std::string text) void Writer::setCaption(std::string text)
{ {
mCaption = text; mCaption = text;
mLenght = text.length(); mLenght = text.length();
} }
// Establece el valor de la variable // Establece el valor de la variable
void Text2::setWrittingSpeed(Uint16 value) void Writer::setWrittingSpeed(Uint16 value)
{ {
mWrittingSpeed = value; mWrittingSpeed = value;
mWrittingTimer = value; mWrittingTimer = value;
} }
// Establece el valor de la variable // Establece el valor de la variable
void Text2::setEnabled(bool value) void Writer::setEnabled(bool value)
{ {
mEnabled = value; mEnabled = value;
} }
// Obtiene el valor de la variable // Obtiene el valor de la variable
bool Text2::IsEnabled() bool Writer::IsEnabled()
{ {
return mEnabled; return mEnabled;
} }
// Establece el valor de la variable // Establece el valor de la variable
void Text2::setEnabledTimer(Uint16 value) void Writer::setEnabledTimer(Uint16 value)
{ {
mEnabledTimer = value; mEnabledTimer = value;
} }
// Obtiene el valor de la variable // Obtiene el valor de la variable
Uint16 Text2::getEnabledTimer() Uint16 Writer::getEnabledTimer()
{ {
return mEnabledTimer; return mEnabledTimer;
} }
// Actualiza el objeto // Actualiza el objeto
void Text2::update() void Writer::update()
{ {
if (mEnabled) if (mEnabled)
{ {
@@ -95,11 +95,11 @@ void Text2::update()
{ {
if (mWrittingTimer > 0) if (mWrittingTimer > 0)
{ {
--mWrittingTimer; mWrittingTimer--;
} }
if (mWrittingTimer == 0) if (mWrittingTimer == 0)
{ {
++mIndex; mIndex++;
mWrittingTimer = mWrittingSpeed; mWrittingTimer = mWrittingSpeed;
} }
if (mIndex == mLenght) if (mIndex == mLenght)
@@ -111,7 +111,7 @@ void Text2::update()
{ {
if (mEnabledTimer > 0) if (mEnabledTimer > 0)
{ {
--mEnabledTimer; mEnabledTimer--;
} }
else if (mEnabledTimer == 0) else if (mEnabledTimer == 0)
{ {
@@ -129,7 +129,7 @@ void Text2::update()
} }
// Dibuja el objeto en pantalla // Dibuja el objeto en pantalla
void Text2::render() void Writer::render()
{ {
if (mEnabled) if (mEnabled)
{ {
@@ -138,19 +138,19 @@ void Text2::render()
} }
// Centra la cadena de texto a un punto X // Centra la cadena de texto a un punto X
void Text2::center(int x) void Writer::center(int x)
{ {
setPosX(x - (lenght(mCaption, mKerning) / 2)); setPosX(x - (lenght(mCaption, mKerning) / 2));
} }
// Establece el valor de la variable // Establece el valor de la variable
void Text2::setId(int id) void Writer::setId(int id)
{ {
mId = id; mId = id;
} }
// Establece el valor de la variable // Establece el valor de la variable
void Text2::setIntroEvents(Uint8 *value) void Writer::setIntroEvents(Uint8 *value)
{ {
mIntroEvents = value; mIntroEvents = value;
} }

View File

@@ -2,18 +2,34 @@
#include "sprite.h" #include "sprite.h"
#include "text.h" #include "text.h"
#ifndef TEXT2_H #ifndef WRITER_H
#define TEXT2_H #define WRITER_H
// Clase texto. Pinta texto en pantalla a partir de un bitmap // Clase texto. Pinta texto en pantalla a partir de un bitmap
class Text2 : public Text class Writer
{ {
private:
int mPosX; // Posicion en el eje X donde empezar a escribir el texto
int mPosY; // Posicion en el eje Y donde empezar a escribir el texto
int mKerning; // Kerning del texto, es decir, espaciado entre caracteres
std::string mCaption; // El texto para escribir
Uint16 mSpeed; // Velocidad de escritura
Uint16 mTimer; // Temporizador de escritura para cada caracter
Uint16 mIndex; // Posición del texto que se está escribiendo
Uint16 mLenght; // Longitud de la cadena a escribir
bool mCompleted; // Indica si se ha escrito todo el texto
bool mEnabled; // Indica si el objeto está habilitado
Uint16 mEnabledTimer; // Temporizador para deshabilitar el objeto
int mId; // Temporizador para deshabilitar el objeto
Uint8 *mIntroEvents; // Dirección del array de eventos donde notificar el estado
Text *mText; // Objeto encargado de escribir el texto
public: public:
// Constructor // Constructor
Text2(std::string file, LTexture *texture, SDL_Renderer *renderer); Writer(Text *text);
// Destructor // Destructor
~Text2(); ~Writer();
// Inicializador // Inicializador
void init(); void init();
@@ -31,7 +47,7 @@ public:
void setCaption(std::string text); void setCaption(std::string text);
// Establece el valor de la variable // Establece el valor de la variable
void setWrittingSpeed(Uint16 value); void setSpeed(Uint16 value);
// Establece el valor de la variable // Establece el valor de la variable
void setEnabled(bool value); void setEnabled(bool value);
@@ -59,44 +75,6 @@ public:
// Establece el valor de la variable // Establece el valor de la variable
void setIntroEvents(Uint8 *value); void setIntroEvents(Uint8 *value);
private:
// Posicion X/Y donde empezar a escribir el texto
int mPosX;
int mPosY;
// Kerning del texto
int mKerning;
// Texto para escribir
std::string mCaption;
// Velocidad de escritura
Uint16 mWrittingSpeed;
// Temporizador de escritura para cada caracter
Uint16 mWrittingTimer;
// Posición del texto que se está escribiendo
Uint16 mIndex;
// Longitud de la cadena a escribir
Uint16 mLenght;
// Indica si se ha escrito todo el texto
bool mWrittingCompleted;
// Indica si el objeto está habilitado
bool mEnabled;
// Temporizador para deshabilitar el objeto
Uint16 mEnabledTimer;
// Identificador
int mId;
// Dirección del array de eventos donde notificar el estado
Uint8 *mIntroEvents;
}; };
#endif #endif