From a57bbf73951d047ec5b96d5c81381b8b6c52abb3 Mon Sep 17 00:00:00 2001 From: nyamatongwe Date: Thu, 21 Jul 2011 16:33:42 +1000 Subject: Added dotted box indicator. --- src/Indicator.cxx | 29 +++++++++++++++++++++++++++++ src/XPM.cxx | 22 +++++++++++++++------- src/XPM.h | 1 + 3 files changed, 45 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/Indicator.cxx b/src/Indicator.cxx index 5efee75e6..7059a55bd 100644 --- a/src/Indicator.cxx +++ b/src/Indicator.cxx @@ -5,9 +5,17 @@ // Copyright 1998-2001 by Neil Hodgson // The License.txt file describes the conditions under which this software may be distributed. +#include +#include + +#ifdef _MSC_VER +#pragma warning(disable: 4786) +#endif + #include "Platform.h" #include "Scintilla.h" +#include "XPM.h" #include "Indicator.h" #ifdef SCI_NAMESPACE @@ -84,6 +92,27 @@ void Indicator::Draw(Surface *surface, const PRectangle &rc, const PRectangle &r rcBox.left = rc.left; rcBox.right = rc.right; surface->AlphaRectangle(rcBox, (style == INDIC_ROUNDBOX) ? 1 : 0, fore.allocated, fillAlpha, fore.allocated, outlineAlpha, 0); + } else if (style == INDIC_DOTBOX) { + PRectangle rcBox = rcLine; + rcBox.top = rcLine.top + 1; + rcBox.left = rc.left; + rcBox.right = rc.right; + // Cap width at 4000 to avoid large allocations when mistakes made + int width = Platform::Minimum(rcBox.Width(), 4000); + RGBAImage image(width, rcBox.Height(), 0); + // Draw horizontal lines top and bottom + for (int x=0; xDrawRGBAImage(rcBox, image.GetWidth(), image.GetHeight(), image.Pixels()); } else if (style == INDIC_DASH) { int x = rc.left; while (x < rc.right) { diff --git a/src/XPM.cxx b/src/XPM.cxx index 6c615dd94..f0277c65f 100644 --- a/src/XPM.cxx +++ b/src/XPM.cxx @@ -353,7 +353,11 @@ int XPMSet::GetWidth() { RGBAImage::RGBAImage(int width_, int height_, const unsigned char *pixels_) : height(height_), width(width_) { - pixelBytes.assign(pixels_, pixels_ + CountBytes()); + if (pixels_) { + pixelBytes.assign(pixels_, pixels_ + CountBytes()); + } else { + pixelBytes.resize(CountBytes()); + } } RGBAImage::RGBAImage(const XPM &xpm) { @@ -365,12 +369,7 @@ RGBAImage::RGBAImage(const XPM &xpm) { ColourDesired colour; bool transparent = false; xpm.PixelAt(x, y, colour, transparent); - unsigned char *pixel = &pixelBytes[0] + (y*width+x) * 4; - // RGBA - pixel[0] = colour.GetRed(); - pixel[1] = colour.GetGreen(); - pixel[2] = colour.GetBlue(); - pixel[3] = transparent ? 0 : 255; + SetPixel(x, y, colour, transparent ? 0 : 255); } } } @@ -386,6 +385,15 @@ const unsigned char *RGBAImage::Pixels() const { return &pixelBytes[0]; } +void RGBAImage::SetPixel(int x, int y, ColourDesired colour, int alpha) { + unsigned char *pixel = &pixelBytes[0] + (y*width+x) * 4; + // RGBA + pixel[0] = colour.GetRed(); + pixel[1] = colour.GetGreen(); + pixel[2] = colour.GetBlue(); + pixel[3] = alpha; +} + RGBAImageSet::RGBAImageSet() : height(-1), width(-1){ } diff --git a/src/XPM.h b/src/XPM.h index 8b72ef08d..b9c7308af 100644 --- a/src/XPM.h +++ b/src/XPM.h @@ -93,6 +93,7 @@ public: int GetWidth() const { return width; } int CountBytes() const; const unsigned char *Pixels() const; + void SetPixel(int x, int y, ColourDesired colour, int alpha=0xff); }; /** -- cgit v1.2.3