]> Shamusworld >> Repos - apple2/blob - src/gui/element.h
e3ad812e309ddb89beb6113e621faaf3d047305e
[apple2] / src / gui / element.h
1 //
2 // ELEMENT.H
3 //
4 // Graphical User Interface base class
5 // All GUI elements are derived from this base class.
6 //
7
8 #ifndef __ELEMENT_H__
9 #define __ELEMENT_H__
10
11 // These are various GUI messages that can be sent to the SDL event handler
12
13 enum { WINDOW_CLOSE, MENU_ITEM_CHOSEN, SCREEN_REFRESH_NEEDED };
14
15 #include <SDL2/SDL.h>
16 #include <list>
17 #include <stdint.h>
18
19 class Element
20 {
21         public:
22                 Element(uint32_t x = 0, uint32_t y = 0, uint32_t w = 0, uint32_t h = 0,
23                         Element * parentElement = NULL);
24                 Element(uint32_t x, uint32_t y, uint32_t w, uint32_t h,
25                         uint8_t fgR = 0xFF, uint8_t fgG = 0xFF, uint8_t fgB = 0xFF, uint8_t fgA = 0xFF,
26                         uint8_t bgR = 0x00, uint8_t bgG = 0x00, uint8_t bgB = 0x00, uint8_t bgA = 0xFF,
27                         Element * parentElement = NULL);
28                 virtual ~Element();                                                     // Destructor cannot be pure virtual...
29                 virtual void HandleKey(SDL_Scancode key) = 0;           // These are "pure" virtual functions...
30                 virtual void HandleMouseMove(uint32_t x, uint32_t y) = 0;
31                 virtual void HandleMouseButton(uint32_t x, uint32_t y, bool mouseDown) = 0;
32                 virtual void Draw(void) = 0;
33                 virtual void Notify(Element *) = 0;
34                 bool Inside(uint32_t x, uint32_t y);
35 //Badly named, though we may code something that does this...
36 //              SDL_Rect GetParentCorner(void);
37                 SDL_Rect GetScreenCoords(void);
38                 SDL_Rect GetExtents(void);
39 #if 1
40 //May use this in the future...
41                 SDL_Rect GetParentRect(void);
42 #endif
43                 void CreateBackstore(void);
44                 void RestoreScreenFromBackstore(void);
45                 void SaveScreenToBackstore(void);
46                 void ResetCoverageList(void);
47 //Need something to prevent this on Elements that don't have mouseover effects...
48                 void AdjustCoverageList(SDL_Rect r);
49                 void SetVisible(bool);
50                 // Class methods...
51                 static void SetScreen(SDL_Surface *);
52                 static bool ScreenNeedsRefreshing(void);
53                 static void ScreenWasRefreshed(void);
54
55         protected:
56                 SDL_Rect extents;
57                 uint32_t state;
58                 Element * parent;
59                 uint32_t fgColor;
60                 uint32_t bgColor;
61                 SDL_Surface * backstore;
62                 std::list<SDL_Rect> coverList;
63                 bool visible;
64
65                 // Class variables...
66                 static SDL_Surface * screen;
67                 static bool needToRefreshScreen;
68 };
69
70 #endif  // __ELEMENT_H__