Check-in [9a2d8e9dac]
Not logged in

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

Overview
Comment:Rewritten for own native activity implementation - works\!
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 9a2d8e9dac540800f5058b568ec413fda5fb8e4f
User & Date: bernd 2014-01-17 23:42:18
Context
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
00:13
Rewrite for Gforth\NativeActivity check-in: af01051ada user: bernd tags: trunk
Changes

Changes to gles2/android.fs.

92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
...
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
...
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
349
350
351
352
353
354
355
356
357
358
359





360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
    field: vm
    field: env
    field: obj
    field: cls
    field: thread-id
    field: ke-fd0
    field: ke-fd1
    field: 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);
................................................................................
    endcase ; is ainput
[THEN]

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

pollfd %size buffer: looperfds
: fds!+ ( fileno flag addr -- addr' )

    >r r@ events w!  r@ fd l!  r> pollfd %size + ; 


: ?poll-file ( -- )
    poll-file 0= IF  app ke-fd0 @ "r\0" drop fdopen to poll-file  THEN ;
: poll? ( ms -- flag )  looperfds 1 rot 1000 * poll 0> dup >r






    IF  loop-event 2 cells poll-file read-file throw drop
	loop-event 2@ swap akey  THEN  r> ;

: >looper  app ke-fd0 @  POLLIN looperfds fds!+ drop  ?poll-file








    BEGIN  0 poll? 0=  UNTIL  looper-to# poll? drop ;
: ?looper  BEGIN  >looper  app window @ UNTIL ;
	    
\ : >looper  BEGIN  0 poll_looper 0<  UNTIL looper-to# poll_looper drop ;
\ : ?looper  BEGIN >looper app window @ UNTIL ;

:noname  0 poll_looper drop defers key? ; IS key?
Defer screen-ops ' noop IS screen-ops
:noname  need-show on  BEGIN  >looper key? screen-ops  UNTIL
    defers key dup #cr = key? and IF  key ?dup-IF unkey THEN THEN ;
IS key

: enum dup Constant 1+ ;
0
................................................................................
	THEN
    ELSE
	0= IF  getUnicodeChar dup 0>
	    IF    android-unicode
	    ELSE  drop  getKeyCode  android-keycode
	    THEN
	THEN
    THEN o ]gref o> ;

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

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-created ' drop is recurse
Defer android-surface-changed ' drop is recurse
Defer android-surface-redraw ' drop is recurse
Defer android-surface-destroyed ' drop is recurse
Defer android-global-layout ' drop is recurse






Create aevents
' android-key ,
' android-touch ,
' android-location ,
' android-sensor ,
' android-characters ,
' android-unicode ,
' android-keycode ,
' android-touch ,
' android-surface-created ,
' android-surface-changed ,
' android-surface-redraw ,
' android-surface-destroyed ,
' android-global-layout ,

:noname ( event type -- ) cells aevents + perform ; is akey

previous previous set-current







|







 







|
|
>
|
>
|


<
>
>
>
>
>
>
|
|

<
>
>
>
>
>
>
>
>






|







 







|






|
|

|





|











<


<

>
>
>
>
>






<
<
<
<






|


92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
...
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
...
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
368

369
370

371
372
373
374
375
376
377
378
379
380
381
382




383
384
385
386
387
388
389
390
391
    field: vm
    field: env
    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);
................................................................................
    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+
    >r r@ events w!  r> fd l!
    1 looperfds +! ;
    
: ?poll-file ( -- )
    poll-file 0= IF  app ke-fd0 @ "r\0" drop fdopen to poll-file  THEN ;

: looper-init ( -- )  looperfds off
    app ke-fd0 @  POLLIN +fds
    stdin fileno  POLLIN +fds
    ?poll-file ;

: get-event ( -- )
    loop-event 2 cells poll-file read-file throw drop
    loop-event 2@ akey ;


: poll? ( ms -- flag )  looperfds dup cell+ swap @
    rot poll 0>
    IF	looperfds cell+ revents w@ POLLIN = dup >r
	IF  get-event  THEN  r>
    ELSE  false
    THEN ;

: >looper  looper-init
    BEGIN  0 poll? 0=  UNTIL  looper-to# poll? drop ;
: ?looper  BEGIN  >looper  app window @ UNTIL ;
	    
\ : >looper  BEGIN  0 poll_looper 0<  UNTIL looper-to# poll_looper drop ;
\ : ?looper  BEGIN >looper app window @ UNTIL ;

:noname  0 poll? drop  defers key? ; IS key?
Defer screen-ops ' noop IS screen-ops
:noname  need-show on  BEGIN  >looper key? screen-ops  UNTIL
    defers key dup #cr = key? and IF  key ?dup-IF unkey THEN THEN ;
IS key

: enum dup Constant 1+ ;
0
................................................................................
	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-changed ' drop is recurse
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 ,
' android-surface-changed ,
' android-surface-redraw ,
' android-surface-destroyed ,
' android-global-layout ,

:noname ( event type -- )  cells aevents + perform ; is akey

previous previous set-current

Changes to gles2/jni-helper.fs.

35
36
37
38
39
40
41

42
43
44
45
46
47
48
jni-method: toggleSoftInput toggleSoftInput (II)V

jni-class: android/view/Window
jni-method: getDecorView getDecorView ()Landroid/view/View;
jni-method: addFlags addFlags (I)V
jni-method: clearFlags clearFlags (I)V
jni-method: getForcedWindowFlags getForcedWindowFlags ()I


jni-class: android/view/KeyEvent
jni-new: newKeyEvent (II)V
jni-method: getUnicodeChar(I) getUnicodeChar (I)I
jni-method: getUnicodeChar getUnicodeChar ()I
jni-method: getKeyCode getKeyCode ()I
jni-method: getCharacters getCharacters ()Ljava/lang/String;







>







35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
jni-method: toggleSoftInput toggleSoftInput (II)V

jni-class: android/view/Window
jni-method: getDecorView getDecorView ()Landroid/view/View;
jni-method: addFlags addFlags (I)V
jni-method: clearFlags clearFlags (I)V
jni-method: getForcedWindowFlags getForcedWindowFlags ()I
jni-method: takeSurface takeSurface (Landroid/view/SurfaceHolder$Callback2;)V

jni-class: android/view/KeyEvent
jni-new: newKeyEvent (II)V
jni-method: getUnicodeChar(I) getUnicodeChar (I)I
jni-method: getUnicodeChar getUnicodeChar ()I
jni-method: getKeyCode getKeyCode ()I
jni-method: getCharacters getCharacters ()Ljava/lang/String;

Changes to gles2/jni-tools.fs.

145
146
147
148
149
150
151


152
153
154
155
156
157
158

\ global ref handling - you should ]gref every global ref after usage

: ]ref ( object -- )  env tuck JNIEnv-DeleteLocalRef() ;
: ]gref ( object -- )  env tuck JNIEnv-DeleteGlobalRef() ;
: ref> ( object -- ) o ]ref r> o> >r ;
comp: drop ]] o ]ref o> [[ ;



: gref! ( gref addr -- )  dup @ ?dup-IF  ]gref  THEN ! ;
: jvalue! ( gref xt -- )  >body gref! ;
comp: drop >body postpone ALiteral postpone gref! ;

: JValue ( "name" -- ) 0 Value ['] jvalue! set-to ;








>
>







145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160

\ global ref handling - you should ]gref every global ref after usage

: ]ref ( object -- )  env tuck JNIEnv-DeleteLocalRef() ;
: ]gref ( object -- )  env tuck JNIEnv-DeleteGlobalRef() ;
: ref> ( object -- ) o ]ref r> o> >r ;
comp: drop ]] o ]ref o> [[ ;
: gref> ( object -- ) o ]gref r> o> >r ;
comp: drop ]] o ]gref o> [[ ;

: gref! ( gref addr -- )  dup @ ?dup-IF  ]gref  THEN ! ;
: jvalue! ( gref xt -- )  >body gref! ;
comp: drop >body postpone ALiteral postpone gref! ;

: JValue ( "name" -- ) 0 Value ['] jvalue! set-to ;