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>
22 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
24 #include <vcl/event.hxx>
25 #include <vcl/svapp.hxx>
26 #include <vcl/wrkwin.hxx>
27 #include <vcl/gradient.hxx>
28 #include <vcl/lineinfo.hxx>
29 #include <vcl/bitmap.hxx>
30 #include <vcl/bmpacc.hxx>
31 #include <vcl/metric.hxx>
33 #include <rtl/ustrbuf.hxx>
37 #include <comphelper/processfactory.hxx>
38 #include <cppuhelper/servicefactory.hxx>
39 #include <cppuhelper/bootstrap.hxx>
41 using namespace ::com::sun::star::uno
;
42 using namespace ::com::sun::star::lang
;
45 // Forward declaration
51 tools::extendApplicationEnvironment();
53 Reference
< XMultiServiceFactory
> xMS
;
54 xMS
= cppu::createRegistryServiceFactory( OUString( "types.rdb" ), OUString( "applicat.rdb" ), sal_True
);
56 comphelper::setProcessServiceFactory( xMS
);
66 class MyWin
: public WorkWindow
70 MyWin( Window
* pParent
, WinBits nWinStyle
);
72 void MouseMove( const MouseEvent
& rMEvt
);
73 void MouseButtonDown( const MouseEvent
& rMEvt
);
74 void MouseButtonUp( const MouseEvent
& rMEvt
);
75 void KeyInput( const KeyEvent
& rKEvt
);
76 void KeyUp( const KeyEvent
& rKEvt
);
77 void Paint( const Rectangle
& rRect
);
84 MyWin
aMainWin( NULL
, WB_APP
| WB_STDWORK
);
85 aMainWin
.SetText( OUString( "VCL - Workbench" ) );
88 Application::Execute();
92 MyWin::MyWin( Window
* pParent
, WinBits nWinStyle
) :
93 WorkWindow( pParent
, nWinStyle
),
94 m_aBitmap( Size( 256, 256 ), 32 )
96 // prepare an alpha mask
97 BitmapWriteAccess
* pAcc
= m_aBitmap
.AcquireWriteAccess();
98 for( int nX
= 0; nX
< 256; nX
++ )
100 for( int nY
= 0; nY
< 256; nY
++ )
102 double fRed
= 255.0-1.5*sqrt((double)(nX
*nX
+nY
*nY
));
105 double fGreen
= 255.0-1.5*sqrt((double)(((255-nX
)*(255-nX
)+nY
*nY
)));
108 double fBlue
= 255.0-1.5*sqrt((double)((128-nX
)*(128-nX
)+(255-nY
)*(255-nY
)));
111 pAcc
->SetPixel( nX
, nY
, BitmapColor( sal_uInt8(fRed
), sal_uInt8(fGreen
), sal_uInt8(fBlue
) ) );
114 m_aBitmap
.ReleaseAccess( pAcc
);
118 void MyWin::MouseMove( const MouseEvent
& rMEvt
)
120 WorkWindow::MouseMove( rMEvt
);
124 void MyWin::MouseButtonDown( const MouseEvent
& rMEvt
)
126 WorkWindow::MouseButtonDown( rMEvt
);
130 void MyWin::MouseButtonUp( const MouseEvent
& rMEvt
)
132 WorkWindow::MouseButtonUp( rMEvt
);
136 void MyWin::KeyInput( const KeyEvent
& rKEvt
)
138 WorkWindow::KeyInput( rKEvt
);
142 void MyWin::KeyUp( const KeyEvent
& rKEvt
)
144 WorkWindow::KeyUp( rKEvt
);
148 static Point
project( const Point
& rPoint
)
150 const double angle_x
= M_PI
/ 6.0;
151 const double angle_z
= M_PI
/ 6.0;
153 // transform planar coordinates to 3d
154 double x
= rPoint
.X();
155 double y
= rPoint
.Y();
157 // rotate around X axis
159 double y1
= y
* cos( angle_x
);
160 double z1
= y
* sin( angle_x
);
162 // rotate around Z axis
163 double x2
= x1
* cos( angle_z
) + y1
* sin( angle_z
);
164 //double y2 = y1 * cos( angle_z ) - x1 * sin( angle_z );
167 return Point( (sal_Int32
)x2
, (sal_Int32
)z2
);
170 static Color
approachColor( const Color
& rFrom
, const Color
& rTo
)
175 if( rFrom
.GetRed() < rTo
.GetRed() )
177 nDiff
= rTo
.GetRed() - rFrom
.GetRed();
178 aColor
.SetRed( rFrom
.GetRed() + ( nDiff
< 10 ? nDiff
: 10 ) );
180 else if( rFrom
.GetRed() > rTo
.GetRed() )
182 nDiff
= rFrom
.GetRed() - rTo
.GetRed();
183 aColor
.SetRed( rFrom
.GetRed() - ( nDiff
< 10 ? nDiff
: 10 ) );
186 aColor
.SetRed( rFrom
.GetRed() );
189 if( rFrom
.GetGreen() < rTo
.GetGreen() )
191 nDiff
= rTo
.GetGreen() - rFrom
.GetGreen();
192 aColor
.SetGreen( rFrom
.GetGreen() + ( nDiff
< 10 ? nDiff
: 10 ) );
194 else if( rFrom
.GetGreen() > rTo
.GetGreen() )
196 nDiff
= rFrom
.GetGreen() - rTo
.GetGreen();
197 aColor
.SetGreen( rFrom
.GetGreen() - ( nDiff
< 10 ? nDiff
: 10 ) );
200 aColor
.SetGreen( rFrom
.GetGreen() );
203 if( rFrom
.GetBlue() < rTo
.GetBlue() )
205 nDiff
= rTo
.GetBlue() - rFrom
.GetBlue();
206 aColor
.SetBlue( rFrom
.GetBlue() + ( nDiff
< 10 ? nDiff
: 10 ) );
208 else if( rFrom
.GetBlue() > rTo
.GetBlue() )
210 nDiff
= rFrom
.GetBlue() - rTo
.GetBlue();
211 aColor
.SetBlue( rFrom
.GetBlue() - ( nDiff
< 10 ? nDiff
: 10 ) );
214 aColor
.SetBlue( rFrom
.GetBlue() );
220 void MyWin::Paint( const Rectangle
& rRect
)
222 WorkWindow::Paint( rRect
);
225 MapMode
aMapMode( MAP_100TH_MM
);
227 SetMapMode( aMapMode
);
229 Size aPaperSize
= GetOutputSize();
230 Point
aCenter( aPaperSize
.Width()/2-300,
231 (aPaperSize
.Height() - 8400)/2 + 8400 );
232 Point
aP1( aPaperSize
.Width()/48, 0), aP2( aPaperSize
.Width()/40, 0 ), aPoint
;
234 DrawRect( Rectangle( Point( 0,0 ), aPaperSize
) );
235 DrawRect( Rectangle( Point( 100,100 ),
236 Size( aPaperSize
.Width()-200,
237 aPaperSize
.Height()-200 ) ) );
238 DrawRect( Rectangle( Point( 200,200 ),
239 Size( aPaperSize
.Width()-400,
240 aPaperSize
.Height()-400 ) ) );
241 DrawRect( Rectangle( Point( 300,300 ),
242 Size( aPaperSize
.Width()-600,
243 aPaperSize
.Height()-600 ) ) );
245 const int nFontCount
= GetDevFontCount();
246 const int nFontSamples
= (nFontCount
<15) ? nFontCount
: 15;
247 for( int i
= 0; i
< nFontSamples
; ++i
)
250 FontInfo aFont
= GetDevFont( (i
*nFontCount
) / nFontSamples
);
251 aFont
.SetHeight( 400 + (i
%7) * 100 );
252 aFont
.SetOrientation( i
* (3600 / nFontSamples
) );
255 sal_uInt8 nRed
= (i
<< 6) & 0xC0;
256 sal_uInt8 nGreen
= (i
<< 4) & 0xC0;
257 sal_uInt8 nBlue
= (i
<< 2) & 0xC0;
258 SetTextColor( Color( nRed
, nGreen
, nBlue
) );
260 OUStringBuffer
aPrintText(1024);
263 aPrintText
.appendAscii( "SVP test program" );
265 DrawText( Rectangle( Point( (aPaperSize
.Width() - 4000) / 2, 2000 ),
266 Size( aPaperSize
.Width() - 2100 - nMaxWidth
,
267 aPaperSize
.Height() - 4000 ) ),
268 aPrintText
.makeStringAndClear(),
269 TEXT_DRAW_MULTILINE
);
273 DrawRect( Rectangle( Point( aPaperSize
.Width() - 4000, 1000 ),
274 Size( 3000,3000 ) ) );
275 DrawBitmap( Point( aPaperSize
.Width() - 4000, 1000 ),
279 Color
aWhite( 0xff, 0xff, 0xff );
280 Color
aBlack( 0, 0, 0 );
281 Color
aLightRed( 0xff, 0, 0 );
282 Color
aDarkRed( 0x40, 0, 0 );
283 Color
aLightBlue( 0, 0, 0xff );
284 Color
aDarkBlue( 0,0,0x40 );
285 Color
aLightGreen( 0, 0xff, 0 );
286 Color
aDarkGreen( 0, 0x40, 0 );
288 Gradient
aGradient( GradientStyle_LINEAR
, aBlack
, aWhite
);
289 aGradient
.SetAngle( 900 );
290 DrawGradient( Rectangle( Point( 1000, 4500 ),
291 Size( aPaperSize
.Width() - 2000,
292 500 ) ), aGradient
);
293 aGradient
.SetStartColor( aDarkRed
);
294 aGradient
.SetEndColor( aLightBlue
);
295 DrawGradient( Rectangle( Point( 1000, 5300 ),
296 Size( aPaperSize
.Width() - 2000,
297 500 ) ), aGradient
);
298 aGradient
.SetStartColor( aDarkBlue
);
299 aGradient
.SetEndColor( aLightGreen
);
300 DrawGradient( Rectangle( Point( 1000, 6100 ),
301 Size( aPaperSize
.Width() - 2000,
302 500 ) ), aGradient
);
303 aGradient
.SetStartColor( aDarkGreen
);
304 aGradient
.SetEndColor( aLightRed
);
305 DrawGradient( Rectangle( Point( 1000, 6900 ),
306 Size( aPaperSize
.Width() - 2000,
307 500 ) ), aGradient
);
311 LineInfo
aLineInfo( LINE_SOLID
, 200 );
312 double sind
= sin( DELTA
*M_PI
/180.0 );
313 double cosd
= cos( DELTA
*M_PI
/180.0 );
314 double factor
= 1 + (DELTA
/1000.0);
316 Color
aLineColor( 0, 0, 0 );
317 Color
aApproachColor( 0, 0, 200 );
318 while ( aP2
.X() < aCenter
.X() && n
++ < 680 )
320 aLineInfo
.SetWidth( n
/3 );
321 aLineColor
= approachColor( aLineColor
, aApproachColor
);
322 SetLineColor( aLineColor
);
324 // switch aproach color
325 if( aApproachColor
.IsRGBEqual( aLineColor
) )
327 if( aApproachColor
.GetRed() )
328 aApproachColor
= Color( 0, 0, 200 );
329 else if( aApproachColor
.GetGreen() )
330 aApproachColor
= Color( 200, 0, 0 );
332 aApproachColor
= Color( 0, 200, 0 );
335 DrawLine( project( aP1
) + aCenter
,
336 project( aP2
) + aCenter
,
338 aPoint
.X() = (int)((((double)aP1
.X())*cosd
- ((double)aP1
.Y())*sind
)*factor
);
339 aPoint
.Y() = (int)((((double)aP1
.Y())*cosd
+ ((double)aP1
.X())*sind
)*factor
);
341 aPoint
.X() = (int)((((double)aP2
.X())*cosd
- ((double)aP2
.Y())*sind
)*factor
);
342 aPoint
.Y() = (int)((((double)aP2
.Y())*cosd
+ ((double)aP2
.X())*sind
)*factor
);
351 WorkWindow::Resize();
354 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */