-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbutton.h
52 lines (44 loc) · 1.32 KB
/
button.h
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
/*
* button.h
*
* Created on: 2017年12月12日
* Author: frank
*/
#ifndef BUTTON_H_
#define BUTTON_H_
#include "rgba.h"
#include "input/InputEvent.h"
#include "input/ActionEvent.h"
#include "enviroment.h"
typedef struct _button {
int x;
int y;
int width;
int height;
rgba *color;
rgba release_color;
rgba hover_color;
rgba press_color;
unsigned char state;
void (*actionListener)(ActionEvent *e);
} button;
#define BUTTON_STATE_RELEASED 0
#define BUTTON_STATE_HOVERED 1
#define BUTTON_STATE_PRESSED 2
#define BUTTON_DEFAULT_RELEASED_COLOR (GRAY)
#define BUTTON_DEFAULT_HOVERED_COLOR (LIGHT_GRAY)
#define BUTTON_DEFAULT_PRESSED_COLOR (DARK_GRAY)
button* createButton(int x, int y, int width, int height, rgba release_color,
rgba hover_color, rgba press_color);
button* createDefaultButton(int x, int y, int width, int height);
void drawButton(rgba *p, button *b);
void setButtonColorRGBA(button *b, int rgb, int alpha);
void setButtonColorRGB(button *b, int rgb);
void setButtonAlpha(button *b, int alpha);
void setActionListener(button *b, void (*actionListener)(ActionEvent *e));
void pressButton(button *b, InputEnent *e);
void hoverButton(button *b, InputEnent *e);
void releaseButton(button *b, InputEnent *e);
void exitButton(button *b, InputEnent *e);
bool inButton(button *b, int x, int y);
#endif /* BUTTON_H_ */