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 <tools/extendapplicationenvironment.hxx>
23 #include <cppuhelper/bootstrap.hxx>
24 #include <comphelper/processfactory.hxx>
26 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
27 #include <com/sun/star/uno/XComponentContext.hpp>
29 #include <vcl/event.hxx>
30 #include <vcl/svapp.hxx>
31 #include <vcl/wrkwin.hxx>
32 #include <vcl/gradient.hxx>
33 #include <vcl/lineinfo.hxx>
34 #include <vcl/bitmap.hxx>
35 #include <vcl/bitmapaccess.hxx>
36 #include <vcl/metric.hxx>
37 #include <vcl/vclptr.hxx>
38 #include <bitmapwriteaccess.hxx>
40 #include <rtl/ustrbuf.hxx>
44 using namespace ::com::sun::star::uno
;
45 using namespace ::com::sun::star::lang
;
48 // Forward declaration
55 tools::extendApplicationEnvironment();
57 Reference
< XComponentContext
> xContext
= defaultBootstrap_InitialComponentContext();
58 Reference
< XMultiServiceFactory
> xServiceManager( xContext
->getServiceManager(), UNO_QUERY
);
60 if( !xServiceManager
.is() )
61 Application::Abort( "Failed to bootstrap" );
63 comphelper::setProcessServiceFactory( xServiceManager
);
69 catch (const Exception
& e
)
71 SAL_WARN("vcl.app", "Fatal: " << e
);
74 catch (const std::exception
&e
)
76 fprintf(stderr
, "fatal error: %s\n", e
.what());
83 class MyWin
: public WorkWindow
87 MyWin( vcl::Window
* pParent
, WinBits nWinStyle
);
89 virtual void Paint( vcl::RenderContext
& /*rRenderContext*/, const tools::Rectangle
& rRect
) override
;
94 ScopedVclPtrInstance
< MyWin
> aMainWin( nullptr, WB_APP
| WB_STDWORK
);
95 aMainWin
->SetText( "VCL - Workbench" );
98 Application::Execute();
101 MyWin::MyWin( vcl::Window
* pParent
, WinBits nWinStyle
) :
102 WorkWindow( pParent
, nWinStyle
),
103 m_aBitmap( Size( 256, 256 ), 32 )
105 // prepare an alpha mask
106 BitmapWriteAccess
* pAcc
= m_aBitmap
.AcquireWriteAccess();
107 for( int nX
= 0; nX
< 256; nX
++ )
109 for( int nY
= 0; nY
< 256; nY
++ )
111 double fRed
= 255.0-1.5*sqrt(static_cast<double>(nX
*nX
+nY
*nY
));
114 double fGreen
= 255.0-1.5*sqrt(static_cast<double>((255-nX
)*(255-nX
)+nY
*nY
));
117 double fBlue
= 255.0-1.5*sqrt(static_cast<double>((128-nX
)*(128-nX
)+(255-nY
)*(255-nY
)));
120 pAcc
->SetPixel( nY
, nX
, BitmapColor( sal_uInt8(fRed
), sal_uInt8(fGreen
), sal_uInt8(fBlue
) ) );
123 Bitmap::ReleaseAccess( pAcc
);
126 static Point
project( const Point
& rPoint
)
128 const double angle_x
= M_PI
/ 6.0;
129 const double angle_z
= M_PI
/ 6.0;
131 // transform planar coordinates to 3d
132 double x
= rPoint
.X();
133 double y
= rPoint
.Y();
135 // rotate around X axis
137 double y1
= y
* cos( angle_x
);
138 double z1
= y
* sin( angle_x
);
140 // rotate around Z axis
141 double x2
= x1
* cos( angle_z
) + y1
* sin( angle_z
);
142 //double y2 = y1 * cos( angle_z ) - x1 * sin( angle_z );
145 return Point( static_cast<sal_Int32
>(x2
), static_cast<sal_Int32
>(z2
) );
148 static Color
approachColor( const Color
& rFrom
, const Color
& rTo
)
153 if( rFrom
.GetRed() < rTo
.GetRed() )
155 nDiff
= rTo
.GetRed() - rFrom
.GetRed();
156 aColor
.SetRed( rFrom
.GetRed() + std::min
<sal_uInt8
>( nDiff
, 10 ) );
158 else if( rFrom
.GetRed() > rTo
.GetRed() )
160 nDiff
= rFrom
.GetRed() - rTo
.GetRed();
161 aColor
.SetRed( rFrom
.GetRed() - std::min
<sal_uInt8
>( nDiff
, 10 ) );
164 aColor
.SetRed( rFrom
.GetRed() );
167 if( rFrom
.GetGreen() < rTo
.GetGreen() )
169 nDiff
= rTo
.GetGreen() - rFrom
.GetGreen();
170 aColor
.SetGreen( rFrom
.GetGreen() + std::min
<sal_uInt8
>( nDiff
, 10 ) );
172 else if( rFrom
.GetGreen() > rTo
.GetGreen() )
174 nDiff
= rFrom
.GetGreen() - rTo
.GetGreen();
175 aColor
.SetGreen( rFrom
.GetGreen() - std::min
<sal_uInt8
>( nDiff
, 10 ) );
178 aColor
.SetGreen( rFrom
.GetGreen() );
181 if( rFrom
.GetBlue() < rTo
.GetBlue() )
183 nDiff
= rTo
.GetBlue() - rFrom
.GetBlue();
184 aColor
.SetBlue( rFrom
.GetBlue() + std::min
<sal_uInt8
>( nDiff
, 10 ) );
186 else if( rFrom
.GetBlue() > rTo
.GetBlue() )
188 nDiff
= rFrom
.GetBlue() - rTo
.GetBlue();
189 aColor
.SetBlue( rFrom
.GetBlue() - std::min
<sal_uInt8
>( nDiff
, 10 ) );
192 aColor
.SetBlue( rFrom
.GetBlue() );
198 void MyWin::Paint(vcl::RenderContext
& rRenderContext
, const tools::Rectangle
& rRect
)
200 WorkWindow::Paint(rRenderContext
, rRect
);
202 rRenderContext
.Push();
203 MapMode
aMapMode(MapUnit::Map100thMM
);
205 rRenderContext
.SetMapMode(aMapMode
);
207 Size aPaperSize
= rRenderContext
.GetOutputSize();
208 Point
aCenter(aPaperSize
.Width() / 2 - 300,
209 (aPaperSize
.Height() - 8400) / 2 + 8400);
210 Point
aP1(aPaperSize
.Width() / 48, 0), aP2(aPaperSize
.Width() / 40, 0);
213 rRenderContext
.DrawRect(tools::Rectangle(Point(0, 0), aPaperSize
));
214 rRenderContext
.DrawRect(tools::Rectangle(Point(100, 100),
215 Size(aPaperSize
.Width() - 200,
216 aPaperSize
.Height() - 200)));
217 rRenderContext
.DrawRect(tools::Rectangle(Point(200, 200),
218 Size(aPaperSize
.Width() - 400,
219 aPaperSize
.Height() - 400)));
220 rRenderContext
.DrawRect(tools::Rectangle(Point(300, 300),
221 Size(aPaperSize
.Width() - 600,
222 aPaperSize
.Height() - 600)));
224 const int nFontCount
= rRenderContext
.GetDevFontCount();
225 const int nFontSamples
= (nFontCount
< 15) ? nFontCount
: 15;
226 for (int i
= 0; i
< nFontSamples
; ++i
)
229 FontMetric aFont
= rRenderContext
.GetDevFont((i
* nFontCount
) / nFontSamples
);
230 aFont
.SetFontHeight(400 + (i
% 7) * 100);
231 aFont
.SetOrientation(i
* (3600 / nFontSamples
));
232 rRenderContext
.SetFont(aFont
);
234 sal_uInt8 nRed
= (i
<< 6) & 0xC0;
235 sal_uInt8 nGreen
= (i
<< 4) & 0xC0;
236 sal_uInt8 nBlue
= (i
<< 2) & 0xC0;
237 rRenderContext
.SetTextColor(Color(nRed
, nGreen
, nBlue
));
239 OUStringBuffer
aPrintText(1024);
241 aPrintText
.append( "SVP test program" );
243 rRenderContext
.DrawText(tools::Rectangle(Point((aPaperSize
.Width() - 4000) / 2, 2000),
244 Size(aPaperSize
.Width() - 2100, aPaperSize
.Height() - 4000)),
245 aPrintText
.makeStringAndClear(),
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 double sind
= sin(DELTA
* M_PI
/ 180.0);
288 double cosd
= cos(DELTA
* M_PI
/ 180.0);
289 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: */