Home

Resume

Blog

Teikitu


/* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */
/*  »Project«   Teikitu Gaming System (TgS) (∂)
    »File«      TgS (WIN) Input - GUI Mouse.c
    »Author«    Andrew Aye (EMail: mailto:andrew.aye@gmail.com, Web: http://www.andrewaye.com)
    »Version«   4.51 / »GUID« A9981407-3EC9-42AF-8B6F-8BE6DD919615                                                                                                        */
/*   -------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
/*  Copyright: © 2002-2017, Andrew Aye.  All Rights Reserved.
    This software is free for non-commercial use.  Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
      following conditions are met:
        Redistribution of source code must retain this copyright notice, this list of conditions and the following disclaimers.
        Redistribution in binary form must reproduce this copyright notice, this list of conditions and the following disclaimers in the documentation and other materials
          provided with the distribution.
    The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission.
    The intellectual property rights of the algorithms used reside with Andrew Aye.
    You may not use this software, in whole or in part, in support of any commercial product without the express written consent of the author.
    There is no warranty or other guarantee of fitness of this software for any purpose. It is provided solely "as is".                                                   */
/* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */

#pragma warning( push, 3 )
#include <winuser.rh>
#pragma warning( pop )




/* == Input ============================================================================================================================================================= */

/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. */
/*  File Local Functions and Data                                                                                                                                         */
/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. */

static TgUINT32                             s_aiGUI_Mouse[ETgPROP_GUI_MOUSE_MAX];

static TgVOID                               tgIN_PM_Update_GUI_Mouse_Callback( TgMS_HWND, TgUINT32, TgUINTPTR, TgSINTPTR );




/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. */
/*  Internal Functions                                                                                                                                                    */
/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. */

/* ---- tgIN_PM_Init_GUI_Mouse ------------------------------------------------------------------------------------------------------------------------------------------ */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgRESULT tgIN_PM_Init_GUI_Mouse( TgVOID )
{
    return (KTgS_OK);
}


/* ---- tgIN_PM_Boot_GUI_Mouse ------------------------------------------------------------------------------------------------------------------------------------------ */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgRESULT tgIN_PM_Boot_GUI_Mouse( TgVOID )
{
    tgKN_Set_GUI_Mouse_Callback( tgIN_PM_Update_GUI_Mouse_Callback );
    return (KTgS_OK);
}


/* ---- tgIN_PM_Stop_GUI_Mouse ------------------------------------------------------------------------------------------------------------------------------------------ */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgRESULT tgIN_PM_Stop_GUI_Mouse( TgVOID )
{
    tgKN_Set_GUI_Mouse_Callback( nullptr );
    return (KTgS_OK);
}


/* ---- tgIN_PM_Free_GUI_Mouse ------------------------------------------------------------------------------------------------------------------------------------------ */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgRESULT tgIN_PM_Free_GUI_Mouse( TgVOID )
{
    return (KTgS_OK);
}


/* ---- tgIN_PM_Update_GUI_Mouse ---------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgVOID tgIN_PM_Update_GUI_Mouse( C_ETgCONTROLLER UNUSED_PARAM enController )
{

}


/* ---- tgIN_PM_Query_Fixed_Memory_GUI_Mouse ---------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgSIZE tgIN_PM_Query_Fixed_Memory_GUI_Mouse( TgVOID )
{
    return (sizeof( s_aiGUI_Mouse ));
}




/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. */
/*  File Local Functions                                                                                                                                                  */
/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. */

/* ---- tgIN_PM_Update_GUI_Mouse_Callback ------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
static TgVOID tgIN_PM_Update_GUI_Mouse_Callback( TgMS_HWND hWnd, TgUINT32 uiMsg, TgUINTPTR wParam, TgSINTPTR lParam )
{
#if !defined(TgCOMPILE_PLATFORM_UWP)
    C_TgSINT32                          nMouseButtonState = wParam & 0xFFFF;
    TgUINT32                            aiGUI_Mouse[ETgPROP_GUI_MOUSE_MAX];
    TgSINT32                            iIndex;
    TgUINT32                            uiEvent;

    if (WM_MOUSEWHEEL == uiMsg)
    {
        /* WM_MOUSEWHEEL passes screen mouse coords so convert them to client coords */
        TgMS_POINT                          pt;

        pt.m_x = lParam & 0xFFFF;
        pt.m_y = (lParam >> 16) & 0xFFFF;

        g_pfnScreenToClient( hWnd, &pt );

        aiGUI_Mouse[ETgPROP_GUI_MOUSE_AXIX_DX] = (TgUINT32)pt.m_x;
        aiGUI_Mouse[ETgPROP_GUI_MOUSE_AXIX_DY] = (TgUINT32)pt.m_y;
        aiGUI_Mouse[ETgPROP_GUI_MOUSE_AXIX_DZ] = WM_MOUSEWHEEL == uiMsg ? (wParam >> 16) & 0xFFFF : 0;
    }
    else
    {
        aiGUI_Mouse[ETgPROP_GUI_MOUSE_AXIX_DX] = lParam & 0xFFFF;
        aiGUI_Mouse[ETgPROP_GUI_MOUSE_AXIX_DY] = (lParam >> 16) & 0xFFFF;
        aiGUI_Mouse[ETgPROP_GUI_MOUSE_AXIX_DZ] = WM_MOUSEWHEEL == uiMsg ? (wParam >> 16) & 0xFFFF : 0;
    }

    aiGUI_Mouse[ETgPROP_GUI_MOUSE_BUTTON0] = ((nMouseButtonState & MK_LBUTTON) != 0);
    aiGUI_Mouse[ETgPROP_GUI_MOUSE_BUTTON1] = ((nMouseButtonState & MK_MBUTTON) != 0);
    aiGUI_Mouse[ETgPROP_GUI_MOUSE_BUTTON2] = ((nMouseButtonState & MK_RBUTTON) != 0);
    aiGUI_Mouse[ETgPROP_GUI_MOUSE_BUTTON3] = ((nMouseButtonState & MK_XBUTTON1) != 0);
    aiGUI_Mouse[ETgPROP_GUI_MOUSE_BUTTON4] = ((nMouseButtonState & MK_XBUTTON2) != 0);

    if (nullptr == g_asController_Active[ETgCONTROLLER_GUI_MOUSE].m_psConsumer)
    {
        memcpy( s_aiGUI_Mouse, aiGUI_Mouse, sizeof( aiGUI_Mouse ) );
        return;
    };

    /* Generate events based on the change between this state and the previous state. */
    for (iIndex = 0; iIndex < ETgPROP_GUI_MOUSE_MAX; ++iIndex)
    {
        if (s_aiGUI_Mouse[iIndex] == aiGUI_Mouse[iIndex])
        {
            continue;
        }

        while (0 == tgCM_UTM_LA_RB_SRSW__Query_Free_Size( &g_asController_Active[ETgCONTROLLER_GUI_MOUSE].m_sLA_RB_SRSW ))
        {
            tgTR_Yield();
        };

        uiEvent = (TgUINT32)tgCM_UTM_LA_RB_SRSW__Push_Next_Index( &g_asController_Active[ETgCONTROLLER_GUI_MOUSE].m_sLA_RB_SRSW );

        g_asController_Active[ETgCONTROLLER_GUI_MOUSE].m_asEvent[uiEvent].m_enController = ETgCONTROLLER_GUI_MOUSE;
        g_asController_Active[ETgCONTROLLER_GUI_MOUSE].m_asEvent[uiEvent].m_uiState.GUI_Mouse = 0;
        g_asController_Active[ETgCONTROLLER_GUI_MOUSE].m_asEvent[uiEvent].m_enProp.GUI_Mouse = (ETgPROP_GUI_MOUSE)iIndex;
        g_asController_Active[ETgCONTROLLER_GUI_MOUSE].m_asEvent[uiEvent].m_uiUTF32 = aiGUI_Mouse[iIndex];
        g_asController_Active[ETgCONTROLLER_GUI_MOUSE].m_asEvent[uiEvent].m_fValue = 0.0F;
        g_asController_Active[ETgCONTROLLER_GUI_MOUSE].m_asEvent[uiEvent].m_fDiff = 0.0F;

        tgCM_UTM_LA_RB_SRSW__Push_Commit( &g_asController_Active[ETgCONTROLLER_GUI_MOUSE].m_sLA_RB_SRSW );
    };

    memcpy( s_aiGUI_Mouse, aiGUI_Mouse, sizeof( aiGUI_Mouse ) );
/*# !defined(TgCOMPILE_PLATFORM_UWP) */
#endif
}