Permalink
Browse files

Platform abstraction for requesting text input

  • Loading branch information...
1 parent eaa1a1b commit 5edfba8e0b62d29fdf06c753125320cb00267127 @thp committed Apr 16, 2014
Showing with 53 additions and 0 deletions.
  1. +19 −0 apkenv.h
  2. +11 −0 platform/fremantle.c
  3. +11 −0 platform/harmattan.c
  4. +12 −0 platform/pandora.c
View
19 apkenv.h
@@ -97,6 +97,13 @@ enum PlatformPath {
PLATFORM_PATH_MODULE_DIRECTORY = 3,
};
+/**
+ * Callback for a request_text_input request
+ * text ........ User-entered text, or NULL if the user canceled text input
+ * user_data ... The pointer passed to request_text_input() for the request
+ **/
+typedef void (*text_callback_t)(const char *text, void *user_data);
+
struct PlatformSupport {
/* Initialize the video mode, return nonzero on success, zero on error */
int (*init)(int gles_version);
@@ -110,6 +117,18 @@ struct PlatformSupport {
/* Process input events and forward to "module", return nonzero to exit */
int (*input_update)(struct SupportModule *module);
+ /**
+ * Asynchronously request text input from the native platform
+ * is_password ... If non-zero, text input will be hidden while typing
+ * text .......... Text to pre-fill into the entry (or NULL for none)
+ * callback ...... Callback for the result
+ * user_data ..... Pointer that will be passed to callback
+ * This function returns right away, when the text input is completed,
+ * callback will be called with user_data (see text_callback_t for details).
+ **/
+ void (*request_text_input)(int is_password, const char *text,
+ text_callback_t callback, void *user_data);
+
/* Called once per rendering frame to swap buffers, etc... */
void (*update)();
View
11 platform/fremantle.c
@@ -193,6 +193,16 @@ fremantle_input_update(struct SupportModule *module)
}
static void
+fremantle_request_text_input(int is_password, const char *text,
+ text_callback_t callback, void *user_data)
+{
+ fprintf(stderr, "XXX: Request text input not implemented!\n");
+
+ // Admit failure right away
+ callback(NULL, user_data);
+}
+
+static void
fremantle_update()
{
SDL_GLES_SwapBuffers();
@@ -208,6 +218,7 @@ struct PlatformSupport platform_support = {
fremantle_get_path,
fremantle_get_size,
fremantle_input_update,
+ fremantle_request_text_input,
fremantle_update,
fremantle_exit,
};
View
11 platform/harmattan.c
@@ -153,6 +153,16 @@ harmattan_input_update(struct SupportModule *module)
}
static void
+harmattan_request_text_input(int is_password, const char *text,
+ text_callback_t callback, void *user_data)
+{
+ fprintf(stderr, "XXX: Request text input not implemented!\n");
+
+ // Admit failure right away
+ callback(NULL, user_data);
+}
+
+static void
harmattan_update()
{
SDL_GL_SwapBuffers();
@@ -168,6 +178,7 @@ struct PlatformSupport platform_support = {
harmattan_get_path,
harmattan_get_size,
harmattan_input_update,
+ harmattan_request_text_input,
harmattan_update,
harmattan_exit,
};
View
12 platform/pandora.c
@@ -328,6 +328,17 @@ pandora_input_update(struct SupportModule *module)
}
static void
+pandora_request_text_input(int is_password, const char *text,
+ text_callback_t callback, void *user_data)
+{
+ fprintf(stderr, "XXX: Request text input not implemented!\n");
+
+ // Admit failure right away
+ callback(NULL, user_data);
+}
+
+
+static void
pandora_update()
{
static unsigned int last_time;
@@ -374,6 +385,7 @@ struct PlatformSupport platform_support = {
pandora_get_path,
pandora_get_size,
pandora_input_update,
+ pandora_request_text_input,
pandora_update,
pandora_exit,
};

0 comments on commit 5edfba8

Please sign in to comment.