PageRenderTime 57ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/llui/llviewborder.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 270 lines | 208 code | 34 blank | 28 comment | 22 complexity | 5b3b8749cd13269b6cbfec22eded1281 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llviewborder.cpp
  3. *
  4. * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  5. * Second Life Viewer Source Code
  6. * Copyright (C) 2010, Linden Research, Inc.
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation;
  11. * version 2.1 of the License only.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with this library; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. *
  22. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  23. * $/LicenseInfo$
  24. */
  25. #include "linden_common.h"
  26. #include "llviewborder.h"
  27. #include "llrender.h"
  28. #include "llfocusmgr.h"
  29. #include "lluictrlfactory.h"
  30. #include "lluiimage.h"
  31. static LLDefaultChildRegistry::Register<LLViewBorder> r("view_border");
  32. void LLViewBorder::BevelValues::declareValues()
  33. {
  34. declare("in", LLViewBorder::BEVEL_IN);
  35. declare("out", LLViewBorder::BEVEL_OUT);
  36. declare("bright", LLViewBorder::BEVEL_BRIGHT);
  37. declare("none", LLViewBorder::BEVEL_NONE);
  38. }
  39. void LLViewBorder::StyleValues::declareValues()
  40. {
  41. declare("line", LLViewBorder::STYLE_LINE);
  42. declare("texture", LLViewBorder::STYLE_TEXTURE);
  43. }
  44. LLViewBorder::Params::Params()
  45. : bevel_style("bevel_style", BEVEL_OUT),
  46. render_style("border_style", STYLE_LINE),
  47. border_thickness("border_thickness"),
  48. highlight_light_color("highlight_light_color"),
  49. highlight_dark_color("highlight_dark_color"),
  50. shadow_light_color("shadow_light_color"),
  51. shadow_dark_color("shadow_dark_color")
  52. {
  53. addSynonym(border_thickness, "thickness");
  54. addSynonym(render_style, "style");
  55. }
  56. LLViewBorder::LLViewBorder(const LLViewBorder::Params& p)
  57. : LLView(p),
  58. mTexture( NULL ),
  59. mHasKeyboardFocus( FALSE ),
  60. mBorderWidth(p.border_thickness),
  61. mHighlightLight(p.highlight_light_color()),
  62. mHighlightDark(p.highlight_dark_color()),
  63. mShadowLight(p.shadow_light_color()),
  64. mShadowDark(p.shadow_dark_color()),
  65. mBevel(p.bevel_style),
  66. mStyle(p.render_style)
  67. {}
  68. void LLViewBorder::setColors( const LLColor4& shadow_dark, const LLColor4& highlight_light )
  69. {
  70. mShadowDark = shadow_dark;
  71. mHighlightLight = highlight_light;
  72. }
  73. void LLViewBorder::setColorsExtended( const LLColor4& shadow_light, const LLColor4& shadow_dark,
  74. const LLColor4& highlight_light, const LLColor4& highlight_dark )
  75. {
  76. mShadowDark = shadow_dark;
  77. mShadowLight = shadow_light;
  78. mHighlightLight = highlight_light;
  79. mHighlightDark = highlight_dark;
  80. }
  81. void LLViewBorder::setTexture( const LLUUID &image_id )
  82. {
  83. mTexture = LLUI::getUIImageByID(image_id);
  84. }
  85. void LLViewBorder::draw()
  86. {
  87. if( STYLE_LINE == mStyle )
  88. {
  89. if( 0 == mBorderWidth )
  90. {
  91. // no visible border
  92. }
  93. else
  94. if( 1 == mBorderWidth )
  95. {
  96. drawOnePixelLines();
  97. }
  98. else
  99. if( 2 == mBorderWidth )
  100. {
  101. drawTwoPixelLines();
  102. }
  103. else
  104. {
  105. llassert( FALSE ); // not implemented
  106. }
  107. }
  108. LLView::draw();
  109. }
  110. void LLViewBorder::drawOnePixelLines()
  111. {
  112. gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
  113. LLColor4 top_color = mHighlightLight.get();
  114. LLColor4 bottom_color = mHighlightLight.get();
  115. switch( mBevel )
  116. {
  117. case BEVEL_OUT:
  118. top_color = mHighlightLight.get();
  119. bottom_color = mShadowDark.get();
  120. break;
  121. case BEVEL_IN:
  122. top_color = mShadowDark.get();
  123. bottom_color = mHighlightLight.get();
  124. break;
  125. case BEVEL_NONE:
  126. // use defaults
  127. break;
  128. default:
  129. llassert(0);
  130. }
  131. if( mHasKeyboardFocus )
  132. {
  133. top_color = gFocusMgr.getFocusColor();
  134. bottom_color = top_color;
  135. LLUI::setLineWidth(lerp(1.f, 3.f, gFocusMgr.getFocusFlashAmt()));
  136. }
  137. S32 left = 0;
  138. S32 top = getRect().getHeight();
  139. S32 right = getRect().getWidth();
  140. S32 bottom = 0;
  141. gGL.color4fv( top_color.mV );
  142. gl_line_2d(left, bottom, left, top);
  143. gl_line_2d(left, top, right, top);
  144. gGL.color4fv( bottom_color.mV );
  145. gl_line_2d(right, top, right, bottom);
  146. gl_line_2d(left, bottom, right, bottom);
  147. LLUI::setLineWidth(1.f);
  148. }
  149. void LLViewBorder::drawTwoPixelLines()
  150. {
  151. gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
  152. LLColor4 focus_color = gFocusMgr.getFocusColor();
  153. LLColor4 top_in_color;
  154. LLColor4 top_out_color;
  155. LLColor4 bottom_in_color;
  156. LLColor4 bottom_out_color;
  157. switch( mBevel )
  158. {
  159. case BEVEL_OUT:
  160. top_in_color = mHighlightLight.get();
  161. top_out_color = mHighlightDark.get();
  162. bottom_in_color = mShadowLight.get();
  163. bottom_out_color = mShadowDark.get();
  164. break;
  165. case BEVEL_IN:
  166. top_in_color = mShadowDark.get();
  167. top_out_color = mShadowLight.get();
  168. bottom_in_color = mHighlightDark.get();
  169. bottom_out_color = mHighlightLight.get();
  170. break;
  171. case BEVEL_BRIGHT:
  172. top_in_color = mHighlightLight.get();
  173. top_out_color = mHighlightLight.get();
  174. bottom_in_color = mHighlightLight.get();
  175. bottom_out_color = mHighlightLight.get();
  176. break;
  177. case BEVEL_NONE:
  178. top_in_color = mShadowDark.get();
  179. top_out_color = mShadowDark.get();
  180. bottom_in_color = mShadowDark.get();
  181. bottom_out_color = mShadowDark.get();
  182. // use defaults
  183. break;
  184. default:
  185. llassert(0);
  186. }
  187. if( mHasKeyboardFocus )
  188. {
  189. top_out_color = focus_color;
  190. bottom_out_color = focus_color;
  191. }
  192. S32 left = 0;
  193. S32 top = getRect().getHeight();
  194. S32 right = getRect().getWidth();
  195. S32 bottom = 0;
  196. // draw borders
  197. gGL.color3fv( top_out_color.mV );
  198. gl_line_2d(left, bottom, left, top-1);
  199. gl_line_2d(left, top-1, right, top-1);
  200. gGL.color3fv( top_in_color.mV );
  201. gl_line_2d(left+1, bottom+1, left+1, top-2);
  202. gl_line_2d(left+1, top-2, right-1, top-2);
  203. gGL.color3fv( bottom_out_color.mV );
  204. gl_line_2d(right-1, top-1, right-1, bottom);
  205. gl_line_2d(left, bottom, right, bottom);
  206. gGL.color3fv( bottom_in_color.mV );
  207. gl_line_2d(right-2, top-2, right-2, bottom+1);
  208. gl_line_2d(left+1, bottom+1, right-1, bottom+1);
  209. }
  210. BOOL LLViewBorder::getBevelFromAttribute(LLXMLNodePtr node, LLViewBorder::EBevel& bevel_style)
  211. {
  212. if (node->hasAttribute("bevel_style"))
  213. {
  214. std::string bevel_string;
  215. node->getAttributeString("bevel_style", bevel_string);
  216. LLStringUtil::toLower(bevel_string);
  217. if (bevel_string == "none")
  218. {
  219. bevel_style = LLViewBorder::BEVEL_NONE;
  220. }
  221. else if (bevel_string == "in")
  222. {
  223. bevel_style = LLViewBorder::BEVEL_IN;
  224. }
  225. else if (bevel_string == "out")
  226. {
  227. bevel_style = LLViewBorder::BEVEL_OUT;
  228. }
  229. else if (bevel_string == "bright")
  230. {
  231. bevel_style = LLViewBorder::BEVEL_BRIGHT;
  232. }
  233. return TRUE;
  234. }
  235. return FALSE;
  236. }