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

Tarted up the fonts demo page; added a scrollbar thickness to the code editor; improved the colour selector's rendering speed.

This commit is contained in:
Julian Storer 2009-11-09 11:30:58 +00:00
parent dad610b948
commit 69321e8b33
5 changed files with 96 additions and 40 deletions

View file

@ -38,12 +38,13 @@ class FontsAndTextDemo : public Component,
ToggleButton* boldButton;
ToggleButton* italicButton;
Slider* sizeSlider;
Slider* kerningSlider;
Slider* horizontalScaleSlider;
StretchableLayoutManager verticalLayout;
StretchableLayoutManager horizontalLayout;
StretchableLayoutResizerBar* verticalDividerBar;
StretchableLayoutResizerBar* horizontalDividerBar;
public:
//==============================================================================
@ -71,12 +72,33 @@ public:
addAndMakeVisible (italicButton = new ToggleButton (T("italic")));
italicButton->addButtonListener (this);
addAndMakeVisible (sizeSlider = new Slider (T("size")));
addAndMakeVisible (sizeSlider = new Slider ("Size"));
sizeSlider->setRange (3.0, 150.0, 0.1);
sizeSlider->setValue (20.0);
sizeSlider->addListener (this);
(new Label (String::empty, sizeSlider->getName()))->attachToComponent (sizeSlider, true);
addAndMakeVisible (kerningSlider = new Slider ("Kerning"));
kerningSlider->setRange (-1.0, 1.0, 0.01);
kerningSlider->setValue (0.0);
kerningSlider->addListener (this);
(new Label (String::empty, kerningSlider->getName()))->attachToComponent (kerningSlider, true);
addAndMakeVisible (horizontalScaleSlider = new Slider ("Stretch"));
horizontalScaleSlider->setRange (0.1, 4.0, 0.01);
horizontalScaleSlider->setValue (1.0);
horizontalScaleSlider->addListener (this);
(new Label (String::empty, horizontalScaleSlider->getName()))->attachToComponent (horizontalScaleSlider, true);
for (int i = 0; i < fonts.size(); ++i)
{
if (fonts[i]->getTypefaceName().startsWithIgnoreCase (T("Arial")))
{
listBox->selectRow (i);
break;
}
}
listBox->selectRow (0);
listBox->setColour (ListBox::outlineColourId, Colours::black.withAlpha (0.5f));
listBox->setOutlineThickness (1);
@ -106,9 +128,6 @@ public:
// space left over - this will stop the
// sliders from always sticking to the
// bottom of the window
horizontalDividerBar = new StretchableLayoutResizerBar (&horizontalLayout, 1, false);
addAndMakeVisible (horizontalDividerBar);
}
~FontsAndTextDemo()
@ -127,18 +146,14 @@ public:
true); // resize the components' heights as well as widths
// now lay out the text box and the controls below it..
Component* hcomps[] = { textBox, horizontalDividerBar, 0,
boldButton, 0,
italicButton, 0,
sizeSlider };
horizontalLayout.layOutComponents (hcomps, 8,
4 + verticalLayout.getItemCurrentPosition (2), // for their widths, refer to the vertical layout state
4,
verticalLayout.getItemCurrentAbsoluteSize (2),
getHeight() - 8,
true, // lay out above each other
true); // resize the components' widths as well as heights
int x = verticalLayout.getItemCurrentPosition (2);
textBox->setBounds (x, 0, getWidth() - x, getHeight() - 110);
x += 70;
sizeSlider->setBounds (x, getHeight() - 106, getWidth() - x, 22);
kerningSlider->setBounds (x, getHeight() - 82, getWidth() - x, 22);
horizontalScaleSlider->setBounds (x, getHeight() - 58, getWidth() - x, 22);
boldButton->setBounds (x, getHeight() - 34, (getWidth() - x) / 2, 22);
italicButton->setBounds (x + (getWidth() - x) / 2, getHeight() - 34, (getWidth() - x) / 2, 22);
}
// implements the ListBoxModel method
@ -162,9 +177,17 @@ public:
font.setHeight (height * 0.7f);
g.setFont (font);
g.setColour (Colours::black);
g.drawText (font.getTypefaceName(),
4, 0, width - 4, height,
Justification::centredLeft, true);
int x = jmax (0, font.getStringWidth (font.getTypefaceName())) + 12;
g.setFont (Font (11.0f, Font::italic));
g.setColour (Colours::grey);
g.drawText (font.getTypefaceName(),
x, 0, width - x - 2, height,
Justification::centredLeft, true);
}
}
@ -179,6 +202,8 @@ public:
font.setHeight ((float) sizeSlider->getValue());
font.setBold (boldButton->getToggleState());
font.setItalic (italicButton->getToggleState());
font.setExtraKerningFactor ((float) kerningSlider->getValue());
font.setHorizontalScale ((float) horizontalScaleSlider->getValue());
textBox->applyFontToAllText (font);
}

View file

@ -75,7 +75,7 @@ public:
typeChooser->addItem (T("image - high quality"), 5);
typeChooser->addItem (T("image - colour-filled alpha channel"), 6);
typeChooser->addItem (T("image - gradient-filled alpha channel"), 7);
typeChooser->addItem (T("image - alphamap-filled alpha channel"), 9);
typeChooser->addItem (T("image - tiled-image-filled alpha channel"), 9);
typeChooser->addItem (T("drawable object"), 10);
typeChooser->addItem (T("SVG object"), 11);
typeChooser->setSelectedId (11);

View file

@ -398,6 +398,15 @@ void CodeEditorComponent::paint (Graphics& g)
}
}
void CodeEditorComponent::setScrollbarThickness (const int thickness) throw()
{
if (scrollbarThickness != thickness)
{
scrollbarThickness = thickness;
resized();
}
}
void CodeEditorComponent::handleAsyncUpdate()
{
rebuildLineTokens();

View file

@ -207,6 +207,10 @@ public:
enabled. */
};
//==============================================================================
/** Changes the size of the scrollbars. */
void setScrollbarThickness (const int thickness) throw();
//==============================================================================
/** @internal */
void resized();

View file

@ -30,7 +30,7 @@ BEGIN_JUCE_NAMESPACE
#include "juce_ColourSelector.h"
#include "../../../text/juce_LocalisedStrings.h"
#include "../menus/juce_PopupMenu.h"
#include "../../graphics/imaging/juce_Image.h"
static const int swatchesPerRow = 8;
static const int swatchHeight = 22;
@ -108,7 +108,8 @@ public:
: owner (owner_),
h (h_), s (s_), v (v_),
lastHue (0.0f),
edge (edgeSize)
edge (edgeSize),
colours (0)
{
addAndMakeVisible (marker = new ColourSpaceMarker());
setMouseCursor (MouseCursor::CrosshairCursor);
@ -117,32 +118,40 @@ public:
~ColourSpaceView()
{
deleteAllChildren();
delete colours;
}
void paint (Graphics& g)
{
const float hue = h;
const float xScale = 1.0f / (getWidth() - edge * 2);
const float yScale = 1.0f / (getHeight() - edge * 2);
const Rectangle clip (g.getClipBounds());
const int x1 = jmax (clip.getX(), edge) & ~1;
const int x2 = jmin (clip.getRight(), getWidth() - edge) | 1;
const int y1 = jmax (clip.getY(), edge) & ~1;
const int y2 = jmin (clip.getBottom(), getHeight() - edge) | 1;
for (int y = y1; y < y2; y += 2)
if (colours == 0)
{
const float v = jlimit (0.0f, 1.0f, 1.0f - (y - edge) * yScale);
const int width = getWidth() / 2;
const int height = getHeight() / 2;
colours = new Image (Image::RGB, width, height, false);
for (int x = x1; x < x2; x += 2)
int ls, ps;
char* data = (char*) colours->lockPixelDataReadWrite (0, 0, width, height, ls, ps);
for (int y = 0; y < height; ++y)
{
const float s = jlimit (0.0f, 1.0f, (x - edge) * xScale);
g.setColour (Colour (hue, s, v, 1.0f));
g.fillRect (x, y, 2, 2);
const float v = 1.0f - y / (float) height;
for (int x = 0; x < width; ++x)
{
const float s = x / (float) width;
const Colour col (h, s, v, 1.0f);
PixelRGB* const pix = (PixelRGB*) (data + ls * y + ps * x);
pix->set (col.getPixelARGB());
}
}
colours->releasePixelDataReadWrite (data);
}
g.setOpacity (1.0f);
g.drawImage (colours, edge, edge, getWidth() - edge * 2, getHeight() - edge * 2,
0, 0, colours->getWidth(), colours->getHeight());
}
void mouseDown (const MouseEvent& e)
@ -163,20 +172,29 @@ public:
if (lastHue != h)
{
lastHue = h;
deleteAndZero (colours);
repaint();
}
resized();
updateMarker();
}
void resized()
{
deleteAndZero (colours);
updateMarker();
}
private:
Image* colours;
void updateMarker() const throw()
{
marker->setBounds (roundFloatToInt ((getWidth() - edge * 2) * s),
roundFloatToInt ((getHeight() - edge * 2) * (1.0f - v)),
edge * 2, edge * 2);
}
private:
ColourSpaceView (const ColourSpaceView&);
const ColourSpaceView& operator= (const ColourSpaceView&);
};