improved the text display in a newgui a bit: make the font proportiona; implemented text alignment (left/right/center); alpha blending now not anymore at 50% but at 66%; moved some #defines to util.h
svn-id: r4972
This commit is contained in:
parent
bb57506d48
commit
f644bea112
4 changed files with 83 additions and 53 deletions
|
@ -22,13 +22,9 @@
|
|||
|
||||
#include "sdl-common.h"
|
||||
#include "common/scaler.h"
|
||||
#include "common/util.h"
|
||||
#include "common/engine.h" // Only #included for error() and warning()
|
||||
|
||||
// FIXME - this macro assumes that we use 565 mode. But what if we are in 555 mode?
|
||||
#define RGB_TO_16(r,g,b) ((((r>>3)&0x1F) << 11) | (((g>>2)&0x3F) << 5) | ((b>>3)&0x1F))
|
||||
//#define RGB_TO_16(r,g,b) ((((r>>3)&0x1F) << 10) | (((g>>3)&0x1F) << 5) | ((b>>3)&0x1F))
|
||||
|
||||
|
||||
class OSystem_SDL_Normal : public OSystem_SDL_Common {
|
||||
public:
|
||||
// Set colors of the palette
|
||||
|
|
|
@ -38,6 +38,20 @@
|
|||
#define SWAP(a,b) do{int tmp=a; a=b; b=tmp; } while(0)
|
||||
#define ARRAYSIZE(x) (sizeof(x)/sizeof(x[0]))
|
||||
|
||||
#if USE_555_FORMAT
|
||||
// Assume the 16 bit graphics data is in 5-5-5 format
|
||||
#define RGB_TO_16(r,g,b) (((((r)>>3)&0x1F) << 10) | ((((g)>>3)&0x1F) << 5) | (((b)>>3)&0x1F))
|
||||
#define RED_FROM_16(x) ((((x)>>10)&0x1F) << 3)
|
||||
#define GREEN_FROM_16(x) ((((x)>>5)&0x1F) << 3)
|
||||
#define BLUE_FROM_16(x) (((x)&0x1F) << 3)
|
||||
|
||||
#else
|
||||
// Assume the 16 bit graphics data is in 5-6-5 format
|
||||
#define RGB_TO_16(r,g,b) (((((r)>>3)&0x1F) << 11) | ((((g)>>2)&0x3F) << 5) | (((b)>>3)&0x1F))
|
||||
#define RED_FROM_16(x) ((((x)>>11)&0x1F) << 3)
|
||||
#define GREEN_FROM_16(x) ((((x)>>5)&0x3F) << 2)
|
||||
#define BLUE_FROM_16(x) (((x)&0x1F) << 3)
|
||||
#endif
|
||||
|
||||
int RGBMatch(byte *palette, int r, int g, int b);
|
||||
int Blend(int src, int dst, byte *palette);
|
||||
|
|
110
gui/newgui.cpp
110
gui/newgui.cpp
|
@ -28,6 +28,7 @@
|
|||
|
||||
/*
|
||||
* TODO list
|
||||
* - use a nice font
|
||||
* - implement the missing / incomplete dialogs
|
||||
* - add more widgets
|
||||
* - allow multi line (l/c/r aligned) text via StaticTextWidget ?
|
||||
|
@ -37,18 +38,6 @@
|
|||
* - ...
|
||||
*/
|
||||
|
||||
// FIXME - this macro assumes that we use 565 mode. But what if we are in 555 mode?
|
||||
#define RGB_TO_16(r,g,b) (((((r)>>3)&0x1F) << 11) | ((((g)>>2)&0x3F) << 5) | (((b)>>3)&0x1F))
|
||||
//#define RGB_TO_16(r,g,b) (((((r)>>3)&0x1F) << 10) | ((((g)>>3)&0x1F) << 5) | (((b)>>3)&0x1F))
|
||||
|
||||
#define RED_FROM_16(x) ((((x)>>11)&0x1F) << 3)
|
||||
#define GREEN_FROM_16(x) ((((x)>>5)&0x3F) << 2)
|
||||
#define BLUE_FROM_16(x) (((x)&0x1F) << 3)
|
||||
|
||||
//#define RED_FROM_16(x) ((((x)>>10)&0x1F) << 3)
|
||||
//#define GREEN_FROM_16(x) ((((x)>>5)&0x1F) << 3)
|
||||
//#define BLUE_FROM_16(x) (((x)&0x1F) << 3)
|
||||
|
||||
|
||||
NewGui::NewGui(Scumm *s) : _s(s), _system(s->_system), _screen(0),
|
||||
_use_alpha_blending(true), _need_redraw(false),_prepare_for_gui(true),
|
||||
|
@ -368,18 +357,18 @@ void NewGui::line(int x, int y, int x2, int y2, int16 color)
|
|||
|
||||
void NewGui::blendRect(int x, int y, int w, int h, int16 color)
|
||||
{
|
||||
int r = RED_FROM_16(color);
|
||||
int g = GREEN_FROM_16(color);
|
||||
int b = BLUE_FROM_16(color);
|
||||
int r = RED_FROM_16(color) * 2;
|
||||
int g = GREEN_FROM_16(color) * 2;
|
||||
int b = BLUE_FROM_16(color) * 2;
|
||||
int16 *ptr = getBasePtr(x, y);
|
||||
if (ptr == NULL)
|
||||
return;
|
||||
|
||||
while (h--) {
|
||||
for (int i = 0; i < w; i++) {
|
||||
ptr[i] = RGB_TO_16((RED_FROM_16(ptr[i])+r)/2,
|
||||
(GREEN_FROM_16(ptr[i])+g)/2,
|
||||
(BLUE_FROM_16(ptr[i])+b)/2);
|
||||
ptr[i] = RGB_TO_16((RED_FROM_16(ptr[i])+r)/3,
|
||||
(GREEN_FROM_16(ptr[i])+g)/3,
|
||||
(BLUE_FROM_16(ptr[i])+b)/3);
|
||||
// ptr[i] = color;
|
||||
}
|
||||
ptr += _screen_pitch;
|
||||
|
@ -474,37 +463,66 @@ void NewGui::drawChar(const char str, int xx, int yy, int16 color)
|
|||
}
|
||||
}
|
||||
|
||||
int NewGui::getStringWidth(const char *str)
|
||||
{
|
||||
int space = 0;
|
||||
while (*str)
|
||||
space += getCharWidth(*str++);
|
||||
return space;
|
||||
}
|
||||
|
||||
int NewGui::getCharWidth(char c)
|
||||
{
|
||||
int space;
|
||||
|
||||
switch (c) {
|
||||
case '.':
|
||||
case ':':
|
||||
case '\'':
|
||||
case '!':
|
||||
space = 3;
|
||||
break;
|
||||
case 'I':
|
||||
case 'i':
|
||||
case 'l':
|
||||
space = 5;
|
||||
break;
|
||||
case ';':
|
||||
case ' ':
|
||||
space = 4;
|
||||
break;
|
||||
case '(':
|
||||
case ')':
|
||||
space = 5;
|
||||
break;
|
||||
case 'c':
|
||||
space = 6;
|
||||
break;
|
||||
case '4':
|
||||
case '/':
|
||||
case 'W':
|
||||
case 'w':
|
||||
case 'M':
|
||||
case 'm':
|
||||
space = 8;
|
||||
break;
|
||||
default:
|
||||
space = 7;
|
||||
}
|
||||
return space;
|
||||
}
|
||||
|
||||
void NewGui::drawString(const char *str, int x, int y, int w, int16 color, int align)
|
||||
{
|
||||
#if 1
|
||||
if (0) {
|
||||
#else
|
||||
if (_s->_gameId) { /* If a game is active.. */
|
||||
StringTab *st = &_s->string[5];
|
||||
st->charset = 1;
|
||||
st->center = (align == kTextAlignCenter);
|
||||
st->color = color;
|
||||
|
||||
if (align == kTextAlignLeft)
|
||||
st->xpos = x;
|
||||
else if (align == kTextAlignCenter)
|
||||
st->xpos = x + w/2;
|
||||
int width = getStringWidth(str);
|
||||
if (align == kTextAlignCenter)
|
||||
x = x + (w - width - 1)/2;
|
||||
else if (align == kTextAlignRight)
|
||||
st->xpos = x + w - _s->charset.getStringWidth(0, (byte *)str, 0);
|
||||
|
||||
st->ypos = y;
|
||||
st->right = x + w;
|
||||
|
||||
_s->_messagePtr = (byte *)str;
|
||||
_s->drawString(5);
|
||||
#endif
|
||||
} else {
|
||||
// FIXME - support center/right align, use nicer custom font.
|
||||
// Ultimately, we might want to *always* draw our messages this way,
|
||||
// but only if we have a nice font.
|
||||
uint len = strlen(str);
|
||||
for (uint letter = 0; letter < len; letter++)
|
||||
drawChar(str[letter], x + (letter * 8), y, color);
|
||||
x = x + w - width;
|
||||
while (*str) {
|
||||
drawChar(*str, x, y, color);
|
||||
x += getCharWidth(*str);
|
||||
str++;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -139,7 +139,9 @@ public:
|
|||
void checkerRect(int x, int y, int w, int h, int16 color);
|
||||
void frameRect(int x, int y, int w, int h, int16 color);
|
||||
void addDirtyRect(int x, int y, int w, int h);
|
||||
void drawChar(const char c, int x, int y, int16 color);
|
||||
void drawChar(char c, int x, int y, int16 color);
|
||||
int getStringWidth(const char *str);
|
||||
int getCharWidth(char c);
|
||||
void drawString(const char *str, int x, int y, int w, int16 color, int align = kTextAlignLeft);
|
||||
|
||||
void drawBitmap(uint32 bitmap[8], int x, int y, int16 color);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue