From 156e3adeb32312cf1d6ae6587fa1ffe2768dc09c Mon Sep 17 00:00:00 2001 From: David Capello Date: Sun, 7 Mar 2010 12:14:25 -0200 Subject: [PATCH] Added 'extras' to Sprite to draw extra-stuff that is not in the Sprite (it will be useful to draw preview of the brush). --- src/raster/sprite.cpp | 14 ++++++++++++++ src/raster/sprite.h | 8 ++++++++ src/util/render.cpp | 18 ++++++++++++++++++ 3 files changed, 40 insertions(+) diff --git a/src/raster/sprite.cpp b/src/raster/sprite.cpp index 9de5a0bd8..257172883 100644 --- a/src/raster/sprite.cpp +++ b/src/raster/sprite.cpp @@ -60,6 +60,7 @@ Sprite::Sprite(int imgtype, int w, int h) this->undo = undo_new(this); this->repository.paths = jlist_new(); this->repository.masks = jlist_new(); + this->m_extras = NULL; /* boundary stuff */ this->bound.nseg = 0; @@ -140,6 +141,7 @@ Sprite::~Sprite() // destroy undo, mask, etc. delete this->undo; delete this->mask; + delete this->m_extras; // image if (this->frlens) jfree(this->frlens); if (this->bound.seg) jfree(this->bound.seg); @@ -384,6 +386,18 @@ void Sprite::unlock() } } +void Sprite::prepare_extra() +{ + if (!m_extras || + m_extras->imgtype != imgtype || + m_extras->w != w || + m_extras->h != h) { + delete m_extras; // image + m_extras = image_new(imgtype, w, h); + image_clear(m_extras, 0); + } +} + Palette* sprite_get_palette(const Sprite* sprite, int frame) { Palette* found = NULL; diff --git a/src/raster/sprite.h b/src/raster/sprite.h index a6eaf09d3..19cd7f107 100644 --- a/src/raster/sprite.h +++ b/src/raster/sprite.h @@ -78,6 +78,9 @@ public: private: + Image* m_extras; // Image with the sprite size to draw some extra stuff (e.g. editor's cursor) + int m_extras_opacity; // Opacity to be used to draw the extra image + // Mutex to modify the 'locked' flag. JMutex m_mutex; @@ -101,6 +104,11 @@ public: void unlock(); LayerFolder* get_folder() const { return m_folder; } + + void prepare_extra(); + Image* get_extras() { return m_extras; } + int get_extras_opacity() const { return m_extras_opacity; } + void set_extras_opacity(int opacity) { m_extras_opacity = opacity; } }; Sprite* sprite_new(int imgtype, int w, int h); diff --git a/src/util/render.cpp b/src/util/render.cpp index ac88198ac..412c7c631 100644 --- a/src/util/render.cpp +++ b/src/util/render.cpp @@ -468,4 +468,22 @@ void RenderEngine::renderLayer(Sprite *sprite, Layer *layer, Image *image, } } + + // Draw extras + if (layer == sprite->layer && sprite->get_extras() != NULL) { + int opacity = sprite->get_extras_opacity(); + + if (zoom == 0) { + image_merge(image, sprite->get_extras(), + -source_x, + -source_y, + opacity, BLEND_MODE_NORMAL); + } + else { + (*zoomed_func)(image, sprite->get_extras(), + -source_x, + -source_y, + opacity, BLEND_MODE_NORMAL, zoom); + } + } }