Check-in [95ff35491e]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Native activity replacement continues
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 95ff35491eae84af1350be30c8b40d7d2b137eb0
User & Date: bernd 2014-01-18 23:27:17
Context
2014-01-19
13:50
Name conflict solved check-in: 8e7b012cfe user: bernd tags: trunk
2014-01-18
23:27
Native activity replacement continues check-in: 95ff35491e user: bernd tags: trunk
2014-01-17
23:42
Rewritten for own native activity implementation - works\! check-in: 9a2d8e9dac user: bernd tags: trunk
Changes

Changes to gl-sample.fs.

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

:noname new-config on ; is config-changed
[THEN]

FVariable touch -100e touch f!
FVariable motion 0.01e motion f!

: draw-tri { f: angle -- angle' }
    new-config @ IF
	dpy-w @ dpy-h @ getwh dpy-w @ dpy-h @ d<> IF  new-config off  THEN
    THEN
    ntime
    0.01e 0.02e 0.15e 1.0e glClearColor
    clear
    Ambient 1 ambient% glUniform1fv
    v0  angle set-triangle
    normals texcoords colors
    none-tex
    i0  0 i, 1 i, 2 i,
    GL_TRIANGLES draw-elements
    v0 colors'
    ascii-tex
    GL_TRIANGLES draw-elements
    sync
    2drop \ ntime d- dnegate ." Frame time: " d. cr






    >looper
    *input >r r@ IF
	r@ pressure @ 0> IF

	    \ ." Touch at " r@ x0 ? r@ y0 ? cr
	    \ r@ x0 @ 20 < r@ y0 @ 20 < and IF -1 (bye) THEN
	    r@ x0 @ dpy-w @ 2/ - s>f dpy-h @ 2/ fm/
	    r@ y0 @ dpy-h @ 2/ - s>f dpy-h @ 2/ fm/
	    fover fover fnegate -0.15e lightpos glUniform3f
	    fatan2
	    touch f@ -100e f= IF
		angle f- touch f!
	    ELSE
		touch f@ f-
		fdup angle f-
		fdup pi f> IF  pi f2* f-  THEN







|
<
<
<
<



|







|
<
>
>
>
>
>
>


<
>




|







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

:noname new-config on ; is config-changed
[THEN]

FVariable touch -100e touch f!
FVariable motion 0.01e motion f!

: draw-tri-angle ( f -- )




    0.01e 0.02e 0.15e 1.0e glClearColor
    clear
    Ambient 1 ambient% glUniform1fv
    v0  set-triangle
    normals texcoords colors
    none-tex
    i0  0 i, 1 i, 2 i,
    GL_TRIANGLES draw-elements
    v0 colors'
    ascii-tex
    GL_TRIANGLES draw-elements
    sync ;


: draw-tri { f: angle -- angle' }
    new-config @ IF
	dpy-w @ dpy-h @ getwh dpy-w @ dpy-h @ d<> IF  new-config off  THEN
    THEN
    angle draw-tri-angle
    >looper
    *input >r r@ IF

	r@ action @ abs 1 <> IF
	    \ ." Touch at " r@ x0 ? r@ y0 ? cr
	    \ r@ x0 @ 20 < r@ y0 @ 20 < and IF -1 (bye) THEN
	    r@ x0 @ dpy-w @ 2/ - s>f dpy-h @ 2/ fm/
	    r@ y0 @ dpy-h @ 2/ - s>f dpy-h @ 2/ fm/
	    fover fover fnegate -1.15e lightpos glUniform3f
	    fatan2
	    touch f@ -100e f= IF
		angle f- touch f!
	    ELSE
		touch f@ f-
		fdup angle f-
		fdup pi f> IF  pi f2* f-  THEN

Added gles2/android-window.fs.



















































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
\ This file has been generated using SWIG and fsi,
\ and is already platform dependent, search for the corresponding
\ fsi-file to compile it where no one has compiled it before ;)
\ GForth has its own dynamic loader and doesn't need addional C-Code.
\ That's why this file contains normal Gforth-code( version 0.6.9 or higher )
\ and could be used directly with include or require.
\ As all comments are stripped during the compilation, please
\ insert the copyright notice of the original file here.

\ ----===< int constants ===>-----
8	constant AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT

\ --------===< enums >===---------
-1	constant AKEY_STATE_UNKNOWN
0	constant AKEY_STATE_UP
1	constant AKEY_STATE_DOWN
2	constant AKEY_STATE_VIRTUAL
0	constant AMETA_NONE
2	constant AMETA_ALT_ON
16	constant AMETA_ALT_LEFT_ON
32	constant AMETA_ALT_RIGHT_ON
1	constant AMETA_SHIFT_ON
64	constant AMETA_SHIFT_LEFT_ON
128	constant AMETA_SHIFT_RIGHT_ON
4	constant AMETA_SYM_ON
1	constant AINPUT_EVENT_TYPE_KEY
2	constant AINPUT_EVENT_TYPE_MOTION
0	constant AKEY_EVENT_ACTION_DOWN
1	constant AKEY_EVENT_ACTION_UP
2	constant AKEY_EVENT_ACTION_MULTIPLE
1	constant AKEY_EVENT_FLAG_WOKE_HERE
2	constant AKEY_EVENT_FLAG_SOFT_KEYBOARD
4	constant AKEY_EVENT_FLAG_KEEP_TOUCH_MODE
8	constant AKEY_EVENT_FLAG_FROM_SYSTEM
16	constant AKEY_EVENT_FLAG_EDITOR_ACTION
32	constant AKEY_EVENT_FLAG_CANCELED
64	constant AKEY_EVENT_FLAG_VIRTUAL_HARD_KEY
128	constant AKEY_EVENT_FLAG_LONG_PRESS
256	constant AKEY_EVENT_FLAG_CANCELED_LONG_PRESS
512	constant AKEY_EVENT_FLAG_TRACKING
255	constant AMOTION_EVENT_ACTION_MASK
65280	constant AMOTION_EVENT_ACTION_POINTER_INDEX_MASK
0	constant AMOTION_EVENT_ACTION_DOWN
1	constant AMOTION_EVENT_ACTION_UP
2	constant AMOTION_EVENT_ACTION_MOVE
3	constant AMOTION_EVENT_ACTION_CANCEL
4	constant AMOTION_EVENT_ACTION_OUTSIDE
5	constant AMOTION_EVENT_ACTION_POINTER_DOWN
6	constant AMOTION_EVENT_ACTION_POINTER_UP
1	constant AMOTION_EVENT_FLAG_WINDOW_IS_OBSCURED
0	constant AMOTION_EVENT_EDGE_FLAG_NONE
1	constant AMOTION_EVENT_EDGE_FLAG_TOP
2	constant AMOTION_EVENT_EDGE_FLAG_BOTTOM
4	constant AMOTION_EVENT_EDGE_FLAG_LEFT
8	constant AMOTION_EVENT_EDGE_FLAG_RIGHT
255	constant AINPUT_SOURCE_CLASS_MASK
1	constant AINPUT_SOURCE_CLASS_BUTTON
2	constant AINPUT_SOURCE_CLASS_POINTER
4	constant AINPUT_SOURCE_CLASS_NAVIGATION
8	constant AINPUT_SOURCE_CLASS_POSITION
0	constant AINPUT_SOURCE_UNKNOWN
257	constant AINPUT_SOURCE_KEYBOARD
513	constant AINPUT_SOURCE_DPAD
4098	constant AINPUT_SOURCE_TOUCHSCREEN
8194	constant AINPUT_SOURCE_MOUSE
65540	constant AINPUT_SOURCE_TRACKBALL
1048584	constant AINPUT_SOURCE_TOUCHPAD
-256	constant AINPUT_SOURCE_ANY
0	constant AINPUT_KEYBOARD_TYPE_NONE
1	constant AINPUT_KEYBOARD_TYPE_NON_ALPHABETIC
2	constant AINPUT_KEYBOARD_TYPE_ALPHABETIC
0	constant AINPUT_MOTION_RANGE_X
1	constant AINPUT_MOTION_RANGE_Y
2	constant AINPUT_MOTION_RANGE_PRESSURE
3	constant AINPUT_MOTION_RANGE_SIZE
4	constant AINPUT_MOTION_RANGE_TOUCH_MAJOR
5	constant AINPUT_MOTION_RANGE_TOUCH_MINOR
6	constant AINPUT_MOTION_RANGE_TOOL_MAJOR
7	constant AINPUT_MOTION_RANGE_TOOL_MINOR
8	constant AINPUT_MOTION_RANGE_ORIENTATION
0	constant AKEYCODE_UNKNOWN
1	constant AKEYCODE_SOFT_LEFT
2	constant AKEYCODE_SOFT_RIGHT
3	constant AKEYCODE_HOME
4	constant AKEYCODE_BACK
5	constant AKEYCODE_CALL
6	constant AKEYCODE_ENDCALL
7	constant AKEYCODE_0
8	constant AKEYCODE_1
9	constant AKEYCODE_2
10	constant AKEYCODE_3
11	constant AKEYCODE_4
12	constant AKEYCODE_5
13	constant AKEYCODE_6
14	constant AKEYCODE_7
15	constant AKEYCODE_8
16	constant AKEYCODE_9
17	constant AKEYCODE_STAR
18	constant AKEYCODE_POUND
19	constant AKEYCODE_DPAD_UP
20	constant AKEYCODE_DPAD_DOWN
21	constant AKEYCODE_DPAD_LEFT
22	constant AKEYCODE_DPAD_RIGHT
23	constant AKEYCODE_DPAD_CENTER
24	constant AKEYCODE_VOLUME_UP
25	constant AKEYCODE_VOLUME_DOWN
26	constant AKEYCODE_POWER
27	constant AKEYCODE_CAMERA
28	constant AKEYCODE_CLEAR
29	constant AKEYCODE_A
30	constant AKEYCODE_B
31	constant AKEYCODE_C
32	constant AKEYCODE_D
33	constant AKEYCODE_E
34	constant AKEYCODE_F
35	constant AKEYCODE_G
36	constant AKEYCODE_H
37	constant AKEYCODE_I
38	constant AKEYCODE_J
39	constant AKEYCODE_K
40	constant AKEYCODE_L
41	constant AKEYCODE_M
42	constant AKEYCODE_N
43	constant AKEYCODE_O
44	constant AKEYCODE_P
45	constant AKEYCODE_Q
46	constant AKEYCODE_R
47	constant AKEYCODE_S
48	constant AKEYCODE_T
49	constant AKEYCODE_U
50	constant AKEYCODE_V
51	constant AKEYCODE_W
52	constant AKEYCODE_X
53	constant AKEYCODE_Y
54	constant AKEYCODE_Z
55	constant AKEYCODE_COMMA
56	constant AKEYCODE_PERIOD
57	constant AKEYCODE_ALT_LEFT
58	constant AKEYCODE_ALT_RIGHT
59	constant AKEYCODE_SHIFT_LEFT
60	constant AKEYCODE_SHIFT_RIGHT
61	constant AKEYCODE_TAB
62	constant AKEYCODE_SPACE
63	constant AKEYCODE_SYM
64	constant AKEYCODE_EXPLORER
65	constant AKEYCODE_ENVELOPE
66	constant AKEYCODE_ENTER
67	constant AKEYCODE_DEL
68	constant AKEYCODE_GRAVE
69	constant AKEYCODE_MINUS
70	constant AKEYCODE_EQUALS
71	constant AKEYCODE_LEFT_BRACKET
72	constant AKEYCODE_RIGHT_BRACKET
73	constant AKEYCODE_BACKSLASH
74	constant AKEYCODE_SEMICOLON
75	constant AKEYCODE_APOSTROPHE
76	constant AKEYCODE_SLASH
77	constant AKEYCODE_AT
78	constant AKEYCODE_NUM
79	constant AKEYCODE_HEADSETHOOK
80	constant AKEYCODE_FOCUS
81	constant AKEYCODE_PLUS
82	constant AKEYCODE_MENU
83	constant AKEYCODE_NOTIFICATION
84	constant AKEYCODE_SEARCH
85	constant AKEYCODE_MEDIA_PLAY_PAUSE
86	constant AKEYCODE_MEDIA_STOP
87	constant AKEYCODE_MEDIA_NEXT
88	constant AKEYCODE_MEDIA_PREVIOUS
89	constant AKEYCODE_MEDIA_REWIND
90	constant AKEYCODE_MEDIA_FAST_FORWARD
91	constant AKEYCODE_MUTE
92	constant AKEYCODE_PAGE_UP
93	constant AKEYCODE_PAGE_DOWN
94	constant AKEYCODE_PICTSYMBOLS
95	constant AKEYCODE_SWITCH_CHARSET
96	constant AKEYCODE_BUTTON_A
97	constant AKEYCODE_BUTTON_B
98	constant AKEYCODE_BUTTON_C
99	constant AKEYCODE_BUTTON_X
100	constant AKEYCODE_BUTTON_Y
101	constant AKEYCODE_BUTTON_Z
102	constant AKEYCODE_BUTTON_L1
103	constant AKEYCODE_BUTTON_R1
104	constant AKEYCODE_BUTTON_L2
105	constant AKEYCODE_BUTTON_R2
106	constant AKEYCODE_BUTTON_THUMBL
107	constant AKEYCODE_BUTTON_THUMBR
108	constant AKEYCODE_BUTTON_START
109	constant AKEYCODE_BUTTON_SELECT
110	constant AKEYCODE_BUTTON_MODE
1	constant WINDOW_FORMAT_RGBA_8888
2	constant WINDOW_FORMAT_RGBX_8888
4	constant WINDOW_FORMAT_RGB_565

\ -------===< structs >===--------
\ struct ANativeWindow_Buffer
begin-structure ANativeWindow_Buffer
	drop 20 24 +field ANativeWindow_Buffer-reserved
	drop 4 4 +field ANativeWindow_Buffer-height
	drop 0 4 +field ANativeWindow_Buffer-width
	drop 8 4 +field ANativeWindow_Buffer-stride
	drop 12 4 +field ANativeWindow_Buffer-format
	drop 16 4 +field ANativeWindow_Buffer-bits
drop 44 end-structure

\ ------===< functions >===-------
c-function ANativeWindow_acquire ANativeWindow_acquire a -- void
c-function ANativeWindow_release ANativeWindow_release a -- void
c-function ANativeWindow_getWidth ANativeWindow_getWidth a -- n
c-function ANativeWindow_getHeight ANativeWindow_getHeight a -- n
c-function ANativeWindow_getFormat ANativeWindow_getFormat a -- n
c-function ANativeWindow_setBuffersGeometry ANativeWindow_setBuffersGeometry a n n n -- n
c-function ANativeWindow_lock ANativeWindow_lock a a a -- n
c-function ANativeWindow_unlockAndPost ANativeWindow_unlockAndPost a -- n
c-function ANativeWindow_fromSurface ANativeWindow_fromSurface a a -- a

Changes to gles2/android.fs.

1
2
3
4
5
6
7
8
9
10
11
..
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
..
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
...
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
...
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
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
...
370
371
372
373
374
375
376

377
378
379
380
381
382
383
\ wrapper to load Swig-generated libraries

require struct0x.fs
require unix/socket.fs

\ public interface, C calls us through these

get-current also forth definitions

Defer ainput
Defer acmd
................................................................................
Vocabulary android
get-current also android definitions

c-library android
    \c #include <android/input.h>
    \c #include <android/native_window.h>
    \c #include <android/native_window_jni.h>
    \c #include <android/native_activity.h>
    \c #include <android/looper.h>
    \c struct android_poll_source {
    \c     int32_t id;
    \c     struct android_app* app;
    \c     void (*process)(struct android_app* app, struct android_poll_source* source);
    \c };
    \c
    \c int poll_looper(int timeout)
    \c {
    \c   int ident;
    \c   int events;
    \c   struct android_poll_source* source;
    \c   
    \c   // If not animating, we will block forever waiting for events.
    \c   // If animating, we loop until all events are read, then continue
    \c   // to draw the next frame of animation.
    \c   if((ident=ALooper_pollAll(timeout, NULL, &events,
    \c				(void**)&source)) >= 0) {
    \c	
    \c	// Process this event.
    \c	if (source != NULL) {
    \c	  source->process(source->app, source);
    \c	}
    \c   }
    \c   return ident;
    \c }
    c-function poll_looper poll_looper n -- n ( timeout -- ident )

    begin-structure ARect
    field: left
    field: top
    field: right
    field: bottom
    end-structure

    begin-structure app_input_state
    field: action
    field: flags
    field: metastate
    field: edgeflags
    field: pressure
................................................................................
    field: obj
    field: cls
    field: thread-id
    field: ke-fd0
    field: ke-fd1
    field: window \ native window
    end-structure

    0 [IF]
    begin-structure android_app \ excluding private data
    field: userData
    field: onAppCmd \ (int32_t)(*)(struct android_app* app, int32_t cmd);
    field: onInputEvent \ (int32_t)(*)(struct android_app* app, AInputEvent* event);
    field: activity
    field: config
    field: savedState
    field: savedStateSize
    field: looper
    field: inputQueue
    field: window
    ARect +field contentRect
    field: activityState
    field: destroyRequested
    end-structure
    [THEN]
    
    s" android" add-lib
    
    include androidlib.fs

end-c-library



s" APP_STATE" getenv s>number drop Value app

get-current also forth definitions

require jni-helper.fs

................................................................................
: keycode>keys ( keycode -- addr u )
    case
	AKEYCODE_MENU of  togglekb s" "  endof
	AKEYCODE_BACK of  aback s" "   endof
	akey>ekey 0
    endcase ;

0 [IF]
:noname { event -- }
    event AInputEvent_getType
    case
	1 of \ ." Key event" cr
	    event AKeyEvent_getAction AKEY_STATE_DOWN = IF
		event getUnicodeKey
		?dup-IF  >xstring
		ELSE  event AKeyEvent_getKeyCode keycode>keys
		THEN
		unkeys
	    THEN
	endof
	2 of \ ." Touch event" cr
	    event AMotionEvent_getAction *input action !
	    event AMotionEvent_getFlags *input flags !
	    event AMotionEvent_getMetaState *input metastate !
	    event AMotionEvent_getEdgeFlags *input edgeflags !
	    event 0 AMotionEvent_getPressure f>s *input pressure !
	    event 0 AMotionEvent_getSize f>s *input size !
	    event AMotionEvent_getPointerCount dup *input tcount !
	    *input x0 swap
	    0 ?DO
		event I AMotionEvent_getY f>s
		event I AMotionEvent_getX f>s
		rot dup >r 2! r> 2 cells +
	    LOOP
	    drop
	endof
    endcase ; is ainput
[THEN]

16 Value looper-to#
2Variable loop-event
0 Value poll-file

variable looperfds pollfd %size 8 * allot
: +fds ( fileno flag -- )
    looperfds dup @ pollfd %size * + cell+
................................................................................

also jni

: android-characters ( string -- )  jstring>sstring unkeys jfree ;
: android-unicode    ( uchar -- )   >xstring unkeys ;
: android-keycode    ( keycode -- ) keycode>keys unkeys ;






: android-key ( event -- )
    >o getAction dup 2 = IF  drop
	getKeyCode dup 0= IF
	    drop getCharacters android-characters
	ELSE
	    android-keycode
	THEN
    ELSE
	0= IF  getUnicodeChar dup 0>
	    IF    android-unicode
	    ELSE  drop  getKeyCode  android-keycode
	    THEN
	THEN
    THEN gref> ;

: android-touch ( event -- ) >o
    me-getAction *input action !
    getFlags *input flags !
    getMetaState *input metastate !
    getEdgeFlags *input edgeflags !
    0 getPressure f>s *input pressure !
    0 getSize f>s *input size !
    getPointerCount dup *input tcount !
    *input x0 swap
    0 ?DO
	I getY f>s
	I getX f>s
	rot dup >r 2! r> 2 cells +
    LOOP  drop
    gref> ;

JValue location
JValue sensor

Defer android-location ( location -- )
:noname to location ; IS android-location
Defer android-sensor ( sensor -- )
:noname to sensor ; IS android-sensor

\ stubs, "is recurse" assigns to last defined word
................................................................................
Defer android-surface-redraw ' drop is recurse
Defer android-global-layout ' drop is recurse

: android-surface-created ( surface -- )
    >o  env o ANativeWindow_fromSurface app window !  gref> ;
: android-surface-destroyed ( surface -- )
    >o  app window off  gref> ;


Create aevents
' android-key ,
' android-touch ,
' android-location ,
' android-sensor ,
' android-surface-created ,



<







 







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







 







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<



|


>
>







 







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







 







>
>
>
>
>
|












|

|













|
<
<
<







 







>







1
2
3

4
5
6
7
8
9
10
..
17
18
19
20
21
22
23



































24
25
26
27
28
29
30
..
58
59
60
61
62
63
64


















65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
...
151
152
153
154
155
156
157
































158
159
160
161
162
163
164
...
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
...
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
\ wrapper to load Swig-generated libraries

require struct0x.fs


\ public interface, C calls us through these

get-current also forth definitions

Defer ainput
Defer acmd
................................................................................
Vocabulary android
get-current also android definitions

c-library android
    \c #include <android/input.h>
    \c #include <android/native_window.h>
    \c #include <android/native_window_jni.h>




































    begin-structure app_input_state
    field: action
    field: flags
    field: metastate
    field: edgeflags
    field: pressure
................................................................................
    field: obj
    field: cls
    field: thread-id
    field: ke-fd0
    field: ke-fd1
    field: window \ native window
    end-structure


















    
    s" android" add-lib
    
    include android-window.fs

end-c-library

require unix/socket.fs

s" APP_STATE" getenv s>number drop Value app

get-current also forth definitions

require jni-helper.fs

................................................................................
: keycode>keys ( keycode -- addr u )
    case
	AKEYCODE_MENU of  togglekb s" "  endof
	AKEYCODE_BACK of  aback s" "   endof
	akey>ekey 0
    endcase ;

































16 Value looper-to#
2Variable loop-event
0 Value poll-file

variable looperfds pollfd %size 8 * allot
: +fds ( fileno flag -- )
    looperfds dup @ pollfd %size * + cell+
................................................................................

also jni

: android-characters ( string -- )  jstring>sstring unkeys jfree ;
: android-unicode    ( uchar -- )   >xstring unkeys ;
: android-keycode    ( keycode -- ) keycode>keys unkeys ;

JValue key-event
JValue touch-event
JValue location
JValue sensor

: android-key ( event -- ) dup to key-event
    >o getAction dup 2 = IF  drop
	getKeyCode dup 0= IF
	    drop getCharacters android-characters
	ELSE
	    android-keycode
	THEN
    ELSE
	0= IF  getUnicodeChar dup 0>
	    IF    android-unicode
	    ELSE  drop  getKeyCode  android-keycode
	    THEN
	THEN
    THEN o> ;

: android-touch ( event -- ) dup to touch-event >o
    me-getAction *input action !
    getFlags *input flags !
    getMetaState *input metastate !
    getEdgeFlags *input edgeflags !
    0 getPressure f>s *input pressure !
    0 getSize f>s *input size !
    getPointerCount dup *input tcount !
    *input x0 swap
    0 ?DO
	I getY f>s
	I getX f>s
	rot dup >r 2! r> 2 cells +
    LOOP  drop
    o> ;




Defer android-location ( location -- )
:noname to location ; IS android-location
Defer android-sensor ( sensor -- )
:noname to sensor ; IS android-sensor

\ stubs, "is recurse" assigns to last defined word
................................................................................
Defer android-surface-redraw ' drop is recurse
Defer android-global-layout ' drop is recurse

: android-surface-created ( surface -- )
    >o  env o ANativeWindow_fromSurface app window !  gref> ;
: android-surface-destroyed ( surface -- )
    >o  app window off  gref> ;
: android-global-layout ( 0 -- ) drop config-changed ;

Create aevents
' android-key ,
' android-touch ,
' android-location ,
' android-sensor ,
' android-surface-created ,

Changes to gles2/gl-sample.fs.

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

:noname new-config on ; is config-changed
[THEN]

FVariable touch -100e touch f!
FVariable motion 0.01e motion f!

: draw-tri { f: angle -- angle' }
    new-config @ IF
	dpy-w @ dpy-h @ getwh dpy-w @ dpy-h @ d<> IF  new-config off  THEN
    THEN
    ntime
    0.01e 0.02e 0.15e 1.0e glClearColor
    clear
    Ambient 1 ambient% glUniform1fv
    v0  angle set-triangle
    normals texcoords colors
    none-tex
    i0  0 i, 1 i, 2 i,
    GL_TRIANGLES draw-elements
    v0 colors'
    ascii-tex
    GL_TRIANGLES draw-elements
    sync
    2drop \ ntime d- dnegate ." Frame time: " d. cr






    >looper
    *input >r r@ IF
	r@ pressure @ 0> IF

	    \ ." Touch at " r@ x0 ? r@ y0 ? cr
	    \ r@ x0 @ 20 < r@ y0 @ 20 < and IF -1 (bye) THEN
	    r@ x0 @ dpy-w @ 2/ - s>f dpy-h @ 2/ fm/
	    r@ y0 @ dpy-h @ 2/ - s>f dpy-h @ 2/ fm/
	    fover fover fnegate -0.15e lightpos glUniform3f
	    fatan2
	    touch f@ -100e f= IF
		angle f- touch f!
	    ELSE
		touch f@ f-
		fdup angle f-
		fdup pi f> IF  pi f2* f-  THEN







|
<
<
<
<



|







|
<
>
>
>
>
>
>


<
>




|







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

:noname new-config on ; is config-changed
[THEN]

FVariable touch -100e touch f!
FVariable motion 0.01e motion f!

: draw-tri-angle ( f -- )




    0.01e 0.02e 0.15e 1.0e glClearColor
    clear
    Ambient 1 ambient% glUniform1fv
    v0  set-triangle
    normals texcoords colors
    none-tex
    i0  0 i, 1 i, 2 i,
    GL_TRIANGLES draw-elements
    v0 colors'
    ascii-tex
    GL_TRIANGLES draw-elements
    sync ;


: draw-tri { f: angle -- angle' }
    new-config @ IF
	dpy-w @ dpy-h @ getwh dpy-w @ dpy-h @ d<> IF  new-config off  THEN
    THEN
    angle draw-tri-angle
    >looper
    *input >r r@ IF

	r@ action @ abs 1 <> IF
	    \ ." Touch at " r@ x0 ? r@ y0 ? cr
	    \ r@ x0 @ 20 < r@ y0 @ 20 < and IF -1 (bye) THEN
	    r@ x0 @ dpy-w @ 2/ - s>f dpy-h @ 2/ fm/
	    r@ y0 @ dpy-h @ 2/ - s>f dpy-h @ 2/ fm/
	    fover fover fnegate -1.15e lightpos glUniform3f
	    fatan2
	    touch f@ -100e f= IF
		angle f- touch f!
	    ELSE
		touch f@ f-
		fdup angle f-
		fdup pi f> IF  pi f2* f-  THEN

Changes to gles2/jni-helper.fs.

69
70
71
72
73
74
75
76
77
78
79
80
81
82
83

84
85
86
87
88
89
90

: l[] ( n list -- object )  >o l-get o> ;
: l# ( list -- n )  >o l-size o> ;

: l-map ( xt list -- )  >o { xt } ( -- )
    l-size 0 ?DO  I l-get >o xt execute ref>  LOOP o> ;

: getUnicodeKey { event -- key }
    event AKeyEvent_getAction event AKeyEvent_getKeyCode newKeyEvent >o
    event AKeyEvent_getMetaState getUnicodeChar(I) o> ;

Variable kbflag

: togglekb ( -- )
    clazz >o INPUT_METHOD_SERVICE getSystemService o> >o 0 0 toggleSoftInput o>

    kbflag @ 0= kbflag ! ;
: hidekb ( -- )  kbflag @    IF  togglekb  THEN ;
: showkb ( -- )  kbflag @ 0= IF  togglekb  THEN ;

0 [IF]
jni-class: android/os/PowerManager
jni-method: newWakeLock newWakeLock (ILjava/lang/String;)Landroid/os/PowerManager$WakeLock;







<
<
<
<



|
>







69
70
71
72
73
74
75




76
77
78
79
80
81
82
83
84
85
86
87

: l[] ( n list -- object )  >o l-get o> ;
: l# ( list -- n )  >o l-size o> ;

: l-map ( xt list -- )  >o { xt } ( -- )
    l-size 0 ?DO  I l-get >o xt execute ref>  LOOP o> ;





Variable kbflag

: togglekb ( -- )
    clazz >o INPUT_METHOD_SERVICE getSystemService o>
    >o 0 0 toggleSoftInput ref>
    kbflag @ 0= kbflag ! ;
: hidekb ( -- )  kbflag @    IF  togglekb  THEN ;
: showkb ( -- )  kbflag @ 0= IF  togglekb  THEN ;

0 [IF]
jni-class: android/os/PowerManager
jni-method: newWakeLock newWakeLock (ILjava/lang/String;)Landroid/os/PowerManager$WakeLock;