mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-11 23:54:18 +00:00
Refactoring of some glypharrangement code.
This commit is contained in:
parent
49fd486c23
commit
fc79df875f
8 changed files with 46 additions and 107 deletions
|
|
@ -554,22 +554,25 @@ int IntrojucerLookAndFeel::getTabButtonOverlap (int /*tabDepth*/)
|
|||
int IntrojucerLookAndFeel::getTabButtonSpaceAroundImage() { return 1; }
|
||||
int IntrojucerLookAndFeel::getTabButtonBestWidth (TabBarButton&, int /*tabDepth*/) { return 120; }
|
||||
|
||||
void IntrojucerLookAndFeel::createTabTextLayout (const TabBarButton& button, const Rectangle<int>& textArea, GlyphArrangement& textLayout)
|
||||
static void createTabTextLayout (const TabBarButton& button, const Rectangle<int>& textArea,
|
||||
const Colour colour, TextLayout& textLayout)
|
||||
{
|
||||
Font font (textArea.getHeight() * 0.5f);
|
||||
font.setUnderline (button.hasKeyboardFocus (false));
|
||||
|
||||
textLayout.addFittedText (font, button.getButtonText().trim(),
|
||||
(float) textArea.getX(), (float) textArea.getY(), (float) textArea.getWidth(), (float) textArea.getHeight(),
|
||||
Justification::centred, 1);
|
||||
AttributedString s;
|
||||
s.setJustification (Justification::centred);
|
||||
s.append (button.getButtonText().trim(), font, colour);
|
||||
|
||||
textLayout.createLayout (s, (float) textArea.getWidth());
|
||||
}
|
||||
|
||||
Colour IntrojucerLookAndFeel::getTabBackgroundColour (TabBarButton& button)
|
||||
static Colour getTabBackgroundColour (TabBarButton& button)
|
||||
{
|
||||
const Colour normalBkg (button.findColour (mainBackgroundColourId));
|
||||
Colour bkg (normalBkg.contrasting (0.15f));
|
||||
const Colour bkg (button.findColour (mainBackgroundColourId).contrasting (0.15f));
|
||||
|
||||
if (button.isFrontTab())
|
||||
bkg = bkg.overlaidWith (Colours::yellow.withAlpha (0.5f));
|
||||
return bkg.overlaidWith (Colours::yellow.withAlpha (0.5f));
|
||||
|
||||
return bkg;
|
||||
}
|
||||
|
|
@ -577,7 +580,6 @@ Colour IntrojucerLookAndFeel::getTabBackgroundColour (TabBarButton& button)
|
|||
void IntrojucerLookAndFeel::drawTabButton (TabBarButton& button, Graphics& g, bool isMouseOver, bool isMouseDown)
|
||||
{
|
||||
const Rectangle<int> activeArea (button.getActiveArea());
|
||||
|
||||
const Colour bkg (getTabBackgroundColour (button));
|
||||
|
||||
g.setGradientFill (ColourGradient (bkg.brighter (0.1f), 0, (float) activeArea.getY(),
|
||||
|
|
@ -587,19 +589,20 @@ void IntrojucerLookAndFeel::drawTabButton (TabBarButton& button, Graphics& g, bo
|
|||
g.setColour (button.findColour (mainBackgroundColourId).darker (0.3f));
|
||||
g.drawRect (activeArea);
|
||||
|
||||
GlyphArrangement textLayout;
|
||||
createTabTextLayout (button, button.getTextArea(), textLayout);
|
||||
|
||||
const float alpha = button.isEnabled() ? ((isMouseOver || isMouseDown) ? 1.0f : 0.8f) : 0.3f;
|
||||
g.setColour (bkg.contrasting().withMultipliedAlpha (alpha));
|
||||
textLayout.draw (g);
|
||||
const Colour col (bkg.contrasting().withMultipliedAlpha (alpha));
|
||||
|
||||
TextLayout textLayout;
|
||||
createTabTextLayout (button, button.getTextArea(), col, textLayout);
|
||||
|
||||
textLayout.draw (g, button.getTextArea().toFloat());
|
||||
}
|
||||
|
||||
Rectangle<int> IntrojucerLookAndFeel::getTabButtonExtraComponentBounds (const TabBarButton& button, Rectangle<int>& textArea, Component& comp)
|
||||
{
|
||||
GlyphArrangement textLayout;
|
||||
createTabTextLayout (button, textArea, textLayout);
|
||||
const int textWidth = (int) textLayout.getBoundingBox (0, -1, false).getWidth();
|
||||
TextLayout textLayout;
|
||||
createTabTextLayout (button, textArea, Colours::black, textLayout);
|
||||
const int textWidth = (int) textLayout.getWidth();
|
||||
const int extraSpace = jmax (0, textArea.getWidth() - (textWidth + comp.getWidth())) / 2;
|
||||
|
||||
textArea.removeFromRight (extraSpace);
|
||||
|
|
|
|||
|
|
@ -89,8 +89,6 @@ public:
|
|||
int getTabButtonOverlap (int tabDepth);
|
||||
int getTabButtonSpaceAroundImage();
|
||||
int getTabButtonBestWidth (TabBarButton& button, int tabDepth);
|
||||
static Colour getTabBackgroundColour (TabBarButton& button);
|
||||
void createTabTextLayout (const TabBarButton& button, const Rectangle<int>& textArea, GlyphArrangement& textLayout);
|
||||
void drawTabButton (TabBarButton& button, Graphics& g, bool isMouseOver, bool isMouseDown);
|
||||
|
||||
Rectangle<int> getTabButtonExtraComponentBounds (const TabBarButton& button, Rectangle<int>& textArea, Component& comp);
|
||||
|
|
|
|||
|
|
@ -232,6 +232,7 @@ Result ModuleList::rescan (const File& newModulesFolder)
|
|||
info->version = m.getVersion();
|
||||
info->name = m.moduleInfo ["name"];
|
||||
info->description = m.moduleInfo ["description"];
|
||||
info->license = m.moduleInfo ["license"];
|
||||
info->file = moduleDef;
|
||||
}
|
||||
}
|
||||
|
|
@ -273,6 +274,7 @@ bool ModuleList::loadFromWebsite()
|
|||
info->version = lm.getVersion();
|
||||
info->name = lm.getName();
|
||||
info->description = lm.getDescription();
|
||||
info->license = lm.getLicense();
|
||||
info->url = baseURL.getChildURL (file);
|
||||
}
|
||||
}
|
||||
|
|
@ -294,6 +296,7 @@ bool ModuleList::Module::operator== (const Module& other) const
|
|||
&& version == other.version
|
||||
&& name == other.name
|
||||
&& description == other.description
|
||||
&& license == other.license
|
||||
&& file == other.file
|
||||
&& url == other.url;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,6 +43,7 @@ public:
|
|||
String getVersion() const { return moduleInfo ["version"].toString(); }
|
||||
String getName() const { return moduleInfo ["name"].toString(); }
|
||||
String getDescription() const { return moduleInfo ["description"].toString(); }
|
||||
String getLicense() const { return moduleInfo ["license"].toString(); }
|
||||
const File& getFolder() const { return moduleFolder; }
|
||||
|
||||
void writeIncludes (ProjectSaver&, OutputStream&);
|
||||
|
|
@ -109,7 +110,7 @@ public:
|
|||
{
|
||||
LibraryModule* create() const;
|
||||
|
||||
String uid, version, name, description;
|
||||
String uid, version, name, description, license;
|
||||
File file;
|
||||
URL url;
|
||||
|
||||
|
|
|
|||
|
|
@ -307,14 +307,17 @@ public:
|
|||
|
||||
if (const ModuleList::Module* module = moduleList.findModuleInfo (moduleID))
|
||||
{
|
||||
String text;
|
||||
text << module->name << newLine << "Version: " << module->version << newLine << newLine
|
||||
<< module->description;
|
||||
AttributedString s;
|
||||
s.setJustification (Justification::topLeft);
|
||||
|
||||
GlyphArrangement ga;
|
||||
ga.addJustifiedText (Font (13.0f), text, 4.0f, 16.0f, getWidth() - 8.0f, Justification::topLeft);
|
||||
g.setColour (Colours::black);
|
||||
ga.draw (g);
|
||||
Font f (13.0f);
|
||||
|
||||
s.append (module->name + "\n", f.boldened());
|
||||
s.append ("Version: " + module->version
|
||||
+ " License: " + module->license + "\n", f.italicised());
|
||||
s.append ("\n" + module->description, f);
|
||||
|
||||
s.draw (g, getLocalBounds().reduced (4, 2).toFloat());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -355,10 +358,10 @@ public:
|
|||
String text ("This module requires the following dependencies:\n");
|
||||
text << missingDependencies.joinIntoString (", ");
|
||||
|
||||
GlyphArrangement ga;
|
||||
ga.addJustifiedText (Font (13.0f), text, 4.0f, 16.0f, getWidth() - 8.0f, Justification::topLeft);
|
||||
g.setColour (Colours::red);
|
||||
ga.draw (g);
|
||||
AttributedString s;
|
||||
s.setJustification (Justification::topLeft);
|
||||
s.append (text, Font (13.0f), Colours::red);
|
||||
s.draw (g, getLocalBounds().reduced (4, 16).toFloat());
|
||||
}
|
||||
|
||||
void buttonClicked (Button*)
|
||||
|
|
|
|||
|
|
@ -296,57 +296,6 @@ String RolloverHelpComp::findTip (Component* c)
|
|||
return String::empty;
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
FloatingLabelComponent::FloatingLabelComponent()
|
||||
: font (10.0f)
|
||||
{
|
||||
setInterceptsMouseClicks (false, false);
|
||||
}
|
||||
|
||||
void FloatingLabelComponent::remove()
|
||||
{
|
||||
if (Component* p = getParentComponent())
|
||||
p->removeChildComponent (this);
|
||||
}
|
||||
|
||||
void FloatingLabelComponent::update (Component* parent, const String& text, const Colour& textColour,
|
||||
int x, int y, bool toRight, bool below)
|
||||
{
|
||||
colour = textColour;
|
||||
|
||||
Rectangle<int> r;
|
||||
|
||||
if (text != getName())
|
||||
{
|
||||
setName (text);
|
||||
glyphs.clear();
|
||||
glyphs.addJustifiedText (font, text, 0, 0, 200.0f, Justification::left);
|
||||
glyphs.justifyGlyphs (0, std::numeric_limits<int>::max(), 0, 0, 1000, 1000, Justification::topLeft);
|
||||
|
||||
r = glyphs.getBoundingBox (0, std::numeric_limits<int>::max(), false)
|
||||
.getSmallestIntegerContainer().expanded (1, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
r = getLocalBounds();
|
||||
}
|
||||
|
||||
r.setPosition (x + (toRight ? 3 : -(r.getWidth() + 3)), y + (below ? 2 : -(r.getHeight() + 2)));
|
||||
setBounds (r);
|
||||
parent->addAndMakeVisible (this);
|
||||
}
|
||||
|
||||
void FloatingLabelComponent::paint (Graphics& g)
|
||||
{
|
||||
g.setFont (font);
|
||||
g.setColour (Colours::white.withAlpha (0.5f));
|
||||
g.fillRoundedRectangle (0, 0, (float) getWidth(), (float) getHeight(), 3);
|
||||
|
||||
g.setColour (colour);
|
||||
glyphs.draw (g, AffineTransform::translation (1.0f, 1.0f));
|
||||
}
|
||||
|
||||
|
||||
//==============================================================================
|
||||
class UTF8Component : public Component,
|
||||
private TextEditorListener
|
||||
|
|
|
|||
|
|
@ -141,24 +141,6 @@ private:
|
|||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PropertyListBuilder)
|
||||
};
|
||||
|
||||
//==============================================================================
|
||||
class FloatingLabelComponent : public Component
|
||||
{
|
||||
public:
|
||||
FloatingLabelComponent();
|
||||
|
||||
void remove();
|
||||
void update (Component* parent, const String& text, const Colour& textColour,
|
||||
int x, int y, bool toRight, bool below);
|
||||
|
||||
void paint (Graphics& g);
|
||||
|
||||
private:
|
||||
Font font;
|
||||
Colour colour;
|
||||
GlyphArrangement glyphs;
|
||||
};
|
||||
|
||||
//==============================================================================
|
||||
// A ValueSource which takes an input source, and forwards any changes in it.
|
||||
// This class is a handy way to create sources which re-map a value.
|
||||
|
|
|
|||
|
|
@ -2178,12 +2178,6 @@ void LookAndFeel::drawTabButtonText (TabBarButton& button, Graphics& g, bool isM
|
|||
Font font (depth * 0.6f);
|
||||
font.setUnderline (button.hasKeyboardFocus (false));
|
||||
|
||||
GlyphArrangement textLayout;
|
||||
textLayout.addFittedText (font, button.getButtonText().trim(),
|
||||
0.0f, 0.0f, (float) length, (float) depth,
|
||||
Justification::centred,
|
||||
jmax (1, ((int) depth) / 12));
|
||||
|
||||
AffineTransform t;
|
||||
|
||||
switch (button.getTabbedButtonBar().getOrientation())
|
||||
|
|
@ -2209,7 +2203,13 @@ void LookAndFeel::drawTabButtonText (TabBarButton& button, Graphics& g, bool isM
|
|||
const float alpha = button.isEnabled() ? ((isMouseOver || isMouseDown) ? 1.0f : 0.8f) : 0.3f;
|
||||
|
||||
g.setColour (col.withMultipliedAlpha (alpha));
|
||||
textLayout.draw (g, t);
|
||||
g.setFont (font);
|
||||
g.addTransform (t);
|
||||
|
||||
g.drawFittedText (button.getButtonText().trim(),
|
||||
0.0f, 0.0f, (float) length, (float) depth,
|
||||
Justification::centred,
|
||||
jmax (1, ((int) depth) / 12));
|
||||
}
|
||||
|
||||
void LookAndFeel::drawTabButton (TabBarButton& button, Graphics& g, bool isMouseOver, bool isMouseDown)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue