PageRenderTime 1146ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/newview/llpanelface.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 1185 lines | 958 code | 137 blank | 90 comment | 109 complexity | 00f6f95ef9d4afb77952c9bb250e70b8 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llpanelface.cpp
  3. * @brief Panel in the tools floater for editing face textures, colors, etc.
  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. #include "llviewerprecompiledheaders.h"
  27. // file include
  28. #include "llpanelface.h"
  29. // library includes
  30. #include "llcalc.h"
  31. #include "llerror.h"
  32. #include "llfocusmgr.h"
  33. #include "llrect.h"
  34. #include "llstring.h"
  35. #include "llfontgl.h"
  36. // project includes
  37. #include "llbutton.h"
  38. #include "llcheckboxctrl.h"
  39. #include "llcolorswatch.h"
  40. #include "llcombobox.h"
  41. #include "lldrawpoolbump.h"
  42. #include "llface.h"
  43. #include "lllineeditor.h"
  44. #include "llmediaentry.h"
  45. #include "llresmgr.h"
  46. #include "llselectmgr.h"
  47. #include "llspinctrl.h"
  48. #include "lltextbox.h"
  49. #include "lltexturectrl.h"
  50. #include "lltextureentry.h"
  51. #include "lltooldraganddrop.h"
  52. #include "llui.h"
  53. #include "llviewercontrol.h"
  54. #include "llviewermedia.h"
  55. #include "llviewerobject.h"
  56. #include "llviewerstats.h"
  57. #include "llvovolume.h"
  58. #include "lluictrlfactory.h"
  59. #include "llpluginclassmedia.h"
  60. #include "llviewertexturelist.h"
  61. //
  62. // Methods
  63. //
  64. BOOL LLPanelFace::postBuild()
  65. {
  66. childSetCommitCallback("combobox shininess",&LLPanelFace::onCommitShiny,this);
  67. childSetCommitCallback("combobox bumpiness",&LLPanelFace::onCommitBump,this);
  68. childSetCommitCallback("TexScaleU",&LLPanelFace::onCommitTextureInfo, this);
  69. childSetCommitCallback("checkbox flip s",&LLPanelFace::onCommitTextureInfo, this);
  70. childSetCommitCallback("TexScaleV",&LLPanelFace::onCommitTextureInfo, this);
  71. childSetCommitCallback("checkbox flip t",&LLPanelFace::onCommitTextureInfo, this);
  72. childSetCommitCallback("TexRot",&LLPanelFace::onCommitTextureInfo, this);
  73. childSetAction("button apply",&LLPanelFace::onClickApply,this);
  74. childSetCommitCallback("checkbox planar align",&LLPanelFace::onCommitPlanarAlign, this);
  75. childSetCommitCallback("TexOffsetU",LLPanelFace::onCommitTextureInfo, this);
  76. childSetCommitCallback("TexOffsetV",LLPanelFace::onCommitTextureInfo, this);
  77. childSetAction("button align",&LLPanelFace::onClickAutoFix,this);
  78. LLRect rect = this->getRect();
  79. LLTextureCtrl* mTextureCtrl;
  80. LLColorSwatchCtrl* mColorSwatch;
  81. LLComboBox* mComboTexGen;
  82. LLCheckBoxCtrl *mCheckFullbright;
  83. LLTextBox* mLabelColorTransp;
  84. LLSpinCtrl* mCtrlColorTransp; // transparency = 1 - alpha
  85. LLSpinCtrl* mCtrlGlow;
  86. setMouseOpaque(FALSE);
  87. mTextureCtrl = getChild<LLTextureCtrl>("texture control");
  88. if(mTextureCtrl)
  89. {
  90. mTextureCtrl->setDefaultImageAssetID(LLUUID( gSavedSettings.getString( "DefaultObjectTexture" )));
  91. mTextureCtrl->setCommitCallback( boost::bind(&LLPanelFace::onCommitTexture, this, _2) );
  92. mTextureCtrl->setOnCancelCallback( boost::bind(&LLPanelFace::onCancelTexture, this, _2) );
  93. mTextureCtrl->setOnSelectCallback( boost::bind(&LLPanelFace::onSelectTexture, this, _2) );
  94. mTextureCtrl->setDragCallback(boost::bind(&LLPanelFace::onDragTexture, this, _2));
  95. mTextureCtrl->setFollowsTop();
  96. mTextureCtrl->setFollowsLeft();
  97. // Don't allow (no copy) or (no transfer) textures to be selected during immediate mode
  98. mTextureCtrl->setImmediateFilterPermMask(PERM_COPY | PERM_TRANSFER);
  99. // Allow any texture to be used during non-immediate mode.
  100. mTextureCtrl->setNonImmediateFilterPermMask(PERM_NONE);
  101. LLAggregatePermissions texture_perms;
  102. if (LLSelectMgr::getInstance()->selectGetAggregateTexturePermissions(texture_perms))
  103. {
  104. BOOL can_copy =
  105. texture_perms.getValue(PERM_COPY) == LLAggregatePermissions::AP_EMPTY ||
  106. texture_perms.getValue(PERM_COPY) == LLAggregatePermissions::AP_ALL;
  107. BOOL can_transfer =
  108. texture_perms.getValue(PERM_TRANSFER) == LLAggregatePermissions::AP_EMPTY ||
  109. texture_perms.getValue(PERM_TRANSFER) == LLAggregatePermissions::AP_ALL;
  110. mTextureCtrl->setCanApplyImmediately(can_copy && can_transfer);
  111. }
  112. else
  113. {
  114. mTextureCtrl->setCanApplyImmediately(FALSE);
  115. }
  116. }
  117. mColorSwatch = getChild<LLColorSwatchCtrl>("colorswatch");
  118. if(mColorSwatch)
  119. {
  120. mColorSwatch->setCommitCallback(boost::bind(&LLPanelFace::onCommitColor, this, _2));
  121. mColorSwatch->setOnCancelCallback(boost::bind(&LLPanelFace::onCancelColor, this, _2));
  122. mColorSwatch->setOnSelectCallback(boost::bind(&LLPanelFace::onSelectColor, this, _2));
  123. mColorSwatch->setFollowsTop();
  124. mColorSwatch->setFollowsLeft();
  125. mColorSwatch->setCanApplyImmediately(TRUE);
  126. }
  127. mLabelColorTransp = getChild<LLTextBox>("color trans");
  128. if(mLabelColorTransp)
  129. {
  130. mLabelColorTransp->setFollowsTop();
  131. mLabelColorTransp->setFollowsLeft();
  132. }
  133. mCtrlColorTransp = getChild<LLSpinCtrl>("ColorTrans");
  134. if(mCtrlColorTransp)
  135. {
  136. mCtrlColorTransp->setCommitCallback(boost::bind(&LLPanelFace::onCommitAlpha, this, _2));
  137. mCtrlColorTransp->setPrecision(0);
  138. mCtrlColorTransp->setFollowsTop();
  139. mCtrlColorTransp->setFollowsLeft();
  140. }
  141. mCheckFullbright = getChild<LLCheckBoxCtrl>("checkbox fullbright");
  142. if (mCheckFullbright)
  143. {
  144. mCheckFullbright->setCommitCallback(LLPanelFace::onCommitFullbright, this);
  145. }
  146. mComboTexGen = getChild<LLComboBox>("combobox texgen");
  147. if(mComboTexGen)
  148. {
  149. mComboTexGen->setCommitCallback(LLPanelFace::onCommitTexGen, this);
  150. mComboTexGen->setFollows(FOLLOWS_LEFT | FOLLOWS_TOP);
  151. }
  152. mCtrlGlow = getChild<LLSpinCtrl>("glow");
  153. if(mCtrlGlow)
  154. {
  155. mCtrlGlow->setCommitCallback(LLPanelFace::onCommitGlow, this);
  156. }
  157. clearCtrls();
  158. return TRUE;
  159. }
  160. LLPanelFace::LLPanelFace()
  161. : LLPanel()
  162. {
  163. }
  164. LLPanelFace::~LLPanelFace()
  165. {
  166. // Children all cleaned up by default view destructor.
  167. }
  168. void LLPanelFace::sendTexture()
  169. {
  170. LLTextureCtrl* mTextureCtrl = getChild<LLTextureCtrl>("texture control");
  171. if(!mTextureCtrl) return;
  172. if( !mTextureCtrl->getTentative() )
  173. {
  174. // we grab the item id first, because we want to do a
  175. // permissions check in the selection manager. ARGH!
  176. LLUUID id = mTextureCtrl->getImageItemID();
  177. if(id.isNull())
  178. {
  179. id = mTextureCtrl->getImageAssetID();
  180. }
  181. LLSelectMgr::getInstance()->selectionSetImage(id);
  182. }
  183. }
  184. void LLPanelFace::sendBump()
  185. {
  186. LLComboBox* mComboBumpiness = getChild<LLComboBox>("combobox bumpiness");
  187. if(!mComboBumpiness)return;
  188. U8 bump = (U8) mComboBumpiness->getCurrentIndex() & TEM_BUMP_MASK;
  189. LLSelectMgr::getInstance()->selectionSetBumpmap( bump );
  190. }
  191. void LLPanelFace::sendTexGen()
  192. {
  193. LLComboBox* mComboTexGen = getChild<LLComboBox>("combobox texgen");
  194. if(!mComboTexGen)return;
  195. U8 tex_gen = (U8) mComboTexGen->getCurrentIndex() << TEM_TEX_GEN_SHIFT;
  196. LLSelectMgr::getInstance()->selectionSetTexGen( tex_gen );
  197. }
  198. void LLPanelFace::sendShiny()
  199. {
  200. LLComboBox* mComboShininess = getChild<LLComboBox>("combobox shininess");
  201. if(!mComboShininess)return;
  202. U8 shiny = (U8) mComboShininess->getCurrentIndex() & TEM_SHINY_MASK;
  203. LLSelectMgr::getInstance()->selectionSetShiny( shiny );
  204. }
  205. void LLPanelFace::sendFullbright()
  206. {
  207. LLCheckBoxCtrl* mCheckFullbright = getChild<LLCheckBoxCtrl>("checkbox fullbright");
  208. if(!mCheckFullbright)return;
  209. U8 fullbright = mCheckFullbright->get() ? TEM_FULLBRIGHT_MASK : 0;
  210. LLSelectMgr::getInstance()->selectionSetFullbright( fullbright );
  211. }
  212. void LLPanelFace::sendColor()
  213. {
  214. LLColorSwatchCtrl* mColorSwatch = getChild<LLColorSwatchCtrl>("colorswatch");
  215. if(!mColorSwatch)return;
  216. LLColor4 color = mColorSwatch->get();
  217. LLSelectMgr::getInstance()->selectionSetColorOnly( color );
  218. }
  219. void LLPanelFace::sendAlpha()
  220. {
  221. LLSpinCtrl* mCtrlColorTransp = getChild<LLSpinCtrl>("ColorTrans");
  222. if(!mCtrlColorTransp)return;
  223. F32 alpha = (100.f - mCtrlColorTransp->get()) / 100.f;
  224. LLSelectMgr::getInstance()->selectionSetAlphaOnly( alpha );
  225. }
  226. void LLPanelFace::sendGlow()
  227. {
  228. LLSpinCtrl* mCtrlGlow = getChild<LLSpinCtrl>("glow");
  229. llassert(mCtrlGlow);
  230. if (mCtrlGlow)
  231. {
  232. F32 glow = mCtrlGlow->get();
  233. LLSelectMgr::getInstance()->selectionSetGlow( glow );
  234. }
  235. }
  236. struct LLPanelFaceSetTEFunctor : public LLSelectedTEFunctor
  237. {
  238. LLPanelFaceSetTEFunctor(LLPanelFace* panel) : mPanel(panel) {}
  239. virtual bool apply(LLViewerObject* object, S32 te)
  240. {
  241. BOOL valid;
  242. F32 value;
  243. LLSpinCtrl* ctrlTexScaleS = mPanel->getChild<LLSpinCtrl>("TexScaleU");
  244. LLSpinCtrl* ctrlTexScaleT = mPanel->getChild<LLSpinCtrl>("TexScaleV");
  245. LLSpinCtrl* ctrlTexOffsetS = mPanel->getChild<LLSpinCtrl>("TexOffsetU");
  246. LLSpinCtrl* ctrlTexOffsetT = mPanel->getChild<LLSpinCtrl>("TexOffsetV");
  247. LLSpinCtrl* ctrlTexRotation = mPanel->getChild<LLSpinCtrl>("TexRot");
  248. LLCheckBoxCtrl* checkFlipScaleS = mPanel->getChild<LLCheckBoxCtrl>("checkbox flip s");
  249. LLCheckBoxCtrl* checkFlipScaleT = mPanel->getChild<LLCheckBoxCtrl>("checkbox flip t");
  250. LLComboBox* comboTexGen = mPanel->getChild<LLComboBox>("combobox texgen");
  251. llassert(comboTexGen);
  252. llassert(object);
  253. if (ctrlTexScaleS)
  254. {
  255. valid = !ctrlTexScaleS->getTentative() || !checkFlipScaleS->getTentative();
  256. if (valid)
  257. {
  258. value = ctrlTexScaleS->get();
  259. if( checkFlipScaleS->get() )
  260. {
  261. value = -value;
  262. }
  263. if (comboTexGen &&
  264. comboTexGen->getCurrentIndex() == 1)
  265. {
  266. value *= 0.5f;
  267. }
  268. object->setTEScaleS( te, value );
  269. }
  270. }
  271. if (ctrlTexScaleT)
  272. {
  273. valid = !ctrlTexScaleT->getTentative() || !checkFlipScaleT->getTentative();
  274. if (valid)
  275. {
  276. value = ctrlTexScaleT->get();
  277. if( checkFlipScaleT->get() )
  278. {
  279. value = -value;
  280. }
  281. if (comboTexGen &&
  282. comboTexGen->getCurrentIndex() == 1)
  283. {
  284. value *= 0.5f;
  285. }
  286. object->setTEScaleT( te, value );
  287. }
  288. }
  289. if (ctrlTexOffsetS)
  290. {
  291. valid = !ctrlTexOffsetS->getTentative();
  292. if (valid)
  293. {
  294. value = ctrlTexOffsetS->get();
  295. object->setTEOffsetS( te, value );
  296. }
  297. }
  298. if (ctrlTexOffsetT)
  299. {
  300. valid = !ctrlTexOffsetT->getTentative();
  301. if (valid)
  302. {
  303. value = ctrlTexOffsetT->get();
  304. object->setTEOffsetT( te, value );
  305. }
  306. }
  307. if (ctrlTexRotation)
  308. {
  309. valid = !ctrlTexRotation->getTentative();
  310. if (valid)
  311. {
  312. value = ctrlTexRotation->get() * DEG_TO_RAD;
  313. object->setTERotation( te, value );
  314. }
  315. }
  316. return true;
  317. }
  318. private:
  319. LLPanelFace* mPanel;
  320. };
  321. // Functor that aligns a face to mCenterFace
  322. struct LLPanelFaceSetAlignedTEFunctor : public LLSelectedTEFunctor
  323. {
  324. LLPanelFaceSetAlignedTEFunctor(LLPanelFace* panel, LLFace* center_face) :
  325. mPanel(panel),
  326. mCenterFace(center_face) {}
  327. virtual bool apply(LLViewerObject* object, S32 te)
  328. {
  329. LLFace* facep = object->mDrawable->getFace(te);
  330. if (!facep)
  331. {
  332. return true;
  333. }
  334. if (facep->getViewerObject()->getVolume()->getNumVolumeFaces() <= te)
  335. {
  336. return true;
  337. }
  338. bool set_aligned = true;
  339. if (facep == mCenterFace)
  340. {
  341. set_aligned = false;
  342. }
  343. if (set_aligned)
  344. {
  345. LLVector2 uv_offset, uv_scale;
  346. F32 uv_rot;
  347. set_aligned = facep->calcAlignedPlanarTE(mCenterFace, &uv_offset, &uv_scale, &uv_rot);
  348. if (set_aligned)
  349. {
  350. object->setTEOffset(te, uv_offset.mV[VX], uv_offset.mV[VY]);
  351. object->setTEScale(te, uv_scale.mV[VX], uv_scale.mV[VY]);
  352. object->setTERotation(te, uv_rot);
  353. }
  354. }
  355. if (!set_aligned)
  356. {
  357. LLPanelFaceSetTEFunctor setfunc(mPanel);
  358. setfunc.apply(object, te);
  359. }
  360. return true;
  361. }
  362. private:
  363. LLPanelFace* mPanel;
  364. LLFace* mCenterFace;
  365. };
  366. // Functor that tests if a face is aligned to mCenterFace
  367. struct LLPanelFaceGetIsAlignedTEFunctor : public LLSelectedTEFunctor
  368. {
  369. LLPanelFaceGetIsAlignedTEFunctor(LLFace* center_face) :
  370. mCenterFace(center_face) {}
  371. virtual bool apply(LLViewerObject* object, S32 te)
  372. {
  373. LLFace* facep = object->mDrawable->getFace(te);
  374. if (!facep)
  375. {
  376. return false;
  377. }
  378. if (facep->getViewerObject()->getVolume()->getNumVolumeFaces() <= te)
  379. { //volume face does not exist, can't be aligned
  380. return false;
  381. }
  382. if (facep == mCenterFace)
  383. {
  384. return true;
  385. }
  386. LLVector2 aligned_st_offset, aligned_st_scale;
  387. F32 aligned_st_rot;
  388. if ( facep->calcAlignedPlanarTE(mCenterFace, &aligned_st_offset, &aligned_st_scale, &aligned_st_rot) )
  389. {
  390. const LLTextureEntry* tep = facep->getTextureEntry();
  391. LLVector2 st_offset, st_scale;
  392. tep->getOffset(&st_offset.mV[VX], &st_offset.mV[VY]);
  393. tep->getScale(&st_scale.mV[VX], &st_scale.mV[VY]);
  394. F32 st_rot = tep->getRotation();
  395. // needs a fuzzy comparison, because of fp errors
  396. if (is_approx_equal_fraction(st_offset.mV[VX], aligned_st_offset.mV[VX], 12) &&
  397. is_approx_equal_fraction(st_offset.mV[VY], aligned_st_offset.mV[VY], 12) &&
  398. is_approx_equal_fraction(st_scale.mV[VX], aligned_st_scale.mV[VX], 12) &&
  399. is_approx_equal_fraction(st_scale.mV[VY], aligned_st_scale.mV[VY], 12) &&
  400. is_approx_equal_fraction(st_rot, aligned_st_rot, 14))
  401. {
  402. return true;
  403. }
  404. }
  405. return false;
  406. }
  407. private:
  408. LLFace* mCenterFace;
  409. };
  410. struct LLPanelFaceSendFunctor : public LLSelectedObjectFunctor
  411. {
  412. virtual bool apply(LLViewerObject* object)
  413. {
  414. object->sendTEUpdate();
  415. return true;
  416. }
  417. };
  418. void LLPanelFace::sendTextureInfo()
  419. {
  420. if ((bool)childGetValue("checkbox planar align").asBoolean())
  421. {
  422. struct f1 : public LLSelectedTEGetFunctor<LLFace *>
  423. {
  424. LLFace* get(LLViewerObject* object, S32 te)
  425. {
  426. return (object->mDrawable) ? object->mDrawable->getFace(te): NULL;
  427. }
  428. } get_last_face_func;
  429. LLFace* last_face;
  430. LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue(&get_last_face_func, last_face);
  431. LLPanelFaceSetAlignedTEFunctor setfunc(this, last_face);
  432. LLSelectMgr::getInstance()->getSelection()->applyToTEs(&setfunc);
  433. }
  434. else
  435. {
  436. LLPanelFaceSetTEFunctor setfunc(this);
  437. LLSelectMgr::getInstance()->getSelection()->applyToTEs(&setfunc);
  438. }
  439. LLPanelFaceSendFunctor sendfunc;
  440. LLSelectMgr::getInstance()->getSelection()->applyToObjects(&sendfunc);
  441. }
  442. void LLPanelFace::getState()
  443. {
  444. LLViewerObject* objectp = LLSelectMgr::getInstance()->getSelection()->getFirstObject();
  445. if( objectp
  446. && objectp->getPCode() == LL_PCODE_VOLUME
  447. && objectp->permModify())
  448. {
  449. BOOL editable = objectp->permModify();
  450. // only turn on auto-adjust button if there is a media renderer and the media is loaded
  451. getChildView("textbox autofix")->setEnabled(editable);
  452. getChildView("button align")->setEnabled(editable);
  453. //if ( LLMediaEngine::getInstance()->getMediaRenderer () )
  454. // if ( LLMediaEngine::getInstance()->getMediaRenderer ()->isLoaded () )
  455. // {
  456. //
  457. // //mLabelTexAutoFix->setEnabled ( editable );
  458. //
  459. // //mBtnAutoFix->setEnabled ( editable );
  460. // }
  461. getChildView("button apply")->setEnabled(editable);
  462. bool identical;
  463. LLTextureCtrl* texture_ctrl = getChild<LLTextureCtrl>("texture control");
  464. // Texture
  465. {
  466. LLUUID id;
  467. struct f1 : public LLSelectedTEGetFunctor<LLUUID>
  468. {
  469. LLUUID get(LLViewerObject* object, S32 te_index)
  470. {
  471. LLUUID id;
  472. LLViewerTexture* image = object->getTEImage(te_index);
  473. if (image) id = image->getID();
  474. if (!id.isNull() && LLViewerMedia::textureHasMedia(id))
  475. {
  476. LLTextureEntry *te = object->getTE(te_index);
  477. if (te)
  478. {
  479. LLViewerTexture* tex = te->getID().notNull() ? gTextureList.findImage(te->getID()) : NULL ;
  480. if(!tex)
  481. {
  482. tex = LLViewerFetchedTexture::sDefaultImagep;
  483. }
  484. if (tex)
  485. {
  486. id = tex->getID();
  487. }
  488. }
  489. }
  490. return id;
  491. }
  492. } func;
  493. identical = LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue( &func, id );
  494. if(LLViewerMedia::textureHasMedia(id))
  495. {
  496. getChildView("textbox autofix")->setEnabled(editable);
  497. getChildView("button align")->setEnabled(editable);
  498. }
  499. if (identical)
  500. {
  501. // All selected have the same texture
  502. if(texture_ctrl)
  503. {
  504. texture_ctrl->setTentative( FALSE );
  505. texture_ctrl->setEnabled( editable );
  506. texture_ctrl->setImageAssetID( id );
  507. }
  508. }
  509. else
  510. {
  511. if(texture_ctrl)
  512. {
  513. if( id.isNull() )
  514. {
  515. // None selected
  516. texture_ctrl->setTentative( FALSE );
  517. texture_ctrl->setEnabled( FALSE );
  518. texture_ctrl->setImageAssetID( LLUUID::null );
  519. }
  520. else
  521. {
  522. // Tentative: multiple selected with different textures
  523. texture_ctrl->setTentative( TRUE );
  524. texture_ctrl->setEnabled( editable );
  525. texture_ctrl->setImageAssetID( id );
  526. }
  527. }
  528. }
  529. }
  530. LLAggregatePermissions texture_perms;
  531. if(texture_ctrl)
  532. {
  533. // texture_ctrl->setValid( editable );
  534. if (LLSelectMgr::getInstance()->selectGetAggregateTexturePermissions(texture_perms))
  535. {
  536. BOOL can_copy =
  537. texture_perms.getValue(PERM_COPY) == LLAggregatePermissions::AP_EMPTY ||
  538. texture_perms.getValue(PERM_COPY) == LLAggregatePermissions::AP_ALL;
  539. BOOL can_transfer =
  540. texture_perms.getValue(PERM_TRANSFER) == LLAggregatePermissions::AP_EMPTY ||
  541. texture_perms.getValue(PERM_TRANSFER) == LLAggregatePermissions::AP_ALL;
  542. texture_ctrl->setCanApplyImmediately(can_copy && can_transfer);
  543. }
  544. else
  545. {
  546. texture_ctrl->setCanApplyImmediately(FALSE);
  547. }
  548. }
  549. // planar align
  550. bool align_planar = false;
  551. bool identical_planar_aligned = false;
  552. bool is_planar = false;
  553. {
  554. LLCheckBoxCtrl* cb_planar_align = getChild<LLCheckBoxCtrl>("checkbox planar align");
  555. align_planar = (cb_planar_align && cb_planar_align->get());
  556. struct f1 : public LLSelectedTEGetFunctor<bool>
  557. {
  558. bool get(LLViewerObject* object, S32 face)
  559. {
  560. return (object->getTE(face)->getTexGen() == LLTextureEntry::TEX_GEN_PLANAR);
  561. }
  562. } func;
  563. bool texgens_identical = LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue( &func, is_planar );
  564. bool enabled = (editable && texgens_identical && is_planar);
  565. childSetValue("checkbox planar align", align_planar && enabled);
  566. childSetEnabled("checkbox planar align", enabled);
  567. if (align_planar && enabled)
  568. {
  569. struct f2 : public LLSelectedTEGetFunctor<LLFace *>
  570. {
  571. LLFace* get(LLViewerObject* object, S32 te)
  572. {
  573. return (object->mDrawable) ? object->mDrawable->getFace(te): NULL;
  574. }
  575. } get_te_face_func;
  576. LLFace* last_face;
  577. LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue(&get_te_face_func, last_face);
  578. LLPanelFaceGetIsAlignedTEFunctor get_is_aligend_func(last_face);
  579. // this will determine if the texture param controls are tentative:
  580. identical_planar_aligned = LLSelectMgr::getInstance()->getSelection()->applyToTEs(&get_is_aligend_func);
  581. }
  582. }
  583. // Texture scale
  584. {
  585. F32 scale_s = 1.f;
  586. struct f2 : public LLSelectedTEGetFunctor<F32>
  587. {
  588. F32 get(LLViewerObject* object, S32 face)
  589. {
  590. return object->getTE(face)->mScaleS;
  591. }
  592. } func;
  593. identical = LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue( &func, scale_s );
  594. identical = align_planar ? identical_planar_aligned : identical;
  595. getChild<LLUICtrl>("TexScaleU")->setValue(editable ? llabs(scale_s) : 0);
  596. getChild<LLUICtrl>("TexScaleU")->setTentative(LLSD((BOOL)(!identical)));
  597. getChildView("TexScaleU")->setEnabled(editable);
  598. getChild<LLUICtrl>("checkbox flip s")->setValue(LLSD((BOOL)(scale_s < 0 ? TRUE : FALSE )));
  599. getChild<LLUICtrl>("checkbox flip s")->setTentative(LLSD((BOOL)((!identical) ? TRUE : FALSE )));
  600. getChildView("checkbox flip s")->setEnabled(editable);
  601. }
  602. {
  603. F32 scale_t = 1.f;
  604. struct f3 : public LLSelectedTEGetFunctor<F32>
  605. {
  606. F32 get(LLViewerObject* object, S32 face)
  607. {
  608. return object->getTE(face)->mScaleT;
  609. }
  610. } func;
  611. identical = LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue( &func, scale_t );
  612. identical = align_planar ? identical_planar_aligned : identical;
  613. getChild<LLUICtrl>("TexScaleV")->setValue(llabs(editable ? llabs(scale_t) : 0));
  614. getChild<LLUICtrl>("TexScaleV")->setTentative(LLSD((BOOL)(!identical)));
  615. getChildView("TexScaleV")->setEnabled(editable);
  616. getChild<LLUICtrl>("checkbox flip t")->setValue(LLSD((BOOL)(scale_t< 0 ? TRUE : FALSE )));
  617. getChild<LLUICtrl>("checkbox flip t")->setTentative(LLSD((BOOL)((!identical) ? TRUE : FALSE )));
  618. getChildView("checkbox flip t")->setEnabled(editable);
  619. }
  620. // Texture offset
  621. {
  622. getChildView("tex offset")->setEnabled(editable);
  623. F32 offset_s = 0.f;
  624. struct f4 : public LLSelectedTEGetFunctor<F32>
  625. {
  626. F32 get(LLViewerObject* object, S32 face)
  627. {
  628. return object->getTE(face)->mOffsetS;
  629. }
  630. } func;
  631. identical = LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue( &func, offset_s );
  632. identical = align_planar ? identical_planar_aligned : identical;
  633. getChild<LLUICtrl>("TexOffsetU")->setValue(editable ? offset_s : 0);
  634. getChild<LLUICtrl>("TexOffsetU")->setTentative(!identical);
  635. getChildView("TexOffsetU")->setEnabled(editable);
  636. }
  637. {
  638. F32 offset_t = 0.f;
  639. struct f5 : public LLSelectedTEGetFunctor<F32>
  640. {
  641. F32 get(LLViewerObject* object, S32 face)
  642. {
  643. return object->getTE(face)->mOffsetT;
  644. }
  645. } func;
  646. identical = LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue( &func, offset_t );
  647. identical = align_planar ? identical_planar_aligned : identical;
  648. getChild<LLUICtrl>("TexOffsetV")->setValue(editable ? offset_t : 0);
  649. getChild<LLUICtrl>("TexOffsetV")->setTentative(!identical);
  650. getChildView("TexOffsetV")->setEnabled(editable);
  651. }
  652. // Texture rotation
  653. {
  654. F32 rotation = 0.f;
  655. struct f6 : public LLSelectedTEGetFunctor<F32>
  656. {
  657. F32 get(LLViewerObject* object, S32 face)
  658. {
  659. return object->getTE(face)->mRotation;
  660. }
  661. } func;
  662. identical = LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue( &func, rotation );
  663. identical = align_planar ? identical_planar_aligned : identical;
  664. getChild<LLUICtrl>("TexRot")->setValue(editable ? rotation * RAD_TO_DEG : 0);
  665. getChild<LLUICtrl>("TexRot")->setTentative(!identical);
  666. getChildView("TexRot")->setEnabled(editable);
  667. }
  668. // Color swatch
  669. LLColorSwatchCtrl* mColorSwatch = getChild<LLColorSwatchCtrl>("colorswatch");
  670. LLColor4 color = LLColor4::white;
  671. if(mColorSwatch)
  672. {
  673. struct f7 : public LLSelectedTEGetFunctor<LLColor4>
  674. {
  675. LLColor4 get(LLViewerObject* object, S32 face)
  676. {
  677. return object->getTE(face)->getColor();
  678. }
  679. } func;
  680. identical = LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue( &func, color );
  681. mColorSwatch->setOriginal(color);
  682. mColorSwatch->set(color, TRUE);
  683. mColorSwatch->setValid(editable);
  684. mColorSwatch->setEnabled( editable );
  685. mColorSwatch->setCanApplyImmediately( editable );
  686. }
  687. // Color transparency
  688. {
  689. getChildView("color trans")->setEnabled(editable);
  690. }
  691. F32 transparency = (1.f - color.mV[VALPHA]) * 100.f;
  692. {
  693. getChild<LLUICtrl>("ColorTrans")->setValue(editable ? transparency : 0);
  694. getChildView("ColorTrans")->setEnabled(editable);
  695. }
  696. {
  697. F32 glow = 0.f;
  698. struct f8 : public LLSelectedTEGetFunctor<F32>
  699. {
  700. F32 get(LLViewerObject* object, S32 face)
  701. {
  702. return object->getTE(face)->getGlow();
  703. }
  704. } func;
  705. identical = LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue( &func, glow );
  706. getChild<LLUICtrl>("glow")->setValue(glow);
  707. getChildView("glow")->setEnabled(editable);
  708. getChild<LLUICtrl>("glow")->setTentative(!identical);
  709. getChildView("glow label")->setEnabled(editable);
  710. }
  711. // Bump
  712. {
  713. F32 shinyf = 0.f;
  714. struct f9 : public LLSelectedTEGetFunctor<F32>
  715. {
  716. F32 get(LLViewerObject* object, S32 face)
  717. {
  718. return (F32)(object->getTE(face)->getShiny());
  719. }
  720. } func;
  721. identical = LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue( &func, shinyf );
  722. LLCtrlSelectionInterface* combobox_shininess =
  723. childGetSelectionInterface("combobox shininess");
  724. if (combobox_shininess)
  725. {
  726. combobox_shininess->selectNthItem((S32)shinyf);
  727. }
  728. else
  729. {
  730. llwarns << "failed childGetSelectionInterface for 'combobox shininess'" << llendl;
  731. }
  732. getChildView("combobox shininess")->setEnabled(editable);
  733. getChild<LLUICtrl>("combobox shininess")->setTentative(!identical);
  734. getChildView("label shininess")->setEnabled(editable);
  735. }
  736. {
  737. F32 bumpf = 0.f;
  738. struct f10 : public LLSelectedTEGetFunctor<F32>
  739. {
  740. F32 get(LLViewerObject* object, S32 face)
  741. {
  742. return (F32)(object->getTE(face)->getBumpmap());
  743. }
  744. } func;
  745. identical = LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue( &func, bumpf );
  746. LLCtrlSelectionInterface* combobox_bumpiness =
  747. childGetSelectionInterface("combobox bumpiness");
  748. if (combobox_bumpiness)
  749. {
  750. combobox_bumpiness->selectNthItem((S32)bumpf);
  751. }
  752. else
  753. {
  754. llwarns << "failed childGetSelectionInterface for 'combobox bumpiness'" << llendl;
  755. }
  756. getChildView("combobox bumpiness")->setEnabled(editable);
  757. getChild<LLUICtrl>("combobox bumpiness")->setTentative(!identical);
  758. getChildView("label bumpiness")->setEnabled(editable);
  759. }
  760. {
  761. F32 genf = 0.f;
  762. struct f11 : public LLSelectedTEGetFunctor<F32>
  763. {
  764. F32 get(LLViewerObject* object, S32 face)
  765. {
  766. return (F32)(object->getTE(face)->getTexGen());
  767. }
  768. } func;
  769. identical = LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue( &func, genf );
  770. S32 selected_texgen = ((S32) genf) >> TEM_TEX_GEN_SHIFT;
  771. LLCtrlSelectionInterface* combobox_texgen =
  772. childGetSelectionInterface("combobox texgen");
  773. if (combobox_texgen)
  774. {
  775. combobox_texgen->selectNthItem(selected_texgen);
  776. }
  777. else
  778. {
  779. llwarns << "failed childGetSelectionInterface for 'combobox texgen'" << llendl;
  780. }
  781. getChildView("combobox texgen")->setEnabled(editable);
  782. getChild<LLUICtrl>("combobox texgen")->setTentative(!identical);
  783. getChildView("tex gen")->setEnabled(editable);
  784. if (selected_texgen == 1)
  785. {
  786. getChild<LLUICtrl>("TexScaleU")->setValue(2.0f * getChild<LLUICtrl>("TexScaleU")->getValue().asReal() );
  787. getChild<LLUICtrl>("TexScaleV")->setValue(2.0f * getChild<LLUICtrl>("TexScaleV")->getValue().asReal() );
  788. }
  789. }
  790. {
  791. F32 fullbrightf = 0.f;
  792. struct f12 : public LLSelectedTEGetFunctor<F32>
  793. {
  794. F32 get(LLViewerObject* object, S32 face)
  795. {
  796. return (F32)(object->getTE(face)->getFullbright());
  797. }
  798. } func;
  799. identical = LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue( &func, fullbrightf );
  800. getChild<LLUICtrl>("checkbox fullbright")->setValue((S32)fullbrightf);
  801. getChildView("checkbox fullbright")->setEnabled(editable);
  802. getChild<LLUICtrl>("checkbox fullbright")->setTentative(!identical);
  803. }
  804. // Repeats per meter label
  805. {
  806. getChildView("rpt")->setEnabled(editable);
  807. }
  808. // Repeats per meter
  809. {
  810. F32 repeats = 1.f;
  811. struct f13 : public LLSelectedTEGetFunctor<F32>
  812. {
  813. F32 get(LLViewerObject* object, S32 face)
  814. {
  815. U32 s_axis = VX;
  816. U32 t_axis = VY;
  817. // BUG: Only repeats along S axis
  818. // BUG: Only works for boxes.
  819. LLPrimitive::getTESTAxes(face, &s_axis, &t_axis);
  820. return object->getTE(face)->mScaleS / object->getScale().mV[s_axis];
  821. }
  822. } func;
  823. identical = LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue( &func, repeats );
  824. getChild<LLUICtrl>("rptctrl")->setValue(editable ? repeats : 0);
  825. getChild<LLUICtrl>("rptctrl")->setTentative(!identical);
  826. LLComboBox* mComboTexGen = getChild<LLComboBox>("combobox texgen");
  827. if (mComboTexGen)
  828. {
  829. BOOL enabled = editable && (!mComboTexGen || mComboTexGen->getCurrentIndex() != 1);
  830. getChildView("rptctrl")->setEnabled(enabled);
  831. getChildView("button apply")->setEnabled(enabled);
  832. }
  833. }
  834. // Set variable values for numeric expressions
  835. LLCalc* calcp = LLCalc::getInstance();
  836. calcp->setVar(LLCalc::TEX_U_SCALE, childGetValue("TexScaleU").asReal());
  837. calcp->setVar(LLCalc::TEX_V_SCALE, childGetValue("TexScaleV").asReal());
  838. calcp->setVar(LLCalc::TEX_U_OFFSET, childGetValue("TexOffsetU").asReal());
  839. calcp->setVar(LLCalc::TEX_V_OFFSET, childGetValue("TexOffsetV").asReal());
  840. calcp->setVar(LLCalc::TEX_ROTATION, childGetValue("TexRot").asReal());
  841. calcp->setVar(LLCalc::TEX_TRANSPARENCY, childGetValue("ColorTrans").asReal());
  842. calcp->setVar(LLCalc::TEX_GLOW, childGetValue("glow").asReal());
  843. }
  844. else
  845. {
  846. // Disable all UICtrls
  847. clearCtrls();
  848. // Disable non-UICtrls
  849. LLTextureCtrl* texture_ctrl = getChild<LLTextureCtrl>("texture control");
  850. if(texture_ctrl)
  851. {
  852. texture_ctrl->setImageAssetID( LLUUID::null );
  853. texture_ctrl->setEnabled( FALSE ); // this is a LLUICtrl, but we don't want it to have keyboard focus so we add it as a child, not a ctrl.
  854. // texture_ctrl->setValid(FALSE);
  855. }
  856. LLColorSwatchCtrl* mColorSwatch = getChild<LLColorSwatchCtrl>("colorswatch");
  857. if(mColorSwatch)
  858. {
  859. mColorSwatch->setEnabled( FALSE );
  860. mColorSwatch->setFallbackImageName("locked_image.j2c" );
  861. mColorSwatch->setValid(FALSE);
  862. }
  863. getChildView("color trans")->setEnabled(FALSE);
  864. getChildView("rpt")->setEnabled(FALSE);
  865. getChildView("tex offset")->setEnabled(FALSE);
  866. getChildView("tex gen")->setEnabled(FALSE);
  867. getChildView("label shininess")->setEnabled(FALSE);
  868. getChildView("label bumpiness")->setEnabled(FALSE);
  869. getChildView("textbox autofix")->setEnabled(FALSE);
  870. getChildView("button align")->setEnabled(FALSE);
  871. getChildView("button apply")->setEnabled(FALSE);
  872. //getChildView("has media")->setEnabled(FALSE);
  873. //getChildView("media info set")->setEnabled(FALSE);
  874. // Set variable values for numeric expressions
  875. LLCalc* calcp = LLCalc::getInstance();
  876. calcp->clearVar(LLCalc::TEX_U_SCALE);
  877. calcp->clearVar(LLCalc::TEX_V_SCALE);
  878. calcp->clearVar(LLCalc::TEX_U_OFFSET);
  879. calcp->clearVar(LLCalc::TEX_V_OFFSET);
  880. calcp->clearVar(LLCalc::TEX_ROTATION);
  881. calcp->clearVar(LLCalc::TEX_TRANSPARENCY);
  882. calcp->clearVar(LLCalc::TEX_GLOW);
  883. }
  884. }
  885. void LLPanelFace::refresh()
  886. {
  887. getState();
  888. }
  889. //
  890. // Static functions
  891. //
  892. // static
  893. F32 LLPanelFace::valueGlow(LLViewerObject* object, S32 face)
  894. {
  895. return (F32)(object->getTE(face)->getGlow());
  896. }
  897. void LLPanelFace::onCommitColor(const LLSD& data)
  898. {
  899. sendColor();
  900. }
  901. void LLPanelFace::onCommitAlpha(const LLSD& data)
  902. {
  903. sendAlpha();
  904. }
  905. void LLPanelFace::onCancelColor(const LLSD& data)
  906. {
  907. LLSelectMgr::getInstance()->selectionRevertColors();
  908. }
  909. void LLPanelFace::onSelectColor(const LLSD& data)
  910. {
  911. LLSelectMgr::getInstance()->saveSelectedObjectColors();
  912. sendColor();
  913. }
  914. // static
  915. void LLPanelFace::onCommitBump(LLUICtrl* ctrl, void* userdata)
  916. {
  917. LLPanelFace* self = (LLPanelFace*) userdata;
  918. self->sendBump();
  919. }
  920. // static
  921. void LLPanelFace::onCommitTexGen(LLUICtrl* ctrl, void* userdata)
  922. {
  923. LLPanelFace* self = (LLPanelFace*) userdata;
  924. self->sendTexGen();
  925. }
  926. // static
  927. void LLPanelFace::onCommitShiny(LLUICtrl* ctrl, void* userdata)
  928. {
  929. LLPanelFace* self = (LLPanelFace*) userdata;
  930. self->sendShiny();
  931. }
  932. // static
  933. void LLPanelFace::onCommitFullbright(LLUICtrl* ctrl, void* userdata)
  934. {
  935. LLPanelFace* self = (LLPanelFace*) userdata;
  936. self->sendFullbright();
  937. }
  938. // static
  939. void LLPanelFace::onCommitGlow(LLUICtrl* ctrl, void* userdata)
  940. {
  941. LLPanelFace* self = (LLPanelFace*) userdata;
  942. self->sendGlow();
  943. }
  944. // static
  945. BOOL LLPanelFace::onDragTexture(LLUICtrl*, LLInventoryItem* item)
  946. {
  947. BOOL accept = TRUE;
  948. for (LLObjectSelection::root_iterator iter = LLSelectMgr::getInstance()->getSelection()->root_begin();
  949. iter != LLSelectMgr::getInstance()->getSelection()->root_end(); iter++)
  950. {
  951. LLSelectNode* node = *iter;
  952. LLViewerObject* obj = node->getObject();
  953. if(!LLToolDragAndDrop::isInventoryDropAcceptable(obj, item))
  954. {
  955. accept = FALSE;
  956. break;
  957. }
  958. }
  959. return accept;
  960. }
  961. void LLPanelFace::onCommitTexture( const LLSD& data )
  962. {
  963. LLViewerStats::getInstance()->incStat(LLViewerStats::ST_EDIT_TEXTURE_COUNT );
  964. sendTexture();
  965. }
  966. void LLPanelFace::onCancelTexture(const LLSD& data)
  967. {
  968. LLSelectMgr::getInstance()->selectionRevertTextures();
  969. }
  970. void LLPanelFace::onSelectTexture(const LLSD& data)
  971. {
  972. LLSelectMgr::getInstance()->saveSelectedObjectTextures();
  973. sendTexture();
  974. }
  975. // static
  976. void LLPanelFace::onCommitTextureInfo( LLUICtrl* ctrl, void* userdata )
  977. {
  978. LLPanelFace* self = (LLPanelFace*) userdata;
  979. self->sendTextureInfo();
  980. }
  981. // Commit the number of repeats per meter
  982. // static
  983. void LLPanelFace::onClickApply(void* userdata)
  984. {
  985. LLPanelFace* self = (LLPanelFace*) userdata;
  986. gFocusMgr.setKeyboardFocus( NULL );
  987. //F32 repeats_per_meter = self->mCtrlRepeatsPerMeter->get();
  988. F32 repeats_per_meter = (F32)self->getChild<LLUICtrl>("rptctrl")->getValue().asReal();//self->mCtrlRepeatsPerMeter->get();
  989. LLSelectMgr::getInstance()->selectionTexScaleAutofit( repeats_per_meter );
  990. }
  991. struct LLPanelFaceSetMediaFunctor : public LLSelectedTEFunctor
  992. {
  993. virtual bool apply(LLViewerObject* object, S32 te)
  994. {
  995. viewer_media_t pMediaImpl;
  996. const LLTextureEntry* tep = object->getTE(te);
  997. const LLMediaEntry* mep = tep->hasMedia() ? tep->getMediaData() : NULL;
  998. if ( mep )
  999. {
  1000. pMediaImpl = LLViewerMedia::getMediaImplFromTextureID(mep->getMediaID());
  1001. }
  1002. if ( pMediaImpl.isNull())
  1003. {
  1004. // If we didn't find face media for this face, check whether this face is showing parcel media.
  1005. pMediaImpl = LLViewerMedia::getMediaImplFromTextureID(tep->getID());
  1006. }
  1007. if ( pMediaImpl.notNull())
  1008. {
  1009. LLPluginClassMedia *media = pMediaImpl->getMediaPlugin();
  1010. if(media)
  1011. {
  1012. S32 media_width = media->getWidth();
  1013. S32 media_height = media->getHeight();
  1014. S32 texture_width = media->getTextureWidth();
  1015. S32 texture_height = media->getTextureHeight();
  1016. F32 scale_s = (F32)media_width / (F32)texture_width;
  1017. F32 scale_t = (F32)media_height / (F32)texture_height;
  1018. // set scale and adjust offset
  1019. object->setTEScaleS( te, scale_s );
  1020. object->setTEScaleT( te, scale_t ); // don't need to flip Y anymore since QT does this for us now.
  1021. object->setTEOffsetS( te, -( 1.0f - scale_s ) / 2.0f );
  1022. object->setTEOffsetT( te, -( 1.0f - scale_t ) / 2.0f );
  1023. }
  1024. }
  1025. return true;
  1026. };
  1027. };
  1028. void LLPanelFace::onClickAutoFix(void* userdata)
  1029. {
  1030. LLPanelFaceSetMediaFunctor setfunc;
  1031. LLSelectMgr::getInstance()->getSelection()->applyToTEs(&setfunc);
  1032. LLPanelFaceSendFunctor sendfunc;
  1033. LLSelectMgr::getInstance()->getSelection()->applyToObjects(&sendfunc);
  1034. }
  1035. // TODO: I don't know who put these in or what these are for???
  1036. void LLPanelFace::setMediaURL(const std::string& url)
  1037. {
  1038. }
  1039. void LLPanelFace::setMediaType(const std::string& mime_type)
  1040. {
  1041. }
  1042. // static
  1043. void LLPanelFace::onCommitPlanarAlign(LLUICtrl* ctrl, void* userdata)
  1044. {
  1045. LLPanelFace* self = (LLPanelFace*) userdata;
  1046. self->getState();
  1047. self->sendTextureInfo();
  1048. }