Skip to content
Snippets Groups Projects
Commit 49f4b68b authored by AndreyL ProductEngine's avatar AndreyL ProductEngine
Browse files

SL-9941 EEP XY_Vector improvement - logarithmic scale mode

parent 5a8e633e
Branches
Tags
No related merge requests found
...@@ -37,6 +37,8 @@ ...@@ -37,6 +37,8 @@
#include "lluictrlfactory.h" #include "lluictrlfactory.h"
#include "llrender.h" #include "llrender.h"
#include "llmath.h"
// Globals // Globals
static LLDefaultChildRegistry::Register<LLXYVector> register_xy_vector("xy_vector"); static LLDefaultChildRegistry::Register<LLXYVector> register_xy_vector("xy_vector");
...@@ -63,7 +65,8 @@ LLXYVector::Params::Params() ...@@ -63,7 +65,8 @@ LLXYVector::Params::Params()
arrow_color("arrow_color", LLColor4::white), arrow_color("arrow_color", LLColor4::white),
ghost_color("ghost_color"), ghost_color("ghost_color"),
area_color("area_color", LLColor4::grey4), area_color("area_color", LLColor4::grey4),
grid_color("grid_color", LLColor4::grey % 0.25f) grid_color("grid_color", LLColor4::grey % 0.25f),
logarithmic("logarithmic", FALSE)
{ {
} }
...@@ -77,7 +80,8 @@ LLXYVector::LLXYVector(const LLXYVector::Params& p) ...@@ -77,7 +80,8 @@ LLXYVector::LLXYVector(const LLXYVector::Params& p)
mIncrementX(p.increment_x), mIncrementX(p.increment_x),
mMinValueY(p.min_val_y), mMinValueY(p.min_val_y),
mMaxValueY(p.max_val_y), mMaxValueY(p.max_val_y),
mIncrementY(p.increment_y) mIncrementY(p.increment_y),
mLogarithmic(p.logarithmic)
{ {
mGhostColor = p.ghost_color.isProvided() ? p.ghost_color() % 0.3f : p.arrow_color() % 0.3f; mGhostColor = p.ghost_color.isProvided() ? p.ghost_color() % 0.3f : p.arrow_color() % 0.3f;
...@@ -138,6 +142,9 @@ LLXYVector::~LLXYVector() ...@@ -138,6 +142,9 @@ LLXYVector::~LLXYVector()
BOOL LLXYVector::postBuild() BOOL LLXYVector::postBuild()
{ {
mLogScaleX = (2 * log(mMaxValueX)) / mTouchArea->getRect().getWidth();
mLogScaleY = (2 * log(mMaxValueY)) / mTouchArea->getRect().getHeight();
return TRUE; return TRUE;
} }
...@@ -165,9 +172,24 @@ void LLXYVector::draw() ...@@ -165,9 +172,24 @@ void LLXYVector::draw()
{ {
S32 centerX = mTouchArea->getRect().getCenterX(); S32 centerX = mTouchArea->getRect().getCenterX();
S32 centerY = mTouchArea->getRect().getCenterY(); S32 centerY = mTouchArea->getRect().getCenterY();
S32 pointX;
S32 pointY;
if (mLogarithmic)
{
pointX = (log(llabs(mValueX) + 1)) / mLogScaleX;
pointX *= (mValueX < 0) ? -1 : 1;
pointX += centerX;
S32 pointX = centerX + (mValueX * mTouchArea->getRect().getWidth() / (2 * mMaxValueX)); pointY = (log(llabs(mValueY) + 1)) / mLogScaleY;
S32 pointY = centerY + (mValueY * mTouchArea->getRect().getHeight() / (2 * mMaxValueY)); pointY *= (mValueY < 0) ? -1 : 1;
pointY += centerY;
}
else // linear
{
pointX = centerX + (mValueX * mTouchArea->getRect().getWidth() / (2 * mMaxValueX));
pointY = centerY + (mValueY * mTouchArea->getRect().getHeight() / (2 * mMaxValueY));
}
// fill // fill
gl_rect_2d(mTouchArea->getRect(), mAreaColor, true); gl_rect_2d(mTouchArea->getRect(), mAreaColor, true);
...@@ -222,22 +244,8 @@ void LLXYVector::setValue(const LLSD& value) ...@@ -222,22 +244,8 @@ void LLXYVector::setValue(const LLSD& value)
void LLXYVector::setValue(F32 x, F32 y) void LLXYVector::setValue(F32 x, F32 y)
{ {
x = llclamp(x, mMinValueX, mMaxValueX); mValueX = ll_round(llclamp(x, mMinValueX, mMaxValueX), mIncrementX);
y = llclamp(y, mMinValueY, mMaxValueY); mValueY = ll_round(llclamp(y, mMinValueY, mMaxValueY), mIncrementY);
// Round the values to nearest increments
x -= mMinValueX;
x += mIncrementX / 2.0001f;
x -= fmod(x, mIncrementX);
x += mMinValueX;
y -= mMinValueY;
y += mIncrementY / 2.0001f;
y -= fmod(y, mIncrementY);
y += mMinValueY;
mValueX = x;
mValueY = y;
update(); update();
} }
...@@ -269,14 +277,24 @@ BOOL LLXYVector::handleHover(S32 x, S32 y, MASK mask) ...@@ -269,14 +277,24 @@ BOOL LLXYVector::handleHover(S32 x, S32 y, MASK mask)
{ {
if (hasMouseCapture()) if (hasMouseCapture())
{ {
F32 valueX = F32(x - mTouchArea->getRect().getCenterX()) / mTouchArea->getRect().getWidth(); if (mLogarithmic)
F32 valueY = F32(y - mTouchArea->getRect().getCenterY()) / mTouchArea->getRect().getHeight(); {
F32 valueX = llfastpow(F_E, mLogScaleX*(llabs(x - mTouchArea->getRect().getCenterX()))) - 1;
valueX *= (x < mTouchArea->getRect().getCenterX()) ? -1 : 1;
F32 valueY = llfastpow(F_E, mLogScaleY*(llabs(y - mTouchArea->getRect().getCenterY()))) - 1;
valueY *= (y < mTouchArea->getRect().getCenterY()) ? -1 : 1;
valueX *= 2 * mMaxValueX; setValueAndCommit(valueX, valueY);
valueY *= 2 * mMaxValueY; }
else //linear
{
F32 valueX = 2 * mMaxValueX * F32(x - mTouchArea->getRect().getCenterX()) / mTouchArea->getRect().getWidth();
F32 valueY = 2 * mMaxValueY * F32(y - mTouchArea->getRect().getCenterY()) / mTouchArea->getRect().getHeight();
setValueAndCommit(valueX, valueY); setValueAndCommit(valueX, valueY);
} }
}
return TRUE; return TRUE;
} }
......
...@@ -59,6 +59,7 @@ class LLXYVector ...@@ -59,6 +59,7 @@ class LLXYVector
Optional<LLUIColor> ghost_color; Optional<LLUIColor> ghost_color;
Optional<LLUIColor> area_color; Optional<LLUIColor> area_color;
Optional<LLUIColor> grid_color; Optional<LLUIColor> grid_color;
Optional<BOOL> logarithmic;
Params(); Params();
}; };
...@@ -112,6 +113,9 @@ class LLXYVector ...@@ -112,6 +113,9 @@ class LLXYVector
LLUIColor mAreaColor; LLUIColor mAreaColor;
LLUIColor mGridColor; LLUIColor mGridColor;
BOOL mLogarithmic;
F32 mLogScaleX;
F32 mLogScaleY;
}; };
#endif #endif
......
...@@ -128,10 +128,11 @@ ...@@ -128,10 +128,11 @@
visible="true" visible="true"
left_delta="0" left_delta="0"
top_delta="21" top_delta="21"
min_val_x="-10" min_val_x="-30"
max_val_x="10" max_val_x="30"
min_val_y="-10" min_val_y="-30"
max_val_y="10" /> max_val_y="30"
logarithmic="1"/>
<text <text
follows="left|top" follows="left|top"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment