Click here to Skip to main content
15,895,011 members
Articles / Desktop Programming / MFC

PicZoom: A Photo Viewer Created in OpenGL

Rate me:
Please Sign up or sign in to vote.
4.86/5 (64 votes)
16 Feb 2011CPOL16 min read 161K   11.6K   151  
PicZoom: A Photo Viewer created in OpenGL
#include "StdAfx.h"
#include "GLText.h"
#include "FontEngine.h"
#include "GL\gl.h"

GLText::GLText( HWND hParentWnd, FontEngine* pFontEngine_i, const int nTimerID_i )
{
    m_hParentWnd = hParentWnd;
    m_pFontEngine = pFontEngine_i;
    m_nTimer = nTimerID_i;
    m_csDisplayString = "";
    m_csDisplayStringNew = "";
}

GLText::~GLText(void)
{
}

void GLText::SetText(const CString csNewText_i)
{
    if( csNewText_i.Compare( m_csDisplayStringNew ))
    {
        //if( !m_bNullString )
        {
            m_csDisplayStringNew = csNewText_i;
        }
        // If Timer is 
        //   bool bTimerNotNeeded = !( m_bNullString && m_csDisplayString.GetLength() &&m_DisplayStringTimer.IsEnabled());
        // Subhash's comment. The transition of string is not smooth.
        // Here window name is changed.
        // Setup a timer for alpha blending of text display.
        m_StringTimerShow.SetMaxElapseTime( 20 );
        if( !m_StringTimerHide.IsEnabled() )
        {
            // If already one hide is started, then need to handle it.
            m_StringTimerHide.SetMaxElapseTime( 20 );
        }

        if( 0 == m_csDisplayString.Compare( L"" ))
        {
            m_StringTimerHide.SetMaxElapseTime( 0 );
        }


        if( 0 == m_csDisplayStringNew.Compare( L"" ))
        {
            m_StringTimerShow.SetMaxElapseTime( 0 );
        }

        ::SetTimer( m_hParentWnd, m_nTimer, 10, 0 );
    }
}

void GLText::Draw(const int nX_i, const int nY_i)
{
    if( m_StringTimerHide.IsEnabled())
    {
        // Hide old string
        int nRemTime = m_StringTimerHide.GetRemainingTime();
        float fColorComponent = ( nRemTime / 20.0 );
        glEnable( GL_BLEND );
        glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
        glColor4f( 1.0, 1.0, 1.0, fColorComponent );
        // Drawing text to screen.
        m_pFontEngine->DrawText( nX_i, nY_i, m_csDisplayString.GetBuffer( 0 ) );
        glDisable( GL_BLEND );
        glColor4f( 1.0, 1.0, 1.0, 1.0 );
        m_StringTimerHide.ElapseTime();
    }
    else
    {
        m_csDisplayString = m_csDisplayStringNew;
        // Show New string.
        int nRemTime = 20 - m_StringTimerShow.GetRemainingTime();
        float fColorComponent = ( nRemTime / 20.0 );
        glEnable( GL_BLEND );
        glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
        glColor4f( 1.0, 1.0, 1.0, fColorComponent );
        // Drawing text to screen.
        m_pFontEngine->DrawText( nX_i, nY_i, m_csDisplayString.GetBuffer( 0 ) );
        glDisable( GL_BLEND );
        glColor4f( 1.0, 1.0, 1.0, 1.0 );
        m_StringTimerShow.ElapseTime();
    }
}

bool GLText::IsDrawPending()
{
    return ( m_StringTimerShow.IsEnabled() || m_StringTimerHide.IsEnabled() );
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions