CPoint と CGPoint
以前作成した MemoryStatus クラスを利用して,Win , iOS で書いてみた.
MemoryStatus の配列として,MemoryStatusAry を作成.
また,float の配列をそれぞれの点配列に変換する ::GraphGetPoint を用意.
Win
void CMemSSDView::OnPaint()
{
CPaintDC dc(this);
CRect rect ;
GetClientRect(rect) ;
{
std::vector<float> grphF = MemSA.GetGraph(MemoryStatusAry::WinPhysF) ;
std::vector<float> grphT = MemSA.GetGraph(MemoryStatusAry::WinPhysT) ;
std::vector<float> grphP = MemSA.GetGraph(MemoryStatusAry::WinPageF) ;
std::vector<CPoint> pntsF = ::GraphGetPoint(grphF,rect) ;
std::vector<CPoint> pntsT = ::GraphGetPoint(grphT,rect) ;
std::vector<CPoint> pntsP = ::GraphGetPoint(grphP,rect) ;
{
CPen penGreen(PS_SOLID,1,RGB(0,192,0)) ;
CPen* oldPen = dc.SelectObject(&penGreen) ;
dc.Polyline(&pntsF[0],pntsF.size()) ;
CPen penRed(PS_SOLID,1,RGB(192,0,0)) ;
oldPen = dc.SelectObject(&penRed) ;
dc.Polyline(&pntsT[0],pntsT.size()) ;
CPen penBlue(PS_SOLID,1,RGB(0,0,192)) ;
oldPen = dc.SelectObject(&penBlue) ;
dc.Polyline(&pntsP[0],pntsP.size()) ;
dc.SelectObject(oldPen) ;
}
}
}
iOS
- (void)drawRect:(CGRect)rect
{
_context = UIGraphicsGetCurrentContext() ;
{
std::vector<float> grphP = MemSA.GetGraph(MemoryStatusAry::MacPFree) ;
std::vector<float> grphA = MemSA.GetGraph(MemoryStatusAry::MacInact) ;
std::vector<float> grphW = MemSA.GetGraph(MemoryStatusAry::MacWired) ;
std::vector<CGPoint> pntsP = ::GraphGetPoint(grphP,rect) ;
std::vector<CGPoint> pntsA = ::GraphGetPoint(grphA,rect) ;
std::vector<CGPoint> pntsW = ::GraphGetPoint(grphW,rect) ;
{
[self setColor_r:0 g:192 b:0] ;
CGContextAddLines (_context,&pntsP[0],pntsP.size()) ;
CGContextStrokePath (_context) ;
[self setColor_r:0 g:0 b:192] ;
CGContextAddLines (_context,&pntsA[0],pntsA.size()) ;
CGContextStrokePath (_context) ;
[self setColor_r:192 g:0 b:0] ;
CGContextAddLines (_context,&pntsW[0],pntsW.size()) ;
CGContextStrokePath (_context) ;
}
}
}