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/bmpacc.hxx>
36 #include <vcl/metric.hxx>
37 #include <vcl/vclptr.hxx>
39 #include <rtl/ustrbuf.hxx>
43 using namespace ::com::sun::star::uno
;
44 using namespace ::com::sun::star::lang
;
47 // Forward declaration
54 tools::extendApplicationEnvironment();
56 Reference
< XComponentContext
> xContext
= defaultBootstrap_InitialComponentContext();
57 Reference
< XMultiServiceFactory
> xServiceManager( xContext
->getServiceManager(), UNO_QUERY
);
59 if( !xServiceManager
.is() )
60 Application::Abort( "Failed to bootstrap" );
62 comphelper::setProcessServiceFactory( xServiceManager
);
68 catch (const Exception
& e
)
70 SAL_WARN("vcl.app", "Fatal exception: " << e
.Message
);
77 class MyWin
: public WorkWindow
81 MyWin( vcl::Window
* pParent
, WinBits nWinStyle
);
83 virtual void MouseMove( const MouseEvent
& rMEvt
) SAL_OVERRIDE
;
84 virtual void MouseButtonDown( const MouseEvent
& rMEvt
) SAL_OVERRIDE
;
85 virtual void MouseButtonUp( const MouseEvent
& rMEvt
) SAL_OVERRIDE
;
86 virtual void KeyInput( const KeyEvent
& rKEvt
) SAL_OVERRIDE
;
87 virtual void KeyUp( const KeyEvent
& rKEvt
) SAL_OVERRIDE
;
88 virtual void Paint( vcl::RenderContext
& /*rRenderContext*/, const Rectangle
& rRect
) SAL_OVERRIDE
;
89 virtual void Resize() SAL_OVERRIDE
;
94 ScopedVclPtrInstance
< MyWin
> aMainWin( nullptr, WB_APP
| WB_STDWORK
);
95 aMainWin
->SetText( OUString( "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((double)(nX
*nX
+nY
*nY
));
114 double fGreen
= 255.0-1.5*sqrt((double)(((255-nX
)*(255-nX
)+nY
*nY
)));
117 double fBlue
= 255.0-1.5*sqrt((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 void MyWin::MouseMove( const MouseEvent
& rMEvt
)
128 WorkWindow::MouseMove( rMEvt
);
131 void MyWin::MouseButtonDown( const MouseEvent
& rMEvt
)
133 WorkWindow::MouseButtonDown( rMEvt
);
136 void MyWin::MouseButtonUp( const MouseEvent
& rMEvt
)
138 WorkWindow::MouseButtonUp( rMEvt
);
141 void MyWin::KeyInput( const KeyEvent
& rKEvt
)
143 WorkWindow::KeyInput( rKEvt
);
146 void MyWin::KeyUp( const KeyEvent
& rKEvt
)
148 WorkWindow::KeyUp( rKEvt
);
151 static Point
project( const Point
& rPoint
)
153 const double angle_x
= M_PI
/ 6.0;
154 const double angle_z
= M_PI
/ 6.0;
156 // transform planar coordinates to 3d
157 double x
= rPoint
.X();
158 double y
= rPoint
.Y();
160 // rotate around X axis
162 double y1
= y
* cos( angle_x
);
163 double z1
= y
* sin( angle_x
);
165 // rotate around Z axis
166 double x2
= x1
* cos( angle_z
) + y1
* sin( angle_z
);
167 //double y2 = y1 * cos( angle_z ) - x1 * sin( angle_z );
170 return Point( (sal_Int32
)x2
, (sal_Int32
)z2
);
173 static Color
approachColor( const Color
& rFrom
, const Color
& rTo
)
178 if( rFrom
.GetRed() < rTo
.GetRed() )
180 nDiff
= rTo
.GetRed() - rFrom
.GetRed();
181 aColor
.SetRed( rFrom
.GetRed() + ( nDiff
< 10 ? nDiff
: 10 ) );
183 else if( rFrom
.GetRed() > rTo
.GetRed() )
185 nDiff
= rFrom
.GetRed() - rTo
.GetRed();
186 aColor
.SetRed( rFrom
.GetRed() - ( nDiff
< 10 ? nDiff
: 10 ) );
189 aColor
.SetRed( rFrom
.GetRed() );
192 if( rFrom
.GetGreen() < rTo
.GetGreen() )
194 nDiff
= rTo
.GetGreen() - rFrom
.GetGreen();
195 aColor
.SetGreen( rFrom
.GetGreen() + ( nDiff
< 10 ? nDiff
: 10 ) );
197 else if( rFrom
.GetGreen() > rTo
.GetGreen() )
199 nDiff
= rFrom
.GetGreen() - rTo
.GetGreen();
200 aColor
.SetGreen( rFrom
.GetGreen() - ( nDiff
< 10 ? nDiff
: 10 ) );
203 aColor
.SetGreen( rFrom
.GetGreen() );
206 if( rFrom
.GetBlue() < rTo
.GetBlue() )
208 nDiff
= rTo
.GetBlue() - rFrom
.GetBlue();
209 aColor
.SetBlue( rFrom
.GetBlue() + ( nDiff
< 10 ? nDiff
: 10 ) );
211 else if( rFrom
.GetBlue() > rTo
.GetBlue() )
213 nDiff
= rFrom
.GetBlue() - rTo
.GetBlue();
214 aColor
.SetBlue( rFrom
.GetBlue() - ( nDiff
< 10 ? nDiff
: 10 ) );
217 aColor
.SetBlue( rFrom
.GetBlue() );
223 void MyWin::Paint(vcl::RenderContext
& rRenderContext
, const Rectangle
& rRect
)
225 WorkWindow::Paint(rRenderContext
, rRect
);
227 rRenderContext
.Push(PushFlags::ALL
);
228 MapMode
aMapMode(MAP_100TH_MM
);
230 rRenderContext
.SetMapMode(aMapMode
);
232 Size aPaperSize
= rRenderContext
.GetOutputSize();
233 Point
aCenter(aPaperSize
.Width() / 2 - 300,
234 (aPaperSize
.Height() - 8400) / 2 + 8400);
235 Point
aP1(aPaperSize
.Width() / 48, 0), aP2(aPaperSize
.Width() / 40, 0);
238 rRenderContext
.DrawRect(Rectangle(Point(0, 0), aPaperSize
));
239 rRenderContext
.DrawRect(Rectangle(Point(100, 100),
240 Size(aPaperSize
.Width() - 200,
241 aPaperSize
.Height() - 200)));
242 rRenderContext
.DrawRect(Rectangle(Point(200, 200),
243 Size(aPaperSize
.Width() - 400,
244 aPaperSize
.Height() - 400)));
245 rRenderContext
.DrawRect(Rectangle(Point(300, 300),
246 Size(aPaperSize
.Width() - 600,
247 aPaperSize
.Height() - 600)));
249 const int nFontCount
= rRenderContext
.GetDevFontCount();
250 const int nFontSamples
= (nFontCount
< 15) ? nFontCount
: 15;
251 for (int i
= 0; i
< nFontSamples
; ++i
)
254 vcl::FontInfo aFont
= rRenderContext
.GetDevFont((i
* nFontCount
) / nFontSamples
);
255 aFont
.SetHeight(400 + (i
% 7) * 100);
256 aFont
.SetOrientation(i
* (3600 / nFontSamples
));
257 rRenderContext
.SetFont(aFont
);
259 sal_uInt8 nRed
= (i
<< 6) & 0xC0;
260 sal_uInt8 nGreen
= (i
<< 4) & 0xC0;
261 sal_uInt8 nBlue
= (i
<< 2) & 0xC0;
262 rRenderContext
.SetTextColor(Color(nRed
, nGreen
, nBlue
));
264 OUStringBuffer
aPrintText(1024);
267 aPrintText
.appendAscii( "SVP test program" );
269 rRenderContext
.DrawText(Rectangle(Point((aPaperSize
.Width() - 4000) / 2, 2000),
270 Size(aPaperSize
.Width() - 2100 - nMaxWidth
, aPaperSize
.Height() - 4000)),
271 aPrintText
.makeStringAndClear(),
272 DrawTextFlags::MultiLine
);
275 rRenderContext
.SetFillColor();
276 DrawRect(Rectangle(Point(aPaperSize
.Width() - 4000, 1000),
278 rRenderContext
.DrawBitmap(Point(aPaperSize
.Width() - 4000, 1000),
282 Color
aWhite(0xff, 0xff, 0xff);
283 Color
aBlack(0, 0, 0);
284 Color
aLightRed(0xff, 0, 0);
285 Color
aDarkRed(0x40, 0, 0);
286 Color
aLightBlue(0, 0, 0xff);
287 Color
aDarkBlue(0,0,0x40);
288 Color
aLightGreen(0, 0xff, 0);
289 Color
aDarkGreen(0, 0x40, 0);
291 Gradient
aGradient(GradientStyle_LINEAR
, aBlack
, aWhite
);
292 aGradient
.SetAngle(900);
293 rRenderContext
.DrawGradient(Rectangle(Point(1000, 4500),
294 Size(aPaperSize
.Width() - 2000, 500)),
296 aGradient
.SetStartColor(aDarkRed
);
297 aGradient
.SetEndColor(aLightBlue
);
298 rRenderContext
.DrawGradient(Rectangle(Point(1000, 5300),
299 Size(aPaperSize
.Width() - 2000, 500)),
301 aGradient
.SetStartColor(aDarkBlue
);
302 aGradient
.SetEndColor(aLightGreen
);
303 rRenderContext
.DrawGradient(Rectangle(Point(1000, 6100),
304 Size(aPaperSize
.Width() - 2000, 500)),
306 aGradient
.SetStartColor(aDarkGreen
);
307 aGradient
.SetEndColor(aLightRed
);
308 rRenderContext
.DrawGradient(Rectangle(Point(1000, 6900),
309 Size(aPaperSize
.Width() - 2000, 500)),
312 LineInfo
aLineInfo(LINE_SOLID
, 200);
313 double sind
= sin(DELTA
* M_PI
/ 180.0);
314 double cosd
= cos(DELTA
* M_PI
/ 180.0);
315 double factor
= 1 + (DELTA
/ 1000.0);
317 Color
aLineColor(0, 0, 0);
318 Color
aApproachColor(0, 0, 200);
320 while (aP2
.X() < aCenter
.X() && n
++ < 680)
322 aLineInfo
.SetWidth(n
/ 3);
323 aLineColor
= approachColor(aLineColor
, aApproachColor
);
324 rRenderContext
.SetLineColor(aLineColor
);
326 // switch aproach color
327 if (aApproachColor
.IsRGBEqual(aLineColor
))
329 if (aApproachColor
.GetRed())
330 aApproachColor
= Color(0, 0, 200);
331 else if (aApproachColor
.GetGreen())
332 aApproachColor
= Color(200, 0, 0);
334 aApproachColor
= Color(0, 200, 0);
337 rRenderContext
.DrawLine(project(aP1
) + aCenter
,
338 project(aP2
) + aCenter
,
340 aPoint
.X() = (int)((((double)aP1
.X())*cosd
- ((double)aP1
.Y())*sind
)*factor
);
341 aPoint
.Y() = (int)((((double)aP1
.Y())*cosd
+ ((double)aP1
.X())*sind
)*factor
);
343 aPoint
.X() = (int)((((double)aP2
.X())*cosd
- ((double)aP2
.Y())*sind
)*factor
);
344 aPoint
.Y() = (int)((((double)aP2
.Y())*cosd
+ ((double)aP2
.X())*sind
)*factor
);
347 rRenderContext
.Pop();
352 WorkWindow::Resize();
355 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */