void CellPanel::paintEvent(QPaintEvent *e) { QPainter painter(this); QRect toBeUpdated = e->rect(); painter.setClipRect(toBeUpdated); int x0 = toBeUpdated.left() - 1; int y0 = toBeUpdated.top(); int x1 = toBeUpdated.right(), y1 = toBeUpdated.bottom(); // visible rows range int r0 = getViewer()->yToRow(y0); int r1 = getViewer()->yToRow(y1); // visible columns range int c0 = getViewer()->xToColumn(x0); int c1 = getViewer()->xToColumn(x1); // cambia colore alle celle prima di rowCount() int rowCount = getViewer()->getRowCount(); //fill with bg color painter.fillRect(toBeUpdated, getViewer()->getLightLightBGColor()); //scene range bg int yLast = getViewer()->rowToY(rowCount); if (yLast < y1) painter.fillRect(x0, y0, x1 - x0, yLast - y0, getViewer()->getBGColor()); else painter.fillRect(toBeUpdated, getViewer()->getBGColor()); //draw cells drawCells(painter, r0, c0, r1, c1); // draw columns painter.setPen(getViewer()->getVerticalLineColor()); for (int col = c0; col <= c1; col++) { int x = getViewer()->columnToX(col); painter.drawLine(x, y0, x, y1); } // draw rows int currentRow = getViewer()->getCurrentRow(); for (int r = r0; r <= r1; r++) { int y = getViewer()->rowToY(r); QColor color = getViewer()->isMarkRow(r) ? getViewer()->getMarkerLineColor() : getViewer()->getLightLineColor(); painter.setPen(color); painter.drawLine(x0, y, x1, y); } // erase the marker interval at upper-end painter.setPen(getViewer()->getLightLineColor()); painter.drawLine(x0, 0, x1, 0); }
void Grid::draw(sf::RenderTarget& target, sf::RenderStates states) const { drawCells(target, states); drawLines(target, states); }
void main() { uchar c, c1; uchar selAnimationT = 0; uint selAnimationTT = 0, keybTimeout=0; intro(); // Инициализируем экран initGameScreen(); // Запускаем игру startGame(); while(1) { rand(); if(selX!=-1) { selAnimationTT++; if(selAnimationTT==500) { selAnimationTT=0; drawSpriteSel(selX, selY, game[selX][selY], selX==cursorX && selY==cursorY, selAnimationT); selAnimationT++; if(selAnimationT>=4) selAnimationT=0; else if(playSound && selAnimationT==2) soundJumpSel(); } } c1 = bioskey_(); if(keybTimeout) { keybTimeout--; continue; } if(c == c1) continue; c = c1; switch(c) { case KEY_PATH: showPath = !showPath; drawOnOff(0, showPath); break; case KEY_SOUND: playSound = !playSound; drawOnOff(1, playSound); break; case KEY_HELP: showHelp = !showHelp; drawOnOff(2, showHelp); redrawNewBalls2(); break; case KEY_RECORD: prepareRecordScreen(); drawRecordScreen(-1); getch_(); drawCells(); break; case KEY_NEW: startGame(); break; /* case KEY_UP: if(score>=10) score-=10; drawScore1(); break; case KEY_DOWN: score+=10; drawScore1(); break; */ case KEY_UP: clearCursor(); if(cursorY==0) cursorY=8; else cursorY--; drawCursor(); break; case KEY_DOWN: clearCursor(); if(cursorY==8) cursorY=0; else cursorY++; drawCursor(); break; case KEY_LEFT: clearCursor(); if(cursorX==0) cursorX=8; else cursorX--; drawCursor(); break; case KEY_RIGHT: clearCursor(); if(cursorX==8) cursorX=0; else cursorX++; drawCursor(); break; case KEY_SPACE: if(game[cursorX][cursorY]) { if(selX!=-1) drawCell(selX, selY); selX=cursorX, selY=cursorY; break; } if(selX==-1) break; move(); if(gameOver) { recordAnimation(); startGame(); } break; default: continue; } keybTimeout=300; } }