//テキストとその背景に void DrawImpl::textBox(const Vector2& pos, int color, int fontHandle, const std::string &str, int alpha, HorizontalPlace::en fh, VerticalPlace::en fv, const Vector2 &boxMargeV2, int boxColor, int boxAlpha, int blendMode, int boxBlendMode){ Vector2 dPos(0, 0); Vector2 fontSize = Vector2( GetDrawFormatStringWidthToHandle(fontHandle, "%s", str.c_str()), GetFontSizeToHandle(fontHandle) ); if (fh == HorizontalPlace::en::center){ dPos.x -= fontSize.x / 2.0; } else if (fh == HorizontalPlace::en::right){ dPos.x -= fontSize.x; } if (fv == VerticalPlace::en::center){ dPos.y -= fontSize.y / 2.0; } else if (fv == VerticalPlace::en::bottom){ dPos.y -= fontSize.y; } Vector2 shift(-(int)fh * fontSize.x * 0.5, -(int)fv * fontSize.y * 0.5); Vector2 leftTop(pos.x + dx + dPos.x, pos.y + dy + dPos.y); Draw.box(leftTop - boxMargeV2 * 0.5, leftTop + fontSize + boxMargeV2 * 0.5, boxColor, boxAlpha); SetDrawBlendMode(blendMode, alpha); DrawFormatStringToHandle(leftTop.x, leftTop.y, color, fontHandle, "%s", str.c_str()); textDrawLog.set(leftTop, color, fontHandle, alpha, blendMode); }
void VideoViewer::paintEvent(QPaintEvent *event) { QLabel::paintEvent(event); if (!enabledDrawPreviewRegion) { return; } if (isPressed && (currentPoint != QPoint(-1, -1))) { QPainter painter(this); painter.setPen(NOMAL_REGION_COLOR); QPoint leftTop(pressedPoint.x() > currentPoint.x() ? currentPoint.x() : pressedPoint.x(), pressedPoint.y() > currentPoint.y() ? currentPoint.y() : pressedPoint.y()); QPoint rightBottom(pressedPoint.x() > currentPoint.x() ? pressedPoint.x() : currentPoint.x(), pressedPoint.y() > currentPoint.y() ? pressedPoint.y() : currentPoint.y()); QPoint center((leftTop.x() + rightBottom.x()) / 2, (leftTop.y() + rightBottom.y()) / 2); int width = rightBottom.x() - leftTop.x(); int height = rightBottom.y() - leftTop.y(); int radius = 0; switch (shape) { case Shapes::Circle: radius = (int)(sqrt(SQUARE(width) + SQUARE(height)) / 2); painter.drawEllipse(center, radius, radius); break; case Shapes::Ellipse: painter.drawEllipse(center, width / 2, height / 2); break; case Shapes::Rectangle: painter.drawRect(leftTop.x(), leftTop.y(), width, height); break; default: break; } } }
void UBMagnifier::grabPoint(const QPoint &pGrab) { QMatrix transM = UBApplication::boardController->controlView()->matrix(); updPointGrab = pGrab; QPointF itemPos = gView->mapFromGlobal(pGrab); qreal zWidth = width() / (params.zoom * transM.m11()); qreal zWidthHalf = zWidth / 2; qreal zHeight = height() / (params.zoom * transM.m22()); qreal zHeightHalf = zHeight / 2; QPointF pfScLtF(UBApplication::boardController->controlView()->mapToScene(QPoint(itemPos.x(), itemPos.y()))); float x = pfScLtF.x() - zWidthHalf; float y = pfScLtF.y() - zHeightHalf; QPointF leftTop(x,y); QPointF rightBottom(x + zWidth, y + zHeight); QRectF srcRect(leftTop, rightBottom); QPixmap newPixMap(QSize(width(), height())); QPainter painter(&newPixMap); UBApplication::boardController->activeScene()->render(&painter, QRectF(0,0,width(),height()), srcRect); painter.end(); // pMap.fill(Qt::transparent); pMap = newPixMap; pMap.setMask(bmpMask); update(); }
// Do our list line drawing here (for cObjType_List or cObjType_DropList) bool oFontDropDown::drawListLine(EXTListLineInfo *pInfo, EXTCompInfo* pECI) { // draw our text qstring * text = newStringFromParam(1, pECI); // first parameter contains our calculated text :) if (text!=NULL) { GDItextSpecStruct textSpec = mCanvas->textSpec(); str255 fontName; qpoint leftTop(pInfo->mLineRect.left+20, pInfo->mLineRect.top); #ifndef iswin32 leftTop.h += 2; #endif // get our font name EXTfldval fontNameFld; str255 fontNameStr; pInfo->mListPtr->getColVal(pInfo->mLine, mFontColumn, fftCharacter, 0, fontNameFld); fontNameFld.getChar(fontNameStr); GDIsetFontName(&textSpec.mFnt, fontNameStr.cString(), fontNameStr.length()); // and draw our text mCanvas->drawText(text->cString(), leftTop, textSpec); delete text; }; return true; // we have drawn this... };
/// ------------------------------------------------ // /// 长方形 /// [4/18/2014 jianglei.kinly] /// ------------------------------------------------ // xObjectSet XGameMap::CaptureObjectByRectangle( const XVector3& vCenter, xgc_uint32 dwXRadius, xgc_uint32 dwYRadius, const std::function< xgc_bool( xObject ) > &fnFilter ) { XVector3 leftTop( vCenter.x - dwXRadius, vCenter.y - dwYRadius, 0 ); XVector3 rightDown( vCenter.x + dwXRadius, vCenter.y + dwYRadius, 0 ); auto fn = [&]( xObject hObject )->xgc_bool { if( xgc_nullptr == fnFilter || fnFilter( hObject ) ) { XGameObject* pObj = ObjectCast<XGameObject>( hObject ); XGC_ASSERT_RETURN( pObj, false ); return pObj->GetPosX() >= leftTop.x && pObj->GetPosY() >= leftTop.y && pObj->GetPosX() <= rightDown.x && pObj->GetPosY() <= rightDown.y; } return false; }; iRect rc( WorldToArea( vCenter.x - dwXRadius, vCenter.y - dwYRadius ), WorldToArea( vCenter.x + dwXRadius, vCenter.y + dwYRadius ) ); return FetchObject( rc, fn ); }
/*! \func * rect * \params no * \return no */ QRectF EdgeAssotiation::boundingRect() const { if (!sourceNode() || !destNode()) return QRectF(); if(sourcePoint == destPoint) { return QRectF(destPoint.x() - 28, destPoint.y() - 28, 30, 30); } QPointF leftTop(qMin(sourcePoint.x(), destPoint.x())-arrowSize, qMin(sourcePoint.y(), destPoint.y())-arrowSize); QSizeF size(abs(sourcePoint.x() - destPoint.x())+2*arrowSize, abs(sourcePoint.y() - destPoint.y())+2*arrowSize); return QRectF(leftTop, size); }
tLane LaneDetector::DetectLanes(Mat &inputImage, Logger &logger) { DebugImage = Mat::zeros(200, 300, CV_8UC3); Mat binaryImage = MakeBinary(inputImage); // Mat kernel = getStructuringElement(CV_SHAPE_ELLIPSE, Size(5, 5)); // morphologyEx(workingImage, workingImage, MORPH_CLOSE, kernel); if (reseted) { ExtractBorder(inputImage); CrossingDetector leftBot("left_bot.bmp", Point(28, 24), &IsLeft, 0.6); CrossingDetector leftTop("left_top.bmp", Point(25, 39), &IsLeft, 0.55); BaseLaneLine *left = new InitLine(0, cvRound(binaryImage.cols / 2.0) - 20, border, CLOCKWISE, leftBot, leftTop, laneLogger); CrossingDetector rightBot("right_bot.bmp", Point(13, 12), &IsRight, 0.55); CrossingDetector rightTop("right_top.bmp", Point(9, 25), &IsRight, 0.55); BaseLaneLine *right = new InitLine(cvRound(binaryImage.cols / 2.0) - 20 + 1, binaryImage.cols - 1, border, COUNTER_CLOCKWISE, rightBot, rightTop, laneLogger); leftLine = Ptr<BaseLaneLine>(left); rightLine = Ptr<BaseLaneLine>(right); reseted = false; tLane result = GenerateNormalizedLaneStruct(binaryImage); return result; } leftLine->Log("Left:"); leftLine = leftLine->UpdateLaneLine(binaryImage, *rightLine); leftLine->Log("------"); rightLine->Log("Right:"); rightLine = rightLine->UpdateLaneLine(binaryImage, *leftLine); rightLine->Log("------"); #ifndef NDEBUG cvtColor(binaryImage, DebugImage, CV_GRAY2RGB); leftLine->Draw(DebugImage); rightLine->Draw(DebugImage); line(DebugImage, Point2f(DebugImage.cols / 2.0f - (15 + 8 + 47), 0), Point2f(DebugImage.cols / 2.0f - (15 + 8 + 47), 199), CV_RGB(0, 0, 255)); line(DebugImage, Point2f(DebugImage.cols / 2.0f + (15 + 8), 0), Point2f(DebugImage.cols / 2.0f + (15 + 8), 199), CV_RGB(0, 0, 255)); #endif tLane result = GenerateNormalizedLaneStruct(binaryImage); return result; }
BRect CenterRectOnScreen(BRect source) { BRect screenFrame = BScreen().Frame(); BPoint leftTop((screenFrame.Width() + source.Width()) / 2.0, (screenFrame.Height() + source.Height()) / 2.0); if (leftTop.x < 0.0) leftTop.x = 0.0; if (leftTop.y < 0.0) leftTop.y = 0.0; return source.OffsetToCopy(leftTop); }
void VideoViewer::mouseReleaseEvent(QMouseEvent *event) { if (currentPoint == QPoint(-1, -1)) { emit clicked(event->pos()); } else { QPoint leftTop(pressedPoint.x() > currentPoint.x() ? currentPoint.x() : pressedPoint.x(), pressedPoint.y() > currentPoint.y() ? currentPoint.y() : pressedPoint.y()); QPoint rightBottom(pressedPoint.x() > currentPoint.x() ? pressedPoint.x() : currentPoint.x(), pressedPoint.y() > currentPoint.y() ? pressedPoint.y() : currentPoint.y()); emit drawNewRegion(leftTop, rightBottom); } setCurrentPoint(-1, -1); setPressedPoint(-1, -1); isPressed = false; }
inline sf::Vector2<T> getLeftTop(std::vector<sf::Vector2<T>> points) { /// ! TODO: Check there is at least one point. sf::Vector2<T> leftTop(points[0].x, points[0].y); for(sf::Vector2<T> point : points) { if(point.x < leftTop.x) leftTop.x = point.x; if(point.y < leftTop.y) leftTop.y = point.y; } return leftTop; }
void TTimeWindow::_AlignWindow() { BPoint pt = TimeSettings().LeftTop(); MoveTo(pt); BRect frame = Frame(); BRect screen = BScreen().Frame(); if (!frame.Intersects(screen.InsetByCopy(50.0, 50.0))) { BRect bounds(Bounds()); BPoint leftTop((screen.Width() - bounds.Width()) / 2.0, (screen.Height() - bounds.Height()) / 2.0); MoveTo(leftTop); } }
BPoint TimeSettings::LeftTop() const { BPath path; BPoint leftTop(-1000.0, -1000.0); if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) == B_OK) { path.Append(fSettingsFile.String()); BFile file(path.Path(), B_READ_ONLY); if (file.InitCheck() == B_OK) { BPoint tmp; if (file.Read(&tmp, sizeof(BPoint)) == sizeof(BPoint)) leftTop = tmp; } } return leftTop; }
/*! Offsets a rectangle's location so that it lies fully in a given rectangular frame. If the rectangle is too wide/high to fully fit in the frame, its left/top edge is offset to 0. The rect's size always remains unchanged. \param rect The rectangle to be moved. \param frameSize The size of the frame the rect shall be moved into. The frame's left-top is (0, 0). \return The modified rect. */ /*static*/ BRect BLayoutUtils::MoveIntoFrame(BRect rect, BSize frameSize) { BPoint leftTop(rect.LeftTop()); // enforce horizontal limits; favor left edge if (rect.right > frameSize.width) leftTop.x -= rect.right - frameSize.width; if (leftTop.x < 0) leftTop.x = 0; // enforce vertical limits; favor top edge if (rect.bottom > frameSize.height) leftTop.y -= rect.bottom - frameSize.height; if (leftTop.y < 0) leftTop.y = 0; return rect.OffsetToSelf(leftTop); }
void CTriThreshold::OnPaint() { CPaintDC dc(this); CRect rect; CDC memDC; CPoint leftTop(mPosition, 0); //Get the rectangle we're supposed to paint: GetClientRect(&rect); dc.IntersectClipRect(&rect); memDC.CreateCompatibleDC(&dc); //Fill in the background with the same color as the dialog: dc.FillSolidRect(&rect, dc.GetNearestColor(GetSysColor(COLOR_3DFACE))); //Actually draw the triangle: //Who WAS that masked Bitmap? DrawMaskedBitmap(&dc, IDB_TRIANGLE, IDB_TRIANGLE_MASK, leftTop); }
void UiEditorPanel::drawFrame() { CCSize size = CCSize(1000, 800); CCPoint leftBottom(0, 0); CCPoint leftTop(0, size.height); CCPoint rightBottom(size.width, 0); CCPoint rightTop(size.width, size.height); CCDrawNode *drawNode = CCDrawNode::create(); addChild(drawNode); drawNode->drawSegment(leftBottom, rightBottom, 0.5f, ccc4f(0.5f, 0.5f, 0.5f, 1)); drawNode->drawSegment(rightBottom, rightTop, 0.5f, ccc4f(0.5f, 0.5f, 0.5f, 1)); drawNode->drawSegment(rightTop, leftTop, 0.5f, ccc4f(0.5f, 0.5f, 0.5f, 1)); drawNode->drawSegment(leftTop, leftBottom, 0.5f, ccc4f(0.5f, 0.5f, 0.5f, 1)); auto winSize = CCDirector::sharedDirector()->getWinSize(); auto offset = ccp((winSize.width - size.width) * 0.5f, (winSize.height - size.height) * 0.5f); drawNode->setPosition(offset); }
// Do our list content drawing here (what we see when the list is collapsed, for cObjType_DropList only) bool oFontDropDown::drawListContents(EXTListLineInfo *pInfo, EXTCompInfo* pECI) { // Draw our text if (pInfo->mLine > 0) { EXTfldval * calcFld; EXTfldval fval; ECOgetProperty(mHWnd,anumListCalc,fval); qstring calculation(fval); calcFld = newCalculation(calculation, pECI); if (calcFld != NULL) { EXTfldval result; calcFld->evalCalculation(result, pECI->mLocLocp, NULL, qfalse); qstring text(result); GDItextSpecStruct textSpec = mCanvas->textSpec(); str255 fontName; qpoint leftTop(pInfo->mLineRect.left+10, pInfo->mLineRect.top); #ifndef iswin32 leftTop.h += 2; #endif // get our font name EXTfldval fontNameFld; str255 fontNameStr; pInfo->mListPtr->getColVal(pInfo->mLine, mFontColumn, fftCharacter, 0, fontNameFld); fontNameFld.getChar(fontNameStr); GDIsetFontName(&textSpec.mFnt, fontNameStr.cString(), fontNameStr.length()); // and draw our text mCanvas->drawText(text.cString(), leftTop, textSpec); delete calcFld; }; }; return true; };
Point3D BodyRegion::getPosition(Region region) { Point3D ret = m_center; switch (region) { case LeftTop: ret = leftTop(); break; case Top: ret = top(); break; case RightTop: ret = rightTop(); break; case Left: ret = left(); break; case Center: ret = center(); break; case Right: ret = right(); break; case LeftBottom: ret = leftBottom(); break; case Bottom: ret = bottom(); break; case RightBottom: ret = rightBottom(); break; default: break; } return ret; }
void LivingRoom::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags) { //画线,用于测试像素坐标和格子坐标的转换 Vec2 point = Vec2(GRIDMAP_ORIGIN_VERTEX_X, GRIDMAP_ORIGIN_VERTEX_Y); float slopeRightTop = 1.0 / std::sqrt(3.0); float slopeLeftTop = -1.0 / std::sqrt(3.0); int unitX = GRID_WIDTH_X / 2; int unitY = GRID_WIDTH_Y / 2; glLineWidth(1.0f); for (int i = 0; i < 19; ++i) { Vec2 leftBottom(0, (0 - point.x) * slopeRightTop + point.y); Vec2 rightTop(1080, (1080 - point.x) * slopeRightTop + point.y); DrawPrimitives::drawLine(leftBottom, rightTop); Vec2 leftTop(0, (0 - point.x) * slopeLeftTop + point.y); Vec2 rightBottom(1080, (1080 - point.x) * slopeLeftTop + point.y); DrawPrimitives::drawLine(leftTop, rightBottom); point.y -= unitY * 2; } }
void NaoHeadControl::ScanAwayFromBall() { float neckYaw, headPitch; if ( headPathPlanner.isLastPathFinished()) { if (lastScanWasLeft) { Vector3f centerTop(0.0,45.0,headPathPlanner.lastNeckYaw), rightTop(0.0,45.0,-120.0), rightBottom(0.0,-45.0,-120.0); Vector3f points[4]={centerTop,rightTop, rightBottom, headDown}; headPathPlanner.oldInit(points, sizeof(points)/sizeof(Vector3f), 600); } else { Vector3f centerTop(0.0,45.0,headPathPlanner.lastNeckYaw), leftTop(0.0,45.0,120.0), leftBottom(0.0,-45.0,120.0); Vector3f points[4]={centerTop,leftTop, leftBottom, headDown}; headPathPlanner.oldInit(points, sizeof(points)/sizeof(Vector3f), 600); } lastScanWasLeft = !lastScanWasLeft; } headPathPlanner.getAngles(neckYaw, headPitch); setJointsDirect(neckYaw, headPitch); }
void JobItem::DrawItem(BView *owner, BRect, bool complete) { BListView* list = dynamic_cast<BListView*>(owner); if (list) { BFont font; owner->GetFont(&font); font_height height; font.GetHeight(&height); float fntheight = height.ascent + height.descent + height.leading; BRect bounds = list->ItemFrame(list->IndexOf(this)); rgb_color color = owner->ViewColor(); rgb_color oldLowColor = owner->LowColor(); rgb_color oldHighColor = owner->HighColor(); if (IsSelected()) color = ui_color(B_LIST_SELECTED_BACKGROUND_COLOR); owner->SetHighColor(color); owner->SetLowColor(color); owner->FillRect(bounds); owner->SetLowColor(oldLowColor); owner->SetHighColor(oldHighColor); BPoint iconPt(bounds.LeftTop() + BPoint(2.0, 2.0)); float iconHeight = B_MINI_ICON; #ifdef HAIKU_TARGET_PLATFORM_HAIKU if (fIcon) iconHeight = fIcon->Bounds().Height(); #endif BPoint leftTop(bounds.LeftTop() + BPoint(12.0 + iconHeight, 2.0)); BPoint namePt(leftTop + BPoint(0.0, fntheight)); BPoint statusPt(leftTop + BPoint(0.0, fntheight * 2.0)); float x = owner->StringWidth(fPages.String()) + 32.0; BPoint pagePt(bounds.RightTop() + BPoint(-x, fntheight)); BPoint sizePt(bounds.RightTop() + BPoint(-x, fntheight * 2.0)); drawing_mode mode = owner->DrawingMode(); #ifdef HAIKU_TARGET_PLATFORM_HAIKU owner->SetDrawingMode(B_OP_ALPHA); #else owner->SetDrawingMode(B_OP_OVER); #endif if (fIcon) owner->DrawBitmap(fIcon, iconPt); // left of item BString name = fName; owner->TruncateString(&name, B_TRUNCATE_MIDDLE, pagePt.x - namePt.x); owner->DrawString(name.String(), name.Length(), namePt); BString status = fStatus; owner->TruncateString(&status, B_TRUNCATE_MIDDLE, sizePt.x - statusPt.x); owner->DrawString(status.String(), status.Length(), statusPt); // right of item owner->DrawString(fPages.String(), fPages.Length(), pagePt); owner->DrawString(fSize.String(), fSize.Length(), sizePt); owner->SetDrawingMode(mode); } }
void JobItem::DrawItem(BView *owner, BRect, bool complete) { BListView* list = dynamic_cast<BListView*>(owner); if (list) { BFont font; owner->GetFont(&font); font_height height; font.GetHeight(&height); float fntheight = height.ascent + height.descent + height.leading; BRect bounds = list->ItemFrame(list->IndexOf(this)); rgb_color color = owner->ViewColor(); rgb_color oldViewColor = color; rgb_color oldLowColor = owner->LowColor(); rgb_color oldHighColor = owner->HighColor(); if (IsSelected()) color = tint_color(color, B_HIGHLIGHT_BACKGROUND_TINT); owner->SetViewColor(color); owner->SetHighColor(color); owner->SetLowColor(color); owner->FillRect(bounds); owner->SetLowColor(oldLowColor); owner->SetHighColor(oldHighColor); BPoint iconPt(bounds.LeftTop() + BPoint(2.0, 2.0)); float iconHeight = B_MINI_ICON; #ifdef ANTARES_TARGET_PLATFORM_ANTARES if (fIcon) iconHeight = fIcon->Bounds().Height(); #endif BPoint leftTop(bounds.LeftTop() + BPoint(12.0 + iconHeight, 2.0)); BPoint namePt(leftTop + BPoint(0.0, fntheight)); BPoint statusPt(leftTop + BPoint(0.0, fntheight * 2.0)); float x = owner->StringWidth(fPages.String()) + 32.0; BPoint pagePt(bounds.RightTop() + BPoint(-x, fntheight)); BPoint sizePt(bounds.RightTop() + BPoint(-x, fntheight * 2.0)); drawing_mode mode = owner->DrawingMode(); #ifdef ANTARES_TARGET_PLATFORM_ANTARES owner->SetDrawingMode(B_OP_ALPHA); #else owner->SetDrawingMode(B_OP_OVER); #endif if (fIcon) owner->DrawBitmap(fIcon, iconPt); // left of item owner->DrawString(fName.String(), fName.Length(), namePt); owner->DrawString(fStatus.String(), fStatus.Length(), statusPt); // right of item owner->DrawString(fPages.String(), fPages.Length(), pagePt); owner->DrawString(fSize.String(), fSize.Length(), sizePt); owner->SetDrawingMode(mode); owner->SetViewColor(oldViewColor); } }
void GraphicsButton::setup() { QRectF r = this->boundingRect(); int mx = m_marginLeft; /// TODO get from keyboard definition int boxWidth = r.width() - m_marginLeft - m_marginRight; int boxHeight = r.height() - m_marginTop - m_marginBottom; /** * if group count = 2, then we have two columns,one aligned left, the other right * if group count = 1, and level count = 2,we have one column, centrally aligned * if group count = 1, and level count = 3,we have two column, left,aligned and right aligned * * Within each column, if one item, align central * if two items, align higher level top, lower level bottom * 1. one cell 2. two cells split vertically, left cell group1, right cell group 2 3. two cells split horizontally, bottom cell level1, top cell level2 (from group1) 4 three cells, split vertically, left cell split horizontally left lower, group 1 level1 left top , group 1 level2 right group2 whatever level 5 four cells , both split horizontally and vertically left low, group 1,level 1 left top, group 1,level 2 right low, group 2, level 1 right top, group 2, level 2 */ // KeyDef * key = m_keydef; switch(m_keydef->decorationCount()) { case 1 : { QRectF rect(mx,m_marginTop,boxWidth,boxHeight); decorateKey(rect,1,1); break; } case 2 : { if (m_keydef->groupCount() == 1) { // split horizontally qreal y = boxHeight/2; QRectF top(mx,m_marginTop,boxWidth,y); QRectF bottom(mx,m_marginTop + y, boxWidth,y); decorateKey(bottom,1,1); decorateKey(top,1,2); } else { qreal x = boxWidth/2; QRectF left(mx,m_marginTop,x,boxHeight); QRectF right(x,m_marginTop,x,boxHeight); decorateKey(left,1,1); decorateKey(right,2,1); } break; } case 3 : { qreal y = boxHeight/2; qreal x = boxWidth/2; QRectF leftTop(mx,m_marginTop,x,y); QRectF leftBottom(mx,m_marginTop+y,x,y); decorateKey(leftBottom,1,1); decorateKey(leftTop,1,2); /// if one group, but third level in the bottom right if (m_keydef->groupCount() == 1) { QRectF right(mx+x,m_marginTop+y,x,y); decorateKey(right,1,3); } else { // otherwise put it in the middle QRectF right(mx+x,m_marginTop,x,boxHeight); decorateKey(right,2,1); } break; } case 4: { qreal y = boxHeight/2; qreal x = boxWidth/2; QRectF leftTop(mx,m_marginTop,x,y); QRectF leftBottom(mx,m_marginTop+y,x,y); QRectF rightTop(mx+x,m_marginTop,x,y); QRectF rightBottom(mx+x,m_marginTop+y,x,y); decorateKey(leftBottom,1,1); decorateKey(leftTop,1,2); decorateKey(rightBottom,2,1); decorateKey(rightTop,2,2); break; } } setPen(QPen(m_keyboardColor)); }
QRectF Grid::boundingRect() const { QPointF leftTop(-m_Width / 2 - MARGIN, -m_Height / 2 - MARGIN); QSizeF size(m_Width + MARGIN, m_Height + MARGIN); return QRectF(leftTop, size); }
void DataSetView::viewportChanged() { if(_viewportX != _viewportX || _viewportY != _viewportY || _viewportW != _viewportW || _viewportH != _viewportH ) //only possible if they are NaN return; #ifdef DEBUG_VIEWPORT std::cout << "viewportChanged!\n" <<std::flush; #endif QVector2D leftTop(_viewportX, _viewportY); QVector2D viewSize(_viewportW, _viewportH); QVector2D rightBottom(leftTop + viewSize); int currentViewportColMin = -1, currentViewportColMax = -1, currentViewportRowMin = -1, currentViewportRowMax = -1; float cumulative = 0; for(int col=0; col<_model->columnCount() && currentViewportColMax == -1; col++) { if(currentViewportColMax == -1 && cumulative > rightBottom.x()) currentViewportColMax = col; cumulative += _dataColsMaxWidth[col]; if(currentViewportColMin == -1 && cumulative > leftTop.x()) currentViewportColMin = col; } if(currentViewportColMax == -1) currentViewportColMax = _model->columnCount(); currentViewportColMin = std::max(0, currentViewportColMin - _viewportMargin); currentViewportColMax = std::min(_model->columnCount(), currentViewportColMax + _viewportMargin); currentViewportRowMin = std::max(qRound(leftTop.y() / _dataRowsMaxHeight) - 1, 0); currentViewportRowMax = std::min(qRound(rightBottom.y() / _dataRowsMaxHeight) + 1, _model->rowCount()); // remove superflouous textItems if they exist (aka store them in stack) if(_previousViewportRowMin != -1 && _previousViewportRowMax != -1 && _previousViewportColMin != -1 && _previousViewportColMax != -1) { for(int col=_previousViewportColMin; col<_previousViewportColMax; col++) { for(int row=_previousViewportRowMin; row < currentViewportRowMin; row++) storeTextItem(row, col); for(int row=currentViewportRowMax; row < _previousViewportRowMax; row++) storeTextItem(row, col); } for(int row=_previousViewportRowMin; row<_previousViewportRowMax; row++) { for(int col=_previousViewportColMin; col < currentViewportColMin; col++) storeTextItem(row, col); for(int col=currentViewportColMax; col < _previousViewportColMax; col++) storeTextItem(row, col); } for(int row=_previousViewportRowMin; row < currentViewportRowMin; row++) storeRowNumber(row); for(int row=currentViewportRowMax; row < _previousViewportRowMax; row++) storeRowNumber(row); } _lines.clear(); //and now we should create some new ones! for(int col=currentViewportColMin; col<currentViewportColMax; col++) for(int row=currentViewportRowMin; row<currentViewportRowMax; row++) { QVector2D pos0(_colXPositions[col], _dataRowsMaxHeight + row * _dataRowsMaxHeight); QVector2D pos1(pos0.x() + _dataColsMaxWidth[col], pos0.y()+ _dataRowsMaxHeight); int lineFlags = _model->data(_model->index(row, col), _roleNameToRole["lines"]).toInt(); bool left = (lineFlags & 1 > 0) && pos0.x() > _rowNumberMaxWidth + _viewportX, right = (lineFlags & 2 > 0) && pos1.x() > _rowNumberMaxWidth + _viewportX, up = lineFlags & 4 > 0 && pos0.y() > _dataRowsMaxHeight + _viewportY, down = lineFlags & 8 > 0 && pos1.y() > _dataRowsMaxHeight + _viewportY; createTextItem(row, col); if(left) _lines.push_back(std::make_pair(QVector2D(pos0.x(), pos1.y()), pos0)); if(up) _lines.push_back(std::make_pair(QVector2D(pos1.x(), pos0.y()), pos0)); if(right) _lines.push_back(std::make_pair(QVector2D(pos1.x(), pos0.y()), pos1)); if(down) _lines.push_back(std::make_pair(QVector2D(pos0.x(), pos1.y()), pos1)); } _lines.push_back(std::make_pair(QVector2D(_viewportX, _viewportY), QVector2D(_viewportX, _viewportY + _viewportH))); _lines.push_back(std::make_pair(QVector2D(_viewportX + _rowNumberMaxWidth, _viewportY), QVector2D(_viewportX + _rowNumberMaxWidth, _viewportY + _viewportH))); _lines.push_back(std::make_pair(QVector2D(_viewportX, _viewportY), QVector2D(_viewportX + _viewportW, _viewportY))); _lines.push_back(std::make_pair(QVector2D(_viewportX, _viewportY + _dataRowsMaxHeight), QVector2D(_viewportX + _viewportW, _viewportY + _dataRowsMaxHeight))); for(int row=currentViewportRowMin; row<currentViewportRowMax; row++) { createRowNumber(row); QVector2D pos0(_viewportX, (1 + row) * _dataRowsMaxHeight); QVector2D pos1(_viewportX + _rowNumberMaxWidth, (2 + row) * _dataRowsMaxHeight); if(pos0.y() > _dataRowsMaxHeight + _viewportY) _lines.push_back(std::make_pair(QVector2D(pos0.x(), pos0.y()), QVector2D(pos1.x(), pos0.y()))); if(row == _model->rowCount() - 1 && pos1.y() > _dataRowsMaxHeight + _viewportY) _lines.push_back(std::make_pair(QVector2D(pos0.x(), pos1.y()), QVector2D(pos1.x(), pos1.y()))); } for(int col=currentViewportColMin; col<currentViewportColMax; col++) { createColumnHeader(col); QVector2D pos0(_colXPositions[col], _viewportY); QVector2D pos1(pos0.x() + _dataColsMaxWidth[col], pos0.y() + _dataRowsMaxHeight); if(pos0.x() > _rowNumberMaxWidth + _viewportX) _lines.push_back(std::make_pair(QVector2D(pos0.x(), pos0.y()), QVector2D(pos0.x(), pos1.y()))); if(col == _model->columnCount() - 1 && pos1.x() > _rowNumberMaxWidth + _viewportX) _lines.push_back(std::make_pair(QVector2D(pos1.x(), pos0.y()), QVector2D(pos1.x(), pos1.y()))); } createleftTopCorner(); update(); #ifdef DEBUG_VIEWPORT std::cout << "viewport X: " << _viewportX << " Y: " << _viewportY << " W: " << _viewportW << " H: " << _viewportH << std::endl << std::flush; std::cout << "_previousViewport ColMin: "<<_previousViewportColMin<<" ColMax: "<<_previousViewportColMax<<" RowMin: "<<_previousViewportRowMin<<" RowMax: "<<_previousViewportRowMax<<"\n"; std::cout << "currentViewport ColMin: "<<currentViewportColMin<<" ColMax: "<<currentViewportColMax<<" RowMin: "<<currentViewportRowMin<<" RowMax: "<<currentViewportRowMax<<"\n"<<std::flush; #endif _previousViewportColMin = currentViewportColMin; _previousViewportColMax = currentViewportColMax; _previousViewportRowMin = currentViewportRowMin; _previousViewportRowMax = currentViewportRowMax; }
SpriteFrame::SpriteFrame(const Rectangle& pRectangle, const graphics::TexturePtr& pTexture, bool rotated, const Size2& sourceSize, const Vector2& sourceOffset, const Vector2& pivot) { texture = pTexture; std::vector<uint16_t> indices = {0, 1, 2, 1, 3, 2}; Vector2 textCoords[4]; Vector2 finalOffset(-sourceSize.width * pivot.x + sourceOffset.x, -sourceSize.height * pivot.y + (sourceSize.height - pRectangle.height - sourceOffset.y)); const Size2& textureSize = texture->getSize(); if (!rotated) { Vector2 leftTop(pRectangle.x / textureSize.width, pRectangle.y / textureSize.height); Vector2 rightBottom((pRectangle.x + pRectangle.width) / textureSize.width, (pRectangle.y + pRectangle.height) / textureSize.height); if (texture->isFlipped()) { leftTop.y = 1.0f - leftTop.y; rightBottom.y = 1.0f - rightBottom.y; } textCoords[0] = Vector2(leftTop.x, rightBottom.y); textCoords[1] = Vector2(rightBottom.x, rightBottom.y); textCoords[2] = Vector2(leftTop.x, leftTop.y); textCoords[3] = Vector2(rightBottom.x, leftTop.y); } else { Vector2 leftTop = Vector2(pRectangle.x / textureSize.width, pRectangle.y / textureSize.height); Vector2 rightBottom = Vector2((pRectangle.x + pRectangle.height) / textureSize.width, (pRectangle.y + pRectangle.width) / textureSize.height); if (texture->isFlipped()) { leftTop.y = 1.0f - leftTop.y; rightBottom.y = 1.0f - rightBottom.y; } textCoords[0] = Vector2(leftTop.x, leftTop.y); textCoords[1] = Vector2(leftTop.x, rightBottom.y); textCoords[2] = Vector2(rightBottom.x, leftTop.y); textCoords[3] = Vector2(rightBottom.x, rightBottom.y); } rectangle = Rectangle(finalOffset.x, finalOffset.y, pRectangle.width, pRectangle.height); std::vector<graphics::VertexPCT> vertices = { graphics::VertexPCT(Vector3(finalOffset.x, rectangle.y, 0.0f), graphics::Color(255, 255, 255, 255), textCoords[0]), graphics::VertexPCT(Vector3(finalOffset.x + rectangle.width, rectangle.y, 0.0f), graphics::Color(255, 255, 255, 255), textCoords[1]), graphics::VertexPCT(Vector3(finalOffset.x, rectangle.y + rectangle.height, 0.0f), graphics::Color(255, 255, 255, 255), textCoords[2]), graphics::VertexPCT(Vector3(finalOffset.x + rectangle.width, rectangle.y + rectangle.height, 0.0f), graphics::Color(255, 255, 255, 255), textCoords[3]) }; meshBuffer = sharedEngine->getRenderer()->createMeshBuffer(); meshBuffer->initFromBuffer(indices.data(), sizeof(uint16_t), static_cast<uint32_t>(indices.size()), false, vertices.data(), graphics::VertexPCT::ATTRIBUTES, static_cast<uint32_t>(vertices.size()), true); }