/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #if 0 # define FIXME_SELF_INTERSECTING_WORKING #endif using namespace css; class DemoBase : public WorkWindow // hide OutputDevice if necessary { public: DemoBase() : WorkWindow( NULL, WB_APP | WB_STDWORK) { } OutputDevice &getOutDev() { return *this; } }; class DemoWin : public DemoBase { Bitmap maIntroBW; BitmapEx maIntro; public: DemoWin() : DemoBase() { // Needed to find images OUString aPath; rtl::Bootstrap::get("SYSBINDIR", aPath); #ifdef FIXME_THIS_FAILS rtl::Bootstrap::set("BRAND_BASE_DIR", aPath + "/.."); if (Application::LoadBrandBitmap("intro", maIntro)) Application::Abort("Failed to load intro image"); #else aPath = aPath + "/intro.png"; SvFileStream aFileStream( aPath, STREAM_READ ); GraphicFilter aGraphicFilter(false); Graphic aGraphic; if (aGraphicFilter.ImportGraphic(aGraphic, aPath, aFileStream) != 0) Application::Abort("Failed to load intro image: " + aPath); maIntro = aGraphic.GetBitmapEx(); #endif maIntroBW = maIntro.GetBitmap(); maIntroBW.Filter( BMP_FILTER_EMBOSS_GREY ); } void drawToDevice(OutputDevice &r, bool bVdev); virtual void Paint( const Rectangle& rRect ) SAL_OVERRIDE { fprintf(stderr, "DemoWin::Paint(%ld,%ld,%ld,%ld)\n", rRect.getX(), rRect.getY(), rRect.getWidth(), rRect.getHeight()); drawToDevice(getOutDev(), false); } std::vector partitionAndClear(OutputDevice &rDev, int nX, int nY); void drawBackground(OutputDevice &rDev) { Rectangle r(Point(0,0), rDev.GetOutputSizePixel()); Gradient aGradient; aGradient.SetStartColor(COL_BLUE); aGradient.SetEndColor(COL_GREEN); aGradient.SetStyle(GradientStyle_LINEAR); // aGradient.SetBorder(r.GetSize().Width()/20); rDev.DrawGradient(r, aGradient); } void drawRadialLines(OutputDevice &rDev, Rectangle r) { rDev.SetFillColor(Color(COL_LIGHTRED)); rDev.SetLineColor(Color(COL_BLACK)); rDev.DrawRect( r ); for(int i=0; i maIcons; void initIcons() { if (maIcons.size()) return; const char *pNames[] = { "cmd/lc_openurl.png", "cmd/lc_newdoc.png", "cmd/lc_save.png", "cmd/lc_saveas.png", "cmd/lc_sendmail.png", "cmd/lc_editdoc.png", "cmd/lc_print.png", "cmd/lc_printpreview.png", "cmd/lc_cut.png", "cmd/lc_copy.png", "cmd/lc_paste.png", "cmd/lc_formatpaintbrush.png", "cmd/lc_undo.png", "cmd/lc_redo.png", }; for (size_t i = 0; i < SAL_N_ELEMENTS(pNames); i++) maIcons.push_back(BitmapEx(OUString::createFromAscii(pNames[i]))); } void drawIcons(OutputDevice &rDev, Rectangle r) { initIcons(); Rectangle p(r); for (size_t i = 0; i < maIcons.size(); i++) { Size aSize(maIcons[i].GetSizePixel()); rDev.DrawBitmapEx(p.TopLeft(), maIcons[i]); p.Move(aSize.Width(), 0); if (p.Left() >= r.Right()) break; } } void fetchDrawBitmap(OutputDevice &rDev, Rectangle r) { Bitmap aBitmap(GetBitmap(Point(0,0),rDev.GetOutputSizePixel())); aBitmap.Scale(r.GetSize(), BMP_SCALE_BESTQUALITY); rDev.DrawBitmap(r.TopLeft(), aBitmap); } }; std::vector DemoWin::partitionAndClear(OutputDevice &rDev, int nX, int nY) { Rectangle r; std::vector aRegions; // Make small cleared area for these guys Size aSize(rDev.GetOutputSizePixel()); long nBorderSize = aSize.Width() / 32; long nBoxWidth = (aSize.Width() - nBorderSize*(nX+1)) / nX; long nBoxHeight = (aSize.Height() - nBorderSize*(nY+1)) / nY; for (int y = 0; y < nY; y++ ) { for (int x = 0; x < nX; x++ ) { r.SetPos(Point(nBorderSize + (nBorderSize + nBoxWidth) * x, nBorderSize + (nBorderSize + nBoxHeight) * y)); r.SetSize(Size(nBoxWidth, nBoxHeight)); // knock up a nice little border rDev.SetLineColor(COL_GRAY); rDev.SetFillColor(COL_LIGHTGRAY); if ((x + y) % 2) rDev.DrawRect(r, nBorderSize, nBorderSize); else rDev.DrawRect(r); aRegions.push_back(r); } } return aRegions; } void DemoWin::drawToDevice(OutputDevice &rDev, bool bVdev) { drawBackground(rDev); std::vector aRegions(partitionAndClear(rDev, 4, 3)); drawRadialLines(rDev, aRegions[0]); drawText(rDev, aRegions[1]); drawPoly(rDev, aRegions[2]); drawEllipse(rDev, aRegions[3]); drawCheckered(rDev, aRegions[4]); drawBitmapEx(rDev, aRegions[5]); drawBitmap(rDev, aRegions[6]); drawGradient(rDev, aRegions[7]); drawPolyPolgons(rDev, aRegions[8]); if (!bVdev) drawToVirtualDevice(rDev, aRegions[9]); drawIcons(rDev, aRegions[10]); // last - thumbnail all the above fetchDrawBitmap(rDev, aRegions[11]); } class DemoApp : public Application { public: DemoApp() {} virtual int Main() SAL_OVERRIDE { DemoWin aMainWin; aMainWin.SetText( "Interactive VCL demo" ); aMainWin.Show(); Application::Execute(); return 0; } protected: uno::Reference xMSF; void Init() SAL_OVERRIDE { try { uno::Reference xComponentContext = ::cppu::defaultBootstrap_InitialComponentContext(); xMSF = uno::Reference ( xComponentContext->getServiceManager(), uno::UNO_QUERY ); if( !xMSF.is() ) Application::Abort("Bootstrap failure - no service manager"); ::comphelper::setProcessServiceFactory( xMSF ); } catch (const uno::Exception &e) { Application::Abort("Bootstrap exception " + e.Message); } } void DeInit() SAL_OVERRIDE { uno::Reference< lang::XComponent >( comphelper::getProcessComponentContext(), uno::UNO_QUERY_THROW )-> dispose(); ::comphelper::setProcessServiceFactory( NULL ); } }; void vclmain::createApplication() { static DemoApp aApp; } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */