1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
|
/*
* Copyright (c) 2018 Samsung Electronics Co., Ltd.
*
* Licensed under the Flora License, Version 1.1 (the License);
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://floralicense.org/license/
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an AS IS BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "view/view_base.h"
#include "view/view_name_input.h"
#include "view_manager/view_manager.h"
#include "controller/controller_name_input.h"
#include <assert.h>
#include "log.h"
#define ENTRY_STYLE "DEFAULT='align=center'"
typedef struct _ss_view_name_input {
s_view_base view_base;
const char *player_name;
} s_view_name_input;
static s_view_name_input s_info = { {0,}, };
static void _layout_back_cb(void *data, Evas_Object *obj, void *event_info)
{
elm_win_lower(view_manager_get_win());
controller_name_input_back();
}
static Eina_Bool _validate_player_name(const char * player_name)
{
if(player_name == NULL || *player_name == '\0')
return false;
//TODO: extended validation
return true;
}
static void _text_entered(Evas_Object * entry)
{
elm_object_focus_set(entry, EINA_FALSE);
if (elm_entry_is_empty(entry)) {
elm_object_signal_emit(s_info.view_base.view, "player,name,invalidated", "");
return;
}
const char *player_name = elm_entry_entry_get(entry);
if (!_validate_player_name(player_name)) {
//TODO: serve incorrect player_name
elm_object_signal_emit(s_info.view_base.view, "player,name,invalidated", "");
return;
}
s_info.player_name = player_name;
elm_object_signal_emit(s_info.view_base.view, "player,name,validated", "");
}
static void _text_set_cb(void *data, Evas_Object *obj, void *event_info)
{
_text_entered(obj);
}
static void _keyboard_showed_cb(void *data, Evas_Object *obj, void *event_info)
{
elm_layout_signal_emit(s_info.view_base.view, "player,name,invalidated", "");
elm_layout_signal_emit(s_info.view_base.view, "entry,active", "entry");
}
static void _keyboard_hidden_cb(void *data, Evas_Object *obj, void *event_info)
{
if (elm_entry_is_empty((Evas_Object*)data)) {
elm_layout_signal_emit(s_info.view_base.view, "entry,inactive", "entry");
}
_text_entered((Evas_Object*)data);
}
static void _destroy_and_save()
{
controller_player_name_set(s_info.player_name);
evas_object_smart_callback_del(view_manager_get_conform(), "virtualkeypad,state,on", _keyboard_showed_cb);
evas_object_smart_callback_del(view_manager_get_conform(), "virtualkeypad,state,off", _keyboard_hidden_cb);
}
static void _ok_button_clicked_cb(void *data, Evas_Object *obj, void *event_info)
{
_destroy_and_save();
controller_name_input_next();
}
static void _view_name_input_create_gui(Evas_Object *parent)
{
s_info.view_base.view = view_base_create_layout(parent, "edje/view_name_input.edj", GRP_MAIN);
eext_object_event_callback_add(s_info.view_base.view, EEXT_CALLBACK_BACK, _layout_back_cb, NULL);
//Creating middle button
view_base_create_button(s_info.view_base.view, "button_middle", "Tap to enter text", NULL, "racing_middle", NULL, NULL);
//Creating entry for player's name
Evas_Object *entry = elm_entry_add(parent);
if (!entry) {
assert(!"Failed to create entry");
}
static Elm_Entry_Filter_Limit_Size limit_size = { .max_char_count = PLAYER_NAME_MAX_LEN, .max_byte_count = 0};
elm_entry_markup_filter_append(entry, elm_entry_filter_limit_size, &limit_size);
elm_entry_single_line_set(entry, EINA_TRUE);
elm_entry_text_style_user_push(entry, ENTRY_STYLE);
evas_object_smart_callback_add(view_manager_get_conform(), "virtualkeypad,state,on", _keyboard_showed_cb, entry);
evas_object_smart_callback_add(view_manager_get_conform(), "virtualkeypad,state,off", _keyboard_hidden_cb, entry);
evas_object_smart_callback_add(entry, "activated", _text_set_cb, NULL);
elm_layout_content_set(s_info.view_base.view, "entry_placeholder", entry);
//Creating confirm button
view_base_create_button(s_info.view_base.view, "button_ok", "OK", NULL, "racing_bottom",_ok_button_clicked_cb, NULL);
}
static void _show_cb(void)
{
controller_name_input_init(NULL);
}
static void _hide_cb(void)
{
controller_name_input_destroy();
}
s_view_base *view_name_input_init(Evas_Object *parent)
{
s_info.view_base.show_cb = _show_cb;
s_info.view_base.hide_cb = _hide_cb;
_view_name_input_create_gui(parent);
return &s_info.view_base;
}
|