forked from aseprite/aseprite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
move_region.cpp
72 lines (59 loc) · 1.73 KB
/
move_region.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Aseprite UI Library
// 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/manager.h"
#include "she/display.h"
#include "she/surface.h"
#include "she/system.h"
#include <vector>
namespace ui {
using namespace gfx;
void move_region(Manager* manager, const Region& region, int dx, int dy)
{
she::System* system = she::instance();
she::Display* display = Manager::getDefault()->getDisplay();
ASSERT(display);
if (!display)
return;
she::Surface* surface = display->getSurface();
she::SurfaceLock lock(surface);
std::size_t nrects = region.size();
// Blit directly screen to screen.
if (nrects == 1) {
gfx::Rect rc = region[0];
surface->scrollTo(rc, dx, dy);
rc.offset(dx, dy);
Manager::getDefault()->dirtyRect(rc);
}
// Blit saving areas and copy them.
else if (nrects > 1) {
std::vector<she::Surface*> images(nrects);
Region::const_iterator it, begin=region.begin(), end=region.end();
int c;
for (c=0, it=begin; it != end; ++it, ++c) {
const Rect& rc = *it;
she::Surface* tmpSur = system->createSurface(rc.w, rc.h);
{
she::SurfaceLock tmpSurLock(tmpSur);
surface->blitTo(tmpSur, rc.x, rc.y, 0, 0, rc.w, rc.h);
}
images[c] = tmpSur;
}
for (c=0, it=begin; it != end; ++it, ++c) {
gfx::Rect rc((*it).x+dx, (*it).y+dy, (*it).w, (*it).h);
she::Surface* tmpSur = images[c];
{
she::SurfaceLock tmpSurLock(tmpSur);
tmpSur->blitTo(surface, 0, 0, rc.x, rc.y, rc.w, rc.h);
manager->dirtyRect(rc);
}
tmpSur->dispose();
}
}
}
} // namespace ui