summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile5
-rw-r--r--include/input.h9
-rw-r--r--input.c13
-rw-r--r--scene-title.c6
4 files changed, 29 insertions, 4 deletions
diff --git a/Makefile b/Makefile
index b43e2c6..ea2ca2a 100644
--- a/Makefile
+++ b/Makefile
@@ -4,12 +4,13 @@ CFLAGS := -std=c11 -g -O0 -Wall -Wextra -Wshadow -Iinclude $(shell sdl2-config
LDFLAGS :=
LDLIBS := -ldl -lm $(shell sdl2-config --libs) $(shell pkg-config --libs cglm)
all: mino
-mino: glad.o tex.o graph.o scene.o scene-title.o mino.o
+mino: glad.o tex.o graph.o input.o scene.o scene-title.o mino.o
mino.o: mino.c include/mino.h
scene.o: scene.c include/scene.h
scene-title.o: scene-title.c
+input.o: input.c include/input.h
graph.o: graph.c include/graph.h
tex.o: tex.c include/tex.h
glad.o: glad.c include/glad/glad.h
clean:
- rm -rf mino mino.o scene-title.o scene.o graph.o tex.o glad.o
+ rm -rf mino mino.o scene-title.o scene.o input.o graph.o tex.o glad.o
diff --git a/include/input.h b/include/input.h
new file mode 100644
index 0000000..0a54d19
--- /dev/null
+++ b/include/input.h
@@ -0,0 +1,9 @@
+#ifndef MINO_INPUT_H
+#define MINO_INPUT_H
+#include"mino.h"
+typedef struct{U32 x,y;}InputPoint;
+typedef struct{U32 f;}InputButtons;
+enum{IB_1=1<<0,IB_2=1<<1,IB_3=1<<2,IB_4=1<<3};
+X InputPoint input_point(V);
+X InputButtons input_buttons(V);
+#endif
diff --git a/input.c b/input.c
new file mode 100644
index 0000000..8248ded
--- /dev/null
+++ b/input.c
@@ -0,0 +1,13 @@
+#include<SDL.h>
+#include<cglm/cglm.h>
+#include"mino.h"
+#include"graph.h"
+#include"input.h"
+#define SDLBUT(x)SDL_BUTTON(SDL_BUTTON_##x)
+InputPoint input_point(V){InputPoint ip;SDL_GetMouseState((S32*)&ip.x,(S32*)&ip.y);ip.y=graph_win_h-ip.y;R ip;}
+InputButtons input_button(V){InputButtons ib={0};U32 mb;mb=SDL_GetMouseState(0,0);
+ Q(SDLBUT(LEFT)&mb, ib.f|=IB_1)
+ Q(SDLBUT(MIDDLE)&mb, ib.f|=IB_2)
+ Q(SDLBUT(RIGHT)&mb, ib.f|=IB_3)
+ Q(SDLBUT(X1)&mb, ib.f|=IB_4)
+ R ib;}
diff --git a/scene-title.c b/scene-title.c
index 64429c5..527c686 100644
--- a/scene-title.c
+++ b/scene-title.c
@@ -5,6 +5,7 @@
#include"mino.h"
#include"graph.h"
#include"scene.h"
+#include"input.h"
_ mat4 win_proj;
@@ -36,12 +37,13 @@ _ V title_init(V){
shader_tex_init();
tex_cat=graph_tex_create("res/tex/cat.jpg");}
-_ V title_loop(V){/*prelude*/graph_before(),graph_events();
+_ V title_loop(V){/*prelude*/graph_before(),graph_events();InputPoint p;
glm_ortho(0,graph_win_w,0,graph_win_h,0,4,win_proj),
/*interlude*/
+ p=input_point(),
graph_shader_use(shader_tex),graph_shader_setM4("proj",win_proj),
graph_tex_use(tex_cat,0),
- graph_quad_xywh(graph_win_w/2.0,graph_win_h/2.0,256,256),
+ graph_quad_xywh(p.x,p.y,256,256),
/*postlude*/
graph_after();}