40 set_title(
"GTK4 drawing demo");
41 set_default_size(640, 400);
43 m_root.set_orientation(Gtk::Orientation::HORIZONTAL);
49 m_buttons.set_orientation(Gtk::Orientation::VERTICAL);
54 const char *btns[7] = {
"TLatex",
"TH1",
"TH2",
"TGraph",
"Toggle menu",
"Toggle toobar",
"Toggle statusbar"};
56 for (
int i = 0; i < 7; ++i) {
57 auto b = Gtk::make_managed<Gtk::Button>(btns[i]);
59 b->signal_clicked().connect([
this, i]() {
64 m_check.set_label(
"Update drawing");
67 m_check.signal_toggled().connect([
this]() {
68 bool is_checked =
m_check.get_active();
70 m_timer_conn = Glib::signal_timeout().connect([
this]() ->
bool {
81 auto spacer = Gtk::make_managed<Gtk::Box>();
82 spacer->set_vexpand(
true);
85 auto quit = Gtk::make_managed<Gtk::Button>(
"Quit");
86 quit->signal_clicked().connect([
this]() { close(); });
110 while (obj = iter()) {
118 if (
auto ltx =
dynamic_cast<TLatex *
>(obj))
120 ltx->SetTextAlign(12);
127 if (
auto h1 =
dynamic_cast<TH1 *
>(obj)) {
130 for (
int n = 0;
n < 300; ++
n) {
139 if (
auto h2 =
dynamic_cast<TH2 *
>(obj)) {
143 for (
int n = 0;
n < 300; ++
n) {
153 if (
auto gr =
dynamic_cast<TGraph *
>(obj)) {
154 for (
int i = 0; i < 100; ++i)
194 auto ltx =
new TLatex(0.5, 0.5,
"TLatex");
195 ltx->SetTextAlign(22);
196 ltx->SetTextSize(0.2);
203 auto h1 =
new TH1I(
"h1",
"Example of TH1I", 100, -5, 5);
210 auto h2 =
new TH2I(
"h2",
"Example of TH2I", 40, -5, 5, 40, -5, 5);
211 h2->SetDirectory(
nullptr);
233int main(
int argc,
char* argv[])
235 auto app = Gtk::Application::create(
"org.example.root_gtk4canv_demo");
236 return app->make_window_and_run<
MainWindow>(argc, argv);
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t index
R__EXTERN TRandom * gRandom
sigc::connection m_timer_conn
void fill_canvas_object()
void button_clicked(int index)
static TCanvas * EmbedGtk4Canvas(Gtk::Window *window, Gtk::Box &place, const char *name)
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
virtual void SetLineColor(Color_t lcolor)
Set the line color.
virtual void ShowMenuBar(Bool_t show=kTRUE)
void Clear(Option_t *option="") override
Remove all primitives from the canvas.
virtual void ToggleEventStatus()
Toggle event statusbar.
TCanvasImp * GetCanvasImp() const override
virtual void Resize(Option_t *option="")
Recompute canvas parameters following a X11 Resize.
void Update() override
Update canvas pad buffers.
virtual void ToggleToolBar()
Toggle toolbar.
A TGraph is an object made of two arrays X and Y with npoints each.
virtual void SetPoint(Int_t i, Double_t x, Double_t y)
Set x and y values for point number i.
void SetName(const char *name="") override
Set graph name.
void SetTitle(const char *title="") override
Change (i.e.
void Reset(Option_t *option="") override
Reset.
1-D histogram with an int per channel (see TH1 documentation)
TH1 is the base class of all histogram classes in ROOT.
virtual void SetDirectory(TDirectory *dir)
By default, when a histogram is created, it is added to the list of histogram objects in the current ...
void SetTitle(const char *title) override
Change/set the title.
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
2-D histogram with an int per channel (see TH1 documentation)
Service class for 2-D histogram classes.
To draw Mathematical Formula.
Mother of all ROOT objects.
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
TList * GetListOfPrimitives() const override
void Range(Double_t x1, Double_t y1, Double_t x2, Double_t y2) override
Set world coordinate system for the pad.
void Add(TObject *obj, Option_t *opt="", Bool_t modified=kTRUE) override
Add an object to list of primitives with specified draw option When.
virtual Double_t Gaus(Double_t mean=0, Double_t sigma=1)
Samples a random number from the standard Normal (Gaussian) Distribution with the given mean and sigm...
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
Double_t Sin(Double_t)
Returns the sine of an angle of x radians.