📄 mes_ui.cpp
字号:
//------------------------------------------------------------------------------
//
// Copyright (C) 2003 MagicEyes Digital Co., Ltd All Rights Reserved
// MagicEyes Digital Co. Proprietary & Confidential
//
// MAGICEYES INFORMS THAT THIS CODE AND INFORMATION IS PROVIDED "AS IS" BASE AND
// WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
//
// Module :
// File : Menu_Dice.cpp
// Description:
// Author : Gamza(nik@mesdigital.com)
// Export :
// History :
// 2008/03/26 Gamza change color animation algorithm
// 2008/03/26 Gamza append a ActionType of a button to post MESUIMSG_EXIT
// 2008/02/20 Gamza fix texture coordinates ( horizontal flip problem )
// 2007/12/03 Gamza First implementation
//------------------------------------------------------------------------------
#include "mes_ui.h"
#include "mes_parser.h"
//#include <SystemOEM.h>
//-----------------------------------------------------------------------------
//
// main menu skin script
//
//-----------------------------------------------------------------------------
#include <windows.h>
#define SUBITEMVISIBILITY_TIME 1
#define SUBITEMVISIBILITY_INPUTLOCKSTATE 2
#define SUBITEMVISIBILITY_BATTERYLEVEL 4
#define SUBITEMVISIBILITY_ALL 0xFFFFFFFF
#define MESSAGE_LENGTH (32)
//------------------------------------------------------------------------------
//
//
//
//------------------------------------------------------------------------------
#include "system_pollux.h"
#include "mes_launcher_utils.h"
#include "GLES/gl.h"
#include "GLES/egl.h"
#include "GLES/glext.h"
#if defined(WIN32) || defined(UNDER_CE)
#pragma warning(disable:4786)
#pragma warning(disable:4514)
#pragma warning(disable:4530)
#pragma warning(push,3)
#endif
//#include <vector>
//#include <string>
#include "SVector.h"
#if defined(WIN32) || defined(UNDER_CE)
#pragma warning(pop)
#endif
#include "WildMagic4/Wm4Quaternion.h"
using namespace Wm4;
//------------------------------------------------------------------------------
//
// local namespace
//
//------------------------------------------------------------------------------
namespace // local namespace
{
#define CONTROL_PLANE_Z (1.0)
#define BUTTONIDBASE_IMAGE 100
#define BUTTONIDBASE_CUBE 200
#define MOUSE_STOP_INTERVAL 1000 // ms
#define MOUSE_STOP_TIMER 2
#define MENU_HEIGHT 32
BOOL g_DrawMouse = FALSE;
extern float g_DiceData[ 5184 ];
#define NUM_OF_VERTEX (sizeof(g_DiceData)/(sizeof(g_DiceData[0])*16))
Quaternionf RotationArc( Vector3f From, Vector3f To )
{
if( From == To ){ return Quaternionf::IDENTITY; }
From.Normalize();
To.Normalize();
Vector3f c = From.Cross( To );
float d = From.Dot( To );
float s = (float)sqrt((1+d)*2);
c /= s;
return Quaternionf( c, s/2.0f );
}
BOOL GetAbsolutePath ( const char* pReleativePath, char* pBuffer , int BufferSize )
{
static char APP_PATH[MAX_PATH];
static int APP_PATH_LEN =0;
if( 0 == APP_PATH_LEN )
{
TCHAR tcPath[MAX_PATH];
int i;
GetModuleFileName( NULL, tcPath, MAX_PATH );
for( i=_tcslen( tcPath )-1; i>=0; i-- )
{
if( (TCHAR)tcPath[i] == (TCHAR)('\\') )
{
tcPath[i] = 0x00;
break;
}
}
wcstombs( APP_PATH, tcPath, sizeof(APP_PATH) );
APP_PATH_LEN = strlen( APP_PATH );
}
int result = _snprintf( pBuffer, BufferSize-1, "%s\\%s", APP_PATH, pReleativePath );
return (result>=0);
}
char g_AbsolutePath[MAX_PATH];
unsigned int g_AbsolutePathLen;
void SetCurrentPath ( const char* pAbsolutePath )
{
g_AbsolutePathLen = strlen( pAbsolutePath );
if( g_AbsolutePathLen < sizeof(g_AbsolutePath)-2 )
{
strcpy( g_AbsolutePath, pAbsolutePath );
g_AbsolutePath[g_AbsolutePathLen+0] = '\\';
g_AbsolutePathLen++;
}
}
const char* GetAbsolutePath ( const char* pReleativePath )
{
strcpy( g_AbsolutePath+g_AbsolutePathLen, pReleativePath );
return g_AbsolutePath;
}
bool CheckPropertyName( HMESPARSERPROPERTY hProperty, const char* pName )
{
return 0 == strcmp( MesParser_GetPropertyName( hProperty ), pName );
}
MESLauncher_Image LoadImageFromFile ( HMESPARSERPROPERTY hProperty, int Index )
{
const char* pfilename = MesParser_GetString( MesParser_GetValue(hProperty,Index) );
if( 0 == pfilename ){ return 0; }
if( '*' == pfilename[0] ){ return 0; }
wchar_t wchar_buffer[1024];
char *pString;
memset(wchar_buffer, 0, 1024);
pString = (char *)GetAbsolutePath(pfilename);
mbstowcs( wchar_buffer, pString, strlen(pString)+1 );
/*HDC hDC = NULL;
HBITMAP hBitmap = NULL;
CMyImage myImage;
ImageInfo imageinfo;
if(!myImage.FileToDCBMP(wchar_buffer, &hDC, &hBitmap, &imageinfo))
{
MessageBox(NULL, L"read image failed", L"KK", MB_OK);
}
MESLauncher_Image pImage =
MESLauncher_LoadImageFromHDC(hDC,
0, 0, imageinfo.Width, imageinfo.Height);
DeleteDC(hDC);
DeleteObject(hBitmap);*/
MESLauncher_Image pImage = MESLauncher_LoadImageFromFile(pString);//pString "\\nand flash\\background.bmp"
/*WCHAR sNum[10] = {0};
memset(sNum, 0, 20);
_itow_s((INT)pImage,sNum, 10, 10);
MessageBox(NULL, sNum, L"pImage", MB_OK);*/
return pImage;
//return MESLauncher_LoadImageFromFile( GetAbsolutePath(pfilename) );
}
unsigned int LoadTextureFromFile( HMESPARSERPROPERTY hProperty, int Index )
{
const char* pfilename = MesParser_GetString( MesParser_GetValue(hProperty,Index) );
if( 0 == pfilename ){ return 0; }
if( '*' == pfilename[0] ){ return 0; }
return MESLauncher_LoadTextureFromFile( GetAbsolutePath(pfilename) );
}
void LoadIntArray( HMESPARSERPROPERTY hProperty, int Start, int Count, int* pOut )
{
for( int i=0; i<Count; i++ )
{
pOut[i] = MesParser_GetInt( MesParser_GetValue(hProperty,Start+i) );
}
}
struct Button
{
int m_ActionType; // 0:none 1:Run application 2:Run SubMenu
int m_ActionParam; // SubMenu Index or Application Index
int m_TouchX, m_TouchY, m_TouchW, m_TouchH;
int m_IconX, m_IconY, m_IconW, m_IconH; // position and size of icon in screen space
//std::string m_MessageString;
char m_MessageString[MESSAGE_LENGTH];
bool IsTouched( int x, int y )
{
if( 0 == m_ActionType ){ return false; }
return ( m_TouchX <= x && x <= m_TouchX + m_TouchW && m_TouchY <= y && y <= m_TouchY + m_TouchH );
}
Button &operator =(Button &btnSource)
{
m_ActionType = btnSource.m_ActionType;
m_ActionParam = btnSource.m_ActionParam;
m_TouchX = btnSource.m_TouchX;
m_TouchY = btnSource.m_TouchY;
m_TouchW = btnSource.m_TouchW;
m_TouchH = btnSource.m_TouchH;
m_IconX = btnSource.m_IconX;
m_IconY = btnSource.m_IconY;
m_IconW = btnSource.m_IconW;
m_IconH = btnSource.m_IconH;
memcpy(m_MessageString, btnSource.m_MessageString, MESSAGE_LENGTH);
return *this;
}
};
struct ImageButton : public Button
{
MESLauncher_Image m_IconTexture;
int m_TitleX, m_TitleY; // position of title in screen space
MESLauncher_Image m_TitleTexture;// Image filename of title. It can be NULL(hidden).
MESLauncher_Image m_TitleAlphaTexture;
bool LoadSkin( HMESPARSERNODE hNode )
{
if( 0 != strcmp( MesParser_GetNodeName(hNode), "Button_Flat" ) ){ return false; }
int numberofproperties = MesParser_GetNumberOfProperties( hNode );
int i;
m_IconTexture = 0;
m_TitleTexture = 0;
m_TitleAlphaTexture = 0;
for( i=0; i<numberofproperties; i++ )
{
HMESPARSERPROPERTY hproperty = MesParser_GetProperty( hNode, i );
if ( CheckPropertyName( hproperty, "ActionType" ) ){ m_ActionType = MesParser_GetInt( MesParser_GetValue(hproperty,0) ); }
else if( CheckPropertyName( hproperty, "ActionParam") ){ m_ActionParam= MesParser_GetInt( MesParser_GetValue(hproperty,0) ); }
else if( CheckPropertyName( hproperty, "MessageString" ) )
{
char *pTemp = (char *)MesParser_GetString( MesParser_GetValue(hproperty,0) );
memcpy(m_MessageString, pTemp, strlen(pTemp));
//m_MessageString = MesParser_GetString( MesParser_GetValue(hproperty,0) );
}
else if( CheckPropertyName( hproperty, "TouchArea" ) )
{
m_TouchX = MesParser_GetInt( MesParser_GetValue(hproperty,0) );
m_TouchY = MesParser_GetInt( MesParser_GetValue(hproperty,1) );
m_TouchW = MesParser_GetInt( MesParser_GetValue(hproperty,2) );
m_TouchH = MesParser_GetInt( MesParser_GetValue(hproperty,3) );
}
else if( CheckPropertyName( hproperty, "DiceArea" ) )
{
m_IconX = MesParser_GetInt( MesParser_GetValue(hproperty,0) );
m_IconY = MesParser_GetInt( MesParser_GetValue(hproperty,1) );
m_IconW = MesParser_GetInt( MesParser_GetValue(hproperty,2) );
m_IconH = MesParser_GetInt( MesParser_GetValue(hproperty,3) );
}
else if( CheckPropertyName( hproperty, "DiceImage" ) ){ m_IconTexture = LoadImageFromFile( hproperty,0 ); }
else if( CheckPropertyName( hproperty, "TextPos" ) ){ m_TitleX = MesParser_GetInt( MesParser_GetValue(hproperty,0) ); m_TitleY = MesParser_GetInt( MesParser_GetValue(hproperty,1) ); }
else if( CheckPropertyName( hproperty, "TextImage" ) ){ m_TitleTexture = LoadImageFromFile( hproperty,0 ); }
else if( CheckPropertyName( hproperty, "TextAlpha" ) ){ m_TitleAlphaTexture = LoadImageFromFile( hproperty,0 ); }
else { RETAILMSG( 1, (L"*E:Button_Flat::LoadSkin : Unknown proterty(%d,%d)\n", i, __LINE__ ) ); }
}
return true;
}
void UnloadSkin( void )
{
if( m_IconTexture ){ MESLauncher_UnloadImage( m_IconTexture ); m_IconTexture = 0; }
if( m_TitleTexture ){ MESLauncher_UnloadImage( m_TitleTexture ); m_TitleTexture = 0; }
if( m_TitleAlphaTexture ){ MESLauncher_UnloadImage( m_TitleAlphaTexture ); m_TitleAlphaTexture = 0; }
}
ImageButton &operator =(ImageButton &btnSource)
{
((Button)(*this)) = ((Button)btnSource);
m_IconTexture = btnSource.m_IconTexture;
m_TitleX = btnSource.m_TitleX;
m_TitleY = btnSource.m_TitleY;
m_TitleTexture = btnSource.m_TitleTexture;
m_TitleAlphaTexture = btnSource.m_TitleAlphaTexture;
return *this;
}
};
struct DiceButton : public Button
{
unsigned int m_DiceTexture;
int m_TitleX, m_TitleY; // position of title in screen space
MESLauncher_Image m_TitleTexture;// Image filename of title. It can be NULL(hidden).
MESLauncher_Image m_TitleAlphaTexture;
int m_CurIconX, m_CurIconY;
float m_DiceZ, m_DiceTartgetZ;
Quaternionf m_DirectionCur; // 泅犁 规氢.
Quaternionf m_Rotate_Normal;
Quaternionf m_Rotate_NormalSpeed;
Quaternionf m_Rotate_Cursor;
Quaternionf m_Rotate_CursorSpeed;
bool LoadSkin( HMESPARSERNODE hNode )
{
if( 0 != strcmp( MesParser_GetNodeName(hNode), "Button_Dice" ) ){ return false; }
int numberofproperties = MesParser_GetNumberOfProperties( hNode );
int i;
m_DiceTexture = 0;
m_TitleTexture = 0;
m_TitleAlphaTexture = 0;
for( i=0; i<numberofproperties; i++ )
{
HMESPARSERPROPERTY hproperty = MesParser_GetProperty( hNode, i );
if ( CheckPropertyName( hproperty, "ActionType" ) ){ m_ActionType = MesParser_GetInt( MesParser_GetValue(hproperty,0) ); }
else if( CheckPropertyName( hproperty, "ActionParam") ){ m_ActionParam= MesParser_GetInt( MesParser_GetValue(hproperty,0) ); }
else if( CheckPropertyName( hproperty, "MessageString" ) )
{
char *pTemp = (char *)MesParser_GetString( MesParser_GetValue(hproperty,0) );
memcpy(m_MessageString, pTemp, strlen(pTemp));
//m_MessageString = MesParser_GetString( MesParser_GetValue(hproperty,0) );
}
else if( CheckPropertyName( hproperty, "TouchArea" ) )
{
m_TouchX = MesParser_GetInt( MesParser_GetValue(hproperty,0) );
m_TouchY = MesParser_GetInt( MesParser_GetValue(hproperty,1) );
m_TouchW = MesParser_GetInt( MesParser_GetValue(hproperty,2) );
m_TouchH = MesParser_GetInt( MesParser_GetValue(hproperty,3) );
}
else if( CheckPropertyName( hproperty, "DiceArea" ) )
{
m_IconX = MesParser_GetInt( MesParser_GetValue(hproperty,0) );
m_IconY = MesParser_GetInt( MesParser_GetValue(hproperty,1) );
m_IconW = MesParser_GetInt( MesParser_GetValue(hproperty,2) );
m_IconH = MesParser_GetInt( MesParser_GetValue(hproperty,3) );
}
else if( CheckPropertyName( hproperty, "DiceImage" ) ){ m_DiceTexture = LoadTextureFromFile( hproperty,0 ); }
else if( CheckPropertyName( hproperty, "TextPos" ) ){ m_TitleX = MesParser_GetInt( MesParser_GetValue(hproperty,0) ); m_TitleY = MesParser_GetInt( MesParser_GetValue(hproperty,1) ); }
else if( CheckPropertyName( hproperty, "TextImage" ) ){ m_TitleTexture = LoadImageFromFile( hproperty,0 ); }
else if( CheckPropertyName( hproperty, "TextAlpha" ) ){ m_TitleAlphaTexture = LoadImageFromFile( hproperty,0 ); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -