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 * =======================================================================
23 #include <glm/gtx/bit.hpp>
25 #include <com/sun/star/lang/XComponent.hpp>
26 #include <com/sun/star/lang/XMultiComponentFactory.hpp>
27 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
28 #include <com/sun/star/ucb/UniversalContentBroker.hpp>
29 #include <comphelper/processfactory.hxx>
30 #include <cppuhelper/bootstrap.hxx>
31 #include <osl/file.hxx>
32 #include <vcl/builder.hxx>
33 #include <vcl/button.hxx>
34 #include <vcl/dialog.hxx>
35 #include <vcl/fixed.hxx>
36 #include <vcl/graph.hxx>
37 #include <vcl/graphicfilter.hxx>
38 #include <vcl/image.hxx>
39 #include <vcl/openglwin.hxx>
40 #include <vcl/opengl/OpenGLContext.hxx>
41 #include <vcl/opengl/OpenGLHelper.hxx>
42 #include <vcl/svapp.hxx>
43 #include <vcl/vclmain.hxx>
44 #include <vcl/wrkwin.hxx>
46 using namespace com::sun::star
;
49 const int WIDTH
= 1000, HEIGHT
= 800;
54 osl_getSystemTime(&aValue
);
55 return (double)aValue
.Seconds
+
56 (double)aValue
.Nanosec
/ (1000*1000*1000);
61 class MyWorkWindow
: public WorkWindow
72 VclPtr
<FixedBitmap
> mpFixedBitmap
;
74 MyWorkWindow( vcl::Window
* pParent
, WinBits nWinStyle
);
75 virtual ~MyWorkWindow() override
{ disposeOnce(); }
76 virtual void dispose() override
{ mpFixedBitmap
.clear(); WorkWindow::dispose(); }
77 void LoadGraphic( const OUString
& sImageFile
);
79 virtual void Paint( vcl::RenderContext
& /*rRenderContext*/, const tools::Rectangle
& rRect
) override
;
80 virtual void Resize() override
;
83 MyWorkWindow::MyWorkWindow( vcl::Window
* pParent
, WinBits nWinStyle
)
84 : WorkWindow(pParent
, nWinStyle
)
86 , mpFixedBitmap(nullptr)
89 mnStartTime
= getTimeNow();
93 void MyWorkWindow::LoadGraphic( const OUString
& sImageFile
)
95 SvFileStream
aFileStream( sImageFile
, StreamMode::READ
);
96 GraphicFilter
aGraphicFilter(false);
97 if (aGraphicFilter
.ImportGraphic(maGraphic
, sImageFile
, aFileStream
) != 0)
99 SAL_WARN("vcl.icontest", "Could not import image '" << sImageFile
<< "'");
104 void MyWorkWindow::Paint(vcl::RenderContext
& rRenderContext
, const tools::Rectangle
& rRect
)
106 std::cout
<< "==> Paint! " << mnPaintCount
++ << " (vcl) " << GetSizePixel() << " " << getTimeNow() - mnStartTime
<< std::endl
;
108 Size
aGraphicSize( maGraphic
.GetSizePixel() );
109 float aspect
= ((float) aGraphicSize
.Width()) / aGraphicSize
.Height();
111 if( aspect
>= ((float) WIDTH
) / HEIGHT
)
112 aSize
= Size( WIDTH
, HEIGHT
/aspect
);
114 aSize
= Size( WIDTH
* aspect
, HEIGHT
);
115 aSize
.setWidth( aSize
.Width() * (1 + (0.1*sin(mnPaintCount
/60.))) );
116 aSize
.setHeight( aSize
.Height() * (1 + (0.1*sin(mnPaintCount
/50.))) );
119 mpFixedBitmap
->SetBitmap( aEmpty
);
120 GraphicConversionParameters
aConv( aSize
);
121 mpBitmap
= new Bitmap( maGraphic
.GetBitmap( aConv
) );
122 mpFixedBitmap
->SetBitmap( *mpBitmap
);
123 mpFixedBitmap
->SetSizePixel( aSize
);
125 WorkWindow::Paint(rRenderContext
, rRect
);
127 if (mnPaintCount
== 100)
130 Invalidate( InvalidateFlags::Children
);
133 void MyWorkWindow::Resize()
135 SAL_INFO("vcl.icontest", "Resize " << GetSizePixel());
138 class IconTestApp
: public Application
141 virtual void Init() override
;
142 virtual int Main() override
;
144 IconTestApp() : nRet(EXIT_SUCCESS
) {};
149 void DoItWithVcl(const OUString
& sImageFile
);
152 void IconTestApp::Init()
156 uno::Reference
<uno::XComponentContext
> xContext
=
157 cppu::defaultBootstrap_InitialComponentContext();
158 uno::Reference
<lang::XMultiComponentFactory
> xFactory
=
159 xContext
->getServiceManager();
160 uno::Reference
<lang::XMultiServiceFactory
> xSFactory
=
161 uno::Reference
<lang::XMultiServiceFactory
> (xFactory
, uno::UNO_QUERY_THROW
);
162 comphelper::setProcessServiceFactory(xSFactory
);
164 // Create UCB (for backwards compatibility, in case some code still uses
165 // plain createInstance w/o args directly to obtain an instance):
166 ::ucb::UniversalContentBroker::create(
167 comphelper::getProcessComponentContext() );
170 int IconTestApp::Main()
172 if (GetCommandLineParamCount() != 1)
174 fprintf(stderr
, "Usage: imagetest <image>\n");
177 OUString
sImageFile( GetCommandLineParam( 0 ) );
178 DoItWithVcl( sImageFile
);
183 void IconTestApp::DoItWithVcl( const OUString
& sImageFile
)
187 VclPtrInstance
<MyWorkWindow
> pWindow( nullptr, WB_APP
| WB_STDWORK
| WB_SIZEABLE
| WB_CLOSEABLE
| WB_CLIPCHILDREN
);
189 pWindow
->SetText("VCL Image Test");
191 pWindow
->LoadGraphic( sImageFile
);
192 pWindow
->mpFixedBitmap
= VclPtr
<FixedBitmap
>::Create( pWindow
);
193 pWindow
->mpFixedBitmap
->SetPosPixel( Point( 0, 0 ) );
194 pWindow
->mpFixedBitmap
->Show();
201 catch (const uno::Exception
&e
)
203 fprintf(stderr
, "fatal error: %s\n", OUStringToOString(e
.Message
, osl_getThreadTextEncoding()).getStr());
206 catch (const std::exception
&e
)
208 fprintf(stderr
, "fatal error: %s\n", e
.what());
213 void vclmain::createApplication()
215 static IconTestApp aApp
;
218 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */