1// Aseprite
2// Copyright (C) 2018-2022 Igara Studio S.A.
3//
4// This program is distributed under the terms of
5// the End-User License Agreement for Aseprite.
6
7#ifdef HAVE_CONFIG_H
8#include "config.h"
9#endif
10
11#include "app/ui/selection_mode_field.h"
12
13#include "app/ui/keyboard_shortcuts.h"
14#include "app/ui/skin/skin_theme.h"
15#include "ui/tooltips.h"
16
17namespace app {
18
19using namespace app::skin;
20using namespace ui;
21
22SelectionModeField::SelectionModeField()
23 : ButtonSet(4)
24{
25 auto theme = SkinTheme::get(this);
26
27 addItem(theme->parts.selectionReplace());
28 addItem(theme->parts.selectionAdd());
29 addItem(theme->parts.selectionSubtract());
30 addItem(theme->parts.selectionIntersect());
31
32 setSelectedItem((int)Preferences::instance().selection.mode());
33}
34
35void SelectionModeField::setupTooltips(TooltipManager* tooltipManager)
36{
37 tooltipManager->addTooltipFor(
38 at(0), "Replace selection", BOTTOM);
39
40 tooltipManager->addTooltipFor(
41 at(1), key_tooltip("Add to selection", KeyAction::AddSelection), BOTTOM);
42
43 tooltipManager->addTooltipFor(
44 at(2), key_tooltip("Subtract from selection", KeyAction::SubtractSelection), BOTTOM);
45
46 tooltipManager->addTooltipFor(
47 at(3), key_tooltip("Intersect selection", KeyAction::IntersectSelection), BOTTOM);
48}
49
50gen::SelectionMode SelectionModeField::selectionMode()
51{
52 return (gen::SelectionMode)selectedItem();
53}
54
55void SelectionModeField::setSelectionMode(gen::SelectionMode mode)
56{
57 setSelectedItem((int)mode, false);
58 invalidate();
59}
60
61void SelectionModeField::onItemChange(Item* item)
62{
63 ButtonSet::onItemChange(item);
64 onSelectionModeChange(selectionMode());
65}
66
67} // namespace app
68