[Libreoffice-commits] core.git: Branch 'feature/opengl-vcl2' - vcl/workben
Michael Meeks
michael.meeks at collabora.com
Sun Nov 16 03:02:30 PST 2014
vcl/workben/vcldemo.cxx | 188 +++++++++++++++++++++++++++++++-----------------
1 file changed, 125 insertions(+), 63 deletions(-)
New commits:
commit 86bc8fe74fd317943828cfd5b42335a74e0a50e5
Author: Michael Meeks <michael.meeks at collabora.com>
Date: Sun Nov 16 12:01:41 2014 +0100
vcldemo: create multiple windows sharing the same renderer.
Change-Id: Iac813b78c476b69dc6aa78d48c025f5fda76db1a
diff --git a/vcl/workben/vcldemo.cxx b/vcl/workben/vcldemo.cxx
index a41d61d..346edda 100644
--- a/vcl/workben/vcldemo.cxx
+++ b/vcl/workben/vcldemo.cxx
@@ -28,31 +28,20 @@
#include <basegfx/numeric/ftools.hxx>
#include <basegfx/matrix/b2dhommatrix.hxx>
-#if 0
-# define FIXME_SELF_INTERSECTING_WORKING
-#endif
+#define FIXME_SELF_INTERSECTING_WORKING 0
+#define FIXME_BOUNCE_BUTTON 0
// debugging hook just for us
SAL_DLLPUBLIC css::uno::Sequence< OUString > ImageTree_getAllImageNames();
using namespace css;
-class DemoBase :
- public WorkWindow // hide OutputDevice if necessary
-{
-public:
- DemoBase() : WorkWindow(NULL, WB_APP | WB_STDWORK)
- {
- }
- OutputDevice &getOutDev() { return *this; }
-};
-
enum RenderStyle {
RENDER_THUMB, // small view <n> to a page
RENDER_EXPANDED, // expanded view of this renderer
};
-class DemoWin : public DemoBase
+class DemoRenderer
{
Bitmap maIntroBW;
BitmapEx maIntro;
@@ -61,9 +50,9 @@ class DemoWin : public DemoBase
int mnSegmentsY;
struct RenderContext {
- RenderStyle meStyle;
- bool mbVDev;
- DemoWin *mpDemoWin;
+ RenderStyle meStyle;
+ bool mbVDev;
+ DemoRenderer *mpDemoRenderer;
};
struct RegionRenderer {
public:
@@ -85,14 +74,15 @@ class DemoWin : public DemoBase
void InitRenderers();
public:
- DemoWin() : DemoBase()
- , mnSegmentsX(4)
- , mnSegmentsY(3)
- , mnSelectedRenderer(-1)
- , mpButton(NULL)
- , mpButtonWin(NULL)
- , mnBounceX(1)
- , mnBounceY(1)
+ DemoRenderer() : mnSegmentsX(4)
+ , mnSegmentsY(3)
+ , mnSelectedRenderer(-1)
+#if FIXME_BOUNCE_BUTTON
+ , mpButton(NULL)
+ , mpButtonWin(NULL)
+ , mnBounceX(1)
+ , mnBounceY(1)
+#endif
{
if (!Application::LoadBrandBitmap("intro", maIntro))
Application::Abort("Failed to load intro image");
@@ -106,29 +96,36 @@ public:
OUString getRendererList();
void selectRenderer(const OUString &rName);
+ Size maSize;
+ void SetSizePixel(const Size &rSize) { maSize = rSize; }
+ Size GetSizePixel() const { return maSize; }
+
+
+// more of a 'Window' concept - push upwards ?
+#if FIXME_BOUNCE_BUTTON
// Bouncing windows on click ...
PushButton *mpButton;
FloatingWindow *mpButtonWin;
AutoTimer maBounce;
int mnBounceX, mnBounceY;
DECL_LINK(BounceTimerCb, void *);
+#endif
- virtual void MouseButtonDown(const MouseEvent& rMEvt) SAL_OVERRIDE;
- virtual void KeyInput( const KeyEvent& rKEvt ) SAL_OVERRIDE;
+ bool MouseButtonDown(const MouseEvent& rMEvt);
+ void KeyInput(const KeyEvent& rKEvt);
- virtual void Paint(const Rectangle& rRect) SAL_OVERRIDE
+ static std::vector<Rectangle> partition(const RenderContext &rCtx, int nX, int nY)
{
- fprintf(stderr, "DemoWin::Paint(%ld,%ld,%ld,%ld)\n", rRect.getX(), rRect.getY(), rRect.getWidth(), rRect.getHeight());
- drawToDevice(getOutDev(), false);
+ return rCtx.mpDemoRenderer->partition(nX, nY);
}
- static std::vector<Rectangle> partition(OutputDevice &rDev, int nX, int nY)
+ std::vector<Rectangle> partition(int nX, int nY)
{
Rectangle r;
std::vector<Rectangle> aRegions;
// Make small cleared area for these guys
- Size aSize(rDev.GetOutputSizePixel());
+ Size aSize(GetSizePixel());
long nBorderSize = aSize.Width() / 32;
long nBoxWidth = (aSize.Width() - nBorderSize*(nX+1)) / nX;
long nBoxHeight = (aSize.Height() - nBorderSize*(nY+1)) / nY;
@@ -184,8 +181,8 @@ public:
sal_uInt16 nOldAA = rDev.GetAntialiasing();
rDev.SetAntialiasing(ANTIALIASING_ENABLE_B2DDRAW);
- std::vector<Rectangle> aRegions(DemoWin::partition(rDev, 4, 4));
- DemoWin::clearRects(rDev, aRegions);
+ std::vector<Rectangle> aRegions(DemoRenderer::partition(rCtx, 4, 4));
+ DemoRenderer::clearRects(rDev, aRegions);
#if 0 // FIXME: get this through to the backend ...
double nTransparency[] = {
@@ -281,7 +278,7 @@ public:
{
if (rCtx.meStyle == RENDER_EXPANDED)
{
- std::vector<Rectangle> aRegions(DemoWin::partition(rDev, 2, 2));
+ std::vector<Rectangle> aRegions(DemoRenderer::partition(rCtx, 2, 2));
for (size_t i = 0; i < aRegions.size(); i++)
{
vcl::Region aRegion;
@@ -378,7 +375,7 @@ public:
{
if (rCtx.meStyle == RENDER_EXPANDED)
{
- std::vector<Rectangle> aRegions(DemoWin::partition(rDev, 5, 4));
+ std::vector<Rectangle> aRegions(DemoRenderer::partition(rCtx,5, 4));
sal_uInt32 nStartCols[] = {
COL_RED, COL_RED, COL_RED, COL_GREEN, COL_GREEN,
COL_BLUE, COL_BLUE, COL_BLUE, COL_CYAN, COL_CYAN,
@@ -410,7 +407,7 @@ public:
1, 10, 20, 10, 1,
0, 0, 0, 0, 0
};
- DemoWin::clearRects(rDev, aRegions);
+ DemoRenderer::clearRects(rDev, aRegions);
assert(aRegions.size() <= SAL_N_ELEMENTS(nStartCols));
assert(aRegions.size() <= SAL_N_ELEMENTS(nEndCols));
assert(aRegions.size() <= SAL_N_ELEMENTS(eStyles));
@@ -447,7 +444,7 @@ public:
virtual void RenderRegion(OutputDevice &rDev, Rectangle r,
const RenderContext &rCtx) SAL_OVERRIDE
{
- Bitmap aBitmap(rCtx.mpDemoWin->maIntroBW);
+ Bitmap aBitmap(rCtx.mpDemoRenderer->maIntroBW);
aBitmap.Scale(r.GetSize(), BMP_SCALE_BESTQUALITY);
rDev.DrawBitmap(r.TopLeft(), aBitmap);
}
@@ -462,7 +459,7 @@ public:
{
maCheckered.RenderRegion(rDev, r, rCtx);
- BitmapEx aBitmap(rCtx.mpDemoWin->maIntro);
+ BitmapEx aBitmap(rCtx.mpDemoRenderer->maIntro);
aBitmap.Scale(r.GetSize(), BMP_SCALE_BESTQUALITY);
AlphaMask aSemiTransp(aBitmap.GetSizePixel());
aSemiTransp.Erase(64);
@@ -480,7 +477,7 @@ public:
struct {
double nX, nY;
} aPoints[] = { { 0.1, 0.1 }, { 0.9, 0.9 },
-#ifdef FIXME_SELF_INTERSECTING_WORKING
+#if FIXME_SELF_INTERSECTING_WORKING
{ 0.9, 0.1 }, { 0.1, 0.9 },
{ 0.1, 0.1 }
#else
@@ -546,7 +543,7 @@ public:
Rectangle aWhole(Point(0,0), r.GetSize());
// mini me
- rCtx.mpDemoWin->drawToDevice(*pNested, true);
+ rCtx.mpDemoRenderer->drawToDevice(*pNested, true);
if (eType == RENDER_AS_BITMAP)
{
@@ -576,8 +573,8 @@ public:
if (rCtx.meStyle == RENDER_EXPANDED)
{
- std::vector<Rectangle> aRegions(DemoWin::partition(rDev, 2, 2));
- DemoWin::clearRects(rDev, aRegions);
+ std::vector<Rectangle> aRegions(DemoRenderer::partition(rCtx,2, 2));
+ DemoRenderer::clearRects(rDev, aRegions);
RenderType eRenderTypes[] = { RENDER_AS_BITMAP, RENDER_AS_OUTDEV,
RENDER_AS_BITMAPEX, RENDER_AS_ALPHA_OUTDEV };
@@ -738,7 +735,7 @@ public:
{
RenderContext aCtx;
aCtx.mbVDev = bVDev;
- aCtx.mpDemoWin = this;
+ aCtx.mpDemoRenderer = this;
Rectangle aWholeWin(Point(0,0), rDev.GetOutputSizePixel());
@@ -753,15 +750,35 @@ public:
else
{
aCtx.meStyle = RENDER_THUMB;
- std::vector<Rectangle> aRegions(DemoWin::partition(rDev, mnSegmentsX, mnSegmentsY));
- DemoWin::clearRects(rDev, aRegions);
+ std::vector<Rectangle> aRegions(partition(mnSegmentsX, mnSegmentsY));
+ DemoRenderer::clearRects(rDev, aRegions);
for (size_t i = 0; i < maRenderers.size(); i++)
maRenderers[i]->RenderRegion(rDev, aRegions[i], aCtx);
}
}
+ std::vector<vcl::Window *> maInvalidates;
+ void addInvalidate(vcl::Window *pWindow) { maInvalidates.push_back(pWindow); };
+ void removeInvalidate(vcl::Window *pWindow)
+ {
+ std::vector<vcl::Window *>::iterator aIt;
+ for (aIt = maInvalidates.begin(); aIt != maInvalidates.end(); ++aIt)
+ {
+ if (*aIt == pWindow)
+ {
+ maInvalidates.erase(aIt);
+ return;
+ }
+ }
+ }
+ void Invalidate()
+ {
+ for (size_t i = 0; i < maInvalidates.size(); ++i)
+ maInvalidates[i]->Invalidate();
+ }
};
-IMPL_LINK_NOARG(DemoWin,BounceTimerCb)
+#if FIXME_BOUNCE_BUTTON
+IMPL_LINK_NOARG(DemoRenderer,BounceTimerCb)
{
mpButton->Check(mnBounceX>0);
mpButton->SetPressed(mnBounceY>0);
@@ -781,8 +798,9 @@ IMPL_LINK_NOARG(DemoWin,BounceTimerCb)
Invalidate(aRect);
return 0;
}
+#endif
-void DemoWin::KeyInput(const KeyEvent &rKEvt)
+void DemoRenderer::KeyInput(const KeyEvent &rKEvt)
{
sal_uInt16 nCode = rKEvt.GetKeyCode().GetCode();
@@ -810,28 +828,29 @@ void DemoWin::KeyInput(const KeyEvent &rKEvt)
}
}
-void DemoWin::MouseButtonDown(const MouseEvent& rMEvt)
+bool DemoRenderer::MouseButtonDown(const MouseEvent& rMEvt)
{
// click to zoom out
if (mnSelectedRenderer >= 0)
{
mnSelectedRenderer = -1;
Invalidate();
- return;
+ return true;
}
// click on a region to zoom into it
- std::vector<Rectangle> aRegions(partition(*this, mnSegmentsX, mnSegmentsY));
+ std::vector<Rectangle> aRegions(partition(mnSegmentsX, mnSegmentsY));
for (size_t i = 0; i < aRegions.size(); i++)
{
if (aRegions[i].IsInside(rMEvt.GetPosPixel()))
{
mnSelectedRenderer = i;
Invalidate();
- return;
+ return true;
}
}
+#if FIXME_BOUNCE_BUTTON
// otherwise bounce floating windows
if (!mpButton)
{
@@ -844,7 +863,7 @@ void DemoWin::MouseButtonDown(const MouseEvent& rMEvt)
mpButtonWin->SetPosSizePixel(Point(0,0), mpButton->GetOptimalSize());
mpButtonWin->Show();
mnBounceX = 1; mnBounceX = 1;
- maBounce.SetTimeoutHdl(LINK(this,DemoWin,BounceTimerCb));
+ maBounce.SetTimeoutHdl(LINK(this,DemoRenderer,BounceTimerCb));
maBounce.SetTimeout(55);
maBounce.Start();
}
@@ -855,9 +874,11 @@ void DemoWin::MouseButtonDown(const MouseEvent& rMEvt)
mpButtonWin = NULL;
mpButton = NULL;
}
+#endif
+ return false;
}
-void DemoWin::InitRenderers()
+void DemoRenderer::InitRenderers()
{
maRenderers.push_back(new DrawLines());
maRenderers.push_back(new DrawText());
@@ -873,7 +894,7 @@ void DemoWin::InitRenderers()
maRenderers.push_back(new FetchDrawBitmap());
}
-OUString DemoWin::getRendererList()
+OUString DemoRenderer::getRendererList()
{
OUStringBuffer aBuf;
for (size_t i = 0; i < maRenderers.size(); i++)
@@ -884,7 +905,7 @@ OUString DemoWin::getRendererList()
return aBuf.makeStringAndClear();
}
-void DemoWin::selectRenderer(const OUString &rName)
+void DemoRenderer::selectRenderer(const OUString &rName)
{
for (size_t i = 0; i < maRenderers.size(); i++)
{
@@ -897,14 +918,52 @@ void DemoWin::selectRenderer(const OUString &rName)
}
}
+class DemoWin : public WorkWindow
+{
+ DemoRenderer &mrRenderer;
+public:
+ DemoWin(DemoRenderer &rRenderer) :
+ WorkWindow(NULL, WB_APP | WB_STDWORK),
+ mrRenderer(rRenderer)
+ {
+ mrRenderer.addInvalidate(this);
+ }
+ virtual ~DemoWin()
+ {
+ mrRenderer.removeInvalidate(this);
+ }
+ virtual void MouseButtonDown(const MouseEvent& rMEvt) SAL_OVERRIDE
+ {
+ mrRenderer.SetSizePixel(GetSizePixel());
+ if (!mrRenderer.MouseButtonDown(rMEvt))
+ {
+ DemoWin *pNewWin = new DemoWin(mrRenderer);
+ pNewWin->SetText("Another interactive VCL demo window");
+ pNewWin->Show();
+ }
+ }
+ virtual void KeyInput(const KeyEvent& rKEvt) SAL_OVERRIDE
+ {
+ mrRenderer.SetSizePixel(GetSizePixel());
+ mrRenderer.KeyInput(rKEvt);
+ }
+ virtual void Paint(const Rectangle& rRect) SAL_OVERRIDE
+ {
+ mrRenderer.SetSizePixel(GetSizePixel());
+ fprintf(stderr, "DemoWin::Paint(%ld,%ld,%ld,%ld)\n", rRect.getX(), rRect.getY(), rRect.getWidth(), rRect.getHeight());
+ mrRenderer.drawToDevice(*this, false);
+ }
+};
+
+
class DemoApp : public Application
{
- int showHelp(DemoWin &rWin)
+ int showHelp(DemoRenderer &rRenderer)
{
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());
+ OUString aRenderers(rRenderer.getRendererList());
fprintf(stderr," %s\n\n",
rtl::OUStringToOString(aRenderers, RTL_TEXTENCODING_UTF8).getStr());
return 0;
@@ -917,25 +976,28 @@ public:
{
try
{
- DemoWin aMainWin;
+ DemoRenderer aRenderer;
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);
+ return showHelp(aRenderer);
if (aArg == "--show")
{
if (bLast)
- return showHelp(aMainWin);
+ return showHelp(aRenderer);
else
- aMainWin.selectRenderer(GetCommandLineParam(++i));
+ aRenderer.selectRenderer(GetCommandLineParam(++i));
}
}
- aMainWin.SetText("Interactive VCL demo");
+ DemoWin aMainWin(aRenderer);
+
+ aMainWin.SetText("Interactive VCL demo #1");
aMainWin.Show();
+
Application::Execute();
}
catch (const css::uno::Exception& e)
More information about the Libreoffice-commits
mailing list