File: GuiPopUpMessageBox.cpp

package info (click to toggle)
scummvm 2.9.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 450,580 kB
  • sloc: cpp: 4,299,825; asm: 28,322; python: 12,901; sh: 11,302; java: 9,289; xml: 7,895; perl: 2,639; ansic: 2,465; yacc: 1,670; javascript: 1,020; makefile: 933; lex: 578; awk: 275; objc: 82; sed: 11; php: 1
file content (158 lines) | stat: -rw-r--r-- 5,370 bytes parent folder | download | duplicates (3)
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
154
155
156
157
158
/* ScummVM - Graphic Adventure Engine
 *
 * ScummVM is the legal property of its developers, whose names
 * are too numerous to list here. Please refer to the COPYRIGHT
 * file distributed with this source distribution.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

/*
 * Copyright (C) 2006-2010 - Frictional Games
 *
 * This file is part of HPL1 Engine.
 */

#include "hpl1/engine/gui/GuiPopUpMessageBox.h"

#include "hpl1/engine/system/low_level_system.h"

#include "hpl1/engine/math/Math.h"

#include "hpl1/engine/graphics/font_data.h"

#include "hpl1/engine/gui/Gui.h"
#include "hpl1/engine/gui/GuiSet.h"
#include "hpl1/engine/gui/GuiSkin.h"

#include "hpl1/engine/gui/WidgetButton.h"
#include "hpl1/engine/gui/WidgetLabel.h"
#include "hpl1/engine/gui/WidgetWindow.h"

namespace hpl {

//////////////////////////////////////////////////////////////////////////
// CONSTRUCTORS
//////////////////////////////////////////////////////////////////////////

//-----------------------------------------------------------------------

cGuiPopUpMessageBox::cGuiPopUpMessageBox(cGuiSet *apSet,
										 const tWString &asLabel, const tWString &asText,
										 const tWString &asButton1, const tWString &asButton2,
										 void *apCallbackObject, tGuiCallbackFunc apCallback)
	: iGuiPopUp(apSet) {
	//////////////////////////
	// Set up variables
	mpCallback = apCallback;
	mpCallbackObject = apCallbackObject;

	cGuiSkinFont *pFont = mpSkin->GetFont(eGuiSkinFont_Default);

	float fWindowMinLength = pFont->mpFont->getLength(pFont->mvSize, asLabel.c_str());
	float fTextLength = pFont->mpFont->getLength(pFont->mvSize, asText.c_str());

	if (fTextLength > fWindowMinLength)
		fWindowMinLength = fTextLength;

	float fWindowWidth = fWindowMinLength + 40 > 200 ? fWindowMinLength + 40 : 200;

	cVector2f vVirtSize = mpSet->GetVirtualSize();

	float fWindowHeight = 90 + pFont->mvSize.y;

	//////////////////////////
	// Window
	cVector3f vPos = cVector3f(vVirtSize.x / 2 - fWindowWidth / 2, vVirtSize.y / 2 - fWindowHeight / 2, 18);
	mpWindow = mpSet->CreateWidgetWindow(vPos, cVector2f(fWindowWidth, fWindowHeight), asLabel, NULL);

	//////////////////////////
	// Buttons
	if (asButton2 == _W("")) {
		vPos = cVector3f(fWindowWidth / 2 - 40, 50 + pFont->mvSize.y, 1);
		mvButtons[0] = mpSet->CreateWidgetButton(vPos, cVector2f(80, 30), asButton1, mpWindow);
		mvButtons[0]->AddCallback(eGuiMessage_ButtonPressed, this, kGuiCallback(ButtonPress));

		mvButtons[1] = NULL;
	} else {
		vPos = cVector3f(fWindowWidth / 2 - (80 * 2 + 20) / 2, 50 + pFont->mvSize.y, 1);
		mvButtons[0] = mpSet->CreateWidgetButton(vPos, cVector2f(80, 30), asButton1, mpWindow);
		mvButtons[0]->AddCallback(eGuiMessage_ButtonPressed, this, kGuiCallback(ButtonPress));

		vPos.x += 80 + 20;
		mvButtons[1] = mpSet->CreateWidgetButton(vPos, cVector2f(80, 30), asButton2, mpWindow);
		mvButtons[1]->AddCallback(eGuiMessage_ButtonPressed, this, kGuiCallback(ButtonPress));
	}

	//////////////////////////
	// Label
	vPos = cVector3f(20, 30, 1);
	mpLabel = mpSet->CreateWidgetLabel(vPos, cVector2f(fWindowWidth - 10, pFont->mvSize.y),
									   asText, mpWindow);

	//////////////////////////
	// Attention
	mpPrevAttention = mpSet->GetAttentionWidget();
	mpSet->SetAttentionWidget(mpWindow);
}

//-----------------------------------------------------------------------

cGuiPopUpMessageBox::~cGuiPopUpMessageBox() {
	if (mpWindow)
		mpSet->DestroyWidget(mpWindow);
	if (mvButtons[0])
		mpSet->DestroyWidget(mvButtons[0]);
	if (mvButtons[1])
		mpSet->DestroyWidget(mvButtons[1]);
	if (mpLabel)
		mpSet->DestroyWidget(mpLabel);
}

//-----------------------------------------------------------------------

//////////////////////////////////////////////////////////////////////////
// PUBLIC METHODS
//////////////////////////////////////////////////////////////////////////

//-----------------------------------------------------------------------

//-----------------------------------------------------------------------

//////////////////////////////////////////////////////////////////////////
// PROTECTED METHODS
//////////////////////////////////////////////////////////////////////////

//-----------------------------------------------------------------------

bool cGuiPopUpMessageBox::ButtonPress(iWidget *apWidget, cGuiMessageData &aData) {
	int lButton = apWidget == mvButtons[0] ? 0 : 1;

	mpSet->SetAttentionWidget(mpPrevAttention);

	if (mpCallback && mpCallbackObject) {
		cGuiMessageData data = cGuiMessageData(lButton);
		mpCallback(mpCallbackObject, apWidget, data);
	}

	SelfDestruct();

	return true;
}
kGuiCalllbackDeclaredFuncEnd(cGuiPopUpMessageBox, ButtonPress)

//-----------------------------------------------------------------------

} // namespace hpl