From d8a9d8cc474ca53c15f70e7132cb5bea370ff6f0 Mon Sep 17 00:00:00 2001 From: Timur Pocheptsov <timur.pocheptsov@cern.ch> Date: Sun, 7 Jun 2015 13:19:28 +0200 Subject: [PATCH] QuartzFillArea/ROOTOpenGLView - fix for 32-bit build CGGradientCreateWithColorComponents accepts CGFloat as parameter, which can be either double or float. TGColorGradient works with Double_t. Make it work with CGFloat == float. --- graf2d/cocoa/inc/ROOTOpenGLView.h | 6 +++- graf2d/cocoa/src/ROOTOpenGLView.mm | 7 +---- graf2d/quartz/src/QuartzFillArea.mm | 48 +++++++++++++++++++++++++---- 3 files changed, 48 insertions(+), 13 deletions(-) diff --git a/graf2d/cocoa/inc/ROOTOpenGLView.h b/graf2d/cocoa/inc/ROOTOpenGLView.h index 3d72fb3ee33..21e055bbf5f 100644 --- a/graf2d/cocoa/inc/ROOTOpenGLView.h +++ b/graf2d/cocoa/inc/ROOTOpenGLView.h @@ -22,7 +22,11 @@ // // /////////////////////////////////////////// -@interface ROOTOpenGLView : QuartzView +@interface ROOTOpenGLView : QuartzView { +@private + NSOpenGLPixelFormat *fPixelFormat; + BOOL fUpdateContext; +} - (id) initWithFrame : (NSRect) frameRect pixelFormat : (NSOpenGLPixelFormat *) format; diff --git a/graf2d/cocoa/src/ROOTOpenGLView.mm b/graf2d/cocoa/src/ROOTOpenGLView.mm index b787534e88e..63c4b1468f0 100644 --- a/graf2d/cocoa/src/ROOTOpenGLView.mm +++ b/graf2d/cocoa/src/ROOTOpenGLView.mm @@ -43,12 +43,7 @@ bool GLViewIsValidDrawable(ROOTOpenGLView *glView) } } -@implementation ROOTOpenGLView { - BOOL fIsOverlapped; - - NSOpenGLPixelFormat *fPixelFormat; - BOOL fUpdateContext; -} +@implementation ROOTOpenGLView @synthesize fOpenGLContext; @synthesize fUpdateContext; diff --git a/graf2d/quartz/src/QuartzFillArea.mm b/graf2d/quartz/src/QuartzFillArea.mm index 73fe2f7d487..15b86cb271f 100644 --- a/graf2d/quartz/src/QuartzFillArea.mm +++ b/graf2d/quartz/src/QuartzFillArea.mm @@ -35,11 +35,50 @@ namespace { const CGSize shadowOffset = CGSizeMake(10., 10.); const CGFloat shadowBlur = 5.; - //ROOT has TColorGradient, TLinearGradient and TRadialGradient - //they all specify parameters in NDC. But for rendering with //Quartz I need more specific parameters, I calculate them here. +// GradientFactory deals with CGFloat being either float or double. +template<class SRC, class DST> +struct GradientFactory { + static CGGradientRef CreateGradient(CGColorSpaceRef colorSpace, + const TColorGradient *extendedColor) + { + assert(colorSpace != nullptr && + "GradientHelper::CreateGradient, parameter 'colorSpace' is null"); + assert(extendedColor != nullptr && + "GradientHelper::CreateGradient, parameter 'extendedColor' is null"); + SRC compStart = extendedColor->GetColors(); + SRC compEnd = compStart + extendedColor->GetNumberOfSteps() * 4;//TODO: this assumes RGBA. + const std::vector<DST> convertedComponents(compStart, compEnd); + SRC posStart = extendedColor->GetColorPositions(); + SRC posEnd = posStart + extendedColor->GetNumberOfSteps(); + const std::vector<DST> convertedPositions(posStart, posEnd); + + return CGGradientCreateWithColorComponents(colorSpace, + &convertedComponents[0], + &convertedPositions[0], + extendedColor->GetNumberOfSteps()); + } +}; + +template<class DST> +struct GradientFactory<DST, DST> { + static CGGradientRef CreateGradient(CGColorSpaceRef colorSpace, + const TColorGradient *extendedColor) + { + assert(colorSpace != nullptr && + "GradientHelper::CreateGradient, parameter 'colorSpace' is null"); + assert(extendedColor != nullptr && + "GradientHelper::CreateGradient, parameter 'extendedColor' is null"); + return CGGradientCreateWithColorComponents(colorSpace, + extendedColor->GetColors(), + extendedColor->GetColorPositions(), + extendedColor->GetNumberOfSteps()); + } +}; + struct GradientParameters { // CGPoint fStartPoint; @@ -468,11 +507,8 @@ void DrawPolygonWithGradientFill(CGContextRef ctx, const TColorGradient *extende return; } - const CFScopeGuard<CGGradientRef> gradient(CGGradientCreateWithColorComponents(baseSpace.Get(), - extendedColor->GetColors(), - extendedColor->GetColorPositions(), - extendedColor->GetNumberOfSteps())); - + typedef GradientFactory<Double_t, CGFloat> Factory; + const CFScopeGuard<CGGradientRef> gradient(Factory::CreateGradient(baseSpace.Get(), extendedColor)); if (!gradient.Get()) { ::Error("DrawPolygonWithGradientFill", "CGGradientCreateWithColorComponents failed"); return; -- GitLab