21#include <Cocoa/Cocoa.h>
51void ConvertPointsROOTToCocoa(
Int_t nPoints,
const TPoint *
xy, std::vector<TPoint> &
dst,
54 assert(nPoints != 0 &&
"ConvertPointsROOTToCocoa, nPoints parameter is 0");
55 assert(
xy != 0 &&
"ConvertPointsROOTToCocoa, xy parameter is null");
56 assert(drawable != 0 &&
"ConvertPointsROOTToCocoa, drawable parameter is null");
58 const auto scaleFactor = drawable.fScaleFactor;
61 for (
Int_t i = 0; i < nPoints; ++i) {
71 : fUseAA(true), fUseFAAA(false)
75 Error(
"TGQuartz",
"TTFhandle::Init() failed");
84 fUseAA(true), fUseFAAA(false)
88 Error(
"TGQuartz",
"TTFhandle::Init() failed");
101 if ([drawable0 isDirectDraw]) {
102 if (!drawable0.fIsPixmap) {
105 ::Warning(
"DrawBoxW",
"Invalid view/window for XOR-mode");
134 polygon[0].
fX =
x1, polygon[0].
fY =
y1;
135 polygon[1].
fX =
x2, polygon[1].
fY =
y1;
136 polygon[2].
fX =
x2, polygon[2].
fY =
y2;
137 polygon[3].
fX =
x1, polygon[3].
fY =
y2;
142 const bool isHollow =
mode ==
kHollow || attfill.GetFillStyle() / 1000 == 2;
146 unsigned patternIndex = 0;
149 Error(
"DrawBoxW",
"Can not find color for index %d",
int(attline.GetLineColor()));
154 Error(
"DrawBoxW",
"SetFillAreaParameters failed");
187 if ([drawable0 isDirectDraw])
198 std::vector<TPoint> pnts;
201 ConvertPointsROOTToCocoa(
n,
xy, pnts, drawable);
207 if (drawable.fScaleFactor > 1.) {
209 CGContextScaleCTM(ctx, 1. / drawable.fScaleFactor, 1. / drawable.fScaleFactor);
214 Error(
"DrawFillAreaW",
"Could not find TColor for index %d", attfill.GetFillColor());
220 pnts.size(), pnts.data(),
kFALSE);
222 unsigned patternIndex = 0;
224 Error(
"DrawFillAreaW",
"SetFillAreaParameters failed");
256 if ([drawable0 isDirectDraw]) {
257 if (!drawable0.fIsPixmap) {
260 ::Warning(
"DrawLineW",
"Invalid view/window for XOR-mode");
282 Error(
"DrawLineW",
"Could not set line color for index %d",
int(attline.GetLineColor()));
316 if ([drawable0 isDirectDraw]) {
317 if (!drawable0.fIsPixmap) {
320 ::Warning(
"DrawPolyLineW",
"Invalid view/window for XOR-mode");
340 Error(
"DrawPolyLineW",
"Could not find TColor for index %d", attline.GetLineColor());
347 std::vector<TPoint> pnts;
350 ConvertPointsROOTToCocoa(
n,
xy, pnts, drawable);
352 if (drawable.fScaleFactor > 1.)
353 CGContextScaleCTM(ctx, 1. / drawable.fScaleFactor, 1. / drawable.fScaleFactor);
377 for(
Int_t i = 0; i < 2*
n; i += 2)
390 if ([drawable0 isDirectDraw]) {
391 if (!drawable0.fIsPixmap) {
394 ::Warning(
"DrawPolyMarkerW",
"Invalid view/window for XOR-mode");
407 std::vector<TPoint> pnts;
409 ConvertPointsROOTToCocoa(
n,
xy, pnts, drawable);
440 Error(
"DrawTextW",
"char string to draw, but TTF initialization failed");
448 if ([drawable0 isDirectDraw])
458 if (att.GetTextSize() < 1.5)
489 Error(
"DrawTextW",
"wchar_t string to draw, but TTF initialization failed");
497 if ([drawable0 isDirectDraw])
507 if (att.GetTextSize() < 1.5)
530 if ([drawable0 isDirectDraw])
541 else if ([drawable isKindOfClass : [
QuartzView class]] || [drawable isKindOfClass : [
QuartzWindow class]])
546 Error(
"DrawTTFglyphsW",
"fSelectedDrawable is neither QuartzPixmap nor a double buffered window");
556 Error(
"DrawTTFglyphsW",
"pixmap creation failed");
560 const unsigned char defaultBackgroundPixel[] = {255, 255, 255, 255};
570 arrayGuard.
Reset([dstPixmap readColorBits : bbox]);
572 if (!arrayGuard.
Get()) {
573 Error(
"DrawTTFglyphsW",
"problem with reading background pixels");
581 for (
int yp = 0; yp <
int(bbox.
fHeight) && yo + yp <
h; ++yp) {
582 const unsigned char *srcBase = arrayGuard.
Get() + bbox.
fWidth * yp * 4;
583 for (
int xp = 0; xp <
int(bbox.
fWidth) && xo + xp <
w; ++xp) {
584 const unsigned char *
const pixel = srcBase + xp * 4;
585 [pixmap.
Get() putPixel :
pixel X : xo + xp Y : yo + yp];
590 [pixmap.
Get() addPixel : defaultBackgroundPixel];
601 CGContextSetRGBStrokeColor(ctx, 0., 0., 1., 1.);
604 Int_t bx = 0, by = 0;
622 for (
unsigned y = 0;
y < rows;
y++) {
623 for (
unsigned x = 0;
x <
width;
x++) {
624 if (
x + bx < pixmap.
Get().fWidth &&
y + by < pixmap.
Get().fHeight) {
625 const unsigned char *
const pixels = pixmap.
Get().fData + (
y + by) * pixmap.
Get().fWidth * 4 + (
x + bx) * 4;
626 r +=
UShort_t(pixels[0] / 255. * 0xffff);
627 g +=
UShort_t(pixels[1] / 255. * 0xffff);
628 b +=
UShort_t(pixels[2] / 255. * 0xffff);
629 if (++dotCnt >= maxDots)
655 for (
int x = 3;
x > 0; --
x) {
664 const unsigned char *s = buffer;
665 for (
unsigned y = 0;
y < rows; ++
y) {
666 for (
unsigned x = 0;
x <
width; ++
x) {
667 unsigned char d = (((*s++ & 0xff) + 10) * 5) / 256;
672 UChar_t(
double(col[
d].fGreen) / 0xffff * 255),
673 UChar_t(
double(col[
d].fBlue) / 0xffff * 255), 255};
674 [pixmap.
Get() putPixel :
pixel X : bx +
x Y : by +
y];
680 unsigned char rgba[4] = {};
685 const unsigned char *row = buffer;
686 for (
unsigned y = 0;
y < rows; ++
y) {
688 const unsigned char *s = row;
689 for (
unsigned x = 0;
x <
width; ++
x) {
694 [pixmap.
Get() putPixel : rgba
X : bx +
x Y : by +
y];
707 [dstPixmap copy : pixmap.
Get() area : copyArea withMask : nil clipOrigin :
X11::Point() toPoint : dstPoint];
846 Error(
"SetTextFont",
"Direct TTF font setting not supported");
930 if (
value ==
"auto") {
931 [[NSScreen mainScreen] backingScaleFactor] > 1. ?
fUseAA = true :
fUseAA =
false;
932 }
else if (
value ==
"no")
935 assert(
value ==
"yes" &&
"SetAA, value must be 'yes', 'no' or 'auto'");
939 if (valuefa ==
"auto") {
940 [[NSScreen mainScreen] backingScaleFactor] > 1. ?
fUseFAAA = true :
fUseFAAA =
false;
941 }
else if (valuefa ==
"no")
944 assert(valuefa ==
"yes" &&
"SetAA, value must be 'yes', 'no' or 'auto'");
955 if (!drawable || !drawable.attFill)
957 return *drawable.attFill;
965 if (!drawable || !drawable.attLine)
967 return *drawable.attLine;
975 if (!drawable || !drawable.attMarker)
977 return *drawable.attMarker;
985 if (!drawable || !drawable.attText)
987 return *drawable.attText;
993 assert(calledFrom != 0 &&
"GetDrawableChecked, calledFrom parameter is null");
999 if (!drawable.fIsPixmap) {
1001 if ([drawable isKindOfClass : [
QuartzView class]]) {
1004 Error(calledFrom,
"Selected window is not double buffered");
1010 Error(calledFrom,
"Selected drawable is neither a pixmap, nor a double buffered window");
1015 if (!drawable.fContext) {
1016 Error(calledFrom,
"Context is null");
Handle_t WinContext_t
Window drawing context.
Handle_t Drawable_t
Drawable handle.
short Style_t
Style number (short)
unsigned short UShort_t
Unsigned Short integer 2 bytes (unsigned short)
int Int_t
Signed integer 4 bytes (int)
short Color_t
Color number (short)
unsigned char UChar_t
Unsigned Character 1 byte (unsigned char)
constexpr ULong_t kBitsPerByte
unsigned long ULong_t
Unsigned long integer 4 bytes (unsigned long). Size depends on architecture.
short Width_t
Line width (short)
float Float_t
Float 4 bytes (float)
short Font_t
Font number (short)
short Short_t
Signed Short integer 2 bytes (short)
short SCoord_t
Screen coordinates (short)
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t GetWindowSize
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void pixel
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t r
Option_t Option_t markerstyle
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
Option_t Option_t TPoint TPoint const char x2
Option_t Option_t TPoint TPoint const char x1
Option_t Option_t textsize
Option_t Option_t TPoint TPoint angle
Option_t Option_t TPoint xy
Option_t Option_t TPoint TPoint const char mode
Option_t Option_t TPoint TPoint const char y2
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t height
Option_t Option_t TPoint TPoint const char text
Option_t Option_t TPoint TPoint const char y1
DerivedType * Get() const
Fill Area Attributes class.
virtual Color_t GetFillColor() const
Return the fill area color.
void Copy(TAttFill &attfill) const
Copy this fill attributes to a new TAttFill.
virtual Style_t GetFillStyle() const
Return the fill area style.
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
virtual void SetFillStyle(Style_t fstyle)
Set the fill area style.
virtual Color_t GetLineColor() const
Return the line color.
virtual void SetLineStyle(Style_t lstyle)
Set the line style.
virtual Width_t GetLineWidth() const
Return the line width.
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
virtual void SetLineColor(Color_t lcolor)
Set the line color.
virtual Style_t GetLineStyle() const
Return the line style.
void Copy(TAttLine &attline) const
Copy this line attributes to a new TAttLine.
virtual Style_t GetMarkerStyle() const
Return the marker style.
virtual Color_t GetMarkerColor() const
Return the marker color.
virtual Size_t GetMarkerSize() const
Return the marker size.
void Copy(TAttMarker &attmarker) const
Copy this marker attributes to a new TAttMarker.
virtual void SetMarkerStyle(Style_t mstyle=1)
Set the marker style.
virtual void SetMarkerSize(Size_t msize=1)
Set the marker size.
virtual void SetMarkerColor(Color_t mcolor=1)
Set the marker color.
virtual Float_t GetTextSize() const
Return the text size.
virtual void SetTextAlign(Short_t align=11)
Set the text alignment.
virtual Short_t GetTextAlign() const
Return the text alignment.
virtual Font_t GetTextFont() const
Return the text font.
virtual Color_t GetTextColor() const
Return the text color.
virtual void SetTextAngle(Float_t tangle=0)
Set the text angle.
virtual Float_t GetTextAngle() const
Return the text angle.
virtual void SetTextColor(Color_t tcolor=1)
Set the text color.
virtual void SetTextFont(Font_t tfont=62)
Set the text font.
virtual void SetTextSize(Float_t tsize=1)
Set the text size.
void Copy(TAttText &atttext) const
Copy this text attributes to a new TAttText.
TColorGradient extends basic TColor.
The color creation and management class.
static Int_t GetColor(const char *hexcolor)
Static method returning color number for color specified by hex color string of form: "#rrggbb",...
virtual Int_t GetValue(const char *name, Int_t dflt) const
Returns the integer value for a resource.
This class implements TVirtualX interface for MacOS X, using Cocoa and Quartz 2D.
Bool_t AllocColor(Colormap_t cmap, ColorStruct_t &color) override
Allocates a read-only colormap entry corresponding to the closest RGB value supported by the hardware...
std::unique_ptr< ROOT::MacOSX::Details::CocoaPrivate > fPimpl
!
void QueryColor(Colormap_t cmap, ColorStruct_t &color) override
Returns the current RGB value for the pixel in the "color" structure.
WinContext_t GetSelectedContext()
Drawable_t fSelectedDrawable
ULong_t GetPixel(Color_t cindex) override
Returns pixel value associated to specified ROOT color number "cindex".
void SetLineWidth(Width_t width) override
Set the line width.
TAttMarker & GetAttMarker(WinContext_t wctxt)
void SetAttLine(WinContext_t wctxt, const TAttLine &att) override
Set line attributes for specified window.
void SetMarkerColor(Color_t cindex) override
Set the marker color.
void SetFillStyle(Style_t style) override
Set the fill area style.
void SetOpacity(Int_t percent) override
Sets opacity of the current window.
void SetFillColor(Color_t cindex) override
Set the fill area color.
void DrawPolyLine(Int_t n, TPoint *xy) override
Draws a line through all points in the list.
Float_t GetTextMagnitude() override
Returns the current font magnification factor.
void SetAttText(WinContext_t wctxt, const TAttText &att) override
Set text attributes for specified window.
void DrawFillArea(Int_t n, TPoint *xy) override
Fills area described by the polygon.
void DrawText(Int_t x, Int_t y, Float_t angle, Float_t mgn, const char *text, ETextMode mode) override
Draws a text string using current font.
void DrawLine(Int_t x1, Int_t y1, Int_t x2, Int_t y2) override
Draws a line.
void DrawTextW(WinContext_t wctxt, Int_t x, Int_t y, Float_t angle, Float_t mgn, const char *text, ETextMode mode) override
Draw text on specified window.
void SetTextColor(Color_t cindex) override
Set the text color.
void SetMarkerStyle(Style_t markerstyle) override
Set the marker style.
void DrawBox(Int_t x1, Int_t y1, Int_t x2, Int_t y2, EBoxMode mode) override
Draws a box between [x1,y1] and [x2,y2] according to the "mode".
void SetAttFill(WinContext_t wctxt, const TAttFill &att) override
Set fill attributes for specified window.
void SetTextAlign(Short_t talign=11) override
Set the text alignment.
TAttText & GetAttText(WinContext_t wctxt)
void SetLineColor(Color_t cindex) override
Set the line color.
void SetTextFont(Font_t fontnumber) override
Set the text font.
void SetAttMarker(WinContext_t wctxt, const TAttMarker &att) override
Set marker attributes for specified window.
void SetMarkerSize(Float_t markersize) override
Set the marker size.
void DrawCellArray(Int_t x1, Int_t y1, Int_t x2, Int_t y2, Int_t nx, Int_t ny, Int_t *ic) override
Draws a cell array.
void DrawLinesSegmentsW(WinContext_t wctxt, Int_t n, TPoint *xy) override
Draw line segments on specified window.
void SetTextSize(Float_t textsize) override
Set the text size.
void DrawPolyMarkerW(WinContext_t wctxt, Int_t n, TPoint *xy) override
Draw poly marker on specified window.
void DrawLineW(WinContext_t wctxt, Int_t x1, Int_t y1, Int_t x2, Int_t y2) override
Draw line on specified window.
void DrawTTFglyphsW(WinContext_t wctxt, Int_t x, Int_t y, TTFhandle &ttf, ETextMode mode) override
Draw TTFglyphs on specified window Will be invoked only if HasTTFonts method returns true.
void DrawPolyLineW(WinContext_t wctxt, Int_t n, TPoint *xy) override
Draw poly line on specified window.
void SetLineStyle(Style_t linestyle) override
Set the line style.
TAttFill & GetAttFill(WinContext_t wctxt)
void DrawBoxW(WinContext_t wctxt, Int_t x1, Int_t y1, Int_t x2, Int_t y2, EBoxMode mode) override
Draw box on specified window.
void SetOpacityW(WinContext_t wctxt, Int_t percent) override
Set opactity for specified window.
void DrawPolyMarker(Int_t n, TPoint *xy) override
Draws "n" markers with the current attributes at position [x,y].
void * GetPixmapDrawable(void *drawable0, const char *calledFrom) const
void DrawFillAreaW(WinContext_t wctxt, Int_t n, TPoint *xy) override
Draw fill area on specified window.
TAttLine & GetAttLine(WinContext_t wctxt)
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
TSubString Strip(EStripType s=kTrailing, char c=' ') const
Return a substring of self stripped at beginning and/or end.
Dynamic handle to work with freetype 2 library.
Bool_t SetTextSize(Float_t textsize)
Set current text size.
void SetRotationMatrix(Float_t angle)
Set the rotation matrix used to rotate the font outlines.
void PrepareString(const char *string)
Put the characters in "string" in the "glyphs" array.
UInt_t GetNumGlyphs() const
return number of glyphs
Int_t GetGlyphsHeight() const
Returns height of all glyphs.
void SetTextFont(Font_t fontnumber)
Set specified font.
Int_t GetGlyphsWidth() const
Returns width of all glyphs.
void LayoutGlyphs()
Compute the glyphs positions, fgAscent and fgWidth (needed for alignment).
Bool_t GetSmoothing() const
void SetSmoothing(Bool_t state)
Bool_t GetGlyphData(UInt_t n, Int_t &offx, Int_t &offy, UChar_t *&buffer, UInt_t &width, UInt_t &rows, UInt_t &pitch)
Returns data for glyph bitmap Instead direct access to FT_BitmapGlyph one can obtain all relevant fie...
Bool_t ApplyAlignRotate(Int_t &px, Int_t &py, Int_t align, Int_t pad_width, Int_t pad_height)
Apply align and configured rotation matrix to text position px and py will be shifted to the place wh...
QuartzPixmap * fBackBuffer
QuartzWindow * fQuartzWindow
void PixelToRGB(Pixel_t pixelColor, CGFloat *rgb)
int LocalYROOTToCocoa(NSView< X11Window > *parentView, CGFloat yROOT)
bool AdjustCropArea(const Rectangle &srcRect, Rectangle &cropArea)
void DrawBox(CGContextRef ctx, Int_t x1, Int_t y1, Int_t x2, Int_t y2, bool hollow)
Bool_t SetLineColor(CGContextRef ctx, Color_t colorIndex)
void DrawPolyMarker(CGContextRef ctx, unsigned nPoints, const TPoint *marker, const TAttMarker &attmark, float scaleFactor)
Bool_t SetFillAreaParameters(CGContextRef ctx, unsigned *patternIndex, const TAttFill &attfill)
void DrawPolyLine(CGContextRef ctx, Int_t n, const TPoint *xy)
void DrawFillArea(CGContextRef ctx, Int_t n, TPoint *xy, Bool_t drawShadow, const TAttFill &attfill)
void DrawPolygonWithGradientFill(CGContextRef ctx, const TColorGradient *extendedColor, const CGSize &sizeOfDrawable, Int_t nPoints, const TPoint *xy, Bool_t drawShadow)
void DrawLine(CGContextRef ctx, Int_t x1, Int_t y1, Int_t x2, Int_t y2)
void SetLineWidth(CGContextRef ctx, Int_t width)
void SetLineStyle(CGContextRef ctx, Int_t lstyle)
Short_t Min(Short_t a, Short_t b)
Returns the smallest of a and b.
ULong_t fPixel
color pixel value (index in color table)
UShort_t fRed
red component (0..65535)
UShort_t fGreen
green component (0..65535)
UShort_t fBlue
blue component (0..65535)