2018-08-20 14:30:31 +02:00
|
|
|
/*
|
|
|
|
* BreakHack - A dungeone crawler RPG
|
|
|
|
* Copyright (C) 2018 Linus Probert <linus.probert@gmail.com>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2018-08-21 22:27:45 +02:00
|
|
|
#include <string.h>
|
2018-08-20 14:30:31 +02:00
|
|
|
#include "tooltip.h"
|
|
|
|
#include "gui_util.h"
|
|
|
|
#include "defines.h"
|
|
|
|
#include "gui.h"
|
2018-10-05 13:08:38 +02:00
|
|
|
#include "texturecache.h"
|
|
|
|
|
|
|
|
static bool
|
|
|
|
render_button_texture_for(const char *text, Position pos, Camera *cam)
|
|
|
|
{
|
2018-10-10 22:34:41 +02:00
|
|
|
Texture *t = texturecache_add("Extras/Controller.png");
|
|
|
|
SDL_Rect clip;
|
2018-10-05 13:08:38 +02:00
|
|
|
if (strcmp(text, "1") == 0) {
|
2018-10-10 22:34:41 +02:00
|
|
|
clip = CLIP16(0, 0);
|
2018-10-09 14:19:59 +02:00
|
|
|
} else if (strcmp(text, "2") == 0) {
|
|
|
|
clip = CLIP16(16, 0);
|
2018-10-10 22:34:41 +02:00
|
|
|
} else if (strcmp(text, "3") == 0) {
|
|
|
|
clip = CLIP16(32, 0);
|
|
|
|
} else if (strcmp(text, "4") == 0) {
|
|
|
|
clip = CLIP16(48, 0);
|
|
|
|
} else if (strcmp(text, "5") == 0) {
|
|
|
|
clip = CLIP16(48, 48);
|
|
|
|
} else if (strcmp(text, "ESC") == 0) {
|
|
|
|
clip = CLIP16(0, 64);
|
|
|
|
} else if (strcmp(text, "SHIFT") == 0) {
|
|
|
|
clip = CLIP16(16, 48);
|
|
|
|
} else if (strcmp(text, "SPACE") == 0) {
|
|
|
|
clip = CLIP16(16, 32);
|
2018-10-05 13:08:38 +02:00
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-10-09 14:19:59 +02:00
|
|
|
SDL_Rect renderBox = { pos.x, pos.y, 16, 16 };
|
2018-10-05 13:08:38 +02:00
|
|
|
texture_render_clip(t, &renderBox, &clip, cam);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
load_texture_for(Texture *text,
|
|
|
|
char *content,
|
|
|
|
SDL_Rect *renderBox,
|
|
|
|
SDL_Renderer *renderer)
|
|
|
|
{
|
|
|
|
texture_load_from_text(text,
|
|
|
|
content,
|
|
|
|
C_WHITE,
|
|
|
|
C_WHITE,
|
|
|
|
renderer);
|
|
|
|
|
|
|
|
renderBox->w = text->dim.width;
|
|
|
|
renderBox->h = text->dim.height;
|
|
|
|
}
|
2018-08-20 14:30:31 +02:00
|
|
|
|
|
|
|
Sprite *
|
|
|
|
tooltip_create(char **content, Camera *cam)
|
|
|
|
{
|
|
|
|
int rowCount = 0;
|
|
|
|
char **contentIndex = content;
|
|
|
|
while (*contentIndex) {
|
|
|
|
rowCount++;
|
|
|
|
contentIndex++;
|
|
|
|
}
|
|
|
|
|
|
|
|
Sprite *sprite = gui_util_create_tooltip_frame_sprite(BOTTOM_GUI_WIDTH/16 - 6,
|
2018-10-09 14:19:59 +02:00
|
|
|
(Uint32) ((rowCount * 9 + 48)/16),
|
2018-08-20 14:30:31 +02:00
|
|
|
cam);
|
|
|
|
sprite->pos.x = 48;
|
2018-10-09 14:19:59 +02:00
|
|
|
sprite->pos.y = 48;
|
2018-08-20 14:30:31 +02:00
|
|
|
Texture *texture = sprite->textures[0];
|
|
|
|
Texture *text = texture_create();
|
|
|
|
texture_load_font(text, "GUI/SDS_8x8.ttf", LOG_FONT_SIZE, 0);
|
|
|
|
SDL_SetRenderTarget(cam->renderer, texture->texture);
|
|
|
|
SDL_Rect renderBox = { 16, 16, 0, 0 };
|
|
|
|
|
|
|
|
while (*content) {
|
|
|
|
if (strlen(*content) > 0) {
|
2018-10-09 14:19:59 +02:00
|
|
|
if (render_button_texture_for(*content, POS(renderBox.x, renderBox.y - 4), cam)) {
|
2018-10-10 22:34:41 +02:00
|
|
|
renderBox.x += 16;
|
2018-10-09 14:19:59 +02:00
|
|
|
} else {
|
2018-10-05 13:08:38 +02:00
|
|
|
load_texture_for(text, *content, &renderBox, cam->renderer);
|
|
|
|
texture_render(text, &renderBox, cam);
|
2018-10-09 14:19:59 +02:00
|
|
|
renderBox.x += text->dim.width;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
renderBox.x = 16;
|
|
|
|
renderBox.y += 14;
|
2018-08-20 14:30:31 +02:00
|
|
|
}
|
|
|
|
content++;
|
|
|
|
}
|
|
|
|
SDL_SetRenderTarget(cam->renderer, NULL);
|
|
|
|
texture_destroy(text);
|
|
|
|
|
|
|
|
return sprite;
|
|
|
|
}
|