00001
00032
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 #include "llimagegl.h"
00045
00046
00047 #include "llsd.h"
00048
00049 class LLColor4;
00050 class LLVector3;
00051 class LLVector2;
00052 class LLUUID;
00053 class LLWindow;
00054 class LLView;
00055 class LLUIImage;
00056
00057
00058 extern const LLColor4 UI_VERTEX_COLOR;
00059 void make_ui_sound(const LLString& name);
00060
00061 BOOL ui_point_in_rect(S32 x, S32 y, S32 left, S32 top, S32 right, S32 bottom);
00062 void gl_state_for_2d(S32 width, S32 height);
00063
00064 void gl_line_2d(S32 x1, S32 y1, S32 x2, S32 y2);
00065 void gl_line_2d(S32 x1, S32 y1, S32 x2, S32 y2, const LLColor4 &color );
00066 void gl_triangle_2d(S32 x1, S32 y1, S32 x2, S32 y2, S32 x3, S32 y3, const LLColor4& color, BOOL filled);
00067 void gl_rect_2d_simple( S32 width, S32 height );
00068
00069 void gl_draw_x(const LLRect& rect, const LLColor4& color);
00070
00071 void gl_rect_2d(S32 left, S32 top, S32 right, S32 bottom, BOOL filled = TRUE );
00072 void gl_rect_2d(S32 left, S32 top, S32 right, S32 bottom, const LLColor4 &color, BOOL filled = TRUE );
00073 void gl_rect_2d_offset_local( S32 left, S32 top, S32 right, S32 bottom, const LLColor4 &color, S32 pixel_offset = 0, BOOL filled = TRUE );
00074 void gl_rect_2d_offset_local( S32 left, S32 top, S32 right, S32 bottom, S32 pixel_offset = 0, BOOL filled = TRUE );
00075 void gl_rect_2d(const LLRect& rect, BOOL filled = TRUE );
00076 void gl_rect_2d(const LLRect& rect, const LLColor4& color, BOOL filled = TRUE );
00077 void gl_rect_2d_checkerboard(const LLRect& rect);
00078
00079 void gl_drop_shadow(S32 left, S32 top, S32 right, S32 bottom, const LLColor4 &start_color, S32 lines);
00080
00081 void gl_circle_2d(F32 x, F32 y, F32 radius, S32 steps, BOOL filled);
00082 void gl_arc_2d(F32 center_x, F32 center_y, F32 radius, S32 steps, BOOL filled, F32 start_angle, F32 end_angle);
00083 void gl_deep_circle( F32 radius, F32 depth );
00084 void gl_ring( F32 radius, F32 width, const LLColor4& center_color, const LLColor4& side_color, S32 steps, BOOL render_center );
00085 void gl_corners_2d(S32 left, S32 top, S32 right, S32 bottom, S32 length, F32 max_frac);
00086 void gl_washer_2d(F32 outer_radius, F32 inner_radius, S32 steps, const LLColor4& inner_color, const LLColor4& outer_color);
00087 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);
00088 void gl_washer_spokes_2d(F32 outer_radius, F32 inner_radius, S32 count, const LLColor4& inner_color, const LLColor4& outer_color);
00089
00090 void gl_draw_image(S32 x, S32 y, LLImageGL* image, const LLColor4& color = UI_VERTEX_COLOR, const LLRectf& uv_rect = LLRectf(0.f, 1.f, 1.f, 0.f));
00091 void gl_draw_scaled_image(S32 x, S32 y, S32 width, S32 height, LLImageGL* image, const LLColor4& color = UI_VERTEX_COLOR, const LLRectf& uv_rect = LLRectf(0.f, 1.f, 1.f, 0.f));
00092 void gl_draw_rotated_image(S32 x, S32 y, F32 degrees, LLImageGL* image, const LLColor4& color = UI_VERTEX_COLOR, const LLRectf& uv_rect = LLRectf(0.f, 1.f, 1.f, 0.f));
00093 void gl_draw_scaled_rotated_image(S32 x, S32 y, S32 width, S32 height, F32 degrees,LLImageGL* image, const LLColor4& color = UI_VERTEX_COLOR, const LLRectf& uv_rect = LLRectf(0.f, 1.f, 1.f, 0.f));
00094 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, const LLRectf& uv_rect = LLRectf(0.f, 1.f, 1.f, 0.f));
00095 void gl_draw_scaled_image_with_border(S32 x, S32 y, S32 width, S32 height, LLImageGL* 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));
00096
00097 void gl_draw_scaled_image_inverted(S32 x, S32 y, S32 width, S32 height, LLImageGL* image, const LLColor4& color = UI_VERTEX_COLOR, const LLRectf& uv_rect = LLRectf(0.f, 1.f, 1.f, 0.f));
00098
00099 void gl_rect_2d_xor(S32 left, S32 top, S32 right, S32 bottom);
00100 void gl_stippled_line_3d( const LLVector3& start, const LLVector3& end, const LLColor4& color, F32 phase = 0.f );
00101
00102 void gl_rect_2d_simple_tex( S32 width, S32 height );
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117 typedef enum e_rounded_edge
00118 {
00119 ROUNDED_RECT_LEFT = 0x1,
00120 ROUNDED_RECT_TOP = 0x2,
00121 ROUNDED_RECT_RIGHT = 0x4,
00122 ROUNDED_RECT_BOTTOM = 0x8,
00123 ROUNDED_RECT_ALL = 0xf
00124 }ERoundedEdge;
00125
00126
00127 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);
00128 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);
00129 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);
00130 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);
00131
00132 inline void gl_rect_2d( const LLRect& rect, BOOL filled )
00133 {
00134 gl_rect_2d( rect.mLeft, rect.mTop, rect.mRight, rect.mBottom, filled );
00135 }
00136
00137 inline void gl_rect_2d_offset_local( const LLRect& rect, S32 pixel_offset, BOOL filled)
00138 {
00139 gl_rect_2d_offset_local( rect.mLeft, rect.mTop, rect.mRight, rect.mBottom, pixel_offset, filled );
00140 }
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150 extern BOOL gShowTextEditCursor;
00151
00152 class LLImageProviderInterface;
00153
00154 typedef void (*LLUIAudioCallback)(const LLUUID& uuid);
00155
00156 class LLUI
00157 {
00158 public:
00159
00160
00161
00162 static void initClass(LLControlGroup* config,
00163 LLControlGroup* colors,
00164 LLImageProviderInterface* image_provider,
00165 LLUIAudioCallback audio_callback = NULL,
00166 const LLVector2 *scale_factor = NULL,
00167 const LLString& language = LLString::null);
00168 static void cleanupClass();
00169
00170 static void pushMatrix();
00171 static void popMatrix();
00172 static void loadIdentity();
00173 static void translate(F32 x, F32 y, F32 z = 0.0f);
00174
00175
00176 static LLString locateSkin(const LLString& filename);
00177 static void setCursorPositionScreen(S32 x, S32 y);
00178 static void setCursorPositionLocal(const LLView* viewp, S32 x, S32 y);
00179 static void setScaleFactor(const LLVector2& scale_factor);
00180 static void setLineWidth(F32 width);
00181 static LLUIImage* getUIImage(const LLString& name);
00182 static LLVector2 getWindowSize();
00183 static void screenPointToGL(S32 screen_x, S32 screen_y, S32 *gl_x, S32 *gl_y);
00184 static void glPointToScreen(S32 gl_x, S32 gl_y, S32 *screen_x, S32 *screen_y);
00185 static void screenRectToGL(const LLRect& screen, LLRect *gl);
00186 static void glRectToScreen(const LLRect& gl, LLRect *screen);
00187 static void setHtmlHelp(LLHtmlHelp* html_help);
00188
00189
00190
00191
00192 static LLControlGroup* sConfigGroup;
00193 static LLControlGroup* sColorsGroup;
00194 static LLImageProviderInterface* sImageProvider;
00195 static LLUIAudioCallback sAudioCallback;
00196 static LLVector2 sGLScaleFactor;
00197 static LLWindow* sWindow;
00198 static BOOL sShowXUINames;
00199 static LLHtmlHelp* sHtmlHelp;
00200
00201
00202
00203
00204 static void setQAMode(BOOL b);
00205 static BOOL sQAMode;
00206
00207 };
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239 template <class T>
00240 class FactoryPolicy
00241 {
00242 public:
00243
00244 static T* findInstance(const LLSD& key);
00245 static T* createInstance(const LLSD& key);
00246 };
00247
00248
00249
00250
00251
00252
00253
00254 template <class T>
00255 class VisibilityPolicy
00256 {
00257 public:
00258
00259 static bool visible(T* instance, const LLSD& key);
00260 static void show(T* instance, const LLSD& key);
00261 static void hide(T* instance, const LLSD& key);
00262 };
00263
00264
00265
00266
00267
00268
00269 template <class T, class FACTORY_POLICY = FactoryPolicy<T>, class VISIBILITY_POLICY = VisibilityPolicy<T> >
00270 class LLUIFactory
00271 {
00272 public:
00273
00274
00275 typedef FACTORY_POLICY factory_policy_t;
00276 typedef VISIBILITY_POLICY visibility_policy_t;
00277
00278 LLUIFactory()
00279 {
00280 }
00281
00282 virtual ~LLUIFactory()
00283 {
00284 }
00285
00286
00287 static T* showInstance(const LLSD& key = LLSD())
00288 {
00289 T* instance = getInstance(key);
00290 if (instance != NULL)
00291 {
00292 VISIBILITY_POLICY::show(instance, key);
00293 }
00294 return instance;
00295 }
00296
00297 static void hideInstance(const LLSD& key = LLSD())
00298 {
00299 T* instance = getInstance(key);
00300 if (instance != NULL)
00301 {
00302 VISIBILITY_POLICY::hide(instance, key);
00303 }
00304 }
00305
00306 static void toggleInstance(const LLSD& key = LLSD())
00307 {
00308 if (instanceVisible(key))
00309 {
00310 hideInstance(key);
00311 }
00312 else
00313 {
00314 showInstance(key);
00315 }
00316 }
00317
00318 static bool instanceVisible(const LLSD& key = LLSD())
00319 {
00320 T* instance = FACTORY_POLICY::findInstance(key);
00321 return instance != NULL && VISIBILITY_POLICY::visible(instance, key);
00322 }
00323
00324 static T* getInstance(const LLSD& key = LLSD())
00325 {
00326 T* instance = FACTORY_POLICY::findInstance(key);
00327 if (instance == NULL)
00328 {
00329 instance = FACTORY_POLICY::createInstance(key);
00330 }
00331 return instance;
00332 }
00333
00334 };
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356 template <class T, class VISIBILITY_POLICY = VisibilityPolicy<T> >
00357 class LLUISingleton: public LLUIFactory<T, LLUISingleton<T, VISIBILITY_POLICY>, VISIBILITY_POLICY>
00358 {
00359 protected:
00360
00361
00362 LLUISingleton() { sInstance = static_cast<T*>(this); }
00363
00364 ~LLUISingleton() { sInstance = NULL; }
00365
00366 public:
00367 static T* findInstance(const LLSD& key = LLSD())
00368 {
00369 return sInstance;
00370 }
00371
00372 static T* createInstance(const LLSD& key = LLSD())
00373 {
00374 if (sInstance == NULL)
00375 {
00376 sInstance = new T(key);
00377 }
00378 return sInstance;
00379 }
00380
00381 private:
00382 static T* sInstance;
00383 };
00384
00385 template <class T, class U> T* LLUISingleton<T,U>::sInstance = NULL;
00386
00387 class LLScreenClipRect
00388 {
00389 public:
00390 LLScreenClipRect(const LLRect& rect, BOOL enabled = TRUE);
00391 virtual ~LLScreenClipRect();
00392
00393 private:
00394 static void pushClipRect(const LLRect& rect);
00395 static void popClipRect();
00396 static void updateScissorRegion();
00397
00398 private:
00399 LLGLState mScissorState;
00400 BOOL mEnabled;
00401
00402 static std::stack<LLRect> sClipRectStack;
00403 };
00404
00405 class LLLocalClipRect : public LLScreenClipRect
00406 {
00407 public:
00408 LLLocalClipRect(const LLRect& rect, BOOL enabled = TRUE);
00409 };
00410
00411 class LLUIImage : public LLRefCount
00412 {
00413 public:
00414 LLUIImage(const LLString& name, LLPointer<LLImageGL> image);
00415
00416 void setClipRegion(const LLRectf& region);
00417 void setScaleRegion(const LLRectf& region);
00418
00419 LLPointer<LLImageGL> getImage() { return mImage; }
00420 const LLPointer<LLImageGL>& getImage() const { return mImage; }
00421
00422 void draw(S32 x, S32 y, S32 width, S32 height, const LLColor4& color = UI_VERTEX_COLOR) const;
00423 void draw(S32 x, S32 y, const LLColor4& color = UI_VERTEX_COLOR) const;
00424 void draw(const LLRect& rect, const LLColor4& color = UI_VERTEX_COLOR) const { draw(rect.mLeft, rect.mBottom, rect.getWidth(), rect.getHeight(), color); }
00425
00426 void drawSolid(S32 x, S32 y, S32 width, S32 height, const LLColor4& color) const;
00427 void drawSolid(const LLRect& rect, const LLColor4& color) const { drawSolid(rect.mLeft, rect.mBottom, rect.getWidth(), rect.getHeight(), color); }
00428 void drawSolid(S32 x, S32 y, const LLColor4& color) const { drawSolid(x, y, mImage->getWidth(0), mImage->getHeight(0), color); }
00429
00430 void drawBorder(S32 x, S32 y, S32 width, S32 height, const LLColor4& color, S32 border_width) const;
00431 void drawBorder(const LLRect& rect, const LLColor4& color, S32 border_width) const { drawBorder(rect.mLeft, rect.mBottom, rect.getWidth(), rect.getHeight(), color, border_width); }
00432 void drawBorder(S32 x, S32 y, const LLColor4& color, S32 border_width) const { drawBorder(x, y, mImage->getWidth(0), mImage->getHeight(0), color, border_width); }
00433
00434 const LLString& getName() const { return mName; }
00435
00436 S32 getWidth() const;
00437 S32 getHeight() const;
00438
00439
00440 S32 getTextureWidth() const;
00441 S32 getTextureHeight() const;
00442
00443 protected:
00444 LLString mName;
00445 LLRectf mScaleRegion;
00446 LLRectf mClipRegion;
00447 LLPointer<LLImageGL> mImage;
00448 BOOL mUniformScaling;
00449 BOOL mNoClip;
00450 };
00451
00452 typedef LLPointer<LLUIImage> LLUIImagePtr;
00453
00454 template <typename T>
00455 class LLTombStone : public LLRefCount
00456 {
00457 public:
00458 LLTombStone(T* target = NULL) : mTarget(target) {}
00459
00460 void setTarget(T* target) { mTarget = target; }
00461 T* getTarget() const { return mTarget; }
00462 private:
00463 T* mTarget;
00464 };
00465
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475 template <typename T>
00476 class LLHandle
00477 {
00478 public:
00479 LLHandle() : mTombStone(sDefaultTombStone) {}
00480 const LLHandle<T>& operator =(const LLHandle<T>& other)
00481 {
00482 mTombStone = other.mTombStone;
00483 return *this;
00484 }
00485
00486 bool isDead() const
00487 {
00488 return mTombStone->getTarget() == NULL;
00489 }
00490
00491 void markDead()
00492 {
00493 mTombStone = sDefaultTombStone;
00494 }
00495
00496 T* get() const
00497 {
00498 return mTombStone->getTarget();
00499 }
00500
00501 friend bool operator== (const LLHandle<T>& lhs, const LLHandle<T>& rhs)
00502 {
00503 return lhs.mTombStone == rhs.mTombStone;
00504 }
00505 friend bool operator!= (const LLHandle<T>& lhs, const LLHandle<T>& rhs)
00506 {
00507 return !(lhs == rhs);
00508 }
00509 friend bool operator< (const LLHandle<T>& lhs, const LLHandle<T>& rhs)
00510 {
00511 return lhs.mTombStone < rhs.mTombStone;
00512 }
00513 friend bool operator> (const LLHandle<T>& lhs, const LLHandle<T>& rhs)
00514 {
00515 return lhs.mTombStone > rhs.mTombStone;
00516 }
00517 protected:
00518
00519 protected:
00520 LLPointer<LLTombStone<T> > mTombStone;
00521
00522 private:
00523 static LLPointer<LLTombStone<T> > sDefaultTombStone;
00524 };
00525
00526
00527 template <typename T> LLPointer<LLTombStone<T> > LLHandle<T>::sDefaultTombStone = new LLTombStone<T>();
00528
00529
00530 template <typename T>
00531 class LLRootHandle : public LLHandle<T>
00532 {
00533 public:
00534 LLRootHandle(T* object) { bind(object); }
00535 LLRootHandle() {};
00536 ~LLRootHandle() { unbind(); }
00537
00538
00539 LLHandle<T> getHandle() { return LLHandle<T>(*this); }
00540
00541 void bind(T* object)
00542 {
00543
00544 if (LLHandle<T>::mTombStone.notNull())
00545 {
00546 if (LLHandle<T>::mTombStone->getTarget() == object) return;
00547 LLHandle<T>::mTombStone->setTarget(NULL);
00548 }
00549
00550 LLHandle<T>::mTombStone = new LLTombStone<T>(object);
00551 }
00552
00553 void unbind()
00554 {
00555 LLHandle<T>::mTombStone->setTarget(NULL);
00556 }
00557
00558
00559 private:
00560 LLRootHandle(const LLRootHandle& other) {};
00561 };
00562
00563
00564
00565 template <typename T>
00566 class LLHandleProvider
00567 {
00568 protected:
00569 typedef LLHandle<T> handle_type_t;
00570 LLHandleProvider()
00571 {
00572
00573 }
00574
00575 LLHandle<T> getHandle()
00576 {
00577
00578
00579 mHandle.bind(static_cast<T*>(this));
00580 return mHandle;
00581 }
00582
00583 private:
00584 LLRootHandle<T> mHandle;
00585 };
00586
00587
00588
00589 class LLImageProviderInterface
00590 {
00591 public:
00592 LLImageProviderInterface() {};
00593 virtual ~LLImageProviderInterface() {};
00594
00595 virtual LLUIImagePtr getUIImage(const LLString& name) = 0;
00596 virtual LLUIImagePtr getUIImageByID(const LLUUID& id) = 0;
00597 virtual void cleanUp() = 0;
00598 };
00599
00600 #endif