bump product version to 4.1.6.2
[LibreOffice.git] / canvas / workben / canvasdemo.cxx
blobfe55c5721b54dcf1b19b796559f1d523f08cdf00
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( (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 = OUString( "Swiss" );
142 aFontInfo.StyleName = OUString( "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;
211 double a;
213 rendering::RenderState maOldRenderState = maRenderState; // push
214 translate( center_x, center_y );
216 for (i = 0; i < VERTICES; i++)
218 a = 2.0 * M_PI * i / VERTICES;
219 geometry::RealPoint2D aSrc( RADIUS * cos (a), RADIUS * sin (a) );
221 for (j = i + 1; j < VERTICES; j++)
223 a = 2.0 * M_PI * j / VERTICES;
225 // FIXME: set cap_style to 'ROUND'
226 mxCanvas->drawLine( aSrc,
227 geometry::RealPoint2D( RADIUS * cos (a),
228 RADIUS * sin (a) ),
229 maViewState, maRenderState );
233 maRenderState = maOldRenderState; // pop
236 void drawHilbert( double anchor_x, double anchor_y )
238 const double SCALE=7.0;
239 const char hilbert[] = "urdrrulurulldluuruluurdrurddldrrruluurdrurddldrddlulldrdldrrurd";
240 int nLength = SAL_N_ELEMENTS( hilbert );
242 uno::Sequence< geometry::RealPoint2D > aPoints( nLength );
243 uno::Reference< rendering::XLinePolyPolygon2D > xPoly;
245 aPoints[0] = geometry::RealPoint2D( anchor_x, anchor_y );
246 for (int i = 0; i < nLength; i++ )
248 switch( hilbert[i] )
250 case 'u':
251 aPoints[i+1] = geometry::RealPoint2D( aPoints[i].X,
252 aPoints[i].Y - SCALE );
253 break;
254 case 'd':
255 aPoints[i+1] = geometry::RealPoint2D( aPoints[i].X,
256 aPoints[i].Y + SCALE );
257 break;
258 case 'l':
259 aPoints[i+1] = geometry::RealPoint2D( aPoints[i].X - SCALE,
260 aPoints[i].Y );
261 break;
262 case 'r':
263 aPoints[i+1] = geometry::RealPoint2D( aPoints[i].X + SCALE,
264 aPoints[i].Y );
265 break;
269 uno::Sequence< uno::Sequence< geometry::RealPoint2D > > aPolys(1);
270 aPolys[0] = aPoints;
272 xPoly = mxDevice->createCompatibleLinePolyPolygon( aPolys );
273 xPoly->setClosed( 0, false );
274 uno::Reference< rendering::XPolyPolygon2D> xPP( xPoly, uno::UNO_QUERY );
276 rendering::RenderState aRenderState( maRenderState );
277 aRenderState.DeviceColor = maColorRed;
278 // aRenderState.DeviceColor[3] = 0.5;
279 rendering::StrokeAttributes aStrokeAttrs;
280 aStrokeAttrs.StrokeWidth = 4.0;
281 aStrokeAttrs.MiterLimit = 2.0; // ?
282 aStrokeAttrs.StartCapType = rendering::PathCapType::BUTT;
283 aStrokeAttrs.EndCapType = rendering::PathCapType::BUTT;
284 aStrokeAttrs.JoinType = rendering::PathJoinType::MITER;
285 //fprintf( stderr, "FIXME: stroking a PolyPolygon doesn't show up\n" );
286 //yes it does
287 mxCanvas->strokePolyPolygon( xPP, maViewState, aRenderState, aStrokeAttrs );
288 // FIXME: do this instead:
289 //mxCanvas->drawPolyPolygon( xPP, maViewState, aRenderState );
292 void drawTitle( OString aTitle )
294 // FIXME: text anchoring to be done
295 double nStringWidth = aTitle.getLength() * 8.0;
296 drawStringAt ( aTitle, (maBox.Width() - nStringWidth) / 2, 15 );
299 void drawRectangles()
301 rendering::RenderState maOldRenderState = maRenderState; // push
303 drawTitle( OString( "Rectangles" ) );
305 drawRect( Rectangle( 20, 30, 70, 60 ), maColorRed, 8 );
306 // color mediumseagreen, stipple fill, outline black
307 drawRect( Rectangle( 90, 40, 180, 100 ), maColorBlack, 4 );
308 // color steelblue, filled, no outline
309 drawRect( Rectangle( 10, 80, 80, 140 ), maColorBlack, 1 );
311 maRenderState = maOldRenderState; // pop
314 void drawEllipses()
316 rendering::RenderState maOldRenderState = maRenderState; // push
317 translate( maBox.Width(), 0.0 );
319 drawTitle( OString( "Ellipses" ) );
321 const basegfx::B2DPoint aCenter( maBox.Width()*.5,
322 maBox.Height()*.5 );
323 const basegfx::B2DPoint aRadii( maBox.Width()*.3,
324 maBox.Height()*.3 );
325 const basegfx::B2DPolygon& rEllipse(
326 basegfx::tools::createPolygonFromEllipse( aCenter,
327 aRadii.getX(),
328 aRadii.getY() ));
330 uno::Reference< rendering::XPolyPolygon2D > xPoly(
331 basegfx::unotools::xPolyPolygonFromB2DPolygon(mxDevice,
332 rEllipse) );
334 rendering::StrokeAttributes aStrokeAttrs;
335 aStrokeAttrs.StrokeWidth = 4.0;
336 aStrokeAttrs.MiterLimit = 2.0; // ?
337 aStrokeAttrs.StartCapType = rendering::PathCapType::BUTT;
338 aStrokeAttrs.EndCapType = rendering::PathCapType::BUTT;
339 aStrokeAttrs.JoinType = rendering::PathJoinType::MITER;
340 mxCanvas->strokePolyPolygon( xPoly, maViewState, maRenderState, aStrokeAttrs );
342 maRenderState = maOldRenderState; // pop
345 void drawText()
347 rendering::RenderState maOldRenderState = maRenderState; // push
348 translate( maBox.Width() * 2.0, 0.0 );
350 drawTitle( OString( "Text" ) );
352 translate( 0.0,
353 maBox.Height() * .5 );
354 drawTitle( OString( "This is lame" ) );
356 maRenderState = maOldRenderState; // pop
359 void drawImages()
361 rendering::RenderState maOldRenderState = maRenderState; // push
362 translate( 0.0, maBox.Height() );
364 drawTitle( OString( "Images" ) );
366 uno::Reference< rendering::XBitmap > xBitmap(mxCanvas, uno::UNO_QUERY);
368 if( !xBitmap.is() )
369 return;
371 translate( maBox.Width()*0.1, maBox.Height()*0.2 );
372 maRenderState.AffineTransform.m00 *= 4.0/15;
373 maRenderState.AffineTransform.m11 *= 3.0/15;
375 mxCanvas->drawBitmap(xBitmap, maViewState, maRenderState);
377 // uno::Reference< rendering::XBitmap > xBitmap2( xBitmap->getScaledBitmap(geometry::RealSize2D(48, 48), false) );
378 // mxCanvas->drawBitmap(xBitmap2, maViewState, maRenderState); //yes, but where?
379 //cairo-canvas says:
380 //called CanvasHelper::getScaledBitmap, we return NULL, TODO
381 //Exception 'BitmapEx vclcanvas::tools::bitmapExFromXBitmap(const com::sun::star::uno::Reference<com::sun::star::rendering::XBitmap>&),
382 //bitmapExFromXBitmap(): could not extract BitmapEx' thrown
384 //vcl-canvas says:
385 //Exception 'BitmapEx vclcanvas::tools::bitmapExFromXBitmap(const com::sun::star::uno::Reference<com::sun::star::rendering::XBitmap>&),
386 //bitmapExFromXBitmap(): could not extract bitmap' thrown
387 // Thorsten says that this is a bug, and Thorsten never lies.
389 maRenderState = maOldRenderState; // pop
392 void drawLines()
394 rendering::RenderState maOldRenderState = maRenderState; // push
395 translate( maBox.Width(), maBox.Height() );
397 drawTitle( OString( "Lines" ) );
399 drawPolishDiamond( 70.0, 80.0 );
400 drawHilbert( 140.0, 140.0 );
402 maRenderState = maOldRenderState; // pop
405 void drawCurves()
407 rendering::RenderState maOldRenderState = maRenderState; // push
408 translate( maBox.Width() * 2.0, maBox.Height() );
410 drawTitle( OString( "Curves" ) );
412 translate( maBox.Width() * .5, maBox.Height() * .5 );
414 const double r= 30.0;
415 const int num_curves = 3;
417 //hacky hack hack
418 uno::Sequence< geometry::RealBezierSegment2D > aBeziers (num_curves);
419 uno::Reference< rendering::XBezierPolyPolygon2D > xPoly;
421 for (int i= 0; i < num_curves; i++)
422 aBeziers[i]= geometry::RealBezierSegment2D( r * cos(i*2*M_PI/num_curves), //Px
423 r * sin(i*2*M_PI/num_curves), //py
424 r * 2 * cos((i*2*M_PI + 2*M_PI)/num_curves), //C1x
425 r * 2 * sin((i*2*M_PI + 2*M_PI)/num_curves), //C1y
426 r * 2 * cos((i*2*M_PI + 2*M_PI)/num_curves), //C2x
427 r * 2 * sin((i*2*M_PI + 2*M_PI)/num_curves)); //C2y
428 uno::Sequence< uno::Sequence< geometry::RealBezierSegment2D > > aPolys(1);
429 aPolys[0] = aBeziers;
430 xPoly = mxDevice->createCompatibleBezierPolyPolygon(aPolys);
431 xPoly->setClosed( 0, true );
432 //uno::Reference< rendering::XBezierPolyPolygon2D> xPP( xPoly, uno::UNO_QUERY );
433 //compiles, but totally screws up. I think it is interpretting the bezier as a line
434 uno::Reference< rendering::XPolyPolygon2D> xPP( xPoly, uno::UNO_QUERY );
436 rendering::StrokeAttributes aStrokeAttrs;
437 aStrokeAttrs.StrokeWidth = 4.0;
438 aStrokeAttrs.MiterLimit = 2.0; // ?
439 aStrokeAttrs.StartCapType = rendering::PathCapType::BUTT;
440 aStrokeAttrs.EndCapType = rendering::PathCapType::BUTT;
441 aStrokeAttrs.JoinType = rendering::PathJoinType::MITER;
442 mxCanvas->strokePolyPolygon( xPP, maViewState, maRenderState, aStrokeAttrs );
443 //you can't draw a BezierPolyPolygon2D with this, even though it is derived from it
444 //mxCanvas->drawPolyPolygon( xPP, maViewState, maRenderState );
446 maRenderState = maOldRenderState; // pop
449 double gimmerand()
451 return (double)(rand()) / RAND_MAX * 100 + 50;
454 void drawArcs()
456 rendering::RenderState maOldRenderState = maRenderState; // push
457 translate( 0.0, maBox.Height() * 2.0 );
459 drawTitle( OString( "Arcs" ) );
462 //begin hacks
463 //This stuff doesn't belong here, but probably in curves
464 //This stuff doesn't work in VCL b/c vcl doesn't do beziers
465 //Hah! Everytime the window redraws, we do this
466 double ax;
467 double ay;
468 double bx;
469 double by;
470 bx= gimmerand();
471 by= gimmerand();
473 for (int i= 0; i < 1; i++)
475 //point a= point b;
476 ax= bx;
477 ay= by;
478 //point b= rand;
479 bx= gimmerand();
480 by= gimmerand();
481 double c1x= gimmerand();
482 double c1y= gimmerand();
483 double c2x= gimmerand();
484 double c2y= gimmerand();
485 maRenderState.DeviceColor = maColorRed;
486 mxCanvas->drawLine(geometry::RealPoint2D(ax, ay), geometry::RealPoint2D(c1x, c1y), maViewState, maRenderState);
487 mxCanvas->drawLine(geometry::RealPoint2D(c1x, c1y), geometry::RealPoint2D(c2x, c2y), maViewState, maRenderState);
488 mxCanvas->drawLine(geometry::RealPoint2D(bx, by), geometry::RealPoint2D(c2x, c2y), maViewState, maRenderState);
489 //draw from a to b
490 geometry::RealBezierSegment2D aBezierSegment(
491 ax, //Px
492 ay, //Py
493 c1x,
494 c1x,
495 c2x,
498 geometry::RealPoint2D aEndPoint(bx, by);
499 maRenderState.DeviceColor = maColorBlack;
500 mxCanvas->drawBezier(
501 aBezierSegment,
502 aEndPoint,
503 maViewState, maRenderState );
505 maRenderState = maOldRenderState; // pop
509 void drawRegularPolygon(double centerx, double centery, int sides, double r)
511 //hacky hack hack
512 uno::Sequence< geometry::RealPoint2D > aPoints (sides);
513 uno::Reference< rendering::XLinePolyPolygon2D > xPoly;
515 for (int i= 0; i < sides; i++)
517 aPoints[i]= geometry::RealPoint2D( centerx + r * cos(i*2 * M_PI/sides),
518 centery + r * sin(i*2 * M_PI/sides));
520 uno::Sequence< uno::Sequence< geometry::RealPoint2D > > aPolys(1);
521 aPolys[0] = aPoints;
522 xPoly = mxDevice->createCompatibleLinePolyPolygon( aPolys );
523 xPoly->setClosed( 0, true );
524 rendering::RenderState aRenderState( maRenderState );
525 aRenderState.DeviceColor = maColorRed;
526 uno::Reference< rendering::XPolyPolygon2D> xPP( xPoly, uno::UNO_QUERY );
527 mxCanvas->drawPolyPolygon( xPP, maViewState, aRenderState);
528 mxCanvas->fillPolyPolygon( xPP,
529 maViewState,
530 aRenderState );
533 void drawPolygons()
535 rendering::RenderState maOldRenderState = maRenderState; // push
536 translate( maBox.Width() * 1.0, maBox.Height() * 2.0 );
538 drawTitle( OString( "Polgyons" ) );
540 int sides= 3;
541 for (int i= 1; i <= 4; i++)
543 drawRegularPolygon(35*i, 35, sides, 15);
544 sides++;
547 maRenderState = maOldRenderState; // pop
550 void drawWidgets() // FIXME: prolly makes no sense
552 rendering::RenderState maOldRenderState = maRenderState; // push
553 translate( maBox.Width() * 2.0, maBox.Height() * 2.0 );
555 drawTitle( OString( "Widgets" ) );
557 maRenderState = maOldRenderState; // pop
562 void TestWindow::Paint( const Rectangle& /*rRect*/ )
566 const Size aVDevSize(300,300);
567 VirtualDevice aVDev(*this);
568 aVDev.SetOutputSizePixel(aVDevSize);
569 uno::Reference< rendering::XCanvas > xVDevCanvas( aVDev.GetCanvas(),
570 uno::UNO_QUERY_THROW );
571 uno::Reference< rendering::XGraphicDevice > xVDevDevice( xVDevCanvas->getDevice(),
572 uno::UNO_QUERY_THROW );
573 DemoRenderer aVDevRenderer( xVDevDevice, xVDevCanvas, aVDevSize);
574 xVDevCanvas->clear();
575 aVDevRenderer.drawGrid();
576 aVDevRenderer.drawRectangles();
577 aVDevRenderer.drawEllipses();
578 aVDevRenderer.drawText();
579 aVDevRenderer.drawLines();
580 aVDevRenderer.drawCurves();
581 aVDevRenderer.drawArcs();
582 aVDevRenderer.drawPolygons();
584 uno::Reference< rendering::XCanvas > xCanvas( GetSpriteCanvas(),
585 uno::UNO_QUERY_THROW );
586 uno::Reference< rendering::XGraphicDevice > xDevice( xCanvas->getDevice(),
587 uno::UNO_QUERY_THROW );
589 DemoRenderer aRenderer( xDevice, xCanvas, GetSizePixel() );
590 xCanvas->clear();
591 aRenderer.drawGrid();
592 aRenderer.drawRectangles();
593 aRenderer.drawEllipses();
594 aRenderer.drawText();
595 aRenderer.drawLines();
596 aRenderer.drawCurves();
597 aRenderer.drawArcs();
598 aRenderer.drawPolygons();
599 aRenderer.drawWidgets();
600 aRenderer.drawImages();
602 // check whether virdev actually contained something
603 uno::Reference< rendering::XBitmap > xBitmap(xVDevCanvas, uno::UNO_QUERY);
604 if( !xBitmap.is() )
605 return;
607 aRenderer.maRenderState.AffineTransform.m02 += 100;
608 aRenderer.maRenderState.AffineTransform.m12 += 100;
609 xCanvas->drawBitmap(xBitmap, aRenderer.maViewState, aRenderer.maRenderState);
611 uno::Reference< rendering::XSpriteCanvas > xSpriteCanvas( xCanvas,
612 uno::UNO_QUERY );
613 if( xSpriteCanvas.is() )
614 xSpriteCanvas->updateScreen( sal_True ); // without
615 // updateScreen(),
616 // nothing is
617 // visible
619 catch (const uno::Exception &e)
621 fprintf( stderr, "Exception '%s' thrown\n" ,
622 OUStringToOString( e.Message, RTL_TEXTENCODING_UTF8 ).getStr() );
626 USHORT DemoApp::Exception( USHORT nError )
628 switch( nError & EXC_MAJORTYPE )
630 case EXC_RSCNOTLOADED:
631 Abort( "Error: could not load language resources.\nPlease check your installation.\n" );
632 break;
634 return 0;
637 void DemoApp::Main()
639 bool bHelp = false;
641 for( USHORT i = 0; i < GetCommandLineParamCount(); i++ )
643 OUString aParam = GetCommandLineParam( i );
645 if( aParam == "--help" || aParam == "-h" )
646 bHelp = true;
649 if( bHelp )
651 PrintHelp();
652 return;
655 //-------------------------------------------------
656 // create the global service-manager
657 //-------------------------------------------------
658 uno::Reference< lang::XMultiServiceFactory > xFactory;
661 uno::Reference< uno::XComponentContext > xCtx = ::cppu::defaultBootstrap_InitialComponentContext();
662 xFactory = uno::Reference< lang::XMultiServiceFactory >( xCtx->getServiceManager(),
663 uno::UNO_QUERY );
664 if( xFactory.is() )
665 ::comphelper::setProcessServiceFactory( xFactory );
667 catch( const uno::Exception& )
671 if( !xFactory.is() )
673 fprintf( stderr, "Could not bootstrap UNO, installation must be in disorder. Exiting.\n" );
674 exit( 1 );
677 // Create UCB (for backwards compatibility, in case some code still uses
678 // plain createInstance w/o args directly to obtain an instance):
679 ::ucb::UniversalContentBroker::create(
680 comphelper::getProcessComponentContext() );
682 InitVCL();
683 TestWindow pWindow;
684 pWindow.Execute();
685 DeInitVCL();
688 DemoApp aDemoApp;
690 // TODO
691 // - bouncing clip-rectangle mode - bounce a clip-rect around the window ...
692 // - complete all of pre-existing canvas bits
693 // - affine transform tweakage ...
695 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */