1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <sal/log.hxx>
22 #include <tools/diagnose_ex.h>
23 #include <tools/extendapplicationenvironment.hxx>
25 #include <cppuhelper/bootstrap.hxx>
26 #include <comphelper/processfactory.hxx>
28 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
29 #include <com/sun/star/uno/XComponentContext.hpp>
31 #include <vcl/event.hxx>
32 #include <vcl/svapp.hxx>
33 #include <vcl/wrkwin.hxx>
34 #include <vcl/gradient.hxx>
35 #include <vcl/lineinfo.hxx>
36 #include <vcl/bitmap.hxx>
37 #include <vcl/metric.hxx>
38 #include <vcl/vclptr.hxx>
39 #include <bitmap/BitmapWriteAccess.hxx>
41 #include <rtl/ustrbuf.hxx>
45 using namespace ::com::sun::star::uno
;
46 using namespace ::com::sun::star::lang
;
49 // Forward declaration
56 tools::extendApplicationEnvironment();
58 Reference
< XComponentContext
> xContext
= defaultBootstrap_InitialComponentContext();
59 Reference
< XMultiServiceFactory
> xServiceManager( xContext
->getServiceManager(), UNO_QUERY
);
61 if( !xServiceManager
.is() )
62 Application::Abort( "Failed to bootstrap" );
64 comphelper::setProcessServiceFactory( xServiceManager
);
70 catch (const Exception
&)
72 TOOLS_WARN_EXCEPTION("vcl.app", "Fatal");
75 catch (const std::exception
&e
)
77 fprintf(stderr
, "fatal error: %s\n", e
.what());
86 class MyWin
: public WorkWindow
90 MyWin( vcl::Window
* pParent
, WinBits nWinStyle
);
92 virtual void Paint( vcl::RenderContext
& /*rRenderContext*/, const tools::Rectangle
& rRect
) override
;
99 ScopedVclPtrInstance
< MyWin
> aMainWin( nullptr, WB_APP
| WB_STDWORK
);
100 aMainWin
->SetText( "VCL - Workbench" );
103 Application::Execute();
106 MyWin::MyWin( vcl::Window
* pParent
, WinBits nWinStyle
) :
107 WorkWindow( pParent
, nWinStyle
),
108 m_aBitmap(Size(256, 256), vcl::PixelFormat::N32_BPP
)
110 // prepare an alpha mask
111 BitmapWriteAccess
* pAcc
= m_aBitmap
.AcquireWriteAccess();
112 for( int nX
= 0; nX
< 256; nX
++ )
114 for( int nY
= 0; nY
< 256; nY
++ )
116 double fRed
= 255.0-1.5*sqrt(static_cast<double>(nX
*nX
+nY
*nY
));
119 double fGreen
= 255.0-1.5*sqrt(static_cast<double>((255-nX
)*(255-nX
)+nY
*nY
));
122 double fBlue
= 255.0-1.5*sqrt(static_cast<double>((128-nX
)*(128-nX
)+(255-nY
)*(255-nY
)));
125 pAcc
->SetPixel( nY
, nX
, BitmapColor( sal_uInt8(fRed
), sal_uInt8(fGreen
), sal_uInt8(fBlue
) ) );
128 Bitmap::ReleaseAccess( pAcc
);
131 static Point
project( const Point
& rPoint
)
133 const double angle_x
= M_PI
/ 6.0;
134 const double angle_z
= M_PI
/ 6.0;
136 // transform planar coordinates to 3d
137 double x
= rPoint
.X();
138 double y
= rPoint
.Y();
140 // rotate around X axis
142 double y1
= y
* cos( angle_x
);
143 double z1
= y
* sin( angle_x
);
145 // rotate around Z axis
146 double x2
= x1
* cos( angle_z
) + y1
* sin( angle_z
);
147 //double y2 = y1 * cos( angle_z ) - x1 * sin( angle_z );
150 return Point( static_cast<sal_Int32
>(x2
), static_cast<sal_Int32
>(z2
) );
153 static Color
approachColor( const Color
& rFrom
, const Color
& rTo
)
158 if( rFrom
.GetRed() < rTo
.GetRed() )
160 nDiff
= rTo
.GetRed() - rFrom
.GetRed();
161 aColor
.SetRed( rFrom
.GetRed() + std::min
<sal_uInt8
>( nDiff
, 10 ) );
163 else if( rFrom
.GetRed() > rTo
.GetRed() )
165 nDiff
= rFrom
.GetRed() - rTo
.GetRed();
166 aColor
.SetRed( rFrom
.GetRed() - std::min
<sal_uInt8
>( nDiff
, 10 ) );
169 aColor
.SetRed( rFrom
.GetRed() );
172 if( rFrom
.GetGreen() < rTo
.GetGreen() )
174 nDiff
= rTo
.GetGreen() - rFrom
.GetGreen();
175 aColor
.SetGreen( rFrom
.GetGreen() + std::min
<sal_uInt8
>( nDiff
, 10 ) );
177 else if( rFrom
.GetGreen() > rTo
.GetGreen() )
179 nDiff
= rFrom
.GetGreen() - rTo
.GetGreen();
180 aColor
.SetGreen( rFrom
.GetGreen() - std::min
<sal_uInt8
>( nDiff
, 10 ) );
183 aColor
.SetGreen( rFrom
.GetGreen() );
186 if( rFrom
.GetBlue() < rTo
.GetBlue() )
188 nDiff
= rTo
.GetBlue() - rFrom
.GetBlue();
189 aColor
.SetBlue( rFrom
.GetBlue() + std::min
<sal_uInt8
>( nDiff
, 10 ) );
191 else if( rFrom
.GetBlue() > rTo
.GetBlue() )
193 nDiff
= rFrom
.GetBlue() - rTo
.GetBlue();
194 aColor
.SetBlue( rFrom
.GetBlue() - std::min
<sal_uInt8
>( nDiff
, 10 ) );
197 aColor
.SetBlue( rFrom
.GetBlue() );
203 void MyWin::Paint(vcl::RenderContext
& rRenderContext
, const tools::Rectangle
& rRect
)
205 WorkWindow::Paint(rRenderContext
, rRect
);
207 rRenderContext
.Push();
208 MapMode
aMapMode(MapUnit::Map100thMM
);
210 rRenderContext
.SetMapMode(aMapMode
);
212 Size aPaperSize
= rRenderContext
.GetOutputSize();
213 Point
aCenter(aPaperSize
.Width() / 2 - 300,
214 (aPaperSize
.Height() - 8400) / 2 + 8400);
215 Point
aP1(aPaperSize
.Width() / 48, 0), aP2(aPaperSize
.Width() / 40, 0);
218 rRenderContext
.DrawRect(tools::Rectangle(Point(0, 0), aPaperSize
));
219 rRenderContext
.DrawRect(tools::Rectangle(Point(100, 100),
220 Size(aPaperSize
.Width() - 200,
221 aPaperSize
.Height() - 200)));
222 rRenderContext
.DrawRect(tools::Rectangle(Point(200, 200),
223 Size(aPaperSize
.Width() - 400,
224 aPaperSize
.Height() - 400)));
225 rRenderContext
.DrawRect(tools::Rectangle(Point(300, 300),
226 Size(aPaperSize
.Width() - 600,
227 aPaperSize
.Height() - 600)));
229 const int nFontCount
= rRenderContext
.GetDevFontCount();
230 const int nFontSamples
= (nFontCount
< 15) ? nFontCount
: 15;
231 for (int i
= 0; i
< nFontSamples
; ++i
)
234 FontMetric aFont
= rRenderContext
.GetDevFont((i
* nFontCount
) / nFontSamples
);
235 aFont
.SetFontHeight(400 + (i
% 7) * 100);
236 aFont
.SetOrientation(Degree10(i
* (3600 / nFontSamples
)));
237 rRenderContext
.SetFont(aFont
);
239 sal_uInt8 nRed
= (i
<< 6) & 0xC0;
240 sal_uInt8 nGreen
= (i
<< 4) & 0xC0;
241 sal_uInt8 nBlue
= (i
<< 2) & 0xC0;
242 rRenderContext
.SetTextColor(Color(nRed
, nGreen
, nBlue
));
244 rRenderContext
.DrawText(tools::Rectangle(Point((aPaperSize
.Width() - 4000) / 2, 2000),
245 Size(aPaperSize
.Width() - 2100, aPaperSize
.Height() - 4000)),
247 DrawTextFlags::MultiLine
);
250 rRenderContext
.SetFillColor();
251 rRenderContext
.DrawRect(tools::Rectangle(Point(aPaperSize
.Width() - 4000, 1000),
253 rRenderContext
.DrawBitmap(Point(aPaperSize
.Width() - 4000, 1000),
257 Color
const aWhite(0xff, 0xff, 0xff);
258 Color
const aBlack(0, 0, 0);
259 Color
const aLightRed(0xff, 0, 0);
260 Color
const aDarkRed(0x40, 0, 0);
261 Color
const aLightBlue(0, 0, 0xff);
262 Color
const aDarkBlue(0,0,0x40);
263 Color
const aLightGreen(0, 0xff, 0);
264 Color
const aDarkGreen(0, 0x40, 0);
266 Gradient
aGradient(GradientStyle::Linear
, aBlack
, aWhite
);
267 aGradient
.SetAngle(900_deg10
);
268 rRenderContext
.DrawGradient(tools::Rectangle(Point(1000, 4500),
269 Size(aPaperSize
.Width() - 2000, 500)),
271 aGradient
.SetStartColor(aDarkRed
);
272 aGradient
.SetEndColor(aLightBlue
);
273 rRenderContext
.DrawGradient(tools::Rectangle(Point(1000, 5300),
274 Size(aPaperSize
.Width() - 2000, 500)),
276 aGradient
.SetStartColor(aDarkBlue
);
277 aGradient
.SetEndColor(aLightGreen
);
278 rRenderContext
.DrawGradient(tools::Rectangle(Point(1000, 6100),
279 Size(aPaperSize
.Width() - 2000, 500)),
281 aGradient
.SetStartColor(aDarkGreen
);
282 aGradient
.SetEndColor(aLightRed
);
283 rRenderContext
.DrawGradient(tools::Rectangle(Point(1000, 6900),
284 Size(aPaperSize
.Width() - 2000, 500)),
287 LineInfo
aLineInfo(LineStyle::Solid
, 200);
288 const double sind
= sin(basegfx::deg2rad(DELTA
));
289 const double cosd
= cos(basegfx::deg2rad(DELTA
));
290 const double factor
= 1 + (DELTA
/ 1000.0);
292 Color
aLineColor(0, 0, 0);
293 Color
aApproachColor(0, 0, 200);
295 while (aP2
.X() < aCenter
.X() && n
++ < 680)
297 aLineInfo
.SetWidth(n
/ 3);
298 aLineColor
= approachColor(aLineColor
, aApproachColor
);
299 rRenderContext
.SetLineColor(aLineColor
);
301 // switch approach color
302 if (aApproachColor
.IsRGBEqual(aLineColor
))
304 if (aApproachColor
.GetRed())
305 aApproachColor
= Color(0, 0, 200);
306 else if (aApproachColor
.GetGreen())
307 aApproachColor
= Color(200, 0, 0);
309 aApproachColor
= Color(0, 200, 0);
312 rRenderContext
.DrawLine(project(aP1
) + aCenter
,
313 project(aP2
) + aCenter
,
315 aPoint
.setX( static_cast<int>((static_cast<double>(aP1
.X())*cosd
- static_cast<double>(aP1
.Y())*sind
)*factor
) );
316 aPoint
.setY( static_cast<int>((static_cast<double>(aP1
.Y())*cosd
+ static_cast<double>(aP1
.X())*sind
)*factor
) );
318 aPoint
.setX( static_cast<int>((static_cast<double>(aP2
.X())*cosd
- static_cast<double>(aP2
.Y())*sind
)*factor
) );
319 aPoint
.setY( static_cast<int>((static_cast<double>(aP2
.Y())*cosd
+ static_cast<double>(aP2
.X())*sind
)*factor
) );
322 rRenderContext
.Pop();
325 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */