mirror of
https://github.com/aseprite/aseprite.git
synced 2025-03-27 11:37:39 +00:00
Improve ui::Theme::drawSlices() performance using os::Surface::drawSurfaceNine()
This commit is contained in:
parent
f5000f7414
commit
84b44a36ea
2
laf
2
laf
@ -1 +1 @@
|
||||
Subproject commit 6586d40005077d5a4ede8375d7f4c8ed0f44b3fe
|
||||
Subproject commit 05592ba7b36b0eb22d50b4ae5c5b160a0794b05d
|
@ -253,6 +253,20 @@ void Graphics::drawColoredRgbaSurface(os::Surface* surface, gfx::Color color,
|
||||
gfx::Clip(m_dx+dstx, m_dy+dsty, srcx, srcy, w, h));
|
||||
}
|
||||
|
||||
void Graphics::drawSurfaceNine(os::Surface* surface,
|
||||
const gfx::Rect& src,
|
||||
const gfx::Rect& center,
|
||||
const gfx::Rect& dst,
|
||||
const ui::Paint* paint)
|
||||
{
|
||||
gfx::Rect displacedDst(m_dx+dst.x, m_dy+dst.y, dst.w, dst.h);
|
||||
dirty(displacedDst);
|
||||
|
||||
os::SurfaceLock lockSrc(surface);
|
||||
os::SurfaceLock lockDst(m_surface);
|
||||
m_surface->drawSurfaceNine(surface, src, center, displacedDst, paint);
|
||||
}
|
||||
|
||||
void Graphics::blit(os::Surface* srcSurface, int srcx, int srcy, int dstx, int dsty, int w, int h)
|
||||
{
|
||||
dirty(gfx::Rect(m_dx+dstx, m_dy+dsty, w, h));
|
||||
|
@ -1,4 +1,5 @@
|
||||
// Aseprite UI Library
|
||||
// Copyright (C) 2019 Igara Studio S.A.
|
||||
// Copyright (C) 2001-2018 David Capello
|
||||
//
|
||||
// This file is released under the terms of the MIT license.
|
||||
@ -15,6 +16,7 @@
|
||||
#include "gfx/point.h"
|
||||
#include "gfx/rect.h"
|
||||
#include "gfx/size.h"
|
||||
#include "os/paint.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
@ -29,6 +31,7 @@ namespace os {
|
||||
}
|
||||
|
||||
namespace ui {
|
||||
using os::Paint;
|
||||
|
||||
// Class to render a widget in the screen.
|
||||
class Graphics {
|
||||
@ -83,6 +86,11 @@ namespace ui {
|
||||
const gfx::Rect& dstRect);
|
||||
void drawColoredRgbaSurface(os::Surface* surface, gfx::Color color, int x, int y);
|
||||
void drawColoredRgbaSurface(os::Surface* surface, gfx::Color color, int srcx, int srcy, int dstx, int dsty, int w, int h);
|
||||
void drawSurfaceNine(os::Surface* surface,
|
||||
const gfx::Rect& src,
|
||||
const gfx::Rect& center,
|
||||
const gfx::Rect& dst,
|
||||
const Paint* paint = nullptr);
|
||||
|
||||
void blit(os::Surface* src, int srcx, int srcy, int dstx, int dsty, int w, int h);
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
// Aseprite UI Library
|
||||
// Copyright (C) 2019 Igara Studio S.A.
|
||||
// Copyright (C) 2001-2018 David Capello
|
||||
//
|
||||
// This file is released under the terms of the MIT license.
|
||||
@ -695,74 +696,11 @@ void Theme::drawSlices(Graphics* g, os::Surface* sheet,
|
||||
const gfx::Color color,
|
||||
const bool drawCenter)
|
||||
{
|
||||
const int w1 = slices.x;
|
||||
const int h1 = slices.y;
|
||||
const int w2 = slices.w;
|
||||
const int h2 = slices.h;
|
||||
const int w3 = sprite.w-w1-w2;
|
||||
const int h3 = sprite.h-h1-h2;
|
||||
const int x2 = rc.x2()-w3;
|
||||
const int y2 = rc.y2()-h3;
|
||||
auto draw = getDrawSurfaceFunction(g, sheet, color);
|
||||
|
||||
// Top
|
||||
int x = rc.x;
|
||||
int y = rc.y;
|
||||
draw(sprite.x, sprite.y,
|
||||
x, y, w1, h1);
|
||||
{
|
||||
IntersectClip clip(g, gfx::Rect(rc.x+w1, rc.y, rc.w-w1-w3, h1));
|
||||
if (clip) {
|
||||
for (x+=w1; x<x2; x+=w2) {
|
||||
draw(sprite.x+w1, sprite.y,
|
||||
x, y, w2, h1);
|
||||
}
|
||||
}
|
||||
}
|
||||
draw(sprite.x+w1+w2, sprite.y,
|
||||
x2, y, w3, h1);
|
||||
|
||||
// Bottom
|
||||
x = rc.x;
|
||||
y = y2;
|
||||
draw(sprite.x, sprite.y+h1+h2,
|
||||
x, y, w1, h3);
|
||||
{
|
||||
IntersectClip clip(g, gfx::Rect(rc.x+w1, y2, rc.w-w1-w3, h3));
|
||||
if (clip) {
|
||||
for (x+=w1; x<x2; x+=w2) {
|
||||
draw(sprite.x+w1, sprite.y+h1+h2,
|
||||
x, y2, w2, h3);
|
||||
}
|
||||
}
|
||||
}
|
||||
draw(sprite.x+w1+w2, sprite.y+h1+h2,
|
||||
x2, y2, w3, h3);
|
||||
|
||||
// Left & Right
|
||||
IntersectClip clip(g, gfx::Rect(rc.x, rc.y+h1, rc.w, rc.h-h1-h3));
|
||||
if (clip) {
|
||||
for (y=rc.y+h1; y<y2; y+=h2) {
|
||||
// Left
|
||||
draw(sprite.x, sprite.y+h1,
|
||||
rc.x, y, w1, h2);
|
||||
// Right
|
||||
draw(sprite.x+w1+w2, sprite.y+h1,
|
||||
x2, y, w3, h2);
|
||||
}
|
||||
}
|
||||
|
||||
// Center
|
||||
if (drawCenter) {
|
||||
IntersectClip clip(g, gfx::Rect(rc.x+w1, rc.y+h1, rc.w-w1-w3, rc.h-h1-h3));
|
||||
if (clip) {
|
||||
for (y=rc.y+h1; y<y2; y+=h2) {
|
||||
for (x=rc.x+w1; x<x2; x+=w2)
|
||||
draw(sprite.x+w1, sprite.y+h1,
|
||||
x, y, w2, h2);
|
||||
}
|
||||
}
|
||||
}
|
||||
Paint paint;
|
||||
paint.color(color);
|
||||
if (!drawCenter)
|
||||
paint.setFlags(Paint::kNineWithoutCenter);
|
||||
g->drawSurfaceNine(sheet, sprite, slices, rc, &paint);
|
||||
}
|
||||
|
||||
// static
|
||||
|
Loading…
x
Reference in New Issue
Block a user