ROOT logo
// @(#)root/ged:$Id$
// Author: Ilka Antcheva   10/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.             *
 *************************************************************************/

//////////////////////////////////////////////////////////////////////////
//                                                                      //
//  TAttLineEditor                                                      //
//                                                                      //
//  Implements GUI for editing line attributes.                         //                                             //
//           color, line width, line style                              //
//                                                                      //
//////////////////////////////////////////////////////////////////////////
//Begin_Html
/*
<img src="gif/TAttLineEditor.gif">
*/
//End_Html


#include "TAttLineEditor.h"
#include "TGColorSelect.h"
#include "TGComboBox.h"
#include "TColor.h"
#include "TGraph.h"
#include "TGLabel.h"
#include "TGNumberEntry.h"
#include "TPad.h"
#include "TCanvas.h"
#include "TROOT.h"

ClassImp(TAttLineEditor)

enum ELineWid {
   kCOLOR,
   kLINE_WIDTH,
   kLINE_STYLE,
   kALPHA,
   kALPHAFIELD
};


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

   fPriority = 1;
   fAttLine = 0;

   MakeTitle("Line");

   TGCompositeFrame *f2 = new TGCompositeFrame(this, 80, 20, kHorizontalFrame);
   AddFrame(f2, new TGLayoutHints(kLHintsTop, 1, 1, 0, 0));

   fColorSelect = new TGColorSelect(f2, 0, kCOLOR);
   f2->AddFrame(fColorSelect, new TGLayoutHints(kLHintsLeft, 1, 1, 1, 1));
   fColorSelect->Associate(this);

   fStyleCombo = new TGLineStyleComboBox(this, kLINE_STYLE);
   fStyleCombo->Resize(137, 20);
   AddFrame(fStyleCombo, new TGLayoutHints(kLHintsLeft, 3, 1, 1, 1));
   fStyleCombo->Associate(this);

   fWidthCombo = new TGLineWidthComboBox(f2, kLINE_WIDTH);
   fWidthCombo->Resize(90, 20);
   f2->AddFrame(fWidthCombo, new TGLayoutHints(kLHintsLeft, 3, 1, 1, 1));
   fWidthCombo->Associate(this);

   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));
}

//______________________________________________________________________________
TAttLineEditor::~TAttLineEditor()
{
   // Destructor of line editor.
}

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

   fColorSelect->Connect("ColorSelected(Pixel_t)", "TAttLineEditor", this, "DoLineColor(Pixel_t)");
   fColorSelect->Connect("AlphaColorSelected(ULong_t)", "TAttLineEditor", this, "DoLineAlphaColor(ULong_t)");
   fStyleCombo->Connect("Selected(Int_t)", "TAttLineEditor", this, "DoLineStyle(Int_t)");
   fWidthCombo->Connect("Selected(Int_t)", "TAttLineEditor", this, "DoLineWidth(Int_t)");
   fAlpha->Connect("Released()","TAttLineEditor", this, "DoAlpha()");
   fAlpha->Connect("PositionChanged(Int_t)","TAttLineEditor", this, "DoLiveAlpha(Int_t)");
   fAlphaField->Connect("ReturnPressed()","TAttLineEditor", this, "DoAlphaField()");
   fAlpha->Connect("Pressed()","TAttLineEditor", this, "GetCurAlpha()");

   fInit = kFALSE;
}

//______________________________________________________________________________
void TAttLineEditor::SetModel(TObject* obj)
{
   // Pick up the used line attributes.

   TAttLine *attline = dynamic_cast<TAttLine*>(obj);
   if (!attline) return;

   fAttLine = attline;
   fAvoidSignal = kTRUE;

   fStyleCombo->Select(fAttLine->GetLineStyle());

   if (obj->InheritsFrom(TGraph::Class())) {
      fWidthCombo->Select(TMath::Abs(fAttLine->GetLineWidth()%100));
   } else {
      fWidthCombo->Select(fAttLine->GetLineWidth());
   }

   Color_t c = fAttLine->GetLineColor();
   Pixel_t p = TColor::Number2Pixel(c);
   fColorSelect->SetColor(p);

   if (fInit) ConnectSignals2Slots();

   fAvoidSignal = kFALSE;

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

//______________________________________________________________________________
void TAttLineEditor::DoLineColor(Pixel_t color)
{
   // Slot connected to the line color.

   if (fAvoidSignal) return;
   fAttLine->SetLineColor(TColor::GetColor(color));

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

   Update();
}


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

   TColor *color = (TColor *)p;

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

   Update();
}

//______________________________________________________________________________
void TAttLineEditor::DoLineStyle(Int_t style)
{
   // Slot connected to the line style.

   if (fAvoidSignal) return;
   fAttLine->SetLineStyle(style);
   Update();
}


//______________________________________________________________________________
void TAttLineEditor::DoLineWidth(Int_t width)
{
   // Slot connected to the line width.

   if (fAvoidSignal) return;
   if (dynamic_cast<TGraph*>(fAttLine)) {
      Int_t graphLineWidth = 100*Int_t(fAttLine->GetLineWidth()/100);
      if (graphLineWidth >= 0) {
         fAttLine->SetLineWidth(graphLineWidth+width);
      } else {
         fAttLine->SetLineWidth(-(TMath::Abs(graphLineWidth)+width));
      }
   } else {
      fAttLine->SetLineWidth(width);
   }
   Update();
}

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

   if (fAvoidSignal) return;

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

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

   if (fAvoidSignal) return;

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

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

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

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

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

   if (fAvoidSignal) return;

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