2013-06-03 17:57:40 +00:00
|
|
|
#pragma once
|
|
|
|
|
2023-05-01 12:23:47 +00:00
|
|
|
#include <mutex>
|
|
|
|
#include <string>
|
|
|
|
#include <deque>
|
2016-02-25 14:39:17 +00:00
|
|
|
|
2020-10-03 22:25:21 +00:00
|
|
|
#include "Common/Math/lin/vec3.h"
|
2020-10-04 18:48:47 +00:00
|
|
|
#include "Common/UI/Screen.h"
|
|
|
|
#include "Common/UI/ViewGroup.h"
|
2013-06-03 17:57:40 +00:00
|
|
|
|
2019-10-22 20:58:10 +00:00
|
|
|
using namespace Lin;
|
|
|
|
|
2013-09-07 11:38:12 +00:00
|
|
|
class I18NCategory;
|
2016-12-25 17:18:19 +00:00
|
|
|
namespace Draw {
|
2016-12-25 20:01:57 +00:00
|
|
|
class DrawContext;
|
2016-12-25 17:18:19 +00:00
|
|
|
}
|
2013-09-07 11:38:12 +00:00
|
|
|
|
2023-05-01 12:23:47 +00:00
|
|
|
enum class QueuedEventType : u8 {
|
|
|
|
KEY,
|
|
|
|
AXIS,
|
|
|
|
TOUCH,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct QueuedEvent {
|
|
|
|
QueuedEventType type;
|
|
|
|
union {
|
|
|
|
TouchInput touch;
|
|
|
|
KeyInput key;
|
|
|
|
AxisInput axis;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2013-06-03 17:57:40 +00:00
|
|
|
class UIScreen : public Screen {
|
|
|
|
public:
|
2013-06-08 20:41:17 +00:00
|
|
|
UIScreen();
|
2013-11-26 12:56:56 +00:00
|
|
|
~UIScreen();
|
2013-06-03 17:57:40 +00:00
|
|
|
|
2018-03-27 21:10:33 +00:00
|
|
|
void update() override;
|
2023-12-11 11:41:44 +00:00
|
|
|
ScreenRenderFlags render(ScreenRenderMode mode) override;
|
2018-03-27 21:10:33 +00:00
|
|
|
void deviceLost() override;
|
|
|
|
void deviceRestored() override;
|
|
|
|
|
2023-05-26 09:49:50 +00:00
|
|
|
virtual void touch(const TouchInput &touch);
|
2023-07-06 09:48:25 +00:00
|
|
|
virtual bool key(const KeyInput &key);
|
|
|
|
virtual void axis(const AxisInput &axis);
|
2023-05-26 09:49:50 +00:00
|
|
|
|
2023-09-04 08:58:11 +00:00
|
|
|
bool UnsyncTouch(const TouchInput &touch) override;
|
2023-07-06 09:48:25 +00:00
|
|
|
bool UnsyncKey(const KeyInput &key) override;
|
2023-09-27 15:34:34 +00:00
|
|
|
void UnsyncAxis(const AxisInput *axes, size_t count) override;
|
2018-03-27 21:10:33 +00:00
|
|
|
|
|
|
|
TouchInput transformTouch(const TouchInput &touch) override;
|
2017-03-19 21:28:24 +00:00
|
|
|
|
2017-03-20 00:43:03 +00:00
|
|
|
virtual void TriggerFinish(DialogResult result);
|
|
|
|
|
2013-06-03 17:57:40 +00:00
|
|
|
// Some useful default event handlers
|
2013-12-05 13:15:18 +00:00
|
|
|
UI::EventReturn OnOK(UI::EventParams &e);
|
|
|
|
UI::EventReturn OnCancel(UI::EventParams &e);
|
2013-06-03 17:57:40 +00:00
|
|
|
UI::EventReturn OnBack(UI::EventParams &e);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual void CreateViews() = 0;
|
|
|
|
|
2022-12-08 15:04:20 +00:00
|
|
|
void RecreateViews() override { recreateViews_ = true; }
|
|
|
|
bool UseVerticalLayout() const;
|
2013-06-08 20:41:17 +00:00
|
|
|
|
2020-03-23 14:58:24 +00:00
|
|
|
UI::ViewGroup *root_ = nullptr;
|
|
|
|
Vec3 translation_ = Vec3(0.0f);
|
|
|
|
Vec3 scale_ = Vec3(1.0f);
|
2017-03-19 21:28:24 +00:00
|
|
|
float alpha_ = 1.0f;
|
2020-05-31 21:20:13 +00:00
|
|
|
bool ignoreInsets_ = false;
|
2023-05-06 13:09:12 +00:00
|
|
|
bool ignoreInput_ = false;
|
2013-06-08 20:41:17 +00:00
|
|
|
|
2023-09-05 14:43:45 +00:00
|
|
|
protected:
|
2023-12-10 20:57:05 +00:00
|
|
|
virtual void DrawBackground(UIContext &ui) {}
|
2023-12-11 11:41:44 +00:00
|
|
|
virtual void DrawForeground(UIContext &ui) {}
|
|
|
|
|
2023-12-10 20:57:05 +00:00
|
|
|
void SetupViewport();
|
2013-07-21 11:30:47 +00:00
|
|
|
void DoRecreateViews();
|
2014-08-17 10:17:59 +00:00
|
|
|
|
2020-03-23 14:58:24 +00:00
|
|
|
bool recreateViews_ = true;
|
2022-12-08 15:04:20 +00:00
|
|
|
bool lastVertical_;
|
2023-05-01 12:23:47 +00:00
|
|
|
|
2023-09-05 14:43:45 +00:00
|
|
|
private:
|
2023-05-01 12:23:47 +00:00
|
|
|
std::mutex eventQueueLock_;
|
|
|
|
std::deque<QueuedEvent> eventQueue_;
|
2013-06-03 17:57:40 +00:00
|
|
|
};
|
2013-07-15 22:25:08 +00:00
|
|
|
|
2013-08-17 10:06:08 +00:00
|
|
|
class UIDialogScreen : public UIScreen {
|
2013-08-12 22:06:23 +00:00
|
|
|
public:
|
2013-10-28 15:05:21 +00:00
|
|
|
UIDialogScreen() : UIScreen(), finished_(false) {}
|
2017-12-02 19:07:27 +00:00
|
|
|
bool key(const KeyInput &key) override;
|
2023-09-30 09:21:22 +00:00
|
|
|
void sendMessage(UIMessage message, const char *value) override;
|
2013-10-28 15:05:21 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
bool finished_;
|
2013-08-12 22:06:23 +00:00
|
|
|
};
|
|
|
|
|
2013-08-17 10:06:08 +00:00
|
|
|
class PopupScreen : public UIDialogScreen {
|
2013-07-15 22:25:08 +00:00
|
|
|
public:
|
2024-01-19 12:44:49 +00:00
|
|
|
PopupScreen(std::string_view title, std::string_view button1 = "", std::string_view button2 = "");
|
2013-07-15 22:25:08 +00:00
|
|
|
|
|
|
|
virtual void CreatePopupContents(UI::ViewGroup *parent) = 0;
|
2022-12-11 04:32:12 +00:00
|
|
|
void CreateViews() override;
|
|
|
|
bool isTransparent() const override { return true; }
|
2022-12-31 20:41:32 +00:00
|
|
|
void touch(const TouchInput &touch) override;
|
2022-12-11 04:32:12 +00:00
|
|
|
bool key(const KeyInput &key) override;
|
2013-07-15 22:25:08 +00:00
|
|
|
|
2022-12-11 04:32:12 +00:00
|
|
|
void TriggerFinish(DialogResult result) override;
|
2017-03-20 00:45:39 +00:00
|
|
|
|
2017-03-22 01:27:57 +00:00
|
|
|
void SetPopupOrigin(const UI::View *view);
|
2024-05-20 16:33:35 +00:00
|
|
|
void SetPopupOffset(float y) { offsetY_ = y; }
|
|
|
|
|
|
|
|
void SetAlignTop(bool alignTop) { alignTop_ = alignTop; }
|
2017-03-22 01:27:57 +00:00
|
|
|
|
2022-02-11 17:23:56 +00:00
|
|
|
void SetHasDropShadow(bool has) { hasDropShadow_ = has; }
|
|
|
|
|
2023-12-10 20:57:05 +00:00
|
|
|
// For the postproc param sliders on DisplayLayoutScreen
|
2023-12-11 01:10:08 +00:00
|
|
|
bool wantBrightBackground() const override { return !hasDropShadow_; }
|
2023-12-10 20:57:05 +00:00
|
|
|
|
2013-07-15 22:25:08 +00:00
|
|
|
protected:
|
2013-09-04 08:50:00 +00:00
|
|
|
virtual bool FillVertical() const { return false; }
|
2016-04-24 18:51:06 +00:00
|
|
|
virtual UI::Size PopupWidth() const { return 550; }
|
2013-09-04 08:50:00 +00:00
|
|
|
virtual bool ShowButtons() const { return true; }
|
2019-08-18 01:24:57 +00:00
|
|
|
virtual bool CanComplete(DialogResult result) { return true; }
|
2013-08-16 10:51:57 +00:00
|
|
|
virtual void OnCompleted(DialogResult result) {}
|
2022-12-07 00:09:44 +00:00
|
|
|
virtual bool HasTitleBar() const { return true; }
|
2021-02-22 00:38:02 +00:00
|
|
|
const std::string &Title() { return title_; }
|
2013-07-15 22:25:08 +00:00
|
|
|
|
2022-12-11 04:32:12 +00:00
|
|
|
void update() override;
|
2017-03-19 22:41:48 +00:00
|
|
|
|
2013-07-15 22:25:08 +00:00
|
|
|
private:
|
2023-01-31 19:38:09 +00:00
|
|
|
UI::LinearLayout *box_ = nullptr;
|
2023-01-30 17:31:49 +00:00
|
|
|
UI::Button *defaultButton_ = nullptr;
|
2013-07-15 22:25:08 +00:00
|
|
|
std::string title_;
|
2013-08-16 10:51:57 +00:00
|
|
|
std::string button1_;
|
|
|
|
std::string button2_;
|
2017-03-19 22:41:48 +00:00
|
|
|
|
2017-03-26 15:58:04 +00:00
|
|
|
enum {
|
|
|
|
FRAMES_LEAD_IN = 6,
|
|
|
|
FRAMES_LEAD_OUT = 4,
|
|
|
|
};
|
|
|
|
|
2017-03-19 22:41:48 +00:00
|
|
|
int frames_ = 0;
|
2017-03-26 15:58:04 +00:00
|
|
|
int finishFrame_ = -1;
|
2023-01-30 17:31:49 +00:00
|
|
|
DialogResult finishResult_ = DR_CANCEL;
|
2017-03-22 01:27:57 +00:00
|
|
|
bool hasPopupOrigin_ = false;
|
2024-05-24 20:51:50 +00:00
|
|
|
Point2D popupOrigin_;
|
2021-08-28 22:23:46 +00:00
|
|
|
float offsetY_ = 0.0f;
|
2024-05-20 16:33:35 +00:00
|
|
|
bool alignTop_ = false;
|
2022-02-11 17:23:56 +00:00
|
|
|
|
|
|
|
bool hasDropShadow_ = true;
|
2013-07-15 22:25:08 +00:00
|
|
|
};
|