fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / chart2 / source / view / main / 3DChartObjects.cxx
blobb1354c588eed10eb35dbd8e14192ee548bddefbf
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 #include "3DChartObjects.hxx"
11 #include <vcl/virdev.hxx>
12 #include <vcl/svapp.hxx>
14 #include <vcl/opengl/GLMHelper.hxx>
15 #include <vcl/opengl/OpenGLHelper.hxx>
16 #include <vcl/bmpacc.hxx>
18 namespace chart {
20 namespace opengl3D {
22 Renderable3DObject::Renderable3DObject(OpenGL3DRenderer* pRenderer, sal_uInt32 nId):
23 mpRenderer(pRenderer),
24 mnUniqueId(nId)
28 void Renderable3DObject::render()
30 (void) mnUniqueId;
33 Bar::Bar(OpenGL3DRenderer* pRenderer, const glm::mat4& rPosition, sal_uInt32 aColor, sal_uInt32 nId)
34 : Renderable3DObject(pRenderer, nId)
35 , mbRoundedCorners(true)
36 , maPos(rPosition)
37 , maColor(aColor)
39 SAL_INFO("chart2.3dopengl", rPosition);
42 void Bar::render()
44 mpRenderer->AddShape3DExtrudeObject(mbRoundedCorners, maColor.GetColor(), 0xFFFFFF, maPos, mnUniqueId);
45 mpRenderer->EndAddShape3DExtrudeObject();
48 Line::Line(OpenGL3DRenderer* pRenderer, sal_uInt32 nId):
49 Renderable3DObject(pRenderer, nId)
53 void Line::render()
55 mpRenderer->AddShapePolygon3DObject(0, true, maLineColor.GetColor(), 0, 0, mnUniqueId);
56 mpRenderer->AddPolygon3DObjectPoint(maPosBegin.x, maPosBegin.y, maPosBegin.z);
57 mpRenderer->AddPolygon3DObjectPoint(maPosEnd.x, maPosEnd.y, maPosEnd.z);
58 mpRenderer->EndAddPolygon3DObjectPoint();
59 mpRenderer->EndAddShapePolygon3DObject();
62 void Line::setPosition(const glm::vec3& rBegin, const glm::vec3& rEnd)
64 maPosBegin = rBegin;
65 maPosEnd = rEnd;
68 void Line::setLineColor(const Color& rColor)
70 maLineColor = rColor;
73 const TextCacheItem& TextCache::getText(OUString const & rText, bool bIs3dText)
75 TextCacheType::const_iterator itr = maTextCache.find(rText);
76 if(itr != maTextCache.end())
77 return *itr->second;
79 ScopedVclPtrInstance< VirtualDevice > pDevice(*Application::GetDefaultDevice(), 0, 0);
80 vcl::Font aFont;
81 if(bIs3dText)
82 aFont = vcl::Font("Brillante St",Size(0,0));
83 else
84 aFont = pDevice->GetFont();
85 aFont.SetSize(Size(0, 96));
86 static bool bOldRender = getenv("OLDRENDER");
87 if (bOldRender)
88 aFont.SetColor(COL_BLACK);
89 else
90 aFont.SetColor(COL_GREEN); // RGB_COLORDATA(0xf0, 0xf0, 0xf0));
91 pDevice->SetFont(aFont);
92 pDevice->Erase();
94 pDevice->SetOutputSize(Size(pDevice->GetTextWidth(rText), pDevice->GetTextHeight()));
95 pDevice->SetBackground(Wallpaper(COL_TRANSPARENT));
96 pDevice->DrawText(Point(0,0), rText);
98 BitmapEx aText(pDevice->GetBitmapEx(Point(0,0), pDevice->GetOutputSize()));
99 // TextCacheItem *pItem = new TextCacheItem(OpenGLHelper::ConvertBitmapExToRGBABuffer(aText), aText.GetSizePixel());
100 Bitmap aBitmap (aText.GetBitmap());
101 BitmapReadAccess *pAcc = aBitmap.AcquireReadAccess();
102 sal_uInt8 *buf = (sal_uInt8 *)pAcc->GetBuffer();
103 long nBmpWidth = aText.GetSizePixel().Width();
104 long nBmpHeight = aText.GetSizePixel().Height();
105 sal_uInt8* pBitmapBuf(new sal_uInt8[3* nBmpWidth * nBmpHeight]);
106 memcpy(pBitmapBuf, buf, 3* nBmpWidth * nBmpHeight);
107 TextCacheItem *pItem = new TextCacheItem(pBitmapBuf, aText.GetSizePixel());
108 maTextCache.insert(rText, pItem);
110 return *maTextCache.find(rText)->second;
113 Text::Text(OpenGL3DRenderer* pRenderer, TextCache& rTextCache, const OUString& rStr, sal_uInt32 nId):
114 Renderable3DObject(pRenderer, nId),
115 maText(rTextCache.getText(rStr))
119 void Text::render()
121 glm::vec3 dir2 = maTopRight - maTopLeft;
122 glm::vec3 bottomLeft = maBottomRight - dir2;
123 mpRenderer->CreateTextTexture(maText.maPixels, maText.maSize,
124 maTopLeft, maTopRight, maBottomRight, bottomLeft,
125 mnUniqueId);
128 void Text::setPosition(const glm::vec3& rTopLeft, const glm::vec3& rTopRight, const glm::vec3& rBottomRight)
130 maTopLeft = rTopLeft;
131 maTopRight = rTopRight;
132 maBottomRight = rBottomRight;
135 ScreenText::ScreenText(OpenGL3DRenderer* pRenderer, TextCache& rTextCache,
136 const OUString& rStr, glm::vec4 rColor, sal_uInt32 nId, bool bIs3dText):
137 Renderable3DObject(pRenderer, nId),
138 maText(rTextCache.getText(rStr,bIs3dText)),
139 maColor(rColor)
143 void ScreenText::setPosition(const glm::vec2& rTopLeft, const glm::vec2& rBottomRight,
144 const glm::vec3& r3DPos)
146 maTopLeft = rTopLeft;
147 maBottomRight = rBottomRight;
148 ma3DPos = r3DPos;
151 void ScreenText::render()
153 mpRenderer->CreateScreenTextTexture(maText.maPixels, maText.maSize,
154 maTopLeft, maBottomRight, ma3DPos, maColor,
155 mnUniqueId);
158 Rectangle::Rectangle(OpenGL3DRenderer* pRenderer, sal_uInt32 nId):
159 Renderable3DObject(pRenderer, nId)
163 void Rectangle::render()
165 glm::vec3 dir1 = maBottomRight - maTopLeft;
166 glm::vec3 dir2 = maTopRight - maTopLeft;
167 glm::vec3 normal = glm::normalize(glm::cross(dir1, dir2));
168 mpRenderer->AddShapePolygon3DObject(maColor.GetColor(), false, 0, 1, 0xFFFFFF, mnUniqueId);
169 glm::vec3 bottomLeft = maBottomRight - dir2;
170 //set polygon points and normals
171 mpRenderer->AddPolygon3DObjectPoint(maBottomRight.x, maBottomRight.y, maBottomRight.z);
172 mpRenderer->AddPolygon3DObjectNormalPoint(normal.x, normal.y, normal.z);
173 mpRenderer->AddPolygon3DObjectPoint(maTopRight.x, maTopRight.y, maTopRight.z);
174 mpRenderer->AddPolygon3DObjectNormalPoint(normal.x, normal.y, normal.z);
175 mpRenderer->AddPolygon3DObjectPoint(maTopLeft.x, maTopLeft.y, maTopLeft.z);
176 mpRenderer->AddPolygon3DObjectNormalPoint(normal.x, normal.y, normal.z);
177 mpRenderer->AddPolygon3DObjectPoint(bottomLeft.x, bottomLeft.y, bottomLeft.z);
178 mpRenderer->AddPolygon3DObjectNormalPoint(normal.x, normal.y, normal.z);
179 mpRenderer->EndAddPolygon3DObjectPoint();
180 mpRenderer->EndAddPolygon3DObjectNormalPoint();
181 mpRenderer->EndAddShapePolygon3DObject();
182 //we should render the edge if the edge color is different from the fill color
183 if (maColor.GetColor() != maLineColor.GetColor())
185 mpRenderer->AddShapePolygon3DObject(0, true, maLineColor.GetColor(), 0, 0xFFFFFF, mnUniqueId);
186 mpRenderer->AddPolygon3DObjectPoint(maBottomRight.x, maBottomRight.y, maBottomRight.z);
187 mpRenderer->AddPolygon3DObjectPoint(maTopRight.x, maTopRight.y, maTopRight.z);
188 mpRenderer->AddPolygon3DObjectPoint(maTopLeft.x, maTopLeft.y, maTopLeft.z);
189 mpRenderer->AddPolygon3DObjectPoint(bottomLeft.x, bottomLeft.y, bottomLeft.z);
190 mpRenderer->EndAddPolygon3DObjectPoint();
191 mpRenderer->EndAddShapePolygon3DObject();
195 void Rectangle::setPosition(const glm::vec3& rTopLeft, const glm::vec3& rTopRight, const glm::vec3& rBottomRight)
197 maTopLeft = rTopLeft;
198 maTopRight = rTopRight;
199 maBottomRight = rBottomRight;
202 void Rectangle::setFillColor(const Color& rColor)
204 maColor = rColor;
207 void Rectangle::setLineColor(const Color& rColor)
209 maLineColor = rColor;
212 Camera::Camera(OpenGL3DRenderer* pRenderer):
213 Renderable3DObject(pRenderer, 0),
214 maPos(10,-50,20),
215 maUp(0, 0, 1),
216 maDirection(glm::vec3(0,0,0))
220 void Camera::render()
222 mpRenderer->SetCameraInfo(maPos, maDirection, maUp);
225 void Camera::setPosition(const glm::vec3& rPos)
227 maPos = rPos;
230 void Camera::setDirection(const glm::vec3& rDir)
232 maDirection = rDir;
239 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */