diff --git a/extras/Introjucer/Source/Application/jucer_AppearanceSettings.cpp b/extras/Introjucer/Source/Application/jucer_AppearanceSettings.cpp index 5c36f850e0..d94aca3378 100644 --- a/extras/Introjucer/Source/Application/jucer_AppearanceSettings.cpp +++ b/extras/Introjucer/Source/Application/jucer_AppearanceSettings.cpp @@ -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))); } diff --git a/modules/juce_graphics/contexts/juce_GraphicsContext.cpp b/modules/juce_graphics/contexts/juce_GraphicsContext.cpp index 7a51e3a095..2605ad6825 100644 --- a/modules/juce_graphics/contexts/juce_GraphicsContext.cpp +++ b/modules/juce_graphics/contexts/juce_GraphicsContext.cpp @@ -416,36 +416,6 @@ void Graphics::drawRect (const Rectangle& 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 (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 (x + i, y + i, width - i * 2, 1), false); - context.setFill (topLeftColour.withMultipliedAlpha (op * 0.75f)); - context.fillRect (Rectangle (x + i, y + i + 1, 1, height - i * 2 - 2), false); - context.setFill (bottomRightColour.withMultipliedAlpha (op)); - context.fillRect (Rectangle (x + i, y + height - i - 1, width - i * 2, 1), false); - context.setFill (bottomRightColour.withMultipliedAlpha (op * 0.75f)); - context.fillRect (Rectangle (x + width - i - 1, y + i + 1, 1, height - i * 2 - 2), false); - } - - context.restoreState(); - } -} - //============================================================================== void Graphics::fillEllipse (const Rectangle& area) const { diff --git a/modules/juce_graphics/contexts/juce_GraphicsContext.h b/modules/juce_graphics/contexts/juce_GraphicsContext.h index 0acda2b867..72ec791d1e 100644 --- a/modules/juce_graphics/contexts/juce_GraphicsContext.h +++ b/modules/juce_graphics/contexts/juce_GraphicsContext.h @@ -305,29 +305,7 @@ public: void drawRoundedRectangle (const Rectangle& 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; //============================================================================== diff --git a/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel.cpp b/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel.cpp index 40cb104707..2a35cd4871 100644 --- a/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel.cpp +++ b/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel.cpp @@ -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 (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 (x + i, y + i, width - i * 2, 1), false); + context.setFill (topLeftColour.withMultipliedAlpha (op * 0.75f)); + context.fillRect (Rectangle (x + i, y + i + 1, 1, height - i * 2 - 2), false); + context.setFill (bottomRightColour.withMultipliedAlpha (op)); + context.fillRect (Rectangle (x + i, y + height - i - 1, width - i * 2, 1), false); + context.setFill (bottomRightColour.withMultipliedAlpha (op * 0.75f)); + context.fillRect (Rectangle (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, diff --git a/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel.h b/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel.h index d3fdd8902a..a0505a1938 100644 --- a/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel.h +++ b/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel.h @@ -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,