diff options
-rw-r--r-- | cocoa/PlatCocoa.h | 2 | ||||
-rw-r--r-- | cocoa/PlatCocoa.mm | 21 | ||||
-rwxr-xr-x | gtk/PlatGTK.cxx | 27 | ||||
-rw-r--r-- | qt/ScintillaEditBase/PlatQt.cpp | 5 | ||||
-rw-r--r-- | qt/ScintillaEditBase/PlatQt.h | 1 | ||||
-rw-r--r-- | src/Platform.h | 1 | ||||
-rw-r--r-- | win32/PlatWin.cxx | 58 |
7 files changed, 92 insertions, 23 deletions
diff --git a/cocoa/PlatCocoa.h b/cocoa/PlatCocoa.h index b918e5ed0..98a9b11ed 100644 --- a/cocoa/PlatCocoa.h +++ b/cocoa/PlatCocoa.h @@ -60,6 +60,7 @@ private: /** Set the CGContext's fill colour to the specified desired colour. */ void FillColour(const ColourDesired &back); + void FillColour(ColourAlpha fill); // 24-bit RGB+A bitmap data constants @@ -95,6 +96,7 @@ public: void Polygon(Scintilla::Point *pts, size_t npts, ColourDesired fore, ColourDesired back) override; void RectangleDraw(PRectangle rc, ColourDesired fore, ColourDesired back) override; void FillRectangle(PRectangle rc, ColourDesired back) override; + void FillRectangle(PRectangle rc, Fill fill) override; void FillRectangle(PRectangle rc, Surface &surfacePattern) override; void RoundedRectangle(PRectangle rc, ColourDesired fore, ColourDesired back) override; void AlphaRectangle(PRectangle rc, int cornerSize, ColourDesired fill, int alphaFill, diff --git a/cocoa/PlatCocoa.mm b/cocoa/PlatCocoa.mm index f84a335aa..a4f01c5c6 100644 --- a/cocoa/PlatCocoa.mm +++ b/cocoa/PlatCocoa.mm @@ -479,6 +479,17 @@ void SurfaceImpl::PenColour(ColourDesired fore) { //-------------------------------------------------------------------------------------------------- +void SurfaceImpl::FillColour(ColourAlpha fill) { + // Set the Fill color to match + CGContextSetRGBFillColor(gc, + fill.GetRedComponent(), + fill.GetGreenComponent(), + fill.GetBlueComponent(), + fill.GetAlphaComponent()); +} + +//-------------------------------------------------------------------------------------------------- + void SurfaceImpl::FillColour(const ColourDesired &back) { if (gc) { ColourDesired colour(back.AsInteger()); @@ -662,6 +673,16 @@ void SurfaceImpl::FillRectangle(PRectangle rc, ColourDesired back) { //-------------------------------------------------------------------------------------------------- +void SurfaceImpl::FillRectangle(PRectangle rc, Fill fill) { + if (gc) { + FillColour(fill.colour); + CGRect rect = PRectangleToCGRect(rc); + CGContextFillRect(gc, rect); + } +} + +//-------------------------------------------------------------------------------------------------- + static void drawImageRefCallback(void *info, CGContextRef gc) { CGImageRef pattern = static_cast<CGImageRef>(info); CGContextDrawImage(gc, CGRectMake(0, 0, CGImageGetWidth(pattern), CGImageGetHeight(pattern)), pattern); diff --git a/gtk/PlatGTK.cxx b/gtk/PlatGTK.cxx index b9c049f1d..3debf8fc8 100755 --- a/gtk/PlatGTK.cxx +++ b/gtk/PlatGTK.cxx @@ -155,6 +155,7 @@ public: int Supports(int feature) noexcept override; bool Initialised() override; void PenColour(ColourDesired fore) override; + void PenColourAlpha(ColourAlpha fore); int LogPixelsY() override; int PixelDivisions() override; int DeviceHeightFont(int points) override; @@ -163,6 +164,7 @@ public: void Polygon(Point *pts, size_t npts, ColourDesired fore, ColourDesired back) override; void RectangleDraw(PRectangle rc, ColourDesired fore, ColourDesired back) override; void FillRectangle(PRectangle rc, ColourDesired back) override; + void FillRectangle(PRectangle rc, Fill fill) override; void FillRectangle(PRectangle rc, Surface &surfacePattern) override; void RoundedRectangle(PRectangle rc, ColourDesired fore, ColourDesired back) override; void AlphaRectangle(PRectangle rc, int cornerSize, ColourDesired fill, int alphaFill, @@ -399,11 +401,20 @@ int SurfaceImpl::Supports(int feature) noexcept { void SurfaceImpl::PenColour(ColourDesired fore) { if (context) { - const ColourDesired cdFore(fore.AsInteger()); cairo_set_source_rgb(context, - cdFore.GetRed() / 255.0, - cdFore.GetGreen() / 255.0, - cdFore.GetBlue() / 255.0); + fore.GetRed() / 255.0, + fore.GetGreen() / 255.0, + fore.GetBlue() / 255.0); + } +} + +void SurfaceImpl::PenColourAlpha(ColourAlpha fore) { + if (context) { + cairo_set_source_rgba(context, + fore.GetRed() / 255.0, + fore.GetGreen() / 255.0, + fore.GetBlue() / 255.0, + fore.GetAlpha() / 255.0); } } @@ -503,6 +514,14 @@ void SurfaceImpl::FillRectangle(PRectangle rc, ColourDesired back) { } } +void SurfaceImpl::FillRectangle(PRectangle rc, Fill fill) { + PenColourAlpha(fill.colour); + if (context && (rc.left < maxCoordinate)) { // Protect against out of range + CairoRectangle(rc); + cairo_fill(context); + } +} + void SurfaceImpl::FillRectangle(PRectangle rc, Surface &surfacePattern) { SurfaceImpl &surfi = dynamic_cast<SurfaceImpl &>(surfacePattern); if (context && surfi.psurf) { diff --git a/qt/ScintillaEditBase/PlatQt.cpp b/qt/ScintillaEditBase/PlatQt.cpp index a1adf0a0d..37fc409f7 100644 --- a/qt/ScintillaEditBase/PlatQt.cpp +++ b/qt/ScintillaEditBase/PlatQt.cpp @@ -319,6 +319,11 @@ void SurfaceImpl::FillRectangle(PRectangle rc, ColourDesired back) GetPainter()->fillRect(QRectFFromPRect(rc), QColorFromCA(back)); } +void SurfaceImpl::FillRectangle(PRectangle rc, Fill fill) +{ + GetPainter()->fillRect(QRectFFromPRect(rc), QColorFromColourAlpha(fill.colour)); +} + void SurfaceImpl::FillRectangle(PRectangle rc, Surface &surfacePattern) { // Tile pattern over rectangle diff --git a/qt/ScintillaEditBase/PlatQt.h b/qt/ScintillaEditBase/PlatQt.h index a743a4be5..173bd53d5 100644 --- a/qt/ScintillaEditBase/PlatQt.h +++ b/qt/ScintillaEditBase/PlatQt.h @@ -103,6 +103,7 @@ public: void RectangleDraw(PRectangle rc, ColourDesired fore, ColourDesired back) override; void FillRectangle(PRectangle rc, ColourDesired back) override; + void FillRectangle(PRectangle rc, Fill fill) override; void FillRectangle(PRectangle rc, Surface &surfacePattern) override; void RoundedRectangle(PRectangle rc, ColourDesired fore, ColourDesired back) override; diff --git a/src/Platform.h b/src/Platform.h index 45c04abdc..abad8abfa 100644 --- a/src/Platform.h +++ b/src/Platform.h @@ -191,6 +191,7 @@ public: virtual void Polygon(Point *pts, size_t npts, ColourDesired fore, ColourDesired back)=0; virtual void RectangleDraw(PRectangle rc, ColourDesired fore, ColourDesired back)=0; virtual void FillRectangle(PRectangle rc, ColourDesired back)=0; + virtual void FillRectangle(PRectangle rc, Fill fill)=0; virtual void FillRectangle(PRectangle rc, Surface &surfacePattern)=0; virtual void RoundedRectangle(PRectangle rc, ColourDesired fore, ColourDesired back)=0; virtual void AlphaRectangle(PRectangle rc, int cornerSize, ColourDesired fill, int alphaFill, diff --git a/win32/PlatWin.cxx b/win32/PlatWin.cxx index 3f93a96fd..3fae8e90f 100644 --- a/win32/PlatWin.cxx +++ b/win32/PlatWin.cxx @@ -489,6 +489,7 @@ public: void Polygon(Point *pts, size_t npts, ColourDesired fore, ColourDesired back) override; void RectangleDraw(PRectangle rc, ColourDesired fore, ColourDesired back) override; void FillRectangle(PRectangle rc, ColourDesired back) override; + void FillRectangle(PRectangle rc, Fill fill) override; void FillRectangle(PRectangle rc, Surface &surfacePattern) override; void RoundedRectangle(PRectangle rc, ColourDesired fore, ColourDesired back) override; void AlphaRectangle(PRectangle rc, int cornerSize, ColourDesired fill, int alphaFill, @@ -688,6 +689,20 @@ void SurfaceGDI::FillRectangle(PRectangle rc, ColourDesired back) { ::ExtTextOut(hdc, rcw.left, rcw.top, ETO_OPAQUE, &rcw, TEXT(""), 0, nullptr); } +void SurfaceGDI::FillRectangle(PRectangle rc, Fill fill) { + if (fill.colour.IsOpaque()) { + // Using ExtTextOut rather than a FillRect ensures that no dithering occurs. + // There is no need to allocate a brush either. + const RECT rcw = RectFromPRectangle(rc); + ::SetBkColor(hdc, fill.colour.GetColour().AsInteger()); + ::ExtTextOut(hdc, rcw.left, rcw.top, ETO_OPAQUE, &rcw, TEXT(""), 0, nullptr); + } else { + const ColourDesired fillOpaque = fill.colour.GetColour(); + const int alpha = fill.colour.GetAlpha(); + AlphaRectangle(rc, 0, fillOpaque, alpha, fillOpaque, alpha, 0); + } +} + void SurfaceGDI::FillRectangle(PRectangle rc, Surface &surfacePattern) { HBRUSH br; if (SurfaceGDI *psgdi = dynamic_cast<SurfaceGDI *>(&surfacePattern); psgdi && psgdi->bitmap) { @@ -1218,6 +1233,15 @@ const int SupportsD2D[] = { SC_SUPPORTS_LINE_DRAWS_FINAL, }; +constexpr D2D_COLOR_F ColorFromColourAlpha(ColourAlpha colour) noexcept { + return D2D_COLOR_F{ + colour.GetRedComponent(), + colour.GetGreenComponent(), + colour.GetBlueComponent(), + colour.GetAlphaComponent() + }; +} + } class BlobInline; @@ -1267,6 +1291,7 @@ public: void PenColour(ColourDesired fore) override; void D2DPenColour(ColourDesired fore, int alpha=255); + void D2DPenColourAlpha(ColourAlpha fore) noexcept; int LogPixelsY() override; int PixelDivisions() override; int DeviceHeightFont(int points) override; @@ -1275,6 +1300,7 @@ public: void Polygon(Point *pts, size_t npts, ColourDesired fore, ColourDesired back) override; void RectangleDraw(PRectangle rc, ColourDesired fore, ColourDesired back) override; void FillRectangle(PRectangle rc, ColourDesired back) override; + void FillRectangle(PRectangle rc, Fill fill) override; void FillRectangle(PRectangle rc, Surface &surfacePattern) override; void RoundedRectangle(PRectangle rc, ColourDesired fore, ColourDesired back) override; void AlphaRectangle(PRectangle rc, int cornerSize, ColourDesired fill, int alphaFill, @@ -1426,13 +1452,12 @@ void SurfaceD2D::PenColour(ColourDesired fore) { } void SurfaceD2D::D2DPenColour(ColourDesired fore, int alpha) { + D2DPenColourAlpha(ColourAlpha(fore, alpha)); +} + +void SurfaceD2D::D2DPenColourAlpha(ColourAlpha fore) noexcept { if (pRenderTarget) { - const D2D_COLOR_F col { - fore.GetRedComponent(), - fore.GetGreenComponent(), - fore.GetBlueComponent(), - alpha / 255.0f - }; + const D2D_COLOR_F col = ColorFromColourAlpha(fore); if (pBrush) { pBrush->SetColor(col); } else { @@ -1573,6 +1598,14 @@ void SurfaceD2D::FillRectangle(PRectangle rc, ColourDesired back) { } } +void SurfaceD2D::FillRectangle(PRectangle rc, Fill fill) { + if (pRenderTarget) { + D2DPenColourAlpha(fill.colour); + const D2D1_RECT_F rectangle = RectangleFromPRectangle(rc); + pRenderTarget->FillRectangle(&rectangle, pBrush); + } +} + void SurfaceD2D::FillRectangle(PRectangle rc, Surface &surfacePattern) { SurfaceD2D *psurfOther = dynamic_cast<SurfaceD2D *>(&surfacePattern); PLATFORM_ASSERT(psurfOther); @@ -1640,19 +1673,6 @@ void SurfaceD2D::AlphaRectangle(PRectangle rc, int cornerSize, ColourDesired fil } } -namespace { - -constexpr D2D_COLOR_F ColorFromColourAlpha(ColourAlpha colour) noexcept { - return D2D_COLOR_F{ - colour.GetRedComponent(), - colour.GetGreenComponent(), - colour.GetBlueComponent(), - colour.GetAlphaComponent() - }; -} - -} - void SurfaceD2D::GradientRectangle(PRectangle rc, const std::vector<ColourStop> &stops, GradientOptions options) { if (pRenderTarget) { D2D1_LINEAR_GRADIENT_BRUSH_PROPERTIES lgbp { |