2013-08-09 08:01:20 +08:00
|
|
|
// Aseprite UI Library
|
2018-11-16 02:42:50 +08:00
|
|
|
// Copyright (C) 2018 Igara Studio S.A.
|
2016-03-09 22:00:17 +08:00
|
|
|
// Copyright (C) 2001-2016 David Capello
|
2012-08-06 12:17:29 +08:00
|
|
|
//
|
2014-03-30 07:08:05 +08:00
|
|
|
// This file is released under the terms of the MIT license.
|
|
|
|
// Read LICENSE.txt for more information.
|
2012-08-06 12:17:29 +08:00
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
#ifdef HAVE_CONFIG_H
|
2012-08-06 12:17:29 +08:00
|
|
|
#include "config.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#endif
|
2012-08-06 12:17:29 +08:00
|
|
|
|
|
|
|
#include "ui/overlay.h"
|
|
|
|
|
2018-08-09 23:58:43 +08:00
|
|
|
#include "os/surface.h"
|
|
|
|
#include "os/system.h"
|
2012-08-06 12:17:29 +08:00
|
|
|
#include "ui/manager.h"
|
|
|
|
|
|
|
|
namespace ui {
|
|
|
|
|
2020-07-08 06:06:48 +08:00
|
|
|
Overlay::Overlay(const os::SurfaceRef& overlaySurface,
|
|
|
|
const gfx::Point& pos,
|
|
|
|
ZOrder zorder)
|
2012-08-06 12:17:29 +08:00
|
|
|
: m_surface(overlaySurface)
|
2018-11-16 02:42:50 +08:00
|
|
|
, m_overlap(nullptr)
|
|
|
|
, m_captured(nullptr)
|
2012-08-06 12:17:29 +08:00
|
|
|
, m_pos(pos)
|
|
|
|
, m_zorder(zorder)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Overlay::~Overlay()
|
|
|
|
{
|
2018-11-16 02:42:50 +08:00
|
|
|
ASSERT(!m_captured);
|
|
|
|
|
2012-08-11 10:14:54 +08:00
|
|
|
if (m_surface) {
|
|
|
|
Manager* manager = Manager::getDefault();
|
|
|
|
if (manager)
|
|
|
|
manager->invalidateRect(gfx::Rect(m_pos.x, m_pos.y,
|
|
|
|
m_surface->width(),
|
|
|
|
m_surface->height()));
|
2020-07-08 06:06:48 +08:00
|
|
|
m_surface.reset();
|
2012-08-11 10:14:54 +08:00
|
|
|
}
|
|
|
|
|
2012-08-06 12:17:29 +08:00
|
|
|
if (m_overlap)
|
2020-07-08 06:06:48 +08:00
|
|
|
m_overlap.reset();
|
2012-08-06 12:17:29 +08:00
|
|
|
}
|
|
|
|
|
2020-07-08 06:06:48 +08:00
|
|
|
os::SurfaceRef Overlay::setSurface(const os::SurfaceRef& newSurface)
|
2012-08-11 10:14:54 +08:00
|
|
|
{
|
2020-07-08 06:06:48 +08:00
|
|
|
os::SurfaceRef oldSurface = m_surface;
|
2012-08-11 10:14:54 +08:00
|
|
|
m_surface = newSurface;
|
|
|
|
return oldSurface;
|
|
|
|
}
|
|
|
|
|
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 Overlay::bounds() const
|
2012-08-06 12:17:29 +08:00
|
|
|
{
|
2012-08-11 10:14:54 +08:00
|
|
|
if (m_surface)
|
|
|
|
return gfx::Rect(m_pos.x, m_pos.y, m_surface->width(), m_surface->height());
|
|
|
|
else
|
|
|
|
return gfx::Rect(0, 0, 0, 0);
|
2012-08-06 12:17:29 +08:00
|
|
|
}
|
|
|
|
|
2018-11-16 02:42:50 +08:00
|
|
|
void Overlay::drawOverlay()
|
2012-08-06 12:17:29 +08:00
|
|
|
{
|
2018-11-16 02:42:50 +08:00
|
|
|
if (!m_surface ||
|
|
|
|
!m_captured)
|
2012-08-11 10:14:54 +08:00
|
|
|
return;
|
|
|
|
|
2020-07-08 06:06:48 +08:00
|
|
|
os::SurfaceLock lock(m_surface.get());
|
|
|
|
m_captured->drawRgbaSurface(m_surface.get(), m_pos.x, m_pos.y);
|
2015-08-24 21:14:25 +08:00
|
|
|
|
2015-08-24 22:56:40 +08:00
|
|
|
Manager::getDefault()->dirtyRect(
|
|
|
|
gfx::Rect(m_pos.x, m_pos.y,
|
|
|
|
m_surface->width(),
|
|
|
|
m_surface->height()));
|
2012-08-06 12:17:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void Overlay::moveOverlay(const gfx::Point& newPos)
|
|
|
|
{
|
2018-11-16 02:42:50 +08:00
|
|
|
if (m_captured)
|
|
|
|
restoreOverlappedArea(gfx::Rect());
|
|
|
|
|
2012-08-06 12:17:29 +08:00
|
|
|
m_pos = newPos;
|
|
|
|
}
|
|
|
|
|
2018-08-09 23:58:43 +08:00
|
|
|
void Overlay::captureOverlappedArea(os::Surface* screen)
|
2012-08-06 12:17:29 +08:00
|
|
|
{
|
2018-11-16 02:42:50 +08:00
|
|
|
if (!m_surface ||
|
|
|
|
m_captured)
|
2012-08-11 10:14:54 +08:00
|
|
|
return;
|
|
|
|
|
2018-10-31 22:10:44 +08:00
|
|
|
if (!m_overlap) {
|
|
|
|
// Use the same color space for the overlay as in the screen
|
2020-07-08 06:06:48 +08:00
|
|
|
m_overlap = os::instance()->makeSurface(m_surface->width(),
|
|
|
|
m_surface->height(),
|
|
|
|
screen->colorSpace());
|
2018-10-31 22:10:44 +08:00
|
|
|
}
|
2012-08-06 12:17:29 +08:00
|
|
|
|
2020-07-08 06:06:48 +08:00
|
|
|
os::SurfaceLock lock(m_overlap.get());
|
|
|
|
screen->blitTo(m_overlap.get(), m_pos.x, m_pos.y, 0, 0,
|
2012-08-06 12:17:29 +08:00
|
|
|
m_overlap->width(), m_overlap->height());
|
2018-11-16 02:42:50 +08:00
|
|
|
|
|
|
|
m_captured = screen;
|
2012-08-06 12:17:29 +08:00
|
|
|
}
|
|
|
|
|
2018-11-16 02:42:50 +08:00
|
|
|
void Overlay::restoreOverlappedArea(const gfx::Rect& restoreBounds)
|
2012-08-06 12:17:29 +08:00
|
|
|
{
|
2018-11-16 02:42:50 +08:00
|
|
|
if (!m_surface ||
|
|
|
|
!m_overlap ||
|
|
|
|
!m_captured)
|
2012-08-11 10:14:54 +08:00
|
|
|
return;
|
|
|
|
|
2018-11-16 02:42:50 +08:00
|
|
|
if (!restoreBounds.isEmpty() &&
|
|
|
|
!restoreBounds.intersects(bounds()))
|
2012-08-06 12:17:29 +08:00
|
|
|
return;
|
|
|
|
|
2020-07-08 06:06:48 +08:00
|
|
|
os::SurfaceLock lock(m_overlap.get());
|
2018-11-16 02:42:50 +08:00
|
|
|
m_overlap->blitTo(m_captured, 0, 0, m_pos.x, m_pos.y,
|
2016-03-09 22:00:17 +08:00
|
|
|
m_overlap->width(), m_overlap->height());
|
2015-08-24 21:14:25 +08:00
|
|
|
|
2018-11-16 02:42:50 +08:00
|
|
|
Manager::getDefault()->dirtyRect(bounds());
|
|
|
|
|
|
|
|
m_captured = nullptr;
|
2012-08-06 12:17:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|