| 1 | // Aseprite UI Library |
| 2 | // Copyright (C) 2021 Igara Studio S.A. |
| 3 | // Copyright (C) 2001-2018 David Capello |
| 4 | // |
| 5 | // This file is released under the terms of the MIT license. |
| 6 | // Read LICENSE.txt for more information. |
| 7 | |
| 8 | #ifndef UI_BUTTON_H_INCLUDED |
| 9 | #define UI_BUTTON_H_INCLUDED |
| 10 | #pragma once |
| 11 | |
| 12 | #include "obs/signal.h" |
| 13 | #include "ui/widget.h" |
| 14 | |
| 15 | #include <vector> |
| 16 | |
| 17 | namespace os { |
| 18 | class Surface; |
| 19 | } |
| 20 | |
| 21 | namespace ui { |
| 22 | |
| 23 | class Event; |
| 24 | |
| 25 | // Generic button |
| 26 | class ButtonBase : public Widget { |
| 27 | public: |
| 28 | ButtonBase(const std::string& text, |
| 29 | const WidgetType type, |
| 30 | const WidgetType behaviorType, |
| 31 | const WidgetType drawType); |
| 32 | virtual ~ButtonBase(); |
| 33 | |
| 34 | WidgetType behaviorType() const; |
| 35 | // Signals |
| 36 | obs::signal<void(Event&)> Click; |
| 37 | |
| 38 | protected: |
| 39 | // Events |
| 40 | bool onProcessMessage(Message* msg) override; |
| 41 | |
| 42 | // New events |
| 43 | virtual void onClick(Event& ev); |
| 44 | virtual void onStartDrag(); |
| 45 | virtual void onSelectWhenDragging(); |
| 46 | |
| 47 | private: |
| 48 | void generateButtonSelectSignal(); |
| 49 | |
| 50 | bool m_pressedStatus; |
| 51 | WidgetType m_behaviorType; |
| 52 | |
| 53 | protected: |
| 54 | bool m_handleSelect; |
| 55 | }; |
| 56 | |
| 57 | // Pushable button to execute commands |
| 58 | class Button : public ButtonBase { |
| 59 | public: |
| 60 | Button(const std::string& text); |
| 61 | }; |
| 62 | |
| 63 | // Check boxes |
| 64 | class CheckBox : public ButtonBase { |
| 65 | public: |
| 66 | CheckBox(const std::string& text, |
| 67 | const WidgetType drawType = kCheckWidget); |
| 68 | }; |
| 69 | |
| 70 | // Radio buttons |
| 71 | class RadioButton : public ButtonBase { |
| 72 | public: |
| 73 | RadioButton(const std::string& text, |
| 74 | const int radioGroup = 0, |
| 75 | const WidgetType drawType = kRadioWidget); |
| 76 | |
| 77 | int getRadioGroup() const; |
| 78 | void setRadioGroup(int radioGroup); |
| 79 | |
| 80 | void deselectRadioGroup(); |
| 81 | |
| 82 | protected: |
| 83 | void onSelect(bool selected) override; |
| 84 | |
| 85 | private: |
| 86 | int m_radioGroup; |
| 87 | }; |
| 88 | |
| 89 | } // namespace ui |
| 90 | |
| 91 | #endif |
| 92 | |