long CMapEditor10View::WindowMoveLBU(POINT xy) { int i,j; d_dot temp; CRect rect; CClientDC dc(this); double xOffset; double yOffset; xOffset=m_startPnt.x-xy.x; //获得x方向上的偏移 yOffset=m_startPnt.y-xy.y; //获得y方向上的偏移 GxOffset+=xOffset/GZoom; GyOffset+=yOffset/GZoom; GetClientRect(&rect); //获取客户区矩形 dc.FillRect(&rect,new CBrush(RGB(255,255,255))); //空白覆盖客户区 dc.SetROP2(R2_NOTXORPEN); if(GPntTmpFOpened==1&&GPntNum!=0) { GPntTmpFile.Seek(0,CFile::begin); for(i=0;i<GPntNum;i++) //遍历所有的点 { GPntTmpFile.Read(&PNT_STRU, sizeof( PNT_STRU )); if(PNT_STRU.isDel==GisShowDeleted) //画出没被删掉的点 { temp.x=PNT_STRU.x; temp.y=PNT_STRU.y; DotDPtoVP(temp); //转换坐标 CPen newPen(PS_SOLID,2,RGB(192,192,192)); dc.MoveTo(temp.x,temp.y-6); dc.LineTo(temp.x,temp.y+6); dc.MoveTo(temp.x-6,temp.y); dc.LineTo(temp.x+6,temp.y); } } } if(GLinTmpFOpened==1&&GLinNum!=0) {} if(GRegTmpFOpened==1&&GRegNum!=0) { for(i=1;i<=GRegNum;i++) { if(GetAReg(i,regNdx,regPntdat,500)==1) //得到一个区 { if(regNdx.isDel==GisShowDeleted) //如果该区没被删除 { CPen pen(PS_SOLID,1,regNdx.color); dc.SelectObject(&pen); CBrush brush(regNdx.color); dc.SelectObject (&brush); SomeDotDPtoVP(regPntdat,regNdx.dotNum); //转换坐标 for(j=0;j<regNdx.dotNum;j++) { regPnt[j].x=regPntdat[j].x; regPnt[j].y=regPntdat[j].y; } DrawAReg(regPnt,regNdx.dotNum,&dc); } } } } m_startPnt.x = 0; m_startPnt.y = 0; slectedPnt.x=0; slectedPnt.y=0; return (1); }
void QwtPlotPropertySetDialog::onPropertyValueChanged(QtProperty * property, const QVariant & value) { if(!m_enableSet) return; int id = m_property_id.getPropertyID(property); if (id < ID_CurveIDBase) { switch(id) { case ID_PlotTitle: m_plot->setTitle(value.toString()); return; case ID_PlotFooter: m_plot->setFooter(value.toString()); return; case ID_PlotCanvasBackground: m_plot->setCanvasBackground(QBrush(value.value<QColor>())); return; case ID_PlotEnableZoomerScroll: m_plot->enableZoomerScroll(value.toBool()); return; case ID_PlotAxisSet: setAxisEnable(value.toInt()); return; case ID_XBottomScale: setAxisScaleDrawStyle(QwtPlot::xBottom,value); return; case ID_XTopScale: setAxisScaleDrawStyle(QwtPlot::xTop,value); return; case ID_YLeftScale: setAxisScaleDrawStyle(QwtPlot::yLeft,value); return; case ID_YRightScale: setAxisScaleDrawStyle(QwtPlot::yRight,value); return; case ID_XBottomDateScaleType: m_plot->setAxisDateFormat(QwtPlot::xBottom,ChartWave_qwt::AxisDateScaleType(value.toInt())); return; case ID_XTopDateScaleType: m_plot->setAxisDateFormat(QwtPlot::xTop,ChartWave_qwt::AxisDateScaleType(value.toInt())); return; case ID_YLeftDateScaleType: m_plot->setAxisDateFormat(QwtPlot::yLeft,ChartWave_qwt::AxisDateScaleType(value.toInt())); return; case ID_YRightDateScaleType: m_plot->setAxisDateFormat(QwtPlot::yRight,ChartWave_qwt::AxisDateScaleType(value.toInt())); return; case ID_XBottomInterval: case ID_XTopInterval: case ID_YLeftInterval: case ID_YRightInterval: setAxisScale(id,value.toPointF()); return; case ID_XBottomTitle: case ID_XTopTitle: case ID_YLeftTitle: case ID_YRightTitle: setAxisTitle(id,value.toString()); return; case ID_XBottomLabelRotation: case ID_XTopLabelRotation: case ID_YLeftLabelRotation: case ID_YRightLabelRotation: setAxislabelRotation(id,value.toDouble()); return; } } else { QwtPlotCurve* cur = getCurvePtr(id); if(!cur) return; const int propertyID = getCurvePropertyID(id); if (ID_CurveTitle == propertyID) { cur->setTitle(value.toString()); return; } QPen newPen(cur->pen()); switch (propertyID) { case ID_CurveColore: newPen.setColor(value.value<QColor>()); break; case ID_CurveWidth: newPen.setWidth(value.toInt()); break; case ID_CurvePenStyle: newPen.setStyle(order2penStyle(value.toInt())); break; } cur->setPen(newPen); } }
void NormalState::paintEvent(CoreEdit *ctxt, QPaintEvent *e) { QPainter p( ctxt->viewport() ); int xOffset = ctxt->horizontalScrollBar()->value() + 4; int yOffset = ctxt->verticalScrollBar()->value(); if ( ctxt->highlightCurrentLine() ) { QRect r(0, ctxt->cursorRect().y(), ctxt->viewport()->width(), QFontMetrics( ctxt->document()->defaultFont() ).lineSpacing() ); p.fillRect(r, QColor(0x00, 0xff, 0xff, 0x30)); } if ( ctxt->drawMargin() ) { int margin = QFontMetrics(ctxt->font()).width(" ") * (ctxt->margin() + 1); margin -= xOffset; p.drawLine( margin, 0, margin, ctxt->viewport()->height()); } //I was forced to do these standard painting afterward so as to get rid //of some scrollbars bugs!!! QRect r = e->rect(); p.translate(-xOffset, -yOffset); r.translate(xOffset, yOffset); QAbstractTextDocumentLayout::PaintContext ctx; ctx.palette = ctxt->palette(); if ( ctxt->bCursor && ctxt->isEnabled() && ctxt->hasFocus() ) ctx.cursorPosition = ctxt->textCursor().position(); if ( ctxt->parenMatching() && !ctxt->curLine.isNull() ) { QPen backupPen = p.pen(); QPen newPen(Qt::DotLine); newPen.setWidth(0); newPen.setColor((ctxt->pMatcher ? ctxt->pMatcher->matchColor() : Qt::black)); p.setPen(newPen); const QFontMetrics fm = ctxt->fontMetrics(); const int fontHeight = fm.height(); const int x = ctxt->curLine.x1();// + (fm.width(" ") / 2); int y1 = ctxt->curLine.y1() + 1; int y2 = 0; for (int y = y1; y < ctxt->curLine.y2(); y += fontHeight) { QTextCursor cursor = ctxt->cursorForPosition(QPoint(x, y)); QChar ch = ParenMatcher::charFromCursor(cursor, QTextCursor::NextCharacter); if (ch.isSpace()) y2 = y + fontHeight; else { QChar ch2 = ParenMatcher::charFromCursor(cursor, QTextCursor::PreviousCharacter); if (ch2 == '\t') { ch2 = ParenMatcher::charFromCursor( ctxt->cursorForPosition(QPoint( x - (ctxt->tabStopWidth() / 2), y) ), QTextCursor::NextCharacter); if (ch2 == '\t') y2 = y + fontHeight; else { if (y1 < y2) { QLine lineToPrint(x, y1, x, y2); lineToPrint.translate(xOffset, yOffset); p.drawLine(lineToPrint); } y1 = y + fontHeight; } } else { if (y1 < y2) { QLine lineToPrint(x, y1, x, y2); lineToPrint.translate(xOffset, yOffset); p.drawLine(lineToPrint); } y1 = y + fontHeight; } } } if (y1 < y2) { QLine lineToPrint(x, y1, x, y2); lineToPrint.translate(xOffset, yOffset); p.drawLine(lineToPrint); } p.setPen(backupPen); } p.setClipRect(r); ctx.clip = r; paintSelection(ctxt, p, xOffset, yOffset, ctx); ctxt->document()->documentLayout()->draw(&p, ctx); }
void CHistogramDlg::OnPaint() { CDialog::OnPaint(); // color definition COLORREF black = RGB(0, 0, 0); COLORREF gray; // Get max value of histogram int hmax = 0; for(size_t i = 0; i < hist_value_.size(); i++ ) { if( hmax < hist_value_[i] ) { hmax = hist_value_[i]; } } // drawing CPaintDC dc(&show_hist_); // device context for painting // select new pen and new brush CPen newPen(PS_SOLID, 1, black); CPen* pOldPen = dc.SelectObject(&newPen); CBrush newBrush(black); CBrush* pOldBrush = dc.SelectObject(&newBrush); // get client size CRect rect; show_hist_.GetClientRect(&rect); // draw border dc.MoveTo( rect.left, rect.top ); dc.LineTo( rect.right, rect.top ); dc.MoveTo( rect.right, rect.top ); dc.LineTo( rect.right, rect.bottom ); dc.MoveTo( rect.right, rect.bottom ); dc.LineTo( rect.left, rect.bottom ); dc.MoveTo( rect.left, rect.bottom ); dc.LineTo( rect.left, rect.top ); // draw histogram float width = rect.right - rect.left - 1; float height = rect.bottom - rect.top - 1; float xstart = 1; float top = height; float step = width / hist_value_.size(); rect.bottom = height + 1; for(size_t i = 0; i < hist_value_.size() ; i++) { rect.left = (long)xstart; rect.right = (long)(xstart + step); rect.top = (long)(height + 1 - ((float)hist_value_[i] / hmax) * top); dc.FillRect( rect, &newBrush ); xstart += step; } dc.SelectObject( pOldBrush ); dc.SelectObject( pOldPen ); // IDC_HISTOGRAM_GRAY CPaintDC dc2(&show_gray_); // device context for painting show_gray_.GetClientRect(&rect); // draw border dc2.MoveTo( rect.left, rect.top ); dc2.LineTo( rect.right, rect.top ); dc2.MoveTo( rect.right, rect.top ); dc2.LineTo( rect.right, rect.bottom ); dc2.MoveTo( rect.right, rect.bottom ); dc2.LineTo( rect.left, rect.bottom ); dc2.MoveTo( rect.left, rect.bottom ); dc2.LineTo( rect.left, rect.top ); width = rect.right - rect.left - 1; height = rect.bottom - rect.top - 1; xstart = 1; step = 1; rect.bottom = height + 1; rect.top = 1; for(int i = 0; i < (int)width; i++) { rect.left = (long) xstart; rect.right = (long) (xstart + step); char component = (int)((float)i / width * 256.0); gray = RGB( component, component, component ); CBrush brush(gray); pOldBrush = dc2.SelectObject(&brush); dc2.FillRect( rect, &brush ); xstart += step; dc2.SelectObject( pOldBrush ); } }
void CMFCApplication1View::OnPaint() { CPaintDC dc(this); // device context for painting // TODO: 여기에 메시지 처리기 코드를 추가합니다. // 그리기 메시지에 대해서는 CRecordView::OnPaint()을(를) 호출하지 마십시오. /* POINT initpoint; initpoint.x = 0; initpoint.y = 0; // 점좌표 초기화를 위한 POINT변수 선언. POINT ptMoving = initpoint; // 움직이고 있는 위치(점, Point)를 나타냄. int nRows = 10; // 행(Row)의 수(Number). int nCols = 10; // 열(Column)의 수. int RowInterval = 30; // 행 간의 간격. int ColInterval = RowInterval*1.78; // 열 간의 간격. 16:9 == 1.78 비율. for (int i = 0; i < nRows; i++){ for (int j = 0; j < nCols; j++){ dc.MoveTo(ptMoving.x, ptMoving.y); //dc.MoveTo(int x, int y) => 시작좌표 설정하는 함수. dc.LineTo(ptMoving.x + ColInterval, ptMoving.y); // dc.Lineto(int x, int y) => 끝 좌표까지 직선을 쭉 그어주는 함수. // dc.MoveTo(ptMoving.x + ColInterval, ptMoving.y); dc.LineTo(ptMoving.x + ColInterval, ptMoving.y + RowInterval); // dc.MoveTo(ptMoving.x + ColInterval, ptMoving.y + RowInterval); dc.LineTo(ptMoving.x, ptMoving.y + RowInterval); // dc.MoveTo(ptMoving.x, ptMoving.y + RowInterval); dc.LineTo(ptMoving.x, ptMoving.y); ptMoving.x += ColInterval; } ptMoving.x = initpoint.x; ptMoving.y += RowInterval; } */ CPen newPen(PS_SOLID, 1, RGB(0, 0, 0)); CPen *pOldPen = dc.SelectObject(&newPen); //팬 객체에 대한 포인터 저장.(이전 펜으로 되돌아 갈 시 필요.) int Init_x = 30; int Init_y = 30; int Pos_x = Init_x; int Pos_y = Init_y; int Interval_y = 30; int Interval_x = (int)(Interval_y * 1.78); int nRows = 10; // 행(Row)의 수(Number). int nCols = 10; // 열(Column)의 수. POINT Selected_Seat; // 마우스로 선택한 좌석의 좌표 Selected_Seat.x = 0; Selected_Seat.y = 0; CRgn classroom[10][10]; CRect desk[10][10]; CString strData = _T(""); //strData.Format(_T("X:%03d, Y:%03d"), m_lbdown.x, m_lbdown.y); for (int i = 0; i < nRows; i++){ for (int j = 0; j < nCols; j++){ dc.Rectangle(Pos_x, Pos_y, Pos_x + Interval_x, Pos_y + Interval_y); //이 방법을 쓰면 표시는 된다. desk[i][j] = CRect(Pos_x, Pos_y, Pos_x + Interval_x, Pos_y + Interval_y); // 이렇게 하니까 화면에 표시되지가 않는다, // dc.FillSolidRect(&desk, RGB(0, 0, 0)); 사각형 내부 채우는 함수. // 그래서 위의 CRect를 제대로 표시되지 않더라도 일단 쓴다. classroom[i][j].CreateEllipticRgnIndirect(desk[i][j]); // 이 함수에는 CRect 객체가 필요하다! Pos_x += Interval_x; } Pos_x = Init_x; Pos_y += Interval_y; } if (m_lbdown != m_Oldlbdown){ BOOL result; for (int i = 0; i < nRows; i++){ for (int j = 0; j < nCols; j++){ result = desk[i][j].PtInRect(m_lbdown); if (result) { Selected_Seat.x = i; Selected_Seat.y = j; //strData.Format(_T("%02d행, %02d열입니다."), Selected_Seat.x + 1, Selected_Seat.y + 1); strData.Format(_T("%3d번 좌석입니다."), Selected_Seat.x * 10 + Selected_Seat.y + 1); dc.TextOut(10, 10, strData); } } } m_Oldlbdown = m_lbdown; } }
void specCanvasItem::setPenColor(const QColor& newColor) { QPen newPen(pen()); newPen.setColor(newColor); setPen(newPen) ; }
void specCanvasItem::setLineWidth(const double& w) { QPen newPen(pen()) ; newPen.setWidthF(w) ; setPen(newPen) ; }
void CALLBACK net_motion_test::motion_draw(PLAY_HANDLE handle,HDC hDc,LONG nUser) { net_motion_test* motion_test = (net_motion_test*)nUser; if(!motion_test->is_show_motion()) { return; } CDC* pDc = CDC::FromHandle(hDc); RECT rt; motion_test->GetClientRect(&rt); int w = 0,h = 0,left_w = 0,left_h = 0; w = (rt.right - rt.left) / motion_test->m_motion_col; h = (rt.bottom - rt.top) / motion_test->m_motion_row; left_w = (rt.right - rt.left) % motion_test->m_motion_col; left_h = (rt.bottom - rt.top) % motion_test->m_motion_row; //TRACE("w %d,left w %d\n",w,left_w); //draw h line int i = 0,j = 0; CPen newPen(0,1,RGB(250,0,0)); CPen *oldPen = pDc->SelectObject(&newPen); for(i = 1; i < motion_test->m_motion_row; i++) { pDc->MoveTo(0,h * i); pDc->LineTo(rt.right,h * i); } //draw v line for(i = 1; i < motion_test->m_motion_col; i++) { pDc->MoveTo(w * i,0); pDc->LineTo(w * i,rt.bottom); } pDc->SelectObject(oldPen); CDC ImageDC,MaskDC; ImageDC.CreateCompatibleDC(pDc); ImageDC.SelectObject(&motion_test->m_mask_bmp); MaskDC.CreateCompatibleDC(pDc); MaskDC.BitBlt(0,0,rt.right,rt.bottom,&ImageDC,0,0,SRCCOPY); ImageDC.SetBkColor(RGB(0,0,0)); ImageDC.SetTextColor(RGB(255,255,255)); ImageDC.BitBlt(0,0,rt.right,rt.bottom,&MaskDC,0,0,SRCAND); int morex,morey; for(i = 0; i < motion_test->m_motion_row; i++) { for(j = 0; j < motion_test->m_motion_col; j++) { if(motion_test->is_motion_set(j,i)) { if(j == motion_test->m_motion_col - 1) { morex = left_w; }else{ morex = 0; } if(i == motion_test->m_motion_row -1) { morey = left_h; }else{ morey = 0; } pDc->BitBlt(j * w,i * h,w + morex,h + morey,&MaskDC,0,0,SRCAND); pDc->BitBlt(j * w,i * h,w + morex,h + morey,&ImageDC,0,0,SRCPAINT); } } } ImageDC.DeleteDC(); MaskDC.DeleteDC(); }