From 7dcbdef9d6ae95e7c9232418d12195582faaa54b Mon Sep 17 00:00:00 2001 From: nyamatongwe Date: Sat, 21 Jul 2012 16:57:24 +1000 Subject: Scale factor implemented for RGBAImages to allow for high definition markers on retina displays. --- cocoa/PlatCocoa.mm | 2 +- doc/ScintillaDoc.html | 11 ++++++++--- include/Scintilla.h | 1 + include/Scintilla.iface | 3 +++ src/Editor.cxx | 7 ++++++- src/Editor.h | 1 + src/Indicator.cxx | 2 +- src/LineMarker.cxx | 12 ++++++------ src/LineMarker.h | 2 +- src/XPM.cxx | 5 +++-- src/XPM.h | 6 +++++- 11 files changed, 36 insertions(+), 16 deletions(-) diff --git a/cocoa/PlatCocoa.mm b/cocoa/PlatCocoa.mm index d5cddb5b5..a4584528f 100644 --- a/cocoa/PlatCocoa.mm +++ b/cocoa/PlatCocoa.mm @@ -675,7 +675,7 @@ static CGImageRef ImageCreateFromRGBA(int width, int height, const unsigned char void SurfaceImpl::DrawRGBAImage(PRectangle rc, int width, int height, const unsigned char *pixelsImage) { CGImageRef image = ImageCreateFromRGBA(width, height, pixelsImage, true); if (image) { - CGRect drawRect = CGRectMake(rc.left, rc.top, width, height); + CGRect drawRect = CGRectMake(rc.left, rc.top, rc.Width(), rc.Height()); CGContextDrawImage(gc, drawRect, image); CGImageRelease(image); } diff --git a/doc/ScintillaDoc.html b/doc/ScintillaDoc.html index 2ab2d7f03..e0dc42bad 100644 --- a/doc/ScintillaDoc.html +++ b/doc/ScintillaDoc.html @@ -79,7 +79,7 @@

Scintilla Documentation

-

Last edited 15/July/2012 NH

+

Last edited 21/July/2012 NH

There is an overview of the internal design of Scintilla.
@@ -3365,6 +3365,7 @@ struct Sci_TextToFind { const char *xpm)
SCI_RGBAIMAGESETWIDTH(int width)
SCI_RGBAIMAGESETHEIGHT(int height)
+ SCI_RGBAIMAGESETSCALE(int scalePercent)
SCI_MARKERDEFINERGBAIMAGE(int markerNumber, const char *pixels)
SCI_MARKERSYMBOLDEFINED(int markerNumber) @@ -3554,12 +3555,16 @@ struct Sci_TextToFind {

SCI_RGBAIMAGESETWIDTH(int width)
SCI_RGBAIMAGESETHEIGHT(int height)
+ SCI_RGBAIMAGESETSCALE(int scalePercent)
SCI_MARKERDEFINERGBAIMAGE(int markerNumber, const char *pixels)
Markers can be set to translucent pixmaps with this message. The
RGBA format is used for the pixmap. The width and height must previously been set with the SCI_RGBAIMAGESETWIDTH and - SCI_RGBAIMAGESETHEIGHT messages. - Pixmaps use the SC_MARK_RGBAIMAGE marker symbol.

+ SCI_RGBAIMAGESETHEIGHT messages.

+

A scale factor in percent may be set with SCI_RGBAIMAGESETSCALE. This is useful on OS X with + a retina display where each display unit is 2 pixels: use a factor of 200 so that each image pixel is dsplayed using a screen pixel. + The default scale, 100, will stretch each image pixel to cover 4 screen pixels on a retina display.

+

Pixmaps use the SC_MARK_RGBAIMAGE marker symbol.

SCI_MARKERSYMBOLDEFINED(int markerNumber)
Returns the symbol defined for a markerNumber with SCI_MARKERDEFINE diff --git a/include/Scintilla.h b/include/Scintilla.h index 52d6eed15..4d467a175 100644 --- a/include/Scintilla.h +++ b/include/Scintilla.h @@ -837,6 +837,7 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SCI_GETIDENTIFIER 2623 #define SCI_RGBAIMAGESETWIDTH 2624 #define SCI_RGBAIMAGESETHEIGHT 2625 +#define SCI_RGBAIMAGESETSCALE 2651 #define SCI_MARKERDEFINERGBAIMAGE 2626 #define SCI_REGISTERRGBAIMAGE 2627 #define SCI_SCROLLTOSTART 2628 diff --git a/include/Scintilla.iface b/include/Scintilla.iface index ef35fe6a4..e31863cfd 100644 --- a/include/Scintilla.iface +++ b/include/Scintilla.iface @@ -2221,6 +2221,9 @@ set void RGBAImageSetWidth=2624(int width,) # Set the height for future RGBA image data. set void RGBAImageSetHeight=2625(int height,) +# Set the scale factor in percent for future RGBA image data. +set void RGBAImageSetScale=2651(int scalePercent,) + # Define a marker from RGBA data. # It has the width and height from RGBAImageSetWidth/Height fun void MarkerDefineRGBAImage=2626(int markerNumber, string pixels) diff --git a/src/Editor.cxx b/src/Editor.cxx index 44226d11b..c3f1b984e 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -104,6 +104,7 @@ Editor::Editor() { stylesValid = false; technology = SC_TECHNOLOGY_DEFAULT; + scaleRGBAImage = 100; printMagnification = 0; printColourMode = SC_PRINT_NORMAL; @@ -8159,9 +8160,13 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) { sizeRGBAImage.y = wParam; break; + case SCI_RGBAIMAGESETSCALE: + scaleRGBAImage = wParam; + break; + case SCI_MARKERDEFINERGBAIMAGE: if (wParam <= MARKER_MAX) { - vs.markers[wParam].SetRGBAImage(sizeRGBAImage, reinterpret_cast(lParam)); + vs.markers[wParam].SetRGBAImage(sizeRGBAImage, scaleRGBAImage / 100.0, reinterpret_cast(lParam)); vs.CalcLargestMarkerHeight(); }; InvalidateStyleData(); diff --git a/src/Editor.h b/src/Editor.h index 00e4ec3a6..0ae1f115f 100644 --- a/src/Editor.h +++ b/src/Editor.h @@ -133,6 +133,7 @@ protected: // ScintillaBase subclass needs access to much of Editor ViewStyle vs; int technology; Point sizeRGBAImage; + float scaleRGBAImage; int printMagnification; int printColourMode; diff --git a/src/Indicator.cxx b/src/Indicator.cxx index 9ea4024bb..bd17c3d1c 100644 --- a/src/Indicator.cxx +++ b/src/Indicator.cxx @@ -95,7 +95,7 @@ void Indicator::Draw(Surface *surface, const PRectangle &rc, const PRectangle &r 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); + RGBAImage image(width, rcBox.Height(), 1.0, 0); // Draw horizontal lines top and bottom for (int x=0; x(((rcWhole.top + rcWhole.bottom) - image->GetHeight()) / 2); - rcImage.bottom = rcImage.top + image->GetHeight(); - rcImage.left = static_cast(((rcWhole.left + rcWhole.right) - image->GetWidth()) / 2); - rcImage.right = rcImage.left + image->GetWidth(); + rcImage.top = static_cast(((rcWhole.top + rcWhole.bottom) - image->GetScaledHeight()) / 2); + rcImage.bottom = rcImage.top + image->GetScaledHeight(); + rcImage.left = static_cast(((rcWhole.left + rcWhole.right) - image->GetScaledWidth()) / 2); + rcImage.right = rcImage.left + image->GetScaledWidth(); surface->DrawRGBAImage(rcImage, image->GetWidth(), image->GetHeight(), image->Pixels()); return; } diff --git a/src/LineMarker.h b/src/LineMarker.h index 5c73a6217..e226ef5f5 100644 --- a/src/LineMarker.h +++ b/src/LineMarker.h @@ -66,7 +66,7 @@ public: } void SetXPM(const char *textForm); void SetXPM(const char *const *linesForm); - void SetRGBAImage(Point sizeRGBAImage, const unsigned char *pixelsRGBAImage); + void SetRGBAImage(Point sizeRGBAImage, float scale, const unsigned char *pixelsRGBAImage); void Draw(Surface *surface, PRectangle &rc, Font &fontForCharacter, typeOfFold tFold, int marginStyle); }; diff --git a/src/XPM.cxx b/src/XPM.cxx index db48ea227..7188c2465 100644 --- a/src/XPM.cxx +++ b/src/XPM.cxx @@ -319,8 +319,8 @@ int XPMSet::GetWidth() { return (width > 0) ? width : 0; } -RGBAImage::RGBAImage(int width_, int height_, const unsigned char *pixels_) : - height(height_), width(width_) { +RGBAImage::RGBAImage(int width_, int height_, float scale_, const unsigned char *pixels_) : + height(height_), width(width_), scale(scale_) { if (pixels_) { pixelBytes.assign(pixels_, pixels_ + CountBytes()); } else { @@ -331,6 +331,7 @@ RGBAImage::RGBAImage(int width_, int height_, const unsigned char *pixels_) : RGBAImage::RGBAImage(const XPM &xpm) { height = xpm.GetHeight(); width = xpm.GetWidth(); + scale = 1; pixelBytes.resize(CountBytes()); for (int y=0; y pixelBytes; public: - RGBAImage(int width_, int height_, const unsigned char *pixels_); + RGBAImage(int width_, int height_, float scale_, const unsigned char *pixels_); RGBAImage(const XPM &xpm); virtual ~RGBAImage(); int GetHeight() const { return height; } int GetWidth() const { return width; } + float GetScale() const { return scale; } + float GetScaledHeight() const { return height / scale; } + float GetScaledWidth() const { return width / scale; } int CountBytes() const; const unsigned char *Pixels() const; void SetPixel(int x, int y, ColourDesired colour, int alpha=0xff); -- cgit v1.2.3