Missing #endif
[LibreOffice.git] / canvas / workben / canvasdemo.cxx
blob63a5652a9eecfaa83b8e1468fa95748f34697afd
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 // MARKER(update_precomp.py): autogen include statement, do not remove
31 #include "precompiled_canvas.hxx"
32 // This code strongly inspired by Miguel / Federico's Gnome Canvas demo code.
34 #include <comphelper/processfactory.hxx>
35 #include <comphelper/regpathhelper.hxx>
36 #include <cppuhelper/servicefactory.hxx>
37 #include <cppuhelper/bootstrap.hxx>
38 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
39 #include <com/sun/star/lang/XInitialization.hpp>
40 #include <com/sun/star/registry/XSimpleRegistry.hpp>
42 #include <ucbhelper/contentbroker.hxx>
43 #include <ucbhelper/configurationkeys.hxx>
45 #include <basegfx/polygon/b2dpolygon.hxx>
46 #include <basegfx/polygon/b2dpolygontools.hxx>
47 #include <basegfx/tools/canvastools.hxx>
49 #include <vcl/window.hxx>
50 #include <vcl/virdev.hxx>
51 #include <vcl/svapp.hxx>
52 #include <vcl/msgbox.hxx>
53 #include <vcl/unowrap.hxx>
54 #include <vcl/canvastools.hxx>
56 #include <rtl/bootstrap.hxx>
57 #include <sal/macros.h>
59 #include <com/sun/star/rendering/XCanvas.hpp>
60 #include <com/sun/star/rendering/FillRule.hpp>
61 #include <com/sun/star/rendering/ViewState.hpp>
62 #include <com/sun/star/rendering/RenderState.hpp>
63 #include <com/sun/star/rendering/PathCapType.hpp>
64 #include <com/sun/star/rendering/PathJoinType.hpp>
65 #include <com/sun/star/rendering/XSpriteCanvas.hpp>
66 #include <com/sun/star/rendering/XGraphicDevice.hpp>
67 #include <com/sun/star/rendering/CompositeOperation.hpp>
68 #include <com/sun/star/rendering/XBitmap.hpp>
70 #include <stdio.h>
71 #include <unistd.h>
74 // never import whole leaf namespaces, since this will result in
75 // absolutely weird effects during (Koenig) name lookup
76 using namespace ::com::sun::star;
79 class DemoApp : public Application
81 public:
82 virtual void Main();
83 virtual USHORT Exception( USHORT nError );
86 static void PrintHelp()
88 fprintf( stdout, "canvasdemo - Exercise the new canvas impl\n" );
91 class TestWindow : public Dialog
93 public:
94 TestWindow() : Dialog( (Window *) NULL )
96 SetText( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Canvas test" )) );
97 SetSizePixel( Size( 600, 450 ) );
98 EnablePaint( true );
99 Show();
101 virtual ~TestWindow() {}
102 virtual void MouseButtonUp( const MouseEvent& /*rMEvt*/ )
104 //TODO: do something cool
105 EndDialog();
107 virtual void Paint( const Rectangle& rRect );
110 class DemoRenderer
112 public:
113 Size maSize;
114 Size maBox;
115 rendering::ViewState maViewState;
116 rendering::RenderState maRenderState;
117 uno::Sequence< double > maColorBlack;
118 uno::Sequence< double > maColorWhite;
119 uno::Sequence< double > maColorRed;
120 uno::Reference< rendering::XCanvas > mxCanvas;
121 uno::Reference< rendering::XCanvasFont > mxDefaultFont;
122 uno::Reference< rendering::XGraphicDevice > mxDevice;
124 DemoRenderer( uno::Reference< rendering::XGraphicDevice > xDevice,
125 uno::Reference< rendering::XCanvas > xCanvas,
126 Size aSize ) :
127 maSize(aSize),
128 maBox(),
129 maViewState(),
130 maRenderState(),
131 maColorBlack( vcl::unotools::colorToStdColorSpaceSequence( Color(COL_BLACK)) ),
132 maColorWhite( vcl::unotools::colorToStdColorSpaceSequence( Color(COL_WHITE)) ),
133 maColorRed( vcl::unotools::colorToStdColorSpaceSequence( Color(COL_RED)) ),
134 mxCanvas(xCanvas),
135 mxDefaultFont(),
136 mxDevice( xDevice )
138 // Geometry init
139 geometry::AffineMatrix2D aUnit( 1,0, 0,
140 0,1, 0 );
141 maViewState.AffineTransform = aUnit;
142 maRenderState.AffineTransform = aUnit;
143 maRenderState.DeviceColor = maColorBlack;
145 //I can't figure out what the compsiteoperation stuff does
146 //it doesn't seem to do anything in either VCL or cairocanvas
147 //I was hoping that CLEAR would clear the canvas before we paint,
148 //but nothing changes
149 maRenderState.CompositeOperation = rendering::CompositeOperation::OVER;
151 maBox.Width() = aSize.Width() / 3;
152 maBox.Height() = aSize.Height() / 3;
154 lang::Locale aLocale;
155 rendering::FontInfo aFontInfo;
156 aFontInfo.FamilyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Swiss" ));
157 aFontInfo.StyleName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "SansSerif" ));
158 geometry::Matrix2D aFontMatrix( 1, 0,
159 0, 1 );
160 rendering::FontRequest aFontRequest( aFontInfo, 12.0, 0.0, aLocale );
161 uno::Sequence< beans::PropertyValue > aExtraFontProperties;
162 mxDefaultFont = xCanvas->createFont( aFontRequest, aExtraFontProperties, aFontMatrix );
163 if( !mxDefaultFont.is() )
164 fprintf( stderr, "Failed to create font\n" );
167 void drawGrid()
169 double d, dIncr = maSize.Width() / 3;
170 for ( d = 0; d <= maSize.Width(); d += dIncr )
171 mxCanvas->drawLine( geometry::RealPoint2D( d, 0 ),
172 geometry::RealPoint2D( d, maSize.Height() ),
173 maViewState, maRenderState );
174 dIncr = maSize.Height() / 3;
175 for ( d = 0; d <= maSize.Height(); d += dIncr )
176 mxCanvas->drawLine( geometry::RealPoint2D( 0, d ),
177 geometry::RealPoint2D( maSize.Width(), d ),
178 maViewState, maRenderState );
181 void drawStringAt( ::rtl::OString aString, double x, double y )
183 rendering::StringContext aText;
184 aText.Text = ::rtl::OStringToOUString( aString, RTL_TEXTENCODING_UTF8 );
185 aText.StartPosition = 0;
186 aText.Length = aString.getLength();
187 rendering::RenderState aRenderState( maRenderState );
188 aRenderState.AffineTransform.m02 += x;
189 aRenderState.AffineTransform.m12 += y;
191 mxCanvas->drawText( aText, mxDefaultFont, maViewState, aRenderState, 0);
194 void drawRect( Rectangle rRect, uno::Sequence< double > &aColor, int /*nWidth*/ )
196 uno::Sequence< geometry::RealPoint2D > aPoints(4);
197 uno::Reference< rendering::XLinePolyPolygon2D > xPoly;
199 aPoints[0] = geometry::RealPoint2D( rRect.Left(), rRect.Top() );
200 aPoints[1] = geometry::RealPoint2D( rRect.Left(), rRect.Bottom() );
201 aPoints[2] = geometry::RealPoint2D( rRect.Right(), rRect.Bottom() );
202 aPoints[3] = geometry::RealPoint2D( rRect.Right(), rRect.Top() );
204 uno::Sequence< uno::Sequence< geometry::RealPoint2D > > aPolys(1);
205 aPolys[0] = aPoints;
206 xPoly = mxDevice->createCompatibleLinePolyPolygon( aPolys );
207 xPoly->setClosed( 0, true );
208 uno::Reference< rendering::XPolyPolygon2D> xPP( xPoly, uno::UNO_QUERY );
210 rendering::RenderState aRenderState( maRenderState );
211 aRenderState.DeviceColor = aColor;
212 mxCanvas->drawPolyPolygon( xPP, maViewState, aRenderState );
215 void translate( double x, double y)
217 maRenderState.AffineTransform.m02 += x;
218 maRenderState.AffineTransform.m12 += y;
221 void drawPolishDiamond( double center_x, double center_y)
223 const int VERTICES = 10;
224 const double RADIUS = 60.0;
225 int i, j;
226 double a;
228 rendering::RenderState maOldRenderState = maRenderState; // push
229 translate( center_x, center_y );
231 for (i = 0; i < VERTICES; i++)
233 a = 2.0 * M_PI * i / VERTICES;
234 geometry::RealPoint2D aSrc( RADIUS * cos (a), RADIUS * sin (a) );
236 for (j = i + 1; j < VERTICES; j++)
238 a = 2.0 * M_PI * j / VERTICES;
240 // FIXME: set cap_style to 'ROUND'
241 mxCanvas->drawLine( aSrc,
242 geometry::RealPoint2D( RADIUS * cos (a),
243 RADIUS * sin (a) ),
244 maViewState, maRenderState );
248 maRenderState = maOldRenderState; // pop
251 void drawHilbert( double anchor_x, double anchor_y )
253 const double SCALE=7.0;
254 const char hilbert[] = "urdrrulurulldluuruluurdrurddldrrruluurdrurddldrddlulldrdldrrurd";
255 int nLength = SAL_N_ELEMENTS( hilbert );
257 uno::Sequence< geometry::RealPoint2D > aPoints( nLength );
258 uno::Reference< rendering::XLinePolyPolygon2D > xPoly;
260 aPoints[0] = geometry::RealPoint2D( anchor_x, anchor_y );
261 for (int i = 0; i < nLength; i++ )
263 switch( hilbert[i] )
265 case 'u':
266 aPoints[i+1] = geometry::RealPoint2D( aPoints[i].X,
267 aPoints[i].Y - SCALE );
268 break;
269 case 'd':
270 aPoints[i+1] = geometry::RealPoint2D( aPoints[i].X,
271 aPoints[i].Y + SCALE );
272 break;
273 case 'l':
274 aPoints[i+1] = geometry::RealPoint2D( aPoints[i].X - SCALE,
275 aPoints[i].Y );
276 break;
277 case 'r':
278 aPoints[i+1] = geometry::RealPoint2D( aPoints[i].X + SCALE,
279 aPoints[i].Y );
280 break;
284 uno::Sequence< uno::Sequence< geometry::RealPoint2D > > aPolys(1);
285 aPolys[0] = aPoints;
287 xPoly = mxDevice->createCompatibleLinePolyPolygon( aPolys );
288 xPoly->setClosed( 0, false );
289 uno::Reference< rendering::XPolyPolygon2D> xPP( xPoly, uno::UNO_QUERY );
291 rendering::RenderState aRenderState( maRenderState );
292 aRenderState.DeviceColor = maColorRed;
293 // aRenderState.DeviceColor[3] = 0.5;
294 rendering::StrokeAttributes aStrokeAttrs;
295 aStrokeAttrs.StrokeWidth = 4.0;
296 aStrokeAttrs.MiterLimit = 2.0; // ?
297 aStrokeAttrs.StartCapType = rendering::PathCapType::BUTT;
298 aStrokeAttrs.EndCapType = rendering::PathCapType::BUTT;
299 aStrokeAttrs.JoinType = rendering::PathJoinType::MITER;
300 //fprintf( stderr, "FIXME: stroking a PolyPolygon doesn't show up\n" );
301 //yes it does
302 mxCanvas->strokePolyPolygon( xPP, maViewState, aRenderState, aStrokeAttrs );
303 // FIXME: do this instead:
304 //mxCanvas->drawPolyPolygon( xPP, maViewState, aRenderState );
307 void drawTitle( rtl::OString aTitle )
309 // FIXME: text anchoring to be done
310 double nStringWidth = aTitle.getLength() * 8.0;
311 drawStringAt ( aTitle, (maBox.Width() - nStringWidth) / 2, 15 );
314 void drawRectangles()
316 rendering::RenderState maOldRenderState = maRenderState; // push
318 drawTitle( ::rtl::OString( "Rectangles" ) );
320 drawRect( Rectangle( 20, 30, 70, 60 ), maColorRed, 8 );
321 // color mediumseagreen, stipple fill, outline black
322 drawRect( Rectangle( 90, 40, 180, 100 ), maColorBlack, 4 );
323 // color steelblue, filled, no outline
324 drawRect( Rectangle( 10, 80, 80, 140 ), maColorBlack, 1 );
326 maRenderState = maOldRenderState; // pop
329 void drawEllipses()
331 rendering::RenderState maOldRenderState = maRenderState; // push
332 translate( maBox.Width(), 0.0 );
334 drawTitle( ::rtl::OString( "Ellipses" ) );
336 const basegfx::B2DPoint aCenter( maBox.Width()*.5,
337 maBox.Height()*.5 );
338 const basegfx::B2DPoint aRadii( maBox.Width()*.3,
339 maBox.Height()*.3 );
340 const basegfx::B2DPolygon& rEllipse(
341 basegfx::tools::createPolygonFromEllipse( aCenter,
342 aRadii.getX(),
343 aRadii.getY() ));
345 uno::Reference< rendering::XPolyPolygon2D > xPoly(
346 basegfx::unotools::xPolyPolygonFromB2DPolygon(mxDevice,
347 rEllipse) );
349 rendering::StrokeAttributes aStrokeAttrs;
350 aStrokeAttrs.StrokeWidth = 4.0;
351 aStrokeAttrs.MiterLimit = 2.0; // ?
352 aStrokeAttrs.StartCapType = rendering::PathCapType::BUTT;
353 aStrokeAttrs.EndCapType = rendering::PathCapType::BUTT;
354 aStrokeAttrs.JoinType = rendering::PathJoinType::MITER;
355 mxCanvas->strokePolyPolygon( xPoly, maViewState, maRenderState, aStrokeAttrs );
357 maRenderState = maOldRenderState; // pop
360 void drawText()
362 rendering::RenderState maOldRenderState = maRenderState; // push
363 translate( maBox.Width() * 2.0, 0.0 );
365 drawTitle( ::rtl::OString( "Text" ) );
367 translate( 0.0,
368 maBox.Height() * .5 );
369 drawTitle( ::rtl::OString( "This is lame" ) );
371 maRenderState = maOldRenderState; // pop
374 void drawImages()
376 rendering::RenderState maOldRenderState = maRenderState; // push
377 translate( 0.0, maBox.Height() );
379 drawTitle( ::rtl::OString( "Images" ) );
381 uno::Reference< rendering::XBitmap > xBitmap(mxCanvas, uno::UNO_QUERY);
383 if( !xBitmap.is() )
384 return;
386 translate( maBox.Width()*0.1, maBox.Height()*0.2 );
387 maRenderState.AffineTransform.m00 *= 4.0/15;
388 maRenderState.AffineTransform.m11 *= 3.0/15;
390 mxCanvas->drawBitmap(xBitmap, maViewState, maRenderState);
392 // uno::Reference< rendering::XBitmap > xBitmap2( xBitmap->getScaledBitmap(geometry::RealSize2D(48, 48), false) );
393 // mxCanvas->drawBitmap(xBitmap2, maViewState, maRenderState); //yes, but where?
394 //cairo-canvas says:
395 //called CanvasHelper::getScaledBitmap, we return NULL, TODO
396 //Exception 'BitmapEx vclcanvas::tools::bitmapExFromXBitmap(const com::sun::star::uno::Reference<com::sun::star::rendering::XBitmap>&),
397 //bitmapExFromXBitmap(): could not extract BitmapEx' thrown
399 //vcl-canvas says:
400 //Exception 'BitmapEx vclcanvas::tools::bitmapExFromXBitmap(const com::sun::star::uno::Reference<com::sun::star::rendering::XBitmap>&),
401 //bitmapExFromXBitmap(): could not extract bitmap' thrown
402 // Thorsten says that this is a bug, and Thorsten never lies.
404 maRenderState = maOldRenderState; // pop
407 void drawLines()
409 rendering::RenderState maOldRenderState = maRenderState; // push
410 translate( maBox.Width(), maBox.Height() );
412 drawTitle( ::rtl::OString( "Lines" ) );
414 drawPolishDiamond( 70.0, 80.0 );
415 drawHilbert( 140.0, 140.0 );
417 maRenderState = maOldRenderState; // pop
420 void drawCurves()
422 rendering::RenderState maOldRenderState = maRenderState; // push
423 translate( maBox.Width() * 2.0, maBox.Height() );
425 drawTitle( ::rtl::OString( "Curves" ) );
427 translate( maBox.Width() * .5, maBox.Height() * .5 );
429 const double r= 30.0;
430 const int num_curves = 3;
432 //hacky hack hack
433 uno::Sequence< geometry::RealBezierSegment2D > aBeziers (num_curves);
434 uno::Reference< rendering::XBezierPolyPolygon2D > xPoly;
436 for (int i= 0; i < num_curves; i++)
437 aBeziers[i]= geometry::RealBezierSegment2D( r * cos(i*2*M_PI/num_curves), //Px
438 r * sin(i*2*M_PI/num_curves), //py
439 r * 2 * cos((i*2*M_PI + 2*M_PI)/num_curves), //C1x
440 r * 2 * sin((i*2*M_PI + 2*M_PI)/num_curves), //C1y
441 r * 2 * cos((i*2*M_PI + 2*M_PI)/num_curves), //C2x
442 r * 2 * sin((i*2*M_PI + 2*M_PI)/num_curves)); //C2y
443 uno::Sequence< uno::Sequence< geometry::RealBezierSegment2D > > aPolys(1);
444 aPolys[0] = aBeziers;
445 xPoly = mxDevice->createCompatibleBezierPolyPolygon(aPolys);
446 xPoly->setClosed( 0, true );
447 //uno::Reference< rendering::XBezierPolyPolygon2D> xPP( xPoly, uno::UNO_QUERY );
448 //compiles, but totally screws up. I think it is interpretting the bezier as a line
449 uno::Reference< rendering::XPolyPolygon2D> xPP( xPoly, uno::UNO_QUERY );
451 rendering::StrokeAttributes aStrokeAttrs;
452 aStrokeAttrs.StrokeWidth = 4.0;
453 aStrokeAttrs.MiterLimit = 2.0; // ?
454 aStrokeAttrs.StartCapType = rendering::PathCapType::BUTT;
455 aStrokeAttrs.EndCapType = rendering::PathCapType::BUTT;
456 aStrokeAttrs.JoinType = rendering::PathJoinType::MITER;
457 mxCanvas->strokePolyPolygon( xPP, maViewState, maRenderState, aStrokeAttrs );
458 //you can't draw a BezierPolyPolygon2D with this, even though it is derived from it
459 //mxCanvas->drawPolyPolygon( xPP, maViewState, maRenderState );
461 maRenderState = maOldRenderState; // pop
464 double gimmerand()
466 return (double)(rand()) / RAND_MAX * 100 + 50;
469 void drawArcs()
471 rendering::RenderState maOldRenderState = maRenderState; // push
472 translate( 0.0, maBox.Height() * 2.0 );
474 drawTitle( ::rtl::OString( "Arcs" ) );
477 //begin hacks
478 //This stuff doesn't belong here, but probably in curves
479 //This stuff doesn't work in VCL b/c vcl doesn't do beziers
480 //Hah! Everytime the window redraws, we do this
481 double ax;
482 double ay;
483 double bx;
484 double by;
485 bx= gimmerand();
486 by= gimmerand();
488 for (int i= 0; i < 1; i++)
490 //point a= point b;
491 ax= bx;
492 ay= by;
493 //point b= rand;
494 bx= gimmerand();
495 by= gimmerand();
496 double c1x= gimmerand();
497 double c1y= gimmerand();
498 double c2x= gimmerand();
499 double c2y= gimmerand();
500 maRenderState.DeviceColor = maColorRed;
501 mxCanvas->drawLine(geometry::RealPoint2D(ax, ay), geometry::RealPoint2D(c1x, c1y), maViewState, maRenderState);
502 mxCanvas->drawLine(geometry::RealPoint2D(c1x, c1y), geometry::RealPoint2D(c2x, c2y), maViewState, maRenderState);
503 mxCanvas->drawLine(geometry::RealPoint2D(bx, by), geometry::RealPoint2D(c2x, c2y), maViewState, maRenderState);
504 //draw from a to b
505 geometry::RealBezierSegment2D aBezierSegment(
506 ax, //Px
507 ay, //Py
508 c1x,
509 c1x,
510 c2x,
513 geometry::RealPoint2D aEndPoint(bx, by);
514 maRenderState.DeviceColor = maColorBlack;
515 mxCanvas->drawBezier(
516 aBezierSegment,
517 aEndPoint,
518 maViewState, maRenderState );
520 maRenderState = maOldRenderState; // pop
524 void drawRegularPolygon(double centerx, double centery, int sides, double r)
526 //hacky hack hack
527 uno::Sequence< geometry::RealPoint2D > aPoints (sides);
528 uno::Reference< rendering::XLinePolyPolygon2D > xPoly;
530 for (int i= 0; i < sides; i++)
532 aPoints[i]= geometry::RealPoint2D( centerx + r * cos(i*2 * M_PI/sides),
533 centery + r * sin(i*2 * M_PI/sides));
535 uno::Sequence< uno::Sequence< geometry::RealPoint2D > > aPolys(1);
536 aPolys[0] = aPoints;
537 xPoly = mxDevice->createCompatibleLinePolyPolygon( aPolys );
538 xPoly->setClosed( 0, true );
539 rendering::RenderState aRenderState( maRenderState );
540 aRenderState.DeviceColor = maColorRed;
541 uno::Reference< rendering::XPolyPolygon2D> xPP( xPoly, uno::UNO_QUERY );
542 mxCanvas->drawPolyPolygon( xPP, maViewState, aRenderState);
543 mxCanvas->fillPolyPolygon( xPP,
544 maViewState,
545 aRenderState );
548 void drawPolygons()
550 rendering::RenderState maOldRenderState = maRenderState; // push
551 translate( maBox.Width() * 1.0, maBox.Height() * 2.0 );
553 drawTitle( ::rtl::OString( "Polgyons" ) );
555 int sides= 3;
556 for (int i= 1; i <= 4; i++)
558 drawRegularPolygon(35*i, 35, sides, 15);
559 sides++;
562 maRenderState = maOldRenderState; // pop
565 void drawWidgets() // FIXME: prolly makes no sense
567 rendering::RenderState maOldRenderState = maRenderState; // push
568 translate( maBox.Width() * 2.0, maBox.Height() * 2.0 );
570 drawTitle( ::rtl::OString( "Widgets" ) );
572 maRenderState = maOldRenderState; // pop
577 void TestWindow::Paint( const Rectangle& /*rRect*/ )
581 const Size aVDevSize(300,300);
582 VirtualDevice aVDev(*this);
583 aVDev.SetOutputSizePixel(aVDevSize);
584 uno::Reference< rendering::XCanvas > xVDevCanvas( aVDev.GetCanvas(),
585 uno::UNO_QUERY_THROW );
586 uno::Reference< rendering::XGraphicDevice > xVDevDevice( xVDevCanvas->getDevice(),
587 uno::UNO_QUERY_THROW );
588 DemoRenderer aVDevRenderer( xVDevDevice, xVDevCanvas, aVDevSize);
589 xVDevCanvas->clear();
590 aVDevRenderer.drawGrid();
591 aVDevRenderer.drawRectangles();
592 aVDevRenderer.drawEllipses();
593 aVDevRenderer.drawText();
594 aVDevRenderer.drawLines();
595 aVDevRenderer.drawCurves();
596 aVDevRenderer.drawArcs();
597 aVDevRenderer.drawPolygons();
599 uno::Reference< rendering::XCanvas > xCanvas( GetSpriteCanvas(),
600 uno::UNO_QUERY_THROW );
601 uno::Reference< rendering::XGraphicDevice > xDevice( xCanvas->getDevice(),
602 uno::UNO_QUERY_THROW );
604 DemoRenderer aRenderer( xDevice, xCanvas, GetSizePixel() );
605 xCanvas->clear();
606 aRenderer.drawGrid();
607 aRenderer.drawRectangles();
608 aRenderer.drawEllipses();
609 aRenderer.drawText();
610 aRenderer.drawLines();
611 aRenderer.drawCurves();
612 aRenderer.drawArcs();
613 aRenderer.drawPolygons();
614 aRenderer.drawWidgets();
615 aRenderer.drawImages();
617 // check whether virdev actually contained something
618 uno::Reference< rendering::XBitmap > xBitmap(xVDevCanvas, uno::UNO_QUERY);
619 if( !xBitmap.is() )
620 return;
622 aRenderer.maRenderState.AffineTransform.m02 += 100;
623 aRenderer.maRenderState.AffineTransform.m12 += 100;
624 xCanvas->drawBitmap(xBitmap, aRenderer.maViewState, aRenderer.maRenderState);
626 uno::Reference< rendering::XSpriteCanvas > xSpriteCanvas( xCanvas,
627 uno::UNO_QUERY );
628 if( xSpriteCanvas.is() )
629 xSpriteCanvas->updateScreen( sal_True ); // without
630 // updateScreen(),
631 // nothing is
632 // visible
634 catch (const uno::Exception &e)
636 fprintf( stderr, "Exception '%s' thrown\n" ,
637 ::rtl::OUStringToOString( e.Message, RTL_TEXTENCODING_UTF8 ).getStr() );
641 USHORT DemoApp::Exception( USHORT nError )
643 switch( nError & EXC_MAJORTYPE )
645 case EXC_RSCNOTLOADED:
646 Abort( String::CreateFromAscii( "Error: could not load language resources.\nPlease check your installation.\n" ) );
647 break;
649 return 0;
652 void DemoApp::Main()
654 bool bHelp = false;
656 for( USHORT i = 0; i < GetCommandLineParamCount(); i++ )
658 ::rtl::OUString aParam = GetCommandLineParam( i );
660 if( aParam.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "--help" ) ) ||
661 aParam.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "-h" ) ) )
662 bHelp = true;
665 if( bHelp )
667 PrintHelp();
668 return;
671 //-------------------------------------------------
672 // create the global service-manager
673 //-------------------------------------------------
674 uno::Reference< lang::XMultiServiceFactory > xFactory;
677 uno::Reference< uno::XComponentContext > xCtx = ::cppu::defaultBootstrap_InitialComponentContext();
678 xFactory = uno::Reference< lang::XMultiServiceFactory >( xCtx->getServiceManager(),
679 uno::UNO_QUERY );
680 if( xFactory.is() )
681 ::comphelper::setProcessServiceFactory( xFactory );
683 catch( uno::Exception& )
687 if( !xFactory.is() )
689 fprintf( stderr, "Could not bootstrap UNO, installation must be in disorder. Exiting.\n" );
690 exit( 1 );
693 // Create UCB.
694 uno::Sequence< uno::Any > aArgs( 2 );
695 aArgs[ 0 ] <<= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( UCB_CONFIGURATION_KEY1_LOCAL ));
696 aArgs[ 1 ] <<= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( UCB_CONFIGURATION_KEY2_OFFICE ));
697 ::ucbhelper::ContentBroker::initialize( xFactory, aArgs );
699 InitVCL( xFactory );
700 TestWindow pWindow;
701 pWindow.Execute();
702 DeInitVCL();
704 // clean up UCB
705 ::ucbhelper::ContentBroker::deinitialize();
708 DemoApp aDemoApp;
710 // TODO
711 // - bouncing clip-rectangle mode - bounce a clip-rect around the window ...
712 // - complete all of pre-existing canvas bits
713 // - affine transform tweakage ...
715 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */