diff --git a/src/app/color_picker.cpp b/src/app/color_picker.cpp index 2283aefca..250175c33 100644 --- a/src/app/color_picker.cpp +++ b/src/app/color_picker.cpp @@ -37,7 +37,8 @@ ColorPicker::ColorPicker() { } -void ColorPicker::pickColor(const DocumentLocation& location, int x, int y, Mode mode) +void ColorPicker::pickColor(const DocumentLocation& location, + const gfx::Point& pos, Mode mode) { m_alpha = 255; m_color = app::Color::fromMask(); @@ -46,17 +47,17 @@ void ColorPicker::pickColor(const DocumentLocation& location, int x, int y, Mode if (mode == FromComposition) { // Pick from the composed image m_color = app::Color::fromImage( location.sprite()->pixelFormat(), - location.sprite()->getPixel(x, y, location.frame())); + location.sprite()->getPixel(pos.x, pos.y, location.frame())); doc::CelList cels; - location.sprite()->pickCels(x, y, location.frame(), 128, cels); + location.sprite()->pickCels(pos.x, pos.y, location.frame(), 128, cels); if (!cels.empty()) m_layer = cels.front()->layer(); } else { // Pick from the current layer int u, v; doc::Image* image = location.image(&u, &v, NULL); - gfx::Point pt(x-u, y-v); + gfx::Point pt(pos.x-u, pos.y-v); if (image && image->bounds().contains(pt)) { doc::color_t imageColor = get_pixel(image, pt.x, pt.y); diff --git a/src/app/color_picker.h b/src/app/color_picker.h index b93a22346..4faf0b1c0 100644 --- a/src/app/color_picker.h +++ b/src/app/color_picker.h @@ -22,6 +22,7 @@ #include "app/color.h" #include "doc/layer.h" +#include "gfx/point.h" namespace app { class DocumentLocation; @@ -32,7 +33,8 @@ namespace app { ColorPicker(); - void pickColor(const DocumentLocation& location, int x, int y, Mode mode); + void pickColor(const DocumentLocation& location, + const gfx::Point& pos, Mode mode); app::Color color() const { return m_color; } int alpha() const { return m_alpha; } diff --git a/src/app/commands/cmd_eyedropper.cpp b/src/app/commands/cmd_eyedropper.cpp index 20ea7ceff..52d487c13 100644 --- a/src/app/commands/cmd_eyedropper.cpp +++ b/src/app/commands/cmd_eyedropper.cpp @@ -84,15 +84,15 @@ void EyedropperCommand::onExecute(Context* context) return; // pixel position to get - int x, y; - editor->screenToEditor(jmouse_x(0), jmouse_y(0), &x, &y); + gfx::Point pixelPos = editor->screenToEditor(ui::get_mouse_position()); // Check if we've to grab alpha channel or the merged color. ISettings* settings = UIContext::instance()->settings(); bool grabAlpha = settings->getGrabAlpha(); ColorPicker picker; - picker.pickColor(editor->getDocumentLocation(), x, y, + picker.pickColor(editor->getDocumentLocation(), + pixelPos, grabAlpha ? ColorPicker::FromActiveLayer: ColorPicker::FromComposition); diff --git a/src/app/commands/cmd_invert_mask.cpp b/src/app/commands/cmd_invert_mask.cpp index c9aa9e0e5..8249057e8 100644 --- a/src/app/commands/cmd_invert_mask.cpp +++ b/src/app/commands/cmd_invert_mask.cpp @@ -106,7 +106,7 @@ void InvertMaskCommand::onExecute(Context* context) } // We need only need the area inside the sprite - mask->intersect(0, 0, sprite->width(), sprite->height()); + mask->intersect(sprite->bounds()); // Set the new mask document->setMask(mask); diff --git a/src/app/commands/cmd_scroll.cpp b/src/app/commands/cmd_scroll.cpp index 32ea10164..38211b8c8 100644 --- a/src/app/commands/cmd_scroll.cpp +++ b/src/app/commands/cmd_scroll.cpp @@ -103,8 +103,7 @@ void ScrollCommand::onExecute(Context* context) gfx::Rect vp = view->getViewportBounds(); gfx::Point scroll = view->getViewScroll(); gfx::Rect gridBounds = docSettings->getGridBounds(); - int dx = 0; - int dy = 0; + gfx::Point delta(0, 0); int pixels = 0; switch (m_units) { @@ -135,13 +134,13 @@ void ScrollCommand::onExecute(Context* context) } switch (m_direction) { - case Left: dx = -m_quantity * pixels; break; - case Right: dx = +m_quantity * pixels; break; - case Up: dy = -m_quantity * pixels; break; - case Down: dy = +m_quantity * pixels; break; + case Left: delta.x = -m_quantity * pixels; break; + case Right: delta.x = +m_quantity * pixels; break; + case Up: delta.y = -m_quantity * pixels; break; + case Down: delta.y = +m_quantity * pixels; break; } - current_editor->setEditorScroll(scroll.x+dx, scroll.y+dy, true); + current_editor->setEditorScroll(scroll+delta, true); } std::string ScrollCommand::onGetFriendlyName() const diff --git a/src/app/commands/filters/filter_manager_impl.cpp b/src/app/commands/filters/filter_manager_impl.cpp index 09b25b02c..c79ad605b 100644 --- a/src/app/commands/filters/filter_manager_impl.cpp +++ b/src/app/commands/filters/filter_manager_impl.cpp @@ -117,8 +117,8 @@ void FilterManagerImpl::beginForPreview() else { m_preview_mask.reset(new Mask()); m_preview_mask->replace(m_offset_x, m_offset_y, - m_src->width(), - m_src->height()); + m_src->width(), + m_src->height()); } m_row = 0; @@ -128,29 +128,16 @@ void FilterManagerImpl::beginForPreview() Editor* editor = current_editor; Sprite* sprite = m_location.sprite(); gfx::Rect vp = View::getView(editor)->getViewportBounds(); - int x1, y1, x2, y2; - int x, y, w, h; + vp = editor->screenToEditor(vp); + vp = vp.createIntersect(sprite->bounds()); - editor->screenToEditor(vp.x, vp.y, &x1, &y1); - editor->screenToEditor(vp.x+vp.w-1, vp.y+vp.h-1, &x2, &y2); - - if (x1 < 0) x1 = 0; - if (y1 < 0) y1 = 0; - if (x2 >= sprite->width()) x2 = sprite->width()-1; - if (y2 >= sprite->height()) y2 = sprite->height()-1; - - x = x1; - y = y1; - w = x2 - x1 + 1; - h = y2 - y1 + 1; - - if ((w < 1) || (h < 1)) { + if (vp.isEmpty()) { m_preview_mask.reset(NULL); m_row = -1; return; } - m_preview_mask->intersect(x, y, w, h); + m_preview_mask->intersect(vp); } if (!updateMask(m_mask, m_src)) { @@ -263,14 +250,15 @@ void FilterManagerImpl::applyToTarget() void FilterManagerImpl::flush() { if (m_row >= 0) { - gfx::Rect rect; - Editor* editor = current_editor; - editor->editorToScreen(m_x+m_offset_x, - m_y+m_offset_y+m_row-1, - &rect.x, &rect.y); - rect.w = (m_w << editor->zoom()); - rect.h = (1 << editor->zoom()); + gfx::Rect rect( + editor->editorToScreen( + gfx::Point( + m_x+m_offset_x, + m_y+m_offset_y+m_row-1)), + gfx::Size( + (m_w << editor->zoom()), + (1 << editor->zoom()))); gfx::Region reg1(rect); gfx::Region reg2; @@ -346,7 +334,7 @@ bool FilterManagerImpl::updateMask(Mask* mask, const Image* image) { int x, y, w, h; - if ((mask) && (mask->bitmap())) { + if (mask && mask->bitmap()) { x = mask->bounds().x - m_offset_x; y = mask->bounds().y - m_offset_y; w = mask->bounds().w; diff --git a/src/app/document.cpp b/src/app/document.cpp index 9ac0f9100..6b9864cc5 100644 --- a/src/app/document.cpp +++ b/src/app/document.cpp @@ -1,5 +1,5 @@ /* Aseprite - * Copyright (C) 2001-2013 David Capello + * Copyright (C) 2001-2014 David Capello * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -233,22 +233,23 @@ void Document::destroyExtraCel() m_extraImage = NULL; } -void Document::prepareExtraCel(int x, int y, int w, int h, int opacity) +void Document::prepareExtraCel(const gfx::Rect& bounds, int opacity) { ASSERT(sprite() != NULL); if (!m_extraCel) m_extraCel = new Cel(FrameNumber(0), 0); // Ignored fields for this cell (frame, and image index) - m_extraCel->setPosition(x, y); + m_extraCel->setPosition(bounds.getOrigin()); m_extraCel->setOpacity(opacity); if (!m_extraImage || m_extraImage->pixelFormat() != sprite()->pixelFormat() || - m_extraImage->width() != w || - m_extraImage->height() != h) { + m_extraImage->width() != bounds.w || + m_extraImage->height() != bounds.h) { delete m_extraImage; // image - m_extraImage = Image::create(sprite()->pixelFormat(), w, h); + m_extraImage = Image::create(sprite()->pixelFormat(), + bounds.w, bounds.h); } } diff --git a/src/app/document.h b/src/app/document.h index 7bd27f3ce..8e64abbdd 100644 --- a/src/app/document.h +++ b/src/app/document.h @@ -1,5 +1,5 @@ /* Aseprite - * Copyright (C) 2001-2013 David Capello + * Copyright (C) 2001-2014 David Capello * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -26,9 +26,10 @@ #include "base/shared_ptr.h" #include "base/unique_ptr.h" #include "doc/document.h" -#include "gfx/transformation.h" #include "doc/frame_number.h" #include "doc/pixel_format.h" +#include "gfx/rect.h" +#include "gfx/transformation.h" #include @@ -125,7 +126,7 @@ namespace app { ////////////////////////////////////////////////////////////////////// // Extra Cel (it is used to draw pen preview, pixels in movement, etc.) - void prepareExtraCel(int x, int y, int w, int h, int opacity); + void prepareExtraCel(const gfx::Rect& bounds, int opacity); void destroyExtraCel(); Cel* getExtraCel() const; Image* getExtraCelImage() const; diff --git a/src/app/ui/color_button.cpp b/src/app/ui/color_button.cpp index de7e494b0..88e2f5316 100644 --- a/src/app/ui/color_button.cpp +++ b/src/app/ui/color_button.cpp @@ -133,12 +133,10 @@ bool ColorButton::onProcessMessage(Message* msg) Editor* editor = static_cast(picked); DocumentLocation location = editor->getDocumentLocation(); if (location.sprite()) { - int x = mousePos.x; - int y = mousePos.y; - editor->screenToEditor(x, y, &x, &y); + gfx::Point editorPos = editor->screenToEditor(mousePos); ColorPicker picker; - picker.pickColor(location, x, y, ColorPicker::FromComposition); + picker.pickColor(location, editorPos, ColorPicker::FromComposition); color = picker.color(); } } diff --git a/src/app/ui/editor/cursor.cpp b/src/app/ui/editor/cursor.cpp index 1d1c4792c..8fda07062 100644 --- a/src/app/ui/editor/cursor.cpp +++ b/src/app/ui/editor/cursor.cpp @@ -87,13 +87,13 @@ static gfx::Region old_clipping_region; static void generate_cursor_boundaries(Editor* editor); -static void trace_thincross_pixels(ui::Graphics* g, Editor* editor, int x, int y, gfx::Color color, Editor::PixelDelegate pixel); -static void trace_thickcross_pixels(ui::Graphics* g, Editor* editor, int x, int y, gfx::Color color, int thickness, Editor::PixelDelegate pixel); -static void trace_brush_bounds(ui::Graphics* g, Editor* editor, int x, int y, gfx::Color color, Editor::PixelDelegate pixel); +static void trace_thincross_pixels(ui::Graphics* g, Editor* editor, const gfx::Point& pt, gfx::Color color, Editor::PixelDelegate pixel); +static void trace_thickcross_pixels(ui::Graphics* g, Editor* editor, const gfx::Point& pt, gfx::Color color, int thickness, Editor::PixelDelegate pixel); +static void trace_brush_bounds(ui::Graphics* g, Editor* editor, const gfx::Point& pt, gfx::Color color, Editor::PixelDelegate pixel); -static void savepixel(ui::Graphics* g, int x, int y, gfx::Color color); -static void drawpixel(ui::Graphics* g, int x, int y, gfx::Color color); -static void clearpixel(ui::Graphics* g, int x, int y, gfx::Color color); +static void savepixel(ui::Graphics* g, const gfx::Point& pt, gfx::Color color); +static void drawpixel(ui::Graphics* g, const gfx::Point& pt, gfx::Color color); +static void clearpixel(ui::Graphics* g, const gfx::Point& pt, gfx::Color color); static color_t get_brush_color(Sprite* sprite, Layer* layer); @@ -209,9 +209,9 @@ void Editor::editor_cursor_exit() // this routine with other editor. // // Note: x and y params are absolute positions of the mouse. -void Editor::drawBrushPreview(int x, int y, bool refresh) +void Editor::drawBrushPreview(const gfx::Point& pos, bool refresh) { - ASSERT(m_cursor_thick == 0); + ASSERT(m_cursorThick == 0); ASSERT(m_sprite != NULL); // Get drawable region @@ -221,11 +221,10 @@ void Editor::drawBrushPreview(int x, int y, bool refresh) cursor_negative = is_cursor_mask; // Cursor in the screen (view) - m_cursor_screen_x = x; - m_cursor_screen_y = y; + m_cursorScreen = pos; // Get cursor position in the editor - screenToEditor(x, y, &x, &y); + gfx::Point spritePos = screenToEditor(pos); // Get the current tool tools::Tool* tool = getCurrentEditorTool(); @@ -265,9 +264,9 @@ void Editor::drawBrushPreview(int x, int y, bool refresh) gfx::Rect brushBounds = brush->bounds(); // Create the extra cel to show the brush preview - m_document->prepareExtraCel(x+brushBounds.x, y+brushBounds.y, - brushBounds.w, brushBounds.h, - tool_settings->getOpacity()); + m_document->prepareExtraCel( + gfx::Rect(brushBounds).offset(spritePos), + tool_settings->getOpacity()); // In 'indexed' images, if the current color is 0, we have to use // a different mask color (different from 0) to draw the extra layer @@ -282,9 +281,10 @@ void Editor::drawBrushPreview(int x, int y, bool refresh) if (refresh) { m_document->notifySpritePixelsModified (m_sprite, - gfx::Region(gfx::Rect(x+brushBounds.x, - y+brushBounds.y, - brushBounds.w, brushBounds.h))); + gfx::Region(gfx::Rect( + spritePos.x+brushBounds.x, + spritePos.y+brushBounds.y, + brushBounds.w, brushBounds.h))); } } @@ -293,35 +293,31 @@ void Editor::drawBrushPreview(int x, int y, bool refresh) ScreenGraphics g; SetClip clip(&g, gfx::Rect(0, 0, g.width(), g.height())); - forEachBrushPixel(&g, m_cursor_screen_x, m_cursor_screen_y, x, y, ui_cursor_color, savepixel); - forEachBrushPixel(&g, m_cursor_screen_x, m_cursor_screen_y, x, y, ui_cursor_color, drawpixel); + forEachBrushPixel(&g, m_cursorScreen, spritePos, ui_cursor_color, savepixel); + forEachBrushPixel(&g, m_cursorScreen, spritePos, ui_cursor_color, drawpixel); } // Cursor thickness - m_cursor_thick = 1; + m_cursorThick = 1; // Cursor in the editor (model) - m_cursor_editor_x = x; - m_cursor_editor_y = y; + m_cursorEditor = spritePos; // Save the clipping-region to know where to clean the pixels old_clipping_region = clipping_region; } -void Editor::moveBrushPreview(int x, int y, bool refresh) +void Editor::moveBrushPreview(const gfx::Point& pos, bool refresh) { ASSERT(m_sprite != NULL); - int old_screen_x = m_cursor_screen_x; - int old_screen_y = m_cursor_screen_y; - int old_x = m_cursor_editor_x; - int old_y = m_cursor_editor_y; + gfx::Point oldScreenPos = m_cursorScreen; + gfx::Point oldEditorPos = m_cursorEditor; clearBrushPreview(false); - drawBrushPreview(x, y, false); + drawBrushPreview(pos, false); - int new_x = m_cursor_editor_x; - int new_y = m_cursor_editor_y; + gfx::Point newEditorPos = m_cursorEditor; if (refresh) { // Restore pixels @@ -329,22 +325,22 @@ void Editor::moveBrushPreview(int x, int y, bool refresh) ScreenGraphics g; SetClip clip(&g, gfx::Rect(0, 0, g.width(), g.height())); - forEachBrushPixel(&g, old_screen_x, old_screen_y, old_x, old_y, gfx::ColorNone, clearpixel); + forEachBrushPixel(&g, oldScreenPos, oldEditorPos, gfx::ColorNone, clearpixel); } if (cursor_type & CURSOR_THINCROSS && m_state->requireBrushPreview()) { Brush* brush = editor_get_current_brush(this); gfx::Rect brushBounds = brush->bounds(); - gfx::Rect rc1(old_x+brushBounds.x, old_y+brushBounds.y, brushBounds.w, brushBounds.h); - gfx::Rect rc2(new_x+brushBounds.x, new_y+brushBounds.y, brushBounds.w, brushBounds.h); + gfx::Rect rc1(oldEditorPos.x+brushBounds.x, oldEditorPos.y+brushBounds.y, brushBounds.w, brushBounds.h); + gfx::Rect rc2(newEditorPos.x+brushBounds.x, newEditorPos.y+brushBounds.y, brushBounds.w, brushBounds.h); m_document->notifySpritePixelsModified (m_sprite, gfx::Region(rc1.createUnion(rc2))); } // Save area and draw the cursor ScreenGraphics g; - forEachBrushPixel(&g, m_cursor_screen_x, m_cursor_screen_y, new_x, new_y, ui_cursor_color, savepixel); - forEachBrushPixel(&g, m_cursor_screen_x, m_cursor_screen_y, new_x, new_y, ui_cursor_color, drawpixel); + forEachBrushPixel(&g, m_cursorScreen, newEditorPos, ui_cursor_color, savepixel); + forEachBrushPixel(&g, m_cursorScreen, newEditorPos, ui_cursor_color, drawpixel); } } @@ -363,22 +359,19 @@ void Editor::moveBrushPreview(int x, int y, bool refresh) */ void Editor::clearBrushPreview(bool refresh) { - int x, y; - - ASSERT(m_cursor_thick != 0); + ASSERT(m_cursorThick != 0); ASSERT(m_sprite != NULL); getDrawableRegion(clipping_region, kCutTopWindows); - x = m_cursor_editor_x; - y = m_cursor_editor_y; + gfx::Point pos = m_cursorEditor; if (refresh) { // Restore pixels ScreenGraphics g; SetClip clip(&g, gfx::Rect(0, 0, g.width(), g.height())); - forEachBrushPixel(&g, m_cursor_screen_x, m_cursor_screen_y, x, y, gfx::ColorNone, clearpixel); + forEachBrushPixel(&g, m_cursorScreen, pos, gfx::ColorNone, clearpixel); } // Clean pixel/brush preview @@ -386,20 +379,21 @@ void Editor::clearBrushPreview(bool refresh) Brush* brush = editor_get_current_brush(this); gfx::Rect brushBounds = brush->bounds(); - m_document->prepareExtraCel(x+brushBounds.x, y+brushBounds.y, - brushBounds.w, brushBounds.h, - 0); // Opacity = 0 + m_document->prepareExtraCel( + gfx::Rect(brushBounds).offset(pos), + 0); // Opacity = 0 if (refresh) { m_document->notifySpritePixelsModified (m_sprite, - gfx::Region(gfx::Rect(x+brushBounds.x, - y+brushBounds.y, - brushBounds.w, brushBounds.h))); + gfx::Region(gfx::Rect( + pos.x+brushBounds.x, + pos.y+brushBounds.y, + brushBounds.w, brushBounds.h))); } } - m_cursor_thick = 0; + m_cursorThick = 0; clipping_region.clear(); old_clipping_region.clear(); @@ -456,24 +450,24 @@ static void generate_cursor_boundaries(Editor* editor) void Editor::forEachBrushPixel( ui::Graphics* g, - int screen_x, int screen_y, - int sprite_x, int sprite_y, + const gfx::Point& screenPos, + const gfx::Point& spritePos, gfx::Color color, Editor::PixelDelegate pixelDelegate) { saved_pixel_n = 0; if (cursor_type & CURSOR_THINCROSS) - trace_thincross_pixels(g, this, screen_x, screen_y, color, pixelDelegate); + trace_thincross_pixels(g, this, screenPos, color, pixelDelegate); if (cursor_type & CURSOR_THICKCROSS) - trace_thickcross_pixels(g, this, sprite_x, sprite_y, color, 1, pixelDelegate); + trace_thickcross_pixels(g, this, spritePos, color, 1, pixelDelegate); if (cursor_type & CURSOR_BRUSHBOUNDS) - trace_brush_bounds(g, this, sprite_x, sprite_y, color, pixelDelegate); + trace_brush_bounds(g, this, spritePos, color, pixelDelegate); if (IS_SUBPIXEL(this)) { - pixelDelegate(g, screen_x, screen_y, color); + pixelDelegate(g, screenPos, color); } } @@ -481,7 +475,7 @@ void Editor::forEachBrushPixel( // New Thin Cross static void trace_thincross_pixels(ui::Graphics* g, Editor* editor, - int x, int y, gfx::Color color, Editor::PixelDelegate pixelDelegate) + const gfx::Point& pt, gfx::Color color, Editor::PixelDelegate pixelDelegate) { static int cursor_cross[7*7] = { 0, 0, 0, 1, 0, 0, 0, @@ -492,14 +486,15 @@ static void trace_thincross_pixels(ui::Graphics* g, Editor* editor, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, }; - int u, v, xout, yout; + gfx::Point out; + int u, v; for (v=0; v<7; v++) { for (u=0; u<7; u++) { if (cursor_cross[v*7+u]) { - xout = x-3+u; - yout = y-3+v; - pixelDelegate(g, xout, yout, color); + out.x = pt.x-3+u; + out.y = pt.y-3+v; + pixelDelegate(g, out, color); } } } @@ -509,7 +504,7 @@ static void trace_thincross_pixels(ui::Graphics* g, Editor* editor, // Old Thick Cross static void trace_thickcross_pixels(ui::Graphics* g, Editor* editor, - int x, int y, gfx::Color color, int thickness, Editor::PixelDelegate pixelDelegate) + const gfx::Point& pt, gfx::Color color, int thickness, Editor::PixelDelegate pixelDelegate) { static int cursor_cross[6*6] = { 0, 0, 1, 1, 0, 0, @@ -519,23 +514,24 @@ static void trace_thickcross_pixels(ui::Graphics* g, Editor* editor, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, }; - int u, v, xout, yout; + gfx::Point out; + int u, v; int zoom = editor->zoom(); for (v=0; v<6; v++) { for (u=0; u<6; u++) { if (cursor_cross[v*6+u]) { - editor->editorToScreen(x, y, &xout, &yout); + out = editor->editorToScreen(pt); - xout += ((u<3) ? - u-((thickness>>1)<>1)<>1)<>1)<>1)<>1)<>1)<>1)<pixelDelegate(data->g, x, y, data->color); + data->pixelDelegate(data->g, gfx::Point(x, y), data->color); } static void trace_brush_bounds(ui::Graphics* g, Editor* editor, - int x, int y, gfx::Color color, Editor::PixelDelegate pixelDelegate) + const gfx::Point& pos, gfx::Color color, Editor::PixelDelegate pixelDelegate) { Data data = { g, color, pixelDelegate }; - int c, x1, y1, x2, y2; + gfx::Point pt1, pt2; BoundSeg* seg; + int c; for (c=0; cx1 - cursor_bound.brush_size/2; - y1 = seg->y1 - cursor_bound.brush_size/2; - x2 = seg->x2 - cursor_bound.brush_size/2; - y2 = seg->y2 - cursor_bound.brush_size/2; + pt1.x = pos.x + seg->x1 - cursor_bound.brush_size/2; + pt1.y = pos.y + seg->y1 - cursor_bound.brush_size/2; + pt2.x = pos.x + seg->x2 - cursor_bound.brush_size/2; + pt2.y = pos.y + seg->y2 - cursor_bound.brush_size/2; - editor->editorToScreen(x+x1, y+y1, &x1, &y1); - editor->editorToScreen(x+x2, y+y2, &x2, &y2); + pt1 = editor->editorToScreen(pt1); + pt2 = editor->editorToScreen(pt2); - if (seg->open) { /* outside */ - if (x1 == x2) { - x1--; - x2--; - y2--; + if (seg->open) { // Outside + if (pt1.x == pt2.x) { + pt1.x--; + pt2.x--; + pt2.y--; } else { - y1--; - y2--; - x2--; + pt1.y--; + pt2.y--; + pt2.x--; } } else { - if (x1 == x2) { - y2--; + if (pt1.x == pt2.x) { + pt2.y--; } else { - x2--; + pt2.x--; } } - doc::algo_line(x1, y1, x2, y2, (void*)&data, algo_line_proxy); + doc::algo_line(pt1.x, pt1.y, pt2.x, pt2.y, (void*)&data, algo_line_proxy); } } ////////////////////////////////////////////////////////////////////// // Helpers -static void savepixel(ui::Graphics* g, int x, int y, gfx::Color color) +static void savepixel(ui::Graphics* g, const gfx::Point& pt, gfx::Color color) { - if (saved_pixel_n < MAX_SAVED && clipping_region.contains(gfx::Point(x, y))) - saved_pixel[saved_pixel_n++] = g->getPixel(x, y); + if (saved_pixel_n < MAX_SAVED && clipping_region.contains(pt)) + saved_pixel[saved_pixel_n++] = g->getPixel(pt.x, pt.y); } -static void drawpixel(ui::Graphics* graphics, int x, int y, gfx::Color color) +static void drawpixel(ui::Graphics* graphics, const gfx::Point& pt, gfx::Color color) { - if (saved_pixel_n < MAX_SAVED && clipping_region.contains(gfx::Point(x, y))) { + if (saved_pixel_n < MAX_SAVED && clipping_region.contains(pt)) { if (cursor_negative) { int c = saved_pixel[saved_pixel_n++]; int r = gfx::getr(c); int g = gfx::getg(c); int b = gfx::getb(c); - graphics->putPixel(color_utils::blackandwhite_neg(gfx::rgba(r, g, b)), x, y); + graphics->putPixel(color_utils::blackandwhite_neg(gfx::rgba(r, g, b)), pt.x, pt.y); } else { - graphics->putPixel(color, x, y); + graphics->putPixel(color, pt.x, pt.y); } } } -static void clearpixel(ui::Graphics* g, int x, int y, gfx::Color color) +static void clearpixel(ui::Graphics* g, const gfx::Point& pt, gfx::Color color) { if (saved_pixel_n < MAX_SAVED) { - if (clipping_region.contains(gfx::Point(x, y))) - g->putPixel(saved_pixel[saved_pixel_n++], x, y); + if (clipping_region.contains(pt)) + g->putPixel(saved_pixel[saved_pixel_n++], pt.x, pt.y); else if (!old_clipping_region.isEmpty() && - old_clipping_region.contains(gfx::Point(x, y))) + old_clipping_region.contains(pt)) saved_pixel_n++; } } diff --git a/src/app/ui/editor/editor.cpp b/src/app/ui/editor/editor.cpp index 9e264fa91..e8316ea65 100644 --- a/src/app/ui/editor/editor.cpp +++ b/src/app/ui/editor/editor.cpp @@ -1,5 +1,5 @@ /* Aseprite - * Copyright (C) 2001-2013 David Capello + * Copyright (C) 2001-2014 David Capello * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -120,15 +120,16 @@ public: void drawLine(int x1, int y1, int x2, int y2, gfx::Color screenColor) { - int u1, v1, u2, v2; - m_editor->editorToScreen(x1, y1, &u1, &v1); - m_editor->editorToScreen(x2, y2, &u2, &v2); + gfx::Point a(x1, y1); + gfx::Point b(x2, y2); + a = m_editor->editorToScreen(a); + b = m_editor->editorToScreen(b); gfx::Rect bounds = m_editor->getBounds(); - u1 -= bounds.x; - v1 -= bounds.y; - u2 -= bounds.x; - v2 -= bounds.y; - m_g->drawLine(screenColor, gfx::Point(u1, v1), gfx::Point(u2, v2)); + a.x -= bounds.x; + a.y -= bounds.y; + b.x -= bounds.x; + b.y -= bounds.y; + m_g->drawLine(screenColor, a, b); } private: @@ -145,6 +146,10 @@ Editor::Editor(Document* document, EditorFlags flags) , m_layer(m_sprite->folder()->getFirstLayer()) , m_frame(FrameNumber(0)) , m_zoom(0) + , m_cursorThick(0) + , m_cursorScreen(0, 0) + , m_cursorEditor(0, 0) + , m_quicktool(NULL) , m_selectionMode(kDefaultSelectionMode) , m_offset_x(0) , m_offset_y(0) @@ -158,14 +163,6 @@ Editor::Editor(Document* document, EditorFlags flags) // Add the first state into the history. m_statesHistory.push(m_state); - m_cursor_thick = 0; - m_cursor_screen_x = 0; - m_cursor_screen_y = 0; - m_cursor_editor_x = 0; - m_cursor_editor_y = 0; - - m_quicktool = NULL; - this->setFocusStop(true); m_currentToolChangeConn = @@ -293,17 +290,19 @@ void Editor::setDefaultScroll() View* view = View::getView(this); Rect vp = view->getViewportBounds(); - setEditorScroll(m_offset_x - vp.w/2 + (m_sprite->width()/2), - m_offset_y - vp.h/2 + (m_sprite->height()/2), false); + setEditorScroll( + gfx::Point( + m_offset_x - vp.w/2 + (m_sprite->width()/2), + m_offset_y - vp.h/2 + (m_sprite->height()/2)), false); } // Sets the scroll position of the editor -void Editor::setEditorScroll(int x, int y, bool blit_valid_rgn) +void Editor::setEditorScroll(const gfx::Point& scroll, bool blit_valid_rgn) { View* view = View::getView(this); Point oldScroll; Region region; - int thick = m_cursor_thick; + int thick = m_cursorThick; if (thick) clearBrushPreview(); @@ -313,25 +312,22 @@ void Editor::setEditorScroll(int x, int y, bool blit_valid_rgn) oldScroll = view->getViewScroll(); } - view->setViewScroll(Point(x, y)); + view->setViewScroll(scroll); Point newScroll = view->getViewScroll(); if (blit_valid_rgn) { // Move screen with blits - scrollRegion(region, - oldScroll.x - newScroll.x, - oldScroll.y - newScroll.y); + scrollRegion(region, oldScroll - newScroll); } if (thick) - drawBrushPreview(m_cursor_screen_x, m_cursor_screen_y); + drawBrushPreview(m_cursorScreen); } void Editor::setEditorZoom(int zoom) { setZoomAndCenterInMouse(zoom, - jmouse_x(0), jmouse_y(0), - Editor::kCofiguredZoomBehavior); + ui::get_mouse_position(), Editor::kCofiguredZoomBehavior); } void Editor::updateEditor() @@ -592,7 +588,7 @@ void Editor::drawMaskSafe() if (isVisible() && m_document && m_document->getBoundariesSegments()) { - int thick = m_cursor_thick; + int thick = m_cursorThick; Region region; getDrawableRegion(region, kCutTopWindows); @@ -614,7 +610,7 @@ void Editor::drawMaskSafe() // Draw the cursor if (thick) - drawBrushPreview(m_cursor_screen_x, m_cursor_screen_y); + drawBrushPreview(m_cursorScreen); else jmouse_show(); } @@ -641,7 +637,7 @@ void Editor::drawGrid(Graphics* g, const gfx::Rect& spriteBounds, const Rect& gr if (grid.y < 0) grid.y += grid.h; // Convert the "grid" rectangle to screen coordinates - editorToScreen(grid, &grid); + grid = editorToScreen(grid); // Adjust for client area gfx::Rect bounds = getBounds(); @@ -682,7 +678,7 @@ void Editor::flashCurrentLayer() if (src_image) { RenderEngine::setPreviewImage(NULL, FrameNumber(0), NULL); - m_document->prepareExtraCel(0, 0, m_sprite->width(), m_sprite->height(), 255); + m_document->prepareExtraCel(m_sprite->bounds(), 255); Image* flash_image = m_document->getExtraCelImage(); clear_image(flash_image, flash_image->maskColor()); @@ -726,7 +722,7 @@ gfx::Point Editor::autoScroll(MouseMessage* msg, AutoScroll dir, bool blit_valid else { scroll -= deltaScroll; } - setEditorScroll(scroll.x, scroll.y, blit_valid_rgn); + setEditorScroll(scroll, blit_valid_rgn); #ifdef WIN32 mousePos -= delta; @@ -860,56 +856,56 @@ tools::Ink* Editor::getCurrentEditorInk() return ink; } -void Editor::screenToEditor(int xin, int yin, int* xout, int* yout) +gfx::Point Editor::screenToEditor(const gfx::Point& pt) { View* view = View::getView(this); Rect vp = view->getViewportBounds(); Point scroll = view->getViewScroll(); - *xout = (xin - vp.x + scroll.x - m_offset_x) >> m_zoom; - *yout = (yin - vp.y + scroll.y - m_offset_y) >> m_zoom; + return gfx::Point( + (pt.x - vp.x + scroll.x - m_offset_x) >> m_zoom, + (pt.y - vp.y + scroll.y - m_offset_y) >> m_zoom); } -void Editor::screenToEditor(const Rect& in, Rect* out) -{ - int x1, y1, x2, y2; - screenToEditor(in.x, in.y, &x1, &y1); - screenToEditor(in.x+in.w, in.y+in.h, &x2, &y2); - *out = Rect(x1, y1, x2 - x1, y2 - y1); -} - -void Editor::editorToScreen(int xin, int yin, int* xout, int* yout) +Point Editor::editorToScreen(const gfx::Point& pt) { View* view = View::getView(this); Rect vp = view->getViewportBounds(); Point scroll = view->getViewScroll(); - *xout = (vp.x - scroll.x + m_offset_x + (xin << m_zoom)); - *yout = (vp.y - scroll.y + m_offset_y + (yin << m_zoom)); + return Point( + (vp.x - scroll.x + m_offset_x + (pt.x << m_zoom)), + (vp.y - scroll.y + m_offset_y + (pt.y << m_zoom))); } -void Editor::editorToScreen(const Rect& in, Rect* out) +Rect Editor::screenToEditor(const Rect& rc) { - int x1, y1, x2, y2; - editorToScreen(in.x, in.y, &x1, &y1); - editorToScreen(in.x+in.w, in.y+in.h, &x2, &y2); - *out = Rect(x1, y1, x2 - x1, y2 - y1); + return gfx::Rect( + screenToEditor(rc.getOrigin()), + screenToEditor(rc.getPoint2())); +} + +Rect Editor::editorToScreen(const Rect& rc) +{ + return gfx::Rect( + editorToScreen(rc.getOrigin()), + editorToScreen(rc.getPoint2())); } void Editor::showDrawingCursor() { ASSERT(m_sprite != NULL); - if (!m_cursor_thick && canDraw()) { + if (!m_cursorThick && canDraw()) { jmouse_hide(); - drawBrushPreview(jmouse_x(0), jmouse_y(0)); + drawBrushPreview(ui::get_mouse_position()); jmouse_show(); } } void Editor::hideDrawingCursor() { - if (m_cursor_thick) { + if (m_cursorThick) { jmouse_hide(); clearBrushPreview(); jmouse_show(); @@ -919,17 +915,14 @@ void Editor::hideDrawingCursor() void Editor::moveDrawingCursor() { // Draw cursor - if (m_cursor_thick) { - int x, y; - - x = jmouse_x(0); - y = jmouse_y(0); + if (m_cursorThick) { + gfx::Point mousePos = ui::get_mouse_position(); // Redraw it only when the mouse change to other pixel (not // when the mouse moves only). - if ((m_cursor_screen_x != x) || (m_cursor_screen_y != y)) { + if (m_cursorScreen != mousePos) { jmouse_hide(); - moveBrushPreview(x, y); + moveBrushPreview(mousePos); jmouse_show(); } } @@ -961,28 +954,25 @@ Rect Editor::getVisibleSpriteBounds() View* view = View::getView(this); Rect vp = view->getViewportBounds(); - int x1, y1, x2, y2; + vp = screenToEditor(vp); - screenToEditor(vp.x, vp.y, &x1, &y1); - screenToEditor(vp.x+vp.w-1, vp.y+vp.h-1, &x2, &y2); - - return Rect(0, 0, m_sprite->width(), m_sprite->height()) - .createIntersect(Rect(x1, y1, x2-x1+1, y2-y1+1)); + return vp.createIntersect(m_sprite->bounds()); } // Changes the scroll to see the given point as the center of the editor. -void Editor::centerInSpritePoint(int x, int y) +void Editor::centerInSpritePoint(const gfx::Point& spritePos) { View* view = View::getView(this); Rect vp = view->getViewportBounds(); hideDrawingCursor(); - x = m_offset_x - (vp.w/2) + ((1<>1) + (x << m_zoom); - y = m_offset_y - (vp.h/2) + ((1<>1) + (y << m_zoom); + gfx::Point scroll( + m_offset_x - (vp.w/2) + ((1<>1) + (spritePos.x << m_zoom), + m_offset_y - (vp.h/2) + ((1<>1) + (spritePos.y << m_zoom)); updateEditor(); - setEditorScroll(x, y, false); + setEditorScroll(scroll, false); showDrawingCursor(); invalidate(); @@ -1238,8 +1228,8 @@ void Editor::onPaint(ui::PaintEvent& ev) gfx::Rect rc = getClientBounds(); SkinTheme* theme = static_cast(this->getTheme()); - int old_cursor_thick = m_cursor_thick; - if (m_cursor_thick) + int old_cursor_thick = m_cursorThick; + if (m_cursorThick) clearBrushPreview(); // Editor without sprite @@ -1266,7 +1256,7 @@ void Editor::onPaint(ui::PaintEvent& ev) // Draw the cursor again if (old_cursor_thick != 0) { - drawBrushPreview(jmouse_x(0), jmouse_y(0)); + drawBrushPreview(ui::get_mouse_position()); } } catch (const LockedDocumentException&) { @@ -1285,7 +1275,7 @@ void Editor::onCurrentToolChange() void Editor::onFgColorChange() { - if (m_cursor_thick) { + if (m_cursorThick) { hideDrawingCursor(); showDrawingCursor(); } @@ -1313,22 +1303,20 @@ bool Editor::canDraw() bool Editor::isInsideSelection() { - int x, y; - screenToEditor(jmouse_x(0), jmouse_y(0), &x, &y); + gfx::Point spritePos = screenToEditor(ui::get_mouse_position()); return (m_selectionMode != kSubtractSelectionMode) && - m_document != NULL && - m_document->isMaskVisible() && - m_document->mask()->containsPoint(x, y); + m_document != NULL && + m_document->isMaskVisible() && + m_document->mask()->containsPoint(spritePos.x, spritePos.y); } -void Editor::setZoomAndCenterInMouse(int zoom, int mouse_x, int mouse_y, ZoomBehavior zoomBehavior) +void Editor::setZoomAndCenterInMouse(int zoom, + const gfx::Point& mousePos, ZoomBehavior zoomBehavior) { View* view = View::getView(this); Rect vp = view->getViewportBounds(); - int x, y; bool centerMouse = false; - int mx, my; switch (zoomBehavior) { case kCofiguredZoomBehavior: @@ -1343,34 +1331,33 @@ void Editor::setZoomAndCenterInMouse(int zoom, int mouse_x, int mouse_y, ZoomBeh } hideDrawingCursor(); - screenToEditor(mouse_x, mouse_y, &x, &y); + gfx::Point spritePos = screenToEditor(mousePos); + gfx::Point mid; if (centerMouse) { - mx = vp.x+vp.w/2; - my = vp.y+vp.h/2; + mid.x = vp.x+vp.w/2; + mid.y = vp.y+vp.h/2; } else { - mx = mouse_x; - my = mouse_y; + mid.x = mousePos.x; + mid.y = mousePos.y; } - x = m_offset_x - (mx - vp.x) + ((1<>1) + (x << zoom); - y = m_offset_y - (my - vp.y) + ((1<>1) + (y << zoom); + spritePos.x = m_offset_x - (mid.x - vp.x) + ((1<>1) + (spritePos.x << zoom); + spritePos.y = m_offset_y - (mid.y - vp.y) + ((1<>1) + (spritePos.y << zoom); - if ((m_zoom != zoom) || - (m_cursor_editor_x != mx) || - (m_cursor_editor_y != my)) { + if ((m_zoom != zoom) || (m_cursorEditor != mid)) { bool blit_valid_rgn = (m_zoom == zoom); m_zoom = zoom; updateEditor(); - setEditorScroll(x, y, blit_valid_rgn); + setEditorScroll(spritePos, blit_valid_rgn); } showDrawingCursor(); } -void Editor::pasteImage(const Image* image, int x, int y) +void Editor::pasteImage(const Image* image, const gfx::Point& pos) { // Change to a selection tool: it's necessary for PixelsMovement // which will use the extra cel for transformation preview, and is @@ -1389,6 +1376,8 @@ void Editor::pasteImage(const Image* image, int x, int y) Layer* layer = this->layer(); // Check bounds where the image will be pasted. + int x = pos.x; + int y = pos.y; { // Then we check if the image will be visible by the user. Rect visibleBounds = getVisibleSpriteBounds(); @@ -1415,10 +1404,10 @@ void Editor::pasteImage(const Image* image, int x, int y) PixelsMovementPtr pixelsMovement( new PixelsMovement(UIContext::instance(), document, sprite, layer, - image, x, y, opacity, "Paste")); + image, gfx::Point(x, y), opacity, "Paste")); // Select the pasted image so the user can move it and transform it. - pixelsMovement->maskImage(image, x, y); + pixelsMovement->maskImage(image); setState(EditorStatePtr(new MovingPixelsState(this, NULL, pixelsMovement, NoHandle))); } @@ -1426,7 +1415,7 @@ void Editor::pasteImage(const Image* image, int x, int y) void Editor::startSelectionTransformation(const gfx::Point& move) { if (MovingPixelsState* movingPixels = dynamic_cast(m_state.get())) { - movingPixels->translate(move.x, move.y); + movingPixels->translate(move); } else if (StandbyState* standby = dynamic_cast(m_state.get())) { standby->startSelectionTransformation(this, move); diff --git a/src/app/ui/editor/editor.h b/src/app/ui/editor/editor.h index 48c33db44..61ab4a0f6 100644 --- a/src/app/ui/editor/editor.h +++ b/src/app/ui/editor/editor.h @@ -1,5 +1,5 @@ /* Aseprite - * Copyright (C) 2001-2013 David Capello + * Copyright (C) 2001-2014 David Capello * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -69,7 +69,7 @@ namespace app { class Editor : public ui::Widget, public DocumentSettingsObserver { public: - typedef void (*PixelDelegate)(ui::Graphics* g, int x, int y, gfx::Color color); + typedef void (*PixelDelegate)(ui::Graphics*, const gfx::Point&, gfx::Color); enum EditorFlags { kNoneFlag = 0, @@ -125,14 +125,14 @@ namespace app { int zoom() const { return m_zoom; } int offsetX() const { return m_offset_x; } int offsetY() const { return m_offset_y; } - int cursorThick() { return m_cursor_thick; } + int cursorThick() { return m_cursorThick; } void setZoom(int zoom) { m_zoom = zoom; } void setOffsetX(int x) { m_offset_x = x; } void setOffsetY(int y) { m_offset_y = y; } void setDefaultScroll(); - void setEditorScroll(int x, int y, bool blit_valid_rgn); + void setEditorScroll(const gfx::Point& scroll, bool blit_valid_rgn); void setEditorZoom(int zoom); // Updates the Editor's view. @@ -144,10 +144,10 @@ namespace app { void flashCurrentLayer(); - void screenToEditor(int xin, int yin, int* xout, int* yout); - void screenToEditor(const gfx::Rect& in, gfx::Rect* out); - void editorToScreen(int xin, int yin, int* xout, int* yout); - void editorToScreen(const gfx::Rect& in, gfx::Rect* out); + gfx::Point screenToEditor(const gfx::Point& pt); + gfx::Point editorToScreen(const gfx::Point& pt); + gfx::Rect screenToEditor(const gfx::Rect& rc); + gfx::Rect editorToScreen(const gfx::Rect& rc); void showDrawingCursor(); void hideDrawingCursor(); @@ -166,7 +166,7 @@ namespace app { gfx::Rect getVisibleSpriteBounds(); // Changes the scroll to see the given point as the center of the editor. - void centerInSpritePoint(int x, int y); + void centerInSpritePoint(const gfx::Point& spritePos); void updateStatusBar(); @@ -187,9 +187,10 @@ namespace app { // Returns true if the cursor is inside the active mask/selection. bool isInsideSelection(); - void setZoomAndCenterInMouse(int zoom, int mouse_x, int mouse_y, ZoomBehavior zoomBehavior); + void setZoomAndCenterInMouse(int zoom, + const gfx::Point& mousePos, ZoomBehavior zoomBehavior); - void pasteImage(const Image* image, int x, int y); + void pasteImage(const Image* image, const gfx::Point& pos); void startSelectionTransformation(const gfx::Point& move); @@ -221,8 +222,8 @@ namespace app { void setStateInternal(const EditorStatePtr& newState); void updateQuicktool(); void updateContextBarFromModifiers(); - void drawBrushPreview(int x, int y, bool refresh = true); - void moveBrushPreview(int x, int y, bool refresh = true); + void drawBrushPreview(const gfx::Point& pos, bool refresh = true); + void moveBrushPreview(const gfx::Point& pos, bool refresh = true); void clearBrushPreview(bool refresh = true); bool doesBrushPreviewNeedSubpixel(); bool isCurrentToolAffectedByRightClickMode(); @@ -235,8 +236,8 @@ namespace app { void forEachBrushPixel( ui::Graphics* g, - int screen_x, int screen_y, - int sprite_x, int sprite_y, + const gfx::Point& screenPos, + const gfx::Point& spritePos, gfx::Color color, PixelDelegate pixelDelegate); @@ -262,11 +263,9 @@ namespace app { int m_zoom; // Zoom in the editor // Drawing cursor - int m_cursor_thick; - int m_cursor_screen_x; // Position in the screen (view) - int m_cursor_screen_y; - int m_cursor_editor_x; // Position in the editor (model) - int m_cursor_editor_y; + int m_cursorThick; + gfx::Point m_cursorScreen; // Position in the screen (view) + gfx::Point m_cursorEditor; // Position in the editor (model) // Current selected quicktool (this genererally should be NULL if // the user is not pressing any keyboard key). diff --git a/src/app/ui/editor/moving_cel_state.cpp b/src/app/ui/editor/moving_cel_state.cpp index 160b51c9f..852a86d6d 100644 --- a/src/app/ui/editor/moving_cel_state.cpp +++ b/src/app/ui/editor/moving_cel_state.cpp @@ -52,17 +52,14 @@ MovingCelState::MovingCelState(Editor* editor, MouseMessage* msg) m_cel = layer->getCel(editor->frame()); if (m_cel) { - m_celStartX = m_cel->x(); - m_celStartY = m_cel->y(); + m_celStart = m_cel->position(); } else { - m_celStartX = 0; - m_celStartY = 0; + m_celStart = gfx::Point(0, 0); } - m_celNewX = m_celStartX; - m_celNewY = m_celStartY; + m_celNew = m_celStart; - editor->screenToEditor(msg->position().x, msg->position().y, &m_mouseStartX, &m_mouseStartY); + m_mouseStart = editor->screenToEditor(msg->position()); editor->captureMouse(); // Hide the mask (temporarily, until mouse-up event) @@ -83,11 +80,10 @@ bool MovingCelState::onMouseUp(Editor* editor, MouseMessage* msg) // Here we put back the cel into its original coordinate (so we can // add an undoer before). - if (m_celStartX != m_celNewX || - m_celStartY != m_celNewY) { + if (m_celStart != m_celNew) { // Put the cel in the original position. if (m_cel) - m_cel->setPosition(m_celStartX, m_celStartY); + m_cel->setPosition(m_celStart); // If the user didn't cancel the operation... if (!m_canceled) { @@ -96,22 +92,21 @@ bool MovingCelState::onMouseUp(Editor* editor, MouseMessage* msg) DocumentApi api = document->getApi(); // And now we move the cel (or all selected range) to the new position. - int deltaX = m_celNewX - m_celStartX; - int deltaY = m_celNewY - m_celStartY; + gfx::Point delta = m_celNew - m_celStart; DocumentRange range = App::instance()->getMainWindow()->getTimeline()->range(); if (range.enabled()) { for (Cel* cel : get_cels_in_range(writer.sprite(), range)) - api.setCelPosition(writer.sprite(), cel, cel->x()+deltaX, cel->y()+deltaY); + api.setCelPosition(writer.sprite(), cel, cel->x()+delta.x, cel->y()+delta.y); } else if (m_cel) { - api.setCelPosition(writer.sprite(), m_cel, m_celNewX, m_celNewY); + api.setCelPosition(writer.sprite(), m_cel, m_celNew.x, m_celNew.y); } // Move selection if it was visible if (m_maskVisible) - api.setMaskPosition(document->mask()->bounds().x + deltaX, - document->mask()->bounds().y + deltaY); + api.setMaskPosition(document->mask()->bounds().x + delta.x, + document->mask()->bounds().y + delta.y); undoTransaction.commit(); } @@ -130,14 +125,11 @@ bool MovingCelState::onMouseUp(Editor* editor, MouseMessage* msg) bool MovingCelState::onMouseMove(Editor* editor, MouseMessage* msg) { - int newMouseX, newMouseY; - editor->screenToEditor(msg->position().x, msg->position().y, &newMouseX, &newMouseY); - - m_celNewX = m_celStartX - m_mouseStartX + newMouseX; - m_celNewY = m_celStartY - m_mouseStartY + newMouseY; + gfx::Point newCursorPos = editor->screenToEditor(msg->position()); + m_celNew = m_celStart - m_mouseStart + newCursorPos; if (m_cel) - m_cel->setPosition(m_celNewX, m_celNewY); + m_cel->setPosition(m_celNew); // Redraw the new cel position. editor->invalidate(); @@ -151,10 +143,10 @@ bool MovingCelState::onUpdateStatusBar(Editor* editor) StatusBar::instance()->setStatusText (0, "Pos %3d %3d Offset %3d %3d", - (int)m_celNewX, - (int)m_celNewY, - (int)(m_celNewX - m_celStartX), - (int)(m_celNewY - m_celStartY)); + (int)m_celNew.x, + (int)m_celNew.y, + (int)(m_celNew.x - m_celStart.x), + (int)(m_celNew.y - m_celStart.y)); return true; } diff --git a/src/app/ui/editor/moving_cel_state.h b/src/app/ui/editor/moving_cel_state.h index 5140d12de..41fe67818 100644 --- a/src/app/ui/editor/moving_cel_state.h +++ b/src/app/ui/editor/moving_cel_state.h @@ -40,12 +40,9 @@ namespace app { private: Cel* m_cel; - int m_celStartX; - int m_celStartY; - int m_mouseStartX; - int m_mouseStartY; - int m_celNewX; - int m_celNewY; + gfx::Point m_celStart; + gfx::Point m_mouseStart; + gfx::Point m_celNew; bool m_canceled; bool m_maskVisible; }; diff --git a/src/app/ui/editor/moving_pixels_state.cpp b/src/app/ui/editor/moving_pixels_state.cpp index 0425ad6cc..b11845564 100644 --- a/src/app/ui/editor/moving_pixels_state.cpp +++ b/src/app/ui/editor/moving_pixels_state.cpp @@ -1,5 +1,5 @@ /* Aseprite - * Copyright (C) 2001-2013 David Capello + * Copyright (C) 2001-2014 David Capello * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -70,9 +70,8 @@ MovingPixelsState::MovingPixelsState(Editor* editor, MouseMessage* msg, PixelsMo m_pixelsMovement = pixelsMovement; if (handle != NoHandle) { - int u, v; - editor->screenToEditor(msg->position().x, msg->position().y, &u, &v); - m_pixelsMovement->catchImage(u, v, handle); + gfx::Point pt = editor->screenToEditor(msg->position()); + m_pixelsMovement->catchImage(pt, handle); editor->captureMouse(); } @@ -119,13 +118,13 @@ MovingPixelsState::~MovingPixelsState() m_editor->document()->generateMaskBoundaries(); } -void MovingPixelsState::translate(int dx, int dy) +void MovingPixelsState::translate(const gfx::Point& delta) { if (m_pixelsMovement->isDragging()) m_pixelsMovement->dropImageTemporarily(); - m_pixelsMovement->catchImageAgain(0, 0, MoveHandle); - m_pixelsMovement->moveImage(dx, dy, PixelsMovement::NormalMovement); + m_pixelsMovement->catchImageAgain(gfx::Point(0, 0), MoveHandle); + m_pixelsMovement->moveImage(delta, PixelsMovement::NormalMovement); m_pixelsMovement->dropImageTemporarily(); } @@ -206,9 +205,8 @@ bool MovingPixelsState::onMouseDown(Editor* editor, MouseMessage* msg) if (handle != NoHandle) { // Re-catch the image - int x, y; - editor->screenToEditor(msg->position().x, msg->position().y, &x, &y); - m_pixelsMovement->catchImageAgain(x, y, handle); + m_pixelsMovement->catchImageAgain( + editor->screenToEditor(msg->position()), handle); editor->captureMouse(); return true; @@ -226,9 +224,8 @@ bool MovingPixelsState::onMouseDown(Editor* editor, MouseMessage* msg) } // Re-catch the image - int x, y; - editor->screenToEditor(msg->position().x, msg->position().y, &x, &y); - m_pixelsMovement->catchImageAgain(x, y, MoveHandle); + m_pixelsMovement->catchImageAgain( + editor->screenToEditor(msg->position()), MoveHandle); editor->captureMouse(); return true; @@ -267,8 +264,7 @@ bool MovingPixelsState::onMouseMove(Editor* editor, MouseMessage* msg) gfx::Point mousePos = editor->autoScroll(msg, AutoScroll::MouseDir, false); // Get the position of the mouse in the sprite - int x, y; - editor->screenToEditor(mousePos.x, mousePos.y, &x, &y); + gfx::Point spritePos = editor->screenToEditor(mousePos); // Get the customization for the pixels movement (snap to grid, angle snap, etc.). PixelsMovement::MoveModifier moveModifier = PixelsMovement::NormalMovement; @@ -291,7 +287,7 @@ bool MovingPixelsState::onMouseMove(Editor* editor, MouseMessage* msg) transfHandles->invalidateHandles(editor, m_pixelsMovement->getTransformation()); // Drag the image to that position - m_pixelsMovement->moveImage(x, y, moveModifier); + m_pixelsMovement->moveImage(spritePos, moveModifier); editor->updateStatusBar(); return true; diff --git a/src/app/ui/editor/moving_pixels_state.h b/src/app/ui/editor/moving_pixels_state.h index 24f0f630c..dc930a926 100644 --- a/src/app/ui/editor/moving_pixels_state.h +++ b/src/app/ui/editor/moving_pixels_state.h @@ -46,7 +46,7 @@ namespace app { MovingPixelsState(Editor* editor, ui::MouseMessage* msg, PixelsMovementPtr pixelsMovement, HandleType handle); virtual ~MovingPixelsState(); - void translate(int dx, int dy); + void translate(const gfx::Point& delta); // EditorState virtual BeforeChangeAction onBeforeChangeState(Editor* editor, EditorState* newState) override; diff --git a/src/app/ui/editor/pixels_movement.cpp b/src/app/ui/editor/pixels_movement.cpp index 9127322a3..8ec4b836e 100644 --- a/src/app/ui/editor/pixels_movement.cpp +++ b/src/app/ui/editor/pixels_movement.cpp @@ -47,9 +47,9 @@ static inline const base::Vector2d point2Vector(const gfx::PointT& pt } PixelsMovement::PixelsMovement(Context* context, - Document* document, Sprite* sprite, Layer* layer, - const Image* moveThis, int initialX, int initialY, int opacity, - const char* operationName) + Document* document, Sprite* sprite, Layer* layer, + const Image* moveThis, const gfx::Point& initialPos, int opacity, + const char* operationName) : m_reader(context) , m_document(document) , m_sprite(sprite) @@ -61,11 +61,11 @@ PixelsMovement::PixelsMovement(Context* context, , m_originalImage(Image::createCopy(moveThis)) , m_maskColor(m_sprite->transparentColor()) { - m_initialData = gfx::Transformation(gfx::Rect(initialX, initialY, moveThis->width(), moveThis->height())); + m_initialData = gfx::Transformation(gfx::Rect(initialPos, gfx::Size(moveThis->width(), moveThis->height()))); m_currentData = m_initialData; ContextWriter writer(m_reader); - m_document->prepareExtraCel(0, 0, m_sprite->width(), m_sprite->height(), opacity); + m_document->prepareExtraCel(m_sprite->bounds(), opacity); redrawExtraImage(); @@ -134,25 +134,21 @@ void PixelsMovement::copyMask() } } -void PixelsMovement::catchImage(int x, int y, HandleType handle) +void PixelsMovement::catchImage(const gfx::Point& pos, HandleType handle) { ASSERT(handle != NoHandle); - m_catchX = x; - m_catchY = y; + m_catchPos = pos; m_isDragging = true; m_handle = handle; } -void PixelsMovement::catchImageAgain(int x, int y, HandleType handle) +void PixelsMovement::catchImageAgain(const gfx::Point& pos, HandleType handle) { // Create a new UndoTransaction to move the pixels to other position m_initialData = m_currentData; m_isDragging = true; - - m_catchX = x; - m_catchY = y; - + m_catchPos = pos; m_handle = handle; // Hide the mask (do not deselect it, it will be moved them using @@ -165,7 +161,7 @@ void PixelsMovement::catchImageAgain(int x, int y, HandleType handle) } } -void PixelsMovement::maskImage(const Image* image, int x, int y) +void PixelsMovement::maskImage(const Image* image) { m_currentMask->replace(m_currentData.bounds()); m_initialMask->copyFrom(m_currentMask); @@ -180,7 +176,7 @@ void PixelsMovement::maskImage(const Image* image, int x, int y) update_screen_for_document(m_document); } -void PixelsMovement::moveImage(int x, int y, MoveModifier moveModifier) +void PixelsMovement::moveImage(const gfx::Point& pos, MoveModifier moveModifier) { gfx::Transformation::Corners oldCorners; m_currentData.transformBox(oldCorners); @@ -196,10 +192,10 @@ void PixelsMovement::moveImage(int x, int y, MoveModifier moveModifier) bool updateBounds = false; int dx, dy; - dx = ((x - m_catchX) * cos(m_currentData.angle()) + - (y - m_catchY) * -sin(m_currentData.angle())); - dy = ((x - m_catchX) * sin(m_currentData.angle()) + - (y - m_catchY) * cos(m_currentData.angle())); + dx = ((pos.x - m_catchPos.x) * cos(m_currentData.angle()) + + (pos.y - m_catchPos.y) * -sin(m_currentData.angle())); + dy = ((pos.x - m_catchPos.x) * sin(m_currentData.angle()) + + (pos.y - m_catchPos.y) * cos(m_currentData.angle())); switch (m_handle) { @@ -339,10 +335,10 @@ void PixelsMovement::moveImage(int x, int y, MoveModifier moveModifier) double newAngle = m_initialData.angle() - + atan2((double)(-y + abs_pivot.y), - (double)(+x - abs_pivot.x)) - - atan2((double)(-m_catchY + abs_initial_pivot.y), - (double)(+m_catchX - abs_initial_pivot.x)); + + atan2((double)(-pos.y + abs_pivot.y), + (double)(+pos.x - abs_pivot.x)) + - atan2((double)(-m_catchPos.y + abs_initial_pivot.y), + (double)(+m_catchPos.x - abs_initial_pivot.x)); // Put the angle in -180 to 180 range. while (newAngle < -PI) newAngle += 2*PI; @@ -377,8 +373,8 @@ void PixelsMovement::moveImage(int x, int y, MoveModifier moveModifier) case PivotHandle: { // Calculate the new position of the pivot - gfx::Point newPivot(m_initialData.pivot().x + (x - m_catchX), - m_initialData.pivot().y + (y - m_catchY)); + gfx::Point newPivot(m_initialData.pivot().x + (pos.x - m_catchPos.x), + m_initialData.pivot().y + (pos.y - m_catchPos.y)); m_currentData = m_initialData; m_currentData.displacePivotTo(newPivot); diff --git a/src/app/ui/editor/pixels_movement.h b/src/app/ui/editor/pixels_movement.h index 777146ec9..bcc1f3b1e 100644 --- a/src/app/ui/editor/pixels_movement.h +++ b/src/app/ui/editor/pixels_movement.h @@ -54,23 +54,24 @@ namespace app { // The "moveThis" image specifies the chunk of pixels to be moved. // The "x" and "y" parameters specify the initial position of the image. PixelsMovement(Context* context, - Document* document, Sprite* sprite, Layer* layer, - const Image* moveThis, int x, int y, int opacity, - const char* operationName); + Document* document, Sprite* sprite, Layer* layer, + const Image* moveThis, + const gfx::Point& initialPos, int opacity, + const char* operationName); ~PixelsMovement(); void cutMask(); void copyMask(); - void catchImage(int x, int y, HandleType handle); - void catchImageAgain(int x, int y, HandleType handle); + void catchImage(const gfx::Point& pos, HandleType handle); + void catchImageAgain(const gfx::Point& pos, HandleType handle); // Creates a mask for the given image. Useful when the user paste a // image from the clipboard. - void maskImage(const Image* image, int x, int y); + void maskImage(const Image* image); // Moves the image to the new position (relative to the start // position given in the ctor). - void moveImage(int x, int y, MoveModifier moveModifier); + void moveImage(const gfx::Point& pos, MoveModifier moveModifier); // Returns a copy of the current image being dragged with the // current transformation. @@ -103,7 +104,7 @@ namespace app { private: void redrawExtraImage(); void redrawCurrentMask(); - void drawImage(doc::Image* dst, const gfx::Point& pt); + void drawImage(doc::Image* dst, const gfx::Point& pos); void drawParallelogram(doc::Image* dst, doc::Image* src, const gfx::Transformation::Corners& corners, const gfx::Point& leftTop); @@ -118,7 +119,7 @@ namespace app { bool m_adjustPivot; HandleType m_handle; Image* m_originalImage; - int m_catchX, m_catchY; + gfx::Point m_catchPos; gfx::Transformation m_initialData; gfx::Transformation m_currentData; Mask* m_initialMask; diff --git a/src/app/ui/editor/scrolling_state.cpp b/src/app/ui/editor/scrolling_state.cpp index 9ba63bb06..b86475084 100644 --- a/src/app/ui/editor/scrolling_state.cpp +++ b/src/app/ui/editor/scrolling_state.cpp @@ -74,7 +74,7 @@ bool ScrollingState::onMouseMove(Editor* editor, MouseMessage* msg) scroll -= newPos - m_oldPos; m_oldPos = newPos; - editor->setEditorScroll(scroll.x, scroll.y, true); + editor->setEditorScroll(scroll, true); return true; } diff --git a/src/app/ui/editor/select_box_state.cpp b/src/app/ui/editor/select_box_state.cpp index ebed213d0..1c2963001 100644 --- a/src/app/ui/editor/select_box_state.cpp +++ b/src/app/ui/editor/select_box_state.cpp @@ -98,17 +98,16 @@ bool SelectBoxState::onMouseUp(Editor* editor, MouseMessage* msg) bool SelectBoxState::onMouseMove(Editor* editor, MouseMessage* msg) { if (m_movingRuler >= 0) { - int u, v; - editor->screenToEditor(msg->position().x, msg->position().y, &u, &v); + gfx::Point pt = editor->screenToEditor(msg->position()); switch (m_rulers[m_movingRuler].getOrientation()) { case Ruler::Horizontal: - m_rulers[m_movingRuler].setPosition(v); + m_rulers[m_movingRuler].setPosition(pt.y); break; case Ruler::Vertical: - m_rulers[m_movingRuler].setPosition(u); + m_rulers[m_movingRuler].setPosition(pt.x); break; } @@ -182,10 +181,9 @@ void SelectBoxState::postRenderDecorator(EditorPostRender* render) Editor* editor = render->getEditor(); int zoom = editor->zoom(); gfx::Rect vp = View::getView(editor)->getViewportBounds(); - vp.w += 1<screenToEditor(vp, &vp); + vp = editor->screenToEditor(vp); // Paint a grid generated by the box if (hasPaintFlag(PaintGrid)) { @@ -222,12 +220,12 @@ void SelectBoxState::postRenderDecorator(EditorPostRender* render) bool SelectBoxState::touchRuler(Editor* editor, Ruler& ruler, int x, int y) { - int u, v; - editor->editorToScreen(ruler.getPosition(), ruler.getPosition(), &u, &v); + gfx::Point pt = editor->editorToScreen( + gfx::Point(ruler.getPosition(), ruler.getPosition())); switch (ruler.getOrientation()) { - case Ruler::Horizontal: return (y >= v-2 && y <= v+2); - case Ruler::Vertical: return (x >= u-2 && x <= u+2); + case Ruler::Horizontal: return (y >= pt.y-2 && y <= pt.y+2); + case Ruler::Vertical: return (x >= pt.x-2 && x <= pt.x+2); } return false; diff --git a/src/app/ui/editor/standby_state.cpp b/src/app/ui/editor/standby_state.cpp index 3ee095fc6..96659606d 100644 --- a/src/app/ui/editor/standby_state.cpp +++ b/src/app/ui/editor/standby_state.cpp @@ -177,14 +177,10 @@ bool StandbyState::onMouseDown(Editor* editor, MouseMessage* msg) if (clickedInk->isCelMovement()) { // Handle "Auto Select Layer" if (editor->isAutoSelectLayer()) { + gfx::Point cursor = editor->screenToEditor(msg->position()); + ColorPicker picker; - int x, y; - - editor->screenToEditor( - msg->position().x, - msg->position().y, &x, &y); - - picker.pickColor(location, x, y, ColorPicker::FromComposition); + picker.pickColor(location, cursor, ColorPicker::FromComposition); if (layer != picker.layer()) { layer = picker.layer(); @@ -367,8 +363,7 @@ bool StandbyState::onMouseWheel(Editor* editor, MouseMessage* msg) int zoom = MID(MIN_ZOOM, editor->zoom()-dz, MAX_ZOOM); if (editor->zoom() != zoom) editor->setZoomAndCenterInMouse(zoom, - mouseMsg->position().x, mouseMsg->position().y, - Editor::kDontCenterOnZoom); + mouseMsg->position(), Editor::kDontCenterOnZoom); break; } @@ -376,29 +371,26 @@ bool StandbyState::onMouseWheel(Editor* editor, MouseMessage* msg) case WHEEL_VSCROLL: { View* view = View::getView(editor); gfx::Rect vp = view->getViewportBounds(); - int dx = 0; - int dy = 0; + gfx::Point delta(0, 0); if (wheelAction == WHEEL_HSCROLL) { - dx = dz * vp.w; + delta.x = dz * vp.w; } else { - dy = dz * vp.h; + delta.y = dz * vp.h; } if (scrollBigSteps) { - dx /= 2; - dy /= 2; + delta /= 2; } else { - dx /= 10; - dy /= 10; + delta /= 10; } gfx::Point scroll = view->getViewScroll(); editor->hideDrawingCursor(); - editor->setEditorScroll(scroll.x+dx, scroll.y+dy, true); + editor->setEditorScroll(scroll+delta, true); editor->showDrawingCursor(); break; } @@ -487,9 +479,7 @@ bool StandbyState::onUpdateStatusBar(Editor* editor) { tools::Ink* ink = editor->getCurrentEditorInk(); const Sprite* sprite = editor->sprite(); - int x, y; - - editor->screenToEditor(jmouse_x(0), jmouse_y(0), &x, &y); + gfx::Point spritePos = editor->screenToEditor(ui::get_mouse_position()); if (!sprite) { StatusBar::instance()->clearText(); @@ -498,13 +488,14 @@ bool StandbyState::onUpdateStatusBar(Editor* editor) else if (ink->isEyedropper()) { bool grabAlpha = UIContext::instance()->settings()->getGrabAlpha(); ColorPicker picker; - picker.pickColor(editor->getDocumentLocation(), x, y, + picker.pickColor(editor->getDocumentLocation(), + spritePos, grabAlpha ? ColorPicker::FromActiveLayer: ColorPicker::FromComposition); char buf[256]; - sprintf(buf, "- Pos %d %d", x, y); + sprintf(buf, "- Pos %d %d", spritePos.x, spritePos.y); StatusBar::instance()->showColor(0, buf, picker.color(), picker.alpha()); } @@ -515,7 +506,7 @@ bool StandbyState::onUpdateStatusBar(Editor* editor) StatusBar::instance()->setStatusText(0, "Pos %d %d, Size %d %d, Frame %d [%d msecs]", - x, y, + spritePos.x, spritePos.y, (mask ? mask->bounds().w: sprite->width()), (mask ? mask->bounds().h: sprite->height()), editor->frame()+1, @@ -535,7 +526,7 @@ void StandbyState::startSelectionTransformation(Editor* editor, const gfx::Point transformSelection(editor, NULL, NoHandle); if (MovingPixelsState* movingPixels = dynamic_cast(editor->getState().get())) - movingPixels->translate(move.x, move.y); + movingPixels->translate(move); } void StandbyState::transformSelection(Editor* editor, MouseMessage* msg, HandleType handle) @@ -544,15 +535,14 @@ void StandbyState::transformSelection(Editor* editor, MouseMessage* msg, HandleT EditorCustomizationDelegate* customization = editor->getCustomizationDelegate(); Document* document = editor->document(); base::UniquePtr tmpImage(NewImageFromMask(editor->getDocumentLocation())); - int x = document->mask()->bounds().x; - int y = document->mask()->bounds().y; + gfx::Point origin = document->mask()->bounds().getOrigin(); int opacity = 255; Sprite* sprite = editor->sprite(); Layer* layer = editor->layer(); PixelsMovementPtr pixelsMovement( new PixelsMovement(UIContext::instance(), document, sprite, layer, - tmpImage, x, y, opacity, + tmpImage, origin, opacity, "Transformation")); // If the Ctrl key is pressed start dragging a copy of the selection diff --git a/src/app/ui/editor/tool_loop_impl.cpp b/src/app/ui/editor/tool_loop_impl.cpp index 11e76685f..6449a1179 100644 --- a/src/app/ui/editor/tool_loop_impl.cpp +++ b/src/app/ui/editor/tool_loop_impl.cpp @@ -253,10 +253,7 @@ public: gfx::Point screenToSprite(const gfx::Point& screenPoint) override { - gfx::Point spritePoint; - m_editor->screenToEditor(screenPoint.x, screenPoint.y, - &spritePoint.x, &spritePoint.y); - return spritePoint; + return m_editor->screenToEditor(screenPoint); } gfx::Region& getDirtyArea() override diff --git a/src/app/ui/editor/transform_handles.cpp b/src/app/ui/editor/transform_handles.cpp index fadf64182..7c130c0f5 100644 --- a/src/app/ui/editor/transform_handles.cpp +++ b/src/app/ui/editor/transform_handles.cpp @@ -78,18 +78,17 @@ HandleType TransformHandles::getHandleAtPoint(Editor* editor, const gfx::Point& gfx::Transformation::Corners corners; transform.transformBox(corners); - std::vector x(corners.size()); - std::vector y(corners.size()); + std::vector screenPoints(corners.size()); for (size_t c=0; ceditorToScreen(corners[c].x, corners[c].y, &x[c], &y[c]); + screenPoints[c] = editor->editorToScreen(gfx::Point(corners[c].x, corners[c].y)); int handle_rs[2] = { gfx->width()*2, gfx->width()*3 }; for (int i=0; i<2; ++i) { int handle_r = handle_rs[i]; for (size_t c=0; c x(corners.size()); - std::vector y(corners.size()); + std::vector screenPoints(corners.size()); for (size_t c=0; ceditorToScreen(corners[c].x, corners[c].y, &x[c], &y[c]); + screenPoints[c] = editor->editorToScreen(gfx::Point(corners[c].x, corners[c].y)); // TODO DO NOT COMMIT #if 0 // Uncomment this if you want to see the bounds in red (only for debugging purposes) @@ -141,9 +139,9 @@ void TransformHandles::drawHandles(Editor* editor, const gfx::Transformation& tr // Draw corner handle for (size_t c=0; c x(corners.size()); - std::vector y(corners.size()); + std::vector screenPoints(corners.size()); for (size_t c=0; ceditorToScreen(corners[c].x, corners[c].y, &x[c], &y[c]); + screenPoints[c] = editor->editorToScreen(gfx::Point(corners[c].x, corners[c].y)); // Invalidate each corner handle. for (size_t c=0; cget_part(PART_TRANSFORMATION_HANDLE); - int u = (x[handles_info[c].i1]+x[handles_info[c].i2])/2; - int v = (y[handles_info[c].i1]+y[handles_info[c].i2])/2; + int u = (screenPoints[handles_info[c].i1].x+screenPoints[handles_info[c].i2].x)/2; + int v = (screenPoints[handles_info[c].i1].y+screenPoints[handles_info[c].i2].y)/2; adjustHandle(u, v, part->width(), part->height(), angle + handles_info[c].angle); @@ -197,16 +194,14 @@ gfx::Rect TransformHandles::getPivotHandleBounds(Editor* editor, { SkinTheme* theme = static_cast(CurrentTheme::get()); she::Surface* part = theme->get_part(PART_PIVOT_HANDLE); - int pvx, pvy; + gfx::Point screenPivotPos = editor->editorToScreen(transform.pivot()); - editor->editorToScreen(transform.pivot().x, transform.pivot().y, &pvx, &pvy); - - pvx += (1 << editor->zoom()) / 2; - pvy += (1 << editor->zoom()) / 2; + screenPivotPos.x += (1 << editor->zoom()) / 2; + screenPivotPos.y += (1 << editor->zoom()) / 2; return gfx::Rect( - pvx-part->width()/2, - pvy-part->height()/2, + screenPivotPos.x-part->width()/2, + screenPivotPos.y-part->height()/2, part->width(), part->height()); } diff --git a/src/app/ui/editor/zooming_state.cpp b/src/app/ui/editor/zooming_state.cpp index 09f45942e..87c81e7d3 100644 --- a/src/app/ui/editor/zooming_state.cpp +++ b/src/app/ui/editor/zooming_state.cpp @@ -60,8 +60,8 @@ bool ZoomingState::onMouseUp(Editor* editor, MouseMessage* msg) else if (msg->right() && zoom > 0) --zoom; - editor->setZoomAndCenterInMouse(zoom, msg->position().x, msg->position().y, - Editor::kCofiguredZoomBehavior); + editor->setZoomAndCenterInMouse(zoom, + msg->position(), Editor::kCofiguredZoomBehavior); editor->backToPreviousState(); editor->releaseMouse(); diff --git a/src/app/ui/mini_editor.cpp b/src/app/ui/mini_editor.cpp index 01afa27ef..984e94b2c 100644 --- a/src/app/ui/mini_editor.cpp +++ b/src/app/ui/mini_editor.cpp @@ -250,7 +250,7 @@ void MiniEditorWindow::updateUsingEditor(Editor* editor) layout(); } - miniEditor->centerInSpritePoint(pt.x, pt.y); + miniEditor->centerInSpritePoint(pt); miniEditor->setLayer(editor->layer()); miniEditor->setFrame(editor->frame()); } diff --git a/src/app/util/clipboard.cpp b/src/app/util/clipboard.cpp index 8c02ab64f..b0e974f39 100644 --- a/src/app/util/clipboard.cpp +++ b/src/app/util/clipboard.cpp @@ -97,8 +97,7 @@ static bool first_time = true; static Palette* clipboard_palette = NULL; static Image* clipboard_image = NULL; static ClipboardRange clipboard_range; -static int clipboard_x = 0; -static int clipboard_y = 0; +static gfx::Point clipboard_pos(0, 0); static void on_exit_delete_clipboard() { @@ -139,8 +138,7 @@ static bool copy_from_document(const DocumentLocation& location) if (!image) return false; - clipboard_x = document->mask()->bounds().x; - clipboard_y = document->mask()->bounds().y; + clipboard_pos = document->mask()->bounds().getOrigin(); const Palette* pal = document->sprite()->getPalette(location.frame()); set_clipboard_image(image, pal ? new Palette(*pal): NULL, true); @@ -234,8 +232,7 @@ void clipboard::copy_image(Image* image, Palette* pal, const gfx::Point& point) set_clipboard_image(Image::createCopy(image), pal ? new Palette(*pal): NULL, true); - clipboard_x = point.x; - clipboard_y = point.y; + clipboard_pos = point; } void clipboard::paste() @@ -285,7 +282,7 @@ void clipboard::paste() } // Change to MovingPixelsState - editor->pasteImage(src_image, clipboard_x, clipboard_y); + editor->pasteImage(src_image, clipboard_pos); if (src_image != clipboard_image) delete src_image; diff --git a/src/doc/cel.cpp b/src/doc/cel.cpp index 469010d73..d955cb5b8 100644 --- a/src/doc/cel.cpp +++ b/src/doc/cel.cpp @@ -23,10 +23,9 @@ Cel::Cel(FrameNumber frame, int image) , m_layer(NULL) , m_frame(frame) , m_image(image) + , m_position(0, 0) + , m_opacity(255) { - m_x = 0; - m_y = 0; - m_opacity = 255; } Cel::Cel(const Cel& cel) @@ -34,10 +33,9 @@ Cel::Cel(const Cel& cel) , m_layer(NULL) , m_frame(cel.m_frame) , m_image(cel.m_image) + , m_position(cel.m_position) + , m_opacity(cel.m_opacity) { - m_x = cel.m_x; - m_y = cel.m_y; - m_opacity = cel.m_opacity; } Cel::~Cel() @@ -80,7 +78,9 @@ gfx::Rect Cel::bounds() const Image* image = this->image(); ASSERT(image); if (image) - return gfx::Rect(m_x, m_y, image->width(), image->height()); + return gfx::Rect( + m_position.x, m_position.y, + image->width(), image->height()); else return gfx::Rect(); } diff --git a/src/doc/cel.h b/src/doc/cel.h index c0aa7a534..0a51a3f95 100644 --- a/src/doc/cel.h +++ b/src/doc/cel.h @@ -8,9 +8,10 @@ #define DOC_CEL_H_INCLUDED #pragma once -#include "gfx/fwd.h" #include "doc/frame_number.h" #include "doc/object.h" +#include "gfx/fwd.h" +#include "gfx/point.h" namespace doc { @@ -26,8 +27,9 @@ namespace doc { FrameNumber frame() const { return m_frame; } int imageIndex() const { return m_image; } - int x() const { return m_x; } - int y() const { return m_y; } + int x() const { return m_position.x; } + int y() const { return m_position.y; } + gfx::Point position() const { return m_position; } int opacity() const { return m_opacity; } LayerImage* layer() const { return m_layer; } @@ -40,7 +42,11 @@ namespace doc { // LayerImage::moveCel() member function. void setFrame(FrameNumber frame) { m_frame = frame; } void setImage(int image) { m_image = image; } - void setPosition(int x, int y) { m_x = x; m_y = y; } + void setPosition(int x, int y) { + m_position.x = x; + m_position.y = y; + } + void setPosition(const gfx::Point& pos) { m_position = pos; } void setOpacity(int opacity) { m_opacity = opacity; } virtual int getMemSize() const override { @@ -55,7 +61,7 @@ namespace doc { LayerImage* m_layer; FrameNumber m_frame; // Frame position int m_image; // Image index of stock - int m_x, m_y; // X/Y screen position + gfx::Point m_position; // X/Y screen position int m_opacity; // Opacity level }; diff --git a/src/doc/mask.cpp b/src/doc/mask.cpp index 6ff52d14e..3e69e1ffd 100644 --- a/src/doc/mask.cpp +++ b/src/doc/mask.cpp @@ -206,7 +206,7 @@ void Mask::intersect(int x, int y, int w, int h) void Mask::intersect(const gfx::Rect& bounds) { - subtract(bounds.x, bounds.y, bounds.w, bounds.h); + intersect(bounds.x, bounds.y, bounds.w, bounds.h); } void Mask::byColor(const Image *src, int color, int fuzziness) @@ -371,7 +371,7 @@ void Mask::crop(const Image *image) get_pixel(image, c, y2)); if (done_count < 4) - intersect(x1, y1, x2, y2); + intersect(x1, y1, x2-x1+1, y2-y1+1); else clear(); diff --git a/src/doc/sprite.h b/src/doc/sprite.h index d260ebb83..2e7122888 100644 --- a/src/doc/sprite.h +++ b/src/doc/sprite.h @@ -16,6 +16,7 @@ #include "doc/object.h" #include "doc/pixel_format.h" #include "doc/sprite_position.h" +#include "gfx/rect.h" #include @@ -52,6 +53,7 @@ namespace doc { PixelFormat pixelFormat() const { return m_format; } void setPixelFormat(PixelFormat format); + gfx::Rect bounds() const { return gfx::Rect(0, 0, m_width, m_height); } int width() const { return m_width; } int height() const { return m_height; } void setSize(int width, int height); diff --git a/src/ui/widget.cpp b/src/ui/widget.cpp index 9eef86d56..28a2cbba9 100644 --- a/src/ui/widget.cpp +++ b/src/ui/widget.cpp @@ -1049,20 +1049,20 @@ void Widget::invalidateRegion(const Region& region) onInvalidateRegion(region); } -void Widget::scrollRegion(const Region& region, int dx, int dy) +void Widget::scrollRegion(const Region& region, const Point& delta) { - if (dx == 0 && dy == 0) + if (delta.x == 0 && delta.y == 0) return; Region reg2 = region; - reg2.offset(dx, dy); + reg2.offset(delta); reg2.createIntersection(reg2, region); - reg2.offset(-dx, -dy); + reg2.offset(-delta); // Move screen pixels - ui::move_region(reg2, dx, dy); + ui::move_region(reg2, delta.x, delta.y); - reg2.offset(dx, dy); + reg2.offset(delta); m_updateRegion.createUnion(m_updateRegion, region); m_updateRegion.createSubtraction(m_updateRegion, reg2); diff --git a/src/ui/widget.h b/src/ui/widget.h index 556d6305c..dbcbbe3c2 100644 --- a/src/ui/widget.h +++ b/src/ui/widget.h @@ -305,7 +305,7 @@ namespace ui { void flushRedraw(); - void scrollRegion(const gfx::Region& region, int dx, int dy); + void scrollRegion(const gfx::Region& region, const gfx::Point& delta); GraphicsPtr getGraphics(const gfx::Rect& clip);