bool Image::init(int width, int height, PixelFormat f, unsigned char* data, bool copyData) { bool recreateBuffer = m_width != width || m_height != height || m_format != f || (data != NULL && copyData && !ownsMem()); m_width = width; m_height = height; m_format = f; size_t buffSize = 0; switch (f) { case PF_GRAYSCALE_8: buffSize = width * height; m_bytesPerPixel = 1; break; case PF_RGB_888: buffSize = width * height * 3; m_bytesPerPixel = 3; break; case PF_FLOAT_32: buffSize = width * height * sizeof(float); m_bytesPerPixel = sizeof(float); break; case PF_YUYV: buffSize = width * height * 2; m_bytesPerPixel = 2; break; default: initEmpty(); LOG_ERROR("Invalid Pixelformat speicifed!"); return false; } if(recreateBuffer){ releaseData(); m_data = new unsigned char[buffSize]; m_ownMem = true; } if (data != NULL) { m_ownMem = copyData || recreateBuffer; if (!copyData) m_data = data; else memcpy(m_data, data, buffSize); } return true; }
/** * Internal constructor-initialiser. * * @param data The data with which to fill the buffer. * @param length The length of the buffer to create. * */ void ManagedBuffer::init(uint8_t *data, int length) { if (length <= 0) { initEmpty(); return; } ptr = (BufferData *) malloc(sizeof(BufferData) + length); ptr->init(); ptr->length = length; // Copy in the data buffer, if provided. if (data) memcpy(ptr->payload, data, length); else memset(ptr->payload, 0, length); }
Image::Image(Rectangle roi, Image* orgImg) { initEmpty(); crop(roi, orgImg); }
Image::Image(int width, int height, PixelFormat f, unsigned char* data, bool copyData) { initEmpty(); init(width,height,f,data,copyData); }
Image::Image(int width, int height, PixelFormat f) { initEmpty(); init(width,height,f); }
Image::Image(Image img, bool copyData) { initEmpty(); if(img.isValid()) init(img.getWidth(),img.getHeight(),img.getFormat(),img.getPtr<unsigned char>(),copyData); }
Image::Image(const Image& img) { initEmpty(); if(img.isValid()) init(img.getWidth(),img.getHeight(),img.getFormat(),img.getPtr<unsigned char>(),true); }
Image::Image() { initEmpty(); }
/** * Default Constructor. * Creates an empty ManagedBuffer. * * Example: * @code * ManagedBuffer p(); * @endcode */ ManagedBuffer::ManagedBuffer() { initEmpty(); }
/** * Get current ptr, do not decr() it, and set the current instance to an empty buffer. * This is to be used by specialized runtimes which pass BufferData around. */ BufferData *ManagedBuffer::leakData() { BufferData* res = ptr; initEmpty(); return res; }
Creator::Creator(QApplication &app) { //播放音乐文件 media = new Phonon::MediaObject(); audioOutput = new Phonon::AudioOutput(Phonon::VideoCategory);//声音 Phonon::createPath(media, audioOutput); sourceList.append(QString("music/infinity.wma")); //建立pad pad = new RoundRectItem(QRectF(QPointF(0,0),QPointF(0,0)),QColor(0,0,255,0)); pad->setZValue(0); //设置backwindow backWindow = new QGraphicsProxyWidget(pad); backWidget = new BackWidget(); backWindow->setX(0); backWindow->setY(0); // backWindow->widget()->setWindowOpacity(1); backWindow->setWidget(backWidget); backWindow->setZValue(0); //设置开始窗口按钮 beginWindow = new QGraphicsProxyWidget(pad); beginWidget = new BeginBottum; beginWindow->setWidget(beginWidget); beginWindow->setX(backWindow->x()+400); beginWindow->setY(backWindow->y()+200); beginWindow->widget()->setWindowOpacity(1); beginWindow->setZValue(0.5); //设置音乐按键 musicWindow = new QGraphicsProxyWidget(pad); musicWidget = new ClickBottum; musicWindow->setWidget(musicWidget); musicWindow->setX(backWindow->widget()->width()-120); musicWindow->setY(backWindow->y()+20); musicWindow->widget()->setWindowOpacity(1); musicWindow->setZValue(0.9); //设置AI对战窗口 aiWindow = new QGraphicsProxyWidget(pad); aiWidget = new AIvsAI(); aiWindow->setWidget(aiWidget); aiWindow->setX(backWindow->x()); aiWindow->setY(backWindow->y()); aiWindow->widget()->setWindowOpacity(0); aiWindow->setZValue(0.5); //按钮控件 singleWindow = new QGraphicsProxyWidget(pad); singleWidget = new widgetssingle; singleWindow->setWidget(singleWidget); singleWindow->setX(backWindow->x()+400); singleWindow->setY(backWindow->y()+200); singleWindow->widget()->setWindowOpacity(0); singleWindow->setZValue(0.5); //回放器 replayerWindow = new QGraphicsProxyWidget(pad); replayerWidget = new ReplayWindow(); replayerWindow->setWidget(replayerWidget); replayerWindow->setX(backWindow->x()); replayerWindow->setY(backWindow->y()); replayerWindow->widget()->setWindowOpacity(0); replayerWindow->setZValue(0.5); //地图编辑器 mapEditWindow = new QGraphicsProxyWidget(pad); mapWideget = new MapEditor(); mapEditWindow->setWidget(mapWideget); mapEditWindow->setX(backWindow->x()); mapEditWindow->setY(backWindow->y()); mapEditWindow->widget()->setWindowOpacity(0); mapEditWindow->setZValue(0.5); //人机对战 humanaiWindow = new QGraphicsProxyWidget(pad); humanaiWidget = new humanai(); humanaiWindow->setX(backWindow->x()); humanaiWindow->setY(backWindow->y()); humanaiWindow->setWidget(humanaiWidget); humanaiWindow->widget()->setWindowOpacity(0); humanaiWindow->setZValue(0.5); //制作团队 teamMeneWindow = new QGraphicsProxyWidget(pad); teamMeneWideget = new TeamMenu(); teamMeneWindow->setWidget(teamMeneWideget); teamMeneWindow->setX(backWindow->x()); teamMeneWindow->setY(backWindow->y()); teamMeneWindow->widget()->setWindowOpacity(1); teamMeneWindow->setZValue(0.5); teamWindow = new QGraphicsProxyWidget(pad); teamWideget = new ProductionTeam(); teamWindow->setWidget(teamWideget); teamWindow->widget()->setWindowOpacity(1); teamWindow->setZValue(0.5); teamWideget->setAutoFillBackground(true); QPalette Tpalette = teamWindow->palette(); Tpalette.setBrush(QPalette::Window, QBrush(Qt::black)); teamWindow->setPalette(Tpalette); //登陆 LogInWindow = new QGraphicsProxyWidget(pad); logInwidget = new LogInWidget(); LogInWindow->setWidget(logInwidget); LogInWindow->widget()->setWindowOpacity(0); LogInWindow->setZValue(0.5); LogInWindow->setX(0); LogInWindow->setY(0); //测试赛 TestWindow = new QGraphicsProxyWidget(pad); testwidget = new TestWidget(); TestWindow->setWidget(testwidget); TestWindow->widget()->setWindowOpacity(0); TestWindow->setZValue(0.5); TestWindow->setX(0); TestWindow->setY(0); // beginWindow->close(); aiWindow->close(); singleWindow->close(); replayerWindow->close(); teamMeneWindow->close(); teamWindow->close(); mapEditWindow->close(); humanaiWindow->close(); LogInWindow->close(); TestWindow->close(); QObject::connect(beginWidget->returnUi()->exitmain,SIGNAL(clicked()),this,SLOT(close())); QObject::connect(beginWidget->returnUi()->startsingle,SIGNAL(clicked()),this,SLOT(BeginToSingle())); connect(this->singleWidget->ui->returnpre,SIGNAL(clicked()),this,SLOT(SingleToBegin())); connect(this->singleWidget->ui->aivsai,SIGNAL(clicked()),this,SLOT(SingleToAi())); connect(this->aiWidget->ui->ReturnPre,SIGNAL(clicked()),this,SLOT(AiToSingle())); connect(this->singleWidget->ui->replay,SIGNAL(clicked()),this,SLOT(SingleToReplayer())); connect(this->replayerWidget->returnUi()->pushButton,SIGNAL(clicked()),this,SLOT(ReplayerToSingle())); connect(this->beginWidget->returnUi()->team,SIGNAL(clicked()),this,SLOT(BeginToTeam())); connect(this->teamMeneWideget->returnUi()->pushButton,SIGNAL(clicked()),this,SLOT(TeamToBegin())); connect(this->musicWidget->ui->checkBox,SIGNAL(clicked()),this,SLOT(Music())); connect(this->replayerWidget->returnUi()->pushButton,SIGNAL(clicked()),this->replayerWidget,SLOT(GoInto())); connect(this->mapWideget->returnUi()->pushButton_5,SIGNAL(clicked()),this,SLOT(MapToSingle())); connect(this->singleWidget->ui->mapedit,SIGNAL(clicked()), this, SLOT(SingLeToMap())); connect(this->singleWidget->ui->playervsai,SIGNAL(clicked()),this,SLOT(SingleToHumanai())); connect(this->singleWidget->ui->playervsai, SIGNAL(clicked()), humanaiWidget, SLOT(initEmpty())); connect(this->humanaiWidget->returnUi()->Button_back, SIGNAL(clicked()), this, SLOT(HumanaiToSingle())); connect(this->media,SIGNAL(aboutToFinish()),this,SLOT(continueMusic())); connect(this->singleWidget->ui->levelmode,SIGNAL(clicked()),this,SLOT(SingleToLogIn())); connect(this->logInwidget->returnUi()->pushButton_2,SIGNAL(clicked()),this,SLOT(LogInToSingle())); connect(this->logInwidget,SIGNAL(login_success(QString)),this,SLOT(LogInToTest(QString))); connect(this->testwidget->returnUi()->pushButton,SIGNAL(clicked()),this,SLOT(TestToLogIn())); // connect(this->singleWidget->ui->replay,SIGNAL(clicked()),this->replayerWidget,SLOT(GoInto())); //设置界面背景 QGraphicsScene *scene = new QGraphicsScene(this); scene->addItem(pad); scene->setBackgroundBrush(QBrush(QColor(0,0,0,255))); scene->setSceneRect(scene->itemsBoundingRect()); setScene(scene); showFullScreen(); //建立状态 stateMachine = new QStateMachine(this); MainState = new QState(stateMachine); TeamState = new QState(stateMachine); BeginState = new QState(stateMachine); TestState = new QState(stateMachine); ReplayerState = new QState(stateMachine); WebState = new QState(stateMachine); MapState = new QState(stateMachine); HumanaiState = new QState(stateMachine); ChatState = new QState(stateMachine); WidState = new QState(stateMachine); BeginMenuState= new QState(stateMachine); SingleState= new QState(stateMachine); OldMenuState = new QState(stateMachine); CheckMenuState = new QState(stateMachine); TeamMenuState = new QState(stateMachine); LogState = new QState(stateMachine); MainState->assignProperty(MainState, "z", 0); MainState->assignProperty(beginWindow->widget(), "windowOpacity", 1); stateMachine->setInitialState(MainState); stateMachine->start(); }