1
0
Fork 0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-12-24 10:39:43 +01:00
VVVVVV/desktop_version/src/IMERender.cpp
Dav999 8b8f827b70 Add IME text rendering
This shows the uncommitted text in a box in the bottom left corner.
This doesn't show the selection (defined by the start and length fields
in the event) yet, but this is already much better than it was on its
own, and I don't know how urgent the selection is since it's broken on
Windows anyway.
2024-08-02 22:25:00 -07:00

57 lines
1.4 KiB
C++

#include <SDL.h>
#include "Constants.h"
#include "Font.h"
#include "Graphics.h"
#include "KeyPoll.h"
static bool render_done = false;
static SDL_Rect imebox;
void ime_render(void)
{
render_done = false;
if (!SDL_IsTextInputActive() || key.imebuffer == "")
{
return;
}
int fontheight = font::height(PR_FONT_LEVEL);
imebox.x = 8;
imebox.y = SCREEN_HEIGHT_PIXELS - 32 - fontheight;
imebox.w = font::len(PR_FONT_LEVEL, key.imebuffer.c_str()) + 1;
imebox.h = fontheight + 1;
SDL_Rect imebox_border = imebox;
imebox_border.x -= 1;
imebox_border.y -= 1;
imebox_border.w += 2;
imebox_border.h += 2;
graphics.fill_rect(&imebox_border, 128, 128, 128);
graphics.fill_rect(&imebox, 0, 0, 0);
font::print(PR_FONT_LEVEL | PR_CJK_LOW, imebox.x + 1, imebox.y + 1, key.imebuffer, 255, 255, 255);
render_done = true;
}
void ime_set_rect(SDL_Rect* stretch_info)
{
if (!render_done)
{
return;
}
SDL_Rect imebox_scaled = imebox;
float x_scale = (float) stretch_info->w / SCREEN_WIDTH_PIXELS;
float y_scale = (float) stretch_info->h / SCREEN_HEIGHT_PIXELS;
imebox_scaled.x *= x_scale;
imebox_scaled.y *= y_scale;
imebox_scaled.w *= x_scale;
imebox_scaled.h *= y_scale;
imebox_scaled.x += stretch_info->x;
imebox_scaled.y += stretch_info->y;
SDL_SetTextInputRect(&imebox_scaled);
}