[Libreoffice-commits] core.git: Branch 'feature/opengl-vcl' - 3 commits - vcl/workben
Michael Meeks
michael.meeks at collabora.com
Fri Nov 14 08:39:31 PST 2014
vcl/workben/vcldemo.cxx | 207 +++++++++++++++++++++++++++++++++++++++++-------
1 file changed, 177 insertions(+), 30 deletions(-)
New commits:
commit 154c863593c7fc81480e59c43c713cbad2e42b51
Author: Michael Meeks <michael.meeks at collabora.com>
Date: Fri Nov 14 14:54:24 2014 +0000
vcldemo: implement key-bindings and command-line
Change-Id: I98ea70a78f340a2050ef934de3111ba3191ff479
diff --git a/vcl/workben/vcldemo.cxx b/vcl/workben/vcldemo.cxx
index 7b4f692..6f6ae4b 100644
--- a/vcl/workben/vcldemo.cxx
+++ b/vcl/workben/vcldemo.cxx
@@ -69,14 +69,21 @@ class DemoWin : public DemoBase
struct RegionRenderer {
public:
virtual ~RegionRenderer() {}
+ virtual OUString getName() = 0;
+ virtual sal_uInt16 getAccelerator() = 0;
virtual void RenderRegion(OutputDevice &rDev, Rectangle r,
const RenderContext &rCtx) = 0;
+#define RENDER_DETAILS(name,key) \
+ virtual OUString getName() SAL_OVERRIDE \
+ { return OUString(SAL_STRINGIFY(name)); } \
+ virtual sal_uInt16 getAccelerator() SAL_OVERRIDE \
+ { return key; }
};
std::vector< RegionRenderer * > maRenderers;
sal_Int32 mnSelectedRenderer;
- void InitRenderers();
+ void InitRenderers();
public:
DemoWin() : DemoBase()
@@ -108,6 +115,9 @@ public:
InitRenderers();
}
+ OUString getRendererList();
+ void selectRenderer(const OUString &rName);
+
// Bouncing windows on click ...
PushButton *mpButton;
FloatingWindow *mpButtonWin;
@@ -116,6 +126,7 @@ public:
DECL_LINK(BounceTimerCb, void *);
virtual void MouseButtonDown(const MouseEvent& rMEvt) SAL_OVERRIDE;
+ virtual void KeyInput( const KeyEvent& rKEvt ) SAL_OVERRIDE;
virtual void Paint(const Rectangle& rRect) SAL_OVERRIDE
{
@@ -175,6 +186,7 @@ public:
struct DrawLines : public RegionRenderer
{
+ RENDER_DETAILS(lines,KEY_L)
virtual void RenderRegion(OutputDevice &rDev, Rectangle r,
const RenderContext &rCtx) SAL_OVERRIDE
{
@@ -261,6 +273,7 @@ public:
struct DrawText : public RegionRenderer
{
+ RENDER_DETAILS(text,KEY_T)
virtual void RenderRegion(OutputDevice &rDev, Rectangle r,
const RenderContext &) SAL_OVERRIDE
{
@@ -273,6 +286,7 @@ public:
struct DrawCheckered : public RegionRenderer
{
+ RENDER_DETAILS(checks,KEY_C)
virtual void RenderRegion(OutputDevice &rDev, Rectangle r,
const RenderContext &rCtx) SAL_OVERRIDE
{
@@ -333,6 +347,7 @@ public:
struct DrawPoly : public RegionRenderer
{
+ RENDER_DETAILS(poly,KEY_P)
DrawCheckered maCheckered;
virtual void RenderRegion(OutputDevice &rDev, Rectangle r,
const RenderContext &rCtx) SAL_OVERRIDE
@@ -356,6 +371,7 @@ public:
struct DrawEllipse : public RegionRenderer
{
+ RENDER_DETAILS(ellipse,KEY_E)
virtual void RenderRegion(OutputDevice &rDev, Rectangle r,
const RenderContext &) SAL_OVERRIDE
{
@@ -367,6 +383,7 @@ public:
struct DrawGradient : public RegionRenderer
{
+ RENDER_DETAILS(gradient,KEY_G)
virtual void RenderRegion(OutputDevice &rDev, Rectangle r,
const RenderContext &rCtx) SAL_OVERRIDE
{
@@ -437,6 +454,7 @@ public:
struct DrawBitmap : public RegionRenderer
{
+ RENDER_DETAILS(bitmap,KEY_B)
virtual void RenderRegion(OutputDevice &rDev, Rectangle r,
const RenderContext &rCtx) SAL_OVERRIDE
{
@@ -448,6 +466,7 @@ public:
struct DrawBitmapEx : public RegionRenderer
{
+ RENDER_DETAILS(bitmapex,KEY_X)
DrawCheckered maCheckered;
virtual void RenderRegion(OutputDevice &rDev, Rectangle r,
const RenderContext &rCtx) SAL_OVERRIDE
@@ -465,6 +484,7 @@ public:
struct DrawPolyPolygons : public RegionRenderer
{
+ RENDER_DETAILS(polypoly,KEY_N)
virtual void RenderRegion(OutputDevice &rDev, Rectangle r,
const RenderContext &) SAL_OVERRIDE
{
@@ -515,6 +535,7 @@ public:
struct DrawToVirtualDevice : public RegionRenderer
{
+ RENDER_DETAILS(vdev,KEY_V)
enum RenderType {
RENDER_AS_BITMAP,
RENDER_AS_OUTDEV,
@@ -581,6 +602,8 @@ public:
struct DrawIcons : public RegionRenderer
{
+ RENDER_DETAILS(icons,KEY_I)
+
std::vector<OUString> maIconNames;
std::vector<BitmapEx> maIcons;
bool bHasLoadedAll;
@@ -712,6 +735,7 @@ public:
struct FetchDrawBitmap : public RegionRenderer
{
+ RENDER_DETAILS(fetchdraw,KEY_F)
virtual void RenderRegion(OutputDevice &rDev, Rectangle r,
const RenderContext &) SAL_OVERRIDE
{
@@ -769,6 +793,34 @@ IMPL_LINK_NOARG(DemoWin,BounceTimerCb)
return 0;
}
+void DemoWin::KeyInput(const KeyEvent &rKEvt)
+{
+ sal_uInt16 nCode = rKEvt.GetKeyCode().GetCode();
+
+ // click to zoom out
+ if (mnSelectedRenderer >= 0)
+ {
+ if (nCode == KEY_ESCAPE || nCode == KEY_BACKSPACE)
+ {
+ mnSelectedRenderer = -1;
+ Invalidate();
+ return;
+ }
+ }
+ else
+ {
+ for (size_t i = 0; i < maRenderers.size(); i++)
+ {
+ if (nCode == maRenderers[i]->getAccelerator())
+ {
+ mnSelectedRenderer = i;
+ Invalidate();
+ return;
+ }
+ }
+ }
+}
+
void DemoWin::MouseButtonDown(const MouseEvent& rMEvt)
{
// click to zoom out
@@ -832,14 +884,65 @@ void DemoWin::InitRenderers()
maRenderers.push_back(new FetchDrawBitmap());
}
+OUString DemoWin::getRendererList()
+{
+ OUStringBuffer aBuf;
+ for (size_t i = 0; i < maRenderers.size(); i++)
+ {
+ aBuf.append(maRenderers[i]->getName());
+ aBuf.append(' ');
+ }
+ return aBuf.makeStringAndClear();
+}
+
+void DemoWin::selectRenderer(const OUString &rName)
+{
+ for (size_t i = 0; i < maRenderers.size(); i++)
+ {
+ if (maRenderers[i]->getName() == rName)
+ {
+ mnSelectedRenderer = i;
+ Invalidate();
+ return;
+ }
+ }
+}
+
class DemoApp : public Application
{
+ int showHelp(DemoWin &rWin)
+ {
+ fprintf(stderr,"vcldemo - a VCL test app\n");
+ fprintf(stderr," --help - print this text\n");
+ fprintf(stderr," --show <renderer> - start with a given renderer, options are:\n");
+ OUString aRenderers(rWin.getRendererList());
+ fprintf(stderr," %s\n\n",
+ rtl::OUStringToOString(aRenderers, RTL_TEXTENCODING_UTF8).getStr());
+ return 0;
+ }
+
public:
DemoApp() {}
virtual int Main() SAL_OVERRIDE
{
DemoWin aMainWin;
+
+ for (sal_Int32 i = 0; i < GetCommandLineParamCount(); i++)
+ {
+ bool bLast = i == GetCommandLineParamCount() - 1;
+ OUString aArg = GetCommandLineParam(i);
+ if (aArg == "--help" || aArg == "-h")
+ return showHelp(aMainWin);
+ if (aArg == "--show")
+ {
+ if (bLast)
+ return showHelp(aMainWin);
+ else
+ aMainWin.selectRenderer(GetCommandLineParam(++i));
+ }
+ }
+
aMainWin.SetText("Interactive VCL demo");
aMainWin.Show();
Application::Execute();
commit 6a867db2683c087c2675c0dccf40d6ac77d2c55b
Author: Michael Meeks <michael.meeks at collabora.com>
Date: Fri Nov 14 14:09:49 2014 +0000
vcldemo: BitmapEx rotation, translation and shear.
Change-Id: I5a44597bc39c6bccfcec32403fae8f8d7d4fe94c
diff --git a/vcl/workben/vcldemo.cxx b/vcl/workben/vcldemo.cxx
index 9b83947..7b4f692 100644
--- a/vcl/workben/vcldemo.cxx
+++ b/vcl/workben/vcldemo.cxx
@@ -26,6 +26,7 @@
#include <vcl/graphicfilter.hxx>
#include <vcl/button.hxx>
#include <vcl/floatwin.hxx>
+#include <basegfx/numeric/ftools.hxx>
#include <basegfx/matrix/b2dhommatrix.hxx>
#if 0
@@ -41,7 +42,7 @@ class DemoBase :
public WorkWindow // hide OutputDevice if necessary
{
public:
- DemoBase() : WorkWindow( NULL, WB_APP | WB_STDWORK)
+ DemoBase() : WorkWindow(NULL, WB_APP | WB_STDWORK)
{
}
OutputDevice &getOutDev() { return *this; }
@@ -94,7 +95,7 @@ public:
Application::Abort("Failed to load intro image");
#else
aPath = aPath + "/intro.png";
- SvFileStream aFileStream( aPath, STREAM_READ );
+ SvFileStream aFileStream(aPath, STREAM_READ);
GraphicFilter aGraphicFilter(false);
Graphic aGraphic;
if (aGraphicFilter.ImportGraphic(aGraphic, aPath, aFileStream) != 0)
@@ -102,7 +103,7 @@ public:
maIntro = aGraphic.GetBitmapEx();
#endif
maIntroBW = maIntro.GetBitmap();
- maIntroBW.Filter( BMP_FILTER_EMBOSS_GREY );
+ maIntroBW.Filter(BMP_FILTER_EMBOSS_GREY);
InitRenderers();
}
@@ -114,9 +115,9 @@ public:
int mnBounceX, mnBounceY;
DECL_LINK(BounceTimerCb, void *);
- virtual void MouseButtonDown( const MouseEvent& rMEvt ) SAL_OVERRIDE;
+ virtual void MouseButtonDown(const MouseEvent& rMEvt) SAL_OVERRIDE;
- virtual void Paint( const Rectangle& rRect ) SAL_OVERRIDE
+ virtual void Paint(const Rectangle& rRect) SAL_OVERRIDE
{
fprintf(stderr, "DemoWin::Paint(%ld,%ld,%ld,%ld)\n", rRect.getX(), rRect.getY(), rRect.getWidth(), rRect.getHeight());
drawToDevice(getOutDev(), false);
@@ -132,9 +133,9 @@ public:
long nBorderSize = aSize.Width() / 32;
long nBoxWidth = (aSize.Width() - nBorderSize*(nX+1)) / nX;
long nBoxHeight = (aSize.Height() - nBorderSize*(nY+1)) / nY;
- for (int y = 0; y < nY; y++ )
+ for (int y = 0; y < nY; y++)
{
- for (int x = 0; x < nX; x++ )
+ for (int x = 0; x < nX; x++)
{
r.SetPos(Point(nBorderSize + (nBorderSize + nBoxWidth) * x,
nBorderSize + (nBorderSize + nBoxHeight) * y));
@@ -237,15 +238,15 @@ public:
{
rDev.SetFillColor(Color(COL_LIGHTRED));
rDev.SetLineColor(Color(COL_BLACK));
- rDev.DrawRect( r );
+ rDev.DrawRect(r);
for(int i=0; i<r.GetHeight(); i+=15)
- rDev.DrawLine( Point(r.Left(), r.Top()+i), Point(r.Right(), r.Bottom()-i) );
+ rDev.DrawLine(Point(r.Left(), r.Top()+i), Point(r.Right(), r.Bottom()-i));
for(int i=0; i<r.GetWidth(); i+=15)
- rDev.DrawLine( Point(r.Left()+i, r.Bottom()), Point(r.Right()-i, r.Top()) );
+ rDev.DrawLine(Point(r.Left()+i, r.Bottom()), Point(r.Right()-i, r.Top()));
// Should draw a white-line across the middle
- Color aLastPixel( COL_WHITE );
+ Color aLastPixel(COL_WHITE);
Point aCenter((r.Left() + r.Right())/2 - 4,
(r.Top() + r.Bottom())/2 - 4);
for(int i=0; i<8; i++)
@@ -263,10 +264,10 @@ public:
virtual void RenderRegion(OutputDevice &rDev, Rectangle r,
const RenderContext &) SAL_OVERRIDE
{
- rDev.SetTextColor( Color( COL_BLACK ) );
- vcl::Font aFont( OUString( "Times" ), Size( 0, 25 ) );
- rDev.SetFont( aFont );
- rDev.DrawText( r, OUString( "Click any rect to zoom" ) );
+ rDev.SetTextColor(Color(COL_BLACK));
+ vcl::Font aFont(OUString("Times"), Size(0, 25));
+ rDev.SetFont(aFont);
+ rDev.DrawText(r, OUString("Click any rect to zoom"));
}
};
@@ -644,27 +645,39 @@ public:
Size aSize(maIcons[i].GetSizePixel());
// sAL_DEBUG("Draw icon '" << maIconNames[i] << "'");
- basegfx::B2DHomMatrix aTransform;
- aTransform.scale(aSize.Width(), aSize.Height());
- aTransform.translate(p.X(), p.Y());
- switch (1)
- {
- case 0:
+ if (!i % 4)
rDev.DrawBitmapEx(p, maIcons[i]);
- break;
- case 1:
- rDev.DrawTransformedBitmapEx(aTransform, maIcons[i]);
- break;
- case 2:
- aTransform.shearX(10);
- rDev.DrawTransformedBitmapEx(aTransform, maIcons[i]);
- break;
- case 3:
- aTransform.rotate(i);
+ else
+ {
+ basegfx::B2DHomMatrix aTransform;
+ aTransform.scale(aSize.Width(), aSize.Height());
+ switch (i % 4)
+ {
+ case 2:
+ aTransform.shearX((double)((i >> 2) % 8) / 8);
+ aTransform.shearY((double)((i >> 4) % 8) / 8);
+ break;
+ case 3:
+ aTransform.translate(-aSize.Width()/2, -aSize.Height()/2);
+ aTransform.rotate(i);
+ if (i & 0x100)
+ {
+ aTransform.shearX((double)((i >> 2) % 8) / 8);
+ aTransform.shearY((double)((i >> 4) % 8) / 8);
+ }
+ aTransform.translate(aSize.Width()/2, aSize.Height()/2);
+ break;
+ default:
+ aTransform.translate(-aSize.Width()/2, -aSize.Height()/2);
+ aTransform.rotate(2 * F_2PI * i / nToRender);
+ aTransform.translate(aSize.Width()/2, aSize.Height()/2);
+ break;
+ }
+ aTransform.translate(p.X(), p.Y());
rDev.DrawTransformedBitmapEx(aTransform, maIcons[i]);
- break;
}
+ // next position
p.Move(aSize.Width(), 0);
if (aSize.Height() > nMaxH)
nMaxH = aSize.Height();
@@ -756,7 +769,7 @@ IMPL_LINK_NOARG(DemoWin,BounceTimerCb)
return 0;
}
-void DemoWin::MouseButtonDown( const MouseEvent& rMEvt )
+void DemoWin::MouseButtonDown(const MouseEvent& rMEvt)
{
// click to zoom out
if (mnSelectedRenderer >= 0)
@@ -827,7 +840,7 @@ public:
virtual int Main() SAL_OVERRIDE
{
DemoWin aMainWin;
- aMainWin.SetText( "Interactive VCL demo" );
+ aMainWin.SetText("Interactive VCL demo");
aMainWin.Show();
Application::Execute();
return 0;
@@ -842,11 +855,11 @@ protected:
uno::Reference<uno::XComponentContext> xComponentContext
= ::cppu::defaultBootstrap_InitialComponentContext();
xMSF = uno::Reference<lang::XMultiServiceFactory>
- ( xComponentContext->getServiceManager(), uno::UNO_QUERY );
- if( !xMSF.is() )
+ (xComponentContext->getServiceManager(), uno::UNO_QUERY);
+ if(!xMSF.is())
Application::Abort("Bootstrap failure - no service manager");
- ::comphelper::setProcessServiceFactory( xMSF );
+ ::comphelper::setProcessServiceFactory(xMSF);
}
catch (const uno::Exception &e)
{
@@ -857,8 +870,8 @@ protected:
{
uno::Reference< lang::XComponent >(
comphelper::getProcessComponentContext(),
- uno::UNO_QUERY_THROW )-> dispose();
- ::comphelper::setProcessServiceFactory( NULL );
+ uno::UNO_QUERY_THROW)-> dispose();
+ ::comphelper::setProcessServiceFactory(NULL);
}
};
commit 0ba3b9681592972df73cd21ed3e7fa28e3e86ef2
Author: Michael Meeks <michael.meeks at collabora.com>
Date: Fri Nov 14 12:27:15 2014 +0000
vcldemo: exercise more BitmapEx rendering paths.
Change-Id: Iecd02534dfbe0938a8635e3b7c2363b4531ef5ef
diff --git a/vcl/workben/vcldemo.cxx b/vcl/workben/vcldemo.cxx
index 01c05c0..9b83947 100644
--- a/vcl/workben/vcldemo.cxx
+++ b/vcl/workben/vcldemo.cxx
@@ -26,6 +26,7 @@
#include <vcl/graphicfilter.hxx>
#include <vcl/button.hxx>
#include <vcl/floatwin.hxx>
+#include <basegfx/matrix/b2dhommatrix.hxx>
#if 0
# define FIXME_SELF_INTERSECTING_WORKING
@@ -623,31 +624,61 @@ public:
bHasLoadedAll = true;
css::uno::Sequence< OUString > aAllIcons = ImageTree_getAllImageNames();
- for (sal_Int32 i = 0; i < aAllIcons.getLength() && i < 1024; i++)
+ for (sal_Int32 i = 0; i < aAllIcons.getLength(); i++)
{
maIconNames.push_back(aAllIcons[i]);
maIcons.push_back(BitmapEx(aAllIcons[i]));
}
}
- void doDrawIcons(OutputDevice &rDev, Rectangle r)
+ void doDrawIcons(OutputDevice &rDev, Rectangle r, bool bExpanded)
{
long nMaxH = 0, nVPos = 0;
Point p(r.TopLeft());
- for (size_t i = 0; i < maIcons.size(); i++)
+ size_t nToRender = maIcons.size();
+
+ if (!bExpanded && maIcons.size() > 64)
+ nToRender = 64;
+ for (size_t i = 0; i < nToRender; i++)
{
Size aSize(maIcons[i].GetSizePixel());
// sAL_DEBUG("Draw icon '" << maIconNames[i] << "'");
- rDev.DrawBitmapEx(p, maIcons[i]);
+
+ basegfx::B2DHomMatrix aTransform;
+ aTransform.scale(aSize.Width(), aSize.Height());
+ aTransform.translate(p.X(), p.Y());
+ switch (1)
+ {
+ case 0:
+ rDev.DrawBitmapEx(p, maIcons[i]);
+ break;
+ case 1:
+ rDev.DrawTransformedBitmapEx(aTransform, maIcons[i]);
+ break;
+ case 2:
+ aTransform.shearX(10);
+ rDev.DrawTransformedBitmapEx(aTransform, maIcons[i]);
+ break;
+ case 3:
+ aTransform.rotate(i);
+ rDev.DrawTransformedBitmapEx(aTransform, maIcons[i]);
+ break;
+ }
+
p.Move(aSize.Width(), 0);
if (aSize.Height() > nMaxH)
nMaxH = aSize.Height();
- if (p.X() >= r.Right())
+ if (p.X() >= r.Right()) // wrap to next line
{
nVPos += nMaxH;
nMaxH = 0;
p = Point(r.Left(), r.Top() + nVPos);
}
+ if (p.Y() >= r.Bottom()) // re-start at top
+ {
+ p = r.TopLeft();
+ nVPos = 0;
+ }
}
}
@@ -657,11 +688,11 @@ public:
if (rCtx.meStyle == RENDER_EXPANDED)
{
LoadAllImages();
- doDrawIcons(rDev, r);
+ doDrawIcons(rDev, r, true);
}
else
{
- doDrawIcons(rDev, r);
+ doDrawIcons(rDev, r, false);
}
}
};
More information about the Libreoffice-commits
mailing list