summaryrefslogtreecommitdiff
path: root/src/mansdl-checkEvent.cc
blob: 8f6988b9471e939dd59011d4b625d26216615c02 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/* Include libraries */
#include <SDL2/SDL.h>

/* Include header files */
#include "fractData.hh"
#include "mansdl.hh"

void mansdl::checkEvent(fractData* fd, SDL_Event* event) {
	const Uint8* keyState = SDL_GetKeyboardState(NULL);
	bool         ctrl     = keyState[SDL_SCANCODE_LCTRL] || keyState[SDL_SCANCODE_RCTRL];

	switch(event->type) {
		case SDL_QUIT:
			quit = true;
			break;

		case SDL_MOUSEWHEEL:
			if(event->wheel.y > 0) {
				switch(ctrl) {
					case true: {
						unsigned int result = fd->maxIter * 2;

						if(result > 2) {
							fd->maxIter = result;

							doGenerate = true;
						}

						break;
					}

					case false:
						fd->zoom = fd->zoom * 1.25;
						doGenerate = true;
						break;
				}
			} else if(event->wheel.y < 0) {
				switch(ctrl) {
					case true: {
						unsigned int result = fd->maxIter / 2;

						if(result >= 2) {
							fd->maxIter = result;
							doGenerate = true;
						}

						break;
					}

					case false:
						fd->zoom = fd->zoom / 1.25;
						doGenerate = true;
						break;
				}
			}

			break;

		case SDL_KEYDOWN:
			switch(ctrl) {
				case true:
					if(keyState[SDL_SCANCODE_X])
						quit = true;

					if(fd->fract == julia) {
						if(keyState[SDL_SCANCODE_W]) {
							fd->julia_imag = fd->julia_imag - 0.005;
							doGenerate = true;
						} if(keyState[SDL_SCANCODE_S]) {
							fd->julia_imag = fd->julia_imag + 0.005;
							doGenerate = true;
						} if(keyState[SDL_SCANCODE_A]) {
							fd->julia_real = fd->julia_real - 0.005;
							doGenerate = true;
						} if(keyState[SDL_SCANCODE_D]) {
							fd->julia_real = fd->julia_real + 0.005;
							doGenerate = true;
						}
					}

					break;

				case false:
					if(keyState[SDL_SCANCODE_A]) {
						fd->real = fd->real - 0.1 / fd->zoom;
						doGenerate = true;
					} if(keyState[SDL_SCANCODE_D]) {
						fd->real = fd->real + 0.1 / fd->zoom;
						doGenerate = true;
					} if(keyState[SDL_SCANCODE_W]) {
						fd->imag = fd->imag - 0.1 / fd->zoom;
						doGenerate = true;
					} if(keyState[SDL_SCANCODE_S]) {
						fd->imag = fd->imag + 0.1 / fd->zoom;
						doGenerate = true;
					}

					break;
			}

			break;
	}
}