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  * Additional copyright for this file:
8  * Copyright (C) 1995-1997 Presto Studios, Inc.
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23  *
24  */
25 
26 #include "pegasus/graphics.h"
27 #include "pegasus/neighborhood/wsc/moleculebin.h"
28 #include "pegasus/neighborhood/wsc/wsc.h"
29 
30 namespace Pegasus {
31 
32 static const CoordType kMoleculeBinWidth = 138;
33 static const CoordType kMoleculeBinHeight = 128;
34 
35 static const CoordType kMoleculeWidth = 66;
36 static const CoordType kMoleculeHeight = 40;
37 
38 static const CoordType kMoleculeBinLeft = kNavAreaLeft + 286;
39 static const CoordType kMoleculeBinTop = kNavAreaLeft + 96;
40 
41 //	Layouts:
42 
MoleculeBin()43 MoleculeBin::MoleculeBin() : DisplayElement(kNoDisplayElement) {
44 	_highlightColor = g_system->getScreenFormat().RGBToColor(0xff, 0xff, 102);
45 	_selectedMolecule = -1;
46 }
47 
initMoleculeBin()48 void MoleculeBin::initMoleculeBin() {
49 	if (!isDisplaying()) {
50 		for (int i = 0; i < 6; i++)
51 			_binLayout[i] = i;
52 
53 		resetBin();
54 		_binImages.getImageFromPICTFile("Images/World Science Center/Molecules");
55 		setDisplayOrder(kWSCMoleculeBinOrder);
56 		setBounds(kMoleculeBinLeft, kMoleculeBinTop, kMoleculeBinLeft + kMoleculeBinWidth,
57 				kMoleculeBinTop + kMoleculeBinHeight);
58 		startDisplaying();
59 		show();
60 	}
61 }
62 
cleanUpMoleculeBin()63 void MoleculeBin::cleanUpMoleculeBin() {
64 	if (isDisplaying()) {
65 		stopDisplaying();
66 		_binImages.deallocateSurface();
67 	}
68 }
69 
setBinLayout(const uint32 * layout)70 void MoleculeBin::setBinLayout(const uint32 *layout) {
71 	for (int i = 0; i < 6; i++)
72 		_binLayout[i] = layout[i];
73 }
74 
highlightMolecule(const uint32 whichMolecule)75 void MoleculeBin::highlightMolecule(const uint32 whichMolecule) {
76 	if (!_moleculeFlags.getFlag(whichMolecule)) {
77 		_moleculeFlags.setFlag(whichMolecule, true);
78 		triggerRedraw();
79 	}
80 }
81 
isMoleculeHighlighted(uint32 whichMolecule)82 bool MoleculeBin::isMoleculeHighlighted(uint32 whichMolecule) {
83 	return _moleculeFlags.getFlag(whichMolecule);
84 }
85 
selectMolecule(const int whichMolecule)86 void MoleculeBin::selectMolecule(const int whichMolecule) {
87 	if (_selectedMolecule != whichMolecule) {
88 		_selectedMolecule = whichMolecule;
89 		triggerRedraw();
90 	}
91 }
92 
resetBin()93 void MoleculeBin::resetBin() {
94 	_moleculeFlags.clearAllFlags();
95 	_selectedMolecule = -1;
96 	triggerRedraw();
97 }
98 
draw(const Common::Rect &)99 void MoleculeBin::draw(const Common::Rect &) {
100 	Common::Rect r1(0, 0, kMoleculeWidth, kMoleculeHeight);
101 	Common::Rect r2 = r1;
102 
103 	for (int i = 0; i < 6; i++) {
104 		r1.moveTo(i * (kMoleculeWidth * 2), 0);
105 
106 		if (_moleculeFlags.getFlag(_binLayout[i]))
107 			r1.translate(kMoleculeWidth, 0);
108 
109 		r2.moveTo((_binLayout[i] & 1) * (kMoleculeWidth + 2) + _bounds.left + 2,
110 				(_binLayout[i] >> 1) * (kMoleculeHeight + 2) + _bounds.top + 2);
111 
112 		_binImages.copyToCurrentPort(r1, r2);
113 	}
114 
115 	if (_selectedMolecule >= 0) {
116 		r2.moveTo((_selectedMolecule & 1) * (kMoleculeWidth + 2) + _bounds.left + 2,
117 				(_selectedMolecule >> 1) * (kMoleculeHeight + 2) + _bounds.top + 2);
118 
119 		Graphics::Surface *screen = ((PegasusEngine *)g_engine)->_gfx->getWorkArea();
120 
121 		screen->frameRect(r2, _highlightColor);
122 		r2.grow(1);
123 		screen->frameRect(r2, _highlightColor);
124 	}
125 }
126 
127 } // End of namespace Pegasus
128