https://github.com/libsdl-org/Maelstrom/commit/9992ab1d084133aa28b5b7ea9f91f5be9ca17a0e
From 9992ab1d084133aa28b5b7ea9f91f5be9ca17a0e Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Sun, 9 Sep 2012 19:16:21 -0700
Subject: [PATCH] Improved the dialog handlers so you can pass in a function
parameter for them.
---
game/features.cpp | 4 ++--
game/main.cpp | 4 ++--
game/scores.cpp | 2 +-
game/scores.h | 2 +-
screenlib/UIDialog.cpp | 9 ++++++---
screenlib/UIDialog.h | 14 +++++++++-----
6 files changed, 21 insertions(+), 14 deletions(-)
diff --git a/game/features.cpp b/game/features.cpp
index 2213cdce..20ec888e 100644
--- a/game/features.cpp
+++ b/game/features.cpp
@@ -43,7 +43,7 @@ bool HasFeature(const char *feature)
static const char *current_feature;
-static void FeatureDialogDone(UIDialog *dialog, int status)
+static void FeatureDialogDone(void*, UIDialog *dialog, int status)
{
if (status == 1) {
// Buy the feature for this platform
@@ -69,7 +69,7 @@ void ShowFeature(const char *feature)
dialog = ui->GetPanel<UIDialog>(DIALOG_FEATURE);
if (dialog) {
current_feature = feature;
- dialog->SetDialogHandlers(NULL, FeatureDialogDone);
+ dialog->SetDialogDoneHandler(FeatureDialogDone);
ui->ShowPanel(dialog);
}
}
diff --git a/game/main.cpp b/game/main.cpp
index 64206999..5e82b6ce 100644
--- a/game/main.cpp
+++ b/game/main.cpp
@@ -151,7 +151,7 @@ static void RunToggleFullscreen(void*)
{
screen->ToggleFullScreen();
}
-static void CheatDialogInit(UIDialog *dialog)
+static void CheatDialogInit(void*, UIDialog *dialog)
{
UIElementEditbox *editbox;
@@ -160,7 +160,7 @@ static void CheatDialogInit(UIDialog *dialog)
editbox->SetFocus(true);
}
}
-static void CheatDialogDone(UIDialog *dialog, int status)
+static void CheatDialogDone(void*, UIDialog *dialog, int status)
{
UIElementEditbox *editbox;
UIElementCheckbox *checkbox;
diff --git a/game/scores.cpp b/game/scores.cpp
index 2e4d4e43..44d257cb 100644
--- a/game/scores.cpp
+++ b/game/scores.cpp
@@ -108,7 +108,7 @@ void FreeScores(void)
}
-void ZapHighScores(UIDialog *dialog, int status)
+void ZapHighScores(void*, UIDialog *dialog, int status)
{
char path[1024];
diff --git a/game/scores.h b/game/scores.h
index 361d8146..b16652d4 100644
--- a/game/scores.h
+++ b/game/scores.h
@@ -28,7 +28,7 @@ class UIDialog;
// Functions from scores.cpp
extern void LoadScores(void);
extern void FreeScores(void);
-extern void ZapHighScores(UIDialog *dialog, int status);
+extern void ZapHighScores(void*, UIDialog *dialog, int status);
/* The high scores structure */
typedef struct {
diff --git a/screenlib/UIDialog.cpp b/screenlib/UIDialog.cpp
index 5b0a04e6..564a6fb7 100644
--- a/screenlib/UIDialog.cpp
+++ b/screenlib/UIDialog.cpp
@@ -32,7 +32,9 @@ UIDialog::UIDialog(UIManager *ui, const char *name) :
m_fullscreen = false;
m_status = 0;
m_handleInit = NULL;
+ m_handleInitData = NULL;
m_handleDone = NULL;
+ m_handleDoneData = NULL;
}
void
@@ -41,7 +43,7 @@ UIDialog::Show()
m_status = 0;
if (m_handleInit) {
- m_handleInit(this);
+ m_handleInit(m_handleInitData, this);
}
UIPanel::Show();
@@ -53,7 +55,7 @@ UIDialog::Hide()
UIPanel::Hide();
if (m_handleDone) {
- m_handleDone(this, m_status);
+ m_handleDone(m_handleDoneData, this, m_status);
}
}
@@ -101,7 +103,8 @@ UIDialogLauncher::operator()()
dialog = m_ui->GetPanel<UIDialog>(m_name);
if (dialog) {
- dialog->SetDialogHandlers(m_handleInit, m_handleDone);
+ dialog->SetDialogInitHandler(m_handleInit);
+ dialog->SetDialogDoneHandler(m_handleDone);
m_ui->ShowPanel(dialog);
}
diff --git a/screenlib/UIDialog.h b/screenlib/UIDialog.h
index 8dd31cac..2ef1ea1a 100644
--- a/screenlib/UIDialog.h
+++ b/screenlib/UIDialog.h
@@ -38,12 +38,12 @@ class UIDialogDelegate : public UIPanelDelegate
/* This function gets called when the dialog is shown.
*/
-typedef void (*UIDialogInitHandler)(UIDialog *dialog);
+typedef void (*UIDialogInitHandler)(void *data, UIDialog *dialog);
/* This function gets called when the dialog is hidden.
The status defaults to 0, but can be changed by dialog buttons.
*/
-typedef void (*UIDialogDoneHandler)(UIDialog *dialog, int status);
+typedef void (*UIDialogDoneHandler)(void *data, UIDialog *dialog, int status);
class UIDialog : public UIPanel
{
@@ -51,11 +51,13 @@ DECLARE_TYPESAFE_CLASS(UIPanel)
public:
UIDialog(UIManager *ui, const char *name);
- /* Set a function that's called when the dialog is hidden */
- void SetDialogHandlers(UIDialogInitHandler handleInit,
- UIDialogDoneHandler handleDone) {
+ void SetDialogInitHandler(UIDialogInitHandler handleInit, void *data = 0) {
m_handleInit = handleInit;
+ m_handleInitData = data;
+ }
+ void SetDialogDoneHandler(UIDialogDoneHandler handleDone, void *data = 0) {
m_handleDone = handleDone;
+ m_handleDoneData = data;
}
void SetDialogStatus(int status) {
m_status = status;
@@ -71,7 +73,9 @@ DECLARE_TYPESAFE_CLASS(UIPanel)
protected:
int m_status;
UIDialogInitHandler m_handleInit;
+ void *m_handleInitData;
UIDialogDoneHandler m_handleDone;
+ void *m_handleDoneData;
};
//