diff options
author | Jacek Antonelli | 2008-08-15 23:44:58 -0500 |
---|---|---|
committer | Jacek Antonelli | 2008-08-15 23:44:58 -0500 |
commit | 089fc07d207c71ce1401e72f09c31ad8c45872e2 (patch) | |
tree | 0028955add042c6f45b47a7b774adeeac9c592cb /linden/indra/llui/llui.h | |
parent | Second Life viewer sources 1.16.0.5 (diff) | |
download | meta-impy-089fc07d207c71ce1401e72f09c31ad8c45872e2.zip meta-impy-089fc07d207c71ce1401e72f09c31ad8c45872e2.tar.gz meta-impy-089fc07d207c71ce1401e72f09c31ad8c45872e2.tar.bz2 meta-impy-089fc07d207c71ce1401e72f09c31ad8c45872e2.tar.xz |
Second Life viewer sources 1.17.0.12
Diffstat (limited to 'linden/indra/llui/llui.h')
-rw-r--r-- | linden/indra/llui/llui.h | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/linden/indra/llui/llui.h b/linden/indra/llui/llui.h index 6b8a86a..3085bd9 100644 --- a/linden/indra/llui/llui.h +++ b/linden/indra/llui/llui.h | |||
@@ -275,4 +275,95 @@ typedef enum e_widget_type | |||
275 | WIDGET_TYPE_COUNT | 275 | WIDGET_TYPE_COUNT |
276 | } EWidgetType; | 276 | } EWidgetType; |
277 | 277 | ||
278 | // Manages generation of UI elements by LLSD, such that there is | ||
279 | // only one instance per uniquely identified LLSD parameter | ||
280 | // Class T is the instance type being managed, and INSTANCE_ADDAPTOR | ||
281 | // wraps an instance of the class with handlers for show/hide semantics, etc. | ||
282 | template <class T, class INSTANCE_ADAPTOR = T> | ||
283 | class LLUIInstanceMgr | ||
284 | { | ||
285 | public: | ||
286 | LLUIInstanceMgr() | ||
287 | { | ||
288 | } | ||
289 | |||
290 | virtual ~LLUIInstanceMgr() | ||
291 | { | ||
292 | } | ||
293 | |||
294 | // default show and hide methods | ||
295 | static T* showInstance(const LLSD& seed) | ||
296 | { | ||
297 | T* instance = INSTANCE_ADAPTOR::getInstance(seed); | ||
298 | INSTANCE_ADAPTOR::show(instance); | ||
299 | return instance; | ||
300 | } | ||
301 | |||
302 | static void hideInstance(const LLSD& seed) | ||
303 | { | ||
304 | T* instance = INSTANCE_ADAPTOR::getInstance(seed); | ||
305 | INSTANCE_ADAPTOR::hide(instance); | ||
306 | } | ||
307 | |||
308 | static void toggleInstance(const LLSD& seed) | ||
309 | { | ||
310 | if (!INSTANCE_ADAPTOR::instanceVisible(seed)) | ||
311 | { | ||
312 | INSTANCE_ADAPTOR::showInstance(seed); | ||
313 | } | ||
314 | else | ||
315 | { | ||
316 | INSTANCE_ADAPTOR::hideInstance(seed); | ||
317 | } | ||
318 | } | ||
319 | |||
320 | static BOOL instanceVisible(const LLSD& seed) | ||
321 | { | ||
322 | T* instance = INSTANCE_ADAPTOR::findInstance(seed); | ||
323 | return instance != NULL && INSTANCE_ADAPTOR::visible(instance); | ||
324 | } | ||
325 | |||
326 | static T* getInstance(const LLSD& seed) | ||
327 | { | ||
328 | T* instance = INSTANCE_ADAPTOR::findInstance(seed); | ||
329 | if (instance == NULL) | ||
330 | { | ||
331 | instance = INSTANCE_ADAPTOR::createInstance(seed); | ||
332 | } | ||
333 | return instance; | ||
334 | } | ||
335 | }; | ||
336 | |||
337 | // Creates a UI singleton by ignoring the identifying parameter | ||
338 | // and always generating the same instance via the LLUIInstanceMgr interface. | ||
339 | // Note that since UI elements can be destroyed by their hierarchy, this singleton | ||
340 | // pattern uses a static pointer to an instance that will be re-created as needed. | ||
341 | template <class T, class INSTANCE_ADAPTOR = T> | ||
342 | class LLUISingleton: public LLUIInstanceMgr<T, INSTANCE_ADAPTOR> | ||
343 | { | ||
344 | public: | ||
345 | // default constructor assumes T is derived from LLUISingleton (a true singleton) | ||
346 | LLUISingleton() : LLUIInstanceMgr<T, INSTANCE_ADAPTOR>() { sInstance = (T*)this; } | ||
347 | ~LLUISingleton() { sInstance = NULL; } | ||
348 | |||
349 | static T* findInstance(const LLSD& seed) | ||
350 | { | ||
351 | return sInstance; | ||
352 | } | ||
353 | |||
354 | static T* createInstance(const LLSD& seed) | ||
355 | { | ||
356 | if (sInstance == NULL) | ||
357 | { | ||
358 | sInstance = new T(seed); | ||
359 | } | ||
360 | return sInstance; | ||
361 | } | ||
362 | |||
363 | protected: | ||
364 | static T* sInstance; | ||
365 | }; | ||
366 | |||
367 | template <class T, class U> T* LLUISingleton<T,U>::sInstance = NULL; | ||
368 | |||
278 | #endif | 369 | #endif |