mirror of
https://github.com/libretro/scummvm.git
synced 2025-01-25 12:05:53 +00:00
419 lines
12 KiB
C++
419 lines
12 KiB
C++
/* 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 2
|
|
* 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
|
|
* aint32 with this program; if not, write to the Free Software
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
*
|
|
*
|
|
* Based on the original sources
|
|
* Faery Tale II -- The Halls of the Dead
|
|
* (c) 1993-1996 The Wyrmkeep Entertainment Co.
|
|
*/
|
|
|
|
#define FORBIDDEN_SYMBOL_ALLOW_ALL // FIXME: Remove
|
|
|
|
#include "saga2/std.h"
|
|
#include "saga2/rmemfta.h"
|
|
#include "saga2/fta.h"
|
|
#include "saga2/mouseimg.h"
|
|
#include "saga2/images.h"
|
|
#include "saga2/panel.h"
|
|
|
|
namespace Saga2 {
|
|
|
|
const int gaugeWidth = 46,
|
|
gaugeImageWidth = gaugeWidth + 2,
|
|
gaugeImageHeight = 5,
|
|
gaugeOneThird = gaugeWidth / 3,
|
|
gaugeTwoThirds = gaugeWidth * 2 / 3;
|
|
|
|
/* ===================================================================== *
|
|
Imports
|
|
* ===================================================================== */
|
|
|
|
extern gFont *mainFont;
|
|
|
|
/* ===================================================================== *
|
|
Globals
|
|
* ===================================================================== */
|
|
|
|
const int maxMouseTextLen = 80;
|
|
|
|
static char mouseText[ maxMouseTextLen ] = { "" }; // Current mouse text string
|
|
|
|
static Point16 mouseImageOffset; // Hotspot on mouse image
|
|
|
|
static gPixelMap *mouseImage = &ArrowImage; // Current mouse cursor image
|
|
|
|
static gStaticImage textImage(0, 0, NULL), // Current mouse text image
|
|
combinedImage(0, 0, NULL); // Combine mouse text
|
|
// and image
|
|
|
|
static int textImageCenteredCol; // The pixel column in the text
|
|
// image to be centered under
|
|
// the mouse pointer
|
|
|
|
static int gaugeNumerator, // Current mouse gauge values
|
|
gaugeDenominator;
|
|
|
|
static uint8 gaugeGrayMap[ 7 ] =
|
|
{ 0x00, 0x18, 0x14, 0x12, 0x16, 0x17, 0x0E }; // Gray
|
|
|
|
static uint8 gaugeColorMapArray[ 3 ][ 7 ] = {
|
|
{ 0x00, 0x18, 0xE2, 0xD1, 0xE5, 0xE7, 0xC9 }, // Green
|
|
{ 0x00, 0x18, 0x5C, 0x5A, 0x5E, 0x60, 0x49 }, // Yellow
|
|
{ 0x00, 0x18, 0x83, 0x81, 0x86, 0x72, 0x39 }, // Red
|
|
};
|
|
|
|
static uint8 gaugeImageData[ gaugeImageWidth * gaugeImageHeight ] = {
|
|
0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, // Row 0
|
|
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
|
|
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
|
|
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00,
|
|
|
|
|
|
0x01, 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, // Row 1
|
|
0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02,
|
|
0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02,
|
|
0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x01,
|
|
|
|
|
|
0x01, 0x04, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, // Row 2
|
|
0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03,
|
|
0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03,
|
|
0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x06, 0x02, 0x01,
|
|
|
|
|
|
0x01, 0x05, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, // Row 3
|
|
0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
|
|
0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
|
|
0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x01,
|
|
|
|
|
|
0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, // Row 4
|
|
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
|
|
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
|
|
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00,
|
|
};
|
|
|
|
static uint8 gaugeImageBuffer[ gaugeImageWidth * gaugeImageHeight ];
|
|
static gStaticImage gaugeImage(
|
|
gaugeImageWidth,
|
|
gaugeImageHeight,
|
|
gaugeImageBuffer);
|
|
|
|
static bool showGauge = FALSE;
|
|
|
|
/* ===================================================================== *
|
|
Functions
|
|
* ===================================================================== */
|
|
|
|
//-----------------------------------------------------------------------
|
|
// Create a new bitmap of several images stacked on top of each other
|
|
|
|
void createStackedImage(
|
|
gPixelMap *newImage,
|
|
int *newImageCenter,
|
|
gPixelMap **imageArray,
|
|
int *imageCenterArray,
|
|
int images) {
|
|
ASSERT(images != 0);
|
|
ASSERT(newImage->data == NULL);
|
|
|
|
int i;
|
|
int newImageBytes,
|
|
newImageRow;
|
|
|
|
newImage->size.x = 0;
|
|
newImage->size.y = 0;
|
|
*newImageCenter = 0;
|
|
|
|
for (i = 0; i < images; i++) {
|
|
if (imageCenterArray[ i ] > *newImageCenter)
|
|
*newImageCenter = imageCenterArray[ i ];
|
|
}
|
|
|
|
for (i = 0; i < images; i++) {
|
|
int16 rightImageBoundary;
|
|
|
|
newImage->size.y += imageArray[ i ]->size.y;
|
|
|
|
rightImageBoundary = *newImageCenter
|
|
+ (imageArray[ i ]->size.x
|
|
- imageCenterArray[ i ]);
|
|
if (rightImageBoundary > newImage->size.x)
|
|
newImage->size.x = rightImageBoundary;
|
|
}
|
|
|
|
newImage->size.y += images - 1;
|
|
newImageBytes = newImage->bytes();
|
|
|
|
newImage->data = (uint8 *) TALLOC(newImageBytes, memPrgOutput) ;
|
|
|
|
memset(newImage->data, 0, newImageBytes);
|
|
|
|
newImageRow = 0;
|
|
for (i = 0; i < images; i++) {
|
|
gPixelMap *currentImage = imageArray[ i ];
|
|
|
|
TBlit(
|
|
newImage,
|
|
currentImage,
|
|
*newImageCenter - imageCenterArray[ i ],
|
|
newImageRow);
|
|
|
|
newImageRow += currentImage->size.y + 1;
|
|
}
|
|
}
|
|
|
|
//-----------------------------------------------------------------------
|
|
// Dispose of an image created with createStackedImage
|
|
|
|
inline void disposeStackedImage(gPixelMap *image) {
|
|
ASSERT(image->data != NULL);
|
|
|
|
delete [] image->data;
|
|
image->data = NULL;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------
|
|
// Combine the mouse image and the mouse text image into a single
|
|
// pixel map and reset the global mouse cursor to use the new combined
|
|
// image.
|
|
|
|
void cleanupMousePointer(void) {
|
|
if (combinedImage.data != NULL) disposeStackedImage(&combinedImage);
|
|
}
|
|
|
|
void setupMousePointer(void) {
|
|
int imageIndex = 1;
|
|
gPixelMap *imageArray[ 3 ];
|
|
int imageCenterArray[ 3 ];
|
|
Point16 imageOffset; // mouse image offset
|
|
int combinedImageCenter;
|
|
|
|
imageArray[ 0 ] = mouseImage;
|
|
imageCenterArray[ 0 ] = mouseImage->size.x / 2;
|
|
if (mouseText[ 0 ] != '\0') {
|
|
imageArray[ imageIndex ] = &textImage;
|
|
imageCenterArray[ imageIndex ] = textImageCenteredCol;
|
|
imageIndex++;
|
|
}
|
|
if (showGauge) {
|
|
imageArray[ imageIndex ] = &gaugeImage;
|
|
imageCenterArray[ imageIndex ] = gaugeImage.size.x / 2;
|
|
imageIndex++;
|
|
}
|
|
|
|
if (combinedImage.data != NULL)
|
|
disposeStackedImage(&combinedImage);
|
|
|
|
createStackedImage(
|
|
&combinedImage,
|
|
&combinedImageCenter,
|
|
imageArray,
|
|
imageCenterArray,
|
|
imageIndex);
|
|
|
|
imageOffset.x = combinedImageCenter - mouseImage->size.x / 2;
|
|
imageOffset.y = 0;
|
|
|
|
// Set the combined image as the new mouse cursor
|
|
pointer.hide();
|
|
pointer.setImage(
|
|
combinedImage,
|
|
mouseImageOffset.x - imageOffset.x,
|
|
mouseImageOffset.y - imageOffset.y);
|
|
pointer.show();
|
|
}
|
|
|
|
//-----------------------------------------------------------------------
|
|
// Setup a new mouse cursor image
|
|
|
|
void setMouseImage(gPixelMap &img, int16 x, int16 y) {
|
|
if (mouseImage != &img
|
|
|| mouseImageOffset.x != x
|
|
|| mouseImageOffset.y != y) {
|
|
mouseImage = &img;
|
|
mouseImageOffset.x = x;
|
|
mouseImageOffset.y = y;
|
|
|
|
setupMousePointer();
|
|
}
|
|
}
|
|
|
|
//-----------------------------------------------------------------------
|
|
// Dispose of old text
|
|
|
|
inline void disposeText(void) {
|
|
mouseText[ 0 ] = '\0';
|
|
|
|
// Free the memory previously allocated to hold the text image
|
|
// bitmap
|
|
if (textImage.data != NULL) {
|
|
delete [] textImage.data;
|
|
textImage.data = NULL;
|
|
}
|
|
textImage.size.x = textImage.size.y = 0;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------
|
|
// Build a new text image
|
|
|
|
void setNewText(char *text) {
|
|
Point16 mousePos;
|
|
int16 textImageBytes; // Bytes needed to hold the text image bitmap
|
|
int mouseImageCenter;
|
|
|
|
// Dispose of old text image
|
|
disposeText();
|
|
|
|
strncpy(mouseText, text, maxMouseTextLen - 1);
|
|
mouseText[ maxMouseTextLen - 1 ] = NULL;
|
|
|
|
// Compute the size of the text bitmap
|
|
textImage.size.y = mainFont->height + 2;
|
|
textImage.size.x = TextWidth(mainFont, text, -1, 0) + 2;
|
|
|
|
// Allocate a new buffer for the text image bitmap
|
|
textImageBytes = textImage.bytes();
|
|
textImage.data = (uint8 *) TALLOC(textImageBytes, memPrgOutput);
|
|
memset(textImage.data, 0, textImageBytes);
|
|
|
|
gPort textImagePort; // gPort used to draw text onto bitmap
|
|
|
|
// Intialize the text image port
|
|
textImagePort.setMap(&textImage);
|
|
textImagePort.setMode(drawModeReplace);
|
|
textImagePort.setColor(11);
|
|
textImagePort.setOutlineColor(24);
|
|
textImagePort.setFont(mainFont);
|
|
textImagePort.setStyle(textStyleOutline);
|
|
textImagePort.moveTo(1, 1);
|
|
|
|
// Draw the text
|
|
textImagePort.drawText(text, -1);
|
|
|
|
// Compute relative position of text
|
|
pointer.getImageCurPos(mousePos);
|
|
mouseImageCenter = mousePos.x + mouseImageOffset.x + mouseImage->size.x / 2;
|
|
textImageCenteredCol = textImage.size.x / 2;
|
|
if (mouseImageCenter - textImageCenteredCol < 5) {
|
|
textImageCenteredCol = mouseImageCenter - 5;
|
|
} else if (mouseImageCenter
|
|
+ (textImage.size.x - textImageCenteredCol)
|
|
>= screenWidth - 5) {
|
|
textImageCenteredCol = textImage.size.x
|
|
- ((screenWidth - 5) - mouseImageCenter);
|
|
}
|
|
}
|
|
|
|
//-----------------------------------------------------------------------
|
|
// Setup a new text string to display on the mouse cursor
|
|
|
|
void setMouseText(char *text) {
|
|
if (text != NULL) {
|
|
if (strcmp(text, mouseText) == 0) return;
|
|
|
|
setNewText(text);
|
|
setupMousePointer();
|
|
} else if (mouseText[ 0 ] != NULL) {
|
|
disposeText();
|
|
setupMousePointer();
|
|
}
|
|
}
|
|
|
|
// Formatted version of setMouseText, for gTools use...
|
|
|
|
void setMouseTextF(char *format, ...) {
|
|
extern gToolBase G_BASE;
|
|
|
|
if (format == NULL) {
|
|
setMouseText(NULL);
|
|
G_BASE.mouseHintSet = TRUE;
|
|
} else {
|
|
char lineBuf[ 128 ];
|
|
va_list argptr;
|
|
|
|
va_start(argptr, format);
|
|
vsprintf(lineBuf, format, argptr);
|
|
va_end(argptr);
|
|
|
|
setMouseText(lineBuf);
|
|
G_BASE.mouseHintSet = TRUE;
|
|
}
|
|
}
|
|
|
|
//-----------------------------------------------------------------------
|
|
// Set the gauge value for the mouse pointer (automatically turns
|
|
// gauge on if necessary ).
|
|
|
|
void setMouseGauge(int numerator, int denominator) {
|
|
ASSERT(denominator != 0);
|
|
ASSERT(numerator <= denominator);
|
|
|
|
if (showGauge
|
|
&& numerator == gaugeNumerator
|
|
&& denominator == gaugeDenominator)
|
|
return;
|
|
|
|
int gaugePos,
|
|
x, y,
|
|
gaugeImageIndex = 0;
|
|
uint8 *gaugeColorMap;
|
|
|
|
gaugeNumerator = numerator;
|
|
gaugeDenominator = denominator;
|
|
|
|
gaugePos = (numerator * gaugeWidth + denominator - 1) / denominator;
|
|
|
|
if (gaugePos <= gaugeOneThird)
|
|
gaugeColorMap = gaugeColorMapArray[ 2 ];
|
|
else if (gaugePos <= gaugeTwoThirds)
|
|
gaugeColorMap = gaugeColorMapArray[ 1 ];
|
|
else
|
|
gaugeColorMap = gaugeColorMapArray[ 0 ];
|
|
|
|
for (y = 0; y < gaugeImageHeight; y++) {
|
|
for (x = 0; x < gaugeImageWidth; x++) {
|
|
uint8 *gaugeMap;
|
|
|
|
gaugeMap = x < gaugePos + 1 ? gaugeColorMap : gaugeGrayMap;
|
|
|
|
gaugeImageBuffer[ gaugeImageIndex ] =
|
|
gaugeMap[ gaugeImageData[ gaugeImageIndex ] ];
|
|
|
|
gaugeImageIndex++;
|
|
}
|
|
}
|
|
|
|
showGauge = TRUE;
|
|
|
|
setupMousePointer();
|
|
}
|
|
|
|
//-----------------------------------------------------------------------
|
|
// Turn off the gauge on the mouse pointer
|
|
|
|
void clearMouseGauge(void) {
|
|
showGauge = FALSE;
|
|
|
|
setupMousePointer();
|
|
}
|
|
|
|
} // end of namespace Saga2
|