From 54947dce2d8a45c4ca3911948cefdd6602ba8e3a Mon Sep 17 00:00:00 2001 From: Sergio Valor Martinez Date: Fri, 26 May 2023 11:00:51 +0200 Subject: [PATCH] OnScreenKeyboard: Creado el esqueleto base --- main.cpp | 26 ++++++++++++++++++++-- units/on_screen_keyboard.cpp | 43 ++++++++++++++++++++++++++++++++++++ units/on_screen_keyboard.h | 43 ++++++++++++++++++++++++++++++++++++ 3 files changed, 110 insertions(+), 2 deletions(-) create mode 100644 units/on_screen_keyboard.cpp create mode 100644 units/on_screen_keyboard.h diff --git a/main.cpp b/main.cpp index 26db734..8be1429 100644 --- a/main.cpp +++ b/main.cpp @@ -15,6 +15,7 @@ Código fuente creado por JailDesigner #include "units/texture.h" #include "units/screen.h" #include "units/input.h" +#include "units/on_screen_keyboard.h" #include "quickcg.h" using namespace QuickCG; @@ -32,6 +33,7 @@ Text *text; Text *debugText; Texture *texture; MovingSprite *sprite; +OnScreenKeyboard *osk; // Variables de uso general Uint32 ticks = 0; // Variable para la frecuencia de actualización de la lógica del programa @@ -90,6 +92,9 @@ void initInput(); // Inicializa el texto void initText(); +// Inicializa el teclado en pantalla +void initOnScreenKeyboard(); + // Inicializa el sprite void initSprite(); @@ -235,6 +240,12 @@ void initText() debugText = new Text(asset->get("debug.txt"), asset->get("debug.png"), renderer); } +// Inicializa el teclado en pantalla +void initOnScreenKeyboard() +{ + osk = new OnScreenKeyboard(renderer, input, asset->get("notify.png"), asset->get("smb2.png"), asset->get("smb2.txt"), options); +} + // Inicializa el sprite void initSprite() { @@ -272,7 +283,7 @@ void initFire() // Saturation is always the maximum: 255 // Lightness is 0..255 for x=0..128, and 255 for x=128..255 ColorRGB color = HSLtoRGB(ColorHSL(x / 3, 255, std::min(255, x * 2))); - + // Pon en la paleta el color calculado palette[x] = (Uint32)16777216 * 255 + 65536 * color.r + 256 * color.g + color.b; } @@ -312,6 +323,9 @@ void initAll(char *argv[]) // Inicializa el texto initText(); + // Inicializa el teclado en pantalla + initOnScreenKeyboard(); + // Inicializa el sprite initSprite(); @@ -514,7 +528,8 @@ void update() // Incrementa el contador counter++; - // Actualiza el objeto screen + // Actualiza los objetos + osk->update(); screen->update(); // Actualiza el sprite @@ -608,6 +623,9 @@ void render() // Dinuja el texto renderText(); + // Dibuja el teclado en pantalla + osk->render(); + // Vuelca el buffer en pantalla screen->blit(); } @@ -621,6 +639,10 @@ void freeAll() if (texture != nullptr) delete texture; + // Finaliza el teclado en pantalla + if (osk != nullptr) + delete osk; + // Finaliza el texto if (text != nullptr) delete text; diff --git a/units/on_screen_keyboard.cpp b/units/on_screen_keyboard.cpp new file mode 100644 index 0000000..3f0b853 --- /dev/null +++ b/units/on_screen_keyboard.cpp @@ -0,0 +1,43 @@ +#include "on_screen_keyboard.h" + +// Constructor +OnScreenKeyboard::OnScreenKeyboard(SDL_Renderer *renderer, Input *input, string iconFile, string bitmapFile, string textFile, options_t *options) +{ + // Inicializa variables + this->renderer = renderer; + this->options = options; + this->input = input; + + // Crea objetos + iconTexture = new Texture(renderer, iconFile); + text = new Text(textFile, bitmapFile, renderer); + + // Inicializa variables + letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; +} + +// Destructor +OnScreenKeyboard::~OnScreenKeyboard() +{ + // Libera la memoria de los objetos + if (iconTexture != nullptr) + { + delete iconTexture; + } + + if (text != nullptr) + { + delete text; + } +} + +// Actualiza la lógica del objeto +void OnScreenKeyboard::update() +{ +} + +// Dibuja el objeto en pantalla +void OnScreenKeyboard::render() +{ + text->write(0,0,"ON_SCREEN_KEYBOARD"); +} \ No newline at end of file diff --git a/units/on_screen_keyboard.h b/units/on_screen_keyboard.h new file mode 100644 index 0000000..cc47c9e --- /dev/null +++ b/units/on_screen_keyboard.h @@ -0,0 +1,43 @@ +#pragma once + +#include +#include "utils.h" +#include "text.h" +#include "input.h" + +#ifndef ON_SCREEN_KEYBOARD_H +#define ON_SCREEN_KEYBOARD_H + +using namespace std; + +class OnScreenKeyboard +{ +private: + + // Objetos y punteros + SDL_Renderer *renderer; // El renderizador de la ventana + Texture *iconTexture; // Textura para los gráficos + Text *text; // Objeto para dibujar texto + Input *input; // Gestor de eventos de entrada de teclado o gamepad + options_t *options; // Variable con todas las opciones del programa + + // Variables + string letters; + +public: + + // Constructor + OnScreenKeyboard(SDL_Renderer *renderer, Input *input, string iconFile, string bitmapFile, string textFile, options_t *options); + + // Destructor + ~OnScreenKeyboard(); + + // Actualiza la lógica del objeto + void update(); + + // Dibuja el objeto en pantalla + void render(); + +}; + +#endif \ No newline at end of file