| 1 | /*! |
| 2 | * \file path_effect.hpp |
| 3 | * \brief file path_effect.hpp |
| 4 | * |
| 5 | * Copyright 2019 by Intel. |
| 6 | * |
| 7 | * Contact: kevin.rogovin@gmail.com |
| 8 | * |
| 9 | * This Source Code Form is subject to the |
| 10 | * terms of the Mozilla Public License, v. 2.0. |
| 11 | * If a copy of the MPL was not distributed with |
| 12 | * this file, You can obtain one at |
| 13 | * http://mozilla.org/MPL/2.0/. |
| 14 | * |
| 15 | * \author Kevin Rogovin <kevin.rogovin@gmail.com> |
| 16 | * |
| 17 | */ |
| 18 | |
| 19 | #ifndef FASTUIDRAW_PATH_EFFECT_HPP |
| 20 | #define FASTUIDRAW_PATH_EFFECT_HPP |
| 21 | |
| 22 | #include <fastuidraw/tessellated_path.hpp> |
| 23 | |
| 24 | namespace fastuidraw |
| 25 | { |
| 26 | /*!\addtogroup Paths |
| 27 | * @{ |
| 28 | */ |
| 29 | |
| 30 | /*! |
| 31 | * \brief |
| 32 | * A \ref PathEffect allows one to process a sequence of |
| 33 | * \ref TessellatedPath::segment_chain, \ref |
| 34 | * TessellatedPath::join and \ref |
| 35 | * TessellatedPath::cap values to produce a |
| 36 | * new sequence of such values for the purpose of effecting |
| 37 | * stroking. |
| 38 | */ |
| 39 | class PathEffect:noncopyable |
| 40 | { |
| 41 | public: |
| 42 | /*! |
| 43 | * Conveniance typedef |
| 44 | */ |
| 45 | typedef TessellatedPath::segment_chain segment_chain; |
| 46 | |
| 47 | /*! |
| 48 | * Conveniance typedef |
| 49 | */ |
| 50 | typedef TessellatedPath::segment segment; |
| 51 | |
| 52 | /*! |
| 53 | * Conveniance typedef |
| 54 | */ |
| 55 | typedef TessellatedPath::join join; |
| 56 | |
| 57 | /*! |
| 58 | * Conveniance typedef |
| 59 | */ |
| 60 | typedef TessellatedPath::cap cap; |
| 61 | |
| 62 | /*! |
| 63 | * \brief |
| 64 | * A \ref Storage is to where \ref TessellatedPath::segment, |
| 65 | * \ref TessellatedPath::join and \ref TessellatedPath::cap |
| 66 | * values are stored from being processed by a \ref PathEffect. |
| 67 | */ |
| 68 | class Storage:noncopyable |
| 69 | { |
| 70 | public: |
| 71 | Storage(void); |
| 72 | ~Storage(); |
| 73 | |
| 74 | /*! |
| 75 | * Clear the Storage of all content |
| 76 | */ |
| 77 | void |
| 78 | clear(void); |
| 79 | |
| 80 | /*! |
| 81 | * Begin a \ref segment_chain. |
| 82 | * \param prev_segment if non-null, then the chain will have |
| 83 | * that \ref segment_chain::m_prev_to_start |
| 84 | * will point to a -COPY- of *prev_segment. |
| 85 | */ |
| 86 | Storage& |
| 87 | begin_chain(const TessellatedPath::segment *prev_segment); |
| 88 | |
| 89 | /*! |
| 90 | * Add a segment to the current chain being built. |
| 91 | * \param segment segment to add |
| 92 | */ |
| 93 | Storage& |
| 94 | add_segment(const TessellatedPath::segment &segment); |
| 95 | |
| 96 | /*! |
| 97 | * Add a join to the \ref Storage |
| 98 | * \param join \ref TessellatedPath::join to add |
| 99 | */ |
| 100 | Storage& |
| 101 | add_join(const join &join); |
| 102 | |
| 103 | /*! |
| 104 | * Add a cap to the \ref Storage |
| 105 | * \param cap \ref TessellatedPath::cap to add |
| 106 | */ |
| 107 | Storage& |
| 108 | add_cap(const cap &cap); |
| 109 | |
| 110 | /*! |
| 111 | * returns the number of \ref segment_chain the |
| 112 | * \ref Storage has. |
| 113 | */ |
| 114 | unsigned int |
| 115 | number_chains(void) const; |
| 116 | |
| 117 | /*! |
| 118 | * Returns the named \ref segment_chain of the storage. |
| 119 | * The return value is only guaranteed to be valid until |
| 120 | * the next call to add_segment() or begin_chain(). |
| 121 | * \param I which \ref segment_chain with 0 <= I <= number_chains(). |
| 122 | */ |
| 123 | segment_chain |
| 124 | chain(unsigned int I) const; |
| 125 | |
| 126 | /*! |
| 127 | * Returns the joins of the \ref Storage added by add_join(). |
| 128 | * The return value is only guaranteed to be valid until the |
| 129 | * next call to add_join(). |
| 130 | */ |
| 131 | c_array<const join> |
| 132 | joins(void) const; |
| 133 | |
| 134 | /*! |
| 135 | * Returns the caps of the \ref Storage added by add_cap(). |
| 136 | * The return value is only guaranteed to be valid until the |
| 137 | * next call to add_cap(). |
| 138 | */ |
| 139 | c_array<const cap> |
| 140 | caps(void) const; |
| 141 | |
| 142 | private: |
| 143 | void *m_d; |
| 144 | }; |
| 145 | |
| 146 | virtual |
| 147 | ~PathEffect() |
| 148 | {} |
| 149 | |
| 150 | /*! |
| 151 | * Provided as a template conveniance, equivalent to |
| 152 | * \code |
| 153 | * for (; begin != end; ++begin) |
| 154 | * { |
| 155 | * process_chain(*begin, dst); |
| 156 | * } |
| 157 | * \endcode |
| 158 | * \param begin iterator to first element to process |
| 159 | * \param end iterator to one past last element to process |
| 160 | * \param dst \ref Storage on which to place values |
| 161 | */ |
| 162 | template<typename iterator> |
| 163 | void |
| 164 | process_chains(iterator begin, iterator end, Storage &dst) const |
| 165 | { |
| 166 | for (; begin != end; ++begin) |
| 167 | { |
| 168 | process_chain(*begin, dst); |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | /*! |
| 173 | * Provided as a template conveniance, equivalent to |
| 174 | * \code |
| 175 | * for (; begin != end; ++begin) |
| 176 | * { |
| 177 | * process_join(*begin, dst); |
| 178 | * } |
| 179 | * \endcode |
| 180 | * \param begin iterator to first element to process |
| 181 | * \param end iterator to one past last element to process |
| 182 | * \param dst \ref Storage on which to place values |
| 183 | */ |
| 184 | template<typename iterator> |
| 185 | void |
| 186 | process_joins(iterator begin, iterator end, Storage &dst) const |
| 187 | { |
| 188 | for (; begin != end; ++begin) |
| 189 | { |
| 190 | process_join(*begin, dst); |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | /*! |
| 195 | * Provided as a template conveniance, equivalent to |
| 196 | * \code |
| 197 | * for (; begin != end; ++begin) |
| 198 | * { |
| 199 | * process_cap(*begin, dst); |
| 200 | * } |
| 201 | * \endcode |
| 202 | * \param begin iterator to first element to process |
| 203 | * \param end iterator to one past last element to process |
| 204 | * \param dst \ref Storage on which to place values |
| 205 | */ |
| 206 | template<typename iterator> |
| 207 | void |
| 208 | process_caps(iterator begin, iterator end, Storage &dst) const |
| 209 | { |
| 210 | for (; begin != end; ++begin) |
| 211 | { |
| 212 | process_cap(*begin, dst); |
| 213 | } |
| 214 | } |
| 215 | |
| 216 | /*! |
| 217 | * To be implemented by a derived class to process a \ref |
| 218 | * segment_chain value placing the results onto a \ref |
| 219 | * PathEffect::Storage |
| 220 | * \param chain \ref segment_chain value to process |
| 221 | * \param dst \ref PathEffect::Storage on which to place values |
| 222 | */ |
| 223 | virtual |
| 224 | void |
| 225 | process_chain(const segment_chain &chain, Storage &dst) const = 0; |
| 226 | |
| 227 | /*! |
| 228 | * To be implemented by a derived class to process a \ref |
| 229 | * TessellatedPath::join value placing the results onto a |
| 230 | * \ref PathEffect::Storage |
| 231 | * \param join \ref TessellatedPath::join value to process |
| 232 | * \param dst \ref PathEffect::Storage on which to place values |
| 233 | */ |
| 234 | virtual |
| 235 | void |
| 236 | process_join(const TessellatedPath::join &join, Storage &dst) const = 0; |
| 237 | |
| 238 | /*! |
| 239 | * To be implemented by a derived class to process a \ref |
| 240 | * TessellatedPath::cap value placing the results onto a |
| 241 | * \ref PathEffect::Storage |
| 242 | * \param cap \ref TessellatedPath::cap value to process |
| 243 | * \param dst \ref PathEffect::Storage on which to place values |
| 244 | */ |
| 245 | virtual |
| 246 | void |
| 247 | process_cap(const TessellatedPath::cap &cap, Storage &dst) const = 0; |
| 248 | }; |
| 249 | |
| 250 | /*! @} */ |
| 251 | } |
| 252 | |
| 253 | #endif |
| 254 | |