File indexing completed on 2024-05-12 15:58:48
0001 /* 0002 * SPDX-FileCopyrightText: 2013 Dmitry Kazakov <dimula73@gmail.com> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef __KIS_WRAPPED_VLINE_ITERATOR_H 0008 #define __KIS_WRAPPED_VLINE_ITERATOR_H 0009 0010 #include "kis_iterator_ng.h" 0011 #include "kis_wrapped_rect.h" 0012 0013 class WrappedVLineIteratorStrategy 0014 { 0015 private: 0016 static const int TOP_OFFSET = 0; 0017 static const int BOTTOM_OFFSET = 2; 0018 0019 public: 0020 typedef KisVLineIteratorSP IteratorTypeSP; 0021 0022 WrappedVLineIteratorStrategy() 0023 : m_iteratorColumnStart(KisWrappedRect::TOPLEFT), 0024 m_lastColumnCoord(-1) 0025 { 0026 } 0027 0028 inline QSize originalRectToColumnsRows(const QRect &rect) { 0029 return QSize(rect.height(), rect.width()); 0030 } 0031 0032 inline QPoint columnRowToXY(const QPoint &pt) const { 0033 return QPoint(pt.y(), pt.x()); 0034 } 0035 0036 inline IteratorTypeSP createIterator(KisDataManager *dataManager, 0037 const QRect &rc, 0038 qint32 offsetX, qint32 offsetY, 0039 bool writable, 0040 KisIteratorCompleteListener *completeListener) { 0041 0042 return new KisVLineIterator2(dataManager, 0043 rc.x(), rc.y(), 0044 rc.height(), 0045 offsetX, offsetY, 0046 writable, 0047 completeListener); 0048 } 0049 0050 inline void completeInitialization(QVector<IteratorTypeSP> *iterators, 0051 KisWrappedRect *splitRect) { 0052 m_splitRect = splitRect; 0053 m_iterators = iterators; 0054 0055 m_lastColumnCoord = m_splitRect->topLeft().right(); 0056 } 0057 0058 inline IteratorTypeSP leftColumnIterator() const { 0059 return m_iterators->at(m_iteratorColumnStart + TOP_OFFSET); 0060 } 0061 0062 inline IteratorTypeSP rightColumnIterator() const { 0063 return m_iterators->at(m_iteratorColumnStart + BOTTOM_OFFSET); 0064 } 0065 0066 inline bool trySwitchIteratorStripe() { 0067 bool needSwitching = leftColumnIterator()->x() == m_lastColumnCoord; 0068 0069 if (needSwitching) { 0070 if (m_iteratorColumnStart == KisWrappedRect::TOPLEFT && 0071 m_iterators->at(KisWrappedRect::TOPRIGHT)) { 0072 0073 m_iteratorColumnStart = KisWrappedRect::TOPRIGHT; 0074 m_lastColumnCoord = m_splitRect->topRight().right(); 0075 } else /* if (m_iteratorColumnStart == KisWrappedRect::TOPRIGHT) */ { 0076 m_iteratorColumnStart = KisWrappedRect::TOPLEFT; 0077 m_lastColumnCoord = m_splitRect->topLeft().right(); 0078 0079 Q_FOREACH (IteratorTypeSP it, *m_iterators) { 0080 if (it) { 0081 it->resetColumnPos(); 0082 } 0083 } 0084 } 0085 } 0086 0087 return needSwitching; 0088 } 0089 0090 inline void iteratorsToNextRow() { 0091 leftColumnIterator()->nextColumn(); 0092 if (rightColumnIterator()) { 0093 rightColumnIterator()->nextColumn(); 0094 } 0095 } 0096 0097 inline bool trySwitchColumnForced() { 0098 leftColumnIterator()->resetPixelPos(); 0099 if (rightColumnIterator()) { 0100 rightColumnIterator()->resetPixelPos(); 0101 } 0102 0103 return true; 0104 } 0105 0106 private: 0107 KisWrappedRect *m_splitRect; 0108 QVector<IteratorTypeSP> *m_iterators; 0109 int m_iteratorColumnStart; // may be either KisWrappedRect::TOPLEFT or KisWrappedRect::TOPRIGHT 0110 int m_lastColumnCoord; 0111 }; 0112 0113 #include "kis_wrapped_line_iterator_base.h" 0114 typedef KisWrappedLineIteratorBase<WrappedVLineIteratorStrategy, KisVLineIteratorNG> KisWrappedVLineIterator; 0115 0116 0117 #endif /* __KIS_WRAPPED_VLINE_ITERATOR_H */