Hasty Badger
Small UI library (a branch of Turbo Badger)
 All Classes Namespaces Functions Variables Enumerations Enumerator Friends Groups Pages
tb_message_window.h
1 // ================================================================================
2 // == This file is a part of Turbo Badger. (C) 2011-2014, Emil SegerÃ¥s ==
3 // == See tb_core.h for more information. ==
4 // ================================================================================
5 
6 #ifndef TB_MESSAGE_WINDOW_H
7 #define TB_MESSAGE_WINDOW_H
8 
9 #include "tb_window.h"
10 #include "tb_widgets_listener.h"
11 
12 namespace tb {
13 
14 enum TB_MSG {
15  TB_MSG_OK,
16  TB_MSG_OK_CANCEL,
17  TB_MSG_YES_NO,
18  TB_MSG_YES_NO_CANCEL,
19 };
20 
23 {
24 public:
25  TBMessageWindowSettings() : msg(TB_MSG_OK), dimmer(false), styling(false) {}
26  TBMessageWindowSettings(TB_MSG msg, TBID icon_skin) : msg(msg), icon_skin(icon_skin), dimmer(false), styling(false), align(TB_TEXT_ALIGN_LEFT) {}
27 public:
28  TB_MSG msg;
30  bool dimmer;
31  bool styling;
33 };
34 
44 class TBMessageWindow : public TBWindow, private TBWidgetListener
45 {
46 public:
47  // For safe typecasting
48  TBOBJECT_SUBCLASS(TBMessageWindow, TBWindow);
49 
50  TBMessageWindow(TBWidget *target, TBID id);
51  virtual ~TBMessageWindow();
52 
53  bool Show(const char *title, const TBStr & message, TBMessageWindowSettings *settings = nullptr);
54 
55  virtual TBWidget *GetEventDestination() { return m_target.Get(); }
56 
57  virtual bool OnEvent(const TBWidgetEvent &ev);
58  virtual void OnDie();
59 private:
60  void AddButton(TBID id, bool focused);
61  // TBWidgetListener
62  virtual void OnWidgetDelete(TBWidget *widget);
63  virtual bool OnWidgetDying(TBWidget *widget);
64  TBWidgetSafePointer m_dimmer;
65  TBWidgetSafePointer m_target;
66 };
67 
68 } // namespace tb
69 
70 #endif // TB_MESSAGE_WINDOW_H
The base TBWidget class.
Definition: tb_widgets.h:418
TBWidgetSafePointer keeps a pointer to a widget that will be set to nullptr if the widget is removed...
Definition: tb_widgets_listener.h:74
TBWidgetListener listens to some callbacks from TBWidget.
Definition: tb_widgets_listener.h:28
Definition: tb_widgets.h:112
TB_TEXT_ALIGN
TB_TEXT_ALIGN specifies horizontal text alignment.
Definition: tb_widgets_common.h:22
TBWindow is a TBWidget that provides some window-like features.
Definition: tb_window.h:33
Aligned left.
Definition: tb_widgets_common.h:23
TB_TEXT_ALIGN align
Text alignment in message box.
Definition: tb_message_window.h:32
TBMessageWindowSettings contains additional settings for TBMessageWindow.
Definition: tb_message_window.h:22
bool styling
Enable styling in the textfield.
Definition: tb_message_window.h:31
virtual bool OnEvent(const TBWidgetEvent &ev)
Callback for handling events.
Definition: tb_message_window.cpp:126
TBWidget * Get() const
Return the widget, or nullptr if it has been deleted.
Definition: tb_widgets_listener.h:85
TBID is a wrapper for a uint32_t to be used as ID.
Definition: tb_id.h:18
TBStr is a simple string class.
Definition: tb_str.h:62
bool dimmer
Set to true to dim background widgets by a TBDimmer.
Definition: tb_message_window.h:30
virtual TBWidget * GetEventDestination()
Get the widget that should receive the events this widget invoke.
Definition: tb_message_window.h:55
TBMessageWindow is a window for showing simple messages.
Definition: tb_message_window.h:44
virtual void OnDie()
Called when Die() is called on this widget.
Definition: tb_message_window.cpp:156
TB_MSG msg
The type of response for the message.
Definition: tb_message_window.h:28
TBID icon_skin
The icon skin (0 for no icon)
Definition: tb_message_window.h:29