aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.Client/Common/UI/UIControl.cpp
blob: 7582e82ffe95d5ccab9e612358d61ccff6ad6a71 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#include "stdafx.h"
#include "UI.h"
#include "UIControl.h"
#include "..\..\..\Minecraft.World\StringHelpers.h"
#include "..\..\..\Minecraft.World\JavaMath.h"

UIControl::UIControl()
{
	m_parentScene = nullptr;
	m_lastOpacity = 1.0f;
	m_controlName = "";
	m_isVisible = true;
	m_bHidden = false;
	m_eControlType = eNoControl;
	m_id = -1;
	m_pParentPanel = NULL;
}

bool UIControl::setupControl(UIScene *scene, IggyValuePath *parent, const string &controlName)
{
	m_parentScene = scene;
	m_controlName = controlName;

	rrbool res = IggyValuePathMakeNameRef ( &m_iggyPath , parent , controlName.c_str() );

	m_nameXPos = registerFastName(L"x");
	m_nameYPos = registerFastName(L"y");
	m_nameWidth = registerFastName(L"width");
	m_nameHeight = registerFastName(L"height");
	m_funcSetAlpha = registerFastName(L"SetControlAlpha");
	m_nameVisible = registerFastName(L"visible");

	F64 fx, fy, fwidth, fheight;
	IggyValueGetF64RS( getIggyValuePath() , m_nameXPos , nullptr , &fx ); 
	IggyValueGetF64RS( getIggyValuePath() , m_nameYPos , nullptr , &fy ); 
	IggyValueGetF64RS( getIggyValuePath() , m_nameWidth , nullptr , &fwidth ); 
	IggyValueGetF64RS( getIggyValuePath() , m_nameHeight , nullptr , &fheight );

	m_x = static_cast<S32>(fx);
	m_y = static_cast<S32>(fy);
	m_width = static_cast<S32>(Math::round(fwidth));
	m_height = static_cast<S32>(Math::round(fheight));

	return res;
}

void UIControl::UpdateControl()
{
	F64 fx, fy, fwidth, fheight;
	IggyValueGetF64RS( getIggyValuePath() , m_nameXPos , nullptr , &fx ); 
	IggyValueGetF64RS( getIggyValuePath() , m_nameYPos , nullptr , &fy ); 
	IggyValueGetF64RS( getIggyValuePath() , m_nameWidth , nullptr , &fwidth ); 
	IggyValueGetF64RS( getIggyValuePath() , m_nameHeight , nullptr , &fheight );
	m_x = static_cast<S32>(fx);
	m_y = static_cast<S32>(fy);
	m_width = static_cast<S32>(Math::round(fwidth));
	m_height = static_cast<S32>(Math::round(fheight));
}

void UIControl::ReInit()
{
	if(m_lastOpacity != 1.0f)
	{
		IggyDataValue result;
		IggyDataValue value[2];
		IggyStringUTF8 stringVal;

		stringVal.string = (char *)m_controlName.c_str();
		stringVal.length = m_controlName.length();
		value[0].type = IGGY_DATATYPE_string_UTF8;
		value[0].string8 = stringVal;

		value[1].type = IGGY_DATATYPE_number;
		value[1].number = m_lastOpacity;

		IggyResult out = IggyPlayerCallMethodRS ( m_parentScene->getMovie() , &result, m_parentScene->m_rootPath , m_funcSetAlpha , 2 , value );
	}

	IggyValueSetBooleanRS( getIggyValuePath(), m_nameVisible, nullptr, m_isVisible );
}

IggyValuePath *UIControl::getIggyValuePath()
{
	return &m_iggyPath;
}

S32 UIControl::getXPos()
{
	return m_x;
}

S32 UIControl::getYPos()
{
	return m_y;
}

S32 UIControl::getWidth()
{
	return m_width;
}

S32 UIControl::getHeight()
{
	return m_height;
}

void UIControl::setOpacity(float percent)
{
	if(percent != m_lastOpacity)
	{
		m_lastOpacity = percent;

		IggyDataValue result;
		IggyDataValue value[2];
		IggyStringUTF8 stringVal;

		stringVal.string = (char *)m_controlName.c_str();
		stringVal.length = m_controlName.length();
		value[0].type = IGGY_DATATYPE_string_UTF8;
		value[0].string8 = stringVal;

		value[1].type = IGGY_DATATYPE_number;
		value[1].number = m_lastOpacity;

		IggyResult out = IggyPlayerCallMethodRS ( m_parentScene->getMovie() , &result, m_parentScene->m_rootPath , m_funcSetAlpha , 2 , value );
	}
}

void UIControl::setVisible(bool visible)
{
	if(visible != m_isVisible)
	{
		rrbool succ = IggyValueSetBooleanRS( getIggyValuePath(), m_nameVisible, nullptr, visible );
		if(succ) m_isVisible = visible;
		else app.DebugPrintf("Failed to set visibility for control\n");
	}
}

bool UIControl::getVisible()
{
	rrbool bVisible = false;
	
	IggyResult result = IggyValueGetBooleanRS ( getIggyValuePath() , m_nameVisible, nullptr, &bVisible );
	
	m_isVisible = bVisible;
	
	return bVisible;
}

IggyName UIControl::registerFastName(const wstring &name)
{
	return m_parentScene->registerFastName(name);
}