]> Shamusworld >> Repos - apple2/blob - src/gui/element.h
Moved stuff into trunk (part 2)...
[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 <list>
17 #include "types.h"
18
19 class Element
20 {
21         public:
22                 Element(uint32 x = 0, uint32 y = 0, uint32 w = 0, uint32 h = 0,
23                         Element * parentElement = NULL);
24                 Element(uint32 x, uint32 y, uint32 w, uint32 h,
25                         uint8 fgR = 0xFF, uint8 fgG = 0xFF, uint8 fgB = 0xFF, uint8 fgA = 0xFF,
26                         uint8 bgR = 0x00, uint8 bgG = 0x00, uint8 bgB = 0x00, uint8 bgA = 0xFF,
27                         Element * parentElement = NULL);
28                 virtual ~Element();                                                     // Destructor cannot be pure virtual...
29                 virtual void HandleKey(SDLKey key) = 0;         // These are "pure" virtual functions...
30                 virtual void HandleMouseMove(uint32 x, uint32 y) = 0;
31                 virtual void HandleMouseButton(uint32 x, uint32 y, bool mouseDown) = 0;
32                 virtual void Draw(void) = 0;
33                 virtual void Notify(Element *) = 0;
34                 bool Inside(uint32 x, uint32 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                 // Class methods...
50                 static void SetScreen(SDL_Surface *);
51                 static bool ScreenNeedsRefreshing(void);
52                 static void ScreenWasRefreshed(void);
53
54         protected:
55                 SDL_Rect extents;
56                 uint32 state;
57                 Element * parent;
58                 uint32 fgColor;
59                 uint32 bgColor;
60                 SDL_Surface * backstore;
61                 std::list<SDL_Rect> coverList;
62
63                 // Class variables...
64                 static SDL_Surface * screen;
65                 static bool needToRefreshScreen;
66 };
67
68 #endif  // __ELEMENT_H__