Browse Source

Some fixes for minor graphical problems.

tags/2021-05-28
jules 12 years ago
parent
commit
57974a793c
7 changed files with 45 additions and 27 deletions
  1. +9
    -1
      modules/juce_graphics/native/juce_RenderingHelpers.h
  2. +16
    -8
      modules/juce_gui_basics/components/juce_Component.cpp
  3. +2
    -1
      modules/juce_gui_basics/components/juce_Component.h
  4. +2
    -1
      modules/juce_gui_basics/layout/juce_ComponentAnimator.cpp
  5. +12
    -12
      modules/juce_gui_basics/widgets/juce_TextEditor.cpp
  6. +2
    -2
      modules/juce_gui_extra/code_editor/juce_CodeEditorComponent.cpp
  7. +2
    -2
      modules/juce_opengl/opengl/juce_OpenGLHelpers.cpp

+ 9
- 1
modules/juce_graphics/native/juce_RenderingHelpers.h View File

@@ -2270,6 +2270,14 @@ public:
renderImage (sourceImage, trans, nullptr);
}
static bool isOnlyTranslationAllowingError (const AffineTransform& t)
{
return (std::abs (t.mat01) < 0.002)
&& (std::abs (t.mat10) < 0.002)
&& (std::abs (t.mat00 - 1.0f) < 0.002)
&& (std::abs (t.mat11 - 1.0f) < 0.002);
}
void renderImage (const Image& sourceImage, const AffineTransform& trans,
const BaseRegionType* const tiledFillClipRegion)
{
@@ -2277,7 +2285,7 @@ public:
const int alpha = fillType.colour.getAlpha();
if (t.isOnlyTranslation())
if (isOnlyTranslationAllowingError (t))
{
// If our translation doesn't involve any distortion, just use a simple blit..
int tx = (int) (t.getTranslationX() * 256.0f);


+ 16
- 8
modules/juce_gui_basics/components/juce_Component.cpp View File

@@ -2023,7 +2023,8 @@ void Component::paintEntireComponent (Graphics& g, const bool ignoreAlphaLevel)
scaledBounds.getWidth(), scaledBounds.getHeight(), ! flags.opaqueFlag);
{
Graphics g2 (effectImage);
g2.addTransform (AffineTransform::scale (scale));
g2.addTransform (AffineTransform::scale (scaledBounds.getWidth() / (float) getWidth(),
scaledBounds.getHeight() / (float) getHeight()));
paintComponentAndChildren (g2);
}
@@ -2058,7 +2059,7 @@ void Component::setPaintingIsUnclipped (const bool shouldPaintWithoutClipping) n
//==============================================================================
Image Component::createComponentSnapshot (const Rectangle<int>& areaToGrab,
const bool clipImageToComponentBounds)
bool clipImageToComponentBounds, float scaleFactor)
{
Rectangle<int> r (areaToGrab);
@@ -2068,14 +2069,21 @@ Image Component::createComponentSnapshot (const Rectangle<int>& areaToGrab,
if (r.isEmpty())
return Image();
Image componentImage (flags.opaqueFlag ? Image::RGB : Image::ARGB,
r.getWidth(), r.getHeight(), true);
const int w = roundToInt (scaleFactor * r.getWidth());
const int h = roundToInt (scaleFactor * r.getHeight());
Graphics imageContext (componentImage);
imageContext.setOrigin (-r.getPosition());
paintEntireComponent (imageContext, true);
Image image (flags.opaqueFlag ? Image::RGB : Image::ARGB, w, h, true);
return componentImage;
Graphics g (image);
if (w != getWidth() || h != getHeight())
g.addTransform (AffineTransform::scale (w / (float) r.getWidth(),
h / (float) r.getHeight()));
g.setOrigin (-r.getPosition());
paintEntireComponent (g, true);
return image;
}
void Component::setComponentEffect (ImageEffectFilter* const newEffect)


+ 2
- 1
modules/juce_gui_basics/components/juce_Component.h View File

@@ -1010,7 +1010,8 @@ public:
@see paintEntireComponent
*/
Image createComponentSnapshot (const Rectangle<int>& areaToGrab,
bool clipImageToComponentBounds = true);
bool clipImageToComponentBounds = true,
float scaleFactor = 1.0f);
/** Draws this component and all its subcomponents onto the specified graphics
context.


+ 2
- 1
modules/juce_gui_basics/layout/juce_ComponentAnimator.cpp View File

@@ -136,7 +136,6 @@ public:
{
public:
ProxyComponent (Component& c)
: image (c.createComponentSnapshot (c.getLocalBounds()))
{
setBounds (c.getBounds());
setTransform (c.getTransform());
@@ -150,6 +149,8 @@ public:
else
jassertfalse; // seem to be trying to animate a component that's not visible..
image = c.createComponentSnapshot (c.getLocalBounds(), false, getDesktopScaleFactor());
setVisible (true);
toBehind (&c);
}


+ 12
- 12
modules/juce_gui_basics/widgets/juce_TextEditor.cpp View File

@@ -556,15 +556,12 @@ public:
}
}
void drawSelection (Graphics& g, const Range<int> selected) const
void addSelection (RectangleList<float>& area, const Range<int> selected) const
{
const int startX = roundToInt (indexToX (selected.getStart()));
const int endX = roundToInt (indexToX (selected.getEnd()));
const float startX = indexToX (selected.getStart());
const float endX = indexToX (selected.getEnd());
const int y = roundToInt (lineY);
const int nextY = roundToInt (lineY + lineHeight);
g.fillRect (startX, y, endX - startX, nextY - y);
area.add (startX, lineY, endX - startX, lineHeight);
}
void drawUnderline (Graphics& g, const Range<int> underline, const Colour colour) const
@@ -1617,20 +1614,23 @@ void TextEditor::drawContent (Graphics& g)
if (! selection.isEmpty())
{
g.setColour (findColour (highlightColourId).withMultipliedAlpha (hasKeyboardFocus (true) ? 1.0f : 0.5f));
selectedTextColour = findColour (highlightedTextColourId);
Iterator i2 (i);
RectangleList<float> selectionArea;
while (i2.next() && i2.lineY < clip.getBottom())
{
if (i2.lineY + i2.lineHeight >= clip.getY()
&& selection.intersects (Range<int> (i2.indexInText, i2.indexInText + i2.atom->numChars)))
{
i2.drawSelection (g, selection);
i2.addSelection (selectionArea, selection);
}
}
g.setColour (findColour (highlightColourId).withMultipliedAlpha (hasKeyboardFocus (true) ? 1.0f : 0.5f));
g.fillRectList (selectionArea);
selectedTextColour = findColour (highlightedTextColourId);
}
const UniformTextSection* lastSection = nullptr;


+ 2
- 2
modules/juce_gui_extra/code_editor/juce_CodeEditorComponent.cpp View File

@@ -83,8 +83,8 @@ public:
void getHighlightArea (RectangleList<float>& area, float x, int y, int lineH, float characterWidth) const
{
if (highlightColumnStart < highlightColumnEnd)
area.addWithoutMerging (Rectangle<float> (x + highlightColumnStart * characterWidth, (float) y,
(highlightColumnEnd - highlightColumnStart) * characterWidth, (float) lineH));
area.add (Rectangle<float> (x + highlightColumnStart * characterWidth - 1.0f, y - 0.5f,
(highlightColumnEnd - highlightColumnStart) * characterWidth + 1.5f, lineH + 1.0f));
}
void draw (CodeEditorComponent& owner, Graphics& g, const Font& fontToUse,


+ 2
- 2
modules/juce_opengl/opengl/juce_OpenGLHelpers.cpp View File

@@ -272,8 +272,8 @@ OpenGLTextureFromImage::OpenGLTextureFromImage (const Image& image)
texture->loadImage (image);
textureID = texture->getTextureID();
fullWidthProportion = imageWidth / (float) texture->getWidth();
fullHeightProportion = imageHeight / (float) texture->getHeight();
fullWidthProportion = (imageWidth - 0.5f) / texture->getWidth();
fullHeightProportion = (imageHeight - 0.5f) / texture->getHeight();
}
JUCE_CHECK_OPENGL_ERROR


Loading…
Cancel
Save