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 * Originally written by Syn9 in FreeBASIC with SDL
23 * http://syn9.thehideoutgames.com/index_backup.php
24 *
25 * Ported to plain C for GCW-Zero handheld by Dmitry Smagin
26 * http://github.com/dmitrysmagin/griffon_legend
27 *
28 *
29 * Programming/Graphics: Daniel "Syn9" Kennedy
30 * Music/Sound effects: David Turner
31 *
32 * Beta testing and gameplay design help:
33 * Deleter, Cha0s, Aether Fox, and Kiz
34 *
35 */
36
37 #include "common/system.h"
38
39 #include "griffon/griffon.h"
40
41 namespace Griffon {
42
addFloatIcon(int ico,float xloc,float yloc)43 void GriffonEngine::addFloatIcon(int ico, float xloc, float yloc) {
44 for (int i = 0; i < kMaxFloat; i++) {
45 if (ABS(_floatIcon[i].framesLeft) < kEpsilon) {
46 _floatIcon[i].framesLeft = 32;
47 _floatIcon[i].x = xloc;
48 _floatIcon[i].y = yloc;
49 _floatIcon[i].ico = ico;
50 return;
51 }
52 }
53 }
54
addFloatText(const char * stri,float xloc,float yloc,int col)55 void GriffonEngine::addFloatText(const char *stri, float xloc, float yloc, int col) {
56 for (int i = 0; i < kMaxFloat; i++) {
57 if (ABS(_floatText[i].framesLeft) < kEpsilon) {
58 _floatText[i].framesLeft = 32;
59 _floatText[i].x = xloc;
60 _floatText[i].y = yloc;
61 _floatText[i].col = col;
62 strcpy(_floatText[i].text, stri);
63 return;
64 }
65 }
66 }
67
eventText(const char * stri)68 void GriffonEngine::eventText(const char *stri) {
69 _videoBuffer2->fillRect(Common::Rect(0, 0, _videoBuffer2->w, _videoBuffer2->h), 0);
70 _videoBuffer3->fillRect(Common::Rect(0, 0, _videoBuffer3->w, _videoBuffer3->h), 0);
71
72 int x = 160 - 4 * strlen(stri);
73
74 _ticks = g_system->getMillis();
75 int pause_ticks = _ticks + 500;
76 int b_ticks = _ticks;
77
78 _videoBuffer->blit(*_videoBuffer3);
79 _videoBuffer->blit(*_videoBuffer2);
80
81 do {
82 g_system->getEventManager()->pollEvent(_event);
83
84 if ((_event.type == Common::EVENT_KEYDOWN || _event.type == Common::EVENT_CUSTOM_ENGINE_ACTION_START) && pause_ticks < _ticks)
85 break;
86 _videoBuffer2->blit(*_videoBuffer);
87
88 int fr = 192;
89
90 if (pause_ticks > _ticks)
91 fr = 192 * (_ticks - b_ticks) / 500;
92 if (fr > 192)
93 fr = 192;
94
95 _windowImg->setAlpha(fr, true);
96
97 _windowImg->blit(*_videoBuffer);
98 if (pause_ticks < _ticks)
99 drawString(_videoBuffer, stri, x, 15, 0);
100
101 g_system->copyRectToScreen(_videoBuffer->getPixels(), _videoBuffer->pitch, 0, 0, _videoBuffer->w, _videoBuffer->h);
102 g_system->updateScreen();
103
104 g_system->getEventManager()->pollEvent(_event);
105 g_system->delayMillis(10);
106
107 _ticksPassed = _ticks;
108 _ticks = g_system->getMillis();
109
110 _ticksPassed = _ticks - _ticksPassed;
111 _fpsr = (float)_ticksPassed / 24.0;
112
113 _fp++;
114 if (_ticks > _nextTicks) {
115 _nextTicks = _ticks + 1000;
116 _fps = _fp;
117 _fp = 0;
118 }
119
120 g_system->delayMillis(10);
121 } while (1);
122
123 _videoBuffer3->blit(*_videoBuffer);
124
125 _itemTicks = _ticks + 210;
126 }
127
drawLine(Graphics::TransparentSurface * buffer,int x1,int y1,int x2,int y2,int col)128 void GriffonEngine::drawLine(Graphics::TransparentSurface *buffer, int x1, int y1, int x2, int y2, int col) {
129 int xdif = x2 - x1;
130 int ydif = y2 - y1;
131
132 if (xdif == 0) {
133 for (int y = y1; y <= y2; y++) {
134 uint32 *temp = (uint32 *)buffer->getBasePtr(x1, y);
135 *temp = col;
136 }
137 }
138
139 if (ydif == 0) {
140 for (int x = x1; x <= x2; x++) {
141 uint32 *temp = (uint32 *)buffer->getBasePtr(x, y1);
142 *temp = col;
143 }
144 }
145 }
146
drawString(Graphics::TransparentSurface * buffer,const char * stri,int xloc,int yloc,int col)147 void GriffonEngine::drawString(Graphics::TransparentSurface *buffer, const char *stri, int xloc, int yloc, int col) {
148 int l = strlen(stri);
149
150 for (int i = 0; i < l; i++) {
151 rcDest.left = xloc + i * 8;
152 rcDest.top = yloc;
153
154 _fontChr[stri[i] - 32][col]->blit(*buffer, rcDest.left, rcDest.top);
155 }
156 }
157
drawProgress(int w,int wm)158 void GriffonEngine::drawProgress(int w, int wm) {
159 long ccc = _videoBuffer->format.RGBToColor(0, 255, 0);
160
161 rcDest.setWidth(w * 74 / wm);
162 _videoBuffer->fillRect(rcDest, ccc);
163
164 g_system->copyRectToScreen(_videoBuffer->getPixels(), _videoBuffer->pitch, 0, 0, _videoBuffer->w, _videoBuffer->h);
165 g_system->updateScreen();
166
167 g_system->getEventManager()->pollEvent(_event);
168 }
169
170
171 } // end of namespace Griffon
172