Root/src/layer.h

Source at commit 00d3c3b57008bddf8770c51271db9d766acaf854 created 7 years 2 months ago.
By Maarten ter Huurne, Gave Layer class a protected constructor
1// (c) 2013 Maarten ter Huurne <maarten@treewalker.org>
2// License: GPL version 2 or later.
3
4#ifndef LAYER_H
5#define LAYER_H
6
7#include "inputmanager.h"
8
9class Surface;
10
11
12/**
13 * Abstract base class for UI layers.
14 * A layer handles both painting and input events.
15 */
16class Layer {
17public:
18    enum class Status { DISMISSED, NORMAL };
19
20    virtual ~Layer() {}
21
22    /**
23     * Perform one frame worth of animation.
24     * Returns true iff there are any animations in progress.
25     */
26    virtual bool runAnimations() { return false; }
27
28    /**
29     * Paints this layer on the given surface.
30     */
31    virtual void paint(Surface &s) = 0;
32
33    /**
34     * Handles the pressing of the give button.
35     * Returns true iff the button press event was fully handled by this layer.
36     */
37    virtual bool handleButtonPress(InputManager::Button button) = 0;
38
39    Status getStatus() { return status; }
40
41protected:
42    Layer() {}
43
44    /**
45     * Request the Layer to be removed from the stack.
46     * There could be a few more calls to the Layer before it is actually
47     * removed, so be prepared to handle those.
48     */
49    void dismiss() {
50        status = Status::DISMISSED;
51    }
52
53private:
54    Status status = Status::NORMAL;
55};
56
57#endif // LAYER_H
58

Archive Download this file



interactive