aseprite/src/ui/image_view.cpp
David Capello c42c5e1453 Backport new laf API to main branch of aseprite
Some features from the beta branch of aseprite & laf were backported
to the main branch of aseprite.

Related commits:
- New memory handling (db4504e816ffccf0ea63a78737ebb6e22cc0453b)
- New get event with timeout (e6ec13cc31e6e689040bc651f98ee1752834d14c)
- Convert os::NativeCursor to an enum (06a5b4f3aebfafb6363ea33d349975d6e419ca7b)
- Adapt code to the new os::Display -> os::Window refactor (5d31314cdb23f314391e5eaebd7cea84f5179ac7)
- Save/load main window layout correctly and limit to current workarea (d6acb9e20f11fda938959c99285fe4f7d7051794)
- Redraw window immediately on "live resizing" (d0b39ebade7736d47e6b2450bf68b088c0da8e57)
2021-07-05 17:51:29 -03:00

57 lines
1.2 KiB
C++

// Aseprite UI Library
// Copyright (C) 2020 Igara Studio S.A.
// Copyright (C) 2001-2016 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "ui/image_view.h"
#include "os/surface.h"
#include "ui/graphics.h"
#include "ui/message.h"
#include "ui/paint_event.h"
#include "ui/size_hint_event.h"
#include "ui/system.h"
#include "ui/theme.h"
namespace ui {
ImageView::ImageView(const os::SurfaceRef& sur, int align)
: Widget(kImageViewWidget)
, m_sur(sur)
{
setAlign(align);
}
void ImageView::onSizeHint(SizeHintEvent& ev)
{
gfx::Rect box;
getTextIconInfo(&box, nullptr, nullptr,
align(), m_sur->width(), m_sur->height());
ev.setSizeHint(
gfx::Size(
box.w + border().width(),
box.h + border().height()));
}
void ImageView::onPaint(PaintEvent& ev)
{
Graphics* g = ev.graphics();
gfx::Rect bounds = clientBounds();
gfx::Rect icon;
getTextIconInfo(
nullptr, nullptr, &icon, align(),
m_sur->width(), m_sur->height());
g->fillRect(bgColor(), bounds);
g->drawRgbaSurface(m_sur.get(), icon.x, icon.y);
}
} // namespace ui