appkit  1.5.1
RoadNarrows Robotics Application Kit
StateWin.cxx
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // Package: RoadNarrows Robotics Application Tool Kit
4 //
5 // Library: librnr_win
6 //
7 // File: StateWin.cxx
8 //
9 /*! \file
10  *
11  * $LastChangedDate: 2013-07-13 14:12:15 -0600 (Sat, 13 Jul 2013) $
12  * $Rev: 3126 $
13  *
14  * \brief GUI window StateWin derived state class implementation.
15  *
16  * \author Robin Knight (robin.knight@roadnarrows.com)
17  * \author Daniel Packard (daniel@roadnarrows.com)
18  *
19  * \par Copyright
20  * \h_copy 2012-2017. RoadNarrows LLC.\n
21  * http://www.roadnarrows.com\n
22  * All Rights Reserved
23  */
24 /*
25  * @EulaBegin@
26  *
27  * Permission is hereby granted, without written agreement and without
28  * license or royalty fees, to use, copy, modify, and distribute this
29  * software and its documentation for any purpose, provided that
30  * (1) The above copyright notice and the following two paragraphs
31  * appear in all copies of the source code and (2) redistributions
32  * including binaries reproduces these notices in the supporting
33  * documentation. Substantial modifications to this software may be
34  * copyrighted by their authors and need not follow the licensing terms
35  * described here, provided that the new terms are clearly indicated in
36  * all files where they apply.
37  *
38  * IN NO EVENT SHALL THE AUTHOR, ROADNARROWS LLC, OR ANY MEMBERS/EMPLOYEES
39  * OF ROADNARROW LLC OR DISTRIBUTORS OF THIS SOFTWARE BE LIABLE TO ANY
40  * PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
41  * DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION,
42  * EVEN IF THE AUTHORS OR ANY OF THE ABOVE PARTIES HAVE BEEN ADVISED OF
43  * THE POSSIBILITY OF SUCH DAMAGE.
44  *
45  * THE AUTHOR AND ROADNARROWS LLC SPECIFICALLY DISCLAIM ANY WARRANTIES,
46  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
47  * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN
48  * "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO
49  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
50  *
51  * @EulaEnd@
52  */
53 ////////////////////////////////////////////////////////////////////////////////
54 
55 #include <stdio.h>
56 
57 #include <string>
58 #include <map>
59 
60 #include "rnr/rnrconfig.h"
61 #include "rnr/log.h"
62 
63 #include "rnr/appkit/Win.h"
64 #include "rnr/appkit/WinMenu.h"
65 #include "rnr/appkit/WinCvMouse.h"
66 #include "rnr/appkit/SessionWin.h"
67 #include "rnr/appkit/State.h"
68 #include "rnr/appkit/StateWin.h"
69 
70 using namespace std;
71 using namespace rnr;
72 
73 
74 //------------------------------------------------------------------------------
75 // StateKb Class
76 //------------------------------------------------------------------------------
77 
78 int StateWin::receiveEvent()
79 {
80  int nEventId;
81 
82  // wait
83  nEventId = m_session.win().waitKey(m_usecTimeOut / 1000);
84 
85  // keyboard event
86  if( m_bKbEvents && (nEventId >= 0) )
87  {
88  return nEventId;
89  }
90 
91  // button menu event
92  else if( (m_pButtons != NULL) &&
93  ((nEventId = m_pButtons->getCurrentEvent()) != UIEventNone) )
94  {
95  m_pButtons->setCurrentEvent(UIEventNone);
96  return nEventId;
97  }
98 
99  // mouse event
100  else if( m_bMouseEvents )
101  {
102  nEventId = m_mouse.getCurrentEvent();
103  m_mouse.setCurrentEvent(UIEventNone);
104  }
105 
106  // no event
107  else
108  {
109  nEventId = UIEventNone;
110  }
111 
112  return nEventId;
113 }
114 
115 void StateWin::actionEnterState(int nPrevStateId, int nEventId)
116 {
117  if( !m_bOneTimeInit )
118  {
119  initOnceGuiInterface();
120  }
121 
122  // build (create) interface
123  buildGuiInterface();
124 
125  // bind menu to window
126  m_pButtons->bind(m_session.getWin());
127 
128  // page identifier
129  m_session.win().showPageRef(m_strRefTag);
130 
131  // enable/disable/toggle menu button states
132  setButtonStates();
133 
134  // set local state context in session
135  m_session.setContext(this);
136 
137  // show interface
138  showGuiInterface();
139 }
140 
141 void StateWin::actionExitState(int nNextStateId, int nEventId)
142 {
143  m_pButtons->unbind();
144 
145  m_session.win().showPageRef("");
146 
147  destroyGuiInterface();
148 }
RoadNarrows Robotics Win abstract base class interface.
GUI window StateWin derived state class interface.
RoadNarrows Robotics base window button menu interface.
no action
Definition: Win.h:115
SessionWin derived class.
RoadNarrows Robotics base OpenCV Mouse class interface.
State base class interface.
RoadNarrows Robotics.
Definition: Camera.h:74