1// Aseprite
2// Copyright (C) 2019 Igara Studio S.A.
3// Copyright (C) 2001-2018 David Capello
4//
5// This program is distributed under the terms of
6// the End-User License Agreement for Aseprite.
7
8#ifndef APP_UI_BUTTON_SET_H_INCLUDED
9#define APP_UI_BUTTON_SET_H_INCLUDED
10#pragma once
11
12#include "app/ui/skin/skin_part.h"
13#include "obs/signal.h"
14#include "ui/grid.h"
15
16#include <string>
17
18namespace app {
19
20 class ButtonSet : public ui::Grid {
21 public:
22 class Item : public ui::Widget {
23 public:
24 Item();
25 void setHotColor(gfx::Color color);
26 void setIcon(const skin::SkinPartPtr& icon, bool mono = false);
27 void setMono(const bool mono) { m_mono = mono; }
28 skin::SkinPartPtr icon() const { return m_icon; }
29 ButtonSet* buttonSet();
30 protected:
31 void onPaint(ui::PaintEvent& ev) override;
32 bool onProcessMessage(ui::Message* msg) override;
33 void onSizeHint(ui::SizeHintEvent& ev) override;
34 virtual void onClick();
35 virtual void onRightClick();
36 private:
37 skin::SkinPartPtr m_icon;
38 bool m_mono;
39 gfx::Color m_hotColor;
40 };
41
42 enum class MultiMode {
43 One, // Only one button can be selected (like radio buttons)
44 Set, // Each button is a checkbox
45 OneOrMore, // One click selects one button, ctrl+click multiple selections
46 };
47
48 ButtonSet(int columns);
49
50 Item* addItem(const std::string& text, int hspan = 1, int vspan = 1);
51 Item* addItem(const skin::SkinPartPtr& icon, int hspan = 1, int vspan = 1);
52 Item* addItem(Item* item, int hspan = 1, int vspan = 1);
53 Item* getItem(int index);
54 int getItemIndex(const Item* item) const;
55
56 int selectedItem() const;
57 int countSelectedItems() const;
58 Item* findSelectedItem() const;
59 void setSelectedItem(int index, bool focusItem = true);
60 void setSelectedItem(Item* item, bool focusItem = true);
61 void deselectItems();
62
63 void setOfferCapture(bool state);
64 void setTriggerOnMouseUp(bool state);
65 void setMultiMode(MultiMode mode);
66
67 obs::signal<void(Item*)> ItemChange;
68 obs::signal<void(Item*)> RightClick;
69
70 protected:
71 virtual void onItemChange(Item* item);
72 virtual void onRightClick(Item* item);
73 virtual void onSelectItem(Item* item, bool focusItem, ui::Message* msg);
74
75 private:
76 bool m_offerCapture;
77 bool m_triggerOnMouseUp;
78 MultiMode m_multiMode;
79 };
80
81} // namespace app
82
83#endif
84