]> Shamusworld >> Repos - apple2/blob - apple2/src/gui/element.h
a53d0011d7b85584792171eec856ee7068529291
[apple2] / 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 <SDL.h>
16 #include "types.h"
17
18 class Element
19 {
20         public:
21                 Element(uint32 x = 0, uint32 y = 0, uint32 w = 0, uint32 h = 0,
22                         Element * parentElement = NULL);
23                 Element(uint32 x, uint32 y, uint32 w, uint32 h,
24                         uint8 fgR = 0xFF, uint8 fgG = 0xFF, uint8 fgB = 0xFF, uint8 fgA = 0xFF,
25                         uint8 bgR = 0x00, uint8 bgG = 0x00, uint8 bgB = 0x00, uint8 bgA = 0xFF,
26                         Element * parentElement = NULL);
27                 virtual ~Element();                                                     // Destructor cannot be pure virtual...
28                 virtual void HandleKey(SDLKey key) = 0;         // These are "pure" virtual functions...
29                 virtual void HandleMouseMove(uint32 x, uint32 y) = 0;
30                 virtual void HandleMouseButton(uint32 x, uint32 y, bool mouseDown) = 0;
31                 virtual void Draw(void) = 0;
32                 virtual void Notify(Element *) = 0;
33                 bool Inside(uint32 x, uint32 y);
34 //Badly named, though we may code something that does this...
35 //              SDL_Rect GetParentCorner(void);
36                 SDL_Rect GetScreenCoords(void);
37 #if 0
38 //May use this in the future...
39                 SDL_Rect GetParentRect(void);
40 #endif
41                 void CreateBackstore(void);
42                 void RestoreScreenFromBackstore(void);
43                 // Class methods...
44                 static void SetScreen(SDL_Surface *);
45                 static bool ScreenNeedsRefreshing(void);
46                 static void ScreenWasRefreshed(void);
47
48         protected:
49                 SDL_Rect extents;
50                 uint32 state;
51                 Element * parent;
52                 uint32 fgColor;
53                 uint32 bgColor;
54                 SDL_Surface * backstore;
55
56                 // Class variables...
57                 static SDL_Surface * screen;
58                 static bool needToRefreshScreen;
59 };
60
61 #endif  // __ELEMENT_H__