Line data Source code
1 : /*
2 : * This file is part of the LibreOffice project.
3 : *
4 : * This Source Code Form is subject to the terms of the Mozilla Public
5 : * License, v. 2.0. If a copy of the MPL was not distributed with this
6 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 : *
8 : * This file incorporates work covered by the following license notice:
9 : *
10 : * Licensed to the Apache Software Foundation (ASF) under one or more
11 : * contributor license agreements. See the NOTICE file distributed
12 : * with this work for additional information regarding copyright
13 : * ownership. The ASF licenses this file to you under the Apache
14 : * License, Version 2.0 (the "License"); you may not use this file
15 : * except in compliance with the License. You may obtain a copy of
16 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
17 : */
18 :
19 : #include <svx/sdr/overlay/overlayrectangle.hxx>
20 : #include <vcl/outdev.hxx>
21 : #include <basegfx/matrix/b2dhommatrix.hxx>
22 : #include <basegfx/polygon/b2dpolygontools.hxx>
23 : #include <basegfx/polygon/b2dpolygon.hxx>
24 : #include <basegfx/numeric/ftools.hxx>
25 : #include <svx/sdr/overlay/overlaytools.hxx>
26 : #include <svx/sdr/overlay/overlaymanager.hxx>
27 : #include <vcl/svapp.hxx>
28 :
29 : //////////////////////////////////////////////////////////////////////////////
30 :
31 : namespace sdr
32 : {
33 : namespace overlay
34 : {
35 0 : drawinglayer::primitive2d::Primitive2DSequence OverlayRectangle::createOverlayObjectPrimitive2DSequence()
36 : {
37 0 : const basegfx::B2DRange aHatchRange(getBasePosition(), getSecondPosition());
38 0 : basegfx::BColor aColor(getBaseColor().getBColor());
39 : static double fChange(0.1); // just small optical change, do not make it annoying
40 :
41 0 : if(mbOverlayState)
42 : {
43 0 : aColor += basegfx::B3DTuple(fChange, fChange, fChange);
44 0 : aColor.clamp();
45 : }
46 : else
47 : {
48 0 : aColor -= basegfx::B3DTuple(fChange, fChange, fChange);
49 0 : aColor.clamp();
50 : }
51 :
52 : const drawinglayer::primitive2d::Primitive2DReference aReference(
53 : new drawinglayer::primitive2d::OverlayRectanglePrimitive(
54 : aHatchRange,
55 : aColor,
56 : getTransparence(),
57 : getDiscreteGrow(),
58 : getDiscreteShrink(),
59 0 : getRotation()));
60 :
61 0 : return drawinglayer::primitive2d::Primitive2DSequence(&aReference, 1);
62 : }
63 :
64 0 : OverlayRectangle::OverlayRectangle(
65 : const basegfx::B2DPoint& rBasePosition,
66 : const basegfx::B2DPoint& rSecondPosition,
67 : const Color& rHatchColor,
68 : double fTransparence,
69 : double fDiscreteGrow,
70 : double fDiscreteShrink,
71 : double fRotation,
72 : sal_uInt32 nBlinkTime,
73 : bool bAnimate)
74 : : OverlayObjectWithBasePosition(rBasePosition, rHatchColor),
75 : maSecondPosition(rSecondPosition),
76 : mfTransparence(fTransparence),
77 : mfDiscreteGrow(fDiscreteGrow),
78 : mfDiscreteShrink(fDiscreteShrink),
79 : mfRotation(fRotation),
80 : mnBlinkTime(nBlinkTime),
81 0 : mbOverlayState(false)
82 : {
83 0 : if(Application::GetSettings().GetStyleSettings().GetHighContrastMode())
84 : {
85 : // no animation in high contrast mode
86 0 : bAnimate = false;
87 : }
88 :
89 : // set AllowsAnimation flag to mark this object as animation capable
90 0 : mbAllowsAnimation = bAnimate;
91 :
92 : // #i53216# check blink time value range
93 0 : mnBlinkTime = impCheckBlinkTimeValueRange(mnBlinkTime);
94 0 : }
95 :
96 0 : void OverlayRectangle::setSecondPosition(const basegfx::B2DPoint& rNew)
97 : {
98 0 : if(rNew != maSecondPosition)
99 : {
100 : // remember new value
101 0 : maSecondPosition = rNew;
102 :
103 : // register change (after change)
104 0 : objectChange();
105 : }
106 0 : }
107 :
108 0 : void OverlayRectangle::setBlinkTime(sal_uInt32 nNew)
109 : {
110 0 : if(mnBlinkTime != nNew)
111 : {
112 : // remember new value
113 0 : mnBlinkTime = nNew;
114 :
115 : // #i53216# check blink time value range
116 0 : mnBlinkTime = impCheckBlinkTimeValueRange(mnBlinkTime);
117 :
118 : // register change (after change)
119 0 : objectChange();
120 : }
121 0 : }
122 :
123 0 : void OverlayRectangle::Trigger(sal_uInt32 nTime)
124 : {
125 0 : if(getOverlayManager())
126 : {
127 : // #i53216# produce event after nTime + x
128 0 : SetTime(nTime + mnBlinkTime);
129 :
130 : // switch state
131 0 : if(mbOverlayState)
132 : {
133 0 : mbOverlayState = false;
134 : }
135 : else
136 : {
137 0 : mbOverlayState = true;
138 : }
139 :
140 : // re-insert me as event
141 0 : getOverlayManager()->InsertEvent(this);
142 :
143 : // register change (after change)
144 0 : objectChange();
145 : }
146 0 : }
147 : } // end of namespace overlay
148 258 : } // end of namespace sdr
149 :
150 : //////////////////////////////////////////////////////////////////////////////
|