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

Moved the Graphics::drawBevel() method into LookAndFeel. Fixed an introjucer caret colour bug.

This commit is contained in:
jules 2012-07-14 11:21:56 +01:00
parent 1b2b1a1aac
commit 006e324114
5 changed files with 76 additions and 65 deletions

View file

@ -33,19 +33,20 @@ namespace AppearanceColours
const char* name;
uint32 colourID;
bool mustBeOpaque;
bool applyToEditorOnly;
};
static const ColourInfo colours[] =
{
{ "Main Window Bkgd", mainBackgroundColourId, true },
{ "Treeview Highlight", treeviewHighlightColourId, false },
{ "Main Window Bkgd", mainBackgroundColourId, true, false },
{ "Treeview Highlight", treeviewHighlightColourId, false, false },
{ "Code Background", CodeEditorComponent::backgroundColourId, true },
{ "Line Number Bkgd", CodeEditorComponent::lineNumberBackgroundId, false },
{ "Line Numbers", CodeEditorComponent::lineNumberTextId, false },
{ "Plain Text", CodeEditorComponent::defaultTextColourId, false },
{ "Selected Text Bkgd", CodeEditorComponent::highlightColourId, false },
{ "Caret", CaretComponent::caretColourId, false }
{ "Code Background", CodeEditorComponent::backgroundColourId, true, false },
{ "Line Number Bkgd", CodeEditorComponent::lineNumberBackgroundId, false, false },
{ "Line Numbers", CodeEditorComponent::lineNumberTextId, false, false },
{ "Plain Text", CodeEditorComponent::defaultTextColourId, false, false },
{ "Selected Text Bkgd", CodeEditorComponent::highlightColourId, false, false },
{ "Caret", CaretComponent::caretColourId, false, true }
};
}
@ -201,7 +202,8 @@ void AppearanceSettings::applyToLookAndFeel (LookAndFeel& lf) const
if (AppearanceColours::colours[i].mustBeOpaque)
col = Colours::white.overlaidWith (col);
lf.setColour (AppearanceColours::colours[i].colourID, col);
if (! AppearanceColours::colours[i].applyToEditorOnly)
lf.setColour (AppearanceColours::colours[i].colourID, col);
}
}
@ -222,6 +224,16 @@ void AppearanceSettings::applyToCodeEditor (CodeEditorComponent& editor) const
editor.setColourScheme (cs);
editor.setFont (getCodeFont());
for (int i = 0; i < sizeof (AppearanceColours::colours) / sizeof (AppearanceColours::colours[0]); ++i)
{
if (AppearanceColours::colours[i].applyToEditorOnly)
{
Colour col;
if (getColour (AppearanceColours::colours[i].name, col))
editor.setColour (AppearanceColours::colours[i].colourID, col);
}
}
editor.setColour (ScrollBar::thumbColourId,
getScrollbarColourForBackground (editor.findColour (CodeEditorComponent::backgroundColourId)));
}

View file

@ -416,36 +416,6 @@ void Graphics::drawRect (const Rectangle<int>& r, const int lineThickness) const
drawRect (r.getX(), r.getY(), r.getWidth(), r.getHeight(), lineThickness);
}
void Graphics::drawBevel (const int x, const int y, const int width, const int height,
const int bevelThickness, const Colour& topLeftColour, const Colour& bottomRightColour,
const bool useGradient, const bool sharpEdgeOnOutside) const
{
// passing in a silly number can cause maths problems in rendering!
jassert (areCoordsSensibleNumbers (x, y, width, height));
if (clipRegionIntersects (Rectangle<int> (x, y, width, height)))
{
context.saveState();
for (int i = bevelThickness; --i >= 0;)
{
const float op = useGradient ? (sharpEdgeOnOutside ? bevelThickness - i : i) / (float) bevelThickness
: 1.0f;
context.setFill (topLeftColour.withMultipliedAlpha (op));
context.fillRect (Rectangle<int> (x + i, y + i, width - i * 2, 1), false);
context.setFill (topLeftColour.withMultipliedAlpha (op * 0.75f));
context.fillRect (Rectangle<int> (x + i, y + i + 1, 1, height - i * 2 - 2), false);
context.setFill (bottomRightColour.withMultipliedAlpha (op));
context.fillRect (Rectangle<int> (x + i, y + height - i - 1, width - i * 2, 1), false);
context.setFill (bottomRightColour.withMultipliedAlpha (op * 0.75f));
context.fillRect (Rectangle<int> (x + width - i - 1, y + i + 1, 1, height - i * 2 - 2), false);
}
context.restoreState();
}
}
//==============================================================================
void Graphics::fillEllipse (const Rectangle<float>& area) const
{

View file

@ -305,29 +305,7 @@ public:
void drawRoundedRectangle (const Rectangle<float>& rectangle,
float cornerSize, float lineThickness) const;
/** Draws a 3D raised (or indented) bevel using two colours.
The bevel is drawn inside the given rectangle, and greater bevel thicknesses
extend inwards.
The top-left colour is used for the top- and left-hand edges of the
bevel; the bottom-right colour is used for the bottom- and right-hand
edges.
If useGradient is true, then the bevel fades out to make it look more curved
and less angular. If sharpEdgeOnOutside is true, the outside of the bevel is
sharp, and it fades towards the centre; if sharpEdgeOnOutside is false, then
the centre edges are sharp and it fades towards the outside.
*/
void drawBevel (int x, int y, int width, int height,
int bevelThickness,
const Colour& topLeftColour = Colours::white,
const Colour& bottomRightColour = Colours::black,
bool useGradient = true,
bool sharpEdgeOnOutside = true) const;
/** Draws a pixel using the current colour or brush.
*/
/** Draws a 1x1 pixel using the current colour or brush. */
void setPixel (int x, int y) const;
//==============================================================================

View file

@ -1238,7 +1238,7 @@ void LookAndFeel::drawTextEditorOutline (Graphics& g, int width, int height, Tex
g.setOpacity (1.0f);
const Colour shadowColour (textEditor.findColour (TextEditor::shadowColourId).withMultipliedAlpha (0.75f));
g.drawBevel (0, 0, width, height + 2, border + 2, shadowColour, shadowColour);
drawBevel (g, 0, 0, width, height + 2, border + 2, shadowColour, shadowColour);
}
else
{
@ -1247,7 +1247,7 @@ void LookAndFeel::drawTextEditorOutline (Graphics& g, int width, int height, Tex
g.setOpacity (1.0f);
const Colour shadowColour (textEditor.findColour (TextEditor::shadowColourId));
g.drawBevel (0, 0, width, height + 2, 3, shadowColour, shadowColour);
drawBevel (g, 0, 0, width, height + 2, 3, shadowColour, shadowColour);
}
}
}
@ -2758,7 +2758,7 @@ void LookAndFeel::drawKeymapChangeButton (Graphics& g, int width, int height, Bu
g.fillAll (textColour.withAlpha (alpha));
g.setOpacity (0.3f);
g.drawBevel (0, 0, width, height, 2);
drawBevel (g, 0, 0, width, height, 2);
}
g.setColour (textColour);
@ -2790,6 +2790,35 @@ void LookAndFeel::drawKeymapChangeButton (Graphics& g, int width, int height, Bu
}
}
//==============================================================================
void LookAndFeel::drawBevel (Graphics& g, const int x, const int y, const int width, const int height,
const int bevelThickness, const Colour& topLeftColour, const Colour& bottomRightColour,
const bool useGradient, const bool sharpEdgeOnOutside)
{
if (g.clipRegionIntersects (Rectangle<int> (x, y, width, height)))
{
LowLevelGraphicsContext& context = g.getInternalContext();
context.saveState();
for (int i = bevelThickness; --i >= 0;)
{
const float op = useGradient ? (sharpEdgeOnOutside ? bevelThickness - i : i) / (float) bevelThickness
: 1.0f;
context.setFill (topLeftColour.withMultipliedAlpha (op));
context.fillRect (Rectangle<int> (x + i, y + i, width - i * 2, 1), false);
context.setFill (topLeftColour.withMultipliedAlpha (op * 0.75f));
context.fillRect (Rectangle<int> (x + i, y + i + 1, 1, height - i * 2 - 2), false);
context.setFill (bottomRightColour.withMultipliedAlpha (op));
context.fillRect (Rectangle<int> (x + i, y + height - i - 1, width - i * 2, 1), false);
context.setFill (bottomRightColour.withMultipliedAlpha (op * 0.75f));
context.fillRect (Rectangle<int> (x + width - i - 1, y + i + 1, 1, height - i * 2 - 2), false);
}
context.restoreState();
}
}
//==============================================================================
void LookAndFeel::drawShinyButtonShape (Graphics& g,
float x, float y, float w, float h,

View file

@ -582,6 +582,28 @@ public:
virtual void playAlertSound();
//==============================================================================
/** Draws a 3D raised (or indented) bevel using two colours.
The bevel is drawn inside the given rectangle, and greater bevel thicknesses
extend inwards.
The top-left colour is used for the top- and left-hand edges of the
bevel; the bottom-right colour is used for the bottom- and right-hand
edges.
If useGradient is true, then the bevel fades out to make it look more curved
and less angular. If sharpEdgeOnOutside is true, the outside of the bevel is
sharp, and it fades towards the centre; if sharpEdgeOnOutside is false, then
the centre edges are sharp and it fades towards the outside.
*/
static void drawBevel (Graphics& g,
int x, int y, int width, int height,
int bevelThickness,
const Colour& topLeftColour = Colours::white,
const Colour& bottomRightColour = Colours::black,
bool useGradient = true,
bool sharpEdgeOnOutside = true);
/** Utility function to draw a shiny, glassy circle (for round LED-type buttons). */
static void drawGlassSphere (Graphics& g,
float x, float y,