66 ClassImp(TGColorPalette);
67 ClassImp(TGColorPick);
68 ClassImp(TGColorDialog);
110 static ULong_t gUcolor[24] = { 0xff000000 };
118 TGColorPalette::TGColorPalette(
const TGWindow *p, Int_t cols, Int_t rows, Int_t
id) :
119 TGFrame(p, 10, 10, kChildFrame)
122 fWidgetFlags = kWidgetIsEnabled;
124 fDrawGC = *fClient->GetResourcePool()->GetFrameGC();
134 fPixels =
new ULong_t[fRows * fCols];
136 for (Int_t i = 0; i < fRows * fCols; ++i) {
137 fPixels[i] = TColor::RGB2Pixel(255, 255, 255);
140 gVirtualX->GrabButton(fId, kAnyButton, kAnyModifier,
141 kButtonPressMask | kButtonReleaseMask |
142 kPointerMotionMask, kNone, kNone);
144 AddInput(kKeyPressMask | kEnterWindowMask | kLeaveWindowMask |
145 kFocusChangeMask | kStructureNotifyMask);
146 fEditDisabled = kEditDisable;
152 TGColorPalette::~TGColorPalette()
160 Bool_t TGColorPalette::HandleButton(Event_t *event)
162 if (event->fCode != kButton1)
165 if ((event->fType == kButtonPress) && HasFocus())
168 Int_t cx =
event->fX / (fCw + 5);
169 Int_t cy =
event->fY / (fCh + 5);
171 if (cx >= 0 && cx < fCols && cy >= 0 && cy < fRows) {
173 DrawFocusHilite(kFALSE);
178 DrawFocusHilite(kTRUE);
180 SendMessage(fMsgWindow, MK_MSG(kC_COLORSEL, kCOL_CLICK), fWidgetId, 0);
190 Bool_t TGColorPalette::HandleMotion(Event_t *event)
195 Int_t cx =
event->fX / (fCw + 5);
196 Int_t cy =
event->fY / (fCh + 5);
198 if (cx >= 0 && cx < fCols && cy >= 0 && cy < fRows) {
200 DrawFocusHilite(kFALSE);
205 DrawFocusHilite(kTRUE);
207 SendMessage(fMsgWindow, MK_MSG(kC_COLORSEL, kCOL_CLICK), fWidgetId, 0);
217 Bool_t TGColorPalette::HandleKey(Event_t *event)
222 if (event->fType == kGKeyPress) {
224 gVirtualX->LookupString(event, input,
sizeof(input), keysym);
229 switch ((EKeySym)keysym) {
235 if (cx < fCols - 1) ++cx;
243 if (cy < fRows - 1) ++cy;
259 if (cx != fCx || cy != fCy) {
261 DrawFocusHilite(kFALSE);
266 DrawFocusHilite(kTRUE);
268 SendMessage(fMsgWindow, MK_MSG(kC_COLORSEL, kCOL_CLICK), fWidgetId, 0);
279 void TGColorPalette::SetColors(ULong_t colors[])
281 for (Int_t i = 0; i < fRows * fCols; ++i)
282 SetColor(i, colors[i]);
283 gClient->NeedRedraw(
this);
289 void TGColorPalette::SetColor(Int_t ix, ULong_t color)
292 gClient->NeedRedraw(
this);
298 void TGColorPalette::SetCurrentCellColor(ULong_t color)
300 SetColor(fCy * fCols + fCx, color);
306 void TGColorPalette::SetCellSize(Int_t w, Int_t h)
310 gClient->NeedRedraw(
this);
316 ULong_t TGColorPalette::GetCurrentColor()
const
318 if (fCx >= 0 && fCy >= 0)
319 return GetColorByIndex(fCy * fCols + fCx);
321 return TColor::RGB2Pixel(0, 0, 0);
327 void TGColorPalette::DoRedraw()
333 for (i = 0; i < fRows; ++i) {
335 for (j = 0; j < fCols; ++j) {
336 Draw3dRectangle(kSunkenFrame | kDoubleBorder, x, y, fCw, fCh);
337 fDrawGC.SetForeground(fPixels[k++]);
338 gVirtualX->FillRectangle(fId, fDrawGC(), x + 2, y + 2, fCw - 4, fCh - 4);
344 DrawFocusHilite(kTRUE);
350 void TGColorPalette::GotFocus()
352 AddInput(kKeyPressMask | kKeyReleaseMask);
358 void TGColorPalette::LostFocus()
360 RemoveInput(kKeyPressMask | kKeyReleaseMask);
361 gClient->NeedRedraw(
this);
367 void TGColorPalette::DrawFocusHilite(Int_t onoff)
369 if (fCx >= 0 && fCy >= 0) {
370 GContext_t gc = onoff ? GetShadowGC()() : GetBckgndGC()();
371 gVirtualX->DrawRectangle(fId, gc, fCx * (fCw + 5) + 0, fCy * (fCh + 5) + 0,
384 TGColorPick::TGColorPick(
const TGWindow *p, Int_t w, Int_t h, Int_t
id) :
385 TGFrame(p, w, h, kChildFrame), fCursorGC(GetBlackGC())
390 fWidgetFlags = kWidgetIsEnabled;
393 fColormapRect.fX = 1;
394 fColormapRect.fY = 1;
395 fColormapRect.fWidth = w - 33 - 2;
396 fColormapRect.fHeight = h - 2;
397 fSliderRect.fX = w - 18 - 2;
399 fSliderRect.fWidth = 10;
400 fSliderRect.fHeight = h - 2;
410 gVirtualX->GetImageSize(fLimage, iw, ih);
416 fClick = kCLICK_NONE;
418 UpdateCurrentColor();
421 gVirtualX->GrabButton(fId, kAnyButton, kAnyModifier,
422 kButtonPressMask | kButtonReleaseMask |
423 kPointerMotionMask, kNone, kNone);
425 AddInput(kKeyPressMask | kEnterWindowMask | kLeaveWindowMask |
426 kFocusChangeMask | kStructureNotifyMask);
427 fEditDisabled = kEditDisable;
433 TGColorPick::~TGColorPick()
435 if (IsZombie())
return;
436 gVirtualX->DeleteImage(fHSimage);
437 gVirtualX->DeleteImage(fLimage);
444 Bool_t TGColorPick::HandleButton(Event_t *event)
446 if (event->fCode != kButton1)
return kFALSE;
448 if (event->fType == kButtonPress) {
449 if ((event->fX > fColormapRect.fX) && (event->fX < fColormapRect.fX + fColormapRect.fWidth) &&
450 (event->fY > fColormapRect.fY) && (event->fY < fColormapRect.fY + fColormapRect.fHeight)) {
453 SetHScursor(event->fX - fColormapRect.fX, event->fY - fColormapRect.fY);
455 }
else if (event->fX > fSliderRect.fX) {
458 SetLcursor(event->fY - fSliderRect.fY);
463 fClick = kCLICK_NONE;
467 UpdateCurrentColor();
468 if (fClick == kCLICK_HS) SetSliderColor();
470 SendMessage(fMsgWindow, MK_MSG(kC_COLORSEL, kCOL_CLICK), fWidgetId, kFALSE);
479 Bool_t TGColorPick::HandleMotion(Event_t *event)
484 if (fClick == kCLICK_HS) {
486 SetHScursor(event->fX - fColormapRect.fX, event->fY - fColormapRect.fY);
488 }
else if (fClick == kCLICK_L) {
490 SetLcursor(event->fY - fSliderRect.fY);
498 UpdateCurrentColor();
499 if (fClick == kCLICK_HS) SetSliderColor();
501 SendMessage(fMsgWindow, MK_MSG(kC_COLORSEL, kCOL_CLICK), fWidgetId, kFALSE);
510 void TGColorPick::CreateImages()
512 UInt_t width, height;
514 width = fColormapRect.fWidth;
515 height = fColormapRect.fHeight;
516 fHSimage = gVirtualX->CreateImage(width, height);
517 width = fSliderRect.fWidth;
518 height = fSliderRect.fHeight;
519 fLimage = gVirtualX->CreateImage(width, height);
526 void TGColorPick::AllocColors()
531 for (i = 0; i < 64; ++i) {
532 Int_t cc[4] = { 0, 21845, 43691, 65535 };
534 color.fRed = cc[i & 0x3];
535 color.fGreen = cc[(i >> 2) & 0x3];
536 color.fBlue = cc[(i >> 4) & 0x3];
537 if (gVirtualX->AllocColor(gVirtualX->GetColormap(), color) == 0)
539 fColormap[i][0] = color.fRed / 256;
540 fColormap[i][1] = color.fGreen / 256;
541 fColormap[i][2] = color.fBlue / 256;
542 fPixel[i] = color.fPixel;
546 if (fNColors == 64)
return;
552 for (i = 0; i < 27; ++i) {
553 Int_t cc[3] = { 0, 32768, 65535 };
555 color.fRed = cc[i % 3];
556 color.fGreen = cc[(i / 3) % 3];
557 color.fBlue = cc[(i / 9) % 3];
558 if (gVirtualX->AllocColor(gVirtualX->GetColormap(), color) == 0)
560 fColormap[i][0] = color.fRed / 256;
561 fColormap[i][1] = color.fGreen / 256;
562 fColormap[i][2] = color.fBlue / 256;
563 fPixel[i] = color.fPixel;
567 if (fNColors == 27)
return;
573 for (i = 0; i < 8; ++i) {
575 color.fRed = (i & 1) * 65535;
576 color.fGreen = ((i >> 1) & 1) * 65535;
577 color.fBlue = ((i >> 2) & 1) * 65535;
578 if (gVirtualX->AllocColor(gVirtualX->GetColormap(), color) == 0)
580 fColormap[i][0] = color.fRed / 256;
581 fColormap[i][1] = color.fGreen / 256;
582 fColormap[i][2] = color.fBlue / 256;
583 fPixel[i] = color.fPixel;
587 if (fNColors == 8)
return;
595 for (i = 0; i < 8; ++i) {
597 color.fRed = (i & 1) * 65535;
598 color.fGreen = ((i >> 1) & 1) * 65535;
599 color.fBlue = ((i >> 2) & 1) * 65535;
600 if (gVirtualX->AllocColor(gVirtualX->GetColormap(), color) != 0) {
601 fColormap[fNColors][0] = color.fRed / 256;
602 fColormap[fNColors][1] = color.fGreen / 256;
603 fColormap[fNColors][2] = color.fBlue / 256;
604 fPixel[fNColors++] = color.fPixel;
614 void TGColorPick::FreeColors()
616 for (Int_t i = 0; i < fNColors; i++)
617 gVirtualX->FreeColor(gVirtualX->GetColormap(), fPixel[i]);
627 void TGColorPick::CreateDitheredImage(Pixmap_t image, Int_t which)
629 const Int_t kWidth = 20;
631 ColorStruct_t line[kWidth];
632 struct { Int_t r, g, b; } ed[kWidth], ef;
633 Int_t x, y, c, v, e[4], nc = 0;
639 gVirtualX->GetImageSize(image, (UInt_t&) iw, (UInt_t&) ih);
641 for (x = 0; x < iw; ++x) {
642 ed[x].r = ed[x].g = ed[x].b = 0;
645 if (fNColors == 0) AllocColors();
647 for (y = 0; y < ih; ++y) {
649 if (which == kIMG_HS) {
651 for (x = 0; x < iw; ++x) {
655 s = (ih - y) * 255 / ih;
657 TColor::HLS2RGB(h, l, s, r, g, b);
664 }
else if (which == kIMG_L) {
666 TColor::Pixel2RGB(fCurrentColor, r, g, b);
667 TColor::RGB2HLS(r, g, b, h, l, s);
669 Int_t ll = (ih - y) * 255 / ih;
671 TColor::HLS2RGB(h, ll, s, r, g, b);
673 for (x = 0; x < iw; ++x) {
685 ef.r = ef.g = ef.b = 0;
687 for (x = 0; x < iw; ++x) {
691 v = line[x].fRed + ed[x].r;
692 if (v < 0) v = 0;
else if (v > 255) v = 255;
695 v = line[x].fGreen + ed[x].g;
696 if (v < 0) v = 0;
else if (v > 255) v = 255;
699 v = line[x].fBlue + ed[x].b;
700 if (v < 0) v = 0;
else if (v > 255) v = 255;
705 for (x = 0; x < iw; ++x) {
709 v = line[x].fRed + ef.r;
710 if (v < 0) v = 0;
else if (v > 255) v = 255;
713 v = line[x].fGreen + ef.g;
714 if (v < 0) v = 0;
else if (v > 255) v = 255;
717 v = line[x].fBlue + ef.b;
718 if (v < 0) v = 0;
else if (v > 255) v = 255;
723 sdist = 255L * 255L * 255L;
724 for (c = 0; c < fNColors; ++c) {
726 Int_t dr = line[x].fRed - fColormap[c][0];
727 Int_t dg = line[x].fGreen - fColormap[c][1];
728 Int_t db = line[x].fBlue - fColormap[c][2];
730 dist = dr * dr + dg * dg + db * db;
737 gVirtualX->PutPixel(image, x, y, fPixel[nc]);
740 e[0] = (7 * v) >> 4; \
742 e[2] = (5 * v) >> 4; \
745 v = line[x].fRed - fColormap[nc][0];
749 if (x < iw-1) ed[x+1].r = e[1];
750 if (x == 0) ed[x].r = e[2]; else ed[x].r += e[2];
751 if (x > 0) ed[x-1].r += e[3];
753 v = line[x].fGreen - fColormap[nc][1];
757 if (x < iw-1) ed[x+1].g = e[1];
758 if (x == 0) ed[x].g = e[2]; else ed[x].g += e[2];
759 if (x > 0) ed[x-1].g += e[3];
761 v = line[x].fBlue - fColormap[nc][2];
765 if (x < iw-1) ed[x+1].b = e[1];
766 if (x == 0) ed[x].b = e[2]; else ed[x].b += e[2];
767 if (x > 0) ed[x-1].b += e[3];
776 void TGColorPick::InitImages()
782 gVirtualX->GetImageSize(fHSimage, (UInt_t&) width, (UInt_t&) height);
786 Int_t ncolors = gVirtualX->GetDepth();
789 for (Int_t y = 0; y < height; ++y) {
790 for (Int_t x = 0; x < width; ++x) {
795 s = (height - y) * 255 / height;
797 TColor::HLS2RGB(h, l, s, r, g, b);
799 ULong_t pixel = TColor::RGB2Pixel(r, g, b);
800 gVirtualX->PutPixel(fHSimage, x, y, pixel);
804 CreateDitheredImage(fHSimage, kIMG_HS);
815 void TGColorPick::SetSliderColor()
821 gVirtualX->GetImageSize(fLimage, (UInt_t&) width, (UInt_t&) height);
823 Int_t ncolors = gVirtualX->GetDepth();
827 for (Int_t y = 0; y < height; ++y) {
829 TColor::Pixel2RGB(fCurrentColor, r, g, b);
830 TColor::RGB2HLS(r, g, b, h, l, s);
832 l = (height - y) * 255 / height;
834 TColor::HLS2RGB(h, l, s, r, g, b);
836 ULong_t pixel = TColor::RGB2Pixel(r, g, b);
838 for (Int_t x = 0; x < width; ++x) {
839 gVirtualX->PutPixel(fLimage, x, y, pixel);
843 CreateDitheredImage(fLimage, kIMG_L);
846 gClient->NeedRedraw(
this);
852 void TGColorPick::SetColor(ULong_t color)
854 UInt_t width, height;
858 gVirtualX->GetImageSize(fHSimage, width, height);
860 fCurrentColor = color;
862 TColor::Pixel2RGB(fCurrentColor, r, g, b);
863 TColor::RGB2HLS(r, g, b, h, l, s);
865 SetHScursor(h * (Int_t)width / 256, (255 - s) * (Int_t)height / 256);
867 gVirtualX->GetImageSize(fLimage, width, height);
869 SetLcursor((255 - l) * (Int_t)height / 256);
877 void TGColorPick::UpdateCurrentColor()
879 UInt_t lwidth, lheight;
880 UInt_t swidth, sheight;
884 gVirtualX->GetImageSize(fLimage, lwidth, lheight);
885 gVirtualX->GetImageSize(fHSimage, swidth, sheight);
887 h = Int_t(fCx * 255 / swidth);
888 l = Int_t((lheight - fCz) * 255 / lheight);
889 s = Int_t((sheight - fCy) * 255 / sheight);
891 TColor::HLS2RGB(h, l, s, r, g, b);
892 fCurrentColor = TColor::RGB2Pixel(r, g, b);
898 void TGColorPick::DoRedraw()
900 UInt_t lwidth, lheight;
901 UInt_t swidth, sheight;
903 gVirtualX->GetImageSize(fLimage, lwidth, lheight);
904 gVirtualX->GetImageSize(fHSimage, swidth, sheight);
908 Draw3dRectangle(kSunkenFrame, fColormapRect.fX - 1, fColormapRect.fY - 1,
909 fColormapRect.fWidth + 2, fColormapRect.fHeight + 2);
910 gVirtualX->PutImage(fId, GetBckgndGC()(), fHSimage,
911 fColormapRect.fX, fColormapRect.fY, 0, 0, swidth, sheight);
913 Draw3dRectangle(kSunkenFrame, fSliderRect.fX - 1, fSliderRect.fY - 1,
914 fSliderRect.fWidth + 2, fSliderRect.fHeight + 2);
915 gVirtualX->PutImage(fId, GetBckgndGC()(), fLimage,
916 fSliderRect.fX, fSliderRect.fY, 0, 0, lwidth, lheight);
925 void TGColorPick::SetHScursor(Int_t x, Int_t y)
927 UInt_t width, height;
929 gVirtualX->GetImageSize(fHSimage, width, height);
931 DrawHScursor(kFALSE);
938 else if (fCx >= (Int_t)width)
939 fCx = (Int_t)width - 1;
943 else if (fCy >= (Int_t)height)
944 fCy = (Int_t)height - 1;
952 void TGColorPick::SetLcursor(Int_t z)
954 UInt_t width, height;
956 gVirtualX->GetImageSize(fLimage, width, height);
960 fCz = z - fSliderRect.fY;
964 else if (fCz >= (Int_t)height)
965 fCz = (Int_t)height - 1;
973 void TGColorPick::DrawHScursor(Int_t onoff)
975 UInt_t width, height;
977 gVirtualX->GetImageSize(fHSimage, width, height);
983 x = fCx + fColormapRect.fX;
984 y = fCy + fColormapRect.fY;
986 rect.fX = fColormapRect.fX;
987 rect.fY = fColormapRect.fX;
988 rect.fWidth = fColormapRect.fWidth;
989 rect.fHeight = fColormapRect.fHeight;
990 gVirtualX->SetClipRectangles(fCursorGC(), 0, 0, &rect, 1);
992 gVirtualX->FillRectangle(fId, fCursorGC(), x - 9, y - 1, 5, 3);
993 gVirtualX->FillRectangle(fId, fCursorGC(), x - 1, y - 9, 3, 5);
994 gVirtualX->FillRectangle(fId, fCursorGC(), x + 5, y - 1, 5, 3);
995 gVirtualX->FillRectangle(fId, fCursorGC(), x - 1, y + 5, 3, 5);
1001 x = fCx - 9; w = 19;
1002 y = fCy - 9; h = 19;
1004 if (x < 0) { w += x; x = 0; }
1005 if (y < 0) { h += y; y = 0; }
1007 if (x + w > width) w = width - x;
1008 if (y + h > height) h = height - y;
1010 gVirtualX->PutImage(fId, GetBckgndGC()(), fHSimage, x, y,
1011 fColormapRect.fX + x, fColormapRect.fY + y, w, h);
1018 void TGColorPick::DrawLcursor(Int_t onoff)
1020 Int_t l = fSliderRect.fX + fSliderRect.fWidth + 3;
1022 Int_t t = fCz - 5 + fSliderRect.fY;
1027 Int_t m = (t + b) >> 1;
1036 GContext_t gc = onoff ? GetShadowGC()() : GetBckgndGC()();
1038 gVirtualX->FillPolygon(fId, gc, points, 3);
1047 TGColorDialog::TGColorDialog(
const TGWindow *p,
const TGWindow *m,
1048 Int_t *retc, ULong_t *color, Bool_t wait) :
1049 TGTransientFrame(p, m, 200, 150)
1051 const Int_t kC_X = 175;
1052 const Int_t kC_Y = 180;
1062 fRetTColor = gROOT->GetColor(TColor::GetColor(*color));
1063 fInitColor = *fRetColor;
1067 if (fRetc) *fRetc = kMBCancel;
1069 TGHorizontalFrame *hftop =
new TGHorizontalFrame(
this, 10, 10);
1070 hftop->SetCleanup();
1071 AddFrame(hftop,
new TGLayoutHints(kLHintsTop | kLHintsLeft, 5, 5, 10, 5));
1073 fTab =
new TGTab(hftop, 300, 300);
1074 hftop->AddFrame(fTab);
1076 TGCompositeFrame *cf =
new TGCompositeFrame(hftop, 10, 10);
1078 hftop->AddFrame(cf,
new TGLayoutHints(kLHintsLeft | kLHintsTop, 5, 0, 30, 0));
1080 TGCompositeFrame *cf1 =
new TGCompositeFrame(cf, 10, 10);
1082 cf->AddFrame(cf1,
new TGLayoutHints(kLHintsLeft | kLHintsTop, 5, 0, 30, 0));
1083 cf1->SetLayoutManager(
new TGMatrixLayout(cf1, 0, 2, 4));
1085 cf1->AddFrame(
new TGLabel(cf1,
new TGHotString(
"Red:")));
1086 cf1->AddFrame(fRte =
new TGTextEntry(cf1, fRtb =
new TGTextBuffer(5), kCDLG_RTE),0);
1087 fRte->Resize(50, fRte->GetDefaultHeight());
1088 cf1->AddFrame(
new TGLabel(cf1,
new TGHotString(
"Green:")),0);
1089 cf1->AddFrame(fGte =
new TGTextEntry(cf1, fGtb =
new TGTextBuffer(5), kCDLG_GTE),0);
1090 fGte->Resize(50, fGte->GetDefaultHeight());
1091 cf1->AddFrame(
new TGLabel(cf1,
new TGHotString(
"Blue:")));
1092 cf1->AddFrame(fBte =
new TGTextEntry(cf1, fBtb =
new TGTextBuffer(5), kCDLG_BTE),0);
1093 fBte->Resize(50, fBte->GetDefaultHeight());
1094 cf1->AddFrame(
new TGLabel(cf1,
new TGHotString(
"Opacity:")),0);
1095 cf1->AddFrame(fAle =
new TGTextEntry(cf1, fAlb =
new TGTextBuffer(5), kCDLG_ALE),0);
1096 fAle->Resize(50, fAle->GetDefaultHeight());
1098 if (!TCanvas::SupportAlpha()) {
1099 fAle->SetEnabled(kFALSE);
1102 TGCompositeFrame *cf2 =
new TGCompositeFrame(cf, 10, 10);
1104 cf->AddFrame(cf2,
new TGLayoutHints(kLHintsLeft | kLHintsTop, 5, 0, 30, 0));
1105 cf2->SetLayoutManager(
new TGMatrixLayout(cf2, 0, 2, 4));
1106 cf2->AddFrame(
new TGLabel(cf2,
new TGHotString(
"Hue:")),0);
1107 cf2->AddFrame(fHte =
new TGTextEntry(cf2, fHtb =
new TGTextBuffer(5), kCDLG_HTE),0);
1108 fHte->Resize(50, fHte->GetDefaultHeight());
1109 cf2->AddFrame(
new TGLabel(cf2,
new TGHotString(
"Sat:")),0);
1110 cf2->AddFrame(fSte =
new TGTextEntry(cf2, fStb =
new TGTextBuffer(5), kCDLG_STE),0);
1111 fSte->Resize(50, fSte->GetDefaultHeight());
1112 cf2->AddFrame(
new TGLabel(cf2,
new TGHotString(
"Lum:")),0);
1113 cf2->AddFrame(fLte =
new TGTextEntry(cf2, fLtb =
new TGTextBuffer(5), kCDLG_LTE),0);
1114 fLte->Resize(50, fLte->GetDefaultHeight());
1116 fHte->Associate(
this);
1117 fLte->Associate(
this);
1118 fSte->Associate(
this);
1119 fRte->Associate(
this);
1120 fGte->Associate(
this);
1121 fBte->Associate(
this);
1122 fAle->Associate(
this);
1125 UpdateRGBentries(color);
1126 UpdateHLSentries(color);
1128 fCurrentColor = *color;
1130 gClient->GetColorByName(
"red", fCurrentColor);
1134 TGCompositeFrame *cf3 =
new TGCompositeFrame(cf, 10, 10);
1136 cf3->SetLayoutManager(
new TGMatrixLayout(cf3, 0, 1, 0));
1137 cf3->AddFrame(fColorInfo =
new TGLabel(cf3,
new TGString(
"New: not set ")),0);
1138 fColorInfo->SetTextJustify(kTextLeft);
1139 cf3->AddFrame(fSample =
new TGFrame(cf3, 50, 25, kOwnBackground),0);
1140 cf3->AddFrame(fSampleOld =
new TGFrame(cf3, 50, 25, kOwnBackground),0);
1141 cf3->AddFrame(
new TGLabel(cf3,
new TGString(
"Current")),0);
1142 cf->AddFrame(cf3,
new TGLayoutHints(kLHintsLeft | kLHintsTop, 5, 5, 20, 0));
1143 fSample->SetBackgroundColor(fCurrentColor);
1144 fSampleOld->SetBackgroundColor(fCurrentColor);
1146 TGCompositeFrame *tf = fTab->AddTab(
"Color Wheel");
1147 TGCompositeFrame *tf1 =
new TGCompositeFrame(tf, 60, 20, kHorizontalFrame);
1149 fEcanvas =
new TRootEmbeddedCanvas(
"wheel", tf1, 360, 360);
1150 tf1->AddFrame(fEcanvas);
1151 TCanvas *wcan = fEcanvas->GetCanvas();
1152 wcan->SetBit(kNoContextMenu);
1153 fColorWheel =
new TColorWheel();
1154 fColorWheel->SetCanvas(wcan);
1155 fColorWheel->Draw();
1157 wcan->Connect(
"ProcessedEvent(Int_t,Int_t,Int_t,TObject*)",
"TGColorDialog",
this,
1158 "SetColorInfo(Int_t,Int_t,Int_t,TObject*)");
1160 tf = fTab->AddTab(
"Basic Colors");
1161 TGCompositeFrame *tf2 =
new TGCompositeFrame(tf, 60, 20, kHorizontalFrame);
1164 TGVerticalFrame *vf1 =
new TGVerticalFrame(tf2, 20, 20);
1166 TGVerticalFrame *vf2 =
new TGVerticalFrame(tf2, 20, 20);
1169 tf2->AddFrame(vf1,
new TGLayoutHints(kLHintsLeft | kLHintsExpandY));
1170 tf2->AddFrame(vf2,
new TGLayoutHints(kLHintsLeft | kLHintsExpandY));
1176 fPalette =
new TGColorPalette(vf1, 6, 8, kCDLG_SPALETTE);
1177 vf1->AddFrame(fPalette,
new TGLayoutHints(kLHintsNormal, 5, 5, 15, 0));
1178 fPalette->Associate(
this);
1180 for (i = 0; i < 48; ++i)
1181 fPalette->SetColor(i, TColor::Number2Pixel(i+10));
1186 fPalette->SetColor(47, TGFrame::GetDefaultFrameBackground());
1195 Pixel_t pixel = TColor::RGB2Pixel(r, g, b);
1196 fPalette->SetColor(46, pixel);
1203 pixel = TColor::RGB2Pixel(r, g, b);
1204 fPalette->SetColor(45, pixel);
1211 pixel = TColor::RGB2Pixel(r, g, b);
1212 fPalette->SetColor(44, pixel);
1219 pixel = TColor::RGB2Pixel(r, g, b);
1220 fPalette->SetColor(43, pixel);
1224 vf1->AddFrame(
new TGLabel(vf1,
new TGHotString(
"&Custom Colors:")),
1225 new TGLayoutHints(kLHintsNormal, 5, 0, 15, 2));
1227 fCpalette =
new TGColorPalette(vf1, 6, 4, kCDLG_CPALETTE);
1228 vf1->AddFrame(fCpalette,
new TGLayoutHints(kLHintsNormal, 5, 5, 5, 0));
1229 fCpalette->Associate(
this);
1231 if (gUcolor[0] == 0xff000000) {
1232 for (i = 0; i < 24; i++)
1233 gUcolor[i] = TColor::RGB2Pixel(255, 255, 255);
1235 fCpalette->SetColors(gUcolor);
1238 TGHorizontalFrame *hf =
new TGHorizontalFrame(
this, 10, 10, kFixedWidth);
1240 AddFrame(hf,
new TGLayoutHints(kLHintsBottom | kLHintsRight, 5, 5, 10, 5));
1242 TGTextButton *ok =
new TGTextButton(hf,
new TGHotString(
"OK"), kCDLG_OK);
1243 TGTextButton *cancel =
new TGTextButton(hf,
new TGHotString(
"Cancel"), kCDLG_CANCEL);
1244 fPreview =
new TGTextButton(hf,
new TGHotString(
"&Preview"), kCDLG_PREVIEW);
1245 fPreview->Connect(
"Clicked()",
"TGColorDialog",
this,
"DoPreview()");
1247 hf->AddFrame(ok,
new TGLayoutHints(kLHintsBottom | kLHintsExpandX, 0, 3, 0, 0));
1248 hf->AddFrame(cancel,
new TGLayoutHints(kLHintsBottom | kLHintsExpandX,3, 0, 0, 0));
1249 hf->AddFrame(fPreview,
new TGLayoutHints(kLHintsBottom | kLHintsExpandX,3, 0, 0, 0));
1251 UInt_t w = ok->GetDefaultWidth();
1252 w = TMath::Max(w, cancel->GetDefaultWidth());
1253 hf->Resize(3 * (w + 30), hf->GetDefaultHeight());
1255 ok->Associate(
this);
1256 cancel->Associate(
this);
1262 fColors =
new TGColorPick(vf2, kC_X + 23, kC_Y, kCDLG_COLORPICK);
1263 vf2->AddFrame(fColors,
new TGLayoutHints(kLHintsLeft | kLHintsTop, 5, 0, 15, 5));
1264 fColors->Associate(
this);
1267 fColors->SetColor(*color);
1269 TGTextButton *add =
new TGTextButton(vf2,
new TGHotString(
"&Add to Custom Colors"),
1271 vf2->AddFrame(add,
new TGLayoutHints(kLHintsBottom | kLHintsExpandX,
1273 add->Associate(
this);
1276 Resize(GetDefaultSize());
1277 SetEditDisabled(kEditDisable);
1281 SetWMSize(fWidth, fHeight);
1282 SetWMSizeHints(fWidth, fHeight, fWidth, fHeight, 0, 0);
1284 SetWindowName(
"Color Selector");
1285 SetIconName(
"Color Selector");
1286 SetClassHints(
"ROOT",
"ColorSelector");
1288 SetMWMHints(kMWMDecorAll | kMWMDecorResizeH | kMWMDecorMaximize |
1289 kMWMDecorMinimize | kMWMDecorMenu,
1290 kMWMFuncAll | kMWMFuncResize | kMWMFuncMaximize |
1297 if (fClient->IsEditable()) {
1298 const TGWindow *main = fMain;
1299 fMain = fClient->GetRoot();
1300 CenterOnParent(kTRUE, TGTransientFrame::kRight);
1308 fClient->WaitForUnmap(
this);
1316 TGColorDialog::~TGColorDialog()
1318 fEcanvas->GetCanvas()->Disconnect(
"ProcessedEvent(Int_t,Int_t,Int_t,TObject*)");
1326 void TGColorDialog::SetCurrentColor(Pixel_t col)
1328 if (fCurrentColor == col) {
1331 fInitColor = *fRetColor = col;
1332 if((fRetTColor = gROOT->GetColor(TColor::GetColor(col)))) {};
1333 fCurrentColor = col;
1334 fColors->SetColor(col);
1335 fSample->SetBackgroundColor(col);
1342 void TGColorDialog::ColorSelected(Pixel_t color)
1344 Emit(
"ColorSelected(Pixel_t)", color);
1350 void TGColorDialog::AlphaColorSelected(ULong_t color)
1352 Emit(
"AlphaColorSelected(ULong_t)", color);
1358 void TGColorDialog::CloseWindow()
1361 for (Int_t i = 0; i < 24; ++i)
1362 gUcolor[i] = fCpalette->GetColorByIndex(i);
1364 if (*fRetc != kMBOk) {
1365 ColorSelected(fInitColor);
1367 if((ptr = (ULong_t)gROOT->GetColor(TColor::GetColor(fInitColor)))) AlphaColorSelected(ptr);
1369 ColorSelected(*fRetColor);
1370 AlphaColorSelected((ULong_t)fRetTColor);
1377 if (gVirtualX->InheritsFrom(
"TGX11") && fEcanvas->GetCanvas()->UseGL())
1378 fEcanvas->GetCanvas()->DeleteCanvasPainter();
1386 void TGColorDialog::UpdateAlpha(ULong_t *c)
1391 if (TColor *color = gROOT->GetColor(TColor::GetColor(*c))) {
1392 alpha = color->GetAlpha();
1393 snprintf(tmp, 20,
"%.1f", alpha);
1395 fAlb->AddText(0,tmp);
1396 gClient->NeedRedraw(fAle);
1404 void TGColorDialog::UpdateRGBentries(ULong_t *c)
1409 TColor::Pixel2RGB(*c, r, g, b);
1411 snprintf(tmp, 20,
"%d", r);
1413 fRtb->AddText(0, tmp);
1414 gClient->NeedRedraw(fRte);
1416 snprintf(tmp, 20,
"%d", g);
1418 fGtb->AddText(0, tmp);
1419 gClient->NeedRedraw(fGte);
1421 snprintf(tmp, 20,
"%d", b);
1423 fBtb->AddText(0, tmp);
1424 gClient->NeedRedraw(fBte);
1430 void TGColorDialog::UpdateHLSentries(ULong_t *c)
1437 TColor::Pixel2RGB(*c, r, g, b);
1438 TColor::RGB2HLS(r, g, b, h, l, s);
1440 snprintf(tmp, 20,
"%d", h);
1442 fHtb->AddText(0, tmp);
1443 gClient->NeedRedraw(fHte);
1445 snprintf(tmp, 20,
"%d", l);
1447 fLtb->AddText(0, tmp);
1448 gClient->NeedRedraw(fLte);
1450 snprintf(tmp, 20,
"%d", s);
1452 fStb->AddText(0, tmp);
1453 gClient->NeedRedraw(fSte);
1459 Bool_t TGColorDialog::ProcessMessage(Long_t msg, Long_t parm1, Long_t )
1465 switch (GET_MSG(msg)) {
1467 switch (GET_SUBMSG(msg)) {
1471 fCpalette->SetCurrentCellColor(fCurrentColor);
1476 *fRetColor = TColor::RGB2Pixel(atoi(fRtb->GetString()),
1477 atoi(fGtb->GetString()),
1478 atoi(fBtb->GetString()));
1479 if ((fRetTColor = gROOT->GetColor(TColor::GetColor(*fRetColor)))) {
1480 fRetTColor->SetAlpha(TMath::Max((Double_t)0, TMath::Min((Double_t)1,
1481 atof(fAlb->GetString()))));
1486 if (!fClient->IsEditable()) {
1487 TGColorPopup *p = (TGColorPopup *)GetMain();
1488 if (p && p->InheritsFrom(
"TGColorPopup"))
1489 p->PreviewColor(fSampleOld->GetBackground());
1498 switch (GET_SUBMSG(msg)) {
1501 case kCDLG_SPALETTE:
1502 color = fPalette->GetCurrentColor();
1503 fSample->SetBackgroundColor(color);
1504 ColorSelected(color);
1505 gClient->NeedRedraw(fSample);
1506 fCurrentColor = color;
1507 fColors->SetColor(color);
1508 UpdateRGBentries(&color);
1509 UpdateHLSentries(&color);
1510 UpdateAlpha(&color);
1513 case kCDLG_CPALETTE:
1514 color = fCpalette->GetCurrentColor();
1515 fSample->SetBackgroundColor(color);
1516 ColorSelected(color);
1517 gClient->NeedRedraw(fSample);
1518 fCurrentColor = color;
1519 fColors->SetColor(color);
1520 UpdateRGBentries(&color);
1521 UpdateHLSentries(&color);
1522 UpdateAlpha(&color);
1525 case kCDLG_COLORPICK:
1526 color = fColors->GetCurrentColor();
1527 fSample->SetBackgroundColor(color);
1528 ColorSelected(color);
1529 gClient->NeedRedraw(fSample);
1530 fCurrentColor = color;
1531 UpdateRGBentries(&color);
1532 UpdateHLSentries(&color);
1533 UpdateAlpha(&color);
1542 switch (GET_SUBMSG(msg)) {
1543 case kTE_TEXTCHANGED:
1549 h = atoi(fHtb->GetString());
1550 l = atoi(fLtb->GetString());
1551 s = atoi(fStb->GetString());
1552 TColor::HLS2RGB(h, l, s, r, g, b);
1554 color = TColor::RGB2Pixel(r, g, b);
1555 fSample->SetBackgroundColor(color);
1556 ColorSelected(color);
1557 gClient->NeedRedraw(fSample);
1558 fCurrentColor = color;
1559 fColors->SetColor(color);
1560 UpdateRGBentries(&color);
1566 color = TColor::RGB2Pixel(atoi(fRtb->GetString()),
1567 atoi(fGtb->GetString()),
1568 atoi(fBtb->GetString()));
1569 fSample->SetBackgroundColor(color);
1570 ColorSelected(color);
1571 gClient->NeedRedraw(fSample);
1572 fCurrentColor = color;
1573 fColors->SetColor(color);
1574 UpdateHLSentries(&color);
1589 void TGColorDialog::SetColorInfo(Int_t event, Int_t px, Int_t py, TObject *
object)
1591 if (
object == fColorWheel) {
1592 Int_t n = fColorWheel->GetColor(px,py);
1594 TColor *color = gROOT->GetColor(n);
1596 ULong_t pcolor = color->GetPixel();
1597 if (event == kButton1Down) {
1598 UpdateRGBentries(&pcolor);
1599 UpdateHLSentries(&pcolor);
1600 UpdateAlpha(&pcolor);
1601 fSample->SetBackgroundColor(pcolor);
1602 fColorInfo->SetText(Form(
"New: %s",color->GetName()));
1603 gClient->NeedRedraw(fSample);
1604 gClient->NeedRedraw(fColorInfo);
1605 fCurrentColor = pcolor;
1606 fColors->SetColor(pcolor);
1607 ColorSelected(pcolor);
1615 void TGColorDialog::DoPreview()
1618 if ((tcolor = gROOT->GetColor(TColor::GetColor(fSample->GetBackground())))) {
1619 tcolor->SetAlpha(TMath::Max((Double_t)0, TMath::Min((Double_t)1, atof(fAlb->GetString()))));
1622 if (fClient->IsEditable()) {
1623 ColorSelected(fSample->GetBackground());
1624 AlphaColorSelected((ULong_t)tcolor);
1627 TGColorPopup *p = (TGColorPopup *)GetMain();
1628 if (p && p->InheritsFrom(
"TGColorPopup")) {
1629 if (tcolor) p->PreviewAlphaColor((ULong_t)tcolor);
1630 else p->PreviewColor(fSample->GetBackground());