ScummVM API documentation
viewportfader.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_MISC_VIEWPORTFADER_H
23 #define NANCY_MISC_VIEWPORTFADER_H
24 
25 #include "engines/nancy/renderobject.h"
26 
27 namespace Nancy {
28 namespace Misc {
29 
30 // Nancy16 covers scene changes by fading the viewport to a solid color, holding it,
31 // and fading back once the next scene is in. An action record arms the fade, and the
32 // next scene change starts it. The new scene only takes over after the hold.
33 class ViewportFader : public RenderObject {
34 public:
35  ViewportFader() : RenderObject(16) {}
36  virtual ~ViewportFader() {}
37 
38  void init() override;
39  void updateGraphics() override;
40 
41  bool isIdle() const { return _state == kIdle; }
42 
43  // The color is RGB; the fade always ends fully opaque
44  void arm(uint32 color, uint32 holdTime);
45 
46  // Starts an armed fade, when a scene change gets requested
47  void onSceneChange();
48 
49  // The requested scene waits until the viewport is fully covered
50  bool holdsSceneChange() const { return _state == kFadingIn || _state == kHolding; }
51 
52 private:
53  enum State {
54  kIdle,
55  kArmed,
56  kFadingIn,
57  kHolding,
58  kFadingOut
59  };
60 
61  bool blendTowards(uint32 target, float seconds);
62  void redraw();
63 
64  State _state = kIdle;
65  float _current[4] = {}; // ARGB channels, starting at transparent black
66  uint32 _target = 0; // ARGB
67  uint32 _holdTime = 0;
68  uint32 _holdEndTime = 0;
69  uint32 _lastUpdateTime = 0;
70 };
71 
72 } // End of namespace Misc
73 } // End of namespace Nancy
74 
75 #endif // NANCY_MISC_VIEWPORTFADER_H
Definition: renderobject.h:36
Definition: viewportfader.h:33
Definition: actionmanager.h:32