Skip to content
Snippets Groups Projects
Commit c75b58c8 authored by Sergey Linev's avatar Sergey Linev
Browse files

Introduce TWebControlBar class

It is web-based implementation class for TControlBar
Should be used like TWebCanvas for TCanvas
parent c75862ec
Branches
Tags
No related merge requests found
......@@ -147,6 +147,15 @@ TContextMenuImp *TGuiFactory::CreateContextMenuImp(TContextMenu *c, const char *
TControlBarImp *TGuiFactory::CreateControlBarImp(TControlBar *c, const char *title)
{
if (gROOT->IsWebDisplay()) {
auto ph = gROOT->GetPluginManager()->FindHandler("TControlBarImp", "TWebControlBar");
if (ph && ph->LoadPlugin() != -1) {
auto imp = (TControlBarImp *) ph->ExecPlugin(4, c, title, 0, 0);
if (imp) return imp;
}
}
return new TControlBarImp(c, title);
}
......@@ -155,6 +164,15 @@ TControlBarImp *TGuiFactory::CreateControlBarImp(TControlBar *c, const char *tit
TControlBarImp *TGuiFactory::CreateControlBarImp(TControlBar *c, const char *title, Int_t x, Int_t y)
{
if (gROOT->IsWebDisplay()) {
auto ph = gROOT->GetPluginManager()->FindHandler("TControlBarImp", "TWebControlBar");
if (ph && ph->LoadPlugin() != -1) {
auto imp = (TControlBarImp *) ph->ExecPlugin(4, c, title, x, y);
if (imp) return imp;
}
}
return new TControlBarImp(c, title, x, y);
}
......
void P010_TWebControlBar()
{
gPluginMgr->AddHandler("TControlBarImp", "TWebControlBar", "TWebControlBar",
"WebGui6", "NewControlBar(TControlBar *, const char *, Int_t, Int_t)");
}
......@@ -82,6 +82,7 @@ will return the name of the last clicked button.
#include "TGuiFactory.h"
#include "TList.h"
#include "TStyle.h"
#include "TROOT.h"
ClassImp(TControlBar);
......@@ -210,10 +211,12 @@ void TControlBar::Initialize(Int_t x, Int_t y)
if (gApplication)
gApplication->InitializeGraphics();
auto factory = gROOT->IsWebDisplay() ? gBatchGuiFactory : gGuiFactory;
if (x == -999) {
fControlBarImp = gGuiFactory->CreateControlBarImp( this, GetName() );
fControlBarImp = factory->CreateControlBarImp( this, GetName() );
} else {
fControlBarImp = gGuiFactory->CreateControlBarImp( this, GetName(), x, y );
fControlBarImp = factory->CreateControlBarImp( this, GetName(), x, y );
}
fButtons = new TList();
......
......@@ -11,6 +11,7 @@
ROOT_STANDARD_LIBRARY_PACKAGE(WebGui6
HEADERS
TWebCanvas.h
TWebControlBar.h
TWebMenuItem.h
TWebPadOptions.h
TWebPadPainter.h
......@@ -19,6 +20,7 @@ ROOT_STANDARD_LIBRARY_PACKAGE(WebGui6
TWebSnapshot.h
SOURCES
src/TWebCanvas.cxx
src/TWebControlBar.cxx
src/TWebMenuItem.cxx
src/TWebPadPainter.cxx
src/TWebPainting.cxx
......
......@@ -33,4 +33,6 @@
#pragma link C++ class TWebCanvas+;
#pragma link C++ class TWebControlBar+;
#endif
// Author: Sergey Linev, GSI 15/12/2022
/*************************************************************************
* Copyright (C) 1995-2022, Rene Brun and Fons Rademakers. *
* All rights reserved. *
* *
* For the licensing terms see $ROOTSYS/LICENSE. *
* For the list of contributors see $ROOTSYS/README/CREDITS. *
*************************************************************************/
#ifndef ROOT_TWebControlBar
#define ROOT_TWebControlBar
#include "TControlBarImp.h"
#include <ROOT/RWebWindow.hxx>
class TWebControlBar : public TControlBarImp {
protected:
std::shared_ptr<ROOT::Experimental::RWebWindow> fWindow; ///!< configured display
void SendInitMsg(unsigned connid);
Bool_t ProcessData(unsigned connid, const std::string &arg);
public:
TWebControlBar(TControlBar *bar, const char *title, Int_t x, Int_t y);
virtual ~TWebControlBar() = default;
void Create() override { }
void Hide() override;
void Show() override;
void SetFont(const char * /*fontName*/) override { }
void SetTextColor(const char * /*colorName*/) override { }
void SetButtonState(const char * /*label*/, Int_t /*state*/) override { }
void SetButtonWidth(UInt_t /*width*/) override { }
static TControlBarImp *NewControlBar(TControlBar *bar, const char *title, Int_t x, Int_t y);
ClassDefOverride(TWebControlBar, 0) // Web-based implementation for TControlBarImp
};
#endif
// Author: Sergey Linev, GSI 15/12/2022
/*************************************************************************
* Copyright (C) 1995-2022, Rene Brun and Fons Rademakers. *
* All rights reserved. *
* *
* For the licensing terms see $ROOTSYS/LICENSE. *
* For the list of contributors see $ROOTSYS/README/CREDITS. *
*************************************************************************/
#include "TWebControlBar.h"
#include "TROOT.h"
/** \class TWebControlBar
\ingroup webgui6
Web-based implementation for TControlBar class
*/
using namespace std::string_literals;
////////////////////////////////////////////////////////////////////////////////
/// Constructor
TWebControlBar::TWebControlBar(TControlBar *bar, const char *title, Int_t x, Int_t y)
: TControlBarImp(bar, title, x, y)
{
}
//////////////////////////////////////////////////////////////////////////////////////////////////
/// Send initial message with buttons configuration
void TWebControlBar::SendInitMsg(unsigned connid)
{
if (!fWindow)
return;
std::string buf = "INIT";
if (!buf.empty())
fWindow->Send(connid, buf);
}
//////////////////////////////////////////////////////////////////////////////////////////
/// Handle data from web browser
/// Returns kFALSE if message was not processed
Bool_t TWebControlBar::ProcessData(unsigned connid, const std::string &arg)
{
if (arg.empty())
return kTRUE;
printf("Get msg %s from conn %u\n", arg.c_str(), connid);
return kTRUE;
}
//////////////////////////////////////////////////////////////////////////////////////////
/// Hide control bar
void TWebControlBar::Hide()
{
if (fWindow)
fWindow->CloseConnections();
}
//////////////////////////////////////////////////////////////////////////////////////////
/// Show canvas in browser window
void TWebControlBar::Show()
{
if (gROOT->IsWebDisplayBatch())
return;
if (!fWindow) {
fWindow = ROOT::Experimental::RWebWindow::Create();
fWindow->SetConnLimit(1); // configure connections limit
fWindow->SetDefaultPage("file:rootui5sys/canv/ctrlbar.html");
fWindow->SetCallBacks(
// connection
[this](unsigned connid) {
SendInitMsg(connid);
},
// data
[this](unsigned connid, const std::string &arg) {
ProcessData(connid, arg);
},
// disconnect
[this](unsigned) {
});
}
ROOT::Experimental::RWebDisplayArgs args;
args.SetWidgetKind("TControlBar");
fWindow->Show(args);
}
//////////////////////////////////////////////////////////////////////////////////////////////////
/// Static method to create TWebControlBar instance
/// Used by plugin manager
TControlBarImp *TWebControlBar::NewControlBar(TControlBar *bar, const char *title, Int_t x, Int_t y)
{
return new TWebControlBar(bar, title, x, y);
}
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Control bar</title>
</head>
<style>
body {
margin: 2px;
}
.btn-group button {
background-color: #4CAF50; /* Green background */
border: 1px solid green; /* Green border */
color: white; /* White text */
padding: 4px 4px; /* Some padding */
cursor: pointer; /* Pointer/hand icon */
width: 100%; /* Set a width if needed */
display: block; /* Make the buttons appear below each other */
}
.btn-group button:not(:last-child) {
border-bottom: none; /* Prevent double borders */
}
/* Add a background color on hover */
.btn-group button:hover {
background-color: #3e8e41;
}
</style>
<body>
<div class="btn-group" id="btns"></div>
</body>
<script type="module">
import { connectWebWindow } from './jsrootsys/modules/webwindow.mjs';
let conn_handle = null;
function sendMsg(txt) {
if (conn_handle)
conn_handle.send(txt);
}
function addButton(text, exec, title) {
let btn = document.createElement("button");
btn.onclick = sendMsg.bind(null, exec + ";");
btn.title = title;
btn.innerHTML = text;
document.getElementById("btns").appendChild(btn);
}
// use code from geodemo.C
addButton("How to run ","help()","Instructions for running this macro");
addButton("Arb8 ","arb8()","An arbitrary polyhedron defined by vertices (max 8) sitting on 2 parallel planes");
addButton("Box ","box()","A box shape.");
addButton("Composite ","composite()","A composite shape");
addButton("Cone ","cone()","A conical tube");
addButton("Cone segment","coneseg()","A conical segment");
addButton("Cut tube ","ctub()","A cut tube segment");
addButton("Elliptical tube","eltu()","An elliptical tube");
addButton("Extruded poly","xtru()","A general polygone extrusion");
addButton("Hyperboloid ","hype()","A hyperboloid");
addButton("Paraboloid ","parab()","A paraboloid");
addButton("Polycone ","pcon()","A polycone shape");
addButton("Polygone ","pgon()","A polygone");
addButton("Parallelepiped","para()","A parallelepiped shape");
addButton("Sphere ","sphere()","A spherical sector");
addButton("Trd1 ","trd1()","A trapezoid with dX varying with Z");
addButton("Trd2 ","trd2()","A trapezoid with both dX and dY varying with Z");
addButton("Trapezoid ","trap()","A general trapezoid");
addButton("Tessellated","tessellated()","A tessellated shape");
addButton("Torus ","torus()","A toroidal segment");
addButton("Tube ","tube()","A tube with inner and outer radius");
addButton("Tube segment","tubeseg()","A tube segment");
addButton("Twisted trap","gtra()","A twisted trapezoid");
addButton("Aligned (ideal)","ideal()","An ideal (un-aligned) geometry");
addButton("Un-aligned","align()","Some alignment operation");
// addButton("RAY-TRACE ON/OFF","raytrace()","Toggle ray-tracing mode");
addButton("COMMENTS ON/OFF","gcomments()","Toggle explanations pad ON/OFF");
addButton("AXES ON/OFF","axes()","Toggle axes ON/OFF");
addButton("AUTOROTATE ON/OFF","autorotate()","Toggle autorotation ON/OFF");
addButton("Quit","quit()","Quit ROOT seesion");
connectWebWindow({
receiver: {
// method called when connection to server is established
onWebsocketOpened(handle) {
conn_handle = handle;
},
onWebsocketMessage(msg) {
console.log('get msg', msg);
},
// method called when connection is gone
onWebsocketClosed(handle) {
conn_handle = null;
// when connection closed, close panel as well
if (window) window.close();
}
}
});
</script>
</html>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment