]> Shamusworld >> Repos - apple2/blob - src/gui/elements.h
First steps towards making config window/settings stick.
[apple2] / src / gui / elements.h
1 #ifndef __ELEMENTS_H__
2 #define __ELEMENTS_H__
3
4 #include <SDL2/SDL.h>
5 #include <stdint.h>
6 #include "font10pt.h"
7
8 enum ObjectType { OTNone = 0, OTCheckBox, OTLineEdit, OTDraggable, OTCount };
9
10 #define OBJECT_COMMON \
11         int type;         \
12         SDL_Rect r;       \
13         bool hovered;
14
15 struct Object {
16         OBJECT_COMMON;
17 };
18
19 struct CheckBox {
20         OBJECT_COMMON;
21         bool * state;
22         const char * text;
23
24         CheckBox(): type(OTCheckBox), hovered(false), state(0), text(0) { r.x = r.y = 0; }
25         CheckBox(int32_t xx, int32_t yy, bool * s = 0, const char * t = 0): type(OTCheckBox), hovered(false), state(s), text(t) { r.x = xx; r.y = yy; }
26 };
27
28 struct LineEdit {
29         OBJECT_COMMON;
30         char * text;
31         uint8_t size;
32         const char * label;
33
34         LineEdit(): type(OTLineEdit), hovered(false), text(0), size(12), label(0) { r.x = r.y = 0; }
35         LineEdit(int32_t xx, int32_t yy, char * t = 0, uint8_t sz = 12, const char * lb = 0): type(OTLineEdit), hovered(false), text(t), size(sz), label(lb) { r.x = xx; r.y = yy; }
36 };
37
38 struct Draggable {
39         OBJECT_COMMON;
40         uint8_t * spot;
41         int32_t homex, homey;
42         bool dragging;
43         SDL_Texture * img;
44         SDL_Rect dest;
45
46         Draggable(): type(OTDraggable), hovered(false), spot(0), homex(0), homey(0), dragging(false), img(0) { r.x = r.y = r.w = r.h = 0; }
47         Draggable(int32_t xx, int32_t yy, int32_t w, int32_t h, uint8_t * s = 0, SDL_Texture * i = 0): type(OTDraggable), hovered(false), spot(s), homex(xx), homey(yy), dragging(false), img(i)
48         {
49                 r.x = xx;
50                 r.y = yy;
51                 r.w = w;
52                 r.h = h;
53
54                 if ((s) && (*s != 0))
55                 {
56                         r.x = 120;
57                         r.y = (7 + *(spot)) * FONT_HEIGHT;
58                 }
59         }
60 };
61
62 #endif  // __ELEMENTS_H__
63