ScummVM API documentation
scrolltextbox.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_SCROLLTEXTBOX_H
23 #define NANCY_UI_SCROLLTEXTBOX_H
24 
25 #include "engines/nancy/commontypes.h"
26 #include "engines/nancy/misc/hypertext.h"
27 #include "engines/nancy/renderobject.h"
28 
29 namespace Nancy {
30 
31 struct NancyInput;
32 struct UIPopupHeader;
33 struct TBOX;
34 
35 namespace UI {
36 
37 // Nancy 10+ game text box: a UIPopupHeader overlay popup at the bottom of the
38 // screen for narration and inventory/timer captions. The header comes from UICO
39 // (Nancy 10) or SCTB (Nancy 11), which are structurally identical, so one widget
40 // serves both. Shows caption text only (no response hotspots; conversation
41 // dialogue uses ConversationPopup). The legacy Textbox forwards to it for
42 // Nancy 10+.
44 public:
45  ScrollTextBox();
46  ~ScrollTextBox() override = default;
47 
48  void init() override;
49  void registerGraphics() override;
50  void updateGraphics() override;
51  void handleInput(NancyInput &input);
52 
53  // Append a line of text. The popup is shown on the first non-empty
54  // addition. A non-zero autoClearTime schedules an automatic clear() after
55  // that many milliseconds (used by inventory closed captions).
56  void addTextLine(const Common::String &text, uint32 autoClearTime = 0);
57  void setOverrideFont(uint fontID);
58  // Nancy 10 only: pick the full box (AR 74) or the strip (AR 75). Ignored from
59  // Nancy 11 on, which picks by line count.
60  void setFullMode(bool fullMode);
61  // True while the full box is showing and covering the taskbar buttons.
62  bool coversTaskbar() const { return _isVisible && _expanded; }
63  void clear() override;
64 
65 private:
66  void drawBackground();
67  void drawContent();
68  // Render the text into the scratch surface, wrapping at wrapWidth.
69  void layoutText(int wrapWidth, uint16 fontID);
70  // Re-composite the expanded overlay at the current scroll position without
71  // re-laying out the text; used for cheap scrollbar-drag updates.
72  void redrawScroll();
73  void drawScrollbar(UIButtonState state);
74  uint16 getInnerHeight() const;
75 
76  // The text content area in popup-local coordinates (the screen-space text
77  // viewport brought into the popup surface's space).
78  Common::Rect textViewportLocal() const;
79 
80  // Width the strip wraps at: its own text area from TBOX, not the viewport.
81  int stripTextWidth() const;
82 
83  // Popup-local bounding rect of the scrollbar thumb at the current scroll
84  // position, or an empty rect when the slider is disabled.
85  Common::Rect computeThumbRect() const;
86 
87  Common::Rect toPopupLocal(const Common::Rect &chunkRect, bool useGameFrame) const;
88  Common::Point popupLocalMouse(const Common::Point &screenMouse) const;
89 
90  // Popup chrome (overlay image, dest rects, slider) supplied by the
91  // version-specific chunk: UICO in Nancy 10, SCTB in Nancy 11.
92  const UIPopupHeader *_header;
93  // Text content area, in screen coordinates.
94  Common::Rect _textViewportScreen;
95  // The fully-expanded popup rect on screen, with the game-frame offset
96  // applied. The mini strip shares its top edge.
97  Common::Rect _fullPopupRect;
98  // Screen rect the taskbar reserves for the caption strip (TASK chunk). The
99  // strip's text is aligned to it; empty when there is no taskbar data.
100  Common::Rect _stripScreenRect;
101  const TBOX *_tboxData;
102 
103  Graphics::ManagedSurface _overlayImage;
104 
105  float _scrollPos;
106  bool _scrollbarDragging;
107  bool _scrollbarHovered;
108  int _scrollbarGrabOffset;
109 
110  // Nancy 10 only: true selects the AR 74 full box, false the AR 75 strip.
111  // Defaults false since every writer but AR 74 uses the strip.
112  bool _fullMode;
113  // True for the full, taskbar-covering box (with scrollbar); false for the strip.
114  bool _expanded;
115 
116  int _fontIDOverride;
117  uint32 _autoClearTime;
118 };
119 
120 } // End of namespace UI
121 } // End of namespace Nancy
122 
123 #endif // NANCY_UI_SCROLLTEXTBOX_H
Definition: managed_surface.h:51
Definition: scrolltextbox.h:43
Definition: str.h:59
Definition: rect.h:536
Definition: input.h:41
Definition: soundequalizerpuzzle.h:27
Definition: hypertext.h:32
Definition: renderobject.h:36
Definition: rect.h:144
Definition: commontypes.h:447
Definition: enginedata.h:156
Definition: actionmanager.h:32