2013-08-06 02:55:32 +03:00
|
|
|
// (c) 2013 Maarten ter Huurne <maarten@treewalker.org>
|
|
|
|
// License: GPL version 2 or later.
|
|
|
|
|
|
|
|
#ifndef LAYER_H
|
|
|
|
#define LAYER_H
|
|
|
|
|
|
|
|
#include "inputmanager.h"
|
|
|
|
|
|
|
|
class Surface;
|
|
|
|
class Touchscreen;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Abstract base class for UI layers.
|
|
|
|
* A layer handles both painting and input events.
|
|
|
|
*/
|
|
|
|
class Layer {
|
|
|
|
public:
|
2013-08-12 20:41:56 +03:00
|
|
|
enum class Status { DISMISSED, NORMAL };
|
2013-08-11 01:05:18 +03:00
|
|
|
|
2013-08-06 02:55:32 +03:00
|
|
|
virtual ~Layer() {}
|
|
|
|
|
2013-08-12 20:41:56 +03:00
|
|
|
/**
|
|
|
|
* Perform one frame worth of animation.
|
|
|
|
* Returns true iff there are any animations in progress.
|
|
|
|
*/
|
|
|
|
virtual bool runAnimations() { return false; }
|
|
|
|
|
2013-08-06 02:55:32 +03:00
|
|
|
/**
|
|
|
|
* Paints this layer on the given surface.
|
|
|
|
*/
|
|
|
|
virtual void paint(Surface &s) = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handles the pressing of the give button.
|
|
|
|
* Returns true iff the button press event was fully handled by this layer.
|
|
|
|
*/
|
|
|
|
virtual bool handleButtonPress(InputManager::Button button) = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handles the touch screen.
|
|
|
|
* Only called if there is a touch screen available.
|
|
|
|
* Returns true iff the touch screen was fully handled by this layer.
|
|
|
|
*/
|
|
|
|
virtual bool handleTouchscreen(Touchscreen &ts) = 0;
|
|
|
|
|
2013-08-11 01:05:18 +03:00
|
|
|
Status getStatus() { return status; }
|
2013-08-06 02:55:32 +03:00
|
|
|
|
|
|
|
protected:
|
|
|
|
/**
|
2013-08-11 01:05:18 +03:00
|
|
|
* Request the Layer to be removed from the stack.
|
|
|
|
* There could be a few more calls to the Layer before it is actually
|
|
|
|
* removed, so be prepared to handle those.
|
|
|
|
*/
|
|
|
|
void dismiss() {
|
|
|
|
status = Status::DISMISSED;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2013-08-12 20:41:56 +03:00
|
|
|
Status status = Status::NORMAL;
|
2013-08-06 02:55:32 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // LAYER_H
|