-frontend: Don't inappropriately truncate text in menu text boxes.

-osd/windows: Handle WM_UNICHAR.
This commit is contained in:
Vas Crabb 2021-11-08 23:44:08 +11:00
parent 7cc9836017
commit 1cc8bcc68e
4 changed files with 63 additions and 28 deletions

View File

@ -203,7 +203,8 @@ protected:
{
// size up the text
float const lrborder(ui().box_lr_border() * machine().render().ui_aspect(&container()));
float maxwidth(origx2 - origx1);
float const origwidth(origx2 - origx1 - (2.0f * lrborder));
float maxwidth(origwidth);
for (Iter it = begin; it != end; ++it)
{
float width;
@ -212,30 +213,27 @@ protected:
0.0f, 0.0f, 1.0f, justify, wrap,
mame_ui_manager::NONE, rgb_t::black(), rgb_t::white(),
&width, nullptr, text_size);
width += 2.0f * lrborder;
maxwidth = (std::max)(maxwidth, width);
}
if (scale && ((origx2 - origx1) < maxwidth))
if (scale && (origwidth < maxwidth))
{
text_size *= ((origx2 - origx1) / maxwidth);
maxwidth = origx2 - origx1;
text_size *= origwidth / maxwidth;
maxwidth = origwidth;
}
// draw containing box
float x1(0.5f * (1.0f - maxwidth));
float x2(x1 + maxwidth);
ui().draw_outlined_box(container(), x1, y1, x2, y2, bgcolor);
float const boxleft(0.5f - (maxwidth * 0.5f) - lrborder);
float boxright(0.5f + (maxwidth * 0.5f) + lrborder);
ui().draw_outlined_box(container(), boxleft, y1, boxright, y2, bgcolor);
// inset box and draw content
x1 += lrborder;
x2 -= lrborder;
float const textleft(0.5f - (maxwidth * 0.5f));
y1 += ui().box_tb_border();
y2 -= ui().box_tb_border();
for (Iter it = begin; it != end; ++it)
{
ui().draw_text_full(
container(), std::string_view(*it),
x1, y1, x2 - x1, justify, wrap,
textleft, y1, maxwidth, justify, wrap,
mame_ui_manager::NORMAL, fgcolor, ui().colors().text_bg_color(),
nullptr, nullptr, text_size);
y1 += ui().get_line_height();

View File

@ -835,7 +835,14 @@ void mame_ui_manager::draw_text(render_container &container, std::string_view bu
// and full size computation
//-------------------------------------------------
void mame_ui_manager::draw_text_full(render_container &container, std::string_view origs, float x, float y, float origwrapwidth, ui::text_layout::text_justify justify, ui::text_layout::word_wrapping wrap, draw_mode draw, rgb_t fgcolor, rgb_t bgcolor, float *totalwidth, float *totalheight, float text_size)
void mame_ui_manager::draw_text_full(
render_container &container,
std::string_view origs,
float x, float y, float origwrapwidth,
ui::text_layout::text_justify justify, ui::text_layout::word_wrapping wrap,
draw_mode draw, rgb_t fgcolor, rgb_t bgcolor,
float *totalwidth, float *totalheight,
float text_size)
{
// create the layout
auto layout = create_layout(container, origwrapwidth, justify, wrap);
@ -844,7 +851,7 @@ void mame_ui_manager::draw_text_full(render_container &container, std::string_vi
layout.add_text(
origs,
fgcolor,
draw == OPAQUE_ ? bgcolor : rgb_t::transparent(),
(draw == OPAQUE_) ? bgcolor : rgb_t::transparent(),
text_size);
// and emit it (if we are asked to do so)
@ -867,7 +874,7 @@ void mame_ui_manager::draw_text_full(render_container &container, std::string_vi
void mame_ui_manager::draw_text_box(render_container &container, std::string_view text, ui::text_layout::text_justify justify, float xpos, float ypos, rgb_t backcolor)
{
// cap the maximum width
float maximum_width = 1.0f - box_lr_border() * 2;
float maximum_width = 1.0f - (box_lr_border() * machine().render().ui_aspect(&container) * 2.0f);
// create a layout
ui::text_layout layout = create_layout(container, maximum_width, justify);
@ -888,17 +895,18 @@ void mame_ui_manager::draw_text_box(render_container &container, std::string_vie
void mame_ui_manager::draw_text_box(render_container &container, ui::text_layout &layout, float xpos, float ypos, rgb_t backcolor)
{
// xpos and ypos are where we want to "pin" the layout, but we need to adjust for the actual size of the payload
auto actual_left = layout.actual_left();
auto actual_width = layout.actual_width();
auto actual_height = layout.actual_height();
auto x = std::clamp(xpos - actual_width / 2, box_lr_border(), 1.0f - actual_width - box_lr_border());
auto y = std::clamp(ypos - actual_height / 2, box_tb_border(), 1.0f - actual_height - box_tb_border());
auto const lrborder = box_lr_border() * machine().render().ui_aspect(&container);
auto const actual_left = layout.actual_left();
auto const actual_width = layout.actual_width();
auto const actual_height = layout.actual_height();
auto const x = std::clamp(xpos - actual_width / 2, lrborder, 1.0f - actual_width - lrborder);
auto const y = std::clamp(ypos - actual_height / 2, box_tb_border(), 1.0f - actual_height - box_tb_border());
// add a box around that
draw_outlined_box(
container,
x - box_lr_border(), y - box_tb_border(),
x + actual_width + box_lr_border(), y + actual_height + box_tb_border(),
x - lrborder, y - box_tb_border(),
x + actual_width + lrborder, y + actual_height + box_tb_border(),
backcolor);
// emit the text

View File

@ -307,6 +307,7 @@ win_window_info::win_window_info(
, m_lastclicktime(std::chrono::steady_clock::time_point::min())
, m_lastclickx(0)
, m_lastclicky(0)
, m_last_surrogate(0)
, m_attached_mode(false)
{
m_non_fullscreen_bounds.left = 0;
@ -1158,7 +1159,34 @@ LRESULT CALLBACK win_window_info::video_window_proc(HWND wnd, UINT message, WPAR
break;
case WM_CHAR:
window->machine().ui_input().push_char_event(window->target(), (char32_t) wparam);
{
char16_t const ch = char16_t(wparam);
if ((0xd800 <= ch) && (0xdbff >= ch))
{
window->m_last_surrogate = ch;
}
else if ((0xdc00 <= ch) && (0xdfff >= ch))
{
if (window->m_last_surrogate)
{
char32_t const uch = 0x10000 + ((ch & 0x03ff) | ((window->m_last_surrogate & 0x03ff) << 10));
window->machine().ui_input().push_char_event(window->target(), uch);
}
window->m_last_surrogate = 0;
}
else
{
window->machine().ui_input().push_char_event(window->target(), char32_t(ch));
window->m_last_surrogate = 0;
}
}
break;
case WM_UNICHAR:
if (UNICODE_NOCHAR == wparam)
return TRUE;
else
window->machine().ui_input().push_char_event(window->target(), char32_t(wparam));
break;
case WM_MOUSEWHEEL:
@ -1166,8 +1194,8 @@ LRESULT CALLBACK win_window_info::video_window_proc(HWND wnd, UINT message, WPAR
UINT ucNumLines = 3; // default
SystemParametersInfo(SPI_GETWHEELSCROLLLINES, 0, &ucNumLines, 0);
window->machine().ui_input().push_mouse_wheel_event(window->target(), GET_X_LPARAM(lparam), GET_Y_LPARAM(lparam), GET_WHEEL_DELTA_WPARAM(wparam), ucNumLines);
break;
}
break;
// pause the system when we start a menu or resize
case WM_ENTERSIZEMOVE:

View File

@ -98,8 +98,8 @@ public:
int m_ismaximized;
// monitor info
int m_fullscreen_safe;
float m_aspect;
int m_fullscreen_safe;
float m_aspect;
// rendering info
std::mutex m_render_lock;
@ -110,8 +110,9 @@ public:
// input info
std::chrono::steady_clock::time_point m_lastclicktime;
int m_lastclickx;
int m_lastclicky;
int m_lastclickx;
int m_lastclicky;
char16_t m_last_surrogate;
private:
void draw_video_contents(HDC dc, bool update);