xref: /aoo42x/main/vcl/workben/svptest.cxx (revision 9f62ea84)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #include <sal/main.h>
25 #include <tools/extendapplicationenvironment.hxx>
26 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
27 
28 #include <vcl/event.hxx>
29 #include <vcl/svapp.hxx>
30 #include <vcl/wrkwin.hxx>
31 #include <vcl/gradient.hxx>
32 #include <vcl/lineinfo.hxx>
33 #include <vcl/bitmap.hxx>
34 #include <vcl/bmpacc.hxx>
35 #include <vcl/metric.hxx>
36 
37 #include <rtl/ustrbuf.hxx>
38 
39 #include <math.h>
40 
41 #include <comphelper/processfactory.hxx>
42 #include <cppuhelper/servicefactory.hxx>
43 #include <cppuhelper/bootstrap.hxx>
44 
45 using namespace rtl;
46 using namespace ::com::sun::star::uno;
47 using namespace ::com::sun::star::lang;
48 // -----------------------------------------------------------------------
49 
50 // Forward declaration
51 void Main();
52 
53 // -----------------------------------------------------------------------
54 
SAL_IMPLEMENT_MAIN()55 SAL_IMPLEMENT_MAIN()
56 {
57     tools::extendApplicationEnvironment();
58 
59     Reference< XMultiServiceFactory > xMS;
60     xMS = cppu::createRegistryServiceFactory( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "types.rdb" ) ), rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "applicat.rdb" ) ), sal_True );
61 
62     InitVCL( xMS );
63     ::Main();
64     DeInitVCL();
65 
66     return 0;
67 }
68 
69 // -----------------------------------------------------------------------
70 
71 class MyWin : public WorkWindow
72 {
73     Bitmap      m_aBitmap;
74 public:
75 				MyWin( Window* pParent, WinBits nWinStyle );
76 
77 	void		MouseMove( const MouseEvent& rMEvt );
78 	void		MouseButtonDown( const MouseEvent& rMEvt );
79 	void		MouseButtonUp( const MouseEvent& rMEvt );
80 	void		KeyInput( const KeyEvent& rKEvt );
81 	void		KeyUp( const KeyEvent& rKEvt );
82 	void		Paint( const Rectangle& rRect );
83 	void		Resize();
84 };
85 
86 // -----------------------------------------------------------------------
87 
Main()88 void Main()
89 {
90 	MyWin aMainWin( NULL, WB_APP | WB_STDWORK );
91 	aMainWin.SetText( XubString( RTL_CONSTASCII_USTRINGPARAM( "VCL - Workbench" ) ) );
92 	aMainWin.Show();
93 
94 	Application::Execute();
95 }
96 
97 // -----------------------------------------------------------------------
98 
MyWin(Window * pParent,WinBits nWinStyle)99 MyWin::MyWin( Window* pParent, WinBits nWinStyle ) :
100 	WorkWindow( pParent, nWinStyle ),
101     m_aBitmap( Size( 256, 256 ), 32 )
102 {
103     // prepare an alpha mask
104     BitmapWriteAccess* pAcc = m_aBitmap.AcquireWriteAccess();
105     for( int nX = 0; nX < 256; nX++ )
106     {
107         for( int nY = 0; nY < 256; nY++ )
108         {
109             double fRed = 255.0-1.5*sqrt((double)(nX*nX+nY*nY));
110             if( fRed < 0.0 )
111                 fRed = 0.0;
112             double fGreen = 255.0-1.5*sqrt((double)(((255-nX)*(255-nX)+nY*nY)));
113             if( fGreen < 0.0 )
114                 fGreen = 0.0;
115             double fBlue = 255.0-1.5*sqrt((double)((128-nX)*(128-nX)+(255-nY)*(255-nY)));
116             if( fBlue < 0.0 )
117                 fBlue = 0.0;
118             pAcc->SetPixel( nX, nY, BitmapColor( sal_uInt8(fRed), sal_uInt8(fGreen), sal_uInt8(fBlue) ) );
119         }
120     }
121     m_aBitmap.ReleaseAccess( pAcc );
122 }
123 
124 // -----------------------------------------------------------------------
125 
MouseMove(const MouseEvent & rMEvt)126 void MyWin::MouseMove( const MouseEvent& rMEvt )
127 {
128 	WorkWindow::MouseMove( rMEvt );
129 }
130 
131 // -----------------------------------------------------------------------
132 
MouseButtonDown(const MouseEvent & rMEvt)133 void MyWin::MouseButtonDown( const MouseEvent& rMEvt )
134 {
135 	WorkWindow::MouseButtonDown( rMEvt );
136 }
137 
138 // -----------------------------------------------------------------------
139 
MouseButtonUp(const MouseEvent & rMEvt)140 void MyWin::MouseButtonUp( const MouseEvent& rMEvt )
141 {
142 	WorkWindow::MouseButtonUp( rMEvt );
143 }
144 
145 // -----------------------------------------------------------------------
146 
KeyInput(const KeyEvent & rKEvt)147 void MyWin::KeyInput( const KeyEvent& rKEvt )
148 {
149 	WorkWindow::KeyInput( rKEvt );
150 }
151 
152 // -----------------------------------------------------------------------
153 
KeyUp(const KeyEvent & rKEvt)154 void MyWin::KeyUp( const KeyEvent& rKEvt )
155 {
156 	WorkWindow::KeyUp( rKEvt );
157 }
158 
159 // -----------------------------------------------------------------------
160 
project(const Point & rPoint)161 static Point project( const Point& rPoint )
162 {
163 	const double angle_x = M_PI / 6.0;
164 	const double angle_z = M_PI / 6.0;
165 
166 	// transform planar coordinates to 3d
167 	double x = rPoint.X();
168 	double y = rPoint.Y();
169 	//double z = 0;
170 
171 	// rotate around X axis
172 	double x1 = x;
173 	double y1 = y * cos( angle_x );
174 	double z1 = y * sin( angle_x );
175 
176 	// rotate around Z axis
177 	double x2 = x1 * cos( angle_z ) + y1 * sin( angle_z );
178 	//double y2 = y1 * cos( angle_z ) - x1 * sin( angle_z );
179 	double z2 = z1;
180 
181 	return Point( (sal_Int32)x2, (sal_Int32)z2 );
182 }
183 
approachColor(const Color & rFrom,const Color & rTo)184 static Color approachColor( const Color& rFrom, const Color& rTo )
185 {
186 	Color aColor;
187 	sal_uInt8 nDiff;
188 	// approach red
189 	if( rFrom.GetRed() < rTo.GetRed() )
190 	{
191 		nDiff = rTo.GetRed() - rFrom.GetRed();
192 		aColor.SetRed( rFrom.GetRed() + ( nDiff < 10 ? nDiff : 10 ) );
193 	}
194 	else if( rFrom.GetRed() > rTo.GetRed() )
195 	{
196 		nDiff = rFrom.GetRed() - rTo.GetRed();
197 		aColor.SetRed( rFrom.GetRed() - ( nDiff < 10 ? nDiff : 10 ) );
198 	}
199 	else
200 		aColor.SetRed( rFrom.GetRed() );
201 
202 	// approach Green
203 	if( rFrom.GetGreen() < rTo.GetGreen() )
204 	{
205 		nDiff = rTo.GetGreen() - rFrom.GetGreen();
206 		aColor.SetGreen( rFrom.GetGreen() + ( nDiff < 10 ? nDiff : 10 ) );
207 	}
208 	else if( rFrom.GetGreen() > rTo.GetGreen() )
209 	{
210 		nDiff = rFrom.GetGreen() - rTo.GetGreen();
211 		aColor.SetGreen( rFrom.GetGreen() - ( nDiff < 10 ? nDiff : 10 ) );
212 	}
213 	else
214 		aColor.SetGreen( rFrom.GetGreen() );
215 
216 	// approach blue
217 	if( rFrom.GetBlue() < rTo.GetBlue() )
218 	{
219 		nDiff = rTo.GetBlue() - rFrom.GetBlue();
220 		aColor.SetBlue( rFrom.GetBlue() + ( nDiff < 10 ? nDiff : 10 ) );
221 	}
222 	else if( rFrom.GetBlue() > rTo.GetBlue() )
223 	{
224 		nDiff = rFrom.GetBlue() - rTo.GetBlue();
225 		aColor.SetBlue( rFrom.GetBlue() - ( nDiff < 10 ? nDiff : 10 ) );
226 	}
227 	else
228 		aColor.SetBlue( rFrom.GetBlue() );
229 
230 	return aColor;
231 }
232 
233 #define DELTA 5.0
Paint(const Rectangle & rRect)234 void MyWin::Paint( const Rectangle& rRect )
235 {
236 	WorkWindow::Paint( rRect );
237 
238     Push( PUSH_ALL );
239 	MapMode aMapMode( MAP_100TH_MM );
240 
241 	SetMapMode( aMapMode );
242 
243 	Size aPaperSize = GetOutputSize();
244 	Point aCenter( aPaperSize.Width()/2-300,
245 				   (aPaperSize.Height() - 8400)/2 + 8400 );
246 	Point aP1( aPaperSize.Width()/48, 0), aP2( aPaperSize.Width()/40, 0 ), aPoint;
247 
248 	DrawRect( Rectangle( Point( 0,0 ), aPaperSize ) );
249 	DrawRect( Rectangle( Point( 100,100 ),
250                          Size( aPaperSize.Width()-200,
251                                aPaperSize.Height()-200 ) ) );
252 	DrawRect( Rectangle( Point( 200,200 ),
253                          Size( aPaperSize.Width()-400,
254                                aPaperSize.Height()-400 ) ) );
255 	DrawRect( Rectangle( Point( 300,300 ),
256                          Size( aPaperSize.Width()-600,
257                                aPaperSize.Height()-600 ) ) );
258 
259     // AllSettings aSettings( Application::GetSettings() );
260 
261     const int nFontCount = GetDevFontCount();
262     const int nFontSamples = (nFontCount<15) ? nFontCount : 15;
263     for( int i = 0; i < nFontSamples; ++i )
264     {
265 #if 0
266         Font aFont( GetFont() );
267         aFont.SetName( String( RTL_CONSTASCII_USTRINGPARAM( "Courier" ) ) );
268         aFont.SetWeight( WEIGHT_NORMAL );
269         aFont.SetItalic( ITALIC_NONE );
270 #else
271         FontInfo aFont = GetDevFont( (i*nFontCount) / nFontSamples );
272         aFont.SetHeight( 400 + (i%7) * 100 );
273         aFont.SetOrientation( i * (3600 / nFontSamples) );
274 #endif
275         SetFont( aFont );
276 
277         sal_uInt8 nRed   = (i << 6) & 0xC0;
278         sal_uInt8 nGreen = (i << 4) & 0xC0;
279         sal_uInt8 nBlue  = (i << 2) & 0xC0;
280         SetTextColor( Color( nRed, nGreen, nBlue ) );
281 
282         OUStringBuffer aPrintText(1024);
283         long nMaxWidth = 0;
284 
285         aPrintText.appendAscii( "SVP test program" );
286 
287         DrawText( Rectangle( Point( (aPaperSize.Width() - 4000) / 2, 2000 ),
288                             Size( aPaperSize.Width() - 2100 - nMaxWidth,
289                                 aPaperSize.Height() - 4000 ) ),
290                 aPrintText.makeStringAndClear(),
291                 TEXT_DRAW_MULTILINE );
292     }
293 
294 	SetFillColor();
295 	DrawRect( Rectangle( Point( aPaperSize.Width() - 4000, 1000 ),
296                          Size( 3000,3000 ) ) );
297     DrawBitmap( Point( aPaperSize.Width() - 4000, 1000 ),
298                 Size( 3000,3000 ),
299                 m_aBitmap );
300 
301 	Color aWhite( 0xff, 0xff, 0xff );
302 	Color aBlack( 0, 0, 0 );
303 	Color aLightRed( 0xff, 0, 0 );
304 	Color aDarkRed( 0x40, 0, 0 );
305 	Color aLightBlue( 0, 0, 0xff );
306 	Color aDarkBlue( 0,0,0x40 );
307 	Color aLightGreen( 0, 0xff, 0 );
308 	Color aDarkGreen( 0, 0x40, 0 );
309 
310 	Gradient aGradient( GRADIENT_LINEAR, aBlack, aWhite );
311 	aGradient.SetAngle( 900 );
312 	DrawGradient( Rectangle( Point( 1000, 4500 ),
313                              Size( aPaperSize.Width() - 2000,
314                                    500 ) ), aGradient );
315 	aGradient.SetStartColor( aDarkRed );
316 	aGradient.SetEndColor( aLightBlue );
317 	DrawGradient( Rectangle( Point( 1000, 5300 ),
318                              Size( aPaperSize.Width() - 2000,
319                                    500 ) ), aGradient );
320 	aGradient.SetStartColor( aDarkBlue );
321 	aGradient.SetEndColor( aLightGreen );
322 	DrawGradient( Rectangle( Point( 1000, 6100 ),
323                              Size( aPaperSize.Width() - 2000,
324                                    500 ) ), aGradient );
325 	aGradient.SetStartColor( aDarkGreen );
326 	aGradient.SetEndColor( aLightRed );
327 	DrawGradient( Rectangle( Point( 1000, 6900 ),
328                              Size( aPaperSize.Width() - 2000,
329                                    500 ) ), aGradient );
330 
331 
332 
333 	LineInfo aLineInfo( LINE_SOLID, 200 );
334 	double sind = sin( DELTA*M_PI/180.0 );
335 	double cosd = cos( DELTA*M_PI/180.0 );
336 	double factor = 1 + (DELTA/1000.0);
337 	int n=0;
338 	Color aLineColor( 0, 0, 0 );
339 	Color aApproachColor( 0, 0, 200 );
340 	while ( aP2.X() < aCenter.X() && n++ < 680 )
341 	{
342 		aLineInfo.SetWidth( n/3 );
343 		aLineColor = approachColor( aLineColor, aApproachColor );
344 		SetLineColor( aLineColor );
345 
346 		// switch aproach color
347 		if( aApproachColor.IsRGBEqual( aLineColor ) )
348 		{
349 			if( aApproachColor.GetRed() )
350 				aApproachColor = Color( 0, 0, 200 );
351 			else if( aApproachColor.GetGreen() )
352 				aApproachColor = Color( 200, 0, 0 );
353 			else
354 				aApproachColor = Color( 0, 200, 0 );
355 		}
356 
357 		DrawLine( project( aP1 ) + aCenter,
358                   project( aP2 ) + aCenter,
359                   aLineInfo );
360 		aPoint.X() = (int)((((double)aP1.X())*cosd - ((double)aP1.Y())*sind)*factor);
361 		aPoint.Y() = (int)((((double)aP1.Y())*cosd + ((double)aP1.X())*sind)*factor);
362 		aP1 = aPoint;
363 		aPoint.X() = (int)((((double)aP2.X())*cosd - ((double)aP2.Y())*sind)*factor);
364 		aPoint.Y() = (int)((((double)aP2.Y())*cosd + ((double)aP2.X())*sind)*factor);
365 		aP2 = aPoint;
366 	}
367     Pop();
368 }
369 
370 // -----------------------------------------------------------------------
371 
Resize()372 void MyWin::Resize()
373 {
374 	WorkWindow::Resize();
375 }
376