Root/src/layer.h

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;
10class Touchscreen;
11
12
13/**
14 * Abstract base class for UI layers.
15 * A layer handles both painting and input events.
16 */
17class Layer {
18public:
19    enum class Status { DISMISSED, NORMAL };
20
21    virtual ~Layer() {}
22
23    /**
24     * Perform one frame worth of animation.
25     * Returns true iff there are any animations in progress.
26     */
27    virtual bool runAnimations() { return false; }
28
29    /**
30     * Paints this layer on the given surface.
31     */
32    virtual void paint(Surface &s) = 0;
33
34    /**
35     * Handles the pressing of the give button.
36     * Returns true iff the button press event was fully handled by this layer.
37     */
38    virtual bool handleButtonPress(InputManager::Button button) = 0;
39
40    /**
41     * Handles the touch screen.
42     * Only called if there is a touch screen available.
43     * Returns true iff the touch screen was fully handled by this layer.
44     */
45    virtual bool handleTouchscreen(Touchscreen &ts) = 0;
46
47    Status getStatus() { return status; }
48
49protected:
50    /**
51     * Request the Layer to be removed from the stack.
52     * There could be a few more calls to the Layer before it is actually
53     * removed, so be prepared to handle those.
54     */
55    void dismiss() {
56        status = Status::DISMISSED;
57    }
58
59private:
60    Status status = Status::NORMAL;
61};
62
63#endif // LAYER_H
64

Archive Download this file



interactive