diff options
author | Neil <nyamatongwe@gmail.com> | 2018-05-22 09:08:54 +1000 |
---|---|---|
committer | Neil <nyamatongwe@gmail.com> | 2018-05-22 09:08:54 +1000 |
commit | 2e2e70c7ee89b353ad0e6ef409cb9621729d72f8 (patch) | |
tree | d5899867d76d457bda2c48dd298b6f41a0217ad1 /qt/ScintillaEditBase/PlatQt.cpp | |
parent | cc5e63013d7aa447a74fafba0ee4dd560b6952c7 (diff) | |
download | scintilla-mirror-2e2e70c7ee89b353ad0e6ef409cb9621729d72f8.tar.gz |
Add GradientRectangle method to Surface to draw rectangles with vertical or
horizontal gradients.
Diffstat (limited to 'qt/ScintillaEditBase/PlatQt.cpp')
-rw-r--r-- | qt/ScintillaEditBase/PlatQt.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/qt/ScintillaEditBase/PlatQt.cpp b/qt/ScintillaEditBase/PlatQt.cpp index 0a4609acc..44082c77a 100644 --- a/qt/ScintillaEditBase/PlatQt.cpp +++ b/qt/ScintillaEditBase/PlatQt.cpp @@ -353,6 +353,26 @@ void SurfaceImpl::AlphaRectangle(PRectangle rc, GetPainter()->drawRoundedRect(rect, radius, radius); } +void SurfaceImpl::GradientRectangle(PRectangle rc, const std::vector<ColourStop> &stops, GradientOptions options) { + QRectF rect = QRectFFromPRect(rc); + QLinearGradient linearGradient; + switch (options) { + case GradientOptions::leftToRight: + linearGradient = QLinearGradient(rc.left, rc.top, rc.right, rc.top); + break; + case GradientOptions::topToBottom: + default: + linearGradient = QLinearGradient(rc.left, rc.top, rc.left, rc.bottom); + break; + } + linearGradient.setSpread(QGradient::RepeatSpread); + for (const ColourStop &stop : stops) { + linearGradient.setColorAt(stop.position, QColorFromColourAlpha(stop.colour)); + } + QBrush brush = QBrush(linearGradient); + GetPainter()->fillRect(rect, brush); +} + static std::vector<unsigned char> ImageByteSwapped(int width, int height, const unsigned char *pixelsImage) { // Input is RGBA, but Format_ARGB32 is BGRA, so swap the red bytes and blue bytes |