QRectF Projection::toProjectedRectF(const QRectF& Viewport, const QRect& screen) const { QPointF tl, br; QRectF pViewport; tl = project(Viewport.topLeft()); br = project(Viewport.bottomRight()); pViewport = QRectF(tl, br); QPointF pCenter(pViewport.center()); qreal wv, hv; //wv = (pViewport.width() / Viewport.londiff()) * ((double)screen.width() / Viewport.londiff()); //hv = (pViewport.height() / Viewport.latdiff()) * ((double)screen.height() / Viewport.latdiff()); qreal Aspect = (double)screen.width() / screen.height(); qreal pAspect = fabs(pViewport.width() / pViewport.height()); if (pAspect > Aspect) { wv = fabs(pViewport.width()); hv = fabs(pViewport.height() * pAspect / Aspect); } else { wv = fabs(pViewport.width() * Aspect / pAspect); hv = fabs(pViewport.height()); } pViewport = QRectF((pCenter.x() - wv/2), (pCenter.y() + hv/2), wv, -hv); return pViewport; }
void CvQueryExecutionPlanView::DrawChildStart (CaSqlQueryExecutionPlanBinaryTree* pQepBinaryTree, CDC* pDC, BOOL bPreview) { int w; BOOL bStart = TRUE; CRect r; CaQepNodeInformation* pNodeInfo = pQepBinaryTree->m_pQepNodeInfo; ASSERT (pNodeInfo); if (!pNodeInfo) return; CWnd* pBox = pNodeInfo->GetQepBox(bPreview); if (!pBox) return; pBox->GetWindowRect (r); ScreenToClient (r); w = r.Width(); CPoint pCenter(r.left + w/2, r.top); CPoint pLeft (pCenter.x - 10, r.bottom); CPoint pRight (pCenter.x + 10, r.bottom); CPen pen (PS_SOLID, 1, RGB (0,0,0)); CPen* old = pDC->SelectObject (&pen); CBrush br (RGB (0,0,0)); bStart = (pQepBinaryTree->m_pQepNodeLeft || pQepBinaryTree->m_pQepNodeRight); CRect rx (pLeft.x, pLeft.y, pLeft.x+5, pLeft.y + 5); pDC->DPtoLP (rx); if (bStart && pQepBinaryTree->m_pQepNodeLeft) pDC->FillRect (rx, &br); rx = CRect (pRight.x, pRight.y, pRight.x+5, pRight.y + 5); pDC->DPtoLP (rx); if (bStart && pQepBinaryTree->m_pQepNodeRight) pDC->FillRect (rx, &br); if (!pNodeInfo->IsRoot()) { rx = CRect (pCenter.x, pCenter.y, pCenter.x+5, pCenter.y - 5); pDC->DPtoLP (rx); pDC->FillRect (rx, &br); } pDC->SelectObject (old); }
void MetalineEnemy::checkToFire() { if (fireCounter >= FIRE_COUNTER_THRESHOLD) { GameState *gs = GameState::GetInstance(); Vector3f playerPos = gs->GetPlayerPosition(); Vector3f pCenter(this->center.x, this->center.y, this->center.z); Vector3f projectileDirection = (playerPos - pCenter).normalized(); Vector3f velocity(projectileDirection(0) * PROJECTILE_SPEED, projectileDirection(1) * PROJECTILE_SPEED, projectileDirection(2) * PROJECTILE_SPEED); Projectile *p = new Ball(pCenter, velocity, PROJECTILE_RADIUS); gs->GetParticleSystems()->AddBullet(p); fireCounter = 0; } else if (fireCounter < FIRE_COUNTER_THRESHOLD) { fireCounter++; } }
bool PopLayer::addButton(const char* normalImage, const char* selectedImage, const char* title, int tag /*= 0*/) { Size visibleSize = Director::getInstance()->getVisibleSize(); Vec2 pCenter(visibleSize.width / 2, visibleSize.height / 2); // 创建图片菜单按钮 MenuItemImage* menuImage = MenuItemImage::create(normalImage, selectedImage, CC_CALLBACK_1(PopLayer::buttonCallback, this)); menuImage->setTag(tag); //menuImage->setPosition(pCenter); // 添加文字说明并设置位置 if(title != NULL) { Size imenu = menuImage->getContentSize(); LabelTTF* ttf = LabelTTF::create(title, "", 20); ttf->setColor(Color3B(0, 0, 0)); ttf->setPosition(Vec2(imenu.width / 2, imenu.height / 2)); menuImage->addChild(ttf); } getMenuButton()->addChild(menuImage); return true; }
void PopLayer::onEnter() { Layer::onEnter(); Size winSize = Director::getInstance()->getVisibleSize(); Vec2 pCenter(winSize.width / 2, winSize.height / 2); Size contentSize; // 设定好参数,在运行时加载 if (getContentSize().equals(Size::ZERO)) { getSpriteBackGround()->setPosition(Vec2(winSize.width / 2, winSize.height / 2)); this->addChild(getSpriteBackGround(), 0, 0); contentSize = getSpriteBackGround()->getTexture()->getContentSize(); } else { Scale9Sprite *background = getSprite9BackGround(); background->setContentSize(getContentSize()); background->setPosition(Vec2(winSize.width / 2, winSize.height / 2)); this->addChild(background, 0, 0); contentSize = getContentSize(); } // 添加按钮,并设置其位置 this->addChild(getMenuButton()); float btnWidth = contentSize.width / (getMenuButton()->getChildrenCount() + 1); Vector<Node *> array = getMenuButton()->getChildren(); getMenuButton()->alignItemsHorizontallyWithPadding(50); getMenuButton()->setPosition(Vec2(winSize.width / 2, winSize.height / 2 - contentSize.height / 3)); // int i = 0; // for(auto &bt: array) // { // Node* node = dynamic_cast<Node*>(bt); // node->setPosition(Vec2( winSize.width / 2 - contentSize.width / 2 + btnWidth * (i + 1), winSize.height / 2 - contentSize.height / 3)); // i++; // } // 显示对话框标题 if (getLabelTitle()){ getLabelTitle()->setPosition((pCenter + Vec2(0, contentSize.height / 2 - 35.0f))); this->addChild(getLabelTitle()); } if(getImgTitle()) { getImgTitle()->setPosition((pCenter + Vec2(0, contentSize.height / 2 - 40.0f))); this->addChild(getImgTitle()); } // 显示文本内容 if (getLabelContentText()){ LabelTTF* ltf = getLabelContentText(); //ltf->setPosition(Vec2(winSize.width / 2, winSize.height / 2)); ltf->setPosition(pCenter); ltf->setDimensions(Size(contentSize.width - m_contentPadding * 2, contentSize.height - m_contentPaddingTop)); ltf->setHorizontalAlignment(TextHAlignment::LEFT); this->addChild(ltf); } // 弹出效果 Action* popupLayer = Sequence::create(ScaleTo::create(0.0, 0.0), ScaleTo::create(0.06, 1.05), ScaleTo::create(0.08, 0.95), ScaleTo::create(0.08, 1.0), NULL); this->runAction(popupLayer); }