void TransformHandles::drawHandles(Editor* editor, const gfx::Transformation& transform) { ScreenGraphics g; fixmath::fixed angle = fixmath::ftofix(128.0 * transform.angle() / PI); gfx::Transformation::Corners corners; transform.transformBox(corners); std::vector<gfx::Point> screenPoints(corners.size()); for (size_t c=0; c<corners.size(); ++c) screenPoints[c] = editor->editorToScreen( gfx::Point((int)corners[c].x, (int)corners[c].y)); // TODO DO NOT COMMIT #if 0 // Uncomment this if you want to see the bounds in red (only for debugging purposes) // ----------------------------------------------- { gfx::Point a(transform.bounds().getOrigin()), b(transform.bounds().getPoint2()); a = editor->editorToScreen(a); b = editor->editorToScreen(b); g.drawRect(gfx::rgba(255, 0, 0), gfx::Rect(a, b)); a = transform.pivot(); a = editor->editorToScreen(a); g.drawRect(gfx::rgba(255, 0, 0), gfx::Rect(a.x-2, a.y-2, 5, 5)); } // ----------------------------------------------- #endif // Draw corner handle for (size_t c=0; c<HANDLES; ++c) { drawHandle(&g, (screenPoints[handles_info[c].i1].x+screenPoints[handles_info[c].i2].x)/2, (screenPoints[handles_info[c].i1].y+screenPoints[handles_info[c].i2].y)/2, angle + handles_info[c].angle); } // Draw the pivot if (visiblePivot(angle)) { gfx::Rect pivotBounds = getPivotHandleBounds(editor, transform, corners); SkinTheme* theme = static_cast<SkinTheme*>(CurrentTheme::get()); she::Surface* part = theme->parts.pivotHandle()->getBitmap(0); g.drawRgbaSurface(part, pivotBounds.x, pivotBounds.y); } }
gfx::Rect TransformHandles::getPivotHandleBounds(Editor* editor, const gfx::Transformation& transform, const gfx::Transformation::Corners& corners) { SkinTheme* theme = static_cast<SkinTheme*>(CurrentTheme::get()); gfx::Size partSize = theme->parts.pivotHandle()->getSize(); gfx::Point screenPivotPos = editor->editorToScreen(transform.pivot()); screenPivotPos.x += editor->zoom().apply(1) / 2; screenPivotPos.y += editor->zoom().apply(1) / 2; return gfx::Rect( screenPivotPos.x-partSize.w/2, screenPivotPos.y-partSize.h/2, partSize.w, partSize.h); }