void DispWidget::arrangeSpots() { qreal width = sceneRect().width(); qreal height = sceneRect().height(); QPointF topLeft = sceneRect().topLeft(); int horizontalCount = int(width / 5); int verticalCount = int(height / 10); QPen pen(Qt::red); // QBrush brush(Qt::red,Qt::SolidPattern); QSizeF size(5,10); QPointF tmpTopLeft = sceneRect().topLeft(); // qreal x,y,startX,startY; // startX = topLeft.x(); // startY = topLeft.y(); for (int i=0;i<horizontalCount;i++) { tmpTopLeft.setX(topLeft.x() + i*5); // x = startX + i*5; qDebug() << "i: " << i; for (int j=0;j<verticalCount;j++) { tmpTopLeft.setY(topLeft.y() + j*10); // y = startY + j*5; qDebug() << "j: " << j; QRectF tmpRect(tmpTopLeft,size); // QRectF tmpRect(x,y,5,10); if (currPath.contains(tmpRect.center())) { addRect(tmpRect,pen); m_spots << tmpRect; } } } }
// TODO: redesign in Qt way ;) // i.e. crop as opacity mask not a copy AvatarEditScene::AvatarEditScene(QObject *parent) : QGraphicsScene(parent) { setSceneRect(0, 0, 480, 360); isSizing = false; isDragged = false; crop = QRect(0, 0, 100, 100); // background setBackgroundBrush(QPixmap(":/images/transparent.png")); // scaled photo photoItem = addPixmap(QPixmap()); // gray it down photoBlurItem = addRect(QRect(), Qt::NoPen, QBrush(QColor(255, 255, 255, 127))); // crop cropItem = addPixmap(QPixmap()); // cropper QPixmap pixmap = getCropper(); cropper = pixmap.rect(); cropperItem = addPixmap(pixmap); cropperItem->setOpacity(0.5); }
void Scene::addIntersections(QPen pen, QBrush brush) { std::vector<Intersection*> intersections = world->getIntersections(); for (const auto &intersection : intersections) { addRect(intersection->getRectangle().toQRect(), pen, brush); } }
void WPainterPath::addRect(const WRectF& rectangle) { addRect(rectangle.x(), rectangle.y(), rectangle.width(), rectangle.height()); }
void WldScene::setItemPlacer(int itemType, unsigned long itemID) { if(cursor) {delete cursor; cursor=NULL;} WriteToLog(QtDebugMsg, QString("ItemPlacer -> set to type-%1 for ID-%2").arg(itemType).arg(itemID)); switch(itemType) { case 0: //Tiles { int j; bool noimage=true, found=false; bool isUser=false; noimage=true; isUser=false; //Check Index exists if(itemID < (unsigned int)index_tiles.size()) { j = index_tiles[itemID].i; if(j<pConfigs->main_wtiles.size()) { if(pConfigs->main_wtiles[j].id == itemID) found=true; } } //if Index found if(found) { //get neccesary element directly isUser=true; noimage=false; tImg = animates_Tiles[index_tiles[itemID].ai]->wholeImage(); } else { //fetching arrays for(j=0;j<uTiles.size();j++) { if(uTiles[j].id==itemID) { isUser=true; noimage=false; tImg = uTiles[j].image; break; } } j=pConfigs->getTileI(itemID); if(j>=0) { noimage=false; if(!isUser) tImg = pConfigs->main_wtiles[j].image; } } if((noimage)||(tImg.isNull())) { tImg=uTileImg; } WldPlacingItems::gridSz=pConfigs->default_grid; WldPlacingItems::gridOffset = QPoint(0, 0); WldPlacingItems::TileSet.id = itemID; long w = tImg.width(); long h = tImg.height()/( (pConfigs->main_wtiles[j].animated)?pConfigs->main_wtiles[j].frames:1); WldPlacingItems::itemW = w; WldPlacingItems::itemH = h; WldPlacingItems::flags.clear(); QPair<int, QVariant > flag; flag.first=0; flag.second="TILE"; WldPlacingItems::flags.push_back(flag); flag.first=1; flag.second=QString::number(itemID); WldPlacingItems::flags.push_back(flag); flag.first = 9; flag.second = QString::number(w); WldPlacingItems::flags.push_back(flag); flag.first = 10; flag.second = QString::number(h); WldPlacingItems::flags.push_back(flag); flag.first = 25; flag.second = "CURSOR"; WldPlacingItems::flags.push_back(flag); if(WldPlacingItems::placingMode==WldPlacingItems::PMODE_Square) { setSquareDrawer(); return; } WldPlacingItems::c_offset_x= qRound(qreal(w) / 2); WldPlacingItems::c_offset_y= qRound(qreal(h) / 2); if(WldPlacingItems::placingMode==WldPlacingItems::PMODE_Line) { setLineDrawer(); return; } cursor = addPixmap(tImg.copy(0,h*pConfigs->main_wtiles[j].display_frame,w,h)); //set data flags foreach(dataFlag_w flag, WldPlacingItems::flags) cursor->setData(flag.first, flag.second); cursor->setZValue(7000); cursor->setOpacity( 0.8 ); cursor->setVisible(false); cursor->setEnabled(true); placingItem=PLC_Tile; WldPlacingItems::TileSet.id = itemID; //flood fill uses 'item' cursor if(WldPlacingItems::placingMode==WldPlacingItems::PMODE_FloodFill) { setFloodFiller(); return; } SwitchEditingMode(MODE_PlacingNew); break; } case 1: //Sceneries { int j; bool noimage=true, found=false; bool isUser=false; noimage=true; isUser=false; //Check Index exists if(itemID < (unsigned int)index_scenes.size()) { j = index_scenes[itemID].i; if(j<pConfigs->main_wscene.size()) { if(pConfigs->main_wscene[j].id == itemID) found=true; } } //if Index found if(found) { //get neccesary element directly isUser=true; noimage=false; tImg = animates_Scenery[index_scenes[itemID].ai]->wholeImage(); } else { //fetching arrays for(j=0;j<uScenes.size();j++) { if(uScenes[j].id==itemID) { isUser=true; noimage=false; tImg = uScenes[j].image; break; } } j=pConfigs->getSceneI(itemID); if(j>=0) { noimage=false; if(!isUser) tImg = pConfigs->main_wscene[j].image; } } if((noimage)||(tImg.isNull())) { tImg=uSceneImg; } WldPlacingItems::gridSz=qRound(qreal(pConfigs->default_grid)/2); WldPlacingItems::gridOffset = QPoint(0, 0); WldPlacingItems::SceneSet.id = itemID; long w = WldPlacingItems::gridSz; long h = WldPlacingItems::gridSz; WldPlacingItems::itemW = w; WldPlacingItems::itemH = h; long iw = tImg.width(); long ih = tImg.height()/( (pConfigs->main_wscene[j].animated)?pConfigs->main_wscene[j].frames:1); WldPlacingItems::flags.clear(); QPair<int, QVariant > flag; flag.first=0; flag.second="SCENERY"; WldPlacingItems::flags.push_back(flag); flag.first=1; flag.second=QString::number(itemID); WldPlacingItems::flags.push_back(flag); flag.first = 9; flag.second = QString::number(w); WldPlacingItems::flags.push_back(flag); flag.first = 10; flag.second = QString::number(h); WldPlacingItems::flags.push_back(flag); flag.first = 25; flag.second = "CURSOR"; WldPlacingItems::flags.push_back(flag); if(WldPlacingItems::placingMode==WldPlacingItems::PMODE_Square) { setSquareDrawer(); return; } WldPlacingItems::c_offset_x= qRound(qreal(w) / 2); WldPlacingItems::c_offset_y= qRound(qreal(h) / 2); if(WldPlacingItems::placingMode==WldPlacingItems::PMODE_Line) { setLineDrawer(); return; } cursor = addPixmap(tImg.copy(0,ih * pConfigs->main_wscene[j].display_frame ,iw,ih)); //set data flags foreach(dataFlag_w flag, WldPlacingItems::flags) cursor->setData(flag.first, flag.second); cursor->setData(25, "CURSOR"); cursor->setZValue(7000); cursor->setOpacity( 0.8 ); cursor->setVisible(false); cursor->setEnabled(true); placingItem=PLC_Scene; WldPlacingItems::SceneSet.id = itemID; //flood fill uses 'item' cursor if(WldPlacingItems::placingMode==WldPlacingItems::PMODE_FloodFill) { setFloodFiller(); return; } SwitchEditingMode(MODE_PlacingNew); break; } case 2: //Path { int j; bool noimage=true, found=false; bool isUser=false; noimage=true; isUser=false; //Check Index exists if(itemID < (unsigned int)index_paths.size()) { j = index_paths[itemID].i; if(j<pConfigs->main_wpaths.size()) { if(pConfigs->main_wpaths[j].id == itemID) found=true; } } //if Index found if(found) { //get neccesary element directly isUser=true; noimage=false; tImg = animates_Paths[index_paths[itemID].ai]->wholeImage(); } else { //fetching arrays for(j=0;j<uPaths.size();j++) { if(uPaths[j].id==itemID) { isUser=true; noimage=false; tImg = uPaths[j].image; break; } } j=pConfigs->getBgoI(itemID); if(j>=0) { noimage=false; if(!isUser) tImg = pConfigs->main_wpaths[j].image; } } if((noimage)||(tImg.isNull())) { tImg=uPathImg; } WldPlacingItems::gridSz=pConfigs->default_grid; WldPlacingItems::gridOffset = QPoint(0, 0); WldPlacingItems::PathSet.id = itemID; long w = tImg.width(); long h = tImg.height()/( (pConfigs->main_wpaths[j].animated)?pConfigs->main_wpaths[j].frames:1); WldPlacingItems::itemW = w; WldPlacingItems::itemH = h; WldPlacingItems::flags.clear(); QPair<int, QVariant > flag; flag.first=0; flag.second="PATH"; WldPlacingItems::flags.push_back(flag); flag.first=1; flag.second=QString::number(itemID); WldPlacingItems::flags.push_back(flag); flag.first = 9; flag.second = QString::number(w); WldPlacingItems::flags.push_back(flag); flag.first = 10; flag.second = QString::number(h); WldPlacingItems::flags.push_back(flag); flag.first = 25; flag.second = "CURSOR"; WldPlacingItems::flags.push_back(flag); if(WldPlacingItems::placingMode==WldPlacingItems::PMODE_Square) { setSquareDrawer(); return; } WldPlacingItems::c_offset_x= qRound(qreal(w) / 2); WldPlacingItems::c_offset_y= qRound(qreal(h) / 2); if(WldPlacingItems::placingMode==WldPlacingItems::PMODE_Line) { setLineDrawer(); return; } cursor = addPixmap(tImg.copy(0,h * pConfigs->main_wpaths[j].display_frame, w ,h)); //set data flags foreach(dataFlag_w flag, WldPlacingItems::flags) cursor->setData(flag.first, flag.second); cursor->setData(25, "CURSOR"); cursor->setZValue(7000); cursor->setOpacity( 0.8 ); cursor->setVisible(false); cursor->setEnabled(true); placingItem=PLC_Path; WldPlacingItems::PathSet.id = itemID; //flood fill uses 'item' cursor if(WldPlacingItems::placingMode==WldPlacingItems::PMODE_FloodFill) { setFloodFiller(); return; } SwitchEditingMode(MODE_PlacingNew); break; } case 3: //Level { int j; bool noimage=true, found=false; bool isUser=false; noimage=true; isUser=false; //Check Index exists if(itemID < (unsigned int)index_levels.size()) { j = index_levels[itemID].i; if(j<pConfigs->main_wlevels.size()) { if(pConfigs->main_wlevels[j].id == itemID) found=true; } } //if Index found if(found) { //get neccesary element directly isUser=true; noimage=false; tImg = animates_Levels[index_levels[itemID].ai]->wholeImage(); } else { //fetching arrays for(j=0;j<uLevels.size();j++) { if(uLevels[j].id==itemID) { isUser=true; noimage=false; tImg = uLevels[j].image; break; } } j=pConfigs->getWLevelI(itemID); if(j>=0) { noimage=false; if(!isUser) tImg = pConfigs->main_wlevels[j].image; } } if((noimage)||(tImg.isNull())) { tImg=uLevelImg; } WldPlacingItems::gridSz=pConfigs->default_grid; WldPlacingItems::gridOffset = QPoint(0, 0); WldPlacingItems::LevelSet.id = itemID; long w = WldPlacingItems::gridSz; long h = WldPlacingItems::gridSz; long iw = tImg.width(); long ih = tImg.height()/( (pConfigs->main_wlevels[j].animated)?pConfigs->main_wlevels[j].frames:1); WldPlacingItems::itemW = w; WldPlacingItems::itemH = h; WldPlacingItems::flags.clear(); QPair<int, QVariant > flag; flag.first=0; flag.second="LEVEL"; WldPlacingItems::flags.push_back(flag); flag.first=1; flag.second=QString::number(itemID); WldPlacingItems::flags.push_back(flag); flag.first = 9; flag.second = QString::number(w); WldPlacingItems::flags.push_back(flag); flag.first = 10; flag.second = QString::number(h); WldPlacingItems::flags.push_back(flag); flag.first = 25; flag.second = "CURSOR"; WldPlacingItems::flags.push_back(flag); if(WldPlacingItems::placingMode==WldPlacingItems::PMODE_Square) { setSquareDrawer(); return; } WldPlacingItems::c_offset_x= qRound(qreal(w) / 2); WldPlacingItems::c_offset_y= qRound(qreal(h) / 2); if(WldPlacingItems::placingMode==WldPlacingItems::PMODE_Line) { setLineDrawer(); return; } cursor = addPixmap(tImg.copy(0, ih * pConfigs->main_wlevels[j].display_frame ,iw,ih)); int imgOffsetX = (int)qRound( -( qreal(tImg.width()) - qreal(WldPlacingItems::gridSz)) / 2 ); int imgOffsetY = (int)qRound( -qreal( tImg.height()/( (pConfigs->main_wlevels[j].animated)?pConfigs->main_wlevels[j].frames:1)) + WldPlacingItems::gridSz); ((QGraphicsPixmapItem*)cursor)->setOffset(imgOffsetX, imgOffsetY ); //set data flags foreach(dataFlag_w flag, WldPlacingItems::flags) cursor->setData(flag.first, flag.second); cursor->setData(25, "CURSOR"); cursor->setZValue(7000); cursor->setOpacity( 0.8 ); cursor->setVisible(false); cursor->setEnabled(true); placingItem=PLC_Level; WldPlacingItems::LevelSet.id = itemID; //flood fill uses 'item' cursor if(WldPlacingItems::placingMode==WldPlacingItems::PMODE_FloodFill) { setFloodFiller(); return; } SwitchEditingMode(MODE_PlacingNew); break; } case 4: //MusicBox placingItem=PLC_Musicbox; WldPlacingItems::MusicSet.id = itemID; WldPlacingItems::gridSz=32; WldPlacingItems::gridOffset = QPoint(0,0); WldPlacingItems::c_offset_x = 16; WldPlacingItems::c_offset_y = 16; cursor = addRect(0,0, 32, 32); cursor->setData(0, "MUSICBOX"); cursor->setData(1, QString::number(itemID)); cursor->setData(9, QString::number(32)); cursor->setData(10, QString::number(32)); ((QGraphicsRectItem *)cursor)->setBrush(QBrush(Qt::yellow)); ((QGraphicsRectItem *)cursor)->setPen(QPen(Qt::yellow, 2,Qt::SolidLine)); cursor->setData(25, "CURSOR"); cursor->setZValue(7000); cursor->setOpacity( 0.8 ); cursor->setVisible(false); cursor->setEnabled(true); SwitchEditingMode(MODE_PlacingNew); break; case 5: //Get point from a world map placingItem=MODE_SetPoint; WldPlacingItems::MusicSet.id = itemID; WldPlacingItems::gridSz=32; WldPlacingItems::gridOffset = QPoint(0,0); WldPlacingItems::c_offset_x = 16; WldPlacingItems::c_offset_y = 16; cursor = addRect(0,0, 32, 32); cursor->setData(0, "WorldMapPoint"); cursor->setData(1, QString::number(itemID)); cursor->setData(9, QString::number(32)); cursor->setData(10, QString::number(32)); ((QGraphicsRectItem *)cursor)->setBrush(QBrush(Qt::yellow)); ((QGraphicsRectItem *)cursor)->setPen(QPen(Qt::yellow, 2,Qt::SolidLine)); cursor->setData(25, "CURSOR"); cursor->setZValue(7000); cursor->setOpacity( 0.8 ); cursor->setVisible(false); cursor->setEnabled(true); SwitchEditingMode(MODE_SetPoint); // restore last point if(!selectedPointNotUsed) setPoint(selectedPoint); break; default: break; } if(itemType!=5) SwitchEditingMode(MODE_PlacingNew); contextMenuOpened=false; }
MyScene::MyScene(QObject *parent) :QGraphicsScene(XPOS,YPOS,WIDTH,HEIGHT, parent) { addRect(XPOS,YPOS,WIDTH,HEIGHT,QPen(Qt::black)); }
void TimeScene::createBackground() { QBrush brush(QColor("white")); QPen pen(QColor("white")); // Background color QList<QGraphicsView*> views = this->views(); int maxWidth = 0; int maxHeight = 0; for (QList<QGraphicsView*>::iterator iter = views.begin(); iter != views.end(); iter++) { QGraphicsView* view = *iter; int viewHeight = view->height(); int viewWidth = view->width(); if (viewHeight > maxHeight) { maxHeight = viewHeight; } if (viewWidth > maxWidth) { maxWidth = viewWidth; } } if (_viewSizeHeight > maxHeight) { maxHeight = _viewSizeHeight; } if (_viewSizeWidth > maxWidth) { maxWidth = _viewSizeWidth; } _viewSizeHeight = maxHeight; _viewSizeWidth = maxWidth; this->addRect(0, 0, maxWidth, maxHeight, pen, brush); // int columnSize = geometry().width() / NU_COLS; int textSize = 30; int margin = 15; int cols = _totalDays; int columnSize = textSize + margin; if ((cols * columnSize) < maxWidth) { cols = (maxWidth / columnSize) + 10; _totalDays = cols; } DateTime startDate = this->_startDate; DateTime today; today.setHour(0); today.setMin(0); today.setSecs(0); for (int x = 0; x < (cols + 1); x++) { QColor barcolor; if ((x % 2) > 0) { barcolor = QColor("white"); } else { barcolor = QColor(240, 240, 240); } QBrush brushBar(barcolor); QPen penBar(barcolor); int left = (x*columnSize) + 0; int top = 0; int heigth = maxHeight; addRect(left, top, columnSize, heigth, penBar, brushBar); QPen pen(QColor(200, 200, 200)); pen.setStyle(Qt::DashLine); addLine(x*columnSize, 0 , x*columnSize, heigth, pen); if (startDate == today) { barcolor = QColor(230, 230, 250); addRect(left, top, columnSize, heigth, penBar, QBrush(barcolor)); } startDate = startDate.addDays(1); } }
void Visual::paintplayer(map &mapp,int k) { QPen pen(Qt::NoPen); QBrush bonus100(QColor(255, 255, 255), QPixmap(":resource/images/player11.png")); QBrush bonus200(QColor(255, 255, 255), QPixmap(":resource/images/player22.png")); QBrush bonus300(QColor(255, 255, 255), QPixmap(":resource/images/palyer33.png")); QBrush money100(QColor(255, 255, 255), QPixmap(":resource/images/Money100.png")); QBrush money500(QColor(255, 255, 255), QPixmap(":resource/images/Money500.png")); QBrush player1 (QColor(255, 255, 255), QPixmap(":resource/images/player1.png")); QBrush player2 (QColor(255, 255, 255), QPixmap(":resource/images/player2.png")); for (int i = 0; i < mapp.len; i++) { for (int j = 0; j < mapp.wid; j++) { //QGraphicsItem * item = QGraphicsScene.items(i*10,j*10,10,10); QList <QGraphicsItem*>item; item=items(QRectF(i*10, j*10, 10, 10)); if (item.size()>0 && item[0]->data(0) != map::WALL && item[0]->data(0) != map::LIFT_UP && item[0]->data(0) != map::LIFT_DOWN) removeItem(item[0]); if (mapp.floor[i][j][k] == map::BONUS100) { QGraphicsItem * item = addRect(QRectF(i*10, j*10, 10, 10), pen, bonus100); item->setData(0, map::BONUS100); } if (mapp.floor[i][j][k] == map::BONUS200) { QGraphicsItem * item = addRect(QRectF(i*10, j*10, 10, 10), pen, bonus200); item->setData(0, map::BONUS200); } if (mapp.floor[i][j][k] == map::BONUS300) { QGraphicsItem * item = addRect(QRectF(i*10, j*10, 10, 10), pen, bonus300); item->setData(0, map::BONUS300); } if (mapp.floor[i][j][k] == map::MONEY100) { QGraphicsItem * item = addRect(QRectF(i*10, j*10, 10, 10), pen, money100); item->setData(0, map::MONEY100); } if (mapp.floor[i][j][k] == map::MONEY500) { QGraphicsItem * item = addRect(QRectF(i*10, j*10, 10, 10), pen, money500); item->setData(0, map::MONEY500); } if (mapp.floor[i][j][k] == map::PLAYER1) { QGraphicsItem * item = addRect(QRectF(i*10, j*10, 10, 10), pen, player1); item->setData(0, map::PLAYER1); } if (mapp.floor[i][j][k] == map::PLAYER2) { QGraphicsItem * item = addRect(QRectF(i*10, j*10, 10, 10), pen, player2); item->setData(0, map::PLAYER2); } } } }
Mouse2(const Size &size) : DefineRectanglesMouseHandler(1,5){ getOptions().handleWidth = 10; addRect(Rect(Point::null,size).enlarged(-5)); }
void init() { world=new b2World(b2Vec2(0.0,9.81)); //addRect(WIDTH/2,HEIGHT-50,WIDTH,30,false); addRect(WIDTH/2,HEIGHT-50,790,30,"base", false); }
void SkPictureRecord::drawOval(const SkRect& oval, const SkPaint& paint) { addDraw(DRAW_OVAL); addPaint(paint); addRect(oval); validate(); }
void RectList::addRect(int x1, int y1, int x2, int y2) { addRect(Common::Rect(x1, y1, x2, y2)); }
void GameBoardScene::drawSquare(int index, const QColor &colour) { QBrush brush(colour, Qt::SolidPattern); addRect(QRectF(qreal((index%width)*spacing), qreal((index/width)*spacing), qreal(spacing), qreal(spacing)), QPen(), brush)->setZValue(-1); }
void LvlScene::setItemPlacer(int itemType, unsigned long itemID, int dType) { if(cursor) {delete cursor; cursor=NULL;} LogDebug(QString("ItemPlacer -> set to type-%1 for ID-%2").arg(itemType).arg(itemID)); LvlPlacingItems::sizableBlock=false; switch(itemType) { case 0: //blocks { obj_block &blockC = uBlocks[itemID]; Items::getItemGFX(&blockC, tImg, false); if(tImg.isNull()) { tImg = uBlockImg; } if(!blockC.isValid) { blockC = pConfigs->main_block[1]; blockC.image = uBlockImg; } LvlPlacingItems::gridSz=blockC.grid; LvlPlacingItems::gridOffset = QPoint(0, 0); if( (itemID != LvlPlacingItems::blockSet.id) || (placingItem!=PLC_Block) ) LvlPlacingItems::blockSet.layer = "Default"; LvlPlacingItems::layer = LvlPlacingItems::blockSet.layer; LvlPlacingItems::blockSet.id = itemID; LvlPlacingItems::blockSet.w = tImg.width(); LvlPlacingItems::blockSet.h = tImg.height(); placingItem=PLC_Block; //Place sizable blocks in the square fill mode if(blockC.sizable) { LvlPlacingItems::sizableBlock=true; LvlPlacingItems::placingMode = LvlPlacingItems::PMODE_Brush; setRectDrawer(); return; } LvlPlacingItems::itemW = LvlPlacingItems::blockSet.w; LvlPlacingItems::itemH = LvlPlacingItems::blockSet.h; LvlPlacingItems::flags.clear(); QPair<int, QVariant > flag; flag.first=ITEM_TYPE; flag.second="Block"; LvlPlacingItems::flags.push_back(flag); flag.first=ITEM_ID; flag.second=QString::number(LvlPlacingItems::blockSet.id); LvlPlacingItems::flags.push_back(flag); if(blockC.sizable) { flag.first=ITEM_BLOCK_IS_SIZABLE; flag.second = "sizable"; LvlPlacingItems::flags.push_back(flag); } flag.first = ITEM_BLOCK_SHAPE; flag.second = QString::number(blockC.phys_shape); LvlPlacingItems::flags.push_back(flag); flag.first = ITEM_WIDTH; flag.second = QString::number(LvlPlacingItems::blockSet.w); LvlPlacingItems::flags.push_back(flag); flag.first = ITEM_HEIGHT; flag.second = QString::number(LvlPlacingItems::blockSet.h); LvlPlacingItems::flags.push_back(flag); flag.first = ITEM_IS_CURSOR; flag.second = "CURSOR"; LvlPlacingItems::flags.push_back(flag); //Rectangular fill mode (uses own cursor item) if(LvlPlacingItems::placingMode == LvlPlacingItems::PMODE_Rect) { setRectDrawer(); return; } //Rectangular fill mode (uses own cursor item) if(LvlPlacingItems::placingMode == LvlPlacingItems::PMODE_Circle) { setCircleDrawer(); return; } //Offset relative to item center LvlPlacingItems::c_offset_x= qRound(qreal(LvlPlacingItems::blockSet.w) / 2); LvlPlacingItems::c_offset_y= qRound(qreal(LvlPlacingItems::blockSet.h) / 2); //Line mode (uses own cursor item) if(LvlPlacingItems::placingMode == LvlPlacingItems::PMODE_Line) { setLineDrawer(); return; } //Single item placing cursor = addPixmap(tImg); //set data flags foreach(dataFlag flag, LvlPlacingItems::flags) cursor->setData(flag.first, flag.second); cursor->setZValue(7000); cursor->setOpacity( 0.8 ); cursor->setVisible(false); cursor->setEnabled(true); //flood fill uses 'item' cursor //if(LvlPlacingItems::floodFillingMode) if(LvlPlacingItems::placingMode == LvlPlacingItems::PMODE_FloodFill) { setFloodFiller(); return; } SwitchEditingMode(MODE_PlacingNew); break; } case 1: //bgos { obj_bgo& bgoC = uBGOs[itemID]; Items::getItemGFX(&bgoC, tImg, false); if(tImg.isNull()) { tImg=uBgoImg; } if(!bgoC.isValid) { bgoC = pConfigs->main_bgo[1]; bgoC.image = uBgoImg; } LvlPlacingItems::gridSz=bgoC.grid; LvlPlacingItems::gridOffset = QPoint(bgoC.offsetX, bgoC.offsetY); if( (itemID != LvlPlacingItems::bgoSet.id) || (placingItem!=PLC_BGO) ) LvlPlacingItems::bgoSet.layer = "Default"; LvlPlacingItems::layer = LvlPlacingItems::bgoSet.layer; LvlPlacingItems::bgoSet.id = itemID; long w = tImg.width(); long h = tImg.height();//( (bgoC.animated)?bgoC.frames:1); LvlPlacingItems::itemW = w; LvlPlacingItems::itemH = h; placingItem=PLC_BGO; LvlPlacingItems::flags.clear(); QPair<int, QVariant > flag; flag.first=0; flag.second="BGO"; LvlPlacingItems::flags.push_back(flag); flag.first=1; flag.second=QString::number(itemID); LvlPlacingItems::flags.push_back(flag); flag.first = 9; flag.second = QString::number(w); LvlPlacingItems::flags.push_back(flag); flag.first = 10; flag.second = QString::number(h); LvlPlacingItems::flags.push_back(flag); flag.first = 25; flag.second = "CURSOR"; LvlPlacingItems::flags.push_back(flag); //Square fill mode if(LvlPlacingItems::placingMode==LvlPlacingItems::PMODE_Rect) { setRectDrawer(); return; } //Rectangular fill mode (uses own cursor item) if(LvlPlacingItems::placingMode == LvlPlacingItems::PMODE_Circle) { setCircleDrawer(); return; } LvlPlacingItems::c_offset_x= qRound(qreal(w) / 2); LvlPlacingItems::c_offset_y= qRound(qreal(h) / 2); //Line mode if(LvlPlacingItems::placingMode==LvlPlacingItems::PMODE_Line) { setLineDrawer(); return; } //Single item placing cursor = addPixmap( tImg ); //set data flags foreach(dataFlag flag, LvlPlacingItems::flags) cursor->setData(flag.first, flag.second); cursor->setZValue(7000); cursor->setOpacity( 0.8 ); cursor->setVisible(false); cursor->setEnabled(true); //flood fill uses 'item' cursor if(LvlPlacingItems::placingMode==LvlPlacingItems::PMODE_FloodFill) { setFloodFiller(); return; } SwitchEditingMode(MODE_PlacingNew); break; } case 2: //npcs { obj_npc &mergedSet = uNPCs[itemID]; tImg = getNPCimg(itemID, LvlPlacingItems::npcSet.direct); if(!mergedSet.isValid) { mergedSet = pConfigs->main_npc[1]; mergedSet.image = uNpcImg; } if( (itemID != LvlPlacingItems::npcSet.id) || (placingItem!=PLC_NPC) ) LvlPlacingItems::npcSet.layer = "Default"; LvlPlacingItems::layer = LvlPlacingItems::npcSet.layer; LvlPlacingItems::npcSet.id = itemID; if(LvlPlacingItems::npcSet.generator) LvlPlacingItems::gridSz=(pConfigs->default_grid/2); else LvlPlacingItems::gridSz=mergedSet.grid; LvlPlacingItems::npcSet.is_star = mergedSet.is_star; LvlPlacingItems::npcGrid=mergedSet.grid; LvlPlacingItems::gridOffset = QPoint(mergedSet.grid_offset_x, mergedSet.grid_offset_y); LvlPlacingItems::flags.clear(); QPair<int, QVariant > flag; long imgOffsetX = (int)round( - ( ( (double)mergedSet.gfx_w - (double)mergedSet.width ) / 2 ) ); long imgOffsetY = (int)round( - (double)mergedSet.gfx_h + (double)mergedSet.height + (double)mergedSet.gfx_offset_y ); LvlPlacingItems::npcGfxOffsetX1 = imgOffsetX; LvlPlacingItems::npcGfxOffsetX2 = (-((double)mergedSet.gfx_offset_x)); LvlPlacingItems::npcGfxOffsetY = imgOffsetY; LvlPlacingItems::itemW = mergedSet.width; LvlPlacingItems::itemH = mergedSet.height; LvlPlacingItems::c_offset_x= qRound(qreal(mergedSet.width) / 2); LvlPlacingItems::c_offset_y= qRound(qreal(mergedSet.height) / 2); placingItem = PLC_NPC; flag.first=ITEM_TYPE; flag.second="NPC"; LvlPlacingItems::flags.push_back(flag); flag.first=ITEM_ID; flag.second=QString::number(itemID); LvlPlacingItems::flags.push_back(flag); flag.first=ITEM_NPC_BLOCK_COLLISION; flag.second=QString::number((int)mergedSet.collision_with_blocks); LvlPlacingItems::flags.push_back(flag); flag.first=ITEM_NPC_NO_NPC_COLLISION; flag.second=QString::number((int)mergedSet.no_npc_collions); LvlPlacingItems::flags.push_back(flag); flag.first=ITEM_WIDTH; flag.second=QString::number(mergedSet.width); LvlPlacingItems::flags.push_back(flag); flag.first=ITEM_HEIGHT; flag.second=QString::number(mergedSet.height); LvlPlacingItems::flags.push_back(flag); flag.first=ITEM_IS_CURSOR; flag.second="CURSOR"; LvlPlacingItems::flags.push_back(flag); //Line mode if(LvlPlacingItems::placingMode==LvlPlacingItems::PMODE_Line) { setLineDrawer(); return; } cursor = addPixmap(tImg); //set data flags foreach(dataFlag flag, LvlPlacingItems::flags) cursor->setData(flag.first, flag.second); ((QGraphicsPixmapItem *)cursor)->setOffset( ( LvlPlacingItems::npcGfxOffsetX1 + ( LvlPlacingItems::npcGfxOffsetX2 * ((LvlPlacingItems::npcSet.direct==0)?-1:LvlPlacingItems::npcSet.direct))), LvlPlacingItems::npcGfxOffsetY ); cursor->setZValue(7000); cursor->setOpacity( 0.8 ); cursor->setVisible(false); cursor->setEnabled(true); break; } case 3: //water placingItem=PLC_Water; LvlPlacingItems::waterType = itemID; LvlPlacingItems::gridSz = 16; LvlPlacingItems::gridOffset = QPoint(0,0); LvlPlacingItems::c_offset_x= 0; LvlPlacingItems::c_offset_y= 0; LvlPlacingItems::waterSet.layer = LvlPlacingItems::layer.isEmpty()? "Default" : LvlPlacingItems::layer; setRectDrawer(); return; break; case 4: //doorPoint placingItem=PLC_Door; LvlPlacingItems::doorType = dType; LvlPlacingItems::doorArrayId = itemID; LvlPlacingItems::gridSz=16; LvlPlacingItems::gridOffset = QPoint(0,0); LvlPlacingItems::c_offset_x = 16; LvlPlacingItems::c_offset_y = 16; LvlPlacingItems::layer = ""; cursor = addRect(0,0, 32, 32); ((QGraphicsRectItem *)cursor)->setBrush(QBrush(QColor(qRgb(0xff,0x00,0x7f)))); ((QGraphicsRectItem *)cursor)->setPen(QPen(QColor(qRgb(0xff,0x00,0x7f)), 2,Qt::SolidLine, Qt::SquareCap, Qt::MiterJoin)); cursor->setData(ITEM_IS_CURSOR, "CURSOR"); cursor->setZValue(7000); cursor->setOpacity( 0.8 ); cursor->setVisible(false); cursor->setEnabled(true); break; case 5: //PlayerPoint { placingItem=PLC_PlayerPoint; LvlPlacingItems::playerID = itemID; LvlPlacingItems::gridSz=2; LvlPlacingItems::gridOffset = QPoint(0,2); LvlPlacingItems::c_offset_x = 16; LvlPlacingItems::c_offset_y = 16; LvlPlacingItems::layer = ""; QPixmap playerPixmap; switch(itemID+1) { case 1: playerPixmap = Themes::Image(Themes::player1); break; case 2: playerPixmap = Themes::Image(Themes::player2); break; default: playerPixmap = Themes::Image(Themes::player_point); break; } PlayerPoint x = FileFormats::CreateLvlPlayerPoint(itemID+1); cursor = addPixmap(playerPixmap); dynamic_cast<QGraphicsPixmapItem *>(cursor)->setOffset(qRound(qreal(x.w-playerPixmap.width())/2.0), x.h-playerPixmap.height() ); cursor->setData(ITEM_IS_CURSOR, "CURSOR"); cursor->setZValue(7000); cursor->setOpacity( 0.8 ); cursor->setVisible(true); cursor->setEnabled(true); break; } default: break; } SwitchEditingMode(MODE_PlacingNew); DrawMode=true; contextMenuOpened=false; }
void LvlScene::setRectDrawer() { if(cursor) {delete cursor; cursor=NULL;} QPen pen; QBrush brush; switch(placingItem) { case PLC_Water: if(LvlPlacingItems::waterType==1) { pen = QPen(Qt::yellow, 2); brush = QBrush(Qt::darkYellow); } else { pen = QPen(Qt::green, 2); brush = QBrush(Qt::darkGreen); } break; case PLC_Block: case PLC_BGO: default: pen = QPen(Qt::gray, 2); brush = QBrush(Qt::darkGray); break; } //Align width and height to fit into item aligning long addW=LvlPlacingItems::gridSz-LvlPlacingItems::itemW%LvlPlacingItems::gridSz; long addH=LvlPlacingItems::gridSz-LvlPlacingItems::itemH%LvlPlacingItems::gridSz; if(addW==LvlPlacingItems::gridSz) addW=0; if(addH==LvlPlacingItems::gridSz) addH=0; LvlPlacingItems::itemW = LvlPlacingItems::itemW+addW; LvlPlacingItems::itemH = LvlPlacingItems::itemH+addH; if((placingItem != PLC_Water) && (!LvlPlacingItems::sizableBlock)) { QPixmap oneCell(LvlPlacingItems::itemW, LvlPlacingItems::itemH); oneCell.fill(QColor(0xFF, 0xFF, 0x00, 128)); QPainter p(&oneCell); p.setBrush(Qt::NoBrush); p.setPen(QPen(Qt::yellow, 2, Qt::SolidLine)); p.drawRect(0,0, LvlPlacingItems::itemW, LvlPlacingItems::itemH); brush.setTexture(oneCell); } cursor = addRect(0,0,1,1, pen, brush); //set data flags foreach(dataFlag flag, LvlPlacingItems::flags) cursor->setData(flag.first, flag.second); cursor->setData(ITEM_TYPE, "Square"); cursor->setData(ITEM_IS_CURSOR, "CURSOR"); cursor->setZValue(7000); cursor->setOpacity( 0.5 ); cursor->setVisible(false); cursor->setEnabled(true); SwitchEditingMode(MODE_DrawRect); DrawMode=true; }
WldScene::WldScene(GraphicsWorkspace * parentView, dataconfigs &configs, WorldData &FileData, QObject *parent) : QGraphicsScene(parent) { setItemIndexMethod(QGraphicsScene::NoIndex); //Pointerss pConfigs = &configs; // Pointer to Main Configs WldData = &FileData; //Ad pointer to level data _viewPort = parentView; //Options opts.animationEnabled = true; opts.collisionsEnabled = true; grid = true; //Indexes index_tiles = pConfigs->index_wtiles; //Applaying blocks indexes index_scenes = pConfigs->index_wscene; index_paths = pConfigs->index_wpaths; index_levels = pConfigs->index_wlvl; //Editing mode EditingMode = 0; EraserEnabled = false; PasteFromBuffer = false; disableMoveItems = false; DrawMode=false; mouseLeft=false; //Left mouse key is pressed mouseMid=false; //Middle mouse key is pressed mouseRight=false;//Right mouse key is pressed mouseMoved=false; //Mouse was moved with right mouseKey MousePressEventOnly=false; MouseMoveEventOnly=false; MouseReleaseEventOnly=false; last_tile_arrayID=0; last_scene_arrayID=0; last_path_arrayID=0; last_level_arrayID=0; last_musicbox_arrayID=0; isSelectionDialog=false; //Editing process flags IsMoved = false; haveSelected = false; emptyCollisionCheck = false; placingItem=0; pResizer = NULL; contextMenuOpened = false; selectedPoint = QPoint(0, 0); selectedPointNotUsed=true; pointTarget = NULL; pointAnimation = NULL; pointImg=QPixmap(":/images/set_point.png"); cursor = NULL; resetCursor(); messageBox = NULL; //set dummy images if target not exist or wrong uTileImg = Themes::Image(Themes::dummy_tile); uSceneImg = Themes::Image(Themes::dummy_scenery); uPathImg = Themes::Image(Themes::dummy_path); uLevelImg = Themes::Image(Themes::dummy_wlevel); musicBoxImg = Themes::Image(Themes::dummy_musicbox); //Build animators for dummies SimpleAnimator * tmpAnimator; tmpAnimator = new SimpleAnimator(uTileImg, 0); animates_Tiles.push_back( tmpAnimator ); tmpAnimator = new SimpleAnimator(uSceneImg, 0); animates_Scenery.push_back( tmpAnimator ); tmpAnimator = new SimpleAnimator(uPathImg, 0); animates_Paths.push_back( tmpAnimator ); tmpAnimator = new SimpleAnimator(uLevelImg, 0); animates_Levels.push_back( tmpAnimator ); //set Default Z Indexes tileZ=0; // tiles sceneZ=5; // scenery pathZ=10; // paths levelZ=15; // levels musicZ=20; // musicboxes //HistoryIndex historyIndex=0; //Locks lock_tile=false; lock_scene=false; lock_path=false; lock_level=false; lock_musbox=false; connect(this, SIGNAL(selectionChanged()), this, SLOT(selectionChanged())); long padding=100000; QGraphicsRectItem * bigRect = addRect(-padding, -padding, padding*2, padding*2, QPen(Qt::transparent), QBrush(Qt::transparent)); bigRect->setZValue(-10000000000); //Build edit mode classes WLD_ModeHand * modeHand = new WLD_ModeHand(this); EditModes.push_back(modeHand); WLD_ModeSelect * modeSelect = new WLD_ModeSelect(this); EditModes.push_back(modeSelect); WLD_ModeResize * modeResize = new WLD_ModeResize(this); EditModes.push_back(modeResize); WLD_ModeErase * modeErase = new WLD_ModeErase(this); EditModes.push_back(modeErase); WLD_ModePlace * modePlace = new WLD_ModePlace(this); EditModes.push_back(modePlace); WLD_ModeSquare * modeSquare = new WLD_ModeSquare(this); EditModes.push_back(modeSquare); WLD_ModeLine * modeLine = new WLD_ModeLine(this); EditModes.push_back(modeLine); WLD_ModeSetPoint * modeSetPoint = new WLD_ModeSetPoint(this); EditModes.push_back(modeSetPoint); WLD_ModeFill * modeFill = new WLD_ModeFill(this); EditModes.push_back(modeFill); CurrentMode = modeSelect; CurrentMode->set(); }
void MetaGLInfoClass::addIteractionRect(GeoCoords pos1, GeoCoords pos2) { iteractionRectNumber = addRect(pos1, pos2); }
void eat(Snake *snake){ addRect( snake->vect, *getRect(snake->vect,getSnakeLength(snake)-1)); }
std::vector<b2Body*> CPhysics::createBridge(b2Body* sta1,b2Body* sta2,int w,int h) {//its returning vector of Bodies!, will use for future to draw the images on top of them in NEW rope/bridge sprite class std::vector<b2Body*> BodyList; //int Lowerangle = 90; //int Upperangle = 90; b2Vec2 pos1=M2P*(sta1->GetWorldCenter()+(((b2PolygonShape*)sta1->GetFixtureList()->GetShape())->GetVertex(1))); b2Vec2 pos2=M2P*(sta2->GetWorldCenter()+(((b2PolygonShape*)sta2->GetFixtureList()->GetShape())->GetVertex(0))); int num=(pos2.x-pos1.x)/w; b2RevoluteJointDef jointDef; //jointDef.collideConnected = false; jointDef.bodyA=sta1; b2Body* prev,*cur; prev=addRect(pos1.x+(w/2),pos1.y,w + (w*0.2f),h,true,0); BodyList.push_back(prev); jointDef.bodyB=prev; jointDef.localAnchorA.Set(((b2PolygonShape*)sta1->GetFixtureList()->GetShape())->GetVertex(1).x,0); jointDef.localAnchorB.Set(-w/2*P2M,0); jointDef.bodyA->SetGravityScale(4); jointDef.bodyB->SetGravityScale(4); world->CreateJoint(&jointDef); for(int i=0;i<num-1;i++) { cur=addRect(pos1.x+i*w,pos1.y,w + (w*0.2f),h,true,0); BodyList.push_back(cur); //not working the way i wanted, got to test this around to figure out how to limit the //rotation angle! // jointDef.enableLimit = true; //jointDef.lowerAngle = jointDef.referenceAngle;//Lowerangle * M_PI/180; //jointDef.upperAngle = jointDef.referenceAngle;//Upperangle * M_PI/180; jointDef.bodyA=prev; jointDef.bodyB=cur; jointDef.localAnchorA.Set(w/2*P2M,0); jointDef.localAnchorB.Set(-w/2*P2M,0); jointDef.bodyA->SetGravityScale(4); jointDef.bodyB->SetGravityScale(4); world->CreateJoint(&jointDef); prev=cur; } //jointDef.enableLimit = true; jointDef.bodyA=prev; jointDef.bodyB=sta2; jointDef.localAnchorA.Set(w/2*P2M,0); jointDef.localAnchorB.Set((((b2PolygonShape*)sta2->GetFixtureList()->GetShape())->GetVertex(0)).x,0); // jointDef.bodyA->SetGravityScale(-20); // jointDef.bodyB->SetGravityScale(-20); world->CreateJoint(&jointDef); return BodyList; }
void SkPictureRecord::drawRect(const SkRect& rect, const SkPaint& paint) { addDraw(DRAW_RECT); addPaint(paint); addRect(rect); validate(); }
void DigestTreeScene::plotNode(const std::vector<TreeLayout::Coordinate>& childNodesCo, QString digest, int nodeSize) { RosterIterator it(m_roster); int n = childNodesCo.size(); int rim = 3; // plot root node QRectF rootBoundingRect(0, 0, nodeSize, nodeSize); QRectF rootInnerBoundingRect(rim, rim, nodeSize - rim * 2, nodeSize - rim * 2); addRect(rootBoundingRect, QPen(Qt::black), QBrush(Qt::darkRed)); addRect(rootInnerBoundingRect, QPen(Qt::black), QBrush(Qt::lightGray)); QRectF digestRect(- 5.5 * nodeSize , - nodeSize, 12 * nodeSize, 30); addRect(digestRect, QPen(Qt::darkCyan), QBrush(Qt::darkCyan)); QGraphicsTextItem *digestItem = addText(digest); QRectF digestBoundingRect = digestItem->boundingRect(); digestItem->setDefaultTextColor(Qt::black); digestItem->setFont(QFont("Cursive", 12, QFont::Bold)); digestItem->setPos(- 4.5 * nodeSize + (12 * nodeSize - digestBoundingRect.width()) / 2, - nodeSize + 5); m_displayRootDigest = digestItem; // plot child nodes for (int i = 0; i < n; i++) { if (it.hasNext()) it.next(); else abort(); double x = childNodesCo[i].x; double y = childNodesCo[i].y; QRectF boundingRect(x, y, nodeSize, nodeSize); QRectF innerBoundingRect(x + rim, y + rim, nodeSize - rim * 2, nodeSize - rim * 2); DisplayUserPtr p = it.value(); QGraphicsRectItem *rectItem = addRect(boundingRect, QPen(Qt::black), QBrush(Qt::darkBlue)); p->setRimRectItem(rectItem); QGraphicsRectItem *innerRectItem = addRect(innerBoundingRect, QPen(Qt::black), QBrush(Qt::lightGray)); p->setInnerRectItem(innerRectItem); std::string s = boost::lexical_cast<std::string>(p->getSeqNo()); QGraphicsTextItem *seqItem = addText(s.c_str()); seqItem->setFont(QFont("Cursive", 12, QFont::Bold)); QRectF seqBoundingRect = seqItem->boundingRect(); seqItem->setPos(x + nodeSize / 2 - seqBoundingRect.width() / 2, y + nodeSize / 2 - seqBoundingRect.height() / 2); p->setSeqTextItem(seqItem); QRectF textRect(x - nodeSize / 2, y + nodeSize, 2 * nodeSize, 30); QGraphicsRectItem *nickRectItem = addRect(textRect, QPen(Qt::darkCyan), QBrush(Qt::darkCyan)); p->setNickRectItem(nickRectItem); QGraphicsTextItem *nickItem = addText(p->getNick()); QRectF textBoundingRect = nickItem->boundingRect(); nickItem->setDefaultTextColor(Qt::white); nickItem->setFont(QFont("Cursive", 12, QFont::Bold)); nickItem->setPos(x + nodeSize / 2 - textBoundingRect.width() / 2, y + nodeSize + 5); p->setNickTextItem(nickItem); } }
void detectFaces(GtkImage *image, StrongClassifier *sc) { static DetectedFace faces[20000000]; int nbFaces = 0; GdkPixbuf *pixbuf = gtk_image_get_pixbuf(image); GreyImage *grey = GreyImageNewFromImage(image); IntegralImage *intImage = IntegralImageNew(grey); int imgW = intImage->width; int imgH = intImage->height; int maxX = imgW - WIN_WIDTH; int maxY = imgH - WIN_HEIGHT; GreyImage *squaredGrey = GreyImageNew(imgW, imgH); for(int i = 0, count = imgW*imgH; i < count; ++i) squaredGrey->pixels[i] = grey->pixels[i]*grey->pixels[i]; IntegralImage *squaredImage = IntegralImageNew(squaredGrey); for(int x = 0; x < maxX; ++x) { for(int y = 0; y < maxY; ++y) { double scale = 1; int maxWidth = imgW - x; int maxHeight = imgH - y; int width = WIN_WIDTH; int height = WIN_HEIGHT; while(width <= maxWidth && height <= maxHeight) { int deviation = IntegralImageGetDeviation(intImage, squaredImage, scale ,x, y, width, height); if(StrongClassifierCheck(sc, intImage, x, y, scale, deviation)) { faces[nbFaces].x = x; faces[nbFaces].y = y; faces[nbFaces].w = width; faces[nbFaces].h = height; ++nbFaces; } scale *= WIN_RATIO; width = WIN_WIDTH * scale; height = WIN_HEIGHT * scale; } } } DetectedFace *trueFaces = postProcessing(faces, nbFaces, &nbFaces); for(int i = 0; i < nbFaces; ++i) addRect(pixbuf, trueFaces[i].x, trueFaces[i].y, trueFaces[i].w, trueFaces[i].h); }
bool HelloWorld::init() { if ( !Layer::init() ) { return false; } // cur_global_init() // 定义重力加速 b2Vec2 gravity; // 设定垂直方向的加速度,这里采用真实的物理数据 gravity.Set(0.0f, -9.8f); // 使用刚刚定义好的加速度生成物理世界对象,这样世界中的所有对象都会受到重力加速度的影响 phyWorld = new b2World(gravity); // 物理世界的对象都参与碰撞检测,无休眠对象 //phyWorld->SetAllowSleeping(false); //连续碰撞检测,避免发生物体穿过另一个物体的事件 //phyWorld->SetContinuousPhysics(true); // 设置碰撞监听器 listener = new ContactListener(); phyWorld->SetContactListener(listener); addFloor(); addRect(5, 3, b2_dynamicBody); scheduleUpdate(); Size visibleSize = Director::getInstance()->getVisibleSize(); Vec2 origin = Director::getInstance()->getVisibleOrigin(); auto closeItem = MenuItemImage::create( "CloseNormal.png", "CloseSelected.png", CC_CALLBACK_1(HelloWorld::menuCloseCallback, this)); closeItem->setPosition(Vec2(origin.x + visibleSize.width - closeItem->getContentSize().width*2 , 60)); closeItem->setScale(2); auto menu = Menu::create(closeItem, NULL); menu->setPosition(Vec2::ZERO); this->addChild(menu, 1); auto left = MenuItemImage::create( "b1.png", "b1.png", CC_CALLBACK_1(HelloWorld::menuLeftCallback, this)); left->setPosition(Vec2(50,60)); left->setScale(2); auto leftMenu = Menu::create(left, NULL); leftMenu->setPosition(Vec2::ZERO); this->addChild(leftMenu, 1); auto right = MenuItemImage::create( "f1.png", "f1.png", CC_CALLBACK_1(HelloWorld::menuRightCallback, this)); right->setPosition(Vec2(100,60)); auto rightMenu = Menu::create(right, NULL); rightMenu->setPosition(Vec2::ZERO); right->setScale(2); this->addChild(rightMenu, 1); inum = 1; auto changeShield = MenuItemImage::create( "changeShield.png", "changeShield.png", CC_CALLBACK_1(HelloWorld::menuChangeShieldCallback, this)); changeShield->setPosition(Vec2(100,200)); auto changeShieldMenu = Menu::create(changeShield, NULL); changeShieldMenu->setPosition(Vec2::ZERO); //changeShield->setScale(2); this->addChild(changeShieldMenu, 1); auto changeWeapon = MenuItemImage::create( "changeWeapon.png", "changeWeapon.png", CC_CALLBACK_1(HelloWorld::menuChangeWeaponCallback, this)); changeWeapon->setPosition(Vec2(200,200)); auto changeWeaponMenu = Menu::create(changeWeapon, NULL); changeWeaponMenu->setPosition(Vec2::ZERO); //changeWeapon->setScale(2); this->addChild(changeWeaponMenu, 1); spineNode = SpineNode::createWithFile("res/spineboy.json", "res/spineboy.atlas"); spineNode->setScale(0.2); spineNode->setPosition(Vec2(visibleSize.width/2 + origin.x, visibleSize.height/4 + origin.y)); this->addChild(spineNode); spineSheildNode = SpineNode::createWithFile("res/shield.json", "res/shield.atlas"); spineSheildNode->setScale(0.2); spineSheildNode->setPosition(Vec2(visibleSize.width/2 + origin.x, 0)); this->addChild(spineSheildNode); return true; }
void KWDWriter::finishTable(int tableno, QRect rect) { int ncols = 0; int nrows = 0; insidetable = false; int x = rect.x(); int y = rect.y(); int w = rect.width(); int h = rect.height(); QDomNodeList nl = docroot().elementsByTagName("FRAMESET"); //FIXME calculate nrows and stuff. //and add empty cells for missing ones. // first, see how big the table is (cols & rows) for (int i = 0;i < nl.count();i++) { QDomElement k = nl.item(i).toElement(); if (k.attribute("grpMgr") == QString("Table %1").arg(tableno)) { ncols = MAX(ncols, k.attribute("col").toInt() + 1); nrows = MAX(nrows, k.attribute("row").toInt() + 1); } } int curcol = 0; int currow = 0; int currow_inc = 0; if (ncols == 0) ncols = 1; // FIXME (floating point division by zero) if (nrows == 0) nrows = 1; int step_x = (w - x) / ncols; int step_y = (h - y) / nrows; // then, let's create the missing cells and resize them if needed. bool must_resize = false; if (x > 0) must_resize = true; while (currow < nrows) { curcol = 0; while (curcol < ncols) { QDomElement e = fetchTableCell(tableno, currow, curcol); if (e.isNull()) { // a missing cell ! kDebug(30503) << QString("creating %1 %2").arg(currow).arg(curcol).toLatin1(); createTableCell(tableno, currow, curcol, 1, QRect(x + step_x*curcol, y + step_y*currow, step_x, step_y) ); // fixme: what to do if we don't have to resize ? } // resize this one FIXME optimize this routine if (must_resize == true) { QDomElement ee = e.firstChild().toElement(); // the frame in the frameset int cs = e.attribute("cols").toInt(); int rs = e.attribute("rows").toInt(); kDebug(30503) << "resizing"; addRect(ee, QRect(x + step_x*curcol, 0, step_x*cs, step_y*rs)); } if (curcol == 0) currow_inc = e.attribute("rows").toInt(); curcol += e.attribute("cols").toInt(); } currow += currow_inc; } }
QGraphicsRectItem* createBox() { QGraphicsRectItem *rect = addRect(0,0,100,100, QPen(Qt::blue)); rect->setFlags(QGraphicsItem::ItemIsMovable); putInTheRightPlace(rect); return rect; }
std::string name; int x1,x2,y1,y2; lineStream >> name >> x1 >> y1 >> x2 >> y2; int returnCode = addSegment(name,Point(x1,y1),Point(x2,y2),saveInUndoList); if(returnCode!=0) { std::cout << "ERR" << std::endl; return returnCode; } } else if(commandId.compare("R")==0) { std::string name; int x1,x2,y1,y2; lineStream >> name >> x1 >> y1 >> x2 >> y2; int returnCode = addRect(name,Point(x1,y1),Point(x2,y2),saveInUndoList); if(returnCode!=0) { std::cout << "ERR" << std::endl; return returnCode; } } else if(commandId.compare("PC")==0) { std::string name; std::vector<Point> points; int c[2]; lineStream >> name; while(!lineStream.eof()) { lineStream >> c[0];
void JViewSet::addJFRect(JFRect rect) { addRect(rect.x, rect.y, rect.width, rect.height);}
//-------------------------------------------------------------- void ofxBox2dCompoundShape::addRect(ofRectangle aLocalRect ) { addRect( ofxBox2dCompoundShape::Rectangle( aLocalRect.x, aLocalRect.y, aLocalRect.width, aLocalRect.height )); }
// ////////////////////////////////////Draw BG image///////////////////////////////////////////////// void LvlScene::DrawBG(int x, int y, int w, int h, int sctID, QPixmap &srcimg, QPixmap &srcimg2, obj_BG &bgsetup) { /* Old Algorith */ //QPixmap BackImg; //QPainter * BGPaint; //QPixmap img; int si_attach, attach; /* New Algorith */ QGraphicsItem * item; //QGraphicsRectItem * itemR=NULL; QColor FillColor; //Fill undrawed space with color long sctW,//Section Width sctH,//Section Height R1W, //Img Width (Row1) R1H, //Img Height (Row1) R1Hc=0, //Crop height from bottom R1Ho=0, //Offset from top R2W, //Img Width (Row2) R2H, //Img Height (Row2) R2Hc=0, //Crop height from bottom R2Ho=0, //Offset from top RectPlus=0, toY; //Placing position Y 0 - top sctW = (long)fabs(x-w); sctH = (long)fabs(y-h); WriteToLog(QtDebugMsg, "Draw BG -> Draw BG Image"); attach = bgsetup.attached; // ///////////////////SingleRow BG/////////////////////////// if((bgsetup.type==0)&&(!bgsetup.editing_tiled)) { WriteToLog(QtDebugMsg, "Draw BG -> Style: SingleRow BG"); R1W = srcimg.width(); R1H = srcimg.height(); if(attach==0) // Get Pixel color (0 - bottom, 1 - top) FillColor = QColor( srcimg.toImage().pixel(0,0) ); // from top else FillColor = QColor( srcimg.toImage().pixel(0,(R1H-1)) ); //from bottom if(attach==0) { // 0 - bottom toY = (sctH>R1H)? sctH-R1H : 0; R1Hc = ((R1H>sctH) ? R1H-sctH : 0); //Crop height from bottom R1Ho = R1Hc; //Offset from top RectPlus=0; } else { // 1 - top toY = 0; R1Hc = ((R1H>sctH) ? R1H-sctH : 0); //Crop height from bottom R1Ho = 0; //Offset from top RectPlus=R1H; } // /////////////////////Draw row////////////////// item = addRect(0, 0, sctW, R1H-R1Hc, Qt::NoPen, QBrush(srcimg.copy(0, R1Ho, R1W, R1H-R1Hc))); item->setData(0, QString("BackGround%1").arg(sctID) ); item->setPos(x, y+toY); item->setZValue(bgZ); if(R1H < sctH) { item = addRect(0, 0, sctW, sctH-R1H, Qt::NoPen, QBrush(FillColor)); item->setData(0, QString("BackGround%1").arg(sctID) ); item->setPos(x,y+RectPlus); item->setZValue(bgZ); } } else // ///////////////////DoubleRow BG//////////////////////// if((bgsetup.type==1)&&(!bgsetup.editing_tiled)) { WriteToLog(QtDebugMsg, "Draw BG -> Style: DoubleRow BG"); si_attach = bgsetup.second_attached; // Second image attach R1W = srcimg.width(); R1H = srcimg.height(); //Fill empty space if((!srcimg2.isNull()) && (si_attach==0)) FillColor = QColor( srcimg2.toImage().pixel(0,0) ); else FillColor = QColor( srcimg.toImage().pixel(0,0) ); toY = (sctH>R1H)? sctH-R1H : 0; R1Hc = ((R1H>sctH) ? R1H-sctH : 0); //Crop height from bottom R1Ho = R1Hc; //Offset from top RectPlus=0; WriteToLog(QtDebugMsg, QString("Draw BG -> Draw first row, params: ")); // /////////////////////Draw first row////////////////// item = addRect(0, 0, sctW, R1H-R1Hc, Qt::NoPen, QBrush(srcimg.copy(0, R1Ho, R1W, R1H-R1Hc))); item->setData(0, QString("BackGround%1").arg(sctID) ); item->setPos(x, y+toY); item->setZValue(bgZ); // /////////////////////Draw first row////////////////// WriteToLog(QtDebugMsg, "Draw BG -> Draw second row"); R2W = srcimg2.width(); R2H = srcimg2.height(); if(si_attach==0) // over first { toY = (sctH-R1H > R2H)? sctH-R2H-R1H : 0; R2Hc = ((R2H+R1H>sctH) ? R2H-(sctH-R1H) : 0); //Crop height from bottom R2Ho = R2Hc; //Offset from top RectPlus=R2H; } else if(si_attach==1) // bottom { toY = (sctH > R2H)? sctH-R2H : 0; R2Hc = ((R2H>sctH) ? R2H-sctH : 0); //Crop height from bottom R2Ho = R2Hc; //Offset from top RectPlus=0; } if((!srcimg2.isNull()) && ((sctH > R1H)||(si_attach==1))) { // /////////////////////Draw second row////////////////// item = addRect(0, 0, sctW, R2H-R2Hc, Qt::NoPen, QBrush( srcimg2.copy(0, R2Ho, R2W, R2H-R2Hc) )); item->setData(0, QString("BackGround%1").arg(sctID) ); item->setPos(x, y+toY); item->setZValue(bgZ+0.0000000001); // /////////////////////Draw second row////////////////// } else if(srcimg2.isNull()) WriteToLog(QtWarningMsg, "Draw BG -> second image is Null"); if( R1H+RectPlus < sctH ) { item = addRect(0, 0, sctW, sctH-R1H-RectPlus, Qt::NoPen, QBrush(FillColor)); item->setData(0, QString("BackGround%1").arg(sctID) ); item->setPos(x,y); item->setZValue(bgZ); } } else // ///////////////////////////////Tiled BG/////////////////////////////// { WriteToLog(QtDebugMsg, "Draw BG -> Style: Tiled"); R1W = srcimg.width(); R1H = srcimg.height(); if(attach==0) { //Attached to Bottom RectPlus = sctH % R1H; toY = (sctH>R1H)? sctH-R1H : 0; //R1Hc = R1H-RectPlus; // Crop height from bottom/Offset from top item = addRect(0, 0, sctW, RectPlus, Qt::NoPen, QBrush(srcimg.copy(0, R1H-RectPlus, R1W, RectPlus)) ); item->setData(0, QString("BackGround%1").arg(sctID) ); item->setPos(x,y); item->setZValue(bgZ); if(sctH >= R1H) { item = addRect(0, 0, sctW, sctH-RectPlus, Qt::NoPen, QBrush(srcimg)); item->setData(0, "BackGround"+QString::number(sctID) ); item->setPos(x,y+RectPlus); item->setZValue(bgZ); } } else { //Attached to Top item = addRect(0, 0, sctW, sctH, Qt::NoPen, QBrush(srcimg)); item->setData(0, QString("BackGround%1").arg(sctID) ); item->setPos(x,y); item->setZValue(bgZ); } } WriteToLog(QtDebugMsg, "acceptedID is "+QString::number(sctID)+" data is "+item->data(0).toString()); WriteToLog(QtDebugMsg, "Draw BG -> Drawed"); }
//-------------------------------------------------------------- void ofxBox2dCompoundShape::addRect( float ax, float ay, float aw, float ah ) { addRect( ofxBox2dCompoundShape::Rectangle( ax, ay, aw, ah )); }