1 //=============================================================================
2 //
3 // Adventure Game Studio (AGS)
4 //
5 // Copyright (C) 1999-2011 Chris Jones and 2011-20xx others
6 // The full list of copyright holders can be found in the Copyright.txt
7 // file, which is part of this source code distribution.
8 //
9 // The AGS source code is provided under the Artistic License 2.0.
10 // A copy of this license can be found in the file License.txt and at
11 // http://www.opensource.org/licenses/artistic-license-2.0.php
12 //
13 //=============================================================================
14 
15 #ifndef __AC_GUIOBJECT_H
16 #define __AC_GUIOBJECT_H
17 
18 #include "core/types.h"
19 #include "gfx/bitmap.h"
20 #include "gui/guidefines.h"
21 #include "util/string.h"
22 
23 namespace AGS { namespace Common { class Stream; } }
24 using namespace AGS; // FIXME later
25 
26 #define GUIDIS_GREYOUT   1
27 #define GUIDIS_BLACKOUT  2
28 #define GUIDIS_UNCHANGED 4
29 #define GUIDIS_GUIOFF  0x80
30 
31 #define BASEGOBJ_SIZE 7
32 #define GALIGN_LEFT   0
33 #define GALIGN_RIGHT  1
34 #define GALIGN_CENTRE 2
35 
36 struct GUIObject
37 {
38   int guin, objn;    // gui and object number of this object
39   unsigned int flags;
40   int x, y;
41   int wid, hit;
42   int zorder;
43   int activated;
44   Common::String scriptName;
45   Common::String eventHandlers[MAX_GUIOBJ_EVENTS];
46 
47   GUIObject();
~GUIObjectGUIObject48   virtual ~GUIObject(){}
49   virtual void MouseMove(int, int) = 0; // x,y relative to gui
50   virtual void MouseOver() = 0; // mouse moves onto object
51   virtual void MouseLeave() = 0;        // mouse moves off object
MouseDownGUIObject52   virtual int  MouseDown() { // button down - return 1 to lock focus
53     return 0;
54   }
55   virtual void MouseUp() = 0;   // button up
56   virtual void KeyPress(int) = 0;
57   virtual void Draw(Common::Bitmap *ds) = 0;
58   // overridable routine to determine whether the mouse is over
59   // the control
IsOverControlGUIObject60   virtual int  IsOverControl(int p_x, int p_y, int p_extra) {
61     if ((p_x >= x) && (p_y >= y) && (p_x < x + wid + p_extra) && (p_y < y + hit + p_extra))
62       return 1;
63     return 0;
64   }
65   virtual void WriteToFile(Common::Stream *out);
66   virtual void ReadFromFile(Common::Stream *in, GuiVersion gui_version);
67   // called when the control is resized
ResizedGUIObject68   virtual void Resized() { }
GetNumEventsGUIObject69   virtual int  GetNumEvents() {
70     return numSupportedEvents;
71   }
GetEventNameGUIObject72   virtual const char *GetEventName(int idx) {
73     if ((idx < 0) || (idx >= numSupportedEvents))
74       return NULL;
75     return supportedEvents[idx];
76   }
GetEventArgsGUIObject77   virtual const char *GetEventArgs(int idx) {
78     if ((idx < 0) || (idx >= numSupportedEvents))
79       return NULL;
80     return supportedEventArgs[idx];
81   }
82   void init();
83 
IsDeletedGUIObject84   int IsDeleted() {
85     return flags & GUIF_DELETED;
86   }
87   int IsDisabled();
EnableGUIObject88   void Enable() {
89     flags &= ~GUIF_DISABLED;
90   }
DisableGUIObject91   void Disable() {
92     flags |= GUIF_DISABLED;
93   }
IsVisibleGUIObject94   int IsVisible() {
95     if (flags & GUIF_INVISIBLE)
96       return 0;
97     return 1;
98   }
ShowGUIObject99   void Show() {
100     flags &= ~GUIF_INVISIBLE;
101   }
HideGUIObject102   void Hide() {
103     flags |= GUIF_INVISIBLE;
104   }
105   int IsClickable();
SetClickableGUIObject106   void SetClickable(bool newValue) {
107     flags &= ~GUIF_NOCLICKS;
108     if (!newValue)
109       flags |= GUIF_NOCLICKS;
110   }
111 
IsTranslatedGUIObject112   inline bool IsTranslated() const
113   {
114      return (flags & GUIF_TRANSLATED) != 0;
115   }
116 
117 protected:
118   const char *supportedEvents[MAX_GUIOBJ_EVENTS];
119   const char *supportedEventArgs[MAX_GUIOBJ_EVENTS];
120   int numSupportedEvents;
121 };
122 
123 #endif // __AC_GUIOBJECT_H
124