From e0d78864db5cceff4e03005405c7017c436811b2 Mon Sep 17 00:00:00 2001 From: Holmes Futrell Date: Fri, 18 Jul 2008 20:52:32 +0000 Subject: [PATCH] Touch input demo (multitouch) --- XCodeiPhoneOS/Demos/src/touch.c | 116 ++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 XCodeiPhoneOS/Demos/src/touch.c diff --git a/XCodeiPhoneOS/Demos/src/touch.c b/XCodeiPhoneOS/Demos/src/touch.c new file mode 100644 index 000000000..9987c22ad --- /dev/null +++ b/XCodeiPhoneOS/Demos/src/touch.c @@ -0,0 +1,116 @@ +/* + * touch.c + * written by Holmes Futrell + * use however you want + */ + +#include "SDL.h" +#include "math.h" +#include "common.h" + +#define BRUSH_SIZE 32 /* width and height of the brush */ +#define PIXELS_PER_ITERATION 5 /* number of pixels between brush blots when forming a line */ + +static SDL_TextureID brushID=0; /* texture for the brush */ + +/* + draws a line from (startx, starty) to (startx + dx, starty + dy) + this is accomplished by drawing several blots spaced PIXELS_PER_ITERATION apart +*/ +void drawLine(float startx, float starty, float dx, float dy) { + + float distance = sqrt(dx*dx+dy*dy); /* length of line segment (pythagoras) */ + int iterations = distance / PIXELS_PER_ITERATION + 1; /* number of brush sprites to draw for the line */ + float dx_prime = dx / iterations; /* x-shift per iteration */ + float dy_prime = dy / iterations; /* y-shift per iteration */ + SDL_Rect dstRect; /* rect to draw brush sprite into */ + + dstRect.w = BRUSH_SIZE; + dstRect.h = BRUSH_SIZE; + + /* setup x and y for the location of the first sprite */ + float x = startx - BRUSH_SIZE / 2.0f; + float y = starty - BRUSH_SIZE / 2.0f; + + int i; + /* draw a series of blots to form the line */ + for (i=0; i