void QPicture::setData( const char* data, uint size ) { QByteArray a( size ); memcpy( a.data(), data, size ); pictb.setBuffer( a ); // set byte array in buffer resetFormat(); // we'll have to check }
bool QPicture::load( const QString &fileName ) { QByteArray a; QFile f( fileName ); if ( !f.open(IO_ReadOnly) ) return FALSE; a.resize( (uint)f.size() ); f.readBlock( a.data(), (uint)f.size() ); // read file into byte array f.close(); pictb.setBuffer( a ); // set byte array in buffer resetFormat(); // we'll have to check return TRUE; }
QPicture::QPicture( int formatVer ) : QPaintDevice( QInternal::Picture | QInternal::ExternalDevice ) // set device type { if ( formatVer != (int)mfhdr_maj ) { formatMajor = formatVer; formatMinor = 0; formatOk = FALSE; } else { resetFormat(); } }
void Graphics::draw() { resetFormat(); if (!isScreenChanged()) return; // if nothing is changed do not draw anything // preserve preovious terminal text for (int i = 0; i < terminalSizeY - lastTerminalSizeY; i++) { printf("\n"); } printf("\033[H");// reset terminal to top left corner std::string textToPrint[terminalSizeX][terminalSizeY]; // set background for (int y = 0; y < terminalSizeY; y++) { // Y axis for (int x = 0; x < terminalSizeX; x++) { // X axis textToPrint[x][y] = "\033[0m "; } } // look what should be drawn on scren for (int i = 0; i < screen.size(); i++) { if( (screen[i].x >= currentCamera->getX() && screen[i].x < terminalSizeX + currentCamera->getX()) && (screen[i].y >= currentCamera->getY() && screen[i].y < terminalSizeY + currentCamera->getY()) ){ textToPrint[screen[i].x - currentCamera->getX()][screen[i].y - currentCamera->getY()] = printFormat(screen[i].format) + screen[i].ch; } } // draw frame for (int y = terminalSizeY - 1; y >= 0; y--) { // Y axis for (int x = 0; x < terminalSizeX; x++) { // X axis printf("%s", textToPrint[x][y].c_str()); } if(y > 0) printf("\n"); } lastTerminalSizeX = terminalSizeX; lastTerminalSizeY = terminalSizeY; lastScreen = screen; screen.clear(); currentFormat.clear(); }