Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TStylePreview.cxx
Go to the documentation of this file.
1// @(#)root/ged:$Id$
2// Author: Denis Favre-Miville 08/09/05
3
4/*************************************************************************
5 * Copyright (C) 1995-2004, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12
13/** \class TStylePreview
14\ingroup ged
15
16This class may be used to preview the result of applying a style
17 to a canvas. The result is shown on a clone of the object,
18 in a different shown over the initial canvas.
19
20*/
21
22
23#include "TStylePreview.h"
24#include "TStyleManager.h"
25
26#include <TCanvas.h>
27#include <TRootEmbeddedCanvas.h>
28#include <TStyle.h>
29#include <TROOT.h>
30
32
33////////////////////////////////////////////////////////////////////////////////
34/// Constructor. Create a new window and draw a clone of
35/// currentPad->GetCanvas() in it, using the style 'style'.
36/// Thanks to that method, one can have a preview of any
37/// style with any object.
38
40 TVirtualPad *currentPad)
42{
43 fPad = 0;
44
45 // Create the main window.
46 SetWindowName("Style Manager's Preview");
49
50 // Create the trash lists to have an effective deletion of every object.
51 fTrashListLayout = new TList();
52
53 // Create the layouts and add them to the layout trash list.
55 fTrashListLayout->Add(layoutXY);
56
57 // Create a canvas for the preview.
58 fEcan = new TRootEmbeddedCanvas("TSMPreviewCanvas", this, 10, 10);
59 AddFrame(fEcan, layoutXY);
60
61 // Draw the preview.
62 Update(style, currentPad);
63
64 // Map main frame.
66
67 // No modifications allowed in the preview.
70}
71
72////////////////////////////////////////////////////////////////////////////////
73/// Destructor.
74
76{
77 // Delete all the widgets created in this class.
78 delete fEcan;
79
80 // Delete all the layouts.
81 TObject *obj1;
82 TObject *obj2;
83 obj1 = fTrashListLayout->First();
84 while (obj1) {
85 obj2 = fTrashListLayout->After(obj1);
87 delete obj1;
88 obj1 = obj2;
89 }
90 delete fTrashListLayout;
91}
92
93////////////////////////////////////////////////////////////////////////////////
94/// Update the preview with possibly another style and
95/// another object than previously.
96
98{
99 TCanvas *c;
100 if (pad != fPad) {
101 delete fEcan->GetCanvas();
102 fEcan->AdoptCanvas(new TCanvas("TSMPreviewCanvas", 10, 10,
104 c = fEcan->GetCanvas();
106 if (pad->GetCanvas())
107 pad->GetCanvas()->DrawClonePad();
108 gROOT->SetSelectedPad(pad);
109 fPad = pad;
110 }
111
112 // Apply the 'style' to the clone of 'pad'.
113 c = fEcan->GetCanvas();
114 TStyle *tmpStyle = gStyle;
115 gStyle = style;
117 gStyle = tmpStyle;
118 c->Modified();
119 c->Update();
120}
121
122////////////////////////////////////////////////////////////////////////////////
123/// Initialize the layout algorithm.
124
126{
128 TCanvas *c = fPad->GetCanvas();
129 if (c) {
130 UInt_t w = c->GetWw() + 4; //4 pixels of borders
131 UInt_t h = c->GetWh() + 4; //4 pixels of borders
132 UInt_t x = (UInt_t) c->GetWindowTopX() + 60;
133 UInt_t y = (UInt_t) c->GetWindowTopY() + 100;
134
135 MoveResize(x, y, w, h);
136 SetWMPosition(x, y);
137 }
138 MapWindow();
139}
140
141////////////////////////////////////////////////////////////////////////////////
142/// Return pointer to the selected canvas.
143
145{
146 return fEcan->GetCanvas();
147}
#define c(i)
Definition RSha256.hxx:101
#define h(i)
Definition RSha256.hxx:106
unsigned int UInt_t
Definition RtypesCore.h:46
constexpr Bool_t kFALSE
Definition RtypesCore.h:101
#define ClassImp(name)
Definition Rtypes.h:377
@ kNoCleanup
Definition TGFrame.h:40
@ kLHintsExpandY
Definition TGLayout.h:31
@ kLHintsExpandX
Definition TGLayout.h:30
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void SetWMPosition
Option_t Option_t style
@ kNoContextMenu
Definition TObject.h:373
#define gROOT
Definition TROOT.h:406
R__EXTERN TStyle * gStyle
Definition TStyle.h:433
The Canvas class.
Definition TCanvas.h:23
void SetSelectedPad(TPad *pad)
Definition TCanvas.h:210
virtual TObject * DrawClonePad()
Draw a clone of this canvas into the current pad In an interactive session, select the destination/cu...
Definition TCanvas.cxx:921
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=nullptr)
Add frame to the composite frame using the specified layout hints.
Definition TGFrame.cxx:1117
void MapSubwindows() override
Map all sub windows that are part of the composite frame.
Definition TGFrame.cxx:1164
void SetCleanup(Int_t mode=kLocalCleanup) override
Turn on automatic cleanup of child frames in dtor.
Definition TGFrame.cxx:1072
void MoveResize(Int_t x, Int_t y, UInt_t w=0, UInt_t h=0) override
Move and/or resize the frame.
Definition TGFrame.cxx:629
void MapWindow() override
map window
Definition TGFrame.h:204
This class describes layout hints used by the layout classes.
Definition TGLayout.h:50
void DontCallClose()
Typically call this method in the slot connected to the CloseWindow() signal to prevent the calling o...
Definition TGFrame.cxx:1780
void SetWindowName(const char *name=nullptr) override
Set window name. This is typically done via the window manager.
Definition TGFrame.cxx:1788
Defines transient windows that typically are used for dialogs windows.
Definition TGFrame.h:498
ROOT GUI Window base class.
Definition TGWindow.h:23
A doubly linked list.
Definition TList.h:38
TObject * After(const TObject *obj) const override
Returns the object after object obj.
Definition TList.cxx:328
void Add(TObject *obj) override
Definition TList.h:83
TObject * Remove(TObject *obj) override
Remove object from the list.
Definition TList.cxx:820
TObject * First() const override
Return the first object in the list. Returns 0 when list is empty.
Definition TList.cxx:657
Mother of all ROOT objects.
Definition TObject.h:41
virtual void UseCurrentStyle()
Set current style settings in this object This function is called when either TCanvas::UseCurrentStyl...
Definition TObject.cxx:801
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition TObject.cxx:780
void SetEditable(Bool_t mode=kTRUE) override
Set pad editable yes/no If a pad is not editable:
Definition TPad.cxx:5942
This class creates a TGCanvas in which a TCanvas is created.
void AdoptCanvas(TCanvas *c)
Canvas c is adopted from this embedded canvas.
TCanvas * GetCanvas() const
Int_t GetCanvasWindowId() const
This class may be used to preview the result of applying a style to a canvas.
TStylePreview(const TGWindow *p, TStyle *style, TVirtualPad *currentPad)
Constructor.
TCanvas * GetMainCanvas()
Return pointer to the selected canvas.
void MapTheWindow()
Initialize the layout algorithm.
TVirtualPad * fPad
original pad previewed
void Update(TStyle *style, TVirtualPad *pad)
Update the preview with possibly another style and another object than previously.
~TStylePreview() override
Destructor.
TList * fTrashListLayout
to avoid memory leak
TRootEmbeddedCanvas * fEcan
canvas for preview
TStyle objects may be created to define special styles.
Definition TStyle.h:29
TVirtualPad is an abstract base class for the Pad and Canvas classes.
Definition TVirtualPad.h:51
virtual TCanvas * GetCanvas() const =0
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17