JUCE-7.0.12-0-g4f43011b96 JUCE-7.0.12-0-g4f43011b96
JUCE — C++ application framework with suport for VST, VST3, LV2 audio plug-ins

« « « Anklang Documentation
Loading...
Searching...
No Matches
juce_ToolbarItemDragAndDropOverlayComponent.h
Go to the documentation of this file.
1 /*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 By using JUCE, you agree to the terms of both the JUCE 7 End-User License
11 Agreement and JUCE Privacy Policy.
12
13 End User License Agreement: www.juce.com/juce-7-licence
14 Privacy Policy: www.juce.com/juce-privacy-policy
15
16 Or: You may also use this code under the terms of the GPL v3 (see
17 www.gnu.org/licenses).
18
19 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
20 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
21 DISCLAIMED.
22
23 ==============================================================================
24*/
25
26namespace juce::detail
27{
28
30{
31public:
33 : isDragging (false)
34 {
35 setAlwaysOnTop (true);
38 }
39
40 void paint (Graphics& g) override
41 {
42 if (ToolbarItemComponent* const tc = getToolbarItemComponent())
43 {
45 && tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar)
46 {
48 g.drawRect (getLocalBounds(), jmin (2, (getWidth() - 1) / 2,
49 (getHeight() - 1) / 2));
50 }
51 }
52 }
53
54 void mouseDown (const MouseEvent& e) override
55 {
56 isDragging = false;
57
58 if (ToolbarItemComponent* const tc = getToolbarItemComponent())
59 {
60 tc->dragOffsetX = e.x;
61 tc->dragOffsetY = e.y;
62 }
63 }
64
65 void mouseDrag (const MouseEvent& e) override
66 {
67 if (e.mouseWasDraggedSinceMouseDown() && ! isDragging)
68 {
69 isDragging = true;
70
72 {
73 dnd->startDragging (Toolbar::toolbarDragDescriptor, getParentComponent(), ScaledImage(), true, nullptr, &e.source);
74
75 if (ToolbarItemComponent* const tc = getToolbarItemComponent())
76 {
77 tc->isBeingDragged = true;
78
79 if (tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar)
80 tc->setVisible (false);
81 }
82 }
83 }
84 }
85
86 void mouseUp (const MouseEvent&) override
87 {
88 isDragging = false;
89
90 if (ToolbarItemComponent* const tc = getToolbarItemComponent())
91 {
92 tc->isBeingDragged = false;
93
94 if (Toolbar* const tb = tc->getToolbar())
95 tb->updateAllItemPositions (true);
96 else if (tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar)
97 delete tc;
98 }
99 }
100
101 void parentSizeChanged() override
102 {
104 }
105
106private:
107 //==============================================================================
108 bool isDragging;
109
110 ToolbarItemComponent* getToolbarItemComponent() const noexcept
111 {
112 return dynamic_cast<ToolbarItemComponent*> (getParentComponent());
113 }
114
115 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ToolbarItemDragAndDropOverlayComponent)
116};
117
118} // namespace juce::detail
The base class for all JUCE user-interface objects.
void setRepaintsOnMouseActivity(bool shouldRepaint) noexcept
Causes automatic repaints when the mouse enters or exits this component.
bool isMouseOverOrDragging(bool includeChildren=false) const
True if the mouse is over this component, or if it's being dragged in this component.
Component * getParentComponent() const noexcept
Returns the component which this component is inside.
int getHeight() const noexcept
Returns the component's height in pixels.
void setAlwaysOnTop(bool shouldStayOnTop)
Sets whether the component should always be kept at the front of its siblings.
void setMouseCursor(const MouseCursor &cursorType)
Changes the mouse cursor shape to use when the mouse is over this component.
void setBounds(int x, int y, int width, int height)
Changes the component's position and size.
Colour findColour(int colourID, bool inheritFromParent=false) const
Looks for a colour that has been registered with the given colour ID number.
int getWidth() const noexcept
Returns the component's width in pixels.
Rectangle< int > getLocalBounds() const noexcept
Returns the component's bounds, relative to its own origin.
int getParentWidth() const noexcept
Returns the width of the component's parent.
int getParentHeight() const noexcept
Returns the height of the component's parent.
Enables drag-and-drop behaviour for a component and all its sub-components.
static DragAndDropContainer * findParentDragContainerFor(Component *childComponent)
Utility to find the DragAndDropContainer for a given Component.
A graphics context, used for drawing a component or image.
void drawRect(int x, int y, int width, int height, int lineThickness=1) const
Draws a rectangular outline, using the current colour or brush.
void setColour(Colour newColour)
Changes the current drawing colour.
@ DraggingHandCursor
An open flat hand for dragging heavy objects around.
Contains position and status information about a mouse event.
MouseInputSource source
The source device that generated this event.
const int x
The x-position of the mouse when the event occurred.
bool mouseWasDraggedSinceMouseDown() const noexcept
Returns true if the user seems to be performing a drag gesture.
const int y
The y-position of the mouse when the event occurred.
An image that will be resampled before it is drawn.
A component that can be used as one of the items in a Toolbar.
@ editableOnToolbar
Means that the component is on a toolbar, but the toolbar is in customisation mode,...
A toolbar component.
@ editingModeOutlineColourId
A colour to use for an outline around buttons when the customisation dialog is active and the mouse m...
void parentSizeChanged() override
Called when this component's immediate parent has been resized.
void mouseUp(const MouseEvent &) override
Called when a mouse button is released.
void mouseDrag(const MouseEvent &e) override
Called when the mouse is moved while a button is held down.
void paint(Graphics &g) override
Components can override this method to draw their content.
void mouseDown(const MouseEvent &e) override
Called when a mouse button is pressed.
#define JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(className)
This is a shorthand way of writing both a JUCE_DECLARE_NON_COPYABLE and JUCE_LEAK_DETECTOR macro for ...
constexpr Type jmin(Type a, Type b)
Returns the smaller of two values.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
Definition juce_Memory.h:88