diff options
Diffstat (limited to 'indra/newview/lljoystickbutton.cpp')
-rw-r--r-- | indra/newview/lljoystickbutton.cpp | 103 |
1 files changed, 65 insertions, 38 deletions
diff --git a/indra/newview/lljoystickbutton.cpp b/indra/newview/lljoystickbutton.cpp index 4fd3b7bddc..9e1dc3a4b0 100644 --- a/indra/newview/lljoystickbutton.cpp +++ b/indra/newview/lljoystickbutton.cpp @@ -42,6 +42,7 @@ // Project includes #include "llui.h" #include "llagent.h" +#include "llagentcamera.h" #include "llviewertexture.h" #include "llviewertexturelist.h" #include "llviewerwindow.h" @@ -134,16 +135,33 @@ void LLJoystick::updateSlop() return; } +bool LLJoystick::pointInCircle(S32 x, S32 y) const +{ + if(this->getLocalRect().getHeight() != this->getLocalRect().getWidth()) + { + llwarns << "Joystick shape is not square"<<llendl; + return true; + } + //center is x and y coordinates of center of joystick circle, and also its radius + int center = this->getLocalRect().getHeight()/2; + bool in_circle = (x - center) * (x - center) + (y - center) * (y - center) <= center * center; + return in_circle; +} BOOL LLJoystick::handleMouseDown(S32 x, S32 y, MASK mask) { //llinfos << "joystick mouse down " << x << ", " << y << llendl; + bool handles = false; - mLastMouse.set(x, y); - mFirstMouse.set(x, y); + if(pointInCircle(x, y)) + { + mLastMouse.set(x, y); + mFirstMouse.set(x, y); + mMouseDownTimer.reset(); + handles = LLButton::handleMouseDown(x, y, mask); + } - mMouseDownTimer.reset(); - return LLButton::handleMouseDown(x, y, mask); + return handles; } @@ -465,25 +483,25 @@ void LLJoystickCameraRotate::onHeldDown() // left-right rotation if (dx > mHorizSlopNear) { - gAgent.unlockView(); - gAgent.setOrbitLeftKey(getOrbitRate()); + gAgentCamera.unlockView(); + gAgentCamera.setOrbitLeftKey(getOrbitRate()); } else if (dx < -mHorizSlopNear) { - gAgent.unlockView(); - gAgent.setOrbitRightKey(getOrbitRate()); + gAgentCamera.unlockView(); + gAgentCamera.setOrbitRightKey(getOrbitRate()); } // over/under rotation if (dy > mVertSlopNear) { - gAgent.unlockView(); - gAgent.setOrbitUpKey(getOrbitRate()); + gAgentCamera.unlockView(); + gAgentCamera.setOrbitUpKey(getOrbitRate()); } else if (dy < -mVertSlopNear) { - gAgent.unlockView(); - gAgent.setOrbitDownKey(getOrbitRate()); + gAgentCamera.unlockView(); + gAgentCamera.setOrbitDownKey(getOrbitRate()); } } @@ -517,43 +535,52 @@ void LLJoystickCameraRotate::draw() LLGLSUIDefault gls_ui; getImageUnselected()->draw( 0, 0 ); + LLPointer<LLUIImage> image = getImageSelected(); if( mInTop ) { - drawRotatedImage( getImageSelected()->getImage(), 0 ); + drawRotatedImage( getImageSelected(), 0 ); } if( mInRight ) { - drawRotatedImage( getImageSelected()->getImage(), 1 ); + drawRotatedImage( getImageSelected(), 1 ); } if( mInBottom ) { - drawRotatedImage( getImageSelected()->getImage(), 2 ); + drawRotatedImage( getImageSelected(), 2 ); } if( mInLeft ) { - drawRotatedImage( getImageSelected()->getImage(), 3 ); + drawRotatedImage( getImageSelected(), 3 ); } } // Draws image rotated by multiples of 90 degrees -void LLJoystickCameraRotate::drawRotatedImage( LLTexture* image, S32 rotations ) +void LLJoystickCameraRotate::drawRotatedImage( LLPointer<LLUIImage> image, S32 rotations ) { S32 width = image->getWidth(); S32 height = image->getHeight(); - + LLTexture* texture = image->getImage(); + + /* + * Scale texture coordinate system + * to handle the different between image size and size of texture. + * If we will use default matrix, + * it may break texture mapping after rotation. + * see EXT-2023 Camera floater: arrows became shifted when pressed. + */ F32 uv[][2] = { - { 1.f, 1.f }, - { 0.f, 1.f }, + { (F32)width/texture->getWidth(), (F32)height/texture->getHeight() }, + { 0.f, (F32)height/texture->getHeight() }, { 0.f, 0.f }, - { 1.f, 0.f } + { (F32)width/texture->getWidth(), 0.f } }; - gGL.getTexUnit(0)->bind(image); + gGL.getTexUnit(0)->bind(texture); gGL.color4fv(UI_VERTEX_COLOR.mV); @@ -599,25 +626,25 @@ void LLJoystickCameraTrack::onHeldDown() if (dx > mVertSlopNear) { - gAgent.unlockView(); - gAgent.setPanRightKey(getOrbitRate()); + gAgentCamera.unlockView(); + gAgentCamera.setPanRightKey(getOrbitRate()); } else if (dx < -mVertSlopNear) { - gAgent.unlockView(); - gAgent.setPanLeftKey(getOrbitRate()); + gAgentCamera.unlockView(); + gAgentCamera.setPanLeftKey(getOrbitRate()); } // over/under rotation if (dy > mVertSlopNear) { - gAgent.unlockView(); - gAgent.setPanUpKey(getOrbitRate()); + gAgentCamera.unlockView(); + gAgentCamera.setPanUpKey(getOrbitRate()); } else if (dy < -mVertSlopNear) { - gAgent.unlockView(); - gAgent.setPanDownKey(getOrbitRate()); + gAgentCamera.unlockView(); + gAgentCamera.setPanDownKey(getOrbitRate()); } } @@ -666,26 +693,26 @@ void LLJoystickCameraZoom::onHeldDown() if (dy > mVertSlopFar) { // Zoom in fast - gAgent.unlockView(); - gAgent.setOrbitInKey(FAST_RATE); + gAgentCamera.unlockView(); + gAgentCamera.setOrbitInKey(FAST_RATE); } else if (dy > mVertSlopNear) { // Zoom in slow - gAgent.unlockView(); - gAgent.setOrbitInKey(getOrbitRate()); + gAgentCamera.unlockView(); + gAgentCamera.setOrbitInKey(getOrbitRate()); } else if (dy < -mVertSlopFar) { // Zoom out fast - gAgent.unlockView(); - gAgent.setOrbitOutKey(FAST_RATE); + gAgentCamera.unlockView(); + gAgentCamera.setOrbitOutKey(FAST_RATE); } else if (dy < -mVertSlopNear) { // Zoom out slow - gAgent.unlockView(); - gAgent.setOrbitOutKey(getOrbitRate()); + gAgentCamera.unlockView(); + gAgentCamera.setOrbitOutKey(getOrbitRate()); } } |