1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 #if defined(ENABLE_EOB) || defined(ENABLE_LOL)
24 
25 #include "kyra/engine/kyra_rpg.h"
26 
27 namespace Kyra {
28 
removeInputTop()29 void KyraRpgEngine::removeInputTop() {
30 	if (!_eventList.empty()) {
31 		if (_eventList.begin()->event.type == Common::EVENT_LBUTTONDOWN)
32 			_mouseClick = 1;
33 		else if (_eventList.begin()->event.type == Common::EVENT_RBUTTONDOWN)
34 			_mouseClick = 2;
35 		else
36 			_mouseClick = 0;
37 
38 		_eventList.erase(_eventList.begin());
39 	}
40 }
41 
gui_drawBox(int x,int y,int w,int h,int frameColor1,int frameColor2,int fillColor)42 void KyraRpgEngine::gui_drawBox(int x, int y, int w, int h, int frameColor1, int frameColor2, int fillColor) {
43 	w--;
44 	h--;
45 	if (fillColor != -1)
46 		screen()->fillRect(x + 1, y + 1, x + w - 1, y + h - 1, fillColor);
47 
48 	screen()->drawClippedLine(x + 1, y, x + w, y, frameColor2);
49 	screen()->drawClippedLine(x + w, y, x + w, y + h - 1, frameColor2);
50 	screen()->drawClippedLine(x, y, x, y + h, frameColor1);
51 	screen()->drawClippedLine(x, y + h, x + w, y + h, frameColor1);
52 }
53 
gui_drawHorizontalBarGraph(int x,int y,int w,int h,int32 cur,int32 max,int col1,int col2)54 void KyraRpgEngine::gui_drawHorizontalBarGraph(int x, int y, int w, int h, int32 cur, int32 max, int col1, int col2) {
55 	if (max < 1)
56 		return;
57 	if (cur < 0)
58 		cur = 0;
59 
60 	int32 e = MIN(cur, max);
61 
62 	if (!--w)
63 		return;
64 	if (!--h)
65 		return;
66 
67 	int32 t = (e * w) / max;
68 
69 	if (!t && e)
70 		t++;
71 
72 	if (t)
73 		screen()->fillRect(x, y, x + t - 1, y + h, col1);
74 
75 	if (t < w && col2)
76 		screen()->fillRect(x + t, y, x + w - 1, y + h, col2);
77 }
78 
gui_initButtonsFromList(const uint8 * list)79 void KyraRpgEngine::gui_initButtonsFromList(const uint8 *list) {
80 	while (*list != 0xFF)
81 		gui_initButton(*list++);
82 }
83 
gui_resetButtonList()84 void KyraRpgEngine::gui_resetButtonList() {
85 	for (uint i = 0; i < ARRAYSIZE(_activeButtonData); ++i)
86 		_activeButtonData[i].nextButton = 0;
87 
88 	gui_notifyButtonListChanged();
89 	_activeButtons = 0;
90 }
91 
gui_notifyButtonListChanged()92 void KyraRpgEngine::gui_notifyButtonListChanged() {
93 	if (gui()) {
94 		if (!_buttonListChanged && !_preserveEvents)
95 			removeInputTop();
96 		_buttonListChanged = true;
97 	}
98 }
99 
clickedShape(int shapeIndex)100 bool KyraRpgEngine::clickedShape(int shapeIndex) {
101 	if (_clickedSpecialFlag != 0x40)
102 		return true;
103 
104 	for (; shapeIndex; shapeIndex = _levelDecorationProperties[shapeIndex].next) {
105 		if (_flags.gameID != GI_LOL)
106 			shapeIndex--;
107 
108 		uint16 s = _levelDecorationProperties[shapeIndex].shapeIndex[1];
109 
110 		if (s == 0xFFFF)
111 			continue;
112 
113 		int w = _flags.gameID == GI_LOL ? _levelDecorationShapes[s][3] : (_levelDecorationShapes[s][2] << 3);
114 		int h = _levelDecorationShapes[s][_flags.gameID == GI_LOL ? 2 : 1];
115 		int x = _levelDecorationProperties[shapeIndex].shapeX[1] + _clickedShapeXOffs;
116 		int y = _levelDecorationProperties[shapeIndex].shapeY[1] + _clickedShapeYOffs;
117 
118 		if (_levelDecorationProperties[shapeIndex].flags & 1) {
119 			if (_flags.gameID == GI_LOL)
120 				w <<= 1;
121 			else
122 				x = 176 - x - w;
123 		}
124 
125 		if (posWithinRect(_mouseX, _mouseY, x - 4, y - 4, x + w + 8, y + h + 8))
126 			return true;
127 	}
128 
129 	return false;
130 }
131 
132 } // End of namespace Kyra
133 
134 #endif // defined(ENABLE_EOB) || defined(ENABLE_LOL)
135