Click here to Skip to main content
15,897,273 members
Articles / Web Development / HTML

Mouse Gestures for Internet Explorer

Rate me:
Please Sign up or sign in to vote.
4.84/5 (99 votes)
21 Sep 200514 min read 1.3M   13.4K   235  
Adding mouse gesture recognition to Internet Explorer.
///////////////////////////////////////////////////////////////
//
// TrailManager.cpp
//
// Created: 27/06/2005
// Copyright (c) 2005 Ralph Hare (ralph.hare@ysgyfarnog.co.uk)
// All rights reserved.
//
// The code and information is provided "as-is" without
// warranty of any kind, either expressed or implied.
//
///////////////////////////////////////////////////////////////

#include "StdAfx.h"
#include "TrailManager.h"
#include "TrailWindow.h"
#include "OSUtils.h"

namespace
{
    LPCTSTR KEY_NAME = _T( "Software\\Drowse\\Mouse Gestures\\Trails" );
    LPCTSTR VALUE_IS_ENABLED = _T( "Is Enabled" );
    LPCTSTR VALUE_COLOUR = _T( "Colour" );
    LPCTSTR VALUE_TRANSPARENCY = _T( "Transparency" );
    LPCTSTR VALUE_WIDTH = _T( "Width" );
    LPCTSTR VALUE_CUSTOM_COLOUR = _T( "Custom Colour" );
    LPCTSTR VALUE_FADE_SPEED = _T( "Fade Speed" );

    class DummyTrail : public MouseTrail
    {
    public:
        DummyTrail() :
            MouseTrail()
        {
        }

    private:
        void Begin( HWND ) {}
        void Update( const Path & ) {}
        void End() {}
        void Show() {}
        void Hide() {}
    };
}

TrailManager::TrailManager() :
    m_regKey(),
    m_isDirty( true ),
    m_pTrail()
{
    m_regKey.Create( HKEY_CURRENT_USER, KEY_NAME );
}

TrailManager::~TrailManager()
{
}

TrailManager & TrailManager::GetInstance()
{
    static TrailManager theInstance;
    return theInstance;
}

bool TrailManager::GetIsEnabled() const
{
    DWORD   val = 1;
    m_regKey.QueryDWORDValue( VALUE_IS_ENABLED, val );
    return val != 0;
}

COLORREF TrailManager::GetColour() const
{
    DWORD   val = RGB( 0, 0x80, 0 );    // dark green
    m_regKey.QueryDWORDValue( VALUE_COLOUR, val );
    return val;
}

BYTE TrailManager::GetTransparency() const
{
    DWORD   val = 128;          // 50%
    m_regKey.QueryDWORDValue( VALUE_TRANSPARENCY, val );
    return static_cast< BYTE >( val );
}

long TrailManager::GetWidth() const
{
    DWORD   val = 10;
    m_regKey.QueryDWORDValue( VALUE_WIDTH, val );
    return static_cast< long >( val );
}

COLORREF TrailManager::GetCustomColour() const
{
    DWORD   val = 0;            // black
    m_regKey.QueryDWORDValue( VALUE_CUSTOM_COLOUR, val );
    return val;
}

int TrailManager::GetFadeSpeed() const
{
    DWORD   val = 255;          // fade disabled
    m_regKey.QueryDWORDValue( VALUE_FADE_SPEED, val );
    return val;
}

void TrailManager::SetIsEnabled( bool isEnabled )
{
    m_regKey.SetDWORDValue( VALUE_IS_ENABLED, isEnabled );
}

void TrailManager::SetColour( COLORREF clr )
{
    m_regKey.SetDWORDValue( VALUE_COLOUR, clr );
    m_isDirty = true;
}

void TrailManager::SetTransparency( BYTE transparency )
{
    m_regKey.SetDWORDValue( VALUE_TRANSPARENCY, transparency );
    m_isDirty = true;
}

void TrailManager::SetWidth( long width )
{
    m_regKey.SetDWORDValue( VALUE_WIDTH, static_cast< DWORD >( width ) );
    m_isDirty = true;
}

void TrailManager::SetCustomColour( COLORREF clr )
{
    m_regKey.SetDWORDValue( VALUE_CUSTOM_COLOUR, clr );
    m_isDirty = true;
}

void TrailManager::SetFadeSpeed( int fadeSpeed )
{
    m_regKey.SetDWORDValue( VALUE_FADE_SPEED, fadeSpeed );
    m_isDirty = true;
}

MouseTrail * TrailManager::GetTrail()
{
    if( ( OSUtils::IsNT4() == false ) && GetIsEnabled() )
    {
        static TrailWindow  trail( GetColour(), GetWidth(), GetTransparency(), GetFadeSpeed() );

        if( m_isDirty )
        {
            trail.UpdateSettings( GetColour(), GetWidth(), GetTransparency(), GetFadeSpeed() );
            m_isDirty = false;
        }

        return &trail;
    }

    static DummyTrail   dummyTrail;
    return &dummyTrail;
}

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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


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

Comments and Discussions