PageRenderTime 107ms CodeModel.GetById 25ms app.highlight 76ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llui/llui.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 609 lines | 421 code | 95 blank | 93 comment | 6 complexity | 0a72def31c7205c5e55a613bde9c9504 MD5 | raw file
  1/** 
  2 * @file llui.h
  3 * @brief GL function declarations and other general static UI services.
  4 *
  5 * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  6 * Second Life Viewer Source Code
  7 * Copyright (C) 2010, Linden Research, Inc.
  8 * 
  9 * This library is free software; you can redistribute it and/or
 10 * modify it under the terms of the GNU Lesser General Public
 11 * License as published by the Free Software Foundation;
 12 * version 2.1 of the License only.
 13 * 
 14 * This library is distributed in the hope that it will be useful,
 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 17 * Lesser General Public License for more details.
 18 * 
 19 * You should have received a copy of the GNU Lesser General Public
 20 * License along with this library; if not, write to the Free Software
 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 22 * 
 23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 24 * $/LicenseInfo$
 25 */
 26
 27// All immediate-mode gl drawing should happen here.
 28
 29#ifndef LL_LLUI_H
 30#define LL_LLUI_H
 31
 32#include "llpointer.h"		// LLPointer<>
 33#include "llrect.h"
 34#include "llcontrol.h"
 35#include "llcoord.h"
 36#include "llglslshader.h"
 37#include "llinitparam.h"
 38#include "llregistry.h"
 39#include "lluicolor.h"
 40#include "lluicolortable.h"
 41#include <boost/signals2.hpp>
 42#include "lllazyvalue.h"
 43#include "llframetimer.h"
 44#include <limits>
 45
 46// LLUIFactory
 47#include "llsd.h"
 48
 49// for initparam specialization
 50#include "llfontgl.h"
 51
 52
 53class LLColor4; 
 54class LLVector3;
 55class LLVector2;
 56class LLUIImage;
 57class LLUUID;
 58class LLWindow;
 59class LLView;
 60class LLHelp;
 61
 62// UI colors
 63extern const LLColor4 UI_VERTEX_COLOR;
 64void make_ui_sound(const char* name);
 65
 66BOOL ui_point_in_rect(S32 x, S32 y, S32 left, S32 top, S32 right, S32 bottom);
 67void gl_state_for_2d(S32 width, S32 height);
 68
 69void gl_line_2d(S32 x1, S32 y1, S32 x2, S32 y2);
 70void gl_line_2d(S32 x1, S32 y1, S32 x2, S32 y2, const LLColor4 &color );
 71void gl_triangle_2d(S32 x1, S32 y1, S32 x2, S32 y2, S32 x3, S32 y3, const LLColor4& color, BOOL filled);
 72void gl_rect_2d_simple( S32 width, S32 height );
 73
 74void gl_draw_x(const LLRect& rect, const LLColor4& color);
 75
 76void gl_rect_2d(S32 left, S32 top, S32 right, S32 bottom, BOOL filled = TRUE );
 77void gl_rect_2d(S32 left, S32 top, S32 right, S32 bottom, const LLColor4 &color, BOOL filled = TRUE );
 78void gl_rect_2d_offset_local( S32 left, S32 top, S32 right, S32 bottom, const LLColor4 &color, S32 pixel_offset = 0, BOOL filled = TRUE );
 79void gl_rect_2d_offset_local( S32 left, S32 top, S32 right, S32 bottom, S32 pixel_offset = 0, BOOL filled = TRUE );
 80void gl_rect_2d(const LLRect& rect, BOOL filled = TRUE );
 81void gl_rect_2d(const LLRect& rect, const LLColor4& color, BOOL filled = TRUE );
 82void gl_rect_2d_checkerboard(const LLRect& rect, GLfloat alpha = 1.0f);
 83
 84void gl_drop_shadow(S32 left, S32 top, S32 right, S32 bottom, const LLColor4 &start_color, S32 lines);
 85
 86void gl_circle_2d(F32 x, F32 y, F32 radius, S32 steps, BOOL filled);
 87void gl_arc_2d(F32 center_x, F32 center_y, F32 radius, S32 steps, BOOL filled, F32 start_angle, F32 end_angle);
 88void gl_deep_circle( F32 radius, F32 depth );
 89void gl_ring( F32 radius, F32 width, const LLColor4& center_color, const LLColor4& side_color, S32 steps, BOOL render_center );
 90void gl_corners_2d(S32 left, S32 top, S32 right, S32 bottom, S32 length, F32 max_frac);
 91void gl_washer_2d(F32 outer_radius, F32 inner_radius, S32 steps, const LLColor4& inner_color, const LLColor4& outer_color);
 92void gl_washer_segment_2d(F32 outer_radius, F32 inner_radius, F32 start_radians, F32 end_radians, S32 steps, const LLColor4& inner_color, const LLColor4& outer_color);
 93
 94void gl_draw_image(S32 x, S32 y, LLTexture* image, const LLColor4& color = UI_VERTEX_COLOR, const LLRectf& uv_rect = LLRectf(0.f, 1.f, 1.f, 0.f));
 95void gl_draw_scaled_image(S32 x, S32 y, S32 width, S32 height, LLTexture* image, const LLColor4& color = UI_VERTEX_COLOR, const LLRectf& uv_rect = LLRectf(0.f, 1.f, 1.f, 0.f));
 96void gl_draw_rotated_image(S32 x, S32 y, F32 degrees, LLTexture* image, const LLColor4& color = UI_VERTEX_COLOR, const LLRectf& uv_rect = LLRectf(0.f, 1.f, 1.f, 0.f));
 97void gl_draw_scaled_rotated_image(S32 x, S32 y, S32 width, S32 height, F32 degrees,LLTexture* image, const LLColor4& color = UI_VERTEX_COLOR, const LLRectf& uv_rect = LLRectf(0.f, 1.f, 1.f, 0.f));
 98void gl_draw_scaled_image_with_border(S32 x, S32 y, S32 border_width, S32 border_height, S32 width, S32 height, LLTexture* image, const LLColor4 &color, BOOL solid_color = FALSE, const LLRectf& uv_rect = LLRectf(0.f, 1.f, 1.f, 0.f));
 99void gl_draw_scaled_image_with_border(S32 x, S32 y, S32 width, S32 height, LLTexture* image, const LLColor4 &color, BOOL solid_color = FALSE, const LLRectf& uv_rect = LLRectf(0.f, 1.f, 1.f, 0.f), const LLRectf& scale_rect = LLRectf(0.f, 1.f, 1.f, 0.f));
100
101void gl_stippled_line_3d( const LLVector3& start, const LLVector3& end, const LLColor4& color, F32 phase = 0.f ); 
102
103void gl_rect_2d_simple_tex( S32 width, S32 height );
104
105// segmented rectangles
106
107/*
108   TL |______TOP_________| TR 
109     /|                  |\  
110   _/_|__________________|_\_
111   L| |    MIDDLE        | |R
112   _|_|__________________|_|_
113    \ |    BOTTOM        | /  
114   BL\|__________________|/ BR
115      |                  |    
116*/
117
118typedef enum e_rounded_edge
119{
120	ROUNDED_RECT_LEFT	= 0x1, 
121	ROUNDED_RECT_TOP	= 0x2, 
122	ROUNDED_RECT_RIGHT	= 0x4, 
123	ROUNDED_RECT_BOTTOM	= 0x8,
124	ROUNDED_RECT_ALL	= 0xf
125}ERoundedEdge;
126
127
128void gl_segmented_rect_2d_tex(const S32 left, const S32 top, const S32 right, const S32 bottom, const S32 texture_width, const S32 texture_height, const S32 border_size, const U32 edges = ROUNDED_RECT_ALL);
129void gl_segmented_rect_2d_fragment_tex(const S32 left, const S32 top, const S32 right, const S32 bottom, const S32 texture_width, const S32 texture_height, const S32 border_size, const F32 start_fragment, const F32 end_fragment, const U32 edges = ROUNDED_RECT_ALL);
130void gl_segmented_rect_3d_tex(const LLVector2& border_scale, const LLVector3& border_width, const LLVector3& border_height, const LLVector3& width_vec, const LLVector3& height_vec, U32 edges = ROUNDED_RECT_ALL);
131void gl_segmented_rect_3d_tex_top(const LLVector2& border_scale, const LLVector3& border_width, const LLVector3& border_height, const LLVector3& width_vec, const LLVector3& height_vec);
132
133inline void gl_rect_2d( const LLRect& rect, BOOL filled )
134{
135	gl_rect_2d( rect.mLeft, rect.mTop, rect.mRight, rect.mBottom, filled );
136}
137
138inline void gl_rect_2d_offset_local( const LLRect& rect, S32 pixel_offset, BOOL filled)
139{
140	gl_rect_2d_offset_local( rect.mLeft, rect.mTop, rect.mRight, rect.mBottom, pixel_offset, filled );
141}
142
143class LLImageProviderInterface;
144
145typedef	void (*LLUIAudioCallback)(const LLUUID& uuid);
146
147class LLUI
148{
149	LOG_CLASS(LLUI);
150public:
151	//
152	// Classes
153	//
154
155	struct RangeS32 
156	{
157		struct Params : public LLInitParam::Block<Params>
158		{
159			Optional<S32>	minimum,
160							maximum;
161
162			Params()
163			:	minimum("min", 0),
164				maximum("max", S32_MAX)
165			{}
166		};
167
168		// correct for inverted params
169		RangeS32(const Params& p = Params())
170		:	mMin(p.minimum),
171			mMax(p.maximum)
172		{
173			sanitizeRange();
174		}
175
176		RangeS32(S32 minimum, S32 maximum)
177		:	mMin(minimum),
178			mMax(maximum)
179		{
180			sanitizeRange();
181		}
182
183		S32 clamp(S32 input)
184		{
185			if (input < mMin) return mMin;
186			if (input > mMax) return mMax;
187			return input;
188		}
189
190		void setRange(S32 minimum, S32 maximum)
191		{
192			mMin = minimum;
193			mMax = maximum;
194			sanitizeRange();
195		}
196
197		S32 getMin() { return mMin; }
198		S32 getMax() { return mMax; }
199
200		bool operator==(const RangeS32& other) const
201		{
202			return mMin == other.mMin 
203				&& mMax == other.mMax;
204		}
205	private:
206		void sanitizeRange()
207		{
208			if (mMin > mMax)
209			{
210				llwarns << "Bad interval range (" << mMin << ", " << mMax << ")" << llendl;
211				// since max is usually the most dangerous one to ignore (buffer overflow, etc), prefer it
212				// in the case of a malformed range
213				mMin = mMax;
214			}
215		}
216
217
218		S32	mMin,
219			mMax;
220	};
221
222	struct ClampedS32 : public RangeS32
223	{
224		struct Params : public LLInitParam::Block<Params, RangeS32::Params>
225		{
226			Mandatory<S32> value;
227
228			Params()
229			:	value("", 0)
230			{
231				addSynonym(value, "value");
232			}
233		};
234
235		ClampedS32(const Params& p)
236		:	RangeS32(p)
237		{}
238
239		ClampedS32(const RangeS32& range)
240		:	RangeS32(range)
241		{
242			// set value here, after range has been sanitized
243			mValue = clamp(0);
244		}
245
246		ClampedS32(S32 value, const RangeS32& range = RangeS32())
247		:	RangeS32(range)
248		{
249			mValue = clamp(value);
250		}
251
252		S32 get()
253		{
254			return mValue;
255		}
256
257		void set(S32 value)
258		{
259			mValue = clamp(value);
260		}
261
262
263	private:
264		S32 mValue;
265	};
266
267	//
268	// Methods
269	//
270	typedef std::map<std::string, LLControlGroup*> settings_map_t;
271	typedef boost::function<void(LLView*)> add_popup_t;
272	typedef boost::function<void(LLView*)> remove_popup_t;
273	typedef boost::function<void(void)> clear_popups_t;
274
275	static void initClass(const settings_map_t& settings,
276						  LLImageProviderInterface* image_provider,
277						  LLUIAudioCallback audio_callback = NULL,
278						  const LLVector2 *scale_factor = NULL,
279						  const std::string& language = LLStringUtil::null);
280	static void cleanupClass();
281	static void setPopupFuncs(const add_popup_t& add_popup, const remove_popup_t&, const clear_popups_t& );
282
283	static void pushMatrix();
284	static void popMatrix();
285	static void loadIdentity();
286	static void translate(F32 x, F32 y, F32 z = 0.0f);
287
288	static LLRect	sDirtyRect;
289	static BOOL		sDirty;
290	static void		dirtyRect(LLRect rect);
291
292	// Return the ISO639 language name ("en", "ko", etc.) for the viewer UI.
293	// http://www.loc.gov/standards/iso639-2/php/code_list.php
294	static std::string getLanguage();
295	
296	static void setupPaths();
297	static const std::vector<std::string>& getXUIPaths() { return sXUIPaths; }
298	static std::string getSkinPath() { return sXUIPaths.front(); }
299	static std::string getLocalizedSkinPath() { return sXUIPaths.back(); }  //all files may not exist at the localized path
300
301	//helper functions (should probably move free standing rendering helper functions here)
302	static LLView* getRootView() { return sRootView; }
303	static void setRootView(LLView* view) { sRootView = view; }
304	/**
305	 * Walk the LLView tree to resolve a path
306	 * Paths can be discovered using Develop > XUI > Show XUI Paths
307	 *
308	 * A leading "/" indicates the root of the tree is the starting
309	 * position of the search, (otherwise the context node is used)
310	 *
311	 * Adjacent "//" mean that the next level of the search is done
312	 * recursively ("descendant" rather than "child").
313	 *
314	 * Return values: If no match is found, NULL is returned,
315	 * otherwise the matching LLView* is returned.
316	 *
317	 * Examples:
318	 *
319	 * "/" -> return the root view
320	 * "/foo" -> find "foo" as a direct child of the root
321	 * "foo" -> find "foo" as a direct child of the context node
322	 * "//foo" -> find the first "foo" child anywhere in the tree
323	 * "/foo/bar" -> find "foo" as direct child of the root, and
324	 *      "bar" as a direct child of "foo"
325	 * "//foo//bar/baz" -> find the first "foo" anywhere in the
326	 *      tree, the first "bar" anywhere under it, and "baz"
327	 *      as a direct child of that
328	 */
329	static const LLView* resolvePath(const LLView* context, const std::string& path);
330	static LLView* resolvePath(LLView* context, const std::string& path);
331	static std::string locateSkin(const std::string& filename);
332	static void setMousePositionScreen(S32 x, S32 y);
333	static void getMousePositionScreen(S32 *x, S32 *y);
334	static void setMousePositionLocal(const LLView* viewp, S32 x, S32 y);
335	static void getMousePositionLocal(const LLView* viewp, S32 *x, S32 *y);
336	static void setScaleFactor(const LLVector2& scale_factor);
337	static void setLineWidth(F32 width);
338	static LLPointer<LLUIImage> getUIImageByID(const LLUUID& image_id, S32 priority = 0);
339	static LLPointer<LLUIImage> getUIImage(const std::string& name, S32 priority = 0);
340	static LLVector2 getWindowSize();
341	static void screenPointToGL(S32 screen_x, S32 screen_y, S32 *gl_x, S32 *gl_y);
342	static void glPointToScreen(S32 gl_x, S32 gl_y, S32 *screen_x, S32 *screen_y);
343	static void screenRectToGL(const LLRect& screen, LLRect *gl);
344	static void glRectToScreen(const LLRect& gl, LLRect *screen);
345	// Returns the control group containing the control name, or the default group
346	static LLControlGroup& getControlControlGroup (const std::string& controlname);
347	static F32 getMouseIdleTime() { return sMouseIdleTimer.getElapsedTimeF32(); }
348	static void resetMouseIdleTimer() { sMouseIdleTimer.reset(); }
349	static LLWindow* getWindow() { return sWindow; }
350
351	static void addPopup(LLView*);
352	static void removePopup(LLView*);
353	static void clearPopups();
354
355	static void reportBadKeystroke();
356
357	// Ensures view does not overlap mouse cursor, but is inside
358	// the view's parent rectangle.  Used for tooltips, inspectors.
359	// Optionally override the view's default X/Y, which are relative to the
360	// view's parent.
361	static void positionViewNearMouse(LLView* view,	S32 spawn_x = S32_MAX, S32 spawn_y = S32_MAX);
362
363	//
364	// Data
365	//
366	static settings_map_t sSettingGroups;
367	static LLUIAudioCallback sAudioCallback;
368	static LLVector2		sGLScaleFactor;
369	static LLWindow*		sWindow;
370	static LLView*			sRootView;
371	static LLHelp*			sHelpImpl;
372private:
373	static LLImageProviderInterface* sImageProvider;
374	static std::vector<std::string> sXUIPaths;
375	static LLFrameTimer		sMouseIdleTimer;
376	static add_popup_t		sAddPopupFunc;
377	static remove_popup_t	sRemovePopupFunc;
378	static clear_popups_t	sClearPopupsFunc;
379};
380
381
382// Moved LLLocalClipRect to lllocalcliprect.h
383
384//RN: maybe this needs to moved elsewhere?
385class LLImageProviderInterface
386{
387protected:
388	LLImageProviderInterface() {};
389	virtual ~LLImageProviderInterface() {};
390public:
391	virtual LLPointer<LLUIImage> getUIImage(const std::string& name, S32 priority) = 0;
392	virtual LLPointer<LLUIImage> getUIImageByID(const LLUUID& id, S32 priority) = 0;
393	virtual void cleanUp() = 0;
394};
395
396class LLCallbackRegistry
397{
398public:
399	typedef boost::signals2::signal<void()> callback_signal_t;
400	
401	void registerCallback(const callback_signal_t::slot_type& slot)
402	{
403		mCallbacks.connect(slot);
404	}
405
406	void fireCallbacks()
407	{
408		mCallbacks();
409	}
410
411private:
412	callback_signal_t mCallbacks;
413};
414
415class LLInitClassList : 
416	public LLCallbackRegistry, 
417	public LLSingleton<LLInitClassList>
418{
419	friend class LLSingleton<LLInitClassList>;
420private:
421	LLInitClassList() {}
422};
423
424class LLDestroyClassList : 
425	public LLCallbackRegistry, 
426	public LLSingleton<LLDestroyClassList>
427{
428	friend class LLSingleton<LLDestroyClassList>;
429private:
430	LLDestroyClassList() {}
431};
432
433template<typename T>
434class LLRegisterWith
435{
436public:
437	LLRegisterWith(boost::function<void ()> func)
438	{
439		T::instance().registerCallback(func);
440	}
441
442	// this avoids a MSVC bug where non-referenced static members are "optimized" away
443	// even if their constructors have side effects
444	void reference()
445	{
446		S32 dummy;
447		dummy = 0;
448	}
449};
450
451template<typename T>
452class LLInitClass
453{
454public:
455	LLInitClass() { sRegister.reference(); }
456
457	static LLRegisterWith<LLInitClassList> sRegister;
458private:
459
460	static void initClass()
461	{
462		llerrs << "No static initClass() method defined for " << typeid(T).name() << llendl;
463	}
464};
465
466template<typename T>
467class LLDestroyClass
468{
469public:
470	LLDestroyClass() { sRegister.reference(); }
471
472	static LLRegisterWith<LLDestroyClassList> sRegister;
473private:
474
475	static void destroyClass()
476	{
477		llerrs << "No static destroyClass() method defined for " << typeid(T).name() << llendl;
478	}
479};
480
481template <typename T> LLRegisterWith<LLInitClassList> LLInitClass<T>::sRegister(&T::initClass);
482template <typename T> LLRegisterWith<LLDestroyClassList> LLDestroyClass<T>::sRegister(&T::destroyClass);
483
484// useful parameter blocks
485struct TimeIntervalParam : public LLInitParam::ChoiceBlock<TimeIntervalParam>
486{
487	Alternative<F32>		seconds;
488	Alternative<S32>		frames;
489	TimeIntervalParam()
490	:	seconds("seconds"),
491		frames("frames")
492	{}
493};
494
495template <class T>
496class LLUICachedControl : public LLCachedControl<T>
497{
498public:
499	// This constructor will declare a control if it doesn't exist in the contol group
500	LLUICachedControl(const std::string& name,
501					  const T& default_value,
502					  const std::string& comment = "Declared In Code")
503	:	LLCachedControl<T>(LLUI::getControlControlGroup(name), name, default_value, comment)
504	{}
505
506	// This constructor will signal an error if the control doesn't exist in the control group
507	LLUICachedControl(const std::string& name)
508	:	LLCachedControl<T>(LLUI::getControlControlGroup(name), name)
509	{}
510};
511
512namespace LLInitParam
513{
514	template<>
515	class ParamValue<LLRect, TypeValues<LLRect> > 
516	:	public CustomParamValue<LLRect>
517	{
518        typedef CustomParamValue<LLRect> super_t;
519	public:
520		Optional<S32>	left,
521						top,
522						right,
523						bottom,
524						width,
525						height;
526
527		ParamValue(const LLRect& value);
528
529		void updateValueFromBlock();
530		void updateBlockFromValue(bool make_block_authoritative);
531	};
532
533	template<>
534	class ParamValue<LLUIColor, TypeValues<LLUIColor> > 
535	:	public CustomParamValue<LLUIColor>
536	{
537        typedef CustomParamValue<LLUIColor> super_t;
538
539	public:
540		Optional<F32>			red,
541								green,
542								blue,
543								alpha;
544		Optional<std::string>	control;
545
546		ParamValue(const LLUIColor& color);
547		void updateValueFromBlock();
548		void updateBlockFromValue(bool make_block_authoritative);
549	};
550
551	template<>
552	class ParamValue<const LLFontGL*, TypeValues<const LLFontGL*> > 
553	:	public CustomParamValue<const LLFontGL* >
554	{
555        typedef CustomParamValue<const LLFontGL*> super_t;
556	public:
557		Optional<std::string>	name,
558								size,
559								style;
560
561		ParamValue(const LLFontGL* value);
562		void updateValueFromBlock();
563		void updateBlockFromValue(bool make_block_authoritative);
564	};
565
566	template<>
567	struct TypeValues<LLFontGL::HAlign> : public TypeValuesHelper<LLFontGL::HAlign>
568	{
569		static void declareValues();
570	};
571
572	template<>
573	struct TypeValues<LLFontGL::VAlign> : public TypeValuesHelper<LLFontGL::VAlign>
574	{
575		static void declareValues();
576	};
577
578	template<>
579	struct TypeValues<LLFontGL::ShadowType> : public TypeValuesHelper<LLFontGL::ShadowType>
580	{
581		static void declareValues();
582	};
583
584	template<>
585	struct ParamCompare<const LLFontGL*, false>
586	{
587		static bool equals(const LLFontGL* a, const LLFontGL* b);
588	};
589
590
591	template<>
592	class ParamValue<LLCoordGL, TypeValues<LLCoordGL> >
593	:	public CustomParamValue<LLCoordGL>
594	{
595		typedef CustomParamValue<LLCoordGL> super_t;
596	public:
597		Optional<S32>	x,
598						y;
599
600		ParamValue(const LLCoordGL& val);
601		void updateValueFromBlock();
602		void updateBlockFromValue(bool make_block_authoritative);
603	};
604}
605
606extern LLGLSLShader gSolidColorProgram;
607extern LLGLSLShader gUIProgram;
608
609#endif