2015-11-25 05:37:13 +08:00
|
|
|
// Aseprite
|
2017-08-15 21:39:06 +08:00
|
|
|
// Copyright (C) 2001-2017 David Capello
|
2015-11-25 05:37:13 +08:00
|
|
|
//
|
2016-08-27 04:02:58 +08:00
|
|
|
// This program is distributed under the terms of
|
|
|
|
|
// the End-User License Agreement for Aseprite.
|
2015-11-25 05:37:13 +08:00
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
|
#include "config.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#include "app/ui/icon_button.h"
|
|
|
|
|
|
|
|
|
|
#include "app/ui/skin/skin_theme.h"
|
2018-08-09 23:58:43 +08:00
|
|
|
#include "os/surface.h"
|
2015-11-25 05:37:13 +08:00
|
|
|
#include "ui/message.h"
|
|
|
|
|
#include "ui/paint_event.h"
|
2015-12-04 08:50:05 +08:00
|
|
|
#include "ui/size_hint_event.h"
|
2015-11-25 05:37:13 +08:00
|
|
|
#include "ui/system.h"
|
|
|
|
|
|
|
|
|
|
namespace app {
|
|
|
|
|
|
|
|
|
|
using namespace ui;
|
|
|
|
|
using namespace app::skin;
|
|
|
|
|
|
2017-08-15 21:39:06 +08:00
|
|
|
IconButton::IconButton(const SkinPartPtr& part)
|
2015-11-25 05:37:13 +08:00
|
|
|
: Button("")
|
2017-08-15 21:39:06 +08:00
|
|
|
, m_part(part)
|
2015-11-25 05:37:13 +08:00
|
|
|
{
|
2017-08-15 21:39:06 +08:00
|
|
|
initTheme();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void IconButton::onInitTheme(InitThemeEvent& ev)
|
|
|
|
|
{
|
|
|
|
|
Button::onInitTheme(ev);
|
2015-11-25 05:37:13 +08:00
|
|
|
setBgColor(SkinTheme::instance()->colors.menuitemNormalFace());
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-04 08:50:05 +08:00
|
|
|
void IconButton::onSizeHint(SizeHintEvent& ev)
|
2015-11-25 05:37:13 +08:00
|
|
|
{
|
2018-08-09 23:58:43 +08:00
|
|
|
os::Surface* icon = m_part->bitmap(0);
|
2015-12-04 08:50:05 +08:00
|
|
|
ev.setSizeHint(
|
2017-08-15 21:39:06 +08:00
|
|
|
gfx::Size(icon->width(),
|
|
|
|
|
icon->height()) + 4*guiscale());
|
2015-11-25 05:37:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void IconButton::onPaint(PaintEvent& ev)
|
|
|
|
|
{
|
|
|
|
|
SkinTheme* theme = SkinTheme::instance();
|
Refactor several "getNoun()" getters to "noun()"
This is a work-in-progress to create a consistent API and finally
separate the whole Aseprite base/gfx/ui libs into a reusable C++ library.
Classes:
app::IFileItem, app::AppMenuItem, app::skin::SkinPart,
gfx::Rect, gfx::Border, she::FileDialog,
ui::IButtonIcon, ui::Graphics, ui::Overlay, ui::Widget,
ui::ScrollableViewDelegate, and UI events
2015-12-05 01:39:04 +08:00
|
|
|
Graphics* g = ev.graphics();
|
2015-11-25 05:37:13 +08:00
|
|
|
gfx::Color fg, bg;
|
|
|
|
|
|
|
|
|
|
if (isSelected()) {
|
|
|
|
|
fg = theme->colors.menuitemHighlightText();
|
|
|
|
|
bg = theme->colors.menuitemHighlightFace();
|
|
|
|
|
}
|
|
|
|
|
else if (isEnabled() && hasMouseOver()) {
|
|
|
|
|
fg = theme->colors.menuitemHotText();
|
|
|
|
|
bg = theme->colors.menuitemHotFace();
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
fg = theme->colors.menuitemNormalText();
|
Refactor several "getNoun()" getters to "noun()"
This is a work-in-progress to create a consistent API and finally
separate the whole Aseprite base/gfx/ui libs into a reusable C++ library.
Classes:
app::IFileItem, app::AppMenuItem, app::skin::SkinPart,
gfx::Rect, gfx::Border, she::FileDialog,
ui::IButtonIcon, ui::Graphics, ui::Overlay, ui::Widget,
ui::ScrollableViewDelegate, and UI events
2015-12-05 01:39:04 +08:00
|
|
|
bg = bgColor();
|
2015-11-25 05:37:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g->fillRect(bg, g->getClipBounds());
|
|
|
|
|
|
Refactor several "getNoun()" getters to "noun()"
This is a work-in-progress to create a consistent API and finally
separate the whole Aseprite base/gfx/ui libs into a reusable C++ library.
Classes:
app::IFileItem, app::AppMenuItem, app::skin::SkinPart,
gfx::Rect, gfx::Border, she::FileDialog,
ui::IButtonIcon, ui::Graphics, ui::Overlay, ui::Widget,
ui::ScrollableViewDelegate, and UI events
2015-12-05 01:39:04 +08:00
|
|
|
gfx::Rect bounds = clientBounds();
|
2018-08-09 23:58:43 +08:00
|
|
|
os::Surface* icon = m_part->bitmap(0);
|
2015-11-25 05:37:13 +08:00
|
|
|
g->drawColoredRgbaSurface(
|
2017-08-15 21:39:06 +08:00
|
|
|
icon, fg,
|
|
|
|
|
bounds.x+bounds.w/2-icon->width()/2,
|
|
|
|
|
bounds.y+bounds.h/2-icon->height()/2);
|
2015-11-25 05:37:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace app
|