fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / chart2 / source / view / inc / GL3DBarChart.hxx
blob4370aa8778f8750fb2fb320d6405d3b934f2a786
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #ifndef INCLUDED_CHART2_SOURCE_VIEW_INC_GL3DBARCHART_HXX
11 #define INCLUDED_CHART2_SOURCE_VIEW_INC_GL3DBARCHART_HXX
13 #include <GL3DPlotterBase.hxx>
15 #include <vector>
16 #include <boost/ptr_container/ptr_vector.hpp>
17 #include "VDataSeries.hxx"
19 #include <glm/glm.hpp>
21 #include <vcl/timer.hxx>
22 #include <vcl/idle.hxx>
23 #include <vcl/openglwin.hxx>
25 #include <rtl/ref.hxx>
26 #include <salhelper/thread.hxx>
27 #include <osl/conditn.hxx>
29 namespace chart {
31 class ExplicitCategoriesProvider;
33 namespace opengl3D {
35 class Renderable3DObject;
36 class OpenGL3DRenderer;
37 class TextCache;
38 class Camera;
42 enum RenderEventType
44 EVENT_NONE,
45 EVENT_CLICK,
46 EVENT_MOVE_TO_DEFAULT,
47 EVENT_DRAG_LEFT,
48 EVENT_DRAG_RIGHT,
49 EVENT_SCROLL,
50 EVENT_SHOW_SCROLL,
51 EVENT_SHOW_SELECT,
52 EVENT_AUTO_FLY,
53 EVENT_DIE,
54 EVENT_SELECTBAR_UPDEDATE
57 class RenderThread;
58 class RenderOneFrameThread;
59 class RenderAnimationThread;
61 class GL3DBarChart : public GL3DPlotterBase, public IRenderer
63 friend class RenderThread;
64 friend class RenderOneFrameThread;
65 friend class RenderAnimationThread;
66 friend class RenderBenchMarkThread;
67 public:
68 GL3DBarChart(
69 const css::uno::Reference<css::chart2::XChartType>& xChartType,
70 OpenGLWindow* pContext);
72 virtual ~GL3DBarChart();
74 virtual void create3DShapes(const boost::ptr_vector<VDataSeries>& rDataSeries,
75 ExplicitCategoriesProvider& rCatProvider) SAL_OVERRIDE;
77 virtual void render() SAL_OVERRIDE;
79 /// Render one frame of the 3D bar chart.
80 void renderFrame();
82 virtual void update() SAL_OVERRIDE;
84 /// Draw to the framebuffer context, and provide the ID of the bar that the user has clicked.
85 sal_uInt32 barIdAtPosition(const Point& rPos);
86 virtual void clickedAt(const Point& rPos, sal_uInt16 nButtons) SAL_OVERRIDE;
88 virtual void mouseDragMove(const Point& rStartPos, const Point& rEndPos, sal_uInt16 nButtons) SAL_OVERRIDE;
89 virtual void scroll(long nDelta) SAL_OVERRIDE;
90 virtual void contextDestroyed() SAL_OVERRIDE;
92 void setOpenGLWindow(OpenGLWindow* pWindow);
94 private:
96 void spawnRenderThread(RenderThread *pThread);
97 void joinRenderThread();
98 void moveToCorner();
99 void moveToDefault();
100 glm::vec3 getCornerPosition(sal_Int8 nCornerId);
101 void updateTimer();
102 void updateScreenText();
103 void updateRenderFPS();
104 void updateDataUpdateFPS();
105 DECL_LINK_TYPED(UpdateTimerHdl, Idle*, void);
106 static int calcTimeInterval(TimeValue &startTime, TimeValue &endTime);
107 float addScreenTextShape(OUString &nStr, const glm::vec2& rLeftOrRightTop, float nTextHeight, bool bLeftTopFlag = true,
108 const glm::vec4& rColor = glm::vec4(0.0f, 1.0f, 1.0f, 0.0f),
109 const glm::vec3& rPos = glm::vec3(0.0f, 0.0f, 0.0f),
110 sal_uInt32 nEvent = 0);
111 void recordBarHistory(sal_uInt32 &nBarID, float &nVal);
112 void updateClickEvent();
113 void calcDistance(std::vector<sal_uInt32> &vectorNearest);
114 static float calcScrollDistance(const glm::mat4 &mvp, const glm::vec3& rPos);
115 void initDistanceHeap(std::vector<sal_uInt32> &vectorNearest);
116 void keepHeap(std::vector<sal_uInt32> &vectorNearest, int index);
117 static void swapVector(int i, int j, std::vector<sal_uInt32> &vectorNearest);
118 void getNearestBars(std::vector<sal_uInt32> &vectorNearest);
119 void updateScroll();
120 void processAutoFly(sal_uInt32 nId, sal_uInt32 nColor);
121 void getNeighborBarID(sal_uInt32 nSelectBarId, sal_uInt32 *pNeighborBarId);
122 void addMovementScreenText(sal_uInt32 nBarId);
123 css::uno::Reference<css::chart2::XChartType> mxChartType;
124 boost::ptr_vector<opengl3D::Renderable3DObject> maShapes;
126 boost::scoped_ptr<opengl3D::OpenGL3DRenderer> mpRenderer;
127 VclPtr<OpenGLWindow> mpWindow;
129 opengl3D::Camera* mpCamera;
130 bool mbValidContext;
132 boost::scoped_ptr<opengl3D::TextCache> mpTextCache;
134 glm::vec3 maCameraPosition;
135 glm::vec3 maCameraDirection;
137 glm::vec3 maDefaultCameraPosition;
138 glm::vec3 maDefaultCameraDirection;
140 glm::vec3 maStepDirection;
141 float mnMaxX;
142 float mnMaxY;
143 float mnDistance;
145 * 0 = corner at (0,0,0);
146 * numbering counter clockwise
148 sal_Int8 mnCornerId;
150 std::vector<OUString> maCategories;
151 std::vector<OUString> maSeriesNames;
152 struct BarInformation
154 glm::vec3 maPos;
155 float mnVal;
156 sal_Int32 mnIndex;
157 sal_Int32 mnSeriesIndex;
159 BarInformation(const glm::vec3& rPos, float nVal,
160 sal_Int32 nIndex, sal_Int32 nSeriesIndex);
163 std::map<sal_uInt32, const BarInformation> maBarMap;
164 bool mbNeedsNewRender;
165 bool mbCameraInit;
167 osl::Mutex maMutex;
168 rtl::Reference<RenderThread> mpRenderThread;
169 bool mbRenderDie;
170 ::osl::Condition maClickCond;
171 RenderEventType maRenderEvent;
172 RenderEventType maPreRenderEvent;
173 sal_uInt32 mnSelectBarId;
174 sal_uInt32 mnPreSelectBarId;
175 Point maClickPos;
176 sal_uInt32 miScrollRate;
177 bool mbScrollFlg;
178 Idle maIdle;
179 bool mbScreenTextNewRender;
180 boost::ptr_vector<opengl3D::Renderable3DObject> maScreenTextShapes;
181 OUString maFPS;
182 OUString maDataUpdateFPS;
183 sal_uInt32 miFrameCount;
184 sal_uInt32 miDataUpdateCounter;
185 TimeValue maFPSRenderStartTime;
186 TimeValue maFPSRenderEndTime;
187 TimeValue maDataUpdateStartTime;
188 TimeValue maDataUpdateEndTime;
189 std::map<sal_uInt32, std::list<float> > maBarHistory;
190 std::vector<sal_uInt32> maVectorNearest;
191 std::map<sal_uInt32, float> maDistanceMap;
192 std::map<sal_uInt32, sal_uInt32> maBarColorMap;
193 int mnColorRate;
194 bool mbBenchMarkMode;
195 sal_uInt32 mnHistoryCounter;
196 sal_uInt32 mnBarsInRow;
197 bool mbAutoFly;
198 sal_Int32 mnUpdateBarId;
200 // these form a pair:
201 // main thread sets condition 1 and waits until it can take the mutex
202 // render thread checks condition 1 before taking the mutex and waits in case it
203 // is set until condition 2 is set
205 // only necessary for the benchmark mode
206 osl::Condition maCond1;
207 osl::Condition maCond2;
212 #endif
214 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */