aboutsummaryrefslogtreecommitdiff
path: root/advtrains/models/advtrains_dtrack_vst31.obj
blob: c4cb84f54d72800b0466d1393102e4df5015f51a (plain)
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
# Blender v2.78 (sub 0) OBJ File: 'rail_redo.blend'
# www.blender.org
o dtrack_vst31_Cube.000
v 0.753760 -0.500000 -0.500000
v 0.753760 -0.500000 0.500000
v 0.753760 -0.166667 0.500000
v -0.753760 -0.500000 -0.500000
v -0.753760 -0.500000 0.500000
v -0.753760 -0.166667 0.500000
v 0.329165 -0.308041 0.171599
v 0.329165 -0.143980 0.171599
v 0.329165 -0.422440 -0.171599
v 0.329165 -0.258379 -0.171599
v 0.462280 -0.308041 0.171599
v 0.462280 -0.143980 0.171599
v 0.462280 -0.422440 -0.171599
v 0.462280 -0.258379 -0.171599
v 0.412289 -0.126667 0.500000
v 0.412289 -0.460000 -0.500000
v 0.560528 -0.460000 -0.500000
v 0.560528 -0.126667 0.500000
v 0.474055 -0.106667 0.500000
v 0.474055 -0.440000 -0.500000
v 0.498762 -0.440000 -0.500000
v 0.498762 -0.106667 0.500000
v 0.474055 -0.056667 0.500000
v 0.474055 -0.390000 -0.500000
v 0.498762 -0.390000 -0.500000
v 0.498762 -0.056667 0.500000
v 0.529645 -0.385000 -0.500000
v 0.529645 -0.051667 0.500000
v 0.443172 -0.051667 0.500000
v 0.443172 -0.385000 -0.500000
v 0.529645 -0.360000 -0.500000
v 0.529645 -0.026667 0.500000
v 0.443172 -0.026667 0.500000
v 0.443172 -0.360000 -0.500000
v 0.741194 -0.198333 0.435000
v -0.741194 -0.198333 0.435000
v -0.741194 -0.238333 0.315000
v 0.741194 -0.238333 0.315000
v 0.741193 -0.148333 0.435000
v -0.741194 -0.148333 0.435000
v -0.741194 -0.188333 0.315000
v 0.741194 -0.188333 0.315000
v -0.011733 2.712519 0.500000
v -0.011732 2.379186 -0.500001
v -0.011733 2.734147 0.500000
v -0.011732 2.400814 -0.500000
v 0.011732 2.379186 -0.500000
v 0.011732 2.712519 0.500000
v 0.011732 2.400814 -0.500000
v 0.011732 2.734148 0.500000
v -0.412289 -0.460000 -0.500000
v -0.412289 -0.126667 0.500000
v -0.560528 -0.126667 0.500000
v -0.560528 -0.460000 -0.500000
v -0.474055 -0.440000 -0.500000
v -0.474055 -0.106666 0.500000
v -0.498762 -0.106667 0.500000
v -0.498762 -0.440000 -0.500000
v -0.474055 -0.390000 -0.500000
v -0.474055 -0.056666 0.500000
v -0.498762 -0.056667 0.500000
v -0.498762 -0.390000 -0.500000
v -0.529645 -0.051667 0.500000
v -0.529645 -0.385000 -0.500000
v -0.443172 -0.385000 -0.500000
v -0.443172 -0.051666 0.500000
v -0.529645 -0.026667 0.500000
v -0.529645 -0.360000 -0.500000
v -0.443172 -0.360000 -0.500000
v -0.443172 -0.026666 0.500000
v -0.741194 -0.488333 -0.435000
v 0.741194 -0.488333 -0.435000
v 0.741194 -0.448333 -0.315000
v -0.741194 -0.448333 -0.315000
v -0.741193 -0.438333 -0.435000
v 0.741194 -0.438333 -0.435000
v 0.741194 -0.398333 -0.315000
v -0.741194 -0.398333 -0.315000
v 0.741194 -0.280713 0.187862
v -0.741194 -0.280713 0.187862
v -0.741194 -0.320713 0.067862
v 0.741194 -0.320713 0.067862
v 0.741193 -0.230713 0.187862
v -0.741194 -0.230713 0.187862
v -0.741194 -0.270713 0.067862
v 0.741194 -0.270713 0.067862
v -0.741194 -0.405954 -0.187862
v 0.741194 -0.405954 -0.187862
v 0.741194 -0.365954 -0.067862
v -0.741194 -0.365954 -0.067862
v -0.741193 -0.355954 -0.187862
v 0.741194 -0.355954 -0.187862
v 0.741194 -0.315954 -0.067862
v -0.741194 -0.315954 -0.067862
v -0.329165 -0.308041 0.171599
v -0.329165 -0.143980 0.171599
v -0.329165 -0.422440 -0.171599
v -0.329165 -0.258379 -0.171599
v -0.462280 -0.308041 0.171599
v -0.462280 -0.143980 0.171599
v -0.462280 -0.422440 -0.171599
v -0.462280 -0.258379 -0.171599
vt 0.7427 0.1169
vt 0.7427 0.3317
vt 0.6400 0.3317
vt 0.6400 0.1169
vt 0.8260 0.3317
vt 0.8260 0.4343
vt 0.7427 0.4343
vt 0.8260 0.1169
vt 0.7427 0.0142
vt 0.8260 0.0142
vt 0.5691 0.2971
vt 0.5691 0.9229
vt 0.5378 0.9229
vt 0.5378 0.2971
vt 0.3413 0.2971
vt 0.3819 0.2971
vt 0.3819 0.9229
vt 0.3413 0.9229
vt 0.4291 0.9855
vt 0.4678 0.9730
vt 0.4833 0.9730
vt 0.5219 0.9855
vt 0.6097 0.9229
vt 0.6097 0.2971
vt 0.4678 0.2470
vt 0.4291 0.2345
vt 0.5219 0.2345
vt 0.4833 0.2470
vt 0.4833 0.2783
vt 0.4678 0.2783
vt 0.4132 0.2971
vt 0.4132 0.9229
vt 0.4678 0.9417
vt 0.4833 0.9417
vt 0.5182 0.9229
vt 0.5182 0.2971
vt 0.4328 0.2971
vt 0.4328 0.9229
vt 0.5026 0.9229
vt 0.5026 0.2971
vt 0.4485 0.2971
vt 0.4485 0.9229
vt 0.5026 0.2814
vt 0.4485 0.2814
vt 0.4485 0.9386
vt 0.5026 0.9386
vt 0.9588 0.9625
vt 0.8837 0.9625
vt 0.8837 0.0348
vt 0.9588 0.0348
vt 0.9901 0.9625
vt 0.9901 0.0348
vt 0.9588 0.0035
vt 0.8837 0.0035
vt 0.8524 0.0348
vt 0.8524 0.9625
vt 0.9588 0.9938
vt 0.8837 0.9938
vt 0.6554 0.3627
vt 0.6690 0.3627
vt 0.6690 0.9885
vt 0.6554 0.9885
vt 0.6972 0.9885
vt 0.6837 0.9885
vt 0.6837 0.3627
vt 0.6972 0.3627
vt 0.7119 0.3627
vt 0.7119 0.9885
vt 0.5691 0.2971
vt 0.5691 0.9229
vt 0.5378 0.9229
vt 0.5378 0.2971
vt 0.3413 0.2971
vt 0.3819 0.2971
vt 0.3819 0.9229
vt 0.3413 0.9229
vt 0.4291 0.9855
vt 0.4678 0.9730
vt 0.4833 0.9730
vt 0.5219 0.9855
vt 0.6097 0.9229
vt 0.6097 0.2971
vt 0.4678 0.2470
vt 0.4291 0.2345
vt 0.5219 0.2345
vt 0.4833 0.2470
vt 0.4833 0.2783
vt 0.4678 0.2783
vt 0.4132 0.2971
vt 0.4132 0.9229
vt 0.4678 0.9417
vt 0.4833 0.9417
vt 0.5182 0.9229
vt 0.5182 0.2971
vt 0.4328 0.2971
vt 0.4328 0.9229
vt 0.5026 0.9229
vt 0.5026 0.2971
vt 0.4485 0.2971
vt 0.4485 0.9229
vt 0.5026 0.2814
vt 0.4485 0.2814
vt 0.4485 0.9386
vt 0.5026 0.9386
vt 0.9588 0.9625
vt 0.8837 0.9625
vt 0.8837 0.0348
vt 0.9588 0.0348
vt 0.9901 0.9625
vt 0.9901 0.0348
vt 0.9588 0.0035
vt 0.8837 0.0035
vt 0.8524 0.0348
vt 0.8524 0.9625
vt 0.9588 0.9938
vt 0.8837 0.9938
vt 0.9588 0.9625
vt 0.8837 0.9625
vt 0.8837 0.0348
vt 0.9588 0.0348
vt 0.9901 0.9625
vt 0.9901 0.0348
vt 0.9588 0.0035
vt 0.8837 0.0035
vt 0.8524 0.0348
vt 0.8524 0.9625
vt 0.9588 0.9938
vt 0.8837 0.9938
vt 0.9588 0.9625
vt 0.8837 0.9625
vt 0.8837 0.0348
vt 0.9588 0.0348
vt 0.9901 0.9625
vt 0.9901 0.0348
vt 0.9588 0.0035
vt 0.8837 0.0035
vt 0.8524 0.0348
vt 0.8524 0.9625
vt 0.9588 0.9938
vt 0.8837 0.9938
vt 0.7427 0.1169
vt 0.6400 0.1169
vt 0.6400 0.3317
vt 0.7427 0.3317
vt 0.7427 0.4343
vt 0.8260 0.4343
vt 0.8260 0.3317
vt 0.8260 0.1169
vt 0.8260 0.0142
vt 0.7427 0.0142
vt 1.1949 -0.0470
vt -0.3152 -0.0470
vt -0.3152 -0.3809
vt 1.1949 -0.3809
vt -0.3120 1.0015
vt -0.3120 -0.0002
vt 1.1981 -0.0002
vt 1.1981 1.0015
vt 1.1949 1.0089
vt 1.5117 0.0586
vt -0.3152 1.0089
vt -0.6320 0.0586
vn -1.0000 0.0000 -0.0000
vn 0.0000 0.0000 -1.0000
vn -0.0000 0.0000 1.0000
vn 0.0000 0.9487 -0.3162
vn 1.0000 0.0000 0.0000
vn -0.2936 0.9069 -0.3023
vn 0.2936 0.9069 -0.3023
vn 0.1518 -0.9377 0.3126
vn -0.1518 -0.9377 0.3126
vn 0.0000 -0.9487 0.3162
vn 0.0000 -1.0000 0.0000
g dtrack_vst31_Cube.000_SlopeRailMaterial
s off
f 8/1/1 10/2/1 9/3/1 7/4/1
f 10/2/2 14/5/2 13/6/2 9/7/2
f 12/8/3 8/1/3 7/9/3 11/10/3
f 12/8/4 14/5/4 10/2/4 8/1/4
f 22/11/5 21/12/5 25/13/5 26/14/5
f 15/15/6 19/16/6 20/17/6 16/18/6
f 16/19/2 20/20/2 21/21/2 17/22/2
f 17/23/7 21/12/7 22/11/7 18/24/7
f 19/25/3 15/26/3 18/27/3 22/28/3
f 26/29/3 23/30/3 19/25/3 22/28/3
f 19/16/1 23/31/1 24/32/1 20/17/1
f 21/21/2 20/20/2 24/33/2 25/34/2
f 26/14/8 25/13/8 27/35/8 28/36/8
f 24/32/9 23/31/9 29/37/9 30/38/9
f 28/36/5 27/35/5 31/39/5 32/40/5
f 30/38/1 29/37/1 33/41/1 34/42/1
f 31/39/4 34/42/4 33/41/4 32/40/4
f 23/30/3 26/29/3 28/43/3 32/40/3 33/41/3 29/44/3
f 24/33/2 30/45/2 34/42/2 31/39/2 27/46/2 25/34/2
f 39/47/4 42/48/4 41/49/4 40/50/4
f 35/51/3 39/47/3 40/50/3 36/52/3
f 36/53/1 40/50/1 41/49/1 37/54/1
f 37/55/2 41/49/2 42/48/2 38/56/2
f 39/47/5 35/57/5 38/58/5 42/48/5
f 43/59/1 45/60/1 46/61/1 44/62/1
f 47/63/5 49/64/5 50/65/5 48/66/5
f 43/67/10 44/68/10 47/63/10 48/66/10
f 45/60/4 50/65/4 49/64/4 46/61/4
f 58/69/1 57/70/1 61/71/1 62/72/1
f 51/73/7 55/74/7 56/75/7 52/76/7
f 52/77/3 56/78/3 57/79/3 53/80/3
f 53/81/6 57/70/6 58/69/6 54/82/6
f 55/83/2 51/84/2 54/85/2 58/86/2
f 62/87/2 59/88/2 55/83/2 58/86/2
f 55/74/5 59/89/5 60/90/5 56/75/5
f 57/79/3 56/78/3 60/91/3 61/92/3
f 62/72/9 61/71/9 63/93/9 64/94/9
f 60/90/8 59/89/8 65/95/8 66/96/8
f 64/94/1 63/93/1 67/97/1 68/98/1
f 66/96/5 65/95/5 69/99/5 70/100/5
f 67/97/4 70/100/4 69/99/4 68/98/4
f 59/88/2 62/87/2 64/101/2 68/98/2 69/99/2 65/102/2
f 60/91/3 66/103/3 70/100/3 67/97/3 63/104/3 61/92/3
f 75/105/4 78/106/4 77/107/4 76/108/4
f 71/109/2 75/105/2 76/108/2 72/110/2
f 72/111/5 76/108/5 77/107/5 73/112/5
f 73/113/3 77/107/3 78/106/3 74/114/3
f 75/105/1 71/115/1 74/116/1 78/106/1
f 83/117/4 86/118/4 85/119/4 84/120/4
f 79/121/3 83/117/3 84/120/3 80/122/3
f 80/123/1 84/120/1 85/119/1 81/124/1
f 81/125/2 85/119/2 86/118/2 82/126/2
f 83/117/5 79/127/5 82/128/5 86/118/5
f 91/129/4 94/130/4 93/131/4 92/132/4
f 87/133/2 91/129/2 92/132/2 88/134/2
f 88/135/5 92/132/5 93/131/5 89/136/5
f 89/137/3 93/131/3 94/130/3 90/138/3
f 91/129/1 87/139/1 90/140/1 94/130/1
f 96/141/5 95/142/5 97/143/5 98/144/5
f 98/144/2 97/145/2 101/146/2 102/147/2
f 100/148/3 99/149/3 95/150/3 96/141/3
f 100/148/4 96/141/4 98/144/4 102/147/4
g dtrack_vst31_Cube.000_SlopeGravelMaterial
f 3/151/3 6/152/3 5/153/3 2/154/3
f 1/155/11 2/156/11 5/157/11 4/158/11
f 1/159/5 3/151/5 2/160/5
f 6/152/1 4/161/1 5/162/1
f 4/161/4 6/152/4 3/151/4 1/159/4
>643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089
/*
Copyright (C) 2014 sapier

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#include "touchscreengui.h"
#include "irrlichttypes.h"
#include "irr_v2d.h"
#include "log.h"
#include "keycode.h"
#include "settings.h"
#include "gettime.h"
#include "util/numeric.h"
#include "porting.h"
#include "guiscalingfilter.h"

#include <iostream>
#include <algorithm>

#include <ISceneCollisionManager.h>

// Very slow button repeat frequency (in seconds)
#define SLOW_BUTTON_REPEAT	(1.0f)

using namespace irr::core;

extern Settings *g_settings;

const char** touchgui_button_imagenames = (const char*[]) {
	"up_arrow.png",
	"down_arrow.png",
	"left_arrow.png",
	"right_arrow.png",
	"jump_btn.png",
	"down.png"
};

static irr::EKEY_CODE id2keycode(touch_gui_button_id id)
{
	std::string key = "";
	switch (id) {
		case forward_id:
			key = "forward";
			break;
		case left_id:
			key = "left";
			break;
		case right_id:
			key = "right";
			break;
		case backward_id:
			key = "backward";
			break;
		case inventory_id:
			key = "inventory";
			break;
		case drop_id:
			key = "drop";
			break;
		case jump_id:
			key = "jump";
			break;
		case crunch_id:
			key = "sneak";
			break;
		case fly_id:
			key = "freemove";
			break;
		case noclip_id:
			key = "noclip";
			break;
		case fast_id:
			key = "fastmove";
			break;
		case debug_id:
			key = "toggle_debug";
			break;
		case chat_id:
			key = "chat";
			break;
		case camera_id:
			key = "camera_mode";
			break;
		case range_id:
			key = "rangeselect";
			break;
	}
	assert(key != "");
	return keyname_to_keycode(g_settings->get("keymap_" + key).c_str());
}

TouchScreenGUI *g_touchscreengui;

static void load_button_texture(button_info* btn, const char* path,
		rect<s32> button_rect, ISimpleTextureSource* tsrc, video::IVideoDriver *driver)
{
	unsigned int tid;
	video::ITexture *texture = guiScalingImageButton(driver,
			tsrc->getTexture(path, &tid), button_rect.getWidth(),
			button_rect.getHeight());
	if (texture) {
		btn->guibutton->setUseAlphaChannel(true);
		if (g_settings->getBool("gui_scaling_filter")) {
			rect<s32> txr_rect = rect<s32>(0, 0, button_rect.getWidth(), button_rect.getHeight());
			btn->guibutton->setImage(texture, txr_rect);
			btn->guibutton->setPressedImage(texture, txr_rect);
			btn->guibutton->setScaleImage(false);
		} else {
			btn->guibutton->setImage(texture);
			btn->guibutton->setPressedImage(texture);
			btn->guibutton->setScaleImage(true);
		}
		btn->guibutton->setDrawBorder(false);
		btn->guibutton->setText(L"");
		}
}

AutoHideButtonBar::AutoHideButtonBar(IrrlichtDevice *device,
		IEventReceiver* receiver) :
			m_texturesource(NULL),
			m_driver(device->getVideoDriver()),
			m_guienv(device->getGUIEnvironment()),
			m_receiver(receiver),
			m_active(false),
			m_visible(true),
			m_timeout(0),
			m_timeout_value(3),
			m_initialized(false),
			m_dir(AHBB_Dir_Right_Left)
{
	m_screensize = device->getVideoDriver()->getScreenSize();

}

void AutoHideButtonBar::init(ISimpleTextureSource* tsrc,
		const char* starter_img, int button_id, v2s32 UpperLeft,
		v2s32 LowerRight, autohide_button_bar_dir dir, float timeout)
{
	m_texturesource = tsrc;

	m_upper_left = UpperLeft;
	m_lower_right = LowerRight;

	/* init settings bar */

	irr::core::rect<int> current_button = rect<s32>(UpperLeft.X, UpperLeft.Y,
			LowerRight.X, LowerRight.Y);

	m_starter.guibutton         = m_guienv->addButton(current_button, 0, button_id, L"", 0);
	m_starter.guibutton->grab();
	m_starter.repeatcounter     = -1;
	m_starter.keycode           = KEY_OEM_8; // use invalid keycode as it's not relevant
	m_starter.immediate_release = true;
	m_starter.ids.clear();

	load_button_texture(&m_starter, starter_img, current_button,
			m_texturesource, m_driver);

	m_dir = dir;
	m_timeout_value = timeout;

	m_initialized = true;
}

AutoHideButtonBar::~AutoHideButtonBar()
{
	m_starter.guibutton->setVisible(false);
	m_starter.guibutton->drop();
}

void AutoHideButtonBar::addButton(touch_gui_button_id button_id,
		const wchar_t* caption, const char* btn_image)
{

	if (!m_initialized) {
		errorstream << "AutoHideButtonBar::addButton not yet initialized!"
				<< std::endl;
		return;
	}
	int button_size = 0;

	if ((m_dir == AHBB_Dir_Top_Bottom) || (m_dir == AHBB_Dir_Bottom_Top)) {
		button_size = m_lower_right.X - m_upper_left.X;
	} else {
		button_size = m_lower_right.Y - m_upper_left.Y;
	}

	irr::core::rect<int> current_button;

	if ((m_dir == AHBB_Dir_Right_Left) || (m_dir == AHBB_Dir_Left_Right)) {

		int x_start = 0;
		int x_end = 0;

		if (m_dir == AHBB_Dir_Left_Right) {
			x_start = m_lower_right.X + (button_size * 1.25 * m_buttons.size())
					+ (button_size * 0.25);
			x_end = x_start + button_size;
		} else {
			x_end = m_upper_left.X - (button_size * 1.25 * m_buttons.size())
					- (button_size * 0.25);
			x_start = x_end - button_size;
		}

		current_button = rect<s32>(x_start, m_upper_left.Y, x_end,
				m_lower_right.Y);
	} else {
		int y_start = 0;
		int y_end = 0;

		if (m_dir == AHBB_Dir_Top_Bottom) {
			y_start = m_lower_right.X + (button_size * 1.25 * m_buttons.size())
					+ (button_size * 0.25);
			y_end = y_start + button_size;
		} else {
			y_end = m_upper_left.X - (button_size * 1.25 * m_buttons.size())
					- (button_size * 0.25);
			y_start = y_end - button_size;
		}

		current_button = rect<s32>(m_upper_left.X, y_start, m_lower_right.Y,
				y_end);
	}

	button_info* btn       = new button_info();
	btn->guibutton         = m_guienv->addButton(current_button, 0, button_id, caption, 0);
	btn->guibutton->grab();
	btn->guibutton->setVisible(false);
	btn->guibutton->setEnabled(false);
	btn->repeatcounter     = -1;
	btn->keycode           = id2keycode(button_id);
	btn->immediate_release = true;
	btn->ids.clear();

	load_button_texture(btn, btn_image, current_button, m_texturesource,
			m_driver);

	m_buttons.push_back(btn);
}

bool AutoHideButtonBar::isButton(const SEvent &event)
{
	IGUIElement* rootguielement = m_guienv->getRootGUIElement();

	if (rootguielement == NULL) {
		return false;
	}

	gui::IGUIElement *element = rootguielement->getElementFromPoint(
			core::position2d<s32>(event.TouchInput.X, event.TouchInput.Y));

	if (element == NULL) {
		return false;
	}

	if (m_active) {
		/* check for all buttons in vector */

		std::vector<button_info*>::iterator iter = m_buttons.begin();

		while (iter != m_buttons.end()) {
			if ((*iter)->guibutton == element) {

				SEvent* translated = new SEvent();
				memset(translated, 0, sizeof(SEvent));
				translated->EventType            = irr::EET_KEY_INPUT_EVENT;
				translated->KeyInput.Key         = (*iter)->keycode;
				translated->KeyInput.Control     = false;
				translated->KeyInput.Shift       = false;
				translated->KeyInput.Char        = 0;

				/* add this event */
				translated->KeyInput.PressedDown = true;
				m_receiver->OnEvent(*translated);

				/* remove this event */
				translated->KeyInput.PressedDown = false;
				m_receiver->OnEvent(*translated);

				delete translated;

				(*iter)->ids.push_back(event.TouchInput.ID);

				m_timeout = 0;

				return true;
			}
			++iter;
		}
	} else {
		/* check for starter button only */
		if (element == m_starter.guibutton) {
			m_starter.ids.push_back(event.TouchInput.ID);
			m_starter.guibutton->setVisible(false);
			m_starter.guibutton->setEnabled(false);
			m_active = true;
			m_timeout = 0;

			std::vector<button_info*>::iterator iter = m_buttons.begin();

			while (iter != m_buttons.end()) {
				(*iter)->guibutton->setVisible(true);
				(*iter)->guibutton->setEnabled(true);
				++iter;
			}

			return true;
		}
	}
	return false;
}

bool AutoHideButtonBar::isReleaseButton(int eventID)
{
	std::vector<int>::iterator id = std::find(m_starter.ids.begin(),
			m_starter.ids.end(), eventID);

	if (id != m_starter.ids.end()) {
		m_starter.ids.erase(id);
		return true;
	}

	std::vector<button_info*>::iterator iter = m_buttons.begin();

	while (iter != m_buttons.end()) {
		std::vector<int>::iterator id = std::find((*iter)->ids.begin(),
				(*iter)->ids.end(), eventID);

		if (id != (*iter)->ids.end()) {
			(*iter)->ids.erase(id);
			// TODO handle settings button release
			return true;
		}
		++iter;
	}

	return false;
}

void AutoHideButtonBar::step(float dtime)
{
	if (m_active) {
		m_timeout += dtime;

		if (m_timeout > m_timeout_value) {
			deactivate();
		}
	}
}

void AutoHideButtonBar::deactivate()
{
	if (m_visible == true) {
		m_starter.guibutton->setVisible(true);
		m_starter.guibutton->setEnabled(true);
	}
	m_active = false;

	std::vector<button_info*>::iterator iter = m_buttons.begin();

	while (iter != m_buttons.end()) {
			(*iter)->guibutton->setVisible(false);
			(*iter)->guibutton->setEnabled(false);
		++iter;
	}
}

void AutoHideButtonBar::hide()
{
	m_visible = false;
	m_starter.guibutton->setVisible(false);
	m_starter.guibutton->setEnabled(false);

	std::vector<button_info*>::iterator iter = m_buttons.begin();

	while (iter != m_buttons.end()) {
		(*iter)->guibutton->setVisible(false);
		(*iter)->guibutton->setEnabled(false);
		++iter;
	}
}

void AutoHideButtonBar::show()
{
	m_visible = true;

	if (m_active) {
		std::vector<button_info*>::iterator iter = m_buttons.begin();

		while (iter != m_buttons.end()) {
			(*iter)->guibutton->setVisible(true);
			(*iter)->guibutton->setEnabled(true);
			++iter;
		}
	} else {
		m_starter.guibutton->setVisible(true);
		m_starter.guibutton->setEnabled(true);
	}
}

TouchScreenGUI::TouchScreenGUI(IrrlichtDevice *device, IEventReceiver* receiver):
	m_device(device),
	m_guienv(device->getGUIEnvironment()),
	m_camera_yaw(0.0),
	m_camera_pitch(0.0),
	m_visible(false),
	m_move_id(-1),
	m_receiver(receiver),
	m_move_has_really_moved(false),
	m_move_downtime(0),
	m_move_sent_as_mouse_event(false),
	// use some downlocation way off screen as init value  to avoid invalid behaviour
	m_move_downlocation(v2s32(-10000, -10000)),
	m_settingsbar(device, receiver),
	m_rarecontrolsbar(device, receiver)
{
	for (unsigned int i=0; i < after_last_element_id; i++) {
		m_buttons[i].guibutton     =  0;
		m_buttons[i].repeatcounter = -1;
		m_buttons[i].repeatdelay   = BUTTON_REPEAT_DELAY;
	}

	m_screensize = m_device->getVideoDriver()->getScreenSize();
}

void TouchScreenGUI::initButton(touch_gui_button_id id, rect<s32> button_rect,
		std::wstring caption, bool immediate_release, float repeat_delay)
{

	button_info* btn       = &m_buttons[id];
	btn->guibutton         = m_guienv->addButton(button_rect, 0, id, caption.c_str());
	btn->guibutton->grab();
	btn->repeatcounter     = -1;
	btn->repeatdelay       = repeat_delay;
	btn->keycode           = id2keycode(id);
	btn->immediate_release = immediate_release;
	btn->ids.clear();

	load_button_texture(btn,touchgui_button_imagenames[id],button_rect,
			m_texturesource, m_device->getVideoDriver());
}

static int getMaxControlPadSize(float density) {
	return 200 * density * g_settings->getFloat("hud_scaling");
}

int TouchScreenGUI::getGuiButtonSize()
{
	u32 control_pad_size = MYMIN((2 * m_screensize.Y) / 3,
			getMaxControlPadSize(porting::getDisplayDensity()));

	return control_pad_size / 3;
}

void TouchScreenGUI::init(ISimpleTextureSource* tsrc)
{
	assert(tsrc != 0);

	u32 button_size      = getGuiButtonSize();
	m_visible            = true;
	m_texturesource      = tsrc;
	m_control_pad_rect   = rect<s32>(0, m_screensize.Y - 3 * button_size,
			3 * button_size, m_screensize.Y);
	/*
	draw control pad
	0 1 2
	3 4 5
	for now only 0, 1, 2, and 4 are used
	*/
	int number = 0;
	for (int y = 0; y < 2; ++y)
		for (int x = 0; x < 3; ++x, ++number) {
			rect<s32> button_rect(
					x * button_size, m_screensize.Y - button_size * (2 - y),
					(x + 1) * button_size, m_screensize.Y - button_size * (1 - y)
			);
			touch_gui_button_id id = after_last_element_id;
			std::wstring caption;
			switch (number) {
			case 0:
				id = left_id;
				caption = L"<";
				break;
			case 1:
				id = forward_id;
				caption = L"^";
				break;
			case 2:
				id = right_id;
				caption = L">";
				break;
			case 4:
				id = backward_id;
				caption = L"v";
				break;
			}
			if (id != after_last_element_id) {
				initButton(id, button_rect, caption, false);
				}
		}

	/* init jump button */
	initButton(jump_id,
			rect<s32>(m_screensize.X-(1.75*button_size),
					m_screensize.Y - (0.5*button_size),
					m_screensize.X-(0.25*button_size),
					m_screensize.Y),
			L"x",false);

	/* init crunch button */
	initButton(crunch_id,
			rect<s32>(m_screensize.X-(3.25*button_size),
					m_screensize.Y - (0.5*button_size),
					m_screensize.X-(1.75*button_size),
					m_screensize.Y),
			L"H",false);

	m_settingsbar.init(m_texturesource, "gear_icon.png", settings_starter_id,
			v2s32(m_screensize.X - (button_size / 2),
					m_screensize.Y - ((SETTINGS_BAR_Y_OFFSET + 1) * button_size)
							+ (button_size * 0.5)),
			v2s32(m_screensize.X,
					m_screensize.Y - (SETTINGS_BAR_Y_OFFSET * button_size)
							+ (button_size * 0.5)), AHBB_Dir_Right_Left,
			3.0);

	m_settingsbar.addButton(fly_id,    L"fly",       "fly_btn.png");
	m_settingsbar.addButton(noclip_id, L"noclip",    "noclip_btn.png");
	m_settingsbar.addButton(fast_id,   L"fast",      "fast_btn.png");
	m_settingsbar.addButton(debug_id,  L"debug",     "debug_btn.png");
	m_settingsbar.addButton(camera_id, L"camera",    "camera_btn.png");
	m_settingsbar.addButton(range_id,  L"rangeview", "rangeview_btn.png");

	m_rarecontrolsbar.init(m_texturesource, "rare_controls.png",
			rare_controls_starter_id,
			v2s32(0,
					m_screensize.Y
							- ((RARE_CONTROLS_BAR_Y_OFFSET + 1) * button_size)
							+ (button_size * 0.5)),
			v2s32(button_size / 2,
					m_screensize.Y - (RARE_CONTROLS_BAR_Y_OFFSET * button_size)
							+ (button_size * 0.5)), AHBB_Dir_Left_Right,
			2);

	m_rarecontrolsbar.addButton(chat_id,      L"Chat", "chat_btn.png");
	m_rarecontrolsbar.addButton(inventory_id, L"inv",  "inventory_btn.png");
	m_rarecontrolsbar.addButton(drop_id,      L"drop", "drop_btn.png");

}

touch_gui_button_id TouchScreenGUI::getButtonID(s32 x, s32 y)
{
	IGUIElement* rootguielement = m_guienv->getRootGUIElement();

	if (rootguielement != NULL) {
		gui::IGUIElement *element =
				rootguielement->getElementFromPoint(core::position2d<s32>(x,y));

		if (element) {
			for (unsigned int i=0; i < after_last_element_id; i++) {
				if (element == m_buttons[i].guibutton) {
					return (touch_gui_button_id) i;
				}
			}
		}
	}
	return after_last_element_id;
}

touch_gui_button_id TouchScreenGUI::getButtonID(int eventID)
{
	for (unsigned int i=0; i < after_last_element_id; i++) {
		button_info* btn = &m_buttons[i];

		std::vector<int>::iterator id =
				std::find(btn->ids.begin(),btn->ids.end(), eventID);

		if (id != btn->ids.end())
			return (touch_gui_button_id) i;
	}

	return after_last_element_id;
}

bool TouchScreenGUI::isHUDButton(const SEvent &event)
{
	// check if hud item is pressed
	for (std::map<int,rect<s32> >::iterator iter = m_hud_rects.begin();
			iter != m_hud_rects.end(); ++iter) {
		if (iter->second.isPointInside(
				v2s32(event.TouchInput.X,
						event.TouchInput.Y)
			)) {
			if ( iter->first < 8) {
				SEvent* translated = new SEvent();
				memset(translated,0,sizeof(SEvent));
				translated->EventType = irr::EET_KEY_INPUT_EVENT;
				translated->KeyInput.Key         = (irr::EKEY_CODE) (KEY_KEY_1 + iter->first);
				translated->KeyInput.Control     = false;
				translated->KeyInput.Shift       = false;
				translated->KeyInput.PressedDown = true;
				m_receiver->OnEvent(*translated);
				m_hud_ids[event.TouchInput.ID]   = translated->KeyInput.Key;
				delete translated;
				return true;
			}
		}
	}
	return false;
}

bool TouchScreenGUI::isReleaseHUDButton(int eventID)
{
	std::map<int,irr::EKEY_CODE>::iterator iter = m_hud_ids.find(eventID);

	if (iter != m_hud_ids.end()) {
		SEvent* translated = new SEvent();
		memset(translated,0,sizeof(SEvent));
		translated->EventType            = irr::EET_KEY_INPUT_EVENT;
		translated->KeyInput.Key         = iter->second;
		translated->KeyInput.PressedDown = false;
		translated->KeyInput.Control     = false;
		translated->KeyInput.Shift       = false;
		m_receiver->OnEvent(*translated);
		m_hud_ids.erase(iter);
		delete translated;
		return true;
	}
	return false;
}

void TouchScreenGUI::handleButtonEvent(touch_gui_button_id button,
		int eventID, bool action)
{
	button_info* btn = &m_buttons[button];
	SEvent* translated = new SEvent();
	memset(translated,0,sizeof(SEvent));
	translated->EventType            = irr::EET_KEY_INPUT_EVENT;
	translated->KeyInput.Key         = btn->keycode;
	translated->KeyInput.Control     = false;
	translated->KeyInput.Shift       = false;
	translated->KeyInput.Char        = 0;

	/* add this event */
	if (action) {
		assert(std::find(btn->ids.begin(),btn->ids.end(), eventID) == btn->ids.end());

		btn->ids.push_back(eventID);

		if (btn->ids.size() > 1) return;

		btn->repeatcounter = 0;
		translated->KeyInput.PressedDown = true;
		translated->KeyInput.Key = btn->keycode;
		m_receiver->OnEvent(*translated);
	}
	/* remove event */
	if ((!action) || (btn->immediate_release)) {

		std::vector<int>::iterator pos =
				std::find(btn->ids.begin(),btn->ids.end(), eventID);
		/* has to be in touch list */
		assert(pos != btn->ids.end());
		btn->ids.erase(pos);

		if (btn->ids.size() > 0)  { return; }

		translated->KeyInput.PressedDown = false;
		btn->repeatcounter               = -1;
		m_receiver->OnEvent(*translated);
	}
	delete translated;
}


void TouchScreenGUI::handleReleaseEvent(int evt_id)
{
	touch_gui_button_id button = getButtonID(evt_id);

	/* handle button events */
	if (button != after_last_element_id) {
		handleButtonEvent(button, evt_id, false);
	}
	/* handle hud button events */
	else if (isReleaseHUDButton(evt_id)) {
		/* nothing to do here */
	} else if (m_settingsbar.isReleaseButton(evt_id)) {
		/* nothing to do here */
	} else if (m_rarecontrolsbar.isReleaseButton(evt_id)) {
		/* nothing to do here */
	}
	/* handle the point used for moving view */
	else if (evt_id == m_move_id) {
		m_move_id = -1;

		/* if this pointer issued a mouse event issue symmetric release here */
		if (m_move_sent_as_mouse_event) {
			SEvent* translated = new SEvent;
			memset(translated,0,sizeof(SEvent));
			translated->EventType               = EET_MOUSE_INPUT_EVENT;
			translated->MouseInput.X            = m_move_downlocation.X;
			translated->MouseInput.Y            = m_move_downlocation.Y;
			translated->MouseInput.Shift        = false;
			translated->MouseInput.Control      = false;
			translated->MouseInput.ButtonStates = 0;
			translated->MouseInput.Event        = EMIE_LMOUSE_LEFT_UP;
			m_receiver->OnEvent(*translated);
			delete translated;
		}
		else {
			/* do double tap detection */
			doubleTapDetection();
		}
	}
	else {
		infostream
			<< "TouchScreenGUI::translateEvent released unknown button: "
			<< evt_id << std::endl;
	}

	for (std::vector<id_status>::iterator iter = m_known_ids.begin();
			iter != m_known_ids.end(); ++iter) {
		if (iter->id == evt_id) {
			m_known_ids.erase(iter);
			break;
		}
	}
}

void TouchScreenGUI::translateEvent(const SEvent &event)
{
	if (!m_visible) {
		infostream << "TouchScreenGUI::translateEvent got event but not visible?!" << std::endl;
		return;
	}

	if (event.EventType != EET_TOUCH_INPUT_EVENT) {
		return;
	}

	if (event.TouchInput.Event == ETIE_PRESSED_DOWN) {

		/* add to own copy of eventlist ...
		 * android would provide this information but irrlicht guys don't
		 * wanna design a efficient interface
		 */
		id_status toadd;
		toadd.id = event.TouchInput.ID;
		toadd.X  = event.TouchInput.X;
		toadd.Y  = event.TouchInput.Y;
		m_known_ids.push_back(toadd);

		int eventID = event.TouchInput.ID;

		touch_gui_button_id button =
				getButtonID(event.TouchInput.X, event.TouchInput.Y);

		/* handle button events */
		if (button != after_last_element_id) {
			handleButtonEvent(button, eventID, true);
			m_settingsbar.deactivate();
			m_rarecontrolsbar.deactivate();
		} else if (isHUDButton(event)) {
			m_settingsbar.deactivate();
			m_rarecontrolsbar.deactivate();
			/* already handled in isHUDButton() */
		} else if (m_settingsbar.isButton(event)) {
			m_rarecontrolsbar.deactivate();
			/* already handled in isSettingsBarButton() */
		} else if (m_rarecontrolsbar.isButton(event)) {
			m_settingsbar.deactivate();
			/* already handled in isSettingsBarButton() */
		}
		/* handle non button events */
		else {
			m_settingsbar.deactivate();
			m_rarecontrolsbar.deactivate();
			/* if we don't already have a moving point make this the moving one */
			if (m_move_id == -1) {
				m_move_id                  = event.TouchInput.ID;
				m_move_has_really_moved    = false;
				m_move_downtime            = getTimeMs();
				m_move_downlocation        = v2s32(event.TouchInput.X, event.TouchInput.Y);
				m_move_sent_as_mouse_event = false;
			}
		}

		m_pointerpos[event.TouchInput.ID] = v2s32(event.TouchInput.X, event.TouchInput.Y);
	}
	else if (event.TouchInput.Event == ETIE_LEFT_UP) {
		verbosestream << "Up event for pointerid: " << event.TouchInput.ID << std::endl;
		handleReleaseEvent(event.TouchInput.ID);
	}
	else {
		assert(event.TouchInput.Event == ETIE_MOVED);
		int move_idx = event.TouchInput.ID;

		if (m_pointerpos[event.TouchInput.ID] ==
				v2s32(event.TouchInput.X, event.TouchInput.Y)) {
			return;
		}

		if (m_move_id != -1) {
			if ((event.TouchInput.ID == m_move_id) &&
				(!m_move_sent_as_mouse_event)) {

				double distance = sqrt(
						(m_pointerpos[event.TouchInput.ID].X - event.TouchInput.X) *
						(m_pointerpos[event.TouchInput.ID].X - event.TouchInput.X) +
						(m_pointerpos[event.TouchInput.ID].Y - event.TouchInput.Y) *
						(m_pointerpos[event.TouchInput.ID].Y - event.TouchInput.Y));

				if ((distance > g_settings->getU16("touchscreen_threshold")) ||
						(m_move_has_really_moved)) {
					m_move_has_really_moved = true;
					s32 X = event.TouchInput.X;
					s32 Y = event.TouchInput.Y;

					// update camera_yaw and camera_pitch
					s32 dx = X - m_pointerpos[event.TouchInput.ID].X;
					s32 dy = Y - m_pointerpos[event.TouchInput.ID].Y;

					/* adapt to similar behaviour as pc screen */
					double d         = g_settings->getFloat("mouse_sensitivity") *4;
					double old_yaw   = m_camera_yaw;
					double old_pitch = m_camera_pitch;

					m_camera_yaw   -= dx * d;
					m_camera_pitch  = MYMIN(MYMAX( m_camera_pitch + (dy * d),-180),180);

					while (m_camera_yaw < 0)
						m_camera_yaw += 360;

					while (m_camera_yaw > 360)
						m_camera_yaw -= 360;

					// update shootline
					m_shootline = m_device
							->getSceneManager()
							->getSceneCollisionManager()
							->getRayFromScreenCoordinates(v2s32(X, Y));
					m_pointerpos[event.TouchInput.ID] = v2s32(X, Y);
				}
			}
			else if ((event.TouchInput.ID == m_move_id) &&
					(m_move_sent_as_mouse_event)) {
				m_shootline = m_device
						->getSceneManager()
						->getSceneCollisionManager()
						->getRayFromScreenCoordinates(