diff --git a/indra/newview/lltoolcomp.cpp b/indra/newview/lltoolcomp.cpp
index 7ea6ebd96e..3c2cf51fe0 100644
--- a/indra/newview/lltoolcomp.cpp
+++ b/indra/newview/lltoolcomp.cpp
@@ -130,6 +130,18 @@ void LLToolComposite::handleSelect()
mSelected = TRUE;
}
+// Add middle mouse control for tools overall
+BOOL LLToolComposite::handleMiddleMouseDown(S32 x, S32 y, MASK mask)
+{
+ return FALSE;
+}
+
+BOOL LLToolComposite::handleMiddleMouseUp(S32 x, S32 y, MASK mask)
+{
+ return FALSE;
+}
+//
+
//----------------------------------------------------------------------------
// LLToolCompInspect
//----------------------------------------------------------------------------
diff --git a/indra/newview/lltoolcomp.h b/indra/newview/lltoolcomp.h
index 9f8a0bb599..76b52fa524 100644
--- a/indra/newview/lltoolcomp.h
+++ b/indra/newview/lltoolcomp.h
@@ -97,6 +97,11 @@ protected:
public:
static const std::string sNameComp;
+
+ // Add middle mouse control for tools overall
+ virtual BOOL handleMiddleMouseDown(S32 x, S32 y, MASK mask);
+ virtual BOOL handleMiddleMouseUp(S32 x, S32 y, MASK mask);
+ //
};
diff --git a/indra/newview/lltoolface.cpp b/indra/newview/lltoolface.cpp
index 4b02174009..d44e79bdfd 100644
--- a/indra/newview/lltoolface.cpp
+++ b/indra/newview/lltoolface.cpp
@@ -43,6 +43,17 @@
#include "rlvhandler.h"
// [/RLVa:KB]
+// Add Middle Mouse control to drag texture faces around
+#include "llpanelface.h"
+#include "llspinctrl.h"
+#include "llkeyboard.h"
+#include "llwindow.h"
+
+BOOL LLToolFace::mTextureGrabbed=FALSE;
+LLViewerObject* LLToolFace::mTextureObject=NULL;
+S32 LLToolFace::mFaceGrabbed=0;
+//
+
//
// Member functions
//
@@ -83,6 +94,17 @@ BOOL LLToolFace::handleMouseDown(S32 x, S32 y, MASK mask)
void LLToolFace::pickCallback(const LLPickInfo& pick_info)
{
LLViewerObject* hit_obj = pick_info.getObject();
+
+ // Add Middle Mouse control to drag texture faces around
+ if(LLToolFace::mTextureGrabbed)
+ {
+ // remember the object being selected when this pick came from a middle mouse click
+ LLToolFace::mTextureObject=hit_obj;
+ // also remember the selected object face
+ LLToolFace::mFaceGrabbed=pick_info.mObjectFace;
+ }
+ //
+
if (hit_obj)
{
S32 hit_face = pick_info.mObjectFace;
@@ -159,5 +181,140 @@ void LLToolFace::handleDeselect()
void LLToolFace::render()
{
- // for now, do nothing
+ // Add Middle Mouse control to drag texture faces around
+ // // for now, do nothing
+
+ // do nothing if no texture was grabbed or no associated object was found
+ if(!LLToolFace::mTextureGrabbed || !LLToolFace::mTextureObject)
+ {
+ return;
+ }
+
+ // This is a rather lazy way of doing this, but the methods tried further down
+ // didn't lead to the necessary accuracy. More research will be done to see if
+ // it can be improved somehow.
+
+ // get the mouse distance from the original grabbing point
+ S32 dx=gViewerWindow->getCurrentMouseX()-mGrabX;
+ S32 dy=mGrabY-gViewerWindow->getCurrentMouseY();
+
+ // if no movement took place, stop here
+ if(dx==0 && dy==0)
+ {
+ return;
+ }
+
+ // move the mouse back to the grabbing point
+ gViewerWindow->getWindow()->setCursorPosition(LLCoordWindow(mGrabX,gViewerWindow->getWindowHeightRaw()-mGrabY-1));
+
+ F32 scaleU;
+ F32 scaleV;
+ F32 u;
+ F32 v;
+
+ // get texture coordinates and scale from the currently edited face
+ mTextureObject->getTE(mFaceGrabbed)->getOffset(&u,&v);
+ mTextureObject->getTE(mFaceGrabbed)->getScale(&scaleU,&scaleV);
+
+ // get the status of modifier keys
+ MASK mask=gKeyboard->currentMask(FALSE);
+
+ // set the value scaling based on SHIFT and CTRL keys being used
+ F32 scale=100.0f;
+ if(mask & MASK_CONTROL)
+ scale=1000.0f;
+ else if(mask & MASK_SHIFT)
+ scale=10000.0;
+
+ // recalculate texture position
+ u-=(F32) dx/scale*scaleU;
+ v+=(F32) dy/scale*scaleV;
+
+ // Bounds check and roll over
+ if (u> 1.0f) u-=1.0f;
+ else if(u<-1.0f) u+=1.0f;
+ if (v> 1.0f) v-=1.0f;
+ else if(v<-1.0f) v+=1.0f;
+
+ // apply new texture position
+ mTextureObject->setTEOffsetS(mFaceGrabbed,u);
+ mTextureObject->setTEOffsetT(mFaceGrabbed,v);
+
+ // update the build floater to reflect the new values
+ LLFloaterTools* toolsFloater=(LLFloaterTools*) LLFloaterReg::findInstance("build");
+ if(toolsFloater)
+ {
+ LLPanelFace* panelFace=toolsFloater->mPanelFace;
+ if(panelFace)
+ {
+ panelFace->refresh();
+ }
+ }
+
+ // this is one way I would rather do it than tracking mouse deltas, because it
+ // would take rotations into account. However, mSTCoords seems too coarse to be useful
+/*
+ S32 x=gViewerWindow->getCurrentMouseX();
+ S32 y=gViewerWindow->getCurrentMouseY();
+
+ const LLPickInfo& pick=gViewerWindow->pickImmediate(x,y,TRUE);
+
+ if(pick.getObjectID()!=LLToolFace::mTextureObject->getID() || pick.mObjectFace!=LLToolFace::mFaceGrabbed)
+ {
+ return;
+ }
+
+ llwarns << x << " " << y << " " << pick.mSTCoords.mV[VX] << " " << pick.mSTCoords.mV[VY] << llendl;
+*/
+
+ // this is another way I would rather do it than tracking mouse deltas, because it
+ // would take rotations into account. However, mSTCoords seems too coarse to be useful
+/*
+ S32 x=gViewerWindow->getCurrentMouseX();
+ S32 y=gViewerWindow->getCurrentMouseY();
+
+ S32 gDebugRaycastFaceHit = -1;
+ LLVector3 gDebugRaycastIntersection;
+ LLVector2 gDebugRaycastTexCoord;
+ LLVector3 gDebugRaycastNormal;
+ LLVector3 gDebugRaycastBinormal;
+ LLVector3 gDebugRaycastStart;
+ LLVector3 gDebugRaycastEnd;
+
+ gDebugRaycastObject = gViewerWindow->cursorIntersect(x,y, 512.f, mTextureObject, mFaceGrabbed, FALSE,
+ &gDebugRaycastFaceHit,
+ &gDebugRaycastIntersection,
+ &gDebugRaycastTexCoord,
+ &gDebugRaycastNormal,
+ &gDebugRaycastBinormal,
+ &gDebugRaycastStart,
+ &gDebugRaycastEnd
+ );
+
+ if(!gDebugRaycastObject || gDebugRaycastFaceHit!=LLToolFace::mFaceGrabbed)
+ {
+ return;
+ }
+*/
}
+
+
+BOOL LLToolFace::handleMiddleMouseDown(S32 x, S32 y, MASK mask)
+{
+ gViewerWindow->hideCursor();
+ mGrabX=x;
+ mGrabY=y;
+ LLToolFace::mTextureGrabbed=TRUE;
+ return handleMouseDown(x,y,mask);
+}
+
+BOOL LLToolFace::handleMiddleMouseUp(S32 x, S32 y, MASK mask)
+{
+ gViewerWindow->showCursor();
+ LLToolFace::mTextureGrabbed=FALSE;
+ LLToolFace::mTextureObject=NULL;
+ LLToolFace::mFaceGrabbed=0;
+
+ return TRUE;
+}
+//
diff --git a/indra/newview/lltoolface.h b/indra/newview/lltoolface.h
index 7eb13b0fbc..d54c49a19d 100644
--- a/indra/newview/lltoolface.h
+++ b/indra/newview/lltoolface.h
@@ -46,6 +46,18 @@ public:
virtual void render(); // draw face highlights
static void pickCallback(const LLPickInfo& pick_info);
+
+ // Add Middle Mouse control to drag texture faces around
+ virtual BOOL handleMiddleMouseDown(S32 x, S32 y, MASK mask);
+ virtual BOOL handleMiddleMouseUp(S32 x, S32 y, MASK mask);
+
+ static BOOL mTextureGrabbed;
+ static LLViewerObject* mTextureObject;
+ static S32 mFaceGrabbed;
+
+ S32 mGrabX;
+ S32 mGrabY;
+ //
};
#endif