本文整理汇总了C++中cellAt函数的典型用法代码示例。如果您正苦于以下问题:C++ cellAt函数的具体用法?C++ cellAt怎么用?C++ cellAt使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了cellAt函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: _movewater
void _movewater(sim_Sim *s, int x, int y, double time) {
int i;
sim_Cell *cc, *bc;//center (x,y)
sim_Cell *currs[4]; //current up, down, left right
sim_Cell *buffs[4]; //next tick up, down, left right
double heightdiff[4]; //>0 means flowing in
double netflow;
cc = &cellAt (x, y, s);
bc = &cellAtBuff (x, y, s);
currs[UP] = &cellAt (x, y - 1, s);
buffs[UP] = &cellAtBuff (x, y - 1, s);
currs[DN] = &cellAt (x, y + 1, s);
buffs[DN] = &cellAtBuff (x, y + 1, s);
currs[LF] = &cellAt (x - 1, y, s);
buffs[LF] = &cellAtBuff (x - 1, y, s);
currs[RT] = &cellAt (x + 1, y, s);
buffs[RT] = &cellAtBuff (x + 1, y, s);
if(x == 0)
currs[LF] = NULL;
if(x == s->w - 1)
currs[RT] = NULL;
if(y == 0)
currs[UP] = NULL;
if(y == s->h - 1)
currs[DN] = NULL;
for(i = 0; i < 4; i++) {
bc->height -= bc->flow[i] * time;
}
}
示例2: fgetc
bool Level::Private::cellsFromFile(FILE* in) {
cells.resize(size.x * size.y, Private::Floor);
Point read = { 0, 0 };
for (read.y = 0; read.y < size.y; ++read.y) {
for (read.x = 0; read.x < size.x + 1; ++read.x) {
char c = fgetc(in);
switch (c) {
case EOF: // Error: file is too short.
return false;
break;
case '\n': // End of line, read next.
if (read.x < size.x)
return false;
continue;
break;
case '+':
cellAt(read) = Private::Wood;
break;
case '#':
cellAt(read) = Private::Stone;
break;
case '@': // Spawner. Just a special floor cell.
spawns.push_back(read);
case ' ':
cellAt(read) = Private::Floor;
break;
};
}
}
return true;
}
示例3: areaIt
void PageItem_Table::updateSpans(int index, int number, ChangeType changeType)
{
// Loop through areas of merged cells.
QMutableListIterator<CellArea> areaIt(m_cellAreas);
while (areaIt.hasNext())
{
CellArea oldArea = areaIt.next();
// Get a copy of the area adjusted to the change.
CellArea newArea;
switch (changeType)
{
case RowsInserted:
newArea = oldArea.adjustedForRowInsertion(index, number);
break;
case RowsRemoved:
newArea = oldArea.adjustedForRowRemoval(index, number);
break;
case ColumnsInserted:
newArea = oldArea.adjustedForColumnInsertion(index, number);
break;
case ColumnsRemoved:
newArea = oldArea.adjustedForColumnRemoval(index, number);
break;
default:
break;
}
// Check if the area was affected by the change.
if (newArea != oldArea)
{
if (newArea.height() < 1 || newArea.width() < 1)
{
// Adjusted area was annihilated, so remove it.
areaIt.remove();
}
else if (newArea.height() == 1 && newArea.width() == 1)
{
// Adjusted area is 1x1, so remove it.
areaIt.remove();
// And reset row/column span of spanning cell to 1.
TableCell oldSpanningCell = cellAt(oldArea.row(), oldArea.column());
oldSpanningCell.setRowSpan(1);
oldSpanningCell.setColumnSpan(1);
}
else
{
// Replace the area with the adjusted copy.
areaIt.setValue(newArea);
// And set row/column spanning of spanning cell.
TableCell newSpanningCell = cellAt(newArea.row(), newArea.column());
newSpanningCell.setRowSpan(newArea.height());
newSpanningCell.setColumnSpan(newArea.width());
}
}
}
}
示例4: m_cells
Maze::Maze(int width,int height):m_width(width),m_height(height),
m_cells(std::vector<Cell>(width*height)){
for(int i=0;i<width;i++){
cellAt(Point(i,0))=cellAt(Point(i,0)).cellBySetWall(DirectionTop,true);
}
for(int i=0;i<height;i++){
cellAt(Point(0,i))=cellAt(Point(0,i)).cellBySetWall(DirectionLeft,true);
}
}
示例5: ASSERT_VALID
void PageItem_Table::mergeCells(int row, int column, int numRows, int numCols)
{
ASSERT_VALID();
if (!validCell(row, column) || !validCell(row + numRows - 1, column + numCols - 1))
return;
CellArea newArea(row, column, numCols, numRows);
// Unite intersecting areas.
QMutableListIterator<CellArea> areaIt(m_cellAreas);
while (areaIt.hasNext())
{
CellArea oldArea = areaIt.next();
if (newArea.intersects(oldArea))
{
// The two areas intersect, so unite them.
newArea = newArea.united(oldArea);
// Reset row/column span of old spanning cell, then remove old area.
TableCell oldSpanningCell = cellAt(oldArea.row(), oldArea.column());
oldSpanningCell.setRowSpan(1);
oldSpanningCell.setColumnSpan(1);
areaIt.remove();
}
}
// Set row/column span of new spanning cell, and add new area.
TableCell newSpanningCell = cellAt(newArea.row(), newArea.column());
newSpanningCell.setRowSpan(newArea.height());
newSpanningCell.setColumnSpan(newArea.width());
m_cellAreas.append(newArea);
// Update cells. TODO: Not for entire table.
updateCells();
// If merged area covers active position, move to the spanning cell.
if (newArea.contains(m_activeRow, m_activeColumn))
moveTo(newSpanningCell);
// Remove all cells covered by the merged area from the selection.
QMutableSetIterator<TableCell> cellIt(m_selection);
while (cellIt.hasNext())
{
TableCell cell = cellIt.next();
if (newArea.contains(cell.row(), cell.column()) &&
!(cell.row() == newArea.row() && cell.column() == newArea.column()))
cellIt.remove();
}
emit changed();
ASSERT_VALID();
}
示例6: insertRows
/*!
\fn void QTextTable::removeRows(int index, int rows)
Removes a number of \a rows starting with the row at the specified \a index.
\sa insertRows(), insertColumns(), resize(), removeColumns(), appendRows(), appendColumns()
*/
void QTextTable::removeRows(int pos, int num)
{
Q_D(QTextTable);
// qDebug() << "-------- removeRows" << pos << num;
if (num <= 0 || pos < 0)
return;
if (d->dirty)
d->update();
if (pos >= d->nRows)
return;
if (pos+num > d->nRows)
num = d->nRows - pos;
QTextDocumentPrivate *p = d->pieceTable;
QTextFormatCollection *collection = p->formatCollection();
p->beginEditBlock();
// delete whole table?
if (pos == 0 && num == d->nRows) {
const int pos = p->fragmentMap().position(d->fragment_start);
p->remove(pos, p->fragmentMap().position(d->fragment_end) - pos + 1);
p->endEditBlock();
return;
}
p->aboutToRemoveCell(cellAt(pos, 0).firstPosition(), cellAt(pos + num - 1, d->nCols - 1).lastPosition());
QList<int> touchedCells;
for (int r = pos; r < pos + num; ++r) {
for (int c = 0; c < d->nCols; ++c) {
int cell = d->grid[r*d->nCols + c];
if (touchedCells.contains(cell))
continue;
touchedCells << cell;
QTextDocumentPrivate::FragmentIterator it(&p->fragmentMap(), cell);
QTextCharFormat fmt = collection->charFormat(it->format);
int span = fmt.tableCellRowSpan();
if (span > 1) {
fmt.setTableCellRowSpan(span - 1);
p->setCharFormat(it.position(), 1, fmt);
} else {
// remove cell
int index = d->cells.indexOf(cell) + 1;
int f_end = index < d->cells.size() ? d->cells.at(index) : d->fragment_end;
p->remove(it.position(), p->fragmentMap().position(f_end) - it.position());
}
}
}
p->endEditBlock();
// qDebug() << "-------- end removeRows" << pos << num;
}
示例7: switch
void Maze::setWall(const Point &p,Direction d,bool exists){
switch(d){
case DirectionLeft:
case DirectionTop:
if(isInside(p)){
cellAt(p)=cellAt(p).cellBySetWall(d,exists);
}
break;
case DirectionRight:
case DirectionBottom:
return setWall(p.neighbor(d),DirectionReverse(d),exists);
}
}
示例8: puzzle
Puzzle *Sheet::toPuzzle() const
{
std::auto_ptr<Puzzle> puzzle(new Puzzle);
Grid &grid = puzzle->grid;
State &state = puzzle->state;
grid.height = grid_size.height();
grid.width = grid_size.width();
grid.vars.resize(layout()->count(), -1);
int hgrp = -1;
std::vector<int> vgrps(grid_size.width(), -1);
for(int n = grid_size.width() + 1, c = 1; n < layout()->count(); ++n)
{
if(cellAt(n).open())
{
if(hgrp == -1)
{
hgrp = state.grps++;
state.sum.push_back(cellAt(n - 1).hsum());
state.mem.resize(state.grps);
}
if(vgrps[c] == -1)
{
vgrps[c] = state.grps++;
state.sum.push_back(cellAt(n - grid_size.width()).vsum());
state.mem.resize(state.grps);
}
grid.vars[n] = state.vars;
state.cand.push_back(cellAt(n).cands());
state.hgrp.push_back(hgrp);
state.vgrp.push_back(vgrps[c]);
state.mem[hgrp].push_back(state.vars);
state.mem[vgrps[c]].push_back(state.vars);
++state.vars;
}
else
{
hgrp = vgrps[c] = -1;
}
if(++c == grid_size.width())
c = 0;
}
return puzzle.release();
}
示例9: _createflow
void _createflow(sim_Sim *s, int x, int y, double time) {//time elapsed in seconds
int i;
sim_Cell *cc, *bc;//center (x,y)
sim_Cell *currs[4]; //current up, down, left right
sim_Cell *buffs[4]; //next tick up, down, left right
double heightdiff[4]; //>0 means flowing in
double netflow;
cc = &cellAt (x, y, s);
bc = &cellAtBuff (x, y, s);
currs[UP] = &cellAt (x, y - 1, s);
buffs[UP] = &cellAtBuff (x, y - 1, s);
currs[DN] = &cellAt (x, y + 1, s);
buffs[DN] = &cellAtBuff (x, y + 1, s);
currs[LF] = &cellAt (x - 1, y, s);
buffs[LF] = &cellAtBuff (x - 1, y, s);
currs[RT] = &cellAt (x + 1, y, s);
buffs[RT] = &cellAtBuff (x + 1, y, s);
if(x == 0)
currs[LF] = NULL;
if(x == s->w - 1)
currs[RT] = NULL;
if(y == 0)
currs[UP] = NULL;
if(y == s->h - 1)
currs[DN] = NULL;
for(i = 0; i < 4; i++) {
if(currs[i]== NULL) {
heightdiff[i] = 0;
continue;
}
heightdiff[i] = currs[i]->height - cc->height;
}
//1 unit of flow = 1 height / second
//zflow =~ flow
netflow = 0;
for(i = 0; i < 4; i++) {
double temp = FLOWCONSTANT * sqrt(fabs(heightdiff[i])) * (heightdiff[i] < 0 ? 1 : -1);
double flowdiff;
flowdiff = temp - bc->flow[i];
bc->flow[i] += time * FLOWEQUALIZINGRATE * flowdiff;
netflow += bc->flow[i];
}
}
示例10: cellAt
bool PickerCells::saveOpenCategories(std::list<std::list<std::string> >& masterList,
const std::list<std::string> &parentHier,
PickerCell *selectedCell) const {
bool hasSelectedCell=false;
for (int i=0; i<count(); i++) {
const PickerCell* cell = cellAt(i);
if (cell == selectedCell) {
hasSelectedCell=true;
}
if (!cell->hideChildren()) {
masterList.push_back(parentHier);
std::list<std::string> * newItem = &masterList.back();
(*newItem).push_back(cell->id());
PickerCells *newCells = cell->children();
bool savedCell=false;
if (newCells) {
savedCell = newCells->saveOpenCategories(masterList, (*newItem), selectedCell);
}
if (savedCell) {
(*newItem).push_back(selectedCell->id());
}
}
}
return hasSelectedCell;
}
示例11: empty
bool Sheet::empty()
{
for(int n = 0; n < grid_size.width()*grid_size.height(); ++n)
if(!cellAt(n).empty())
return false;
return true;
}
示例12: cellAt
void Field::generate(int x, int y)
{
Cell *banned = cellAt(x, y);
QVector<Cell*> bannedCells = banned->getNeighbors();
bannedCells.append(banned);
int minesToPlace = m_numberOfMines;
while (minesToPlace > 0) {
Cell *cell = m_cells.at(qrand() % m_cells.count());
if (cell->haveMine()) {
continue;
}
if (bannedCells.contains(cell)){
continue;
}
cell->setHaveMine(true);
--minesToPlace;
}
m_generated = true;
}
示例13: cellAt
/**************************************
* Definition: Whether or not we can occupy the cell at x,y
*
* Parameters: x and y as ints
*
* Returns: true if we can, false if not
**************************************/
bool Map::canOccupy(int x, int y) {
Cell *moveCell = NULL;
moveCell = cellAt(x, y);
if (moveCell == NULL) {
return false;
}
return !moveCell->isBlocked();
}
示例14: selectCell
void PageItem_Table::selectCell(int row, int column)
{
if (!validCell(row, column))
return;
m_selection.insert(cellAt(row, column));
emit selectionChanged();
}
示例15: setUpdatesEnabled
void Sheet::setPuzzle(const Puzzle &puzzle)
{
setUpdatesEnabled(false);
int W = puzzle.grid.width, H = puzzle.grid.height;
QSize new_size(W, H);
if(grid_size != new_size)
setGridSize(QSize(W, H));
for(int n = 0; n < W*H; ++n)
{
int v = puzzle.grid.vars[n];
if(v >= 0)
{
cellAt(n).setOpen(true);
cellAt(n).setCands(puzzle.state.cand[v]);
cellAt(n - W).setVsum(puzzle.state.sum[puzzle.state.vgrp[v]]);
cellAt(n - 1).setHsum(puzzle.state.sum[puzzle.state.hgrp[v]]);
}
else
{
cellAt(n).setOpen(false);
cellAt(n).setHsum(0);
cellAt(n).setVsum(0);
}
}
setUpdatesEnabled(true);
}