ScummVM API documentation
te_button_layout.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef TETRAEDGE_TE_TE_BUTTON_LAYOUT_H
23 #define TETRAEDGE_TE_TE_BUTTON_LAYOUT_H
24 
25 #include "tetraedge/te/te_callback.h"
26 #include "tetraedge/te/te_layout.h"
27 #include "tetraedge/te/te_signal.h"
28 #include "tetraedge/te/te_timer.h"
29 
30 #include "common/path.h"
31 
32 namespace Common {
33 struct Point;
34 }
35 
36 namespace Tetraedge {
37 
38 class TeButtonLayout : public TeLayout {
39 public:
41 
42  virtual ~TeButtonLayout();
43 
44  enum State {
45  BUTTON_STATE_UP = 0,
46  BUTTON_STATE_DOWN = 1,
47  BUTTON_STATE_DISABLED = 2,
48  BUTTON_STATE_ROLLOVER = 3
49  };
50 
51  uint64 doubleValidationProtectionTimeoutTime() { return 500; }
52  uint64 frozenValidationTimeoutTime() { return 500; }
53 
54  virtual bool isMouseIn(const TeVector2s32 &mouseloc) override;
55  bool onMouseLeftDown(const Common::Point &pt);
56  bool onMouseLeftDownMaxPriority(const Common::Point &pt) { return false; }
57  bool onMouseLeftUp(const Common::Point &pt);
58  bool onMouseLeftUpMaxPriority(const Common::Point &pt) { return false; }
59  bool onMousePositionChanged(const Common::Point &pt);
60  bool onMousePositionChangedMaxPriority(const Common::Point &pt) {
61  _mousePositionChangedCatched = false;
62  return false;
63  }
64 
65  void reset();
66 
67  void resetTimeFromLastValidation();
68  uint64 timeFromLastValidation();
69 
70  void setDisabledLayout(TeLayout *disabledLayout);
71  void setHitZone(TeLayout *hitZoneLayout);
72  void setDownLayout(TeLayout *downLayout);
73  void setRollOverLayout(TeLayout *rollOverLayout);
74  void setUpLayout(TeLayout *upLayout);
75 
76  void setDoubleValidationProtectionEnabled(bool enable);
77  void setEnable(bool enable);
78  virtual void setPosition(const TeVector3f32 &pos) override;
79 
80  void setClickPassThrough(bool val) {
81  _clickPassThrough = val;
82  }
83  void setValidationSound(const Common::Path &val) {
84  _validationSound = val;
85  }
86  void setValidationSoundVolume(float val) {
87  _validationSoundVolume = val;
88  }
89 
90  void setState(State newState);
91  State state() const { return _currentState; };
92 
93  TeSignal0Param &onMouseClickValidated() { return _onMouseClickValidatedSignal; };
94  TeSignal0Param &onButtonChangedToStateUpSignal() { return _onButtonChangedToStateUpSignal; };
95  TeSignal0Param &onButtonChangedToStateDownSignal() { return _onButtonChangedToStateDownSignal; };
96  TeSignal0Param &onButtonChangedToStateRolloverSignal() { return _onButtonChangedToStateRolloverSignal; };
97 
98  TeLayout *upLayout() { return _upLayout; }
99  TeLayout *downLayout() { return _downLayout; }
100  void setIgnoreMouseEvents(bool val) { _ignoreMouseEvents = val; }
101 
102  // From TeSpriteButton, a direct way to load the images.
103  void load(const Common::Path &upImg, const Common::Path &downImg, const Common::Path &overImg);
104 
105 private:
106  static bool _mousePositionChangedCatched;
107  static TeTimer *getDoubleValidationProtectionTimer();
108  static TeTimer *_doubleValidationProtectionTimer;
109 
110  bool _doubleValidationProtectionEnabled;
111  bool _ignoreMouseEvents;
112  bool _ownedLayouts;
113 
114  bool _clickPassThrough;
115  State _currentState;
116  Common::Path _validationSound;
117  float _validationSoundVolume;
118 
119  Common::Array<uint> _intArr;
120 
121  TeICallback1ParamPtr<const Common::Point &> _onMousePositionChangedMaxPriorityCallback;
122  TeICallback1ParamPtr<const Common::Point &> _onMousePositionChangedCallback;
123  TeICallback1ParamPtr<const Common::Point &> _onMouseLeftDownCallback;
124  TeICallback1ParamPtr<const Common::Point &> _onMouseLeftUpMaxPriorityCallback;
125  TeICallback1ParamPtr<const Common::Point &> _onMouseLeftUpCallback;
126 
127  TeLayout *_rolloverLayout;
128  TeLayout *_disabledLayout;
129  TeLayout *_hitZoneLayout;
130  TeLayout *_upLayout;
131  TeLayout *_downLayout;
132 
133  TeSignal0Param _onMouseClickValidatedSignal;
134  TeSignal0Param _onButtonChangedToStateUpSignal;
135  TeSignal0Param _onButtonChangedToStateDownSignal;
136  TeSignal0Param _onButtonChangedToStateRolloverSignal;
137 };
138 
139 } // end namespace Tetraedge
140 
141 #endif // TETRAEDGE_TE_TE_BUTTON_LAYOUT_H
Definition: te_signal.h:40
Definition: detection.h:27
Definition: display_client.h:58
Definition: path.h:52
Definition: te_timer.h:33
Definition: te_button_layout.h:38
Definition: algorithm.h:29
Definition: te_layout.h:35
Definition: rect.h:45
Definition: te_vector2s32.h:31
Definition: te_vector3f32.h:33
Definition: ptr.h:159