diff --git a/src/she/alleg4/surface.h b/src/she/alleg4/surface.h index e1b9c7fd4..74a6b58ca 100644 --- a/src/she/alleg4/surface.h +++ b/src/she/alleg4/surface.h @@ -349,6 +349,13 @@ namespace she { width, height); } + void scrollTo(const gfx::Rect& rc, int dx, int dy) override { + blit(m_bmp, m_bmp, + rc.x, rc.y, + rc.x+dx, rc.y+dy, + rc.w, rc.h); + } + void drawSurface(const LockedSurface* src, int dstx, int dsty) override { draw_sprite(m_bmp, static_cast(src)->m_bmp, dstx, dsty); } diff --git a/src/she/locked_surface.h b/src/she/locked_surface.h index bb22f013c..bee2615d3 100644 --- a/src/she/locked_surface.h +++ b/src/she/locked_surface.h @@ -44,6 +44,7 @@ namespace she { virtual void fillRect(gfx::Color color, const gfx::Rect& rc) = 0; virtual void blitTo(LockedSurface* dest, int srcx, int srcy, int dstx, int dsty, int width, int height) const = 0; + virtual void scrollTo(const gfx::Rect& rc, int dx, int dy) = 0; virtual void drawSurface(const LockedSurface* src, int dstx, int dsty) = 0; virtual void drawRgbaSurface(const LockedSurface* src, int dstx, int dsty) = 0; virtual void drawColoredRgbaSurface(const LockedSurface* src, gfx::Color fg, gfx::Color bg, const gfx::Clip& clip) = 0; diff --git a/src/she/skia/skia_surface.h b/src/she/skia/skia_surface.h index 1c71341f7..0da92b82e 100644 --- a/src/she/skia/skia_surface.h +++ b/src/she/skia/skia_surface.h @@ -258,6 +258,39 @@ public: ((SkiaSurface*)dest)->m_canvas->drawBitmapRectToRect(m_bitmap, &srcRect, dstRect, &paint); } + void scrollTo(const gfx::Rect& rc, int dx, int dy) override { + int w = m_bitmap.width(); + int h = m_bitmap.height(); + gfx::Clip clip(rc.x+dx, rc.y+dy, rc); + if (!clip.clip(w, h, w, h)) + return; + + int bytesPerPixel = m_bitmap.bytesPerPixel(); + int rowBytes = (int)m_bitmap.rowBytes(); + int rowDelta; + + if (dy > 0) { + clip.src.y += clip.size.h-1; + clip.dst.y += clip.size.h-1; + rowDelta = -rowBytes; + } + else + rowDelta = rowBytes; + + char* dst = (char*)m_bitmap.getPixels(); + const char* src = dst; + dst += rowBytes*clip.dst.y + bytesPerPixel*clip.dst.x; + src += rowBytes*clip.src.y + bytesPerPixel*clip.src.x; + w = bytesPerPixel*clip.size.w; + h = clip.size.h; + + while (--h >= 0) { + memmove(dst, src, w); + dst += rowDelta; + src += rowDelta; + } + } + void drawSurface(const LockedSurface* src, int dstx, int dsty) override { gfx::Clip clip(dstx, dsty, 0, 0, ((SkiaSurface*)src)->m_bitmap.width(), diff --git a/src/ui/move_region.cpp b/src/ui/move_region.cpp index c383f40ba..2763f5a5d 100644 --- a/src/ui/move_region.cpp +++ b/src/ui/move_region.cpp @@ -22,12 +22,8 @@ namespace ui { using namespace gfx; -void move_region(const Region& region, int dx, int dy) +void move_region(Manager* manager, const Region& region, int dx, int dy) { - ASSERT(Manager::getDefault()); - if (!Manager::getDefault()) - return; - she::System* system = she::instance(); she::Display* display = Manager::getDefault()->getDisplay(); ASSERT(display); @@ -40,7 +36,7 @@ void move_region(const Region& region, int dx, int dy) // Blit directly screen to screen. if (nrects == 1) { Rect rc = region[0]; - lock->blitTo(lock, rc.x, rc.y, rc.x+dx, rc.y+dy, rc.w, rc.h); + lock->scrollTo(rc, dx, dy); } // Blit saving areas and copy them. else if (nrects > 1) { diff --git a/src/ui/move_region.h b/src/ui/move_region.h index 2f046708d..e945fc231 100644 --- a/src/ui/move_region.h +++ b/src/ui/move_region.h @@ -1,5 +1,5 @@ // Aseprite UI Library -// Copyright (C) 2001-2014 David Capello +// Copyright (C) 2001-2015 David Capello // // This file is released under the terms of the MIT license. // Read LICENSE.txt for more information. @@ -10,9 +10,11 @@ #include "gfx/region.h" -namespace ui { // TODO all these functions are deprecated and must be replaced by Graphics methods. +namespace ui { - void move_region(const gfx::Region& region, int dx, int dy); + class Manager; + + void move_region(Manager* manager, const gfx::Region& region, int dx, int dy); } // namespace ui diff --git a/src/ui/widget.cpp b/src/ui/widget.cpp index 6c4218a2c..0c091cfbf 100644 --- a/src/ui/widget.cpp +++ b/src/ui/widget.cpp @@ -1068,7 +1068,7 @@ void Widget::scrollRegion(const Region& region, const Point& delta) reg2.offset(-delta); // Move screen pixels - ui::move_region(reg2, delta.x, delta.y); + ui::move_region(getManager(), reg2, delta.x, delta.y); reg2.offset(delta); diff --git a/src/ui/window.cpp b/src/ui/window.cpp index cac8dff0a..7c7f34fe3 100644 --- a/src/ui/window.cpp +++ b/src/ui/window.cpp @@ -577,7 +577,7 @@ void Window::moveWindow(const gfx::Rect& rect, bool use_blit) { IntersectClip clip(&g, man_pos); if (clip) { - ui::move_region(moveableRegion, dx, dy); + ui::move_region(manager, moveableRegion, dx, dy); } } show_mouse_cursor();