test/testeyes.c
author Eli Gottlieb <eligottlieb@gmail.com>
Sun, 18 Jul 2010 15:15:05 -0400
changeset 4798 980614a70cfc
parent 4795 6f0bc179771c
permissions -rw-r--r--
Updated testeyes.c. It now shows some kind of gibberish Missingno-type picture somewhere on the screen and, possibly, hangs the window system. On the upside, the Missingno is definitely a non-rectangular window.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4770
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
     1
#include <stdlib.h>
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
     2
#include <math.h>
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
     3
#include <SDL_events.h>
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
     4
#include <SDL_rect.h>
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
     5
#include <SDL_pixels.h>
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
     6
#include <SDL_video.h>
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
     7
#include <SDL_shape.h>
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
     8
#include "testeyes_bitmap.h"
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
     9
#include "testeyes_mask_bitmap.h"
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
    10
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
    11
/* The following code for the calculation of pupil positions has been taken and rewritten from the original xeyes.  The
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
    12
   copyright notice is included as follows, and the code is now under the same license as the rest of this file. */
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
    13
/*
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
    14
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
    15
Copyright (c) 1991  X Consortium
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
    16
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
    17
Permission is hereby granted, free of charge, to any person obtaining
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
    18
a copy of this software and associated documentation files (the
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
    19
"Software"), to deal in the Software without restriction, including
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
    20
without limitation the rights to use, copy, modify, merge, publish,
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
    21
distribute, sublicense, and/or sell copies of the Software, and to
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
    22
permit persons to whom the Software is furnished to do so, subject to
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
    23
the following conditions:
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
    24
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
    25
The above copyright notice and this permission notice shall be included
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
    26
in all copies or substantial portions of the Software.
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
    27
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
    28
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
    29
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
    30
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
    31
IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
    32
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
    33
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
    34
OTHER DEALINGS IN THE SOFTWARE.
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
    35
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
    36
Except as contained in this notice, the name of the X Consortium shall
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
    37
not be used in advertising or otherwise to promote the sale, use or
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
    38
other dealings in this Software without prior written authorization
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
    39
from the X Consortium.
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
    40
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
    41
*/
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
    42
# define NUM_EYES	2
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
    43
# define EYE_X(n)	((n) * 2.0)
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
    44
# define EYE_Y(n)	(0.0)
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
    45
# define EYE_THICK	(0.175)	/* thickness of eye rim */
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
    46
# define EYE_OFFSET	(0.1)	/* padding between eyes */
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
    47
# define EYE_WIDTH	(2.0 - (EYE_THICK + EYE_OFFSET) * 2)
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
    48
# define EYE_HEIGHT	EYE_WIDTH
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
    49
# define EYE_HWIDTH	(EYE_WIDTH / 2.0)
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
    50
# define EYE_HHEIGHT	(EYE_HEIGHT / 2.0)
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
    51
# define BALL_WIDTH	(0.3)
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
    52
# define BALL_HEIGHT	BALL_WIDTH
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
    53
# define BALL_PAD	(0.05)
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
    54
# define BALL_DIST	((EYE_WIDTH - BALL_WIDTH) / 2.0 - BALL_PAD)
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
    55
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
    56
SDL_Point computePupil (int num,SDL_Point mouse) {
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
    57
	double dx = mouse.x - EYE_X(num);
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
    58
	double dy = mouse.y - EYE_Y(num);
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
    59
	double cx = 0.0,cy = 0.0;
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
    60
	if(dx == 0 && dy == 0) {
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
    61
		cx = EYE_X(num);
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
    62
		cy = EYE_Y(num);
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
    63
	}
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
    64
	else {
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
    65
		double angle = atan2((double)dy,(double)dx);
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
    66
		double cosa = cos(angle);
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
    67
		double sina = sin(angle);
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
    68
		double hypotenuse = hypot(EYE_HHEIGHT * cosa, EYE_HWIDTH * sina);
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
    69
		double dist = BALL_DIST * hypot((EYE_HWIDTH * EYE_HHEIGHT) * cosa / hypotenuse,
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
    70
					        (EYE_HWIDTH * EYE_HHEIGHT) * sina / hypotenuse);
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
    71
		if(dist > hypot((double)dx,(double)dy)) {
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
    72
			cx = dx + EYE_X(num);
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
    73
			cy = dy + EYE_Y(num);
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
    74
		}
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
    75
		else {
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
    76
			cx = dist * cosa + EYE_X(num);
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
    77
			cy = dist * sina + EYE_Y(num);
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
    78
		}
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
    79
	}
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
    80
	SDL_Point ret = {cx,cy};
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
    81
	return ret;
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
    82
}
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
    83
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
    84
/* Here begins the code exclusively and entirely written by Eli Gottlieb in May 2010. */
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
    85
typedef struct {
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
    86
	SDL_Rect left;
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
    87
	SDL_Rect right;
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
    88
} Pupil_Pair;
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
    89
typedef struct {
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
    90
	SDL_Point left;
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
    91
	SDL_Point right;
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
    92
} Pupil_Points;
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
    93
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
    94
Pupil_Pair compute_pupil_positions(SDL_Point target) {
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
    95
	Pupil_Pair result;
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
    96
	Pupil_Points points;
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
    97
	points.left = computePupil(0,target);
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
    98
	points.right = computePupil(1,target);
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
    99
	result.left.x = points.left.x - BALL_WIDTH / 2.0;
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
   100
	result.left.y = points.left.y - BALL_HEIGHT / 2.0;
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
   101
	result.right.x = points.right.x - BALL_WIDTH / 2.0;
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
   102
	result.right.y = points.right.y - BALL_HEIGHT / 2.0;
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
   103
	result.left.w = result.right.w = BALL_WIDTH;
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
   104
	result.left.h = result.left.w = BALL_HEIGHT;
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
   105
	return result;
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
   106
}
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
   107
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
   108
void render_eyes(SDL_Window *window,SDL_Texture *eyes_texture,Pupil_Pair pupils) {
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
   109
	SDL_SelectRenderer(window);
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
   110
	
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
   111
	//Clear render-target to blue.
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
   112
	SDL_SetRenderDrawColor(0x00,0x00,0xff,0xff);
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
   113
	SDL_RenderClear();
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
   114
	
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
   115
	//Render the whites of the eyes.
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
   116
	SDL_Rect srcdestrect = {0,0,eyes_width,eyes_height};
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
   117
	SDL_RenderCopy(eyes_texture,&srcdestrect,&srcdestrect);
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
   118
	
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
   119
	//Render the pupils.
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
   120
	SDL_SetRenderDrawColor(0x00,0x00,0x00,0xff);
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
   121
	const SDL_Rect eyes[2] = {pupils.left,pupils.right};
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
   122
	SDL_RenderFillRects((const SDL_Rect**)&eyes,2);
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
   123
	
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
   124
	SDL_RenderPresent();
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
   125
}
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
   126
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
   127
int main(int argc,char** argv) {
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
   128
	if(SDL_VideoInit(NULL,0) == -1) {
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
   129
		printf("Could not initialize SDL video.\n");
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
   130
		exit(-1);
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
   131
	}
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
   132
	
4798
980614a70cfc Updated testeyes.c. It now shows some kind of gibberish Missingno-type picture somewhere on the screen and, possibly, hangs the window system. On the upside, the Missingno is definitely a non-rectangular window.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4795
diff changeset
   133
	SDL_Window *window = SDL_CreateShapedWindow("Big Brother is watching you.",eyes_x_hot,eyes_y_hot,eyes_width,eyes_height,SDL_WINDOW_RESIZABLE | SDL_WINDOW_SHOWN);
4770
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
   134
	if(window == NULL) {
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
   135
		SDL_VideoQuit();
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
   136
		printf("Could not create shaped window for eyes.\n");
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
   137
		exit(-2);
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
   138
	}
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
   139
	if(SDL_CreateRenderer(window,-1,SDL_RENDERER_PRESENTFLIP2) == -1) {
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
   140
		SDL_DestroyWindow(window);
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
   141
		SDL_VideoQuit();
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
   142
		printf("Could not create rendering context for SDL_Eyes window.\n");
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
   143
		exit(-3);
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
   144
	}
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
   145
	
4795
6f0bc179771c Numerous bug fixes that keep testeyes from crashing and dying.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4785
diff changeset
   146
	int bpp = 0;
6f0bc179771c Numerous bug fixes that keep testeyes from crashing and dying.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4785
diff changeset
   147
	Uint32 r = 0,g = 0,b = 0,a = 0;
6f0bc179771c Numerous bug fixes that keep testeyes from crashing and dying.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4785
diff changeset
   148
	SDL_PixelFormatEnumToMasks(SDL_PIXELFORMAT_ARGB4444,&bpp,&r,&g,&b,&a);
6f0bc179771c Numerous bug fixes that keep testeyes from crashing and dying.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4785
diff changeset
   149
	SDL_Surface *eyes = SDL_CreateRGBSurface(0,eyes_width,eyes_height,bpp,r,g,b,a);
6f0bc179771c Numerous bug fixes that keep testeyes from crashing and dying.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4785
diff changeset
   150
	if(eyes == NULL) {
6f0bc179771c Numerous bug fixes that keep testeyes from crashing and dying.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4785
diff changeset
   151
		SDL_DestroyRenderer(window);
6f0bc179771c Numerous bug fixes that keep testeyes from crashing and dying.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4785
diff changeset
   152
		SDL_DestroyWindow(window);
6f0bc179771c Numerous bug fixes that keep testeyes from crashing and dying.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4785
diff changeset
   153
		SDL_VideoQuit();
6f0bc179771c Numerous bug fixes that keep testeyes from crashing and dying.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4785
diff changeset
   154
		printf("Could not create eyes surface.\n");
6f0bc179771c Numerous bug fixes that keep testeyes from crashing and dying.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4785
diff changeset
   155
		exit(-4);
6f0bc179771c Numerous bug fixes that keep testeyes from crashing and dying.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4785
diff changeset
   156
	}
6f0bc179771c Numerous bug fixes that keep testeyes from crashing and dying.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4785
diff changeset
   157
	
6f0bc179771c Numerous bug fixes that keep testeyes from crashing and dying.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4785
diff changeset
   158
	void *pixels = NULL;
6f0bc179771c Numerous bug fixes that keep testeyes from crashing and dying.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4785
diff changeset
   159
	int pitch = 0;
6f0bc179771c Numerous bug fixes that keep testeyes from crashing and dying.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4785
diff changeset
   160
	SDL_Rect rect = {0,0,eyes_width,eyes_height};
6f0bc179771c Numerous bug fixes that keep testeyes from crashing and dying.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4785
diff changeset
   161
	if(SDL_MUSTLOCK(eyes))
6f0bc179771c Numerous bug fixes that keep testeyes from crashing and dying.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4785
diff changeset
   162
		SDL_LockSurface(eyes);
6f0bc179771c Numerous bug fixes that keep testeyes from crashing and dying.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4785
diff changeset
   163
	pixels = eyes->pixels;
6f0bc179771c Numerous bug fixes that keep testeyes from crashing and dying.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4785
diff changeset
   164
	pitch = eyes->pitch;
6f0bc179771c Numerous bug fixes that keep testeyes from crashing and dying.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4785
diff changeset
   165
	for(int y=0;y<eyes_height;y++)
6f0bc179771c Numerous bug fixes that keep testeyes from crashing and dying.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4785
diff changeset
   166
		for(int x=0;x<eyes_width;x++) {
6f0bc179771c Numerous bug fixes that keep testeyes from crashing and dying.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4785
diff changeset
   167
			Uint8 brightness = *(Uint8*)(eyes_bits+(eyes_width/8)*y+(x/8)) & (1 << (7 - x % 8)) ? 255 : 0;
6f0bc179771c Numerous bug fixes that keep testeyes from crashing and dying.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4785
diff changeset
   168
			*(Uint16*)(pixels+pitch*y+x*16/8) = SDL_MapRGBA(eyes->format,brightness,brightness,brightness,255);
6f0bc179771c Numerous bug fixes that keep testeyes from crashing and dying.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4785
diff changeset
   169
		}
6f0bc179771c Numerous bug fixes that keep testeyes from crashing and dying.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4785
diff changeset
   170
	if(SDL_MUSTLOCK(eyes))
6f0bc179771c Numerous bug fixes that keep testeyes from crashing and dying.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4785
diff changeset
   171
		SDL_UnlockSurface(eyes);
4798
980614a70cfc Updated testeyes.c. It now shows some kind of gibberish Missingno-type picture somewhere on the screen and, possibly, hangs the window system. On the upside, the Missingno is definitely a non-rectangular window.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4795
diff changeset
   172
	SDL_Texture *eyes_texture = SDL_CreateTextureFromSurface(0,eyes);
4770
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
   173
	if(eyes_texture == NULL) {
4795
6f0bc179771c Numerous bug fixes that keep testeyes from crashing and dying.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4785
diff changeset
   174
		SDL_FreeSurface(eyes);
4770
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
   175
		SDL_DestroyRenderer(window);
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
   176
		SDL_DestroyWindow(window);
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
   177
		SDL_VideoQuit();
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
   178
		printf("Could not create eyes texture.\n");
4795
6f0bc179771c Numerous bug fixes that keep testeyes from crashing and dying.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4785
diff changeset
   179
		exit(-5);
4770
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
   180
	}
4795
6f0bc179771c Numerous bug fixes that keep testeyes from crashing and dying.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4785
diff changeset
   181
4785
ef8b32ef9793 Updated test code, updated win32 code a bit (still not complete, but hopefully tonight), and removed the last vestiges of ellipse and polygon drawing support.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4770
diff changeset
   182
	SDL_PixelFormatEnumToMasks(SDL_PIXELFORMAT_ARGB4444,&bpp,&r,&g,&b,&a);
ef8b32ef9793 Updated test code, updated win32 code a bit (still not complete, but hopefully tonight), and removed the last vestiges of ellipse and polygon drawing support.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4770
diff changeset
   183
	SDL_Surface *mask = SDL_CreateRGBSurface(0,eyesmask_width,eyesmask_height,bpp,r,g,b,a);
ef8b32ef9793 Updated test code, updated win32 code a bit (still not complete, but hopefully tonight), and removed the last vestiges of ellipse and polygon drawing support.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4770
diff changeset
   184
	if(mask == NULL) {
4770
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
   185
		SDL_DestroyTexture(eyes_texture);
4795
6f0bc179771c Numerous bug fixes that keep testeyes from crashing and dying.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4785
diff changeset
   186
		SDL_FreeSurface(eyes);
4770
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
   187
		SDL_DestroyRenderer(window);
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
   188
		SDL_DestroyWindow(window);
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
   189
		SDL_VideoQuit();
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
   190
		printf("Could not create shape mask texture.\n");
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
   191
		exit(-5);
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
   192
	}
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
   193
	
4785
ef8b32ef9793 Updated test code, updated win32 code a bit (still not complete, but hopefully tonight), and removed the last vestiges of ellipse and polygon drawing support.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4770
diff changeset
   194
	if(SDL_MUSTLOCK(mask))
ef8b32ef9793 Updated test code, updated win32 code a bit (still not complete, but hopefully tonight), and removed the last vestiges of ellipse and polygon drawing support.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4770
diff changeset
   195
		SDL_LockSurface(mask);
ef8b32ef9793 Updated test code, updated win32 code a bit (still not complete, but hopefully tonight), and removed the last vestiges of ellipse and polygon drawing support.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4770
diff changeset
   196
	pixels = mask->pixels;
4795
6f0bc179771c Numerous bug fixes that keep testeyes from crashing and dying.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4785
diff changeset
   197
	pitch = mask->pitch;
4785
ef8b32ef9793 Updated test code, updated win32 code a bit (still not complete, but hopefully tonight), and removed the last vestiges of ellipse and polygon drawing support.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4770
diff changeset
   198
	for(int y=0;y<eyesmask_height;y++)
ef8b32ef9793 Updated test code, updated win32 code a bit (still not complete, but hopefully tonight), and removed the last vestiges of ellipse and polygon drawing support.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4770
diff changeset
   199
		for(int x=0;x<eyesmask_width;x++) {
ef8b32ef9793 Updated test code, updated win32 code a bit (still not complete, but hopefully tonight), and removed the last vestiges of ellipse and polygon drawing support.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4770
diff changeset
   200
			Uint8 alpha = *(Uint8*)(eyesmask_bits+(eyesmask_width/8)*y+(x/8)) & (1 << (7 - x % 8)) ? 1 : 0;
ef8b32ef9793 Updated test code, updated win32 code a bit (still not complete, but hopefully tonight), and removed the last vestiges of ellipse and polygon drawing support.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4770
diff changeset
   201
			*(Uint16*)(pixels+pitch*y+x*bpp/8) = SDL_MapRGBA(mask->format,0,0,0,alpha);
ef8b32ef9793 Updated test code, updated win32 code a bit (still not complete, but hopefully tonight), and removed the last vestiges of ellipse and polygon drawing support.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4770
diff changeset
   202
		}
ef8b32ef9793 Updated test code, updated win32 code a bit (still not complete, but hopefully tonight), and removed the last vestiges of ellipse and polygon drawing support.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4770
diff changeset
   203
	if(SDL_MUSTLOCK(mask))
ef8b32ef9793 Updated test code, updated win32 code a bit (still not complete, but hopefully tonight), and removed the last vestiges of ellipse and polygon drawing support.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4770
diff changeset
   204
		SDL_UnlockSurface(mask);
4770
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
   205
	
4785
ef8b32ef9793 Updated test code, updated win32 code a bit (still not complete, but hopefully tonight), and removed the last vestiges of ellipse and polygon drawing support.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4770
diff changeset
   206
	SDL_WindowShapeMode mode = {ShapeModeDefault,1};
ef8b32ef9793 Updated test code, updated win32 code a bit (still not complete, but hopefully tonight), and removed the last vestiges of ellipse and polygon drawing support.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4770
diff changeset
   207
	SDL_SetWindowShape(window,mask,&mode);
4770
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
   208
	
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
   209
	SDL_Event event;
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
   210
	int event_pending = 0;
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
   211
	event_pending = SDL_PollEvent(&event);
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
   212
	SDL_Point mouse_position;
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
   213
	Pupil_Pair pupil_positions;
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
   214
	SDL_SelectMouse(0);
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
   215
	SDL_GetMouseState(&mouse_position.x,&mouse_position.y);
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
   216
	pupil_positions = compute_pupil_positions(mouse_position);
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
   217
	while(event.type != SDL_QUIT) {
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
   218
		if(event.type == SDL_MOUSEMOTION) {
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
   219
			mouse_position.x = event.motion.x;
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
   220
			mouse_position.y = event.motion.y;
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
   221
			pupil_positions = compute_pupil_positions(mouse_position);
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
   222
		}
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
   223
		render_eyes(window,eyes_texture,pupil_positions);
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
   224
		event_pending = SDL_PollEvent(&event);
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
   225
	}
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
   226
	
4785
ef8b32ef9793 Updated test code, updated win32 code a bit (still not complete, but hopefully tonight), and removed the last vestiges of ellipse and polygon drawing support.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4770
diff changeset
   227
	SDL_FreeSurface(mask);
ef8b32ef9793 Updated test code, updated win32 code a bit (still not complete, but hopefully tonight), and removed the last vestiges of ellipse and polygon drawing support.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4770
diff changeset
   228
	SDL_DestroyTexture(eyes_texture);
ef8b32ef9793 Updated test code, updated win32 code a bit (still not complete, but hopefully tonight), and removed the last vestiges of ellipse and polygon drawing support.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4770
diff changeset
   229
	SDL_DestroyWindow(window);
4770
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
   230
	//Call SDL_VideoQuit() before quitting.
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
   231
	SDL_VideoQuit();
cf7976fd3258 Moved the SDL_Eyes test program for shaped windows into the Hg repository and got it building and linking as a test.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
   232
}