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 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (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, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 * 21 */ 22 23 #ifndef TITANIC_PET_SLIDER_H 24 #define TITANIC_PET_SLIDER_H 25 26 #include "titanic/support/rect.h" 27 #include "titanic/support/string.h" 28 #include "titanic/core/game_object.h" 29 30 namespace Titanic { 31 32 enum SliderOrientation { ORIENTATION_HORIZONTAL = 1, ORIENTATION_VERTICAL = 2 }; 33 34 class CPetControl; 35 36 class CPetSlider { 37 private: 38 int _orientation; 39 Rect _bounds; 40 Rect _slidingRect; 41 int _thumbWidth; 42 int _thumbHeight; 43 int _sliderOffset; 44 bool _thumbFocused; 45 Rect _dirtyArea; 46 private: 47 /** 48 * Center the center position of the slider's thumb 49 */ 50 Point getThumbCentroidPos() const; 51 52 /** 53 * Returns true if the passed point is within the thumb 54 */ 55 bool thumbContains(const Point &pt) const; 56 57 /** 58 * Gets the area the slider's thumbnail covers 59 */ 60 Rect getThumbRect() const; 61 62 /** 63 * Calculates the slider offset at the specificed position 64 */ 65 int calcSliderOffset(const Point &pt) const; 66 protected: 67 /** 68 * Get the position to draw the background at 69 */ 70 Point getBackgroundDrawPos(); 71 72 /** 73 * Get the position to draw the slider thumbnail at 74 */ 75 Point getThumbDrawPos(); 76 77 /** 78 * Returns true if the passed point falls within the slider's bounds 79 */ containsPt(const Point & pt)80 bool containsPt(const Point &pt) const { return _bounds.contains(pt); } 81 public: 82 CPetSlider(); ~CPetSlider()83 virtual ~CPetSlider() {} 84 85 /** 86 * Setup the background 87 */ setupBackground(const CString & name,CPetControl * petControl)88 virtual void setupBackground(const CString &name, CPetControl *petControl) {} 89 90 /** 91 * Setup the thumb 92 */ setupThumb(const CString & name,CPetControl * petControl)93 virtual void setupThumb(const CString &name, CPetControl *petControl) {} 94 95 /** 96 * Setup the background 97 */ setupBackground2(const CString & name,CPetControl * petControl)98 virtual void setupBackground2(const CString &name, CPetControl *petControl) {} 99 100 /** 101 * Setup the thumb 102 */ setupThumb2(const CString & name,CPetControl * petControl)103 virtual void setupThumb2(const CString &name, CPetControl *petControl) {} 104 105 /** 106 * Reset the slider 107 */ reset(const CString & name)108 virtual void reset(const CString &name) {} 109 110 /** 111 * Draw the slider 112 */ draw(CScreenManager * screenManager)113 virtual void draw(CScreenManager *screenManager) {} 114 115 /** 116 * Reset the dirty area 117 */ 118 virtual Rect clearDirtyArea(); 119 120 /** 121 * Checks whether the slider is highlighted 122 */ 123 virtual bool checkThumb(const Point &pt); 124 125 /** 126 * Resets the thumb focused flag 127 */ 128 virtual bool resetThumbFocus(); 129 130 /** 131 * Handles dragging the slider 132 */ 133 virtual bool MouseDragMoveMsg(const Point &pt); 134 135 /** 136 * Called when a slider drag ends 137 */ MouseDragEndMsg(const Point & pt)138 virtual bool MouseDragEndMsg(const Point &pt) { return true; } 139 140 /** 141 * Handles mouse button up messaes 142 */ 143 virtual bool MouseButtonUpMsg(const Point &pt); 144 proc13()145 virtual bool proc13() { return false; } proc14()146 virtual bool proc14() { return false; } 147 148 149 virtual bool contains(const Point &pt) const; 150 151 /** 152 * Returns the slider offset in pixels 153 */ 154 virtual double getOffsetPixels() const; 155 156 /** 157 * Sets the slider offset 158 */ 159 virtual void setSliderOffset(double offset); 160 161 /** 162 * Set a new slider offset in pixels 163 */ 164 virtual void setOffsetPixels(int offset); 165 166 /** 167 * Enables a given orientation 168 */ 169 void setOrientation(SliderOrientation orientation); 170 171 /** 172 * Set the bounds for the slider 173 */ setBounds(const Rect & r)174 void setBounds(const Rect &r) { _bounds = r; } 175 176 /** 177 * Set the sliding bounds for the slider 178 */ setSlidingBounds(const Rect & r)179 void setSlidingBounds(const Rect &r) { _slidingRect = r; } 180 181 /** 182 * Set the size of the slider thumb 183 */ setThumbSize(const Point & pt)184 void setThumbSize(const Point &pt) { 185 _thumbWidth = pt.x; 186 _thumbHeight = pt.y; 187 } 188 189 /** 190 * Move the slider 191 */ translate(const Point & pt)192 void translate(const Point &pt) { 193 _bounds.translate(pt.x, pt.y); 194 _slidingRect.translate(pt.x, pt.y); 195 } 196 197 /** 198 * Change the current position of a slider by a step amount 199 */ 200 void stepPosition(int direction); 201 }; 202 203 class CPetSoundSlider : public CPetSlider { 204 public: 205 CGameObject *_background; 206 CGameObject *_thumb; 207 public: CPetSoundSlider()208 CPetSoundSlider() : CPetSlider(), _background(nullptr), 209 _thumb(0) {} 210 211 /** 212 * Setup the background 213 */ 214 virtual void setupBackground(const CString &name, CPetControl *petControl); 215 216 /** 217 * Setup the thumb 218 */ 219 virtual void setupThumb(const CString &name, CPetControl *petControl); 220 221 /** 222 * Setup the background 223 */ 224 virtual void setupBackground2(const CString &name, CPetControl *petControl); 225 226 /** 227 * Setup the thumb 228 */ 229 virtual void setupThumb2(const CString &name, CPetControl *petControl); 230 231 /** 232 * Draw the slider 233 */ 234 virtual void draw(CScreenManager *screenManager); 235 }; 236 237 } // End of namespace Titanic 238 239 #endif /* TITANIC_PET_SLIDER_H */ 240