mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-17 00:44:19 +00:00
Improved drop-shadow code.
This commit is contained in:
parent
8d283685fc
commit
225040e62b
2 changed files with 41 additions and 59 deletions
|
|
@ -36,19 +36,30 @@ public:
|
|||
ItemPreviewComponent (const File& file_)
|
||||
: file (file_)
|
||||
{
|
||||
setOpaque (true);
|
||||
tryToLoadImage();
|
||||
}
|
||||
|
||||
void paint (Graphics& g)
|
||||
{
|
||||
g.drawImageWithin (image, 2, 22, getWidth() - 4, getHeight() - 24,
|
||||
RectanglePlacement::centred | RectanglePlacement::onlyReduceInSize,
|
||||
false);
|
||||
drawTexturedBackground (g);
|
||||
|
||||
Rectangle<int> area = RectanglePlacement (RectanglePlacement::centred | RectanglePlacement::onlyReduceInSize)
|
||||
.appliedTo (image.getBounds(), Rectangle<int> (4, 22, getWidth() - 8, getHeight() - 26));
|
||||
|
||||
Path p;
|
||||
p.addRectangle (area);
|
||||
DropShadow (Colours::black.withAlpha (0.5f), 6, Point<int> (0, 1)).drawForPath (g, p);
|
||||
|
||||
g.fillCheckerBoard (area, 24, 24, Colour (0xffffffff), Colour (0xffeeeeee));
|
||||
|
||||
g.setOpacity (1.0f);
|
||||
g.drawImageWithin (image, area.getX(), area.getY(), area.getWidth(), area.getHeight(),
|
||||
RectanglePlacement::stretchToFit, false);
|
||||
|
||||
g.setFont (Font (14.0f, Font::bold));
|
||||
g.setColour (findColour (mainBackgroundColourId).contrasting());
|
||||
g.drawMultiLineText (facts.joinIntoString ("\n"),
|
||||
10, 15, getWidth() - 16);
|
||||
g.drawMultiLineText (facts.joinIntoString ("\n"), 10, 15, getWidth() - 16);
|
||||
}
|
||||
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -23,63 +23,38 @@
|
|||
==============================================================================
|
||||
*/
|
||||
|
||||
#if JUCE_MSVC && JUCE_DEBUG
|
||||
#pragma optimize ("t", on)
|
||||
#endif
|
||||
static inline void blurDataTriplets (uint8* d, int num, const int delta) noexcept
|
||||
{
|
||||
uint32 last = d[0];
|
||||
d[0] = (uint8) ((d[0] + d[delta] + 1) / 3);
|
||||
d += delta;
|
||||
|
||||
num -= 2;
|
||||
|
||||
do
|
||||
{
|
||||
const uint32 newLast = d[0];
|
||||
d[0] = (uint8) ((last + d[0] + d[delta] + 1) / 3);
|
||||
d += delta;
|
||||
last = newLast;
|
||||
}
|
||||
while (--num > 0);
|
||||
|
||||
d[0] = (uint8) ((last + d[0] + 1) / 3);
|
||||
}
|
||||
|
||||
static void blurSingleChannelImage (uint8* const data, const int width, const int height,
|
||||
const int lineStride, const int repetitions) noexcept
|
||||
{
|
||||
uint8* line = data;
|
||||
jassert (width > 2 && height > 2);
|
||||
|
||||
for (int y = height; --y >= 0;)
|
||||
{
|
||||
for (int y = 0; y < height; ++y)
|
||||
for (int i = repetitions; --i >= 0;)
|
||||
{
|
||||
uint8* p = line;
|
||||
*p++ = (((int) p[0]) + p[1]) / 2;
|
||||
blurDataTriplets (data + lineStride * y, width, 1);
|
||||
|
||||
for (int x = width - 2; --x >= 0;)
|
||||
*p++ = (((int) p[-1]) + p[0] + p[1] + 1) / 3;
|
||||
|
||||
*p = (((int) p[0]) + p[-1]) / 2;
|
||||
}
|
||||
|
||||
line += lineStride;
|
||||
}
|
||||
|
||||
for (int i = repetitions; --i >= 0;)
|
||||
{
|
||||
line = data;
|
||||
|
||||
{
|
||||
uint8* p1 = line;
|
||||
uint8* p2 = line + lineStride;
|
||||
|
||||
for (int x = width; --x >= 0;)
|
||||
*p1++ = (((int) *p1) + *p2++) / 2;
|
||||
}
|
||||
|
||||
line += lineStride;
|
||||
|
||||
for (int y = height - 2; --y >= 0;)
|
||||
{
|
||||
uint8* p1 = line;
|
||||
uint8* p2 = line - lineStride;
|
||||
uint8* p3 = line + lineStride;
|
||||
|
||||
for (int x = width; --x >= 0;)
|
||||
*p1++ = (((int) *p1) + *p2++ + *p3++ + 1) / 3;
|
||||
|
||||
line += lineStride;
|
||||
}
|
||||
|
||||
uint8* p1 = line;
|
||||
uint8* p2 = line - lineStride;
|
||||
|
||||
for (int x = width; --x >= 0;)
|
||||
*p1++ = (((int) *p1) + *p2++) / 2;
|
||||
}
|
||||
for (int x = 0; x < width; ++x)
|
||||
for (int i = repetitions; --i >= 0;)
|
||||
blurDataTriplets (data + x, height, lineStride);
|
||||
}
|
||||
|
||||
static void blurSingleChannelImage (Image& image, int radius)
|
||||
|
|
@ -88,10 +63,6 @@ static void blurSingleChannelImage (Image& image, int radius)
|
|||
blurSingleChannelImage (bm.data, bm.width, bm.height, bm.lineStride, 2 * radius);
|
||||
}
|
||||
|
||||
#if JUCE_MSVC && JUCE_DEBUG
|
||||
#pragma optimize ("", on) // resets optimisations to the project defaults
|
||||
#endif
|
||||
|
||||
//==============================================================================
|
||||
DropShadow::DropShadow() noexcept
|
||||
: colour (0x90000000), radius (4)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue