Bump version to 5.0-14
[LibreOffice.git] / canvas / workben / canvasdemo.cxx
blobcdf3acbd8b1e40876f5e05afe38bfe5629138fe1
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 // This code strongly inspired by Miguel / Federico's Gnome Canvas demo code.
23 #include <comphelper/processfactory.hxx>
24 #include <cppuhelper/servicefactory.hxx>
25 #include <cppuhelper/bootstrap.hxx>
26 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
27 #include <com/sun/star/lang/XInitialization.hpp>
28 #include <com/sun/star/registry/XSimpleRegistry.hpp>
29 #include <com/sun/star/ucb/UniversalContentBroker.hpp>
31 #include <basegfx/polygon/b2dpolygon.hxx>
32 #include <basegfx/polygon/b2dpolygontools.hxx>
33 #include <basegfx/tools/canvastools.hxx>
35 #include <vcl/window.hxx>
36 #include <vcl/virdev.hxx>
37 #include <vcl/svapp.hxx>
38 #include <vcl/msgbox.hxx>
39 #include <vcl/unowrap.hxx>
40 #include <vcl/canvastools.hxx>
42 #include <rtl/bootstrap.hxx>
43 #include <sal/macros.h>
45 #include <com/sun/star/rendering/XCanvas.hpp>
46 #include <com/sun/star/rendering/FillRule.hpp>
47 #include <com/sun/star/rendering/ViewState.hpp>
48 #include <com/sun/star/rendering/RenderState.hpp>
49 #include <com/sun/star/rendering/PathCapType.hpp>
50 #include <com/sun/star/rendering/PathJoinType.hpp>
51 #include <com/sun/star/rendering/XSpriteCanvas.hpp>
52 #include <com/sun/star/rendering/XGraphicDevice.hpp>
53 #include <com/sun/star/rendering/CompositeOperation.hpp>
54 #include <com/sun/star/rendering/XBitmap.hpp>
56 #include <stdio.h>
57 #include <unistd.h>
59 // never import whole leaf namespaces, since this will result in
60 // absolutely weird effects during (Koenig) name lookup
61 using namespace ::com::sun::star;
64 class DemoApp : public Application
66 public:
67 virtual void Main();
68 virtual USHORT Exception( USHORT nError );
71 static void PrintHelp()
73 fprintf( stdout, "canvasdemo - Exercise the new canvas impl\n" );
76 class TestWindow : public Dialog
78 public:
79 TestWindow() : Dialog( (vcl::Window *) NULL )
81 SetText( OUString( "Canvas test" ) );
82 SetSizePixel( Size( 600, 450 ) );
83 EnablePaint( true );
84 Show();
86 virtual ~TestWindow() {}
87 virtual void MouseButtonUp( const MouseEvent& /*rMEvt*/ )
89 //TODO: do something cool
90 EndDialog();
92 virtual void Paint( const Rectangle& rRect );
95 class DemoRenderer
97 public:
98 Size maSize;
99 Size maBox;
100 rendering::ViewState maViewState;
101 rendering::RenderState maRenderState;
102 uno::Sequence< double > maColorBlack;
103 uno::Sequence< double > maColorWhite;
104 uno::Sequence< double > maColorRed;
105 uno::Reference< rendering::XCanvas > mxCanvas;
106 uno::Reference< rendering::XCanvasFont > mxDefaultFont;
107 uno::Reference< rendering::XGraphicDevice > mxDevice;
109 DemoRenderer( uno::Reference< rendering::XGraphicDevice > xDevice,
110 uno::Reference< rendering::XCanvas > xCanvas,
111 Size aSize ) :
112 maSize(aSize),
113 maBox(),
114 maViewState(),
115 maRenderState(),
116 maColorBlack( vcl::unotools::colorToStdColorSpaceSequence( Color(COL_BLACK)) ),
117 maColorWhite( vcl::unotools::colorToStdColorSpaceSequence( Color(COL_WHITE)) ),
118 maColorRed( vcl::unotools::colorToStdColorSpaceSequence( Color(COL_RED)) ),
119 mxCanvas(xCanvas),
120 mxDefaultFont(),
121 mxDevice( xDevice )
123 // Geometry init
124 geometry::AffineMatrix2D aUnit( 1,0, 0,
125 0,1, 0 );
126 maViewState.AffineTransform = aUnit;
127 maRenderState.AffineTransform = aUnit;
128 maRenderState.DeviceColor = maColorBlack;
130 //I can't figure out what the compsiteoperation stuff does
131 //it doesn't seem to do anything in either VCL or cairocanvas
132 //I was hoping that CLEAR would clear the canvas before we paint,
133 //but nothing changes
134 maRenderState.CompositeOperation = rendering::CompositeOperation::OVER;
136 maBox.Width() = aSize.Width() / 3;
137 maBox.Height() = aSize.Height() / 3;
139 lang::Locale aLocale;
140 rendering::FontInfo aFontInfo;
141 aFontInfo.FamilyName = "Swiss";
142 aFontInfo.StyleName = "SansSerif";
143 geometry::Matrix2D aFontMatrix( 1, 0,
144 0, 1 );
145 rendering::FontRequest aFontRequest( aFontInfo, 12.0, 0.0, aLocale );
146 uno::Sequence< beans::PropertyValue > aExtraFontProperties;
147 mxDefaultFont = xCanvas->createFont( aFontRequest, aExtraFontProperties, aFontMatrix );
148 if( !mxDefaultFont.is() )
149 fprintf( stderr, "Failed to create font\n" );
152 void drawGrid()
154 double d, dIncr = maSize.Width() / 3;
155 for ( d = 0; d <= maSize.Width(); d += dIncr )
156 mxCanvas->drawLine( geometry::RealPoint2D( d, 0 ),
157 geometry::RealPoint2D( d, maSize.Height() ),
158 maViewState, maRenderState );
159 dIncr = maSize.Height() / 3;
160 for ( d = 0; d <= maSize.Height(); d += dIncr )
161 mxCanvas->drawLine( geometry::RealPoint2D( 0, d ),
162 geometry::RealPoint2D( maSize.Width(), d ),
163 maViewState, maRenderState );
166 void drawStringAt( OString aString, double x, double y )
168 rendering::StringContext aText;
169 aText.Text = OStringToOUString( aString, RTL_TEXTENCODING_UTF8 );
170 aText.StartPosition = 0;
171 aText.Length = aString.getLength();
172 rendering::RenderState aRenderState( maRenderState );
173 aRenderState.AffineTransform.m02 += x;
174 aRenderState.AffineTransform.m12 += y;
176 mxCanvas->drawText( aText, mxDefaultFont, maViewState, aRenderState, 0);
179 void drawRect( Rectangle rRect, uno::Sequence< double > &aColor, int /*nWidth*/ )
181 uno::Sequence< geometry::RealPoint2D > aPoints(4);
182 uno::Reference< rendering::XLinePolyPolygon2D > xPoly;
184 aPoints[0] = geometry::RealPoint2D( rRect.Left(), rRect.Top() );
185 aPoints[1] = geometry::RealPoint2D( rRect.Left(), rRect.Bottom() );
186 aPoints[2] = geometry::RealPoint2D( rRect.Right(), rRect.Bottom() );
187 aPoints[3] = geometry::RealPoint2D( rRect.Right(), rRect.Top() );
189 uno::Sequence< uno::Sequence< geometry::RealPoint2D > > aPolys(1);
190 aPolys[0] = aPoints;
191 xPoly = mxDevice->createCompatibleLinePolyPolygon( aPolys );
192 xPoly->setClosed( 0, true );
193 uno::Reference< rendering::XPolyPolygon2D> xPP( xPoly, uno::UNO_QUERY );
195 rendering::RenderState aRenderState( maRenderState );
196 aRenderState.DeviceColor = aColor;
197 mxCanvas->drawPolyPolygon( xPP, maViewState, aRenderState );
200 void translate( double x, double y)
202 maRenderState.AffineTransform.m02 += x;
203 maRenderState.AffineTransform.m12 += y;
206 void drawPolishDiamond( double center_x, double center_y)
208 const int VERTICES = 10;
209 const double RADIUS = 60.0;
210 int i, j;
212 rendering::RenderState maOldRenderState = maRenderState; // push
213 translate( center_x, center_y );
215 for (i = 0; i < VERTICES; i++)
217 double a = 2.0 * M_PI * i / VERTICES;
218 geometry::RealPoint2D aSrc( RADIUS * cos (a), RADIUS * sin (a) );
220 for (j = i + 1; j < VERTICES; j++)
222 a = 2.0 * M_PI * j / VERTICES;
224 // FIXME: set cap_style to 'ROUND'
225 mxCanvas->drawLine( aSrc,
226 geometry::RealPoint2D( RADIUS * cos (a),
227 RADIUS * sin (a) ),
228 maViewState, maRenderState );
232 maRenderState = maOldRenderState; // pop
235 void drawHilbert( double anchor_x, double anchor_y )
237 const double SCALE=7.0;
238 const char hilbert[] = "urdrrulurulldluuruluurdrurddldrrruluurdrurddldrddlulldrdldrrurd";
239 int nLength = SAL_N_ELEMENTS( hilbert );
241 uno::Sequence< geometry::RealPoint2D > aPoints( nLength );
242 uno::Reference< rendering::XLinePolyPolygon2D > xPoly;
244 aPoints[0] = geometry::RealPoint2D( anchor_x, anchor_y );
245 for (int i = 0; i < nLength; i++ )
247 switch( hilbert[i] )
249 case 'u':
250 aPoints[i+1] = geometry::RealPoint2D( aPoints[i].X,
251 aPoints[i].Y - SCALE );
252 break;
253 case 'd':
254 aPoints[i+1] = geometry::RealPoint2D( aPoints[i].X,
255 aPoints[i].Y + SCALE );
256 break;
257 case 'l':
258 aPoints[i+1] = geometry::RealPoint2D( aPoints[i].X - SCALE,
259 aPoints[i].Y );
260 break;
261 case 'r':
262 aPoints[i+1] = geometry::RealPoint2D( aPoints[i].X + SCALE,
263 aPoints[i].Y );
264 break;
268 uno::Sequence< uno::Sequence< geometry::RealPoint2D > > aPolys(1);
269 aPolys[0] = aPoints;
271 xPoly = mxDevice->createCompatibleLinePolyPolygon( aPolys );
272 xPoly->setClosed( 0, false );
273 uno::Reference< rendering::XPolyPolygon2D> xPP( xPoly, uno::UNO_QUERY );
275 rendering::RenderState aRenderState( maRenderState );
276 aRenderState.DeviceColor = maColorRed;
277 // aRenderState.DeviceColor[3] = 0.5;
278 rendering::StrokeAttributes aStrokeAttrs;
279 aStrokeAttrs.StrokeWidth = 4.0;
280 aStrokeAttrs.MiterLimit = 2.0; // ?
281 aStrokeAttrs.StartCapType = rendering::PathCapType::BUTT;
282 aStrokeAttrs.EndCapType = rendering::PathCapType::BUTT;
283 aStrokeAttrs.JoinType = rendering::PathJoinType::MITER;
284 //fprintf( stderr, "FIXME: stroking a tools::PolyPolygon doesn't show up\n" );
285 //yes it does
286 mxCanvas->strokePolyPolygon( xPP, maViewState, aRenderState, aStrokeAttrs );
287 // FIXME: do this instead:
288 //mxCanvas->drawPolyPolygon( xPP, maViewState, aRenderState );
291 void drawTitle( OString aTitle )
293 // FIXME: text anchoring to be done
294 double nStringWidth = aTitle.getLength() * 8.0;
295 drawStringAt ( aTitle, (maBox.Width() - nStringWidth) / 2, 15 );
298 void drawRectangles()
300 rendering::RenderState maOldRenderState = maRenderState; // push
302 drawTitle( OString( "Rectangles" ) );
304 drawRect( Rectangle( 20, 30, 70, 60 ), maColorRed, 8 );
305 // color mediumseagreen, stipple fill, outline black
306 drawRect( Rectangle( 90, 40, 180, 100 ), maColorBlack, 4 );
307 // color steelblue, filled, no outline
308 drawRect( Rectangle( 10, 80, 80, 140 ), maColorBlack, 1 );
310 maRenderState = maOldRenderState; // pop
313 void drawEllipses()
315 rendering::RenderState maOldRenderState = maRenderState; // push
316 translate( maBox.Width(), 0.0 );
318 drawTitle( OString( "Ellipses" ) );
320 const basegfx::B2DPoint aCenter( maBox.Width()*.5,
321 maBox.Height()*.5 );
322 const basegfx::B2DPoint aRadii( maBox.Width()*.3,
323 maBox.Height()*.3 );
324 const basegfx::B2DPolygon& rEllipse(
325 basegfx::tools::createPolygonFromEllipse( aCenter,
326 aRadii.getX(),
327 aRadii.getY() ));
329 uno::Reference< rendering::XPolyPolygon2D > xPoly(
330 basegfx::unotools::xPolyPolygonFromB2DPolygon(mxDevice,
331 rEllipse) );
333 rendering::StrokeAttributes aStrokeAttrs;
334 aStrokeAttrs.StrokeWidth = 4.0;
335 aStrokeAttrs.MiterLimit = 2.0; // ?
336 aStrokeAttrs.StartCapType = rendering::PathCapType::BUTT;
337 aStrokeAttrs.EndCapType = rendering::PathCapType::BUTT;
338 aStrokeAttrs.JoinType = rendering::PathJoinType::MITER;
339 mxCanvas->strokePolyPolygon( xPoly, maViewState, maRenderState, aStrokeAttrs );
341 maRenderState = maOldRenderState; // pop
344 void drawText()
346 rendering::RenderState maOldRenderState = maRenderState; // push
347 translate( maBox.Width() * 2.0, 0.0 );
349 drawTitle( OString( "Text" ) );
351 translate( 0.0,
352 maBox.Height() * .5 );
353 drawTitle( OString( "This is lame" ) );
355 maRenderState = maOldRenderState; // pop
358 void drawImages()
360 rendering::RenderState maOldRenderState = maRenderState; // push
361 translate( 0.0, maBox.Height() );
363 drawTitle( OString( "Images" ) );
365 uno::Reference< rendering::XBitmap > xBitmap(mxCanvas, uno::UNO_QUERY);
367 if( !xBitmap.is() )
368 return;
370 translate( maBox.Width()*0.1, maBox.Height()*0.2 );
371 maRenderState.AffineTransform.m00 *= 4.0/15;
372 maRenderState.AffineTransform.m11 *= 3.0/15;
374 mxCanvas->drawBitmap(xBitmap, maViewState, maRenderState);
376 // uno::Reference< rendering::XBitmap > xBitmap2( xBitmap->getScaledBitmap(geometry::RealSize2D(48, 48), false) );
377 // mxCanvas->drawBitmap(xBitmap2, maViewState, maRenderState); //yes, but where?
378 //cairo-canvas says:
379 //called CanvasHelper::getScaledBitmap, we return NULL, TODO
380 //Exception 'BitmapEx vclcanvas::tools::bitmapExFromXBitmap(const com::sun::star::uno::Reference<com::sun::star::rendering::XBitmap>&),
381 //bitmapExFromXBitmap(): could not extract BitmapEx' thrown
383 //vcl-canvas says:
384 //Exception 'BitmapEx vclcanvas::tools::bitmapExFromXBitmap(const com::sun::star::uno::Reference<com::sun::star::rendering::XBitmap>&),
385 //bitmapExFromXBitmap(): could not extract bitmap' thrown
386 // Thorsten says that this is a bug, and Thorsten never lies.
388 maRenderState = maOldRenderState; // pop
391 void drawLines()
393 rendering::RenderState maOldRenderState = maRenderState; // push
394 translate( maBox.Width(), maBox.Height() );
396 drawTitle( OString( "Lines" ) );
398 drawPolishDiamond( 70.0, 80.0 );
399 drawHilbert( 140.0, 140.0 );
401 maRenderState = maOldRenderState; // pop
404 void drawCurves()
406 rendering::RenderState maOldRenderState = maRenderState; // push
407 translate( maBox.Width() * 2.0, maBox.Height() );
409 drawTitle( OString( "Curves" ) );
411 translate( maBox.Width() * .5, maBox.Height() * .5 );
413 const double r= 30.0;
414 const int num_curves = 3;
416 //hacky hack hack
417 uno::Sequence< geometry::RealBezierSegment2D > aBeziers (num_curves);
418 uno::Reference< rendering::XBezierPolyPolygon2D > xPoly;
420 for (int i= 0; i < num_curves; i++)
421 aBeziers[i]= geometry::RealBezierSegment2D( r * cos(i*2*M_PI/num_curves), //Px
422 r * sin(i*2*M_PI/num_curves), //py
423 r * 2 * cos((i*2*M_PI + 2*M_PI)/num_curves), //C1x
424 r * 2 * sin((i*2*M_PI + 2*M_PI)/num_curves), //C1y
425 r * 2 * cos((i*2*M_PI + 2*M_PI)/num_curves), //C2x
426 r * 2 * sin((i*2*M_PI + 2*M_PI)/num_curves)); //C2y
427 uno::Sequence< uno::Sequence< geometry::RealBezierSegment2D > > aPolys(1);
428 aPolys[0] = aBeziers;
429 xPoly = mxDevice->createCompatibleBezierPolyPolygon(aPolys);
430 xPoly->setClosed( 0, true );
431 //uno::Reference< rendering::XBezierPolyPolygon2D> xPP( xPoly, uno::UNO_QUERY );
432 //compiles, but totally screws up. I think it is interpretting the bezier as a line
433 uno::Reference< rendering::XPolyPolygon2D> xPP( xPoly, uno::UNO_QUERY );
435 rendering::StrokeAttributes aStrokeAttrs;
436 aStrokeAttrs.StrokeWidth = 4.0;
437 aStrokeAttrs.MiterLimit = 2.0; // ?
438 aStrokeAttrs.StartCapType = rendering::PathCapType::BUTT;
439 aStrokeAttrs.EndCapType = rendering::PathCapType::BUTT;
440 aStrokeAttrs.JoinType = rendering::PathJoinType::MITER;
441 mxCanvas->strokePolyPolygon( xPP, maViewState, maRenderState, aStrokeAttrs );
442 //you can't draw a BezierPolyPolygon2D with this, even though it is derived from it
443 //mxCanvas->drawPolyPolygon( xPP, maViewState, maRenderState );
445 maRenderState = maOldRenderState; // pop
448 double gimmerand()
450 return (double)(rand()) / RAND_MAX * 100 + 50;
453 void drawArcs()
455 rendering::RenderState maOldRenderState = maRenderState; // push
456 translate( 0.0, maBox.Height() * 2.0 );
458 drawTitle( OString( "Arcs" ) );
461 //begin hacks
462 //This stuff doesn't belong here, but probably in curves
463 //This stuff doesn't work in VCL b/c vcl doesn't do beziers
464 //Hah! Every time the window redraws, we do this
465 double bx;
466 double by;
467 bx= gimmerand();
468 by= gimmerand();
470 for (int i= 0; i < 1; i++)
472 double ax;
473 double ay;
474 //point a= point b;
475 ax= bx;
476 ay= by;
477 //point b= rand;
478 bx= gimmerand();
479 by= gimmerand();
480 double c1x= gimmerand();
481 double c1y= gimmerand();
482 double c2x= gimmerand();
483 double c2y= gimmerand();
484 maRenderState.DeviceColor = maColorRed;
485 mxCanvas->drawLine(geometry::RealPoint2D(ax, ay), geometry::RealPoint2D(c1x, c1y), maViewState, maRenderState);
486 mxCanvas->drawLine(geometry::RealPoint2D(c1x, c1y), geometry::RealPoint2D(c2x, c2y), maViewState, maRenderState);
487 mxCanvas->drawLine(geometry::RealPoint2D(bx, by), geometry::RealPoint2D(c2x, c2y), maViewState, maRenderState);
488 //draw from a to b
489 geometry::RealBezierSegment2D aBezierSegment(
490 ax, //Px
491 ay, //Py
492 c1x,
493 c1x,
494 c2x,
497 geometry::RealPoint2D aEndPoint(bx, by);
498 maRenderState.DeviceColor = maColorBlack;
499 mxCanvas->drawBezier(
500 aBezierSegment,
501 aEndPoint,
502 maViewState, maRenderState );
504 maRenderState = maOldRenderState; // pop
508 void drawRegularPolygon(double centerx, double centery, int sides, double r)
510 //hacky hack hack
511 uno::Sequence< geometry::RealPoint2D > aPoints (sides);
512 uno::Reference< rendering::XLinePolyPolygon2D > xPoly;
514 for (int i= 0; i < sides; i++)
516 aPoints[i]= geometry::RealPoint2D( centerx + r * cos(i*2 * M_PI/sides),
517 centery + r * sin(i*2 * M_PI/sides));
519 uno::Sequence< uno::Sequence< geometry::RealPoint2D > > aPolys(1);
520 aPolys[0] = aPoints;
521 xPoly = mxDevice->createCompatibleLinePolyPolygon( aPolys );
522 xPoly->setClosed( 0, true );
523 rendering::RenderState aRenderState( maRenderState );
524 aRenderState.DeviceColor = maColorRed;
525 uno::Reference< rendering::XPolyPolygon2D> xPP( xPoly, uno::UNO_QUERY );
526 mxCanvas->drawPolyPolygon( xPP, maViewState, aRenderState);
527 mxCanvas->fillPolyPolygon( xPP,
528 maViewState,
529 aRenderState );
532 void drawPolygons()
534 rendering::RenderState maOldRenderState = maRenderState; // push
535 translate( maBox.Width() * 1.0, maBox.Height() * 2.0 );
537 drawTitle( OString( "Polgyons" ) );
539 int sides= 3;
540 for (int i= 1; i <= 4; i++)
542 drawRegularPolygon(35*i, 35, sides, 15);
543 sides++;
546 maRenderState = maOldRenderState; // pop
549 void drawWidgets() // FIXME: prolly makes no sense
551 rendering::RenderState maOldRenderState = maRenderState; // push
552 translate( maBox.Width() * 2.0, maBox.Height() * 2.0 );
554 drawTitle( OString( "Widgets" ) );
556 maRenderState = maOldRenderState; // pop
561 void TestWindow::Paint( const Rectangle& /*rRect*/ )
565 const Size aVDevSize(300,300);
566 VirtualDevice aVDev(*this);
567 aVDev.SetOutputSizePixel(aVDevSize);
568 uno::Reference< rendering::XCanvas > xVDevCanvas( aVDev.GetCanvas(),
569 uno::UNO_QUERY_THROW );
570 uno::Reference< rendering::XGraphicDevice > xVDevDevice( xVDevCanvas->getDevice(),
571 uno::UNO_QUERY_THROW );
572 DemoRenderer aVDevRenderer( xVDevDevice, xVDevCanvas, aVDevSize);
573 xVDevCanvas->clear();
574 aVDevRenderer.drawGrid();
575 aVDevRenderer.drawRectangles();
576 aVDevRenderer.drawEllipses();
577 aVDevRenderer.drawText();
578 aVDevRenderer.drawLines();
579 aVDevRenderer.drawCurves();
580 aVDevRenderer.drawArcs();
581 aVDevRenderer.drawPolygons();
583 uno::Reference< rendering::XCanvas > xCanvas( GetSpriteCanvas(),
584 uno::UNO_QUERY_THROW );
585 uno::Reference< rendering::XGraphicDevice > xDevice( xCanvas->getDevice(),
586 uno::UNO_QUERY_THROW );
588 DemoRenderer aRenderer( xDevice, xCanvas, GetSizePixel() );
589 xCanvas->clear();
590 aRenderer.drawGrid();
591 aRenderer.drawRectangles();
592 aRenderer.drawEllipses();
593 aRenderer.drawText();
594 aRenderer.drawLines();
595 aRenderer.drawCurves();
596 aRenderer.drawArcs();
597 aRenderer.drawPolygons();
598 aRenderer.drawWidgets();
599 aRenderer.drawImages();
601 // check whether virdev actually contained something
602 uno::Reference< rendering::XBitmap > xBitmap(xVDevCanvas, uno::UNO_QUERY);
603 if( !xBitmap.is() )
604 return;
606 aRenderer.maRenderState.AffineTransform.m02 += 100;
607 aRenderer.maRenderState.AffineTransform.m12 += 100;
608 xCanvas->drawBitmap(xBitmap, aRenderer.maViewState, aRenderer.maRenderState);
610 uno::Reference< rendering::XSpriteCanvas > xSpriteCanvas( xCanvas,
611 uno::UNO_QUERY );
612 if( xSpriteCanvas.is() )
613 xSpriteCanvas->updateScreen( sal_True ); // without
614 // updateScreen(),
615 // nothing is
616 // visible
618 catch (const uno::Exception &e)
620 fprintf( stderr, "Exception '%s' thrown\n" ,
621 OUStringToOString( e.Message, RTL_TEXTENCODING_UTF8 ).getStr() );
625 USHORT DemoApp::Exception( USHORT nError )
627 switch( nError & EXC_MAJORTYPE )
629 case EXC_RSCNOTLOADED:
630 Abort( "Error: could not load language resources.\nPlease check your installation.\n" );
631 break;
633 return 0;
636 void DemoApp::Main()
638 bool bHelp = false;
640 for( USHORT i = 0; i < GetCommandLineParamCount(); i++ )
642 OUString aParam = GetCommandLineParam( i );
644 if( aParam == "--help" || aParam == "-h" )
645 bHelp = true;
648 if( bHelp )
650 PrintHelp();
651 return;
655 // create the global service-manager
657 uno::Reference< lang::XMultiServiceFactory > xFactory;
660 uno::Reference< uno::XComponentContext > xCtx = ::cppu::defaultBootstrap_InitialComponentContext();
661 xFactory = uno::Reference< lang::XMultiServiceFactory >( xCtx->getServiceManager(),
662 uno::UNO_QUERY );
663 if( xFactory.is() )
664 ::comphelper::setProcessServiceFactory( xFactory );
666 catch( const uno::Exception& )
670 if( !xFactory.is() )
672 fprintf( stderr, "Could not bootstrap UNO, installation must be in disorder. Exiting.\n" );
673 exit( 1 );
676 // Create UCB (for backwards compatibility, in case some code still uses
677 // plain createInstance w/o args directly to obtain an instance):
678 ::ucb::UniversalContentBroker::create(
679 comphelper::getProcessComponentContext() );
681 InitVCL();
682 TestWindow pWindow;
683 pWindow.Execute();
684 DeInitVCL();
687 DemoApp aDemoApp;
689 // TODO
690 // - bouncing clip-rectangle mode - bounce a clip-rect around the window ...
691 // - complete all of pre-existing canvas bits
692 // - affine transform tweakage ...
694 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */