-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
92 lines (68 loc) · 2.04 KB
/
main.cpp
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
#include <SDL/SDL.h>
#include "randistrs.h"
#include "mtwist.h"
#include "buttons.h"
int main(int args, char *argv[]) {
// Init
mt_seed();
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER);
TTF_Init();
TTF_Font* f = TTF_OpenFont("courier_noir.ttf", 40);
SDL_Surface* screen;
screen = SDL_SetVideoMode(800, 600, 32, SDL_SWSURFACE);
SDL_WM_SetCaption("Buttonset by Bob Rubbens", NULL);
bool quit = false;
int draw = 0;
SDL_Event event;
// cButton b(f, "TEST", 300, 300, B_MOUT, DIR_LEFT, 1000, SDL_MapRGB(screen->format, 0, 0, 0), SDL_MapRGB(screen->format, 128, 128, 128), screen->format);
cButtonSet b(f, true, B_MIN, 100, 100, 50, 50, 1000, 500, DIR_LEFT, SDL_MapRGB(screen->format, 0, 0, 0), SDL_MapRGB(screen->format, 128, 128, 128), screen->format);
b.addB("Add Button");
b.addB("Quit");
SDL_Rect t;
t.x = 0;
t.y = t.x;
t.w = 10;
t.h = t.w;
std::string caption = "Deactivate";
// Game loop
while (!quit) {
// Input handling
while (SDL_PollEvent(&event)) {
b.handleEvents(&event);
switch (event.type) {
case SDL_QUIT: // User x's out
quit = true;
break;
case SDL_KEYDOWN: // ESCAPE terminates program
if (event.key.keysym.sym == SDLK_ESCAPE) {
quit = true;
}
break;
}
}
if (b.gPressed() == 1) {
b.addB(caption);
caption = "Activate";
}
if (b.gPressed() == 2) {
quit = true;
}
if (b.gPressed() == 3) {
b.off(3, true);
}
if (b.gReleased() == 4) {
b.on(3, false);
}
// Logic
b.logic();
// Rendering
SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 255, 255, 255));
b.render(screen);
SDL_Flip(screen);
}
// Exit
TTF_CloseFont(f);
TTF_Quit();
SDL_Quit();
return 0;
}