| 1 |
#include "stdafx.h" |
| 2 |
#include "CMultiStatic.h" |
| 3 |
#include "CSkinPlugin.h" |
| 4 |
|
| 5 |
// 内部定数 |
| 6 |
const int MULTISTATIC_MARGIN = 2; // 余白 |
| 7 |
|
| 8 |
/* |
| 9 |
* 初期化 |
| 10 |
*/ |
| 11 |
void CMultiStatic::Init( |
| 12 |
int x, int y, // 座標 |
| 13 |
int w, int h, // サイズ |
| 14 |
CInterface *p, // 親 |
| 15 |
int lh // 行高さ |
| 16 |
){ |
| 17 |
CInterface::Init(x, y, w, h, "", p); |
| 18 |
LinkTab(true); |
| 19 |
m_ScrollV.Init(m_Width-TILE_UNIT, 0, TILE_UNIT, m_Height, this); |
| 20 |
m_LineHeight = lh; |
| 21 |
} |
| 22 |
|
| 23 |
/* |
| 24 |
* サイズ変更 |
| 25 |
*/ |
| 26 |
void CMultiStatic::SetSize( |
| 27 |
int w, int h // 新規サイズ |
| 28 |
){ |
| 29 |
m_Width = w; m_Height = h; |
| 30 |
m_ScrollV.SetPos(m_Width-TILE_UNIT, 0); |
| 31 |
m_ScrollV.SetSize(TILE_UNIT, m_Height); |
| 32 |
SetText(NULL); |
| 33 |
SetScroll(); |
| 34 |
} |
| 35 |
|
| 36 |
/* |
| 37 |
* テキスト設定 |
| 38 |
*/ |
| 39 |
void CMultiStatic::SetText( |
| 40 |
char *t // テクスト |
| 41 |
){ |
| 42 |
if(t) m_Text = t; |
| 43 |
m_LineText.clear(); |
| 44 |
int tw = m_Width-TILE_UNIT-MULTISTATIC_MARGIN*2; |
| 45 |
char *str = (char *)m_Text.c_str(); |
| 46 |
while(*str){ |
| 47 |
if(*str=='\n'){ |
| 48 |
m_LineText.push_back(""); |
| 49 |
str++; |
| 50 |
}else if(*str=='\r'){ |
| 51 |
str++; |
| 52 |
}else{ |
| 53 |
char *tmp = CharNext(str), *tmp2 = CharNext(tmp); |
| 54 |
for(; *tmp && *tmp!='\n'; tmp2 = CharNext(tmp2)){ |
| 55 |
string test(str, tmp2); |
| 56 |
if(g_StrTex->DrawString(test.c_str(), 0)->GetWidth()>tw) break; |
| 57 |
tmp = tmp2; |
| 58 |
} |
| 59 |
m_LineText.push_back(string(str, tmp)); |
| 60 |
str = tmp; |
| 61 |
if(*str=='\n') str++; |
| 62 |
} |
| 63 |
} |
| 64 |
} |
| 65 |
|
| 66 |
/* |
| 67 |
* スクロールバーの更新 |
| 68 |
*/ |
| 69 |
void CMultiStatic::SetScroll(){ |
| 70 |
m_Lines = (m_Height-MULTISTATIC_MARGIN*2)/m_LineHeight; |
| 71 |
m_ScrollV.SetRange(m_LineText.size() ? m_LineText.size() : 1); |
| 72 |
m_ScrollV.SetPage(m_Lines); |
| 73 |
} |
| 74 |
|
| 75 |
/* |
| 76 |
* 指定座標がリスト内か調べる |
| 77 |
*/ |
| 78 |
bool CMultiStatic::IsInsideList( |
| 79 |
int x, int y // 座標 |
| 80 |
){ |
| 81 |
int px, py; |
| 82 |
GetAbsPos(&px, &py); |
| 83 |
return px<=x && x<px+m_Width-TILE_UNIT && py+TILE_UNIT<=y && y<py+m_Height; |
| 84 |
} |
| 85 |
|
| 86 |
/* |
| 87 |
* 入力チェック |
| 88 |
*/ |
| 89 |
bool CMultiStatic::ScanInput(){ |
| 90 |
POINT pos = g_Cursor.GetPos(); |
| 91 |
int px, py; |
| 92 |
GetAbsPos(&px, &py); |
| 93 |
SetScroll(); |
| 94 |
if(IsInsideList(pos.x, pos.y) && GetButton(DIM_LEFT)==S_PUSH){ |
| 95 |
GiveFocus(); |
| 96 |
return true; |
| 97 |
} |
| 98 |
if(IsFocus()){ |
| 99 |
static int rep; |
| 100 |
int s; |
| 101 |
if((s = GetKey(DIK_UP))>=S_PUSH){ |
| 102 |
if(PickRepeat(&rep, s)) m_ScrollV.SetScroll(m_ScrollV.GetScroll()-1); |
| 103 |
}else if((s = GetKey(DIK_DOWN))>=S_PUSH){ |
| 104 |
if(PickRepeat(&rep, s)) m_ScrollV.SetScroll(m_ScrollV.GetScroll()+1); |
| 105 |
}else if(GetWheel()<0){ |
| 106 |
m_ScrollV.SetScroll(m_ScrollV.GetScroll()+3); |
| 107 |
}else if(GetWheel()>0){ |
| 108 |
m_ScrollV.SetScroll(m_ScrollV.GetScroll()-3); |
| 109 |
} |
| 110 |
} |
| 111 |
return CInterface::ScanInput(); |
| 112 |
} |
| 113 |
|
| 114 |
/* |
| 115 |
* レンダリング |
| 116 |
*/ |
| 117 |
void CMultiStatic::Render(){ |
| 118 |
CInterface::RenderBrother(); |
| 119 |
CInterface::RenderChild(); |
| 120 |
int i, px, py; |
| 121 |
GetAbsPos(&px, &py); |
| 122 |
devSetTexture(0, NULL); |
| 123 |
px += MULTISTATIC_MARGIN; |
| 124 |
int ofs = m_ScrollV.GetScroll(), ty = py+MULTISTATIC_MARGIN, by = py+m_Height; |
| 125 |
list<string>::iterator it = m_LineText.begin(); |
| 126 |
for(i = 0; it!=m_LineText.end(); it++, i++){ |
| 127 |
if(i<ofs) continue; |
| 128 |
int th = by-ty; |
| 129 |
if(th<=0) break; |
| 130 |
if(th>m_LineHeight) th = m_LineHeight; |
| 131 |
g_StrTex->RenderLeft(px, ty, g_Skin->m_InterfaceData.m_StaticFontColor, |
| 132 |
0, it->c_str(), m_Width-TILE_UNIT, th); |
| 133 |
ty += m_LineHeight; |
| 134 |
} |
| 135 |
if(IsFocus()) DrawFocusFrame(); |
| 136 |
} |