mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-08-26 09:24:28 +02:00
Text input dialogue
This commit is contained in:
70
src/dialogues/TextPrompt.cpp
Normal file
70
src/dialogues/TextPrompt.cpp
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
/*
|
||||||
|
* ConfirmPrompt.cpp
|
||||||
|
*
|
||||||
|
* Created on: Apr 6, 2012
|
||||||
|
* Author: Simon
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "TextPrompt.h"
|
||||||
|
#include "interface/Label.h"
|
||||||
|
#include "interface/Button.h"
|
||||||
|
|
||||||
|
class CloseAction: public ui::ButtonAction
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
TextPrompt * prompt;
|
||||||
|
TextPrompt::DialogueResult result;
|
||||||
|
CloseAction(TextPrompt * prompt_, TextPrompt::DialogueResult result_) { prompt = prompt_; result = result_; }
|
||||||
|
void ActionCallback(ui::Button * sender)
|
||||||
|
{
|
||||||
|
ui::Engine::Ref().CloseWindow();
|
||||||
|
prompt->callback->TextCallback(result, prompt->textField->GetText());
|
||||||
|
prompt->SelfDestruct(); //TODO: Fix component disposal
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
TextPrompt::TextPrompt(std::string title, std::string message, bool multiline, TextDialogueCallback * callback_):
|
||||||
|
ui::Window(ui::Point(-1, -1), ui::Point(200, 75)),
|
||||||
|
callback(callback_)
|
||||||
|
{
|
||||||
|
ui::Label * titleLabel = new ui::Label(ui::Point(2, 1), ui::Point(Size.X-4, 16), title);
|
||||||
|
titleLabel->SetTextColour(ui::Colour(220, 220, 50));
|
||||||
|
titleLabel->SetAlignment(AlignLeft, AlignBottom);
|
||||||
|
AddComponent(titleLabel);
|
||||||
|
|
||||||
|
ui::Label * messageLabel = new ui::Label(ui::Point(4, 18), ui::Point(Size.X-8, 60), message);
|
||||||
|
messageLabel->SetAlignment(AlignLeft, AlignTop);
|
||||||
|
AddComponent(messageLabel);
|
||||||
|
|
||||||
|
ui::Button * cancelButton = new ui::Button(ui::Point(0, Size.Y-16), ui::Point(Size.X-50, 16), "Cancel");
|
||||||
|
cancelButton->SetAlignment(AlignLeft, AlignBottom);
|
||||||
|
cancelButton->SetBorderColour(ui::Colour(200, 200, 200));
|
||||||
|
cancelButton->SetActionCallback(new CloseAction(this, ResultCancel));
|
||||||
|
AddComponent(cancelButton);
|
||||||
|
|
||||||
|
ui::Button * okayButton = new ui::Button(ui::Point(Size.X-50, Size.Y-16), ui::Point(50, 16), "Continue");
|
||||||
|
okayButton->SetAlignment(AlignLeft, AlignBottom);
|
||||||
|
okayButton->SetTextColour(ui::Colour(220, 220, 50));
|
||||||
|
okayButton->SetActionCallback(new CloseAction(this, ResultOkay));
|
||||||
|
AddComponent(okayButton);
|
||||||
|
|
||||||
|
textField = new ui::Textbox(ui::Point(4, 32), ui::Point(Size.X-8, 16), "");
|
||||||
|
textField->SetAlignment(AlignLeft, AlignBottom);
|
||||||
|
AddComponent(textField);
|
||||||
|
|
||||||
|
ui::Engine::Ref().ShowWindow(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TextPrompt::OnDraw()
|
||||||
|
{
|
||||||
|
Graphics * g = ui::Engine::Ref().g;
|
||||||
|
|
||||||
|
g->clearrect(Position.X-2, Position.Y-2, Size.X+4, Size.Y+4);
|
||||||
|
g->drawrect(Position.X, Position.Y, Size.X, Size.Y, 200, 200, 200, 255);
|
||||||
|
}
|
||||||
|
|
||||||
|
TextPrompt::~TextPrompt() {
|
||||||
|
if(callback)
|
||||||
|
delete callback;
|
||||||
|
}
|
||||||
|
|
35
src/dialogues/TextPrompt.h
Normal file
35
src/dialogues/TextPrompt.h
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
/*
|
||||||
|
* ConfirmPrompt.h
|
||||||
|
*
|
||||||
|
* Created on: Apr 6, 2012
|
||||||
|
* Author: Simon
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef CONFIRMPROMPT_H_
|
||||||
|
#define CONFIRMPROMPT_H_
|
||||||
|
|
||||||
|
#include "interface/Window.h"
|
||||||
|
#include "interface/Textbox.h"
|
||||||
|
|
||||||
|
class TextDialogueCallback;
|
||||||
|
class TextPrompt: public ui::Window {
|
||||||
|
protected:
|
||||||
|
ui::Textbox * textField;
|
||||||
|
public:
|
||||||
|
//class CloseAction;
|
||||||
|
friend class CloseAction;
|
||||||
|
enum DialogueResult { ResultCancel, ResultOkay };
|
||||||
|
TextPrompt(std::string title, std::string message, bool multiline, TextDialogueCallback * callback_);
|
||||||
|
virtual void OnDraw();
|
||||||
|
virtual ~TextPrompt();
|
||||||
|
TextDialogueCallback * callback;
|
||||||
|
};
|
||||||
|
|
||||||
|
class TextDialogueCallback
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual void TextCallback(TextPrompt::DialogueResult result, std::string resultText) {}
|
||||||
|
virtual ~TextDialogueCallback() {}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* CONFIRMPROMPT_H_ */
|
Reference in New Issue
Block a user