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
31
32////////////////////////////////////////////////////////////////////////////////
33/// Constructor. Create a new window and draw a clone of
34/// currentPad->GetCanvas() in it, using the style 'style'.
35/// Thanks to that method, one can have a preview of any
36/// style with any object.
37
41{
42 fPad = 0;
43
44 // Create the main window.
45 SetWindowName("Style Manager's Preview");
48
49 // Create the trash lists to have an effective deletion of every object.
50 fTrashListLayout = new TList();
51
52 // Create the layouts and add them to the layout trash list.
55
56 // Create a canvas for the preview.
57 fEcan = new TRootEmbeddedCanvas("TSMPreviewCanvas", this, 10, 10);
59
60 // Draw the preview.
62
63 // Map main frame.
65
66 // No modifications allowed in the preview.
69}
70
71////////////////////////////////////////////////////////////////////////////////
72/// Destructor.
73
75{
76 // Delete all the widgets created in this class.
77 delete fEcan;
78
79 // Delete all the layouts.
83 while (obj1) {
86 delete obj1;
87 obj1 = obj2;
88 }
89 delete fTrashListLayout;
90}
91
92////////////////////////////////////////////////////////////////////////////////
93/// Update the preview with possibly another style and
94/// another object than previously.
95
97{
98 TCanvas *c;
99 if (pad != fPad) {
100 delete fEcan->GetCanvas();
101 fEcan->AdoptCanvas(new TCanvas("TSMPreviewCanvas", 10, 10,
103 c = fEcan->GetCanvas();
105 if (pad->GetCanvas())
106 pad->GetCanvas()->DrawClonePad();
107 gROOT->SetSelectedPad(pad);
108 fPad = pad;
109 }
110
111 // Apply the 'style' to the clone of 'pad'.
112 c = fEcan->GetCanvas();
114 gStyle = style;
117 c->Modified();
118 c->Update();
119}
120
121////////////////////////////////////////////////////////////////////////////////
122/// Initialize the layout algorithm.
123
125{
127 TCanvas *c = fPad->GetCanvas();
128 if (c) {
129 UInt_t w = c->GetWw() + 4; //4 pixels of borders
130 UInt_t h = c->GetWh() + 4; //4 pixels of borders
131 UInt_t x = (UInt_t) c->GetWindowTopX() + 60;
132 UInt_t y = (UInt_t) c->GetWindowTopY() + 100;
133
134 MoveResize(x, y, w, h);
135 SetWMPosition(x, y);
136 }
137 MapWindow();
138}
139
140////////////////////////////////////////////////////////////////////////////////
141/// Return pointer to the selected canvas.
142
#define c(i)
Definition RSha256.hxx:101
#define h(i)
Definition RSha256.hxx:106
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int)
Definition RtypesCore.h:60
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
@ 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:376
#define gROOT
Definition TROOT.h:411
R__EXTERN TStyle * gStyle
Definition TStyle.h:442
The Canvas class.
Definition TCanvas.h:23
void SetSelectedPad(TPad *pad)
Definition TCanvas.h:210
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=nullptr)
Add frame to the composite frame using the specified layout hints.
Definition TGFrame.cxx:1109
void MapSubwindows() override
Map all sub windows that are part of the composite frame.
Definition TGFrame.cxx:1156
void SetCleanup(Int_t mode=kLocalCleanup) override
Turn on automatic cleanup of child frames in dtor.
Definition TGFrame.cxx:1064
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:621
void MapWindow() override
map window
Definition TGFrame.h:206
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:1772
void SetWindowName(const char *name=nullptr) override
Set window name. This is typically done via the window manager.
Definition TGFrame.cxx:1780
Defines transient windows that typically are used for dialogs windows.
Definition TGFrame.h:500
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:327
void Add(TObject *obj) override
Definition TList.h:81
TObject * Remove(TObject *obj) override
Remove object from the list.
Definition TList.cxx:819
TObject * First() const override
Return the first object in the list. Returns 0 when list is empty.
Definition TList.cxx:656
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:885
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition TObject.cxx:864
void SetEditable(Bool_t mode=kTRUE) override
Set pad editable yes/no If a pad is not editable:
Definition TPad.cxx:6126
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
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