void CSpindialCtrl::OnDraw( CDC* pdc, const CRect& rcBounds, const CRect&) { LPRECT lpr; OLE_COLOR color; CBrush br; POINT centerPt; POINT tickpos[MAX_POSITIONS]; CPen* pOldPen; lpr = (LPRECT)(LPCRECT)rcBounds; // Paint background using the ambient background color color = AmbientBackColor(); br.CreateSolidBrush(TranslateColor(color)); pdc->FillRect(lpr, &br); // Draw the dial using a black pen pOldPen = (CPen*)pdc->SelectStockObject(BLACK_PEN); pdc->Ellipse(lpr); // Determine coordinates of center point centerPt.x = lpr->left + ((lpr->right - lpr->left) / 2); centerPt.y = lpr->top + ((lpr->bottom - lpr->top) / 2); // Determine coordinates of intersections of tick marks and dial tickpos[0].x = centerPt.x; tickpos[0].y = lpr->top; tickpos[1].x = lpr->right; tickpos[1].y = centerPt.y; tickpos[2].x = centerPt.x; tickpos[2].y = lpr->bottom; tickpos[3].x = lpr->left; tickpos[3].y = centerPt.y; // Draw each tick mark pdc->MoveTo(tickpos[0]); pdc->LineTo(tickpos[0].x, tickpos[0].y+TICK_LEN); pdc->MoveTo(tickpos[1]); pdc->LineTo(tickpos[1].x-TICK_LEN, tickpos[1].y); pdc->MoveTo(tickpos[2]); pdc->LineTo(tickpos[2].x,tickpos[2].y-TICK_LEN); pdc->MoveTo(tickpos[3]); pdc->LineTo(tickpos[3].x+TICK_LEN, tickpos[3].y); // Draw pointer of dial pdc->MoveTo(centerPt); pdc->LineTo(tickpos[m_needlePosition]); pdc->SelectObject(pOldPen); return; }
void CLREnvelopeEditorCtrl::OnDraw( CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid) { //build memory device context to draw to CDC DrawDC; CDC* pDrawDC=&DrawDC; CBitmap MemoryBitmap; CBitmap* pMemoryBitmap=&MemoryBitmap; CBitmap* pOldBitmap; pDrawDC->CreateCompatibleDC(pdc); pMemoryBitmap->CreateCompatibleBitmap(pdc,rcBounds.right,rcBounds.bottom); pOldBitmap=pDrawDC->SelectObject(pMemoryBitmap); //refresh m_RCCtrlArea with valid one m_RCCtrlArea=rcBounds; m_RCCtrlArea.bottom-=CONTROL_BAR_HEIGHT; //clear background CBrush brBackground(TranslateColor(AmbientBackColor())); pDrawDC->FillRect(m_RCCtrlArea, &brBackground); //draw selected area if present if(m_bHasSelection) { CBrush brSelection; COLORREF selection_color=TranslateColor(AmbientBackColor()); BYTE r_color,g_color,b_color; r_color=GetRValue(selection_color); g_color=GetGValue(selection_color); b_color=GetBValue(selection_color); int sum3=((int)r_color+(int)g_color+(int)b_color)/3; if(sum3>30) { if(r_color>30) r_color-=30; else r_color=0; if(g_color>30) g_color-=30; else g_color=0; if(b_color>30) b_color-=30; else b_color=0; } else { if(r_color<225) r_color+=30; else r_color=255; if(g_color<225) g_color+=30; else g_color=255; if(b_color<225) b_color+=30; else b_color=255; } selection_color=RGB(r_color,g_color,b_color); brSelection.CreateSolidBrush(selection_color); CRect selection_rect; selection_rect.top=0; selection_rect.bottom=m_RCCtrlArea.bottom; selection_rect.left=translateEnvelopeXToScreenX(m_lFirstSelectedPosition); selection_rect.right=translateEnvelopeXToScreenX(m_lLastSelectedPosition); pDrawDC->FillRect(&selection_rect,&brSelection); } //draw X and Y axes CPen axis_pen; axis_pen.CreatePen(PS_SOLID,2,RGB(0,0,0)); CPen* old_pen; old_pen=pDrawDC->SelectObject(&axis_pen); //X pDrawDC->MoveTo(0,translateEnvelopeYToScreenY(0.0f)); pDrawDC->LineTo(m_RCCtrlArea.right,translateEnvelopeYToScreenY(0.0f)); //Y pDrawDC->MoveTo(translateEnvelopeXToScreenX(0),0); pDrawDC->LineTo(translateEnvelopeXToScreenX(0),m_RCCtrlArea.bottom); //draw grid CPen grid_pen; grid_pen.CreatePen(PS_SOLID,1,RGB(0,0,0)); pDrawDC->SelectObject(&grid_pen); //draw control border pDrawDC->MoveTo(0,0); pDrawDC->LineTo(m_RCCtrlArea.right-1,0); pDrawDC->LineTo(m_RCCtrlArea.right-1,m_RCCtrlArea.bottom-1); pDrawDC->LineTo(0,m_RCCtrlArea.bottom-1); pDrawDC->LineTo(0,0); //here grid drawing starts long x_step=calcEnvelopeXStep(); float y_step=calcEnvelopeYStep(); long x_pos; float y_pos; //y x_pos=(m_lFirstKeyPosition/x_step+1)*x_step; while(x_pos<m_lLastKeyPosition) { pDrawDC->MoveTo(translateEnvelopeXToScreenX(x_pos),0); pDrawDC->LineTo(translateEnvelopeXToScreenX(x_pos),m_RCCtrlArea.bottom); x_pos+=x_step; } //x y_pos=((float)floor(m_fLowValue/y_step)+1.0f)*y_step; while(y_pos<m_fHighValue) { pDrawDC->MoveTo(0,translateEnvelopeYToScreenY(y_pos)); pDrawDC->LineTo(m_RCCtrlArea.right,translateEnvelopeYToScreenY(y_pos)); y_pos+=y_step; } //draw curve CPen cpEnvelope; cpEnvelope.CreatePen(PS_SOLID,2,m_CurveColor); pDrawDC->SelectObject(&cpEnvelope); x_pos=0; //beware that now it is screen, not envelope coordinate float fEvalRes=m_pEnvelope->evalEnvelope(translateScreenXToSeconds(x_pos)); pDrawDC->MoveTo(x_pos,translateEnvelopeYToScreenY(fEvalRes)); while(x_pos<m_RCCtrlArea.right) { fEvalRes=m_pEnvelope->evalEnvelope(translateScreenXToSeconds(x_pos)); pDrawDC->LineTo(x_pos,translateEnvelopeYToScreenY(fEvalRes)); x_pos++; } //draw keys if(!(m_bDirtyPositions || m_bDirtyValues)) { long i; long lNumKeys=m_pEnvelope->getNumKeys(); for(i=0;i<lNumKeys;i++) { drawKey(i,pDrawDC); } } //draw bottom bar CBrush white_brush; white_brush.CreateSolidBrush(RGB(255,255,255)); CRect rcBottom=rcBounds; rcBottom.top=rcBounds.bottom-CONTROL_BAR_HEIGHT; pDrawDC->FillRect(rcBottom,&white_brush); pDrawDC->SelectObject(&grid_pen); //draw bottom bar border pDrawDC->MoveTo(0,rcBottom.top); pDrawDC->LineTo(rcBottom.right-1,rcBottom.top); pDrawDC->LineTo(rcBottom.right-1,rcBottom.bottom-1); pDrawDC->LineTo(0,rcBottom.bottom-1); pDrawDC->LineTo(0,rcBottom.top); //draw vertical lines and frame numbers every 10 x_steps in bottom bar CFont cfFrameFont; CString csFrameString; cfFrameFont.CreateFont(8,0,0,0,FW_NORMAL,0,0,0,DEFAULT_CHARSET,OUT_DEVICE_PRECIS, CLIP_DEFAULT_PRECIS,PROOF_QUALITY,FIXED_PITCH,NULL); pDrawDC->SelectObject(&cfFrameFont); pDrawDC->SetBkMode(TRANSPARENT); x_pos=m_lFirstKeyPosition-m_lFirstKeyPosition%(10*x_step)-10*x_step; while(x_pos<m_lLastKeyPosition) { if((x_pos%(10*x_step))==0) { pDrawDC->MoveTo(translateEnvelopeXToScreenX(x_pos),rcBottom.top); pDrawDC->LineTo(translateEnvelopeXToScreenX(x_pos),rcBottom.bottom); csFrameString.Format("%d",x_pos); pDrawDC->TextOut(translateEnvelopeXToScreenX(x_pos), rcBottom.top,csFrameString); } x_pos+=x_step; } pDrawDC->SelectObject(old_pen); pdc->BitBlt(0,0,rcBounds.right,rcBounds.bottom,pDrawDC,0,0,SRCCOPY); pDrawDC->SelectObject(pOldBitmap); pDrawDC->DeleteDC(); }