Skip to content

Commit 0663220

Browse files
SapierSapier
Sapier
authored and
Sapier
committedDec 18, 2015
Android: Implement Autohiding button bars to cleanup screen
1 parent bde6194 commit 0663220

File tree

7 files changed

+504
-133
lines changed

7 files changed

+504
-133
lines changed
 

Diff for: ‎src/game.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -2173,7 +2173,7 @@ bool Game::initGui()
21732173
#ifdef HAVE_TOUCHSCREENGUI
21742174

21752175
if (g_touchscreengui)
2176-
g_touchscreengui->init(texture_src, porting::getDisplayDensity());
2176+
g_touchscreengui->init(texture_src);
21772177

21782178
#endif
21792179

@@ -2570,7 +2570,7 @@ void Game::processUserInput(VolatileRunFlags *flags,
25702570
|| guienv->hasFocus(gui_chat_console)) {
25712571
input->clear();
25722572
#ifdef HAVE_TOUCHSCREENGUI
2573-
g_touchscreengui->Hide();
2573+
g_touchscreengui->hide();
25742574
#endif
25752575
}
25762576
#ifdef HAVE_TOUCHSCREENGUI

Diff for: ‎src/modalMenu.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ class GUIModalMenu : public gui::IGUIElement
108108
this->remove();
109109
#ifdef HAVE_TOUCHSCREENGUI
110110
if (g_touchscreengui)
111-
g_touchscreengui->Show();
111+
g_touchscreengui->show();
112112
#endif
113113
}
114114

Diff for: ‎src/touchscreengui.cpp

+405-113
Large diffs are not rendered by default.

Diff for: ‎src/touchscreengui.h

+96-17
Original file line numberDiff line numberDiff line change
@@ -38,26 +38,105 @@ typedef enum {
3838
backward_id,
3939
left_id,
4040
right_id,
41-
inventory_id,
42-
drop_id,
4341
jump_id,
4442
crunch_id,
43+
after_last_element_id,
44+
settings_starter_id,
45+
rare_controls_starter_id,
4546
fly_id,
4647
noclip_id,
4748
fast_id,
4849
debug_id,
49-
chat_id,
5050
camera_id,
5151
range_id,
52-
after_last_element_id
52+
chat_id,
53+
inventory_id,
54+
drop_id
5355
} touch_gui_button_id;
5456

57+
typedef enum {
58+
AHBB_Dir_Top_Bottom,
59+
AHBB_Dir_Bottom_Top,
60+
AHBB_Dir_Left_Right,
61+
AHBB_Dir_Right_Left
62+
} autohide_button_bar_dir;
63+
5564
#define MIN_DIG_TIME_MS 500
5665
#define MAX_TOUCH_COUNT 64
5766
#define BUTTON_REPEAT_DELAY 0.2f
5867

68+
#define SETTINGS_BAR_Y_OFFSET 6.5
69+
#define RARE_CONTROLS_BAR_Y_OFFSET 4
70+
5971
extern const char** touchgui_button_imagenames;
6072

73+
struct button_info {
74+
float repeatcounter;
75+
float repeatdelay;
76+
irr::EKEY_CODE keycode;
77+
std::vector<int> ids;
78+
IGUIButton* guibutton;
79+
bool immediate_release;
80+
};
81+
82+
class AutoHideButtonBar
83+
{
84+
public:
85+
86+
AutoHideButtonBar( IrrlichtDevice *device, IEventReceiver* receiver );
87+
88+
void init(ISimpleTextureSource* tsrc, const char* starter_img,
89+
int button_id, v2s32 UpperLeft, v2s32 LowerRight,
90+
autohide_button_bar_dir dir, float timeout);
91+
92+
~AutoHideButtonBar();
93+
94+
/* add button to be shown */
95+
void addButton(touch_gui_button_id id, const wchar_t* caption,
96+
const char* btn_image);
97+
98+
/* detect settings bar button events */
99+
bool isButton(const SEvent &event);
100+
101+
/* handle released hud buttons */
102+
bool isReleaseButton(int eventID);
103+
104+
/* step handler */
105+
void step(float dtime);
106+
107+
/* deactivate button bar */
108+
void deactivate();
109+
110+
/* hide the whole buttonbar */
111+
void hide();
112+
113+
/* unhide the buttonbar */
114+
void show();
115+
116+
private:
117+
ISimpleTextureSource* m_texturesource;
118+
irr::video::IVideoDriver* m_driver;
119+
IGUIEnvironment* m_guienv;
120+
IEventReceiver* m_receiver;
121+
v2u32 m_screensize;
122+
button_info m_starter;
123+
std::vector<button_info*> m_buttons;
124+
125+
v2s32 m_upper_left;
126+
v2s32 m_lower_right;
127+
128+
/* show settings bar */
129+
bool m_active;
130+
131+
bool m_visible;
132+
133+
/* settings bar timeout */
134+
float m_timeout;
135+
float m_timeout_value;
136+
bool m_initialized;
137+
autohide_button_bar_dir m_dir;
138+
};
139+
61140
class TouchScreenGUI
62141
{
63142
public:
@@ -66,7 +145,7 @@ class TouchScreenGUI
66145

67146
void translateEvent(const SEvent &event);
68147

69-
void init(ISimpleTextureSource* tsrc,float density);
148+
void init(ISimpleTextureSource* tsrc);
70149

71150
double getYaw() { return m_camera_yaw; }
72151
double getPitch() { return m_camera_pitch; }
@@ -77,8 +156,8 @@ class TouchScreenGUI
77156
void registerHudItem(int index, const rect<s32> &rect);
78157
void Toggle(bool visible);
79158

80-
void Hide();
81-
void Show();
159+
void hide();
160+
void show();
82161

83162
private:
84163
IrrlichtDevice* m_device;
@@ -104,15 +183,6 @@ class TouchScreenGUI
104183
bool m_move_sent_as_mouse_event;
105184
v2s32 m_move_downlocation;
106185

107-
struct button_info {
108-
float repeatcounter;
109-
float repeatdelay;
110-
irr::EKEY_CODE keycode;
111-
std::vector<int> ids;
112-
IGUIButton* guibutton;
113-
bool immediate_release;
114-
};
115-
116186
button_info m_buttons[after_last_element_id];
117187

118188
/* gui button detection */
@@ -142,7 +212,7 @@ class TouchScreenGUI
142212
std::vector<id_status> m_known_ids;
143213

144214
/* handle a button event */
145-
void ButtonEvent(touch_gui_button_id bID, int eventID, bool action);
215+
void handleButtonEvent(touch_gui_button_id bID, int eventID, bool action);
146216

147217
/* handle pressed hud buttons */
148218
bool isHUDButton(const SEvent &event);
@@ -156,6 +226,9 @@ class TouchScreenGUI
156226
/* handle release event */
157227
void handleReleaseEvent(int evt_id);
158228

229+
/* get size of regular gui control button */
230+
int getGuiButtonSize();
231+
159232
/* doubleclick detection variables */
160233
struct key_event {
161234
unsigned int down_time;
@@ -168,6 +241,12 @@ class TouchScreenGUI
168241

169242
/* array for doubletap detection */
170243
key_event m_key_events[2];
244+
245+
/* settings bar */
246+
AutoHideButtonBar m_settingsbar;
247+
248+
/* rare controls bar */
249+
AutoHideButtonBar m_rarecontrolsbar;
171250
};
172251
extern TouchScreenGUI *g_touchscreengui;
173252
#endif

Diff for: ‎textures/base/pack/drop_btn.png

496 Bytes
Loading

Diff for: ‎textures/base/pack/gear_icon.png

1005 Bytes
Loading

Diff for: ‎textures/base/pack/rare_controls.png

349 Bytes
Loading

0 commit comments

Comments
 (0)
Please sign in to comment.