update dev300-m58
[ooovba.git] / canvas / workben / canvasdemo.cxx
blobc5fffe46881ef2c7639c45a00c2d81e76243bafe
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: canvasdemo.cxx,v $
10 * $Revision: 1.7 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
32 // MARKER(update_precomp.py): autogen include statement, do not remove
33 #include "precompiled_canvas.hxx"
34 // This code strongly inspired by Miguel / Federico's Gnome Canvas demo code.
36 #include <comphelper/processfactory.hxx>
37 #include <comphelper/regpathhelper.hxx>
38 #include <cppuhelper/servicefactory.hxx>
39 #include <cppuhelper/bootstrap.hxx>
40 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
41 #include <com/sun/star/lang/XInitialization.hpp>
42 #include <com/sun/star/registry/XSimpleRegistry.hpp>
44 #include <ucbhelper/contentbroker.hxx>
45 #include <ucbhelper/configurationkeys.hxx>
47 #include <basegfx/polygon/b2dpolygon.hxx>
48 #include <basegfx/polygon/b2dpolygontools.hxx>
49 #include <basegfx/tools/canvastools.hxx>
51 #include <vcl/window.hxx>
52 #include <vcl/virdev.hxx>
53 #include <vcl/svapp.hxx>
54 #include <vcl/msgbox.hxx>
55 #include <vcl/unowrap.hxx>
56 #include <vcl/canvastools.hxx>
58 #include <rtl/bootstrap.hxx>
60 #include <com/sun/star/rendering/XCanvas.hpp>
61 #include <com/sun/star/rendering/FillRule.hpp>
62 #include <com/sun/star/rendering/ViewState.hpp>
63 #include <com/sun/star/rendering/RenderState.hpp>
64 #include <com/sun/star/rendering/PathCapType.hpp>
65 #include <com/sun/star/rendering/PathJoinType.hpp>
66 #include <com/sun/star/rendering/XSpriteCanvas.hpp>
67 #include <com/sun/star/rendering/XGraphicDevice.hpp>
68 #include <com/sun/star/rendering/CompositeOperation.hpp>
69 #include <com/sun/star/rendering/XBitmap.hpp>
71 #include <stdio.h>
72 #include <unistd.h>
75 // never import whole leaf namespaces, since this will result in
76 // absolutely weird effects during (Koenig) name lookup
77 using namespace ::com::sun::star;
80 class DemoApp : public Application
82 public:
83 virtual void Main();
84 virtual USHORT Exception( USHORT nError );
87 static void PrintHelp()
89 fprintf( stdout, "canvasdemo - Exercise the new canvas impl\n" );
92 class TestWindow : public Dialog
94 public:
95 TestWindow() : Dialog( (Window *) NULL )
97 SetText( rtl::OUString::createFromAscii( "Canvas test" ) );
98 SetSizePixel( Size( 600, 450 ) );
99 EnablePaint( true );
100 Show();
102 virtual ~TestWindow() {}
103 virtual void MouseButtonUp( const MouseEvent& /*rMEvt*/ )
105 //TODO: do something cool
106 EndDialog();
108 virtual void Paint( const Rectangle& rRect );
111 class DemoRenderer
113 public:
114 Size maSize;
115 Size maBox;
116 rendering::ViewState maViewState;
117 rendering::RenderState maRenderState;
118 uno::Sequence< double > maColorBlack;
119 uno::Sequence< double > maColorWhite;
120 uno::Sequence< double > maColorRed;
121 uno::Reference< rendering::XCanvas > mxCanvas;
122 uno::Reference< rendering::XCanvasFont > mxDefaultFont;
123 uno::Reference< rendering::XGraphicDevice > mxDevice;
125 DemoRenderer( uno::Reference< rendering::XGraphicDevice > xDevice,
126 uno::Reference< rendering::XCanvas > xCanvas,
127 Size aSize ) :
128 maSize(aSize),
129 maBox(),
130 maViewState(),
131 maRenderState(),
132 maColorBlack( vcl::unotools::colorToStdColorSpaceSequence( Color(COL_BLACK)) ),
133 maColorWhite( vcl::unotools::colorToStdColorSpaceSequence( Color(COL_WHITE)) ),
134 maColorRed( vcl::unotools::colorToStdColorSpaceSequence( Color(COL_RED)) ),
135 mxCanvas(xCanvas),
136 mxDefaultFont(),
137 mxDevice( xDevice )
139 // Geometry init
140 geometry::AffineMatrix2D aUnit( 1,0, 0,
141 0,1, 0 );
142 maViewState.AffineTransform = aUnit;
143 maRenderState.AffineTransform = aUnit;
144 maRenderState.DeviceColor = maColorBlack;
146 //I can't figure out what the compsiteoperation stuff does
147 //it doesn't seem to do anything in either VCL or cairocanvas
148 //I was hoping that CLEAR would clear the canvas before we paint,
149 //but nothing changes
150 maRenderState.CompositeOperation = rendering::CompositeOperation::OVER;
152 maBox.Width() = aSize.Width() / 3;
153 maBox.Height() = aSize.Height() / 3;
155 lang::Locale aLocale;
156 rendering::FontInfo aFontInfo;
157 aFontInfo.FamilyName = ::rtl::OUString::createFromAscii( "Swiss" );
158 aFontInfo.StyleName = ::rtl::OUString::createFromAscii( "SansSerif" );
159 geometry::Matrix2D aFontMatrix( 1, 0,
160 0, 1 );
161 rendering::FontRequest aFontRequest( aFontInfo, 12.0, 0.0, aLocale );
162 uno::Sequence< beans::PropertyValue > aExtraFontProperties;
163 mxDefaultFont = xCanvas->createFont( aFontRequest, aExtraFontProperties, aFontMatrix );
164 if( !mxDefaultFont.is() )
165 fprintf( stderr, "Failed to create font\n" );
168 void drawGrid()
170 double d, dIncr = maSize.Width() / 3;
171 for ( d = 0; d <= maSize.Width(); d += dIncr )
172 mxCanvas->drawLine( geometry::RealPoint2D( d, 0 ),
173 geometry::RealPoint2D( d, maSize.Height() ),
174 maViewState, maRenderState );
175 dIncr = maSize.Height() / 3;
176 for ( d = 0; d <= maSize.Height(); d += dIncr )
177 mxCanvas->drawLine( geometry::RealPoint2D( 0, d ),
178 geometry::RealPoint2D( maSize.Width(), d ),
179 maViewState, maRenderState );
182 void drawStringAt( ::rtl::OString aString, double x, double y )
184 rendering::StringContext aText;
185 aText.Text = ::rtl::OStringToOUString( aString, RTL_TEXTENCODING_UTF8 );
186 aText.StartPosition = 0;
187 aText.Length = aString.getLength();
188 rendering::RenderState aRenderState( maRenderState );
189 aRenderState.AffineTransform.m02 += x;
190 aRenderState.AffineTransform.m12 += y;
192 mxCanvas->drawText( aText, mxDefaultFont, maViewState, aRenderState, 0);
195 void drawRect( Rectangle rRect, uno::Sequence< double > &aColor, int /*nWidth*/ )
197 uno::Sequence< geometry::RealPoint2D > aPoints(4);
198 uno::Reference< rendering::XLinePolyPolygon2D > xPoly;
200 aPoints[0] = geometry::RealPoint2D( rRect.Left(), rRect.Top() );
201 aPoints[1] = geometry::RealPoint2D( rRect.Left(), rRect.Bottom() );
202 aPoints[2] = geometry::RealPoint2D( rRect.Right(), rRect.Bottom() );
203 aPoints[3] = geometry::RealPoint2D( rRect.Right(), rRect.Top() );
205 uno::Sequence< uno::Sequence< geometry::RealPoint2D > > aPolys(1);
206 aPolys[0] = aPoints;
207 xPoly = mxDevice->createCompatibleLinePolyPolygon( aPolys );
208 xPoly->setClosed( 0, true );
209 uno::Reference< rendering::XPolyPolygon2D> xPP( xPoly, uno::UNO_QUERY );
211 rendering::RenderState aRenderState( maRenderState );
212 aRenderState.DeviceColor = aColor;
213 mxCanvas->drawPolyPolygon( xPP, maViewState, aRenderState );
216 void translate( double x, double y)
218 maRenderState.AffineTransform.m02 += x;
219 maRenderState.AffineTransform.m12 += y;
222 void drawPolishDiamond( double center_x, double center_y)
224 const int VERTICES = 10;
225 const double RADIUS = 60.0;
226 int i, j;
227 double a;
229 rendering::RenderState maOldRenderState = maRenderState; // push
230 translate( center_x, center_y );
232 for (i = 0; i < VERTICES; i++)
234 a = 2.0 * M_PI * i / VERTICES;
235 geometry::RealPoint2D aSrc( RADIUS * cos (a), RADIUS * sin (a) );
237 for (j = i + 1; j < VERTICES; j++)
239 a = 2.0 * M_PI * j / VERTICES;
241 // FIXME: set cap_style to 'ROUND'
242 mxCanvas->drawLine( aSrc,
243 geometry::RealPoint2D( RADIUS * cos (a),
244 RADIUS * sin (a) ),
245 maViewState, maRenderState );
249 maRenderState = maOldRenderState; // pop
252 void drawHilbert( double anchor_x, double anchor_y )
254 const double SCALE=7.0;
255 const char hilbert[] = "urdrrulurulldluuruluurdrurddldrrruluurdrurddldrddlulldrdldrrurd";
256 int nLength = sizeof( hilbert ) / sizeof (hilbert [0]);
258 uno::Sequence< geometry::RealPoint2D > aPoints( nLength );
259 uno::Reference< rendering::XLinePolyPolygon2D > xPoly;
261 aPoints[0] = geometry::RealPoint2D( anchor_x, anchor_y );
262 for (int i = 0; i < nLength; i++ )
264 switch( hilbert[i] )
266 case 'u':
267 aPoints[i+1] = geometry::RealPoint2D( aPoints[i].X,
268 aPoints[i].Y - SCALE );
269 break;
270 case 'd':
271 aPoints[i+1] = geometry::RealPoint2D( aPoints[i].X,
272 aPoints[i].Y + SCALE );
273 break;
274 case 'l':
275 aPoints[i+1] = geometry::RealPoint2D( aPoints[i].X - SCALE,
276 aPoints[i].Y );
277 break;
278 case 'r':
279 aPoints[i+1] = geometry::RealPoint2D( aPoints[i].X + SCALE,
280 aPoints[i].Y );
281 break;
285 uno::Sequence< uno::Sequence< geometry::RealPoint2D > > aPolys(1);
286 aPolys[0] = aPoints;
288 xPoly = mxDevice->createCompatibleLinePolyPolygon( aPolys );
289 xPoly->setClosed( 0, false );
290 uno::Reference< rendering::XPolyPolygon2D> xPP( xPoly, uno::UNO_QUERY );
292 rendering::RenderState aRenderState( maRenderState );
293 aRenderState.DeviceColor = maColorRed;
294 // aRenderState.DeviceColor[3] = 0.5;
295 rendering::StrokeAttributes aStrokeAttrs;
296 aStrokeAttrs.StrokeWidth = 4.0;
297 aStrokeAttrs.MiterLimit = 2.0; // ?
298 aStrokeAttrs.StartCapType = rendering::PathCapType::BUTT;
299 aStrokeAttrs.EndCapType = rendering::PathCapType::BUTT;
300 aStrokeAttrs.JoinType = rendering::PathJoinType::MITER;
301 //fprintf( stderr, "FIXME: stroking a PolyPolygon doesn't show up\n" );
302 //yes it does
303 mxCanvas->strokePolyPolygon( xPP, maViewState, aRenderState, aStrokeAttrs );
304 // FIXME: do this instead:
305 //mxCanvas->drawPolyPolygon( xPP, maViewState, aRenderState );
308 void drawTitle( rtl::OString aTitle )
310 // FIXME: text anchoring to be done
311 double nStringWidth = aTitle.getLength() * 8.0;
312 drawStringAt ( aTitle, (maBox.Width() - nStringWidth) / 2, 15 );
315 void drawRectangles()
317 rendering::RenderState maOldRenderState = maRenderState; // push
319 drawTitle( ::rtl::OString( "Rectangles" ) );
321 drawRect( Rectangle( 20, 30, 70, 60 ), maColorRed, 8 );
322 // color mediumseagreen, stipple fill, outline black
323 drawRect( Rectangle( 90, 40, 180, 100 ), maColorBlack, 4 );
324 // color steelblue, filled, no outline
325 drawRect( Rectangle( 10, 80, 80, 140 ), maColorBlack, 1 );
327 maRenderState = maOldRenderState; // pop
330 void drawEllipses()
332 rendering::RenderState maOldRenderState = maRenderState; // push
333 translate( maBox.Width(), 0.0 );
335 drawTitle( ::rtl::OString( "Ellipses" ) );
337 const basegfx::B2DPoint aCenter( maBox.Width()*.5,
338 maBox.Height()*.5 );
339 const basegfx::B2DPoint aRadii( maBox.Width()*.3,
340 maBox.Height()*.3 );
341 const basegfx::B2DPolygon& rEllipse(
342 basegfx::tools::createPolygonFromEllipse( aCenter,
343 aRadii.getX(),
344 aRadii.getY() ));
346 uno::Reference< rendering::XPolyPolygon2D > xPoly(
347 basegfx::unotools::xPolyPolygonFromB2DPolygon(mxDevice,
348 rEllipse) );
350 rendering::StrokeAttributes aStrokeAttrs;
351 aStrokeAttrs.StrokeWidth = 4.0;
352 aStrokeAttrs.MiterLimit = 2.0; // ?
353 aStrokeAttrs.StartCapType = rendering::PathCapType::BUTT;
354 aStrokeAttrs.EndCapType = rendering::PathCapType::BUTT;
355 aStrokeAttrs.JoinType = rendering::PathJoinType::MITER;
356 mxCanvas->strokePolyPolygon( xPoly, maViewState, maRenderState, aStrokeAttrs );
358 maRenderState = maOldRenderState; // pop
361 void drawText()
363 rendering::RenderState maOldRenderState = maRenderState; // push
364 translate( maBox.Width() * 2.0, 0.0 );
366 drawTitle( ::rtl::OString( "Text" ) );
368 translate( 0.0,
369 maBox.Height() * .5 );
370 drawTitle( ::rtl::OString( "This is lame" ) );
372 maRenderState = maOldRenderState; // pop
375 void drawImages()
377 rendering::RenderState maOldRenderState = maRenderState; // push
378 translate( 0.0, maBox.Height() );
380 drawTitle( ::rtl::OString( "Images" ) );
382 uno::Reference< rendering::XBitmap > xBitmap(mxCanvas, uno::UNO_QUERY);
384 if( !xBitmap.is() )
385 return;
387 translate( maBox.Width()*0.1, maBox.Height()*0.2 );
388 maRenderState.AffineTransform.m00 *= 4.0/15;
389 maRenderState.AffineTransform.m11 *= 3.0/15;
391 mxCanvas->drawBitmap(xBitmap, maViewState, maRenderState);
393 // uno::Reference< rendering::XBitmap > xBitmap2( xBitmap->getScaledBitmap(geometry::RealSize2D(48, 48), false) );
394 // mxCanvas->drawBitmap(xBitmap2, maViewState, maRenderState); //yes, but where?
395 //cairo-canvas says:
396 //called CanvasHelper::getScaledBitmap, we return NULL, TODO
397 //Exception 'BitmapEx vclcanvas::tools::bitmapExFromXBitmap(const com::sun::star::uno::Reference<com::sun::star::rendering::XBitmap>&),
398 //bitmapExFromXBitmap(): could not extract BitmapEx' thrown
400 //vcl-canvas says:
401 //Exception 'BitmapEx vclcanvas::tools::bitmapExFromXBitmap(const com::sun::star::uno::Reference<com::sun::star::rendering::XBitmap>&),
402 //bitmapExFromXBitmap(): could not extract bitmap' thrown
403 // Thorsten says that this is a bug, and Thorsten never lies.
405 maRenderState = maOldRenderState; // pop
408 void drawLines()
410 rendering::RenderState maOldRenderState = maRenderState; // push
411 translate( maBox.Width(), maBox.Height() );
413 drawTitle( ::rtl::OString( "Lines" ) );
415 drawPolishDiamond( 70.0, 80.0 );
416 drawHilbert( 140.0, 140.0 );
418 maRenderState = maOldRenderState; // pop
421 void drawCurves()
423 rendering::RenderState maOldRenderState = maRenderState; // push
424 translate( maBox.Width() * 2.0, maBox.Height() );
426 drawTitle( ::rtl::OString( "Curves" ) );
428 translate( maBox.Width() * .5, maBox.Height() * .5 );
430 const double r= 30.0;
431 const int num_curves = 3;
433 //hacky hack hack
434 uno::Sequence< geometry::RealBezierSegment2D > aBeziers (num_curves);
435 uno::Reference< rendering::XBezierPolyPolygon2D > xPoly;
437 for (int i= 0; i < num_curves; i++)
438 aBeziers[i]= geometry::RealBezierSegment2D( r * cos(i*2*M_PI/num_curves), //Px
439 r * sin(i*2*M_PI/num_curves), //py
440 r * 2 * cos((i*2*M_PI + 2*M_PI)/num_curves), //C1x
441 r * 2 * sin((i*2*M_PI + 2*M_PI)/num_curves), //C1y
442 r * 2 * cos((i*2*M_PI + 2*M_PI)/num_curves), //C2x
443 r * 2 * sin((i*2*M_PI + 2*M_PI)/num_curves)); //C2y
444 uno::Sequence< uno::Sequence< geometry::RealBezierSegment2D > > aPolys(1);
445 aPolys[0] = aBeziers;
446 xPoly = mxDevice->createCompatibleBezierPolyPolygon(aPolys);
447 xPoly->setClosed( 0, true );
448 //uno::Reference< rendering::XBezierPolyPolygon2D> xPP( xPoly, uno::UNO_QUERY );
449 //compiles, but totally screws up. I think it is interpretting the bezier as a line
450 uno::Reference< rendering::XPolyPolygon2D> xPP( xPoly, uno::UNO_QUERY );
452 rendering::StrokeAttributes aStrokeAttrs;
453 aStrokeAttrs.StrokeWidth = 4.0;
454 aStrokeAttrs.MiterLimit = 2.0; // ?
455 aStrokeAttrs.StartCapType = rendering::PathCapType::BUTT;
456 aStrokeAttrs.EndCapType = rendering::PathCapType::BUTT;
457 aStrokeAttrs.JoinType = rendering::PathJoinType::MITER;
458 mxCanvas->strokePolyPolygon( xPP, maViewState, maRenderState, aStrokeAttrs );
459 //you can't draw a BezierPolyPolygon2D with this, even though it is derived from it
460 //mxCanvas->drawPolyPolygon( xPP, maViewState, maRenderState );
462 maRenderState = maOldRenderState; // pop
465 double gimmerand()
467 return (double)(rand()) / RAND_MAX * 100 + 50;
470 void drawArcs()
472 rendering::RenderState maOldRenderState = maRenderState; // push
473 translate( 0.0, maBox.Height() * 2.0 );
475 drawTitle( ::rtl::OString( "Arcs" ) );
478 //begin hacks
479 //This stuff doesn't belong here, but probably in curves
480 //This stuff doesn't work in VCL b/c vcl doesn't do beziers
481 //Hah! Everytime the window redraws, we do this
482 double ax;
483 double ay;
484 double bx;
485 double by;
486 bx= gimmerand();
487 by= gimmerand();
489 for (int i= 0; i < 1; i++)
491 //point a= point b;
492 ax= bx;
493 ay= by;
494 //point b= rand;
495 bx= gimmerand();
496 by= gimmerand();
497 double c1x= gimmerand();
498 double c1y= gimmerand();
499 double c2x= gimmerand();
500 double c2y= gimmerand();
501 maRenderState.DeviceColor = maColorRed;
502 mxCanvas->drawLine(geometry::RealPoint2D(ax, ay), geometry::RealPoint2D(c1x, c1y), maViewState, maRenderState);
503 mxCanvas->drawLine(geometry::RealPoint2D(c1x, c1y), geometry::RealPoint2D(c2x, c2y), maViewState, maRenderState);
504 mxCanvas->drawLine(geometry::RealPoint2D(bx, by), geometry::RealPoint2D(c2x, c2y), maViewState, maRenderState);
505 //draw from a to b
506 geometry::RealBezierSegment2D aBezierSegment(
507 ax, //Px
508 ay, //Py
509 c1x,
510 c1x,
511 c2x,
514 geometry::RealPoint2D aEndPoint(bx, by);
515 maRenderState.DeviceColor = maColorBlack;
516 mxCanvas->drawBezier(
517 aBezierSegment,
518 aEndPoint,
519 maViewState, maRenderState );
521 maRenderState = maOldRenderState; // pop
525 void drawRegularPolygon(double centerx, double centery, int sides, double r)
527 //hacky hack hack
528 uno::Sequence< geometry::RealPoint2D > aPoints (sides);
529 uno::Reference< rendering::XLinePolyPolygon2D > xPoly;
531 for (int i= 0; i < sides; i++)
533 aPoints[i]= geometry::RealPoint2D( centerx + r * cos(i*2 * M_PI/sides),
534 centery + r * sin(i*2 * M_PI/sides));
536 uno::Sequence< uno::Sequence< geometry::RealPoint2D > > aPolys(1);
537 aPolys[0] = aPoints;
538 xPoly = mxDevice->createCompatibleLinePolyPolygon( aPolys );
539 xPoly->setClosed( 0, true );
540 rendering::RenderState aRenderState( maRenderState );
541 aRenderState.DeviceColor = maColorRed;
542 uno::Reference< rendering::XPolyPolygon2D> xPP( xPoly, uno::UNO_QUERY );
543 mxCanvas->drawPolyPolygon( xPP, maViewState, aRenderState);
544 mxCanvas->fillPolyPolygon( xPP,
545 maViewState,
546 aRenderState );
549 void drawPolygons()
551 rendering::RenderState maOldRenderState = maRenderState; // push
552 translate( maBox.Width() * 1.0, maBox.Height() * 2.0 );
554 drawTitle( ::rtl::OString( "Polgyons" ) );
556 int sides= 3;
557 for (int i= 1; i <= 4; i++)
559 drawRegularPolygon(35*i, 35, sides, 15);
560 sides++;
563 maRenderState = maOldRenderState; // pop
566 void drawWidgets() // FIXME: prolly makes no sense
568 rendering::RenderState maOldRenderState = maRenderState; // push
569 translate( maBox.Width() * 2.0, maBox.Height() * 2.0 );
571 drawTitle( ::rtl::OString( "Widgets" ) );
573 maRenderState = maOldRenderState; // pop
578 void TestWindow::Paint( const Rectangle& /*rRect*/ )
582 const Size aVDevSize(300,300);
583 VirtualDevice aVDev(*this);
584 aVDev.SetOutputSizePixel(aVDevSize);
585 uno::Reference< rendering::XCanvas > xVDevCanvas( aVDev.GetCanvas(),
586 uno::UNO_QUERY_THROW );
587 uno::Reference< rendering::XGraphicDevice > xVDevDevice( xVDevCanvas->getDevice(),
588 uno::UNO_QUERY_THROW );
589 DemoRenderer aVDevRenderer( xVDevDevice, xVDevCanvas, aVDevSize);
590 xVDevCanvas->clear();
591 aVDevRenderer.drawGrid();
592 aVDevRenderer.drawRectangles();
593 aVDevRenderer.drawEllipses();
594 aVDevRenderer.drawText();
595 aVDevRenderer.drawLines();
596 aVDevRenderer.drawCurves();
597 aVDevRenderer.drawArcs();
598 aVDevRenderer.drawPolygons();
600 uno::Reference< rendering::XCanvas > xCanvas( GetSpriteCanvas(),
601 uno::UNO_QUERY_THROW );
602 uno::Reference< rendering::XGraphicDevice > xDevice( xCanvas->getDevice(),
603 uno::UNO_QUERY_THROW );
605 DemoRenderer aRenderer( xDevice, xCanvas, GetSizePixel() );
606 xCanvas->clear();
607 aRenderer.drawGrid();
608 aRenderer.drawRectangles();
609 aRenderer.drawEllipses();
610 aRenderer.drawText();
611 aRenderer.drawLines();
612 aRenderer.drawCurves();
613 aRenderer.drawArcs();
614 aRenderer.drawPolygons();
615 aRenderer.drawWidgets();
616 aRenderer.drawImages();
618 // check whether virdev actually contained something
619 uno::Reference< rendering::XBitmap > xBitmap(xVDevCanvas, uno::UNO_QUERY);
620 if( !xBitmap.is() )
621 return;
623 aRenderer.maRenderState.AffineTransform.m02 += 100;
624 aRenderer.maRenderState.AffineTransform.m12 += 100;
625 xCanvas->drawBitmap(xBitmap, aRenderer.maViewState, aRenderer.maRenderState);
627 uno::Reference< rendering::XSpriteCanvas > xSpriteCanvas( xCanvas,
628 uno::UNO_QUERY );
629 if( xSpriteCanvas.is() )
630 xSpriteCanvas->updateScreen( sal_True ); // without
631 // updateScreen(),
632 // nothing is
633 // visible
635 catch (const uno::Exception &e)
637 fprintf( stderr, "Exception '%s' thrown\n" ,
638 (const sal_Char *) ::rtl::OUStringToOString( e.Message, RTL_TEXTENCODING_UTF8 ) );
642 USHORT DemoApp::Exception( USHORT nError )
644 switch( nError & EXC_MAJORTYPE )
646 case EXC_RSCNOTLOADED:
647 Abort( String::CreateFromAscii( "Error: could not load language resources.\nPlease check your installation.\n" ) );
648 break;
650 return 0;
653 void DemoApp::Main()
655 bool bHelp = false;
657 for( USHORT i = 0; i < GetCommandLineParamCount(); i++ )
659 ::rtl::OUString aParam = GetCommandLineParam( i );
661 if( aParam.equalsAscii( "--help" ) ||
662 aParam.equalsAscii( "-h" ) )
663 bHelp = true;
666 if( bHelp )
668 PrintHelp();
669 return;
672 //-------------------------------------------------
673 // create the global service-manager
674 //-------------------------------------------------
675 uno::Reference< lang::XMultiServiceFactory > xFactory;
678 uno::Reference< uno::XComponentContext > xCtx = ::cppu::defaultBootstrap_InitialComponentContext();
679 xFactory = uno::Reference< lang::XMultiServiceFactory >( xCtx->getServiceManager(),
680 uno::UNO_QUERY );
681 if( xFactory.is() )
682 ::comphelper::setProcessServiceFactory( xFactory );
684 catch( uno::Exception& )
688 if( !xFactory.is() )
690 fprintf( stderr, "Could not bootstrap UNO, installation must be in disorder. Exiting.\n" );
691 exit( 1 );
694 // Create UCB.
695 uno::Sequence< uno::Any > aArgs( 2 );
696 aArgs[ 0 ] <<= rtl::OUString::createFromAscii( UCB_CONFIGURATION_KEY1_LOCAL );
697 aArgs[ 1 ] <<= rtl::OUString::createFromAscii( UCB_CONFIGURATION_KEY2_OFFICE );
698 ::ucbhelper::ContentBroker::initialize( xFactory, aArgs );
700 InitVCL( xFactory );
701 TestWindow pWindow;
702 pWindow.Execute();
703 DeInitVCL();
705 // clean up UCB
706 ::ucbhelper::ContentBroker::deinitialize();
709 DemoApp aDemoApp;
711 // TODO
712 // - bouncing clip-rectangle mode - bounce a clip-rect around the window ...
713 // - complete all of pre-existing canvas bits
714 // - affine transform tweakage ...