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 <sal/log.hxx>
33 #include <tools/stream.hxx>
34 #include <vcl/builder.hxx>
35 #include <vcl/toolkit/button.hxx>
36 #include <vcl/toolkit/dialog.hxx>
37 #include <vcl/toolkit/fixed.hxx>
38 #include <vcl/graph.hxx>
39 #include <vcl/graphicfilter.hxx>
40 #include <vcl/image.hxx>
41 #include <vcl/opengl/OpenGLContext.hxx>
42 #include <vcl/opengl/OpenGLHelper.hxx>
43 #include <vcl/svapp.hxx>
44 #include <vcl/vclmain.hxx>
45 #include <vcl/wrkwin.hxx>
47 using namespace com::sun::star
;
50 const int WIDTH
= 1000, HEIGHT
= 800;
55 osl_getSystemTime(&aValue
);
56 return static_cast<double>(aValue
.Seconds
) +
57 static_cast<double>(aValue
.Nanosec
) / (1000*1000*1000);
60 class MyWorkWindow
: public WorkWindow
68 VclPtr
<FixedBitmap
> mpFixedBitmap
;
70 MyWorkWindow( vcl::Window
* pParent
, WinBits nWinStyle
);
71 virtual ~MyWorkWindow() override
{ disposeOnce(); }
72 virtual void dispose() override
{ mpFixedBitmap
.clear(); WorkWindow::dispose(); }
73 void LoadGraphic( const OUString
& sImageFile
);
75 virtual void Paint( vcl::RenderContext
& /*rRenderContext*/, const tools::Rectangle
& rRect
) override
;
76 virtual void Resize() override
;
81 MyWorkWindow::MyWorkWindow( vcl::Window
* pParent
, WinBits nWinStyle
)
82 : WorkWindow(pParent
, nWinStyle
)
84 , mpFixedBitmap(nullptr)
87 mnStartTime
= getTimeNow();
91 void MyWorkWindow::LoadGraphic( const OUString
& sImageFile
)
93 SvFileStream
aFileStream( sImageFile
, StreamMode::READ
);
94 GraphicFilter
aGraphicFilter(false);
95 if (aGraphicFilter
.ImportGraphic(maGraphic
, sImageFile
, aFileStream
) != ERRCODE_NONE
)
97 SAL_WARN("vcl.icontest", "Could not import image '" << sImageFile
<< "'");
102 void MyWorkWindow::Paint(vcl::RenderContext
& rRenderContext
, const tools::Rectangle
& rRect
)
104 std::cout
<< "==> Paint! " << mnPaintCount
++ << " (vcl) " << GetSizePixel() << " " << getTimeNow() - mnStartTime
<< std::endl
;
106 Size
aGraphicSize( maGraphic
.GetSizePixel() );
107 float aspect
= static_cast<float>(aGraphicSize
.Width()) / aGraphicSize
.Height();
109 if( aspect
>= (float(WIDTH
)) / HEIGHT
)
110 aSize
= Size( WIDTH
, HEIGHT
/aspect
);
112 aSize
= Size( WIDTH
* aspect
, HEIGHT
);
113 aSize
.setWidth( aSize
.Width() * (1 + (0.1*sin(mnPaintCount
/60.))) );
114 aSize
.setHeight( aSize
.Height() * (1 + (0.1*sin(mnPaintCount
/50.))) );
117 mpFixedBitmap
->SetBitmap( aEmpty
);
118 GraphicConversionParameters
aConv( aSize
);
119 mpBitmap
= new BitmapEx(maGraphic
.GetBitmapEx( aConv
));
120 mpFixedBitmap
->SetBitmap( *mpBitmap
);
121 mpFixedBitmap
->SetSizePixel( aSize
);
123 WorkWindow::Paint(rRenderContext
, rRect
);
125 if (mnPaintCount
== 100)
128 Invalidate( InvalidateFlags::Children
);
131 void MyWorkWindow::Resize()
133 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
);
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(xFactory
, uno::UNO_QUERY_THROW
);
163 comphelper::setProcessServiceFactory(xSFactory
);
165 // Create UCB (for backwards compatibility, in case some code still uses
166 // plain createInstance w/o args directly to obtain an instance):
167 ::ucb::UniversalContentBroker::create(
168 comphelper::getProcessComponentContext() );
171 int IconTestApp::Main()
173 if (GetCommandLineParamCount() != 1)
175 fprintf(stderr
, "Usage: imagetest <image>\n");
178 OUString
sImageFile( GetCommandLineParam( 0 ) );
179 DoItWithVcl( sImageFile
);
184 void IconTestApp::DoItWithVcl( const OUString
& sImageFile
)
188 VclPtrInstance
<MyWorkWindow
> pWindow( nullptr, WB_APP
| WB_STDWORK
| WB_SIZEABLE
| WB_CLOSEABLE
| WB_CLIPCHILDREN
);
190 pWindow
->SetText("VCL Image Test");
192 pWindow
->LoadGraphic( sImageFile
);
193 pWindow
->mpFixedBitmap
= VclPtr
<FixedBitmap
>::Create( pWindow
);
194 pWindow
->mpFixedBitmap
->SetPosPixel( Point( 0, 0 ) );
195 pWindow
->mpFixedBitmap
->Show();
202 catch (const uno::Exception
&e
)
204 fprintf(stderr
, "fatal error: %s\n", OUStringToOString(e
.Message
, osl_getThreadTextEncoding()).getStr());
207 catch (const std::exception
&e
)
209 fprintf(stderr
, "fatal error: %s\n", e
.what());
214 void vclmain::createApplication()
216 static IconTestApp aApp
;
219 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */