Kaydet (Commit) a4749a48 authored tarafından Jan-Marek Glogowski's avatar Jan-Marek Glogowski

Convert canvasdemo to gbuild

Change-Id: Ieb3b1846a5a31915297cdc80053dba3d1656aba2
Reviewed-on: https://gerrit.libreoffice.org/65365
Tested-by: Jenkins
Reviewed-by: 's avatarJan-Marek Glogowski <glogow@fbihome.de>
üst 718c9b8a
......@@ -21,6 +21,7 @@ $(eval $(call gb_Helper_register_executables,NONE, \
HelpIndexer \
HelpLinker \
bestreversemap \
canvasdemo \
cfgex \
concat-deps \
cpp \
......
# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
#
#
# 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/.
#
$(eval $(call gb_Executable_Executable,canvasdemo))
$(eval $(call gb_Executable_use_api,canvasdemo,\
offapi \
udkapi \
))
$(eval $(call gb_Executable_use_externals,canvasdemo,\
boost_headers \
))
$(eval $(call gb_Executable_set_include,canvasdemo,\
$$(INCLUDE) \
))
$(eval $(call gb_Executable_use_libraries,canvasdemo,\
basegfx \
comphelper \
cppu \
cppuhelper \
tl \
sal \
salhelper \
vcl \
))
$(eval $(call gb_Executable_add_exception_objects,canvasdemo,\
canvas/workben/canvasdemo \
))
$(eval $(call gb_Executable_use_static_libraries,canvasdemo,\
vclmain \
))
ifeq ($(OS), $(filter LINUX %BSD SOLARIS, $(OS)))
$(eval $(call gb_Executable_add_libs,canvasdemo,\
-lm $(DLOPEN_LIBS) \
-lpthread \
-lX11 \
))
$(eval $(call gb_Executable_use_static_libraries,canvasdemo,\
glxtest \
))
endif
# vim: set noet sw=4 ts=4:
......@@ -24,6 +24,7 @@ $(eval $(call gb_Module_add_targets,canvas,\
Library_canvastools \
Library_simplecanvas \
Library_vclcanvas \
$(if $(DISABLE_GUI),,Executable_canvasdemo) \
))
ifeq ($(ENABLE_CAIRO_CANVAS),TRUE)
......
......@@ -17,20 +17,14 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
// This code strongly inspired by Miguel / Federico's Gnome Canvas demo code.
#include <sal/config.h>
#include <stdio.h>
#include <unistd.h>
#include <basegfx/polygon/b2dpolygon.hxx>
#include <basegfx/polygon/b2dpolygontools.hxx>
#include <basegfx/utils/canvastools.hxx>
#include <com/sun/star/lang/XInitialization.hpp>
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#include <com/sun/star/registry/XSimpleRegistry.hpp>
#include <com/sun/star/rendering/CompositeOperation.hpp>
#include <com/sun/star/rendering/FillRule.hpp>
#include <com/sun/star/rendering/PathCapType.hpp>
......@@ -44,49 +38,37 @@
#include <com/sun/star/ucb/UniversalContentBroker.hpp>
#include <comphelper/processfactory.hxx>
#include <cppuhelper/bootstrap.hxx>
#include <cppuhelper/servicefactory.hxx>
#include <rtl/bootstrap.hxx>
#include <sal/macros.h>
#include <vcl/canvastools.hxx>
#include <vcl/svapp.hxx>
#include <vcl/vclmain.hxx>
#include <vcl/virdev.hxx>
#include <vcl/window.hxx>
#include <vcl/wrkwin.hxx>
// never import whole leaf namespaces, since this will result in
// absolutely weird effects during (Koenig) name lookup
using namespace ::com::sun::star;
class DemoApp : public Application
{
public:
virtual void Main();
virtual void Exception( ExceptionCategory nCategory );
};
static void PrintHelp()
{
fprintf( stdout, "canvasdemo - Exercise the new canvas impl\n" );
}
class TestWindow : public Dialog
class TestWindow : public WorkWindow
{
public:
TestWindow() : Dialog( (vcl::Window *) NULL )
TestWindow() : WorkWindow(nullptr, WB_APP | WB_STDWORK)
{
SetText( OUString( "Canvas test" ) );
SetText("Canvas test");
SetSizePixel( Size( 600, 450 ) );
EnablePaint( true );
Show();
}
virtual ~TestWindow() {}
virtual void MouseButtonUp( const MouseEvent& /*rMEvt*/ )
virtual ~TestWindow() override {}
virtual void MouseButtonUp( const MouseEvent& /*rMEvt*/ ) override
{
//TODO: do something cool
EndDialog();
Application::Quit();
}
virtual void Paint( const Rectangle& rRect );
virtual void Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect) override;
};
class DemoRenderer
......@@ -130,8 +112,8 @@ class DemoRenderer
//but nothing changes
maRenderState.CompositeOperation = rendering::CompositeOperation::OVER;
maBox.Width() = aSize.Width() / 3;
maBox.Height() = aSize.Height() / 3;
maBox.setWidth(aSize.Width() / 3);
maBox.setHeight(aSize.Height() / 3);
lang::Locale aLocale;
rendering::FontInfo aFontInfo;
......@@ -173,7 +155,7 @@ class DemoRenderer
mxCanvas->drawText( aText, mxDefaultFont, maViewState, aRenderState, 0);
}
void drawRect( Rectangle rRect, uno::Sequence< double > &aColor, int /*nWidth*/ )
void drawRect( tools::Rectangle rRect, uno::Sequence< double > &aColor, int /*nWidth*/ )
{
uno::Sequence< geometry::RealPoint2D > aPoints(4);
uno::Reference< rendering::XLinePolyPolygon2D > xPoly;
......@@ -298,11 +280,11 @@ class DemoRenderer
drawTitle( OString( "Rectangles" ) );
drawRect( Rectangle( 20, 30, 70, 60 ), maColorRed, 8 );
drawRect( tools::Rectangle( 20, 30, 70, 60 ), maColorRed, 8 );
// color mediumseagreen, stipple fill, outline black
drawRect( Rectangle( 90, 40, 180, 100 ), maColorBlack, 4 );
drawRect( tools::Rectangle( 90, 40, 180, 100 ), maColorBlack, 4 );
// color steelblue, filled, no outline
drawRect( Rectangle( 10, 80, 80, 140 ), maColorBlack, 1 );
drawRect( tools::Rectangle( 10, 80, 80, 140 ), maColorBlack, 1 );
maRenderState = maOldRenderState; // pop
}
......@@ -444,7 +426,7 @@ class DemoRenderer
double gimmerand()
{
return (double)(rand()) / RAND_MAX * 100 + 50;
return static_cast<double>(rand()) / RAND_MAX * 100 + 50;
}
void drawArcs()
......@@ -555,18 +537,15 @@ class DemoRenderer
};
void TestWindow::Paint( const Rectangle& /*rRect*/ )
void TestWindow::Paint(vcl::RenderContext&, const tools::Rectangle&)
{
try
{
const Size aVDevSize(300,300);
VirtualDevice aVDev(*this);
aVDev.SetOutputSizePixel(aVDevSize);
uno::Reference< rendering::XCanvas > xVDevCanvas( aVDev.GetCanvas(),
uno::Reference< rendering::XCanvas > xVDevCanvas( GetCanvas(),
uno::UNO_QUERY_THROW );
uno::Reference< rendering::XGraphicDevice > xVDevDevice( xVDevCanvas->getDevice(),
uno::UNO_QUERY_THROW );
DemoRenderer aVDevRenderer( xVDevDevice, xVDevCanvas, aVDevSize);
DemoRenderer aVDevRenderer( xVDevDevice, xVDevCanvas, GetSizePixel());
xVDevCanvas->clear();
aVDevRenderer.drawGrid();
aVDevRenderer.drawRectangles();
......@@ -607,7 +586,7 @@ void TestWindow::Paint( const Rectangle& /*rRect*/ )
uno::Reference< rendering::XSpriteCanvas > xSpriteCanvas( xCanvas,
uno::UNO_QUERY );
if( xSpriteCanvas.is() )
xSpriteCanvas->updateScreen( sal_True ); // without
xSpriteCanvas->updateScreen( true ); // without
// updateScreen(),
// nothing is
// visible
......@@ -619,21 +598,22 @@ void TestWindow::Paint( const Rectangle& /*rRect*/ )
}
}
void DemoApp::Exception( ExceptionCategory nCategory )
class DemoApp : public Application
{
switch( nCategory )
{
case ExceptionCategory::ResourceNotLoaded:
Abort( "Error: could not load language resources.\nPlease check your installation.\n" );
break;
}
}
public:
virtual int Main() override;
virtual void Exception(ExceptionCategory nCategory) override;
void DemoApp::Main()
protected:
void Init() override;
void DeInit() override;
};
int DemoApp::Main()
{
bool bHelp = false;
for( USHORT i = 0; i < GetCommandLineParamCount(); i++ )
for( unsigned int i = 0; i < GetCommandLineParamCount(); i++ )
{
OUString aParam = GetCommandLineParam( i );
......@@ -644,42 +624,64 @@ void DemoApp::Main()
if( bHelp )
{
PrintHelp();
return;
return 1;
}
// Create UCB (for backwards compatibility, in case some code still uses
// plain createInstance w/o args directly to obtain an instance):
::ucb::UniversalContentBroker::create(
comphelper::getProcessComponentContext() );
ScopedVclPtr<TestWindow> aWindow = VclPtr<TestWindow>::Create();
aWindow->Show();
// create the global service-manager
Application::Execute();
return 0;
}
uno::Reference< lang::XMultiServiceFactory > xFactory;
try
void DemoApp::Exception( ExceptionCategory nCategory )
{
switch( nCategory )
{
uno::Reference< uno::XComponentContext > xCtx = ::cppu::defaultBootstrap_InitialComponentContext();
xFactory.set( xCtx->getServiceManager(), uno::UNO_QUERY );
if( xFactory.is() )
::comphelper::setProcessServiceFactory( xFactory );
case ExceptionCategory::ResourceNotLoaded:
Abort( "Error: could not load language resources.\nPlease check your installation.\n" );
break;
default:
break;
}
catch( const uno::Exception& )
}
void DemoApp::Init()
{
try
{
uno::Reference<uno::XComponentContext> xComponentContext
= ::cppu::defaultBootstrap_InitialComponentContext();
uno::Reference<lang::XMultiServiceFactory> xMSF;
xMSF.set(xComponentContext->getServiceManager(), uno::UNO_QUERY);
if(!xMSF.is())
Application::Abort("Bootstrap failure - no service manager");
::comphelper::setProcessServiceFactory(xMSF);
}
if( !xFactory.is() )
catch (const uno::Exception &e)
{
fprintf( stderr, "Could not bootstrap UNO, installation must be in disorder. Exiting.\n" );
exit( 1 );
Application::Abort("Bootstrap exception " + e.Message);
}
}
// Create UCB (for backwards compatibility, in case some code still uses
// plain createInstance w/o args directly to obtain an instance):
::ucb::UniversalContentBroker::create(
comphelper::getProcessComponentContext() );
InitVCL();
TestWindow pWindow;
pWindow.Execute();
DeInitVCL();
void DemoApp::DeInit()
{
uno::Reference< lang::XComponent >(
comphelper::getProcessComponentContext(),
uno::UNO_QUERY_THROW)-> dispose();
::comphelper::setProcessServiceFactory(nullptr);
}
DemoApp aDemoApp;
void vclmain::createApplication()
{
static DemoApp aApp;
}
// TODO
// - bouncing clip-rectangle mode - bounce a clip-rect around the window...
......
#
# 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/.
#
# This file incorporates work covered by the following license notice:
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed
# with this work for additional information regarding copyright
# ownership. The ASF licenses this file to you under the Apache
# License, Version 2.0 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.apache.org/licenses/LICENSE-2.0 .
#
PRJ=..
PRJNAME=canvas
TARGET=canvasdemo
TARGETTYPE=GUI
LIBTARGET=NO
ENABLE_EXCEPTIONS=TRUE
# --- Settings -----------------------------------------------------
.INCLUDE : settings.mk
# --- Files --------------------------------------------------------
APP1TARGET= $(TARGET)
APP1OBJS= \
$(OBJ)$/canvasdemo.obj
APP1STDLIBS=$(TOOLSLIB) \
$(COMPHELPERLIB) \
$(CPPULIB) \
$(CPPUHELPERLIB) \
$(UCBHELPERLIB) \
$(SALLIB) \
$(VCLLIB) \
$(BASEGFXLIB)
.IF "$(OS)"=="WNT"
APP1DEF= $(MISC)$/$(TARGET).def
.ENDIF
# --- Targets ------------------------------------------------------
.INCLUDE : target.mk
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment