Exemple #1
0
ResizableWindow::~ResizableWindow()
{
    // Don't delete or remove the resizer components yourself! They're managed by the
    // ResizableWindow, and you should leave them alone! You may have deleted them
    // accidentally by careless use of deleteAllChildren()..?
    jassert (resizableCorner == nullptr || getIndexOfChildComponent (resizableCorner) >= 0);
    jassert (resizableBorder == nullptr || getIndexOfChildComponent (resizableBorder) >= 0);

    resizableCorner = nullptr;
    resizableBorder = nullptr;
    clearContentComponent();

    // have you been adding your own components directly to this window..? tut tut tut.
    // Read the instructions for using a ResizableWindow!
    jassert (getNumChildComponents() == 0);
}
Exemple #2
0
    int getRowNumberOfComponent (Component* const rowComponent) const noexcept
    {
        const int index = getIndexOfChildComponent (rowComponent);
        const int num = rows.size();

        for (int i = num; --i >= 0;)
            if (((firstIndex + i) % jmax (1, num)) == index)
                return firstIndex + i;

        return -1;
    }
Exemple #3
0
void Toolbar::itemDragMove (const SourceDetails& dragSourceDetails)
{
    ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (dragSourceDetails.sourceComponent.get());

    if (tc != nullptr)
    {
        if (! items.contains (tc))
        {
            if (tc->getEditingMode() == ToolbarItemComponent::editableOnPalette)
            {
                ToolbarItemPalette* const palette = tc->findParentComponentOfClass<ToolbarItemPalette>();

                if (palette != nullptr)
                    palette->replaceComponent (tc);
            }
            else
            {
                jassert (tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar);
            }

            items.add (tc);
            addChildComponent (tc);
            updateAllItemPositions (true);
        }

        for (int i = getNumItems(); --i >= 0;)
        {
            const int currentIndex = items.indexOf (tc);
            int newIndex = currentIndex;

            const int dragObjectLeft = vertical ? (dragSourceDetails.localPosition.getY() - tc->dragOffsetY)
                                                : (dragSourceDetails.localPosition.getX() - tc->dragOffsetX);
            const int dragObjectRight = dragObjectLeft + (vertical ? tc->getHeight() : tc->getWidth());

            const Rectangle<int> current (Desktop::getInstance().getAnimator()
                                            .getComponentDestination (getChildComponent (newIndex)));
            ToolbarItemComponent* const prev = getNextActiveComponent (newIndex, -1);

            if (prev != nullptr)
            {
                const Rectangle<int> previousPos (Desktop::getInstance().getAnimator().getComponentDestination (prev));

                if (abs (dragObjectLeft - (vertical ? previousPos.getY() : previousPos.getX())
                      < abs (dragObjectRight - (vertical ? current.getBottom() : current.getRight()))))
                {
                    newIndex = getIndexOfChildComponent (prev);
                }
            }

            ToolbarItemComponent* const next = getNextActiveComponent (newIndex, 1);
            if (next != nullptr)
            {
                const Rectangle<int> nextPos (Desktop::getInstance().getAnimator().getComponentDestination (next));

                if (abs (dragObjectLeft - (vertical ? current.getY() : current.getX())
                     > abs (dragObjectRight - (vertical ? nextPos.getBottom() : nextPos.getRight()))))
                {
                    newIndex = getIndexOfChildComponent (next) + 1;
                }
            }

            if (newIndex == currentIndex)
                break;

            items.removeObject (tc, false);
            removeChildComponent (tc);
            addChildComponent (tc, newIndex);
            items.insert (newIndex, tc);
            updateAllItemPositions (true);
        }
    }
}