1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

Minor clean-ups around the Justification class.

This commit is contained in:
jules 2013-08-20 17:27:41 +01:00
parent 14b5857440
commit 45b56e2e20
11 changed files with 57 additions and 102 deletions

View file

@ -231,13 +231,13 @@ private:
{
}
void setJustification (const Justification& newJustification)
void setJustification (Justification newJustification)
{
document.perform (new ComboJustifyChangeAction (component, *document.getComponentLayout(), newJustification),
"Change combo box justification");
}
const Justification getJustification() const { return component->getJustificationType(); }
Justification getJustification() const { return component->getJustificationType(); }
private:
ComboBox* const component;
@ -246,7 +246,7 @@ private:
class ComboJustifyChangeAction : public ComponentUndoableAction <ComboBox>
{
public:
ComboJustifyChangeAction (ComboBox* const comp, ComponentLayout& layout, const Justification& newState_)
ComboJustifyChangeAction (ComboBox* const comp, ComponentLayout& layout, Justification newState_)
: ComponentUndoableAction <ComboBox> (comp, layout),
newState (newState_),
oldState (comp->getJustificationType())

View file

@ -176,13 +176,13 @@ private:
document.removeChangeListener (this);
}
void setJustification (const Justification& newJustification)
void setJustification (Justification newJustification)
{
document.perform (new GroupJustifyChangeAction (group, *document.getComponentLayout(), newJustification),
"Change text label position");
}
const Justification getJustification() const
Justification getJustification() const
{
return group->getTextLabelPosition();
}
@ -196,7 +196,7 @@ private:
class GroupJustifyChangeAction : public ComponentUndoableAction <GroupComponent>
{
public:
GroupJustifyChangeAction (GroupComponent* const comp, ComponentLayout& layout, const Justification& newState_)
GroupJustifyChangeAction (GroupComponent* const comp, ComponentLayout& layout, Justification newState_)
: ComponentUndoableAction <GroupComponent> (comp, layout),
newState (newState_),
oldState (comp->getTextLabelPosition())

View file

@ -370,13 +370,13 @@ private:
document.removeChangeListener (this);
}
void setJustification (const Justification& newJustification)
void setJustification (Justification newJustification)
{
document.perform (new LabelJustifyChangeAction (label, *document.getComponentLayout(), newJustification),
"Change Label justification");
}
const Justification getJustification() const
Justification getJustification() const
{
return label->getJustificationType();
}
@ -390,7 +390,7 @@ private:
class LabelJustifyChangeAction : public ComponentUndoableAction <Label>
{
public:
LabelJustifyChangeAction (Label* const comp, ComponentLayout& layout, const Justification& newState_)
LabelJustifyChangeAction (Label* const comp, ComponentLayout& layout, Justification newState_)
: ComponentUndoableAction <Label> (comp, layout),
newState (newState_),
oldState (comp->getJustificationType())

View file

@ -279,15 +279,15 @@ public:
}
}
String getTypefaceName() const noexcept { return typefaceName; }
String getTypefaceName() const noexcept { return typefaceName; }
//==============================================================================
const Justification& getJustification() const noexcept { return justification; }
Justification getJustification() const noexcept { return justification; }
class SetJustifyAction : public PaintElementUndoableAction <PaintElementText>
{
public:
SetJustifyAction (PaintElementText* const element, const Justification& newValue_)
SetJustifyAction (PaintElementText* const element, Justification newValue_)
: PaintElementUndoableAction <PaintElementText> (element),
newValue (newValue_),
oldValue (element->getJustification())
@ -312,7 +312,7 @@ public:
Justification newValue, oldValue;
};
void setJustification (const Justification& j, const bool undoable)
void setJustification (Justification j, const bool undoable)
{
if (justification.getFlags() != j.getFlags())
{
@ -516,12 +516,12 @@ private:
element->getDocument()->removeChangeListener (this);
}
void setJustification (const Justification& newJustification)
void setJustification (Justification newJustification)
{
element->setJustification (newJustification, true);
}
const Justification getJustification() const
Justification getJustification() const
{
return element->getJustification();
}

View file

@ -53,9 +53,8 @@ public:
}
//==============================================================================
virtual void setJustification (const Justification& newJustification) = 0;
virtual const Justification getJustification() const = 0;
virtual void setJustification (Justification newJustification) = 0;
virtual Justification getJustification() const = 0;
//==============================================================================
void setIndex (int newIndex)

View file

@ -262,7 +262,7 @@ void GlyphArrangement::addJustifiedText (const Font& font,
const String& text,
float x, float y,
const float maxLineWidth,
const Justification& horizontalLayout)
Justification horizontalLayout)
{
int lineStartIndex = glyphs.size();
addLineOfText (font, text, x, y);
@ -344,7 +344,7 @@ void GlyphArrangement::addFittedText (const Font& f,
const String& text,
const float x, const float y,
const float width, const float height,
const Justification& layout,
Justification layout,
int maximumLines,
const float minimumHorizontalScale)
{
@ -541,7 +541,7 @@ void GlyphArrangement::moveRangeOfGlyphs (int startIndex, int num, const float d
}
int GlyphArrangement::fitLineIntoSpace (int start, int numGlyphs, float x, float y, float w, float h, const Font& font,
const Justification& justification, float minimumHorizontalScale)
Justification justification, float minimumHorizontalScale)
{
int numDeleted = 0;
const float lineStartX = glyphs.getReference (start).getLeft();
@ -611,7 +611,7 @@ Rectangle<float> GlyphArrangement::getBoundingBox (int startIndex, int num, cons
void GlyphArrangement::justifyGlyphs (const int startIndex, const int num,
const float x, const float y, const float width, const float height,
const Justification& justification)
Justification justification)
{
jassert (num >= 0 && startIndex >= 0);

View file

@ -120,12 +120,12 @@ public:
GlyphArrangement();
/** Takes a copy of another arrangement. */
GlyphArrangement (const GlyphArrangement& other);
GlyphArrangement (const GlyphArrangement&);
/** Copies another arrangement onto this one.
To add another arrangement without clearing this one, use addGlyphArrangement().
*/
GlyphArrangement& operator= (const GlyphArrangement& other);
GlyphArrangement& operator= (const GlyphArrangement&);
/** Destructor. */
~GlyphArrangement();
@ -143,8 +143,7 @@ public:
PositionedGlyph& getGlyph (int index) const noexcept;
//==============================================================================
/** Clears all text from the arrangement and resets it.
*/
/** Clears all text from the arrangement and resets it. */
void clear();
/** Appends a line of text to the arrangement.
@ -188,7 +187,7 @@ public:
const String& text,
float x, float y,
float maxLineWidth,
const Justification& horizontalLayout);
Justification horizontalLayout);
/** Tries to fit some text withing a given space.
@ -208,7 +207,7 @@ public:
void addFittedText (const Font& font,
const String& text,
float x, float y, float width, float height,
const Justification& layout,
Justification layout,
int maximumLinesToUse,
float minimumHorizontalScale = 0.7f);
@ -224,23 +223,21 @@ public:
This uses cached bitmaps so is much faster than the draw (Graphics&, const AffineTransform&)
method, which renders the glyphs as filled vectors.
*/
void draw (const Graphics& g) const;
void draw (const Graphics&) const;
/** Draws this glyph arrangement to a graphics context.
This renders the paths as filled vectors, so is far slower than the draw (Graphics&)
method for non-transformed arrangements.
*/
void draw (const Graphics& g, const AffineTransform& transform) const;
void draw (const Graphics&, const AffineTransform&) const;
/** Converts the set of glyphs into a path.
@param path the glyphs' outlines will be appended to this path
*/
void createPath (Path& path) const;
/** Looks for a glyph that contains the given coordinate.
@returns the index of the glyph, or -1 if none were found.
*/
int findGlyphIndexAt (float x, float y) const;
@ -296,7 +293,7 @@ public:
*/
void justifyGlyphs (int startIndex, int numGlyphs,
float x, float y, float width, float height,
const Justification& justification);
Justification justification);
private:
@ -305,7 +302,7 @@ private:
int insertEllipsis (const Font&, float maxXPos, int startIndex, int endIndex);
int fitLineIntoSpace (int start, int numGlyphs, float x, float y, float w, float h, const Font&,
const Justification&, float minimumHorizontalScale);
Justification, float minimumHorizontalScale);
void spreadOutLine (int start, int numGlyphs, float targetWidth);
void drawGlyphUnderline (const Graphics&, const PositionedGlyph&, int, const AffineTransform&) const;

View file

@ -105,7 +105,6 @@ namespace juce
#include "geometry/juce_Path.cpp"
#include "geometry/juce_PathIterator.cpp"
#include "geometry/juce_PathStrokeType.cpp"
#include "placement/juce_Justification.cpp"
#include "placement/juce_RectanglePlacement.cpp"
#include "contexts/juce_GraphicsContext.cpp"
#include "contexts/juce_LowLevelGraphicsPostScriptRenderer.cpp"

View file

@ -1,44 +0,0 @@
/*
==============================================================================
This file is part of the JUCE library.
Copyright (c) 2013 - Raw Material Software Ltd.
Permission is granted to use this software under the terms of either:
a) the GPL v2 (or any later version)
b) the Affero GPL v3
Details of these licenses can be found at: www.gnu.org/licenses
JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
------------------------------------------------------------------------------
To release a closed-source product which uses JUCE, commercial licenses are
available: visit www.juce.com for more information.
==============================================================================
*/
Justification::Justification (const Justification& other) noexcept
: flags (other.flags)
{
}
Justification& Justification::operator= (const Justification& other) noexcept
{
flags = other.flags;
return *this;
}
int Justification::getOnlyVerticalFlags() const noexcept
{
return flags & (top | bottom | verticallyCentred);
}
int Justification::getOnlyHorizontalFlags() const noexcept
{
return flags & (left | right | horizontallyCentred | horizontallyJustified);
}

View file

@ -37,37 +37,40 @@
It is used in various places wherever this kind of information is needed.
*/
class JUCE_API Justification
class Justification
{
public:
//==============================================================================
/** Creates a Justification object using a combination of flags from the Flags enum. */
inline Justification (int justificationFlags) noexcept : flags (justificationFlags) {}
Justification (int justificationFlags) noexcept : flags (justificationFlags) {}
/** Creates a copy of another Justification object. */
Justification (const Justification& other) noexcept;
Justification (const Justification& other) noexcept : flags (other.flags) {}
/** Copies another Justification object. */
Justification& operator= (const Justification& other) noexcept;
Justification& operator= (const Justification& other) noexcept
{
flags = other.flags;
return *this;
}
bool operator== (const Justification& other) const noexcept { return flags == other.flags; }
bool operator!= (const Justification& other) const noexcept { return flags != other.flags; }
//==============================================================================
/** Returns the raw flags that are set for this Justification object. */
inline int getFlags() const noexcept { return flags; }
inline int getFlags() const noexcept { return flags; }
/** Tests a set of flags for this object.
@returns true if any of the flags passed in are set on this object.
*/
inline bool testFlags (int flagsToTest) const noexcept { return (flags & flagsToTest) != 0; }
inline bool testFlags (int flagsToTest) const noexcept { return (flags & flagsToTest) != 0; }
/** Returns just the flags from this object that deal with vertical layout. */
int getOnlyVerticalFlags() const noexcept;
int getOnlyVerticalFlags() const noexcept { return flags & (top | bottom | verticallyCentred); }
/** Returns just the flags from this object that deal with horizontal layout. */
int getOnlyHorizontalFlags() const noexcept;
int getOnlyHorizontalFlags() const noexcept { return flags & (left | right | horizontallyCentred | horizontallyJustified); }
//==============================================================================
/** Adjusts the position of a rectangle to fit it into a space.

View file

@ -1448,25 +1448,26 @@ int PopupMenu::showWithOptionalCallback (const Options& options, ModalComponentM
ScopedPointer<ModalComponentManager::Callback> userCallbackDeleter (userCallback);
ScopedPointer<PopupMenuCompletionCallback> callback (new PopupMenuCompletionCallback());
Component* window = createWindow (options, &(callback->managerOfChosenCommand));
if (window == nullptr)
return 0;
if (Component* window = createWindow (options, &(callback->managerOfChosenCommand)))
{
callback->component = window;
callback->component = window;
window->setVisible (true); // (must be called before enterModalState on Windows to avoid DropShadower confusion)
window->enterModalState (false, userCallbackDeleter.release());
ModalComponentManager::getInstance()->attachCallback (window, callback.release());
window->setVisible (true); // (must be called before enterModalState on Windows to avoid DropShadower confusion)
window->enterModalState (false, userCallbackDeleter.release());
ModalComponentManager::getInstance()->attachCallback (window, callback.release());
window->toFront (false); // need to do this after making it modal, or it could
// be stuck behind other comps that are already modal..
window->toFront (false); // need to do this after making it modal, or it could
// be stuck behind other comps that are already modal..
#if JUCE_MODAL_LOOPS_PERMITTED
if (userCallback == nullptr && canBeModal)
return window->runModalLoop();
#else
jassert (! (userCallback == nullptr && canBeModal));
#endif
}
#if JUCE_MODAL_LOOPS_PERMITTED
return (userCallback == nullptr && canBeModal) ? window->runModalLoop() : 0;
#else
jassert (! (userCallback == nullptr && canBeModal));
return 0;
#endif
}
//==============================================================================