summaryrefslogtreecommitdiffstatshomepage
path: root/src/osd
diff options
context:
space:
mode:
author Vas Crabb <vas@vastheman.com>2016-05-27 16:02:01 +1000
committer Vas Crabb <vas@vastheman.com>2016-05-27 16:03:03 +1000
commit73153c3387a8f0bc628b8f0ee3a63ba8bb6717e8 (patch)
treefd8c90af5704ce62c605f61075c16f88e541be4d /src/osd
parent14ad4244485b2f719e471522fa890e1bc17c0898 (diff)
ui refactoring [Vas Crabb]
* Make ARRAY_LENGTH cause a compile error if used with a pointer/vector * Clean up text input code, move common operations to inline templates * Fix numerous one-byte buffer overruns * Don't flat-out ignore input beyond the C1 hole * Fix decoding of SDL text input
Diffstat (limited to 'src/osd')
-rw-r--r--src/osd/modules/input/input_sdl.cpp18
-rw-r--r--src/osd/osdcomm.h10
2 files changed, 20 insertions, 8 deletions
diff --git a/src/osd/modules/input/input_sdl.cpp b/src/osd/modules/input/input_sdl.cpp
index 2101623fe6c..6ba3ccb2be2 100644
--- a/src/osd/modules/input/input_sdl.cpp
+++ b/src/osd/modules/input/input_sdl.cpp
@@ -156,11 +156,23 @@ public:
{
auto window = GET_FOCUS_WINDOW(&event.text);
//printf("Focus window is %p - wl %p\n", window, sdl_window_list);
- unicode_char result;
if (window != nullptr)
{
- osd_uchar_from_osdchar(&result, sdlevent.text.text, 1);
- machine().ui_input().push_char_event(window->target(), result);
+ auto ptr = sdlevent.text.text;
+ auto len = std::strlen(sdlevent.text.text);
+ while (len)
+ {
+ unicode_char ch;
+ auto chlen = uchar_from_utf8(&ch, ptr, len);
+ if (0 > chlen)
+ {
+ ch = 0x0fffd;
+ chlen = 1;
+ }
+ ptr += chlen;
+ len -= chlen;
+ machine().ui_input().push_char_event(window->target(), ch);
+ }
}
}
break;
diff --git a/src/osd/osdcomm.h b/src/osd/osdcomm.h
index ee040498cf0..723c61d133c 100644
--- a/src/osd/osdcomm.h
+++ b/src/osd/osdcomm.h
@@ -11,8 +11,8 @@
#pragma once
-#ifndef __OSDCOMM_H__
-#define __OSDCOMM_H__
+#ifndef MAME_OSD_OSDCOMM_H
+#define MAME_OSD_OSDCOMM_H
#include <stdio.h>
#include <string.h>
@@ -128,8 +128,8 @@ using FPTR = uintptr_t;
#define EXTRACT_64HI(val) ((UINT32)((val) >> 32))
#define EXTRACT_64LO(val) ((UINT32)(val))
-/* Highly useful macro for compile-time knowledge of an array size */
-#define ARRAY_LENGTH(x) (sizeof(x) / sizeof(x[0]))
+// Highly useful template for compile-time knowledge of an array size
+template <typename T, size_t N> constexpr inline std::size_t ARRAY_LENGTH(T (&)[N]) { return N;}
/* Macros for normalizing data into big or little endian formats */
@@ -184,4 +184,4 @@ typedef ptrdiff_t ssize_t;
#endif
#endif
-#endif /* __OSDCOMM_H__ */
+#endif /* MAME_OSD_OSDCOMM_H */