Fix editor drawing code (issue 355, editor decorators weren't visible outside sprite bounds)

This commit is contained in:
David Capello 2014-03-03 00:09:14 -03:00
parent 1b86d613bf
commit 10ae3a9d28
2 changed files with 76 additions and 86 deletions

View File

@ -403,32 +403,6 @@ void Editor::drawOneSpriteUnclippedRect(ui::Graphics* g, const gfx::Rect& rc, in
g->blit(tmp, 0, 0, dest_x, dest_y, width, height);
}
}
// Document settings
IDocumentSettings* docSettings =
UIContext::instance()->getSettings()->getDocumentSettings(m_document);
// Draw the pixel grid
if (docSettings->getPixelGridVisible()) {
if (m_zoom > 1)
this->drawGrid(Rect(0, 0, 1, 1),
docSettings->getPixelGridColor());
}
// Draw the grid
if (docSettings->getGridVisible())
this->drawGrid(docSettings->getGridBounds(),
docSettings->getGridColor());
// Draw the mask
if (m_document->getBoundariesSegments())
this->drawMask();
// Post-render decorator.
if (m_decorator) {
EditorPostRenderImpl postRender(this);
m_decorator->postRenderDecorator(&postRender);
}
}
void Editor::drawSpriteUnclippedRect(ui::Graphics* g, const gfx::Rect& rc)
@ -484,12 +458,32 @@ void Editor::drawSpriteUnclippedRect(ui::Graphics* g, const gfx::Rect& rc)
SkinTheme* theme = static_cast<SkinTheme*>(this->getTheme());
g->fillRegion(theme->getColor(ThemeColor::EditorFace), outside);
// Draw the pixel grid
if (docSettings->getPixelGridVisible()) {
if (m_zoom > 1)
drawGrid(g, enclosingRect, Rect(0, 0, 1, 1), docSettings->getPixelGridColor());
}
// Draw the grid
if (docSettings->getGridVisible())
drawGrid(g, enclosingRect, docSettings->getGridBounds(), docSettings->getGridColor());
// Draw the borders that enclose the sprite.
enclosingRect.enlarge(1);
g->drawRect(theme->getColor(ThemeColor::EditorSpriteBorder), enclosingRect);
g->drawHLine(
theme->getColor(ThemeColor::EditorSpriteBottomBorder),
enclosingRect.x, enclosingRect.y+enclosingRect.h, enclosingRect.w);
// Draw the mask
if (m_document->getBoundariesSegments())
drawMask(g);
// Post-render decorator.
if (m_decorator) {
EditorPostRenderImpl postRender(this);
m_decorator->postRenderDecorator(&postRender);
}
}
void Editor::drawSpriteUnclippedRect(const gfx::Rect& rc)
@ -527,59 +521,55 @@ void Editor::drawSpriteClipped(const gfx::Region& updateRegion)
* regenerate boundaries, use the sprite_generate_mask_boundaries()
* routine.
*/
void Editor::drawMask()
void Editor::drawMask(Graphics* g)
{
if ((m_flags & kShowMaskFlag) == 0)
return;
View* view = View::getView(this);
Rect vp = view->getViewportBounds();
Point scroll = view->getViewScroll();
int x1, y1, x2, y2;
int c, x, y;
dotted_mode(m_offset_count);
x = vp.x - scroll.x + m_offset_x;
y = vp.y - scroll.y + m_offset_y;
int x = m_offset_x;
int y = m_offset_y;
int nseg = m_document->getBoundariesSegmentsCount();
const BoundSeg* seg = m_document->getBoundariesSegments();
for (c=0; c<nseg; ++c, ++seg) {
x1 = seg->x1<<m_zoom;
y1 = seg->y1<<m_zoom;
x2 = seg->x2<<m_zoom;
y2 = seg->y2<<m_zoom;
dotted_mode(m_offset_count);
for (int c=0; c<nseg; ++c, ++seg) {
x1 = seg->x1 << m_zoom;
y1 = seg->y1 << m_zoom;
x2 = seg->x2 << m_zoom;
y2 = seg->y2 << m_zoom;
#if 1 // Bounds inside mask
if (!seg->open)
#else // Bounds outside mask
if (seg->open)
#endif
{
if (x1 == x2) {
x1--;
x2--;
y2--;
}
else {
y1--;
y2--;
x2--;
}
{
if (x1 == x2) {
x1--;
x2--;
y2--;
}
else
{
if (x1 == x2) {
y2--;
}
else {
x2--;
}
else {
y1--;
y2--;
x2--;
}
}
else {
if (x1 == x2) {
y2--;
}
else {
x2--;
}
}
line(ji_screen, x+x1, y+y1, x+x2, y+y2, 0);
// The color doesn't matter, we are using dotted_mode()
// TODO send dotted_mode() to ui::Graphics domain.
g->drawLine(0, gfx::Point(x+x1, y+y1), gfx::Point(x+x2, y+y2));
}
dotted_mode(-1);
@ -598,32 +588,30 @@ void Editor::drawMaskSafe()
Region region;
getDrawableRegion(region, kCutTopWindows);
acquire_bitmap(ji_screen);
if (thick)
editor_clean_cursor();
else
jmouse_hide();
gfx::Point offset = -getBounds().getOrigin();
GraphicsPtr g = getGraphics(getClientBounds());
for (Region::const_iterator it=region.begin(), end=region.end();
it != end; ++it) {
const Rect& rc = *it;
set_clip_rect(ji_screen, rc.x, rc.y, rc.x2()-1, rc.y2()-1);
drawMask();
IntersectClip clip(g, gfx::Rect(*it).offset(offset));
if (clip)
drawMask(g);
}
set_clip_rect(ji_screen, 0, 0, JI_SCREEN_W-1, JI_SCREEN_H-1);
// Draw the cursor
if (thick)
editor_draw_cursor(m_cursor_screen_x, m_cursor_screen_y);
else
jmouse_show();
release_bitmap(ji_screen);
}
}
void Editor::drawGrid(const Rect& gridBounds, const app::Color& color)
void Editor::drawGrid(Graphics* g, const gfx::Rect& spriteBounds, const Rect& gridBounds, const app::Color& color)
{
if ((m_flags & kShowGridFlag) == 0)
return;
@ -646,28 +634,31 @@ void Editor::drawGrid(const Rect& gridBounds, const app::Color& color)
// Convert the "grid" rectangle to screen coordinates
editorToScreen(grid, &grid);
// Get the grid's color
int grid_color = color_utils::color_for_allegro(color, bitmap_color_depth(ji_screen));
// Adjust for client area
gfx::Rect bounds = getBounds();
grid.offset(-bounds.getOrigin());
// Get the position of the sprite in the screen.
Rect spriteRect;
editorToScreen(Rect(0, 0, m_sprite->getWidth(), m_sprite->getHeight()), &spriteRect);
while (grid.x-grid.w >= spriteBounds.x) grid.x -= grid.w;
while (grid.y-grid.h >= spriteBounds.y) grid.y -= grid.h;
// Get the grid's color
ui::Color grid_color = color_utils::color_for_ui(color);
// Draw horizontal lines
int x1 = spriteRect.x;
int x1 = spriteBounds.x;
int y1 = grid.y;
int x2 = spriteRect.x+spriteRect.w;
int y2 = spriteRect.y+spriteRect.h;
int x2 = spriteBounds.x + spriteBounds.w;
int y2 = spriteBounds.y + spriteBounds.h;
for (int c=y1; c<=y2; c+=grid.h)
hline(ji_screen, x1, c, x2, grid_color);
g->drawHLine(grid_color, x1, c, spriteBounds.w);
// Draw vertical lines
x1 = grid.x;
y1 = spriteRect.y;
y1 = spriteBounds.y;
for (int c=x1; c<=x2; c+=grid.w)
vline(ji_screen, c, y1, y2, grid_color);
g->drawVLine(grid_color, c, y1, spriteBounds.h);
}
void Editor::flashCurrentLayer()
@ -1057,7 +1048,7 @@ void Editor::onPaint(ui::PaintEvent& ev)
// Draw the mask boundaries
if (m_document->getBoundariesSegments()) {
drawMask();
drawMask(g);
m_mask_timer.start();
}
else {

View File

@ -117,9 +117,6 @@ namespace app {
// Draws the sprite taking care of the whole clipping region.
void drawSpriteClipped(const gfx::Region& updateRegion);
void drawMask();
void drawMaskSafe();
void flashCurrentLayer();
void screenToEditor(int xin, int yin, int* xout, int* yout);
@ -195,7 +192,9 @@ namespace app {
void editor_clean_cursor(bool refresh = true);
bool editor_cursor_is_subpixel();
void drawGrid(const gfx::Rect& gridBounds, const app::Color& color);
void drawMaskSafe();
void drawMask(ui::Graphics* g);
void drawGrid(ui::Graphics* g, const gfx::Rect& spriteBounds, const gfx::Rect& gridBounds, const app::Color& color);
void editor_setcursor();