Files
ppsspp/Common/UI/UIScreen.h

146 lines
3.3 KiB
C
Raw Permalink Normal View History

#pragma once
#include <mutex>
#include <string>
#include <deque>
#include "Common/Math/lin/vec3.h"
#include "Common/UI/Screen.h"
#include "Common/UI/ViewGroup.h"
using namespace Lin;
2013-09-07 13:38:12 +02:00
class I18NCategory;
2016-12-25 18:18:19 +01:00
namespace Draw {
2016-12-25 21:01:57 +01:00
class DrawContext;
2016-12-25 18:18:19 +01:00
}
2013-09-07 13:38:12 +02:00
enum class QueuedEventType : u8 {
KEY,
AXIS,
TOUCH,
};
struct QueuedEvent {
QueuedEventType type;
union {
TouchInput touch;
KeyInput key;
AxisInput axis;
};
};
class UIScreen : public Screen {
public:
UIScreen();
2013-11-26 13:56:56 +01:00
~UIScreen();
void update() override;
void preRender() override;
void render() override;
void postRender() override;
void deviceLost() override;
void deviceRestored() override;
virtual void touch(const TouchInput &touch);
virtual bool key(const KeyInput &key);
virtual void axis(const AxisInput &axis);
2023-09-04 10:58:11 +02:00
bool UnsyncTouch(const TouchInput &touch) override;
bool UnsyncKey(const KeyInput &key) override;
void UnsyncAxis(const AxisInput &axis) override;
TouchInput transformTouch(const TouchInput &touch) override;
virtual void TriggerFinish(DialogResult result);
// Some useful default event handlers
2013-12-05 14:15:18 +01:00
UI::EventReturn OnOK(UI::EventParams &e);
UI::EventReturn OnCancel(UI::EventParams &e);
UI::EventReturn OnBack(UI::EventParams &e);
protected:
virtual void CreateViews() = 0;
virtual void DrawBackground(UIContext &dc) {}
void RecreateViews() override { recreateViews_ = true; }
bool UseVerticalLayout() const;
UI::ViewGroup *root_ = nullptr;
Vec3 translation_ = Vec3(0.0f);
Vec3 scale_ = Vec3(1.0f);
float alpha_ = 1.0f;
bool ignoreInsets_ = false;
bool ignoreInput_ = false;
protected:
void DoRecreateViews();
2014-08-17 12:17:59 +02:00
bool recreateViews_ = true;
bool lastVertical_;
private:
std::mutex eventQueueLock_;
std::deque<QueuedEvent> eventQueue_;
};
2013-07-16 00:25:08 +02:00
2013-08-17 12:06:08 +02:00
class UIDialogScreen : public UIScreen {
2013-08-13 00:06:23 +02:00
public:
2013-10-28 16:05:21 +01:00
UIDialogScreen() : UIScreen(), finished_(false) {}
bool key(const KeyInput &key) override;
void sendMessage(const char *msg, const char *value) override;
2013-10-28 16:05:21 +01:00
private:
bool finished_;
2013-08-13 00:06:23 +02:00
};
2013-08-17 12:06:08 +02:00
class PopupScreen : public UIDialogScreen {
2013-07-16 00:25:08 +02:00
public:
2013-08-16 12:51:57 +02:00
PopupScreen(std::string title, std::string button1 = "", std::string button2 = "");
2013-07-16 00:25:08 +02:00
virtual void CreatePopupContents(UI::ViewGroup *parent) = 0;
void CreateViews() override;
bool isTransparent() const override { return true; }
void touch(const TouchInput &touch) override;
bool key(const KeyInput &key) override;
2013-07-16 00:25:08 +02:00
void TriggerFinish(DialogResult result) override;
2017-03-19 17:45:39 -07:00
void SetPopupOrigin(const UI::View *view);
void SetPopupOffset(float y);
void SetHasDropShadow(bool has) { hasDropShadow_ = has; }
2013-07-16 00:25:08 +02:00
protected:
2013-09-04 10:50:00 +02:00
virtual bool FillVertical() const { return false; }
virtual UI::Size PopupWidth() const { return 550; }
2013-09-04 10:50:00 +02:00
virtual bool ShowButtons() const { return true; }
virtual bool CanComplete(DialogResult result) { return true; }
2013-08-16 12:51:57 +02:00
virtual void OnCompleted(DialogResult result) {}
virtual bool HasTitleBar() const { return true; }
const std::string &Title() { return title_; }
2013-07-16 00:25:08 +02:00
void update() override;
2013-07-16 00:25:08 +02:00
private:
2023-01-31 20:38:09 +01:00
UI::LinearLayout *box_ = nullptr;
UI::Button *defaultButton_ = nullptr;
2013-07-16 00:25:08 +02:00
std::string title_;
2013-08-16 12:51:57 +02:00
std::string button1_;
std::string button2_;
enum {
FRAMES_LEAD_IN = 6,
FRAMES_LEAD_OUT = 4,
};
int frames_ = 0;
int finishFrame_ = -1;
DialogResult finishResult_ = DR_CANCEL;
bool hasPopupOrigin_ = false;
Point popupOrigin_;
float offsetY_ = 0.0f;
bool hasDropShadow_ = true;
2013-07-16 00:25:08 +02:00
};