diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2015-03-25 15:42:41 +0900 |
---|---|---|
committer | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2015-03-27 10:45:15 +0900 |
commit | 913b3a648117206d21821b0cea40ff15a0e8e5cf (patch) | |
tree | 83c28ebde2e2d9dda7227c26e05d0a0d89f652d8 | |
parent | 33094a542fbcdcdaf14d5d7304e79f2e5b8cd4de (diff) |
Experimental: draw handles instead of getting them from bitmap
Currently object handles are defined in the bitmap which is a pain
when using in HiDPI as they have to be scaled and don't look
pretty. They are also hard to change and non theme-able (change
of color needs a change the bitmap). This commit experimentaly
enables the drawn handles (enable with environment variable
SVX_DRAW_HANDLES) which currently exchanges the default some
basic handles.
Change-Id: If80aa7fe756a6d8d6991e9515f2951ee21b31b72
-rw-r--r-- | svx/Library_svxcore.mk | 1 | ||||
-rw-r--r-- | svx/inc/sdr/overlay/overlayhandle.hxx | 42 | ||||
-rw-r--r-- | svx/inc/sdr/overlay/overlaytools.hxx | 36 | ||||
-rw-r--r-- | svx/source/sdr/overlay/overlayhandle.cxx | 63 | ||||
-rw-r--r-- | svx/source/sdr/overlay/overlaytools.cxx | 89 | ||||
-rw-r--r-- | svx/source/svdraw/svdhdl.cxx | 54 |
6 files changed, 279 insertions, 6 deletions
diff --git a/svx/Library_svxcore.mk b/svx/Library_svxcore.mk index 04b05f5b7f20..1586bd5d9cb7 100644 --- a/svx/Library_svxcore.mk +++ b/svx/Library_svxcore.mk @@ -227,6 +227,7 @@ $(eval $(call gb_Library_add_exception_objects,svxcore,\ svx/source/sdr/overlay/overlayobject \ svx/source/sdr/overlay/overlaymanager \ svx/source/sdr/overlay/overlayobjectlist \ + svx/source/sdr/overlay/overlayhandle \ svx/source/sdr/primitive2d/sdrellipseprimitive2d \ svx/source/sdr/primitive2d/sdrprimitivetools \ svx/source/sdr/primitive2d/sdrtextprimitive2d \ diff --git a/svx/inc/sdr/overlay/overlayhandle.hxx b/svx/inc/sdr/overlay/overlayhandle.hxx new file mode 100644 index 000000000000..60d7e54418f4 --- /dev/null +++ b/svx/inc/sdr/overlay/overlayhandle.hxx @@ -0,0 +1,42 @@ +/* -*- 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/. + * + */ + +#ifndef INCLUDED_SVX_SDR_OVERLAY_OVERLAYHANDLE_HXX +#define INCLUDED_SVX_SDR_OVERLAY_OVERLAYHANDLE_HXX + +#include <svx/sdr/overlay/overlayobject.hxx> +#include <basegfx/vector/b2dsize.hxx> + +namespace sdr { namespace overlay { + + +class SVX_DLLPUBLIC OverlayHandle : public OverlayObjectWithBasePosition +{ +protected: + basegfx::B2DSize maSize; + Color maStrokeColor; + + // geometry creation for OverlayObject + virtual drawinglayer::primitive2d::Primitive2DSequence createOverlayObjectPrimitive2DSequence() SAL_OVERRIDE; + +public: + OverlayHandle(const basegfx::B2DPoint& rBasePos, + const basegfx::B2DSize& rSize, + Color& rStrokeColor, + Color& rFillColor); + + virtual ~OverlayHandle(); +}; + +}} // end of namespace sdr::overlay + +#endif // INCLUDED_SVX_SDR_OVERLAY_OVERLAYHANDLE_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svx/inc/sdr/overlay/overlaytools.hxx b/svx/inc/sdr/overlay/overlaytools.hxx index 095c411e1d5d..9a6f9fe31fe4 100644 --- a/svx/inc/sdr/overlay/overlaytools.hxx +++ b/svx/inc/sdr/overlay/overlaytools.hxx @@ -22,7 +22,43 @@ #include <drawinglayer/primitive2d/primitivetools2d.hxx> #include <vcl/bitmapex.hxx> +#include <basegfx/vector/b2dsize.hxx> +namespace drawinglayer { namespace primitive2d { + +class OverlayStaticRectanglePrimitive : public DiscreteMetricDependentPrimitive2D +{ +private: + basegfx::B2DPoint maPosition; + basegfx::B2DSize maSize; + + // the graphic definition + basegfx::BColor maStrokeColor; + basegfx::BColor maFillColor; + double mfTransparence; + + // the rotation of the primitive itself + double mfRotation; + +protected: + virtual Primitive2DSequence create2DDecomposition(const geometry::ViewInformation2D& rViewInformation) const SAL_OVERRIDE; + +public: + OverlayStaticRectanglePrimitive( + const basegfx::B2DPoint& rPosition, + const basegfx::B2DSize& rSize, + const basegfx::BColor& rStrokeColor, + const basegfx::BColor& rFillColor, + double fTransparence, + double fRotation); + + // compare operator + virtual bool operator==( const BasePrimitive2D& rPrimitive ) const SAL_OVERRIDE; + + DeclPrimitive2DIDBlock() +}; + +}} // end of namespace drawinglayer::primitive2d // Overlay helper class which holds a BotmapEx which is to be visualized // at the given logic position with the Bitmap's pixel size, unscaled and diff --git a/svx/source/sdr/overlay/overlayhandle.cxx b/svx/source/sdr/overlay/overlayhandle.cxx new file mode 100644 index 000000000000..8cd47ff837d6 --- /dev/null +++ b/svx/source/sdr/overlay/overlayhandle.cxx @@ -0,0 +1,63 @@ +/* -*- 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/. + * + * 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 . + */ + +#include <sdr/overlay/overlayhandle.hxx> +#include <sdr/overlay/overlaytools.hxx> +#include <tools/poly.hxx> +#include <vcl/outdev.hxx> +#include <basegfx/matrix/b2dhommatrix.hxx> +#include <basegfx/polygon/b2dpolygontools.hxx> +#include <basegfx/polygon/b2dpolygon.hxx> +#include <svx/sdr/overlay/overlaymanager.hxx> +#include <drawinglayer/primitive2d/polygonprimitive2d.hxx> +#include <drawinglayer/primitive2d/polypolygonprimitive2d.hxx> + +namespace sdr { namespace overlay { + +using namespace drawinglayer::primitive2d; +using namespace basegfx; + +Primitive2DSequence OverlayHandle::createOverlayObjectPrimitive2DSequence() +{ + basegfx::BColor aStrokeColor = maStrokeColor.getBColor(); + basegfx::BColor aFillColor = getBaseColor().getBColor(); + + const Primitive2DReference aReference( + new OverlayStaticRectanglePrimitive(maBasePosition, maSize, aStrokeColor, aFillColor, 0.3f, 0.0f)); + + return Primitive2DSequence(&aReference, 1); +} + +OverlayHandle::OverlayHandle(const B2DPoint& rBasePos, + const B2DSize& rSize, + Color& rStrokeColor, + Color& rFillColor) + : OverlayObjectWithBasePosition(rBasePos, rFillColor) + , maSize(rSize) + , maStrokeColor(rStrokeColor) +{ +} + +OverlayHandle::~OverlayHandle() +{ +} + +}} // end of namespace sdr::overlay + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svx/source/sdr/overlay/overlaytools.cxx b/svx/source/sdr/overlay/overlaytools.cxx index ea0cab69899c..b333ce212179 100644 --- a/svx/source/sdr/overlay/overlaytools.cxx +++ b/svx/source/sdr/overlay/overlaytools.cxx @@ -33,6 +33,95 @@ #include <vcl/settings.hxx> +namespace drawinglayer +{ +namespace primitive2d +{ + +OverlayStaticRectanglePrimitive::OverlayStaticRectanglePrimitive( + const basegfx::B2DPoint& rPosition, + const basegfx::B2DSize& rSize, + const basegfx::BColor& rStrokeColor, + const basegfx::BColor& rFillColor, + double fTransparence, + double fRotation) + : DiscreteMetricDependentPrimitive2D() + , maPosition(rPosition) + , maSize(rSize) + , maStrokeColor(rStrokeColor) + , maFillColor(rFillColor) + , mfTransparence(fTransparence) + , mfRotation(fRotation) +{} + +Primitive2DSequence OverlayStaticRectanglePrimitive::create2DDecomposition(const geometry::ViewInformation2D& /*rViewInformation*/) const +{ + Primitive2DSequence aPrimitive2DSequence; + const double fHalfWidth = maSize.getX() * getDiscreteUnit() / 2.0; + const double fHalfHeight = maSize.getY() * getDiscreteUnit() / 2.0; + + basegfx::B2DRange aRange( + maPosition.getX() - fHalfWidth, maPosition.getY() - fHalfHeight, + maPosition.getX() + fHalfWidth, maPosition.getY() + fHalfHeight); + + if (basegfx::fTools::more(getDiscreteUnit(), 0.0) && mfTransparence <= 1.0) + { + basegfx::B2DPolygon aPolygon( + basegfx::tools::createPolygonFromRect(aRange)); + + // create filled primitive + basegfx::B2DPolyPolygon aPolyPolygon; + aPolyPolygon.append(aPolygon); + + const attribute::LineAttribute aLineAttribute(maStrokeColor, 1.0); + + // create data + const Primitive2DReference aStroke( + new PolyPolygonStrokePrimitive2D(aPolyPolygon, aLineAttribute)); + + // create fill primitive + const Primitive2DReference aFill( + new PolyPolygonColorPrimitive2D(aPolyPolygon, maFillColor)); + + aPrimitive2DSequence = Primitive2DSequence(2); + aPrimitive2DSequence[0] = aFill; + aPrimitive2DSequence[1] = aStroke; + + // embed filled to transparency (if used) + if (mfTransparence > 0.0) + { + const Primitive2DReference aFillTransparent( + new UnifiedTransparencePrimitive2D( + aPrimitive2DSequence, + mfTransparence)); + + aPrimitive2DSequence = Primitive2DSequence(&aFillTransparent, 1); + } + } + + return aPrimitive2DSequence; +} + +bool OverlayStaticRectanglePrimitive::operator==(const BasePrimitive2D& rPrimitive) const +{ + if (DiscreteMetricDependentPrimitive2D::operator==(rPrimitive)) + { + const OverlayStaticRectanglePrimitive& rCompare = static_cast<const OverlayStaticRectanglePrimitive&>(rPrimitive); + + return (maPosition == rCompare.maPosition + && maSize == rCompare.maSize + && maStrokeColor == rCompare.maStrokeColor + && maFillColor == rCompare.maFillColor + && mfTransparence == rCompare.mfTransparence + && mfRotation == rCompare.mfRotation); + } + + return false; +} + +ImplPrimitive2DIDBlock(OverlayStaticRectanglePrimitive, PRIMITIVE2D_ID_OVERLAYRECTANGLEPRIMITIVE) + +}} // end of namespace drawinglayer::primitive2d namespace drawinglayer { diff --git a/svx/source/svdraw/svdhdl.cxx b/svx/source/svdraw/svdhdl.cxx index 4e251272eca3..6f7a078cb9f7 100644 --- a/svx/source/svdraw/svdhdl.cxx +++ b/svx/source/svdraw/svdhdl.cxx @@ -50,6 +50,7 @@ #include <svx/sdr/overlay/overlaybitmapex.hxx> #include <sdr/overlay/overlayline.hxx> #include <svx/sdr/overlay/overlaytriangle.hxx> +#include <sdr/overlay/overlayhandle.hxx> #include <sdr/overlay/overlayrectangle.hxx> #include <svx/sdrpagewindow.hxx> #include <svx/sdrpaintwindow.hxx> @@ -577,13 +578,54 @@ void SdrHdl::CreateB2dIAObject() if (xManager.is()) { basegfx::B2DPoint aPosition(aPos.X(), aPos.Y()); - sdr::overlay::OverlayObject* pNewOverlayObject = CreateOverlayObject( - aPosition, - eColIndex, - eKindOfMarker, - rOutDev, - aMoveOutsideOffset); + sdr::overlay::OverlayObject* pNewOverlayObject = NULL; + if (getenv ("SVX_DRAW_HANDLES") && (eKindOfMarker == Rect_7x7 || eKindOfMarker == Rect_9x9 || eKindOfMarker == Rect_11x11)) + { + double fSize = 7.0; + switch (eKindOfMarker) + { + case Rect_9x9: + fSize = 9.0; + break; + case Rect_11x11: + fSize = 11.0; + break; + default: + break; + } + sal_Int32 nScaleFactor = rOutDev.GetDPIScaleFactor(); + basegfx::B2DSize aB2DSize(fSize * nScaleFactor, fSize * nScaleFactor); + Color aHandleStrokeColor(COL_BLACK); + Color aHandleFillColor(COL_LIGHTGREEN); + switch (eColIndex) + { + case Cyan: + aHandleFillColor = Color(COL_CYAN); + break; + case LightCyan: + aHandleFillColor = Color(COL_LIGHTCYAN); + break; + case Red: + aHandleFillColor = Color(COL_RED); + break; + case LightRed: + aHandleFillColor = Color(COL_LIGHTRED); + break; + case Yellow: + aHandleFillColor = Color(COL_YELLOW); + break; + default: + break; + } + pNewOverlayObject = new sdr::overlay::OverlayHandle(aPosition, aB2DSize, aHandleStrokeColor, aHandleFillColor); + } + else + { + pNewOverlayObject = CreateOverlayObject( + aPosition, eColIndex, eKindOfMarker, + rOutDev, aMoveOutsideOffset); + } // OVERLAYMANAGER if (pNewOverlayObject) { |