42 const auto tie = [] (
auto&
t) {
return std::make_tuple (
t.getX(),
t.getY(),
t.getWidth(),
t.getHeight()); };
48 return a.getFlags() <
b.getFlags();
54 struct ConfiguredArrangement
56 void draw (
const Graphics&
g)
const { arrangement.draw (
g, transform); }
58 GlyphArrangement arrangement;
59 AffineTransform transform;
62 template <
typename ArrangementArgs>
63 class GlyphArrangementCache
final :
public DeletedAtShutdown
66 GlyphArrangementCache() =
default;
68 ~GlyphArrangementCache()
override
70 clearSingletonInstance();
73 template <
typename ConfigureArrangement>
74 void draw (
const Graphics&
g, ArrangementArgs&& args, ConfigureArrangement&& configureArrangement)
80 configureArrangement (args).draw (
g);
84 const auto cached = [&]
86 const auto iter = cache.find (args);
88 if (iter != cache.end())
90 if (iter->second.cachePosition != cacheOrder.begin())
91 cacheOrder.splice (cacheOrder.begin(), cacheOrder, iter->second.cachePosition);
96 auto result = cache.emplace (std::move (args), CachedGlyphArrangement { configureArrangement (args), {} }).first;
97 cacheOrder.push_front (
result);
101 cached->second.cachePosition = cacheOrder.begin();
102 cached->second.configured.draw (
g);
104 while (cache.size() > cacheSize)
106 cache.erase (cacheOrder.back());
107 cacheOrder.pop_back();
114 struct CachedGlyphArrangement
116 using CachePtr =
typename std::map<ArrangementArgs, CachedGlyphArrangement>::const_iterator;
117 ConfiguredArrangement configured;
118 typename std::list<CachePtr>::const_iterator cachePosition;
121 static constexpr size_t cacheSize = 128;
122 std::map<ArrangementArgs, CachedGlyphArrangement> cache;
123 std::list<typename CachedGlyphArrangement::CachePtr> cacheOrder;
124 CriticalSection lock;
127 template <
typename ArrangementArgs>
128 juce::SingletonHolder<GlyphArrangementCache<ArrangementArgs>, juce::CriticalSection,
false> GlyphArrangementCache<ArrangementArgs>::singletonHolder;
131 template <
typename Type>
135 const int maxVal = 0x3fffffff;
138 && (
int)
y >= -maxVal && (
int)
y <= maxVal
139 && (
int)
w >= 0 && (
int)
w <= maxVal
140 && (
int)
h >= 0 && (
int)
h <= maxVal);
143 return {
x,
y,
w,
h };
171 return context.isVectorDevice();
177 return context.clipToRectangle (area);
188 return context.clipToRectangleList (clipRegion);
194 context.clipToPath (path, transform);
195 return !
context.isClipEmpty();
202 return !
context.isClipEmpty();
208 context.excludeClipRectangle (rectangleToExclude);
218 return context.getClipBounds();
258 context.addTransform (transform);
263 return context.clipRegionIntersects (area);
269 context.beginTransparencyLayer (layerOpacity);
274 context.endTransparencyLayer();
287 context.setOpacity (newOpacity);
348 struct ArrangementArgs
350 auto tie()
const noexcept {
return std::tie (font,
text, startX, baselineY); }
351 bool operator< (
const ArrangementArgs& other)
const {
return tie() < other.tie(); }
355 const int startX, baselineY,
flags;
358 auto configureArrangement = [] (
const ArrangementArgs& args)
362 arrangement.
addLineOfText (args.font, args.text, (
float) args.startX, (
float) args.baselineY);
374 return ConfiguredArrangement { std::move (arrangement), std::move (transform) };
377 GlyphArrangementCache<ArrangementArgs>::getInstance()->draw (*
this,
379 std::move (configureArrangement));
383 const int baselineY,
const int maximumLineWidth,
386 if (
text.isEmpty() || startX >=
context.getClipBounds().getRight())
389 struct ArrangementArgs
391 auto tie()
const noexcept {
return std::tie (font,
text, startX, baselineY, maximumLineWidth, justification, leading); }
392 bool operator< (
const ArrangementArgs& other)
const {
return tie() < other.tie(); }
396 const int startX, baselineY, maximumLineWidth;
401 auto configureArrangement = [] (
const ArrangementArgs& args)
405 (
float) args.startX, (
float) args.baselineY, (
float) args.maximumLineWidth,
406 args.justification, args.leading);
407 return ConfiguredArrangement { std::move (arrangement), {} };
410 GlyphArrangementCache<ArrangementArgs>::getInstance()->draw (*
this,
411 {
context.getFont(),
text, startX, baselineY, maximumLineWidth, justification, leading },
412 std::move (configureArrangement));
416 Justification justificationType,
bool useEllipsesIfTooBig)
const
421 struct ArrangementArgs
423 auto tie()
const noexcept {
return std::tie (font,
text, area, justificationType, useEllipsesIfTooBig); }
424 bool operator< (
const ArrangementArgs& other)
const {
return tie() < other.tie(); }
430 const bool useEllipsesIfTooBig;
433 auto configureArrangement = [] (
const ArrangementArgs& args)
437 args.area.getWidth(), args.useEllipsesIfTooBig);
440 args.area.getX(), args.area.getY(), args.area.getWidth(), args.area.getHeight(),
441 args.justificationType);
442 return ConfiguredArrangement { std::move (arrangement), {} };
445 GlyphArrangementCache<ArrangementArgs>::getInstance()->draw (*
this,
446 {
context.getFont(),
text, area, justificationType, useEllipsesIfTooBig },
447 std::move (configureArrangement));
451 Justification justificationType,
bool useEllipsesIfTooBig)
const
457 Justification justificationType,
const bool useEllipsesIfTooBig)
const
464 const int maximumNumberOfLines,
465 const float minimumHorizontalScale)
const
470 struct ArrangementArgs
472 auto tie()
const noexcept {
return std::tie (font,
text, area, justification, maximumNumberOfLines, minimumHorizontalScale); }
473 bool operator< (
const ArrangementArgs& other)
const noexcept {
return tie() < other.tie(); }
479 const int maximumNumberOfLines;
480 const float minimumHorizontalScale;
483 auto configureArrangement = [] (
const ArrangementArgs& args)
487 args.area.getX(), args.area.getY(),
488 args.area.getWidth(), args.area.getHeight(),
490 args.maximumNumberOfLines,
491 args.minimumHorizontalScale);
492 return ConfiguredArrangement { std::move (arrangement), {} };
495 GlyphArrangementCache<ArrangementArgs>::getInstance()->draw (*
this,
496 {
context.getFont(),
text, area.
toFloat(), justification, maximumNumberOfLines, minimumHorizontalScale },
497 std::move (configureArrangement));
502 const int maximumNumberOfLines,
503 const float minimumHorizontalScale)
const
506 justification, maximumNumberOfLines, minimumHorizontalScale);
532 context.fillRectList (rectangles);
537 for (
auto&
r : rects)
550 auto clip =
context.getClipBounds();
554 context.fillRect (clip,
false);
570 context.fillPath (path, transform);
595 drawRect (
r.toFloat(), (
float) lineThickness);
600 jassert (
r.getWidth() >= 0.0f &&
r.getHeight() >= 0.0f);
635 p.addEllipse (area.
expanded (lineThickness * 0.5f));
636 p.addEllipse (area.
reduced (lineThickness * 0.5f));
637 p.setUsingNonZeroWinding (
false);
655 p.addRoundedRectangle (
r, cornerSize);
660 float cornerSize,
float lineThickness)
const
668 p.addRoundedRectangle (
r, cornerSize);
675 p.addArrow (line, lineThickness, arrowheadWidth, arrowheadLength);
682 jassert (checkWidth > 0 && checkHeight > 0);
684 if (checkWidth > 0 && checkHeight > 0)
688 if (colour1 == colour2)
697 if (! clipped.isEmpty())
699 const int checkNumX = (
int) (((
float) clipped.getX() - area.
getX()) / checkWidth);
700 const int checkNumY = (
int) (((
float) clipped.getY() - area.
getY()) / checkHeight);
701 const float startX = area.
getX() + (float) checkNumX * checkWidth;
702 const float startY = area.
getY() + (float) checkNumY * checkHeight;
703 const float right = (float) clipped.getRight();
704 const float bottom = (float) clipped.getBottom();
706 for (
int i = 0;
i < 2; ++
i)
711 for (
float y = startY;
y < bottom;
y += checkHeight)
712 for (
float x = startX + (cy++ & 1) * checkWidth;
x <
right;
x += checkWidth * 2.0f)
716 context.setFill (
i == ((checkNumX ^ checkNumY) & 1) ? colour1 : colour2);
757 p.addLineSegment (line, lineThickness);
762 int numDashLengths,
float lineThickness,
int n)
const
771 const double onePixAlpha = 1.0 / totalLen;
773 for (
double alpha = 0.0; alpha < 1.0;)
777 const double lastAlpha = alpha;
778 alpha += dashLengths [
n] * onePixAlpha;
779 n = (
n + 1) % numDashLengths;
784 line.
getStart() + (delta *
jmin (1.0, alpha)).toFloat());
786 if (lineThickness != 1.0f)
799 context.setInterpolationQuality (newQuality);
811 RectanglePlacement placementWithinTarget,
bool fillAlphaChannelWithCurrentBrush)
const
816 fillAlphaChannelWithCurrentBrush);
820 RectanglePlacement placementWithinTarget,
bool fillAlphaChannelWithCurrentBrush)
const
822 drawImage (imageToDraw, coordsToRectangle (dx,
dy, dw, dh).toFloat(),
823 placementWithinTarget, fillAlphaChannelWithCurrentBrush);
827 int dx,
int dy,
int dw,
int dh,
828 int sx,
int sy,
int sw,
int sh,
829 const bool fillAlphaChannelWithCurrentBrush)
const
831 if (imageToDraw.
isValid() &&
context.clipRegionIntersects (coordsToRectangle (dx,
dy, dw, dh)))
834 .translated ((
float) dx, (
float)
dy),
835 fillAlphaChannelWithCurrentBrush);
840 const bool fillAlphaChannelWithCurrentBrush)
const
844 if (fillAlphaChannelWithCurrentBrush)
847 context.clipToImageAlpha (imageToDraw, transform);
853 context.drawImage (imageToDraw, transform);
#define noexcept
Definition DistrhoDefines.h:72
#define final
Definition DistrhoDefines.h:74
static void drawLine(const Point< T > &posStart, const Point< T > &posEnd)
Definition OpenGL.cpp:79
uint8_t a
Definition Spc_Cpu.h:141
Definition juce_ColourGradient.h:38
Definition juce_Colour.h:38
bool isTransparent() const noexcept
Definition juce_Colour.cpp:307
Definition juce_FillType.h:41
Definition juce_Font.h:42
static bool compare(const Font &, const Font &) noexcept
Definition juce_Font.cpp:426
Definition juce_GlyphArrangement.h:117
void addLineOfText(const Font &font, const String &text, float x, float y)
Definition juce_GlyphArrangement.cpp:144
Rectangle< float > getBoundingBox(int startIndex, int numGlyphs, bool includeWhitespace) const
Definition juce_GlyphArrangement.cpp:441
int getNumGlyphs() const noexcept
Definition juce_GlyphArrangement.h:133
void addFittedText(const Font &font, const String &text, float x, float y, float width, float height, Justification layout, int maximumLinesToUse, float minimumHorizontalScale=0.0f)
Definition juce_GlyphArrangement.cpp:310
void addCurtailedLineOfText(const Font &font, const String &text, float x, float y, float maxWidthPixels, bool useEllipsis)
Definition juce_GlyphArrangement.cpp:149
void addJustifiedText(const Font &font, const String &text, float x, float y, float maxLineWidth, Justification horizontalLayout, float leading=0.0f)
Definition juce_GlyphArrangement.cpp:228
void justifyGlyphs(int startIndex, int numGlyphs, float x, float y, float width, float height, Justification justification)
Definition juce_GlyphArrangement.cpp:461
~ScopedSaveState()
Definition juce_GraphicsContext.cpp:864
Graphics & context
Definition juce_GraphicsContext.h:666
ScopedSaveState(Graphics &)
Definition juce_GraphicsContext.cpp:859
void saveState()
Definition juce_GraphicsContext.cpp:221
void drawImage(const Image &imageToDraw, int destX, int destY, int destWidth, int destHeight, int sourceX, int sourceY, int sourceWidth, int sourceHeight, bool fillAlphaChannelWithCurrentBrush=false) const
Definition juce_GraphicsContext.cpp:826
void setOpacity(float newOpacity)
Definition juce_GraphicsContext.cpp:284
void drawText(const String &text, int x, int y, int width, int height, Justification justificationType, bool useEllipsesIfTooBig=true) const
Definition juce_GraphicsContext.cpp:456
void saveStateIfPending()
Definition juce_GraphicsContext.cpp:235
void drawFittedText(const String &text, int x, int y, int width, int height, Justification justificationFlags, int maximumNumberOfLines, float minimumHorizontalScale=0.0f) const
Definition juce_GraphicsContext.cpp:500
Font getCurrentFont() const
Definition juce_GraphicsContext.cpp:325
void setFont(const Font &newFont)
Definition juce_GraphicsContext.cpp:314
void fillRectList(const RectangleList< float > &rectangles) const
Definition juce_GraphicsContext.cpp:530
void restoreState()
Definition juce_GraphicsContext.cpp:227
ResamplingQuality
Definition juce_GraphicsContext.h:462
@ mediumResamplingQuality
Definition juce_GraphicsContext.h:464
bool isClipEmpty() const
Definition juce_GraphicsContext.cpp:211
void setFillType(const FillType &newFill)
Definition juce_GraphicsContext.cpp:307
void drawImageAt(const Image &imageToDraw, int topLeftX, int topLeftY, bool fillAlphaChannelWithCurrentBrush=false) const
Definition juce_GraphicsContext.cpp:803
void drawArrow(Line< float > line, float lineThickness, float arrowheadWidth, float arrowheadLength) const
Definition juce_GraphicsContext.cpp:672
void drawImageWithin(const Image &imageToDraw, int destX, int destY, int destWidth, int destHeight, RectanglePlacement placementWithinTarget, bool fillAlphaChannelWithCurrentBrush=false) const
Definition juce_GraphicsContext.cpp:819
void setGradientFill(const ColourGradient &gradient)
Definition juce_GraphicsContext.cpp:290
void setImageResamplingQuality(const ResamplingQuality newQuality)
Definition juce_GraphicsContext.cpp:796
void fillRoundedRectangle(float x, float y, float width, float height, float cornerSize) const
Definition juce_GraphicsContext.cpp:647
void excludeClipRegion(Rectangle< int > rectangleToExclude)
Definition juce_GraphicsContext.cpp:205
void drawRect(int x, int y, int width, int height, int lineThickness=1) const
Definition juce_GraphicsContext.cpp:588
void endTransparencyLayer()
Definition juce_GraphicsContext.cpp:272
void drawImageTransformed(const Image &imageToDraw, const AffineTransform &transform, bool fillAlphaChannelWithCurrentBrush=false) const
Definition juce_GraphicsContext.cpp:838
LowLevelGraphicsContext & context
Definition juce_GraphicsContext.h:741
void setTiledImageFill(const Image &imageToUse, int anchorX, int anchorY, float opacity)
Definition juce_GraphicsContext.cpp:300
void addTransform(const AffineTransform &transform)
Definition juce_GraphicsContext.cpp:255
bool clipRegionIntersects(Rectangle< int > area) const
Definition juce_GraphicsContext.cpp:261
void fillRect(Rectangle< int > rectangle) const
Definition juce_GraphicsContext.cpp:510
void drawVerticalLine(int x, float top, float bottom) const
Definition juce_GraphicsContext.cpp:727
void beginTransparencyLayer(float layerOpacity)
Definition juce_GraphicsContext.cpp:266
void drawMultiLineText(const String &text, int startX, int baselineY, int maximumLineWidth, Justification justification=Justification::left, float leading=0.0f) const
Definition juce_GraphicsContext.cpp:382
void fillPath(const Path &path) const
Definition juce_GraphicsContext.cpp:561
Graphics(const Image &imageToDrawOnto)
Definition juce_GraphicsContext.cpp:148
void resetToDefaultState()
Definition juce_GraphicsContext.cpp:161
void drawEllipse(float x, float y, float width, float height, float lineThickness) const
Definition juce_GraphicsContext.cpp:623
void drawSingleLineText(const String &text, int startX, int baselineY, Justification justification=Justification::left) const
Definition juce_GraphicsContext.cpp:331
bool reduceClipRegion(int x, int y, int width, int height)
Definition juce_GraphicsContext.cpp:180
bool saveStatePending
Definition juce_GraphicsContext.h:743
void fillCheckerBoard(Rectangle< float > area, float checkWidth, float checkHeight, Colour colour1, Colour colour2) const
Definition juce_GraphicsContext.cpp:679
Rectangle< int > getClipBounds() const
Definition juce_GraphicsContext.cpp:216
bool isVectorDevice() const
Definition juce_GraphicsContext.cpp:169
void drawHorizontalLine(int y, float left, float right) const
Definition juce_GraphicsContext.cpp:733
void setColour(Colour newColour)
Definition juce_GraphicsContext.cpp:278
std::unique_ptr< LowLevelGraphicsContext > contextHolder
Definition juce_GraphicsContext.h:740
void drawLine(float startX, float startY, float endX, float endY) const
Definition juce_GraphicsContext.cpp:744
void strokePath(const Path &path, const PathStrokeType &strokeType, const AffineTransform &transform={}) const
Definition juce_GraphicsContext.cpp:573
void fillAll() const
Definition juce_GraphicsContext.cpp:541
void setOrigin(Point< int > newOrigin)
Definition juce_GraphicsContext.cpp:244
void drawRoundedRectangle(float x, float y, float width, float height, float cornerSize, float lineThickness) const
Definition juce_GraphicsContext.cpp:659
void drawDashedLine(Line< float > line, const float *dashLengths, int numDashLengths, float lineThickness=1.0f, int dashIndexToStartFrom=0) const
Definition juce_GraphicsContext.cpp:761
void fillEllipse(float x, float y, float width, float height) const
Definition juce_GraphicsContext.cpp:618
Definition juce_Image.h:58
Image getClippedImage(const Rectangle< int > &area) const
Definition juce_Image.cpp:210
Rectangle< int > getBounds() const noexcept
Definition juce_Image.cpp:273
bool isValid() const noexcept
Definition juce_Image.h:147
Definition juce_Justification.h:41
@ horizontallyJustified
Definition juce_Justification.h:132
@ left
Definition juce_Justification.h:108
@ horizontallyCentred
Definition juce_Justification.h:115
@ right
Definition juce_Justification.h:111
int getOnlyVerticalFlags() const noexcept
Definition juce_Justification.h:66
int getOnlyHorizontalFlags() const noexcept
Definition juce_Justification.h:69
Definition juce_Line.h:47
Point< ValueType > getEnd() const noexcept
Definition juce_Line.h:91
Point< ValueType > getStart() const noexcept
Definition juce_Line.h:88
Definition juce_LowLevelGraphicsContext.h:46
Definition juce_Path.h:65
bool isEmpty() const noexcept
Definition juce_Path.cpp:179
Definition juce_PathStrokeType.h:42
void createStrokedPath(Path &destPath, const Path &sourcePath, const AffineTransform &transform=AffineTransform(), float extraAccuracy=1.0f) const
Definition juce_PathStrokeType.cpp:655
Definition juce_Point.h:42
ValueType getDistanceFromOrigin() const noexcept
Definition juce_Point.h:157
Definition juce_Rectangle.h:67
Rectangle< float > toFloat() const noexcept
Definition juce_Rectangle.h:873
Rectangle< int > getSmallestIntegerContainer() const noexcept
Definition juce_Rectangle.h:840
ValueType getHeight() const noexcept
Definition juce_Rectangle.h:136
ValueType getX() const noexcept
Definition juce_Rectangle.h:127
ValueType getWidth() const noexcept
Definition juce_Rectangle.h:133
Rectangle reduced(ValueType deltaX, ValueType deltaY) const noexcept
Definition juce_Rectangle.h:485
bool isEmpty() const noexcept
Definition juce_Rectangle.h:121
ValueType getY() const noexcept
Definition juce_Rectangle.h:130
Rectangle expanded(ValueType deltaX, ValueType deltaY) const noexcept
Definition juce_Rectangle.h:451
Definition juce_RectangleList.h:43
void addWithoutMerging(RectangleType rect)
Definition juce_RectangleList.h:180
bool clipTo(RectangleType rect)
Definition juce_RectangleList.h:314
Definition juce_RectanglePlacement.h:40
AffineTransform getTransformToFit(const Rectangle< float > &source, const Rectangle< float > &destination) const noexcept
Definition juce_RectanglePlacement.cpp:82
Definition juce_String.h:53
UINT_D64 w
Definition inflate.c:942
struct huft * t
Definition inflate.c:943
int y
Definition inflate.c:1588
int g
Definition inflate.c:1573
register unsigned i
Definition inflate.c:1575
unsigned x[BMAX+1]
Definition inflate.c:1586
struct @113205115357366127300225113341150224053346037032::@137033172036070230260373056156374243321245367362 left
struct @113205115357366127300225113341150224053346037032::@137033172036070230260373056156374243321245367362 right
static int int height
Definition pugl.h:1594
static int width
Definition pugl.h:1593
#define JUCE_DECLARE_SINGLETON(Classname, doNotRecreateAfterDeletion)
Definition juce_Singleton.h:184
Definition carla_juce.cpp:31
constexpr Type jmin(Type a, Type b)
Definition juce_MathsFunctions.h:106
CriticalSection::ScopedTryLockType ScopedTryLock
Definition juce_CriticalSection.h:260
static auto tie(const AudioDeviceManager::AudioDeviceSetup &s)
Definition juce_AudioDeviceManager.cpp:41
@ image
Definition juce_AccessibilityRole.h:42
jack_client_t client jack_client_t client jack_client_t client jack_client_t JackInfoShutdownCallback void arg jack_client_t jack_port_t port void func jack_client_t const char const char unsigned long flags
Definition juce_linux_JackAudio.cpp:69
Definition juce_GraphicsContext.cpp:30
static auto compareFont(const Font &a, const Font &b)
Definition juce_GraphicsContext.cpp:31
const char * text
Definition swell-functions.h:167
void Rectangle(HDC ctx, int l, int t, int r, int b)
Definition swell-gdi-generic.cpp:279
int n
Definition crypt.c:458
uch * p
Definition crypt.c:594
int r
Definition crypt.c:458
uch h[RAND_HEAD_LEN]
Definition crypt.c:459
int result
Definition process.c:1455
typedef int(UZ_EXP MsgFn)()
dy
Definition zipinfo.c:2288