| 1 |
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
| 2 |
/* |
| 3 |
* This file is part of the LibreOffice project. |
| 4 |
* |
| 5 |
* This Source Code Form is subject to the terms of the Mozilla Public |
| 6 |
* License, v. 2.0. If a copy of the MPL was not distributed with this |
| 7 |
* file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 8 |
* |
| 9 |
* This file incorporates work covered by the following license notice: |
| 10 |
* |
| 11 |
* Licensed to the Apache Software Foundation (ASF) under one or more |
| 12 |
* contributor license agreements. See the NOTICE file distributed |
| 13 |
* with this work for additional information regarding copyright |
| 14 |
* ownership. The ASF licenses this file to you under the Apache |
| 15 |
* License, Version 2.0 (the "License"); you may not use this file |
| 16 |
* except in compliance with the License. You may obtain a copy of |
| 17 |
* the License at http://www.apache.org/licenses/LICENSE-2.0 . |
| 18 |
*/ |
| 19 |
|
| 20 |
#ifndef INCLUDED_DRAWINGLAYER_PROCESSOR2D_HITTESTPROCESSOR2D_HXX |
| 21 |
#define INCLUDED_DRAWINGLAYER_PROCESSOR2D_HITTESTPROCESSOR2D_HXX |
| 22 |
|
| 23 |
#include <drawinglayer/drawinglayerdllapi.h> |
| 24 |
#include <drawinglayer/primitive2d/Primitive2DContainer.hxx> |
| 25 |
#include <drawinglayer/processor2d/baseprocessor2d.hxx> |
| 26 |
|
| 27 |
namespace basegfx { class B2DPolygon; } |
| 28 |
namespace basegfx { class B2DPolyPolygon; } |
| 29 |
namespace drawinglayer::primitive2d { class ScenePrimitive2D; } |
| 30 |
class Bitmap; |
| 31 |
|
| 32 |
namespace drawinglayer::processor2d |
| 33 |
{ |
| 34 |
/** HitTestProcessor2D class |
| 35 |
|
| 36 |
This processor implements a HitTest with the fed primitives, |
| 37 |
given tolerance and extras |
| 38 |
*/ |
| 39 |
class DRAWINGLAYER_DLLPUBLIC HitTestProcessor2D final : public BaseProcessor2D |
| 40 |
{ |
| 41 |
private: |
| 42 |
/// discrete HitTest position |
| 43 |
basegfx::B2DPoint maDiscreteHitPosition; |
| 44 |
|
| 45 |
/// discrete HitTolerance |
| 46 |
basegfx::B2DVector maDiscreteHitTolerancePerAxis; |
| 47 |
|
| 48 |
/// stack of HitPrimitives, taken care of during HitTest run |
| 49 |
primitive2d::Primitive2DContainer maHitStack; |
| 50 |
|
| 51 |
/// flag if HitStack shall be collected as part of the result, default is false |
| 52 |
bool mbCollectHitStack : 1; |
| 53 |
|
| 54 |
/// Boolean to flag if a hit was found. If yes, fast exit is taken |
| 55 |
bool mbHit : 1; |
| 56 |
|
| 57 |
/// flag to concentrate on text hits only |
| 58 |
bool mbHitTextOnly : 1; |
| 59 |
|
| 60 |
/// tooling methods |
| 61 |
void processBasePrimitive2D(const primitive2d::BasePrimitive2D& rCandidate) override; |
| 62 |
bool checkHairlineHitWithTolerance( |
| 63 |
const basegfx::B2DPolygon& rPolygon, |
| 64 |
const basegfx::B2DVector& rDiscreteHitTolerancePerAxis) const; |
| 65 |
bool checkFillHitWithTolerance( |
| 66 |
const basegfx::B2DPolyPolygon& rPolyPolygon, |
| 67 |
const basegfx::B2DVector& rDiscreteHitTolerancePerAxis) const; |
| 68 |
void check3DHit(const primitive2d::ScenePrimitive2D& rCandidate); |
| 69 |
void checkBitmapHit(basegfx::B2DRange aRange, const Bitmap& rBitmap, const basegfx::B2DHomMatrix& rTransform); |
| 70 |
|
| 71 |
public: |
| 72 |
HitTestProcessor2D( |
| 73 |
const geometry::ViewInformation2D& rViewInformation, |
| 74 |
const basegfx::B2DPoint& rLogicHitPosition, |
| 75 |
const basegfx::B2DVector& rLogicHitTolerancePerAxis, |
| 76 |
bool bHitTextOnly); |
| 77 |
virtual ~HitTestProcessor2D() override; |
| 78 |
|
| 79 |
/// switch on collecting primitives for a found hit on maHitStack, default is off |
| 80 |
void collectHitStack(bool bCollect) { mbCollectHitStack = bCollect; } |
| 81 |
|
| 82 |
/// get HitStack of primitives, first is the one that created the hit, last is the |
| 83 |
/// top-most |
| 84 |
const primitive2d::Primitive2DContainer& getHitStack() const { return maHitStack; } |
| 85 |
|
| 86 |
/// data read access |
| 87 |
const basegfx::B2DPoint& getDiscreteHitPosition() const { return maDiscreteHitPosition; } |
| 88 |
const basegfx::B2DVector& getDiscreteHitTolerance() const { return maDiscreteHitTolerancePerAxis; } |
| 89 |
bool getCollectHitStack() const { return mbCollectHitStack; } |
| 90 |
bool getHit() const { return mbHit; } |
| 91 |
bool getHitTextOnly() const { return mbHitTextOnly; } |
| 92 |
}; |
| 93 |
|
| 94 |
} // end of namespace drawinglayer::processor2d |
| 95 |
|
| 96 |
#endif // INCLUDED_DRAWINGLAYER_PROCESSOR2D_HITTESTPROCESSOR2D_HXX |
| 97 |
|
| 98 |
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |