Bump version to 6.0-36
[LibreOffice.git] / slideshow / source / inc / shapeattributelayer.hxx
blob27ed2c1ae22d5cea5b4fd3b8096a1d0cd6845bb7
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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"
34 #include <stack>
35 #include <memory>
38 namespace slideshow
40 namespace internal
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
48 changed.
50 class State final
52 public:
54 /// Abstract, numerically encoded state ID
55 typedef ::std::size_t StateId;
58 class ShapeAttributeLayer;
60 typedef ::std::shared_ptr< ShapeAttributeLayer > ShapeAttributeLayerSharedPtr;
62 /** Encapsulates all modifiable attributes of a shape.
64 This class holds all modifiable attributes of a shape, and
65 at the same time provides means to layer attributes on top
66 of each other..
68 And yes, there's a reason why we even pass bools and ints
69 by const reference. Namely, that makes the set* methods
70 differ only in the value type, which greatly reduces
71 template variability (e.g. in AnimationFactory).
73 class ShapeAttributeLayer
75 public:
76 /** Create a ShapeAttributeLayer instance, with all
77 attributes set to default.
79 Furthermore, this constructor gets a pointer to a
80 child layer, which is used as the fallback (or the
81 base value) for all attributes
83 @param rChildLayer
84 Layer below this one
86 @attention
87 This method is only supposed to be called from Shape objects
89 explicit ShapeAttributeLayer( const ShapeAttributeLayerSharedPtr& rChildLayer );
91 // Children management methods
94 /** Revoke the given layer.
96 This method revokes the given layer from this object
97 or one of the children. That is, if this object does
98 have children, and the given layer is no direct child,
99 it is recursively passed to the children for removal.
101 @return true, if removal was successful.
103 @attention
104 This method is only supposed to be called from Shape objects
106 bool revokeChildLayer( const ShapeAttributeLayerSharedPtr& rChildLayer );
108 /** Query the child layer of this object.
110 @attention
111 This method is only supposed to be called from Shape objects
113 const ShapeAttributeLayerSharedPtr& getChildLayer() const;
115 /** Set the additive mode for possible child attributes
117 This method sets the additive mode for child
118 attributes. That is the way underlying attribute
119 layers are combined with this one (i.e. to overrule
120 lower layers, or how to combine the values). The
121 default is
122 css::animations::AnimationAdditiveMode::BASE,
123 which means, take the value of the underlying layers,
124 or from the model shape itself.
126 @param nMode
127 Must be one of
128 css::animations::AnimationAdditiveMode.
130 void setAdditiveMode( sal_Int16 nMode );
132 // Attribute methods
135 /** Query whether the width attribute is valid.
137 bool isWidthValid() const;
138 /** Query the current width of the shape
140 double getWidth() const;
141 /** Set the new width of the shape
143 @param rNewWidth
144 A negative width mirrors the shape.
146 void setWidth( const double& rNewWidth );
148 /** Query whether the height attribute is valid.
150 bool isHeightValid() const;
151 /** Query the current height of the shape
153 double getHeight() const;
154 /** Set the new height of the shape
156 @param rNewHeight
157 A negative height mirrors the shape.
159 void setHeight( const double& rNewHeight );
161 /** Set the new size of the shape
163 @param rNewSize
164 A negative size mirrors the shape.
166 void setSize( const ::basegfx::B2DSize& rNewSize );
168 /** Query whether the x position attribute is valid
170 bool isPosXValid() const;
171 /** Query the current x position of the shape.
173 The current x position of the shape is always relative
174 to the <em>center</em> of the shape (in contrast to
175 the Shape::getBounds() and Shape::getUpdateArea()
176 methods).
178 double getPosX() const;
179 /** Set the new x position of the shape
181 The current x position of the shape is always relative
182 to the <em>center</em> of the shape (in contrast to
183 the Shape::getBounds() and Shape::getUpdateArea()
184 methods).
186 void setPosX( const double& rNewX );
188 /** Query whether the y position attribute is valid
190 bool isPosYValid() const;
191 /** Query the current y position of the shape
193 The current y position of the shape is always relative
194 to the <em>center</em> of the shape (in contrast to
195 the Shape::getBounds() and Shape::getUpdateArea()
196 methods).
198 double getPosY() const;
199 /** Set the new y position of the shape
201 The current y position of the shape is always relative
202 to the <em>center</em> of the shape (in contrast to
203 the Shape::getBounds() and Shape::getUpdateArea()
204 methods).
206 void setPosY( const double& rNewY );
208 /** Set the new position of the shape
210 The current position of the shape is always relative
211 to the <em>center</em> of the shape (in contrast to
212 the Shape::getBounds() and Shape::getUpdateArea()
213 methods).
215 void setPosition( const ::basegfx::B2DPoint& rNewPos );
217 /** Query whether the rotation angle attribute is valid
219 bool isRotationAngleValid() const;
220 /** Query the current rotation angle of the shape
222 @return the rotation angle in degrees.
224 double getRotationAngle() const;
225 /** Set the new rotation angle of the shape
227 @param rNewAngle
228 New rotation angle in degrees.
230 void setRotationAngle( const double& rNewAngle );
232 /** Query whether the shear x angle attribute is valid
234 bool isShearXAngleValid() const;
235 /** Query the current shear angle at the x axis of the shape
237 @return the shear angle in degrees.
239 double getShearXAngle() const;
240 /** Set the new shear angle at the x axis of the shape
242 @param rNewAngle
243 New shear angle in radians.
245 void setShearXAngle( const double& rNewAngle );
247 /** Query whether the shear y angle attribute is valid
249 bool isShearYAngleValid() const;
250 /** Query the current shear angle at the y axis of the shape
252 @return the shear angle in degrees.
254 double getShearYAngle() const;
255 /** Set the new shear angle at the y axis of the shape
257 @param rNewAngle
258 New shear angle in radians.
260 void setShearYAngle( const double& rNewAngle );
262 /** Query whether the alpha attribute is valid
264 bool isAlphaValid() const;
265 /** Query the current alpha value of the shape
267 double getAlpha() const;
268 /** Set the new alpha value of the shape
270 @param rNewValue
271 New alpha value, must be in the [0,1] range
273 void setAlpha( const double& rNewValue );
275 /** Query whether the clip attribute is valid
277 bool isClipValid() const;
278 /** Query the current clip polygon of the shape
280 ::basegfx::B2DPolyPolygon getClip() const;
281 /** Set the new clip polygon of the shape
283 @param rNewClip
284 New clip polygon, is interpreted in shape view coordinates, but
285 relative to the shape (i.e. the origin of the shape coincides
286 with the origin of the clip polygon).
288 void setClip( const ::basegfx::B2DPolyPolygon& rNewClip );
290 /** Query whether the dim color attribute is valid
292 The dim color globally 'dims' the shape towards that
293 color
295 bool isDimColorValid() const;
296 /** Get the dim color for the whole shape.
298 RGBColor getDimColor() const;
299 /** Set the dim color globally for the whole shape.
301 void setDimColor( const RGBColor& nNewColor );
303 /** Query whether the fill color attribute is valid
305 bool isFillColorValid() const;
306 /** Get the fill color for the whole shape.
308 If there's no unique fill color, the color from the
309 first filled polygon is returned.
311 RGBColor getFillColor() const;
312 /** Set the fill color globally for the whole shape.
314 void setFillColor( const RGBColor& nNewColor );
316 /** Query whether the line color attribute is valid
318 bool isLineColorValid() const;
319 /** Get the line color for the whole shape.
321 If there's no unique line color, the color from the
322 first line is returned.
324 RGBColor getLineColor() const;
325 /** Set the line color globally for the whole shape.
327 void setLineColor( const RGBColor& nNewColor );
329 /** Query whether the fill mode attribute is valid
331 bool isFillStyleValid() const;
332 /** Get the current fill mode for polygon fillings.
334 @returns the current style
336 sal_Int16 getFillStyle() const;
337 /** Changes polygon fillings.
339 void setFillStyle( const sal_Int16& rStyle );
341 /** Query whether the line mode attribute is valid
343 bool isLineStyleValid() const;
344 /** Get the current line mode for line drawing.
346 @returns the current line style
348 sal_Int16 getLineStyle() const;
349 /** Set line style for the whole shape
351 void setLineStyle( const sal_Int16& rStyle );
353 /** Query whether the visibility state attribute is valid
355 bool isVisibilityValid() const;
356 /** Get the current shape visibility.
358 @returns true for visible, false for invisible.
360 bool getVisibility() const;
361 /** Set the shape visibility
363 void setVisibility( const bool& bVisible );
365 /** Query whether the char color attribute is valid
367 bool isCharColorValid() const;
368 /** Get the text color for the whole shape.
370 If there's no unique text color, the color from the
371 first text drawn is returned.
373 RGBColor getCharColor() const;
374 /** Set the text color globally for the whole shape.
376 void setCharColor( const RGBColor& nNewColor );
378 /** Query whether the char rotation angle attribute is valid
380 bool isCharRotationAngleValid() const;
381 /** Query the current text rotation angle of the shape
383 @return the text rotation angle in degrees.
385 double getCharRotationAngle() const;
386 /** Set the new text rotation angle of the shape
388 @param rNewAngle
389 New text rotation angle in degrees.
391 void setCharRotationAngle( const double& rNewAngle );
393 /** Query whether the char weight attribute is valid
395 bool isCharWeightValid() const;
396 /** Get the current char weight value for the whole shape.
398 @returns the value for the char weight. The value must
399 be out of the css::awt::FontWeight
400 constant group.
402 double getCharWeight() const;
403 /** Set the char weight globally for the whole shape.
405 The value must be out of the
406 css::awt::FontWeight constant group.
408 void setCharWeight( const double& rStyle );
410 /** Query whether the underline mode attribute is valid
412 bool isUnderlineModeValid() const;
413 /** Get the current text underline status for the whole shape.
415 If there is no unique underline status, false is returned.
417 @returns true for underlined text, false for normal.
419 sal_Int16 getUnderlineMode() const;
420 /** Set the underline status globally for the whole shape
422 void setUnderlineMode( const sal_Int16& bUnderline );
424 /** Query whether the font family attribute is valid
426 bool isFontFamilyValid() const;
427 /** Get the current text font family for the whole shape.
429 If there is no unique font family, the font family of
430 the first text of the shape is returned.
432 OUString getFontFamily() const;
433 /** Set the text font family name globally for the whole shape
435 void setFontFamily( const OUString& rName );
437 /** Query whether the italic mode attribute is valid
439 bool isCharPostureValid() const;
440 /** Get the current text italic style for the whole shape.
442 @returns the italic style. The value returned is one
443 of the css::awt::FontSlant enums
445 sal_Int16 getCharPosture() const;
446 /** Set the italic style globally for the whole shape.
448 The value must be one of the
449 css::awt::FontSlant enums.
451 void setCharPosture( const sal_Int16& rStyle );
453 /** Query whether the char scaling attribute is valid
455 bool isCharScaleValid() const;
456 /** Query the current char scaling attribute globally for
457 the shape.
459 The char scaling changes the scale of the whole shape
460 text (uniformely, i.e. both in x and in y direction).
462 double getCharScale() const;
463 /** Set the new char scale globally for the shape
465 @param rNewScale
466 New char scale
468 void setCharScale( const double& rNewScale );
470 // State change query methods
473 State::StateId getTransformationState() const;
474 State::StateId getClipState() const;
475 State::StateId getAlphaState() const;
476 State::StateId getPositionState() const;
477 State::StateId getContentState() const;
478 State::StateId getVisibilityState() const;
480 private:
481 // default copy/assignment operator is okay
482 // ShapeAttributeLayer(const ShapeAttributeLayer&);
483 // ShapeAttributeLayer& operator=( const ShapeAttributeLayer& );
485 bool haveChild() const { return static_cast< bool >(mpChild); }
486 void updateStateIds();
488 template< typename T > T calcValue( const T& rCurrValue,
489 bool bThisInstanceValid,
490 bool (ShapeAttributeLayer::*pIsValid)() const,
491 T (ShapeAttributeLayer::*pGetValue)() const ) const;
493 ShapeAttributeLayerSharedPtr mpChild; // may be NULL
495 ::basegfx::B2DSize maSize;
496 ::basegfx::B2DPoint maPosition;
497 ::basegfx::B2DPolyPolygon maClip;
499 OUString maFontFamily;
501 double mnRotationAngle;
502 double mnShearXAngle;
503 double mnShearYAngle;
504 double mnAlpha;
505 double mnCharRotationAngle;
506 double mnCharScale;
507 double mnCharWeight;
509 css::drawing::FillStyle meFillStyle;
510 css::drawing::LineStyle meLineStyle;
511 css::awt::FontSlant meCharPosture;
512 sal_Int16 mnUnderlineMode;
514 RGBColor maDimColor;
515 RGBColor maFillColor;
516 RGBColor maLineColor;
517 RGBColor maCharColor;
519 State::StateId mnTransformationState;
520 State::StateId mnClipState;
521 State::StateId mnAlphaState;
522 State::StateId mnPositionState;
523 State::StateId mnContentState;
524 State::StateId mnVisibilityState;
526 sal_Int16 mnAdditiveMode;
528 bool mbVisibility : 1;
530 bool mbWidthValid : 1;
531 bool mbHeightValid : 1;
532 bool mbPosXValid : 1;
533 bool mbPosYValid : 1;
534 bool mbClipValid : 1;
536 bool mbFontFamilyValid : 1;
538 bool mbRotationAngleValid : 1;
539 bool mbShearXAngleValid : 1;
540 bool mbShearYAngleValid : 1;
542 bool mbAlphaValid : 1;
544 bool mbCharRotationAngleValid: 1;
545 bool mbCharScaleValid : 1;
547 bool mbDimColorValid : 1;
548 bool mbFillColorValid : 1;
549 bool mbLineColorValid : 1;
550 bool mbCharColorValid : 1;
552 bool mbFillStyleValid : 1;
553 bool mbLineStyleValid : 1;
554 bool mbCharWeightValid : 1;
555 bool mbUnderlineModeValid : 1;
556 bool mbCharPostureValid : 1;
557 bool mbVisibilityValid : 1;
563 #endif // INCLUDED_SLIDESHOW_SOURCE_INC_SHAPEATTRIBUTELAYER_HXX
565 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */