1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
|
/*
* Copyright (c) 2013 Dmitry Kazakov <dimula73@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef __KIS_WRAPPED_HLINE_ITERATOR_H
#define __KIS_WRAPPED_HLINE_ITERATOR_H
#include "kis_iterator_ng.h"
#include "kis_wrapped_rect.h"
class WrappedHLineIteratorStrategy
{
public:
typedef KisHLineIteratorSP IteratorTypeSP;
WrappedHLineIteratorStrategy()
: m_iteratorRowStart(KisWrappedRect::TOPLEFT),
m_lastRowCoord(-1)
{
}
inline QSize originalRectToColumnsRows(const QRect &rect) {
return rect.size();
}
inline QPoint columnRowToXY(const QPoint &pt) const {
return pt;
}
inline IteratorTypeSP createIterator(KisDataManager *dataManager,
const QRect &rc,
qint32 offsetX, qint32 offsetY,
bool writable) {
return new KisHLineIterator2(dataManager,
rc.x(), rc.y(),
rc.width(),
offsetX, offsetY,
writable);
}
inline void completeInitialization(QVector<IteratorTypeSP> *iterators,
KisWrappedRect *splitRect) {
m_splitRect = splitRect;
m_iterators = iterators;
m_lastRowCoord = m_splitRect->topLeft().bottom();
}
inline IteratorTypeSP leftColumnIterator() const {
return m_iterators->at(m_iteratorRowStart + KisWrappedRect::TOPLEFT);
}
inline IteratorTypeSP rightColumnIterator() const {
return m_iterators->at(m_iteratorRowStart + KisWrappedRect::TOPRIGHT);
}
inline bool trySwitchIteratorStripe() {
bool needSwitching = leftColumnIterator()->y() == m_lastRowCoord;
if (needSwitching) {
if (m_iteratorRowStart == KisWrappedRect::TOPLEFT &&
m_iterators->at(KisWrappedRect::BOTTOMLEFT)) {
m_iteratorRowStart = KisWrappedRect::BOTTOMLEFT;
m_lastRowCoord = m_splitRect->bottomLeft().bottom();
} else /* if (m_iteratorRowStart == KisWrappedRect::BOTTOMLEFT) */ {
m_iteratorRowStart = KisWrappedRect::TOPLEFT;
m_lastRowCoord = m_splitRect->topLeft().bottom();
foreach (IteratorTypeSP it, *m_iterators) {
if (it) {
it->resetRowPos();
}
}
}
}
return needSwitching;
}
inline void iteratorsToNextRow() {
leftColumnIterator()->nextRow();
if (rightColumnIterator()) {
rightColumnIterator()->nextRow();
}
}
inline bool trySwitchColumnForced() {
leftColumnIterator()->resetPixelPos();
if (rightColumnIterator()) {
rightColumnIterator()->resetPixelPos();
}
return true;
}
private:
KisWrappedRect *m_splitRect;
QVector<IteratorTypeSP> *m_iterators;
int m_iteratorRowStart; // may be either KisWrappedRect::TOPLEFT or KisWrappedRect::BOTTOMLEFT
int m_lastRowCoord;
};
#include "kis_wrapped_line_iterator_base.h"
typedef KisWrappedLineIteratorBase<WrappedHLineIteratorStrategy, KisHLineIteratorNG> KisWrappedHLineIterator;
#endif /* __KIS_WRAPPED_HLINE_ITERATOR_H */
|