Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include <sal/main.h>
21 : #include <tools/extendapplicationenvironment.hxx>
22 :
23 : #include <cppuhelper/bootstrap.hxx>
24 : #include <comphelper/processfactory.hxx>
25 :
26 : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
27 : #include <com/sun/star/uno/XComponentContext.hpp>
28 :
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 :
38 : #include <rtl/ustrbuf.hxx>
39 :
40 : #include <math.h>
41 :
42 : using namespace ::com::sun::star::uno;
43 : using namespace ::com::sun::star::lang;
44 : using namespace cppu;
45 :
46 : // Forward declaration
47 : void Main();
48 :
49 0 : SAL_IMPLEMENT_MAIN()
50 : {
51 0 : tools::extendApplicationEnvironment();
52 :
53 0 : Reference< XComponentContext > xContext = defaultBootstrap_InitialComponentContext();
54 0 : Reference< XMultiServiceFactory > xServiceManager( xContext->getServiceManager(), UNO_QUERY );
55 :
56 0 : if( !xServiceManager.is() )
57 0 : Application::Abort( "Failed to bootstrap" );
58 :
59 0 : comphelper::setProcessServiceFactory( xServiceManager );
60 :
61 0 : InitVCL();
62 0 : ::Main();
63 0 : DeInitVCL();
64 :
65 0 : return 0;
66 : }
67 :
68 0 : class MyWin : public WorkWindow
69 : {
70 : Bitmap m_aBitmap;
71 : public:
72 : MyWin( vcl::Window* pParent, WinBits nWinStyle );
73 :
74 : virtual void MouseMove( const MouseEvent& rMEvt ) SAL_OVERRIDE;
75 : virtual void MouseButtonDown( const MouseEvent& rMEvt ) SAL_OVERRIDE;
76 : virtual void MouseButtonUp( const MouseEvent& rMEvt ) SAL_OVERRIDE;
77 : virtual void KeyInput( const KeyEvent& rKEvt ) SAL_OVERRIDE;
78 : virtual void KeyUp( const KeyEvent& rKEvt ) SAL_OVERRIDE;
79 : virtual void Paint( const Rectangle& rRect ) SAL_OVERRIDE;
80 : virtual void Resize() SAL_OVERRIDE;
81 : };
82 :
83 0 : void Main()
84 : {
85 0 : MyWin aMainWin( NULL, WB_APP | WB_STDWORK );
86 0 : aMainWin.SetText( OUString( "VCL - Workbench" ) );
87 0 : aMainWin.Show();
88 :
89 0 : Application::Execute();
90 0 : }
91 :
92 0 : MyWin::MyWin( vcl::Window* pParent, WinBits nWinStyle ) :
93 : WorkWindow( pParent, nWinStyle ),
94 0 : m_aBitmap( Size( 256, 256 ), 32 )
95 : {
96 : // prepare an alpha mask
97 0 : BitmapWriteAccess* pAcc = m_aBitmap.AcquireWriteAccess();
98 0 : for( int nX = 0; nX < 256; nX++ )
99 : {
100 0 : for( int nY = 0; nY < 256; nY++ )
101 : {
102 0 : double fRed = 255.0-1.5*sqrt((double)(nX*nX+nY*nY));
103 0 : if( fRed < 0.0 )
104 0 : fRed = 0.0;
105 0 : double fGreen = 255.0-1.5*sqrt((double)(((255-nX)*(255-nX)+nY*nY)));
106 0 : if( fGreen < 0.0 )
107 0 : fGreen = 0.0;
108 0 : double fBlue = 255.0-1.5*sqrt((double)((128-nX)*(128-nX)+(255-nY)*(255-nY)));
109 0 : if( fBlue < 0.0 )
110 0 : fBlue = 0.0;
111 0 : pAcc->SetPixel( nY, nX, BitmapColor( sal_uInt8(fRed), sal_uInt8(fGreen), sal_uInt8(fBlue) ) );
112 : }
113 : }
114 0 : m_aBitmap.ReleaseAccess( pAcc );
115 0 : }
116 :
117 0 : void MyWin::MouseMove( const MouseEvent& rMEvt )
118 : {
119 0 : WorkWindow::MouseMove( rMEvt );
120 0 : }
121 :
122 0 : void MyWin::MouseButtonDown( const MouseEvent& rMEvt )
123 : {
124 0 : WorkWindow::MouseButtonDown( rMEvt );
125 0 : }
126 :
127 0 : void MyWin::MouseButtonUp( const MouseEvent& rMEvt )
128 : {
129 0 : WorkWindow::MouseButtonUp( rMEvt );
130 0 : }
131 :
132 0 : void MyWin::KeyInput( const KeyEvent& rKEvt )
133 : {
134 0 : WorkWindow::KeyInput( rKEvt );
135 0 : }
136 :
137 0 : void MyWin::KeyUp( const KeyEvent& rKEvt )
138 : {
139 0 : WorkWindow::KeyUp( rKEvt );
140 0 : }
141 :
142 0 : static Point project( const Point& rPoint )
143 : {
144 0 : const double angle_x = M_PI / 6.0;
145 0 : const double angle_z = M_PI / 6.0;
146 :
147 : // transform planar coordinates to 3d
148 0 : double x = rPoint.X();
149 0 : double y = rPoint.Y();
150 :
151 : // rotate around X axis
152 0 : double x1 = x;
153 0 : double y1 = y * cos( angle_x );
154 0 : double z1 = y * sin( angle_x );
155 :
156 : // rotate around Z axis
157 0 : double x2 = x1 * cos( angle_z ) + y1 * sin( angle_z );
158 : //double y2 = y1 * cos( angle_z ) - x1 * sin( angle_z );
159 0 : double z2 = z1;
160 :
161 0 : return Point( (sal_Int32)x2, (sal_Int32)z2 );
162 : }
163 :
164 0 : static Color approachColor( const Color& rFrom, const Color& rTo )
165 : {
166 0 : Color aColor;
167 : sal_uInt8 nDiff;
168 : // approach red
169 0 : if( rFrom.GetRed() < rTo.GetRed() )
170 : {
171 0 : nDiff = rTo.GetRed() - rFrom.GetRed();
172 0 : aColor.SetRed( rFrom.GetRed() + ( nDiff < 10 ? nDiff : 10 ) );
173 : }
174 0 : else if( rFrom.GetRed() > rTo.GetRed() )
175 : {
176 0 : nDiff = rFrom.GetRed() - rTo.GetRed();
177 0 : aColor.SetRed( rFrom.GetRed() - ( nDiff < 10 ? nDiff : 10 ) );
178 : }
179 : else
180 0 : aColor.SetRed( rFrom.GetRed() );
181 :
182 : // approach Green
183 0 : if( rFrom.GetGreen() < rTo.GetGreen() )
184 : {
185 0 : nDiff = rTo.GetGreen() - rFrom.GetGreen();
186 0 : aColor.SetGreen( rFrom.GetGreen() + ( nDiff < 10 ? nDiff : 10 ) );
187 : }
188 0 : else if( rFrom.GetGreen() > rTo.GetGreen() )
189 : {
190 0 : nDiff = rFrom.GetGreen() - rTo.GetGreen();
191 0 : aColor.SetGreen( rFrom.GetGreen() - ( nDiff < 10 ? nDiff : 10 ) );
192 : }
193 : else
194 0 : aColor.SetGreen( rFrom.GetGreen() );
195 :
196 : // approach blue
197 0 : if( rFrom.GetBlue() < rTo.GetBlue() )
198 : {
199 0 : nDiff = rTo.GetBlue() - rFrom.GetBlue();
200 0 : aColor.SetBlue( rFrom.GetBlue() + ( nDiff < 10 ? nDiff : 10 ) );
201 : }
202 0 : else if( rFrom.GetBlue() > rTo.GetBlue() )
203 : {
204 0 : nDiff = rFrom.GetBlue() - rTo.GetBlue();
205 0 : aColor.SetBlue( rFrom.GetBlue() - ( nDiff < 10 ? nDiff : 10 ) );
206 : }
207 : else
208 0 : aColor.SetBlue( rFrom.GetBlue() );
209 :
210 0 : return aColor;
211 : }
212 :
213 : #define DELTA 5.0
214 0 : void MyWin::Paint( const Rectangle& rRect )
215 : {
216 0 : WorkWindow::Paint( rRect );
217 :
218 0 : Push( PushFlags::ALL );
219 0 : MapMode aMapMode( MAP_100TH_MM );
220 :
221 0 : SetMapMode( aMapMode );
222 :
223 0 : Size aPaperSize = GetOutputSize();
224 0 : Point aCenter( aPaperSize.Width()/2-300,
225 0 : (aPaperSize.Height() - 8400)/2 + 8400 );
226 0 : Point aP1( aPaperSize.Width()/48, 0), aP2( aPaperSize.Width()/40, 0 ), aPoint;
227 :
228 0 : DrawRect( Rectangle( Point( 0,0 ), aPaperSize ) );
229 : DrawRect( Rectangle( Point( 100,100 ),
230 0 : Size( aPaperSize.Width()-200,
231 0 : aPaperSize.Height()-200 ) ) );
232 : DrawRect( Rectangle( Point( 200,200 ),
233 0 : Size( aPaperSize.Width()-400,
234 0 : aPaperSize.Height()-400 ) ) );
235 : DrawRect( Rectangle( Point( 300,300 ),
236 0 : Size( aPaperSize.Width()-600,
237 0 : aPaperSize.Height()-600 ) ) );
238 :
239 0 : const int nFontCount = GetDevFontCount();
240 0 : const int nFontSamples = (nFontCount<15) ? nFontCount : 15;
241 0 : for( int i = 0; i < nFontSamples; ++i )
242 : {
243 :
244 0 : vcl::FontInfo aFont = GetDevFont( (i*nFontCount) / nFontSamples );
245 0 : aFont.SetHeight( 400 + (i%7) * 100 );
246 0 : aFont.SetOrientation( i * (3600 / nFontSamples) );
247 0 : SetFont( aFont );
248 :
249 0 : sal_uInt8 nRed = (i << 6) & 0xC0;
250 0 : sal_uInt8 nGreen = (i << 4) & 0xC0;
251 0 : sal_uInt8 nBlue = (i << 2) & 0xC0;
252 0 : SetTextColor( Color( nRed, nGreen, nBlue ) );
253 :
254 0 : OUStringBuffer aPrintText(1024);
255 0 : long nMaxWidth = 0;
256 :
257 0 : aPrintText.appendAscii( "SVP test program" );
258 :
259 0 : DrawText( Rectangle( Point( (aPaperSize.Width() - 4000) / 2, 2000 ),
260 0 : Size( aPaperSize.Width() - 2100 - nMaxWidth,
261 0 : aPaperSize.Height() - 4000 ) ),
262 : aPrintText.makeStringAndClear(),
263 0 : TEXT_DRAW_MULTILINE );
264 0 : }
265 :
266 0 : SetFillColor();
267 0 : DrawRect( Rectangle( Point( aPaperSize.Width() - 4000, 1000 ),
268 0 : Size( 3000,3000 ) ) );
269 0 : DrawBitmap( Point( aPaperSize.Width() - 4000, 1000 ),
270 : Size( 3000,3000 ),
271 0 : m_aBitmap );
272 :
273 0 : Color aWhite( 0xff, 0xff, 0xff );
274 0 : Color aBlack( 0, 0, 0 );
275 0 : Color aLightRed( 0xff, 0, 0 );
276 0 : Color aDarkRed( 0x40, 0, 0 );
277 0 : Color aLightBlue( 0, 0, 0xff );
278 0 : Color aDarkBlue( 0,0,0x40 );
279 0 : Color aLightGreen( 0, 0xff, 0 );
280 0 : Color aDarkGreen( 0, 0x40, 0 );
281 :
282 0 : Gradient aGradient( GradientStyle_LINEAR, aBlack, aWhite );
283 0 : aGradient.SetAngle( 900 );
284 : DrawGradient( Rectangle( Point( 1000, 4500 ),
285 0 : Size( aPaperSize.Width() - 2000,
286 0 : 500 ) ), aGradient );
287 0 : aGradient.SetStartColor( aDarkRed );
288 0 : aGradient.SetEndColor( aLightBlue );
289 : DrawGradient( Rectangle( Point( 1000, 5300 ),
290 0 : Size( aPaperSize.Width() - 2000,
291 0 : 500 ) ), aGradient );
292 0 : aGradient.SetStartColor( aDarkBlue );
293 0 : aGradient.SetEndColor( aLightGreen );
294 : DrawGradient( Rectangle( Point( 1000, 6100 ),
295 0 : Size( aPaperSize.Width() - 2000,
296 0 : 500 ) ), aGradient );
297 0 : aGradient.SetStartColor( aDarkGreen );
298 0 : aGradient.SetEndColor( aLightRed );
299 : DrawGradient( Rectangle( Point( 1000, 6900 ),
300 0 : Size( aPaperSize.Width() - 2000,
301 0 : 500 ) ), aGradient );
302 :
303 0 : LineInfo aLineInfo( LINE_SOLID, 200 );
304 0 : double sind = sin( DELTA*M_PI/180.0 );
305 0 : double cosd = cos( DELTA*M_PI/180.0 );
306 0 : double factor = 1 + (DELTA/1000.0);
307 0 : int n=0;
308 0 : Color aLineColor( 0, 0, 0 );
309 0 : Color aApproachColor( 0, 0, 200 );
310 0 : while ( aP2.X() < aCenter.X() && n++ < 680 )
311 : {
312 0 : aLineInfo.SetWidth( n/3 );
313 0 : aLineColor = approachColor( aLineColor, aApproachColor );
314 0 : SetLineColor( aLineColor );
315 :
316 : // switch aproach color
317 0 : if( aApproachColor.IsRGBEqual( aLineColor ) )
318 : {
319 0 : if( aApproachColor.GetRed() )
320 0 : aApproachColor = Color( 0, 0, 200 );
321 0 : else if( aApproachColor.GetGreen() )
322 0 : aApproachColor = Color( 200, 0, 0 );
323 : else
324 0 : aApproachColor = Color( 0, 200, 0 );
325 : }
326 :
327 0 : DrawLine( project( aP1 ) + aCenter,
328 0 : project( aP2 ) + aCenter,
329 0 : aLineInfo );
330 0 : aPoint.X() = (int)((((double)aP1.X())*cosd - ((double)aP1.Y())*sind)*factor);
331 0 : aPoint.Y() = (int)((((double)aP1.Y())*cosd + ((double)aP1.X())*sind)*factor);
332 0 : aP1 = aPoint;
333 0 : aPoint.X() = (int)((((double)aP2.X())*cosd - ((double)aP2.Y())*sind)*factor);
334 0 : aPoint.Y() = (int)((((double)aP2.Y())*cosd + ((double)aP2.X())*sind)*factor);
335 0 : aP2 = aPoint;
336 : }
337 0 : Pop();
338 0 : }
339 :
340 0 : void MyWin::Resize()
341 : {
342 0 : WorkWindow::Resize();
343 0 : }
344 :
345 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|