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
84
85
86// TODO:
87// - implement "custom" colors.
88// - optimize the code, specially the one handling the fColormap image
89// and dithering in pseudo-color modes; remove duplicated code.
90// - improve the color allocation routine.
91// - use a buffering pixmap for the fColormap image.
92
94 kCDLG_OK = 100,
98
102
111
117
120 kIMG_L
122
123// "User" defined colors
124
125static ULong_t gUcolor[24] = { 0xff000000 };
126
127
128////////////////////////////////////////////////////////////////////////////////
129/// TGColorPalette widget: this is just a grid of color cells of the
130/// specified size. Colors can be selected by clicking on them or by
131/// using the arrow keys.
132
134 TGFrame(p, 10, 10, kChildFrame)
135{
136 fWidgetId = id;
138 fMsgWindow = p;
140
141 fCw = 20;
142 fCh = 17;
143
144 fRows = rows;
145 fCols = cols;
146
147 fCx = fCy = 0;
148
149 fPixels = new ULong_t[fRows * fCols];
150
151 for (Int_t i = 0; i < fRows * fCols; ++i) {
152 fPixels[i] = TColor::RGB2Pixel(255, 255, 255);
153 }
154
155 gVirtualX->GrabButton(fId, kAnyButton, kAnyModifier,
158
162}
163
164////////////////////////////////////////////////////////////////////////////////
165/// Destructor.
166
168{
169 delete [] fPixels;
170}
171
172////////////////////////////////////////////////////////////////////////////////
173/// Handle button events in color palette
174
176{
177 if (event->fCode != kButton1)
178 return kFALSE;
179
180 if ((event->fType == kButtonPress) && HasFocus())
181 WantFocus();
182
183 Int_t cx = event->fX / (fCw + 5);
184 Int_t cy = event->fY / (fCh + 5);
185
186 if (cx >= 0 && cx < fCols && cy >= 0 && cy < fRows) {
187
189
190 fCx = cx;
191 fCy = cy;
192
194
197 }
198
199 return kTRUE;
200}
201
202////////////////////////////////////////////////////////////////////////////////
203/// Handle mouse motion events in color palette.
204
206{
207 if (!IsEnabled())
208 return kTRUE;
209
210 Int_t cx = event->fX / (fCw + 5);
211 Int_t cy = event->fY / (fCh + 5);
212
213 if (cx >= 0 && cx < fCols && cy >= 0 && cy < fRows) {
214
216
217 fCx = cx;
218 fCy = cy;
219
221
224 }
225
226 return kTRUE;
227}
228
229////////////////////////////////////////////////////////////////////////////////
230/// Handle keyboard events in color palette.
231
233{
234 Char_t input[10];
235 UInt_t keysym;
236
237 if (event->fType == kGKeyPress) {
238
239 gVirtualX->LookupString(event, input, sizeof(input), keysym);
240
241 Int_t cx = fCx;
242 Int_t cy = fCy;
243
244 switch ((EKeySym)keysym) {
245 case kKey_Left:
246 if (cx > 0) --cx;
247 break;
248
249 case kKey_Right:
250 if (cx < fCols - 1) ++cx;
251 break;
252
253 case kKey_Up:
254 if (cy > 0) --cy;
255 break;
256
257 case kKey_Down:
258 if (cy < fRows - 1) ++cy;
259 break;
260
261 case kKey_Home:
262 cx = cy = 0;
263 break;
264
265 case kKey_End:
266 cx = fCols - 1;
267 cy = fRows - 1;
268 break;
269
270 default:
271 break;
272 }
273
274 if (cx != fCx || cy != fCy) {
275
277
278 fCx = cx;
279 fCy = cy;
280
282
285 }
286 }
287
288 return kTRUE;
289}
290
291////////////////////////////////////////////////////////////////////////////////
292/// Set color entries in color samples.
293
295{
296 for (Int_t i = 0; i < fRows * fCols; ++i)
297 SetColor(i, colors[i]);
298 gClient->NeedRedraw(this);
299}
300
301////////////////////////////////////////////////////////////////////////////////
302/// Set color at index ix of color entries.
303
305{
306 fPixels[ix] = color;
307 gClient->NeedRedraw(this);
308}
309
310////////////////////////////////////////////////////////////////////////////////
311/// Set current cell color.
312
314{
315 SetColor(fCy * fCols + fCx, color);
316}
317
318////////////////////////////////////////////////////////////////////////////////
319/// Set color cell size.
320
322{
323 fCw = w;
324 fCh = h;
325 gClient->NeedRedraw(this);
326}
327
328////////////////////////////////////////////////////////////////////////////////
329/// Return currently selected color value.
330
332{
333 if (fCx >= 0 && fCy >= 0)
334 return GetColorByIndex(fCy * fCols + fCx);
335 else
336 return TColor::RGB2Pixel(0, 0, 0);
337}
338
339////////////////////////////////////////////////////////////////////////////////
340/// Redraw color palette.
341
343{
344 Int_t i, j, k, x, y;
345
346 k = 0;
347 y = 2;
348 for (i = 0; i < fRows; ++i) {
349 x = 2;
350 for (j = 0; j < fCols; ++j) {
353 gVirtualX->FillRectangle(fId, fDrawGC(), x + 2, y + 2, fCw - 4, fCh - 4);
354 x += fCw + 5;
355 }
356 y += fCh + 5;
357 }
358
360}
361
362////////////////////////////////////////////////////////////////////////////////
363/// Add keyboard input.
364
366{
368}
369
370////////////////////////////////////////////////////////////////////////////////
371/// Remove keyboard input.
372
374{
376 gClient->NeedRedraw(this);
377}
378
379////////////////////////////////////////////////////////////////////////////////
380/// Draw a highlight rectangle around cell obtaining focus.
381
383{
384 if (fCx >= 0 && fCy >= 0) {
385 GContext_t gc = onoff ? GetShadowGC()() : GetBckgndGC()();
386 gVirtualX->DrawRectangle(fId, gc, fCx * (fCw + 5) + 0, fCy * (fCh + 5) + 0,
387 fCw + 3, fCh + 3);
388 }
389}
390
391
392////////////////////////////////////////////////////////////////////////////////
393/// TGColorPick constructor.
394/// TGColorPick is a widget which allows a color to be picked from HLS space.
395/// It consists of two elements: a color map window from where the user can
396/// select the hue and saturation level of a color, and a slider to select
397/// color's lightness.
398
400 TGFrame(p, w, h, kChildFrame), fCursorGC(GetBlackGC())
401{
402 UInt_t iw, ih;
403
404 fWidgetId = id;
406 fMsgWindow = p;
407
408 fColormapRect.fX = 1;
409 fColormapRect.fY = 1;
410 fColormapRect.fWidth = w - 33 - 2;
411 fColormapRect.fHeight = h - 2;
412 fSliderRect.fX = w - 18 - 2;
413 fSliderRect.fY = 1;
414 fSliderRect.fWidth = 10;
415 fSliderRect.fHeight = h - 2;
416
417 fNColors = 0;
418
419 if (!p) {
420 MakeZombie();
421 // coverity[uninit_member]
422 return;
423 }
424 CreateImages();
425 gVirtualX->GetImageSize(fLimage, iw, ih);
426
427 fCx = 0;
428 fCy = 0;
429 fCz = (Int_t)ih / 2;
430
432
434 InitImages();
435
436 gVirtualX->GrabButton(fId, kAnyButton, kAnyModifier,
439
443}
444
445////////////////////////////////////////////////////////////////////////////////
446/// TGColorPick destructor.
447
449{
450 if (IsZombie()) return;
451 gVirtualX->DeleteImage(fHSimage);
452 gVirtualX->DeleteImage(fLimage);
453 FreeColors();
454}
455
456////////////////////////////////////////////////////////////////////////////////
457/// Handle mouse button events in color pick widget.
458
460{
461 if (event->fCode != kButton1) return kFALSE;
462
463 if (event->fType == kButtonPress) {
464 if ((event->fX > fColormapRect.fX) && (event->fX < fColormapRect.fX + fColormapRect.fWidth) &&
465 (event->fY > fColormapRect.fY) && (event->fY < fColormapRect.fY + fColormapRect.fHeight)) {
466
468 SetHScursor(event->fX - fColormapRect.fX, event->fY - fColormapRect.fY);
469
470 } else if (event->fX > fSliderRect.fX) {
471
473 SetLcursor(event->fY - fSliderRect.fY);
474
475 }
476 } else { // ButtonRelease
477
479
480 }
481
484
487
488 return kTRUE;
489}
490
491////////////////////////////////////////////////////////////////////////////////
492/// Handle mouse motion events in color pick widget.
493
495{
496 if (!IsEnabled())
497 return kTRUE;
498
499 if (fClick == kCLICK_HS) {
500
501 SetHScursor(event->fX - fColormapRect.fX, event->fY - fColormapRect.fY);
502
503 } else if (fClick == kCLICK_L) {
504
505 SetLcursor(event->fY - fSliderRect.fY);
506
507 } else {
508
509 return kTRUE;
510
511 }
512
515
518
519 return kTRUE;
520}
521
522////////////////////////////////////////////////////////////////////////////////
523/// Create colormap and color slider images.
524
526{
528
531 fHSimage = gVirtualX->CreateImage(width, height);
534 fLimage = gVirtualX->CreateImage(width, height);
535}
536
537////////////////////////////////////////////////////////////////////////////////
538/// Try to allocate first a palette of 64 colors. Used by the dithered
539/// version of the color maps.
540
542{
543 ColorStruct_t color;
544 Int_t i;
545
546 for (i = 0; i < 64; ++i) {
547 Int_t cc[4] = { 0, 21845, 43691, 65535 };
548 color.fPixel = 0;
549 color.fRed = cc[i & 0x3];
550 color.fGreen = cc[(i >> 2) & 0x3];
551 color.fBlue = cc[(i >> 4) & 0x3];
552 if (gVirtualX->AllocColor(gVirtualX->GetColormap(), color) == 0)
553 break;
554 fColormap[i][0] = color.fRed / 256;
555 fColormap[i][1] = color.fGreen / 256;
556 fColormap[i][2] = color.fBlue / 256;
557 fPixel[i] = color.fPixel;
558 }
559
560 fNColors = i;
561 if (fNColors == 64) return; // success
562
563 // Failed, try a simpler 27-color.
564
565 FreeColors();
566
567 for (i = 0; i < 27; ++i) {
568 Int_t cc[3] = { 0, 32768, 65535 };
569 color.fPixel = 0;
570 color.fRed = cc[i % 3];
571 color.fGreen = cc[(i / 3) % 3];
572 color.fBlue = cc[(i / 9) % 3];
573 if (gVirtualX->AllocColor(gVirtualX->GetColormap(), color) == 0)
574 break;
575 fColormap[i][0] = color.fRed / 256;
576 fColormap[i][1] = color.fGreen / 256;
577 fColormap[i][2] = color.fBlue / 256;
578 fPixel[i] = color.fPixel;
579 }
580
581 fNColors = i;
582 if (fNColors == 27) return; // success
583
584 // Failed, try then a much simpler 8-color.
585
586 FreeColors();
587
588 for (i = 0; i < 8; ++i) {
589 color.fPixel = 0;
590 color.fRed = (i & 1) * 65535;
591 color.fGreen = ((i >> 1) & 1) * 65535;
592 color.fBlue = ((i >> 2) & 1) * 65535;
593 if (gVirtualX->AllocColor(gVirtualX->GetColormap(), color) == 0)
594 break;
595 fColormap[i][0] = color.fRed / 256;
596 fColormap[i][1] = color.fGreen / 256;
597 fColormap[i][2] = color.fBlue / 256;
598 fPixel[i] = color.fPixel;
599 }
600
601 fNColors = i;
602 if (fNColors == 8) return; // success
603
604 // Failed, try to get at least 8 closest colors...
605 // (TODO: search for closest colors in the colormap, right now we just
606 // get as many as exact colors we can for the 8-color palette)
607
608 FreeColors();
609
610 for (i = 0; i < 8; ++i) {
611 color.fPixel = 0;
612 color.fRed = (i & 1) * 65535;
613 color.fGreen = ((i >> 1) & 1) * 65535;
614 color.fBlue = ((i >> 2) & 1) * 65535;
615 if (gVirtualX->AllocColor(gVirtualX->GetColormap(), color) != 0) {
616 fColormap[fNColors][0] = color.fRed / 256;
617 fColormap[fNColors][1] = color.fGreen / 256;
618 fColormap[fNColors][2] = color.fBlue / 256;
619 fPixel[fNColors++] = color.fPixel;
620 }
621 }
622
623 // continue with what we got...
624}
625
626////////////////////////////////////////////////////////////////////////////////
627/// Free allocated colors.
628
630{
631 for (Int_t i = 0; i < fNColors; i++)
632 gVirtualX->FreeColor(gVirtualX->GetColormap(), fPixel[i]);
633 fNColors = 0;
634}
635
636////////////////////////////////////////////////////////////////////////////////
637/// Create a dithered version of the color map and lightness images for
638/// display modes with reduced number of colors. The Floyd-Steinberg error
639/// diffusion dithering algorithm is used.
640/// This routine is called in PseudoColor modes only.
641
643{
644 const Int_t kWidth = 20;
645
646 ColorStruct_t line[kWidth];
647 struct { Int_t r, g, b; } ed[kWidth], ef;
648 Int_t x, y, c, v, e[4], nc = 0;
649 Int_t r, g, b;
650 Int_t h, l, s;
651 Long_t dist, sdist;
652 Int_t iw, ih;
653
654 gVirtualX->GetImageSize(image, (UInt_t&) iw, (UInt_t&) ih);
655
656 for (x = 0; x < iw; ++x) {
657 ed[x].r = ed[x].g = ed[x].b = 0;
658 }
659
660 if (fNColors == 0) AllocColors();
661
662 for (y = 0; y < ih; ++y) {
663
664 if (which == kIMG_HS) {
665
666 for (x = 0; x < iw; ++x) {
667
668 h = x * 255 / iw;
669 l = 128;
670 s = (ih - y) * 255 / ih;
671
672 TColor::HLS2RGB(h, l, s, r, g, b);
673
674 line[x].fRed = r;
675 line[x].fGreen = g;
676 line[x].fBlue = b;
677 }
678
679 } else if (which == kIMG_L) {
680
682 TColor::RGB2HLS(r, g, b, h, l, s);
683
684 Int_t ll = (ih - y) * 255 / ih;
685
686 TColor::HLS2RGB(h, ll, s, r, g, b);
687
688 for (x = 0; x < iw; ++x) {
689 line[x].fRed = r;
690 line[x].fGreen = g;
691 line[x].fBlue = b;
692 }
693
694 } else {
695
696 return;
697
698 }
699
700 ef.r = ef.g = ef.b = 0; // no forward error for first pixel
701
702 for (x = 0; x < iw; ++x) {
703
704 // add errors from previous line
705
706 v = line[x].fRed + ed[x].r;
707 if (v < 0) v = 0; else if (v > 255) v = 255;
708 line[x].fRed = v;
709
710 v = line[x].fGreen + ed[x].g;
711 if (v < 0) v = 0; else if (v > 255) v = 255;
712 line[x].fGreen = v;
713
714 v = line[x].fBlue + ed[x].b;
715 if (v < 0) v = 0; else if (v > 255) v = 255;
716 line[x].fBlue = v;
717
718 }
719
720 for (x = 0; x < iw; ++x) {
721
722 // add forward errors
723
724 v = line[x].fRed + ef.r;
725 if (v < 0) v = 0; else if (v > 255) v = 255;
726 line[x].fRed = v;
727
728 v = line[x].fGreen + ef.g;
729 if (v < 0) v = 0; else if (v > 255) v = 255;
730 line[x].fGreen = v;
731
732 v = line[x].fBlue + ef.b;
733 if (v < 0) v = 0; else if (v > 255) v = 255;
734 line[x].fBlue = v;
735
736 // find the nearest color in colormap[]
737
738 sdist = 255L * 255L * 255L;
739 for (c = 0; c < fNColors; ++c) {
740
741 Int_t dr = line[x].fRed - fColormap[c][0];
742 Int_t dg = line[x].fGreen - fColormap[c][1];
743 Int_t db = line[x].fBlue - fColormap[c][2];
744
745 dist = dr * dr + dg * dg + db * db;
746 if (dist < sdist) {
747 nc = c;
748 sdist = dist;
749 }
750 }
751
752 gVirtualX->PutPixel(image, x, y, fPixel[nc]);
753
754#define FILTER(v) \
755 e[0] = (7 * v) >> 4; \
756 e[1] = v >> 4; \
757 e[2] = (5 * v) >> 4; \
758 e[3] = (3 * v) >> 4;
759
760 v = line[x].fRed - fColormap[nc][0];
761 FILTER(v)
762
763 ef.r = e[0];
764 if (x < iw-1) ed[x+1].r = e[1];
765 if (x == 0) ed[x].r = e[2]; else ed[x].r += e[2];
766 if (x > 0) ed[x-1].r += e[3];
767
768 v = line[x].fGreen - fColormap[nc][1];
769 FILTER(v)
770
771 ef.g = e[0];
772 if (x < iw-1) ed[x+1].g = e[1];
773 if (x == 0) ed[x].g = e[2]; else ed[x].g += e[2];
774 if (x > 0) ed[x-1].g += e[3];
775
776 v = line[x].fBlue - fColormap[nc][2];
777 FILTER(v)
778
779 ef.b = e[0];
780 if (x < iw-1) ed[x+1].b = e[1];
781 if (x == 0) ed[x].b = e[2]; else ed[x].b += e[2];
782 if (x > 0) ed[x-1].b += e[3];
783
784 }
785 }
786}
787
788////////////////////////////////////////////////////////////////////////////////
789/// Initialize color palette and slider images.
790
792{
794 Int_t h, l, s;
795 Int_t r, g, b;
796
797 gVirtualX->GetImageSize(fHSimage, (UInt_t&) width, (UInt_t&) height);
798
799 // initialize fHSimage
800
801 Int_t ncolors = gVirtualX->GetDepth();
802
803 if (ncolors > 8) {
804 for (Int_t y = 0; y < height; ++y) {
805 for (Int_t x = 0; x < width; ++x) {
806
807 r = g = b = 0;
808 h = x * 255 / width;
809 l = 128;
810 s = (height - y) * 255 / height;
811
812 TColor::HLS2RGB(h, l, s, r, g, b);
813
815 gVirtualX->PutPixel(fHSimage, x, y, pixel);
816 }
817 }
818 } else {
820 }
821
822 // initialize fLimage
823
825}
826
827////////////////////////////////////////////////////////////////////////////////
828/// Set slider colors.
829
831{
833 Int_t h, l, s;
834 Int_t r, g, b;
835
836 gVirtualX->GetImageSize(fLimage, (UInt_t&) width, (UInt_t&) height);
837
838 Int_t ncolors = gVirtualX->GetDepth();
839
840 if (ncolors > 8) {
841
842 for (Int_t y = 0; y < height; ++y) {
843
845 TColor::RGB2HLS(r, g, b, h, l, s);
846
847 l = (height - y) * 255 / height;
848
849 TColor::HLS2RGB(h, l, s, r, g, b);
850
852
853 for (Int_t x = 0; x < width; ++x) {
854 gVirtualX->PutPixel(fLimage, x, y, pixel);
855 }
856 }
857 } else {
859 }
860
861 gClient->NeedRedraw(this);
862}
863
864////////////////////////////////////////////////////////////////////////////////
865/// Position the slider cursor on right color position.
866
868{
870 Int_t h, l, s;
871 Int_t r, g, b;
872
873 gVirtualX->GetImageSize(fHSimage, width, height);
874
875 fCurrentColor = color;
876
878 TColor::RGB2HLS(r, g, b, h, l, s);
879
880 SetHScursor(h * (Int_t)width / 256, (255 - s) * (Int_t)height / 256);
881
882 gVirtualX->GetImageSize(fLimage, width, height);
883
884 SetLcursor((255 - l) * (Int_t)height / 256);
885
887}
888
889////////////////////////////////////////////////////////////////////////////////
890/// Assign the current cursor position as currently selected color.
891
893{
894 UInt_t lwidth, lheight;
895 UInt_t swidth, sheight;
896 Int_t r, g, b;
897 Int_t h, l, s;
898
899 gVirtualX->GetImageSize(fLimage, lwidth, lheight);
900 gVirtualX->GetImageSize(fHSimage, swidth, sheight);
901
902 h = Int_t(fCx * 255 / swidth);
903 l = Int_t((lheight - fCz) * 255 / lheight);
904 s = Int_t((sheight - fCy) * 255 / sheight);
905
906 TColor::HLS2RGB(h, l, s, r, g, b);
908}
909
910////////////////////////////////////////////////////////////////////////////////
911/// Redraw the color pick widget.
912
914{
915 UInt_t lwidth, lheight;
916 UInt_t swidth, sheight;
917
918 gVirtualX->GetImageSize(fLimage, lwidth, lheight);
919 gVirtualX->GetImageSize(fHSimage, swidth, sheight);
920
921 DrawBorder();
922
925 gVirtualX->PutImage(fId, GetBckgndGC()(), fHSimage,
926 fColormapRect.fX, fColormapRect.fY, 0, 0, swidth, sheight);
927
930 gVirtualX->PutImage(fId, GetBckgndGC()(), fLimage,
931 fSliderRect.fX, fSliderRect.fY, 0, 0, lwidth, lheight);
932
935}
936
937////////////////////////////////////////////////////////////////////////////////
938/// Set hue / saturation cursor position.
939
941{
943
944 gVirtualX->GetImageSize(fHSimage, width, height);
945
947
948 fCx = x;
949 fCy = y;
950
951 if (fCx < 0)
952 fCx = 0;
953 else if (fCx >= (Int_t)width)
954 fCx = (Int_t)width - 1;
955
956 if (fCy < 0)
957 fCy = 0;
958 else if (fCy >= (Int_t)height)
959 fCy = (Int_t)height - 1;
960
962}
963
964////////////////////////////////////////////////////////////////////////////////
965/// Set lightness slider cursor position.
966
968{
970
971 gVirtualX->GetImageSize(fLimage, width, height);
972
974
975 fCz = z - fSliderRect.fY;
976
977 if (fCz < 0)
978 fCz = 0;
979 else if (fCz >= (Int_t)height)
980 fCz = (Int_t)height - 1;
981
983}
984
985////////////////////////////////////////////////////////////////////////////////
986/// Draw hue / saturation cursor
987
989{
991
992 gVirtualX->GetImageSize(fHSimage, width, height);
993
994 if (onoff) {
995 Int_t x, y;
997
998 x = fCx + fColormapRect.fX;
999 y = fCy + fColormapRect.fY;
1000
1003 rect.fWidth = fColormapRect.fWidth;
1004 rect.fHeight = fColormapRect.fHeight;
1005 gVirtualX->SetClipRectangles(fCursorGC(), 0, 0, &rect, 1);
1006
1007 gVirtualX->FillRectangle(fId, fCursorGC(), x - 9, y - 1, 5, 3);
1008 gVirtualX->FillRectangle(fId, fCursorGC(), x - 1, y - 9, 3, 5);
1009 gVirtualX->FillRectangle(fId, fCursorGC(), x + 5, y - 1, 5, 3);
1010 gVirtualX->FillRectangle(fId, fCursorGC(), x - 1, y + 5, 3, 5);
1011
1012 } else {
1013 Int_t x, y;
1014 UInt_t w, h;
1015
1016 x = fCx - 9; w = 19;
1017 y = fCy - 9; h = 19;
1018
1019 if (x < 0) { w += x; x = 0; }
1020 if (y < 0) { h += y; y = 0; }
1021
1022 if (x + w > width) w = width - x;
1023 if (y + h > height) h = height - y;
1024
1025 gVirtualX->PutImage(fId, GetBckgndGC()(), fHSimage, x, y,
1027 }
1028}
1029
1030////////////////////////////////////////////////////////////////////////////////
1031/// Draw lightness slider cursor
1032
1034{
1036 Int_t r = l + 5;
1037 Int_t t = fCz - 5 + fSliderRect.fY;
1038 Int_t b = t + 10;
1039
1040 Point_t points[3];
1041
1042 Int_t m = (t + b) >> 1;
1043
1044 points[0].fX = r;
1045 points[0].fY = t;
1046 points[1].fX = r;
1047 points[1].fY = b;
1048 points[2].fX = l;
1049 points[2].fY = m;
1050
1051 GContext_t gc = onoff ? GetShadowGC()() : GetBckgndGC()();
1052
1053 gVirtualX->FillPolygon(fId, gc, points, 3);
1054}
1055
1056
1057////////////////////////////////////////////////////////////////////////////////
1058/// Color selection dialog constructor.
1059/// The TGColorDialog presents a full featured color selection dialog.
1060/// It uses 2 TGColorPalette's and the TGColorPick widgets.
1061
1063 Int_t *retc, Pixel_t *color, Bool_t wait) :
1064 TGTransientFrame(p, m, 200, 150)
1065{
1066 const Int_t kC_X = 175; // Win95: 177
1067 const Int_t kC_Y = 180; // Win95: 189
1068
1069 Int_t i;
1070
1071 fRetc = retc;
1072 fRetColor = 0;
1073 fRetTColor = 0;
1074 fInitColor = 0;
1075 if (color) {
1076 fRetColor = color;
1079 }
1080 fWaitFor = wait;
1081
1082 if (fRetc) *fRetc = kMBCancel;
1083
1084 TGHorizontalFrame *hftop = new TGHorizontalFrame(this, 10, 10);
1085 hftop->SetCleanup();
1086 AddFrame(hftop, new TGLayoutHints(kLHintsTop | kLHintsLeft, 5, 5, 10, 5));
1087
1088 fTab = new TGTab(hftop, 300, 300);
1089 hftop->AddFrame(fTab);
1090
1091 TGCompositeFrame *cf = new TGCompositeFrame(hftop, 10, 10);
1092 cf->SetCleanup();
1093 hftop->AddFrame(cf, new TGLayoutHints(kLHintsLeft | kLHintsTop, 5, 0, 30, 0));
1094
1095 TGCompositeFrame *cf1 = new TGCompositeFrame(cf, 10, 10);
1096 cf1->SetCleanup();
1097 cf->AddFrame(cf1, new TGLayoutHints(kLHintsLeft | kLHintsTop, 5, 0, 30, 0));
1098 cf1->SetLayoutManager(new TGMatrixLayout(cf1, 0, 2, 4));
1099
1100 cf1->AddFrame(new TGLabel(cf1, new TGHotString("Red:")));
1101 cf1->AddFrame(fRte = new TGTextEntry(cf1, fRtb = new TGTextBuffer(5), kCDLG_RTE),0);
1103 cf1->AddFrame(new TGLabel(cf1, new TGHotString("Green:")),0);
1104 cf1->AddFrame(fGte = new TGTextEntry(cf1, fGtb = new TGTextBuffer(5), kCDLG_GTE),0);
1106 cf1->AddFrame(new TGLabel(cf1, new TGHotString("Blue:")));
1107 cf1->AddFrame(fBte = new TGTextEntry(cf1, fBtb = new TGTextBuffer(5), kCDLG_BTE),0);
1109 cf1->AddFrame(new TGLabel(cf1, new TGHotString("Opacity:")),0);
1110 cf1->AddFrame(fAle = new TGTextEntry(cf1, fAlb = new TGTextBuffer(5), kCDLG_ALE),0);
1112
1113 if (!TCanvas::SupportAlpha()) {
1115 }
1116
1117 TGCompositeFrame *cf2 = new TGCompositeFrame(cf, 10, 10);
1118 cf2->SetCleanup();
1119 cf->AddFrame(cf2, new TGLayoutHints(kLHintsLeft | kLHintsTop, 5, 0, 30, 0));
1120 cf2->SetLayoutManager(new TGMatrixLayout(cf2, 0, 2, 4));
1121 cf2->AddFrame(new TGLabel(cf2, new TGHotString("Hue:")),0);
1122 cf2->AddFrame(fHte = new TGTextEntry(cf2, fHtb = new TGTextBuffer(5), kCDLG_HTE),0);
1124 cf2->AddFrame(new TGLabel(cf2, new TGHotString("Sat:")),0);
1125 cf2->AddFrame(fSte = new TGTextEntry(cf2, fStb = new TGTextBuffer(5), kCDLG_STE),0);
1127 cf2->AddFrame(new TGLabel(cf2, new TGHotString("Lum:")),0);
1128 cf2->AddFrame(fLte = new TGTextEntry(cf2, fLtb = new TGTextBuffer(5), kCDLG_LTE),0);
1130
1131 fHte->Associate(this);
1132 fLte->Associate(this);
1133 fSte->Associate(this);
1134 fRte->Associate(this);
1135 fGte->Associate(this);
1136 fBte->Associate(this);
1137 fAle->Associate(this);
1138
1139 if (color) {
1140 UpdateRGBentries(color);
1141 UpdateHLSentries(color);
1142 UpdateAlpha(color);
1143 fCurrentColor = *color;
1144 } else {
1145 gClient->GetColorByName("red", fCurrentColor);
1146 }
1147
1148 // color sample
1149 TGCompositeFrame *cf3 = new TGCompositeFrame(cf, 10, 10);
1150 cf3->SetCleanup();
1151 cf3->SetLayoutManager(new TGMatrixLayout(cf3, 0, 1, 0));
1152 cf3->AddFrame(fColorInfo = new TGLabel(cf3, new TGString("New: not set ")),0);
1154 cf3->AddFrame(fSample = new TGFrame(cf3, 50, 25, kOwnBackground),0);
1155 cf3->AddFrame(fSampleOld = new TGFrame(cf3, 50, 25, kOwnBackground),0);
1156 cf3->AddFrame(new TGLabel(cf3, new TGString("Current")),0);
1157 cf->AddFrame(cf3, new TGLayoutHints(kLHintsLeft | kLHintsTop, 5, 5, 20, 0));
1160
1161 TGCompositeFrame *tf = fTab->AddTab("Color Wheel");
1162 TGCompositeFrame *tf1 = new TGCompositeFrame(tf, 60, 20, kHorizontalFrame);
1163 tf->AddFrame(tf1);
1164 fEcanvas = new TRootEmbeddedCanvas("wheel", tf1, 360, 360);
1165 tf1->AddFrame(fEcanvas);
1166 TCanvas *wcan = fEcanvas->GetCanvas();
1167 wcan->SetBit(kNoContextMenu);
1168 fColorWheel = new TColorWheel();
1169 fColorWheel->SetCanvas(wcan);
1170 fColorWheel->Draw();
1171 wcan->Update();
1172 wcan->Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)","TGColorDialog",this,
1173 "SetColorInfo(Int_t,Int_t,Int_t,TObject*)");
1174
1175 tf = fTab->AddTab("Basic Colors");
1176 TGCompositeFrame *tf2 = new TGCompositeFrame(tf, 60, 20, kHorizontalFrame);
1177 tf->AddFrame(tf2);
1178
1179 TGVerticalFrame *vf1 = new TGVerticalFrame(tf2, 20, 20);
1180 vf1->SetCleanup();
1181 TGVerticalFrame *vf2 = new TGVerticalFrame(tf2, 20, 20);
1182 vf2->SetCleanup();
1183
1186
1187 //----------------------------------------- Left panel
1188
1189 // basic colors
1190
1191 fPalette = new TGColorPalette(vf1, 6, 8, kCDLG_SPALETTE);
1192 vf1->AddFrame(fPalette, new TGLayoutHints(kLHintsNormal, 5, 5, 15, 0));
1193 fPalette->Associate(this);
1194
1195 for (i = 0; i < 48; ++i)
1196 fPalette->SetColor(i, TColor::Number2Pixel(i+10)); // root colors
1197 // the basic colors were set via bcolor
1198 //fPalette->SetColor(i, TColor::GetPixel(bcolor[i][0], bcolor[i][1], bcolor[i][2]));
1199
1200 // add some default colors
1202
1203 Float_t r, g, b;
1204
1205 r = 232./255;
1206 g = 232./255;
1207 b = 222./255;
1208
1209 // Gui Builder background
1211 fPalette->SetColor(46, pixel);
1212
1213 r = 230./255;
1214 g = 230./255;
1215 b = 230./255;
1216
1217 // a la MAC background
1219 fPalette->SetColor(45, pixel);
1220
1221 r = 172./255;
1222 g = 174./255;
1223 b = 205./255;
1224
1225 // a la CDE background
1227 fPalette->SetColor(44, pixel);
1228
1229 r = 205./255;
1230 g = 195./255;
1231 b = 175./255;
1232
1233 // a la FOX background
1235 fPalette->SetColor(43, pixel);
1236
1237 // custom colors
1238
1239 vf1->AddFrame(new TGLabel(vf1, new TGHotString("&Custom Colors:")),
1240 new TGLayoutHints(kLHintsNormal, 5, 0, 15, 2));
1241
1242 fCpalette = new TGColorPalette(vf1, 6, 4, kCDLG_CPALETTE);
1243 vf1->AddFrame(fCpalette, new TGLayoutHints(kLHintsNormal, 5, 5, 5, 0));
1244 fCpalette->Associate(this);
1245
1246 if (gUcolor[0] == 0xff000000) {
1247 for (i = 0; i < 24; i++)
1248 gUcolor[i] = TColor::RGB2Pixel(255, 255, 255);
1249 }
1251
1252 // button frame - OK, Cancel
1253 TGHorizontalFrame *hf = new TGHorizontalFrame(this, 10, 10, kFixedWidth);
1254 hf->SetCleanup();
1255 AddFrame(hf, new TGLayoutHints(kLHintsBottom | kLHintsRight, 5, 5, 10, 5));
1256
1257 TGTextButton *ok = new TGTextButton(hf, new TGHotString("OK"), kCDLG_OK);
1258 TGTextButton *cancel = new TGTextButton(hf, new TGHotString("Cancel"), kCDLG_CANCEL);
1259 fPreview = new TGTextButton(hf, new TGHotString("&Preview"), kCDLG_PREVIEW);
1260 fPreview->Connect("Clicked()", "TGColorDialog", this, "DoPreview()");
1261
1262 hf->AddFrame(ok, new TGLayoutHints(kLHintsBottom | kLHintsExpandX, 0, 3, 0, 0));
1263 hf->AddFrame(cancel, new TGLayoutHints(kLHintsBottom | kLHintsExpandX,3, 0, 0, 0));
1265
1266 UInt_t w = ok->GetDefaultWidth();
1267 w = TMath::Max(w, cancel->GetDefaultWidth());
1268 hf->Resize(3 * (w + 30), hf->GetDefaultHeight());
1269
1270 ok->Associate(this);
1271 cancel->Associate(this);
1272
1273 //----------------------------------------- Right panel
1274
1275 // fColormap frame
1276
1277 fColors = new TGColorPick(vf2, kC_X + 23, kC_Y, kCDLG_COLORPICK);
1278 vf2->AddFrame(fColors, new TGLayoutHints(kLHintsLeft | kLHintsTop, 5, 0, 15, 5));
1279 fColors->Associate(this);
1280
1281 if (color)
1282 fColors->SetColor(*color);
1283
1284 TGTextButton *add = new TGTextButton(vf2, new TGHotString("&Add to Custom Colors"),
1285 kCDLG_ADD);
1287 5, 10, 0, 5));
1288 add->Associate(this);
1289
1290 MapSubwindows();
1293
1294 //---- make the message box non-resizable
1295
1298
1299 SetWindowName("Color Selector");
1300 SetIconName("Color Selector");
1301 SetClassHints("ROOT", "ColorSelector");
1302
1308
1309
1310 //---- position relative to the parent's window
1311
1312 if (fClient->IsEditable()) {
1313 const TGWindow *main = fMain;
1314 fMain = fClient->GetRoot();
1316 fMain = main;
1317 } else {
1319 }
1320
1321 if (fWaitFor) {
1322 MapWindow();
1323 fClient->WaitForUnmap(this);
1324 DeleteWindow();
1325 }
1326}
1327
1328////////////////////////////////////////////////////////////////////////////////
1329/// TGColorDialog destructor.
1330
1332{
1333 fEcanvas->GetCanvas()->Disconnect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)");
1334 delete fEcanvas;
1335 Cleanup();
1336}
1337
1338////////////////////////////////////////////////////////////////////////////////
1339/// Change current color.
1340
1342{
1343 if (fCurrentColor == col) {
1344 return;
1345 }
1346 fInitColor = *fRetColor = col;
1347 if((fRetTColor = gROOT->GetColor(TColor::GetColor(col)))) {};
1348 fCurrentColor = col;
1349 fColors->SetColor(col);
1351 ColorSelected(col);
1352}
1353
1354////////////////////////////////////////////////////////////////////////////////
1355/// Emit signal about selected color.
1356
1358{
1359 Emit("ColorSelected(Pixel_t)", color);
1360}
1361
1362////////////////////////////////////////////////////////////////////////////////
1363/// Emit signal about selected alpha and color.
1364
1366{
1367 Emit("AlphaColorSelected(ULong_t)", color);
1368}
1369
1370////////////////////////////////////////////////////////////////////////////////
1371/// Called when window is closed via window manager.
1372
1374{
1375 // save user set colors
1376 for (Int_t i = 0; i < 24; ++i)
1378
1379 if (*fRetc != kMBOk) {
1381 ULongptr_t ptr;
1382 if((ptr = (ULongptr_t)gROOT->GetColor(TColor::GetColor(fInitColor)))) AlphaColorSelected(ptr);
1383 } else {
1386 }
1387 // don't call DeleteWindow() here since that will cause access
1388 // to the deleted dialog in the WaitFor() method (see ctor)
1389
1390 //OpenGL + XQuartz on Mac: gl context and related resources
1391 //must be deleted _before_ UnmapWindow.
1392 if (gVirtualX->InheritsFrom("TGX11") && fEcanvas->GetCanvas()->UseGL())
1394
1395 UnmapWindow();
1396}
1397
1398////////////////////////////////////////////////////////////////////////////////
1399/// Update Opacity text entry with alpha value of color c.
1400
1402{
1403 Char_t tmp[20];
1404 Double_t alpha;
1405
1406 if (TColor *color = gROOT->GetColor(TColor::GetColor(*c))) {
1407 alpha = color->GetAlpha();
1408 snprintf(tmp, 20, "%.1f", alpha);
1409 fAlb->Clear();
1410 fAlb->AddText(0,tmp);
1411 gClient->NeedRedraw(fAle);
1412 }
1413}
1414
1415
1416////////////////////////////////////////////////////////////////////////////////
1417/// Update RGB text entries with RGB values of color c.
1418
1420{
1421 Char_t tmp[20];
1422
1423 Int_t r, g, b;
1424 TColor::Pixel2RGB(*c, r, g, b);
1425
1426 snprintf(tmp, 20, "%d", r);
1427 fRtb->Clear();
1428 fRtb->AddText(0, tmp);
1429 gClient->NeedRedraw(fRte);
1430
1431 snprintf(tmp, 20, "%d", g);
1432 fGtb->Clear();
1433 fGtb->AddText(0, tmp);
1434 gClient->NeedRedraw(fGte);
1435
1436 snprintf(tmp, 20, "%d", b);
1437 fBtb->Clear();
1438 fBtb->AddText(0, tmp);
1439 gClient->NeedRedraw(fBte);
1440}
1441
1442////////////////////////////////////////////////////////////////////////////////
1443/// Update HLS text entries with HLS values of color c.
1444
1446{
1447 Char_t tmp[20];
1448
1449 Int_t h, l, s;
1450 Int_t r, g, b;
1451
1452 TColor::Pixel2RGB(*c, r, g, b);
1453 TColor::RGB2HLS(r, g, b, h, l, s);
1454
1455 snprintf(tmp, 20, "%d", h);
1456 fHtb->Clear();
1457 fHtb->AddText(0, tmp);
1458 gClient->NeedRedraw(fHte);
1459
1460 snprintf(tmp, 20, "%d", l);
1461 fLtb->Clear();
1462 fLtb->AddText(0, tmp);
1463 gClient->NeedRedraw(fLte);
1464
1465 snprintf(tmp, 20, "%d", s);
1466 fStb->Clear();
1467 fStb->AddText(0, tmp);
1468 gClient->NeedRedraw(fSte);
1469}
1470
1471////////////////////////////////////////////////////////////////////////////////
1472/// Process messages for the color selection dialog.
1473
1475{
1476 ULong_t color;
1477 Int_t h, l, s;
1478 Int_t r, g, b;
1479
1480 switch (GET_MSG(msg)) {
1481 case kC_COMMAND:
1482 switch (GET_SUBMSG(msg)) {
1483 case kCM_BUTTON:
1484 switch(parm1) {
1485 case kCDLG_ADD:
1487 break;
1488
1489 case kCDLG_OK:
1490 *fRetc = kMBOk;
1492 atoi(fGtb->GetString()),
1493 atoi(fBtb->GetString()));
1496 atof(fAlb->GetString()))));
1497 }
1498 CloseWindow();
1499 break;
1500 case kCDLG_CANCEL:
1501 if (!fClient->IsEditable()) {
1503 if (p && p->InheritsFrom("TGColorPopup"))
1504 p->PreviewColor(fSampleOld->GetBackground());
1505 }
1506 CloseWindow();
1507 break;
1508 }
1509 break;
1510 }
1511 break;
1512 case kC_COLORSEL:
1513 switch (GET_SUBMSG(msg)) {
1514 case kCOL_CLICK:
1515 switch (parm1) {
1516 case kCDLG_SPALETTE:
1517 color = fPalette->GetCurrentColor();
1519 ColorSelected(color);
1520 gClient->NeedRedraw(fSample);
1521 fCurrentColor = color;
1522 fColors->SetColor(color);
1523 UpdateRGBentries(&color);
1524 UpdateHLSentries(&color);
1525 UpdateAlpha(&color);
1526 break;
1527
1528 case kCDLG_CPALETTE:
1529 color = fCpalette->GetCurrentColor();
1531 ColorSelected(color);
1532 gClient->NeedRedraw(fSample);
1533 fCurrentColor = color;
1534 fColors->SetColor(color);
1535 UpdateRGBentries(&color);
1536 UpdateHLSentries(&color);
1537 UpdateAlpha(&color);
1538 break;
1539
1540 case kCDLG_COLORPICK:
1541 color = fColors->GetCurrentColor();
1543 ColorSelected(color);
1544 gClient->NeedRedraw(fSample);
1545 fCurrentColor = color;
1546 UpdateRGBentries(&color);
1547 UpdateHLSentries(&color);
1548 UpdateAlpha(&color);
1549 break;
1550
1551 }
1552 break;
1553 }
1554 break;
1555
1556 case kC_TEXTENTRY:
1557 switch (GET_SUBMSG(msg)) {
1558 case kTE_TEXTCHANGED:
1559 switch (parm1) {
1560 case kCDLG_HTE:
1561 case kCDLG_LTE:
1562 case kCDLG_STE:
1563
1564 h = atoi(fHtb->GetString());
1565 l = atoi(fLtb->GetString());
1566 s = atoi(fStb->GetString());
1567 TColor::HLS2RGB(h, l, s, r, g, b);
1568
1569 color = TColor::RGB2Pixel(r, g, b);
1571 ColorSelected(color);
1572 gClient->NeedRedraw(fSample);
1573 fCurrentColor = color;
1574 fColors->SetColor(color);
1575 UpdateRGBentries(&color);
1576 break;
1577
1578 case kCDLG_RTE:
1579 case kCDLG_GTE:
1580 case kCDLG_BTE:
1581 color = TColor::RGB2Pixel(atoi(fRtb->GetString()),
1582 atoi(fGtb->GetString()),
1583 atoi(fBtb->GetString()));
1585 ColorSelected(color);
1586 gClient->NeedRedraw(fSample);
1587 fCurrentColor = color;
1588 fColors->SetColor(color);
1589 UpdateHLSentries(&color);
1590 break;
1591
1592 }
1593 break;
1594 }
1595 break;
1596 }
1597
1598 return kTRUE;
1599}
1600
1601////////////////////////////////////////////////////////////////////////////////
1602/// Set the color info in RGB and HLS parts
1603
1605{
1606 if (object == fColorWheel) {
1607 Int_t n = fColorWheel->GetColor(px,py);
1608 if (n < 0) return;
1609 TColor *color = gROOT->GetColor(n);
1610 if (!color) return;
1611 ULong_t pcolor = color->GetPixel();
1612 if (event == kButton1Down) {
1613 UpdateRGBentries(&pcolor);
1614 UpdateHLSentries(&pcolor);
1615 UpdateAlpha(&pcolor);
1616 fSample->SetBackgroundColor(pcolor);
1617 fColorInfo->SetText(Form("New: %s",color->GetName()));
1618 gClient->NeedRedraw(fSample);
1619 gClient->NeedRedraw(fColorInfo);
1620 fCurrentColor = pcolor;
1621 fColors->SetColor(pcolor);
1622 ColorSelected(pcolor);
1623 }
1624 }
1625}
1626
1627////////////////////////////////////////////////////////////////////////////////
1628/// Slot method called when Preview button is clicked.
1629
1631{
1632 TColor *tcolor;
1633 if ((tcolor = gROOT->GetColor(TColor::GetColor(fSample->GetBackground())))) {
1634 tcolor->SetAlpha(TMath::Max((Double_t)0, TMath::Min((Double_t)1, atof(fAlb->GetString()))));
1635 }
1636
1637 if (fClient->IsEditable()) {
1640 return;
1641 }
1643 if (p && p->InheritsFrom("TGColorPopup")) {
1644 if (tcolor) p->PreviewAlphaColor((ULongptr_t)tcolor);
1645 else p->PreviewColor(fSample->GetBackground());
1646 }
1647}
@ 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
Definition RtypesCore.h:45
long Longptr_t
Definition RtypesCore.h:82
char Char_t
Definition RtypesCore.h:37
unsigned long ULong_t
Definition RtypesCore.h:55
long Long_t
Definition RtypesCore.h:54
unsigned long ULongptr_t
Definition RtypesCore.h:83
float Float_t
Definition RtypesCore.h:57
constexpr Bool_t kFALSE
Definition RtypesCore.h:101
constexpr Bool_t kTRUE
Definition RtypesCore.h:100
#define ClassImp(name)
Definition Rtypes.h:377
#define gClient
Definition TGClient.h:156
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:373
#define gROOT
Definition TROOT.h:406
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
Definition TString.cxx:2489
#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:1540
The Canvas class.
Definition TCanvas.h:23
void DeleteCanvasPainter()
assert on IsBatch() == false?
Definition TCanvas.cxx:2613
static Bool_t SupportAlpha()
Static function returning "true" if transparency is supported.
Definition TCanvas.cxx:2463
void Update() override
Update canvas pad buffers.
Definition TCanvas.cxx:2476
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:21
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:1527
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:2358
static ULong_t Number2Pixel(Int_t ci)
Static method that given a color index number, returns the corresponding pixel value.
Definition TColor.cxx:2320
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:1839
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:2396
ULong_t GetPixel() const
Return pixel value corresponding to this color.
Definition TColor.cxx:1510
virtual void SetAlpha(Float_t a)
Definition TColor.h:70
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:1667
Bool_t IsEditable() const
Definition TGClient.h:89
const TGWindow * GetRoot() const
Returns current root (i.e.
Definition TGClient.cxx:224
void WaitForUnmap(TGWindow *w)
Wait for window to be unmapped.
Definition TGClient.cxx:737
const TGResourcePool * GetResourcePool() const
Definition TGClient.h:124
A full featured color selection dialog.
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:287
TGDimension GetDefaultSize() const override
std::cout << fWidth << "x" << fHeight << std::endl;
Definition TGFrame.h:316
virtual void SetLayoutManager(TGLayoutManager *l)
Set the layout manager for the composite frame.
Definition TGFrame.cxx:1000
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=nullptr)
Add frame to the composite frame using the specified layout hints.
Definition TGFrame.cxx:1117
virtual void Cleanup()
Cleanup and delete all objects contained in this composite frame.
Definition TGFrame.cxx:967
void MapSubwindows() override
Map all sub windows that are part of the composite frame.
Definition TGFrame.cxx:1164
UInt_t GetDefaultHeight() const override
Definition TGFrame.h:314
void SetCleanup(Int_t mode=kLocalCleanup) override
Turn on automatic cleanup of child frames in dtor.
Definition TGFrame.cxx:1072
void SetEditDisabled(UInt_t on=1) override
Set edit disable flag for this frame and subframes.
Definition TGFrame.cxx:1022
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:339
void Resize(UInt_t w=0, UInt_t h=0) override
Resize the frame.
Definition TGFrame.cxx:605
void RemoveInput(UInt_t emask)
Remove events specified in emask from the events the frame should handle.
Definition TGFrame.cxx:348
UInt_t fHeight
frame height
Definition TGFrame.h:88
virtual UInt_t GetDefaultWidth() const
Definition TGFrame.h:190
virtual UInt_t GetDefaultHeight() const
Definition TGFrame.h:191
virtual void DrawBorder()
Draw frame border.
Definition TGFrame.cxx:421
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:357
void SetBackgroundColor(Pixel_t back) override
Set background color (override from TGWindow base class).
Definition TGFrame.cxx:312
void MapWindow() override
map window
Definition TGFrame.h:204
static Pixel_t GetDefaultFrameBackground()
Get default frame background.
Definition TGFrame.cxx:683
virtual void DeleteWindow()
Delete window.
Definition TGFrame.cxx:276
virtual void SendMessage(const TGWindow *w, Longptr_t msg, Longptr_t parm1, Longptr_t parm2)
Send message (i.e.
Definition TGFrame.cxx:645
static const TGGC & GetShadowGC()
Get shadow color graphics context.
Definition TGFrame.cxx:765
UInt_t fWidth
frame width
Definition TGFrame.h:87
virtual Pixel_t GetBackground() const
Definition TGFrame.h:192
static const TGGC & GetBckgndGC()
Get background color graphics context.
Definition TGFrame.cxx:775
void SetForeground(Pixel_t v)
Set foreground color.
Definition TGGC.cxx:278
A composite frame that layout their children in horizontal way.
Definition TGFrame.h:385
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:396
virtual void SetText(TGString *newText)
Set new text in label.
Definition TGLabel.cxx:180
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:1858
void SetIconName(const char *name)
Set window icon name. This is typically done via the window manager.
Definition TGFrame.cxx:1801
void SetWMSize(UInt_t w, UInt_t h)
Give the window manager a window size hint.
Definition TGFrame.cxx:1893
void SetWindowName(const char *name=nullptr) override
Set window name. This is typically done via the window manager.
Definition TGFrame.cxx:1788
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
const TGGC * GetFrameGC() const
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:376
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:498
const TGWindow * GetMain() const
Definition TGFrame.h:514
const TGWindow * fMain
Definition TGFrame.h:501
virtual void CenterOnParent(Bool_t croot=kTRUE, EPlacement pos=kCenter)
Position transient frame centered relative to the parent frame.
Definition TGFrame.cxx:1957
A composite frame that layout their children in vertical way.
Definition TGFrame.h:374
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:47
Mother of all ROOT objects.
Definition TObject.h:41
R__ALWAYS_INLINE Bool_t IsZombie() const
Definition TObject.h:153
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition TObject.cxx:780
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition TObject.cxx:525
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:869
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:250
Short_t Min(Short_t a, Short_t b)
Returns the smallest of a and b.
Definition TMathBase.h:198
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