[Libreoffice-commits] core.git: 2 commits - chart2/source
weigao
weigao at multicorewareinc.com
Wed Aug 20 04:10:34 PDT 2014
chart2/source/view/charttypes/GL3DBarChart.cxx | 102 ++++++++++++++++++++++---
chart2/source/view/inc/GL3DBarChart.hxx | 5 +
2 files changed, 98 insertions(+), 9 deletions(-)
New commits:
commit b7c78772571933b34ff618f07161697c958ba60a
Author: weigao <weigao at multicorewareinc.com>
Date: Wed Aug 20 13:01:19 2014 +0200
add screen text to auto fly
Change-Id: I6a4549bf47f5126510c3ddb93733b2d56a4159e2
diff --git a/chart2/source/view/charttypes/GL3DBarChart.cxx b/chart2/source/view/charttypes/GL3DBarChart.cxx
index be8a561..fb6e912 100644
--- a/chart2/source/view/charttypes/GL3DBarChart.cxx
+++ b/chart2/source/view/charttypes/GL3DBarChart.cxx
@@ -189,11 +189,11 @@ class RenderBenchMarkThread : public RenderThread
public:
RenderBenchMarkThread(GL3DBarChart * pChart)
: RenderThread(pChart)
+ , mbAutoFlyExecuting(0)
, mbExecuting(false)
, mbNeedFlyBack(false)
, mnStep(0)
, mnStepsTotal(0)
- , mbAutoFlyExecuting(0)
{
osl_getSystemTime(&maClickFlyBackStartTime);
osl_getSystemTime(&maClickFlyBackEndTime);
@@ -536,7 +536,6 @@ void GL3DBarChart::create3DShapes(const boost::ptr_vector<VDataSeries>& rDataSer
if (BENCH_MARK_MODE)
{
mnColorRate = 0;
- mnAutoFlyBarID = 0;
}
maShapes.push_back(new opengl3D::Camera(mpRenderer.get()));
mpCamera = static_cast<opengl3D::Camera*>(&maShapes.back());
@@ -601,8 +600,8 @@ void GL3DBarChart::create3DShapes(const boost::ptr_vector<VDataSeries>& rDataSer
recordBarHistory(nId, nVal);
if (BENCH_MARK_MODE)
{
- std::map<sal_uInt32, sal_uInt32>::const_iterator itr = maBarColorMap.find(nId);
- if (itr == maBarColorMap.end())
+ std::map<sal_uInt32, sal_uInt32>::const_iterator it = maBarColorMap.find(nId);
+ if (it == maBarColorMap.end())
{
maBarColorMap[nId] = nColor;
}
@@ -1070,9 +1069,10 @@ void GL3DBarChart::recordBarHistory(sal_uInt32 &nBarID, float &nVal)
void GL3DBarChart::updateClickEvent()
{
- if (maRenderEvent == EVENT_CLICK)
+ if (maRenderEvent == EVENT_CLICK || maRenderEvent == EVENT_AUTO_FLY)
{
- std::list<float>& aList = maBarHistory[mSelectBarId];
+ sal_uInt32 nBarId = maRenderEvent == EVENT_CLICK ? mSelectBarId : mnAutoFlyBarID;
+ std::list<float>& aList = maBarHistory[nBarId];
sal_uInt32 idex = 0;
for (std::list<float>::iterator it = aList.begin();it != aList.end();++it)
{
@@ -1083,7 +1083,7 @@ void GL3DBarChart::updateClickEvent()
maScreenTextShapes.push_back(new opengl3D::ScreenText(mpRenderer.get(), *mpTextCache, aBarValue, CALC_POS_EVENT_ID));
const opengl3D::TextCacheItem& rTextCache = mpTextCache->getText(aBarValue);
float nRectWidth = (float)rTextCache.maSize.Width() / (float)rTextCache.maSize.Height() * 0.03;
- std::map<sal_uInt32, const BarInformation>::const_iterator itr = maBarMap.find(mSelectBarId);
+ std::map<sal_uInt32, const BarInformation>::const_iterator itr = maBarMap.find(nBarId);
const BarInformation& rBarInfo = itr->second;
glm::vec3 aTextPos = glm::vec3(rBarInfo.maPos.x + BAR_SIZE_X / 2.0f,
rBarInfo.maPos.y + BAR_SIZE_Y / 2.0f,
@@ -1240,7 +1240,7 @@ void GL3DBarChart::processAutoFly(sal_uInt32 nId, sal_uInt32 nColor)
sal_uInt32 nPreColor = maBarColorMap[nId];
maBarColorMap[nId] = nColor;
//if has manul event, just record the color and process manul event first
- if ((maRenderEvent != EVENT_NONE) && (maRenderEvent != EVENT_AUTO_FLY))
+ if ((maRenderEvent != EVENT_NONE))
{
return;
}
commit 8434a2b6aaff9a1a9ce10d9eb9489ebf2929f724
Author: weigao <weigao at multicorewareinc.com>
Date: Tue Aug 19 19:24:06 2014 +0800
add auto fly code
Change-Id: Id137892b855b4a70625335ede8015dfe6dce1e7e
diff --git a/chart2/source/view/charttypes/GL3DBarChart.cxx b/chart2/source/view/charttypes/GL3DBarChart.cxx
index 8f9d8ec..be8a561 100644
--- a/chart2/source/view/charttypes/GL3DBarChart.cxx
+++ b/chart2/source/view/charttypes/GL3DBarChart.cxx
@@ -33,6 +33,7 @@
#define HISTORY_NUM 5
#define SHOW_VALUE_COUNT 15
#define SHOW_SCROLL_TEXT_DISTANCE 1000
+#define FLY_THRESHOLD 20
using namespace com::sun::star;
@@ -192,6 +193,7 @@ public:
, mbNeedFlyBack(false)
, mnStep(0)
, mnStepsTotal(0)
+ , mbAutoFlyExecuting(0)
{
osl_getSystemTime(&maClickFlyBackStartTime);
osl_getSystemTime(&maClickFlyBackEndTime);
@@ -207,9 +209,11 @@ private:
void ProcessScroll();
void UpdateScreenText();
void ProcessClickFlyBack();
+ void AutoMoveToBar();
private:
glm::vec3 maStartPos;
glm::vec3 maEndPos;
+ bool mbAutoFlyExecuting;
bool mbExecuting;
bool mbNeedFlyBack;
glm::vec3 maStep;
@@ -235,7 +239,8 @@ void RenderBenchMarkThread::MoveCamera()
{
mnStep = 0;
mbExecuting = false;
- if (mpChart->maRenderEvent == EVENT_CLICK)
+ mbAutoFlyExecuting = false;
+ if ((mpChart->maRenderEvent == EVENT_CLICK) || (mpChart->maRenderEvent == EVENT_AUTO_FLY))
{
mpChart->mpRenderer->EndClick();
mbNeedFlyBack = true;
@@ -260,6 +265,8 @@ void RenderBenchMarkThread::MoveToDefault()
}
if (!mbExecuting)
{
+ mpChart->mpRenderer->EndClick();
+ mnStep = 0;
mnStepsTotal = STEPS;
maStep = (mpChart->maDefaultCameraPosition - mpChart->maCameraPosition)/((float)mnStepsTotal);
maStepDirection = (mpChart->maDefaultCameraDirection - mpChart->maCameraDirection)/((float)mnStepsTotal);
@@ -272,6 +279,7 @@ void RenderBenchMarkThread::MoveToBar()
{
if (!mbExecuting)
{
+ mpChart->mpRenderer->EndClick();
mpChart->mpRenderer->SetPickingMode(true);
mpChart->mpCamera->render();
mpChart->mpRenderer->ProcessUnrenderedShape(mpChart->mbNeedsNewRender);
@@ -285,6 +293,7 @@ void RenderBenchMarkThread::MoveToBar()
return;
}
const GL3DBarChart::BarInformation& rBarInfo = itr->second;
+ mnStep = 0;
mnStepsTotal = STEPS;
glm::vec3 maTargetPosition = rBarInfo.maPos;
maTargetPosition.z += 240;
@@ -301,10 +310,40 @@ void RenderBenchMarkThread::MoveToBar()
MoveCamera();
}
+void RenderBenchMarkThread::AutoMoveToBar()
+{
+ if (!mbAutoFlyExecuting)
+ {
+ mpChart->mpRenderer->EndClick();
+ std::map<sal_uInt32, const GL3DBarChart::BarInformation>::const_iterator itr = mpChart->maBarMap.find(mpChart->mnAutoFlyBarID);
+ if(itr == mpChart->maBarMap.end())
+ {
+ mpChart->maRenderEvent = EVENT_NONE;
+ return;
+ }
+ const GL3DBarChart::BarInformation& rBarInfo = itr->second;
+ mnStep = 0;
+ mnStepsTotal = STEPS;
+ glm::vec3 maTargetPosition = rBarInfo.maPos;
+ maTargetPosition.z += 240;
+ maTargetPosition.x += BAR_SIZE_X / 2.0f;
+ maStep = (maTargetPosition - mpChart->maCameraPosition)/((float)mnStepsTotal);
+ glm::vec3 maTargetDirection = rBarInfo.maPos;
+ maTargetDirection.x += BAR_SIZE_X / 2.0f;
+ maTargetDirection.y += BAR_SIZE_Y / 2.0f;
+ maStepDirection = (maTargetDirection - mpChart->maCameraDirection)/((float)mnStepsTotal);
+ mpChart->mpRenderer->StartClick(mpChart->mnAutoFlyBarID);
+ mbAutoFlyExecuting = true;
+ }
+ MoveCamera();
+}
+
void RenderBenchMarkThread::MoveToCorner()
{
if (!mbExecuting)
{
+ mpChart->mpRenderer->EndClick();
+ mnStep = 0;
mnStepsTotal = STEPS;
maStep = (mpChart->getCornerPosition(mpChart->mnCornerId) - mpChart->maCameraPosition) / float(mnStepsTotal);
maStepDirection = (glm::vec3(mpChart->mnMaxX/2.0f, mpChart->mnMaxY/2.0f, 0) - mpChart->maCameraDirection)/ float(mnStepsTotal);
@@ -350,6 +389,11 @@ void RenderBenchMarkThread::ProcessMouseEvent()
{
ProcessScroll();
}
+ else if (mpChart->maRenderEvent == EVENT_AUTO_FLY)
+ {
+ AutoMoveToBar();
+ }
+
}
void RenderBenchMarkThread::UpdateScreenText()
@@ -414,7 +458,9 @@ GL3DBarChart::GL3DBarChart(
maFPS(OUString("Render FPS: 0")),
maDataUpdateFPS(OUString("Data Update FPS: 0")),
miFrameCount(0),
- miDataUpdateCounter(0)
+ miDataUpdateCounter(0),
+ mnColorRate(0),
+ mnAutoFlyBarID(0)
{
if (BENCH_MARK_MODE)
{
@@ -487,6 +533,11 @@ void GL3DBarChart::create3DShapes(const boost::ptr_vector<VDataSeries>& rDataSer
maSeriesNames.reserve(rDataSeriesContainer.size());
maBarMap.clear();
maShapes.clear();
+ if (BENCH_MARK_MODE)
+ {
+ mnColorRate = 0;
+ mnAutoFlyBarID = 0;
+ }
maShapes.push_back(new opengl3D::Camera(mpRenderer.get()));
mpCamera = static_cast<opengl3D::Camera*>(&maShapes.back());
@@ -548,6 +599,18 @@ void GL3DBarChart::create3DShapes(const boost::ptr_vector<VDataSeries>& rDataSer
BarInformation(glm::vec3(nXPos, nYPos, float(nVal/nMaxVal)),
nVal, nIndex, nSeriesIndex)));
recordBarHistory(nId, nVal);
+ if (BENCH_MARK_MODE)
+ {
+ std::map<sal_uInt32, sal_uInt32>::const_iterator itr = maBarColorMap.find(nId);
+ if (itr == maBarColorMap.end())
+ {
+ maBarColorMap[nId] = nColor;
+ }
+ else
+ {
+ processAutoFly(nId, nColor);
+ }
+ }
maShapes.push_back(new opengl3D::Bar(mpRenderer.get(), aBarPosition, nColor, nId));
nId += ID_STEP;
}
@@ -719,7 +782,7 @@ void GL3DBarChart::moveToDefault()
if(BENCH_MARK_MODE)
{
// add correct handling here!!
- if ((maRenderEvent != EVENT_NONE) && (maRenderEvent != EVENT_SHOW_SCROLL))
+ if ((maRenderEvent != EVENT_NONE) && (maRenderEvent != EVENT_SHOW_SCROLL) && (maRenderEvent != EVENT_AUTO_FLY))
return;
{
@@ -760,7 +823,7 @@ void GL3DBarChart::clickedAt(const Point& rPos, sal_uInt16 nButtons)
if (BENCH_MARK_MODE)
{
// add correct handling here !!
- if ((maRenderEvent != EVENT_NONE) && (maRenderEvent != EVENT_SHOW_SCROLL))
+ if ((maRenderEvent != EVENT_NONE) && (maRenderEvent != EVENT_SHOW_SCROLL) && (maRenderEvent != EVENT_AUTO_FLY))
return;
{
@@ -831,7 +894,7 @@ void GL3DBarChart::mouseDragMove(const Point& rStartPos, const Point& rEndPos, s
{
long nDirection = rEndPos.X() - rStartPos.X();
osl::MutexGuard aGuard(maMutex);
- if ((maRenderEvent == EVENT_NONE) || (maRenderEvent == EVENT_SHOW_SCROLL))
+ if ((maRenderEvent == EVENT_NONE) || (maRenderEvent == EVENT_SHOW_SCROLL) || (maRenderEvent == EVENT_AUTO_FLY))
maRenderEvent = nDirection > 0 ? EVENT_DRAG_RIGHT : EVENT_DRAG_LEFT;
if(nDirection < 0)
{
@@ -906,7 +969,7 @@ void GL3DBarChart::scroll(long nDelta)
{
{
osl::MutexGuard aGuard(maMutex);
- if ((maRenderEvent != EVENT_NONE) && (maRenderEvent != EVENT_SHOW_SCROLL))
+ if ((maRenderEvent != EVENT_NONE) && (maRenderEvent != EVENT_SHOW_SCROLL) && (maRenderEvent != EVENT_AUTO_FLY))
return;
glm::vec3 maDir = glm::normalize(maCameraPosition - maCameraDirection);
maCameraPosition -= (float((nDelta/10)) * maDir);
@@ -1171,6 +1234,27 @@ void GL3DBarChart::updateScroll()
}
}
+void GL3DBarChart::processAutoFly(sal_uInt32 nId, sal_uInt32 nColor)
+{
+ //record the color
+ sal_uInt32 nPreColor = maBarColorMap[nId];
+ maBarColorMap[nId] = nColor;
+ //if has manul event, just record the color and process manul event first
+ if ((maRenderEvent != EVENT_NONE) && (maRenderEvent != EVENT_AUTO_FLY))
+ {
+ return;
+ }
+ //calc the percentage of color change
+ int nColorRate = (nColor - nPreColor) * 100 / nPreColor;
+ nColorRate = abs(nColorRate);
+ if (nColorRate >= FLY_THRESHOLD)
+ {
+ maRenderEvent = EVENT_AUTO_FLY;
+ mnAutoFlyBarID = nColorRate > mnColorRate ? nId : mnAutoFlyBarID;
+ mnColorRate = nColorRate > mnColorRate ? nColorRate : mnColorRate;
+ }
+}
+
IMPL_LINK_NOARG(GL3DBarChart, updateTimer)
{
maTimer.Stop();
diff --git a/chart2/source/view/inc/GL3DBarChart.hxx b/chart2/source/view/inc/GL3DBarChart.hxx
index 4e9f7ca..2560d58 100644
--- a/chart2/source/view/inc/GL3DBarChart.hxx
+++ b/chart2/source/view/inc/GL3DBarChart.hxx
@@ -47,6 +47,7 @@ enum RenderEventType
EVENT_DRAG_RIGHT,
EVENT_SCROLL,
EVENT_SHOW_SCROLL,
+ EVENT_AUTO_FLY,
EVENT_DIE
};
@@ -100,6 +101,7 @@ private:
void swapVector(int i, int j, std::vector<sal_uInt32> &vectorNearest);
void getNearestBars(std::vector<sal_uInt32> &vectorNearest);
void updateScroll();
+ void processAutoFly(sal_uInt32 nId, sal_uInt32 nColor);
css::uno::Reference<css::chart2::XChartType> mxChartType;
boost::ptr_vector<opengl3D::Renderable3DObject> maShapes;
@@ -167,6 +169,9 @@ private:
std::map<sal_uInt32, std::list<float> > maBarHistory;
std::vector<sal_uInt32> maVectorNearest;
std::map<sal_uInt32, float> maDistanceMap;
+ std::map<sal_uInt32, sal_uInt32> maBarColorMap;
+ int mnColorRate;
+ sal_uInt32 mnAutoFlyBarID;
};
}
More information about the Libreoffice-commits
mailing list