Drag/drop example

This commit is contained in:
neauoire 2021-02-16 15:34:55 -08:00
parent 36bfb2a417
commit 38d3917cd3
2 changed files with 41 additions and 28 deletions

View File

@ -111,7 +111,7 @@ void
drawdebugger(Uint32 *dst, Uxn *u) drawdebugger(Uint32 *dst, Uxn *u)
{ {
Uint8 i; Uint8 i;
for(i = 0; i < 0x10; ++i) { /* memory */ for(i = 0; i < 0x20; ++i) { /* memory */
Uint8 x = (i % 8) * 3 + 1, y = i / 8 + 1, b = u->ram.dat[i]; Uint8 x = (i % 8) * 3 + 1, y = i / 8 + 1, b = u->ram.dat[i];
drawicn(dst, x * 8, y * 8, icons[(b >> 4) & 0xf], 1, 0); drawicn(dst, x * 8, y * 8, icons[(b >> 4) & 0xf], 1, 0);
drawicn(dst, x * 8 + 8, y * 8, icons[b & 0xf], 1, 0); drawicn(dst, x * 8 + 8, y * 8, icons[b & 0xf], 1, 0);
@ -182,12 +182,11 @@ domouse(SDL_Event *event)
devmouse->mem[1] = x & 0xff; devmouse->mem[1] = x & 0xff;
devmouse->mem[2] = (y >> 8) & 0xff; devmouse->mem[2] = (y >> 8) & 0xff;
devmouse->mem[3] = y & 0xff; devmouse->mem[3] = y & 0xff;
devmouse->mem[4] = event->button.button == SDL_BUTTON_LEFT;
devmouse->mem[5] = 0x00;
switch(event->type) { switch(event->type) {
case SDL_MOUSEBUTTONUP: case SDL_MOUSEBUTTONUP: devmouse->mem[5] = 0x10; break;
devmouse->mem[4] = 0; case SDL_MOUSEBUTTONDOWN: devmouse->mem[5] = 0x01; break;
break;
case SDL_MOUSEBUTTONDOWN:
devmouse->mem[4] = event->button.button == SDL_BUTTON_LEFT;
} }
} }
@ -254,8 +253,6 @@ screenw(Device *d, Memory *m, Uint8 b)
d->mem[4]); d->mem[4]);
if(d->mem[5] == 1) if(d->mem[5] == 1)
REQDRAW = 1; REQDRAW = 1;
if(d->mem[5] == 2)
clear(pixels);
d->ptr = 0; d->ptr = 0;
} }
(void)m; (void)m;
@ -288,6 +285,8 @@ start(Uxn *u)
{ {
int ticknext = 0; int ticknext = 0;
evaluxn(u, u->vreset); evaluxn(u, u->vreset);
if(REQDRAW)
redraw(pixels, u);
while(1) { while(1) {
int tick = SDL_GetTicks(); int tick = SDL_GetTicks();
SDL_Event event; SDL_Event event;

View File

@ -4,32 +4,53 @@
:dev/w fff9 ( std write port ) :dev/w fff9 ( std write port )
;drawx 2 ;drawy 2 ;x 2 ;y 2 ;w 2 ;h 2 ;color 1 ;drawx 2 ;drawy 2 ;x 2 ;y 2 ;w 2 ;h 2 ;color 1
;touchx 2 ;touchy 2 ;down 1
|0100 @RESET |0100 @RESET
#05 =dev/r ( set dev/read mouse ) #05 =dev/r ( set dev/read mouse )
#01 =dev/w ( set dev/write to screen ) #01 =dev/w ( set dev/write to screen )
#02 =color
#0050 =w #0080 =h ,update JSR
BRK BRK
|c000 @FRAME |c000 @FRAME
( get touch ) ( get touch )
#04 IOR #01 NEQ ,frame-end ROT JMP? POP2 #05 IOR #01 EQU ,on-touch ROT JMP? POP2
#05 IOR #10 EQU ,on-release ROT JMP? POP2
#01 ~down EQU ,on-drag ROT JMP? POP2
BRK
( clear ) @on-touch
#00 =color #01 =down
~x ~y #0060 #0040 ,fillrect JSR #01 =color
#00 IOR2 =touchx #02 IOR2 =touchy
,update JSR
BRK
@on-release
#00 =down
#02 =color
,update JSR
BRK
@on-drag
( clear last rect )
#00 =color
~x ~y ~w ~h ,fillrect JSR
( draw new rect )
#03 =color
#00 IOR2 ~touchx SUBS2 ~x ADDS2 =x
#02 IOR2 ~touchy SUBS2 ~y ADDS2 =y
#00 IOR2 =touchx #02 IOR2 =touchy
,update JSR
BRK
( fill rect x y w h ) @update
#01 =color ~x ~y ~w ~h ,fillrect JSR
#00 IOR2 ( get mouse-x ) =x ,redraw JSR
#02 IOR2 ( get mouse-y ) =y BRK
~x ~y #0060 #0040 ,fillrect JSR
,redraw JSR
@frame-end
BRK BRK
@ -58,12 +79,5 @@ BRK
#01 IOW #01 IOW
RTS RTS
@clear
#0000 IOW2
#0000 IOW2
#00 IOW
#02 IOW
RTS
|d000 @ERROR BRK |d000 @ERROR BRK
|FFFA .RESET .FRAME .ERROR |FFFA .RESET .FRAME .ERROR