From 531232cf05838b79c1f8f36c8103730e32dfa23d Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Fri, 12 Mar 2010 07:30:41 +0000 Subject: [PATCH] Add Dialog class --- source/dialog.cpp | 48 +++++++++++++++++++++++++++++++++++++++++++++++ source/dialog.h | 48 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 source/dialog.cpp create mode 100644 source/dialog.h diff --git a/source/dialog.cpp b/source/dialog.cpp new file mode 100644 index 0000000..5eea609 --- /dev/null +++ b/source/dialog.cpp @@ -0,0 +1,48 @@ +/* $Id$ + +This file is part of libmspgltk +Copyright © 2010 Mikko Rasa, Mikkosoft Productions +Distributed under the LGPL +*/ + +#include "button.h" +#include "dialog.h" + +namespace Msp { +namespace GLtk { + +Dialog::Dialog(const Resources &r): + Widget(r), + Panel(r), + stale(false) +{ } + +void Dialog::add_button(Button &button, int code) +{ + add(button); + button.signal_clicked.connect(sigc::bind(sigc::mem_fun(this, &Dialog::response), code)); +} + +void Dialog::button_release(int x, int y, unsigned button) +{ + Panel::button_release(x, y, button); + if(stale) + delete this; +} + +void Dialog::key_release(unsigned key, unsigned mod) +{ + Panel::key_release(key, mod); + if(stale) + delete this; +} + +void Dialog::response(int code) +{ + on_response(code); + signal_response.emit(code); + stale=true; +} + +} // namespace GLtk +} // namespace Msp diff --git a/source/dialog.h b/source/dialog.h new file mode 100644 index 0000000..0a9b0d8 --- /dev/null +++ b/source/dialog.h @@ -0,0 +1,48 @@ +/* $Id$ + +This file is part of libmspgltk +Copyright © 2010 Mikko Rasa, Mikkosoft Productions +Distributed under the LGPL +*/ + +#ifndef MSP_GLTK_DIALOG_H_ +#define MSP_GLTK_DIALOG_H_ + +#include "panel.h" + +namespace Msp { +namespace GLtk { + +class Button; + +/** +A Dialog is used for temporary interaction with the user. When any of the +Dialog's action buttons are clicked, it will emit a signal and delete itself. +*/ +class Dialog: public Panel +{ +private: + bool stale; + +public: + sigc::signal signal_response; + + Dialog(const Resources &); + + /** Adds an action button to the dialog. Pressing the button will invoke + response handlers and delete the dialog. */ + void add_button(Button &, int); + + virtual void button_release(int, int, unsigned); + virtual void key_release(unsigned, unsigned); +protected: + void response(int); + + /** Called when an action button is pressed. */ + virtual void on_response(int) { } +}; + +} // namespace GLtk +} // namespace Msp + +#endif -- 2.43.0