| 1 |
#include "stdafx.h" |
| 2 |
#include "CCursor.h" |
| 3 |
#include "CSkinPlugin.h" |
| 4 |
|
| 5 |
// 内部定数 |
| 6 |
extern const int CSR_MOVE_TSD = 3; // カーソル移動判定閾値 |
| 7 |
const float CURSOR_HIDE_RATIO = 0.3f; // カーソル消去速度 |
| 8 |
|
| 9 |
/* |
| 10 |
* 読込 |
| 11 |
*/ |
| 12 |
char *CSkinPlugin::_CURSORDATA::Read( |
| 13 |
char *str, // 対象文字列 |
| 14 |
char *name // カーソル名 |
| 15 |
){ |
| 16 |
char *tmp, *eee; |
| 17 |
int i; |
| 18 |
if(!(str = BeginBlock(eee = str, name))) throw CSynErr(eee); |
| 19 |
if(!(str = AsgnString(eee = str, "TexFileName", |
| 20 |
&m_TexFileName))) throw CSynErr(eee); |
| 21 |
if(!(str = AsgnInteger(eee = str, "ImageSize", |
| 22 |
m_ImageSize, 2, false))) throw CSynErr(eee); |
| 23 |
if(tmp = AsgnInteger(eee = str, "Cursor2DSize", m_Cursor2DSize, 2, false)) str = tmp; |
| 24 |
else for(i = 0; i<2; i++) m_Cursor2DSize[i] = m_ImageSize[i]; |
| 25 |
if(!(str = AsgnInteger(eee = str, "Cursor2DHotSpot", |
| 26 |
m_Cursor2DHotSpot, 2, false))) throw CSynErr(eee); |
| 27 |
if(tmp = AsgnInteger(eee = str, "Cursor2DAnimNumber", &m_Cursor2DAnimNumber)) str = tmp; |
| 28 |
else m_Cursor2DAnimNumber = 1; |
| 29 |
m_Cursor2DAnimFrame = new int[m_Cursor2DAnimNumber]; |
| 30 |
if(tmp = AsgnInteger(eee = str, "Cursor2DAnimFrame", |
| 31 |
m_Cursor2DAnimFrame, m_Cursor2DAnimNumber, true)) str = tmp; |
| 32 |
else for(i = 0; i<m_Cursor2DAnimNumber; i++) m_Cursor2DAnimFrame[i] = 1; |
| 33 |
if(!(str = EndBlock(eee = str))) throw CSynErr(eee, ERR_ENDBLOCK); |
| 34 |
return str; |
| 35 |
} |
| 36 |
|
| 37 |
/* |
| 38 |
* データ読込 |
| 39 |
*/ |
| 40 |
void CSkinPlugin::_CURSORDATA::LoadData(){ |
| 41 |
m_CursorTexture = g_TexList.Get(FALSE, m_TexFileName.c_str(), 0, 1); |
| 42 |
} |
| 43 |
|
| 44 |
/* |
| 45 |
* 描画 |
| 46 |
*/ |
| 47 |
void CSkinPlugin::_CURSORDATA::Render( |
| 48 |
POINT pos, // 座標 |
| 49 |
float alpha // α値 |
| 50 |
){ |
| 51 |
int tw = m_ImageSize[0], th = m_ImageSize[1]; |
| 52 |
int cw = m_Cursor2DSize[0], ch = m_Cursor2DSize[1]; |
| 53 |
int cols = tw/cw; |
| 54 |
int px = pos.x-m_Cursor2DHotSpot[0], py = pos.y-m_Cursor2DHotSpot[1]; |
| 55 |
devSetTexture(0, m_CursorTexture); |
| 56 |
float fw = (float)cw/tw, fh = (float)ch/th; |
| 57 |
float u = (m_Anim%cols)*fw; |
| 58 |
float v = (m_Anim/cols)*fh; |
| 59 |
SetUVMap(u, v, u+fw, v+fh); |
| 60 |
TexMap2DRect(px, py, px+cw, py+ch, ScaleColor(0xffffffff, alpha)); |
| 61 |
m_Frame--; |
| 62 |
if(m_Frame<=0){ |
| 63 |
m_Anim = (m_Anim+1)%m_Cursor2DAnimNumber; |
| 64 |
m_Frame = m_Cursor2DAnimFrame[m_Anim]; |
| 65 |
} |
| 66 |
} |
| 67 |
|
| 68 |
//////////////////////////////////////////////////////////////////////////////// |
| 69 |
//////////////////////////////////////////////////////////////////////////////// |
| 70 |
|
| 71 |
/* |
| 72 |
* 初期化 |
| 73 |
*/ |
| 74 |
void CCursor::Init(){ |
| 75 |
m_Alpha = 1.0f; |
| 76 |
m_Resizing = -2; |
| 77 |
if(!sv3.fWindowed || svw.fActive){ |
| 78 |
Center(); |
| 79 |
ShowCursor(FALSE); |
| 80 |
Clip(); |
| 81 |
} |
| 82 |
} |
| 83 |
|
| 84 |
/* |
| 85 |
* ウィンドウ内にクリップ |
| 86 |
*/ |
| 87 |
void CCursor::Clip(){ |
| 88 |
POINT wp = {0, 0}; |
| 89 |
ClientToScreen(svw.hWnd, &wp); |
| 90 |
RECT crc = {wp.x, wp.y, wp.x+g_DispWidth, wp.y+g_DispHeight}; |
| 91 |
ClipCursor(&crc); |
| 92 |
} |
| 93 |
|
| 94 |
/* |
| 95 |
* カーソルを中央へ |
| 96 |
*/ |
| 97 |
void CCursor::Center(){ |
| 98 |
SetCursor(m_Pos.x = g_DispWidth/2, m_Pos.y = g_DispHeight/2); |
| 99 |
} |
| 100 |
|
| 101 |
/* |
| 102 |
* 描画 |
| 103 |
*/ |
| 104 |
void CCursor::Render(){ |
| 105 |
if(m_State) m_Alpha = m_Alpha*CURSOR_HIDE_RATIO; |
| 106 |
else m_Alpha = m_Alpha*CURSOR_HIDE_RATIO+(1.0f-CURSOR_HIDE_RATIO); |
| 107 |
if(m_Resizing<0) g_Skin->m_NormalCursorData.Render(m_Pos, m_Alpha); |
| 108 |
else g_Skin->m_ResizeCursorData[m_Resizing].Render(m_Pos, m_Alpha); |
| 109 |
m_Resizing = -2; |
| 110 |
} |
| 111 |
|
| 112 |
/* |
| 113 |
* 入力チェック |
| 114 |
*/ |
| 115 |
void CCursor::ScanInput( |
| 116 |
bool forcelock // 強制ロック |
| 117 |
){ |
| 118 |
ScanInputDevice(); |
| 119 |
g_Cursor.FixCursor(); |
| 120 |
|
| 121 |
int cx = g_DispWidth/2, cy = g_DispHeight/2; |
| 122 |
m_Delta = GetCursorXY(); |
| 123 |
m_Delta.x -= cx; |
| 124 |
m_Delta.y -= cy; |
| 125 |
if(!m_State && !forcelock){ |
| 126 |
m_Pos.x += m_Delta.x; |
| 127 |
m_Pos.y += m_Delta.y; |
| 128 |
ValueArea((int *)&m_Pos.x, 0, g_DispWidth-1); |
| 129 |
ValueArea((int *)&m_Pos.y, 0, g_DispHeight-1); |
| 130 |
} |
| 131 |
} |
| 132 |
|
| 133 |
/* |
| 134 |
* カーソル固定 |
| 135 |
*/ |
| 136 |
void CCursor::FixCursor(){ |
| 137 |
int cx = g_DispWidth/2, cy = g_DispHeight/2; |
| 138 |
SetCursor(cx, cy); |
| 139 |
} |
| 140 |
|
| 141 |
/* |
| 142 |
* ドラッグ開始判定 |
| 143 |
*/ |
| 144 |
bool CCursor::CheckDrag(){ |
| 145 |
return abs(m_Delta.x)>=CSR_MOVE_TSD || abs(m_Delta.y)>=CSR_MOVE_TSD; |
| 146 |
} |
| 147 |
|
| 148 |
/* |
| 149 |
* ロック |
| 150 |
*/ |
| 151 |
void CCursor::Lock(){ |
| 152 |
m_State = 1; |
| 153 |
m_Delta.x = m_Delta.y = 0; |
| 154 |
SetCursor(g_DispWidth/2, g_DispHeight/2); |
| 155 |
} |
| 156 |
|
| 157 |
/* |
| 158 |
* 解放 |
| 159 |
*/ |
| 160 |
void CCursor::Release(){ |
| 161 |
m_State = 0; |
| 162 |
} |