Don't use allegro.h in ui::move_region()

This commit is contained in:
David Capello 2014-09-19 11:08:39 -03:00
parent a5a5d1db81
commit 30d09c9334
8 changed files with 55 additions and 31 deletions

View File

@ -11,7 +11,6 @@ add_library(ui-lib
component.cpp
cursor.cpp
custom_label.cpp
draw.cpp
entry.cpp
event.cpp
graphics.cpp
@ -27,6 +26,7 @@ add_library(ui-lib
menu.cpp
message.cpp
message_loop.cpp
move_region.cpp
overlay.cpp
overlay_manager.cpp
paint_event.cpp

View File

@ -11,7 +11,6 @@
#include "ui/image_view.h"
#include "she/surface.h"
#include "ui/draw.h"
#include "ui/graphics.h"
#include "ui/message.h"
#include "ui/paint_event.h"

View File

@ -1,5 +1,5 @@
// Aseprite UI Library
// Copyright (C) 2001-2013 David Capello
// Copyright (C) 2001-2014 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
@ -8,61 +8,65 @@
#include "config.h"
#endif
#include "ui/draw.h"
#include "ui/intern.h"
#include "ui/manager.h"
#include "ui/system.h"
#include "ui/widget.h"
#include "she/display.h"
#include "she/locked_surface.h"
#include "she/scoped_surface_lock.h"
#include "she/surface.h"
#include "she/system.h"
#include <allegro.h>
#include <vector>
namespace ui {
using namespace gfx;
void _move_region(const Region& region, int dx, int dy)
void move_region(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);
if (!display)
return;
BITMAP* native_bmp = reinterpret_cast<BITMAP*>(display->getSurface()->nativeHandle());
she::ScopedSurfaceLock lock(display->getSurface());
size_t nrects = region.size();
// Blit directly screen to screen.
if (is_linear_bitmap(native_bmp) && nrects == 1) {
if (nrects == 1) {
Rect rc = region[0];
blit(native_bmp, native_bmp, rc.x, rc.y, rc.x+dx, rc.y+dy, rc.w, rc.h);
lock->blitTo(lock, rc.x, rc.y, rc.x+dx, rc.y+dy, rc.w, rc.h);
}
// Blit saving areas and copy them.
else if (nrects > 1) {
std::vector<BITMAP*> images(nrects);
std::vector<she::Surface*> images(nrects);
Region::const_iterator it, begin=region.begin(), end=region.end();
BITMAP* bmp;
she::Surface* sur;
int c;
for (c=0, it=begin; it != end; ++it, ++c) {
const Rect& rc = *it;
bmp = create_bitmap(rc.w, rc.h);
blit(native_bmp, bmp, rc.x, rc.y, 0, 0, bmp->w, bmp->h);
images[c] = bmp;
sur = system->createSurface(rc.w, rc.h);
{
she::ScopedSurfaceLock surlock(sur);
lock->blitTo(surlock, rc.x, rc.y, 0, 0, rc.w, rc.h);
}
images[c] = sur;
}
for (c=0, it=begin; it != end; ++it, ++c) {
const Rect& rc = *it;
bmp = images[c];
blit(bmp, native_bmp, 0, 0, rc.x+dx, rc.y+dy, bmp->w, bmp->h);
destroy_bitmap(bmp);
sur = images[c];
{
she::ScopedSurfaceLock surlock(sur);
surlock->blitTo(lock, 0, 0, rc.x+dx, rc.y+dy, rc.w, rc.h);
}
sur->dispose();
}
}
}

View File

@ -1,18 +1,18 @@
// Aseprite UI Library
// Copyright (C) 2001-2013 David Capello
// Copyright (C) 2001-2014 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
#ifndef UI_DRAW_H_INCLUDED
#define UI_DRAW_H_INCLUDED
#ifndef UI_MOVE_REGION_H_INCLUDED
#define UI_MOVE_REGION_H_INCLUDED
#pragma once
#include "gfx/region.h"
namespace ui { // TODO all these functions are deprecated and must be replaced by Graphics methods.
void _move_region(const gfx::Region& region, int dx, int dy);
void move_region(const gfx::Region& region, int dx, int dy);
} // namespace ui

View File

@ -12,7 +12,6 @@
#include "gfx/size.h"
#include "she/font.h"
#include "she/system.h"
#include "ui/draw.h"
#include "ui/intern.h"
#include "ui/manager.h"
#include "ui/system.h"

View File

@ -19,7 +19,6 @@
#include "ui/cursor.h"
#include "ui/cursor_type.h"
#include "ui/custom_label.h"
#include "ui/draw.h"
#include "ui/entry.h"
#include "ui/event.h"
#include "ui/graphics.h"

View File

@ -10,14 +10,29 @@
#include "config.h"
#endif
#include "ui/widget.h"
#include "base/memory.h"
#include "she/display.h"
#include "she/font.h"
#include "she/scoped_surface_lock.h"
#include "she/surface.h"
#include "she/system.h"
#include "ui/init_theme_event.h"
#include "ui/intern.h"
#include "ui/ui.h"
#include "ui/layout_io.h"
#include "ui/load_layout_event.h"
#include "ui/manager.h"
#include "ui/message.h"
#include "ui/move_region.h"
#include "ui/paint_event.h"
#include "ui/preferred_size_event.h"
#include "ui/resize_event.h"
#include "ui/save_layout_event.h"
#include "ui/system.h"
#include "ui/theme.h"
#include "ui/view.h"
#include "ui/window.h"
#include <cctype>
#include <climits>
@ -1045,7 +1060,7 @@ void Widget::scrollRegion(const Region& region, int dx, int dy)
reg2.offset(-dx, -dy);
// Move screen pixels
ui::_move_region(reg2, dx, dy);
ui::move_region(reg2, dx, dy);
reg2.offset(dx, dy);

View File

@ -8,11 +8,19 @@
#include "config.h"
#endif
#include "ui/window.h"
#include "gfx/size.h"
#include "ui/graphics.h"
#include "ui/intern.h"
#include "ui/manager.h"
#include "ui/message.h"
#include "ui/message_loop.h"
#include "ui/move_region.h"
#include "ui/preferred_size_event.h"
#include "ui/ui.h"
#include "ui/resize_event.h"
#include "ui/system.h"
#include "ui/theme.h"
namespace ui {
@ -570,7 +578,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(moveableRegion, dx, dy);
}
}
jmouse_show();