WorldMap.C: This macro shows how to use a TGImageMap class. | Graphics User Interface | buttonTest.C: This macro gives an example of how to set/change text button attributes. |
// // Author: Ilka Antcheva 1/12/2006 // This macro gives an example for changing text button labels anytime // the Start or Pause buttons are clicked. // To run it do either: // .x buttonChangelabel.C // .x buttonChangelabel.C++ #include <TGClient.h> #include <TGButton.h> #include <TGFrame.h> class MyMainFrame : public TGMainFrame { private: TGCompositeFrame *fCframe; TGTextButton *fStart, *fPause, *fExit; Bool_t start, pause; public: MyMainFrame(const TGWindow *p, UInt_t w, UInt_t h); virtual ~MyMainFrame(); // slots void ChangeStartLabel(); void ChangePauseLabel(); ClassDef(MyMainFrame, 0) }; void MyMainFrame::ChangeStartLabel() { // Slot connected to the Clicked() signal. // It will toggle labels "Start" and "Stop". fStart->SetState(kButtonDown); if (!start) { fStart->SetText("&Stop"); start = kTRUE; } else { fStart->SetText("&Start"); start = kFALSE; } fStart->SetState(kButtonUp); } void MyMainFrame::ChangePauseLabel() { // Slot connected to the Clicked() signal. // It will toggle labels "Resume" and "Pause". fPause->SetState(kButtonDown); if (!pause) { fPause->SetText("&Resume"); pause = kTRUE; } else { fPause->SetText("&Pause"); pause = kFALSE; } fPause->SetState(kButtonUp); } MyMainFrame::MyMainFrame(const TGWindow *p, UInt_t w, UInt_t h) : TGMainFrame(p, w, h) { // Create a horizontal frame containing buttons fCframe = new TGCompositeFrame(this, 170, 20, kHorizontalFrame|kFixedWidth); fStart = new TGTextButton(fCframe, "&Start"); fStart->Connect("Clicked()", "MyMainFrame", this, "ChangeStartLabel()"); fCframe->AddFrame(fStart, new TGLayoutHints(kLHintsTop | kLHintsExpandX, 3, 2, 2, 2)); fStart->SetToolTipText("Click to toggle the button label (Start/Stop)"); start = kFALSE; fPause = new TGTextButton(fCframe, "&Pause"); fPause->Connect("Clicked()", "MyMainFrame", this, "ChangePauseLabel()"); fPause->SetToolTipText("Click to toggle the button label (Pause/Resume)"); fCframe->AddFrame(fPause, new TGLayoutHints(kLHintsTop | kLHintsExpandX, 3, 2, 2, 2)); pause = kFALSE; AddFrame(fCframe, new TGLayoutHints(kLHintsCenterX, 2, 2, 5, 1)); fExit = new TGTextButton(this, "&Exit ","gApplication->Terminate(0)"); AddFrame(fExit, new TGLayoutHints(kLHintsTop | kLHintsExpandX,5,5,2,2)); SetWindowName("Change Labels"); MapSubwindows(); Resize(GetDefaultSize()); MapWindow(); } MyMainFrame::~MyMainFrame() { // Clean up all widgets, frames and layouthints that were used fCframe->Cleanup(); Cleanup(); } void buttonChangelabel() { // Popup the GUI... new MyMainFrame(gClient->GetRoot(), 350, 80); } buttonChangelabel.C:1 buttonChangelabel.C:2 buttonChangelabel.C:3 buttonChangelabel.C:4 buttonChangelabel.C:5 buttonChangelabel.C:6 buttonChangelabel.C:7 buttonChangelabel.C:8 buttonChangelabel.C:9 buttonChangelabel.C:10 buttonChangelabel.C:11 buttonChangelabel.C:12 buttonChangelabel.C:13 buttonChangelabel.C:14 buttonChangelabel.C:15 buttonChangelabel.C:16 buttonChangelabel.C:17 buttonChangelabel.C:18 buttonChangelabel.C:19 buttonChangelabel.C:20 buttonChangelabel.C:21 buttonChangelabel.C:22 buttonChangelabel.C:23 buttonChangelabel.C:24 buttonChangelabel.C:25 buttonChangelabel.C:26 buttonChangelabel.C:27 buttonChangelabel.C:28 buttonChangelabel.C:29 buttonChangelabel.C:30 buttonChangelabel.C:31 buttonChangelabel.C:32 buttonChangelabel.C:33 buttonChangelabel.C:34 buttonChangelabel.C:35 buttonChangelabel.C:36 buttonChangelabel.C:37 buttonChangelabel.C:38 buttonChangelabel.C:39 buttonChangelabel.C:40 buttonChangelabel.C:41 buttonChangelabel.C:42 buttonChangelabel.C:43 buttonChangelabel.C:44 buttonChangelabel.C:45 buttonChangelabel.C:46 buttonChangelabel.C:47 buttonChangelabel.C:48 buttonChangelabel.C:49 buttonChangelabel.C:50 buttonChangelabel.C:51 buttonChangelabel.C:52 buttonChangelabel.C:53 buttonChangelabel.C:54 buttonChangelabel.C:55 buttonChangelabel.C:56 buttonChangelabel.C:57 buttonChangelabel.C:58 buttonChangelabel.C:59 buttonChangelabel.C:60 buttonChangelabel.C:61 buttonChangelabel.C:62 buttonChangelabel.C:63 buttonChangelabel.C:64 buttonChangelabel.C:65 buttonChangelabel.C:66 buttonChangelabel.C:67 buttonChangelabel.C:68 buttonChangelabel.C:69 buttonChangelabel.C:70 buttonChangelabel.C:71 buttonChangelabel.C:72 buttonChangelabel.C:73 buttonChangelabel.C:74 buttonChangelabel.C:75 buttonChangelabel.C:76 buttonChangelabel.C:77 buttonChangelabel.C:78 buttonChangelabel.C:79 buttonChangelabel.C:80 buttonChangelabel.C:81 buttonChangelabel.C:82 buttonChangelabel.C:83 buttonChangelabel.C:84 buttonChangelabel.C:85 buttonChangelabel.C:86 buttonChangelabel.C:87 buttonChangelabel.C:88 buttonChangelabel.C:89 buttonChangelabel.C:90 buttonChangelabel.C:91 buttonChangelabel.C:92 buttonChangelabel.C:93 buttonChangelabel.C:94 buttonChangelabel.C:95 buttonChangelabel.C:96 buttonChangelabel.C:97 buttonChangelabel.C:98 buttonChangelabel.C:99 buttonChangelabel.C:100 buttonChangelabel.C:101 buttonChangelabel.C:102 buttonChangelabel.C:103 buttonChangelabel.C:104 buttonChangelabel.C:105 buttonChangelabel.C:106 buttonChangelabel.C:107 buttonChangelabel.C:108 buttonChangelabel.C:109 |
|