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/.
11 * =======================================================================
13 * This is a quick hack to test some stuff. Work in progress. Don't touch
14 * and don't bother inspecting too closely.
16 * =======================================================================
25 #include <glm/gtx/bit.hpp>
27 #include <com/sun/star/lang/XComponent.hpp>
28 #include <com/sun/star/lang/XMultiComponentFactory.hpp>
29 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
30 #include <com/sun/star/ucb/UniversalContentBroker.hpp>
31 #include <comphelper/processfactory.hxx>
32 #include <cppuhelper/bootstrap.hxx>
33 #include <osl/file.hxx>
34 #include <vcl/builder.hxx>
35 #include <vcl/button.hxx>
36 #include <vcl/dialog.hxx>
37 #include <vcl/fixed.hxx>
38 #include <vcl/graph.hxx>
39 #include <vcl/graphicfilter.hxx>
40 #include <vcl/image.hxx>
41 #include <vcl/openglwin.hxx>
42 #include <vcl/opengl/OpenGLContext.hxx>
43 #include <vcl/opengl/OpenGLHelper.hxx>
44 #include <vcl/svapp.hxx>
45 #include <vcl/vclmain.hxx>
46 #include <vcl/wrkwin.hxx>
48 using namespace com::sun::star
;
51 const int WIDTH
= 1000, HEIGHT
= 800;
56 osl_getSystemTime(&aValue
);
57 return (double)aValue
.Seconds
+
58 (double)aValue
.Nanosec
/ (1000*1000*1000);
63 class MyWorkWindow
: public WorkWindow
74 VclPtr
<FixedBitmap
> mpFixedBitmap
;
76 MyWorkWindow( vcl::Window
* pParent
, WinBits nWinStyle
);
77 virtual ~MyWorkWindow() { disposeOnce(); }
78 virtual void dispose() SAL_OVERRIDE
{ mpFixedBitmap
.clear(); WorkWindow::dispose(); }
79 void LoadGraphic( const OUString
& sImageFile
);
81 virtual void Paint( vcl::RenderContext
& /*rRenderContext*/, const Rectangle
& rRect
) SAL_OVERRIDE
;
82 virtual void Resize() SAL_OVERRIDE
;
85 MyWorkWindow::MyWorkWindow( vcl::Window
* pParent
, WinBits nWinStyle
)
86 : WorkWindow(pParent
, nWinStyle
)
91 mnStartTime
= getTimeNow();
95 void MyWorkWindow::LoadGraphic( const OUString
& sImageFile
)
97 SvFileStream
aFileStream( sImageFile
, StreamMode::READ
);
98 GraphicFilter
aGraphicFilter(false);
99 if (aGraphicFilter
.ImportGraphic(maGraphic
, sImageFile
, aFileStream
) != 0)
101 SAL_WARN("vcl.icontest", "Could not import image '" << sImageFile
<< "'");
106 void MyWorkWindow::Paint(vcl::RenderContext
& rRenderContext
, const Rectangle
& rRect
)
108 std::cout
<< "==> Paint! " << mnPaintCount
++ << " (vcl) " << GetSizePixel() << " " << getTimeNow() - mnStartTime
<< std::endl
;
110 Size
aGraphicSize( maGraphic
.GetSizePixel() );
111 float aspect
= ((float) aGraphicSize
.Width()) / aGraphicSize
.Height();
113 if( aspect
>= ((float) WIDTH
) / HEIGHT
)
114 aSize
= Size( WIDTH
, HEIGHT
/aspect
);
116 aSize
= Size( WIDTH
* aspect
, HEIGHT
);
117 aSize
.setWidth( aSize
.Width() * (1 + (0.1*sin(mnPaintCount
/60.))) );
118 aSize
.setHeight( aSize
.Height() * (1 + (0.1*sin(mnPaintCount
/50.))) );
121 mpFixedBitmap
->SetBitmap( aEmpty
);
122 GraphicConversionParameters
aConv( aSize
);
123 mpBitmap
= new Bitmap( maGraphic
.GetBitmap( aConv
) );
124 mpFixedBitmap
->SetBitmap( *mpBitmap
);
125 mpFixedBitmap
->SetSizePixel( aSize
);
127 WorkWindow::Paint(rRenderContext
, rRect
);
129 if (mnPaintCount
== 100)
132 Invalidate( INVALIDATE_CHILDREN
);
135 void MyWorkWindow::Resize()
137 SAL_INFO("vcl.icontest", "Resize " << GetSizePixel());
140 class IconTestApp
: public Application
143 virtual void Init() SAL_OVERRIDE
;
144 virtual int Main() SAL_OVERRIDE
;
146 IconTestApp() : nRet(EXIT_SUCCESS
) {};
151 void DoItWithVcl(const OUString
& sImageFile
);
154 void IconTestApp::Init()
158 uno::Reference
<uno::XComponentContext
> xContext
=
159 cppu::defaultBootstrap_InitialComponentContext();
160 uno::Reference
<lang::XMultiComponentFactory
> xFactory
=
161 xContext
->getServiceManager();
162 uno::Reference
<lang::XMultiServiceFactory
> xSFactory
=
163 uno::Reference
<lang::XMultiServiceFactory
> (xFactory
, uno::UNO_QUERY_THROW
);
164 comphelper::setProcessServiceFactory(xSFactory
);
166 // Create UCB (for backwards compatibility, in case some code still uses
167 // plain createInstance w/o args directly to obtain an instance):
168 ::ucb::UniversalContentBroker::create(
169 comphelper::getProcessComponentContext() );
172 int IconTestApp::Main()
174 if (GetCommandLineParamCount() != 1)
176 fprintf(stderr
, "Usage: imagetest <image>\n");
179 OUString
sImageFile( GetCommandLineParam( 0 ) );
180 DoItWithVcl( sImageFile
);
185 void IconTestApp::DoItWithVcl( const OUString
& sImageFile
)
189 VclPtrInstance
<MyWorkWindow
> pWindow( nullptr, WB_APP
| WB_STDWORK
| WB_SIZEABLE
| WB_CLOSEABLE
| WB_CLIPCHILDREN
);
191 pWindow
->SetText(OUString("VCL Image Test"));
193 pWindow
->LoadGraphic( sImageFile
);
194 pWindow
->mpFixedBitmap
= VclPtr
<FixedBitmap
>::Create( pWindow
);
195 pWindow
->mpFixedBitmap
->SetPosPixel( Point( 0, 0 ) );
196 pWindow
->mpFixedBitmap
->Show();
203 catch (const uno::Exception
&e
)
205 fprintf(stderr
, "fatal error: %s\n", OUStringToOString(e
.Message
, osl_getThreadTextEncoding()).getStr());
208 catch (const std::exception
&e
)
210 fprintf(stderr
, "fatal error: %s\n", e
.what());
215 void vclmain::createApplication()
217 static IconTestApp aApp
;
220 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */