| 1 |
#include "stdafx.h" |
| 2 |
#include "CRadioButton.h" |
| 3 |
#include "CSkinPlugin.h" |
| 4 |
|
| 5 |
/* |
| 6 |
* 初期化 |
| 7 |
*/ |
| 8 |
void CRadioButton::Init( |
| 9 |
int x, int y, // 座標 |
| 10 |
int w, int h, // サイズ |
| 11 |
char *t, // テキスト |
| 12 |
CInterface *p, // 親 |
| 13 |
CRadioButton *l // 前リンク |
| 14 |
){ |
| 15 |
CInterface::Init(x, y, w, h, t, p); |
| 16 |
m_State = 0; |
| 17 |
if(l){ |
| 18 |
m_Check = 0; |
| 19 |
m_Prev = l; |
| 20 |
m_Next = m_Prev->m_Next; |
| 21 |
m_Prev->m_Next = m_Next->m_Prev = this; |
| 22 |
}else{ |
| 23 |
m_Check = 1; |
| 24 |
m_Prev = m_Next = this; |
| 25 |
} |
| 26 |
LinkTab(true); |
| 27 |
} |
| 28 |
|
| 29 |
/* |
| 30 |
* チェッククリア |
| 31 |
*/ |
| 32 |
void CRadioButton::ClearGroupCheck(){ |
| 33 |
CRadioButton *ptr = this; |
| 34 |
do{ |
| 35 |
ptr->m_Check = 0; |
| 36 |
ptr = ptr->m_Next; |
| 37 |
} while(ptr!=this); |
| 38 |
} |
| 39 |
|
| 40 |
/* |
| 41 |
* チェック番号の取得 |
| 42 |
*/ |
| 43 |
int CRadioButton::GetNumber(){ |
| 44 |
CRadioButton *ptr = this; |
| 45 |
int i = 0; |
| 46 |
do{ |
| 47 |
if(ptr->m_Check) return i; |
| 48 |
i++; |
| 49 |
ptr = ptr->m_Next; |
| 50 |
} while(ptr!=this); |
| 51 |
return -1; |
| 52 |
} |
| 53 |
|
| 54 |
/* |
| 55 |
* 入力チェック |
| 56 |
*/ |
| 57 |
bool CRadioButton::ScanInput(){ |
| 58 |
if(!m_Enabled){ |
| 59 |
m_State = 0; |
| 60 |
return CInterface::ScanInput(); |
| 61 |
} |
| 62 |
POINT pos = g_Cursor.GetPos(); |
| 63 |
int key = GetKey(DIK_SPACE)|GetKey(DIK_RETURN)|GetKey(DIK_NUMPADENTER); |
| 64 |
bool in = IsInside(pos.x, pos.y), focus = IsFocus(); |
| 65 |
if(in || focus && key){ |
| 66 |
int stt = 0; |
| 67 |
if(in) stt |= GetButton(DIM_LEFT); |
| 68 |
if(focus) stt |= key; |
| 69 |
switch(stt){ |
| 70 |
case S_PUSH: |
| 71 |
m_State = 2; |
| 72 |
GiveFocus(); |
| 73 |
return true; |
| 74 |
case S_HOLD: |
| 75 |
if(m_State){ |
| 76 |
m_State = 2; |
| 77 |
return true; |
| 78 |
} |
| 79 |
break; |
| 80 |
default: |
| 81 |
if(m_State){ |
| 82 |
g_Skin->MouseUp(); |
| 83 |
SetCheck(); |
| 84 |
} |
| 85 |
m_State = 0; |
| 86 |
break; |
| 87 |
} |
| 88 |
}else if(m_State){ |
| 89 |
switch(GetButton(DIM_LEFT)){ |
| 90 |
case S_HOLD: |
| 91 |
m_State = 1; |
| 92 |
return true; |
| 93 |
default: |
| 94 |
m_State = 0; |
| 95 |
break; |
| 96 |
} |
| 97 |
} |
| 98 |
return CInterface::ScanInput(); |
| 99 |
} |
| 100 |
|
| 101 |
/* |
| 102 |
* レンダリング |
| 103 |
*/ |
| 104 |
void CRadioButton::Render(){ |
| 105 |
CInterface::RenderBrother(); |
| 106 |
int px, py, push = m_State==2; |
| 107 |
float tv = m_State==2 ? 0.125f : (m_Check ? 0.25f : 0.0f); |
| 108 |
GetAbsPos(&px, &py); |
| 109 |
g_Skin->SetInterfaceTexture(); |
| 110 |
SetUVMap(0.5f, tv, 0.625f, tv+0.125f); |
| 111 |
TexMap2DRect(px, py, px+TILE_UNIT, py+m_Height, 0xffffffff); |
| 112 |
int lim = m_Width-TILE_UNIT*3/2-push; |
| 113 |
D3DCOLOR fc = g_Skin->m_InterfaceData.m_StaticFontColor, sdw = 0; |
| 114 |
if(!m_Enabled){ |
| 115 |
fc = g_Skin->m_PopupMenuData.m_DisabledFontColor; |
| 116 |
sdw = g_Skin->m_PopupMenuData.m_DisabledShadowColor; |
| 117 |
} |
| 118 |
if(sdw) g_StrTex->RenderLeft(px+TILE_UNIT*3/2+push+1, py+FontY(m_Height)+push+1, |
| 119 |
sdw, 0, m_Text.c_str(), lim>0 ? lim : 1); |
| 120 |
g_StrTex->RenderLeft(px+TILE_UNIT*3/2+push, py+FontY(m_Height)+push, |
| 121 |
fc, 0, m_Text.c_str(), lim>0 ? lim : 1); |
| 122 |
CInterface::RenderChild(); |
| 123 |
if(IsFocus()){ |
| 124 |
devSetTexture(0, NULL); |
| 125 |
Draw2DRect(px+TILE_UNIT*5/4, py, px+m_Width, py+m_Height, |
| 126 |
g_Skin->m_InterfaceData.m_FocusFrameColor); |
| 127 |
} |
| 128 |
} |