ScummVM API documentation
scrollbar.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 NANCY_UI_SCROLLBAR_H
23 #define NANCY_UI_SCROLLBAR_H
24 
25 #include "engines/nancy/renderobject.h"
26 
27 namespace Nancy {
28 
29 struct NancyInput;
30 
31 namespace UI {
32 
33 // Returns the number of pixels a single mouse wheel notch should scroll a view of
34 // the given height, so that scrolling advances by a fixed part of a page.
35 int wheelScrollPixels(int visibleHeight);
36 
37 // Same, expressed as a fraction of the total scroll range. Returns 0 when the
38 // content fits inside the viewport and thus cannot be scrolled.
39 float wheelScrollStep(int visibleHeight, int contentHeight);
40 
41 // Applies mouse wheel input to a [0, 1] scroll position, as long as the mouse is
42 // inside the hotspot. Consumes the wheel input and returns true if the position changed.
43 bool scrollWithMouseWheel(NancyInput &input, const Common::Rect &hotspot, float &scrollPos, float step);
44 
45 class Scrollbar : public RenderObject {
46 public:
47  Scrollbar(uint16 zOrder, const Common::Rect &srcBounds, const Common::Point &topPosition, uint16 scrollDistance, bool isVertical = true);
48  Scrollbar(uint16 zOrder, const Common::Rect &srcBounds, Graphics::ManagedSurface &srcSurf, const Common::Point &topPosition, uint16 scrollDistance, bool isVertical = true);
49  virtual ~Scrollbar() = default;
50 
51  void init() override;
52 
53  void handleInput(NancyInput &input);
54 
55  void resetPosition();
56  float getPos() const { return _currentPosition; }
57 
58  // The screen rect the thumb travels along. Unlike _screenPosition, which only
59  // covers the thumb itself, this covers the whole scrollbar.
60  Common::Rect getTrackRect() const;
61 
62  void setPosition(float pos);
63  void calculatePosition();
64 
65  Common::Point _startPosition;
66  uint _maxDist;
67  bool _isVertical;
68 
69  float _currentPosition;
70  bool _isClicked;
71  Common::Point _mousePosOnClick;
72 };
73 
74 } // End of namespace UI
75 } // End of namespace Nancy
76 
77 #endif // NANCY_UI_SCROLLBAR_H
Definition: managed_surface.h:51
Definition: rect.h:536
Definition: scrollbar.h:45
Definition: input.h:41
Definition: soundequalizerpuzzle.h:27
Definition: renderobject.h:36
Definition: rect.h:144
Definition: actionmanager.h:32