Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TGQuartz.mm
Go to the documentation of this file.
1// @(#)root/graf2d:$Id$
2// Author: Olivier Couet, Timur Pocheptsov 23/01/2012
3
4
5/*************************************************************************
6 * Copyright (C) 1995-2011, Rene Brun and Fons Rademakers. *
7 * All rights reserved. *
8 * *
9 * For the licensing terms see $ROOTSYS/LICENSE. *
10 * For the list of contributors see $ROOTSYS/README/CREDITS. *
11 *************************************************************************/
12
13//#define NDEBUG
14
15#include <stdexcept>
16#include <iostream>
17#include <cstring>
18#include <cassert>
19#include <limits>
20
21#include <Cocoa/Cocoa.h>
22
23#include "QuartzFillArea.h"
24#include "TColorGradient.h"
25#include "QuartzMarker.h"
26#include "CocoaPrivate.h"
27#include "QuartzWindow.h"
28#include "QuartzPixmap.h"
29#include "QuartzUtils.h"
30#include "X11Drawable.h"
31#include "QuartzText.h"
32#include "QuartzLine.h"
33#include "CocoaUtils.h"
34#include "TTFhandle.h"
35#include "TGQuartz.h"
36#include "TString.h"
37#include "TPoint.h"
38#include "TColor.h"
39#include "TStyle.h"
40#include "TROOT.h"
41#include "TMath.h"
42#include "TEnv.h"
43
44namespace X11 = ROOT::MacOSX::X11;
45namespace Quartz = ROOT::Quartz;
46namespace Util = ROOT::MacOSX::Util;
47
48namespace {
49
50//______________________________________________________________________________
51void ConvertPointsROOTToCocoa(Int_t nPoints, const TPoint *xy, std::vector<TPoint> &dst,
52 NSObject<X11Drawable> *drawable)
53{
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");
57
58 const auto scaleFactor = drawable.fScaleFactor;
59
60 dst.resize(nPoints);
61 for (Int_t i = 0; i < nPoints; ++i) {
62 dst[i].fX = SCoord_t(xy[i].fX * scaleFactor);
63 dst[i].fY = SCoord_t(X11::LocalYROOTToCocoa(drawable, xy[i].fY) * scaleFactor);
64 }
65}
66
67}
68
69//______________________________________________________________________________
71 : fUseAA(true), fUseFAAA(false)
72{
73 //Default ctor.
74 if (!TTFhandle::Init())
75 Error("TGQuartz", "TTFhandle::Init() failed");
76
77 SetAA();
78}
79
80
81//______________________________________________________________________________
82TGQuartz::TGQuartz(const char *name, const char *title)
83 : TGCocoa(name, title),
84 fUseAA(true), fUseFAAA(false)
85{
86 //Constructor.
87 if (!TTFhandle::Init())
88 Error("TGQuartz", "TTFhandle::Init() failed");
89
90 SetAA();
91}
92
93//______________________________________________________________________________
95{
96 auto drawable0 = (NSObject<X11Drawable> * const) wctxt;
97 if (!drawable0)
98 return;
99
100 //Check some conditions first.
101 if ([drawable0 isDirectDraw]) {
102 if (!drawable0.fIsPixmap) {
103 QuartzView * const view = (QuartzView *)fPimpl->GetWindow(drawable0.fID).fContentView;
104 if (!view) {
105 ::Warning("DrawBoxW", "Invalid view/window for XOR-mode");
106 return;
107 }
108
109 [view.fQuartzWindow addXorBox: view : x1 : y1 : x2 : y2];
110 }
111 return;
112 }
113
114 auto &attline = GetAttLine(wctxt);
115 auto &attfill = GetAttFill(wctxt);
116
117 auto drawable = (NSObject<X11Drawable> * const) GetPixmapDrawable(drawable0, "DrawBoxW");
118 if (!drawable)
119 return;
120
121 CGContextRef ctx = drawable.fContext;
123 //AA flag is not a part of a state.
125
126 //Go to low-left-corner system.
127 y1 = Int_t(X11::LocalYROOTToCocoa(drawable, y1));
128 y2 = Int_t(X11::LocalYROOTToCocoa(drawable, y2));
129
130 if (const TColorGradient * const gradient = dynamic_cast<TColorGradient *>(gROOT->GetColor(attfill.GetFillColor()))) {
131 //Draw a box with a gradient fill and a shadow.
132 //Ignore all fill styles and EBoxMode, use a gradient fill.
133 TPoint polygon[4];
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;
138
139 Quartz::DrawPolygonWithGradientFill(ctx, gradient, CGSizeMake(drawable.fWidth, drawable.fHeight),
140 4, polygon, kFALSE); //kFALSE == don't draw a shadow.
141 } else {
142 const bool isHollow = mode == kHollow || attfill.GetFillStyle() / 1000 == 2;
143
144 //Note! Pattern index (and its address) MUST live
145 //long enough to be valid at the point of Quartz::DrawBox call!
146 unsigned patternIndex = 0;
147 if (isHollow) {
148 if (!Quartz::SetLineColor(ctx, attline.GetLineColor())) {
149 Error("DrawBoxW", "Can not find color for index %d", int(attline.GetLineColor()));
150 return;
151 }
152 } else {
154 Error("DrawBoxW", "SetFillAreaParameters failed");
155 return;
156 }
157 }
158 Quartz::SetLineStyle(ctx, attline.GetLineStyle());
159 Quartz::SetLineWidth(ctx, attline.GetLineWidth());
161 }
162}
163
164
165//______________________________________________________________________________
170
171//______________________________________________________________________________
173{
174 //Comment from TVirtualX:
175
176 // Draw a filled area through all points.
177 // n : number of points
178 // xy : array of points
179
180 auto drawable0 = (NSObject<X11Drawable> * const) wctxt;
181 if (!drawable0)
182 return;
183
184 if (n < 3)
185 return;
186 // No fill area with direct drawing
187 if ([drawable0 isDirectDraw])
188 return;
189
190 auto &attfill = GetAttFill(wctxt);
191
192 auto drawable = (NSObject<X11Drawable> * const) GetPixmapDrawable(drawable0, "DrawFillAreaW");
193 if (!drawable)
194 return;
195
196 CGContextRef ctx = drawable.fContext;
197
198 std::vector<TPoint> pnts;
199
200 //Convert points to bottom-left system:
201 ConvertPointsROOTToCocoa(n, xy, pnts, drawable);
202
204 //AA flag is not a part of a state.
206
207 if (drawable.fScaleFactor > 1.) {
208 // The CTM will be restored by 'ctxGuard'.
209 CGContextScaleCTM(ctx, 1. / drawable.fScaleFactor, 1. / drawable.fScaleFactor);
210 }
211
212 const TColor * const fillColor = gROOT->GetColor(attfill.GetFillColor());
213 if (!fillColor) {
214 Error("DrawFillAreaW", "Could not find TColor for index %d", attfill.GetFillColor());
215 return;
216 }
217
218 if (const TColorGradient * const gradient = dynamic_cast<const TColorGradient *>(fillColor)) {
219 Quartz::DrawPolygonWithGradientFill(ctx, gradient, CGSizeMake(drawable.fWidth, drawable.fHeight),
220 pnts.size(), pnts.data(), kFALSE);//kFALSE == don't draw a shadow.
221 } else {
222 unsigned patternIndex = 0;
224 Error("DrawFillAreaW", "SetFillAreaParameters failed");
225 return;
226 }
227
228 // kFALSE - do not draw shadows.
229 // last argument - fill style
230 Quartz::DrawFillArea(ctx, pnts.size(), pnts.data(), kFALSE, attfill);
231 }
232}
233
234
235//______________________________________________________________________________
240
241
242//______________________________________________________________________________
243void TGQuartz::DrawCellArray(Int_t /*x1*/, Int_t /*y1*/, Int_t /*x2*/, Int_t /*y2*/,
244 Int_t /*nx*/, Int_t /*ny*/, Int_t */*ic*/)
245{
246 //Noop.
247}
248
249//______________________________________________________________________________
251{
252 auto drawable0 = (NSObject<X11Drawable> * const) wctxt;
253 if (!drawable0)
254 return;
255
256 if ([drawable0 isDirectDraw]) {
257 if (!drawable0.fIsPixmap) {
258 QuartzView * const view = (QuartzView *)fPimpl->GetWindow(drawable0.fID).fContentView;
259 if (!view) {
260 ::Warning("DrawLineW", "Invalid view/window for XOR-mode");
261 return;
262 }
263
264 [view.fQuartzWindow addXorLine: view : x1 : y1 : x2 : y2];
265 }
266
267 return;
268 }
269
270 auto &attline = GetAttLine(wctxt);
271
272 auto drawable = (NSObject<X11Drawable> * const) GetPixmapDrawable(drawable0, "DrawLineW");
273 if (!drawable)
274 return;
275
276 CGContextRef ctx = drawable.fContext;
278 //AA flag is not a part of a state.
280
281 if (!Quartz::SetLineColor(ctx, attline.GetLineColor())) {
282 Error("DrawLineW", "Could not set line color for index %d", int(attline.GetLineColor()));
283 return;
284 }
285
286 Quartz::SetLineStyle(ctx, attline.GetLineStyle());
287 Quartz::SetLineWidth(ctx, attline.GetLineWidth());
288
290 X11::LocalYROOTToCocoa(drawable, y2));
291}
292
293//______________________________________________________________________________
295{
296 // Draw a line.
297 // x1,y1 : begin of line
298 // x2,y2 : end of line
299
300 assert(fSelectedDrawable > fPimpl->GetRootWindowID() && "DrawLine, bad drawable is selected");
301
303}
304
305
306//______________________________________________________________________________
308{
309 auto drawable0 = (NSObject<X11Drawable> * const) wctxt;
310 if (!drawable0)
311 return;
312
313 auto &attline = GetAttLine(wctxt);
314
315 //Some checks first.
316 if ([drawable0 isDirectDraw]) {
317 if (!drawable0.fIsPixmap) {
318 QuartzView * const view = (QuartzView *)fPimpl->GetWindow(drawable0.fID).fContentView;
319 if (!view) {
320 ::Warning("DrawPolyLineW", "Invalid view/window for XOR-mode");
321 return;
322 }
323
324 [view.fQuartzWindow addXorPolyLine: view : n : xy : attline ];
325 }
326
327 return;
328 }
329
330 auto drawable = (NSObject<X11Drawable> * const) GetPixmapDrawable(drawable0, "DrawPolyLineW");
331 if (!drawable)
332 return;
333
334 CGContextRef ctx = drawable.fContext;
336 //AA flag is not a part of a state.
338
339 if (!Quartz::SetLineColor(ctx, attline.GetLineColor())) {
340 Error("DrawPolyLineW", "Could not find TColor for index %d", attline.GetLineColor());
341 return;
342 }
343
344 Quartz::SetLineStyle(ctx, attline.GetLineStyle());
345 Quartz::SetLineWidth(ctx, attline.GetLineWidth());
346
347 std::vector<TPoint> pnts;
348
349 //Convert to bottom-left-corner system.
350 ConvertPointsROOTToCocoa(n, xy, pnts, drawable);
351
352 if (drawable.fScaleFactor > 1.)
353 CGContextScaleCTM(ctx, 1. / drawable.fScaleFactor, 1. / drawable.fScaleFactor);
354
355 Quartz::DrawPolyLine(ctx, pnts.size(), pnts.data());
356
357 // CTM (current transformation matrix) is restored by 'ctxGuard's dtor.
358}
359
360//______________________________________________________________________________
362{
363 //Comment from TVirtualX:
364 // Draw a line through all points.
365 // n : number of points
366 // xy : list of points
367 //End of comment.
368
369 assert(fSelectedDrawable > fPimpl->GetRootWindowID() && "DrawPolyLine, bad drawable is selected");
370
372}
373
374//______________________________________________________________________________
376{
377 for(Int_t i = 0; i < 2*n; i += 2)
378 DrawPolyLineW(wctxt, 2, &xy[i]);
379}
380
381//______________________________________________________________________________
383{
384 auto drawable0 = (NSObject<X11Drawable> * const) wctxt;
385 if (!drawable0)
386 return;
387
388 auto &attmark = GetAttMarker(wctxt);
389
390 if ([drawable0 isDirectDraw]) {
391 if (!drawable0.fIsPixmap) {
392 QuartzView * const view = (QuartzView *)fPimpl->GetWindow(drawable0.fID).fContentView;
393 if (!view) {
394 ::Warning("DrawPolyMarkerW", "Invalid view/window for XOR-mode");
395 return;
396 }
397
398 [view.fQuartzWindow addXorMarker: view : n : xy : attmark ];
399 }
400
401 return;
402 }
403 auto drawable = (NSObject<X11Drawable> * const) GetPixmapDrawable(drawable0, "DrawPolyMarkerW");
404 if (!drawable)
405 return;
406
407 std::vector<TPoint> pnts;
408
409 ConvertPointsROOTToCocoa(n, xy, pnts, drawable);
410
411 CGContextRef ctx = drawable.fContext;
413 //AA flag is not a part of a state.
415
416 Quartz::DrawPolyMarker(ctx, pnts.size(), pnts.data(), attmark, drawable.fScaleFactor);
417}
418
419//______________________________________________________________________________
421{
422 //Comment from TVirtualX:
423 // Draw PolyMarker
424 // n : number of points
425 // xy : list of points
426 //End of comment.
427
429}
430
431
432//______________________________________________________________________________
434 const char *text, ETextMode mode)
435{
436 if (!text || !*text)
437 return;
438
439 if (!TTFhandle::Init()) {
440 Error("DrawTextW", "char string to draw, but TTF initialization failed");
441 return;
442 }
443
444 auto drawable0 = (NSObject<X11Drawable> * const) wctxt;
445 if (!drawable0)
446 return;
447
448 if ([drawable0 isDirectDraw])
449 return;
450
451 UInt_t width = 0, height = 0;
452 Int_t xy = 0;
454
455 auto &att = GetAttText(wctxt);
456
457 //Do not draw anything when pixel size too small
458 if (att.GetTextSize() < 1.5)
459 return;
460
462
463 ttf.SetSmoothing(kTRUE);
464 ttf.SetTextFont(att.GetTextFont());
465 ttf.SetTextSize(att.GetTextSize());
466 ttf.SetRotationMatrix(angle);
467 ttf.PrepareString(text);
468 ttf.LayoutGlyphs();
469
470 if (ttf.ApplyAlignRotate(x, y, att.GetTextAlign(), width, height))
472}
473
474//______________________________________________________________________________
480
481//______________________________________________________________________________
483 const wchar_t *text, ETextMode mode)
484{
485 if (!text || !*text)
486 return;
487
488 if (!TTFhandle::Init()) {
489 Error("DrawTextW", "wchar_t string to draw, but TTF initialization failed");
490 return;
491 }
492
493 auto drawable0 = (NSObject<X11Drawable> * const) wctxt;
494 if (!drawable0)
495 return;
496
497 if ([drawable0 isDirectDraw])
498 return;
499
500 UInt_t width = 0, height = 0;
501 Int_t xy = 0;
503
504 auto &att = GetAttText(wctxt);
505
506 //Do not draw anything, or CoreText will create some small (but not of size 0 font).
507 if (att.GetTextSize() < 1.5)
508 return;
509
511
512 ttf.SetSmoothing(kTRUE);
513 ttf.SetTextFont(att.GetTextFont());
514 ttf.SetTextSize(att.GetTextSize());
515 ttf.SetRotationMatrix(angle);
516 ttf.PrepareString(text);
517 ttf.LayoutGlyphs();
518
519 if (ttf.ApplyAlignRotate(x, y, att.GetTextAlign(), width, height))
521}
522
523//______________________________________________________________________________
525{
526 auto drawable0 = (NSObject<X11Drawable> * const) wctxt;
527 if (!drawable0)
528 return;
529
530 if ([drawable0 isDirectDraw])
531 return;
532
533 auto drawable = (NSObject<X11Drawable> * const) GetPixmapDrawable(drawable0, "DrawTTFglyphsW");
534 if (!drawable)
535 return;
536
537 //This code is a modified (for Quartz) version of TG11TTF text drawing
539 if ([drawable isKindOfClass : [QuartzPixmap class]])
540 dstPixmap = (QuartzPixmap *)drawable;
541 else if ([drawable isKindOfClass : [QuartzView class]] || [drawable isKindOfClass : [QuartzWindow class]])
542 dstPixmap = ((NSObject<X11Window> *)drawable).fBackBuffer;
543
544 if (!dstPixmap) {
545 //I can not read pixels from a window (I can, but this is too slow and unreliable).
546 Error("DrawTTFglyphsW", "fSelectedDrawable is neither QuartzPixmap nor a double buffered window");
547 return;
548 }
549
550 Int_t w = ttf.GetGlyphsWidth();
551 Int_t h = ttf.GetGlyphsHeight();
552
553 //By default, all pixels are set to 0 (all components, that's what code in TGX11TTF also does here).
555 if (!pixmap.Get()) {
556 Error("DrawTTFglyphsW", "pixmap creation failed");
557 return;
558 }
559
560 const unsigned char defaultBackgroundPixel[] = {255, 255, 255, 255};
562 if (mode == kClear) {
563 //For this mode, TGX11TTF does some work to: a) preserve pixels under symbols
564 //b) calculate (interpolate) pixel for glyphs.
565
566 X11::Rectangle bbox(x1, y1, w, h);
567 //We already check IsVisible, so, in principle, bbox at least has intersection with
568 //the current selected drawable.
570 arrayGuard.Reset([dstPixmap readColorBits : bbox]);
571
572 if (!arrayGuard.Get()) {
573 Error("DrawTTFglyphsW", "problem with reading background pixels");
574 return;
575 }
576
577 // This is copy & paste from TGX11TTF:
578 const Int_t xo = x1 < 0 ? -x1 : 0;
579 const Int_t yo = y1 < 0 ? -y1 : 0;
580
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];
586 }
587 }
588 } else {
589 //Find background color and set for all pixels.
591 }
592
593 CGContextRef ctx = drawable.fContext;
595
596 auto &att = GetAttText(wctxt);
597
598 ULong_t fore = TGCocoa::GetPixel(att.GetTextColor());
599 ULong_t back = 0xffffff;
600
601 CGContextSetRGBStrokeColor(ctx, 0., 0., 1., 1.);
602 // paint the glyphs in the pixmap.
603 for (UInt_t nglyph = 0; nglyph < ttf.GetNumGlyphs(); nglyph++) {
604 Int_t bx = 0, by = 0;
605 UChar_t *buffer = nullptr;
606 UInt_t width = 0, rows = 0, pitch = 0;
607 if (!ttf.GetGlyphData(nglyph, bx, by, buffer, width, rows, pitch))
608 continue;
609
610 if (ttf.GetSmoothing()) {
612 // background kClear, i.e. transparent, we take as background color
613 // the average of the rgb values of all pixels covered by this character
614 if (mode == kClear) {
615 const UInt_t maxDots = TMath::Min((UInt_t) 50000, width * rows);
616
617 //In original code, they first have to extract
618 //pixels and call XQueryColors.
619 //I have only one loop here.
620 ULong_t r = 0, g = 0, b = 0;
621 UInt_t dotCnt = 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)
630 break;
631 }
632 }
633 }
634
635 if (dotCnt > 0) {
636 r /= dotCnt;
637 g /= dotCnt;
638 b /= dotCnt;
639 }
640
641 col[0].fRed = (UShort_t) r;
642 col[0].fGreen = (UShort_t) g;
643 col[0].fBlue = (UShort_t) b;
644 } else {
645 // request background color
646 col[0].fPixel = back;
648 }
649
650 // request foreground color
651 col[4].fPixel = fore;
652 TGCocoa::QueryColor(kNone, col[4]);//calculate fRed/fGreen/fBlue triple from fPixel.
653
654 // interpolate between fore and background colors
655 for (int x = 3; x > 0; --x) {
656 col[x].fRed = (col[4].fRed * x + col[0].fRed * (4 - x)) / 4;
657 col[x].fGreen = (col[4].fGreen * x + col[0].fGreen * (4 - x)) / 4;
658 col[x].fBlue = (col[4].fBlue * x + col[0].fBlue * (4 - x)) / 4;
659 TGCocoa::AllocColor(kNone, col[x]);//Calculate fPixel from fRed/fGreen/fBlue triplet.
660 }
661
662 // put smoothed character, character pixmap values are an index
663 // into the 5 colors used for aliasing (4 = foreground, 0 = background)
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;
668 if (d > 4)
669 d = 4;
670 if (d > 0) {
671 const UChar_t pixel[] = {UChar_t(double(col[d].fRed) / 0xffff * 255),
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];
675 }
676 }
677 }
678 } else {
679 // no smoothing, just put character using foreground color
680 unsigned char rgba[4] = {};
681 rgba[3] = 255;
683 unsigned char d = 0;
684
685 const unsigned char *row = buffer;
686 for (unsigned y = 0; y < rows; ++y) {
687 unsigned n = 0;
688 const unsigned char *s = row;
689 for (unsigned x = 0; x < width; ++x) {
690 if (!n)
691 d = *s++;
692
693 if (TESTBIT(d,7 - n))
694 [pixmap.Get() putPixel : rgba X : bx + x Y : by + y];
695
696 if (++n == kBitsPerByte)
697 n = 0;
698 }
699
700 row += pitch;
701 }
702 }
703 }
704
705 const X11::Rectangle copyArea(0, 0, w, h);
706 const X11::Point dstPoint(x1, y1);
708}
709
710
711
712//______________________________________________________________________________
718
719
720//______________________________________________________________________________
722{
723 // Returns the current font magnification factor
724 return 0;
725}
726
727//______________________________________________________________________________
729{
730 // Set color index "cindex" for drawing lines.
732
734}
735
736
737//______________________________________________________________________________
739{
740 // Set line style.
742
744}
745
746
747//______________________________________________________________________________
749{
750 // Set the line width.
751
753
755}
756
757
758//______________________________________________________________________________
760{
761 // Set color index "cindex" for fill areas.
762
764
766}
767
768
769//______________________________________________________________________________
771{
772 // Set fill area style.
774
776}
777
778
779//______________________________________________________________________________
781{
782 // Set color index "cindex" for markers.
784
786}
787
788
789//______________________________________________________________________________
791{
792 // Set marker size index.
793 //
794 // markersize - the marker scale factor
796
798}
799
800
801//______________________________________________________________________________
803{
804 // Set marker style.
805
807
809}
810
811
812//______________________________________________________________________________
814{
815 // Set the text alignment.
816
818
820}
821
822//______________________________________________________________________________
824{
825 // Set the color index "cindex" for text.
826
828
830}
831
832
833//______________________________________________________________________________
835{
836 // Set the current text font number.
837
839
841}
842
843//______________________________________________________________________________
844Int_t TGQuartz::SetTextFont(char * /* fontName */, ETextSetMode /* mode */)
845{
846 Error("SetTextFont", "Direct TTF font setting not supported");
847 return 1;
848}
849
850//______________________________________________________________________________
852{
853 // Set the current text size to "textsize"
854
856
858}
859
860//______________________________________________________________________________
862{
863 // Set opacity of the current window. This image manipulation routine
864 // works by adding to a percent amount of neutral to each pixels RGB.
865 // Since it requires quite some additional color map entries is it
866 // only supported on displays with more than > 8 color planes (> 256
867 // colors).
868}
869
870//______________________________________________________________________________
871void TGQuartz::SetOpacityW(WinContext_t /* wctxt */, Int_t /* percent */)
872{
873}
874
875//______________________________________________________________________________
877{
878 att.Copy(GetAttFill(wctxt));
879
880 // TODO: remove this after transition done
881 TAttFill::SetFillColor(att.GetFillColor());
882 TAttFill::SetFillStyle(att.GetFillStyle());
883}
884
885//______________________________________________________________________________
887{
888 att.Copy(GetAttLine(wctxt));
889
890 // TODO: remove this after transition done
891 TAttLine::SetLineColor(att.GetLineColor());
892 TAttLine::SetLineStyle(att.GetLineStyle());
893 TAttLine::SetLineWidth(att.GetLineWidth());
894}
895
896//______________________________________________________________________________
898{
899 att.Copy(GetAttMarker(wctxt));
900
901 // TODO: remove this after transition done
902 TAttMarker::SetMarkerColor(att.GetMarkerColor());
903 TAttMarker::SetMarkerSize(att.GetMarkerSize());
904 TAttMarker::SetMarkerStyle(att.GetMarkerStyle());
905}
906
907//______________________________________________________________________________
909{
910 att.Copy(GetAttText(wctxt));
911
912 // TODO: remove this after transition done
913 TAttText::SetTextAlign(att.GetTextAlign());
914 TAttText::SetTextAngle(att.GetTextAngle());
915 TAttText::SetTextColor(att.GetTextColor());
916 TAttText::SetTextSize(att.GetTextSize());
917 TAttText::SetTextFont(att.GetTextFont());
918}
919
920//TTF related part.
921
922
923//Aux. functions.
924
925//______________________________________________________________________________
927{
928 if (gEnv) {
929 const TString value(TString(gEnv->GetValue("Cocoa.EnableAntiAliasing", "auto")).Strip());
930 if (value == "auto") {
932 } else if (value == "no")
933 fUseAA = false;
934 else {
935 assert(value == "yes" && "SetAA, value must be 'yes', 'no' or 'auto'");
936 fUseAA = true;
937 }
938 const TString valuefa(TString(gEnv->GetValue("Cocoa.EnableFillAreaAntiAliasing", "auto")).Strip());
939 if (valuefa == "auto") {
941 } else if (valuefa == "no")
942 fUseFAAA = false;
943 else {
944 assert(valuefa == "yes" && "SetAA, value must be 'yes', 'no' or 'auto'");
945 fUseFAAA = true;
946 }
947 }
948}
949
950//______________________________________________________________________________
952{
953 // attributes stored in direct drawable (view) and not in underlying pixmap
954 auto drawable = (NSObject<X11Drawable> *) wctxt;
955 if (!drawable || !drawable.attFill)
956 return *this;
957 return *drawable.attFill;
958}
959
960//______________________________________________________________________________
962{
963 // attributes stored in direct drawable (view) and not in underlying pixmap
964 auto drawable = (NSObject<X11Drawable> *) wctxt;
965 if (!drawable || !drawable.attLine)
966 return *this;
967 return *drawable.attLine;
968}
969
970//______________________________________________________________________________
972{
973 // attributes stored in direct drawable (view) and not in underlying pixmap
974 auto drawable = (NSObject<X11Drawable> *) wctxt;
975 if (!drawable || !drawable.attMarker)
976 return *this;
977 return *drawable.attMarker;
978}
979
980//______________________________________________________________________________
982{
983 // attributes stored in direct drawable (view) and not in underlying pixmap
984 auto drawable = (NSObject<X11Drawable> *) wctxt;
985 if (!drawable || !drawable.attText)
986 return *this;
987 return *drawable.attText;
988}
989
990//______________________________________________________________________________
991void *TGQuartz::GetPixmapDrawable(void *drawable0, const char *calledFrom) const
992{
993 assert(calledFrom != 0 && "GetDrawableChecked, calledFrom parameter is null");
994
995 if (!drawable0)
996 return nullptr;
997
998 auto drawable = (NSObject<X11Drawable> *) drawable0;
999 if (!drawable.fIsPixmap) {
1000 //TPad/TCanvas ALWAYS draw only into a pixmap.
1001 if ([drawable isKindOfClass : [QuartzView class]]) {
1002 QuartzView *view = (QuartzView *)drawable;
1003 if (!view.fBackBuffer) {
1004 Error(calledFrom, "Selected window is not double buffered");
1005 return nullptr;
1006 }
1007
1008 drawable = view.fBackBuffer;
1009 } else {
1010 Error(calledFrom, "Selected drawable is neither a pixmap, nor a double buffered window");
1011 return nullptr;
1012 }
1013 }
1014
1015 if (!drawable.fContext) {
1016 Error(calledFrom, "Context is null");
1017 return nullptr;
1018 }
1019
1020 return drawable;
1021}
Handle_t WinContext_t
Window drawing context.
Definition GuiTypes.h:30
Handle_t Drawable_t
Drawable handle.
Definition GuiTypes.h:32
const Handle_t kNone
Definition GuiTypes.h:89
#define d(i)
Definition RSha256.hxx:102
#define b(i)
Definition RSha256.hxx:100
#define g(i)
Definition RSha256.hxx:105
#define h(i)
Definition RSha256.hxx:106
short Style_t
Style number (short)
Definition RtypesCore.h:97
unsigned short UShort_t
Unsigned Short integer 2 bytes (unsigned short)
Definition RtypesCore.h:55
int Int_t
Signed integer 4 bytes (int)
Definition RtypesCore.h:60
short Color_t
Color number (short)
Definition RtypesCore.h:100
unsigned char UChar_t
Unsigned Character 1 byte (unsigned char)
Definition RtypesCore.h:53
constexpr ULong_t kBitsPerByte
Definition RtypesCore.h:131
unsigned long ULong_t
Unsigned long integer 4 bytes (unsigned long). Size depends on architecture.
Definition RtypesCore.h:70
short Width_t
Line width (short)
Definition RtypesCore.h:99
float Float_t
Float 4 bytes (float)
Definition RtypesCore.h:72
short Font_t
Font number (short)
Definition RtypesCore.h:96
short Short_t
Signed Short integer 2 bytes (short)
Definition RtypesCore.h:54
constexpr Bool_t kFALSE
Definition RtypesCore.h:109
short SCoord_t
Screen coordinates (short)
Definition RtypesCore.h:101
constexpr Bool_t kTRUE
Definition RtypesCore.h:108
#define TESTBIT(n, i)
Definition Rtypes.h:94
#define X(type, name)
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
R__EXTERN TEnv * gEnv
Definition TEnv.h:126
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 cindex
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void pixel
Option_t Option_t mgn
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 width
Option_t Option_t style
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
char name[80]
Definition TGX11.cxx:142
#define gROOT
Definition TROOT.h:417
Fill Area Attributes class.
Definition TAttFill.h:21
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
Definition TAttFill.h:40
virtual void SetFillStyle(Style_t fstyle)
Set the fill area style.
Definition TAttFill.h:42
Line Attributes class.
Definition TAttLine.h:21
virtual void SetLineStyle(Style_t lstyle)
Set the line style.
Definition TAttLine.h:46
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
Definition TAttLine.h:47
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition TAttLine.h:44
Marker Attributes class.
Definition TAttMarker.h:22
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.
Text Attributes class.
Definition TAttText.h:21
virtual void SetTextAlign(Short_t align=11)
Set the text alignment.
Definition TAttText.h:48
virtual void SetTextAngle(Float_t tangle=0)
Set the text angle.
Definition TAttText.h:49
virtual void SetTextColor(Color_t tcolor=1)
Set the text color.
Definition TAttText.h:50
virtual void SetTextFont(Font_t tfont=62)
Set the text font.
Definition TAttText.h:52
virtual void SetTextSize(Float_t tsize=1)
Set the text size.
Definition TAttText.h:53
TColorGradient extends basic TColor.
The color creation and management class.
Definition TColor.h:22
virtual Int_t GetValue(const char *name, Int_t dflt) const
Returns the integer value for a resource.
Definition TEnv.cxx:511
This class implements TVirtualX interface for MacOS X, using Cocoa and Quartz 2D.
Definition TGCocoa.h:57
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...
Definition TGCocoa.mm:2980
std::unique_ptr< ROOT::MacOSX::Details::CocoaPrivate > fPimpl
!
Definition TGCocoa.h:451
void QueryColor(Colormap_t cmap, ColorStruct_t &color) override
Returns the current RGB value for the pixel in the "color" structure.
Definition TGCocoa.mm:2990
WinContext_t GetSelectedContext()
Definition TGCocoa.mm:696
Drawable_t fSelectedDrawable
Definition TGCocoa.h:449
ULong_t GetPixel(Color_t cindex) override
Returns pixel value associated to specified ROOT color number "cindex".
Definition TGCocoa.mm:3005
void SetLineWidth(Width_t width) override
Set the line width.
Definition TGQuartz.mm:748
TAttMarker & GetAttMarker(WinContext_t wctxt)
Definition TGQuartz.mm:971
bool fUseFAAA
Definition TGQuartz.h:96
void SetAttLine(WinContext_t wctxt, const TAttLine &att) override
Set line attributes for specified window.
Definition TGQuartz.mm:886
void SetMarkerColor(Color_t cindex) override
Set the marker color.
Definition TGQuartz.mm:780
void SetFillStyle(Style_t style) override
Set the fill area style.
Definition TGQuartz.mm:770
void SetOpacity(Int_t percent) override
Sets opacity of the current window.
Definition TGQuartz.mm:861
void SetFillColor(Color_t cindex) override
Set the fill area color.
Definition TGQuartz.mm:759
void DrawPolyLine(Int_t n, TPoint *xy) override
Draws a line through all points in the list.
Definition TGQuartz.mm:361
Float_t GetTextMagnitude() override
Returns the current font magnification factor.
Definition TGQuartz.mm:721
void SetAttText(WinContext_t wctxt, const TAttText &att) override
Set text attributes for specified window.
Definition TGQuartz.mm:908
void SetAA()
Definition TGQuartz.mm:926
void DrawFillArea(Int_t n, TPoint *xy) override
Fills area described by the polygon.
Definition TGQuartz.mm:236
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.
Definition TGQuartz.mm:475
void DrawLine(Int_t x1, Int_t y1, Int_t x2, Int_t y2) override
Draws a line.
Definition TGQuartz.mm:294
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.
Definition TGQuartz.mm:433
void SetTextColor(Color_t cindex) override
Set the text color.
Definition TGQuartz.mm:823
void SetMarkerStyle(Style_t markerstyle) override
Set the marker style.
Definition TGQuartz.mm:802
bool fUseAA
Definition TGQuartz.h:95
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".
Definition TGQuartz.mm:166
void SetAttFill(WinContext_t wctxt, const TAttFill &att) override
Set fill attributes for specified window.
Definition TGQuartz.mm:876
void SetTextAlign(Short_t talign=11) override
Set the text alignment.
Definition TGQuartz.mm:813
TAttText & GetAttText(WinContext_t wctxt)
Definition TGQuartz.mm:981
void SetLineColor(Color_t cindex) override
Set the line color.
Definition TGQuartz.mm:728
void SetTextFont(Font_t fontnumber) override
Set the text font.
Definition TGQuartz.mm:834
void SetAttMarker(WinContext_t wctxt, const TAttMarker &att) override
Set marker attributes for specified window.
Definition TGQuartz.mm:897
void SetMarkerSize(Float_t markersize) override
Set the marker size.
Definition TGQuartz.mm:790
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.
Definition TGQuartz.mm:243
void DrawLinesSegmentsW(WinContext_t wctxt, Int_t n, TPoint *xy) override
Draw line segments on specified window.
Definition TGQuartz.mm:375
void SetTextSize(Float_t textsize) override
Set the text size.
Definition TGQuartz.mm:851
void DrawPolyMarkerW(WinContext_t wctxt, Int_t n, TPoint *xy) override
Draw poly marker on specified window.
Definition TGQuartz.mm:382
void DrawLineW(WinContext_t wctxt, Int_t x1, Int_t y1, Int_t x2, Int_t y2) override
Draw line on specified window.
Definition TGQuartz.mm:250
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.
Definition TGQuartz.mm:524
void DrawPolyLineW(WinContext_t wctxt, Int_t n, TPoint *xy) override
Draw poly line on specified window.
Definition TGQuartz.mm:307
void SetLineStyle(Style_t linestyle) override
Set the line style.
Definition TGQuartz.mm:738
TAttFill & GetAttFill(WinContext_t wctxt)
Definition TGQuartz.mm:951
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.
Definition TGQuartz.mm:94
void SetOpacityW(WinContext_t wctxt, Int_t percent) override
Set opactity for specified window.
Definition TGQuartz.mm:871
void DrawPolyMarker(Int_t n, TPoint *xy) override
Draws "n" markers with the current attributes at position [x,y].
Definition TGQuartz.mm:420
void * GetPixmapDrawable(void *drawable0, const char *calledFrom) const
Definition TGQuartz.mm:991
void DrawFillAreaW(WinContext_t wctxt, Int_t n, TPoint *xy) override
Draw fill area on specified window.
Definition TGQuartz.mm:172
TAttLine & GetAttLine(WinContext_t wctxt)
Definition TGQuartz.mm:961
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition TObject.cxx:1082
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:1096
Basic string class.
Definition TString.h:138
TSubString Strip(EStripType s=kTrailing, char c=' ') const
Return a substring of self stripped at beginning and/or end.
Definition TString.cxx:1170
Dynamic handle to work with freetype 2 library.
Definition TTFhandle.h:21
static Bool_t Init()
QuartzPixmap * fBackBuffer
QuartzWindow * fQuartzWindow
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
const Int_t n
Definition legend1.C:16
void PixelToRGB(Pixel_t pixelColor, CGFloat *rgb)
Definition X11Colors.mm:920
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)
Definition QuartzLine.mm:29
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)
Definition QuartzLine.mm:75
Short_t Min(Short_t a, Short_t b)
Returns the smallest of a and b.
Definition TMathBase.h:197