Version 6.1.4.1, tag libreoffice-6.1.4.1
[LibreOffice.git] / canvas / workben / canvasdemo.cxx
blobc419bb72775a5184d3ed7c17eef4cd375223db7f
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 <sal/config.h>
25 #include <stdio.h>
26 #include <unistd.h>
28 #include <basegfx/polygon/b2dpolygon.hxx>
29 #include <basegfx/polygon/b2dpolygontools.hxx>
30 #include <basegfx/utils/canvastools.hxx>
31 #include <com/sun/star/lang/XInitialization.hpp>
32 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
33 #include <com/sun/star/registry/XSimpleRegistry.hpp>
34 #include <com/sun/star/rendering/CompositeOperation.hpp>
35 #include <com/sun/star/rendering/FillRule.hpp>
36 #include <com/sun/star/rendering/PathCapType.hpp>
37 #include <com/sun/star/rendering/PathJoinType.hpp>
38 #include <com/sun/star/rendering/RenderState.hpp>
39 #include <com/sun/star/rendering/ViewState.hpp>
40 #include <com/sun/star/rendering/XBitmap.hpp>
41 #include <com/sun/star/rendering/XCanvas.hpp>
42 #include <com/sun/star/rendering/XGraphicDevice.hpp>
43 #include <com/sun/star/rendering/XSpriteCanvas.hpp>
44 #include <com/sun/star/ucb/UniversalContentBroker.hpp>
45 #include <comphelper/processfactory.hxx>
46 #include <cppuhelper/bootstrap.hxx>
47 #include <cppuhelper/servicefactory.hxx>
48 #include <rtl/bootstrap.hxx>
49 #include <sal/macros.h>
50 #include <vcl/canvastools.hxx>
51 #include <vcl/svapp.hxx>
52 #include <vcl/unowrap.hxx>
53 #include <vcl/virdev.hxx>
54 #include <vcl/window.hxx>
57 // never import whole leaf namespaces, since this will result in
58 // absolutely weird effects during (Koenig) name lookup
59 using namespace ::com::sun::star;
62 class DemoApp : public Application
64 public:
65 virtual void Main();
66 virtual void Exception( ExceptionCategory nCategory );
69 static void PrintHelp()
71 fprintf( stdout, "canvasdemo - Exercise the new canvas impl\n" );
74 class TestWindow : public Dialog
76 public:
77 TestWindow() : Dialog( (vcl::Window *) NULL )
79 SetText( OUString( "Canvas test" ) );
80 SetSizePixel( Size( 600, 450 ) );
81 EnablePaint( true );
82 Show();
84 virtual ~TestWindow() {}
85 virtual void MouseButtonUp( const MouseEvent& /*rMEvt*/ )
87 //TODO: do something cool
88 EndDialog();
90 virtual void Paint( const Rectangle& rRect );
93 class DemoRenderer
95 public:
96 Size maSize;
97 Size maBox;
98 rendering::ViewState maViewState;
99 rendering::RenderState maRenderState;
100 uno::Sequence< double > maColorBlack;
101 uno::Sequence< double > maColorWhite;
102 uno::Sequence< double > maColorRed;
103 uno::Reference< rendering::XCanvas > mxCanvas;
104 uno::Reference< rendering::XCanvasFont > mxDefaultFont;
105 uno::Reference< rendering::XGraphicDevice > mxDevice;
107 DemoRenderer( uno::Reference< rendering::XGraphicDevice > xDevice,
108 uno::Reference< rendering::XCanvas > xCanvas,
109 Size aSize ) :
110 maSize(aSize),
111 maBox(),
112 maViewState(),
113 maRenderState(),
114 maColorBlack( vcl::unotools::colorToStdColorSpaceSequence( COL_BLACK) ),
115 maColorWhite( vcl::unotools::colorToStdColorSpaceSequence( COL_WHITE) ),
116 maColorRed( vcl::unotools::colorToStdColorSpaceSequence( COL_RED) ),
117 mxCanvas(xCanvas),
118 mxDefaultFont(),
119 mxDevice( xDevice )
121 // Geometry init
122 geometry::AffineMatrix2D aUnit( 1,0, 0,
123 0,1, 0 );
124 maViewState.AffineTransform = aUnit;
125 maRenderState.AffineTransform = aUnit;
126 maRenderState.DeviceColor = maColorBlack;
128 //I can't figure out what the compositeoperation stuff does
129 //it doesn't seem to do anything in either VCL or cairocanvas
130 //I was hoping that CLEAR would clear the canvas before we paint,
131 //but nothing changes
132 maRenderState.CompositeOperation = rendering::CompositeOperation::OVER;
134 maBox.Width() = aSize.Width() / 3;
135 maBox.Height() = aSize.Height() / 3;
137 lang::Locale aLocale;
138 rendering::FontInfo aFontInfo;
139 aFontInfo.FamilyName = "Swiss";
140 aFontInfo.StyleName = "SansSerif";
141 geometry::Matrix2D aFontMatrix( 1, 0,
142 0, 1 );
143 rendering::FontRequest aFontRequest( aFontInfo, 12.0, 0.0, aLocale );
144 uno::Sequence< beans::PropertyValue > aExtraFontProperties;
145 mxDefaultFont = xCanvas->createFont( aFontRequest, aExtraFontProperties, aFontMatrix );
146 if( !mxDefaultFont.is() )
147 fprintf( stderr, "Failed to create font\n" );
150 void drawGrid()
152 double d, dIncr = maSize.Width() / 3;
153 for ( d = 0; d <= maSize.Width(); d += dIncr )
154 mxCanvas->drawLine( geometry::RealPoint2D( d, 0 ),
155 geometry::RealPoint2D( d, maSize.Height() ),
156 maViewState, maRenderState );
157 dIncr = maSize.Height() / 3;
158 for ( d = 0; d <= maSize.Height(); d += dIncr )
159 mxCanvas->drawLine( geometry::RealPoint2D( 0, d ),
160 geometry::RealPoint2D( maSize.Width(), d ),
161 maViewState, maRenderState );
164 void drawStringAt( OString aString, double x, double y )
166 rendering::StringContext aText;
167 aText.Text = OStringToOUString( aString, RTL_TEXTENCODING_UTF8 );
168 aText.StartPosition = 0;
169 aText.Length = aString.getLength();
170 rendering::RenderState aRenderState( maRenderState );
171 aRenderState.AffineTransform.m02 += x;
172 aRenderState.AffineTransform.m12 += y;
174 mxCanvas->drawText( aText, mxDefaultFont, maViewState, aRenderState, 0);
177 void drawRect( Rectangle rRect, uno::Sequence< double > &aColor, int /*nWidth*/ )
179 uno::Sequence< geometry::RealPoint2D > aPoints(4);
180 uno::Reference< rendering::XLinePolyPolygon2D > xPoly;
182 aPoints[0] = geometry::RealPoint2D( rRect.Left(), rRect.Top() );
183 aPoints[1] = geometry::RealPoint2D( rRect.Left(), rRect.Bottom() );
184 aPoints[2] = geometry::RealPoint2D( rRect.Right(), rRect.Bottom() );
185 aPoints[3] = geometry::RealPoint2D( rRect.Right(), rRect.Top() );
187 uno::Sequence< uno::Sequence< geometry::RealPoint2D > > aPolys(1);
188 aPolys[0] = aPoints;
189 xPoly = mxDevice->createCompatibleLinePolyPolygon( aPolys );
190 xPoly->setClosed( 0, true );
191 uno::Reference< rendering::XPolyPolygon2D> xPP( xPoly, uno::UNO_QUERY );
193 rendering::RenderState aRenderState( maRenderState );
194 aRenderState.DeviceColor = aColor;
195 mxCanvas->drawPolyPolygon( xPP, maViewState, aRenderState );
198 void translate( double x, double y)
200 maRenderState.AffineTransform.m02 += x;
201 maRenderState.AffineTransform.m12 += y;
204 void drawPolishDiamond( double center_x, double center_y)
206 const int VERTICES = 10;
207 const double RADIUS = 60.0;
208 int i, j;
210 rendering::RenderState maOldRenderState = maRenderState; // push
211 translate( center_x, center_y );
213 for (i = 0; i < VERTICES; i++)
215 double a = 2.0 * M_PI * i / VERTICES;
216 geometry::RealPoint2D aSrc( RADIUS * cos (a), RADIUS * sin (a) );
218 for (j = i + 1; j < VERTICES; j++)
220 a = 2.0 * M_PI * j / VERTICES;
222 // FIXME: set cap_style to 'ROUND'
223 mxCanvas->drawLine( aSrc,
224 geometry::RealPoint2D( RADIUS * cos (a),
225 RADIUS * sin (a) ),
226 maViewState, maRenderState );
230 maRenderState = maOldRenderState; // pop
233 void drawHilbert( double anchor_x, double anchor_y )
235 const double SCALE=7.0;
236 const char hilbert[] = "urdrrulurulldluuruluurdrurddldrrruluurdrurddldrddlulldrdldrrurd";
237 int nLength = SAL_N_ELEMENTS( hilbert );
239 uno::Sequence< geometry::RealPoint2D > aPoints( nLength );
240 uno::Reference< rendering::XLinePolyPolygon2D > xPoly;
242 aPoints[0] = geometry::RealPoint2D( anchor_x, anchor_y );
243 for (int i = 0; i < nLength; i++ )
245 switch( hilbert[i] )
247 case 'u':
248 aPoints[i+1] = geometry::RealPoint2D( aPoints[i].X,
249 aPoints[i].Y - SCALE );
250 break;
251 case 'd':
252 aPoints[i+1] = geometry::RealPoint2D( aPoints[i].X,
253 aPoints[i].Y + SCALE );
254 break;
255 case 'l':
256 aPoints[i+1] = geometry::RealPoint2D( aPoints[i].X - SCALE,
257 aPoints[i].Y );
258 break;
259 case 'r':
260 aPoints[i+1] = geometry::RealPoint2D( aPoints[i].X + SCALE,
261 aPoints[i].Y );
262 break;
266 uno::Sequence< uno::Sequence< geometry::RealPoint2D > > aPolys(1);
267 aPolys[0] = aPoints;
269 xPoly = mxDevice->createCompatibleLinePolyPolygon( aPolys );
270 xPoly->setClosed( 0, false );
271 uno::Reference< rendering::XPolyPolygon2D> xPP( xPoly, uno::UNO_QUERY );
273 rendering::RenderState aRenderState( maRenderState );
274 aRenderState.DeviceColor = maColorRed;
275 // aRenderState.DeviceColor[3] = 0.5;
276 rendering::StrokeAttributes aStrokeAttrs;
277 aStrokeAttrs.StrokeWidth = 4.0;
278 aStrokeAttrs.MiterLimit = 2.0; // ?
279 aStrokeAttrs.StartCapType = rendering::PathCapType::BUTT;
280 aStrokeAttrs.EndCapType = rendering::PathCapType::BUTT;
281 aStrokeAttrs.JoinType = rendering::PathJoinType::MITER;
282 //fprintf( stderr, "FIXME: stroking a tools::PolyPolygon doesn't show up\n" );
283 //yes it does
284 mxCanvas->strokePolyPolygon( xPP, maViewState, aRenderState, aStrokeAttrs );
285 // FIXME: do this instead:
286 //mxCanvas->drawPolyPolygon( xPP, maViewState, aRenderState );
289 void drawTitle( OString aTitle )
291 // FIXME: text anchoring to be done
292 double nStringWidth = aTitle.getLength() * 8.0;
293 drawStringAt ( aTitle, (maBox.Width() - nStringWidth) / 2, 15 );
296 void drawRectangles()
298 rendering::RenderState maOldRenderState = maRenderState; // push
300 drawTitle( OString( "Rectangles" ) );
302 drawRect( Rectangle( 20, 30, 70, 60 ), maColorRed, 8 );
303 // color mediumseagreen, stipple fill, outline black
304 drawRect( Rectangle( 90, 40, 180, 100 ), maColorBlack, 4 );
305 // color steelblue, filled, no outline
306 drawRect( Rectangle( 10, 80, 80, 140 ), maColorBlack, 1 );
308 maRenderState = maOldRenderState; // pop
311 void drawEllipses()
313 rendering::RenderState maOldRenderState = maRenderState; // push
314 translate( maBox.Width(), 0.0 );
316 drawTitle( OString( "Ellipses" ) );
318 const basegfx::B2DPoint aCenter( maBox.Width()*.5,
319 maBox.Height()*.5 );
320 const basegfx::B2DPoint aRadii( maBox.Width()*.3,
321 maBox.Height()*.3 );
322 const basegfx::B2DPolygon& rEllipse(
323 basegfx::utils::createPolygonFromEllipse( aCenter,
324 aRadii.getX(),
325 aRadii.getY() ));
327 uno::Reference< rendering::XPolyPolygon2D > xPoly(
328 basegfx::unotools::xPolyPolygonFromB2DPolygon(mxDevice,
329 rEllipse) );
331 rendering::StrokeAttributes aStrokeAttrs;
332 aStrokeAttrs.StrokeWidth = 4.0;
333 aStrokeAttrs.MiterLimit = 2.0; // ?
334 aStrokeAttrs.StartCapType = rendering::PathCapType::BUTT;
335 aStrokeAttrs.EndCapType = rendering::PathCapType::BUTT;
336 aStrokeAttrs.JoinType = rendering::PathJoinType::MITER;
337 mxCanvas->strokePolyPolygon( xPoly, maViewState, maRenderState, aStrokeAttrs );
339 maRenderState = maOldRenderState; // pop
342 void drawText()
344 rendering::RenderState maOldRenderState = maRenderState; // push
345 translate( maBox.Width() * 2.0, 0.0 );
347 drawTitle( OString( "Text" ) );
349 translate( 0.0,
350 maBox.Height() * .5 );
351 drawTitle( OString( "This is lame" ) );
353 maRenderState = maOldRenderState; // pop
356 void drawImages()
358 rendering::RenderState maOldRenderState = maRenderState; // push
359 translate( 0.0, maBox.Height() );
361 drawTitle( OString( "Images" ) );
363 uno::Reference< rendering::XBitmap > xBitmap(mxCanvas, uno::UNO_QUERY);
365 if( !xBitmap.is() )
366 return;
368 translate( maBox.Width()*0.1, maBox.Height()*0.2 );
369 maRenderState.AffineTransform.m00 *= 4.0/15;
370 maRenderState.AffineTransform.m11 *= 3.0/15;
372 mxCanvas->drawBitmap(xBitmap, maViewState, maRenderState);
374 // uno::Reference< rendering::XBitmap > xBitmap2( xBitmap->getScaledBitmap(geometry::RealSize2D(48, 48), false) );
375 // mxCanvas->drawBitmap(xBitmap2, maViewState, maRenderState); //yes, but where?
376 //cairo-canvas says:
377 //called CanvasHelper::getScaledBitmap, we return NULL, TODO
378 //Exception 'BitmapEx vclcanvas::tools::bitmapExFromXBitmap(const css::uno::Reference<css::rendering::XBitmap>&),
379 //bitmapExFromXBitmap(): could not extract BitmapEx' thrown
381 //vcl-canvas says:
382 //Exception 'BitmapEx vclcanvas::tools::bitmapExFromXBitmap(const css::uno::Reference<css::rendering::XBitmap>&),
383 //bitmapExFromXBitmap(): could not extract bitmap' thrown
384 // Thorsten says that this is a bug, and Thorsten never lies.
386 maRenderState = maOldRenderState; // pop
389 void drawLines()
391 rendering::RenderState maOldRenderState = maRenderState; // push
392 translate( maBox.Width(), maBox.Height() );
394 drawTitle( OString( "Lines" ) );
396 drawPolishDiamond( 70.0, 80.0 );
397 drawHilbert( 140.0, 140.0 );
399 maRenderState = maOldRenderState; // pop
402 void drawCurves()
404 rendering::RenderState maOldRenderState = maRenderState; // push
405 translate( maBox.Width() * 2.0, maBox.Height() );
407 drawTitle( OString( "Curves" ) );
409 translate( maBox.Width() * .5, maBox.Height() * .5 );
411 const double r= 30.0;
412 const int num_curves = 3;
414 //hacky hack hack
415 uno::Sequence< geometry::RealBezierSegment2D > aBeziers (num_curves);
416 uno::Reference< rendering::XBezierPolyPolygon2D > xPoly;
418 for (int i= 0; i < num_curves; i++)
419 aBeziers[i]= geometry::RealBezierSegment2D( r * cos(i*2*M_PI/num_curves), //Px
420 r * sin(i*2*M_PI/num_curves), //py
421 r * 2 * cos((i*2*M_PI + 2*M_PI)/num_curves), //C1x
422 r * 2 * sin((i*2*M_PI + 2*M_PI)/num_curves), //C1y
423 r * 2 * cos((i*2*M_PI + 2*M_PI)/num_curves), //C2x
424 r * 2 * sin((i*2*M_PI + 2*M_PI)/num_curves)); //C2y
425 uno::Sequence< uno::Sequence< geometry::RealBezierSegment2D > > aPolys(1);
426 aPolys[0] = aBeziers;
427 xPoly = mxDevice->createCompatibleBezierPolyPolygon(aPolys);
428 xPoly->setClosed( 0, true );
429 //uno::Reference< rendering::XBezierPolyPolygon2D> xPP( xPoly, uno::UNO_QUERY );
430 //compiles, but totally screws up. I think it is interpreting the bezier as a line
431 uno::Reference< rendering::XPolyPolygon2D> xPP( xPoly, uno::UNO_QUERY );
433 rendering::StrokeAttributes aStrokeAttrs;
434 aStrokeAttrs.StrokeWidth = 4.0;
435 aStrokeAttrs.MiterLimit = 2.0; // ?
436 aStrokeAttrs.StartCapType = rendering::PathCapType::BUTT;
437 aStrokeAttrs.EndCapType = rendering::PathCapType::BUTT;
438 aStrokeAttrs.JoinType = rendering::PathJoinType::MITER;
439 mxCanvas->strokePolyPolygon( xPP, maViewState, maRenderState, aStrokeAttrs );
440 //you can't draw a BezierPolyPolygon2D with this, even though it is derived from it
441 //mxCanvas->drawPolyPolygon( xPP, maViewState, maRenderState );
443 maRenderState = maOldRenderState; // pop
446 double gimmerand()
448 return (double)(rand()) / RAND_MAX * 100 + 50;
451 void drawArcs()
453 rendering::RenderState maOldRenderState = maRenderState; // push
454 translate( 0.0, maBox.Height() * 2.0 );
456 drawTitle( OString( "Arcs" ) );
459 //begin hacks
460 //This stuff doesn't belong here, but probably in curves
461 //This stuff doesn't work in VCL b/c vcl doesn't do beziers
462 //Hah! Every time the window redraws, we do this
463 double bx;
464 double by;
465 bx= gimmerand();
466 by= gimmerand();
468 for (int i= 0; i < 1; i++)
470 double ax;
471 double ay;
472 //point a= point b;
473 ax= bx;
474 ay= by;
475 //point b= rand;
476 bx= gimmerand();
477 by= gimmerand();
478 double c1x= gimmerand();
479 double c1y= gimmerand();
480 double c2x= gimmerand();
481 double c2y= gimmerand();
482 maRenderState.DeviceColor = maColorRed;
483 mxCanvas->drawLine(geometry::RealPoint2D(ax, ay), geometry::RealPoint2D(c1x, c1y), maViewState, maRenderState);
484 mxCanvas->drawLine(geometry::RealPoint2D(c1x, c1y), geometry::RealPoint2D(c2x, c2y), maViewState, maRenderState);
485 mxCanvas->drawLine(geometry::RealPoint2D(bx, by), geometry::RealPoint2D(c2x, c2y), maViewState, maRenderState);
486 //draw from a to b
487 geometry::RealBezierSegment2D aBezierSegment(
488 ax, //Px
489 ay, //Py
490 c1x,
491 c1x,
492 c2x,
495 geometry::RealPoint2D aEndPoint(bx, by);
496 maRenderState.DeviceColor = maColorBlack;
497 mxCanvas->drawBezier(
498 aBezierSegment,
499 aEndPoint,
500 maViewState, maRenderState );
502 maRenderState = maOldRenderState; // pop
506 void drawRegularPolygon(double centerx, double centery, int sides, double r)
508 //hacky hack hack
509 uno::Sequence< geometry::RealPoint2D > aPoints (sides);
510 uno::Reference< rendering::XLinePolyPolygon2D > xPoly;
512 for (int i= 0; i < sides; i++)
514 aPoints[i]= geometry::RealPoint2D( centerx + r * cos(i*2 * M_PI/sides),
515 centery + r * sin(i*2 * M_PI/sides));
517 uno::Sequence< uno::Sequence< geometry::RealPoint2D > > aPolys(1);
518 aPolys[0] = aPoints;
519 xPoly = mxDevice->createCompatibleLinePolyPolygon( aPolys );
520 xPoly->setClosed( 0, true );
521 rendering::RenderState aRenderState( maRenderState );
522 aRenderState.DeviceColor = maColorRed;
523 uno::Reference< rendering::XPolyPolygon2D> xPP( xPoly, uno::UNO_QUERY );
524 mxCanvas->drawPolyPolygon( xPP, maViewState, aRenderState);
525 mxCanvas->fillPolyPolygon( xPP,
526 maViewState,
527 aRenderState );
530 void drawPolygons()
532 rendering::RenderState maOldRenderState = maRenderState; // push
533 translate( maBox.Width() * 1.0, maBox.Height() * 2.0 );
535 drawTitle( OString( "Polgyons" ) );
537 int sides= 3;
538 for (int i= 1; i <= 4; i++)
540 drawRegularPolygon(35*i, 35, sides, 15);
541 sides++;
544 maRenderState = maOldRenderState; // pop
547 void drawWidgets() // FIXME: prolly makes no sense
549 rendering::RenderState maOldRenderState = maRenderState; // push
550 translate( maBox.Width() * 2.0, maBox.Height() * 2.0 );
552 drawTitle( OString( "Widgets" ) );
554 maRenderState = maOldRenderState; // pop
559 void TestWindow::Paint( const Rectangle& /*rRect*/ )
563 const Size aVDevSize(300,300);
564 VirtualDevice aVDev(*this);
565 aVDev.SetOutputSizePixel(aVDevSize);
566 uno::Reference< rendering::XCanvas > xVDevCanvas( aVDev.GetCanvas(),
567 uno::UNO_QUERY_THROW );
568 uno::Reference< rendering::XGraphicDevice > xVDevDevice( xVDevCanvas->getDevice(),
569 uno::UNO_QUERY_THROW );
570 DemoRenderer aVDevRenderer( xVDevDevice, xVDevCanvas, aVDevSize);
571 xVDevCanvas->clear();
572 aVDevRenderer.drawGrid();
573 aVDevRenderer.drawRectangles();
574 aVDevRenderer.drawEllipses();
575 aVDevRenderer.drawText();
576 aVDevRenderer.drawLines();
577 aVDevRenderer.drawCurves();
578 aVDevRenderer.drawArcs();
579 aVDevRenderer.drawPolygons();
581 uno::Reference< rendering::XCanvas > xCanvas( GetSpriteCanvas(),
582 uno::UNO_QUERY_THROW );
583 uno::Reference< rendering::XGraphicDevice > xDevice( xCanvas->getDevice(),
584 uno::UNO_QUERY_THROW );
586 DemoRenderer aRenderer( xDevice, xCanvas, GetSizePixel() );
587 xCanvas->clear();
588 aRenderer.drawGrid();
589 aRenderer.drawRectangles();
590 aRenderer.drawEllipses();
591 aRenderer.drawText();
592 aRenderer.drawLines();
593 aRenderer.drawCurves();
594 aRenderer.drawArcs();
595 aRenderer.drawPolygons();
596 aRenderer.drawWidgets();
597 aRenderer.drawImages();
599 // check whether virdev actually contained something
600 uno::Reference< rendering::XBitmap > xBitmap(xVDevCanvas, uno::UNO_QUERY);
601 if( !xBitmap.is() )
602 return;
604 aRenderer.maRenderState.AffineTransform.m02 += 100;
605 aRenderer.maRenderState.AffineTransform.m12 += 100;
606 xCanvas->drawBitmap(xBitmap, aRenderer.maViewState, aRenderer.maRenderState);
608 uno::Reference< rendering::XSpriteCanvas > xSpriteCanvas( xCanvas,
609 uno::UNO_QUERY );
610 if( xSpriteCanvas.is() )
611 xSpriteCanvas->updateScreen( sal_True ); // without
612 // updateScreen(),
613 // nothing is
614 // visible
616 catch (const uno::Exception &e)
618 fprintf( stderr, "Exception '%s' thrown\n" ,
619 OUStringToOString( e.Message, RTL_TEXTENCODING_UTF8 ).getStr() );
623 void DemoApp::Exception( ExceptionCategory nCategory )
625 switch( nCategory )
627 case ExceptionCategory::ResourceNotLoaded:
628 Abort( "Error: could not load language resources.\nPlease check your installation.\n" );
629 break;
633 void DemoApp::Main()
635 bool bHelp = false;
637 for( USHORT i = 0; i < GetCommandLineParamCount(); i++ )
639 OUString aParam = GetCommandLineParam( i );
641 if( aParam == "--help" || aParam == "-h" )
642 bHelp = true;
645 if( bHelp )
647 PrintHelp();
648 return;
652 // create the global service-manager
654 uno::Reference< lang::XMultiServiceFactory > xFactory;
657 uno::Reference< uno::XComponentContext > xCtx = ::cppu::defaultBootstrap_InitialComponentContext();
658 xFactory.set( xCtx->getServiceManager(), uno::UNO_QUERY );
659 if( xFactory.is() )
660 ::comphelper::setProcessServiceFactory( xFactory );
662 catch( const uno::Exception& )
666 if( !xFactory.is() )
668 fprintf( stderr, "Could not bootstrap UNO, installation must be in disorder. Exiting.\n" );
669 exit( 1 );
672 // Create UCB (for backwards compatibility, in case some code still uses
673 // plain createInstance w/o args directly to obtain an instance):
674 ::ucb::UniversalContentBroker::create(
675 comphelper::getProcessComponentContext() );
677 InitVCL();
678 TestWindow pWindow;
679 pWindow.Execute();
680 DeInitVCL();
683 DemoApp aDemoApp;
685 // TODO
686 // - bouncing clip-rectangle mode - bounce a clip-rect around the window...
687 // - complete all of pre-existing canvas bits
688 // - affine transform tweakage...
690 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */