on_screen_keyboard: Ya dibuja el objeto básico en pantalla
This commit is contained in:
@@ -1,19 +1,30 @@
|
||||
#include "on_screen_keyboard.h"
|
||||
|
||||
// Constructor
|
||||
OnScreenKeyboard::OnScreenKeyboard(SDL_Renderer *renderer, Input *input, string iconFile, string bitmapFile, string textFile, options_t *options)
|
||||
OnScreenKeyboard::OnScreenKeyboard(SDL_Renderer *renderer, Input *input, string iconFile, string bitmapFile, string textFile, options_t *options, int width, int height, color_t color)
|
||||
{
|
||||
// Inicializa variables
|
||||
this->renderer = renderer;
|
||||
this->options = options;
|
||||
this->input = input;
|
||||
this->width = width;
|
||||
this->height = height;
|
||||
|
||||
// Crea objetos
|
||||
iconTexture = new Texture(renderer, iconFile);
|
||||
text = new Text(textFile, bitmapFile, renderer);
|
||||
texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, width, height);
|
||||
|
||||
// Inicializa variables
|
||||
letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
||||
char_upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
char_lower = "abcdefghijklmnopqrstuvwxyz";
|
||||
char_numbers = "0123456789";
|
||||
char_symbol = " !\"#$%&'()*+,-./:;<=>?@[]";
|
||||
caption = "";
|
||||
dest = {(options->screen.nativeWidth - width) / 2, (options->screen.nativeHeight - height) / 2, width, height};
|
||||
|
||||
// Rellena la textura de fondo con el color y el texto
|
||||
fillTexture();
|
||||
}
|
||||
|
||||
// Destructor
|
||||
@@ -29,6 +40,37 @@ OnScreenKeyboard::~OnScreenKeyboard()
|
||||
{
|
||||
delete text;
|
||||
}
|
||||
|
||||
if (texture != nullptr)
|
||||
{
|
||||
SDL_DestroyTexture(texture);
|
||||
}
|
||||
}
|
||||
|
||||
// Rellena la textura de fondo con el color y el texto
|
||||
void OnScreenKeyboard::fillTexture()
|
||||
{
|
||||
// Empieza a dibujar en la textura
|
||||
SDL_SetRenderTarget(renderer, texture);
|
||||
|
||||
// Establece el color de fondo
|
||||
SDL_SetRenderDrawColor(renderer, bgColor.r, bgColor.g, bgColor.b, 255);
|
||||
SDL_RenderClear(renderer);
|
||||
|
||||
// Escribe el texto que aparece en el objeto
|
||||
text->write(text->getCharacterSize(), text->getCharacterSize(), caption);
|
||||
|
||||
// Dibuja el cuadro donde va el texto que se escribirá
|
||||
SDL_SetRenderDrawColor(renderer, bgColor.r - 10, bgColor.g - 10, bgColor.b - 10, 255);
|
||||
const int x_rect = (text->getCharacterSize() * 2) + text->lenght(caption);
|
||||
const int y_rect = text->getCharacterSize();
|
||||
const int w_rect = width - text->getCharacterSize() - x_rect;
|
||||
const int h_rect = text->getCharacterSize();
|
||||
SDL_Rect rect = {x_rect, y_rect, w_rect, h_rect};
|
||||
SDL_RenderFillRect(renderer, &rect);
|
||||
|
||||
// Deja de dibujar en la textura
|
||||
SDL_SetRenderTarget(renderer, nullptr);
|
||||
}
|
||||
|
||||
// Actualiza la lógica del objeto
|
||||
@@ -39,5 +81,19 @@ void OnScreenKeyboard::update()
|
||||
// Dibuja el objeto en pantalla
|
||||
void OnScreenKeyboard::render()
|
||||
{
|
||||
text->write(0,0,"ON_SCREEN_KEYBOARD");
|
||||
SDL_RenderCopy(renderer, texture, nullptr, &dest);
|
||||
}
|
||||
|
||||
// Establece el color de fondo
|
||||
void OnScreenKeyboard::setBgColor(color_t color)
|
||||
{
|
||||
bgColor = color;
|
||||
fillTexture();
|
||||
}
|
||||
|
||||
// Establece el texto a mostrar junto al texto a introducir
|
||||
void OnScreenKeyboard::setCaption(string text)
|
||||
{
|
||||
caption = text;
|
||||
fillTexture();
|
||||
}
|
||||
Reference in New Issue
Block a user