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