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/bitmapaccess.hxx>
38 #include <vcl/metric.hxx>
39 #include <vcl/vclptr.hxx>
40 #include <bitmapwriteaccess.hxx>
42 #include <rtl/ustrbuf.hxx>
46 using namespace ::com::sun::star::uno
;
47 using namespace ::com::sun::star::lang
;
50 // Forward declaration
57 tools::extendApplicationEnvironment();
59 Reference
< XComponentContext
> xContext
= defaultBootstrap_InitialComponentContext();
60 Reference
< XMultiServiceFactory
> xServiceManager( xContext
->getServiceManager(), UNO_QUERY
);
62 if( !xServiceManager
.is() )
63 Application::Abort( "Failed to bootstrap" );
65 comphelper::setProcessServiceFactory( xServiceManager
);
71 catch (const Exception
&)
73 TOOLS_WARN_EXCEPTION("vcl.app", "Fatal");
76 catch (const std::exception
&e
)
78 fprintf(stderr
, "fatal error: %s\n", e
.what());
85 class MyWin
: public WorkWindow
89 MyWin( vcl::Window
* pParent
, WinBits nWinStyle
);
91 virtual void Paint( vcl::RenderContext
& /*rRenderContext*/, const tools::Rectangle
& rRect
) override
;
96 ScopedVclPtrInstance
< MyWin
> aMainWin( nullptr, WB_APP
| WB_STDWORK
);
97 aMainWin
->SetText( "VCL - Workbench" );
100 Application::Execute();
103 MyWin::MyWin( vcl::Window
* pParent
, WinBits nWinStyle
) :
104 WorkWindow( pParent
, nWinStyle
),
105 m_aBitmap( Size( 256, 256 ), 32 )
107 // prepare an alpha mask
108 BitmapWriteAccess
* pAcc
= m_aBitmap
.AcquireWriteAccess();
109 for( int nX
= 0; nX
< 256; nX
++ )
111 for( int nY
= 0; nY
< 256; nY
++ )
113 double fRed
= 255.0-1.5*sqrt(static_cast<double>(nX
*nX
+nY
*nY
));
116 double fGreen
= 255.0-1.5*sqrt(static_cast<double>((255-nX
)*(255-nX
)+nY
*nY
));
119 double fBlue
= 255.0-1.5*sqrt(static_cast<double>((128-nX
)*(128-nX
)+(255-nY
)*(255-nY
)));
122 pAcc
->SetPixel( nY
, nX
, BitmapColor( sal_uInt8(fRed
), sal_uInt8(fGreen
), sal_uInt8(fBlue
) ) );
125 Bitmap::ReleaseAccess( pAcc
);
128 static Point
project( const Point
& rPoint
)
130 const double angle_x
= M_PI
/ 6.0;
131 const double angle_z
= M_PI
/ 6.0;
133 // transform planar coordinates to 3d
134 double x
= rPoint
.X();
135 double y
= rPoint
.Y();
137 // rotate around X axis
139 double y1
= y
* cos( angle_x
);
140 double z1
= y
* sin( angle_x
);
142 // rotate around Z axis
143 double x2
= x1
* cos( angle_z
) + y1
* sin( angle_z
);
144 //double y2 = y1 * cos( angle_z ) - x1 * sin( angle_z );
147 return Point( static_cast<sal_Int32
>(x2
), static_cast<sal_Int32
>(z2
) );
150 static Color
approachColor( const Color
& rFrom
, const Color
& rTo
)
155 if( rFrom
.GetRed() < rTo
.GetRed() )
157 nDiff
= rTo
.GetRed() - rFrom
.GetRed();
158 aColor
.SetRed( rFrom
.GetRed() + std::min
<sal_uInt8
>( nDiff
, 10 ) );
160 else if( rFrom
.GetRed() > rTo
.GetRed() )
162 nDiff
= rFrom
.GetRed() - rTo
.GetRed();
163 aColor
.SetRed( rFrom
.GetRed() - std::min
<sal_uInt8
>( nDiff
, 10 ) );
166 aColor
.SetRed( rFrom
.GetRed() );
169 if( rFrom
.GetGreen() < rTo
.GetGreen() )
171 nDiff
= rTo
.GetGreen() - rFrom
.GetGreen();
172 aColor
.SetGreen( rFrom
.GetGreen() + std::min
<sal_uInt8
>( nDiff
, 10 ) );
174 else if( rFrom
.GetGreen() > rTo
.GetGreen() )
176 nDiff
= rFrom
.GetGreen() - rTo
.GetGreen();
177 aColor
.SetGreen( rFrom
.GetGreen() - std::min
<sal_uInt8
>( nDiff
, 10 ) );
180 aColor
.SetGreen( rFrom
.GetGreen() );
183 if( rFrom
.GetBlue() < rTo
.GetBlue() )
185 nDiff
= rTo
.GetBlue() - rFrom
.GetBlue();
186 aColor
.SetBlue( rFrom
.GetBlue() + std::min
<sal_uInt8
>( nDiff
, 10 ) );
188 else if( rFrom
.GetBlue() > rTo
.GetBlue() )
190 nDiff
= rFrom
.GetBlue() - rTo
.GetBlue();
191 aColor
.SetBlue( rFrom
.GetBlue() - std::min
<sal_uInt8
>( nDiff
, 10 ) );
194 aColor
.SetBlue( rFrom
.GetBlue() );
200 void MyWin::Paint(vcl::RenderContext
& rRenderContext
, const tools::Rectangle
& rRect
)
202 WorkWindow::Paint(rRenderContext
, rRect
);
204 rRenderContext
.Push();
205 MapMode
aMapMode(MapUnit::Map100thMM
);
207 rRenderContext
.SetMapMode(aMapMode
);
209 Size aPaperSize
= rRenderContext
.GetOutputSize();
210 Point
aCenter(aPaperSize
.Width() / 2 - 300,
211 (aPaperSize
.Height() - 8400) / 2 + 8400);
212 Point
aP1(aPaperSize
.Width() / 48, 0), aP2(aPaperSize
.Width() / 40, 0);
215 rRenderContext
.DrawRect(tools::Rectangle(Point(0, 0), aPaperSize
));
216 rRenderContext
.DrawRect(tools::Rectangle(Point(100, 100),
217 Size(aPaperSize
.Width() - 200,
218 aPaperSize
.Height() - 200)));
219 rRenderContext
.DrawRect(tools::Rectangle(Point(200, 200),
220 Size(aPaperSize
.Width() - 400,
221 aPaperSize
.Height() - 400)));
222 rRenderContext
.DrawRect(tools::Rectangle(Point(300, 300),
223 Size(aPaperSize
.Width() - 600,
224 aPaperSize
.Height() - 600)));
226 const int nFontCount
= rRenderContext
.GetDevFontCount();
227 const int nFontSamples
= (nFontCount
< 15) ? nFontCount
: 15;
228 for (int i
= 0; i
< nFontSamples
; ++i
)
231 FontMetric aFont
= rRenderContext
.GetDevFont((i
* nFontCount
) / nFontSamples
);
232 aFont
.SetFontHeight(400 + (i
% 7) * 100);
233 aFont
.SetOrientation(i
* (3600 / nFontSamples
));
234 rRenderContext
.SetFont(aFont
);
236 sal_uInt8 nRed
= (i
<< 6) & 0xC0;
237 sal_uInt8 nGreen
= (i
<< 4) & 0xC0;
238 sal_uInt8 nBlue
= (i
<< 2) & 0xC0;
239 rRenderContext
.SetTextColor(Color(nRed
, nGreen
, nBlue
));
241 OUString aPrintText
= "SVP test program";
243 rRenderContext
.DrawText(tools::Rectangle(Point((aPaperSize
.Width() - 4000) / 2, 2000),
244 Size(aPaperSize
.Width() - 2100, aPaperSize
.Height() - 4000)),
246 DrawTextFlags::MultiLine
);
249 rRenderContext
.SetFillColor();
250 DrawRect(tools::Rectangle(Point(aPaperSize
.Width() - 4000, 1000),
252 rRenderContext
.DrawBitmap(Point(aPaperSize
.Width() - 4000, 1000),
256 Color
const aWhite(0xff, 0xff, 0xff);
257 Color
const aBlack(0, 0, 0);
258 Color
const aLightRed(0xff, 0, 0);
259 Color
const aDarkRed(0x40, 0, 0);
260 Color
const aLightBlue(0, 0, 0xff);
261 Color
const aDarkBlue(0,0,0x40);
262 Color
const aLightGreen(0, 0xff, 0);
263 Color
const aDarkGreen(0, 0x40, 0);
265 Gradient
aGradient(GradientStyle::Linear
, aBlack
, aWhite
);
266 aGradient
.SetAngle(900);
267 rRenderContext
.DrawGradient(tools::Rectangle(Point(1000, 4500),
268 Size(aPaperSize
.Width() - 2000, 500)),
270 aGradient
.SetStartColor(aDarkRed
);
271 aGradient
.SetEndColor(aLightBlue
);
272 rRenderContext
.DrawGradient(tools::Rectangle(Point(1000, 5300),
273 Size(aPaperSize
.Width() - 2000, 500)),
275 aGradient
.SetStartColor(aDarkBlue
);
276 aGradient
.SetEndColor(aLightGreen
);
277 rRenderContext
.DrawGradient(tools::Rectangle(Point(1000, 6100),
278 Size(aPaperSize
.Width() - 2000, 500)),
280 aGradient
.SetStartColor(aDarkGreen
);
281 aGradient
.SetEndColor(aLightRed
);
282 rRenderContext
.DrawGradient(tools::Rectangle(Point(1000, 6900),
283 Size(aPaperSize
.Width() - 2000, 500)),
286 LineInfo
aLineInfo(LineStyle::Solid
, 200);
287 const double sind
= sin(basegfx::deg2rad(DELTA
));
288 const double cosd
= cos(basegfx::deg2rad(DELTA
));
289 const double factor
= 1 + (DELTA
/ 1000.0);
291 Color
aLineColor(0, 0, 0);
292 Color
aApproachColor(0, 0, 200);
294 while (aP2
.X() < aCenter
.X() && n
++ < 680)
296 aLineInfo
.SetWidth(n
/ 3);
297 aLineColor
= approachColor(aLineColor
, aApproachColor
);
298 rRenderContext
.SetLineColor(aLineColor
);
300 // switch approach color
301 if (aApproachColor
.IsRGBEqual(aLineColor
))
303 if (aApproachColor
.GetRed())
304 aApproachColor
= Color(0, 0, 200);
305 else if (aApproachColor
.GetGreen())
306 aApproachColor
= Color(200, 0, 0);
308 aApproachColor
= Color(0, 200, 0);
311 rRenderContext
.DrawLine(project(aP1
) + aCenter
,
312 project(aP2
) + aCenter
,
314 aPoint
.setX( static_cast<int>((static_cast<double>(aP1
.X())*cosd
- static_cast<double>(aP1
.Y())*sind
)*factor
) );
315 aPoint
.setY( static_cast<int>((static_cast<double>(aP1
.Y())*cosd
+ static_cast<double>(aP1
.X())*sind
)*factor
) );
317 aPoint
.setX( static_cast<int>((static_cast<double>(aP2
.X())*cosd
- static_cast<double>(aP2
.Y())*sind
)*factor
) );
318 aPoint
.setY( static_cast<int>((static_cast<double>(aP2
.Y())*cosd
+ static_cast<double>(aP2
.X())*sind
)*factor
) );
321 rRenderContext
.Pop();
324 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */