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
|
/* c-basic-offset: 2; tab-width: 2; indent-tabs-mode: nil
* vi: set shiftwidth=2 tabstop=2 expandtab:
* :indentSize=2:tabSize=2:noTabs=true:
*/
#ifndef __H_GAME_BUTTON__
#define __H_GAME_BUTTON__
/*
* This file, as the rest of the project is under MIT license.
* see http://opensource.org/licenses/MIT
*
* Author Gustav Hartvigsson <gustav.hartvigsson _at_ gmail.com> 2014
*/
#include <SDL2/SDL.h>
#include <stdbool.h>
#include "MousePointer.h"
typedef struct GameButton GameButton; // hack to make the callback work...
typedef void (* BtnCallback)(GameButton * self, void * data);
typedef struct GameButton {
SDL_Rect base; //this will behave like an SDL_Rect when cast to an SDL_Rect.
bool fill;
bool is_clicked;
bool is_hover;
bool is_stop_hover;
SDL_Color colour;
BtnCallback clicked;
void * clicked_data;
BtnCallback hover;
void * hover_data;
BtnCallback stop_hover;
void * stop_hover_data;
} GameButton;
typedef void (* BtnCallback)(GameButton * self, void * data);
GameButton * game_button_new (int x, int y, int h, int w);
bool game_button_check_clicked (GameButton * self, MousePointer * pointer);
bool game_button_check_hover (GameButton * self, MousePointer * pointer);
void game_button_set_callback (GameButton * self,
const char * name,
BtnCallback callback,
void * data);
void game_button_do_callback (GameButton * self,
const char * name);
void game_button_draw (GameButton * self, SDL_Renderer * renderer);
void game_button_set_fill (GameButton * self, bool fill);
void game_button_free (GameButton * self);
#endif
|