Argus Camera Sample Argus Camera Sample

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
AppModuleGallery.cpp
Go to the documentation of this file.
1 /*
2 * Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of NVIDIA CORPORATION nor the names of its
13 * contributors may be used to endorse or promote products derived
14 * from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
20 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
24 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 #include <stdlib.h>
30
31 #include "AppModuleGallery.h"
32 #include "Error.h"
33
34 namespace ArgusSamples
35 {
36
37 /* static */ bool AppModuleGallery::prevItem(void *userPtr, const char *optArg)
38 {
39 AppModuleGallery *module = reinterpret_cast< AppModuleGallery*>(userPtr);
40
41 PROPAGATE_ERROR(module->m_gallery.prevItem());
42
43 return true;
44 }
45
46 /* static */ bool AppModuleGallery::nextItem(void *userPtr, const char *optArg)
47 {
48 AppModuleGallery *module = reinterpret_cast< AppModuleGallery*>(userPtr);
49
50 PROPAGATE_ERROR(module->m_gallery.nextItem());
51
52 return true;
53 }
54
55 /* static */ bool AppModuleGallery::togglePlayBack(void *userPtr, const char *optArg)
56 {
57 AppModuleGallery *module = reinterpret_cast< AppModuleGallery*>(userPtr);
58
59 PROPAGATE_ERROR(module->m_gallery.togglePlayBack());
60
61 return true;
62 }
63
64 /* static */ bool AppModuleGallery::rewind(void *userPtr, const char *optArg)
65 {
66 AppModuleGallery *module = reinterpret_cast< AppModuleGallery*>(userPtr);
67
68 PROPAGATE_ERROR(module->m_gallery.rewind());
69
70 return true;
71 }
72
73 AppModuleGallery::AppModuleGallery()
74 : m_initialized(false)
75 , m_running(false)
76 , m_guiContainerConfig(NULL)
77 , m_guiConfig(NULL)
78 {
79 }
80
81 AppModuleGallery::~AppModuleGallery()
82 {
83 shutdown();
84 }
85
86 bool AppModuleGallery::initialize(Options &options)
87 {
88 if (m_initialized)
89 return true;
90
91 PROPAGATE_ERROR(m_gallery.initialize());
92
93 m_initialized = true;
94
95 return true;
96 }
97
98 bool AppModuleGallery::shutdown()
99 {
100 if (!m_initialized)
101 return true;
102
103 PROPAGATE_ERROR_CONTINUE(stop());
104
105 PROPAGATE_ERROR_CONTINUE(m_gallery.shutdown());
106
107 m_initialized = false;
108
109 return true;
110 }
111
112 bool AppModuleGallery::start(Window::IGuiMenuBar *iGuiMenuBar,
113 Window::IGuiContainer *iGuiContainerConfig)
114 {
115 if (m_running)
116 return true;
117
118 // register key observer
119 PROPAGATE_ERROR(Window::getInstance().registerObserver(this));
120
121 // initialize the GUI
122 if (iGuiContainerConfig && !m_guiConfig)
123 {
124 // initialize the GUI
125
126 // create a grid container
127 PROPAGATE_ERROR(Window::IGuiContainerGrid::create(&m_guiConfig));
128
129 // create the elements
130 UniquePointer<Window::IGuiElement> element;
131 unsigned int column = 0;
132
133 PROPAGATE_ERROR(Window::IGuiElement::createAction("Previous Item",
134 AppModuleGallery::prevItem, this, Window::IGuiElement::FLAG_NONE,
135 Window::IGuiElement::ICON_PREVIOUS, &element));
136 PROPAGATE_ERROR(m_guiConfig->attach(element.get(), column++, 0));
137 element.release();
138
139 PROPAGATE_ERROR(Window::IGuiElement::createAction("Rewind",
140 AppModuleGallery::rewind, this, Window::IGuiElement::FLAG_NONE,
141 Window::IGuiElement::ICON_MEDIA_REWIND, &element));
142 PROPAGATE_ERROR(m_guiConfig->attach(element.get(), column++, 0));
143 element.release();
144
145 PROPAGATE_ERROR(Window::IGuiElement::createAction("Toggle Playback",
146 AppModuleGallery::togglePlayBack, this, Window::IGuiElement::FLAG_BUTTON_TOGGLE,
147 Window::IGuiElement::ICON_MEDIA_PLAY, &element));
148 PROPAGATE_ERROR(m_guiConfig->attach(element.get(), column++, 0));
149 element.release();
150
151 PROPAGATE_ERROR(Window::IGuiElement::createAction("Next Item",
152 AppModuleGallery::nextItem, this, Window::IGuiElement::FLAG_NONE,
153 Window::IGuiElement::ICON_NEXT, &element));
154 PROPAGATE_ERROR(m_guiConfig->attach(element.get(), column++, 0));
155 element.release();
156
157 m_guiContainerConfig = iGuiContainerConfig;
158 }
159
160 if (m_guiContainerConfig)
161 PROPAGATE_ERROR(m_guiContainerConfig->add(m_guiConfig));
162
163 PROPAGATE_ERROR(m_gallery.start());
164
165 m_running = true;
166
167 return true;
168 }
169
170 bool AppModuleGallery::stop()
171 {
172 if (!m_running)
173 return true;
174
175 PROPAGATE_ERROR(m_gallery.stop());
176
177 if (m_guiContainerConfig)
178 PROPAGATE_ERROR(m_guiContainerConfig->remove(m_guiConfig));
179
180 // unregister key observer
181 PROPAGATE_ERROR(Window::getInstance().unregisterObserver(this));
182
183 m_running = false;
184
185 return true;
186 }
187
188 bool AppModuleGallery::onKey(const Key &key)
189 {
190 if (key == Key("Left"))
191 {
192 PROPAGATE_ERROR(m_gallery.prevItem());
193 }
194 else if (key == Key("Right"))
195 {
196 PROPAGATE_ERROR(m_gallery.nextItem());
197 }
198 else if (key == Key("space"))
199 {
200 PROPAGATE_ERROR(m_gallery.togglePlayBack());
201 }
202
203 return true;
204 }
205
206 }; // namespace ArgusSamples