Version 3.6.0.2, tag libreoffice-3.6.0.2
[LibreOffice.git] / canvas / workben / canvasdemo.cxx
blob1aa919f28d40079c610ceb2149b407cc7f60c5d0
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 // This code strongly inspired by Miguel / Federico's Gnome Canvas demo code.
32 #include <comphelper/processfactory.hxx>
33 #include <cppuhelper/servicefactory.hxx>
34 #include <cppuhelper/bootstrap.hxx>
35 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
36 #include <com/sun/star/lang/XInitialization.hpp>
37 #include <com/sun/star/registry/XSimpleRegistry.hpp>
39 #include <ucbhelper/contentbroker.hxx>
40 #include <ucbhelper/configurationkeys.hxx>
42 #include <basegfx/polygon/b2dpolygon.hxx>
43 #include <basegfx/polygon/b2dpolygontools.hxx>
44 #include <basegfx/tools/canvastools.hxx>
46 #include <vcl/window.hxx>
47 #include <vcl/virdev.hxx>
48 #include <vcl/svapp.hxx>
49 #include <vcl/msgbox.hxx>
50 #include <vcl/unowrap.hxx>
51 #include <vcl/canvastools.hxx>
53 #include <rtl/bootstrap.hxx>
54 #include <sal/macros.h>
56 #include <com/sun/star/rendering/XCanvas.hpp>
57 #include <com/sun/star/rendering/FillRule.hpp>
58 #include <com/sun/star/rendering/ViewState.hpp>
59 #include <com/sun/star/rendering/RenderState.hpp>
60 #include <com/sun/star/rendering/PathCapType.hpp>
61 #include <com/sun/star/rendering/PathJoinType.hpp>
62 #include <com/sun/star/rendering/XSpriteCanvas.hpp>
63 #include <com/sun/star/rendering/XGraphicDevice.hpp>
64 #include <com/sun/star/rendering/CompositeOperation.hpp>
65 #include <com/sun/star/rendering/XBitmap.hpp>
67 #include <stdio.h>
68 #include <unistd.h>
71 // never import whole leaf namespaces, since this will result in
72 // absolutely weird effects during (Koenig) name lookup
73 using namespace ::com::sun::star;
76 class DemoApp : public Application
78 public:
79 virtual void Main();
80 virtual USHORT Exception( USHORT nError );
83 static void PrintHelp()
85 fprintf( stdout, "canvasdemo - Exercise the new canvas impl\n" );
88 class TestWindow : public Dialog
90 public:
91 TestWindow() : Dialog( (Window *) NULL )
93 SetText( rtl::OUString( "Canvas test" ) );
94 SetSizePixel( Size( 600, 450 ) );
95 EnablePaint( true );
96 Show();
98 virtual ~TestWindow() {}
99 virtual void MouseButtonUp( const MouseEvent& /*rMEvt*/ )
101 //TODO: do something cool
102 EndDialog();
104 virtual void Paint( const Rectangle& rRect );
107 class DemoRenderer
109 public:
110 Size maSize;
111 Size maBox;
112 rendering::ViewState maViewState;
113 rendering::RenderState maRenderState;
114 uno::Sequence< double > maColorBlack;
115 uno::Sequence< double > maColorWhite;
116 uno::Sequence< double > maColorRed;
117 uno::Reference< rendering::XCanvas > mxCanvas;
118 uno::Reference< rendering::XCanvasFont > mxDefaultFont;
119 uno::Reference< rendering::XGraphicDevice > mxDevice;
121 DemoRenderer( uno::Reference< rendering::XGraphicDevice > xDevice,
122 uno::Reference< rendering::XCanvas > xCanvas,
123 Size aSize ) :
124 maSize(aSize),
125 maBox(),
126 maViewState(),
127 maRenderState(),
128 maColorBlack( vcl::unotools::colorToStdColorSpaceSequence( Color(COL_BLACK)) ),
129 maColorWhite( vcl::unotools::colorToStdColorSpaceSequence( Color(COL_WHITE)) ),
130 maColorRed( vcl::unotools::colorToStdColorSpaceSequence( Color(COL_RED)) ),
131 mxCanvas(xCanvas),
132 mxDefaultFont(),
133 mxDevice( xDevice )
135 // Geometry init
136 geometry::AffineMatrix2D aUnit( 1,0, 0,
137 0,1, 0 );
138 maViewState.AffineTransform = aUnit;
139 maRenderState.AffineTransform = aUnit;
140 maRenderState.DeviceColor = maColorBlack;
142 //I can't figure out what the compsiteoperation stuff does
143 //it doesn't seem to do anything in either VCL or cairocanvas
144 //I was hoping that CLEAR would clear the canvas before we paint,
145 //but nothing changes
146 maRenderState.CompositeOperation = rendering::CompositeOperation::OVER;
148 maBox.Width() = aSize.Width() / 3;
149 maBox.Height() = aSize.Height() / 3;
151 lang::Locale aLocale;
152 rendering::FontInfo aFontInfo;
153 aFontInfo.FamilyName = ::rtl::OUString( "Swiss" );
154 aFontInfo.StyleName = ::rtl::OUString( "SansSerif" );
155 geometry::Matrix2D aFontMatrix( 1, 0,
156 0, 1 );
157 rendering::FontRequest aFontRequest( aFontInfo, 12.0, 0.0, aLocale );
158 uno::Sequence< beans::PropertyValue > aExtraFontProperties;
159 mxDefaultFont = xCanvas->createFont( aFontRequest, aExtraFontProperties, aFontMatrix );
160 if( !mxDefaultFont.is() )
161 fprintf( stderr, "Failed to create font\n" );
164 void drawGrid()
166 double d, dIncr = maSize.Width() / 3;
167 for ( d = 0; d <= maSize.Width(); d += dIncr )
168 mxCanvas->drawLine( geometry::RealPoint2D( d, 0 ),
169 geometry::RealPoint2D( d, maSize.Height() ),
170 maViewState, maRenderState );
171 dIncr = maSize.Height() / 3;
172 for ( d = 0; d <= maSize.Height(); d += dIncr )
173 mxCanvas->drawLine( geometry::RealPoint2D( 0, d ),
174 geometry::RealPoint2D( maSize.Width(), d ),
175 maViewState, maRenderState );
178 void drawStringAt( ::rtl::OString aString, double x, double y )
180 rendering::StringContext aText;
181 aText.Text = ::rtl::OStringToOUString( aString, RTL_TEXTENCODING_UTF8 );
182 aText.StartPosition = 0;
183 aText.Length = aString.getLength();
184 rendering::RenderState aRenderState( maRenderState );
185 aRenderState.AffineTransform.m02 += x;
186 aRenderState.AffineTransform.m12 += y;
188 mxCanvas->drawText( aText, mxDefaultFont, maViewState, aRenderState, 0);
191 void drawRect( Rectangle rRect, uno::Sequence< double > &aColor, int /*nWidth*/ )
193 uno::Sequence< geometry::RealPoint2D > aPoints(4);
194 uno::Reference< rendering::XLinePolyPolygon2D > xPoly;
196 aPoints[0] = geometry::RealPoint2D( rRect.Left(), rRect.Top() );
197 aPoints[1] = geometry::RealPoint2D( rRect.Left(), rRect.Bottom() );
198 aPoints[2] = geometry::RealPoint2D( rRect.Right(), rRect.Bottom() );
199 aPoints[3] = geometry::RealPoint2D( rRect.Right(), rRect.Top() );
201 uno::Sequence< uno::Sequence< geometry::RealPoint2D > > aPolys(1);
202 aPolys[0] = aPoints;
203 xPoly = mxDevice->createCompatibleLinePolyPolygon( aPolys );
204 xPoly->setClosed( 0, true );
205 uno::Reference< rendering::XPolyPolygon2D> xPP( xPoly, uno::UNO_QUERY );
207 rendering::RenderState aRenderState( maRenderState );
208 aRenderState.DeviceColor = aColor;
209 mxCanvas->drawPolyPolygon( xPP, maViewState, aRenderState );
212 void translate( double x, double y)
214 maRenderState.AffineTransform.m02 += x;
215 maRenderState.AffineTransform.m12 += y;
218 void drawPolishDiamond( double center_x, double center_y)
220 const int VERTICES = 10;
221 const double RADIUS = 60.0;
222 int i, j;
223 double a;
225 rendering::RenderState maOldRenderState = maRenderState; // push
226 translate( center_x, center_y );
228 for (i = 0; i < VERTICES; i++)
230 a = 2.0 * M_PI * i / VERTICES;
231 geometry::RealPoint2D aSrc( RADIUS * cos (a), RADIUS * sin (a) );
233 for (j = i + 1; j < VERTICES; j++)
235 a = 2.0 * M_PI * j / VERTICES;
237 // FIXME: set cap_style to 'ROUND'
238 mxCanvas->drawLine( aSrc,
239 geometry::RealPoint2D( RADIUS * cos (a),
240 RADIUS * sin (a) ),
241 maViewState, maRenderState );
245 maRenderState = maOldRenderState; // pop
248 void drawHilbert( double anchor_x, double anchor_y )
250 const double SCALE=7.0;
251 const char hilbert[] = "urdrrulurulldluuruluurdrurddldrrruluurdrurddldrddlulldrdldrrurd";
252 int nLength = SAL_N_ELEMENTS( hilbert );
254 uno::Sequence< geometry::RealPoint2D > aPoints( nLength );
255 uno::Reference< rendering::XLinePolyPolygon2D > xPoly;
257 aPoints[0] = geometry::RealPoint2D( anchor_x, anchor_y );
258 for (int i = 0; i < nLength; i++ )
260 switch( hilbert[i] )
262 case 'u':
263 aPoints[i+1] = geometry::RealPoint2D( aPoints[i].X,
264 aPoints[i].Y - SCALE );
265 break;
266 case 'd':
267 aPoints[i+1] = geometry::RealPoint2D( aPoints[i].X,
268 aPoints[i].Y + SCALE );
269 break;
270 case 'l':
271 aPoints[i+1] = geometry::RealPoint2D( aPoints[i].X - SCALE,
272 aPoints[i].Y );
273 break;
274 case 'r':
275 aPoints[i+1] = geometry::RealPoint2D( aPoints[i].X + SCALE,
276 aPoints[i].Y );
277 break;
281 uno::Sequence< uno::Sequence< geometry::RealPoint2D > > aPolys(1);
282 aPolys[0] = aPoints;
284 xPoly = mxDevice->createCompatibleLinePolyPolygon( aPolys );
285 xPoly->setClosed( 0, false );
286 uno::Reference< rendering::XPolyPolygon2D> xPP( xPoly, uno::UNO_QUERY );
288 rendering::RenderState aRenderState( maRenderState );
289 aRenderState.DeviceColor = maColorRed;
290 // aRenderState.DeviceColor[3] = 0.5;
291 rendering::StrokeAttributes aStrokeAttrs;
292 aStrokeAttrs.StrokeWidth = 4.0;
293 aStrokeAttrs.MiterLimit = 2.0; // ?
294 aStrokeAttrs.StartCapType = rendering::PathCapType::BUTT;
295 aStrokeAttrs.EndCapType = rendering::PathCapType::BUTT;
296 aStrokeAttrs.JoinType = rendering::PathJoinType::MITER;
297 //fprintf( stderr, "FIXME: stroking a PolyPolygon doesn't show up\n" );
298 //yes it does
299 mxCanvas->strokePolyPolygon( xPP, maViewState, aRenderState, aStrokeAttrs );
300 // FIXME: do this instead:
301 //mxCanvas->drawPolyPolygon( xPP, maViewState, aRenderState );
304 void drawTitle( rtl::OString aTitle )
306 // FIXME: text anchoring to be done
307 double nStringWidth = aTitle.getLength() * 8.0;
308 drawStringAt ( aTitle, (maBox.Width() - nStringWidth) / 2, 15 );
311 void drawRectangles()
313 rendering::RenderState maOldRenderState = maRenderState; // push
315 drawTitle( ::rtl::OString( "Rectangles" ) );
317 drawRect( Rectangle( 20, 30, 70, 60 ), maColorRed, 8 );
318 // color mediumseagreen, stipple fill, outline black
319 drawRect( Rectangle( 90, 40, 180, 100 ), maColorBlack, 4 );
320 // color steelblue, filled, no outline
321 drawRect( Rectangle( 10, 80, 80, 140 ), maColorBlack, 1 );
323 maRenderState = maOldRenderState; // pop
326 void drawEllipses()
328 rendering::RenderState maOldRenderState = maRenderState; // push
329 translate( maBox.Width(), 0.0 );
331 drawTitle( ::rtl::OString( "Ellipses" ) );
333 const basegfx::B2DPoint aCenter( maBox.Width()*.5,
334 maBox.Height()*.5 );
335 const basegfx::B2DPoint aRadii( maBox.Width()*.3,
336 maBox.Height()*.3 );
337 const basegfx::B2DPolygon& rEllipse(
338 basegfx::tools::createPolygonFromEllipse( aCenter,
339 aRadii.getX(),
340 aRadii.getY() ));
342 uno::Reference< rendering::XPolyPolygon2D > xPoly(
343 basegfx::unotools::xPolyPolygonFromB2DPolygon(mxDevice,
344 rEllipse) );
346 rendering::StrokeAttributes aStrokeAttrs;
347 aStrokeAttrs.StrokeWidth = 4.0;
348 aStrokeAttrs.MiterLimit = 2.0; // ?
349 aStrokeAttrs.StartCapType = rendering::PathCapType::BUTT;
350 aStrokeAttrs.EndCapType = rendering::PathCapType::BUTT;
351 aStrokeAttrs.JoinType = rendering::PathJoinType::MITER;
352 mxCanvas->strokePolyPolygon( xPoly, maViewState, maRenderState, aStrokeAttrs );
354 maRenderState = maOldRenderState; // pop
357 void drawText()
359 rendering::RenderState maOldRenderState = maRenderState; // push
360 translate( maBox.Width() * 2.0, 0.0 );
362 drawTitle( ::rtl::OString( "Text" ) );
364 translate( 0.0,
365 maBox.Height() * .5 );
366 drawTitle( ::rtl::OString( "This is lame" ) );
368 maRenderState = maOldRenderState; // pop
371 void drawImages()
373 rendering::RenderState maOldRenderState = maRenderState; // push
374 translate( 0.0, maBox.Height() );
376 drawTitle( ::rtl::OString( "Images" ) );
378 uno::Reference< rendering::XBitmap > xBitmap(mxCanvas, uno::UNO_QUERY);
380 if( !xBitmap.is() )
381 return;
383 translate( maBox.Width()*0.1, maBox.Height()*0.2 );
384 maRenderState.AffineTransform.m00 *= 4.0/15;
385 maRenderState.AffineTransform.m11 *= 3.0/15;
387 mxCanvas->drawBitmap(xBitmap, maViewState, maRenderState);
389 // uno::Reference< rendering::XBitmap > xBitmap2( xBitmap->getScaledBitmap(geometry::RealSize2D(48, 48), false) );
390 // mxCanvas->drawBitmap(xBitmap2, maViewState, maRenderState); //yes, but where?
391 //cairo-canvas says:
392 //called CanvasHelper::getScaledBitmap, we return NULL, TODO
393 //Exception 'BitmapEx vclcanvas::tools::bitmapExFromXBitmap(const com::sun::star::uno::Reference<com::sun::star::rendering::XBitmap>&),
394 //bitmapExFromXBitmap(): could not extract BitmapEx' thrown
396 //vcl-canvas says:
397 //Exception 'BitmapEx vclcanvas::tools::bitmapExFromXBitmap(const com::sun::star::uno::Reference<com::sun::star::rendering::XBitmap>&),
398 //bitmapExFromXBitmap(): could not extract bitmap' thrown
399 // Thorsten says that this is a bug, and Thorsten never lies.
401 maRenderState = maOldRenderState; // pop
404 void drawLines()
406 rendering::RenderState maOldRenderState = maRenderState; // push
407 translate( maBox.Width(), maBox.Height() );
409 drawTitle( ::rtl::OString( "Lines" ) );
411 drawPolishDiamond( 70.0, 80.0 );
412 drawHilbert( 140.0, 140.0 );
414 maRenderState = maOldRenderState; // pop
417 void drawCurves()
419 rendering::RenderState maOldRenderState = maRenderState; // push
420 translate( maBox.Width() * 2.0, maBox.Height() );
422 drawTitle( ::rtl::OString( "Curves" ) );
424 translate( maBox.Width() * .5, maBox.Height() * .5 );
426 const double r= 30.0;
427 const int num_curves = 3;
429 //hacky hack hack
430 uno::Sequence< geometry::RealBezierSegment2D > aBeziers (num_curves);
431 uno::Reference< rendering::XBezierPolyPolygon2D > xPoly;
433 for (int i= 0; i < num_curves; i++)
434 aBeziers[i]= geometry::RealBezierSegment2D( r * cos(i*2*M_PI/num_curves), //Px
435 r * sin(i*2*M_PI/num_curves), //py
436 r * 2 * cos((i*2*M_PI + 2*M_PI)/num_curves), //C1x
437 r * 2 * sin((i*2*M_PI + 2*M_PI)/num_curves), //C1y
438 r * 2 * cos((i*2*M_PI + 2*M_PI)/num_curves), //C2x
439 r * 2 * sin((i*2*M_PI + 2*M_PI)/num_curves)); //C2y
440 uno::Sequence< uno::Sequence< geometry::RealBezierSegment2D > > aPolys(1);
441 aPolys[0] = aBeziers;
442 xPoly = mxDevice->createCompatibleBezierPolyPolygon(aPolys);
443 xPoly->setClosed( 0, true );
444 //uno::Reference< rendering::XBezierPolyPolygon2D> xPP( xPoly, uno::UNO_QUERY );
445 //compiles, but totally screws up. I think it is interpretting the bezier as a line
446 uno::Reference< rendering::XPolyPolygon2D> xPP( xPoly, uno::UNO_QUERY );
448 rendering::StrokeAttributes aStrokeAttrs;
449 aStrokeAttrs.StrokeWidth = 4.0;
450 aStrokeAttrs.MiterLimit = 2.0; // ?
451 aStrokeAttrs.StartCapType = rendering::PathCapType::BUTT;
452 aStrokeAttrs.EndCapType = rendering::PathCapType::BUTT;
453 aStrokeAttrs.JoinType = rendering::PathJoinType::MITER;
454 mxCanvas->strokePolyPolygon( xPP, maViewState, maRenderState, aStrokeAttrs );
455 //you can't draw a BezierPolyPolygon2D with this, even though it is derived from it
456 //mxCanvas->drawPolyPolygon( xPP, maViewState, maRenderState );
458 maRenderState = maOldRenderState; // pop
461 double gimmerand()
463 return (double)(rand()) / RAND_MAX * 100 + 50;
466 void drawArcs()
468 rendering::RenderState maOldRenderState = maRenderState; // push
469 translate( 0.0, maBox.Height() * 2.0 );
471 drawTitle( ::rtl::OString( "Arcs" ) );
474 //begin hacks
475 //This stuff doesn't belong here, but probably in curves
476 //This stuff doesn't work in VCL b/c vcl doesn't do beziers
477 //Hah! Everytime the window redraws, we do this
478 double ax;
479 double ay;
480 double bx;
481 double by;
482 bx= gimmerand();
483 by= gimmerand();
485 for (int i= 0; i < 1; i++)
487 //point a= point b;
488 ax= bx;
489 ay= by;
490 //point b= rand;
491 bx= gimmerand();
492 by= gimmerand();
493 double c1x= gimmerand();
494 double c1y= gimmerand();
495 double c2x= gimmerand();
496 double c2y= gimmerand();
497 maRenderState.DeviceColor = maColorRed;
498 mxCanvas->drawLine(geometry::RealPoint2D(ax, ay), geometry::RealPoint2D(c1x, c1y), maViewState, maRenderState);
499 mxCanvas->drawLine(geometry::RealPoint2D(c1x, c1y), geometry::RealPoint2D(c2x, c2y), maViewState, maRenderState);
500 mxCanvas->drawLine(geometry::RealPoint2D(bx, by), geometry::RealPoint2D(c2x, c2y), maViewState, maRenderState);
501 //draw from a to b
502 geometry::RealBezierSegment2D aBezierSegment(
503 ax, //Px
504 ay, //Py
505 c1x,
506 c1x,
507 c2x,
510 geometry::RealPoint2D aEndPoint(bx, by);
511 maRenderState.DeviceColor = maColorBlack;
512 mxCanvas->drawBezier(
513 aBezierSegment,
514 aEndPoint,
515 maViewState, maRenderState );
517 maRenderState = maOldRenderState; // pop
521 void drawRegularPolygon(double centerx, double centery, int sides, double r)
523 //hacky hack hack
524 uno::Sequence< geometry::RealPoint2D > aPoints (sides);
525 uno::Reference< rendering::XLinePolyPolygon2D > xPoly;
527 for (int i= 0; i < sides; i++)
529 aPoints[i]= geometry::RealPoint2D( centerx + r * cos(i*2 * M_PI/sides),
530 centery + r * sin(i*2 * M_PI/sides));
532 uno::Sequence< uno::Sequence< geometry::RealPoint2D > > aPolys(1);
533 aPolys[0] = aPoints;
534 xPoly = mxDevice->createCompatibleLinePolyPolygon( aPolys );
535 xPoly->setClosed( 0, true );
536 rendering::RenderState aRenderState( maRenderState );
537 aRenderState.DeviceColor = maColorRed;
538 uno::Reference< rendering::XPolyPolygon2D> xPP( xPoly, uno::UNO_QUERY );
539 mxCanvas->drawPolyPolygon( xPP, maViewState, aRenderState);
540 mxCanvas->fillPolyPolygon( xPP,
541 maViewState,
542 aRenderState );
545 void drawPolygons()
547 rendering::RenderState maOldRenderState = maRenderState; // push
548 translate( maBox.Width() * 1.0, maBox.Height() * 2.0 );
550 drawTitle( ::rtl::OString( "Polgyons" ) );
552 int sides= 3;
553 for (int i= 1; i <= 4; i++)
555 drawRegularPolygon(35*i, 35, sides, 15);
556 sides++;
559 maRenderState = maOldRenderState; // pop
562 void drawWidgets() // FIXME: prolly makes no sense
564 rendering::RenderState maOldRenderState = maRenderState; // push
565 translate( maBox.Width() * 2.0, maBox.Height() * 2.0 );
567 drawTitle( ::rtl::OString( "Widgets" ) );
569 maRenderState = maOldRenderState; // pop
574 void TestWindow::Paint( const Rectangle& /*rRect*/ )
578 const Size aVDevSize(300,300);
579 VirtualDevice aVDev(*this);
580 aVDev.SetOutputSizePixel(aVDevSize);
581 uno::Reference< rendering::XCanvas > xVDevCanvas( aVDev.GetCanvas(),
582 uno::UNO_QUERY_THROW );
583 uno::Reference< rendering::XGraphicDevice > xVDevDevice( xVDevCanvas->getDevice(),
584 uno::UNO_QUERY_THROW );
585 DemoRenderer aVDevRenderer( xVDevDevice, xVDevCanvas, aVDevSize);
586 xVDevCanvas->clear();
587 aVDevRenderer.drawGrid();
588 aVDevRenderer.drawRectangles();
589 aVDevRenderer.drawEllipses();
590 aVDevRenderer.drawText();
591 aVDevRenderer.drawLines();
592 aVDevRenderer.drawCurves();
593 aVDevRenderer.drawArcs();
594 aVDevRenderer.drawPolygons();
596 uno::Reference< rendering::XCanvas > xCanvas( GetSpriteCanvas(),
597 uno::UNO_QUERY_THROW );
598 uno::Reference< rendering::XGraphicDevice > xDevice( xCanvas->getDevice(),
599 uno::UNO_QUERY_THROW );
601 DemoRenderer aRenderer( xDevice, xCanvas, GetSizePixel() );
602 xCanvas->clear();
603 aRenderer.drawGrid();
604 aRenderer.drawRectangles();
605 aRenderer.drawEllipses();
606 aRenderer.drawText();
607 aRenderer.drawLines();
608 aRenderer.drawCurves();
609 aRenderer.drawArcs();
610 aRenderer.drawPolygons();
611 aRenderer.drawWidgets();
612 aRenderer.drawImages();
614 // check whether virdev actually contained something
615 uno::Reference< rendering::XBitmap > xBitmap(xVDevCanvas, uno::UNO_QUERY);
616 if( !xBitmap.is() )
617 return;
619 aRenderer.maRenderState.AffineTransform.m02 += 100;
620 aRenderer.maRenderState.AffineTransform.m12 += 100;
621 xCanvas->drawBitmap(xBitmap, aRenderer.maViewState, aRenderer.maRenderState);
623 uno::Reference< rendering::XSpriteCanvas > xSpriteCanvas( xCanvas,
624 uno::UNO_QUERY );
625 if( xSpriteCanvas.is() )
626 xSpriteCanvas->updateScreen( sal_True ); // without
627 // updateScreen(),
628 // nothing is
629 // visible
631 catch (const uno::Exception &e)
633 fprintf( stderr, "Exception '%s' thrown\n" ,
634 ::rtl::OUStringToOString( e.Message, RTL_TEXTENCODING_UTF8 ).getStr() );
638 USHORT DemoApp::Exception( USHORT nError )
640 switch( nError & EXC_MAJORTYPE )
642 case EXC_RSCNOTLOADED:
643 Abort( String::CreateFromAscii( "Error: could not load language resources.\nPlease check your installation.\n" ) );
644 break;
646 return 0;
649 void DemoApp::Main()
651 bool bHelp = false;
653 for( USHORT i = 0; i < GetCommandLineParamCount(); i++ )
655 ::rtl::OUString aParam = GetCommandLineParam( i );
657 if( aParam == "--help" || aParam == "-h" )
658 bHelp = true;
661 if( bHelp )
663 PrintHelp();
664 return;
667 //-------------------------------------------------
668 // create the global service-manager
669 //-------------------------------------------------
670 uno::Reference< lang::XMultiServiceFactory > xFactory;
673 uno::Reference< uno::XComponentContext > xCtx = ::cppu::defaultBootstrap_InitialComponentContext();
674 xFactory = uno::Reference< lang::XMultiServiceFactory >( xCtx->getServiceManager(),
675 uno::UNO_QUERY );
676 if( xFactory.is() )
677 ::comphelper::setProcessServiceFactory( xFactory );
679 catch( const uno::Exception& )
683 if( !xFactory.is() )
685 fprintf( stderr, "Could not bootstrap UNO, installation must be in disorder. Exiting.\n" );
686 exit( 1 );
689 // Create UCB.
690 uno::Sequence< uno::Any > aArgs( 2 );
691 aArgs[ 0 ] <<= rtl::OUString(UCB_CONFIGURATION_KEY1_LOCAL );
692 aArgs[ 1 ] <<= rtl::OUString(UCB_CONFIGURATION_KEY2_OFFICE );
693 ::ucbhelper::ContentBroker::initialize( xFactory, aArgs );
695 InitVCL( xFactory );
696 TestWindow pWindow;
697 pWindow.Execute();
698 DeInitVCL();
700 // clean up UCB
701 ::ucbhelper::ContentBroker::deinitialize();
704 DemoApp aDemoApp;
706 // TODO
707 // - bouncing clip-rectangle mode - bounce a clip-rect around the window ...
708 // - complete all of pre-existing canvas bits
709 // - affine transform tweakage ...
711 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */