void CToolRegularRuler::Draw(CDC* pDC, CRect& rcInvalid) { if(m_nPtCount <= 1) { return; } Graphics graph(pDC->m_hDC); graph.SetSmoothingMode(SmoothingModeAntiAlias); Matrix mat; mat.RotateAt(m_fAngle,m_ptCenter); graph.SetTransform(&mat); Pen penDraw(m_crColor, 2); RectF rcf(m_ptary[0].X, m_ptary[0].Y, m_ptary[1].X - m_ptary[0].X, m_ptary[1].Y - m_ptary[0].Y); DrawRulerMarks(graph); graph.DrawRectangle(&penDraw, rcf); if(m_bSelected || m_bEdit) { DrawHotShape(graph); } }
SizeF BUIEdit::getTextSize(const bstring text) { m_textDesc.content = text; RectF rcf(getContentRect().left, getContentRect().top, getContentRect().right - getContentRect().left + 100, getContentRect().bottom - getContentRect().top); return BRenderEngineManager::GetInstance()->RenderEngine()->GetTextSize(m_pUIManager->GetPaintDC(), rcf, m_textDesc); //return BRenderEngineManager::GetInstance()->RenderEngine()->GetTextSize(text, m_textDesc.fontFamily, m_textDesc.fontSize, m_textDesc.style); }
void TempoTrackV2::calculateBeatPeriod(const vector<double> &df, vector<double> &beat_period, vector<double> &tempi) { // to follow matlab.. split into 512 sample frames with a 128 hop size // calculate the acf, // then the rcf.. and then stick the rcfs as columns of a matrix // then call viterbi decoding with weight vector and transition matrix // and get best path unsigned int wv_len = 128; double rayparam = 43.; // make rayleigh weighting curve d_vec_t wv(wv_len); for (unsigned int i=0; i<wv.size(); i++) { wv[i] = (static_cast<double> (i) / pow(rayparam,2.)) * exp((-1.*pow(-static_cast<double> (i),2.)) / (2.*pow(rayparam,2.))); } // beat tracking frame size (roughly 6 seconds) and hop (1.5 seconds) unsigned int winlen = 512; unsigned int step = 128; // matrix to store output of comb filter bank, increment column of matrix at each frame d_mat_t rcfmat; int col_counter = -1; // main loop for beat period calculation for (unsigned int i=0; i+winlen<df.size(); i+=step) { // get dfframe d_vec_t dfframe(winlen); for (unsigned int k=0; k<winlen; k++) { dfframe[k] = df[i+k]; } // get rcf vector for current frame d_vec_t rcf(wv_len); get_rcf(dfframe,wv,rcf); rcfmat.push_back( d_vec_t() ); // adds a new column col_counter++; for (unsigned int j=0; j<rcf.size(); j++) { rcfmat[col_counter].push_back( rcf[j] ); } } // now call viterbi decoding function viterbi_decode(rcfmat,wv,beat_period,tempi); }
void BUIEdit::PaintText(HDC hDC) { RECT rcPaint; if (IntersectRect(&rcPaint, &m_rcPaint, &getContentRect())) { m_textDesc.content = m_strText.substr(m_beginDrawPlace); m_textDesc.selectedBegin = m_selectedBeginPalce - m_beginDrawPlace; m_textDesc.selectedCount = m_selectedEndPlace - m_selectedBeginPalce; RectF rcf(rcPaint.left, rcPaint.top, rcPaint.right - rcPaint.left, rcPaint.bottom - rcPaint.top); m_textDesc.selectedBkColor = 0xAACC6600; BRenderEngineManager::GetInstance()->RenderEngine()->DrawText(hDC, rcf, m_textDesc); } }
void MapReprojector::reproject(shared_ptr<OsmMap> map, shared_ptr<OGRSpatialReference> ref) { shared_ptr<OGRSpatialReference> sourceSrs = map->getProjection(); OGRCoordinateTransformation* t(OGRCreateCoordinateTransformation(sourceSrs.get(), ref.get())); if (t == 0) { throw HootException(QString("Error creating transformation object: ") + CPLGetLastErrorMsg()); } ReprojectCoordinateFilter rcf(t); int count = 0; const NodeMap& nodes = map->getNodeMap(); for (NodeMap::const_iterator it = nodes.begin(); it != nodes.end(); ++it) { Node* n = it->second.get(); Coordinate c = n->toCoordinate(); try { rcf.project(&c); } catch(IllegalArgumentException& e) { LOG_WARN("Failure projecting node: " << n->toString()); throw e; } n->setX(c.x); n->setY(c.y); if (count % 1000 == 0 && Log::getInstance().isInfoEnabled()) { cout << "Reprojecting " << count << " / " << nodes.size() << " \r"; cout.flush(); } count++; } if (Log::getInstance().isInfoEnabled()) { cout << endl; } map->setProjection(ref); OGRCoordinateTransformation::DestroyCT(t); }
void CToolRegularRuler::SetRegion() { if(!m_bFinish) { return; } float left = min(m_ptary[0].X, m_ptary[1].X); float top = min(m_ptary[0].Y, m_ptary[1].Y); float width = fabs(m_ptary[0].X - m_ptary[1].X); float height = fabs(m_ptary[0].Y - m_ptary[1].Y); RectF rcf(left, top, width, height); m_Region.MakeEmpty(); m_Region.Union(rcf); }
void CRectangle::SetRegion() { float left = min(m_ptary[0].X,m_ptary[1].X); float top = min(m_ptary[0].Y,m_ptary[1].Y); float width = fabs(m_ptary[0].X - m_ptary[1].X); float height = fabs(m_ptary[0].Y - m_ptary[1].Y); /*PointF* pPt = m_ptary.GetData();*/ int nWidth = m_nWidth; if(m_nWidth < 6) { nWidth = 6; } Pen greenPen(Color(255, 0, 255, 0), (float)nWidth); GraphicsPath path; if(RS_ROUND == m_nRStyle) { CRect rc((int)left,(int)top,(int)(left + width),(int)(top + height)); INT offsetX = (rc.right - rc.left) * 20/100; INT offsetY = (rc.bottom - rc.top) * 20/100; path.AddArc(rc.right - offsetX, rc.top, offsetX, offsetY, 270, 90); path.AddArc(rc.right - offsetX, rc.bottom - offsetY, offsetX, offsetY, 0, 90); path.AddArc(rc.left, rc.bottom - offsetY, offsetX, offsetY, 90, 90); path.AddArc(rc.left, rc.top, offsetX, offsetY, 180, 90); path.AddLine(rc.left + offsetX, rc.top, rc.right - offsetX/2, rc.top); } else { RectF rcf(left,top,width,height); path.AddRectangle(rcf); } path.Widen(&greenPen); path.Outline(); m_Region.MakeEmpty(); m_Region.Union(&path); }
/* 通知自绘的消息入口。 流程: 1、CDDS_PREPAINT 开始自绘,如果 返回 CDRF_DODEFAULT,则 CListCtrl 自行绘制。 如果不存在内存dc,bmp,则创建之,用于绘制。 或者在 OnEraseBkgndCustom 中创建。 2、CDDS_ITEMPREPAINT,绘制每个 Item。 3、CDDS_POSTPAINT,绘制结束。 将内存dc,bmp中的数据拷贝到实际dc中,并删除内存dc,bmp。 */ void CxResLibImgList::OnNMCustomdraw(NMHDR *pNMHDR, LRESULT *pResult) { static const DWORD CDDS_SUBITEMPREPAINT = (DWORD)(CDDS_ITEMPREPAINT | CDDS_SUBITEM); static const DWORD CDDS_SUBITEMPOSTPAINT = (CDDS_ITEMPOSTPAINT | CDDS_SUBITEM); static int nDrawCount = 0; LPNMLVCUSTOMDRAW lplvcd = reinterpret_cast<LPNMLVCUSTOMDRAW>(pNMHDR); // TODO: 在此添加控件通知处理程序代码 //if (lplvcd == NULL) return; switch(lplvcd->nmcd.dwDrawStage) { //整个控件的绘制循环开始前。 //如果此处返回 CDRF_DODEFAULT,控件将自己绘制自己,不会再收到任何通知。 case CDDS_PREPAINT: { if (m_pBmpCanvas != NULL || m_pGraphics != NULL) { delete m_pGraphics; m_pGraphics = NULL; delete m_pBmpCanvas; m_pBmpCanvas = NULL; } if (m_pBmpCanvas == NULL && m_pGraphics == NULL) { CRect rc; GetClientRect(&rc); m_pBmpCanvas = new Bitmap(rc.Width(), rc.Height(), PixelFormat32bppARGB); m_pGraphics = new Graphics(m_pBmpCanvas); //设定透明模式,和点阵模式,如果不设定会出现毛边,造成图形边界不是很平滑 m_pGraphics->SetSmoothingMode(SmoothingModeAntiAlias); m_pGraphics->SetPixelOffsetMode(PixelOffsetModeHighQuality); //m_pGraphics->SetTextRenderingHint(TextRenderingHintAntiAlias); //擦除背景 RectF rcf((float)rc.left, (float)rc.top, (float)rc.Width(), (float)rc.Height()); SolidBrush br(m_crCanvasBk); m_pGraphics->FillRectangle(&br, rcf); nDrawCount = 0; //ZTools::WriteZToolsFormatLog( "CxResLibImgList::OnNMCustomdraw %s", "创建Canvas\r\n" ); } } *pResult = CDRF_NOTIFYITEMDRAW //Item 绘制前后,通知 | CDRF_NOTIFYPOSTPAINT //整个控件绘制完成后,通知 | CDRF_NOTIFYPOSTERASE //擦除之后,通知。完全不起作用,个人理解,可以通过实现 OnEraseBkgnd 替代。 | CDRF_NOTIFYSUBITEMDRAW //子Item 绘制前后,通知 ; break; case CDDS_POSTPAINT: //整个控件的绘制循环完成。 { if (m_pBmpCanvas != NULL && m_pGraphics != NULL ) { BOOL bDraw = TRUE; if ( m_vImg.size() > 1 && nDrawCount <= 1 ) { bDraw = FALSE; } else { //xp下,当有其他窗口档在最后一个组件上时,右侧区域不被绘制 DWORD dwBakSpec = lplvcd->nmcd.dwItemSpec; for (int i=0; i<(int)m_vImg.size(); i++) { lplvcd->nmcd.dwItemSpec = i; OnItemPaint(lplvcd); } lplvcd->nmcd.dwItemSpec = dwBakSpec; } //if ( bDraw ) { Graphics g(lplvcd->nmcd.hdc); CachedBitmap cachedBmp(m_pBmpCanvas, &g); g.DrawCachedBitmap(&cachedBmp, 0, 0); g.ReleaseHDC(lplvcd->nmcd.hdc); } delete m_pGraphics; m_pGraphics = NULL; delete m_pBmpCanvas; m_pBmpCanvas = NULL; nDrawCount = 0; //ZTools::WriteZToolsFormatLog( "CxResLibImgList::OnNMCustomdraw %s", "拷贝Canvas到DC\r\n" ); } } *pResult = CDRF_DODEFAULT; break; case CDDS_PREERASE: // Before the erase cycle begins case CDDS_POSTERASE: // After the erase cycle is complete case CDDS_ITEMPREERASE: // Before an item is erased case CDDS_ITEMPOSTERASE: // After an item has been erased // these are not handled now, but you might like to do so in the future *pResult = CDRF_DODEFAULT; break; //Before an item is drawn. case CDDS_ITEMPREPAINT: // Item 绘制前 if ( !OnItemPaint(lplvcd) ) *pResult = CDRF_DODEFAULT; //失败 else { //成功 nDrawCount++; *pResult = CDRF_NOTIFYSUBITEMDRAW | CDRF_NOTIFYPOSTPAINT | CDRF_SKIPDEFAULT; } //ZTools::WriteZToolsFormatLog( "CxResLibImgList::OnNMCustomdraw %s", "OnItemPaint\r\n" ); break; //After an item is drawn. case CDDS_ITEMPOSTPAINT: //Item 绘制完成后 //*pResult = CDRF_DODEFAULT; //*pResult = CDRF_SKIPDEFAULT; *pResult = CDRF_NOTIFYSUBITEMDRAW; break; //Before an sub-item is drawn. case CDDS_SUBITEMPREPAINT: //SubItem 绘制前 *pResult = CDRF_DODEFAULT; break; ////after an sub-item is drawn. case CDDS_SUBITEMPOSTPAINT: //SubItem 绘制完成后 *pResult = CDRF_DODEFAULT; break; } //*pResult = 0; 通过返回值控制绘制的各个阶段 }
void CAngleLabel::DrawAngleLabelMark(Graphics& graph) { CPoint pt2((int)m_ptary[1].X, (int)m_ptary[1].Y); CPoint pt3((int)m_ptary[2].X, (int)m_ptary[2].Y); float fAngle3 = 0.0f; float fAngle1 = CalcRotateAngle(pt2, m_ptary[0]) - 90.0f; float fAngle2 = CalcRotateAngle(pt3, m_ptary[0]) - 90.0f; if(fAngle1 > - 90 && fAngle1 <= 0) { if(fAngle2 >= 180 && fAngle2 <= 270) { fAngle2 -= 360; } else if(fAngle2 - fAngle1 >= 180) { fAngle1 += 360; } } else if(fAngle1 >= 0 && fAngle1 <= 90) { if(fAngle2 >= 180) { if(fAngle2 - fAngle1 >= 180) { fAngle2 -= 360; } } } else if(fAngle1 >= 90 && fAngle1 <= 180) { if(fAngle2 >= -90 && fAngle2 <= 0) { if(fAngle1 - fAngle2 >= 180) { fAngle2 += 360; } } } else if(fAngle1 >= 180 && fAngle1 <= 270) { if(fAngle2 >= 0 && fAngle2 <= 90) { if(fAngle1 - fAngle2 >= 180) { fAngle2 += 360; } } else if(fAngle2 >= -90 && fAngle2 <= 0) { fAngle2 += 360; } } fAngle3 = (fAngle1 + fAngle2) / 2.0f; PointF ptDraw; ptDraw.Y = m_ptary[0].Y; if(fabs(fAngle1 - fAngle2) <= 20) { ptDraw.X = 100 + m_ptary[0].X; } else if(fabs(fAngle1 - fAngle2) <= 30) { ptDraw.X = 80 + m_ptary[0].X; } else { ptDraw.X = 60 + m_ptary[0].X; } Matrix mat; mat.RotateAt(fAngle3, m_ptary[0]); mat.TransformPoints(&ptDraw, 1); Pen penDraw(Color::Blue, 2); RectF rcf(m_ptary[0].X - 30, m_ptary[0].Y - 30, 60, 60); graph.DrawArc(&penDraw, rcf, fAngle1, fAngle2 - fAngle1); Font myFont(_T("Arial"), 12); SolidBrush brush(Color::Red); StringFormat format; format.SetAlignment(StringAlignmentCenter); int nAngle = CalLinesAngle(); m_strAngle.Format(_T("%dбу"), nAngle); graph.SetTextRenderingHint(TextRenderingHintAntiAlias); graph.DrawString(m_strAngle, m_strAngle.GetLength(), &myFont, ptDraw, &format, &brush); }