Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hrydgard
GitHub Repository: hrydgard/ppsspp
Path: blob/master/Core/Dialog/PSPDialog.h
3186 views
1
// Copyright (c) 2012- PPSSPP Project.
2
3
// This program is free software: you can redistribute it and/or modify
4
// it under the terms of the GNU General Public License as published by
5
// the Free Software Foundation, version 2.0 or later versions.
6
7
// This program is distributed in the hope that it will be useful,
8
// but WITHOUT ANY WARRANTY; without even the implied warranty of
9
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
// GNU General Public License 2.0 for more details.
11
12
// A copy of the GPL 2.0 should have been included with the program.
13
// If not, see http://www.gnu.org/licenses/
14
15
// Official git repository and contact information can be found at
16
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
17
18
#pragma once
19
20
#include "Common/CommonTypes.h"
21
#include "Common/Render/TextureAtlas.h"
22
#include "Common/Swap.h"
23
#include "Core/HLE/sceUtility.h"
24
#include "Core/Util/PPGeDraw.h"
25
26
class PointerWrap;
27
28
#define SCE_UTILITY_DIALOG_RESULT_SUCCESS 0
29
#define SCE_UTILITY_DIALOG_RESULT_CANCEL 1
30
#define SCE_UTILITY_DIALOG_RESULT_ABORT 2
31
32
struct pspUtilityDialogCommon {
33
u32_le size; /** Size of the structure */
34
s32_le language; /** Language */
35
s32_le buttonSwap; /** Set to 1 for X/O button swap */
36
s32_le graphicsThread; /** Graphics thread priority */
37
s32_le accessThread; /** Access/fileio thread priority (SceJobThread) */
38
s32_le fontThread; /** Font thread priority (ScePafThread) */
39
s32_le soundThread; /** Sound thread priority */
40
s32_le result; /** Result */
41
s32_le reserved[4]; /** Set to 0 */
42
};
43
44
class PSPDialog {
45
public:
46
PSPDialog(UtilityDialogType type) : dialogType_(type) {}
47
virtual ~PSPDialog() {}
48
49
virtual int Update(int animSpeed) = 0;
50
virtual int Shutdown(bool force = false);
51
virtual void DoState(PointerWrap &p);
52
virtual pspUtilityDialogCommon *GetCommonParam() {
53
// This is returned properly by the derived classes (or should be...).
54
return nullptr;
55
}
56
57
enum DialogStatus {
58
SCE_UTILITY_STATUS_NONE = 0,
59
SCE_UTILITY_STATUS_INITIALIZE = 1,
60
SCE_UTILITY_STATUS_RUNNING = 2,
61
SCE_UTILITY_STATUS_FINISHED = 3,
62
SCE_UTILITY_STATUS_SHUTDOWN = 4,
63
SCE_UTILITY_STATUS_SCREENSHOT_UNKNOWN = 5,
64
};
65
66
enum DialogStockButton {
67
DS_BUTTON_NONE = 0x00,
68
DS_BUTTON_OK = 0x01,
69
DS_BUTTON_CANCEL = 0x02,
70
DS_BUTTON_BOTH = 0x03,
71
};
72
73
DialogStatus GetStatus();
74
UtilityDialogType DialogType() { return dialogType_; }
75
76
void StartDraw();
77
void EndDraw();
78
79
void FinishVolatile();
80
int FinishInit();
81
int FinishShutdown();
82
83
protected:
84
void InitCommon();
85
void UpdateCommon();
86
PPGeStyle FadedStyle(PPGeAlign align, float scale);
87
PPGeImageStyle FadedImageStyle();
88
void UpdateButtons();
89
bool IsButtonPressed(int checkButton);
90
bool IsButtonHeld(int checkButton, int &framesHeld, int framesHeldThreshold = 30, int framesHeldRepeatRate = 10);
91
// The caption override is assumed to have a size of 64 bytes.
92
void DisplayButtons(int flags, std::string_view caption = "");
93
void DisplayMessage2(std::string_view text1, std::string_view text2a = "", std::string_view text2b = "", std::string_view text3a = "", std::string_view text3b = "", bool hasYesNo = false, bool hasOK = false);
94
void ChangeStatus(DialogStatus newStatus, int delayUs);
95
void ChangeStatusInit(int delayUs);
96
void ChangeStatusShutdown(int delayUs);
97
DialogStatus ReadStatus() const {
98
return status;
99
}
100
101
// TODO: Remove this once all dialogs are updated.
102
virtual bool UseAutoStatus() = 0;
103
104
static int GetConfirmButton();
105
static int GetCancelButton();
106
107
void StartFade(bool fadeIn_);
108
void UpdateFade(int animSpeed);
109
virtual void FinishFadeOut();
110
u32 CalcFadedColor(u32 inColor) const;
111
112
DialogStatus pendingStatus = SCE_UTILITY_STATUS_NONE;
113
u64 pendingStatusTicks = 0;
114
115
unsigned int lastButtons = 0;
116
unsigned int buttons = 0;
117
118
float fadeTimer = 0.0f;
119
bool isFading = false;
120
bool fadeIn = false;
121
u32 fadeValue = 0;
122
123
ImageID okButtonImg;
124
ImageID cancelButtonImg;
125
int okButtonFlag = 0;
126
int cancelButtonFlag = 0;
127
128
// DisplayMessage2 variables
129
int yesnoChoice = 0;
130
float scrollPos_ = 0.0f;
131
int framesUpHeld_ = 0;
132
int framesDownHeld_ = 0;
133
134
private:
135
DialogStatus status = SCE_UTILITY_STATUS_NONE;
136
UtilityDialogType dialogType_ = UtilityDialogType::NONE;
137
bool volatileLocked_ = false;
138
};
139
140
const char *UtilityDialogTypeToString(UtilityDialogType type);
141
142