diff options
Diffstat (limited to 'indra/newview/llpanelface.cpp')
-rw-r--r-- | indra/newview/llpanelface.cpp | 344 |
1 files changed, 243 insertions, 101 deletions
diff --git a/indra/newview/llpanelface.cpp b/indra/newview/llpanelface.cpp index 7d5be39074..bce496cbad 100644 --- a/indra/newview/llpanelface.cpp +++ b/indra/newview/llpanelface.cpp @@ -2,31 +2,25 @@ * @file llpanelface.cpp * @brief Panel in the tools floater for editing face textures, colors, etc. * - * $LicenseInfo:firstyear=2001&license=viewergpl$ - * - * Copyright (c) 2001-2009, Linden Research, Inc. - * + * $LicenseInfo:firstyear=2001&license=viewerlgpl$ * Second Life Viewer Source Code - * The source code in this file ("Source Code") is provided by Linden Lab - * to you under the terms of the GNU General Public License, version 2.0 - * ("GPL"), unless you have obtained a separate licensing agreement - * ("Other License"), formally executed by you and Linden Lab. Terms of - * the GPL can be found in doc/GPL-license.txt in this distribution, or - * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2 + * Copyright (C) 2010, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. * - * There are special exceptions to the terms and conditions of the GPL as - * it is applied to this Source Code. View the full text of the exception - * in the file doc/FLOSS-exception.txt in this software distribution, or - * online at - * http://secondlifegrid.net/programs/open_source/licensing/flossexception + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. * - * By copying, modifying or distributing this software, you acknowledge - * that you have read and understood your obligations described above, - * and agree to abide by those obligations. + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO - * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, - * COMPLETENESS OR PERFORMANCE. + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ @@ -48,6 +42,7 @@ #include "llcolorswatch.h" #include "llcombobox.h" #include "lldrawpoolbump.h" +#include "llface.h" #include "lllineeditor.h" #include "llmediaentry.h" #include "llresmgr.h" @@ -81,6 +76,7 @@ BOOL LLPanelFace::postBuild() childSetCommitCallback("checkbox flip t",&LLPanelFace::onCommitTextureInfo, this); childSetCommitCallback("TexRot",&LLPanelFace::onCommitTextureInfo, this); childSetAction("button apply",&LLPanelFace::onClickApply,this); + childSetCommitCallback("checkbox planar align",&LLPanelFace::onCommitPlanarAlign, this); childSetCommitCallback("TexOffsetU",LLPanelFace::onCommitTextureInfo, this); childSetCommitCallback("TexOffsetV",LLPanelFace::onCommitTextureInfo, this); childSetAction("button align",&LLPanelFace::onClickAutoFix,this); @@ -365,6 +361,93 @@ private: LLPanelFace* mPanel; }; +// Functor that aligns a face to mCenterFace +struct LLPanelFaceSetAlignedTEFunctor : public LLSelectedTEFunctor +{ + LLPanelFaceSetAlignedTEFunctor(LLPanelFace* panel, LLFace* center_face) : + mPanel(panel), + mCenterFace(center_face) {} + + virtual bool apply(LLViewerObject* object, S32 te) + { + LLFace* facep = object->mDrawable->getFace(te); + if (!facep) + { + return true; + } + + bool set_aligned = true; + if (facep == mCenterFace) + { + set_aligned = false; + } + if (set_aligned) + { + LLVector2 uv_offset, uv_scale; + F32 uv_rot; + set_aligned = facep->calcAlignedPlanarTE(mCenterFace, &uv_offset, &uv_scale, &uv_rot); + if (set_aligned) + { + object->setTEOffset(te, uv_offset.mV[VX], uv_offset.mV[VY]); + object->setTEScale(te, uv_scale.mV[VX], uv_scale.mV[VY]); + object->setTERotation(te, uv_rot); + } + } + if (!set_aligned) + { + LLPanelFaceSetTEFunctor setfunc(mPanel); + setfunc.apply(object, te); + } + return true; + } +private: + LLPanelFace* mPanel; + LLFace* mCenterFace; +}; + +// Functor that tests if a face is aligned to mCenterFace +struct LLPanelFaceGetIsAlignedTEFunctor : public LLSelectedTEFunctor +{ + LLPanelFaceGetIsAlignedTEFunctor(LLFace* center_face) : + mCenterFace(center_face) {} + + virtual bool apply(LLViewerObject* object, S32 te) + { + LLFace* facep = object->mDrawable->getFace(te); + if (!facep) + { + return false; + } + if (facep == mCenterFace) + { + return true; + } + + LLVector2 aligned_st_offset, aligned_st_scale; + F32 aligned_st_rot; + if ( facep->calcAlignedPlanarTE(mCenterFace, &aligned_st_offset, &aligned_st_scale, &aligned_st_rot) ) + { + const LLTextureEntry* tep = facep->getTextureEntry(); + LLVector2 st_offset, st_scale; + tep->getOffset(&st_offset.mV[VX], &st_offset.mV[VY]); + tep->getScale(&st_scale.mV[VX], &st_scale.mV[VY]); + F32 st_rot = tep->getRotation(); + // needs a fuzzy comparison, because of fp errors + if (is_approx_equal_fraction(st_offset.mV[VX], aligned_st_offset.mV[VX], 12) && + is_approx_equal_fraction(st_offset.mV[VY], aligned_st_offset.mV[VY], 12) && + is_approx_equal_fraction(st_scale.mV[VX], aligned_st_scale.mV[VX], 12) && + is_approx_equal_fraction(st_scale.mV[VY], aligned_st_scale.mV[VY], 12) && + is_approx_equal_fraction(st_rot, aligned_st_rot, 14)) + { + return true; + } + } + return false; + } +private: + LLFace* mCenterFace; +}; + struct LLPanelFaceSendFunctor : public LLSelectedObjectFunctor { virtual bool apply(LLViewerObject* object) @@ -376,8 +459,26 @@ struct LLPanelFaceSendFunctor : public LLSelectedObjectFunctor void LLPanelFace::sendTextureInfo() { - LLPanelFaceSetTEFunctor setfunc(this); - LLSelectMgr::getInstance()->getSelection()->applyToTEs(&setfunc); + if ((bool)childGetValue("checkbox planar align").asBoolean()) + { + struct f1 : public LLSelectedTEGetFunctor<LLFace *> + { + LLFace* get(LLViewerObject* object, S32 te) + { + return (object->mDrawable) ? object->mDrawable->getFace(te): NULL; + } + } get_last_face_func; + LLFace* last_face; + LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue(&get_last_face_func, last_face); + + LLPanelFaceSetAlignedTEFunctor setfunc(this, last_face); + LLSelectMgr::getInstance()->getSelection()->applyToTEs(&setfunc); + } + else + { + LLPanelFaceSetTEFunctor setfunc(this); + LLSelectMgr::getInstance()->getSelection()->applyToTEs(&setfunc); + } LLPanelFaceSendFunctor sendfunc; LLSelectMgr::getInstance()->getSelection()->applyToObjects(&sendfunc); @@ -394,8 +495,8 @@ void LLPanelFace::getState() BOOL editable = objectp->permModify(); // only turn on auto-adjust button if there is a media renderer and the media is loaded - childSetEnabled("textbox autofix", editable); - childSetEnabled("button align", editable); + getChildView("textbox autofix")->setEnabled(editable); + getChildView("button align")->setEnabled(editable); //if ( LLMediaEngine::getInstance()->getMediaRenderer () ) // if ( LLMediaEngine::getInstance()->getMediaRenderer ()->isLoaded () ) @@ -405,7 +506,7 @@ void LLPanelFace::getState() // // //mBtnAutoFix->setEnabled ( editable ); // } - childSetEnabled("button apply",editable); + getChildView("button apply")->setEnabled(editable); bool identical; LLTextureCtrl* texture_ctrl = getChild<LLTextureCtrl>("texture control"); @@ -445,8 +546,8 @@ void LLPanelFace::getState() if(LLViewerMedia::textureHasMedia(id)) { - childSetEnabled("textbox autofix",editable); - childSetEnabled("button align",editable); + getChildView("textbox autofix")->setEnabled(editable); + getChildView("button align")->setEnabled(editable); } if (identical) @@ -503,10 +604,46 @@ void LLPanelFace::getState() } } + + // planar align + bool align_planar = false; + bool identical_planar_aligned = false; + bool is_planar = false; + { + LLCheckBoxCtrl* cb_planar_align = getChild<LLCheckBoxCtrl>("checkbox planar align"); + align_planar = (cb_planar_align && cb_planar_align->get()); + struct f1 : public LLSelectedTEGetFunctor<bool> + { + bool get(LLViewerObject* object, S32 face) + { + return (object->getTE(face)->getTexGen() == LLTextureEntry::TEX_GEN_PLANAR); + } + } func; + + bool texgens_identical = LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue( &func, is_planar ); + bool enabled = (editable && texgens_identical && is_planar); + childSetValue("checkbox planar align", align_planar && enabled); + childSetEnabled("checkbox planar align", enabled); + + if (align_planar && enabled) + { + struct f2 : public LLSelectedTEGetFunctor<LLFace *> + { + LLFace* get(LLViewerObject* object, S32 te) + { + return (object->mDrawable) ? object->mDrawable->getFace(te): NULL; + } + } get_te_face_func; + LLFace* last_face; + LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue(&get_te_face_func, last_face); + LLPanelFaceGetIsAlignedTEFunctor get_is_aligend_func(last_face); + // this will determine if the texture param controls are tentative: + identical_planar_aligned = LLSelectMgr::getInstance()->getSelection()->applyToTEs(&get_is_aligend_func); + } + } + // Texture scale { - childSetEnabled("tex scale",editable); - //mLabelTexScale->setEnabled( editable ); F32 scale_s = 1.f; struct f2 : public LLSelectedTEGetFunctor<F32> { @@ -516,12 +653,13 @@ void LLPanelFace::getState() } } func; identical = LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue( &func, scale_s ); - childSetValue("TexScaleU",editable ? llabs(scale_s) : 0); - childSetTentative("TexScaleU",LLSD((BOOL)(!identical))); - childSetEnabled("TexScaleU",editable); - childSetValue("checkbox flip s",LLSD((BOOL)(scale_s < 0 ? TRUE : FALSE ))); - childSetTentative("checkbox flip s",LLSD((BOOL)((!identical) ? TRUE : FALSE ))); - childSetEnabled("checkbox flip s",editable); + identical = align_planar ? identical_planar_aligned : identical; + getChild<LLUICtrl>("TexScaleU")->setValue(editable ? llabs(scale_s) : 0); + getChild<LLUICtrl>("TexScaleU")->setTentative(LLSD((BOOL)(!identical))); + getChildView("TexScaleU")->setEnabled(editable); + getChild<LLUICtrl>("checkbox flip s")->setValue(LLSD((BOOL)(scale_s < 0 ? TRUE : FALSE ))); + getChild<LLUICtrl>("checkbox flip s")->setTentative(LLSD((BOOL)((!identical) ? TRUE : FALSE ))); + getChildView("checkbox flip s")->setEnabled(editable); } { @@ -534,18 +672,19 @@ void LLPanelFace::getState() } } func; identical = LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue( &func, scale_t ); - - childSetValue("TexScaleV",llabs(editable ? llabs(scale_t) : 0)); - childSetTentative("TexScaleV",LLSD((BOOL)(!identical))); - childSetEnabled("TexScaleV",editable); - childSetValue("checkbox flip t",LLSD((BOOL)(scale_t< 0 ? TRUE : FALSE ))); - childSetTentative("checkbox flip t",LLSD((BOOL)((!identical) ? TRUE : FALSE ))); - childSetEnabled("checkbox flip t",editable); + identical = align_planar ? identical_planar_aligned : identical; + + getChild<LLUICtrl>("TexScaleV")->setValue(llabs(editable ? llabs(scale_t) : 0)); + getChild<LLUICtrl>("TexScaleV")->setTentative(LLSD((BOOL)(!identical))); + getChildView("TexScaleV")->setEnabled(editable); + getChild<LLUICtrl>("checkbox flip t")->setValue(LLSD((BOOL)(scale_t< 0 ? TRUE : FALSE ))); + getChild<LLUICtrl>("checkbox flip t")->setTentative(LLSD((BOOL)((!identical) ? TRUE : FALSE ))); + getChildView("checkbox flip t")->setEnabled(editable); } // Texture offset { - childSetEnabled("tex offset",editable); + getChildView("tex offset")->setEnabled(editable); F32 offset_s = 0.f; struct f4 : public LLSelectedTEGetFunctor<F32> { @@ -555,9 +694,10 @@ void LLPanelFace::getState() } } func; identical = LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue( &func, offset_s ); - childSetValue("TexOffsetU", editable ? offset_s : 0); - childSetTentative("TexOffsetU",!identical); - childSetEnabled("TexOffsetU",editable); + identical = align_planar ? identical_planar_aligned : identical; + getChild<LLUICtrl>("TexOffsetU")->setValue(editable ? offset_s : 0); + getChild<LLUICtrl>("TexOffsetU")->setTentative(!identical); + getChildView("TexOffsetU")->setEnabled(editable); } { @@ -570,14 +710,14 @@ void LLPanelFace::getState() } } func; identical = LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue( &func, offset_t ); - childSetValue("TexOffsetV", editable ? offset_t : 0); - childSetTentative("TexOffsetV",!identical); - childSetEnabled("TexOffsetV",editable); + identical = align_planar ? identical_planar_aligned : identical; + getChild<LLUICtrl>("TexOffsetV")->setValue(editable ? offset_t : 0); + getChild<LLUICtrl>("TexOffsetV")->setTentative(!identical); + getChildView("TexOffsetV")->setEnabled(editable); } // Texture rotation { - childSetEnabled("tex rotate",editable); F32 rotation = 0.f; struct f6 : public LLSelectedTEGetFunctor<F32> { @@ -587,9 +727,10 @@ void LLPanelFace::getState() } } func; identical = LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue( &func, rotation ); - childSetValue("TexRot", editable ? rotation * RAD_TO_DEG : 0); - childSetTentative("TexRot",!identical); - childSetEnabled("TexRot",editable); + identical = align_planar ? identical_planar_aligned : identical; + getChild<LLUICtrl>("TexRot")->setValue(editable ? rotation * RAD_TO_DEG : 0); + getChild<LLUICtrl>("TexRot")->setTentative(!identical); + getChildView("TexRot")->setEnabled(editable); } // Color swatch @@ -615,13 +756,13 @@ void LLPanelFace::getState() } // Color transparency { - childSetEnabled("color trans",editable); + getChildView("color trans")->setEnabled(editable); } F32 transparency = (1.f - color.mV[VALPHA]) * 100.f; { - childSetValue("ColorTrans", editable ? transparency : 0); - childSetEnabled("ColorTrans",editable); + getChild<LLUICtrl>("ColorTrans")->setValue(editable ? transparency : 0); + getChildView("ColorTrans")->setEnabled(editable); } { @@ -635,10 +776,10 @@ void LLPanelFace::getState() } func; identical = LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue( &func, glow ); - childSetValue("glow",glow); - childSetEnabled("glow",editable); - childSetTentative("glow",!identical); - childSetEnabled("glow label",editable); + getChild<LLUICtrl>("glow")->setValue(glow); + getChildView("glow")->setEnabled(editable); + getChild<LLUICtrl>("glow")->setTentative(!identical); + getChildView("glow label")->setEnabled(editable); } @@ -663,9 +804,9 @@ void LLPanelFace::getState() { llwarns << "failed childGetSelectionInterface for 'combobox shininess'" << llendl; } - childSetEnabled("combobox shininess",editable); - childSetTentative("combobox shininess",!identical); - childSetEnabled("label shininess",editable); + getChildView("combobox shininess")->setEnabled(editable); + getChild<LLUICtrl>("combobox shininess")->setTentative(!identical); + getChildView("label shininess")->setEnabled(editable); } { @@ -688,9 +829,9 @@ void LLPanelFace::getState() { llwarns << "failed childGetSelectionInterface for 'combobox bumpiness'" << llendl; } - childSetEnabled("combobox bumpiness",editable); - childSetTentative("combobox bumpiness",!identical); - childSetEnabled("label bumpiness",editable); + getChildView("combobox bumpiness")->setEnabled(editable); + getChild<LLUICtrl>("combobox bumpiness")->setTentative(!identical); + getChildView("label bumpiness")->setEnabled(editable); } { @@ -714,19 +855,14 @@ void LLPanelFace::getState() { llwarns << "failed childGetSelectionInterface for 'combobox texgen'" << llendl; } - childSetEnabled("combobox texgen",editable); - childSetTentative("combobox texgen",!identical); - childSetEnabled("tex gen",editable); + getChildView("combobox texgen")->setEnabled(editable); + getChild<LLUICtrl>("combobox texgen")->setTentative(!identical); + getChildView("tex gen")->setEnabled(editable); if (selected_texgen == 1) { - childSetText("tex scale",getString("string repeats per meter")); - childSetValue("TexScaleU", 2.0f * childGetValue("TexScaleU").asReal() ); - childSetValue("TexScaleV", 2.0f * childGetValue("TexScaleV").asReal() ); - } - else - { - childSetText("tex scale",getString("string repeats per face")); + getChild<LLUICtrl>("TexScaleU")->setValue(2.0f * getChild<LLUICtrl>("TexScaleU")->getValue().asReal() ); + getChild<LLUICtrl>("TexScaleV")->setValue(2.0f * getChild<LLUICtrl>("TexScaleV")->getValue().asReal() ); } } @@ -742,14 +878,14 @@ void LLPanelFace::getState() } func; identical = LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue( &func, fullbrightf ); - childSetValue("checkbox fullbright",(S32)fullbrightf); - childSetEnabled("checkbox fullbright",editable); - childSetTentative("checkbox fullbright",!identical); + getChild<LLUICtrl>("checkbox fullbright")->setValue((S32)fullbrightf); + getChildView("checkbox fullbright")->setEnabled(editable); + getChild<LLUICtrl>("checkbox fullbright")->setTentative(!identical); } // Repeats per meter label { - childSetEnabled("rpt",editable); + getChildView("rpt")->setEnabled(editable); } // Repeats per meter @@ -769,14 +905,14 @@ void LLPanelFace::getState() } func; identical = LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue( &func, repeats ); - childSetValue("rptctrl", editable ? repeats : 0); - childSetTentative("rptctrl",!identical); + getChild<LLUICtrl>("rptctrl")->setValue(editable ? repeats : 0); + getChild<LLUICtrl>("rptctrl")->setTentative(!identical); LLComboBox* mComboTexGen = getChild<LLComboBox>("combobox texgen"); if (mComboTexGen) { BOOL enabled = editable && (!mComboTexGen || mComboTexGen->getCurrentIndex() != 1); - childSetEnabled("rptctrl",enabled); - childSetEnabled("button apply",enabled); + getChildView("rptctrl")->setEnabled(enabled); + getChildView("button apply")->setEnabled(enabled); } } } @@ -800,21 +936,19 @@ void LLPanelFace::getState() mColorSwatch->setFallbackImageName("locked_image.j2c" ); mColorSwatch->setValid(FALSE); } - childSetEnabled("color trans",FALSE); - childSetEnabled("rpt",FALSE); - childSetEnabled("tex scale",FALSE); - childSetEnabled("tex offset",FALSE); - childSetEnabled("tex rotate",FALSE); - childSetEnabled("tex gen",FALSE); - childSetEnabled("label shininess",FALSE); - childSetEnabled("label bumpiness",FALSE); - - childSetEnabled("textbox autofix",FALSE); - - childSetEnabled("button align",FALSE); - childSetEnabled("button apply",FALSE); - //childSetEnabled("has media", FALSE); - //childSetEnabled("media info set", FALSE); + getChildView("color trans")->setEnabled(FALSE); + getChildView("rpt")->setEnabled(FALSE); + getChildView("tex offset")->setEnabled(FALSE); + getChildView("tex gen")->setEnabled(FALSE); + getChildView("label shininess")->setEnabled(FALSE); + getChildView("label bumpiness")->setEnabled(FALSE); + + getChildView("textbox autofix")->setEnabled(FALSE); + + getChildView("button align")->setEnabled(FALSE); + getChildView("button apply")->setEnabled(FALSE); + //getChildView("has media")->setEnabled(FALSE); + //getChildView("media info set")->setEnabled(FALSE); } } @@ -944,7 +1078,7 @@ void LLPanelFace::onClickApply(void* userdata) gFocusMgr.setKeyboardFocus( NULL ); //F32 repeats_per_meter = self->mCtrlRepeatsPerMeter->get(); - F32 repeats_per_meter = (F32)self->childGetValue( "rptctrl" ).asReal();//self->mCtrlRepeatsPerMeter->get(); + F32 repeats_per_meter = (F32)self->getChild<LLUICtrl>("rptctrl")->getValue().asReal();//self->mCtrlRepeatsPerMeter->get(); LLSelectMgr::getInstance()->selectionTexScaleAutofit( repeats_per_meter ); } @@ -1009,3 +1143,11 @@ void LLPanelFace::setMediaType(const std::string& mime_type) { } +// static +void LLPanelFace::onCommitPlanarAlign(LLUICtrl* ctrl, void* userdata) +{ + LLPanelFace* self = (LLPanelFace*) userdata; + self->getState(); + self->sendTextureInfo(); +} + |