示例#1
0
void Rectan::Draw(Graphics* graphics)
{
	Pen myPen(m_Color, m_Width);
	graphics->DrawRectangle(&myPen, min(m_x1, m_x2), min(m_y1, m_y2), abs(m_x1 - m_x2), abs(m_y1 - m_y2)); 
	SolidBrush myBrush(m_Background_Color);
	graphics->FillRectangle(&myBrush, min(m_x1, m_x2), min(m_y1, m_y2), abs(m_x1 - m_x2), abs(m_y1 - m_y2));
}
示例#2
0
void AeroControlBase::DrawRect(LPRECT prc, HDC hdcPaint, DashStyle dashStyle, Color clr, REAL width) const
{
    std::unique_ptr<Pen> myPen(new Pen(clr, width));
    myPen->SetDashStyle(dashStyle);
    std::unique_ptr<Graphics> myGraphics(new Graphics(hdcPaint));

    myGraphics->DrawRectangle(myPen.get(), prc->left, prc->top,
        prc->right - 1 - prc->left, prc->bottom - 1 - prc->top);
}
示例#3
0
/*!
 * \brief DrawingArea::fillArea - Залить область.
 * \param point Точка начала заливки.
 * \param act Цвет области, которую нужно залить.
 *
 * Заливает область пользовательским цветом, ограниченную линией другого цвета.
 * Для заливки используется floodFill алгоритм, использующий очередь из точек и
 * продвигающийся по четырем направлениям.
 */
void DrawingArea::fillArea(const QPoint &point, QColor act)
{
    QPainter painter(&image);
             printf("painтттting!!!1\n");
    QPen myPen(myPenColor);
    myPen.setWidth(1);
    painter.setPen(myPen);

    QQueue<QPoint> pixels;
    pixels.enqueue(point);
    while(pixels.isEmpty() == 0)
    {
        QPoint newPoint = pixels.dequeue();
        QColor actual;
        actual.fromRgb(image.pixel(newPoint));
            if(actual == act)
            {
               painter.drawPoint(newPoint);
               update();

               QPoint left((newPoint.x()-1), newPoint.y());
               if(left.x() >0 && left.x() < image.width() && image.pixel(left) == act.rgb())
               {
                   pixels.enqueue(left);
                   painter.drawPoint(left);
                   update();
               }

               QPoint right((newPoint.x()+1), newPoint.y());
               if(right.x() > 0 && right.x() < image.width() && image.pixel(right) == act.rgb())
               {
                   pixels.enqueue(right);
                   painter.drawPoint(right);
                   update();
               }

               QPoint up((newPoint.x()), (newPoint.y()-1));
               if(up.y() > 0 && up.y() < image.height() && image.pixel(up) == act.rgb())
               {
                   pixels.enqueue(up);
                   painter.drawPoint(up);
                   update();
               }

               QPoint down((newPoint.x()), (newPoint.y()+1));
               if(down.y() > 0 && down.y() < image.height() && image.pixel(down) == act.rgb())
               {
                   pixels.enqueue(down);
                   painter.drawPoint(down);
                   update();
               }
            }
      }
}
示例#4
0
文件: shape.cpp 项目: nauhc/CellGUI
void Shape::drawColorBarText(QPainter *painter) {

    int bar_txt_y   = height()*6/7;
    int bar_txt_h   = 20;
    int bar_txt_w   = width()/8;
    QRect txt_old   = QRect(0,                      bar_txt_y, bar_txt_w, bar_txt_h);
    QRect txt_new   = QRect(width()-bar_txt_w-10,   bar_txt_y, bar_txt_w, bar_txt_h);

    QPen myPen(QColor(120, 120, 118));
    painter->setPen(myPen);
    painter->drawText(txt_old, Qt::AlignRight, "0");
    painter->drawText(txt_new, Qt::AlignLeft,  QString::number(maxIndex-begin));
}
示例#5
0
void KateRenderer::paintIndentMarker(QPainter &paint, uint x, uint y /*row*/)
{
  QPen penBackup( paint.pen() );
  QPen myPen(config()->indentationLineColor());
  static const QVector<qreal> dashPattern = QVector<qreal>() << 1 << 1;
  myPen.setDashPattern(dashPattern);
  if (y % 2)
    myPen.setDashOffset(1);
  paint.setPen(myPen);

  const int height = fontHeight();
  const int top = 0;
  const int bottom = height-1;

  QPainter::RenderHints renderHints = paint.renderHints();
  paint.setRenderHints(renderHints, false);

  paint.drawLine(x + 2, top, x + 2, bottom);

  paint.setRenderHints(renderHints, true);

  paint.setPen( penBackup );
}
示例#6
0
LRESULT AeroControlBase::ButtonWindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    switch(uMsg)
    {
    case WM_SETTEXT:
    case WM_ENABLE:
    case WM_STYLECHANGED:
        {
            LRESULT res = DefSubclassProc(hWnd, uMsg, wParam, lParam);
            InvalidateRgn(hWnd, NULL, FALSE);
            return res;
        }
        break;
    case WM_PAINT:
        {
            PAINTSTRUCT ps;
            HDC hdc = BeginPaint(hWnd, &ps);
            if(hdc)
            {
                LONG_PTR dwStyle = GetWindowLongPtr(hWnd, GWL_STYLE);
                LONG_PTR dwButtonStyle = LOWORD(dwStyle);
                LONG_PTR dwButtonType = dwButtonStyle&0xF;
                RECT rcClient;
                VERIFY(GetClientRect(hWnd, &rcClient));

                if((dwButtonType&BS_GROUPBOX)==BS_GROUPBOX)
                {
                    ///
                    /// it must be a group box
                    ///
                    HTHEME hTheme = OpenThemeData(hWnd, L"Button");
                    if(hTheme)
                    {
                        BP_PAINTPARAMS params = { sizeof(BP_PAINTPARAMS) };
                        params.dwFlags        = BPPF_ERASE;

                        RECT rcExclusion = rcClient;
                        params.prcExclude = &rcExclusion;

                        ///
                        /// We have to calculate the exclusion rect and therefore
                        /// calculate the font height. We select the control's font
                        /// into the DC and fake a drawing operation:
                        ///
                        HFONT hFontOld = (HFONT)SendMessage(hWnd, WM_GETFONT, 0L, NULL);
                        if(hFontOld)
                            hFontOld = (HFONT) SelectObject(hdc, hFontOld);

                        RECT rcDraw = rcClient;
                        DWORD dwFlags = DT_SINGLELINE;

                        ///
                        /// we use uppercase A to determine the height of text, so we
                        /// can draw the upper line of the groupbox:
                        ///
                        DrawTextW(hdc, L"A", -1,  &rcDraw, dwFlags|DT_CALCRECT);

                        if (hFontOld)
                        {
                            SelectObject(hdc, hFontOld);
                            hFontOld    = NULL;
                        }

                        VERIFY(InflateRect(&rcExclusion, -1, -1*RECTHEIGHT(rcDraw)));

                        HDC hdcPaint = NULL;
                        HPAINTBUFFER hBufferedPaint = BeginBufferedPaint(hdc, &rcClient, BPBF_TOPDOWNDIB,
                            &params, &hdcPaint);
                        if (hdcPaint)
                        {
                            ///
                            /// now we again retrieve the font, but this time we select it into
                            /// the buffered DC:
                            ///
                            hFontOld = (HFONT)SendMessage(hWnd, WM_GETFONT, 0L, NULL);
                            if(hFontOld)
                                hFontOld = (HFONT) SelectObject(hdcPaint, hFontOld);


                            VERIFY(PatBlt(hdcPaint, 0, 0, RECTWIDTH(rcClient), RECTHEIGHT(rcClient), BLACKNESS));

                            VERIFY(S_OK==BufferedPaintSetAlpha(hBufferedPaint, &ps.rcPaint, 0x00));
                            int iPartId = BP_GROUPBOX;

                            int iState = GetStateFromBtnState(dwStyle, FALSE, FALSE, 0L, iPartId, FALSE);

                            DTTOPTS DttOpts = {sizeof(DTTOPTS)};
                            DttOpts.dwFlags = DTT_COMPOSITED | DTT_GLOWSIZE;
                            DttOpts.crText   = RGB(255, 255, 255);
                            DttOpts.iGlowSize = 12; // Default value

                            VERIFY(DetermineGlowSize(&DttOpts.iGlowSize));

                            COLORREF cr = RGB(0x00, 0x00, 0x00);
                            VERIFY(GetEditBorderColor(hWnd, &cr));
                            ///
                            /// add the alpha value:
                            ///
                            cr |= 0xff000000;

                            std::unique_ptr<Pen> myPen( new Pen(Color(cr), 1) );
                            std::unique_ptr<Graphics> myGraphics( new Graphics(hdcPaint) );
                            int iY = RECTHEIGHT(rcDraw)/2;
                            Rect rr = Rect(rcClient.left, rcClient.top+iY,
                                RECTWIDTH(rcClient), RECTHEIGHT(rcClient)-iY-1);
                            GraphicsPath path;
                            GetRoundRectPath(&path, rr, 10);
                            myGraphics->DrawPath(myPen.get(), &path);
                            //myGraphics->DrawRectangle(myPen, rcClient.left, rcClient.top + iY,
                            //  RECTWIDTH(rcClient)-1, RECTHEIGHT(rcClient) - iY-1);
                            myGraphics.reset();
                            myPen.reset();

                            int iLen = GetWindowTextLength(hWnd);

                            if(iLen)
                            {
                                iLen+=5; // 1 for terminating zero, 4 for DT_MODIFYSTRING
                                LPWSTR szText = (LPWSTR)LocalAlloc(LPTR, sizeof(WCHAR)*iLen);
                                if(szText)
                                {
                                    iLen = GetWindowTextW(hWnd, szText, iLen);
                                    if(iLen)
                                    {
                                        int iX = RECTWIDTH(rcDraw);
                                        rcDraw = rcClient;
                                        rcDraw.left += iX;
                                        DrawTextW(hdcPaint, szText, -1,  &rcDraw, dwFlags|DT_CALCRECT);
                                        VERIFY(PatBlt(hdcPaint, rcDraw.left, rcDraw.top , RECTWIDTH(rcDraw) + 3, RECTHEIGHT(rcDraw), BLACKNESS));
                                        rcDraw.left++;
                                        rcDraw.right++;
                                        VERIFY(S_OK==DrawThemeTextEx(hTheme, hdcPaint, iPartId, iState, szText, -1,
                                            dwFlags, &rcDraw, &DttOpts));

                                    }

                                    VERIFY(!LocalFree(szText));
                                }
                            }

                            if (hFontOld)
                            {
                                SelectObject(hdcPaint, hFontOld);
                                hFontOld    = NULL;
                            }

                            VERIFY(S_OK==EndBufferedPaint(hBufferedPaint, TRUE));

                        }

                        VERIFY(S_OK==CloseThemeData(hTheme));
                    }
                }

                else if(dwButtonType==BS_CHECKBOX || dwButtonType==BS_AUTOCHECKBOX ||
                    dwButtonType==BS_3STATE || dwButtonType==BS_AUTO3STATE || dwButtonType==BS_RADIOBUTTON || dwButtonType==BS_AUTORADIOBUTTON)
                {
                    HTHEME hTheme = OpenThemeData(hWnd, L"Button");
                    if(hTheme)
                    {
                        HDC hdcPaint = NULL;
                        BP_PAINTPARAMS params = { sizeof(BP_PAINTPARAMS) };
                        params.dwFlags        = BPPF_ERASE;
                        HPAINTBUFFER hBufferedPaint = BeginBufferedPaint(hdc, &rcClient, BPBF_TOPDOWNDIB, &params, &hdcPaint);
                        if (hdcPaint)
                        {
                            VERIFY(PatBlt(hdcPaint, 0, 0, RECTWIDTH(rcClient), RECTHEIGHT(rcClient), BLACKNESS));

                            VERIFY(S_OK==BufferedPaintSetAlpha(hBufferedPaint, &ps.rcPaint, 0x00));

                            LRESULT dwCheckState = SendMessage(hWnd, BM_GETCHECK, 0, NULL);
                            POINT pt;
                            RECT rc;
                            GetWindowRect(hWnd, &rc);
                            GetCursorPos(&pt);
                            BOOL bHot = PtInRect(&rc, pt);
                            BOOL bFocus = GetFocus()==hWnd;

                            int iPartId = BP_CHECKBOX;
                            if(dwButtonType==BS_RADIOBUTTON || dwButtonType==BS_AUTORADIOBUTTON)
                                iPartId = BP_RADIOBUTTON;

                            int iState = GetStateFromBtnState(dwStyle, bHot, bFocus, dwCheckState, iPartId, FALSE);

                            int bmWidth = int(ceil(13.0 * GetDeviceCaps(hdcPaint, LOGPIXELSX) / 96.0));

                            UINT uiHalfWidth = (RECTWIDTH(rcClient) - bmWidth)/2;

                            ///
                            /// we have to use the whole client area, otherwise we get only partially
                            /// drawn areas:
                            ///
                            RECT rcPaint = rcClient;

                            if(dwButtonStyle & BS_LEFTTEXT)
                            {
                                rcPaint.left += uiHalfWidth;
                                rcPaint.right += uiHalfWidth;
                            }
                            else
                            {
                                rcPaint.left -= uiHalfWidth;
                                rcPaint.right -= uiHalfWidth;
                            }


                            ///
                            /// we assume that bmWidth is both the horizontal and the vertical
                            /// dimension of the control bitmap and that it is square. bm.bmHeight
                            /// seems to be the height of a striped bitmap because it is an absurdly
                            /// high dimension value
                            ///
                            if((dwButtonStyle&BS_VCENTER)==BS_VCENTER) /// BS_VCENTER is BS_TOP|BS_BOTTOM
                            {
                                int h = RECTHEIGHT(rcPaint);
                                rcPaint.top = (h - bmWidth) / 2;
                                rcPaint.bottom = rcPaint.top + bmWidth;
                            }
                            else if(dwButtonStyle&BS_TOP)
                            {
                                rcPaint.bottom = rcPaint.top + bmWidth;
                            }
                            else if(dwButtonStyle&BS_BOTTOM)
                            {
                                rcPaint.top =  rcPaint.bottom - bmWidth;
                            }
                            else // default: center the checkbox/radiobutton vertically
                            {
                                int h = RECTHEIGHT(rcPaint);
                                rcPaint.top = (h - bmWidth) / 2;
                                rcPaint.bottom = rcPaint.top + bmWidth;
                            }


                            VERIFY(S_OK==DrawThemeBackground(hTheme, hdcPaint, iPartId, iState, &rcPaint, NULL));
                            rcPaint = rcClient;


                            VERIFY(S_OK==GetThemeBackgroundContentRect(hTheme, hdcPaint, iPartId, iState, &rcPaint, &rc));

                            if(dwButtonStyle & BS_LEFTTEXT)
                                rc.right -= bmWidth + 2 * GetSystemMetrics(SM_CXEDGE);
                            else
                                rc.left += bmWidth + 2 * GetSystemMetrics(SM_CXEDGE);

                            DTTOPTS DttOpts = {sizeof(DTTOPTS)};
                            DttOpts.dwFlags = DTT_COMPOSITED | DTT_GLOWSIZE;
                            DttOpts.crText   = RGB(255, 255, 255);
                            DttOpts.iGlowSize = 12; // Default value

                            VERIFY(DetermineGlowSize(&DttOpts.iGlowSize));


                            HFONT hFontOld = (HFONT)SendMessage(hWnd, WM_GETFONT, 0L, NULL);
                            if(hFontOld)
                                hFontOld = (HFONT) SelectObject(hdcPaint, hFontOld);
                            int iLen = GetWindowTextLength(hWnd);

                            if(iLen)
                            {
                                iLen+=5; // 1 for terminating zero, 4 for DT_MODIFYSTRING
                                LPWSTR szText = (LPWSTR)LocalAlloc(LPTR, sizeof(WCHAR)*iLen);
                                if(szText)
                                {
                                    iLen = GetWindowTextW(hWnd, szText, iLen);
                                    if(iLen)
                                    {
                                        DWORD dwFlags = DT_SINGLELINE /*|DT_VCENTER*/;
                                        if(dwButtonStyle&BS_MULTILINE)
                                        {
                                            dwFlags|=DT_WORDBREAK;
                                            dwFlags&= ~(DT_SINGLELINE |DT_VCENTER);
                                        }

                                        if((dwButtonStyle&BS_CENTER)==BS_CENTER) /// BS_CENTER is BS_LEFT|BS_RIGHT
                                            dwFlags|=DT_CENTER;
                                        else if(dwButtonStyle&BS_LEFT)
                                            dwFlags|=DT_LEFT;
                                        else if(dwButtonStyle&BS_RIGHT)
                                            dwFlags|=DT_RIGHT;


                                        if((dwButtonStyle&BS_VCENTER)==BS_VCENTER) /// BS_VCENTER is BS_TOP|BS_BOTTOM
                                            dwFlags|=DT_VCENTER;
                                        else if(dwButtonStyle&BS_TOP)
                                            dwFlags|=DT_TOP;
                                        else if(dwButtonStyle&BS_BOTTOM)
                                            dwFlags|=DT_BOTTOM;
                                        else
                                            dwFlags|=DT_VCENTER;

                                        VERIFY(S_OK==DrawThemeTextEx(hTheme, hdcPaint, iPartId,
                                            iState, szText, -1, dwFlags, &rc, &DttOpts));

                                        ///
                                        /// if our control has the focus, we also have to draw the focus rectangle:
                                        ///
                                        if(bFocus)
                                        {
                                            ///
                                            /// now calculate the text size:
                                            ///
                                            RECT rcDraw = rc;

                                            ///
                                            /// we use GDI's good old DrawText, because it returns much more
                                            /// accurate data than DrawThemeTextEx, which takes the glow
                                            /// into account which we don't want:
                                            ///
                                            VERIFY(DrawTextW(hdcPaint, szText, -1,  &rcDraw, dwFlags|DT_CALCRECT));
                                            if(dwFlags&DT_SINGLELINE)
                                            {
                                                dwFlags &= ~DT_VCENTER;
                                                RECT rcDrawTop;
                                                DrawTextW(hdcPaint, szText, -1,  &rcDrawTop, dwFlags|DT_CALCRECT);
                                                rcDraw.top = rcDraw.bottom - RECTHEIGHT(rcDrawTop);
                                            }

                                            if(dwFlags & DT_RIGHT)
                                            {
                                                int iWidth = RECTWIDTH(rcDraw);
                                                rcDraw.right = rc.right;
                                                rcDraw.left = rcDraw.right - iWidth;
                                            }

                                            RECT rcFocus;
                                            VERIFY(IntersectRect(&rcFocus, &rc, &rcDraw));

                                            DrawFocusRect(&rcFocus, hdcPaint);
                                        }
                                    }

                                    VERIFY(!LocalFree(szText));
                                }
                            }

                            if (hFontOld)
                            {
                                SelectObject(hdcPaint, hFontOld);
                                hFontOld    = NULL;
                            }

                            VERIFY(S_OK==EndBufferedPaint(hBufferedPaint, TRUE));
                        }
                        VERIFY(S_OK==CloseThemeData(hTheme));
                    }


                }
                else if(BS_PUSHBUTTON==dwButtonType || BS_DEFPUSHBUTTON==dwButtonType)
                {
                    ///
                    /// it is a push button
                    ///
                    HTHEME hTheme = OpenThemeData(hWnd, L"Button");
                    if(hTheme)
                    {
                        HDC hdcPaint = NULL;
                        BP_PAINTPARAMS params = { sizeof(BP_PAINTPARAMS) };
                        params.dwFlags        = BPPF_ERASE;
                        HPAINTBUFFER hBufferedPaint = BeginBufferedPaint(hdc, &rcClient, BPBF_TOPDOWNDIB, &params, &hdcPaint);
                        if (hdcPaint)
                        {
                            VERIFY(PatBlt(hdcPaint, 0, 0, RECTWIDTH(rcClient), RECTHEIGHT(rcClient), BLACKNESS));

                            VERIFY(S_OK==BufferedPaintSetAlpha(hBufferedPaint, &ps.rcPaint, 0x00));

                            LRESULT dwCheckState = SendMessage(hWnd, BM_GETCHECK, 0, NULL);
                            POINT pt;
                            RECT rc;
                            GetWindowRect(hWnd, &rc);
                            GetCursorPos(&pt);
                            BOOL bHot = PtInRect(&rc, pt);
                            BOOL bFocus = GetFocus()==hWnd;
                            int iPartId = BP_PUSHBUTTON;

                            if(dwButtonStyle==BS_RADIOBUTTON || dwButtonStyle==BS_AUTORADIOBUTTON)
                                iPartId = BP_RADIOBUTTON;


                            int iState = GetStateFromBtnState(dwStyle, bHot, bFocus, dwCheckState, iPartId, GetCapture()==hWnd);

                            ///
                            /// we have to use the whole client area, otherwise we get only partially
                            /// drawn areas:
                            ///
                            RECT rcPaint = rcClient;
                            VERIFY(S_OK==DrawThemeBackground(hTheme, hdcPaint, iPartId, iState, &rcPaint, NULL));


                            VERIFY(S_OK==GetThemeBackgroundContentRect(hTheme, hdcPaint, iPartId, iState, &rcPaint, &rc));


                            DTTOPTS DttOpts = {sizeof(DTTOPTS)};
                            DttOpts.dwFlags = DTT_COMPOSITED | DTT_GLOWSIZE;
                            DttOpts.crText   = RGB(255, 255, 255);
                            DttOpts.iGlowSize = 12; // Default value

                            VERIFY(DetermineGlowSize(&DttOpts.iGlowSize));


                            HFONT hFontOld = (HFONT)SendMessage(hWnd, WM_GETFONT, 0L, NULL);
                            if(hFontOld)
                                hFontOld = (HFONT) SelectObject(hdcPaint, hFontOld);
                            int iLen = GetWindowTextLength(hWnd);

                            if(iLen)
                            {
                                iLen+=5; // 1 for terminating zero, 4 for DT_MODIFYSTRING
                                LPWSTR szText = (LPWSTR)LocalAlloc(LPTR, sizeof(WCHAR)*iLen);
                                if(szText)
                                {
                                    iLen = GetWindowTextW(hWnd, szText, iLen);
                                    if(iLen)
                                    {
                                        DWORD dwFlags = DT_SINGLELINE | DT_CENTER | DT_VCENTER;
                                        VERIFY(S_OK==DrawThemeTextEx(hTheme, hdcPaint,
                                            iPartId, iState, szText, -1, dwFlags, &rc, &DttOpts));

                                        ///
                                        /// if our control has the focus, we also have to draw the focus rectangle:
                                        ///
                                        if(bFocus)
                                        {
                                            RECT rcDraw = rcClient;
                                            VERIFY(InflateRect(&rcDraw, -3, -3));
                                            DrawFocusRect(&rcDraw, hdcPaint);
                                        }

                                    }

                                    VERIFY(!LocalFree(szText));
                                }
                            }

                            if (hFontOld)
                            {
                                SelectObject(hdcPaint, hFontOld);
                                hFontOld    = NULL;
                            }

                            VERIFY(S_OK==EndBufferedPaint(hBufferedPaint, TRUE));
                        }
                        VERIFY(S_OK==CloseThemeData(hTheme));
                    }
                }
                else
                    //PaintControl(hWnd, hdc, &ps.rcPaint, (m_dwFlags & WD_DRAW_BORDER)!=0);
                    PaintControl(hWnd, hdc, &ps.rcPaint, false);
            }

            EndPaint(hWnd, &ps);
            return 0;
        }
        break;
    case WM_DESTROY:
    case WM_NCDESTROY:
        RemoveWindowSubclass(hWnd, SubclassProc, Button);
        subclassedControls.erase(hWnd);
        break;
    }

    return DefSubclassProc(hWnd, uMsg, wParam, lParam);
}
void DialogVideoPlayer::paintCurrentVisualizationFrame() {


    bool show_fixation_numbers = true;

    QPixmap pixmap(display_width, display_height);
    pixmap.fill(Qt::transparent);
    QPainter painter(&pixmap);


    QPen myPen(QColor(0,0,0,127), 1, Qt::SolidLine);
    myPen.setCapStyle(Qt::RoundCap);
    painter.setPen(myPen);

    if (show_fixation_numbers && p_fixAllM->n_rows > 0) {
        QFont serifFont("Times", 64, QFont::Bold);
        painter.setFont(serifFont);
        uvec fixIndex =  arma::find((*p_fixAllM).col(FIXCOL_START) <= currentIndex);
        mat aux = (*p_fixAllM).rows(fixIndex);
        fixIndex =  arma::find(aux.col(FIXCOL_END) >= currentIndex);
        if (fixIndex.n_rows != 0) {
            painter.drawText( QRect(0, 0, display_width, display_height), Qt::AlignCenter, QString::number(fixIndex(0)) );
        }
    }


    mat *matrixToUse = settingPlaySmooth ? p_smoothM : p_roughM;

    if (matrixToUse->is_empty()) return;

    QPen *pensToUse = settingPlaySmooth ? smoothPens : roughPens;
    int nPensToUse = settingPlaySmooth ? 1 : 2;
    double width_multi = settingPlaySmooth ? (double)display_width / (double)expWidth : display_width;
    double height_multi = settingPlaySmooth ? (double)display_height / (double)expHeight : display_height;

    for(int i = 0; i < nPensToUse; ++i) {
        myPen.setColor(pensToUse[i * 2].color());

        // Pupil width
        if (p_roughM->n_cols >= 8 && p_roughM->at(currentIndex, 6) > 0 && p_roughM->at(currentIndex, 7) > 0) {
            double width = (p_roughM->at(currentIndex, 6) + p_roughM->at(currentIndex, 7)) / 6;
            int penWidth = (int)floor(width * actualDotSize);
            myPen.setWidth(penWidth);
        } else {
            myPen.setWidth(actualDotSize);
        }



        uword index = 2 * (i + 1);
        int x = matrixToUse->at(currentIndex, index) * width_multi;
        int y = matrixToUse->at(currentIndex, index + 1) * height_multi;

        painter.setPen(myPen);
        painter.drawPoint(x,y);
        painter.setPen(whitePen);
        painter.drawPoint(x,y);
    }


    painter.end();
    visualizationPixmapItem->setPixmap(pixmap);

}
示例#8
0
void CSpermView::DrawImage(CDC *pDC)
{	
	int i,n;
	
	CMainFrame* pMainfrm=(CMainFrame*)AfxGetMainWnd();
	CMorphaDetectDLG* pWnd=(CMorphaDetectDLG*)((CView3*)pMainfrm->GetView3())->m_pwndMorphaDetDlg;
	if(pWnd==NULL || pWnd->m_hWnd == NULL) return;
	vector<SpermRegion>& m_vSpermRegion = pWnd->m_vSpermRegion;
	int& m_r=pWnd->m_nR;
	vector<IsSperNormal>& m_vbIsNormal=pWnd->m_vbIsNormal;
	vector<SperMopyParameter>& m_vSperMopyParameter=pWnd->m_vSperMopyParameter;
	LPBYTE& m_lpResBmDataSrc=pWnd->m_lpResBmDataSrc;
	LPBITMAPINFOHEADER& m_lpResBmInfoSrc= pWnd->m_lpResBmInfoSrc;

	LPBYTE& m_lpResEdgeBmDataSrc=pWnd->m_lpResEdgeBmDataSrc;
	LPBITMAPINFOHEADER& m_lpResEdgeBmInfoSrc= pWnd->m_lpResEdgeBmInfoSrc;

	switch(pWnd->m_wndCbxShowOpt.GetCurSel())
	{
	case 2:  //  画原图
		m_imgMorphaImg.Show(pDC->m_hDC,0,0,m_imgMorphaImg.Width(),m_imgMorphaImg.Height());
		break;
	case 1:	 //  画填充图
		if(m_lpResBmInfoSrc && m_lpResBmDataSrc)
		{
			::StretchDIBits(pDC->GetSafeHdc(), 
				0,0, m_lpResBmInfoSrc->biWidth, m_lpResBmInfoSrc->biHeight, 
				0, 0, m_lpResBmInfoSrc->biWidth, m_lpResBmInfoSrc->biHeight, 
				m_lpResBmDataSrc, (LPBITMAPINFO)m_lpResBmInfoSrc, DIB_RGB_COLORS, SRCCOPY);
		}
		break;
	case 0:  // 画边缘图
		if(m_lpResEdgeBmDataSrc && m_lpResBmInfoSrc)
		{
			::StretchDIBits(pDC->GetSafeHdc(), 
				0,0,m_lpResBmInfoSrc->biWidth, m_lpResBmInfoSrc->biHeight, 
				0, 0, m_lpResBmInfoSrc->biWidth, m_lpResBmInfoSrc->biHeight, 
				m_lpResEdgeBmDataSrc, (LPBITMAPINFO)m_lpResBmInfoSrc, DIB_RGB_COLORS, SRCCOPY);
		}
		break;
	}
	if(pWnd->m_wndChkRectangle.GetCheck())
	{
		// 画边框
		CPen myRedPen(PS_SOLID, 1, RGB(255,0,0));
		CPen myBluePen(PS_SOLID, 1, RGB(0,0,255));
		CPen *myPen, *pOldPen;

		n = m_vSpermRegion.size();
		list<int>& m_lsOperateIndex = pWnd->m_lsOperateIndex;
		for(i=0; i<n; i++)
		{			
			if(m_vbIsNormal[i].IsNormalVector[0] == TRUE)
				myPen = &myBluePen;
			else myPen = &myRedPen;
			
			pOldPen = pDC->SelectObject(myPen);  // 选用红画笔
			pDC->SelectObject(GetStockObject(NULL_BRUSH));  // 空白画刷

			if( find(m_lsOperateIndex.begin(),pWnd->m_itListIndex,i )
				!= pWnd->m_itListIndex ) continue;
			CPoint lt = CPoint(m_vSpermRegion[i].SpermCenterPos.y - m_r, m_vSpermRegion[i].SpermCenterPos.x - m_r);
			CPoint rt = CPoint(m_vSpermRegion[i].SpermCenterPos.y + m_r, m_vSpermRegion[i].SpermCenterPos.x - m_r);
			CPoint lb = CPoint(m_vSpermRegion[i].SpermCenterPos.y - m_r, m_vSpermRegion[i].SpermCenterPos.x + m_r);
			CPoint rb = CPoint(m_vSpermRegion[i].SpermCenterPos.y + m_r, m_vSpermRegion[i].SpermCenterPos.x + m_r);	
			CRect  rect = CRect(lt, rb);
            if( m_nPos == i)
			{
				pDC->SelectObject(pOldPen);
				COLORREF color; 
				if(m_vbIsNormal[i].IsNormalVector[0] == TRUE)
					color = RGB(0,0,255); // 选用蓝画笔
				else 
					color = RGB(255,0,0); // 选用红画笔

				CPen dotpen(PS_DASHDOT,1,color);
				pDC->SelectObject(&dotpen);
				pDC->Rectangle(rect);
			    pDC->SelectObject(myPen);
			}
			else
			{
				pDC->Rectangle(rect);
			}
		
		}
		if(n>0)	pDC->SelectObject(pOldPen);		
		// 编号
		{
			CPen myPen(PS_SOLID, 2, RGB(255,0,0));
			CPen *pOldPen = pDC->SelectObject(&myPen); //选用新画笔
			pDC->SetBkMode(TRANSPARENT);
			CString  strNo, cs;
			n = m_vbIsNormal.size();
			for(i=0; i<n; i++)
			{
				if( find(m_lsOperateIndex.begin(),pWnd->m_itListIndex,i)
					!= pWnd->m_itListIndex ) continue;
				
				pDC->SetTextColor(RGB(0,0,255));
				strNo.Format("%d", i+1);
				pDC->TextOut(m_vSpermRegion[i].SpermCenterPos.y - m_r, m_vSpermRegion[i].SpermCenterPos.x + m_r - 15, strNo);
				
				if( m_vbIsNormal[i].IsNormalVector[0] == TRUE )
				{
					pDC->SetTextColor(RGB(0,0,255));
					cs = "正常";
				}
				else
				{
					pDC->SetTextColor(RGB(255,0,0));
					cs = "异常";
				}
				pDC->TextOut(m_vSpermRegion[i].SpermCenterPos.y - m_r + 20, m_vSpermRegion[i].SpermCenterPos.x + m_r - 17, cs);
				
			}	
			pDC->SelectObject(pOldPen);
		}
	}
	if(m_nPos != -1)
	{
		
		CString cs;
 		cs.Format("%.2lf", m_vSperMopyParameter[m_nPos].m_length);
 		pWnd->m_strLength      = cs;
		
		cs.Format("%.2lf", m_vSperMopyParameter[m_nPos].m_width);
		pWnd->m_strWidth       = cs;
		
		cs.Format("%.2lf", m_vSperMopyParameter[m_nPos].m_area);
		pWnd->m_strArea        = cs;
		
		cs.Format("%.2lf", m_vSperMopyParameter[m_nPos].m_perimeter);
		pWnd->m_strPerimeter   = cs;
		
		cs.Format("%3.2lf", m_vSperMopyParameter[m_nPos].m_ellipticity);
		pWnd->m_strEllipticity = cs;
		
		cs.Format("%.2lf", m_vSperMopyParameter[m_nPos].m_perfor_area);
		pWnd->m_strPerforArea = cs;
		
		cs.Format("%.2lf", m_vSperMopyParameter[m_nPos].m_head_area);
		pWnd->m_strHeadArea   = cs;
		
		cs.Format("%.1f", m_vSperMopyParameter[m_nPos].m_head_perfor_area*100);
		pWnd->m_strHeadPerforArea  = cs + "%";
		
		
		cs.Format("%.2lf", m_vSperMopyParameter[m_nPos].m_tail_length);
		pWnd->m_strMitsomaLength = cs;
		
		cs.Format("%.2lf", m_vSperMopyParameter[m_nPos].m_tail_width);
		pWnd->m_strMitosomaWidth  = cs;
		
		cs.Format("%.2lf", m_vSperMopyParameter[m_nPos].m_tail_angle);
		pWnd->m_strMitosmaDevangle  = cs + "度";
		
		cs.Format("%.2f", m_vSperMopyParameter[m_nPos].m_ruga);
		pWnd->m_strRuga  = cs;
		
		cs.Format("%.2f", m_vSperMopyParameter[m_nPos].m_extension);
		pWnd->m_strExtension  = cs;
		
		cs.Format("%.2f", m_vSperMopyParameter[m_nPos].m_symmetry);
		pWnd->m_strSymmetry   = cs;
		
		// 精子编号	
		cs.Format("第%d号精子  -->> ", m_nPos+1);
		pWnd->m_strInfo  =  cs;
	
		cs = ( (m_vbIsNormal[m_nPos].IsNormalVector[0] == TRUE ) ? "正常" : "异常");
		pWnd->m_strIsNormal = cs;
		
		pWnd->UpdateData(FALSE);
		pWnd->Invalidate();
	}
}
示例#9
0
文件: areavis.cpp 项目: nauhc/CellGUI
void DataVis::paintEvent(QPaintEvent *event)
{
    QPainter painter(this);
    QPen myPen(QColor(128, 128, 128, 20));
    myPen.setWidth(2);
    painter.setPen(myPen);

    // draw background grid
    for(int j = 0; j < this->height(); j+=gridStepY)
        painter.drawLine(0, j, this->width(), j);
    for(int i = gridStepX; i < this->width(); i+=gridStepX)
        painter.drawLine(i, 0, i, this->height());

    /*
    //text showing what is y-axis for
    QRectF rectY = QRectF(QPointF(60, 5), QPointF(250, 50));
    QString textY = string+" (pixels)";
    myPen.setColor(color);
    painter.setPen(myPen);
    painter.setFont(QFont("Arial", 20));
    painter.drawText(rectY, Qt::AlignLeft, textY);*/

    if(on){
        ////initial line
        //painter.drawLine(0, (this->height()/2), gridStepX, (this->height()/2));

        if (track && (currFrm >= startFrm+2)){
            //draw y-axis with graduation
            myPen.setColor(QColor(160, 160, 160, 250));
            myPen.setWidth(3);
            painter.setRenderHint(QPainter::Antialiasing, true);
            painter.setPen(myPen);
            painter.drawLine(2*gridStepX, 0, 2*gridStepX, this->height()/*-this->height()%gridStepX*/);
            for(int j = gridStepY; j < this->height(); j+=gridStepY)
                painter.drawLine(2*gridStepX-5, j, 2*gridStepX+5, j);

            //draw x-axis
            int verticalPos = gridStepY*(num+1);
            painter.drawLine(2*gridStepX-5, verticalPos, this->width(), verticalPos);
            painter.drawLine(currPoint_value.x(), verticalPos-2, currPoint_value.x(), verticalPos+1);
            QRectF rect_f = QRectF(QPointF(currPoint_value.x()-15, verticalPos+5),
                                   QPointF(currPoint_value.x()+15, verticalPos+15));
            QString textFrm = QString::number(currFrm);
            painter.setFont(QFont("Arial", 14/*, QFont::Bold*/));
            painter.drawText(rect_f, Qt::AlignCenter, textFrm);
            painter.setFont(QFont("Arial", 17/*, QFont::Bold*/));
            QRectF rect_frmLbl = QRectF(QPointF(this->width()-55, verticalPos-20),
                                   QPointF(this->width()-5, verticalPos-5));
            QString textFrmLbl = "Frame";
            painter.drawText(rect_frmLbl, Qt::AlignLeft, textFrmLbl);

            // pen for drawing data line chart
            myPen.setColor(color);
            myPen.setWidth(3);
            myPen.setCapStyle(Qt::RoundCap);
            painter.setPen(myPen);

            // text for y-axis graduation
            for(int n = 0; n < num+1; n+=2){
                QRectF rect = QRectF(QPointF(0, gridStepY*n+9), QPointF(gridStepX*2-5, gridStepY*(n+2)));
                QString textGrad = QString::number(value_max-n*(value_max-value_min)/num);
                if(n%4 == 0)
                    painter.setFont(QFont("Arial", 16));
                else
                    painter.setFont(QFont("Arial", 12));
                painter.drawText(rect, Qt::AlignRight, textGrad);
            }

            //realtime line chart - area
            painter.drawPolyline(polyline_value);
            myPen.setWidth(10);
            painter.setPen(myPen);
            painter.drawPoint(currPoint_value);

            //draw text showing the cell area
            myPen.setWidth(4);
            painter.setPen(myPen);
            QRectF rect_a = QRectF(QPointF(currPoint_value.x()-50, currPoint_value.y()-60),
                                   QPointF(currPoint_value.x()+50, currPoint_value.y()-20));
            QString textArea = QString::number(value);
            painter.setFont(QFont("Arial", 16));
            painter.drawText(rect_a, Qt::AlignCenter, textArea);
        }
    }

//    this->update(); //This consumes too much resources
}