g4tools  5.4.0
Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
tools::Xt::sg_viewer Class Reference
Inheritance diagram for tools::Xt::sg_viewer:
Inheritance graph
[legend]
Collaboration diagram for tools::Xt::sg_viewer:
Collaboration graph
[legend]

Public Member Functions

 sg_viewer (session &a_session, int a_x=0, int a_y=0, unsigned int a_width=500, unsigned int a_height=500, const std::string &a_win_title="")
 
virtual ~sg_viewer ()
 
bool has_window () const
 
bool show ()
 
void win_render ()
 
void set_device_interactor (tools::sg::device_interactor *a_interactor)
 
- Public Member Functions inherited from tools::sg::GL_viewer
void render ()
 
 GL_viewer (std::ostream &a_out, unsigned int a_width, unsigned int a_height)
 
virtual ~GL_viewer ()
 
 GL_viewer (const GL_viewer &a_from)
 
GL_vieweroperator= (const GL_viewer &a_from)
 
- Public Member Functions inherited from tools::sg::viewer
virtual void * cast (const std::string &a_class) const
 
virtual void set_size (unsigned int a_w, unsigned int a_h)
 
virtual bool set_cursor_shape (cursor_shape)
 
 viewer (std::ostream &a_out, unsigned int a_width, unsigned int a_height)
 
virtual ~viewer ()
 
 viewer (const viewer &a_from)
 
vieweroperator= (const viewer &a_from)
 
bool set_default_cursor_shape ()
 
groupsg ()
 
const groupsg () const
 
unsigned int width () const
 
unsigned int height () const
 
bool screen2aspect (int a_x, int a_y, float &a_wx, float &a_wy) const
 
void set_clear_color (float a_r, float a_g, float a_b, float a_a=1)
 
void set_clear_color (const colorf &a_color)
 
void get_clear_color (float &a_r, float &a_g, float &a_b, float &a_a)
 
const colorfbackground () const
 
std::ostream & out () const
 
const std::string & out_dir () const
 
void set_produce_out_jpeg (bool a_value)
 
bool produce_out_jpeg () const
 
void set_produce_out_png (bool a_value)
 
bool produce_out_png () const
 
void set_produce_out_file (const std::string &a_file)
 
const std::string & produce_out_file () const
 
void set_produce_out_bpp (unsigned int a_bpp)
 
unsigned int produce_out_bpp () const
 

Protected Member Functions

 sg_viewer (const sg_viewer &a_from)
 
sg_vieweroperator= (const sg_viewer &a_from)
 
tools::key_code convert (KeySym a_key)
 

Static Protected Member Functions

static void paint_cbk (Widget a_widget, XtPointer a_tag, XtPointer)
 
static void event_cbk (Widget, XtPointer a_tag, XtPointer a_data)
 
static void destroy_shell_callback (Widget, XtPointer a_tag, XtPointer)
 

Protected Attributes

sessionm_session
 
Widget m_shell
 
Widget m_glarea
 
tools::sg::device_interactorm_interactor
 
- Protected Attributes inherited from tools::sg::GL_viewer
GL_manager m_gl_mgr
 
- Protected Attributes inherited from tools::sg::viewer
std::ostream & m_out
 
colorf m_clear_color
 
unsigned int m_ww
 
unsigned int m_wh
 
group m_sg
 
std::string m_out_dir
 
bool m_use_gsto
 
bool m_produce_out_jpeg
 
bool m_produce_out_png
 
std::string m_produce_out_file
 
unsigned int m_produce_out_bpp
 

Detailed Description

Definition at line 24 of file sg_viewer.

Constructor & Destructor Documentation

◆ sg_viewer() [1/2]

tools::Xt::sg_viewer::sg_viewer ( session a_session,
int  a_x = 0,
int  a_y = 0,
unsigned int  a_width = 500,
unsigned int  a_height = 500,
const std::string &  a_win_title = "" 
)
inline

Definition at line 27 of file sg_viewer.

31  :parent(a_session.out(),a_width,a_height)
32  ,m_session(a_session)
33  ,m_shell(0)
34  ,m_glarea(0)
35  ,m_interactor(0)
36  {
37  Widget app_widget = a_session.get_app_widget();
38  if(!app_widget) return;
39 
40  std::string sgeom;
41  tools::numas(a_width,sgeom);
42  sgeom += "x";
43  tools::numas(a_height,sgeom);
44  sgeom += "+";
45  tools::numas(a_x,sgeom);
46  sgeom += "+";
47  tools::numas(a_y,sgeom);
48 
49  Arg args[2];
50  XtSetArg(args[0],XtNgeometry,XtNewString(sgeom.c_str()));
51  XtSetArg(args[1],XtNborderWidth,0);
52 
53  m_shell = ::XtAppCreateShell((char*)a_win_title.c_str(),
54  (char*)"sg_viewer_shell",
55  topLevelShellWidgetClass,XtDisplay(app_widget),args,2);
56  ::XtSetMappedWhenManaged(m_shell,True);
57 
58  m_glarea = ::XtCreateManagedWidget("glarea",OpenGLArea::widget_class(),m_shell,args,0);
59  ::XtAddCallback(m_glarea,XoNpaintCallback,paint_cbk,(XtPointer)this);
60  ::XtAddCallback(m_glarea,XoNeventCallback,event_cbk,(XtPointer)this);
61 
62  ::XtAddCallback(m_shell,XtNdestroyCallback,destroy_shell_callback,(XtPointer)this);
63 
64  ::XtRealizeWidget(m_shell);
65 
66  //Atom WM_DELETE_WINDOW_atom = ::XInternAtom(XtDisplay(m_shell),"WM_DELETE_WINDOW",False);
67  //::XSetWMProtocols(XtDisplay(m_shell),XtWindow(m_shell),&WM_DELETE_WINDOW_atom,1);
68  }

◆ ~sg_viewer()

virtual tools::Xt::sg_viewer::~sg_viewer ( )
inlinevirtual

Definition at line 69 of file sg_viewer.

69  {
70  if(m_shell) {
71  ::XtRemoveCallback(m_glarea,XoNpaintCallback,paint_cbk,(XtPointer)this);
72  ::XtRemoveCallback(m_shell,XtNdestroyCallback,destroy_shell_callback,(XtPointer)this);
73  ::XtDestroyWidget(m_shell);
74  }
75  m_shell = 0;
76  m_glarea = 0;
77  }

◆ sg_viewer() [2/2]

tools::Xt::sg_viewer::sg_viewer ( const sg_viewer a_from)
inlineprotected

Definition at line 79 of file sg_viewer.

80  :parent(a_from)
81  ,m_session(a_from.m_session)
82  ,m_shell(0)
83  ,m_glarea(0)
84  ,m_interactor(0)
85  {}

Member Function Documentation

◆ convert()

tools::key_code tools::Xt::sg_viewer::convert ( KeySym  a_key)
inlineprotected

Definition at line 168 of file sg_viewer.

168  {
169  if(a_key==XK_Shift_L) return tools::sg::key_shift();
170  if(a_key==XK_Shift_R) return tools::sg::key_shift();
171  return a_key;
172  }

◆ destroy_shell_callback()

static void tools::Xt::sg_viewer::destroy_shell_callback ( Widget  ,
XtPointer  a_tag,
XtPointer   
)
inlinestaticprotected

Definition at line 162 of file sg_viewer.

162  {
163  sg_viewer* _this = (sg_viewer*)a_tag;
164  _this->m_shell = 0;
165  _this->m_glarea = 0;
166  }

◆ event_cbk()

static void tools::Xt::sg_viewer::event_cbk ( Widget  ,
XtPointer  a_tag,
XtPointer  a_data 
)
inlinestaticprotected

Definition at line 122 of file sg_viewer.

122  {
123  sg_viewer* _this = (sg_viewer*)a_tag;
124  if(!_this->m_interactor) return;
125  XoAnyCallbackStruct* data = (XoAnyCallbackStruct*)a_data;
126  XEvent* xevent = data->event;
127  switch( xevent->type ) {
128  case KeyPress:{
129  KeySym key_sym;
130  ::XLookupString(&(xevent->xkey),NULL,0,&key_sym,NULL);
131  tools::sg::key_down_event event(_this->convert(key_sym));
132  _this->m_interactor->key_press(event);
133  }return;
134  case KeyRelease:{
135  KeySym key_sym;
136  ::XLookupString(&(xevent->xkey),NULL,0,&key_sym,NULL);
137  tools::sg::key_up_event event(_this->convert(key_sym));
138  _this->m_interactor->key_release(event);
139  }return;
140  case ButtonPress:{
141  if(xevent->xbutton.button==Button4) { //4=wheel down, or move down double touch on trackpad = zoom in.
142  tools::sg::wheel_rotate_event event(8); //8=cooking.
143  _this->m_interactor->wheel_rotate(event);
144  } else if(xevent->xbutton.button==Button5) { //5=wheel up, or move up double touch on trackpad = zoom out.
145  tools::sg::wheel_rotate_event event(-8); //8=cooking.
146  _this->m_interactor->wheel_rotate(event);
147  } else {
148  tools::sg::mouse_down_event event(xevent->xbutton.x,xevent->xbutton.y);
149  _this->m_interactor->mouse_press(event);
150  }
151  }return;
152  case ButtonRelease:{
153  tools::sg::mouse_up_event event(xevent->xbutton.x,xevent->xbutton.y);
154  _this->m_interactor->mouse_release(event);
155  }return;
156  case MotionNotify:{
157  tools::sg::mouse_move_event event(xevent->xmotion.x,xevent->xmotion.y,0,0,false);
158  _this->m_interactor->mouse_move(event);
159  }return;
160  default:return;}
161  }

◆ has_window()

bool tools::Xt::sg_viewer::has_window ( ) const
inline

Definition at line 91 of file sg_viewer.

91 {return m_glarea?true:false;}

◆ operator=()

sg_viewer& tools::Xt::sg_viewer::operator= ( const sg_viewer a_from)
inlineprotected

Definition at line 86 of file sg_viewer.

86  {
87  parent::operator=(a_from);
88  return *this;
89  }

◆ paint_cbk()

static void tools::Xt::sg_viewer::paint_cbk ( Widget  a_widget,
XtPointer  a_tag,
XtPointer   
)
inlinestaticprotected

Definition at line 114 of file sg_viewer.

114  {
115  unsigned int width = a_widget->core.width;
116  unsigned int height = a_widget->core.height;
117  //::printf("debug : tools::Xt::sg_viewer::paint_cbk : %d %d\n",width,height);
118  sg_viewer* _this = (sg_viewer*)a_tag;
119  _this->set_size(width,height);
120  _this->render();
121  }

◆ set_device_interactor()

void tools::Xt::sg_viewer::set_device_interactor ( tools::sg::device_interactor a_interactor)
inline

Definition at line 112 of file sg_viewer.

112 {m_interactor = a_interactor;} //we do not have ownership.

◆ show()

bool tools::Xt::sg_viewer::show ( )
inline

Definition at line 93 of file sg_viewer.

93  {
94  if(!m_shell) return false;
95  ::XtRealizeWidget(m_shell);
96  ::XtMapWidget(m_shell);
97  // Raise window :
98  if(XtIsWidget(m_shell) && XtIsRealized(m_shell) ) {
99  Display* display = XtDisplay(m_shell);
100  Atom atom = ::XInternAtom(display,"WM_DELETE_WINDOW",False);
101  ::XSetWMProtocols(display,XtWindow(m_shell),&atom,1);
102  ::XRaiseWindow(display,XtWindow(m_shell));
103  }
104  return true;
105  }

◆ win_render()

void tools::Xt::sg_viewer::win_render ( )
inline

Definition at line 107 of file sg_viewer.

107  {
109  }

Member Data Documentation

◆ m_glarea

Widget tools::Xt::sg_viewer::m_glarea
protected

Definition at line 176 of file sg_viewer.

◆ m_interactor

tools::sg::device_interactor* tools::Xt::sg_viewer::m_interactor
protected

Definition at line 177 of file sg_viewer.

◆ m_session

session& tools::Xt::sg_viewer::m_session
protected

Definition at line 174 of file sg_viewer.

◆ m_shell

Widget tools::Xt::sg_viewer::m_shell
protected

Definition at line 175 of file sg_viewer.


The documentation for this class was generated from the following file:
tools::Xt::sg_viewer::m_shell
Widget m_shell
Definition: sg_viewer:175
tools::Xt::sg_viewer::m_glarea
Widget m_glarea
Definition: sg_viewer:176
tools::sg::GL_viewer::operator=
GL_viewer & operator=(const GL_viewer &a_from)
Definition: GL_viewer:58
tools::sg::key_shift
key_code key_shift()
Definition: keys:12
tools::numas
bool numas(const T &a_value, std::string &a_s)
Definition: num2s:89
tools::sg::key_up_event
Definition: event:350
tools::Xt::sg_viewer::m_session
session & m_session
Definition: sg_viewer:174
tools::Xt::sg_viewer::destroy_shell_callback
static void destroy_shell_callback(Widget, XtPointer a_tag, XtPointer)
Definition: sg_viewer:162
tools::sg::key_down_event
Definition: event:312
tools::sg::mouse_up_event
Definition: event:150
tools::Xt::sg_viewer::m_interactor
tools::sg::device_interactor * m_interactor
Definition: sg_viewer:177
tools::Xt::sg_viewer::paint_cbk
static void paint_cbk(Widget a_widget, XtPointer a_tag, XtPointer)
Definition: sg_viewer:114
tools::sg::mouse_down_event
Definition: event:107
XoNpaintCallback
#define XoNpaintCallback
Definition: OpenGLArea:34
tools::sg::mouse_move_event
Definition: event:193
tools::sg::viewer::height
unsigned int height() const
Definition: viewer:98
tools::sg::viewer::width
unsigned int width() const
Definition: viewer:97
tools::Xt::OpenGLArea::paint
static void paint(Widget a_this)
Definition: OpenGLArea:75
tools::Xt::sg_viewer::sg_viewer
sg_viewer(session &a_session, int a_x=0, int a_y=0, unsigned int a_width=500, unsigned int a_height=500, const std::string &a_win_title="")
Definition: sg_viewer:27
tools::sg::wheel_rotate_event
Definition: event:388
tools::Xt::OpenGLArea::widget_class
static WidgetClass widget_class()
Definition: OpenGLArea:416
tools::Xt::sg_viewer::event_cbk
static void event_cbk(Widget, XtPointer a_tag, XtPointer a_data)
Definition: sg_viewer:122
XoNeventCallback
#define XoNeventCallback
Definition: OpenGLArea:35