mirror of
https://github.com/aseprite/aseprite.git
synced 2025-02-28 16:11:35 +00:00
Move dotted_mode() from app to she module
Replaced a huge array of marching ant patterns (which was taken from GIMP 1.3.11) with a simple formula.
This commit is contained in:
parent
b9f38b5df9
commit
0defe27dc6
@ -20,9 +20,6 @@
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <allegro.h>
|
||||
#include <allegro/internal/aintern.h>
|
||||
|
||||
#include "gfx/color.h"
|
||||
#include "ui/intern.h"
|
||||
#include "ui/system.h"
|
||||
@ -47,123 +44,6 @@ namespace app {
|
||||
using namespace app::skin;
|
||||
using namespace gfx;
|
||||
|
||||
void dotted_mode(int offset)
|
||||
{
|
||||
/* these pattern were taken from The GIMP:
|
||||
gimp-1.3.11/app/display/gimpdisplayshell-marching-ants.h */
|
||||
static int pattern_data[8][8] = {
|
||||
{
|
||||
0xF0, /* ####---- */
|
||||
0xE1, /* ###----# */
|
||||
0xC3, /* ##----## */
|
||||
0x87, /* #----### */
|
||||
0x0F, /* ----#### */
|
||||
0x1E, /* ---####- */
|
||||
0x3C, /* --####-- */
|
||||
0x78, /* -####--- */
|
||||
},
|
||||
{
|
||||
0xE1, /* ###----# */
|
||||
0xC3, /* ##----## */
|
||||
0x87, /* #----### */
|
||||
0x0F, /* ----#### */
|
||||
0x1E, /* ---####- */
|
||||
0x3C, /* --####-- */
|
||||
0x78, /* -####--- */
|
||||
0xF0, /* ####---- */
|
||||
},
|
||||
{
|
||||
0xC3, /* ##----## */
|
||||
0x87, /* #----### */
|
||||
0x0F, /* ----#### */
|
||||
0x1E, /* ---####- */
|
||||
0x3C, /* --####-- */
|
||||
0x78, /* -####--- */
|
||||
0xF0, /* ####---- */
|
||||
0xE1, /* ###----# */
|
||||
},
|
||||
{
|
||||
0x87, /* #----### */
|
||||
0x0F, /* ----#### */
|
||||
0x1E, /* ---####- */
|
||||
0x3C, /* --####-- */
|
||||
0x78, /* -####--- */
|
||||
0xF0, /* ####---- */
|
||||
0xE1, /* ###----# */
|
||||
0xC3, /* ##----## */
|
||||
},
|
||||
{
|
||||
0x0F, /* ----#### */
|
||||
0x1E, /* ---####- */
|
||||
0x3C, /* --####-- */
|
||||
0x78, /* -####--- */
|
||||
0xF0, /* ####---- */
|
||||
0xE1, /* ###----# */
|
||||
0xC3, /* ##----## */
|
||||
0x87, /* #----### */
|
||||
},
|
||||
{
|
||||
0x1E, /* ---####- */
|
||||
0x3C, /* --####-- */
|
||||
0x78, /* -####--- */
|
||||
0xF0, /* ####---- */
|
||||
0xE1, /* ###----# */
|
||||
0xC3, /* ##----## */
|
||||
0x87, /* #----### */
|
||||
0x0F, /* ----#### */
|
||||
},
|
||||
{
|
||||
0x3C, /* --####-- */
|
||||
0x78, /* -####--- */
|
||||
0xF0, /* ####---- */
|
||||
0xE1, /* ###----# */
|
||||
0xC3, /* ##----## */
|
||||
0x87, /* #----### */
|
||||
0x0F, /* ----#### */
|
||||
0x1E, /* ---####- */
|
||||
},
|
||||
{
|
||||
0x78, /* -####--- */
|
||||
0xF0, /* ####---- */
|
||||
0xE1, /* ###----# */
|
||||
0xC3, /* ##----## */
|
||||
0x87, /* #----### */
|
||||
0x0F, /* ----#### */
|
||||
0x1E, /* ---####- */
|
||||
0x3C, /* --####-- */
|
||||
},
|
||||
};
|
||||
|
||||
static BITMAP* pattern = NULL;
|
||||
int x, y, fg, bg;
|
||||
|
||||
if (offset < 0) {
|
||||
if (pattern) {
|
||||
destroy_bitmap(pattern);
|
||||
pattern = NULL;
|
||||
}
|
||||
drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!pattern)
|
||||
pattern = create_bitmap(8, 8);
|
||||
|
||||
offset = 7 - (offset & 7);
|
||||
|
||||
bg = makecol(0, 0, 0);
|
||||
fg = makecol(255, 255, 255);
|
||||
|
||||
clear_bitmap(pattern);
|
||||
|
||||
for (y=0; y<8; y++)
|
||||
for (x=0; x<8; x++)
|
||||
putpixel(pattern, x, y,
|
||||
(pattern_data[offset][y] & (1<<(7-x)))? fg: bg);
|
||||
|
||||
drawing_mode(DRAW_MODE_COPY_PATTERN, pattern, 0, 0);
|
||||
}
|
||||
|
||||
static void rectgrid(ui::Graphics* g, const gfx::Rect& rc, const gfx::Size& tile)
|
||||
{
|
||||
if (tile.w < 1 || tile.h < 1)
|
||||
|
@ -29,8 +29,6 @@
|
||||
namespace app {
|
||||
using namespace raster;
|
||||
|
||||
void dotted_mode(int offset);
|
||||
|
||||
void draw_color_button(ui::Graphics* g,
|
||||
const gfx::Rect& rc, const app::Color& color,
|
||||
bool hot, bool drag);
|
||||
|
@ -543,7 +543,7 @@ void Editor::drawMask(Graphics* g)
|
||||
int nseg = m_document->getBoundariesSegmentsCount();
|
||||
const BoundSeg* seg = m_document->getBoundariesSegments();
|
||||
|
||||
dotted_mode(m_offset_count);
|
||||
CheckedDrawMode checked(g, m_offset_count);
|
||||
|
||||
for (int c=0; c<nseg; ++c, ++seg) {
|
||||
x1 = seg->x1 << m_zoom;
|
||||
@ -577,12 +577,9 @@ void Editor::drawMask(Graphics* g)
|
||||
}
|
||||
}
|
||||
|
||||
// The color doesn't matter, we are using dotted_mode()
|
||||
// TODO send dotted_mode() to ui::Graphics domain.
|
||||
// The color doesn't matter, we are using CheckedDrawMode
|
||||
g->drawLine(0, gfx::Point(x+x1, y+y1), gfx::Point(x+x2, y+y2));
|
||||
}
|
||||
|
||||
dotted_mode(-1);
|
||||
}
|
||||
|
||||
void Editor::drawMaskSafe()
|
||||
|
@ -1079,9 +1079,8 @@ void Timeline::drawClipboardRange(ui::Graphics* g)
|
||||
if (!m_clipboard_timer.isRunning())
|
||||
m_clipboard_timer.start();
|
||||
|
||||
dotted_mode(m_offset_count);
|
||||
CheckedDrawMode checked(g, m_offset_count);
|
||||
g->drawRect(0, getRangeBounds(clipboard_range));
|
||||
dotted_mode(-1);
|
||||
}
|
||||
|
||||
void Timeline::drawHeader(ui::Graphics* g)
|
||||
|
@ -17,6 +17,40 @@
|
||||
#include "she/locked_surface.h"
|
||||
#include "she/surface.h"
|
||||
|
||||
namespace {
|
||||
|
||||
void checked_mode(int offset)
|
||||
{
|
||||
static BITMAP* pattern = NULL;
|
||||
int x, y, fg, bg;
|
||||
|
||||
if (offset < 0) {
|
||||
if (pattern) {
|
||||
destroy_bitmap(pattern);
|
||||
pattern = NULL;
|
||||
}
|
||||
drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!pattern)
|
||||
pattern = create_bitmap(8, 8);
|
||||
|
||||
bg = makecol(0, 0, 0);
|
||||
fg = makecol(255, 255, 255);
|
||||
offset = 7 - (offset & 7);
|
||||
|
||||
clear_bitmap(pattern);
|
||||
|
||||
for (y=0; y<8; y++)
|
||||
for (x=0; x<8; x++)
|
||||
putpixel(pattern, x, y, ((x+y+offset)&7) < 4 ? fg: bg);
|
||||
|
||||
drawing_mode(DRAW_MODE_COPY_PATTERN, pattern, 0, 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace she {
|
||||
|
||||
inline int to_allegro(int color_depth, gfx::Color color) {
|
||||
@ -115,6 +149,13 @@ namespace she {
|
||||
return this;
|
||||
}
|
||||
|
||||
void setDrawMode(DrawMode mode, int param) {
|
||||
switch (mode) {
|
||||
case DrawMode::Solid: checked_mode(-1); break;
|
||||
case DrawMode::Checked: checked_mode(param); break;
|
||||
}
|
||||
}
|
||||
|
||||
void applyScale(int scale) override {
|
||||
if (scale < 2)
|
||||
return;
|
||||
|
@ -14,6 +14,11 @@ namespace she {
|
||||
|
||||
class LockedSurface;
|
||||
|
||||
enum class DrawMode {
|
||||
Solid,
|
||||
Checked
|
||||
};
|
||||
|
||||
class Surface {
|
||||
public:
|
||||
virtual ~Surface() { }
|
||||
@ -26,6 +31,8 @@ namespace she {
|
||||
virtual void setClipBounds(const gfx::Rect& rc) = 0;
|
||||
virtual bool intersectClipRect(const gfx::Rect& rc) = 0;
|
||||
|
||||
virtual void setDrawMode(DrawMode mode, int param = 0) = 0;
|
||||
|
||||
virtual LockedSurface* lock() = 0;
|
||||
virtual void applyScale(int scaleFactor) = 0;
|
||||
virtual void* nativeHandle() = 0;
|
||||
|
@ -60,6 +60,18 @@ bool Graphics::intersectClipRect(const gfx::Rect& rc)
|
||||
return m_surface->intersectClipRect(gfx::Rect(rc).offset(m_dx, m_dy));
|
||||
}
|
||||
|
||||
void Graphics::setDrawMode(DrawMode mode, int param)
|
||||
{
|
||||
switch (mode) {
|
||||
case DrawMode::Solid:
|
||||
m_surface->setDrawMode(she::DrawMode::Solid);
|
||||
break;
|
||||
case DrawMode::Checked:
|
||||
m_surface->setDrawMode(she::DrawMode::Checked, param);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
gfx::Color Graphics::getPixel(int x, int y)
|
||||
{
|
||||
she::ScopedSurfaceLock dst(m_surface);
|
||||
|
@ -31,6 +31,11 @@ namespace ui {
|
||||
// Class to render a widget in the screen.
|
||||
class Graphics {
|
||||
public:
|
||||
enum class DrawMode {
|
||||
Solid,
|
||||
Checked,
|
||||
};
|
||||
|
||||
Graphics(she::Surface* surface, int dx, int dy);
|
||||
~Graphics();
|
||||
|
||||
@ -45,6 +50,8 @@ namespace ui {
|
||||
void setClipBounds(const gfx::Rect& rc);
|
||||
bool intersectClipRect(const gfx::Rect& rc);
|
||||
|
||||
void setDrawMode(DrawMode mode, int param = 0);
|
||||
|
||||
gfx::Color getPixel(int x, int y);
|
||||
void putPixel(gfx::Color color, int x, int y);
|
||||
|
||||
@ -146,6 +153,22 @@ namespace ui {
|
||||
DISABLE_COPYING(IntersectClip);
|
||||
};
|
||||
|
||||
class CheckedDrawMode {
|
||||
public:
|
||||
CheckedDrawMode(Graphics* g, int param) : m_graphics(g) {
|
||||
m_graphics->setDrawMode(Graphics::DrawMode::Checked, param);
|
||||
}
|
||||
|
||||
~CheckedDrawMode() {
|
||||
m_graphics->setDrawMode(Graphics::DrawMode::Solid);
|
||||
}
|
||||
|
||||
private:
|
||||
Graphics* m_graphics;
|
||||
|
||||
DISABLE_COPYING(CheckedDrawMode);
|
||||
};
|
||||
|
||||
typedef SharedPtr<Graphics> GraphicsPtr;
|
||||
|
||||
} // namespace ui
|
||||
|
Loading…
x
Reference in New Issue
Block a user