| 1 | // Aseprite UI Library |
|---|---|
| 2 | // Copyright (C) 2020-2021 Igara Studio S.A. |
| 3 | // Copyright (C) 2001-2016 David Capello |
| 4 | // |
| 5 | // This file is released under the terms of the MIT license. |
| 6 | // Read LICENSE.txt for more information. |
| 7 | |
| 8 | #ifdef HAVE_CONFIG_H |
| 9 | #include "config.h" |
| 10 | #endif |
| 11 | |
| 12 | #include "ui/cursor.h" |
| 13 | |
| 14 | #include "base/debug.h" |
| 15 | #include "os/surface.h" |
| 16 | #include "os/system.h" |
| 17 | |
| 18 | namespace ui { |
| 19 | |
| 20 | Cursor::Cursor(const os::SurfaceRef& surface, |
| 21 | const gfx::Point& focus) |
| 22 | : m_surface(surface) |
| 23 | , m_focus(focus) |
| 24 | , m_scale(0) |
| 25 | { |
| 26 | } |
| 27 | |
| 28 | void Cursor::reset() |
| 29 | { |
| 30 | m_surface.reset(); |
| 31 | m_cursor.reset(); |
| 32 | m_focus = gfx::Point(0, 0); |
| 33 | m_scale = 0; |
| 34 | } |
| 35 | |
| 36 | os::CursorRef Cursor::nativeCursor(const int scale) const |
| 37 | { |
| 38 | if (m_cursor && m_scale == scale) |
| 39 | return m_cursor; |
| 40 | |
| 41 | m_cursor = os::instance()->makeCursor( |
| 42 | m_surface.get(), |
| 43 | m_focus, |
| 44 | m_scale = scale); |
| 45 | return m_cursor; |
| 46 | } |
| 47 | |
| 48 | } // namespace ui |
| 49 |