A component for showing a message or other graphics inside a speech-bubble-shaped outline, pointing at a location on the screen. More...
Inherits Component.
Inherited by BubbleMessageComponent.
Public Types | |
| enum | BubblePlacement { above = 1, below = 2, left = 4, right = 8 } |
A list of permitted placements for the bubble, relative to the co-ordinates at which it should be pointing. More... | |
Public Member Functions | |
| ~BubbleComponent () | |
| Destructor. | |
| void | setAllowedPlacement (int newPlacement) |
| Tells the bubble which positions it's allowed to put itself in, relative to the point at which it's pointing. | |
| void | setPosition (Component *componentToPointTo) |
| Moves and resizes the bubble to point at a given component. | |
| void | setPosition (int arrowTipX, int arrowTipY) |
| Moves and resizes the bubble to point at a given point. | |
| void | setPosition (const Rectangle< int > &rectangleToPointTo) |
| Moves and resizes the bubble to point at a given rectangle. | |
| void | paint (Graphics &g) |
| Components can override this method to draw their content. | |
Protected Member Functions | |
| BubbleComponent () | |
| Creates a BubbleComponent. | |
| virtual void | getContentSize (int &width, int &height)=0 |
| Subclasses should override this to return the size of the content they want to draw inside the bubble. | |
| virtual void | paintContent (Graphics &g, int width, int height)=0 |
| Subclasses should override this to draw their bubble's contents. | |
A component for showing a message or other graphics inside a speech-bubble-shaped outline, pointing at a location on the screen.
This is a base class that just draws and positions the bubble shape, but leaves the drawing of any content up to a subclass. See BubbleMessageComponent for a subclass that draws a text message.
To use it, create your subclass, then either add it to a parent component or put it on the desktop with addToDesktop (0), use setPosition() to resize and position it, then make it visible.
A list of permitted placements for the bubble, relative to the co-ordinates at which it should be pointing.
| BubbleComponent::BubbleComponent | ( | ) | [protected] |
Creates a BubbleComponent.
Your subclass will need to implement the getContentSize() and paintContent() methods to draw the bubble's contents.
| BubbleComponent::~BubbleComponent | ( | ) |
Destructor.
| void BubbleComponent::setAllowedPlacement | ( | int | newPlacement ) |
Tells the bubble which positions it's allowed to put itself in, relative to the point at which it's pointing.
By default when setPosition() is called, the bubble will place itself either above, below, left, or right of the target area. You can pass in a bitwise-'or' of the values in BubblePlacement to restrict this choice.
E.g. if you only want your bubble to appear above or below the target area, use setAllowedPlacement (above | below);
| void BubbleComponent::setPosition | ( | Component * | componentToPointTo ) |
Moves and resizes the bubble to point at a given component.
This will resize the bubble to fit its content, then find a position for it so that it's next to, but doesn't overlap the given component.
It'll put itself either above, below, or to the side of the component depending on where there's the most space, honouring any restrictions that were set with setAllowedPlacement().
| void BubbleComponent::setPosition | ( | int | arrowTipX, |
| int | arrowTipY | ||
| ) |
Moves and resizes the bubble to point at a given point.
This will resize the bubble to fit its content, then position it so that the tip of the bubble points to the given co-ordinate. The co-ordinates are relative to either the bubble component's parent component if it has one, or they are screen co-ordinates if not.
It'll put itself either above, below, or to the side of this point, depending on where there's the most space, honouring any restrictions that were set with setAllowedPlacement().
| void BubbleComponent::setPosition | ( | const Rectangle< int > & | rectangleToPointTo ) |
Moves and resizes the bubble to point at a given rectangle.
This will resize the bubble to fit its content, then find a position for it so that it's next to, but doesn't overlap the given rectangle. The rectangle's co-ordinates are relative to either the bubble component's parent component if it has one, or they are screen co-ordinates if not.
It'll put itself either above, below, or to the side of the component depending on where there's the most space, honouring any restrictions that were set with setAllowedPlacement().
| virtual void BubbleComponent::getContentSize | ( | int & | width, |
| int & | height | ||
| ) | [protected, pure virtual] |
Subclasses should override this to return the size of the content they want to draw inside the bubble.
Implemented in BubbleMessageComponent.
| virtual void BubbleComponent::paintContent | ( | Graphics & | g, |
| int | width, | ||
| int | height | ||
| ) | [protected, pure virtual] |
Subclasses should override this to draw their bubble's contents.
The graphics object's clip region and the dimensions passed in here are set up to paint just the rectangle inside the bubble.
Implemented in BubbleMessageComponent.
| void BubbleComponent::paint | ( | Graphics & | g ) | [virtual] |
Components can override this method to draw their content.
The paint() method gets called when a region of a component needs redrawing, either because the component's repaint() method has been called, or because something has happened on the screen that means a section of a window needs to be redrawn.
Any child components will draw themselves over whatever this method draws. If you need to paint over the top of your child components, you can also implement the paintOverChildren() method to do this.
If you want to cause a component to redraw itself, this is done asynchronously - calling the repaint() method marks a region of the component as "dirty", and the paint() method will automatically be called sometime later, by the message thread, to paint any bits that need refreshing. In Juce (and almost all modern UI frameworks), you never redraw something synchronously.
You should never need to call this method directly - to take a snapshot of the component you could use createComponentSnapshot() or paintEntireComponent().
| g | the graphics context that must be used to do the drawing operations. |
Reimplemented from Component.