appkit  1.5.1
RoadNarrows Robotics Application Kit
rnr::Win Class Referenceabstract

RNR Win window abstract base class. More...

#include <Win.h>

Inheritance diagram for rnr::Win:
rnr::WinGtk

Public Member Functions

 Win (const std::string &strWinName, int nWidth, int nHeight, bool bDecorate=true)
 Windowing class initialization constructor. More...
 
virtual ~Win ()
 Destructor.
 
virtual const char * getGuiToolkitName ()
 Get GUI toolkit name. More...
 
virtual void setLookAndFeel (const std::string &strKey, const std::string &strVal)
 Set GUI look and feel value. More...
 
virtual std::string getLookAndFeel (const std::string &strKey)
 Get the GUI look and feel value. More...
 
virtual void show ()=0
 Show/refresh all gui widgets in window.
 
virtual void showCvImage (cv::Mat &img, uint_t uImgIndex=0)=0
 Show a OpenCv image on the workspace. More...
 
virtual void showPageRef (int nPageRef)=0
 Show page reference number. More...
 
virtual void showPageRef (const std::string &strPageRef)=0
 Show page reference string. More...
 
virtual void showStatus (const char *sFmt,...)=0
 Show status message. More...
 
virtual void clearStatus ()=0
 Clear status message.
 
virtual int waitKey (int delay)=0
 Wait for keypress or timeout. More...
 
virtual void waitMouse (int delay)=0
 Wait for timeout or registered mouse event. More...
 
virtual void wait (int delay)=0
 Wait for timeout. More...
 
virtual bool addImageButton (int nBttnId, AlignOp eAlign, const std::string &strIconPath, const std::string &strAltText, const std::string &strToolTip="")=0
 Add a button with an image to window button menu. More...
 
virtual bool addImageButton (int nBttnId, AlignOp eAlign, void *wBttnImg, const std::string &strAltText, const std::string &strToolTip="")=0
 Add a button with an image widget to window button menu. More...
 
virtual bool addLabelButton (int nBttnId, AlignOp eAlign, const std::string &strLabel, const std::string &strToolTip="")=0
 Add a button with a label to window button menu. More...
 
virtual bool replaceButtonImage (int nBttnId, const std::string &strIconPath, const std::string &strToolTip="")=0
 Replace existing button image with new image. More...
 
virtual bool replaceButtonImage (int nBttnId, void *wBttnImg, const std::string &strToolTip="")=0
 Replace existing button image with new GTK image widget. More...
 
virtual bool replaceButtonLabel (int nBttnId, const std::string &strLabel, const std::string &strToolTip="")=0
 Replace existing button label with new label. More...
 
virtual bool removeButton (int nBttnId)=0
 Remove a button from a menu. More...
 
virtual void removeAllButtons ()=0
 Remove all buttons from all menus.
 
virtual bool showButtonState (int nBttnId, WidgetState eBttnState)=0
 Show a button's widget state. More...
 
cv::Size getWorkspaceSize ()
 Get the window's workspace size. More...
 
virtual void initWorkspace ()=0
 Initialize window's workspace to hold a native GUI toolkit widget tree. More...
 
virtual uint_t initWorkspaceAsCvImage ()=0
 Initialize the workspace as a display to show OpenCV images. More...
 
virtual void initWorkspaceAsGstWin (const cv::Size &sizeVidWin)=0
 Initialize the workspace as a window display to show GStreamer video/images. More...
 
virtual uint_t addWorkspaceCvImageDisplay (void *wContainer)=0
 Add an OpenCV display widget to the container widget. More...
 
virtual void removeWorkspaceCvImageDisplay (uint_t uImgIndex)=0
 Remove OpenCV display widget from workspace. More...
 
virtual void showWorkspace ()=0
 Show/refresh all gui widgets in workspace.
 
virtual void eraseWorkspace ()=0
 Remove all widgets contained in the window's workspace container.
 
ulong_t getGstXid ()
 Get GStreamer X-Window id. More...
 
void registerCvImageMouseCallback (MouseCbFunc_T funcCb, void *param, uint_t uImgIndex=0)
 Register application mouse event callback. More...
 
void unregisterCvImageMouseCallback (uint_t uImgIndex=0)
 Unregister application mouse event callback. More...
 
void registerKeyboardCallback (KeyCbFunc_T funcCb, void *param)
 Register application keyboard press event callback. More...
 
void unregisterKeyboardCallback ()
 Unregister application keyboard press event callback.
 
void registerButtonClickCallback (BttnCbFunc_T funcCb, void *param)
 Register application button click event callback. More...
 
void unregisterButtonClickCallback ()
 Unregister application button click event callback.
 

Static Public Attributes

static const int MaxCvImages = 4
 max workspace images/video
 
static const int NumOfButtonMenus = 2
 left and right menus
 

Protected Types

typedef std::map< std::string, std::string > MapLookFeel_T
 

Protected Member Functions

void setLookAndFeelDefaults ()
 Set look and feel standard set defaults.
 

Protected Attributes

std::string m_strWinName
 window name (and title)
 
int m_nWinWidth
 window width
 
int m_nWinHeight
 window height
 
bool m_bDecorate
 do [not] decorate window
 
CvRect m_rectWorkspace
 workspace bounding rectangle
 
ulong_t m_uGstWinXid
 GstWin container X window id.
 
uint_t m_uLastKey
 last pressed keyboard code
 
bool m_bMouseEvent
 was a mouse event (click, drag, etc)
 
MouseCbFunc_T m_funcMouseCb [MaxCvImages]
 registered mouse cb func
 
void * m_dataMouseCb [MaxCvImages]
 registered mouse cb data
 
KeyCbFunc_T m_funcKeyCb
 registered keyboard callback func
 
void * m_dataKeyCb
 registered keyboard callback data
 
BttnCbFunc_T m_funcBttnCb
 registered menu button callback func
 
void * m_dataBttnCb
 registered menu button callback data
 
MapLookFeel_T m_mapLookFeel
 look and feel map
 

Detailed Description

RNR Win window abstract base class.

An instance of a derived Win class divides the screen into three vertical regions above, and two regions below.

*        -----------------------------------------------
*        |     |                                 |     |
*        |     |                                 |     |
*        |Left |                                 |Right|
*        |Menu |           Workspace             | Menu|
*        |Box  |                                 |  Box|
*        |     |                                 |     |
*        |     |                                 |     |
*        -----------------------------------------------
*        | ref |         status  message               |
*        -----------------------------------------------
* 

The left and right menu boxes hold on-screen buttons. The workspace can hold a collection of application specific widgets, including OpenCV image matrices and GStreamer video. Below, the reference box displays workflow context, while the status line displays prompts, errors, and info messages.

Definition at line 211 of file Win.h.

Constructor & Destructor Documentation

Win::Win ( const std::string &  strWinName,
int  nWidth,
int  nHeight,
bool  bDecorate = true 
)

Windowing class initialization constructor.

Parameters
strWinNameWindow name.
nWidthWindow width in pixels.
nHeightWindow height in pixels.
bDecorateDo [not] decorate window with title, border, etc. Windowing system specific.

Definition at line 69 of file Win.cxx.

References m_bMouseEvent, m_dataBttnCb, m_dataKeyCb, m_dataMouseCb, m_funcBttnCb, m_funcKeyCb, m_funcMouseCb, m_strWinName, m_uGstWinXid, m_uLastKey, MaxCvImages, and setLookAndFeelDefaults().

72  :
73  m_strWinName(strWinName),
74  m_nWinWidth(nWidth),
75  m_nWinHeight(nHeight),
76  m_bDecorate(bDecorate)
77 {
78  if( m_strWinName.empty() )
79  {
80  m_strWinName = "Main";
81  }
82 
83  for(int i=0; i<MaxCvImages; ++i)
84  {
85  m_funcMouseCb[i] = NULL;
86  m_dataMouseCb[i] = NULL;
87  }
88 
89  m_funcKeyCb = NULL;
90  m_dataKeyCb = NULL;
91  m_funcBttnCb = NULL;
92  m_dataBttnCb = NULL;
93  m_uGstWinXid = 0;
94  m_uLastKey = 0;
95  m_bMouseEvent = false;
96 
98 }
static const int MaxCvImages
max workspace images/video
Definition: Win.h:214
void setLookAndFeelDefaults()
Set look and feel standard set defaults.
Definition: Win.cxx:100
MouseCbFunc_T m_funcMouseCb[MaxCvImages]
registered mouse cb func
Definition: Win.h:662
bool m_bDecorate
do [not] decorate window
Definition: Win.h:657
void * m_dataMouseCb[MaxCvImages]
registered mouse cb data
Definition: Win.h:663
std::string m_strWinName
window name (and title)
Definition: Win.h:654
uint_t m_uLastKey
last pressed keyboard code
Definition: Win.h:660
KeyCbFunc_T m_funcKeyCb
registered keyboard callback func
Definition: Win.h:664
ulong_t m_uGstWinXid
GstWin container X window id.
Definition: Win.h:659
void * m_dataKeyCb
registered keyboard callback data
Definition: Win.h:665
int m_nWinHeight
window height
Definition: Win.h:656
BttnCbFunc_T m_funcBttnCb
registered menu button callback func
Definition: Win.h:666
bool m_bMouseEvent
was a mouse event (click, drag, etc)
Definition: Win.h:661
int m_nWinWidth
window width
Definition: Win.h:655
void * m_dataBttnCb
registered menu button callback data
Definition: Win.h:667

Member Function Documentation

virtual bool rnr::Win::addImageButton ( int  nBttnId,
AlignOp  eAlign,
const std::string &  strIconPath,
const std::string &  strAltText,
const std::string &  strToolTip = "" 
)
pure virtual

Add a button with an image to window button menu.

If the image fails to load, the alternate text is display instead.

Parameters
nBttnIdWindow unique button id.
eAlignMenu item icon alignment. See rnmpwin_align
strIconPathPath to icon image file.
strAltTextButton alternate text.
strToolTipOptional button tool tip text.
Returns
Returns true on success, false otherwise.

Implemented in rnr::WinGtk.

Referenced by getLookAndFeel().

virtual bool rnr::Win::addImageButton ( int  nBttnId,
AlignOp  eAlign,
void *  wBttnImg,
const std::string &  strAltText,
const std::string &  strToolTip = "" 
)
pure virtual

Add a button with an image widget to window button menu.

Parameters
nBttnIdWindow unique button id.
eAlignMenu item icon alignment. See rnmpwin_align
wBttnImgPointer to button image widget (gui toolkit specific).
strAltTextButton alternate text.
strToolTipOptional button tool tip text.
Returns
Returns true on success, false otherwise.

Implemented in rnr::WinGtk.

virtual bool rnr::Win::addLabelButton ( int  nBttnId,
AlignOp  eAlign,
const std::string &  strLabel,
const std::string &  strToolTip = "" 
)
pure virtual

Add a button with a label to window button menu.

Parameters
nBttnIdWindow unique button id.
eAlignMenu item icon alignment. See rnmpwin_align
strLabelButton text label.
strToolTipOptional button tool tip text.
Returns
Returns true on success, false otherwise.

Implemented in rnr::WinGtk.

Referenced by getLookAndFeel().

virtual uint_t rnr::Win::addWorkspaceCvImageDisplay ( void *  wContainer)
pure virtual

Add an OpenCV display widget to the container widget.

The container widget must be added to the window workspace by the application to keep the widget control correct.

Parameters
wContainerPointer to the container widget. (gui toolkit specific).
Returns
On success, returns index (handle) to CvImage instance.
On failure, returns -1.

Implemented in rnr::WinGtk.

Referenced by getWorkspaceSize().

ulong_t rnr::Win::getGstXid ( )
inline

Get GStreamer X-Window id.

Returns
Xid.

Definition at line 572 of file Win.h.

References m_uGstWinXid.

573  {
574  return m_uGstWinXid;
575  }
ulong_t m_uGstWinXid
GstWin container X window id.
Definition: Win.h:659
virtual const char* rnr::Win::getGuiToolkitName ( )
inlinevirtual

Get GUI toolkit name.

Returns
GUI toolkit identifier string.

Reimplemented in rnr::WinGtk.

Definition at line 241 of file Win.h.

242  {
243  return "abstract";
244  }
virtual std::string rnr::Win::getLookAndFeel ( const std::string &  strKey)
inlinevirtual

Get the GUI look and feel value.

Parameters
strKeyKey.
Returns
Value.

Definition at line 291 of file Win.h.

References addImageButton(), addLabelButton(), clearStatus(), m_mapLookFeel, removeAllButtons(), removeButton(), replaceButtonImage(), replaceButtonLabel(), show(), showButtonState(), showCvImage(), showPageRef(), showStatus(), wait(), waitKey(), and waitMouse().

292  {
293  std::string strVal;
294 
295  if( m_mapLookFeel.find(strKey) != m_mapLookFeel.end() )
296  {
297  strVal = m_mapLookFeel[strKey];
298  }
299  return strVal;
300  }
MapLookFeel_T m_mapLookFeel
look and feel map
Definition: Win.h:668
cv::Size rnr::Win::getWorkspaceSize ( )
inline

Get the window's workspace size.

Returns
Size of workspace.

Definition at line 495 of file Win.h.

References addWorkspaceCvImageDisplay(), eraseWorkspace(), initWorkspace(), initWorkspaceAsCvImage(), initWorkspaceAsGstWin(), m_rectWorkspace, removeWorkspaceCvImageDisplay(), and showWorkspace().

496  {
497  return cv::Size(m_rectWorkspace.width, m_rectWorkspace.height);
498  }
CvRect m_rectWorkspace
workspace bounding rectangle
Definition: Win.h:658
virtual void rnr::Win::initWorkspace ( )
pure virtual

Initialize window's workspace to hold a native GUI toolkit widget tree.

All previous gui elements are erased.

Implemented in rnr::WinGtk.

Referenced by getWorkspaceSize().

virtual uint_t rnr::Win::initWorkspaceAsCvImage ( )
pure virtual

Initialize the workspace as a display to show OpenCV images.

This is a convinience function to use if only one image gui element is contained in the workspace.

Use

to display an OpenCv image.

All previous gui elements are erased.

Returns
Index (handle) to CvImage widget instance.

Implemented in rnr::WinGtk.

Referenced by getWorkspaceSize().

virtual void rnr::Win::initWorkspaceAsGstWin ( const cv::Size &  sizeVidWin)
pure virtual

Initialize the workspace as a window display to show GStreamer video/images.

GStreamer automatically displays video/images via the GTK callback mechanism, so no show function is required.

This is a convinience function to use if only one stream is contained in the workspace.

All previous gui elements are erased.

Implemented in rnr::WinGtk.

Referenced by getWorkspaceSize().

void rnr::Win::registerButtonClickCallback ( BttnCbFunc_T  funcCb,
void *  param 
)
inline

Register application button click event callback.

Parameters
funcCbButton click callback function.
paramUser provided data given on callback.

Definition at line 636 of file Win.h.

References m_dataBttnCb, and m_funcBttnCb.

637  {
638  m_funcBttnCb = funcCb;
639  m_dataBttnCb = param;
640  }
BttnCbFunc_T m_funcBttnCb
registered menu button callback func
Definition: Win.h:666
void * m_dataBttnCb
registered menu button callback data
Definition: Win.h:667
void rnr::Win::registerCvImageMouseCallback ( MouseCbFunc_T  funcCb,
void *  param,
uint_t  uImgIndex = 0 
)
inline

Register application mouse event callback.

Parameters
funcCbMouse callback function.
paramUser provided data given on callback.
uImgIndexImage instance.

Definition at line 584 of file Win.h.

References m_dataMouseCb, and m_funcMouseCb.

587  {
588  if( uImgIndex < MaxCvImages )
589  {
590  m_funcMouseCb[uImgIndex] = funcCb;
591  m_dataMouseCb[uImgIndex] = param;
592  }
593  }
static const int MaxCvImages
max workspace images/video
Definition: Win.h:214
MouseCbFunc_T m_funcMouseCb[MaxCvImages]
registered mouse cb func
Definition: Win.h:662
void * m_dataMouseCb[MaxCvImages]
registered mouse cb data
Definition: Win.h:663
void rnr::Win::registerKeyboardCallback ( KeyCbFunc_T  funcCb,
void *  param 
)
inline

Register application keyboard press event callback.

Parameters
funcCbKeyboard callback function.
paramUser provided data given on callback.

Definition at line 615 of file Win.h.

References m_dataKeyCb, and m_funcKeyCb.

616  {
617  m_funcKeyCb = funcCb;
618  m_dataKeyCb = param;
619  }
KeyCbFunc_T m_funcKeyCb
registered keyboard callback func
Definition: Win.h:664
void * m_dataKeyCb
registered keyboard callback data
Definition: Win.h:665
virtual bool rnr::Win::removeButton ( int  nBttnId)
pure virtual

Remove a button from a menu.

Parameters
nBttnIdUnique button id.
Returns
Returns true if button is removed, false otherwise.

Implemented in rnr::WinGtk.

Referenced by getLookAndFeel().

virtual void rnr::Win::removeWorkspaceCvImageDisplay ( uint_t  uImgIndex)
pure virtual

Remove OpenCV display widget from workspace.

Parameters
uImgIndexImage instance.

Implemented in rnr::WinGtk.

Referenced by getWorkspaceSize().

virtual bool rnr::Win::replaceButtonImage ( int  nBttnId,
const std::string &  strIconPath,
const std::string &  strToolTip = "" 
)
pure virtual

Replace existing button image with new image.

Parameters
nBttnIdUnique button id.
strIconPathPath to icon image file.
strToolTipOptional button tool tip text. If empty, then the current tooltip, if any, is used.
Returns
Returns true if button image is replaced, false otherwise.

Implemented in rnr::WinGtk.

Referenced by getLookAndFeel().

virtual bool rnr::Win::replaceButtonImage ( int  nBttnId,
void *  wBttnImg,
const std::string &  strToolTip = "" 
)
pure virtual

Replace existing button image with new GTK image widget.

Parameters
nBttnIdUnique button id.
wBttnImgPointer to new button image widget (gui toolkit specific).
strToolTipOptional button tool tip text. If empty, then the current tooltip, if any, is used.
Returns
Returns true if button image is replaced, false otherwise.

Implemented in rnr::WinGtk.

virtual bool rnr::Win::replaceButtonLabel ( int  nBttnId,
const std::string &  strLabel,
const std::string &  strToolTip = "" 
)
pure virtual

Replace existing button label with new label.

Parameters
nBttnIdUnique button id.
strLabelButton text label.
strToolTipOptional button tooltip text. If empty, then the current tooltip, if any, is used.
Returns
Returns true if button label is replaced, false otherwise.

Implemented in rnr::WinGtk.

Referenced by getLookAndFeel().

virtual void rnr::Win::setLookAndFeel ( const std::string &  strKey,
const std::string &  strVal 
)
inlinevirtual

Set GUI look and feel value.

A look and feel value can be a color, font, line spacing, etc. There is a standard set which can be extended for application-specific needs.

Standard set:

key description
color_win_bg window background color
color_status_fg status bar foreground color
color_status_bg status bar background color
color_status_border status bar border color
color_button_bg button background color
color_text_fg default text foreground color
color_text_bg default text background color
color_image_bg default image background color
color_rn_black RoadNarrows black
color_rn_white RoadNarrows black
color_rn_red RoadNarrows black
color_rn_yellow RoadNarrows black
font_text default text font
font_status status bar font
font_large large font
font_medium medium font
font_small small font
font_tiny tiny font
Parameters
strKeyKey.
strValValue.

Reimplemented in rnr::WinGtk.

Definition at line 278 of file Win.h.

References m_mapLookFeel.

Referenced by rnr::WinGtk::setLookAndFeel().

280  {
281  m_mapLookFeel[strKey] = strVal;
282  }
MapLookFeel_T m_mapLookFeel
look and feel map
Definition: Win.h:668
virtual bool rnr::Win::showButtonState ( int  nBttnId,
WidgetState  eBttnState 
)
pure virtual

Show a button's widget state.

Parameters
nBttnIdUnique button id.
eBttnStateNew button state. See rnmpwin_itemstate.
Returns
Returns true if button state set, false otherwise.

Implemented in rnr::WinGtk.

Referenced by getLookAndFeel().

virtual void rnr::Win::showCvImage ( cv::Mat &  img,
uint_t  uImgIndex = 0 
)
pure virtual

Show a OpenCv image on the workspace.

Parameters
imgPointer to image.
uImgIndexImage instance.

Implemented in rnr::WinGtk.

Referenced by getLookAndFeel().

virtual void rnr::Win::showPageRef ( int  nPageRef)
pure virtual

Show page reference number.

Parameters
nPageRefPage reference number.

Implemented in rnr::WinGtk.

Referenced by getLookAndFeel().

virtual void rnr::Win::showPageRef ( const std::string &  strPageRef)
pure virtual

Show page reference string.

Parameters
strPageRefPage reference string.

Implemented in rnr::WinGtk.

virtual void rnr::Win::showStatus ( const char *  sFmt,
  ... 
)
pure virtual

Show status message.

Parameters
sFmtFormat string.
...Variable arguments.

Implemented in rnr::WinGtk.

Referenced by getLookAndFeel().

void rnr::Win::unregisterCvImageMouseCallback ( uint_t  uImgIndex = 0)
inline

Unregister application mouse event callback.

Parameters
uImgIndexImage instance.

Definition at line 600 of file Win.h.

References m_dataMouseCb, and m_funcMouseCb.

601  {
602  if( uImgIndex < MaxCvImages )
603  {
604  m_funcMouseCb[uImgIndex] = NULL;
605  m_dataMouseCb[uImgIndex] = NULL;
606  }
607  }
static const int MaxCvImages
max workspace images/video
Definition: Win.h:214
MouseCbFunc_T m_funcMouseCb[MaxCvImages]
registered mouse cb func
Definition: Win.h:662
void * m_dataMouseCb[MaxCvImages]
registered mouse cb data
Definition: Win.h:663
virtual void rnr::Win::wait ( int  delay)
pure virtual

Wait for timeout.

Window widgets can be updated during this wait.

Parameters
delayTimeout delay in millseconds > 0.

Implemented in rnr::WinGtk.

Referenced by getLookAndFeel().

virtual int rnr::Win::waitKey ( int  delay)
pure virtual

Wait for keypress or timeout.

Window widgets can be updated during this wait.

Parameters
delayTimeout delay in millseconds. Set to 0 for no timeout.
Returns
Returns code of last key pressed or -1 if timed out.

Implemented in rnr::WinGtk.

Referenced by getLookAndFeel().

virtual void rnr::Win::waitMouse ( int  delay)
pure virtual

Wait for timeout or registered mouse event.

Window widgets can be updated during this wait.

Parameters
delayTimeout delay in millseconds > 0.

Implemented in rnr::WinGtk.

Referenced by getLookAndFeel().


The documentation for this class was generated from the following files: