mirror of
https://github.com/aseprite/aseprite.git
synced 2025-04-09 18:44:46 +00:00
Replace internal doc::Brush image with a doc::ImageRef
This commit is contained in:
parent
3810cfc1fa
commit
4a05436252
@ -24,7 +24,6 @@ Brush::Brush()
|
|||||||
m_type = kCircleBrushType;
|
m_type = kCircleBrushType;
|
||||||
m_size = 1;
|
m_size = 1;
|
||||||
m_angle = 0;
|
m_angle = 0;
|
||||||
m_image = NULL;
|
|
||||||
|
|
||||||
regenerate();
|
regenerate();
|
||||||
}
|
}
|
||||||
@ -34,7 +33,6 @@ Brush::Brush(BrushType type, int size, int angle)
|
|||||||
m_type = type;
|
m_type = type;
|
||||||
m_size = size;
|
m_size = size;
|
||||||
m_angle = angle;
|
m_angle = angle;
|
||||||
m_image = NULL;
|
|
||||||
|
|
||||||
regenerate();
|
regenerate();
|
||||||
}
|
}
|
||||||
@ -74,11 +72,7 @@ void Brush::setAngle(int angle)
|
|||||||
// Cleans the brush's data (image and region).
|
// Cleans the brush's data (image and region).
|
||||||
void Brush::clean()
|
void Brush::clean()
|
||||||
{
|
{
|
||||||
if (m_image) {
|
m_image.reset();
|
||||||
delete m_image;
|
|
||||||
m_image = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_scanline.clear();
|
m_scanline.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,23 +92,23 @@ void Brush::regenerate()
|
|||||||
if (m_type == kSquareBrushType && m_angle != 0 && m_size > 2)
|
if (m_type == kSquareBrushType && m_angle != 0 && m_size > 2)
|
||||||
size = (int)std::sqrt((double)2*m_size*m_size)+2;
|
size = (int)std::sqrt((double)2*m_size*m_size)+2;
|
||||||
|
|
||||||
m_image = Image::create(IMAGE_BITMAP, size, size);
|
m_image.reset(Image::create(IMAGE_BITMAP, size, size));
|
||||||
|
|
||||||
if (size == 1) {
|
if (size == 1) {
|
||||||
clear_image(m_image, BitmapTraits::max_value);
|
clear_image(m_image.get(), BitmapTraits::max_value);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
clear_image(m_image, BitmapTraits::min_value);
|
clear_image(m_image.get(), BitmapTraits::min_value);
|
||||||
|
|
||||||
switch (m_type) {
|
switch (m_type) {
|
||||||
|
|
||||||
case kCircleBrushType:
|
case kCircleBrushType:
|
||||||
fill_ellipse(m_image, 0, 0, size-1, size-1, BitmapTraits::max_value);
|
fill_ellipse(m_image.get(), 0, 0, size-1, size-1, BitmapTraits::max_value);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case kSquareBrushType:
|
case kSquareBrushType:
|
||||||
if (m_angle == 0 || size <= 2) {
|
if (m_angle == 0 || size <= 2) {
|
||||||
clear_image(m_image, BitmapTraits::max_value);
|
clear_image(m_image.get(), BitmapTraits::max_value);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
double a = PI * m_angle / 180;
|
double a = PI * m_angle / 180;
|
||||||
@ -131,7 +125,7 @@ void Brush::regenerate()
|
|||||||
int y4 = int(y3 - d*sin(a+PI));
|
int y4 = int(y3 - d*sin(a+PI));
|
||||||
int points[8] = { x1, y1, x2, y2, x3, y3, x4, y4 };
|
int points[8] = { x1, y1, x2, y2, x3, y3, x4, y4 };
|
||||||
|
|
||||||
doc::algorithm::polygon(4, points, m_image, algo_hline);
|
doc::algorithm::polygon(4, points, m_image.get(), algo_hline);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -144,7 +138,7 @@ void Brush::regenerate()
|
|||||||
int x2 = int(x1 + d*cos(a));
|
int x2 = int(x1 + d*cos(a));
|
||||||
int y2 = int(y1 - d*sin(a));
|
int y2 = int(y1 - d*sin(a));
|
||||||
|
|
||||||
draw_line(m_image, x1, y1, x2, y2, BitmapTraits::max_value);
|
draw_line(m_image.get(), x1, y1, x2, y2, BitmapTraits::max_value);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -155,11 +149,11 @@ void Brush::regenerate()
|
|||||||
m_scanline[y].state = false;
|
m_scanline[y].state = false;
|
||||||
|
|
||||||
for (int x=0; x<m_image->width(); x++) {
|
for (int x=0; x<m_image->width(); x++) {
|
||||||
if (get_pixel(m_image, x, y)) {
|
if (get_pixel(m_image.get(), x, y)) {
|
||||||
m_scanline[y].x1 = x;
|
m_scanline[y].x1 = x;
|
||||||
|
|
||||||
for (; x<m_image->width(); x++)
|
for (; x<m_image->width(); x++)
|
||||||
if (!get_pixel(m_image, x, y))
|
if (!get_pixel(m_image.get(), x, y))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
m_scanline[y].x2 = x-1;
|
m_scanline[y].x2 = x-1;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// Aseprite Document Library
|
// Aseprite Document Library
|
||||||
// Copyright (c) 2001-2014 David Capello
|
// Copyright (c) 2001-2015 David Capello
|
||||||
//
|
//
|
||||||
// This file is released under the terms of the MIT license.
|
// This file is released under the terms of the MIT license.
|
||||||
// Read LICENSE.txt for more information.
|
// Read LICENSE.txt for more information.
|
||||||
@ -8,15 +8,15 @@
|
|||||||
#define DOC_BRUSH_H_INCLUDED
|
#define DOC_BRUSH_H_INCLUDED
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "doc/brush_type.h"
|
||||||
|
#include "doc/image_ref.h"
|
||||||
#include "gfx/point.h"
|
#include "gfx/point.h"
|
||||||
#include "gfx/rect.h"
|
#include "gfx/rect.h"
|
||||||
#include "doc/brush_type.h"
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace doc {
|
namespace doc {
|
||||||
|
|
||||||
class Image;
|
|
||||||
|
|
||||||
struct BrushScanline {
|
struct BrushScanline {
|
||||||
int state, x1, x2;
|
int state, x1, x2;
|
||||||
};
|
};
|
||||||
@ -34,7 +34,7 @@ namespace doc {
|
|||||||
BrushType type() const { return m_type; }
|
BrushType type() const { return m_type; }
|
||||||
int size() const { return m_size; }
|
int size() const { return m_size; }
|
||||||
int angle() const { return m_angle; }
|
int angle() const { return m_angle; }
|
||||||
Image* image() { return m_image; }
|
Image* image() { return m_image.get(); }
|
||||||
const std::vector<BrushScanline>& scanline() const { return m_scanline; }
|
const std::vector<BrushScanline>& scanline() const { return m_scanline; }
|
||||||
|
|
||||||
const gfx::Rect& bounds() const { return m_bounds; }
|
const gfx::Rect& bounds() const { return m_bounds; }
|
||||||
@ -50,7 +50,7 @@ namespace doc {
|
|||||||
BrushType m_type; // Type of brush
|
BrushType m_type; // Type of brush
|
||||||
int m_size; // Size (diameter)
|
int m_size; // Size (diameter)
|
||||||
int m_angle; // Angle in degrees 0-360
|
int m_angle; // Angle in degrees 0-360
|
||||||
Image* m_image; // Image of the brush
|
ImageRef m_image; // Image of the brush
|
||||||
std::vector<BrushScanline> m_scanline;
|
std::vector<BrushScanline> m_scanline;
|
||||||
gfx::Rect m_bounds;
|
gfx::Rect m_bounds;
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user