Exemplo n.º 1
0
void CLCDIcon::OnDraw(CLCDGfxBase &rGfx)
{
    if (m_hIcon)
    {
        int nOldBkMode = SetBkMode(rGfx.GetHDC(), TRANSPARENT);

        DrawIconEx(rGfx.GetHDC(), 0, 0, m_hIcon,
                   m_nIconWidth, m_nIconHeight, 0, NULL, DI_NORMAL);

        SetBkMode(rGfx.GetHDC(), nOldBkMode);
    }
}
Exemplo n.º 2
0
void CLCDMyProgressBar::OnDraw(CLCDGfxBase& rGfx)
{
    // draw the border
    RECT r = { 0, 0, GetWidth(), GetHeight() };

    FrameRect(rGfx.GetHDC(), &r, m_hBrush);

    // draw the progress
    switch (m_eMyStyle) {
        case STYLE_CURSOR: {
            int nCursorPos = (int)Scalef((float)m_Range.nMin, (float)m_Range.nMax,
                                         (float)1, (float)(GetWidth() - m_nCursorWidth - 1),
                                         m_fPos);
            r.left = nCursorPos;
            r.right = r.left + m_nCursorWidth;
            FillRect(rGfx.GetHDC(), &r, m_hBrush);
        }
        break;
        case STYLE_FILLED_H:
        case STYLE_FILLED_V: {
            int nBar = (int)Scalef((float)m_Range.nMin, (float)m_Range.nMax,
                                   0.0f, (m_eMyStyle == STYLE_FILLED_H ? (float)GetWidth() : (float)GetHeight()) - 4,
                                   m_fPos);
            r.left   = r.left + 2;
            r.bottom = r.bottom - 2;
            if (m_eMyStyle == STYLE_FILLED_H) {
                r.right = nBar + 2;
                r.top   = r.top + 2;
            } else {
                r.right = r.right - 2;
                r.top   = r.bottom - nBar;
            }

            FillRect(rGfx.GetHDC(), &r, m_hBrush);
        }
        break;
        case STYLE_DASHED_CURSOR: {
            int nCursorPos = (int)Scalef((float)m_Range.nMin, (float)m_Range.nMax,
                                         (float)1, (float)(GetWidth() - m_nCursorWidth - 1),
                                         m_fPos);
            r.left = nCursorPos;
            r.right = r.left + m_nCursorWidth;
            FillRect(rGfx.GetHDC(), &r, m_hBrush);
            HPEN hOldPen = (HPEN)::SelectObject(rGfx.GetHDC(), m_hPen);

            ::MoveToEx(rGfx.GetHDC(), 0, (r.bottom - r.top) / 2, NULL);
            ::LineTo(rGfx.GetHDC(), nCursorPos, (r.bottom - r.top) / 2);
            ::SelectObject(rGfx.GetHDC(), hOldPen);
        }
        break;
        default:
            break;
    }
}
Exemplo n.º 3
0
void CLCDCollection::OnDraw(CLCDGfxBase &rGfx)
{
    if(!IsVisible())
    {
        return;
    }

    //iterate through your objects and draw them
    LCD_OBJECT_LIST::iterator it = m_Objects.begin();
    while(it != m_Objects.end())
    {
        CLCDBase *pObject = *it++;
        LCDUIASSERT(NULL != pObject);

        if (pObject->IsVisible())
        {
            pObject->OnPrepareDraw(rGfx);

            // create the clip region
            HRGN hRgn = CreateRectRgn(pObject->GetOrigin().x, pObject->GetOrigin().y,
                                      pObject->GetOrigin().x + pObject->GetWidth(),
                                      pObject->GetOrigin().y + pObject->GetHeight());

            // ensure that controls only draw within their specified region
            SelectClipRgn(rGfx.GetHDC(), hRgn);

            // free the region (a copy is used in the call above)
            DeleteObject(hRgn);

            // offset the control at its origin so controls use (0,0)
            POINT ptPrevViewportOrg = { 0, 0 };
            SetViewportOrgEx(rGfx.GetHDC(),
                             pObject->GetOrigin().x,
                             pObject->GetOrigin().y,
                             &ptPrevViewportOrg);

            // allow controls to supply additional translation
            // this allows controls to move freely within the confined viewport
            OffsetViewportOrgEx(rGfx.GetHDC(),
                                pObject->GetLogicalOrigin().x,
                                pObject->GetLogicalOrigin().y,
                                NULL);

            pObject->OnDraw(rGfx);

            // set the clipping region to nothing
            SelectClipRgn(rGfx.GetHDC(), NULL);

            // restore the viewport origin
            SetViewportOrgEx(rGfx.GetHDC(),
                ptPrevViewportOrg.x,
                ptPrevViewportOrg.y,
                NULL);

            // restore the viewport origin offset
            OffsetViewportOrgEx(rGfx.GetHDC(), 0, 0, NULL);
        }
    }
}
void CLCDBitmap::OnDraw(CLCDGfxBase &rGfx)
{
    if(m_hBitmap)
    {
        HDC hCompatibleDC = CreateCompatibleDC(rGfx.GetHDC());
        HBITMAP hOldBitmap = (HBITMAP)SelectObject(hCompatibleDC, m_hBitmap);
        
        // If monochrome output, don't even bother with alpha blend
        if (LGLCD_BMP_FORMAT_160x43x1 == rGfx.GetLCDScreen()->hdr.Format)
        {
            BitBlt(rGfx.GetHDC(), 0, 0, m_sizeLogical.cx, m_sizeLogical.cy, hCompatibleDC, 0, 0, m_dwROP);
        }
        else
        {
            if(0.001f > fabs(1.0f - m_fZoom))
            {
                BOOL b = FALSE;
                if(m_bAlpha)
                {
                    BLENDFUNCTION opblender = {AC_SRC_OVER, 0, 255, AC_SRC_ALPHA};
                    b = AlphaBlend(rGfx.GetHDC(), 0, 0, m_sizeLogical.cx, m_sizeLogical.cy, hCompatibleDC, 0, 0, m_sizeLogical.cx, m_sizeLogical.cy, opblender);
                }
                else
                {
                    BitBlt(rGfx.GetHDC(), 0, 0, m_sizeLogical.cx, m_sizeLogical.cy, hCompatibleDC, 0, 0, m_dwROP);
                }
            }
            else
            {
                if(m_bAlpha)
                {
                    BLENDFUNCTION opblender = {AC_SRC_OVER, 0, 255, AC_SRC_ALPHA};
                    AlphaBlend(rGfx.GetHDC(), 0, 0, (int)(m_fZoom* m_sizeLogical.cx), (int)(m_fZoom*m_sizeLogical.cy), hCompatibleDC, 0, 0, m_sizeLogical.cx, m_sizeLogical.cy, opblender);
                }
                else
                {
                    BLENDFUNCTION opblender = {AC_SRC_OVER, 0, 255, 0};
                    AlphaBlend(rGfx.GetHDC(), 0, 0, (int)(m_fZoom* m_sizeLogical.cx), (int)(m_fZoom*m_sizeLogical.cy), hCompatibleDC, 0, 0, m_sizeLogical.cx, m_sizeLogical.cy, opblender);
                }
            }
        }
        
        // restores
        SelectObject(hCompatibleDC, hOldBitmap);
        DeleteDC(hCompatibleDC);
    }
}
Exemplo n.º 5
0
void CLCDColorText::OnDraw(CLCDGfxBase &rGfx)
{
    if(GetBackgroundMode() == OPAQUE)
    {
        HBRUSH backbrush = CreateSolidBrush(m_backColor);

        // clear the clipped area
        RECT rcClp = { 0, 0, m_Size.cx, m_Size.cy };
        FillRect(rGfx.GetHDC(), &rcClp, backbrush);

        // clear the logical area
        RECT rcLog = { 0, 0, m_sizeLogical.cx, m_sizeLogical.cy };
        FillRect(rGfx.GetHDC(), &rcLog, backbrush);

        DeleteObject(backbrush);
    }

    if(m_nTextLength)
    {

        // map mode text, with transparency
        int nOldMapMode = SetMapMode(rGfx.GetHDC(), MM_TEXT);

        int nOldBkMode = SetBkMode(rGfx.GetHDC(), TRANSPARENT);

        // select current font
        HFONT hOldFont = (HFONT)SelectObject(rGfx.GetHDC(), m_hFont);

        // select color
        COLORREF crOldTextColor = SetTextColor(rGfx.GetHDC(), m_crForegroundColor);

        if (m_bRecalcExtent)
        {
            int nTextFormat;

            RECT rExtent;
            // calculate vertical extent with word wrap
            nTextFormat = (m_nTextFormat | DT_WORDBREAK | DT_CALCRECT);
            rExtent.left = rExtent.top = 0;
            rExtent.right = GetWidth();
            rExtent.bottom = GetHeight();
            DrawTextEx(rGfx.GetHDC(), (LPTSTR)m_sText.c_str(), static_cast<int>(m_nTextLength), &rExtent, nTextFormat, &m_dtp);
            m_sizeVExtent.cx = rExtent.right;
            m_sizeVExtent.cy = rExtent.bottom;

            // calculate horizontal extent w/o word wrap
            nTextFormat = (m_nTextFormat | DT_CALCRECT);
            rExtent.left = rExtent.top = 0;
            rExtent.right = GetWidth();
            rExtent.bottom = GetHeight();
            DrawTextEx(rGfx.GetHDC(), (LPTSTR)m_sText.c_str(), static_cast<int>(m_nTextLength), &rExtent, nTextFormat, &m_dtp);
            m_sizeHExtent.cx = rExtent.right;
            m_sizeHExtent.cy = rExtent.bottom;

            m_bRecalcExtent = FALSE;

            //For scrolling
            m_PixelLength = m_sizeHExtent.cx;
            m_StartX = 0;

            if( m_bAutoScroll )
            {
                if( m_PixelLength > GetWidth() )
                {
                    m_ScrollRate = -1*GetHeight();
                }
                else
                {
                    m_ScrollRate = 0;
                }
            }

            if( m_ScrollRate > 0 )
            {
                if( GetWidth() > m_PixelLength + m_ScrollBuffer )
                {
                    m_JumpDistance = -1 * GetWidth();
                }
                else
                {
                    m_JumpDistance = -1 * (m_PixelLength + m_ScrollBuffer);
                }
            }
            else if( m_ScrollRate < 0 )
            {
                if( GetWidth() > m_PixelLength + m_ScrollBuffer )
                {
                    m_JumpDistance = GetWidth();
                }
                else
                {
                    m_JumpDistance = m_PixelLength + m_ScrollBuffer;
                }
            }

            m_LoopX = m_JumpDistance;
        }

        if( IsVisible() )
        {
            if( m_ScrollRate == 0 )
            {
                RECT rBoundary = { 0, 0, 0 + GetLogicalSize().cx, 0 + GetLogicalSize().cy }; 
                DrawTextEx(rGfx.GetHDC(), (LPTSTR)m_sText.c_str(), static_cast<int>(m_nTextLength), &rBoundary, m_nTextFormat, &m_dtp);
            }
            else
            {
                RECT rBoundaryFirst = { m_StartX, 0, 0 + GetLogicalSize().cx, 0 + GetLogicalSize().cy }; 
                RECT rBoundarySecond = { m_LoopX, 0, 0 + GetLogicalSize().cx, 0 + GetLogicalSize().cy }; 

                DrawTextEx(rGfx.GetHDC(), (LPTSTR)m_sText.c_str(), static_cast<int>(m_nTextLength), 
                    &rBoundaryFirst, m_nTextFormat, &m_dtp);
                DrawTextEx(rGfx.GetHDC(), (LPTSTR)m_sText.c_str(), static_cast<int>(m_nTextLength), 
                    &rBoundarySecond, m_nTextFormat, &m_dtp);
            }
        }

        // restores
        SetMapMode(rGfx.GetHDC(), nOldMapMode);
        SetTextColor(rGfx.GetHDC(), crOldTextColor);
        SetBkMode(rGfx.GetHDC(), nOldBkMode);
        SelectObject(rGfx.GetHDC(), hOldFont);
    }
}
Exemplo n.º 6
0
void CLCDSkinnedProgressBar::OnDraw(CLCDGfxBase &rGfx)
{
    RECT rBoundary = { 0, 0, GetWidth(), GetHeight() };

    HDC hdcMem = CreateCompatibleDC(rGfx.GetHDC());
    HBITMAP hbmOld = (HBITMAP)SelectObject(hdcMem, m_hBackground);

    //Draw the background
    //BitBlt the background onto the screen
    BLENDFUNCTION opblender = {AC_SRC_OVER, 0, 255, AC_SRC_ALPHA};
    AlphaBlend(rGfx.GetHDC(), 0, 0, GetWidth(), GetHeight(), hdcMem, 0, 0, GetWidth(), GetHeight(), opblender);

    SelectObject(hdcMem, hbmOld);
    DeleteDC(hdcMem);

    //Drawing the cursor
    switch(m_eStyle)
    {
    case STYLE_FILLED:
        {
            

            HDC hdcMemCursor = CreateCompatibleDC(rGfx.GetHDC());

            if(m_bUse3P)
            {
                RECT r = rBoundary;
                r.left = 0;
                r.right = GetWidth() - m_3PCursorRightWidth - m_3PCursorLeftWidth;
                int nBarWidth = (int)Scalef((float)m_Range.nMin, (float)m_Range.nMax,
                    (float)r.left, (float)r.right,
                    m_fPos);

                int midstart, midwidth;
                midstart = m_3PCursorLeftWidth;
                midwidth = nBarWidth;

                //Left
                hbmOld = (HBITMAP)SelectObject(hdcMemCursor, m_h3PCursorLeft);

                AlphaBlend(rGfx.GetHDC(), 0, 0, m_3PCursorLeftWidth, GetHeight(), 
                    hdcMemCursor, 0, 0, m_3PCursorLeftWidth, m_3PCursorLeftHeight, opblender);

                //Mid
                SelectObject(hdcMemCursor, m_h3PCursorMid);

                AlphaBlend(rGfx.GetHDC(), midstart, 0, midwidth, GetHeight(), 
                    hdcMemCursor, 0, 0, m_3PCursorMidWidth, m_3PCursorMidHeight, opblender);

                //Right
                SelectObject(hdcMemCursor, m_h3PCursorRight);

                AlphaBlend(rGfx.GetHDC(), midstart+midwidth, 0, m_3PCursorRightWidth, GetHeight(), 
                    hdcMemCursor, 0, 0, m_3PCursorRightWidth, m_3PCursorRightHeight, opblender);

                // restore previous bitmap
                SelectObject(hdcMemCursor, hbmOld);
                
            }
            else
            {     
                RECT r = rBoundary;
                int nBarWidth = (int)Scalef((float)m_Range.nMin, (float)m_Range.nMax,
                    (float)rBoundary.left, (float)(rBoundary.right),
                    m_fPos);
                r.right = nBarWidth ? nBarWidth : r.left;

                HBITMAP hbmOldCursor = (HBITMAP)SelectObject(hdcMemCursor, m_hFiller);

                BitBlt(rGfx.GetHDC(), 0, 0, nBarWidth, GetHeight(), hdcMemCursor, 0, 0, SRCCOPY);

                SelectObject(hdcMemCursor, hbmOldCursor);
            }

            DeleteDC(hdcMemCursor);

            break;
        }
        //These two cases will be the same
    case STYLE_CURSOR:
    case STYLE_DASHED_CURSOR:
        {
            HDC hdcMemCursor = CreateCompatibleDC(rGfx.GetHDC());

            if(m_bUse3P)
            {
                RECT r = rBoundary;
                int nCursorPos = (int)Scalef((float)m_Range.nMin, (float)m_Range.nMax,
                    (float)rBoundary.left, (float)(rBoundary.right - m_nCursorWidth),
                    m_fPos);
                r.left = nCursorPos;
                r.right = nCursorPos + m_nCursorWidth;

                int midstart, midwidth;
                midstart = r.left+m_3PCursorLeftWidth;
                midwidth = m_3PCursorMidWidth;
                
                //Left
                hbmOld = (HBITMAP)SelectObject(hdcMemCursor, m_h3PCursorLeft);

                AlphaBlend(rGfx.GetHDC(), r.left, 0, m_3PCursorLeftWidth, GetHeight(), 
                    hdcMemCursor, 0, 0, m_3PCursorLeftWidth, m_3PCursorLeftHeight, opblender);

                //Mid
                SelectObject(hdcMemCursor, m_h3PCursorMid);

                AlphaBlend(rGfx.GetHDC(), midstart, 0, midwidth, GetHeight(), 
                    hdcMemCursor, 0, 0, m_3PCursorMidWidth, m_3PCursorMidHeight, opblender);

                //Right                
                SelectObject(hdcMemCursor, m_h3PCursorRight);

                AlphaBlend(rGfx.GetHDC(), midstart+midwidth, 0, m_3PCursorRightWidth, GetHeight(), 
                    hdcMemCursor, 0, 0, m_3PCursorRightWidth, m_3PCursorRightHeight, opblender);

                // restore old bitmap
                SelectObject(hdcMemCursor, hbmOld);
            }
            else
            {
                RECT r = rBoundary;
                int nCursorPos = (int)Scalef((float)m_Range.nMin, (float)m_Range.nMax,
                    (float)rBoundary.left, (float)(rBoundary.right - m_nCursorWidth),
                    m_fPos);
                r.left = nCursorPos;
                r.right = nCursorPos + m_nCursorWidth;
                
                HBITMAP hbmOldCursor = (HBITMAP)SelectObject(hdcMemCursor, m_hCursor);

                BitBlt(rGfx.GetHDC(), r.left, 0, m_nCursorWidth, GetHeight(), hdcMemCursor, 0, 0, SRCCOPY);

                SelectObject(hdcMemCursor, hbmOldCursor);
            }

            DeleteDC(hdcMemCursor);

            break;
        }
    default:
        break;
    }

    if( NULL != m_hHighlight )
    {
        HDC hdcMemHighlight = CreateCompatibleDC(rGfx.GetHDC());
        HBITMAP hbmOldHighlight = (HBITMAP)SelectObject(hdcMemHighlight, m_hHighlight);

        AlphaBlend(rGfx.GetHDC(), 0, 0, GetWidth(), GetHeight(), hdcMemHighlight, 0, 0, m_HighlightWidth, m_HighlightHeight, opblender);

        SelectObject(hdcMemHighlight, hbmOldHighlight);
        DeleteDC(hdcMemHighlight);
    }
}
Exemplo n.º 7
0
void CLCDPage::OnDraw(CLCDGfxBase &rGfx)
{
    if(!IsVisible())
    {
        return;
    }

    //Draw the background first
    if(m_bUseBitmapBackground)
    {
        m_Background.OnDraw(rGfx);
    }
    else if(m_bUseColorBackground)
    {
        HBRUSH hBackBrush = CreateSolidBrush(m_BackgroundColor);
        HBRUSH hOldBrush = (HBRUSH)SelectObject(rGfx.GetHDC(), hBackBrush);
        Rectangle(rGfx.GetHDC(), 0, 0, GetWidth(), GetHeight());
        SelectObject(rGfx.GetHDC(), hOldBrush);
        DeleteObject(hBackBrush);
    }


    //iterate through your objects and draw them
    LCD_OBJECT_LIST::iterator it = m_Objects.begin();
    while(it != m_Objects.end())
    {
        CLCDBase *pObject = *it++;
        LCDUIASSERT(NULL != pObject);

        if (pObject->IsVisible())
        {
            // create the clip region
            // Note that pages can now be added to pages (GetOrigin of the page is now factored in)
            HRGN hRgn = CreateRectRgn(GetOrigin().x + pObject->GetOrigin().x, GetOrigin().y + pObject->GetOrigin().y,
                GetOrigin().x + pObject->GetOrigin().x + pObject->GetWidth(),
                GetOrigin().y + pObject->GetOrigin().y + pObject->GetHeight());

            // ensure that controls only draw within their specified region
            SelectClipRgn(rGfx.GetHDC(), hRgn);

            // free the region (a copy is used in the call above)
            DeleteObject(hRgn);

            // offset the control at its origin so controls use (0,0)
            POINT ptPrevViewportOrg = { 0, 0 };
            SetViewportOrgEx(rGfx.GetHDC(),
                GetOrigin().x + pObject->GetOrigin().x,
                GetOrigin().y + pObject->GetOrigin().y,
                &ptPrevViewportOrg);

            // allow controls to supply additional translation
            // this allows controls to move freely within the confined viewport
            OffsetViewportOrgEx(rGfx.GetHDC(),
                pObject->GetLogicalOrigin().x,
                pObject->GetLogicalOrigin().y,
                NULL);

            pObject->OnDraw(rGfx);

            // set the clipping region to nothing
            SelectClipRgn(rGfx.GetHDC(), NULL);

            // restore the viewport origin
            SetViewportOrgEx(rGfx.GetHDC(),
                ptPrevViewportOrg.x,
                ptPrevViewportOrg.y,
                NULL);

            // restore the viewport origin offset
            OffsetViewportOrgEx(rGfx.GetHDC(), 0, 0, NULL);
        }
    }
}