// @(#)root/ged:$Id$
// Author: Ilka Antcheva   11/05/04

/*************************************************************************
 * Copyright (C) 1995-2002, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

//////////////////////////////////////////////////////////////////////////
//                                                                      //
//  TAttMarkerEditor                                                    //
//                                                                      //
//  Implements GUI for editing marker attributes.                       //
//            color, style and size                                     //
//                                                                      //
//////////////////////////////////////////////////////////////////////////
//Begin_Html
/*
<img src="gif/TAttMarkerEditor.gif">
*/
//End_Html


#include "TAttMarkerEditor.h"
#include "TGedMarkerSelect.h"
#include "TGColorSelect.h"
#include "TGNumberEntry.h"
#include "TColor.h"
#include "TGLabel.h"
#include "TGNumberEntry.h"
#include "TPad.h"
#include "TCanvas.h"
#include "TROOT.h"

ClassImp(TAttMarkerEditor)

enum EMarkerWid {
   kCOLOR,
   kMARKER,
   kMARKER_SIZE,
   kALPHA,
   kALPHAFIELD
};

//______________________________________________________________________________
TAttMarkerEditor::TAttMarkerEditor(const TGWindow *p, Int_t width,
                                   Int_t height,UInt_t options, Pixel_t back)
   : TGedFrame(p, width, height, options | kVerticalFrame, back)
{
   // Constructor of marker attributes GUI.

   fAttMarker = 0;
   fSizeForText = kFALSE;

   MakeTitle("Marker");

   TGCompositeFrame *f2 = new TGCompositeFrame(this, 80, 20, kHorizontalFrame);
   fColorSelect = new TGColorSelect(f2, 0, kCOLOR);
   f2->AddFrame(fColorSelect, new TGLayoutHints(kLHintsLeft, 1, 1, 1, 1));
   fColorSelect->Associate(this);

   fMarkerType = new TGedMarkerSelect(f2, 1, kMARKER);
   f2->AddFrame(fMarkerType, new TGLayoutHints(kLHintsLeft, 1, 1, 1, 1));
   fMarkerType->Associate(this);

   fMarkerSize = new TGNumberEntry(f2, 0., 4, kMARKER_SIZE,
                                   TGNumberFormat::kNESRealOne,
                                   TGNumberFormat::kNEANonNegative,
                                   TGNumberFormat::kNELLimitMinMax, 0.2, 5.0);
   fMarkerSize->GetNumberEntry()->SetToolTipText("Set marker size");
   f2->AddFrame(fMarkerSize, new TGLayoutHints(kLHintsLeft, 1, 1, 1, 1));
   fMarkerSize->Associate(this);
   AddFrame(f2, new TGLayoutHints(kLHintsTop, 1, 1, 0, 0));

   TGLabel *AlphaLabel = new TGLabel(this,"Opacity");
   AddFrame(AlphaLabel,
            new TGLayoutHints(kLHintsLeft | kLHintsCenterY));
   TGHorizontalFrame *f2a = new TGHorizontalFrame(this);
   fAlpha = new TGHSlider(f2a,100,kSlider2|kScaleNo,kALPHA);
   fAlpha->SetRange(0,1000);
   f2a->AddFrame(fAlpha,new TGLayoutHints(kLHintsLeft | kLHintsCenterY));
   fAlphaField = new TGNumberEntryField(f2a, kALPHAFIELD, 0,
                                        TGNumberFormat::kNESReal,
                                        TGNumberFormat::kNEANonNegative);
   fAlphaField->Resize(40,20);
   if (!TCanvas::SupportAlpha()) {
      fAlpha->SetEnabled(kFALSE);
      AlphaLabel->Disable(kTRUE);
      fAlphaField->SetEnabled(kFALSE);
   }
   f2a->AddFrame(fAlphaField,new TGLayoutHints(kLHintsLeft | kLHintsCenterY));
   AddFrame(f2a, new TGLayoutHints(kLHintsLeft | kLHintsCenterY));
}

//______________________________________________________________________________
TAttMarkerEditor::~TAttMarkerEditor()
{
   // Destructor of marker editor.
}

//______________________________________________________________________________
void TAttMarkerEditor::ConnectSignals2Slots()
{
   // Connect signals to slots.

   fColorSelect->Connect("ColorSelected(Pixel_t)", "TAttMarkerEditor", this, "DoMarkerColor(Pixel_t)");
   fColorSelect->Connect("AlphaColorSelected(ULong_t)", "TAttMarkerEditor", this, "DoMarkerAlphaColor(ULong_t)");
   fMarkerType->Connect("MarkerSelected(Style_t)", "TAttMarkerEditor", this, "DoMarkerStyle(Style_t)");
   fMarkerSize->Connect("ValueSet(Long_t)", "TAttMarkerEditor", this, "DoMarkerSize()");
   (fMarkerSize->GetNumberEntry())->Connect("ReturnPressed()", "TAttMarkerEditor", this, "DoMarkerSize()");
   fAlpha->Connect("Released()","TAttMarkerEditor", this, "DoAlpha()");
   fAlpha->Connect("PositionChanged(Int_t)","TAttMarkerEditor", this, "DoLiveAlpha(Int_t)");
   fAlphaField->Connect("ReturnPressed()","TAttMarkerEditor", this, "DoAlphaField()");
   fAlpha->Connect("Pressed()","TAttMarkerEditor", this, "GetCurAlpha()");
   fInit = kFALSE;
}

//______________________________________________________________________________
void TAttMarkerEditor::SetModel(TObject* obj)
{
   // Pick up the values of used marker attributes.
   fAvoidSignal = kTRUE;

   fAttMarker = dynamic_cast<TAttMarker *>(obj);
   if (!fAttMarker) return;

   TString str = GetDrawOption();
   str.ToUpper();
   if (obj->InheritsFrom("TH2") && str.Contains("TEXT")) {
      fSizeForText = kTRUE;
   } else {
      fSizeForText = kFALSE;
   }
   Style_t marker = fAttMarker->GetMarkerStyle();
   if ((marker==1 || marker==6 || marker==7) && !fSizeForText) {
      fMarkerSize->SetNumber(1.);
      fMarkerSize->SetState(kFALSE);
   } else {
      Float_t s = fAttMarker->GetMarkerSize();
      fMarkerSize->SetState(kTRUE);
      fMarkerSize->SetNumber(s);
   }
   fMarkerType->SetMarkerStyle(marker);

   Color_t c = fAttMarker->GetMarkerColor();
   Pixel_t p = TColor::Number2Pixel(c);
   fColorSelect->SetColor(p);

   if (fInit) ConnectSignals2Slots();
   fAvoidSignal = kFALSE;

   if (TColor *color = gROOT->GetColor(fAttMarker->GetMarkerColor())) {
      fAlpha->SetPosition((Int_t)(color->GetAlpha()*1000));
      fAlphaField->SetNumber(color->GetAlpha());
   }
}


//______________________________________________________________________________
void TAttMarkerEditor::DoMarkerColor(Pixel_t color)
{
   // Slot connected to the marker color.

   if (fAvoidSignal) return;
   fAttMarker->SetMarkerColor(TColor::GetColor(color));

   if (TColor *tcolor = gROOT->GetColor(TColor::GetColor(color))) {
      fAlpha->SetPosition((Int_t)(tcolor->GetAlpha()*1000));
      fAlphaField->SetNumber(tcolor->GetAlpha());
   }

   Update();
}

//______________________________________________________________________________
void TAttMarkerEditor::DoMarkerAlphaColor(ULong_t p)
{
   // Slot connected to the color with alpha.

   TColor *color = (TColor *)p;

   if (fAvoidSignal) return;
   fAttMarker->SetMarkerColor(color->GetNumber());
   fAlpha->SetPosition((Int_t)(color->GetAlpha()*1000));
   fAlphaField->SetNumber(color->GetAlpha());

   Update();
}

//______________________________________________________________________________
void TAttMarkerEditor::DoMarkerStyle(Style_t marker)
{
   // Slot connected to the marker type.

   if (fAvoidSignal) return;
   if ((marker==1 || marker==6 || marker==7) && !fSizeForText) {
      fMarkerSize->SetNumber(1.);
      fMarkerSize->SetState(kFALSE);
   } else
      fMarkerSize->SetState(kTRUE);

   fAttMarker->SetMarkerStyle(marker);
   Update();
}

//______________________________________________________________________________
void TAttMarkerEditor::DoMarkerSize()
{
   // Slot connected to the marker size.

   if (fAvoidSignal) return;
   Style_t marker = fAttMarker->GetMarkerStyle();
   if ((marker==1 || marker==6 || marker==7) && !fSizeForText) {
      fMarkerSize->SetNumber(1.);
      fMarkerSize->SetState(kFALSE);
   } else
      fMarkerSize->SetState(kTRUE);
   Float_t size = fMarkerSize->GetNumber();
   fAttMarker->SetMarkerSize(size);
   Update();
}

//______________________________________________________________________________
void TAttMarkerEditor::DoAlphaField()
{
   // Slot to set the alpha value from the entry field.

   if (fAvoidSignal) return;

   if (TColor *color = gROOT->GetColor(fAttMarker->GetMarkerColor())) {
      color->SetAlpha((Float_t)fAlphaField->GetNumber());
      fAlpha->SetPosition((Int_t)fAlphaField->GetNumber()*1000);
   }
   Update();
}

//______________________________________________________________________________
void TAttMarkerEditor::DoAlpha()
{
   // Slot to set the alpha value

   if (fAvoidSignal) return;

   if (TColor *color = gROOT->GetColor(fAttMarker->GetMarkerColor())) {
      color->SetAlpha((Float_t)fAlpha->GetPosition()/1000);
      fAlphaField->SetNumber((Float_t)fAlpha->GetPosition()/1000);
   }
   Update();
}

//______________________________________________________________________________
void TAttMarkerEditor::DoLiveAlpha(Int_t a)
{
   // Slot to set alpha value online.

   if (fAvoidSignal) return;
   fAlphaField->SetNumber((Float_t)a/1000);

   if (TColor *color = gROOT->GetColor(fAttMarker->GetMarkerColor())) {
      // In case the color is not transparent a new color is created.
      if (color->GetAlpha() == 1.) {
         fAttMarker->SetMarkerColor(TColor::GetColorTransparent(color->GetNumber(),0.99));
      } else {
         color->SetAlpha((Float_t)a/1000);
      }
   }
   Update();
}

//_______________________________________________________________________________
void TAttMarkerEditor::GetCurAlpha()
{
   // Slot to update alpha value on click on Slider

   if (fAvoidSignal) return;

   if (TColor *color = gROOT->GetColor(fAttMarker->GetMarkerColor())) {
      fAlpha->SetPosition((Int_t)(color->GetAlpha()*1000));
      fAlphaField->SetNumber(color->GetAlpha());
   }
   Update();
}
 TAttMarkerEditor.cxx:1
 TAttMarkerEditor.cxx:2
 TAttMarkerEditor.cxx:3
 TAttMarkerEditor.cxx:4
 TAttMarkerEditor.cxx:5
 TAttMarkerEditor.cxx:6
 TAttMarkerEditor.cxx:7
 TAttMarkerEditor.cxx:8
 TAttMarkerEditor.cxx:9
 TAttMarkerEditor.cxx:10
 TAttMarkerEditor.cxx:11
 TAttMarkerEditor.cxx:12
 TAttMarkerEditor.cxx:13
 TAttMarkerEditor.cxx:14
 TAttMarkerEditor.cxx:15
 TAttMarkerEditor.cxx:16
 TAttMarkerEditor.cxx:17
 TAttMarkerEditor.cxx:18
 TAttMarkerEditor.cxx:19
 TAttMarkerEditor.cxx:20
 TAttMarkerEditor.cxx:21
 TAttMarkerEditor.cxx:22
 TAttMarkerEditor.cxx:23
 TAttMarkerEditor.cxx:24
 TAttMarkerEditor.cxx:25
 TAttMarkerEditor.cxx:26
 TAttMarkerEditor.cxx:27
 TAttMarkerEditor.cxx:28
 TAttMarkerEditor.cxx:29
 TAttMarkerEditor.cxx:30
 TAttMarkerEditor.cxx:31
 TAttMarkerEditor.cxx:32
 TAttMarkerEditor.cxx:33
 TAttMarkerEditor.cxx:34
 TAttMarkerEditor.cxx:35
 TAttMarkerEditor.cxx:36
 TAttMarkerEditor.cxx:37
 TAttMarkerEditor.cxx:38
 TAttMarkerEditor.cxx:39
 TAttMarkerEditor.cxx:40
 TAttMarkerEditor.cxx:41
 TAttMarkerEditor.cxx:42
 TAttMarkerEditor.cxx:43
 TAttMarkerEditor.cxx:44
 TAttMarkerEditor.cxx:45
 TAttMarkerEditor.cxx:46
 TAttMarkerEditor.cxx:47
 TAttMarkerEditor.cxx:48
 TAttMarkerEditor.cxx:49
 TAttMarkerEditor.cxx:50
 TAttMarkerEditor.cxx:51
 TAttMarkerEditor.cxx:52
 TAttMarkerEditor.cxx:53
 TAttMarkerEditor.cxx:54
 TAttMarkerEditor.cxx:55
 TAttMarkerEditor.cxx:56
 TAttMarkerEditor.cxx:57
 TAttMarkerEditor.cxx:58
 TAttMarkerEditor.cxx:59
 TAttMarkerEditor.cxx:60
 TAttMarkerEditor.cxx:61
 TAttMarkerEditor.cxx:62
 TAttMarkerEditor.cxx:63
 TAttMarkerEditor.cxx:64
 TAttMarkerEditor.cxx:65
 TAttMarkerEditor.cxx:66
 TAttMarkerEditor.cxx:67
 TAttMarkerEditor.cxx:68
 TAttMarkerEditor.cxx:69
 TAttMarkerEditor.cxx:70
 TAttMarkerEditor.cxx:71
 TAttMarkerEditor.cxx:72
 TAttMarkerEditor.cxx:73
 TAttMarkerEditor.cxx:74
 TAttMarkerEditor.cxx:75
 TAttMarkerEditor.cxx:76
 TAttMarkerEditor.cxx:77
 TAttMarkerEditor.cxx:78
 TAttMarkerEditor.cxx:79
 TAttMarkerEditor.cxx:80
 TAttMarkerEditor.cxx:81
 TAttMarkerEditor.cxx:82
 TAttMarkerEditor.cxx:83
 TAttMarkerEditor.cxx:84
 TAttMarkerEditor.cxx:85
 TAttMarkerEditor.cxx:86
 TAttMarkerEditor.cxx:87
 TAttMarkerEditor.cxx:88
 TAttMarkerEditor.cxx:89
 TAttMarkerEditor.cxx:90
 TAttMarkerEditor.cxx:91
 TAttMarkerEditor.cxx:92
 TAttMarkerEditor.cxx:93
 TAttMarkerEditor.cxx:94
 TAttMarkerEditor.cxx:95
 TAttMarkerEditor.cxx:96
 TAttMarkerEditor.cxx:97
 TAttMarkerEditor.cxx:98
 TAttMarkerEditor.cxx:99
 TAttMarkerEditor.cxx:100
 TAttMarkerEditor.cxx:101
 TAttMarkerEditor.cxx:102
 TAttMarkerEditor.cxx:103
 TAttMarkerEditor.cxx:104
 TAttMarkerEditor.cxx:105
 TAttMarkerEditor.cxx:106
 TAttMarkerEditor.cxx:107
 TAttMarkerEditor.cxx:108
 TAttMarkerEditor.cxx:109
 TAttMarkerEditor.cxx:110
 TAttMarkerEditor.cxx:111
 TAttMarkerEditor.cxx:112
 TAttMarkerEditor.cxx:113
 TAttMarkerEditor.cxx:114
 TAttMarkerEditor.cxx:115
 TAttMarkerEditor.cxx:116
 TAttMarkerEditor.cxx:117
 TAttMarkerEditor.cxx:118
 TAttMarkerEditor.cxx:119
 TAttMarkerEditor.cxx:120
 TAttMarkerEditor.cxx:121
 TAttMarkerEditor.cxx:122
 TAttMarkerEditor.cxx:123
 TAttMarkerEditor.cxx:124
 TAttMarkerEditor.cxx:125
 TAttMarkerEditor.cxx:126
 TAttMarkerEditor.cxx:127
 TAttMarkerEditor.cxx:128
 TAttMarkerEditor.cxx:129
 TAttMarkerEditor.cxx:130
 TAttMarkerEditor.cxx:131
 TAttMarkerEditor.cxx:132
 TAttMarkerEditor.cxx:133
 TAttMarkerEditor.cxx:134
 TAttMarkerEditor.cxx:135
 TAttMarkerEditor.cxx:136
 TAttMarkerEditor.cxx:137
 TAttMarkerEditor.cxx:138
 TAttMarkerEditor.cxx:139
 TAttMarkerEditor.cxx:140
 TAttMarkerEditor.cxx:141
 TAttMarkerEditor.cxx:142
 TAttMarkerEditor.cxx:143
 TAttMarkerEditor.cxx:144
 TAttMarkerEditor.cxx:145
 TAttMarkerEditor.cxx:146
 TAttMarkerEditor.cxx:147
 TAttMarkerEditor.cxx:148
 TAttMarkerEditor.cxx:149
 TAttMarkerEditor.cxx:150
 TAttMarkerEditor.cxx:151
 TAttMarkerEditor.cxx:152
 TAttMarkerEditor.cxx:153
 TAttMarkerEditor.cxx:154
 TAttMarkerEditor.cxx:155
 TAttMarkerEditor.cxx:156
 TAttMarkerEditor.cxx:157
 TAttMarkerEditor.cxx:158
 TAttMarkerEditor.cxx:159
 TAttMarkerEditor.cxx:160
 TAttMarkerEditor.cxx:161
 TAttMarkerEditor.cxx:162
 TAttMarkerEditor.cxx:163
 TAttMarkerEditor.cxx:164
 TAttMarkerEditor.cxx:165
 TAttMarkerEditor.cxx:166
 TAttMarkerEditor.cxx:167
 TAttMarkerEditor.cxx:168
 TAttMarkerEditor.cxx:169
 TAttMarkerEditor.cxx:170
 TAttMarkerEditor.cxx:171
 TAttMarkerEditor.cxx:172
 TAttMarkerEditor.cxx:173
 TAttMarkerEditor.cxx:174
 TAttMarkerEditor.cxx:175
 TAttMarkerEditor.cxx:176
 TAttMarkerEditor.cxx:177
 TAttMarkerEditor.cxx:178
 TAttMarkerEditor.cxx:179
 TAttMarkerEditor.cxx:180
 TAttMarkerEditor.cxx:181
 TAttMarkerEditor.cxx:182
 TAttMarkerEditor.cxx:183
 TAttMarkerEditor.cxx:184
 TAttMarkerEditor.cxx:185
 TAttMarkerEditor.cxx:186
 TAttMarkerEditor.cxx:187
 TAttMarkerEditor.cxx:188
 TAttMarkerEditor.cxx:189
 TAttMarkerEditor.cxx:190
 TAttMarkerEditor.cxx:191
 TAttMarkerEditor.cxx:192
 TAttMarkerEditor.cxx:193
 TAttMarkerEditor.cxx:194
 TAttMarkerEditor.cxx:195
 TAttMarkerEditor.cxx:196
 TAttMarkerEditor.cxx:197
 TAttMarkerEditor.cxx:198
 TAttMarkerEditor.cxx:199
 TAttMarkerEditor.cxx:200
 TAttMarkerEditor.cxx:201
 TAttMarkerEditor.cxx:202
 TAttMarkerEditor.cxx:203
 TAttMarkerEditor.cxx:204
 TAttMarkerEditor.cxx:205
 TAttMarkerEditor.cxx:206
 TAttMarkerEditor.cxx:207
 TAttMarkerEditor.cxx:208
 TAttMarkerEditor.cxx:209
 TAttMarkerEditor.cxx:210
 TAttMarkerEditor.cxx:211
 TAttMarkerEditor.cxx:212
 TAttMarkerEditor.cxx:213
 TAttMarkerEditor.cxx:214
 TAttMarkerEditor.cxx:215
 TAttMarkerEditor.cxx:216
 TAttMarkerEditor.cxx:217
 TAttMarkerEditor.cxx:218
 TAttMarkerEditor.cxx:219
 TAttMarkerEditor.cxx:220
 TAttMarkerEditor.cxx:221
 TAttMarkerEditor.cxx:222
 TAttMarkerEditor.cxx:223
 TAttMarkerEditor.cxx:224
 TAttMarkerEditor.cxx:225
 TAttMarkerEditor.cxx:226
 TAttMarkerEditor.cxx:227
 TAttMarkerEditor.cxx:228
 TAttMarkerEditor.cxx:229
 TAttMarkerEditor.cxx:230
 TAttMarkerEditor.cxx:231
 TAttMarkerEditor.cxx:232
 TAttMarkerEditor.cxx:233
 TAttMarkerEditor.cxx:234
 TAttMarkerEditor.cxx:235
 TAttMarkerEditor.cxx:236
 TAttMarkerEditor.cxx:237
 TAttMarkerEditor.cxx:238
 TAttMarkerEditor.cxx:239
 TAttMarkerEditor.cxx:240
 TAttMarkerEditor.cxx:241
 TAttMarkerEditor.cxx:242
 TAttMarkerEditor.cxx:243
 TAttMarkerEditor.cxx:244
 TAttMarkerEditor.cxx:245
 TAttMarkerEditor.cxx:246
 TAttMarkerEditor.cxx:247
 TAttMarkerEditor.cxx:248
 TAttMarkerEditor.cxx:249
 TAttMarkerEditor.cxx:250
 TAttMarkerEditor.cxx:251
 TAttMarkerEditor.cxx:252
 TAttMarkerEditor.cxx:253
 TAttMarkerEditor.cxx:254
 TAttMarkerEditor.cxx:255
 TAttMarkerEditor.cxx:256
 TAttMarkerEditor.cxx:257
 TAttMarkerEditor.cxx:258
 TAttMarkerEditor.cxx:259
 TAttMarkerEditor.cxx:260
 TAttMarkerEditor.cxx:261
 TAttMarkerEditor.cxx:262
 TAttMarkerEditor.cxx:263
 TAttMarkerEditor.cxx:264
 TAttMarkerEditor.cxx:265
 TAttMarkerEditor.cxx:266
 TAttMarkerEditor.cxx:267
 TAttMarkerEditor.cxx:268
 TAttMarkerEditor.cxx:269
 TAttMarkerEditor.cxx:270
 TAttMarkerEditor.cxx:271
 TAttMarkerEditor.cxx:272
 TAttMarkerEditor.cxx:273
 TAttMarkerEditor.cxx:274
 TAttMarkerEditor.cxx:275
 TAttMarkerEditor.cxx:276
 TAttMarkerEditor.cxx:277
 TAttMarkerEditor.cxx:278
 TAttMarkerEditor.cxx:279
 TAttMarkerEditor.cxx:280
 TAttMarkerEditor.cxx:281
 TAttMarkerEditor.cxx:282
 TAttMarkerEditor.cxx:283
 TAttMarkerEditor.cxx:284
 TAttMarkerEditor.cxx:285