|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/columnfan.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// TnzCore includes
|
|
Toshihiro Shimizu |
890ddd |
#include "tstream.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// STD includss
|
|
Toshihiro Shimizu |
890ddd |
#include <assert.h></assert.h>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=============================================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
const int colWidth = 74;
|
|
Toshihiro Shimizu |
890ddd |
const int colSkip = 9;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=============================================================================
|
|
Toshihiro Shimizu |
890ddd |
// ColumnFan
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
ColumnFan::ColumnFan()
|
|
Toshihiro Shimizu |
890ddd |
: m_firstFreePos(0)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void ColumnFan::update()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
int lastPos = -colWidth;
|
|
Toshihiro Shimizu |
890ddd |
bool lastActive = true;
|
|
Toshihiro Shimizu |
890ddd |
int m = m_columns.size();
|
|
Toshihiro Shimizu |
890ddd |
int i;
|
|
Toshihiro Shimizu |
890ddd |
for (i = 0; i < m; i++) {
|
|
Toshihiro Shimizu |
890ddd |
bool active = m_columns[i].m_active;
|
|
Toshihiro Shimizu |
890ddd |
if (lastActive)
|
|
Toshihiro Shimizu |
890ddd |
lastPos += colWidth;
|
|
Toshihiro Shimizu |
890ddd |
else if (active)
|
|
Toshihiro Shimizu |
890ddd |
lastPos += colSkip;
|
|
Toshihiro Shimizu |
890ddd |
m_columns[i].m_pos = lastPos;
|
|
Toshihiro Shimizu |
890ddd |
lastActive = active;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
m_firstFreePos = lastPos + (lastActive ? colWidth : colSkip);
|
|
Toshihiro Shimizu |
890ddd |
m_table.clear();
|
|
Toshihiro Shimizu |
890ddd |
for (i = 0; i < m; i++)
|
|
Toshihiro Shimizu |
890ddd |
if (m_columns[i].m_active)
|
|
Toshihiro Shimizu |
890ddd |
m_table[m_columns[i].m_pos + colWidth - 1] = i;
|
|
Toshihiro Shimizu |
890ddd |
else if (i + 1 < m && m_columns[i + 1].m_active)
|
|
Toshihiro Shimizu |
890ddd |
m_table[m_columns[i + 1].m_pos - 1] = i;
|
|
Toshihiro Shimizu |
890ddd |
else if (i + 1 == m)
|
|
Toshihiro Shimizu |
890ddd |
m_table[m_firstFreePos - 1] = i;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int ColumnFan::xToCol(int x) const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (x < m_firstFreePos) {
|
|
Toshihiro Shimizu |
890ddd |
std::map<int, int="">::const_iterator it = m_table.lower_bound(x);</int,>
|
|
Toshihiro Shimizu |
890ddd |
if (it == m_table.end())
|
|
Toshihiro Shimizu |
890ddd |
return -3;
|
|
Toshihiro Shimizu |
890ddd |
assert(it != m_table.end());
|
|
Toshihiro Shimizu |
890ddd |
return it->second;
|
|
Toshihiro Shimizu |
890ddd |
} else
|
|
Toshihiro Shimizu |
890ddd |
return m_columns.size() + (x - m_firstFreePos) / colWidth;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int ColumnFan::colToX(int col) const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
int m = m_columns.size();
|
|
Toshihiro Shimizu |
890ddd |
if (col >= 0 && col < m)
|
|
Toshihiro Shimizu |
890ddd |
return m_columns[col].m_pos;
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
return m_firstFreePos + (col - m) * colWidth;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void ColumnFan::activate(int col)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
int m = m_columns.size();
|
|
Toshihiro Shimizu |
890ddd |
if (col < m) {
|
|
Toshihiro Shimizu |
890ddd |
m_columns[col].m_active = true;
|
|
Toshihiro Shimizu |
890ddd |
int i;
|
|
Toshihiro Shimizu |
890ddd |
for (i = m - 1; i >= 0 && m_columns[i].m_active; i--) {
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
i++;
|
|
Toshihiro Shimizu |
890ddd |
if (i < m) {
|
|
Toshihiro Shimizu |
890ddd |
m = i;
|
|
Toshihiro Shimizu |
890ddd |
m_columns.erase(
|
|
Toshihiro Shimizu |
890ddd |
m_columns.begin() + i,
|
|
Toshihiro Shimizu |
890ddd |
m_columns.end());
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
update();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void ColumnFan::deactivate(int col)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
while ((int)m_columns.size() <= col)
|
|
Toshihiro Shimizu |
890ddd |
m_columns.push_back(Column());
|
|
Toshihiro Shimizu |
890ddd |
m_columns[col].m_active = false;
|
|
Toshihiro Shimizu |
890ddd |
update();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bool ColumnFan::isActive(int col) const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return 0 <= col && col < (int)m_columns.size() ? m_columns[col].m_active : true;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bool ColumnFan::isEmpty() const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return m_columns.empty();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void ColumnFan::saveData(TOStream &os)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
int index, n = (int)m_columns.size();
|
|
Toshihiro Shimizu |
890ddd |
for (index = 0; index < n;) {
|
|
Toshihiro Shimizu |
890ddd |
while (index < n && m_columns[index].m_active)
|
|
Toshihiro Shimizu |
890ddd |
index++;
|
|
Toshihiro Shimizu |
890ddd |
if (index < n) {
|
|
Toshihiro Shimizu |
890ddd |
int firstIndex = index;
|
|
Toshihiro Shimizu |
890ddd |
os << index;
|
|
Toshihiro Shimizu |
890ddd |
index++;
|
|
Toshihiro Shimizu |
890ddd |
while (index < n && !m_columns[index].m_active)
|
|
Toshihiro Shimizu |
890ddd |
index++;
|
|
Toshihiro Shimizu |
890ddd |
os << index - firstIndex;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void ColumnFan::loadData(TIStream &is)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
m_columns.clear();
|
|
Toshihiro Shimizu |
890ddd |
m_table.clear();
|
|
Toshihiro Shimizu |
890ddd |
m_firstFreePos = 0;
|
|
Toshihiro Shimizu |
890ddd |
while (!is.eos()) {
|
|
Toshihiro Shimizu |
890ddd |
int index = 0, count = 0;
|
|
Toshihiro Shimizu |
890ddd |
is >> index >> count;
|
|
Toshihiro Shimizu |
890ddd |
int j;
|
|
Toshihiro Shimizu |
890ddd |
for (j = 0; j < count; j++)
|
|
Toshihiro Shimizu |
890ddd |
deactivate(index + j);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|