LCOV - code coverage report
Current view: top level - vcl/workben - svptest.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 0 182 0.0 %
Date: 2015-06-13 12:38:46 Functions: 0 15 0.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.11