summaryrefslogtreecommitdiff
path: root/svx/source/sdr/overlay/overlayrollingrectangle.cxx
blob: 8b862484d63525589c1291d33b0d6f7166b174ff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 * 
 * Copyright 2008 by Sun Microsystems, Inc.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * $RCSfile: overlayrollingrectangle.cxx,v $
 * $Revision: 1.4 $
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/

// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_svx.hxx"
#include <svx/sdr/overlay/overlayrollingrectangle.hxx>
#include <tools/gen.hxx>
#include <vcl/salbtype.hxx>
#include <vcl/outdev.hxx>
#include <basegfx/matrix/b2dhommatrix.hxx>

//////////////////////////////////////////////////////////////////////////////

namespace sdr
{
    namespace overlay
    {
        void OverlayRollingRectangleStriped::drawGeometry(OutputDevice& rOutputDevice)
        {
            const basegfx::B2DRange aRange(getBasePosition(), getSecondPosition());

            if(getShowBounds())
            {
                ImpDrawRangeStriped(rOutputDevice, aRange);
            }

            if(getExtendedLines())
            {
                const Point aEmptyPoint;
                const Rectangle aVisiblePixel(aEmptyPoint, rOutputDevice.GetOutputSizePixel());
                const Rectangle aVisibleLogic(rOutputDevice.PixelToLogic(aVisiblePixel));

                // Left lines
                ImpDrawLineStriped(rOutputDevice, aVisibleLogic.Left(), aRange.getMinY(), aRange.getMinX(), aRange.getMinY());
                ImpDrawLineStriped(rOutputDevice, aVisibleLogic.Left(), aRange.getMaxY(), aRange.getMinX(), aRange.getMaxY());

                // Right lines
                ImpDrawLineStriped(rOutputDevice, aRange.getMaxX(), aRange.getMinY(), aVisibleLogic.Right(), aRange.getMinY());
                ImpDrawLineStriped(rOutputDevice, aRange.getMaxX(), aRange.getMaxY(), aVisibleLogic.Right(), aRange.getMaxY());

                // Top lines
                ImpDrawLineStriped(rOutputDevice, aRange.getMinX(), aVisibleLogic.Top(), aRange.getMinX(), aRange.getMinY());
                ImpDrawLineStriped(rOutputDevice, aRange.getMaxX(), aVisibleLogic.Top(), aRange.getMaxX(), aRange.getMinY());

                // Bottom lines
                ImpDrawLineStriped(rOutputDevice, aRange.getMinX(), aRange.getMaxY(), aRange.getMinX(), aVisibleLogic.Bottom());
                ImpDrawLineStriped(rOutputDevice, aRange.getMaxX(), aRange.getMaxY(), aRange.getMaxX(), aVisibleLogic.Bottom());
            }
        }

        void OverlayRollingRectangleStriped::createBaseRange(OutputDevice& rOutputDevice)
        {
            // reset range and expand it
            maBaseRange.reset();

            if(getExtendedLines())
            {
                const Point aEmptyPoint;
                const Rectangle aVisiblePixel(aEmptyPoint, rOutputDevice.GetOutputSizePixel());
                const Rectangle aVisibleLogic(rOutputDevice.PixelToLogic(aVisiblePixel));
                maBaseRange.expand(basegfx::B2DPoint(aVisibleLogic.Left(), aVisibleLogic.Top()));
                maBaseRange.expand(basegfx::B2DPoint(aVisibleLogic.Right(), aVisibleLogic.Bottom()));
            }

            if(getShowBounds())
            {
                maBaseRange.expand(getBasePosition());
                maBaseRange.expand(getSecondPosition());
            }
        }

        OverlayRollingRectangleStriped::OverlayRollingRectangleStriped(
            const basegfx::B2DPoint& rBasePos,
            const basegfx::B2DPoint& rSecondPos,
            sal_Bool bExtendedLines,
            sal_Bool bShowBounds)
        :	OverlayObjectWithBasePosition(rBasePos, Color(COL_BLACK)),
            maSecondPosition(rSecondPos),
            mbExtendedLines(bExtendedLines),
            mbShowBounds(bShowBounds)
        {
        }
        
        OverlayRollingRectangleStriped::~OverlayRollingRectangleStriped()
        {
        }

        void OverlayRollingRectangleStriped::setSecondPosition(const basegfx::B2DPoint& rNew)
        {
            if(rNew != maSecondPosition)
            {
                // remember new value
                maSecondPosition = rNew;

                // register change (after change)
                objectChange();
            }
        }

        void OverlayRollingRectangleStriped::setExtendedLines(sal_Bool bNew)
        {
            if(bNew != mbExtendedLines)
            {
                // remember new value
                mbExtendedLines = bNew;

                // register change (after change)
                objectChange();
            }
        }

        void OverlayRollingRectangleStriped::setShowBounds(sal_Bool bNew)
        {
            if(bNew != mbShowBounds)
            {
                // remember new value
                mbShowBounds = bNew;

                // register change (after change)
                objectChange();
            }
        }

        sal_Bool OverlayRollingRectangleStriped::isHit(const basegfx::B2DPoint& rPos, double fTol) const
        {
            if(isHittable())
            {
                if(getExtendedLines())
                {
                    const basegfx::B2DRange aRange(getBaseRange());
                    const basegfx::B2DPoint aMinimum(aRange.getMinimum());
                    const basegfx::B2DPoint aMaximum(aRange.getMaximum());

                    // test upper line horizontal
                    if(rPos.getY() > (aMinimum.getY() - fTol) && rPos.getY() < (aMinimum.getY() + fTol))
                    {
                        return sal_True;
                    }

                    // test lower line horizontal
                    if(rPos.getY() > (aMaximum.getY() - fTol) && rPos.getY() < (aMaximum.getY() + fTol))
                    {
                        return sal_True;
                    }

                    // test left line vertical
                    if(rPos.getX() > (aMinimum.getX() - fTol) && rPos.getX() < (aMinimum.getX() + fTol))
                    {
                        return sal_True;
                    }

                    // test rightline vertical
                    if(rPos.getX() > (aMaximum.getX() - fTol) && rPos.getX() < (aMaximum.getX() + fTol))
                    {
                        return sal_True;
                    }
                }

                if(getShowBounds())
                {
                    // test for inside grown range, outside shrinked one to test for border
                    // hit without interiour
                    basegfx::B2DRange aOuterRange(getBaseRange());
                    aOuterRange.grow(fTol);
                    
                    if(aOuterRange.isInside(rPos))
                    {
                        basegfx::B2DRange aInnerRange(getBaseRange());
                        aInnerRange.grow(-fTol);

                        return !aInnerRange.isInside(rPos);
                    }
                }
            }

            return sal_False;
        }

        void OverlayRollingRectangleStriped::transform(const basegfx::B2DHomMatrix& rMatrix)
        {
            if(!rMatrix.isIdentity())
            {
                // transform base position
                OverlayObjectWithBasePosition::transform(rMatrix);

                // transform maSecondPosition
                const basegfx::B2DPoint aNewSecondPosition = rMatrix * getSecondPosition();
                setSecondPosition(aNewSecondPosition);
            }
        }
    } // end of namespace overlay
} // end of namespace sdr

//////////////////////////////////////////////////////////////////////////////

namespace sdr
{
    namespace overlay
    {
        void OverlayRollingRectangle::drawGeometry(OutputDevice& rOutputDevice)
        {
            const Point aStart(FRound(getBasePosition().getX()), FRound(getBasePosition().getY()));
            const Point aEnd(FRound(getSecondPosition().getX()), FRound(getSecondPosition().getY()));
            Rectangle aRectangle(aStart, aEnd);
            aRectangle.Justify();

            if(getShowBounds())
            {
                rOutputDevice.SetLineColor(getBaseColor());
                rOutputDevice.SetFillColor();

                rOutputDevice.DrawRect(aRectangle);
            }

            if(getExtendedLines())
            {
                const Point aEmptyPoint;
                const Rectangle aVisiblePixel(aEmptyPoint, rOutputDevice.GetOutputSizePixel());
                const Rectangle aVisibleLogic(rOutputDevice.PixelToLogic(aVisiblePixel));

                // Left lines
                rOutputDevice.DrawLine(Point(aVisibleLogic.Left(), aRectangle.Top()), aRectangle.TopLeft());
                rOutputDevice.DrawLine(Point(aVisibleLogic.Left(), aRectangle.Bottom()), aRectangle.BottomLeft());

                // Right lines
                rOutputDevice.DrawLine(aRectangle.TopRight(), Point(aVisibleLogic.Right(), aRectangle.Top()));
                rOutputDevice.DrawLine(aRectangle.BottomRight(), Point(aVisibleLogic.Right(), aRectangle.Bottom()));

                // Top lines
                rOutputDevice.DrawLine(Point(aRectangle.Left(), aVisibleLogic.Top()), aRectangle.TopLeft());
                rOutputDevice.DrawLine(Point(aRectangle.Right(), aVisibleLogic.Top()), aRectangle.TopRight());

                // Bottom lines
                rOutputDevice.DrawLine(aRectangle.BottomLeft(), Point(aRectangle.Left(), aVisibleLogic.Bottom()));
                rOutputDevice.DrawLine(aRectangle.BottomRight(), Point(aRectangle.Right(), aVisibleLogic.Bottom()));
            }
        }

        OverlayRollingRectangle::OverlayRollingRectangle(
            const basegfx::B2DPoint& rBasePos,
            const basegfx::B2DPoint& rSecondPos,
            Color aLineColor,
            sal_Bool bExtendedLines,
            sal_Bool bShowBounds)
        :	OverlayRollingRectangleStriped(rBasePos, rSecondPos, bExtendedLines, bShowBounds)
        {
            // set base color here, OverlayCrosshairStriped constructor has set
            // it to it's own default.
            maBaseColor = aLineColor;
        }
        
        OverlayRollingRectangle::~OverlayRollingRectangle()
        {
        }
    } // end of namespace overlay
} // end of namespace sdr

//////////////////////////////////////////////////////////////////////////////
// eof