diff options
author | Neil <nyamatongwe@gmail.com> | 2021-03-20 09:24:43 +1100 |
---|---|---|
committer | Neil <nyamatongwe@gmail.com> | 2021-03-20 09:24:43 +1100 |
commit | 6c56011f882cdfa758898029be5cabe82fc9228c (patch) | |
tree | 7b9720ac901dcaa37a7d93035d34b5c9bd536897 | |
parent | 6ca286d41a1ca8e6d948d131fdaaf8b8199c905e (diff) | |
download | scintilla-mirror-6c56011f882cdfa758898029be5cabe82fc9228c.tar.gz |
Implement RectangleFrame.
-rw-r--r-- | cocoa/PlatCocoa.h | 1 | ||||
-rw-r--r-- | cocoa/PlatCocoa.mm | 18 | ||||
-rwxr-xr-x | gtk/PlatGTK.cxx | 10 | ||||
-rw-r--r-- | qt/ScintillaEditBase/PlatQt.cpp | 8 | ||||
-rw-r--r-- | qt/ScintillaEditBase/PlatQt.h | 1 | ||||
-rw-r--r-- | src/Platform.h | 1 | ||||
-rw-r--r-- | win32/PlatWin.cxx | 18 |
7 files changed, 57 insertions, 0 deletions
diff --git a/cocoa/PlatCocoa.h b/cocoa/PlatCocoa.h index 4487d9945..36022286c 100644 --- a/cocoa/PlatCocoa.h +++ b/cocoa/PlatCocoa.h @@ -100,6 +100,7 @@ public: void Polygon(const Scintilla::Point *pts, size_t npts, FillStroke fillStroke) override; void RectangleDraw(PRectangle rc, ColourDesired fore, ColourDesired back) override; void RectangleDraw(PRectangle rc, FillStroke fillStroke) override; + void RectangleFrame(PRectangle rc, Stroke stroke) override; void FillRectangle(PRectangle rc, ColourDesired back) override; void FillRectangle(PRectangle rc, Fill fill) override; void FillRectangle(PRectangle rc, Surface &surfacePattern) override; diff --git a/cocoa/PlatCocoa.mm b/cocoa/PlatCocoa.mm index 618d17de1..55a6ee620 100644 --- a/cocoa/PlatCocoa.mm +++ b/cocoa/PlatCocoa.mm @@ -737,6 +737,24 @@ void SurfaceImpl::RectangleDraw(PRectangle rc, FillStroke fillStroke) { //-------------------------------------------------------------------------------------------------- +void SurfaceImpl::RectangleFrame(PRectangle rc, Stroke stroke) { + if (!gc) + return; + + CGContextBeginPath(gc); + PenColourAlpha(stroke.colour); + CGContextSetLineWidth(gc, stroke.width); + + CGContextAddRect(gc, CGRectFromPRectangleInset(rc, stroke.width)); + + CGContextDrawPath(gc, kCGPathStroke); + + // Restore as not all paths set + CGContextSetLineWidth(gc, 1.0f); +} + +//-------------------------------------------------------------------------------------------------- + void SurfaceImpl::FillRectangle(PRectangle rc, ColourDesired back) { if (gc) { FillColour(back); diff --git a/gtk/PlatGTK.cxx b/gtk/PlatGTK.cxx index b71689007..0b87b8743 100755 --- a/gtk/PlatGTK.cxx +++ b/gtk/PlatGTK.cxx @@ -165,6 +165,7 @@ public: void Polygon(const Point *pts, size_t npts, FillStroke fillStroke) override; void RectangleDraw(PRectangle rc, ColourDesired fore, ColourDesired back) override; void RectangleDraw(PRectangle rc, FillStroke fillStroke) override; + void RectangleFrame(PRectangle rc, Stroke stroke) override; void FillRectangle(PRectangle rc, ColourDesired back) override; void FillRectangle(PRectangle rc, Fill fill) override; void FillRectangle(PRectangle rc, Surface &surfacePattern) override; @@ -534,6 +535,15 @@ void SurfaceImpl::RectangleDraw(PRectangle rc, FillStroke fillStroke) { } } +void SurfaceImpl::RectangleFrame(PRectangle rc, Stroke stroke) { + if (context) { + CairoRectangle(rc.Inset(stroke.width / 2)); + PenColourAlpha(stroke.colour); + cairo_set_line_width(context, stroke.width); + cairo_stroke(context); + } +} + void SurfaceImpl::FillRectangle(PRectangle rc, ColourDesired back) { PenColour(back); if (context && (rc.left < maxCoordinate)) { // Protect against out of range diff --git a/qt/ScintillaEditBase/PlatQt.cpp b/qt/ScintillaEditBase/PlatQt.cpp index 6c7f789ce..fa4c062d8 100644 --- a/qt/ScintillaEditBase/PlatQt.cpp +++ b/qt/ScintillaEditBase/PlatQt.cpp @@ -346,6 +346,14 @@ void SurfaceImpl::RectangleDraw(PRectangle rc, FillStroke fillStroke) GetPainter()->drawRect(rect); } +void SurfaceImpl::RectangleFrame(PRectangle rc, Stroke stroke) { + PenColourWidth(stroke.colour, stroke.width); + // Default QBrush is Qt::NoBrush so does not fill + GetPainter()->setBrush(QBrush()); + const QRectF rect = QRectFFromPRect(rc.Inset(stroke.width / 2)); + GetPainter()->drawRect(rect); +} + void SurfaceImpl::FillRectangle(PRectangle rc, ColourDesired back) { GetPainter()->fillRect(QRectFFromPRect(rc), QColorFromCA(back)); diff --git a/qt/ScintillaEditBase/PlatQt.h b/qt/ScintillaEditBase/PlatQt.h index 12f3e7726..2ca31da2d 100644 --- a/qt/ScintillaEditBase/PlatQt.h +++ b/qt/ScintillaEditBase/PlatQt.h @@ -110,6 +110,7 @@ public: void RectangleDraw(PRectangle rc, ColourDesired fore, ColourDesired back) override; void RectangleDraw(PRectangle rc, FillStroke fillStroke) override; + void RectangleFrame(PRectangle rc, Stroke stroke) override; void FillRectangle(PRectangle rc, ColourDesired back) override; void FillRectangle(PRectangle rc, Fill fill) override; void FillRectangle(PRectangle rc, Surface &surfacePattern) override; diff --git a/src/Platform.h b/src/Platform.h index 6848e4d4f..4c7b6523d 100644 --- a/src/Platform.h +++ b/src/Platform.h @@ -192,6 +192,7 @@ public: virtual void Polygon(const Point *pts, size_t npts, FillStroke fillStroke)=0; virtual void RectangleDraw(PRectangle rc, ColourDesired fore, ColourDesired back)=0; virtual void RectangleDraw(PRectangle rc, FillStroke fillStroke)=0; + virtual void RectangleFrame(PRectangle rc, Stroke stroke)=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; diff --git a/win32/PlatWin.cxx b/win32/PlatWin.cxx index dacea8522..eac743ef3 100644 --- a/win32/PlatWin.cxx +++ b/win32/PlatWin.cxx @@ -492,6 +492,7 @@ public: void Polygon(const Point *pts, size_t npts, FillStroke fillStroke) override; void RectangleDraw(PRectangle rc, ColourDesired fore, ColourDesired back) override; void RectangleDraw(PRectangle rc, FillStroke fillStroke) override; + void RectangleFrame(PRectangle rc, Stroke stroke) override; void FillRectangle(PRectangle rc, ColourDesired back) override; void FillRectangle(PRectangle rc, Fill fill) override; void FillRectangle(PRectangle rc, Surface &surfacePattern) override; @@ -723,6 +724,12 @@ void SurfaceGDI::RectangleDraw(PRectangle rc, FillStroke fillStroke) { FillRectangle(rc.Inset(fillStroke.stroke.width), fillStroke.fill.colour); } +void SurfaceGDI::RectangleFrame(PRectangle rc, Stroke stroke) { + BrushColour(stroke.colour); + const RECT rcw = RectFromPRectangle(rc); + ::FrameRect(hdc, &rcw, brush); +} + void SurfaceGDI::FillRectangle(PRectangle rc, ColourDesired back) { // Using ExtTextOut rather than a FillRect ensures that no dithering occurs. // There is no need to allocate a brush either. @@ -1416,6 +1423,7 @@ public: void Polygon(const Point *pts, size_t npts, FillStroke fillStroke) override; void RectangleDraw(PRectangle rc, ColourDesired fore, ColourDesired back) override; void RectangleDraw(PRectangle rc, FillStroke fillStroke) override; + void RectangleFrame(PRectangle rc, Stroke stroke) override; void FillRectangle(PRectangle rc, ColourDesired back) override; void FillRectangle(PRectangle rc, Fill fill) override; void FillRectangle(PRectangle rc, Surface &surfacePattern) override; @@ -1759,6 +1767,16 @@ void SurfaceD2D::RectangleDraw(PRectangle rc, FillStroke fillStroke) { pRenderTarget->DrawRectangle(&rectOutline, pBrush, fillStroke.stroke.width); } +void SurfaceD2D::RectangleFrame(PRectangle rc, Stroke stroke) { + if (pRenderTarget) { + const XYPOSITION halfStroke = stroke.width / 2.0f; + const D2D1_RECT_F rectangle1 = D2D1::RectF(rc.left + halfStroke, rc.top + halfStroke, + rc.right - halfStroke, rc.bottom - halfStroke); + D2DPenColourAlpha(stroke.colour); + pRenderTarget->DrawRectangle(&rectangle1, pBrush, stroke.width); + } +} + void SurfaceD2D::FillRectangle(PRectangle rc, ColourDesired back) { if (pRenderTarget) { D2DPenColour(back); |