1 | // Aseprite |
---|---|
2 | // Copyright (C) 2022 Igara Studio S.A. |
3 | // Copyright (C) 2001-2017 David Capello |
4 | // |
5 | // This program is distributed under the terms of |
6 | // the End-User License Agreement for Aseprite. |
7 | |
8 | #ifdef HAVE_CONFIG_H |
9 | #include "config.h" |
10 | #endif |
11 | |
12 | #include "app/ui/icon_button.h" |
13 | |
14 | #include "app/ui/skin/skin_theme.h" |
15 | #include "os/surface.h" |
16 | #include "ui/message.h" |
17 | #include "ui/paint_event.h" |
18 | #include "ui/size_hint_event.h" |
19 | #include "ui/system.h" |
20 | |
21 | namespace app { |
22 | |
23 | using namespace ui; |
24 | using namespace app::skin; |
25 | |
26 | IconButton::IconButton(const SkinPartPtr& part) |
27 | : Button("") |
28 | , m_part(part) |
29 | { |
30 | initTheme(); |
31 | } |
32 | |
33 | void IconButton::onInitTheme(InitThemeEvent& ev) |
34 | { |
35 | Button::onInitTheme(ev); |
36 | |
37 | auto theme = SkinTheme::get(this); |
38 | setBgColor(theme->colors.menuitemNormalFace()); |
39 | } |
40 | |
41 | void IconButton::onSizeHint(SizeHintEvent& ev) |
42 | { |
43 | os::Surface* icon = m_part->bitmap(0); |
44 | ev.setSizeHint( |
45 | gfx::Size(icon->width(), |
46 | icon->height()) + 4*guiscale()); |
47 | } |
48 | |
49 | void IconButton::onPaint(PaintEvent& ev) |
50 | { |
51 | auto theme = SkinTheme::get(this); |
52 | Graphics* g = ev.graphics(); |
53 | gfx::Color fg, bg; |
54 | |
55 | if (isSelected()) { |
56 | fg = theme->colors.menuitemHighlightText(); |
57 | bg = theme->colors.menuitemHighlightFace(); |
58 | } |
59 | else if (isEnabled() && hasMouseOver()) { |
60 | fg = theme->colors.menuitemHotText(); |
61 | bg = theme->colors.menuitemHotFace(); |
62 | } |
63 | else { |
64 | fg = theme->colors.menuitemNormalText(); |
65 | bg = bgColor(); |
66 | } |
67 | |
68 | g->fillRect(bg, g->getClipBounds()); |
69 | |
70 | gfx::Rect bounds = clientBounds(); |
71 | os::Surface* icon = m_part->bitmap(0); |
72 | g->drawColoredRgbaSurface( |
73 | icon, fg, |
74 | bounds.x+bounds.w/2-icon->width()/2, |
75 | bounds.y+bounds.h/2-icon->height()/2); |
76 | } |
77 | |
78 | } // namespace app |
79 |