llui.h

Go to the documentation of this file.
00001 
00032 // All immediate-mode gl drawing should happen here.
00033 
00034 #ifndef LL_LLUI_H
00035 #define LL_LLUI_H
00036 
00037 #include "llrect.h"
00038 #include "llcontrol.h"
00039 #include "llrect.h"
00040 #include "llcoord.h"
00041 #include "llhtmlhelp.h"
00042 #include "llgl.h"
00043 #include <stack>
00044 
00045 class LLColor4;
00046 class LLVector3;
00047 class LLVector2;
00048 class LLImageGL;
00049 class LLUUID;
00050 class LLWindow;
00051 class LLView;
00052 
00053 // UI colors
00054 extern const LLColor4 UI_VERTEX_COLOR;
00055 void make_ui_sound(const LLString& name);
00056 
00057 BOOL ui_point_in_rect(S32 x, S32 y, S32 left, S32 top, S32 right, S32 bottom);
00058 void gl_state_for_2d(S32 width, S32 height);
00059 
00060 void gl_line_2d(S32 x1, S32 y1, S32 x2, S32 y2);
00061 void gl_line_2d(S32 x1, S32 y1, S32 x2, S32 y2, const LLColor4 &color );
00062 void gl_triangle_2d(S32 x1, S32 y1, S32 x2, S32 y2, S32 x3, S32 y3, const LLColor4& color, BOOL filled);
00063 void gl_rect_2d_simple( S32 width, S32 height );
00064 
00065 void gl_draw_x(const LLRect& rect, const LLColor4& color);
00066 
00067 void gl_rect_2d(S32 left, S32 top, S32 right, S32 bottom, BOOL filled = TRUE );
00068 void gl_rect_2d(S32 left, S32 top, S32 right, S32 bottom, const LLColor4 &color, BOOL filled = TRUE );
00069 void gl_rect_2d_offset_local( S32 left, S32 top, S32 right, S32 bottom, const LLColor4 &color, S32 pixel_offset = 0, BOOL filled = TRUE );
00070 void gl_rect_2d_offset_local( S32 left, S32 top, S32 right, S32 bottom, S32 pixel_offset = 0, BOOL filled = TRUE );
00071 void gl_rect_2d(const LLRect& rect, BOOL filled = TRUE );
00072 void gl_rect_2d(const LLRect& rect, const LLColor4& color, BOOL filled = TRUE );
00073 void gl_rect_2d_checkerboard(const LLRect& rect);
00074 
00075 void gl_drop_shadow(S32 left, S32 top, S32 right, S32 bottom, const LLColor4 &start_color, S32 lines);
00076 
00077 void gl_circle_2d(F32 x, F32 y, F32 radius, S32 steps, BOOL filled);
00078 void gl_arc_2d(F32 center_x, F32 center_y, F32 radius, S32 steps, BOOL filled, F32 start_angle, F32 end_angle);
00079 void gl_deep_circle( F32 radius, F32 depth );
00080 void gl_ring( F32 radius, F32 width, const LLColor4& center_color, const LLColor4& side_color, S32 steps, BOOL render_center );
00081 void gl_corners_2d(S32 left, S32 top, S32 right, S32 bottom, S32 length, F32 max_frac);
00082 void gl_washer_2d(F32 outer_radius, F32 inner_radius, S32 steps, const LLColor4& inner_color, const LLColor4& outer_color);
00083 void 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);
00084 void gl_washer_spokes_2d(F32 outer_radius, F32 inner_radius, S32 count, const LLColor4& inner_color, const LLColor4& outer_color);
00085 
00086 void gl_draw_image(S32 x, S32 y, LLImageGL* image, const LLColor4& color = UI_VERTEX_COLOR);
00087 void gl_draw_scaled_image(S32 x, S32 y, S32 width, S32 height, LLImageGL* image, const LLColor4& color = UI_VERTEX_COLOR);
00088 void gl_draw_rotated_image(S32 x, S32 y, F32 degrees, LLImageGL* image, const LLColor4& color = UI_VERTEX_COLOR);
00089 void gl_draw_scaled_rotated_image(S32 x, S32 y, S32 width, S32 height, F32 degrees,LLImageGL* image, const LLColor4& color = UI_VERTEX_COLOR);
00090 void gl_draw_scaled_image_with_border(S32 x, S32 y, S32 border_width, S32 border_height, S32 width, S32 height, LLImageGL* image, const LLColor4 &color, BOOL solid_color = FALSE);
00091 // Flip vertical, used for LLFloaterHTML
00092 void gl_draw_scaled_image_inverted(S32 x, S32 y, S32 width, S32 height, LLImageGL* image, const LLColor4& color = UI_VERTEX_COLOR);
00093 
00094 void gl_rect_2d_xor(S32 left, S32 top, S32 right, S32 bottom);
00095 void gl_stippled_line_3d( const LLVector3& start, const LLVector3& end, const LLColor4& color, F32 phase = 0.f ); 
00096 
00097 void gl_rect_2d_simple_tex( S32 width, S32 height );
00098 
00099 // segmented rectangles
00100 
00101 /*
00102    TL |______TOP_________| TR 
00103      /|                  |\  
00104    _/_|__________________|_\_
00105    L| |    MIDDLE        | |R
00106    _|_|__________________|_|_
00107     \ |    BOTTOM        | /  
00108    BL\|__________________|/ BR
00109       |                  |    
00110 */
00111 
00112 typedef enum e_rounded_edge
00113 {
00114         ROUNDED_RECT_LEFT       = 0x1, 
00115         ROUNDED_RECT_TOP        = 0x2, 
00116         ROUNDED_RECT_RIGHT      = 0x4, 
00117         ROUNDED_RECT_BOTTOM     = 0x8,
00118         ROUNDED_RECT_ALL        = 0xf
00119 }ERoundedEdge;
00120 
00121 
00122 void 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);
00123 void 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);
00124 void 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);
00125 void 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);
00126 
00127 inline void gl_rect_2d( const LLRect& rect, BOOL filled )
00128 {
00129         gl_rect_2d( rect.mLeft, rect.mTop, rect.mRight, rect.mBottom, filled );
00130 }
00131 
00132 inline void gl_rect_2d_offset_local( const LLRect& rect, S32 pixel_offset, BOOL filled)
00133 {
00134         gl_rect_2d_offset_local( rect.mLeft, rect.mTop, rect.mRight, rect.mBottom, pixel_offset, filled );
00135 }
00136 
00137 // No longer used
00138 // Initializes translation table
00139 // void init_tr();
00140 
00141 // Returns a string from the string table in the correct language
00142 // LLString tr(const LLString& english_chars);
00143 
00144 // Used to hide the flashing text cursor when window doesn't have focus.
00145 extern BOOL gShowTextEditCursor;
00146 
00147 class LLImageProviderInterface;
00148 typedef void (*LLUIAudioCallback)(const LLUUID& uuid);
00149 
00150 class LLUI
00151 {
00152 public:
00153         static void initClass(LLControlGroup* config, 
00154                                                   LLControlGroup* colors, 
00155                                                   LLControlGroup* assets, 
00156                                                   LLImageProviderInterface* image_provider,
00157                                                   LLUIAudioCallback audio_callback = NULL,
00158                                                   const LLVector2 *scale_factor = NULL,
00159                                                   const LLString& language = LLString::null);
00160         static void cleanupClass();
00161 
00162         static void pushMatrix();
00163         static void popMatrix();
00164         static void loadIdentity();
00165         static void translate(F32 x, F32 y, F32 z = 0.0f);
00166 
00167         //helper functions (should probably move free standing rendering helper functions here)
00168         static LLString locateSkin(const LLString& filename);
00169         static void pushClipRect(const LLRect& rect);
00170         static void popClipRect();
00171         static void setCursorPositionScreen(S32 x, S32 y);
00172         static void setCursorPositionLocal(LLView* viewp, S32 x, S32 y);
00173         static void setScaleFactor(const LLVector2& scale_factor);
00174         static void setLineWidth(F32 width);
00175         static LLUUID findAssetUUIDByName(const LLString&       name);
00176         static LLVector2 getWindowSize();
00177         static void setHtmlHelp(LLHtmlHelp* html_help);
00178 
00179 private:
00180         static void setScissorRegionScreen(const LLRect& rect);
00181         static void setScissorRegionLocal(const LLRect& rect); // works assuming LLUI::translate has been called
00182 
00183 public:
00184         static LLControlGroup* sConfigGroup;
00185         static LLControlGroup* sColorsGroup;
00186         static LLControlGroup* sAssetsGroup;
00187         static LLImageProviderInterface* sImageProvider;
00188         static LLUIAudioCallback sAudioCallback;
00189         static LLVector2                sGLScaleFactor;
00190         static LLWindow*                sWindow;
00191         static BOOL             sShowXUINames;
00192         static LLHtmlHelp*              sHtmlHelp;
00193         static std::stack<LLRect> sClipRectStack;
00194 
00195 };
00196 
00197 // UI widgets
00198 // This MUST match UICtrlNames in lluictrlfactory.cpp
00199 typedef enum e_widget_type
00200 {
00201         WIDGET_TYPE_VIEW = 0,
00202         WIDGET_TYPE_ROOT_VIEW,
00203         WIDGET_TYPE_FLOATER_VIEW,
00204         WIDGET_TYPE_BUTTON,
00205         WIDGET_TYPE_JOYSTICK_TURN,
00206         WIDGET_TYPE_JOYSTICK_SLIDE,
00207         WIDGET_TYPE_CHECKBOX,
00208         WIDGET_TYPE_COLOR_SWATCH,
00209         WIDGET_TYPE_COMBO_BOX,
00210         WIDGET_TYPE_LINE_EDITOR,
00211         WIDGET_TYPE_SEARCH_EDITOR,
00212         WIDGET_TYPE_SCROLL_LIST,
00213         WIDGET_TYPE_NAME_LIST,
00214         WIDGET_TYPE_WEBBROWSER,
00215         WIDGET_TYPE_SLIDER,     // actually LLSliderCtrl
00216         WIDGET_TYPE_SLIDER_BAR, // actually LLSlider
00217         WIDGET_TYPE_VOLUME_SLIDER,//actually LLVolumeSliderCtrl
00218         WIDGET_TYPE_SPINNER,
00219         WIDGET_TYPE_TEXT_EDITOR,
00220         WIDGET_TYPE_TEXTURE_PICKER,
00221         WIDGET_TYPE_TEXT_BOX,
00222         WIDGET_TYPE_PAD,        // used in XML for positioning, not a real widget
00223         WIDGET_TYPE_RADIO_GROUP,
00224         WIDGET_TYPE_ICON,
00225         WIDGET_TYPE_LANDMARK_PICKER,
00226         WIDGET_TYPE_LOCATE,     // used in XML for positioning, not a real widget
00227         WIDGET_TYPE_VIEW_BORDER,        // decorative border
00228         WIDGET_TYPE_PANEL,
00229         WIDGET_TYPE_MENU,
00230         WIDGET_TYPE_PIE_MENU,
00231         WIDGET_TYPE_PIE_MENU_BRANCH,
00232         WIDGET_TYPE_MENU_ITEM,
00233         WIDGET_TYPE_MENU_ITEM_SEPARATOR,
00234         WIDGET_TYPE_MENU_SEPARATOR_VERTICAL,
00235         WIDGET_TYPE_MENU_ITEM_CALL,
00236         WIDGET_TYPE_MENU_ITEM_CHECK,
00237         WIDGET_TYPE_MENU_ITEM_BRANCH,
00238         WIDGET_TYPE_MENU_ITEM_BRANCH_DOWN,
00239         WIDGET_TYPE_MENU_ITEM_BLANK,
00240         WIDGET_TYPE_TEAROFF_MENU,
00241         WIDGET_TYPE_MENU_BAR,
00242         WIDGET_TYPE_TAB_CONTAINER,
00243         WIDGET_TYPE_SCROLL_CONTAINER, // LLScrollableContainerView
00244         WIDGET_TYPE_SCROLLBAR,
00245         WIDGET_TYPE_INVENTORY_PANEL, // LLInventoryPanel
00246         WIDGET_TYPE_FLOATER,
00247         WIDGET_TYPE_DRAG_HANDLE_TOP,
00248         WIDGET_TYPE_DRAG_HANDLE_LEFT,
00249         WIDGET_TYPE_RESIZE_HANDLE,
00250         WIDGET_TYPE_RESIZE_BAR,
00251         WIDGET_TYPE_NAME_EDITOR,
00252         WIDGET_TYPE_MULTI_FLOATER,
00253         WIDGET_TYPE_MEDIA_REMOTE,
00254         WIDGET_TYPE_FOLDER_VIEW,
00255         WIDGET_TYPE_FOLDER_ITEM,
00256         WIDGET_TYPE_FOLDER,
00257         WIDGET_TYPE_STAT_GRAPH,
00258         WIDGET_TYPE_STAT_VIEW,
00259         WIDGET_TYPE_STAT_BAR,
00260         WIDGET_TYPE_DROP_TARGET,
00261         WIDGET_TYPE_TEXTURE_BAR,
00262         WIDGET_TYPE_TEX_MEM_BAR,
00263         WIDGET_TYPE_SNAPSHOT_LIVE_PREVIEW,
00264         WIDGET_TYPE_STATUS_BAR,
00265         WIDGET_TYPE_PROGRESS_VIEW,
00266         WIDGET_TYPE_TALK_VIEW,
00267         WIDGET_TYPE_OVERLAY_BAR,
00268         WIDGET_TYPE_HUD_VIEW,
00269         WIDGET_TYPE_HOVER_VIEW,
00270         WIDGET_TYPE_MORPH_VIEW,
00271         WIDGET_TYPE_NET_MAP,
00272         WIDGET_TYPE_PERMISSIONS_VIEW,
00273         WIDGET_TYPE_MENU_HOLDER,
00274         WIDGET_TYPE_DEBUG_VIEW,
00275         WIDGET_TYPE_SCROLLING_PANEL_LIST,
00276         WIDGET_TYPE_AUDIO_STATUS,
00277         WIDGET_TYPE_CONTAINER_VIEW,
00278         WIDGET_TYPE_CONSOLE,
00279         WIDGET_TYPE_FAST_TIMER_VIEW,
00280         WIDGET_TYPE_VELOCITY_BAR,
00281         WIDGET_TYPE_TEXTURE_VIEW,
00282         WIDGET_TYPE_MEMORY_VIEW,
00283         WIDGET_TYPE_FRAME_STAT_VIEW,
00284         WIDGET_TYPE_LAYOUT_STACK,
00285         WIDGET_TYPE_DONTCARE,
00286         WIDGET_TYPE_COUNT
00287 } EWidgetType;
00288 
00289 // Manages generation of UI elements by LLSD, such that there is
00290 // only one instance per uniquely identified LLSD parameter
00291 // Class T is the instance type being managed, and INSTANCE_ADDAPTOR
00292 // wraps an instance of the class with handlers for show/hide semantics, etc.
00293 template <class T, class INSTANCE_ADAPTOR = T>
00294 class LLUIInstanceMgr
00295 {
00296 public:
00297         LLUIInstanceMgr()
00298         {
00299         }
00300 
00301         virtual ~LLUIInstanceMgr() 
00302         { 
00303         }
00304 
00305         // default show and hide methods
00306         static T* showInstance(const LLSD& seed = LLSD()) 
00307         { 
00308                 T* instance = INSTANCE_ADAPTOR::getInstance(seed); 
00309                 INSTANCE_ADAPTOR::show(instance);
00310                 return instance;
00311         }
00312 
00313         static void hideInstance(const LLSD& seed = LLSD()) 
00314         { 
00315                 T* instance = INSTANCE_ADAPTOR::getInstance(seed); 
00316                 INSTANCE_ADAPTOR::hide(instance);
00317         }
00318 
00319         static void toggleInstance(const LLSD& seed = LLSD())
00320         {
00321                 if (INSTANCE_ADAPTOR::instanceVisible(seed))
00322                 {
00323                         INSTANCE_ADAPTOR::hideInstance(seed);
00324                 }
00325                 else
00326                 {
00327                         INSTANCE_ADAPTOR::showInstance(seed);
00328                 }
00329         }
00330 
00331         static BOOL instanceVisible(const LLSD& seed = LLSD())
00332         {
00333                 T* instance = INSTANCE_ADAPTOR::findInstance(seed);
00334                 return instance != NULL && INSTANCE_ADAPTOR::visible(instance);
00335         }
00336 
00337         static T* getInstance(const LLSD& seed = LLSD()) 
00338         {
00339                 T* instance = INSTANCE_ADAPTOR::findInstance(seed);
00340                 if (instance == NULL)
00341                 {
00342                         instance = INSTANCE_ADAPTOR::createInstance(seed);
00343                 }
00344                 return instance;
00345         }
00346 
00347 };
00348 
00349 // Creates a UI singleton by ignoring the identifying parameter
00350 // and always generating the same instance via the LLUIInstanceMgr interface.
00351 // Note that since UI elements can be destroyed by their hierarchy, this singleton
00352 // pattern uses a static pointer to an instance that will be re-created as needed.
00353 template <class T, class INSTANCE_ADAPTOR = T>
00354 class LLUISingleton: public LLUIInstanceMgr<T, INSTANCE_ADAPTOR>
00355 {
00356 public:
00357         // default constructor assumes T is derived from LLUISingleton (a true singleton)
00358         LLUISingleton() : LLUIInstanceMgr<T, INSTANCE_ADAPTOR>() { sInstance = (T*)this; }
00359         ~LLUISingleton() { sInstance = NULL; }
00360 
00361         static T* findInstance(const LLSD& seed = LLSD())
00362         {
00363                 return sInstance;
00364         }
00365 
00366         static T* createInstance(const LLSD& seed = LLSD())
00367         {
00368                 if (sInstance == NULL)
00369                 {
00370                         sInstance = new T(seed);
00371                 }
00372                 return sInstance;
00373         }
00374 
00375 protected:
00376         static T*       sInstance;
00377 };
00378 
00379 template <class T, class U> T* LLUISingleton<T,U>::sInstance = NULL;
00380 
00381 class LLClipRect
00382 {
00383 public:
00384         LLClipRect(const LLRect& rect, BOOL enabled = TRUE);
00385         virtual ~LLClipRect();
00386 protected:
00387         LLGLState               mScissorState;
00388         BOOL                    mEnabled;
00389 };
00390 
00391 class LLLocalClipRect
00392 {
00393 public:
00394         LLLocalClipRect(const LLRect& rect, BOOL enabled = TRUE);
00395         virtual ~LLLocalClipRect();
00396 protected:
00397         LLGLState               mScissorState;
00398         BOOL                    mEnabled;
00399 };
00400 
00401 #endif

Generated on Thu Jul 1 06:09:23 2010 for Second Life Viewer by  doxygen 1.4.7