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

A couple of minor graphical tweaks to MidiKeyboardComponent.

This commit is contained in:
jules 2015-08-18 09:58:47 +01:00
parent 4e8921aa48
commit 15812950c6
2 changed files with 27 additions and 16 deletions

View file

@ -79,7 +79,7 @@ MidiKeyboardComponent::MidiKeyboardComponent (MidiKeyboardState& s, Orientation
addChildComponent (scrollDown = new MidiKeyboardUpDownButton (*this, -1));
addChildComponent (scrollUp = new MidiKeyboardUpDownButton (*this, 1));
// initialise with a default set of querty key-mappings..
// initialise with a default set of qwerty key-mappings..
const char* const keymap = "awsedftgyhujkolp;";
for (int i = 0; keymap[i] != 0; ++i)
@ -104,8 +104,13 @@ MidiKeyboardComponent::~MidiKeyboardComponent()
//==============================================================================
void MidiKeyboardComponent::setKeyWidth (const float widthInPixels)
{
keyWidth = widthInPixels;
resized();
jassert (widthInPixels > 0);
if (keyWidth != widthInPixels) // Prevent infinite recursion if the width is being computed in a 'resized()' call-back
{
keyWidth = widthInPixels;
resized();
}
}
void MidiKeyboardComponent::setOrientation (const Orientation newOrientation)
@ -382,14 +387,18 @@ void MidiKeyboardComponent::paint (Graphics& g)
x += w;
const Colour shadowCol (findColour (shadowColourId));
g.setGradientFill (ColourGradient (shadowCol, x1, y1, shadowCol.withAlpha (0.0f), x2, y2, false));
switch (orientation)
if (! shadowCol.isTransparent())
{
case horizontalKeyboard: g.fillRect (0, 0, x, 5); break;
case verticalKeyboardFacingLeft: g.fillRect (width - 5, 0, 5, x); break;
case verticalKeyboardFacingRight: g.fillRect (0, 0, 5, x); break;
default: break;
g.setGradientFill (ColourGradient (shadowCol, x1, y1, shadowCol.withAlpha (0.0f), x2, y2, false));
switch (orientation)
{
case horizontalKeyboard: g.fillRect (0, 0, x, 5); break;
case verticalKeyboardFacingLeft: g.fillRect (width - 5, 0, 5, x); break;
case verticalKeyboardFacingRight: g.fillRect (0, 0, 5, x); break;
default: break;
}
}
g.setColour (lineColour);
@ -449,14 +458,16 @@ void MidiKeyboardComponent::drawWhiteNote (int midiNoteNumber,
if (text.isNotEmpty())
{
const float fontHeight = jmin (12.0f, keyWidth * 0.9f);
g.setColour (textColour);
g.setFont (Font (jmin (12.0f, keyWidth * 0.9f)).withHorizontalScale (0.8f));
g.setFont (Font (fontHeight).withHorizontalScale (0.8f));
switch (orientation)
{
case horizontalKeyboard: g.drawFittedText (text, x + 1, y, w - 1, h - 2, Justification::centredBottom, 1); break;
case verticalKeyboardFacingLeft: g.drawFittedText (text, x + 2, y + 2, w - 4, h - 4, Justification::centredLeft, 1); break;
case verticalKeyboardFacingRight: g.drawFittedText (text, x + 2, y + 2, w - 4, h - 4, Justification::centredRight, 1); break;
case horizontalKeyboard: g.drawText (text, x + 1, y, w - 1, h - 2, Justification::centredBottom, false); break;
case verticalKeyboardFacingLeft: g.drawText (text, x + 2, y + 2, w - 4, h - 4, Justification::centredLeft, false); break;
case verticalKeyboardFacingRight: g.drawText (text, x + 2, y + 2, w - 4, h - 4, Justification::centredRight, false); break;
default: break;
}
}
@ -524,10 +535,10 @@ void MidiKeyboardComponent::setOctaveForMiddleC (const int octaveNum)
String MidiKeyboardComponent::getWhiteNoteText (const int midiNoteNumber)
{
if (keyWidth > 11.0f && midiNoteNumber % 12 == 0)
if (midiNoteNumber % 12 == 0)
return MidiMessage::getMidiNoteName (midiNoteNumber, true, true, octaveNumForMiddleC);
return String::empty;
return String();
}
void MidiKeyboardComponent::drawUpDownButton (Graphics& g, int w, int h,