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 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
|
/* 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/>.
*
*/
#include "watchmaker/2d_stuff.h"
#include "watchmaker/fonts.h"
#include "watchmaker/renderer.h"
namespace Watchmaker {
void TwoDeeStuff::writeBitmapListTo(SDDBitmap* target) {
memcpy(target, DDBitmapsList, sizeof(struct SDDBitmap)*MAX_DD_BITMAPS);
}
void TwoDeeStuff::garbageCollectPreRenderedText() {
// Destroys pre-rendered writings that are no longer needed
SDDText *r, *t;
int32 c, a;
for (c = 0, r = &RendText[0]; c < MAX_REND_TEXTS; c++, r++) {
if (!r->text[0]) continue;
for (a = 0, t = &DDTextsList[0]; a < MAX_DD_TEXTS; a++, t++) {
if (!t->text[0]) continue;
if (!strcmp(t->text, r->text) && (t->color == r->color) && (t->font == r->font))
break;
}
// If it should no longer be displayed
if (a >= MAX_DD_TEXTS) {
rReleaseBitmap(r->tnum);
if (r) r->reset();
}
}
}
void TwoDeeStuff::clearBitmapList() {
int32 a;
SDDBitmap *b;
for (a = 0, b = &DDBitmapsList[0]; a < MAX_DD_BITMAPS; a++, b++) {
b->tnum = b->px = b->py = b->ox = b->oy = b->dx = b->dy = 0;
}
}
void TwoDeeStuff::clearTextList() {
int32 a;
SDDText *t;
for (a = 0, t = &DDTextsList[0]; a < MAX_DD_TEXTS; a++, t++) {
memset(t->text, 0, sizeof(t->text));
t->tnum = 0;
}
}
int32 TwoDeeStuff::findFreeBitmap() {
int32 a = 0;
for (a = 0; a < MAX_DD_BITMAPS; a++)
if (!DDBitmapsList[a].tnum)
return a;
warning("Too many DD Bitmaps!");
return -1;
}
void TwoDeeStuff::displayDDBitmap(int32 tnum, int32 px, int32 py, int32 ox, int32 oy, int32 dx, int32 dy) {
int32 a = findFreeBitmap();
if (a == -1) {
warning("Skipping draw");
return;
}
DDBitmapsList[a].tnum = tnum;
DDBitmapsList[a].px = _renderer->rFitX(px);
DDBitmapsList[a].py = _renderer->rFitY(py);
DDBitmapsList[a].ox = _renderer->rFitX(px + ox) - _renderer->rFitX(px);
DDBitmapsList[a].oy = _renderer->rFitY(py + oy) - _renderer->rFitY(py);
DDBitmapsList[a].dx = _renderer->rFitX(px + dx) - _renderer->rFitX(px);
DDBitmapsList[a].dy = _renderer->rFitY(py + dy) - _renderer->rFitY(py);
if (dx <= 0) DDBitmapsList[a].dx += _renderer->getBitmapDimX(tnum) - DDBitmapsList[a].ox;
if (dy <= 0) DDBitmapsList[a].dy += _renderer->getBitmapDimY(tnum) - DDBitmapsList[a].oy;
}
void TwoDeeStuff::displayDDBitmap_NoFit(int32 tnum, int32 px, int32 py, int32 ox, int32 oy, int32 dx, int32 dy) {
int32 a = findFreeBitmap();
if (a == -1) {
warning("Skipping draw");
return;
}
DDBitmapsList[a].tnum = tnum;
DDBitmapsList[a].px = (px);
DDBitmapsList[a].py = (py);
DDBitmapsList[a].ox = (px + ox) - (px);
DDBitmapsList[a].oy = (py + oy) - (py);
DDBitmapsList[a].dx = (px + dx) - (px);
DDBitmapsList[a].dy = (py + dy) - (py);
if (dx <= 0) DDBitmapsList[a].dx += _renderer->getBitmapDimX(tnum) - DDBitmapsList[a].ox;
if (dy <= 0) DDBitmapsList[a].dy += _renderer->getBitmapDimY(tnum) - DDBitmapsList[a].oy;
}
int32 TwoDeeStuff::rendDDText(char *text, FontKind font, FontColor color) {
struct SDDText *r;
int32 c, tdx, tdy;
char info[100];
if ((!text) || (text[0] == '\0')) return -1;
for (c = 0, r = &RendText[0]; c < MAX_REND_TEXTS; c++, r++) {
if (r->text[0]) continue;
// Get the size of the text to render
_renderer->_fonts->getTextDim(text, font, &tdx, &tdy);
// Create a surface to contain it
r->tnum = rCreateSurface(tdx, tdy, rBITMAPSURFACE);
_renderer->clearBitmap(r->tnum, 0, 0, tdx, tdy, 0, 0, 0);
// Render the lettering on the surface
//DebugLogWindow("Creo testo %s | %d %d",text,tdx,tdy );
_renderer->printText(text, r->tnum, font, color, 0, 0);
Common::strlcpy(info, "text: ", sizeof(info));
strncat(info, text, 15);
//DebugLogWindow("Creato %s",info);
rSetBitmapName(r->tnum, info);
Common::strlcpy(r->text, text, sizeof(r->text));
r->color = color;
r->font = font;
return r->tnum;
}
return -1;
}
void TwoDeeStuff::displayDDText(char *text, FontKind font, FontColor color, int32 px, int32 py, int32 ox, int32 oy, int32 dx, int32 dy) {
struct SDDText *t, *r;
int32 a, c;
if ((!text) || (text[0] == '\0')) return;
for (a = 0; a < MAX_DD_TEXTS; a++)
if (!DDTextsList[a].text[0])
break;
if (a >= MAX_DD_TEXTS) {
warning("Too many DD Texts!");
return ;
}
DDTextsList[a] = SDDText(text, font, color, -1);
t = &DDTextsList[a];
// Try searching the pre-rendered scripts
for (c = 0, r = &RendText[0]; c < MAX_REND_TEXTS; c++, r++) {
if (!r->text[0]) continue;
if (!strcmp(t->text, r->text) && (t->color == r->color) && (t->font == r->font)) {
this->displayDDBitmap(r->tnum, px, py, ox, oy, dx, dy);
break;
}
}
// if I didn't prerender the script, I render it now
if (c >= MAX_REND_TEXTS) {
/* if( ( r->tnum = RendDDText( t->text, t->font, t->color ) ) > 0 )
// Add the bitmap with pre-rendered lettering to display
DisplayDDBitmap( r->tnum, px, py, ox, oy, dx, dy );*/
int32 tn;
if ((tn = rendDDText(t->text, t->font, t->color)) > 0)
// Add the bitmap with pre-rendered lettering to display
this->displayDDBitmap(tn, px, py, ox, oy, dx, dy);
}
}
} // End of namespace Watchmaker
|