aseprite/src/app/ui/notifications.cpp
2017-03-13 14:14:29 -03:00

85 lines
1.8 KiB
C++

// Aseprite
// Copyright (C) 2001-2017 David Capello
//
// This program is distributed under the terms of
// the End-User License Agreement for Aseprite.
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "app/ui/notifications.h"
#include "app/notification_delegate.h"
#include "app/ui/skin/skin_theme.h"
#include "app/ui/skin/style.h"
#include "base/launcher.h"
#include "ui/menu.h"
#include "ui/paint_event.h"
#include "ui/size_hint_event.h"
namespace app {
using namespace ui;
class NotificationItem : public MenuItem {
public:
NotificationItem(INotificationDelegate* del)
: MenuItem(del->notificationText()),
m_delegate(del) {
}
protected:
void onClick() override {
MenuItem::onClick();
m_delegate->notificationClick();
}
private:
INotificationDelegate* m_delegate;
};
Notifications::Notifications()
: Button("")
, m_flagStyle(skin::SkinTheme::instance()->newStyles.flag())
, m_withNotifications(false)
{
}
void Notifications::addLink(INotificationDelegate* del)
{
m_popup.addChild(new NotificationItem(del));
m_withNotifications = true;
}
void Notifications::onSizeHint(SizeHintEvent& ev)
{
ev.setSizeHint(gfx::Size(16, 10)*guiscale()); // TODO hard-coded flag size
}
void Notifications::onPaint(PaintEvent& ev)
{
Graphics* g = ev.graphics();
PaintWidgetPartInfo info;
if (hasMouseOver()) info.styleFlags |= ui::Style::Layer::kMouse;
if (m_withNotifications) info.styleFlags |= ui::Style::Layer::kFocus;
if (isSelected()) info.styleFlags |= ui::Style::Layer::kSelected;
theme()->paintWidgetPart(
g, m_flagStyle, clientBounds(), info);
}
void Notifications::onClick(ui::Event& ev)
{
m_withNotifications = false;
invalidate();
gfx::Rect bounds = this->bounds();
m_popup.showPopup(gfx::Point(
bounds.x - m_popup.sizeHint().w,
bounds.y + bounds.h));
}
} // namespace app