mirror of https://git.cro.wtf/kip.git
kip-io:add mouse buttons
This commit is contained in:
parent
ae23b15c75
commit
8ffaa3a020
|
@ -8,3 +8,4 @@ X(io_display_pos)
|
|||
X(io_display_blit)
|
||||
X(io_display_out)
|
||||
X(io_mouse_pos)
|
||||
X(io_mouse_but)
|
||||
|
|
11
kip-sdl2.c
11
kip-sdl2.c
|
@ -13,11 +13,9 @@ _ W palette[0x10]={0x212425,0x212425,0x86215f,0xc33479,0x392874,0x0a5c9f,0xa0c5c
|
|||
_ B layer[4][wid*hig]={0},redraw;
|
||||
_ W computed[wid*hig]={0};
|
||||
|
||||
_ H mx,my,px,py;
|
||||
_ H mx,my,mb,px,py;
|
||||
_ W blit,out,pal;
|
||||
|
||||
_ Ws min(Ws x,Ws y){R x<y?x:y;}
|
||||
_ Ws max(Ws x,Ws y){R x>y?x:y;}
|
||||
_ NR V err(V){die("sdl:%s\n",SDL_GetError());}
|
||||
|
||||
_ V out_pixel(B l,W c,H x,H y){Q(c,redraw=1,layer[l&3][x+wid*y]=(l>>2)?0:(B)c&0xf;)}
|
||||
|
@ -31,6 +29,7 @@ DEV(display_pos,(px=x>>16,py=x),(R px<<16|py))
|
|||
DEV(display_blit,(blit=x),(R blit))
|
||||
DEV(display_out,(W c;B m,l;out=x,m=0xf&x,l=(0xf0&x)>>4,c=x>>8,outs[m](l,c,px,py)),(R out))
|
||||
DEV(mouse_pos,(mx=x<<16,my=x),(R mx<<16|my))
|
||||
DEV(mouse_but,((V)x),(R mb))
|
||||
|
||||
V front_init(V){
|
||||
Q(SDL_Init(SDL_INIT_VIDEO),err())
|
||||
|
@ -43,9 +42,9 @@ V front_init(V){
|
|||
|
||||
V front_events(V){_ SDL_Event ev;W t;
|
||||
WH(SDL_PollEvent(&ev),t=ev.type;
|
||||
Q(SDL_MOUSEMOTION==t,mx=min(wid,max(0,ev.motion.x)),my=min(hig,max(0,ev.motion.y)))OR
|
||||
Q(SDL_MOUSEBUTTONDOWN==t,vec(0x04))OR
|
||||
Q(SDL_MOUSEBUTTONUP==t,vec(0x08))OR
|
||||
Q(SDL_MOUSEMOTION==t,mx=SDL_clamp(ev.motion.x,0,wid),my=SDL_clamp(ev.motion.y,0,hig))OR
|
||||
Q(SDL_MOUSEBUTTONDOWN==t,mb|=1<<(ev.button.button-1),vec(0x04))OR
|
||||
Q(SDL_MOUSEBUTTONUP==t, mb^=1<<(ev.button.button-1),vec(0x08))OR
|
||||
Q(SDL_QUIT==t,kip_deinit(),exit(0)))}
|
||||
|
||||
V front_redraw(V){W i,j,k;
|
||||
|
|
Loading…
Reference in New Issue