libresman
diff examples/imgthumbs/src/main.c @ 2:026cdd1737ff
added spaceball controls to the example and needless GLEW dependency
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Fri, 31 Jan 2014 03:40:00 +0200 |
parents | 469ce01809bc |
children | a396d43a62f9 |
line diff
1.1 --- a/examples/imgthumbs/src/main.c Fri Jan 31 03:17:24 2014 +0200 1.2 +++ b/examples/imgthumbs/src/main.c Fri Jan 31 03:40:00 2014 +0200 1.3 @@ -13,6 +13,7 @@ 1.4 static void keyb(unsigned char key, int x, int y); 1.5 static void mouse(int bn, int st, int x, int y); 1.6 static void motion(int x, int y); 1.7 +static void sball_motion(int x, int y, int z); 1.8 static struct thumbnail *find_thumb(int x, int y); 1.9 1.10 const char *path = "."; 1.11 @@ -43,6 +44,7 @@ 1.12 glutKeyboardFunc(keyb); 1.13 glutMouseFunc(mouse); 1.14 glutMotionFunc(motion); 1.15 + glutSpaceballMotionFunc(sball_motion); 1.16 1.17 if(init() == -1) { 1.18 return 1; 1.19 @@ -55,6 +57,8 @@ 1.20 1.21 static int init(void) 1.22 { 1.23 + glewInit(); 1.24 + 1.25 thumbs = create_thumbs(path); 1.26 return 0; 1.27 } 1.28 @@ -211,6 +215,26 @@ 1.29 } 1.30 } 1.31 1.32 +static void sball_motion(int x, int y, int z) 1.33 +{ 1.34 + float fx = -x * 0.0004; 1.35 + float fy = z * 0.0004; 1.36 + float fz = -y * 0.0005; 1.37 + 1.38 + if(show_thumb) { 1.39 + show_pan_x += fx / show_zoom; 1.40 + show_pan_y += fy / show_zoom; 1.41 + show_zoom += fz; 1.42 + if(show_zoom <= 0) show_zoom = 0; 1.43 + } else { 1.44 + pan_x += fx; 1.45 + pan_y += fy; 1.46 + thumbs_size += fz; 1.47 + if(thumbs_size <= 0.01) thumbs_size = 0.01; 1.48 + } 1.49 + glutPostRedisplay(); 1.50 +} 1.51 + 1.52 static struct thumbnail *find_thumb(int x, int y) 1.53 { 1.54 float fx = (float)x / (float)win_width;