Add TAL-Reverb-II plugin to test
[juce-lv2.git] / juce / source / extras / JuceDemo / Source / demos / FontsAndTextDemo.cpp
blob5e6e327372d171d5d398a9327ccd8b547bc859ab
1 /*
2 ==============================================================================
4 This file is part of the JUCE library - "Jules' Utility Class Extensions"
5 Copyright 2004-9 by Raw Material Software Ltd.
7 ------------------------------------------------------------------------------
9 JUCE can be redistributed and/or modified under the terms of the GNU General
10 Public License (Version 2), as published by the Free Software Foundation.
11 A copy of the license is included in the JUCE distribution, or can be found
12 online at www.gnu.org/licenses.
14 JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
18 ------------------------------------------------------------------------------
20 To release a closed-source product which uses JUCE, commercial licenses are
21 available: visit www.rawmaterialsoftware.com/juce for more information.
23 ==============================================================================
26 #include "../jucedemo_headers.h"
29 //==============================================================================
30 class FontsAndTextDemo : public Component,
31 public ListBoxModel,
32 public ButtonListener,
33 public SliderListener
35 public:
36 //==============================================================================
37 FontsAndTextDemo()
38 : boldButton ("Bold"),
39 italicButton ("Italic"),
40 sizeLabel (String::empty, "Size"),
41 kerningLabel (String::empty, "Kerning"),
42 horizontalScaleLabel (String::empty, "Scale")
44 setName ("Fonts");
46 Font::findFonts (fonts);
48 addAndMakeVisible (listBox = new ListBox ("fonts", this));
49 listBox->setRowHeight (28);
51 addAndMakeVisible (&textBox);
53 textBox.setColour (TextEditor::backgroundColourId, Colours::white);
54 textBox.setColour (TextEditor::outlineColourId, Colours::black.withAlpha (0.5f));
56 textBox.setMultiLine (true, true);
57 textBox.setReturnKeyStartsNewLine (true);
58 textBox.setText ("The Quick Brown Fox Jumps Over The Lazy Dog\n\nAa Bb Cc Dd Ee Ff Gg Hh Ii Jj Kk Ll Mm Nn Oo Pp Qq Rr Ss Tt Uu Vv Ww Xx Yy Zz 0123456789");
60 addAndMakeVisible (&boldButton);
61 boldButton.addListener (this);
63 addAndMakeVisible (&italicButton);
64 italicButton.addListener (this);
66 addAndMakeVisible (&sizeSlider);
67 sizeSlider.setRange (3.0, 150.0, 0.1);
68 sizeSlider.setValue (20.0);
69 sizeSlider.addListener (this);
70 sizeLabel.attachToComponent (&sizeSlider, true);
72 addAndMakeVisible (&kerningSlider);
73 kerningSlider.setRange (-1.0, 1.0, 0.01);
74 kerningSlider.setValue (0.0);
75 kerningSlider.addListener (this);
76 kerningLabel.attachToComponent (&kerningSlider, true);
78 addAndMakeVisible (&horizontalScaleSlider);
79 horizontalScaleSlider.setRange (0.1, 4.0, 0.01);
80 horizontalScaleSlider.setValue (1.0);
81 horizontalScaleSlider.addListener (this);
82 horizontalScaleLabel.attachToComponent (&horizontalScaleSlider, true);
84 listBox->setColour (ListBox::outlineColourId, Colours::black.withAlpha (0.5f));
85 listBox->setOutlineThickness (1);
86 listBox->selectRow (Random::getSystemRandom().nextInt (fonts.size()));
88 // set up the layout and resizer bars..
90 verticalLayout.setItemLayout (0, -0.2, -0.8, -0.5); // width of the font list must be
91 // between 20% and 80%, preferably 50%
92 verticalLayout.setItemLayout (1, 8, 8, 8); // the vertical divider drag-bar thing is always 8 pixels wide
93 verticalLayout.setItemLayout (2, 150, -1.0, -0.5); // the components on the right must be
94 // at least 150 pixels wide, preferably 50% of the total width
96 verticalDividerBar = new StretchableLayoutResizerBar (&verticalLayout, 1, true);
97 addAndMakeVisible (verticalDividerBar);
100 ~FontsAndTextDemo()
104 void resized()
106 // lay out the list box and vertical divider..
107 Component* vcomps[] = { listBox, verticalDividerBar, 0 };
109 verticalLayout.layOutComponents (vcomps, 3,
110 4, 4, getWidth() - 8, getHeight() - 8,
111 false, // lay out side-by-side
112 true); // resize the components' heights as well as widths
114 // now lay out the text box and the controls below it..
115 int x = verticalLayout.getItemCurrentPosition (2) + 4;
116 textBox.setBounds (x, 0, getWidth() - x, getHeight() - 110);
117 x += 70;
118 sizeSlider.setBounds (x, getHeight() - 106, getWidth() - x, 22);
119 kerningSlider.setBounds (x, getHeight() - 82, getWidth() - x, 22);
120 horizontalScaleSlider.setBounds (x, getHeight() - 58, getWidth() - x, 22);
121 boldButton.setBounds (x, getHeight() - 34, (getWidth() - x) / 2, 22);
122 italicButton.setBounds (x + (getWidth() - x) / 2, getHeight() - 34, (getWidth() - x) / 2, 22);
125 // implements the ListBoxModel method
126 int getNumRows()
128 return fonts.size();
131 // implements the ListBoxModel method
132 void paintListBoxItem (int rowNumber,
133 Graphics& g,
134 int width, int height,
135 bool rowIsSelected)
137 if (rowIsSelected)
138 g.fillAll (Colours::lightblue);
140 Font font (fonts [rowNumber]);
141 font.setHeight (height * 0.7f);
143 g.setFont (font);
144 g.setColour (Colours::black);
145 g.drawText (font.getTypefaceName(),
146 4, 0, width - 4, height,
147 Justification::centredLeft, true);
149 int x = jmax (0, font.getStringWidth (font.getTypefaceName())) + 12;
150 g.setFont (Font (11.0f, Font::italic));
151 g.setColour (Colours::grey);
152 g.drawText (font.getTypefaceName(),
153 x, 0, width - x - 2, height,
154 Justification::centredLeft, true);
157 void updatePreviewBoxText()
159 Font font (fonts [listBox->getSelectedRow()]);
161 font.setHeight ((float) sizeSlider.getValue());
162 font.setBold (boldButton.getToggleState());
163 font.setItalic (italicButton.getToggleState());
164 font.setExtraKerningFactor ((float) kerningSlider.getValue());
165 font.setHorizontalScale ((float) horizontalScaleSlider.getValue());
167 textBox.applyFontToAllText (font);
170 void selectedRowsChanged (int /*lastRowselected*/)
172 updatePreviewBoxText();
175 void buttonClicked (Button*)
177 updatePreviewBoxText();
180 void sliderValueChanged (Slider*)
182 // (this is called when the size slider is moved)
183 updatePreviewBoxText();
186 private:
187 Array<Font> fonts;
189 ScopedPointer<ListBox> listBox;
190 TextEditor textBox;
191 ToggleButton boldButton, italicButton;
192 Slider sizeSlider, kerningSlider, horizontalScaleSlider;
193 Label sizeLabel, kerningLabel, horizontalScaleLabel;
195 StretchableLayoutManager verticalLayout;
196 ScopedPointer<StretchableLayoutResizerBar> verticalDividerBar;
200 //==============================================================================
201 Component* createFontsAndTextDemo()
203 return new FontsAndTextDemo();