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_ToolbarItemComponent.cpp
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
27{
28
29ToolbarItemFactory::ToolbarItemFactory() {}
31
32//==============================================================================
34 const String& labelText,
35 const bool isBeingUsedAsAButton_)
36 : Button (labelText),
37 itemId (itemId_),
38 mode (normalMode),
39 toolbarStyle (Toolbar::iconsOnly),
40 dragOffsetX (0),
41 dragOffsetY (0),
42 isActive (true),
43 isBeingDragged (false),
44 isBeingUsedAsAButton (isBeingUsedAsAButton_)
45{
46 // Your item ID can't be 0!
47 jassert (itemId_ != 0);
48}
49
51{
52 overlayComp.reset();
53}
54
56{
57 return dynamic_cast<Toolbar*> (getParentComponent());
58}
59
61{
62 const Toolbar* const t = getToolbar();
63 return t != nullptr && t->isVertical();
64}
65
67{
68 if (toolbarStyle != newStyle)
69 {
70 toolbarStyle = newStyle;
71 repaint();
72 resized();
73 }
74}
75
76void ToolbarItemComponent::paintButton (Graphics& g, const bool over, const bool down)
77{
78 if (isBeingUsedAsAButton)
79 getLookAndFeel().paintToolbarButtonBackground (g, getWidth(), getHeight(),
80 over, down, *this);
81
82 if (toolbarStyle != Toolbar::iconsOnly)
83 {
84 auto indent = contentArea.getX();
85 auto y = indent;
86 auto h = getHeight() - indent * 2;
87
88 if (toolbarStyle == Toolbar::iconsWithText)
89 {
90 y = contentArea.getBottom() + indent / 2;
91 h -= contentArea.getHeight();
92 }
93
94 getLookAndFeel().paintToolbarButtonLabel (g, indent, y, getWidth() - indent * 2, h,
95 getButtonText(), *this);
96 }
97
98 if (! contentArea.isEmpty())
99 {
101
102 g.reduceClipRegion (contentArea);
103 g.setOrigin (contentArea.getPosition());
104
105 paintButtonArea (g, contentArea.getWidth(), contentArea.getHeight(), over, down);
106 }
107}
108
110{
111 if (toolbarStyle != Toolbar::textOnly)
112 {
113 const int indent = jmin (proportionOfWidth (0.08f),
114 proportionOfHeight (0.08f));
115
116 contentArea = Rectangle<int> (indent, indent,
117 getWidth() - indent * 2,
118 toolbarStyle == Toolbar::iconsWithText ? proportionOfHeight (0.55f)
119 : (getHeight() - indent * 2));
120 }
121 else
122 {
123 contentArea = {};
124 }
125
126 contentAreaChanged (contentArea);
127}
128
130{
131 if (mode != newMode)
132 {
133 mode = newMode;
134 repaint();
135
136 if (mode == normalMode)
137 {
138 overlayComp.reset();
139 }
140 else if (overlayComp == nullptr)
141 {
142 overlayComp.reset (new detail::ToolbarItemDragAndDropOverlayComponent());
143 addAndMakeVisible (overlayComp.get());
144 overlayComp->parentSizeChanged();
145 }
146
147 resized();
148 }
149}
150
151//==============================================================================
153{
157
160
161 return std::make_unique<detail::ButtonAccessibilityHandler> (*this, AccessibilityRole::button);
162}
163
164} // namespace juce
A base class for buttons.
Definition juce_Button.h:43
const String & getButtonText() const
Returns the text displayed in the button.
Definition juce_Button.h:67
int proportionOfWidth(float proportion) const noexcept
Returns a proportion of the component's width.
Component * getParentComponent() const noexcept
Returns the component which this component is inside.
int proportionOfHeight(float proportion) const noexcept
Returns a proportion of the component's height.
int getHeight() const noexcept
Returns the component's height in pixels.
void addAndMakeVisible(Component *child, int zOrder=-1)
Adds a child component to this one, and also makes the child visible if it isn't already.
void repaint()
Marks the whole component as needing to be redrawn.
int getWidth() const noexcept
Returns the component's width in pixels.
LookAndFeel & getLookAndFeel() const noexcept
Finds the appropriate look-and-feel to use for this component.
Uses RAII to save and restore the state of a graphics context.
A graphics context, used for drawing a component or image.
bool reduceClipRegion(int x, int y, int width, int height)
Intersects the current clipping region with another region.
void setOrigin(Point< int > newOrigin)
Moves the position of the context's origin.
Manages a rectangle and allows geometric operations to be performed on it.
ValueType getX() const noexcept
Returns the x coordinate of the rectangle's left-hand-side.
Point< ValueType > getPosition() const noexcept
Returns the rectangle's top-left position as a Point.
ValueType getBottom() const noexcept
Returns the y coordinate of the rectangle's bottom edge.
ValueType getWidth() const noexcept
Returns the width of the rectangle.
bool isEmpty() const noexcept
Returns true if the rectangle's width or height are zero or less.
ValueType getHeight() const noexcept
Returns the height of the rectangle.
The JUCE String class!
Definition juce_String.h:53
virtual void contentAreaChanged(const Rectangle< int > &newBounds)=0
Callback to indicate that the content area of this item has changed.
Toolbar * getToolbar() const
Returns the toolbar that contains this component, or nullptr if it's not currently inside one.
~ToolbarItemComponent() override
Destructor.
@ normalMode
Means that the component is active, inside a toolbar.
virtual void paintButtonArea(Graphics &g, int width, int height, bool isMouseOver, bool isMouseDown)=0
Your subclass should use this method to draw its content area.
void setEditingMode(ToolbarEditingMode newMode)
Changes the editing mode of this component.
void paintButton(Graphics &, bool isMouseOver, bool isMouseDown) override
Subclasses should override this to actually paint the button's contents.
std::unique_ptr< AccessibilityHandler > createAccessibilityHandler() override
Override this method to return a custom AccessibilityHandler for this component.
ToolbarItemComponent(int itemId, const String &labelText, bool isBeingUsedAsAButton)
Constructor.
virtual void setStyle(const Toolbar::ToolbarItemStyle &newStyle)
Changes the current style setting of this item.
bool isToolbarVertical() const
Returns true if this component is currently inside a toolbar which is vertical.
void resized() override
Called when this component's size has been changed.
@ flexibleSpacerId
The item ID for a gap that pushes outwards against the things on either side of it,...
@ separatorBarId
The item ID for a vertical (or horizontal) separator bar that can be placed between sets of items to ...
@ spacerId
The item ID for a fixed-width space that can be placed between items.
A toolbar component.
ToolbarItemStyle
Options for the way items should be displayed.
@ textOnly
Means that the toolbar only display text labels for each item.
@ iconsWithText
Means that the toolbar should have text labels under each icon.
@ iconsOnly
Means that the toolbar should just contain icons.
bool isVertical() const noexcept
Returns true if the bar is set to be vertical, or false if it's horizontal.
#define jassert(expression)
Platform-independent assertion macro.
JUCE Namespace.
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