Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TGColorDialog.cxx
Go to the documentation of this file.
1// @(#)root/gui:$Id: c1ecfb3a4b91442ae3b6fe3059ae838e463f2f56 $
2// Author: Bertrand Bellenot + Fons Rademakers 22/08/02
3// Author: Ilka Antcheva (color wheel support) 16/03/07
4
5/*************************************************************************
6 * Copyright (C) 1995-2002, 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
14 This source is based on Xclass95, a Win95-looking GUI toolkit.
15 Copyright (C) 1996, 1997 David Barth, Ricky Ralston, Hector Peraza.
16
17 Xclass95 is free software; you can redistribute it and/or
18 modify it under the terms of the GNU Library General Public
19 License as published by the Free Software Foundation; either
20 version 2 of the License, or (at your option) any later version.
21
22**************************************************************************/
23
24
25/** \class TGColorPalette
26 \ingroup guiwidgets
27
28A widget showing an matrix of color cells. The colors can be set and selected.
29
30*/
31
32
33/** \class TGColorPick
34 \ingroup guiwidgets
35
36A widget which allows a color to be picked from HLS color space.
37It consists of two elements: a color map window from
38where the user can select the hue and saturation level of a color,
39and a slider to select color's lightness.
40
41Selecting a color in these two widgets will generate the event:
42 - kC_COLORSEL, kCOL_CLICK, widget id, 0.
43
44and the signal:
45 - ColorSelected(Pixel_t color)
46
47*/
48
49
50/** \class TGColorDialog
51 \ingroup guiwidgets
52
53A full featured color selection dialog.
54It uses 2 TGColorPalette's and the TGColorPick widgets.
55
56*/
57
58
59#include <cstdlib>
60
61#include "TGLabel.h"
62#include "TGMsgBox.h" // for ID_OK, ID_CANCEL
63#include "TGLayout.h"
64#include "TGGC.h"
65#include "KeySymbols.h"
66#include "TGColorDialog.h"
67#include "TGTextEntry.h"
68#include "TGButton.h"
69#include "TGResourcePool.h"
70#include "TColor.h"
71#include "TColorWheel.h"
72#include "TGColorSelect.h"
73#include "TGTab.h"
74#include "TRootEmbeddedCanvas.h"
75#include "TCanvas.h"
76#include "TROOT.h"
77#include "TMath.h"
78#include "TVirtualX.h"
79#include "snprintf.h"
80
81
82
83// TODO:
84// - implement "custom" colors.
85// - optimize the code, specially the one handling the fColormap image
86// and dithering in pseudo-color modes; remove duplicated code.
87// - improve the color allocation routine.
88// - use a buffering pixmap for the fColormap image.
89
108
114
119
120// "User" defined colors
121
122static ULong_t gUcolor[24] = { 0xff000000 };
123
124
125////////////////////////////////////////////////////////////////////////////////
126/// TGColorPalette widget: this is just a grid of color cells of the
127/// specified size. Colors can be selected by clicking on them or by
128/// using the arrow keys.
129
131 TGFrame(p, 10, 10, kChildFrame)
132{
133 fWidgetId = id;
135 fMsgWindow = p;
136 fDrawGC = *fClient->GetResourcePool()->GetFrameGC();
137
138 fCw = 20;
139 fCh = 17;
140
141 fRows = rows;
142 fCols = cols;
143
144 fCx = fCy = 0;
145
146 fPixels = new ULong_t[fRows * fCols];
147
148 for (Int_t i = 0; i < fRows * fCols; ++i) {
149 fPixels[i] = TColor::RGB2Pixel(255, 255, 255);
150 }
151
152 gVirtualX->GrabButton(fId, kAnyButton, kAnyModifier,
155
159}
160
161////////////////////////////////////////////////////////////////////////////////
162/// Destructor.
163
165{
166 delete [] fPixels;
167}
168
169////////////////////////////////////////////////////////////////////////////////
170/// Handle button events in color palette
171
173{
174 if (event->fCode != kButton1)
175 return kFALSE;
176
177 if ((event->fType == kButtonPress) && HasFocus())
178 WantFocus();
179
180 Int_t cx = event->fX / (fCw + 5);
181 Int_t cy = event->fY / (fCh + 5);
182
183 if (cx >= 0 && cx < fCols && cy >= 0 && cy < fRows) {
184
186
187 fCx = cx;
188 fCy = cy;
189
191
194 }
195
196 return kTRUE;
197}
198
199////////////////////////////////////////////////////////////////////////////////
200/// Handle mouse motion events in color palette.
201
203{
204 if (!IsEnabled())
205 return kTRUE;
206
207 Int_t cx = event->fX / (fCw + 5);
208 Int_t cy = event->fY / (fCh + 5);
209
210 if (cx >= 0 && cx < fCols && cy >= 0 && cy < fRows) {
211
213
214 fCx = cx;
215 fCy = cy;
216
218
221 }
222
223 return kTRUE;
224}
225
226////////////////////////////////////////////////////////////////////////////////
227/// Handle keyboard events in color palette.
228
230{
231 Char_t input[10];
233
234 if (event->fType == kGKeyPress) {
235
236 gVirtualX->LookupString(event, input, sizeof(input), keysym);
237
238 Int_t cx = fCx;
239 Int_t cy = fCy;
240
241 switch ((EKeySym)keysym) {
242 case kKey_Left:
243 if (cx > 0) --cx;
244 break;
245
246 case kKey_Right:
247 if (cx < fCols - 1) ++cx;
248 break;
249
250 case kKey_Up:
251 if (cy > 0) --cy;
252 break;
253
254 case kKey_Down:
255 if (cy < fRows - 1) ++cy;
256 break;
257
258 case kKey_Home:
259 cx = cy = 0;
260 break;
261
262 case kKey_End:
263 cx = fCols - 1;
264 cy = fRows - 1;
265 break;
266
267 default:
268 break;
269 }
270
271 if (cx != fCx || cy != fCy) {
272
274
275 fCx = cx;
276 fCy = cy;
277
279
282 }
283 }
284
285 return kTRUE;
286}
287
288////////////////////////////////////////////////////////////////////////////////
289/// Set color entries in color samples.
290
292{
293 for (Int_t i = 0; i < fRows * fCols; ++i)
294 SetColor(i, colors[i]);
295 gClient->NeedRedraw(this);
296}
297
298////////////////////////////////////////////////////////////////////////////////
299/// Set color at index ix of color entries.
300
302{
303 fPixels[ix] = color;
304 gClient->NeedRedraw(this);
305}
306
307////////////////////////////////////////////////////////////////////////////////
308/// Set current cell color.
309
311{
312 SetColor(fCy * fCols + fCx, color);
313}
314
315////////////////////////////////////////////////////////////////////////////////
316/// Set color cell size.
317
319{
320 fCw = w;
321 fCh = h;
322 gClient->NeedRedraw(this);
323}
324
325////////////////////////////////////////////////////////////////////////////////
326/// Return currently selected color value.
327
329{
330 if (fCx >= 0 && fCy >= 0)
331 return GetColorByIndex(fCy * fCols + fCx);
332 else
333 return TColor::RGB2Pixel(0, 0, 0);
334}
335
336////////////////////////////////////////////////////////////////////////////////
337/// Redraw color palette.
338
340{
341 Int_t i, j, k, x, y;
342
343 k = 0;
344 y = 2;
345 for (i = 0; i < fRows; ++i) {
346 x = 2;
347 for (j = 0; j < fCols; ++j) {
350 gVirtualX->FillRectangle(fId, fDrawGC(), x + 2, y + 2, fCw - 4, fCh - 4);
351 x += fCw + 5;
352 }
353 y += fCh + 5;
354 }
355
357}
358
359////////////////////////////////////////////////////////////////////////////////
360/// Add keyboard input.
361
366
367////////////////////////////////////////////////////////////////////////////////
368/// Remove keyboard input.
369
371{
373 gClient->NeedRedraw(this);
374}
375
376////////////////////////////////////////////////////////////////////////////////
377/// Draw a highlight rectangle around cell obtaining focus.
378
380{
381 if (fCx >= 0 && fCy >= 0) {
383 gVirtualX->DrawRectangle(fId, gc, fCx * (fCw + 5) + 0, fCy * (fCh + 5) + 0,
384 fCw + 3, fCh + 3);
385 }
386}
387
388
389////////////////////////////////////////////////////////////////////////////////
390/// TGColorPick constructor.
391/// TGColorPick is a widget which allows a color to be picked from HLS space.
392/// It consists of two elements: a color map window from where the user can
393/// select the hue and saturation level of a color, and a slider to select
394/// color's lightness.
395
397 TGFrame(p, w, h, kChildFrame), fCursorGC(GetBlackGC())
398{
399 UInt_t iw, ih;
400
401 fWidgetId = id;
403 fMsgWindow = p;
404
405 fColormapRect.fX = 1;
406 fColormapRect.fY = 1;
407 fColormapRect.fWidth = w - 33 - 2;
408 fColormapRect.fHeight = h - 2;
409 fSliderRect.fX = w - 18 - 2;
410 fSliderRect.fY = 1;
411 fSliderRect.fWidth = 10;
412 fSliderRect.fHeight = h - 2;
413
414 fNColors = 0;
415
416 if (!p) {
417 MakeZombie();
418 // coverity[uninit_member]
419 return;
420 }
421 CreateImages();
422 gVirtualX->GetImageSize(fLimage, iw, ih);
423
424 fCx = 0;
425 fCy = 0;
426 fCz = (Int_t)ih / 2;
427
429
431 InitImages();
432
433 gVirtualX->GrabButton(fId, kAnyButton, kAnyModifier,
436
440}
441
442////////////////////////////////////////////////////////////////////////////////
443/// TGColorPick destructor.
444
446{
447 if (IsZombie()) return;
448 gVirtualX->DeleteImage(fHSimage);
449 gVirtualX->DeleteImage(fLimage);
450 FreeColors();
451}
452
453////////////////////////////////////////////////////////////////////////////////
454/// Handle mouse button events in color pick widget.
455
457{
458 if (event->fCode != kButton1) return kFALSE;
459
460 if (event->fType == kButtonPress) {
461 if ((event->fX > fColormapRect.fX) && (event->fX < fColormapRect.fX + fColormapRect.fWidth) &&
462 (event->fY > fColormapRect.fY) && (event->fY < fColormapRect.fY + fColormapRect.fHeight)) {
463
465 SetHScursor(event->fX - fColormapRect.fX, event->fY - fColormapRect.fY);
466
467 } else if (event->fX > fSliderRect.fX) {
468
470 SetLcursor(event->fY - fSliderRect.fY);
471
472 }
473 } else { // ButtonRelease
474
476
477 }
478
481
484
485 return kTRUE;
486}
487
488////////////////////////////////////////////////////////////////////////////////
489/// Handle mouse motion events in color pick widget.
490
492{
493 if (!IsEnabled())
494 return kTRUE;
495
496 if (fClick == kCLICK_HS) {
497
498 SetHScursor(event->fX - fColormapRect.fX, event->fY - fColormapRect.fY);
499
500 } else if (fClick == kCLICK_L) {
501
502 SetLcursor(event->fY - fSliderRect.fY);
503
504 } else {
505
506 return kTRUE;
507
508 }
509
512
515
516 return kTRUE;
517}
518
519////////////////////////////////////////////////////////////////////////////////
520/// Create colormap and color slider images.
521
533
534////////////////////////////////////////////////////////////////////////////////
535/// Try to allocate first a palette of 64 colors. Used by the dithered
536/// version of the color maps.
537
539{
540 ColorStruct_t color;
541 Int_t i;
542
543 for (i = 0; i < 64; ++i) {
544 Int_t cc[4] = { 0, 21845, 43691, 65535 };
545 color.fPixel = 0;
546 color.fRed = cc[i & 0x3];
547 color.fGreen = cc[(i >> 2) & 0x3];
548 color.fBlue = cc[(i >> 4) & 0x3];
549 if (gVirtualX->AllocColor(gVirtualX->GetColormap(), color) == 0)
550 break;
551 fColormap[i][0] = color.fRed / 256;
552 fColormap[i][1] = color.fGreen / 256;
553 fColormap[i][2] = color.fBlue / 256;
554 fPixel[i] = color.fPixel;
555 }
556
557 fNColors = i;
558 if (fNColors == 64) return; // success
559
560 // Failed, try a simpler 27-color.
561
562 FreeColors();
563
564 for (i = 0; i < 27; ++i) {
565 Int_t cc[3] = { 0, 32768, 65535 };
566 color.fPixel = 0;
567 color.fRed = cc[i % 3];
568 color.fGreen = cc[(i / 3) % 3];
569 color.fBlue = cc[(i / 9) % 3];
570 if (gVirtualX->AllocColor(gVirtualX->GetColormap(), color) == 0)
571 break;
572 fColormap[i][0] = color.fRed / 256;
573 fColormap[i][1] = color.fGreen / 256;
574 fColormap[i][2] = color.fBlue / 256;
575 fPixel[i] = color.fPixel;
576 }
577
578 fNColors = i;
579 if (fNColors == 27) return; // success
580
581 // Failed, try then a much simpler 8-color.
582
583 FreeColors();
584
585 for (i = 0; i < 8; ++i) {
586 color.fPixel = 0;
587 color.fRed = (i & 1) * 65535;
588 color.fGreen = ((i >> 1) & 1) * 65535;
589 color.fBlue = ((i >> 2) & 1) * 65535;
590 if (gVirtualX->AllocColor(gVirtualX->GetColormap(), color) == 0)
591 break;
592 fColormap[i][0] = color.fRed / 256;
593 fColormap[i][1] = color.fGreen / 256;
594 fColormap[i][2] = color.fBlue / 256;
595 fPixel[i] = color.fPixel;
596 }
597
598 fNColors = i;
599 if (fNColors == 8) return; // success
600
601 // Failed, try to get at least 8 closest colors...
602 // (TODO: search for closest colors in the colormap, right now we just
603 // get as many as exact colors we can for the 8-color palette)
604
605 FreeColors();
606
607 for (i = 0; i < 8; ++i) {
608 color.fPixel = 0;
609 color.fRed = (i & 1) * 65535;
610 color.fGreen = ((i >> 1) & 1) * 65535;
611 color.fBlue = ((i >> 2) & 1) * 65535;
612 if (gVirtualX->AllocColor(gVirtualX->GetColormap(), color) != 0) {
613 fColormap[fNColors][0] = color.fRed / 256;
614 fColormap[fNColors][1] = color.fGreen / 256;
615 fColormap[fNColors][2] = color.fBlue / 256;
616 fPixel[fNColors++] = color.fPixel;
617 }
618 }
619
620 // continue with what we got...
621}
622
623////////////////////////////////////////////////////////////////////////////////
624/// Free allocated colors.
625
627{
628 for (Int_t i = 0; i < fNColors; i++)
629 gVirtualX->FreeColor(gVirtualX->GetColormap(), fPixel[i]);
630 fNColors = 0;
631}
632
633////////////////////////////////////////////////////////////////////////////////
634/// Create a dithered version of the color map and lightness images for
635/// display modes with reduced number of colors. The Floyd-Steinberg error
636/// diffusion dithering algorithm is used.
637/// This routine is called in PseudoColor modes only.
638
640{
641 const Int_t kWidth = 20;
642
644 struct { Int_t r, g, b; } ed[kWidth], ef;
645 Int_t x, y, c, v, e[4], nc = 0;
646 Int_t r, g, b;
647 Int_t h, l, s;
648 Long_t dist, sdist;
649 Int_t iw, ih;
650
651 gVirtualX->GetImageSize(image, (UInt_t&) iw, (UInt_t&) ih);
652
653 for (x = 0; x < iw; ++x) {
654 ed[x].r = ed[x].g = ed[x].b = 0;
655 }
656
657 if (fNColors == 0) AllocColors();
658
659 for (y = 0; y < ih; ++y) {
660
661 if (which == kIMG_HS) {
662
663 for (x = 0; x < iw; ++x) {
664
665 h = x * 255 / iw;
666 l = 128;
667 s = (ih - y) * 255 / ih;
668
669 TColor::HLS2RGB(h, l, s, r, g, b);
670
671 line[x].fRed = r;
672 line[x].fGreen = g;
673 line[x].fBlue = b;
674 }
675
676 } else if (which == kIMG_L) {
677
679 TColor::RGB2HLS(r, g, b, h, l, s);
680
681 Int_t ll = (ih - y) * 255 / ih;
682
683 TColor::HLS2RGB(h, ll, s, r, g, b);
684
685 for (x = 0; x < iw; ++x) {
686 line[x].fRed = r;
687 line[x].fGreen = g;
688 line[x].fBlue = b;
689 }
690
691 } else {
692
693 return;
694
695 }
696
697 ef.r = ef.g = ef.b = 0; // no forward error for first pixel
698
699 for (x = 0; x < iw; ++x) {
700
701 // add errors from previous line
702
703 v = line[x].fRed + ed[x].r;
704 if (v < 0) v = 0; else if (v > 255) v = 255;
705 line[x].fRed = v;
706
707 v = line[x].fGreen + ed[x].g;
708 if (v < 0) v = 0; else if (v > 255) v = 255;
709 line[x].fGreen = v;
710
711 v = line[x].fBlue + ed[x].b;
712 if (v < 0) v = 0; else if (v > 255) v = 255;
713 line[x].fBlue = v;
714
715 }
716
717 for (x = 0; x < iw; ++x) {
718
719 // add forward errors
720
721 v = line[x].fRed + ef.r;
722 if (v < 0) v = 0; else if (v > 255) v = 255;
723 line[x].fRed = v;
724
725 v = line[x].fGreen + ef.g;
726 if (v < 0) v = 0; else if (v > 255) v = 255;
727 line[x].fGreen = v;
728
729 v = line[x].fBlue + ef.b;
730 if (v < 0) v = 0; else if (v > 255) v = 255;
731 line[x].fBlue = v;
732
733 // find the nearest color in colormap[]
734
735 sdist = 255L * 255L * 255L;
736 for (c = 0; c < fNColors; ++c) {
737
738 Int_t dr = line[x].fRed - fColormap[c][0];
739 Int_t dg = line[x].fGreen - fColormap[c][1];
740 Int_t db = line[x].fBlue - fColormap[c][2];
741
742 dist = dr * dr + dg * dg + db * db;
743 if (dist < sdist) {
744 nc = c;
745 sdist = dist;
746 }
747 }
748
749 gVirtualX->PutPixel(image, x, y, fPixel[nc]);
750
751#define FILTER(v) \
752 e[0] = (7 * v) >> 4; \
753 e[1] = v >> 4; \
754 e[2] = (5 * v) >> 4; \
755 e[3] = (3 * v) >> 4;
756
757 v = line[x].fRed - fColormap[nc][0];
758 FILTER(v)
759
760 ef.r = e[0];
761 if (x < iw-1) ed[x+1].r = e[1];
762 if (x == 0) ed[x].r = e[2]; else ed[x].r += e[2];
763 if (x > 0) ed[x-1].r += e[3];
764
765 v = line[x].fGreen - fColormap[nc][1];
766 FILTER(v)
767
768 ef.g = e[0];
769 if (x < iw-1) ed[x+1].g = e[1];
770 if (x == 0) ed[x].g = e[2]; else ed[x].g += e[2];
771 if (x > 0) ed[x-1].g += e[3];
772
773 v = line[x].fBlue - fColormap[nc][2];
774 FILTER(v)
775
776 ef.b = e[0];
777 if (x < iw-1) ed[x+1].b = e[1];
778 if (x == 0) ed[x].b = e[2]; else ed[x].b += e[2];
779 if (x > 0) ed[x-1].b += e[3];
780
781 }
782 }
783}
784
785////////////////////////////////////////////////////////////////////////////////
786/// Initialize color palette and slider images.
787
789{
791 Int_t h, l, s;
792 Int_t r, g, b;
793
794 gVirtualX->GetImageSize(fHSimage, (UInt_t&) width, (UInt_t&) height);
795
796 // initialize fHSimage
797
798 Int_t ncolors = gVirtualX->GetDepth();
799
800 if (ncolors > 8) {
801 for (Int_t y = 0; y < height; ++y) {
802 for (Int_t x = 0; x < width; ++x) {
803
804 r = g = b = 0;
805 h = x * 255 / width;
806 l = 128;
807 s = (height - y) * 255 / height;
808
809 TColor::HLS2RGB(h, l, s, r, g, b);
810
812 gVirtualX->PutPixel(fHSimage, x, y, pixel);
813 }
814 }
815 } else {
817 }
818
819 // initialize fLimage
820
822}
823
824////////////////////////////////////////////////////////////////////////////////
825/// Set slider colors.
826
828{
830 Int_t h, l, s;
831 Int_t r, g, b;
832
833 gVirtualX->GetImageSize(fLimage, (UInt_t&) width, (UInt_t&) height);
834
835 Int_t ncolors = gVirtualX->GetDepth();
836
837 if (ncolors > 8) {
838
839 for (Int_t y = 0; y < height; ++y) {
840
842 TColor::RGB2HLS(r, g, b, h, l, s);
843
844 l = (height - y) * 255 / height;
845
846 TColor::HLS2RGB(h, l, s, r, g, b);
847
849
850 for (Int_t x = 0; x < width; ++x) {
851 gVirtualX->PutPixel(fLimage, x, y, pixel);
852 }
853 }
854 } else {
856 }
857
858 gClient->NeedRedraw(this);
859}
860
861////////////////////////////////////////////////////////////////////////////////
862/// Position the slider cursor on right color position.
863
865{
867 Int_t h, l, s;
868 Int_t r, g, b;
869
870 gVirtualX->GetImageSize(fHSimage, width, height);
871
872 fCurrentColor = color;
873
875 TColor::RGB2HLS(r, g, b, h, l, s);
876
877 SetHScursor(h * (Int_t)width / 256, (255 - s) * (Int_t)height / 256);
878
879 gVirtualX->GetImageSize(fLimage, width, height);
880
881 SetLcursor((255 - l) * (Int_t)height / 256);
882
884}
885
886////////////////////////////////////////////////////////////////////////////////
887/// Assign the current cursor position as currently selected color.
888
890{
893 Int_t r, g, b;
894 Int_t h, l, s;
895
896 gVirtualX->GetImageSize(fLimage, lwidth, lheight);
897 gVirtualX->GetImageSize(fHSimage, swidth, sheight);
898
899 h = Int_t(fCx * 255 / swidth);
900 l = Int_t((lheight - fCz) * 255 / lheight);
901 s = Int_t((sheight - fCy) * 255 / sheight);
902
903 TColor::HLS2RGB(h, l, s, r, g, b);
905}
906
907////////////////////////////////////////////////////////////////////////////////
908/// Redraw the color pick widget.
909
933
934////////////////////////////////////////////////////////////////////////////////
935/// Set hue / saturation cursor position.
936
938{
940
941 gVirtualX->GetImageSize(fHSimage, width, height);
942
944
945 fCx = x;
946 fCy = y;
947
948 if (fCx < 0)
949 fCx = 0;
950 else if (fCx >= (Int_t)width)
951 fCx = (Int_t)width - 1;
952
953 if (fCy < 0)
954 fCy = 0;
955 else if (fCy >= (Int_t)height)
956 fCy = (Int_t)height - 1;
957
959}
960
961////////////////////////////////////////////////////////////////////////////////
962/// Set lightness slider cursor position.
963
965{
967
968 gVirtualX->GetImageSize(fLimage, width, height);
969
971
972 fCz = z - fSliderRect.fY;
973
974 if (fCz < 0)
975 fCz = 0;
976 else if (fCz >= (Int_t)height)
977 fCz = (Int_t)height - 1;
978
980}
981
982////////////////////////////////////////////////////////////////////////////////
983/// Draw hue / saturation cursor
984
986{
988
989 gVirtualX->GetImageSize(fHSimage, width, height);
990
991 if (onoff) {
992 Int_t x, y;
994
995 x = fCx + fColormapRect.fX;
996 y = fCy + fColormapRect.fY;
997
1000 rect.fWidth = fColormapRect.fWidth;
1001 rect.fHeight = fColormapRect.fHeight;
1002 gVirtualX->SetClipRectangles(fCursorGC(), 0, 0, &rect, 1);
1003
1004 gVirtualX->FillRectangle(fId, fCursorGC(), x - 9, y - 1, 5, 3);
1005 gVirtualX->FillRectangle(fId, fCursorGC(), x - 1, y - 9, 3, 5);
1006 gVirtualX->FillRectangle(fId, fCursorGC(), x + 5, y - 1, 5, 3);
1007 gVirtualX->FillRectangle(fId, fCursorGC(), x - 1, y + 5, 3, 5);
1008
1009 } else {
1010 Int_t x, y;
1011 UInt_t w, h;
1012
1013 x = fCx - 9; w = 19;
1014 y = fCy - 9; h = 19;
1015
1016 if (x < 0) { w += x; x = 0; }
1017 if (y < 0) { h += y; y = 0; }
1018
1019 if (x + w > width) w = width - x;
1020 if (y + h > height) h = height - y;
1021
1022 gVirtualX->PutImage(fId, GetBckgndGC()(), fHSimage, x, y,
1024 }
1025}
1026
1027////////////////////////////////////////////////////////////////////////////////
1028/// Draw lightness slider cursor
1029
1031{
1033 Int_t r = l + 5;
1034 Int_t t = fCz - 5 + fSliderRect.fY;
1035 Int_t b = t + 10;
1036
1037 Point_t points[3];
1038
1039 Int_t m = (t + b) >> 1;
1040
1041 points[0].fX = r;
1042 points[0].fY = t;
1043 points[1].fX = r;
1044 points[1].fY = b;
1045 points[2].fX = l;
1046 points[2].fY = m;
1047
1049
1050 gVirtualX->FillPolygon(fId, gc, points, 3);
1051}
1052
1053
1054////////////////////////////////////////////////////////////////////////////////
1055/// Color selection dialog constructor.
1056/// The TGColorDialog presents a full featured color selection dialog.
1057/// It uses 2 TGColorPalette's and the TGColorPick widgets.
1058
1060 Int_t *retc, Pixel_t *color, Bool_t wait) :
1061 TGTransientFrame(p, m, 200, 150)
1062{
1063 const Int_t kC_X = 175; // Win95: 177
1064 const Int_t kC_Y = 180; // Win95: 189
1065
1066 Int_t i;
1067
1068 fRetc = retc;
1069 fRetColor = 0;
1070 fRetTColor = 0;
1071 fInitColor = 0;
1072 if (color) {
1073 fRetColor = color;
1076 }
1077 fWaitFor = wait;
1078
1079 if (fRetc) *fRetc = kMBCancel;
1080
1081 TGHorizontalFrame *hftop = new TGHorizontalFrame(this, 10, 10);
1082 hftop->SetCleanup();
1083 AddFrame(hftop, new TGLayoutHints(kLHintsTop | kLHintsLeft, 5, 5, 10, 5));
1084
1085 fTab = new TGTab(hftop, 300, 300);
1086 hftop->AddFrame(fTab);
1087
1088 TGCompositeFrame *cf = new TGCompositeFrame(hftop, 10, 10);
1089 cf->SetCleanup();
1090 hftop->AddFrame(cf, new TGLayoutHints(kLHintsLeft | kLHintsTop, 5, 0, 30, 0));
1091
1092 TGCompositeFrame *cf1 = new TGCompositeFrame(cf, 10, 10);
1093 cf1->SetCleanup();
1094 cf->AddFrame(cf1, new TGLayoutHints(kLHintsLeft | kLHintsTop, 5, 0, 30, 0));
1095 cf1->SetLayoutManager(new TGMatrixLayout(cf1, 0, 2, 4));
1096
1097 cf1->AddFrame(new TGLabel(cf1, new TGHotString("Red:")));
1098 cf1->AddFrame(fRte = new TGTextEntry(cf1, fRtb = new TGTextBuffer(5), kCDLG_RTE),0);
1100 cf1->AddFrame(new TGLabel(cf1, new TGHotString("Green:")),0);
1101 cf1->AddFrame(fGte = new TGTextEntry(cf1, fGtb = new TGTextBuffer(5), kCDLG_GTE),0);
1103 cf1->AddFrame(new TGLabel(cf1, new TGHotString("Blue:")));
1104 cf1->AddFrame(fBte = new TGTextEntry(cf1, fBtb = new TGTextBuffer(5), kCDLG_BTE),0);
1106 cf1->AddFrame(new TGLabel(cf1, new TGHotString("Opacity:")),0);
1107 cf1->AddFrame(fAle = new TGTextEntry(cf1, fAlb = new TGTextBuffer(5), kCDLG_ALE),0);
1109
1110 if (!TCanvas::SupportAlpha()) {
1112 }
1113
1114 TGCompositeFrame *cf2 = new TGCompositeFrame(cf, 10, 10);
1115 cf2->SetCleanup();
1116 cf->AddFrame(cf2, new TGLayoutHints(kLHintsLeft | kLHintsTop, 5, 0, 30, 0));
1117 cf2->SetLayoutManager(new TGMatrixLayout(cf2, 0, 2, 4));
1118 cf2->AddFrame(new TGLabel(cf2, new TGHotString("Hue:")),0);
1119 cf2->AddFrame(fHte = new TGTextEntry(cf2, fHtb = new TGTextBuffer(5), kCDLG_HTE),0);
1121 cf2->AddFrame(new TGLabel(cf2, new TGHotString("Sat:")),0);
1122 cf2->AddFrame(fSte = new TGTextEntry(cf2, fStb = new TGTextBuffer(5), kCDLG_STE),0);
1124 cf2->AddFrame(new TGLabel(cf2, new TGHotString("Lum:")),0);
1125 cf2->AddFrame(fLte = new TGTextEntry(cf2, fLtb = new TGTextBuffer(5), kCDLG_LTE),0);
1127
1128 fHte->Associate(this);
1129 fLte->Associate(this);
1130 fSte->Associate(this);
1131 fRte->Associate(this);
1132 fGte->Associate(this);
1133 fBte->Associate(this);
1134 fAle->Associate(this);
1135
1136 if (color) {
1137 UpdateRGBentries(color);
1138 UpdateHLSentries(color);
1139 UpdateAlpha(color);
1140 fCurrentColor = *color;
1141 } else {
1142 gClient->GetColorByName("red", fCurrentColor);
1143 }
1144
1145 // color sample
1146 TGCompositeFrame *cf3 = new TGCompositeFrame(cf, 10, 10);
1147 cf3->SetCleanup();
1148 cf3->SetLayoutManager(new TGMatrixLayout(cf3, 0, 1, 0));
1149 cf3->AddFrame(fColorInfo = new TGLabel(cf3, new TGString("New: not set ")),0);
1151 cf3->AddFrame(fSample = new TGFrame(cf3, 50, 25, kOwnBackground),0);
1152 cf3->AddFrame(fSampleOld = new TGFrame(cf3, 50, 25, kOwnBackground),0);
1153 cf3->AddFrame(new TGLabel(cf3, new TGString("Current")),0);
1154 cf->AddFrame(cf3, new TGLayoutHints(kLHintsLeft | kLHintsTop, 5, 5, 20, 0));
1157
1158 TGCompositeFrame *tf = fTab->AddTab("Color Wheel");
1160 tf->AddFrame(tf1);
1161 fEcanvas = new TRootEmbeddedCanvas("wheel", tf1, 360, 360);
1162 tf1->AddFrame(fEcanvas);
1164 wcan->SetBit(kNoContextMenu);
1165 fColorWheel = new TColorWheel();
1167 fColorWheel->Draw();
1168 wcan->Update();
1169 wcan->Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)","TGColorDialog",this,
1170 "SetColorInfo(Int_t,Int_t,Int_t,TObject*)");
1171
1172 tf = fTab->AddTab("Basic Colors");
1174 tf->AddFrame(tf2);
1175
1176 TGVerticalFrame *vf1 = new TGVerticalFrame(tf2, 20, 20);
1177 vf1->SetCleanup();
1178 TGVerticalFrame *vf2 = new TGVerticalFrame(tf2, 20, 20);
1179 vf2->SetCleanup();
1180
1181 tf2->AddFrame(vf1, new TGLayoutHints(kLHintsLeft | kLHintsExpandY));
1182 tf2->AddFrame(vf2, new TGLayoutHints(kLHintsLeft | kLHintsExpandY));
1183
1184 //----------------------------------------- Left panel
1185
1186 // basic colors
1187
1189 vf1->AddFrame(fPalette, new TGLayoutHints(kLHintsNormal, 5, 5, 15, 0));
1190 fPalette->Associate(this);
1191
1192 for (i = 0; i < 48; ++i)
1193 fPalette->SetColor(i, TColor::Number2Pixel(i+10)); // root colors
1194 // the basic colors were set via bcolor
1195 //fPalette->SetColor(i, TColor::GetPixel(bcolor[i][0], bcolor[i][1], bcolor[i][2]));
1196
1197 // add some default colors
1199
1200 Float_t r, g, b;
1201
1202 r = 232./255;
1203 g = 232./255;
1204 b = 222./255;
1205
1206 // Gui Builder background
1208 fPalette->SetColor(46, pixel);
1209
1210 r = 230./255;
1211 g = 230./255;
1212 b = 230./255;
1213
1214 // a la MAC background
1216 fPalette->SetColor(45, pixel);
1217
1218 r = 172./255;
1219 g = 174./255;
1220 b = 205./255;
1221
1222 // a la CDE background
1224 fPalette->SetColor(44, pixel);
1225
1226 r = 205./255;
1227 g = 195./255;
1228 b = 175./255;
1229
1230 // a la FOX background
1232 fPalette->SetColor(43, pixel);
1233
1234 // custom colors
1235
1236 vf1->AddFrame(new TGLabel(vf1, new TGHotString("&Custom Colors:")),
1237 new TGLayoutHints(kLHintsNormal, 5, 0, 15, 2));
1238
1240 vf1->AddFrame(fCpalette, new TGLayoutHints(kLHintsNormal, 5, 5, 5, 0));
1241 fCpalette->Associate(this);
1242
1243 if (gUcolor[0] == 0xff000000) {
1244 for (i = 0; i < 24; i++)
1245 gUcolor[i] = TColor::RGB2Pixel(255, 255, 255);
1246 }
1248
1249 // button frame - OK, Cancel
1250 TGHorizontalFrame *hf = new TGHorizontalFrame(this, 10, 10, kFixedWidth);
1251 hf->SetCleanup();
1252 AddFrame(hf, new TGLayoutHints(kLHintsBottom | kLHintsRight, 5, 5, 10, 5));
1253
1254 TGTextButton *ok = new TGTextButton(hf, new TGHotString("OK"), kCDLG_OK);
1256 fPreview = new TGTextButton(hf, new TGHotString("&Preview"), kCDLG_PREVIEW);
1257 fPreview->Connect("Clicked()", "TGColorDialog", this, "DoPreview()");
1258
1259 hf->AddFrame(ok, new TGLayoutHints(kLHintsBottom | kLHintsExpandX, 0, 3, 0, 0));
1260 hf->AddFrame(cancel, new TGLayoutHints(kLHintsBottom | kLHintsExpandX,3, 0, 0, 0));
1261 hf->AddFrame(fPreview, new TGLayoutHints(kLHintsBottom | kLHintsExpandX,3, 0, 0, 0));
1262
1263 UInt_t w = ok->GetDefaultWidth();
1264 w = TMath::Max(w, cancel->GetDefaultWidth());
1265 hf->Resize(3 * (w + 30), hf->GetDefaultHeight());
1266
1267 ok->Associate(this);
1268 cancel->Associate(this);
1269
1270 //----------------------------------------- Right panel
1271
1272 // fColormap frame
1273
1275 vf2->AddFrame(fColors, new TGLayoutHints(kLHintsLeft | kLHintsTop, 5, 0, 15, 5));
1276 fColors->Associate(this);
1277
1278 if (color)
1279 fColors->SetColor(*color);
1280
1281 TGTextButton *add = new TGTextButton(vf2, new TGHotString("&Add to Custom Colors"),
1282 kCDLG_ADD);
1283 vf2->AddFrame(add, new TGLayoutHints(kLHintsBottom | kLHintsExpandX,
1284 5, 10, 0, 5));
1285 add->Associate(this);
1286
1287 MapSubwindows();
1290
1291 //---- make the message box non-resizable
1292
1295
1296 SetWindowName("Color Selector");
1297 SetIconName("Color Selector");
1298 SetClassHints("ROOT", "ColorSelector");
1299
1305
1306
1307 //---- position relative to the parent's window
1308
1309 if (fClient->IsEditable()) {
1310 const TGWindow *main = fMain;
1311 fMain = fClient->GetRoot();
1313 fMain = main;
1314 } else {
1316 }
1317
1318 if (fWaitFor) {
1319 MapWindow();
1320 fClient->WaitForUnmap(this);
1321 DeleteWindow();
1322 }
1323}
1324
1325////////////////////////////////////////////////////////////////////////////////
1326/// TGColorDialog destructor.
1327
1329{
1330 fEcanvas->GetCanvas()->Disconnect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)");
1331 delete fEcanvas;
1332 Cleanup();
1333}
1334
1335////////////////////////////////////////////////////////////////////////////////
1336/// Change current color.
1337
1339{
1340 if (fCurrentColor == col) {
1341 return;
1342 }
1343 fInitColor = *fRetColor = col;
1344 if((fRetTColor = gROOT->GetColor(TColor::GetColor(col)))) {};
1345 fCurrentColor = col;
1346 fColors->SetColor(col);
1348 ColorSelected(col);
1349}
1350
1351////////////////////////////////////////////////////////////////////////////////
1352/// Emit signal about selected color.
1353
1355{
1356 Emit("ColorSelected(Pixel_t)", color);
1357}
1358
1359////////////////////////////////////////////////////////////////////////////////
1360/// Emit signal about selected alpha and color.
1361
1363{
1364 Emit("AlphaColorSelected(ULong_t)", color);
1365}
1366
1367////////////////////////////////////////////////////////////////////////////////
1368/// Called when window is closed via window manager.
1369
1371{
1372 // save user set colors
1373 for (Int_t i = 0; i < 24; ++i)
1375
1376 if (*fRetc != kMBOk) {
1378 ULongptr_t ptr;
1379 if((ptr = (ULongptr_t)gROOT->GetColor(TColor::GetColor(fInitColor)))) AlphaColorSelected(ptr);
1380 } else {
1383 }
1384 // don't call DeleteWindow() here since that will cause access
1385 // to the deleted dialog in the WaitFor() method (see ctor)
1386
1387 //OpenGL + XQuartz on Mac: gl context and related resources
1388 //must be deleted _before_ UnmapWindow.
1389 if (gVirtualX->InheritsFrom("TGX11") && fEcanvas->GetCanvas()->UseGL())
1391
1392 UnmapWindow();
1393}
1394
1395////////////////////////////////////////////////////////////////////////////////
1396/// Update Opacity text entry with alpha value of color c.
1397
1399{
1400 Char_t tmp[20];
1401 Double_t alpha;
1402
1403 if (TColor *color = gROOT->GetColor(TColor::GetColor(*c))) {
1404 alpha = color->GetAlpha();
1405 snprintf(tmp, 20, "%.1f", alpha);
1406 fAlb->Clear();
1407 fAlb->AddText(0,tmp);
1408 gClient->NeedRedraw(fAle);
1409 }
1410}
1411
1412
1413////////////////////////////////////////////////////////////////////////////////
1414/// Update RGB text entries with RGB values of color c.
1415
1417{
1418 Char_t tmp[20];
1419
1420 Int_t r, g, b;
1421 TColor::Pixel2RGB(*c, r, g, b);
1422
1423 snprintf(tmp, 20, "%d", r);
1424 fRtb->Clear();
1425 fRtb->AddText(0, tmp);
1426 gClient->NeedRedraw(fRte);
1427
1428 snprintf(tmp, 20, "%d", g);
1429 fGtb->Clear();
1430 fGtb->AddText(0, tmp);
1431 gClient->NeedRedraw(fGte);
1432
1433 snprintf(tmp, 20, "%d", b);
1434 fBtb->Clear();
1435 fBtb->AddText(0, tmp);
1436 gClient->NeedRedraw(fBte);
1437}
1438
1439////////////////////////////////////////////////////////////////////////////////
1440/// Update HLS text entries with HLS values of color c.
1441
1443{
1444 Char_t tmp[20];
1445
1446 Int_t h, l, s;
1447 Int_t r, g, b;
1448
1449 TColor::Pixel2RGB(*c, r, g, b);
1450 TColor::RGB2HLS(r, g, b, h, l, s);
1451
1452 snprintf(tmp, 20, "%d", h);
1453 fHtb->Clear();
1454 fHtb->AddText(0, tmp);
1455 gClient->NeedRedraw(fHte);
1456
1457 snprintf(tmp, 20, "%d", l);
1458 fLtb->Clear();
1459 fLtb->AddText(0, tmp);
1460 gClient->NeedRedraw(fLte);
1461
1462 snprintf(tmp, 20, "%d", s);
1463 fStb->Clear();
1464 fStb->AddText(0, tmp);
1465 gClient->NeedRedraw(fSte);
1466}
1467
1468////////////////////////////////////////////////////////////////////////////////
1469/// Process messages for the color selection dialog.
1470
1472{
1473 ULong_t color;
1474 Int_t h, l, s;
1475 Int_t r, g, b;
1476
1477 switch (GET_MSG(msg)) {
1478 case kC_COMMAND:
1479 switch (GET_SUBMSG(msg)) {
1480 case kCM_BUTTON:
1481 switch(parm1) {
1482 case kCDLG_ADD:
1484 break;
1485
1486 case kCDLG_OK:
1487 *fRetc = kMBOk;
1489 atoi(fGtb->GetString()),
1490 atoi(fBtb->GetString()));
1493 atof(fAlb->GetString()))));
1494 }
1495 CloseWindow();
1496 break;
1497 case kCDLG_CANCEL:
1498 if (!fClient->IsEditable()) {
1500 if (p && p->InheritsFrom("TGColorPopup"))
1501 p->PreviewColor(fSampleOld->GetBackground());
1502 }
1503 CloseWindow();
1504 break;
1505 }
1506 break;
1507 }
1508 break;
1509 case kC_COLORSEL:
1510 switch (GET_SUBMSG(msg)) {
1511 case kCOL_CLICK:
1512 switch (parm1) {
1513 case kCDLG_SPALETTE:
1514 color = fPalette->GetCurrentColor();
1516 ColorSelected(color);
1517 gClient->NeedRedraw(fSample);
1518 fCurrentColor = color;
1519 fColors->SetColor(color);
1520 UpdateRGBentries(&color);
1521 UpdateHLSentries(&color);
1522 UpdateAlpha(&color);
1523 break;
1524
1525 case kCDLG_CPALETTE:
1526 color = fCpalette->GetCurrentColor();
1528 ColorSelected(color);
1529 gClient->NeedRedraw(fSample);
1530 fCurrentColor = color;
1531 fColors->SetColor(color);
1532 UpdateRGBentries(&color);
1533 UpdateHLSentries(&color);
1534 UpdateAlpha(&color);
1535 break;
1536
1537 case kCDLG_COLORPICK:
1538 color = fColors->GetCurrentColor();
1540 ColorSelected(color);
1541 gClient->NeedRedraw(fSample);
1542 fCurrentColor = color;
1543 UpdateRGBentries(&color);
1544 UpdateHLSentries(&color);
1545 UpdateAlpha(&color);
1546 break;
1547
1548 }
1549 break;
1550 }
1551 break;
1552
1553 case kC_TEXTENTRY:
1554 switch (GET_SUBMSG(msg)) {
1555 case kTE_TEXTCHANGED:
1556 switch (parm1) {
1557 case kCDLG_HTE:
1558 case kCDLG_LTE:
1559 case kCDLG_STE:
1560
1561 h = atoi(fHtb->GetString());
1562 l = atoi(fLtb->GetString());
1563 s = atoi(fStb->GetString());
1564 TColor::HLS2RGB(h, l, s, r, g, b);
1565
1566 color = TColor::RGB2Pixel(r, g, b);
1568 ColorSelected(color);
1569 gClient->NeedRedraw(fSample);
1570 fCurrentColor = color;
1571 fColors->SetColor(color);
1572 UpdateRGBentries(&color);
1573 break;
1574
1575 case kCDLG_RTE:
1576 case kCDLG_GTE:
1577 case kCDLG_BTE:
1578 color = TColor::RGB2Pixel(atoi(fRtb->GetString()),
1579 atoi(fGtb->GetString()),
1580 atoi(fBtb->GetString()));
1582 ColorSelected(color);
1583 gClient->NeedRedraw(fSample);
1584 fCurrentColor = color;
1585 fColors->SetColor(color);
1586 UpdateHLSentries(&color);
1587 break;
1588
1589 }
1590 break;
1591 }
1592 break;
1593 }
1594
1595 return kTRUE;
1596}
1597
1598////////////////////////////////////////////////////////////////////////////////
1599/// Set the color info in RGB and HLS parts
1600
1602{
1603 if (object == fColorWheel) {
1604 Int_t n = fColorWheel->GetColor(px,py);
1605 if (n < 0) return;
1606 TColor *color = gROOT->GetColor(n);
1607 if (!color) return;
1608 ULong_t pcolor = color->GetPixel();
1609 if (event == kButton1Down) {
1614 fColorInfo->SetText(Form("New: %s",color->GetName()));
1615 gClient->NeedRedraw(fSample);
1616 gClient->NeedRedraw(fColorInfo);
1620 }
1621 }
1622}
1623
1624////////////////////////////////////////////////////////////////////////////////
1625/// Slot method called when Preview button is clicked.
1626
1628{
1629 TColor *tcolor;
1630 if ((tcolor = gROOT->GetColor(TColor::GetColor(fSample->GetBackground())))) {
1631 tcolor->SetAlpha(TMath::Max((Double_t)0, TMath::Min((Double_t)1, atof(fAlb->GetString()))));
1632 }
1633
1634 if (fClient->IsEditable()) {
1637 return;
1638 }
1640 if (p && p->InheritsFrom("TGColorPopup")) {
1641 if (tcolor) p->PreviewAlphaColor((ULongptr_t)tcolor);
1642 else p->PreviewColor(fSample->GetBackground());
1643 }
1644}
@ kButton1Down
Definition Buttons.h:17
@ kGKeyPress
Definition GuiTypes.h:60
@ kButtonPress
Definition GuiTypes.h:60
Handle_t Pixmap_t
Pixmap handle.
Definition GuiTypes.h:30
const Mask_t kFocusChangeMask
Definition GuiTypes.h:169
const Mask_t kButtonPressMask
Definition GuiTypes.h:161
const Mask_t kKeyReleaseMask
Definition GuiTypes.h:160
const Mask_t kAnyModifier
Definition GuiTypes.h:210
const Mask_t kKeyPressMask
Definition GuiTypes.h:159
Handle_t GContext_t
Graphics context handle.
Definition GuiTypes.h:38
const Mask_t kPointerMotionMask
Definition GuiTypes.h:163
@ kChildFrame
Definition GuiTypes.h:379
@ kSunkenFrame
Definition GuiTypes.h:383
@ kDoubleBorder
Definition GuiTypes.h:385
@ kFixedWidth
Definition GuiTypes.h:387
@ kHorizontalFrame
Definition GuiTypes.h:382
@ kOwnBackground
Definition GuiTypes.h:391
const Handle_t kNone
Definition GuiTypes.h:88
const Mask_t kLeaveWindowMask
Definition GuiTypes.h:168
const Mask_t kStructureNotifyMask
Definition GuiTypes.h:166
const Mask_t kButtonReleaseMask
Definition GuiTypes.h:162
const Mask_t kEnterWindowMask
Definition GuiTypes.h:167
ULong_t Pixel_t
Pixel value.
Definition GuiTypes.h:40
@ kButton1
Definition GuiTypes.h:214
@ kAnyButton
Definition GuiTypes.h:214
EKeySym
Definition KeySymbols.h:25
@ kKey_Right
Definition KeySymbols.h:42
@ kKey_Down
Definition KeySymbols.h:43
@ kKey_Up
Definition KeySymbols.h:41
@ kKey_Left
Definition KeySymbols.h:40
@ kKey_Home
Definition KeySymbols.h:38
@ kKey_End
Definition KeySymbols.h:39
int main()
Definition Prototype.cxx:12
#define b(i)
Definition RSha256.hxx:100
#define c(i)
Definition RSha256.hxx:101
#define g(i)
Definition RSha256.hxx:105
#define h(i)
Definition RSha256.hxx:106
#define e(i)
Definition RSha256.hxx:103
int Int_t
Signed integer 4 bytes (int)
Definition RtypesCore.h:59
long Longptr_t
Integer large enough to hold a pointer (platform-dependent)
Definition RtypesCore.h:89
char Char_t
Character 1 byte (char)
Definition RtypesCore.h:51
unsigned long ULong_t
Unsigned long integer 4 bytes (unsigned long). Size depends on architecture.
Definition RtypesCore.h:69
long Long_t
Signed long integer 4 bytes (long). Size depends on architecture.
Definition RtypesCore.h:68
unsigned long ULongptr_t
Unsigned integer large enough to hold a pointer (platform-dependent)
Definition RtypesCore.h:90
float Float_t
Float 4 bytes (float)
Definition RtypesCore.h:71
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
#define gClient
Definition TGClient.h:157
EColorPick
@ kCLICK_NONE
@ kCLICK_HS
@ kCLICK_L
#define FILTER(v)
EColorImage
@ kIMG_HS
@ kIMG_L
EColorDialog
@ kCDLG_OK
@ kCDLG_RTE
@ kCDLG_SPALETTE
@ kCDLG_LTE
@ kCDLG_BTE
@ kCDLG_ALE
@ kCDLG_STE
@ kCDLG_CANCEL
@ kCDLG_ADD
@ kCDLG_PREVIEW
@ kCDLG_GTE
@ kCDLG_COLORPICK
@ kCDLG_HTE
@ kCDLG_CPALETTE
static ULong_t gUcolor[24]
@ kMWMDecorResizeH
Definition TGFrame.h:65
@ kMWMFuncAll
Definition TGFrame.h:49
@ kMWMFuncResize
Definition TGFrame.h:50
@ kMWMDecorMaximize
Definition TGFrame.h:69
@ kMWMDecorMinimize
Definition TGFrame.h:68
@ kMWMDecorMenu
Definition TGFrame.h:67
@ kMWMDecorAll
Definition TGFrame.h:63
@ kMWMFuncMaximize
Definition TGFrame.h:53
@ kMWMInputModeless
Definition TGFrame.h:57
@ kMWMFuncMinimize
Definition TGFrame.h:52
@ kLHintsRight
Definition TGLayout.h:26
@ kLHintsExpandY
Definition TGLayout.h:31
@ kLHintsLeft
Definition TGLayout.h:24
@ kLHintsNormal
Definition TGLayout.h:32
@ kLHintsBottom
Definition TGLayout.h:29
@ kLHintsTop
Definition TGLayout.h:27
@ kLHintsExpandX
Definition TGLayout.h:30
@ kMBCancel
Definition TGMsgBox.h:37
@ kMBOk
Definition TGMsgBox.h:33
@ kTextLeft
Definition TGWidget.h:23
@ kWidgetIsEnabled
Definition TGWidget.h:37
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void input
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize UnmapWindow
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 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 Int_t Int_t UInt_t UInt_t Rectangle_t rect
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize id
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void SetMWMHints
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t SetWMSizeHints
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t points
Option_t Option_t width
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 GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void gc
@ kNoContextMenu
Definition TObject.h:376
#define gROOT
Definition TROOT.h:411
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
Definition TString.cxx:2495
#define gVirtualX
Definition TVirtualX.h:337
Int_t MK_MSG(EWidgetMessageTypes msg, EWidgetMessageTypes submsg)
Int_t GET_MSG(Long_t val)
@ kTE_TEXTCHANGED
@ kCOL_CLICK
@ kC_COLORSEL
@ kC_COMMAND
@ kCM_BUTTON
@ kC_TEXTENTRY
Int_t GET_SUBMSG(Long_t val)
Color * colors
Definition X3DBuffer.c:21
#define snprintf
Definition civetweb.c:1579
The Canvas class.
Definition TCanvas.h:23
void DeleteCanvasPainter()
assert on IsBatch() == false?
Definition TCanvas.cxx:2623
static Bool_t SupportAlpha()
Static function returning "true" if transparency is supported.
Definition TCanvas.cxx:2473
Bool_t UseGL() const
Definition TCanvas.h:228
Draw the ROOT Color Wheel.
Definition TColorWheel.h:23
virtual void SetCanvas(TCanvas *can)
Definition TColorWheel.h:61
virtual Int_t GetColor(Int_t px, Int_t py) const
Return the color number pointed by the mouse.
void Draw(Option_t *option="") override
Paint the color wheel.
The color creation and management class.
Definition TColor.h:22
static void HLS2RGB(Float_t h, Float_t l, Float_t s, Float_t &r, Float_t &g, Float_t &b)
Static method to compute RGB from HLS.
Definition TColor.cxx:1581
static ULong_t RGB2Pixel(Int_t r, Int_t g, Int_t b)
Convert r,g,b to graphics system dependent pixel value.
Definition TColor.cxx:2483
static ULong_t Number2Pixel(Int_t ci)
Static method that given a color index number, returns the corresponding pixel value.
Definition TColor.cxx:2445
static Int_t GetColor(const char *hexcolor)
Static method returning color number for color specified by hex color string of form: "#rrggbb",...
Definition TColor.cxx:1926
static void Pixel2RGB(ULong_t pixel, Int_t &r, Int_t &g, Int_t &b)
Convert machine dependent pixel value (obtained via RGB2Pixel or via Number2Pixel() or via TColor::Ge...
Definition TColor.cxx:2521
ULong_t GetPixel() const
Return pixel value corresponding to this color.
Definition TColor.cxx:1564
virtual void SetAlpha(Float_t a)
Definition TColor.h:71
static void RGB2HLS(Float_t r, Float_t g, Float_t b, Float_t &h, Float_t &l, Float_t &s)
Static method to compute HLS from RGB.
Definition TColor.cxx:1721
Bool_t IsEditable() const
Definition TGClient.h:89
const TGWindow * GetRoot() const
Returns current root (i.e.
Definition TGClient.cxx:223
void WaitForUnmap(TGWindow *w)
Wait for window to be unmapped.
Definition TGClient.cxx:745
const TGResourcePool * GetResourcePool() const
Definition TGClient.h:124
TGTextEntry * fLte
TGTextEntry * fBte
Bool_t ProcessMessage(Longptr_t msg, Longptr_t parm1, Longptr_t parm2) override
Process messages for the color selection dialog.
TGColorPalette * fPalette
color palette
TGTab * fTab
tab widget holding the color selectors
TGLabel * fColorInfo
color info
virtual void SetCurrentColor(Pixel_t col)
Change current color.
void DoPreview()
Slot method called when Preview button is clicked.
TGTextEntry * fRte
Int_t * fRetc
return code (kMBOk, kMBCancel)
TColorWheel * fColorWheel
color wheel
TGTextBuffer * fStb
TGTextBuffer * fAlb
RGB/HLS associated buffers.
TGTextButton * fPreview
preview button;
Pixel_t fCurrentColor
currently selected color
Pixel_t * fRetColor
return color
TGColorPick * fColors
color pick widget
TGColorDialog(const TGColorDialog &)=delete
TColor * fRetTColor
return TColor, needed for changed alpha
TGTextEntry * fHte
void SetColorInfo(Int_t event, Int_t px, Int_t py, TObject *selected)
Set the color info in RGB and HLS parts.
TRootEmbeddedCanvas * fEcanvas
embedded canvas holding the color wheel
TGColorPalette * fCpalette
color palette
TGTextBuffer * fLtb
virtual void ColorSelected(Pixel_t)
Emit signal about selected color.
void CloseWindow() override
Called when window is closed via window manager.
TGTextEntry * fAle
RGB/HLS text entries.
TGFrame * fSample
color sample frame
TGTextBuffer * fBtb
TGTextBuffer * fHtb
virtual void AlphaColorSelected(ULongptr_t)
Emit signal about selected alpha and color.
TGTextBuffer * fRtb
Bool_t fWaitFor
call WaitFor method in constructor
Pixel_t fInitColor
initially set color
void UpdateRGBentries(Pixel_t *c)
Update RGB text entries with RGB values of color c.
void UpdateHLSentries(Pixel_t *c)
Update HLS text entries with HLS values of color c.
TGFrame * fSampleOld
color sample frame
TGTextEntry * fGte
~TGColorDialog() override
TGColorDialog destructor.
void UpdateAlpha(Pixel_t *c)
Update Opacity text entry with alpha value of color c.
TGTextEntry * fSte
TGTextBuffer * fGtb
A widget showing an matrix of color cells.
void SetCellSize(Int_t w=20, Int_t h=17)
Set color cell size.
Bool_t HandleButton(Event_t *event) override
Handle button events in color palette.
Bool_t HandleMotion(Event_t *event) override
Handle mouse motion events in color palette.
void SetColors(Pixel_t colors[])
Set color entries in color samples.
void DoRedraw() override
Redraw color palette.
Int_t fRows
number of color cell rows
Pixel_t GetColorByIndex(Int_t ix) const
virtual void LostFocus()
Remove keyboard input.
Pixel_t GetCurrentColor() const
Return currently selected color value.
UInt_t fCh
color cell height
void SetCurrentCellColor(Pixel_t color)
Set current cell color.
Int_t fCols
number of color cell columns
UInt_t fCw
color cell width
void DrawFocusHilite(Int_t onoff)
Draw a highlight rectangle around cell obtaining focus.
Pixel_t * fPixels
pixel value of colors
TGGC fDrawGC
graphics context used for drawing
virtual void GotFocus()
Add keyboard input.
void SetColor(Int_t ix, Pixel_t color)
Set color at index ix of color entries.
Int_t fCy
y coordinate of currently selected color cell
TGColorPalette(const TGColorPalette &)=delete
~TGColorPalette() override
Destructor.
virtual void ColorSelected(Pixel_t col=0)
Bool_t HandleKey(Event_t *event) override
Handle keyboard events in color palette.
Int_t fCx
x coordinate of currently selected color cell
A widget which allows a color to be picked from HLS color space.
Bool_t HandleButton(Event_t *event) override
Handle mouse button events in color pick widget.
void SetLcursor(Int_t z)
Set lightness slider cursor position.
void DoRedraw() override
Redraw the color pick widget.
Int_t fCx
x position in hs colormap
~TGColorPick() override
TGColorPick destructor.
Pixmap_t fLimage
color lightness slider pixmap
Int_t fNColors
number of color samples
Pixmap_t fHSimage
hue / saturation colormap pixmap
void UpdateCurrentColor()
Assign the current cursor position as currently selected color.
Int_t fClick
mouse click location (kCLICK_NONE, kCLICK_HS, kCLICK_L)
void CreateImages()
Create colormap and color slider images.
void SetColor(Pixel_t color)
Position the slider cursor on right color position.
virtual void ColorSelected(Pixel_t col=0)
Pixel_t fCurrentColor
currently selected color value
Int_t fCz
position in lightness slider
void SetSliderColor()
Set slider colors.
TGColorPick(const TGWindow *p=nullptr, Int_t w=1, Int_t h=1, Int_t id=-1)
TGColorPick constructor.
void AllocColors()
Try to allocate first a palette of 64 colors.
Rectangle_t fColormapRect
hue / saturation colormap rectangle
void FreeColors()
Free allocated colors.
Pixel_t GetCurrentColor() const
Int_t fColormap[64][3]
void DrawHScursor(Int_t onoff)
Draw hue / saturation cursor.
void CreateDitheredImage(Pixmap_t image, Int_t which)
Create a dithered version of the color map and lightness images for display modes with reduced number...
void DrawLcursor(Int_t onoff)
Draw lightness slider cursor.
void InitImages()
Initialize color palette and slider images.
Rectangle_t fSliderRect
color lightness slider rectangle
void SetHScursor(Int_t x, Int_t y)
Set hue / saturation cursor position.
Bool_t HandleMotion(Event_t *event) override
Handle mouse motion events in color pick widget.
Pixel_t fPixel[64]
Int_t fCy
y position in hs colormap
TGGC fCursorGC
color lightness slider cursor GC
A popup containing a TG16ColorSelector and a "More..." button which popups up a TGColorDialog allowin...
The base class for composite widgets (menu bars, list boxes, etc.).
Definition TGFrame.h:289
TGDimension GetDefaultSize() const override
std::cout << fWidth << "x" << fHeight << std::endl;
Definition TGFrame.h:318
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=nullptr)
Add frame to the composite frame using the specified layout hints.
Definition TGFrame.cxx:1109
virtual void Cleanup()
Cleanup and delete all objects contained in this composite frame.
Definition TGFrame.cxx:959
void MapSubwindows() override
Map all sub windows that are part of the composite frame.
Definition TGFrame.cxx:1156
TGCompositeFrame(const TGCompositeFrame &)=delete
void SetEditDisabled(UInt_t on=1) override
Set edit disable flag for this frame and subframes.
Definition TGFrame.cxx:1014
A subclasses of TGWindow, and is used as base class for some simple widgets (buttons,...
Definition TGFrame.h:80
void AddInput(UInt_t emask)
Add events specified in the emask to the events the frame should handle.
Definition TGFrame.cxx:331
void Resize(UInt_t w=0, UInt_t h=0) override
Resize the frame.
Definition TGFrame.cxx:597
void RemoveInput(UInt_t emask)
Remove events specified in emask from the events the frame should handle.
Definition TGFrame.cxx:340
TGFrame(const TGFrame &)=delete
UInt_t fHeight
frame height
Definition TGFrame.h:88
virtual UInt_t GetDefaultWidth() const
Definition TGFrame.h:192
virtual UInt_t GetDefaultHeight() const
Definition TGFrame.h:193
virtual void DrawBorder()
Draw frame border.
Definition TGFrame.cxx:413
virtual void Draw3dRectangle(UInt_t type, Int_t x, Int_t y, UInt_t w, UInt_t h)
Draw 3D rectangle on the frame border.
Definition TGFrame.cxx:349
void SetBackgroundColor(Pixel_t back) override
Set background color (override from TGWindow base class).
Definition TGFrame.cxx:304
void MapWindow() override
map window
Definition TGFrame.h:206
static Pixel_t GetDefaultFrameBackground()
Get default frame background.
Definition TGFrame.cxx:675
virtual void DeleteWindow()
Delete window.
Definition TGFrame.cxx:268
virtual void SendMessage(const TGWindow *w, Longptr_t msg, Longptr_t parm1, Longptr_t parm2)
Send message (i.e.
Definition TGFrame.cxx:637
static const TGGC & GetShadowGC()
Get shadow color graphics context.
Definition TGFrame.cxx:757
UInt_t fWidth
frame width
Definition TGFrame.h:87
virtual Pixel_t GetBackground() const
Definition TGFrame.h:194
static const TGGC & GetBckgndGC()
Get background color graphics context.
Definition TGFrame.cxx:767
void SetForeground(Pixel_t v)
Set foreground color.
Definition TGGC.cxx:277
A composite frame that layout their children in horizontal way.
Definition TGFrame.h:387
TGHotString is a string with a "hot" character underlined.
Definition TGString.h:42
This class handles GUI labels.
Definition TGLabel.h:24
void SetTextJustify(Int_t tmode)
Set text justification.
Definition TGLabel.cxx:395
virtual void SetText(TGString *newText)
Set new text in label.
Definition TGLabel.cxx:179
This class describes layout hints used by the layout classes.
Definition TGLayout.h:50
void SetClassHints(const char *className, const char *resourceName)
Set the windows class and resource name.
Definition TGFrame.cxx:1850
void SetIconName(const char *name)
Set window icon name. This is typically done via the window manager.
Definition TGFrame.cxx:1793
void SetWMSize(UInt_t w, UInt_t h)
Give the window manager a window size hint.
Definition TGFrame.cxx:1885
void SetWindowName(const char *name=nullptr) override
Set window name. This is typically done via the window manager.
Definition TGFrame.cxx:1780
This layout managers does not make use of TGLayoutHints.
Definition TGLayout.h:269
TGClient * fClient
Connection to display server.
Definition TGObject.h:25
Handle_t fId
X11/Win32 Window identifier.
Definition TGObject.h:24
TGString wraps a TString and adds some graphics routines like drawing, size of string on screen depen...
Definition TGString.h:20
A tab widget contains a set of composite frames each with a little tab with a name (like a set of fol...
Definition TGTab.h:46
virtual TGCompositeFrame * AddTab(TGString *text)
Add a tab to the tab widget.
Definition TGTab.cxx:373
A text buffer is used in several widgets, like TGTextEntry, TGFileDialog, etc.
void AddText(Int_t pos, const char *text)
const char * GetString() const
Yield an action as soon as it is clicked.
Definition TGButton.h:142
A TGTextEntry is a one line text input widget.
Definition TGTextEntry.h:24
void SetEnabled(Bool_t flag=kTRUE)
Defines transient windows that typically are used for dialogs windows.
Definition TGFrame.h:500
const TGWindow * GetMain() const
Definition TGFrame.h:516
const TGWindow * fMain
Definition TGFrame.h:503
virtual void CenterOnParent(Bool_t croot=kTRUE, EPlacement pos=kCenter)
Position transient frame centered relative to the parent frame.
Definition TGFrame.cxx:1949
A composite frame that layout their children in vertical way.
Definition TGFrame.h:376
Int_t fWidgetId
the widget id (used for event processing)
Definition TGWidget.h:46
virtual void Associate(const TGWindow *w)
Definition TGWidget.h:72
Bool_t HasFocus() const
Definition TGWidget.h:70
Int_t fWidgetFlags
widget status flags (OR of EWidgetStatus)
Definition TGWidget.h:47
const TGWindow * fMsgWindow
window which handles widget events
Definition TGWidget.h:48
Bool_t IsEnabled() const
Definition TGWidget.h:69
Bool_t WantFocus() const
Definition TGWidget.h:71
ROOT GUI Window base class.
Definition TGWindow.h:23
@ kEditDisable
disable edit of this window
Definition TGWindow.h:57
UInt_t fEditDisabled
flags used for "guibuilding"
Definition TGWindow.h:32
const char * GetName() const override
Returns name of object.
Definition TNamed.h:49
Mother of all ROOT objects.
Definition TObject.h:41
R__ALWAYS_INLINE Bool_t IsZombie() const
Definition TObject.h:159
void MakeZombie()
Definition TObject.h:53
SCoord_t fY
Definition TPoint.h:36
SCoord_t fX
Definition TPoint.h:35
void Emit(const char *signal, const T &arg)
Activate signal with single parameter.
Definition TQObject.h:164
Bool_t Connect(const char *signal, const char *receiver_class, void *receiver, const char *slot)
Non-static method is used to connect from the signal of this object to the receiver slot.
Definition TQObject.cxx:865
Bool_t Disconnect(const char *signal=nullptr, void *receiver=nullptr, const char *slot=nullptr)
Disconnects signal of this object from slot of receiver.
This class creates a TGCanvas in which a TCanvas is created.
TCanvas * GetCanvas() const
TLine * line
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
const Int_t n
Definition legend1.C:16
Short_t Max(Short_t a, Short_t b)
Returns the largest of a and b.
Definition TMathBase.h:251
Short_t Min(Short_t a, Short_t b)
Returns the smallest of a and b.
Definition TMathBase.h:199
ULong_t fPixel
color pixel value (index in color table)
Definition GuiTypes.h:311
UShort_t fRed
red component (0..65535)
Definition GuiTypes.h:312
UShort_t fGreen
green component (0..65535)
Definition GuiTypes.h:313
UShort_t fBlue
blue component (0..65535)
Definition GuiTypes.h:314
Event structure.
Definition GuiTypes.h:174
EGEventType fType
of event (see EGEventType)
Definition GuiTypes.h:175
Int_t fY
pointer x, y coordinates in event window
Definition GuiTypes.h:178
Int_t fX
Definition GuiTypes.h:178
UInt_t fCode
key or button code
Definition GuiTypes.h:180
Point structure (maps to the X11 XPoint structure)
Definition GuiTypes.h:356
Rectangle structure (maps to the X11 XRectangle structure)
Definition GuiTypes.h:361
Short_t fX
Definition GuiTypes.h:362
UShort_t fHeight
Definition GuiTypes.h:363
Short_t fY
Definition GuiTypes.h:362
UShort_t fWidth
Definition GuiTypes.h:363
TMarker m
Definition textangle.C:8
TLine l
Definition textangle.C:4