mirror of
https://github.com/TerryCavanagh/VVVVVV.git
synced 2024-12-22 09:39:43 +01:00
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.
This commit is contained in:
parent
a9ca63b367
commit
8b8f827b70
4 changed files with 72 additions and 3 deletions
|
@ -82,6 +82,7 @@ set(VVV_CXX_SRC
|
|||
src/Graphics.cpp
|
||||
src/GraphicsResources.cpp
|
||||
src/GraphicsUtil.cpp
|
||||
src/IMERender.cpp
|
||||
src/Input.cpp
|
||||
src/KeyPoll.cpp
|
||||
src/Labclass.cpp
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#include "FileSystemUtils.h"
|
||||
#include "Font.h"
|
||||
#include "GraphicsUtil.h"
|
||||
#include "IMERender.h"
|
||||
#include "Localization.h"
|
||||
#include "Map.h"
|
||||
#include "Maths.h"
|
||||
|
@ -3529,6 +3530,7 @@ void Graphics::get_stretch_info(SDL_Rect* rect)
|
|||
|
||||
void Graphics::render(void)
|
||||
{
|
||||
ime_render();
|
||||
draw_screenshot_border();
|
||||
|
||||
if (gameScreen.badSignalEffect)
|
||||
|
@ -3541,10 +3543,12 @@ void Graphics::render(void)
|
|||
|
||||
draw_window_background();
|
||||
|
||||
SDL_Rect rect;
|
||||
get_stretch_info(&rect);
|
||||
SDL_Rect stretch_info;
|
||||
get_stretch_info(&stretch_info);
|
||||
|
||||
copy_texture(gameTexture, NULL, &rect, 0, NULL, flipmode ? SDL_FLIP_VERTICAL : SDL_FLIP_NONE);
|
||||
ime_set_rect(&stretch_info);
|
||||
|
||||
copy_texture(gameTexture, NULL, &stretch_info, 0, NULL, flipmode ? SDL_FLIP_VERTICAL : SDL_FLIP_NONE);
|
||||
}
|
||||
|
||||
void Graphics::renderwithscreeneffects(void)
|
||||
|
|
57
desktop_version/src/IMERender.cpp
Normal file
57
desktop_version/src/IMERender.cpp
Normal file
|
@ -0,0 +1,57 @@
|
|||
#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);
|
||||
}
|
7
desktop_version/src/IMERender.h
Normal file
7
desktop_version/src/IMERender.h
Normal file
|
@ -0,0 +1,7 @@
|
|||
#ifndef IMERENDER_H
|
||||
#define IMERENDER_H
|
||||
|
||||
void ime_render(void);
|
||||
void ime_set_rect(SDL_Rect* stretch_info);
|
||||
|
||||
#endif /* IMERENDER_H */
|
Loading…
Reference in a new issue