1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_SLIDESHOW_SOURCE_INC_SHAPEATTRIBUTELAYER_HXX
21 #define INCLUDED_SLIDESHOW_SOURCE_INC_SHAPEATTRIBUTELAYER_HXX
23 #include <com/sun/star/drawing/FillStyle.hpp>
24 #include <com/sun/star/drawing/LineStyle.hpp>
25 #include <com/sun/star/awt/FontSlant.hpp>
27 #include <basegfx/vector/b2dsize.hxx>
28 #include <basegfx/point/b2dpoint.hxx>
29 #include <basegfx/range/b2drectangle.hxx>
30 #include <basegfx/polygon/b2dpolypolygon.hxx>
32 #include "rgbcolor.hxx"
43 /** This interface represents a stateful object.
45 The state ID returned by the getStateId() method
46 abstractly encodes the object's state. When this ID
47 changes, clients can assume that the object's state has
55 /// Abstract, numerically encoded state ID
56 typedef ::std::size_t StateId
;
59 class ShapeAttributeLayer
;
61 typedef ::std::shared_ptr
< ShapeAttributeLayer
> ShapeAttributeLayerSharedPtr
;
63 /** Encapsulates all modifiable attributes of a shape.
65 This class holds all modifiable attributes of a shape, and
66 at the same time provides means to layer attributes on top
69 And yes, there's a reason why we even pass bools and ints
70 by const reference. Namely, that makes the set* methods
71 differ only in the value type, which greatly reduces
72 template variability (e.g. in AnimationFactory).
74 class ShapeAttributeLayer
77 /** Create a ShapeAttributeLayer instance, with all
78 attributes set to default.
80 Furthermore, this constructor gets a pointer to a
81 child layer, which is used as the fallback (or the
82 base value) for all attributes
88 This method is only supposed to be called from Shape objects
90 explicit ShapeAttributeLayer( const ShapeAttributeLayerSharedPtr
& rChildLayer
);
92 // Children management methods
95 /** Revoke the given layer.
97 This method revokes the given layer from this object
98 or one of the children. That is, if this object does
99 have children, and the given layer is no direct child,
100 it is recursively passed to the children for removal.
102 @return true, if removal was successful.
105 This method is only supposed to be called from Shape objects
107 bool revokeChildLayer( const ShapeAttributeLayerSharedPtr
& rChildLayer
);
109 /** Query the child layer of this object.
112 This method is only supposed to be called from Shape objects
114 const ShapeAttributeLayerSharedPtr
& getChildLayer() const;
116 /** Set the additive mode for possible child attributes
118 This method sets the additive mode for child
119 attributes. That is the way underlying attribute
120 layers are combined with this one (i.e. to overrule
121 lower layers, or how to combine the values). The
123 css::animations::AnimationAdditiveMode::BASE,
124 which means, take the value of the underlying layers,
125 or from the model shape itself.
129 css::animations::AnimationAdditiveMode.
131 void setAdditiveMode( sal_Int16 nMode
);
136 /** Query whether the width attribute is valid.
138 bool isWidthValid() const;
139 /** Query the current width of the shape
141 double getWidth() const;
142 /** Set the new width of the shape
145 A negative width mirrors the shape.
147 void setWidth( const double& rNewWidth
);
149 /** Query whether the height attribute is valid.
151 bool isHeightValid() const;
152 /** Query the current height of the shape
154 double getHeight() const;
155 /** Set the new height of the shape
158 A negative height mirrors the shape.
160 void setHeight( const double& rNewHeight
);
162 /** Set the new size of the shape
165 A negative size mirrors the shape.
167 void setSize( const ::basegfx::B2DSize
& rNewSize
);
169 /** Query whether the x position attribute is valid
171 bool isPosXValid() const;
172 /** Query the current x position of the shape.
174 The current x position of the shape is always relative
175 to the <em>center</em> of the shape (in contrast to
176 the Shape::getBounds() and Shape::getUpdateArea()
179 double getPosX() const;
180 /** Set the new x position of the shape
182 The current x position of the shape is always relative
183 to the <em>center</em> of the shape (in contrast to
184 the Shape::getBounds() and Shape::getUpdateArea()
187 void setPosX( const double& rNewX
);
189 /** Query whether the y position attribute is valid
191 bool isPosYValid() const;
192 /** Query the current y position of the shape
194 The current y position of the shape is always relative
195 to the <em>center</em> of the shape (in contrast to
196 the Shape::getBounds() and Shape::getUpdateArea()
199 double getPosY() const;
200 /** Set the new y position of the shape
202 The current y position of the shape is always relative
203 to the <em>center</em> of the shape (in contrast to
204 the Shape::getBounds() and Shape::getUpdateArea()
207 void setPosY( const double& rNewY
);
209 /** Set the new position of the shape
211 The current position of the shape is always relative
212 to the <em>center</em> of the shape (in contrast to
213 the Shape::getBounds() and Shape::getUpdateArea()
216 void setPosition( const ::basegfx::B2DPoint
& rNewPos
);
218 /** Query whether the rotation angle attribute is valid
220 bool isRotationAngleValid() const;
221 /** Query the current rotation angle of the shape
223 @return the rotation angle in degrees.
225 double getRotationAngle() const;
226 /** Set the new rotation angle of the shape
229 New rotation angle in degrees.
231 void setRotationAngle( const double& rNewAngle
);
233 /** Query whether the shear x angle attribute is valid
235 bool isShearXAngleValid() const;
236 /** Query the current shear angle at the x axis of the shape
238 @return the shear angle in degrees.
240 double getShearXAngle() const;
241 /** Set the new shear angle at the x axis of the shape
244 New shear angle in radians.
246 void setShearXAngle( const double& rNewAngle
);
248 /** Query whether the shear y angle attribute is valid
250 bool isShearYAngleValid() const;
251 /** Query the current shear angle at the y axis of the shape
253 @return the shear angle in degrees.
255 double getShearYAngle() const;
256 /** Set the new shear angle at the y axis of the shape
259 New shear angle in radians.
261 void setShearYAngle( const double& rNewAngle
);
263 /** Query whether the alpha attribute is valid
265 bool isAlphaValid() const;
266 /** Query the current alpha value of the shape
268 double getAlpha() const;
269 /** Set the new alpha value of the shape
272 New alpha value, must be in the [0,1] range
274 void setAlpha( const double& rNewValue
);
276 /** Query whether the clip attribute is valid
278 bool isClipValid() const;
279 /** Query the current clip polygon of the shape
281 ::basegfx::B2DPolyPolygon
getClip() const;
282 /** Set the new clip polygon of the shape
285 New clip polygon, is interpreted in shape view coordinates, but
286 relative to the shape (i.e. the origin of the shape coincides
287 with the origin of the clip polygon).
289 void setClip( const ::basegfx::B2DPolyPolygon
& rNewClip
);
291 /** Query whether the dim color attribute is valid
293 The dim color globally 'dims' the shape towards that
296 bool isDimColorValid() const;
297 /** Get the dim color for the whole shape.
299 RGBColor
getDimColor() const;
300 /** Set the dim color globally for the whole shape.
302 void setDimColor( const RGBColor
& nNewColor
);
304 /** Query whether the fill color attribute is valid
306 bool isFillColorValid() const;
307 /** Get the fill color for the whole shape.
309 If there's no unique fill color, the color from the
310 first filled polygon is returned.
312 RGBColor
getFillColor() const;
313 /** Set the fill color globally for the whole shape.
315 void setFillColor( const RGBColor
& nNewColor
);
317 /** Query whether the line color attribute is valid
319 bool isLineColorValid() const;
320 /** Get the line color for the whole shape.
322 If there's no unique line color, the color from the
323 first line is returned.
325 RGBColor
getLineColor() const;
326 /** Set the line color globally for the whole shape.
328 void setLineColor( const RGBColor
& nNewColor
);
330 /** Query whether the fill mode attribute is valid
332 bool isFillStyleValid() const;
333 /** Get the current fill mode for polygon fillings.
335 @returns the current style
337 sal_Int16
getFillStyle() const;
338 /** Changes polygon fillings.
340 void setFillStyle( const sal_Int16
& rStyle
);
342 /** Query whether the line mode attribute is valid
344 bool isLineStyleValid() const;
345 /** Get the current line mode for line drawing.
347 @returns the current line style
349 sal_Int16
getLineStyle() const;
350 /** Set line style for the whole shape
352 void setLineStyle( const sal_Int16
& rStyle
);
354 /** Query whether the visibility state attribute is valid
356 bool isVisibilityValid() const;
357 /** Get the current shape visibility.
359 @returns true for visible, false for invisible.
361 bool getVisibility() const;
362 /** Set the shape visibility
364 void setVisibility( const bool& bVisible
);
366 /** Query whether the char color attribute is valid
368 bool isCharColorValid() const;
369 /** Get the text color for the whole shape.
371 If there's no unique text color, the color from the
372 first text drawn is returned.
374 RGBColor
getCharColor() const;
375 /** Set the text color globally for the whole shape.
377 void setCharColor( const RGBColor
& nNewColor
);
379 /** Query whether the char rotation angle attribute is valid
381 bool isCharRotationAngleValid() const;
382 /** Query the current text rotation angle of the shape
384 @return the text rotation angle in degrees.
386 double getCharRotationAngle() const;
387 /** Set the new text rotation angle of the shape
390 New text rotation angle in degrees.
392 void setCharRotationAngle( const double& rNewAngle
);
394 /** Query whether the char weight attribute is valid
396 bool isCharWeightValid() const;
397 /** Get the current char weight value for the whole shape.
399 @returns the value for the char weight. The value must
400 be out of the css::awt::FontWeight
403 double getCharWeight() const;
404 /** Set the char weight globally for the whole shape.
406 The value must be out of the
407 css::awt::FontWeight constant group.
409 void setCharWeight( const double& rStyle
);
411 /** Query whether the underline mode attribute is valid
413 bool isUnderlineModeValid() const;
414 /** Get the current text underline status for the whole shape.
416 If there is no unique underline status, false is returned.
418 @returns true for underlined text, false for normal.
420 sal_Int16
getUnderlineMode() const;
421 /** Set the underline status globally for the whole shape
423 void setUnderlineMode( const sal_Int16
& bUnderline
);
425 /** Query whether the font family attribute is valid
427 bool isFontFamilyValid() const;
428 /** Get the current text font family for the whole shape.
430 If there is no unique font family, the font family of
431 the first text of the shape is returned.
433 OUString
getFontFamily() const;
434 /** Set the text font family name globally for the whole shape
436 void setFontFamily( const OUString
& rName
);
438 /** Query whether the italic mode attribute is valid
440 bool isCharPostureValid() const;
441 /** Get the current text italic style for the whole shape.
443 @returns the italic style. The value returned is one
444 of the css::awt::FontSlant enums
446 sal_Int16
getCharPosture() const;
447 /** Set the italic style globally for the whole shape.
449 The value must be one of the
450 css::awt::FontSlant enums.
452 void setCharPosture( const sal_Int16
& rStyle
);
454 /** Query whether the char scaling attribute is valid
456 bool isCharScaleValid() const;
457 /** Query the current char scaling attribute globally for
460 The char scaling changes the scale of the whole shape
461 text (uniformely, i.e. both in x and in y direction).
463 double getCharScale() const;
464 /** Set the new char scale globally for the shape
469 void setCharScale( const double& rNewScale
);
471 // State change query methods
474 State::StateId
getTransformationState() const;
475 State::StateId
getClipState() const;
476 State::StateId
getAlphaState() const;
477 State::StateId
getPositionState() const;
478 State::StateId
getContentState() const;
479 State::StateId
getVisibilityState() const;
482 // default copy/assignment operator is okay
483 // ShapeAttributeLayer(const ShapeAttributeLayer&);
484 // ShapeAttributeLayer& operator=( const ShapeAttributeLayer& );
486 bool haveChild() const { return static_cast< bool >(mpChild
); }
487 void updateStateIds();
489 template< typename T
> T
calcValue( const T
& rCurrValue
,
490 bool bThisInstanceValid
,
491 bool (ShapeAttributeLayer::*pIsValid
)() const,
492 T (ShapeAttributeLayer::*pGetValue
)() const ) const;
494 ShapeAttributeLayerSharedPtr mpChild
; // may be NULL
496 ::basegfx::B2DSize maSize
;
497 ::basegfx::B2DPoint maPosition
;
498 ::basegfx::B2DPolyPolygon maClip
;
500 OUString maFontFamily
;
502 double mnRotationAngle
;
503 double mnShearXAngle
;
504 double mnShearYAngle
;
506 double mnCharRotationAngle
;
510 css::drawing::FillStyle meFillStyle
;
511 css::drawing::LineStyle meLineStyle
;
512 css::awt::FontSlant meCharPosture
;
513 sal_Int16 mnUnderlineMode
;
516 RGBColor maFillColor
;
517 RGBColor maLineColor
;
518 RGBColor maCharColor
;
520 State::StateId mnTransformationState
;
521 State::StateId mnClipState
;
522 State::StateId mnAlphaState
;
523 State::StateId mnPositionState
;
524 State::StateId mnContentState
;
525 State::StateId mnVisibilityState
;
527 sal_Int16 mnAdditiveMode
;
529 bool mbVisibility
: 1;
531 bool mbWidthValid
: 1;
532 bool mbHeightValid
: 1;
533 bool mbPosXValid
: 1;
534 bool mbPosYValid
: 1;
535 bool mbClipValid
: 1;
537 bool mbFontFamilyValid
: 1;
539 bool mbRotationAngleValid
: 1;
540 bool mbShearXAngleValid
: 1;
541 bool mbShearYAngleValid
: 1;
543 bool mbAlphaValid
: 1;
545 bool mbCharRotationAngleValid
: 1;
546 bool mbCharScaleValid
: 1;
548 bool mbDimColorValid
: 1;
549 bool mbFillColorValid
: 1;
550 bool mbLineColorValid
: 1;
551 bool mbCharColorValid
: 1;
553 bool mbFillStyleValid
: 1;
554 bool mbLineStyleValid
: 1;
555 bool mbCharWeightValid
: 1;
556 bool mbUnderlineModeValid
: 1;
557 bool mbCharPostureValid
: 1;
558 bool mbVisibilityValid
: 1;
564 #endif // INCLUDED_SLIDESHOW_SOURCE_INC_SHAPEATTRIBUTELAYER_HXX
566 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */