Develop and Download Open Source Software

Browse Subversion Repository

Contents of /trunk/CPushButton.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (show annotations) (download) (as text)
Sun Aug 15 01:53:13 2010 UTC (13 years, 9 months ago) by okadu
File MIME type: text/x-c++src
File size: 2706 byte(s)


1 #include "stdafx.h"
2 #include "CPushButton.h"
3 #include "CSkinPlugin.h"
4
5 /*
6 * 初期化
7 */
8 void CPushButton::Init(
9 int x, int y, // 座標
10 int w, int h, // サイズ
11 char *t, // テキスト
12 CInterface *p // 親
13 ){
14 CInterface::Init(x, y, w, h, t, p);
15 m_State = 0;
16 m_Sound = true;
17 m_Pushed = false;
18 m_Pushable = true;
19 LinkTab(true);
20 }
21
22 /*
23 * 入力チェック
24 */
25 bool CPushButton::ScanInput(){
26 m_Pushed = false;
27 if(!m_Pushable) return CInterface::ScanInput();
28 if(!m_Enabled){
29 m_State = 0;
30 return CInterface::ScanInput();
31 }
32 POINT pos = g_Cursor.GetPos();
33 int key = GetKey(DIK_SPACE)|GetKey(DIK_RETURN)|GetKey(DIK_NUMPADENTER);
34 bool in = IsInside(pos.x, pos.y), focus = IsFocus();
35 if(in || focus && key){
36 int stt = 0;
37 if(in) stt |= GetButton(DIM_LEFT);
38 if(focus) stt |= key;
39 switch(stt){
40 case S_PUSH:
41 m_State = 2;
42 GiveFocus();
43 return true;
44 case S_HOLD:
45 if(m_State){
46 m_State = 2;
47 return true;
48 }
49 break;
50 default:
51 if(m_State){
52 m_Pushed = true;
53 if(m_Sound) g_Skin->MouseUp();
54 }
55 m_State = 0;
56 break;
57 }
58 }else if(m_State){
59 switch(GetButton(DIM_LEFT)){
60 case S_HOLD:
61 m_State = 1;
62 return true;
63 default:
64 m_State = 0;
65 break;
66 }
67 }
68 return CInterface::ScanInput();
69 }
70
71 /*
72 * レンダリング
73 */
74 void CPushButton::Render(){
75 CInterface::RenderBrother();
76 int px, py, push = m_State==2;
77 float tv = m_State==2 ? 0.625f : 0.5f;
78 GetAbsPos(&px, &py);
79 g_Skin->SetInterfaceTexture();
80 if(m_Width<2*TILE_UNIT){
81 int w1 = m_Width/2, w2 = m_Width-w1;
82 SetUVMap(0.0f, tv, 0.125f*w1/TILE_UNIT, tv+0.125f);
83 TexMap2DRect(px, py, px+w1, py+m_Height, 0xffffffff);
84 SetUVMap(0.375f-0.125*w2/TILE_UNIT, tv, 0.375f, tv+0.125f);
85 TexMap2DRect(px+w1, py, px+m_Width, py+m_Height, 0xffffffff);
86 }else{
87 SetUVMap(0.0f, tv, 0.125f, tv+0.125f);
88 TexMap2DRect(px, py, px+TILE_UNIT, py+m_Height, 0xffffffff);
89 SetUVMap(0.125f, tv, 0.25f, tv+0.125f);
90 TexMap2DRect(px+TILE_UNIT, py, px+m_Width-TILE_UNIT, py+m_Height, 0xffffffff);
91 SetUVMap(0.25f, tv, 0.375f, tv+0.125f);
92 TexMap2DRect(px+m_Width-TILE_UNIT, py, px+m_Width, py+m_Height, 0xffffffff);
93 }
94 D3DCOLOR fc = g_Skin->m_InterfaceData.m_ButtonFontColor, sdw = 0;
95 if(!m_Enabled){
96 fc = g_Skin->m_PopupMenuData.m_DisabledFontColor;
97 sdw = g_Skin->m_PopupMenuData.m_DisabledShadowColor;
98 }
99 if(sdw) g_StrTex->RenderCenter(px+m_Width/2+push+1, py+FontY(m_Height)+push+1,
100 sdw, 0, m_Text.c_str(), m_Width, m_Height);
101 g_StrTex->RenderCenter(px+m_Width/2+push, py+FontY(m_Height)+push,
102 fc, 0, m_Text.c_str(), m_Width, m_Height);
103 CInterface::RenderChild();
104 if(IsFocus()) DrawFocusFrame();
105 }

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26