Added ScummVM font handling code. The font is now proportional,

which means more text can fit onscreen.


git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@381 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
stephena 2005-03-13 03:38:41 +00:00
parent b0ec277a94
commit 24a81a0d11
14 changed files with 3038 additions and 300 deletions

View File

@ -13,7 +13,7 @@
## See the file "license" for information on usage and redistribution of
## this file, and for a DISCLAIMER OF ALL WARRANTIES.
##
## $Id: makefile,v 1.64 2005-03-12 01:47:14 stephena Exp $
## $Id: makefile,v 1.65 2005-03-13 03:38:39 stephena Exp $
##============================================================================
##============================================================================
@ -153,7 +153,7 @@ CORE_OBJS = Booster.o Cart.o Cart2K.o Cart3F.o Cart4K.o CartAR.o CartDPC.o \
Event.o Joystick.o Keyboard.o M6532.o MD5.o MediaSrc.o Paddles.o \
Props.o PropsSet.o Random.o Sound.o Switches.o Settings.o TIA.o \
Serializer.o Deserializer.o TIASound.o EventHandler.o FrameBuffer.o \
OSystem.o Menu.o Widget.o Dialog.o OptionsDialog.o\
OSystem.o StellaFont.o Menu.o Widget.o Dialog.o OptionsDialog.o\
$(M6502_OBJS)
stella: $(CORE_OBJS) $(OBJS)
@ -352,6 +352,9 @@ NullDev.o: $(CORE)/m6502/src/NullDev.cxx $(CORE)/m6502/src/NullDev.hxx
System.o: $(CORE)/m6502/src/System.cxx $(CORE)/m6502/src/System.hxx
$(CXX) -c $(FLAGS) $(OPTIONS) $(CORE)/m6502/src/System.cxx
StellaFont.o: $(GUI)/StellaFont.cxx $(GUI)/StellaFont.hxx
$(CXX) -c $(FLAGS) $(OPTIONS) $(LDFLAGS) $(GUI)/StellaFont.cxx
Menu.o: $(GUI)/Menu.cxx $(GUI)/Menu.hxx
$(CXX) -c $(FLAGS) $(OPTIONS) $(LDFLAGS) $(GUI)/Menu.cxx

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: FrameBufferSoft.cxx,v 1.10 2005-03-12 01:47:14 stephena Exp $
// $Id: FrameBufferSoft.cxx,v 1.11 2005-03-13 03:38:39 stephena Exp $
//============================================================================
#include <SDL.h>
@ -26,6 +26,8 @@
#include "MediaSrc.hxx"
#include "Settings.hxx"
#include "OSystem.hxx"
#include "StellaFont.hxx"
#include "GuiUtils.hxx"
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
FrameBufferSoft::FrameBufferSoft(OSystem* osystem)
@ -71,6 +73,11 @@ bool FrameBufferSoft::initSubsystem()
if(myOSystem->settings().getBool("showinfo"))
cout << "Video rendering: Software mode" << endl << endl;
// Precompute the GUI palette
// We abuse the concept of 'enum' by referring directly to the integer values
for(uInt8 i = 0; i < 5; i++)
myGUIPalette[i] = mapRGB(myGUIColors[i][0], myGUIColors[i][1], myGUIColors[i][2]);
return true;
}
@ -253,51 +260,7 @@ void FrameBufferSoft::drawMediaSource()
theRedrawEntireFrameIndicator = false;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void FrameBufferSoft::drawBoundedBox(uInt32 x, uInt32 y, uInt32 w, uInt32 h)
{
SDL_Rect tmp;
// Scale all values to the current window size
x *= theZoomLevel;
y *= theZoomLevel;
w *= theZoomLevel;
h *= theZoomLevel;
// First draw the underlying box
tmp.x = x;
tmp.y = y;
tmp.w = w;
tmp.h = h;
myRectList->add(&tmp);
SDL_FillRect(myScreen, &tmp, myPalette[myBGColor]);
// Now draw the bounding sides
tmp.x = x;
tmp.y = y;
tmp.w = w;
tmp.h = theZoomLevel;
SDL_FillRect(myScreen, &tmp, myPalette[myFGColor]); // top
tmp.x = x;
tmp.y = y + h - theZoomLevel;
tmp.w = w;
tmp.h = theZoomLevel;
SDL_FillRect(myScreen, &tmp, myPalette[myFGColor]); // bottom
tmp.x = x;
tmp.y = y;
tmp.w = theZoomLevel;
tmp.h = h;
SDL_FillRect(myScreen, &tmp, myPalette[myFGColor]); // left
tmp.x = x + w - theZoomLevel;
tmp.y = y;
tmp.w = theZoomLevel;
tmp.h = h;
SDL_FillRect(myScreen, &tmp, myPalette[myFGColor]); // right
}
/*
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void FrameBufferSoft::drawText(uInt32 xorig, uInt32 yorig, const string& message)
{
@ -316,7 +279,7 @@ void FrameBufferSoft::drawText(uInt32 xorig, uInt32 yorig, const string& message
tmp.x = ((x<<3) + z + xorig) * theZoomLevel;
tmp.y = (y + yorig) * theZoomLevel;
tmp.w = tmp.h = theZoomLevel;
SDL_FillRect(myScreen, &tmp, myPalette[myFGColor]);
SDL_FillRect(myScreen, &tmp, myPalette[10]);
}
}
}
@ -340,11 +303,12 @@ void FrameBufferSoft::drawChar(uInt32 xorig, uInt32 yorig, uInt32 c)
tmp.x = (z + xorig) * theZoomLevel;
tmp.y = (y + yorig) * theZoomLevel;
tmp.w = tmp.h = theZoomLevel;
SDL_FillRect(myScreen, &tmp, myPalette[myFGColor]);
SDL_FillRect(myScreen, &tmp, myPalette[10]);
}
}
}
}
*/
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void FrameBufferSoft::preFrameUpdate()
@ -420,7 +384,7 @@ void FrameBufferSoft::hLine(uInt32 x, uInt32 y, uInt32 x2, OverlayColor color)
tmp.y = y * theZoomLevel;
tmp.w = (x2 - x + 1) * theZoomLevel;
tmp.h = theZoomLevel;
SDL_FillRect(myScreen, &tmp, myPalette[myFGColor]); // top
SDL_FillRect(myScreen, &tmp, myGUIPalette[color]);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -433,7 +397,7 @@ void FrameBufferSoft::vLine(uInt32 x, uInt32 y, uInt32 y2, OverlayColor color)
tmp.y = y * theZoomLevel;
tmp.w = theZoomLevel;
tmp.h = (y2 - y + 1) * theZoomLevel;
SDL_FillRect(myScreen, &tmp, myPalette[myFGColor]); // left
SDL_FillRect(myScreen, &tmp, myGUIPalette[color]);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -449,7 +413,7 @@ void FrameBufferSoft::blendRect(int x, int y, int w, int h,
tmp.w = w * theZoomLevel;
tmp.h = h * theZoomLevel;
myRectList->add(&tmp);
SDL_FillRect(myScreen, &tmp, myPalette[myBGColor]);
SDL_FillRect(myScreen, &tmp, myGUIPalette[color]);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -464,7 +428,7 @@ void FrameBufferSoft::fillRect(uInt32 x, uInt32 y, uInt32 w, uInt32 h,
tmp.w = w * theZoomLevel;
tmp.h = h * theZoomLevel;
myRectList->add(&tmp);
SDL_FillRect(myScreen, &tmp, myPalette[myBGColor]);
SDL_FillRect(myScreen, &tmp, myGUIPalette[color]);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -475,12 +439,45 @@ void FrameBufferSoft::frameRect(uInt32 x, uInt32 y, uInt32 w, uInt32 h,
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void FrameBufferSoft::drawString(const string& str, Int32 x, Int32 y, Int32 w,
OverlayColor color, TextAlignment align,
Int32 deltax, bool useEllipsis)
void FrameBufferSoft::drawChar(uInt8 chr, uInt32 xorig, uInt32 yorig,
OverlayColor color)
{
// FIXME - implement this correctly
drawText(x, y, str);
// If this character is not included in the font, use the default char.
if(chr < myFont->desc().firstchar ||
chr >= myFont->desc().firstchar + myFont->desc().size)
{
if (chr == ' ')
return;
chr = myFont->desc().defaultchar;
}
const Int32 w = myFont->getCharWidth(chr);
const Int32 h = myFont->getFontHeight();
chr -= myFont->desc().firstchar;
const uInt16* tmp = myFont->desc().bits + (myFont->desc().offset ?
myFont->desc().offset[chr] : (chr * h));
SDL_Rect rect;
for(int y = 0; y < h; y++)
{
const uInt16 buffer = *tmp++;
uInt16 mask = 0x8000;
// if(ty + y < 0 || ty + y >= dst->h)
// continue;
for(int x = 0; x < w; x++, mask >>= 1)
{
// if (tx + x < 0 || tx + x >= dst->w)
// continue;
if ((buffer & mask) != 0)
{
rect.x = (x + xorig) * theZoomLevel;
rect.y = (y + yorig) * theZoomLevel;
rect.w = rect.h = theZoomLevel;
SDL_FillRect(myScreen, &rect, myGUIPalette[color]);
}
}
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: FrameBufferSoft.hxx,v 1.8 2005-03-12 01:47:15 stephena Exp $
// $Id: FrameBufferSoft.hxx,v 1.9 2005-03-13 03:38:39 stephena Exp $
//============================================================================
#ifndef FRAMEBUFFER_SOFT_HXX
@ -34,7 +34,7 @@ class RectList;
This class implements an SDL software framebuffer.
@author Stephen Anthony
@version $Id: FrameBufferSoft.hxx,v 1.8 2005-03-12 01:47:15 stephena Exp $
@version $Id: FrameBufferSoft.hxx,v 1.9 2005-03-13 03:38:39 stephena Exp $
*/
class FrameBufferSoft : public FrameBuffer
{
@ -162,53 +162,21 @@ class FrameBufferSoft : public FrameBuffer
OverlayColor color);
/**
This routine is called to draw the specified string.
This routine is called to draw the specified character.
@param c The character to draw
@param x The x coordinate
@param y The y coordinate
@param w The width of the area
@param h The height of the area
@param color The color of the surrounding frame
@param color The color of the character
*/
virtual void drawString(const string& str, Int32 x, Int32 y, Int32 w,
OverlayColor color, TextAlignment align = kTextAlignLeft,
Int32 deltax = 0, bool useEllipsis = true);
/**
This routine should be called to draw a rectangular box with sides
at the specified coordinates.
@param x The x coordinate
@param y The y coordinate
@param w The width of the box
@param h The height of the box
*/
virtual void drawBoundedBox(uInt32 x, uInt32 y, uInt32 w, uInt32 h);
/**
This routine should be called to draw text at the specified coordinates.
@param x The x coordinate
@param y The y coordinate
@param message The message text
*/
virtual void drawText(uInt32 x, uInt32 y, const string& message);
/**
This routine should be called to draw character 'c' at the specified coordinates.
@param x The x coordinate
@param y The y coordinate
@param c The character to draw
*/
virtual void drawChar(uInt32 x, uInt32 y, uInt32 c);
virtual void drawChar(uInt8 c, uInt32 x, uInt32 y, OverlayColor color);
private:
// Used in the dirty update of the SDL surface
RectList* myRectList;
// GUI palette
Uint32 myGUIPalette[5];
};
class RectList

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: FrameBuffer.cxx,v 1.19 2005-03-11 23:36:30 stephena Exp $
// $Id: FrameBuffer.cxx,v 1.20 2005-03-13 03:38:40 stephena Exp $
//============================================================================
#include <sstream>
@ -26,6 +26,9 @@
#include "Settings.hxx"
#include "MediaSrc.hxx"
#include "FrameBuffer.hxx"
#include "FontData.hxx"
#include "StellaFont.hxx"
#include "GuiUtils.hxx"
#include "Menu.hxx"
#include "OSystem.hxx"
@ -53,8 +56,6 @@ FrameBuffer::FrameBuffer(OSystem* osystem)
myWidth(0),
myHeight(0),
theRedrawEntireFrameIndicator(true),
myFGColor(10),
myBGColor(0),
myWMAvailable(false),
theZoomLevel(1),
@ -63,32 +64,50 @@ FrameBuffer::FrameBuffer(OSystem* osystem)
myFrameRate(0),
myPauseStatus(false),
myCurrentWidget(W_NONE),
myRemapEventSelectedFlag(false),
mySelectedEvent(Event::NoType),
myMenuMode(false),
theMenuChangedIndicator(false),
myMaxRows(0),
myMaxColumns(0),
myMainMenuIndex(0),
myMainMenuItems(sizeof(ourMainMenu)/sizeof(MainMenuItem)),
myRemapMenuIndex(0),
myRemapMenuLowIndex(0),
myRemapMenuHighIndex(0),
myRemapMenuItems(sizeof(ourRemapMenu)/sizeof(RemapMenuItem)),
myRemapMenuMaxLines(0),
myMessageTime(0),
myMessageText(""),
myMenuRedraws(2),
myInfoMenuWidth(0)
myMenuRedraws(2)
{
// Add the framebuffer to the system
myOSystem->attach(this);
// Fill the GUI colors array
// The specific video subsystem will know what to do with it
uInt8 colors[5][3] = {
{104, 104, 104},
{0, 0, 0},
{64, 64, 64},
{32, 160, 32},
{0, 255, 0}
};
for(uInt8 i = 0; i < 5; i++)
for(uInt8 j = 0; j < 3; j++)
myGUIColors[i][j] = colors[i][j];
// Create a font to draw text
const FontDesc desc = {
"04b-16b-10",
9,
10,
8,
33,
94,
_font_bits,
0, /* no encode table*/
_sysfont_width,
33,
sizeof(_font_bits)/sizeof(uInt16)
};
myFont = new StellaFont(this, desc);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
FrameBuffer::~FrameBuffer(void)
{
if(myFont)
delete myFont;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -212,14 +231,15 @@ void FrameBuffer::update()
// Draw any pending messages
if(myMessageTime > 0)
{
uInt32 width = myMessageText.length()*FONTWIDTH + FONTWIDTH;
uInt32 height = LINEOFFSET + FONTHEIGHT;
uInt32 x = (myWidth >> 1) - (width >> 1);
uInt32 y = myHeight - height - LINEOFFSET/2;
uInt32 w = myFont->getStringWidth(myMessageText) + 10;
uInt32 h = myFont->getFontHeight() + 5;
uInt32 x = (myWidth >> 1) - (w >> 1);
uInt32 y = myHeight - h - LINEOFFSET/2;
// Draw the bounded box and text
box(x, y+1, width, height-2, 0, 0); // FIXME
drawText(x + XBOXOFFSET/2, LINEOFFSET/2 + y, myMessageText);
fillRect(x+1, y+2, w-2, h-4, kBGColor); // FIXME - possibly change this to blended rect
box(x, y+1, w, h-2, kColor, kColor);
myFont->drawString(myMessageText, x, y, w, kTextColor, kTextAlignCenter);
myMessageTime--;
// Erase this message on next update
@ -230,7 +250,7 @@ void FrameBuffer::update()
break; // S_EMULATE
}
case EventHandler::S_MENU: // FIXME - this whole thing will disappear into the gui().menu class
case EventHandler::S_MENU:
{
// Only update the screen if it's been invalidated or the menus have changed
if(theMenuChangedIndicator || theRedrawEntireFrameIndicator)
@ -240,24 +260,6 @@ void FrameBuffer::update()
// Then overlay any menu items
myOSystem->menu().draw();
/*
switch(myCurrentWidget)
{
case W_NONE:
break;
case MAIN_MENU:
drawMainMenu();
break;
case REMAP_MENU:
drawRemapMenu();
break;
case INFO_MENU:
drawInfoMenu();
break;
default:
break;
}
*/
// Now the screen is up to date
theRedrawEntireFrameIndicator = false;
@ -289,6 +291,15 @@ void FrameBuffer::update()
postFrameUpdate();
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void FrameBuffer::showMessage(const string& message)
{
myMessageText = message;
myMessageTime = myFrameRate << 1; // Show message for 2 seconds
theRedrawEntireFrameIndicator = true;
}
/*
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void FrameBuffer::showMenu(bool show)
{
@ -300,14 +311,6 @@ void FrameBuffer::showMenu(bool show)
theRedrawEntireFrameIndicator = true;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void FrameBuffer::showMessage(const string& message)
{
myMessageText = message;
myMessageTime = myFrameRate << 1; // Show message for 2 seconds
theRedrawEntireFrameIndicator = true;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
inline void FrameBuffer::drawMainMenu()
{
@ -320,7 +323,7 @@ inline void FrameBuffer::drawMainMenu()
// Draw the bounded box and text, leaving a little room for arrows
xpos = x + XBOXOFFSET;
box(x-2, y-2, width+3, height+3, 0, 0); //FIXME
box(x-2, y-2, width+3, height+3, kColor, kBGColor); //FIXME
for(i = 0; i < myMainMenuItems; i++)
drawText(xpos, LINEOFFSET*i + y + YBOXOFFSET, ourMainMenu[i].action);
@ -341,7 +344,7 @@ inline void FrameBuffer::drawRemapMenu()
y = (myHeight >> 1) - (height >> 1);
// Draw the bounded box and text, leaving a little room for arrows
box(x-2, y-2, width+3, height+3, 0, 0); //FIXME
box(x-2, y-2, width+3, height+3, kColor, kBGColor); //FIXME
for(Int32 i = myRemapMenuLowIndex; i < myRemapMenuHighIndex; i++)
{
ypos = LINEOFFSET*(i-myRemapMenuLowIndex) + y + YBOXOFFSET;
@ -392,7 +395,7 @@ inline void FrameBuffer::drawInfoMenu()
// Draw the bounded box and text
xpos = x + XBOXOFFSET;
box(x, y, width, height, 0, 0); //FIXME
box(x, y, width, height, kColor, kBGColor); //FIXME
for(i = 0; i < 9; i++)
drawText(xpos, LINEOFFSET*i + y + YBOXOFFSET, ourPropertiesInfo[i]);
}
@ -515,6 +518,7 @@ void FrameBuffer::sendJoyEvent(StellaEvent::JoyStick stick,
break;
}
}
*/
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void FrameBuffer::pause(bool status)
@ -526,6 +530,7 @@ void FrameBuffer::pause(bool status)
//FIXME pauseEvent(myPauseStatus);
}
/*
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
FrameBuffer::Widget FrameBuffer::currentSelectedWidget()
{
@ -826,7 +831,9 @@ FrameBuffer::RemapMenuItem FrameBuffer::ourRemapMenu[57] = {
{ Event::KeyboardOne0, "Right-Pad 0", "" },
{ Event::KeyboardOnePound, "Right-Pad #", "" }
};
*/
#if 0
/**
This array must be initialized in a specific order, matching
their initialization in StellaEvent::KeyCode.
@ -858,6 +865,7 @@ const char* FrameBuffer::ourEventName[StellaEvent::LastKCODE] = {
"F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10",
"F11", "F12", "F13", "F14", "F15",
};
#endif
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void FrameBuffer::setupPalette()

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: FrameBuffer.hxx,v 1.19 2005-03-12 01:47:15 stephena Exp $
// $Id: FrameBuffer.hxx,v 1.20 2005-03-13 03:38:40 stephena Exp $
//============================================================================
#ifndef FRAMEBUFFER_HXX
@ -25,20 +25,14 @@
#include "bspf.hxx"
#include "Event.hxx"
#include "MediaSrc.hxx"
#include "StellaFont.hxx"
#include "StellaEvent.hxx"
#include "GuiUtils.hxx"
class StellaFont;
class Console;
class OSystem;
typedef uInt32 OverlayColor;
// Text alignment modes for drawString()
enum TextAlignment {
kTextAlignLeft,
kTextAlignCenter,
kTextAlignRight
};
/**
This class encapsulates the MediaSource and is the basis for the video
display in Stella. All graphics ports should derive from this class for
@ -47,7 +41,7 @@ enum TextAlignment {
All GUI elements (ala ScummVM) are drawn here as well.
@author Stephen Anthony
@version $Id: FrameBuffer.hxx,v 1.19 2005-03-12 01:47:15 stephena Exp $
@version $Id: FrameBuffer.hxx,v 1.20 2005-03-13 03:38:40 stephena Exp $
*/
class FrameBuffer
{
@ -62,6 +56,13 @@ class FrameBuffer
*/
virtual ~FrameBuffer();
/**
Get the font object of the framebuffer
@return The font reference
*/
StellaFont& font() const { return *myFont; }
/**
(Re)initializes the framebuffer display. This must be called before any
calls are made to derived methods.
@ -78,14 +79,6 @@ class FrameBuffer
*/
void update();
/**
Shows the main menu onscreen. This will only be called if event
remapping has been enabled in the event handler.
@param show Show/hide the menu based on the boolean value
*/
void showMenu(bool show);
/**
Shows a message onscreen.
@ -132,24 +125,6 @@ FIXME
*/
uInt32 screenHeight();
/**
Send a keyboard event to the user interface.
@param code The StellaEvent code
@param state The StellaEvent state
*/
void sendKeyEvent(StellaEvent::KeyCode code, Int32 state);
/**
Send a joystick button event to the user interface.
@param stick The joystick activated
@param code The StellaEvent joystick code
@param state The StellaEvent state
*/
void sendJoyEvent(StellaEvent::JoyStick stick, StellaEvent::JoyCode code,
Int32 state);
/**
Sets the pause status. While pause is selected, the
MediaSource will not be updated.
@ -224,14 +199,6 @@ FIXME
*/
void setupPalette();
/**
Colors to use for the various GUI elements
*/
OverlayColor color, shadowcolor;
OverlayColor bgcolor;
OverlayColor textcolor;
OverlayColor textcolorhi;
/**
This routine should be called to draw a rectangular box with sides
at the specified coordinates.
@ -364,48 +331,19 @@ FIXME
OverlayColor color) = 0;
/**
This routine should be called to draw the specified string.
This routine should be called to draw the specified character.
@param c The character to draw
@param x The x coordinate
@param y The y coordinate
@param w The width of the area
@param h The height of the area
@param color The color of the surrounding frame
@param color The color of the character
*/
virtual void drawString(const string& str, Int32 x, Int32 y, Int32 w,
OverlayColor color, TextAlignment align = kTextAlignLeft,
Int32 deltax = 0, bool useEllipsis = true) = 0;
virtual void drawChar(uInt8 c, uInt32 x, uInt32 y, OverlayColor color) = 0;
/* FIXME
void drawChar(byte c, int x, int y, OverlayColor color, const Graphics::Font *font = 0);
int getStringWidth(const String &str);
int getCharWidth(byte c);
void drawBitmap(uint32 *bitmap, int x, int y, OverlayColor color, int h = 8);
*/
/**
This routine should be called to draw text at the specified coordinates.
@param x The x coordinate
@param y The y coordinate
@param message The message text
*/
virtual void drawText(uInt32 x, uInt32 y, const string& message) = 0;
/**
This routine should be called to draw character 'c' at the specified coordinates.
@param x The x coordinate
@param y The y coordinate
@param c The character to draw
*/
virtual void drawChar(uInt32 x, uInt32 y, uInt32 c) = 0;
#if 0
FIXME
/**
@ -428,12 +366,6 @@ FIXME
// Indicates if the entire frame should be redrawn
bool theRedrawEntireFrameIndicator;
// Table of bitmapped fonts.
static const uInt8 ourFontData[2048];
// Holds the foreground and background color table indices
uInt8 myFGColor, myBGColor;
// The SDL video buffer
SDL_Surface* myScreen;
@ -443,6 +375,9 @@ FIXME
// SDL palette
Uint32 myPalette[256];
// Holds the palette for GUI elements
uInt8 myGUIColors[5][3];
// Used to get window-manager specifics
SDL_SysWMinfo myWMInfo;
@ -462,12 +397,16 @@ FIXME
// The aspect ratio of the window
float theAspectRatio;
// The font object to use
StellaFont* myFont;
private:
/**
Set the icon for the main SDL window.
*/
void setWindowIcon();
/*
// Enumeration representing the different types of user interface widgets
enum Widget { W_NONE, MAIN_MENU, REMAP_MENU, INFO_MENU };
@ -501,7 +440,7 @@ FIXME
// scan the mapping arrays and update the remap menu
void loadRemapMenu();
*/
private:
// Indicates the current framerate of the system
uInt32 myFrameRate;
@ -509,6 +448,19 @@ FIXME
// Indicates the current pause status
bool myPauseStatus;
// Indicates if the menus should be redrawn
bool theMenuChangedIndicator;
// Message timer
Int32 myMessageTime;
// Message text
string myMessageText;
// Number of times menu have been drawn
uInt32 myMenuRedraws;
/*
// Structure used for main menu items
struct MainMenuItem
{
@ -539,9 +491,6 @@ FIXME
// Indicates if we are in menu mode
bool myMenuMode;
// Indicates if the menus should be redrawn
bool theMenuChangedIndicator;
// The maximum number of vertical lines of text that can be onscreen
Int32 myMaxRows;
@ -555,15 +504,6 @@ FIXME
Int32 myRemapMenuIndex, myRemapMenuLowIndex, myRemapMenuHighIndex;
Int32 myRemapMenuItems, myRemapMenuMaxLines;
// Message timer
Int32 myMessageTime;
// Message text
string myMessageText;
// Number of times menu have been drawn
uInt32 myMenuRedraws;
// The width of the information menu, determined by the longest string
Int32 myInfoMenuWidth;
@ -587,6 +527,7 @@ FIXME
// Holds the number of items in the joytable array
uInt32 myJoyTableSize;
*/
};
#endif

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: Dialog.cxx,v 1.4 2005-03-12 01:47:15 stephena Exp $
// $Id: Dialog.cxx,v 1.5 2005-03-13 03:38:40 stephena Exp $
//
// Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project
@ -120,8 +120,8 @@ void Dialog::drawDialog()
FrameBuffer& fb = instance()->frameBuffer();
fb.blendRect(_x, _y, _w, _h, fb.bgcolor);
fb.box(_x, _y, _w, _h, fb.color, fb.shadowcolor);
fb.blendRect(_x, _y, _w, _h, kBGColor);
fb.box(_x, _y, _w, _h, kColor, kShadowColor);
// Draw all children
Widget* w = _firstWidget;

2586
stella/src/gui/FontData.hxx Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,42 @@
//============================================================================
//
// SSSS tt lll lll
// SS SS tt ll ll
// SS tttttt eeee ll ll aaaa
// SSSS tt ee ee ll ll aa
// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator"
// SS SS tt ee ll ll aa aa
// SSSS ttt eeeee llll llll aaaaa
//
// Copyright (c) 1995-2005 by Bradford W. Mott
//
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: GuiUtils.hxx,v 1.1 2005-03-13 03:38:40 stephena Exp $
//
// Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project
//============================================================================
#ifndef UTILITIES_HXX
#define UTILITIES_HXX
/**
A place to put GUI-related things that don't fit anywhere else.
Probably not very neat, but at least it works ...
@author Stephen Anthony
@version $Id: GuiUtils.hxx,v 1.1 2005-03-13 03:38:40 stephena Exp $
*/
// Colors indices to use for the various GUI elements
enum OverlayColor {
kColor,
kBGColor,
kShadowColor,
kTextColor,
kTextColorHi
};
#endif

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: Menu.cxx,v 1.3 2005-03-12 01:47:15 stephena Exp $
// $Id: Menu.cxx,v 1.4 2005-03-13 03:38:40 stephena Exp $
//============================================================================
#include <SDL.h>
@ -93,12 +93,8 @@ void Menu::handleKeyEvent(SDLKey key, SDLMod mod, uInt8 state)
Dialog* activeDialog = myDialogStack.top();
// Convert SDL values to ascii so the ScummVM subsystem can work with it
// FIXME - convert SDLKey and SDLMod to int values
uInt16 ascii = 0;
Int32 keycode = 0, modifiers = 0;
if(state == 1)
activeDialog->handleKeyDown(ascii, keycode, modifiers);
activeDialog->handleKeyDown(key, key, mod);
else
activeDialog->handleKeyUp(ascii, keycode, modifiers);
activeDialog->handleKeyUp(key, key, mod);
}

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: OptionsDialog.cxx,v 1.3 2005-03-12 01:47:15 stephena Exp $
// $Id: OptionsDialog.cxx,v 1.4 2005-03-13 03:38:40 stephena Exp $
//
// Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project
@ -28,19 +28,6 @@
#include "bspf.hxx"
/*
using GUI::CommandSender;
using GUI::StaticTextWidget;
using GUI::kButtonWidth;
using GUI::kCloseCmd;
using GUI::kTextAlignCenter;
using GUI::kTextAlignLeft;
using GUI::WIDGET_ENABLED;
typedef GUI::OptionsDialog GUI_OptionsDialog;
typedef GUI::ChooserDialog GUI_ChooserDialog;
*/
enum {
kVidCmd = 'VIDO',
kAudCmd = 'AUDO',
@ -51,20 +38,23 @@ enum {
};
enum {
kRowHeight = 20,
kBigButtonWidth = 140,
kRowHeight = 22,
kBigButtonWidth = 100,
kMainMenuWidth = (kBigButtonWidth + 2 * 8),
kMainMenuHeight = 6 * kRowHeight + 10,
};
#define addBigButton(label, cmd, hotkey) \
new ButtonWidget(this, x, y, kBigButtonWidth, 16, label, cmd, hotkey); y += kRowHeight
new ButtonWidget(this, x, y, kBigButtonWidth, 18, label, cmd, hotkey); y += kRowHeight
OptionsDialog::OptionsDialog(OSystem* osystem)
: Dialog(osystem, (320 - kMainMenuWidth) / 2, (200 - kMainMenuHeight)/2, kMainMenuWidth, kMainMenuHeight)
/* FIXME - make this depend on the framebuffer dimensions
: Dialog(osystem, (osystem->frameBuffer().width() - kMainMenuWidth) / 2,
(osystem->frameBuffer().height() - kMainMenuHeight)/2,
kMainMenuWidth, kMainMenuHeight)
*/
{
cerr << "OptionsDialog::OptionsDialog()\n";
int y = 7;
const int x = (_w - kBigButtonWidth) / 2;

View File

@ -0,0 +1,128 @@
//============================================================================
//
// SSSS tt lll lll
// SS SS tt ll ll
// SS tttttt eeee ll ll aaaa
// SSSS tt ee ee ll ll aa
// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator"
// SS SS tt ee ll ll aa aa
// SSSS ttt eeeee llll llll aaaaa
//
// Copyright (c) 1995-2005 by Bradford W. Mott
//
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: StellaFont.cxx,v 1.1 2005-03-13 03:38:40 stephena Exp $
//
// Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project
//============================================================================
#include "FrameBuffer.hxx"
#include "GuiUtils.hxx"
#include "StellaFont.hxx"
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Int32 StellaFont::getCharWidth(uInt8 chr) const
{
// If no width table is specified, return the maximum width
if(!myFontDesc.width)
return myFontDesc.maxwidth;
// If this character is not included in the font, use the default char.
if(chr < myFontDesc.firstchar || myFontDesc.firstchar + myFontDesc.size < chr)
{
if(chr == ' ')
return myFontDesc.maxwidth / 2;
chr = myFontDesc.defaultchar;
}
return myFontDesc.width[chr - myFontDesc.firstchar];
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Int32 StellaFont::getStringWidth(const string& str) const
{
Int32 space = 0;
for(uInt32 i = 0; i < str.size(); ++i)
space += getCharWidth(str[i]);
return space;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void StellaFont::drawString(const string& s, uInt32 x, uInt32 y, uInt32 w,
OverlayColor color, TextAlignment align,
Int32 deltax, bool useEllipsis) const
{
const uInt32 leftX = x, rightX = x + w;
uInt32 i;
uInt32 width = getStringWidth(s);
string str;
if(useEllipsis && width > w)
{
// String is too wide. So we shorten it "intelligently", by replacing
// parts of it by an ellipsis ("..."). There are three possibilities
// for this: replace the start, the end, or the middle of the string.
// What is best really depends on the context; but unless we want to
// make this configurable, replacing the middle probably is a good
// compromise.
const int ellipsisWidth = getStringWidth("...");
// SLOW algorithm to remove enough of the middle. But it is good enough for now.
const int halfWidth = (w - ellipsisWidth) / 2;
int w2 = 0;
for(i = 0; i < s.size(); ++i)
{
int charWidth = getCharWidth(s[i]);
if(w2 + charWidth > halfWidth)
break;
w2 += charWidth;
str += s[i];
}
// At this point we know that the first 'i' chars are together 'w2'
// pixels wide. We took the first i-1, and add "..." to them.
str += "...";
// The original string is width wide. Of those we already skipped past
// w2 pixels, which means (width - w2) remain.
// The new str is (w2+ellipsisWidth) wide, so we can accomodate about
// (w - (w2+ellipsisWidth)) more pixels.
// Thus we skip ((width - w2) - (w - (w2+ellipsisWidth))) =
// (width + ellipsisWidth - w)
int skip = width + ellipsisWidth - w;
for(; i < s.size() && skip > 0; ++i)
skip -= getCharWidth(s[i]);
// Append the remaining chars, if any
for(; i < s.size(); ++i)
str += s[i];
width = getStringWidth(str);
}
else
str = s;
if(align == kTextAlignCenter)
x = x + (w - width - 1)/2;
else if(align == kTextAlignRight)
x = x + w - width;
x += deltax;
for(i = 0; i < str.size(); ++i)
{
w = getCharWidth(str[i]);
if(x+w > rightX)
break;
if(x >= leftX)
myFrameBuffer->drawChar(str[i], x, y, color);
x += w;
}
}

View File

@ -0,0 +1,77 @@
//============================================================================
//
// SSSS tt lll lll
// SS SS tt ll ll
// SS tttttt eeee ll ll aaaa
// SSSS tt ee ee ll ll aa
// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator"
// SS SS tt ee ll ll aa aa
// SSSS ttt eeeee llll llll aaaaa
//
// Copyright (c) 1995-2005 by Bradford W. Mott
//
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: StellaFont.hxx,v 1.1 2005-03-13 03:38:41 stephena Exp $
//
// Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project
//============================================================================
#ifndef STELLA_FONT_HXX
#define STELLA_FONT_HXX
class FrameBuffer;
#include "bspf.hxx"
#include "GuiUtils.hxx"
// Text alignment modes for drawString()
enum TextAlignment {
kTextAlignLeft,
kTextAlignCenter,
kTextAlignRight
};
/* builtin C-based proportional/fixed font structure */
/* based on The Microwindows Project http://microwindows.org */
struct FontDesc
{
const char* name; /* font name */
Int32 maxwidth; /* max width in pixels */
Int32 height; /* height in pixels */
Int32 ascent; /* ascent (baseline) height */
Int32 firstchar; /* first character in bitmap */
Int32 size; /* font size in glyphs */
const uInt16* bits; /* 16-bit right-padded bitmap data */
const uInt32* offset; /* offsets into bitmap data */
const uInt8* width; /* character widths or NULL if fixed */
Int32 defaultchar; /* default char (not glyph index) */
long bits_size; /* # words of bitmap_t bits */
};
class StellaFont
{
public:
StellaFont(FrameBuffer* buffer, const FontDesc& desc)
: myFrameBuffer(buffer), myFontDesc(desc) {}
const FontDesc& desc() { return myFontDesc; }
Int32 getFontHeight() const { return myFontDesc.height; }
Int32 getMaxCharWidth() const { return myFontDesc.maxwidth; }
Int32 getCharWidth(uInt8 chr) const;
Int32 getStringWidth(const string& str) const;
void drawString(const string& str, uInt32 x, uInt32 y, uInt32 w,
OverlayColor color, TextAlignment align = kTextAlignLeft,
Int32 deltax = 0, bool useEllipsis = true) const;
protected:
FrameBuffer* myFrameBuffer;
FontDesc myFontDesc;
};
#endif

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: Widget.cxx,v 1.3 2005-03-11 23:36:30 stephena Exp $
// $Id: Widget.cxx,v 1.4 2005-03-13 03:38:41 stephena Exp $
//
// Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project
@ -21,6 +21,7 @@
#include "OSystem.hxx"
#include "FrameBuffer.hxx"
#include "StellaFont.hxx"
#include "Dialog.hxx"
#include "Command.hxx"
#include "GuiObject.hxx"
@ -64,12 +65,12 @@ void Widget::draw()
// Clear background (unless alpha blending is enabled)
if(_flags & WIDGET_CLEARBG)
fb.fillRect(_x, _y, _w, _h, fb.bgcolor);
fb.fillRect(_x, _y, _w, _h, kBGColor);
// Draw border
if(_flags & WIDGET_BORDER) {
OverlayColor colorA = fb.color;
OverlayColor colorB = fb.shadowcolor;
OverlayColor colorA = kColor;
OverlayColor colorB = kShadowColor;
if((_flags & WIDGET_INV_BORDER) == WIDGET_INV_BORDER)
; //FIXME - add swap function SWAP(colorA, colorB);
fb.box(_x, _y, _w, _h, colorA, colorB);
@ -145,8 +146,8 @@ void StaticTextWidget::setValue(Int32 value)
void StaticTextWidget::drawWidget(bool hilite)
{
FrameBuffer& fb = _boss->instance()->frameBuffer();
fb.drawString(_label, _x, _y, _w,
isEnabled() ? fb.textcolor : fb.color, _align);
fb.font().drawString(_label, _x, _y, _w,
isEnabled() ? kTextColor : kColor, _align);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -174,9 +175,9 @@ void ButtonWidget::drawWidget(bool hilite)
int kLineHeight = 10; //FIXME
FrameBuffer& fb = _boss->instance()->frameBuffer();
fb.drawString(_label, _x, _y + (_h - kLineHeight)/2 + 1, _w,
!isEnabled() ? fb.color :
hilite ? fb.textcolorhi : fb.textcolor, _align);
fb.font().drawString(_label, _x, _y + (_h - kLineHeight)/2 + 1, _w,
!isEnabled() ? kColor :
hilite ? kTextColorHi : kTextColor, _align);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -228,7 +229,7 @@ void CheckboxWidget::drawWidget(bool hilite)
FrameBuffer& fb = _boss->instance()->frameBuffer();
// Draw the box
fb.box(_x, _y, 14, 14, fb.color, fb.shadowcolor);
fb.box(_x, _y, 14, 14, kColor, kShadowColor);
// If checked, draw cross inside the box
if(_state)
@ -236,11 +237,11 @@ void CheckboxWidget::drawWidget(bool hilite)
// fb.drawBitmap(checked_img, _x + 3, _y + 3,
// isEnabled() ? fb.textcolor : fb.color);
else
fb.fillRect(_x + 2, _y + 2, 10, 10, fb.bgcolor);
fb.fillRect(_x + 2, _y + 2, 10, 10, kBGColor);
// Finally draw the label
fb.drawString(_label, _x + 20, _y + 3, _w,
isEnabled() ? fb.textcolor : fb.color);
fb.font().drawString(_label, _x + 20, _y + 3, _w,
isEnabled() ? kTextColor : kColor);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -307,16 +308,16 @@ void SliderWidget::drawWidget(bool hilite)
// Draw the label, if any
if(_labelWidth > 0)
fb.drawString(_label, _x, _y + 2, _labelWidth,
isEnabled() ? fb.textcolor : fb.color, kTextAlignRight);
fb.font().drawString(_label, _x, _y + 2, _labelWidth,
isEnabled() ? kTextColor : kColor, kTextAlignRight);
// Draw the box
fb.box(_x + _labelWidth, _y, _w - _labelWidth, _h, fb.color, fb.shadowcolor);
fb.box(_x + _labelWidth, _y, _w - _labelWidth, _h, kColor, kShadowColor);
// Draw the 'bar'
fb.fillRect(_x + _labelWidth + 2, _y + 2, valueToPos(_value), _h - 4,
!isEnabled() ? fb.color :
hilite ? fb.textcolorhi : fb.textcolor);
!isEnabled() ? kColor :
hilite ? kTextColorHi : kTextColor);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: Widget.hxx,v 1.3 2005-03-11 23:36:30 stephena Exp $
// $Id: Widget.hxx,v 1.4 2005-03-13 03:38:41 stephena Exp $
//
// Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project
@ -24,6 +24,7 @@
class Dialog;
#include "StellaFont.hxx"
#include "FrameBuffer.hxx"
#include "GuiObject.hxx"
#include "bspf.hxx"
@ -61,7 +62,7 @@ enum {
This is the base class for all widgets.
@author Stephen Anthony
@version $Id: Widget.hxx,v 1.3 2005-03-11 23:36:30 stephena Exp $
@version $Id: Widget.hxx,v 1.4 2005-03-13 03:38:41 stephena Exp $
*/
class Widget : public GuiObject
{