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_Button.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
27{
28
29//==============================================================================
41class JUCE_API Button : public Component,
43{
44protected:
45 //==============================================================================
52 explicit Button (const String& buttonName);
53
54public:
56 ~Button() override;
57
58 //==============================================================================
62 void setButtonText (const String& newText);
63
67 const String& getButtonText() const { return text; }
68
69 //==============================================================================
73 bool isDown() const noexcept;
74
79 bool isOver() const noexcept;
80
81 //==============================================================================
94 void setToggleable (bool shouldBeToggleable);
95
100 bool isToggleable() const noexcept { return canBeToggled || clickTogglesState; }
101
117 void setToggleState (bool shouldBeOn, NotificationType notification);
118
127 bool getToggleState() const noexcept { return isOn.getValue(); }
128
137 Value& getToggleStateValue() noexcept { return isOn; }
138
147 void setClickingTogglesState (bool shouldAutoToggleOnClick) noexcept;
148
152 bool getClickingTogglesState() const noexcept { return clickTogglesState; }
153
154 //==============================================================================
175 void setRadioGroupId (int newGroupId, NotificationType notification = sendNotification);
176
180 int getRadioGroupId() const noexcept { return radioGroupId; }
181
182 //==============================================================================
188 class JUCE_API Listener
189 {
190 public:
192 virtual ~Listener() = default;
193
195 virtual void buttonClicked (Button*) = 0;
196
198 virtual void buttonStateChanged (Button*) {}
199 };
200
205 void addListener (Listener* newListener);
206
210 void removeListener (Listener* listener);
211
212 //==============================================================================
215
218
219 //==============================================================================
227 virtual void triggerClick();
228
229 //==============================================================================
244 void setCommandToTrigger (ApplicationCommandManager* commandManagerToUse,
245 CommandID commandID,
246 bool generateTooltip);
247
249 CommandID getCommandID() const noexcept { return commandID; }
250
251 //==============================================================================
261 void addShortcut (const KeyPress&);
262
266 void clearShortcuts();
267
271 bool isRegisteredForShortcut (const KeyPress&) const;
272
273 //==============================================================================
287 void setRepeatSpeed (int initialDelayInMillisecs,
288 int repeatDelayInMillisecs,
289 int minimumDelayInMillisecs = -1) noexcept;
290
300 void setTriggeredOnMouseDown (bool isTriggeredOnMouseDown) noexcept;
301
305 bool getTriggeredOnMouseDown() const noexcept;
306
310 uint32 getMillisecondsSinceButtonDown() const noexcept;
311
312 //==============================================================================
316 void setTooltip (const String& newTooltip) override;
317
318 //==============================================================================
321 {
322 ConnectedOnLeft = 1,
323 ConnectedOnRight = 2,
324 ConnectedOnTop = 4,
325 ConnectedOnBottom = 8
326 };
327
339 void setConnectedEdges (int connectedEdgeFlags);
340
342 int getConnectedEdgeFlags() const noexcept { return connectedEdgeFlags; }
343
347 bool isConnectedOnLeft() const noexcept { return (connectedEdgeFlags & ConnectedOnLeft) != 0; }
348
352 bool isConnectedOnRight() const noexcept { return (connectedEdgeFlags & ConnectedOnRight) != 0; }
353
357 bool isConnectedOnTop() const noexcept { return (connectedEdgeFlags & ConnectedOnTop) != 0; }
358
362 bool isConnectedOnBottom() const noexcept { return (connectedEdgeFlags & ConnectedOnBottom) != 0; }
363
364
365 //==============================================================================
368 {
369 buttonNormal,
370 buttonOver,
371 buttonDown
372 };
373
382 void setState (ButtonState newState);
383
385 ButtonState getState() const noexcept { return buttonState; }
386
387 //==============================================================================
391 struct JUCE_API LookAndFeelMethods
392 {
393 virtual ~LookAndFeelMethods() = default;
394
395 virtual void drawButtonBackground (Graphics&, Button&, const Colour& backgroundColour,
396 bool shouldDrawButtonAsHighlighted, bool shouldDrawButtonAsDown) = 0;
397
398 virtual Font getTextButtonFont (TextButton&, int buttonHeight) = 0;
399 virtual int getTextButtonWidthToFitText (TextButton&, int buttonHeight) = 0;
400
403 bool shouldDrawButtonAsHighlighted, bool shouldDrawButtonAsDown) = 0;
404
407 bool shouldDrawButtonAsHighlighted, bool shouldDrawButtonAsDown) = 0;
408
409 virtual void changeToggleButtonWidthToFitText (ToggleButton&) = 0;
410
411 virtual void drawTickBox (Graphics&, Component&, float x, float y, float w, float h,
412 bool ticked, bool isEnabled,
413 bool shouldDrawButtonAsHighlighted, bool shouldDrawButtonAsDown) = 0;
414
415 virtual void drawDrawableButton (Graphics&, DrawableButton&,
416 bool shouldDrawButtonAsHighlighted, bool shouldDrawButtonAsDown) = 0;
417 };
418
419 //==============================================================================
420 #ifndef DOXYGEN
421 [[deprecated ("This method's parameters have changed.")]]
422 void setToggleState (bool, bool);
423 #endif
424
425protected:
426 //==============================================================================
434 virtual void clicked();
435
443 virtual void clicked (const ModifierKeys& modifiers);
444
454 virtual void paintButton (Graphics& g,
455 bool shouldDrawButtonAsHighlighted,
456 bool shouldDrawButtonAsDown) = 0;
457
465 virtual void buttonStateChanged();
466
467 //==============================================================================
469 virtual void internalClickCallback (const ModifierKeys&);
471 void handleCommandMessage (int commandId) override;
473 void mouseEnter (const MouseEvent&) override;
475 void mouseExit (const MouseEvent&) override;
477 void mouseDown (const MouseEvent&) override;
479 void mouseDrag (const MouseEvent&) override;
481 void mouseUp (const MouseEvent&) override;
483 bool keyPressed (const KeyPress&) override;
485 using Component::keyStateChanged;
487 void paint (Graphics&) override;
489 void parentHierarchyChanged() override;
491 void visibilityChanged() override;
493 void focusGained (FocusChangeType) override;
495 void focusLost (FocusChangeType) override;
497 void enablementChanged() override;
499 std::unique_ptr<AccessibilityHandler> createAccessibilityHandler() override;
500
501private:
502 //==============================================================================
503 Array<KeyPress> shortcuts;
504 WeakReference<Component> keySource;
505 String text;
506 ListenerList<Listener> buttonListeners;
507
508 struct CallbackHelper;
509 std::unique_ptr<CallbackHelper> callbackHelper;
510 uint32 buttonPressTime = 0, lastRepeatTime = 0;
511 ApplicationCommandManager* commandManagerToUse = nullptr;
512 int autoRepeatDelay = -1, autoRepeatSpeed = 0, autoRepeatMinimumDelay = -1;
513 int radioGroupId = 0, connectedEdgeFlags = 0;
514 CommandID commandID = {};
515 ButtonState buttonState = buttonNormal, lastStatePainted = buttonNormal;
516
517 Value isOn;
518 bool canBeToggled = false;
519 bool lastToggleState = false;
520 bool clickTogglesState = false;
521 bool needsToRelease = false;
522 bool needsRepainting = false;
523 bool isKeyDown = false;
524 bool triggerOnMouseDown = false;
525 bool generateTooltip = false;
526
527 void checkToggleableState (bool wasToggleable);
528
529 void repeatTimerCallback();
530 bool keyStateChangedCallback();
531 void applicationCommandListChangeCallback();
532 void updateAutomaticTooltip (const ApplicationCommandInfo&);
533
534 ButtonState updateState();
535 ButtonState updateState (bool isOver, bool isDown);
536 bool isShortcutPressed() const;
537 void turnOffOtherButtonsInGroup (NotificationType click, NotificationType state);
538
539 void flashButtonState();
540 void sendClickMessage (const ModifierKeys&);
541 void sendStateMessage();
542 void setToggleState (bool shouldBeOn, NotificationType click, NotificationType state);
543
544 bool isMouseSourceOver (const MouseEvent& e);
545
547};
548
549
550} // namespace juce
One of these objects holds a list of all the commands your app can perform, and despatches these comm...
Holds a resizable array of primitive or copy-by-value objects.
Definition juce_Array.h:56
Used to receive callbacks when a button is clicked.
virtual ~Listener()=default
Destructor.
virtual void buttonClicked(Button *)=0
Called when the button is clicked.
virtual void buttonStateChanged(Button *)
Called when the button's state changes.
A base class for buttons.
Definition juce_Button.h:43
ButtonState getState() const noexcept
Returns the button's current over/down/up state.
bool isConnectedOnBottom() const noexcept
Indicates whether the button adjoins another one on its bottom edge.
bool getToggleState() const noexcept
Returns true if the button is 'on'.
bool isConnectedOnTop() const noexcept
Indicates whether the button adjoins another one on its top edge.
bool getClickingTogglesState() const noexcept
Returns true if this button is set to be an automatic toggle-button.
std::function< void()> onClick
You can assign a lambda to this callback object to have it called when the button is clicked.
const String & getButtonText() const
Returns the text displayed in the button.
Definition juce_Button.h:67
int getConnectedEdgeFlags() const noexcept
Returns the set of flags passed into setConnectedEdges().
ConnectedEdgeFlags
A combination of these flags are used by setConnectedEdges().
int getRadioGroupId() const noexcept
Returns the ID of the group to which this button belongs.
bool isConnectedOnLeft() const noexcept
Indicates whether the button adjoins another one on its left edge.
virtual void paintButton(Graphics &g, bool shouldDrawButtonAsHighlighted, bool shouldDrawButtonAsDown)=0
Subclasses should override this to actually paint the button's contents.
bool isConnectedOnRight() const noexcept
Indicates whether the button adjoins another one on its right edge.
std::function< void()> onStateChange
You can assign a lambda to this callback object to have it called when the button's state changes.
ButtonState
Used by setState().
CommandID getCommandID() const noexcept
Returns the command ID that was set by setCommandToTrigger().
Value & getToggleStateValue() noexcept
Returns the Value object that represents the button's toggle state.
Represents a colour, also including a transparency value.
Definition juce_Colour.h:38
The base class for all JUCE user-interface objects.
FocusChangeType
Enumeration used by the focusGained() and focusLost() methods.
A button that displays a Drawable.
Represents a particular font, including its size, style, etc.
Definition juce_Font.h:42
A graphics context, used for drawing a component or image.
Represents a key press, including any modifier keys that are needed.
Holds a set of objects and can invoke a member function callback on each object in the set with a sin...
Represents the state of the mouse buttons and modifier keys.
Contains position and status information about a mouse event.
An implementation of TooltipClient that stores the tooltip string and a method for changing it.
The JUCE String class!
Definition juce_String.h:53
A button that uses the standard lozenge-shaped background with a line of text on it.
A button that can be toggled on/off.
Represents a shared variant value.
Definition juce_Value.h:51
This class acts as a pointer which will automatically become null if the object to which it points is...
#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 ...
JUCE Namespace.
NotificationType
These enums are used in various classes to indicate whether a notification event should be sent out.
unsigned int uint32
A platform-independent 32-bit unsigned integer type.
int CommandID
A type used to hold the unique ID for an application command.
Holds information describing an application command.
This abstract base class is implemented by LookAndFeel classes to provide button-drawing functionalit...
virtual void drawButtonText(Graphics &, TextButton &, bool shouldDrawButtonAsHighlighted, bool shouldDrawButtonAsDown)=0
Draws the text for a TextButton.
virtual void drawToggleButton(Graphics &, ToggleButton &, bool shouldDrawButtonAsHighlighted, bool shouldDrawButtonAsDown)=0
Draws the contents of a standard ToggleButton.