Totally reworked the font subsystem. Fonts now belong to OSystem instead

of the FrameBuffer (since fonts should only be created once, and the
FrameBuffer is deleted and re-created many times).

Added a default font to the Widget class, as well as a setFont() method.
So each widget can individually choose its own font.

Added a monospaced font.  It's currently used only in the PromptDialog,
but due to the above changes, it can be used anywhere.

Tweaked some keys in the PromptDialog.  Shift-(Home, End, PageUp, PageDown)
now control the scrollbar, and without shift, those keys control the current
line editing/navigation.


git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@473 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
stephena 2005-06-08 18:45:09 +00:00
parent 0a84fa22bb
commit 35f9b5b0e4
24 changed files with 5558 additions and 2941 deletions

View File

@ -13,7 +13,7 @@
## See the file "license" for information on usage and redistribution of ## See the file "license" for information on usage and redistribution of
## this file, and for a DISCLAIMER OF ALL WARRANTIES. ## this file, and for a DISCLAIMER OF ALL WARRANTIES.
## ##
## $Id: makefile,v 1.87 2005-06-07 01:14:38 stephena Exp $ ## $Id: makefile,v 1.88 2005-06-08 18:45:07 stephena Exp $
##============================================================================ ##============================================================================
##============================================================================ ##============================================================================
@ -154,7 +154,7 @@ win32-gl:
############################################################################### ###############################################################################
M6502_OBJS = D6502.o Device.o M6502.o M6502Low.o M6502Hi.o NullDev.o System.o M6502_OBJS = D6502.o Device.o M6502.o M6502Low.o M6502Hi.o NullDev.o System.o
GUI_OBJS = StellaFont.o Menu.o Launcher.o Debugger.o \ GUI_OBJS = Font.o Menu.o Launcher.o Debugger.o \
Widget.o PopUpWidget.o ScrollBarWidget.o ListWidget.o TabWidget.o \ Widget.o PopUpWidget.o ScrollBarWidget.o ListWidget.o TabWidget.o \
Dialog.o DialogContainer.o OptionsDialog.o VideoDialog.o AudioDialog.o \ Dialog.o DialogContainer.o OptionsDialog.o VideoDialog.o AudioDialog.o \
EventMappingDialog.o GameInfoDialog.o HelpDialog.o AboutDialog.o \ EventMappingDialog.o GameInfoDialog.o HelpDialog.o AboutDialog.o \
@ -380,8 +380,8 @@ NullDev.o: $(CORE)/m6502/src/NullDev.cxx $(CORE)/m6502/src/NullDev.hxx
System.o: $(CORE)/m6502/src/System.cxx $(CORE)/m6502/src/System.hxx System.o: $(CORE)/m6502/src/System.cxx $(CORE)/m6502/src/System.hxx
$(CXX) -c $(FLAGS) $(OPTIONS) $(CORE)/m6502/src/System.cxx $(CXX) -c $(FLAGS) $(OPTIONS) $(CORE)/m6502/src/System.cxx
StellaFont.o: $(GUI)/StellaFont.cxx $(GUI)/StellaFont.hxx Font.o: $(GUI)/Font.cxx $(GUI)/Font.hxx
$(CXX) -c $(FLAGS) $(OPTIONS) $(LDFLAGS) $(GUI)/StellaFont.cxx $(CXX) -c $(FLAGS) $(OPTIONS) $(LDFLAGS) $(GUI)/Font.cxx
Menu.o: $(GUI)/Menu.cxx $(GUI)/Menu.hxx Menu.o: $(GUI)/Menu.cxx $(GUI)/Menu.hxx
$(CXX) -c $(FLAGS) $(OPTIONS) $(LDFLAGS) $(GUI)/Menu.cxx $(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 // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: FrameBufferGL.cxx,v 1.27 2005-06-03 17:52:04 stephena Exp $ // $Id: FrameBufferGL.cxx,v 1.28 2005-06-08 18:45:07 stephena Exp $
//============================================================================ //============================================================================
#include <SDL.h> #include <SDL.h>
@ -26,7 +26,7 @@
#include "MediaSrc.hxx" #include "MediaSrc.hxx"
#include "Settings.hxx" #include "Settings.hxx"
#include "OSystem.hxx" #include "OSystem.hxx"
#include "StellaFont.hxx" #include "Font.hxx"
#include "GuiUtils.hxx" #include "GuiUtils.hxx"
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -352,23 +352,26 @@ void FrameBufferGL::fillRect(uInt32 x, uInt32 y, uInt32 w, uInt32 h,
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void FrameBufferGL::drawChar(uInt8 chr, uInt32 xorig, uInt32 yorig, void FrameBufferGL::drawChar(const GUI::Font& FONT, uInt8 chr,
OverlayColor color) uInt32 xorig, uInt32 yorig, OverlayColor color)
{ {
// FIXME - I do this to prevent 'const' warnings; it should be done better
GUI::Font& font = (GUI::Font&)FONT;
// If this character is not included in the font, use the default char. // If this character is not included in the font, use the default char.
if(chr < myFont->desc().firstchar || if(chr < font.desc().firstchar ||
chr >= myFont->desc().firstchar + myFont->desc().size) chr >= font.desc().firstchar + font.desc().size)
{ {
if (chr == ' ') if (chr == ' ')
return; return;
chr = myFont->desc().defaultchar; chr = font.desc().defaultchar;
} }
const Int32 w = myFont->getCharWidth(chr); const Int32 w = font.getCharWidth(chr);
const Int32 h = myFont->getFontHeight(); const Int32 h = font.getFontHeight();
chr -= myFont->desc().firstchar; chr -= font.desc().firstchar;
const uInt16* tmp = myFont->desc().bits + (myFont->desc().offset ? const uInt16* tmp = font.desc().bits + (font.desc().offset ?
myFont->desc().offset[chr] : (chr * h)); font.desc().offset[chr] : (chr * h));
SDL_Rect rect; SDL_Rect rect;
for(int y = 0; y < h; y++) for(int y = 0; y < h; y++)

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: FrameBufferGL.hxx,v 1.14 2005-05-30 16:25:46 stephena Exp $ // $Id: FrameBufferGL.hxx,v 1.15 2005-06-08 18:45:08 stephena Exp $
//============================================================================ //============================================================================
#ifndef FRAMEBUFFER_GL_HXX #ifndef FRAMEBUFFER_GL_HXX
@ -24,6 +24,7 @@
#include <SDL_syswm.h> #include <SDL_syswm.h>
class OSystem; class OSystem;
class GUI::Font;
#include "bspf.hxx" #include "bspf.hxx"
#include "GuiUtils.hxx" #include "GuiUtils.hxx"
@ -34,7 +35,7 @@ class OSystem;
This class implements an SDL OpenGL framebuffer. This class implements an SDL OpenGL framebuffer.
@author Stephen Anthony @author Stephen Anthony
@version $Id: FrameBufferGL.hxx,v 1.14 2005-05-30 16:25:46 stephena Exp $ @version $Id: FrameBufferGL.hxx,v 1.15 2005-06-08 18:45:08 stephena Exp $
*/ */
class FrameBufferGL : public FrameBuffer class FrameBufferGL : public FrameBuffer
{ {
@ -157,12 +158,14 @@ class FrameBufferGL : public FrameBuffer
/** /**
This routine is called to draw the specified character. This routine is called to draw the specified character.
@param font The font to use to draw the character
@param c The character to draw @param c The character to draw
@param x The x coordinate @param x The x coordinate
@param y The y coordinate @param y The y coordinate
@param color The color of the character @param color The color of the character
*/ */
virtual void drawChar(uInt8 c, uInt32 x, uInt32 y, OverlayColor color); virtual void drawChar(const GUI::Font& font, uInt8 c, uInt32 x, uInt32 y,
OverlayColor color);
/** /**
This routine is called to draw the bitmap image. This routine is called to draw the bitmap image.

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: FrameBufferSoft.cxx,v 1.23 2005-05-30 16:25:46 stephena Exp $ // $Id: FrameBufferSoft.cxx,v 1.24 2005-06-08 18:45:08 stephena Exp $
//============================================================================ //============================================================================
#include <SDL.h> #include <SDL.h>
@ -26,7 +26,7 @@
#include "MediaSrc.hxx" #include "MediaSrc.hxx"
#include "Settings.hxx" #include "Settings.hxx"
#include "OSystem.hxx" #include "OSystem.hxx"
#include "StellaFont.hxx" #include "Font.hxx"
#include "GuiUtils.hxx" #include "GuiUtils.hxx"
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -375,23 +375,26 @@ void FrameBufferSoft::fillRect(uInt32 x, uInt32 y, uInt32 w, uInt32 h,
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void FrameBufferSoft::drawChar(uInt8 chr, uInt32 xorig, uInt32 yorig, void FrameBufferSoft::drawChar(const GUI::Font& FONT, uInt8 chr,
OverlayColor color) uInt32 xorig, uInt32 yorig, OverlayColor color)
{ {
// FIXME - I do this to prevent 'const' warnings; it should be done better
GUI::Font& font = (GUI::Font&)FONT;
// If this character is not included in the font, use the default char. // If this character is not included in the font, use the default char.
if(chr < myFont->desc().firstchar || if(chr < font.desc().firstchar ||
chr >= myFont->desc().firstchar + myFont->desc().size) chr >= font.desc().firstchar + font.desc().size)
{ {
if (chr == ' ') if (chr == ' ')
return; return;
chr = myFont->desc().defaultchar; chr = font.desc().defaultchar;
} }
const Int32 w = myFont->getCharWidth(chr); const Int32 w = font.getCharWidth(chr);
const Int32 h = myFont->getFontHeight(); const Int32 h = font.getFontHeight();
chr -= myFont->desc().firstchar; chr -= font.desc().firstchar;
const uInt16* tmp = myFont->desc().bits + (myFont->desc().offset ? const uInt16* tmp = font.desc().bits + (font.desc().offset ?
myFont->desc().offset[chr] : (chr * h)); font.desc().offset[chr] : (chr * h));
SDL_Rect rect; SDL_Rect rect;
for(int y = 0; y < h; y++) for(int y = 0; y < h; y++)

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: FrameBufferSoft.hxx,v 1.14 2005-05-30 16:25:46 stephena Exp $ // $Id: FrameBufferSoft.hxx,v 1.15 2005-06-08 18:45:08 stephena Exp $
//============================================================================ //============================================================================
#ifndef FRAMEBUFFER_SOFT_HXX #ifndef FRAMEBUFFER_SOFT_HXX
@ -23,6 +23,7 @@
#include <SDL_syswm.h> #include <SDL_syswm.h>
class OSystem; class OSystem;
class GUI::Font;
class RectList; class RectList;
#include "bspf.hxx" #include "bspf.hxx"
@ -34,7 +35,7 @@ class RectList;
This class implements an SDL software framebuffer. This class implements an SDL software framebuffer.
@author Stephen Anthony @author Stephen Anthony
@version $Id: FrameBufferSoft.hxx,v 1.14 2005-05-30 16:25:46 stephena Exp $ @version $Id: FrameBufferSoft.hxx,v 1.15 2005-06-08 18:45:08 stephena Exp $
*/ */
class FrameBufferSoft : public FrameBuffer class FrameBufferSoft : public FrameBuffer
{ {
@ -157,12 +158,14 @@ class FrameBufferSoft : public FrameBuffer
/** /**
This routine is called to draw the specified character. This routine is called to draw the specified character.
@param font The font to use to draw the character
@param c The character to draw @param c The character to draw
@param x The x coordinate @param x The x coordinate
@param y The y coordinate @param y The y coordinate
@param color The color of the character @param color The color of the character
*/ */
virtual void drawChar(uInt8 c, uInt32 x, uInt32 y, OverlayColor color); virtual void drawChar(const GUI::Font& font, uInt8 c, uInt32 x, uInt32 y,
OverlayColor color);
/** /**
This routine is called to draw the bitmap image. This routine is called to draw the bitmap image.

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: EventHandler.hxx,v 1.36 2005-06-07 21:22:39 stephena Exp $ // $Id: EventHandler.hxx,v 1.37 2005-06-08 18:45:08 stephena Exp $
//============================================================================ //============================================================================
#ifndef EVENTHANDLER_HXX #ifndef EVENTHANDLER_HXX
@ -74,7 +74,7 @@ struct Stella_Joystick {
mapping can take place. mapping can take place.
@author Stephen Anthony @author Stephen Anthony
@version $Id: EventHandler.hxx,v 1.36 2005-06-07 21:22:39 stephena Exp $ @version $Id: EventHandler.hxx,v 1.37 2005-06-08 18:45:08 stephena Exp $
*/ */
class EventHandler class EventHandler
{ {
@ -183,7 +183,7 @@ class EventHandler
inline bool kbdAlt(int mod) inline bool kbdAlt(int mod)
{ {
#ifndef MAC_OSX #ifndef MAC_OSX
return (mod & KMOD_ALT) > 0; return (mod & KMOD_ALT);
#else #else
return ((mod & KMOD_META) && (mod & KMOD_SHIFT)); return ((mod & KMOD_META) && (mod & KMOD_SHIFT));
#endif #endif
@ -200,7 +200,7 @@ class EventHandler
inline bool kbdShift(int mod) inline bool kbdShift(int mod)
{ {
return (mod & KMOD_SHIFT) > 0; return (mod & KMOD_SHIFT);
} }
// Holds static strings for the remap menu // Holds static strings for the remap menu

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: FrameBuffer.cxx,v 1.42 2005-06-07 21:22:39 stephena Exp $ // $Id: FrameBuffer.cxx,v 1.43 2005-06-08 18:45:08 stephena Exp $
//============================================================================ //============================================================================
#include <sstream> #include <sstream>
@ -25,7 +25,7 @@
#include "Settings.hxx" #include "Settings.hxx"
#include "MediaSrc.hxx" #include "MediaSrc.hxx"
#include "FrameBuffer.hxx" #include "FrameBuffer.hxx"
#include "StellaFont.hxx" #include "Font.hxx"
#include "GuiUtils.hxx" #include "GuiUtils.hxx"
#include "Menu.hxx" #include "Menu.hxx"
#include "Launcher.hxx" #include "Launcher.hxx"
@ -64,9 +64,6 @@ FrameBuffer::FrameBuffer(OSystem* osystem)
for(uInt8 j = 0; j < 3; j++) for(uInt8 j = 0; j < 3; j++)
myGUIColors[i][j] = colors[i][j]; myGUIColors[i][j] = colors[i][j];
// Create a font to draw text
myFont = new StellaFont(this);
myBaseDim.x = myBaseDim.y = myBaseDim.w = myBaseDim.h = 0; myBaseDim.x = myBaseDim.y = myBaseDim.w = myBaseDim.h = 0;
myImageDim = myScreenDim = myDesktopDim = myBaseDim; myImageDim = myScreenDim = myDesktopDim = myBaseDim;
} }
@ -74,8 +71,6 @@ FrameBuffer::FrameBuffer(OSystem* osystem)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
FrameBuffer::~FrameBuffer(void) FrameBuffer::~FrameBuffer(void)
{ {
if(myFont)
delete myFont;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -182,15 +177,15 @@ void FrameBuffer::update()
// Draw any pending messages // Draw any pending messages
if(myMessageTime > 0) if(myMessageTime > 0)
{ {
int w = myFont->getStringWidth(myMessageText) + 10; int w = myOSystem->font().getStringWidth(myMessageText) + 10;
int h = myFont->getFontHeight() + 8; int h = myOSystem->font().getFontHeight() + 8;
int x = (myBaseDim.w >> 1) - (w >> 1); int x = (myBaseDim.w >> 1) - (w >> 1);
int y = myBaseDim.h - h - 10/2; int y = myBaseDim.h - h - 10/2;
// Draw the bounded box and text // Draw the bounded box and text
blendRect(x+1, y+2, w-2, h-4, kBGColor); blendRect(x+1, y+2, w-2, h-4, kBGColor);
box(x, y+1, w, h-2, kColor, kColor); box(x, y+1, w, h-2, kColor, kColor);
myFont->drawString(myMessageText, x+1, y+4, w, kTextColor, kTextAlignCenter); drawString(myOSystem->font(), myMessageText, x+1, y+4, w, kTextColor, kTextAlignCenter);
myMessageTime--; myMessageTime--;
// Erase this message on next update // Erase this message on next update
@ -539,3 +534,79 @@ void FrameBuffer::frameRect(uInt32 x, uInt32 y, uInt32 w, uInt32 h,
vLine(x, y, y + h - 1, color); vLine(x, y, y + h - 1, color);
vLine(x + w - 1, y, y + h - 1, color); vLine(x + w - 1, y, y + h - 1, color);
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void FrameBuffer::drawString(const GUI::Font& font, const string& s,
int x, int y, int w,
OverlayColor color, TextAlignment align,
int deltax, bool useEllipsis)
{
const int leftX = x, rightX = x + w;
unsigned int i;
int width = font.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 = font.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 = font.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 -= font.getCharWidth(s[i]);
// Append the remaining chars, if any
for(; i < s.size(); ++i)
str += s[i];
width = font.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 = font.getCharWidth(str[i]);
if(x+w > rightX)
break;
if(x >= leftX)
drawChar(font, str[i], x, y, color);
x += w;
}
}

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: FrameBuffer.hxx,v 1.37 2005-05-31 17:57:50 stephena Exp $ // $Id: FrameBuffer.hxx,v 1.38 2005-06-08 18:45:08 stephena Exp $
//============================================================================ //============================================================================
#ifndef FRAMEBUFFER_HXX #ifndef FRAMEBUFFER_HXX
@ -25,13 +25,19 @@
#include "bspf.hxx" #include "bspf.hxx"
#include "Event.hxx" #include "Event.hxx"
#include "MediaSrc.hxx" #include "MediaSrc.hxx"
#include "StellaFont.hxx" #include "Font.hxx"
#include "GuiUtils.hxx" #include "GuiUtils.hxx"
class StellaFont;
class Console; class Console;
class OSystem; class OSystem;
// Text alignment modes for drawString()
enum TextAlignment {
kTextAlignLeft,
kTextAlignCenter,
kTextAlignRight
};
/** /**
This class encapsulates the MediaSource and is the basis for the video This class encapsulates the MediaSource and is the basis for the video
display in Stella. All graphics ports should derive from this class for display in Stella. All graphics ports should derive from this class for
@ -40,7 +46,7 @@ class OSystem;
All GUI elements (ala ScummVM) are drawn here as well. All GUI elements (ala ScummVM) are drawn here as well.
@author Stephen Anthony @author Stephen Anthony
@version $Id: FrameBuffer.hxx,v 1.37 2005-05-31 17:57:50 stephena Exp $ @version $Id: FrameBuffer.hxx,v 1.38 2005-06-08 18:45:08 stephena Exp $
*/ */
class FrameBuffer class FrameBuffer
{ {
@ -55,13 +61,6 @@ class FrameBuffer
*/ */
virtual ~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 (Re)initializes the framebuffer display. This must be called before any
calls are made to derived methods. calls are made to derived methods.
@ -156,7 +155,7 @@ class FrameBuffer
void setFullscreen(bool enable); void setFullscreen(bool enable);
/** /**
This routine is called when the user wants to resize the window. This method is called when the user wants to resize the window.
Size = 'PreviousSize' means window should decrease in size Size = 'PreviousSize' means window should decrease in size
Size = 'NextSize' means window should increase in size Size = 'NextSize' means window should increase in size
Size = 'GivenSize' means window should be resized to quantity given in 'zoom' Size = 'GivenSize' means window should be resized to quantity given in 'zoom'
@ -206,7 +205,7 @@ class FrameBuffer
void setPalette(const uInt32* palette); void setPalette(const uInt32* palette);
/** /**
This routine should be called to draw a rectangular box with sides This method should be called to draw a rectangular box with sides
at the specified coordinates. at the specified coordinates.
@param x The x coordinate @param x The x coordinate
@ -220,7 +219,7 @@ class FrameBuffer
OverlayColor colorA, OverlayColor colorB); OverlayColor colorA, OverlayColor colorB);
/** /**
This routine should be called to draw a framed rectangle. This method should be called to draw a framed rectangle.
I'm not exactly sure what it is, so I can't explain it :) I'm not exactly sure what it is, so I can't explain it :)
@param x The x coordinate @param x The x coordinate
@ -232,23 +231,42 @@ class FrameBuffer
void frameRect(uInt32 x, uInt32 y, uInt32 w, uInt32 h, void frameRect(uInt32 x, uInt32 y, uInt32 w, uInt32 h,
OverlayColor color); OverlayColor color);
/**
This method should be called to draw the specified string.
@param font The font to draw the string with
@param str The string to draw
@param x The x coordinate
@param y The y coordinate
@param w The width of the string area
@param h The height of the string area
@param color The color of the text
@param align The alignment of the text in the string width area
@param deltax
@param useEllipsis Whether to use '...' when the string is too long
*/
void drawString(const GUI::Font& font, const string& str, int x, int y, int w,
OverlayColor color, TextAlignment align = kTextAlignLeft,
int deltax = 0, bool useEllipsis = true);
public: public:
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// The following methods are system-specific and must be implemented // The following methods are system-specific and must be implemented
// in derived classes. // in derived classes.
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
/** /**
This routine is called to initialize the subsystem-specific video mode. This method is called to initialize the subsystem-specific video mode.
*/ */
virtual bool initSubsystem() = 0; virtual bool initSubsystem() = 0;
/** /**
This routine is called to set the aspect ratio of the screen. This method is called to set the aspect ratio of the screen.
*/ */
virtual void setAspectRatio() = 0; virtual void setAspectRatio() = 0;
/** /**
This routine is called whenever the screen needs to be recreated. This method is called whenever the screen needs to be recreated.
It updates the global screen variable. It updates the global screen variable.
*/ */
virtual bool createScreen() = 0; virtual bool createScreen() = 0;
@ -259,23 +277,23 @@ class FrameBuffer
virtual void toggleFilter() = 0; virtual void toggleFilter() = 0;
/** /**
This routine should be called anytime the MediaSource needs to be redrawn This method should be called anytime the MediaSource needs to be redrawn
to the screen. to the screen.
*/ */
virtual void drawMediaSource() = 0; virtual void drawMediaSource() = 0;
/** /**
This routine is called before any drawing is done (per-frame). This method is called before any drawing is done (per-frame).
*/ */
virtual void preFrameUpdate() = 0; virtual void preFrameUpdate() = 0;
/** /**
This routine is called after any drawing is done (per-frame). This method is called after any drawing is done (per-frame).
*/ */
virtual void postFrameUpdate() = 0; virtual void postFrameUpdate() = 0;
/** /**
This routine is called to get the specified scanline data. This method is called to get the specified scanline data.
@param row The row we are looking for @param row The row we are looking for
@param data The actual pixel data (in bytes) @param data The actual pixel data (in bytes)
@ -283,7 +301,7 @@ class FrameBuffer
virtual void scanline(uInt32 row, uInt8* data) = 0; virtual void scanline(uInt32 row, uInt8* data) = 0;
/** /**
This routine is called to map a given r,g,b triple to the screen palette. This method is called to map a given r,g,b triple to the screen palette.
@param r The red component of the color. @param r The red component of the color.
@param g The green component of the color. @param g The green component of the color.
@ -292,7 +310,7 @@ class FrameBuffer
virtual Uint32 mapRGB(Uint8 r, Uint8 g, Uint8 b) = 0; virtual Uint32 mapRGB(Uint8 r, Uint8 g, Uint8 b) = 0;
/** /**
This routine should be called to draw a horizontal line. This method should be called to draw a horizontal line.
@param x The first x coordinate @param x The first x coordinate
@param y The y coordinate @param y The y coordinate
@ -302,7 +320,7 @@ class FrameBuffer
virtual void hLine(uInt32 x, uInt32 y, uInt32 x2, OverlayColor color) = 0; virtual void hLine(uInt32 x, uInt32 y, uInt32 x2, OverlayColor color) = 0;
/** /**
This routine should be called to draw a vertical line. This method should be called to draw a vertical line.
@param x The x coordinate @param x The x coordinate
@param y The first y coordinate @param y The first y coordinate
@ -312,7 +330,7 @@ class FrameBuffer
virtual void vLine(uInt32 x, uInt32 y, uInt32 y2, OverlayColor color) = 0; virtual void vLine(uInt32 x, uInt32 y, uInt32 y2, OverlayColor color) = 0;
/** /**
This routine should be called to draw a blended rectangle. This method should be called to draw a blended rectangle.
@param x The x coordinate @param x The x coordinate
@param y The y coordinate @param y The y coordinate
@ -325,7 +343,7 @@ class FrameBuffer
OverlayColor color, uInt32 level = 3) = 0; OverlayColor color, uInt32 level = 3) = 0;
/** /**
This routine should be called to draw a filled rectangle. This method should be called to draw a filled rectangle.
@param x The x coordinate @param x The x coordinate
@param y The y coordinate @param y The y coordinate
@ -337,17 +355,19 @@ class FrameBuffer
OverlayColor color) = 0; OverlayColor color) = 0;
/** /**
This routine should be called to draw the specified character. This method should be called to draw the specified character.
@param font The font to use to draw the character
@param c The character to draw @param c The character to draw
@param x The x coordinate @param x The x coordinate
@param y The y coordinate @param y The y coordinate
@param color The color of the character @param color The color of the character
*/ */
virtual void drawChar(uInt8 c, uInt32 x, uInt32 y, OverlayColor color) = 0; virtual void drawChar(const GUI::Font& font, uInt8 c, uInt32 x, uInt32 y,
OverlayColor color) = 0;
/** /**
This routine should be called to draw the bitmap image. This method should be called to draw the bitmap image.
@param bitmap The data to draw @param bitmap The data to draw
@param x The x coordinate @param x The x coordinate
@ -359,7 +379,7 @@ class FrameBuffer
Int32 h = 8) = 0; Int32 h = 8) = 0;
/** /**
This routine should be called to translate the given coordinates This method should be called to translate the given coordinates
to their unzoomed/unscaled equivalents. to their unzoomed/unscaled equivalents.
@param x X coordinate to translate @param x X coordinate to translate
@ -410,9 +430,6 @@ class FrameBuffer
// The aspect ratio of the window // The aspect ratio of the window
float theAspectRatio; float theAspectRatio;
// The font object to use
StellaFont* myFont;
private: private:
/** /**
Set the icon for the main SDL window. Set the icon for the main SDL window.

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: OSystem.cxx,v 1.22 2005-05-27 18:00:48 stephena Exp $ // $Id: OSystem.cxx,v 1.23 2005-06-08 18:45:08 stephena Exp $
//============================================================================ //============================================================================
#include <cassert> #include <cassert>
@ -41,6 +41,9 @@
#include "Menu.hxx" #include "Menu.hxx"
#include "Launcher.hxx" #include "Launcher.hxx"
#include "Debugger.hxx" #include "Debugger.hxx"
#include "Font.hxx"
#include "StellaFont.hxx"
#include "ConsoleFont.hxx"
#include "bspf.hxx" #include "bspf.hxx"
#include "OSystem.hxx" #include "OSystem.hxx"
@ -56,13 +59,19 @@ OSystem::OSystem()
myLauncher(NULL), myLauncher(NULL),
myDebugger(NULL), myDebugger(NULL),
myRomFile(""), myRomFile(""),
myFeatures("") myFeatures(""),
myFont(NULL),
myConsoleFont(NULL)
{ {
// Create menu and launcher GUI objects // Create menu and launcher GUI objects
myMenu = new Menu(this); myMenu = new Menu(this);
myLauncher = new Launcher(this); myLauncher = new Launcher(this);
myDebugger = new Debugger(this); myDebugger = new Debugger(this);
// Create fonts to draw text
myFont = new GUI::Font(GUI::stellaDesc);
myConsoleFont = new GUI::Font(GUI::consoleDesc);
// Determine which features were conditionally compiled into Stella // Determine which features were conditionally compiled into Stella
#ifdef DISPLAY_OPENGL #ifdef DISPLAY_OPENGL
myFeatures += "OpenGL "; myFeatures += "OpenGL ";
@ -89,6 +98,8 @@ OSystem::~OSystem()
delete myMenu; delete myMenu;
delete myLauncher; delete myLauncher;
delete myDebugger; delete myDebugger;
delete myFont;
delete myConsoleFont;
// Remove any game console that is currently attached // Remove any game console that is currently attached
delete myConsole; delete myConsole;

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: OSystem.hxx,v 1.19 2005-05-27 18:00:48 stephena Exp $ // $Id: OSystem.hxx,v 1.20 2005-06-08 18:45:08 stephena Exp $
//============================================================================ //============================================================================
#ifndef OSYSTEM_HXX #ifndef OSYSTEM_HXX
@ -31,6 +31,10 @@ class Debugger;
#include "Settings.hxx" #include "Settings.hxx"
#include "Console.hxx" #include "Console.hxx"
#include "StringList.hxx" #include "StringList.hxx"
#include "Font.hxx"
//#include "StellaFont.hxx"
//#include "ConsoleFont.hxx"
#include "bspf.hxx" #include "bspf.hxx"
@ -40,7 +44,7 @@ class Debugger;
other objects belong. other objects belong.
@author Stephen Anthony @author Stephen Anthony
@version $Id: OSystem.hxx,v 1.19 2005-05-27 18:00:48 stephena Exp $ @version $Id: OSystem.hxx,v 1.20 2005-06-08 18:45:08 stephena Exp $
*/ */
class OSystem class OSystem
{ {
@ -140,6 +144,20 @@ class OSystem
*/ */
Debugger& debugger(void) const { return *myDebugger; } Debugger& debugger(void) const { return *myDebugger; }
/**
Get the font object of the system
@return The font reference
*/
inline const GUI::Font& font() const { return *myFont; }
/**
Get the console font object of the system
@return The console font reference
*/
inline const GUI::Font& consoleFont() const { return *myConsoleFont; }
/** /**
Set the framerate for the video system. It's placed in this class since Set the framerate for the video system. It's placed in this class since
the mainLoop() method is defined here. the mainLoop() method is defined here.
@ -360,6 +378,12 @@ class OSystem
string myFeatures; string myFeatures;
// The normal GUI font object to use
GUI::Font* myFont;
// The console font object to use
GUI::Font* myConsoleFont;
private: private:
// Copy constructor isn't supported by this class so make it private // Copy constructor isn't supported by this class so make it private
OSystem(const OSystem&); OSystem(const OSystem&);

File diff suppressed because it is too large Load Diff

61
stella/src/gui/Font.cxx Normal file
View File

@ -0,0 +1,61 @@
//============================================================================
//
// 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: Font.cxx,v 1.1 2005-06-08 18:45:08 stephena Exp $
//
// Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project
//============================================================================
#include "Font.hxx"
namespace GUI {
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Font::Font(FontDesc desc)
: myFontDesc(desc)
{
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
int Font::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];
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
int Font::getStringWidth(const string& str) const
{
int space = 0;
for(unsigned int i = 0; i < str.size(); ++i)
space += getCharWidth(str[i]);
return space;
}
} // namespace GUI

67
stella/src/gui/Font.hxx Normal file
View File

@ -0,0 +1,67 @@
//============================================================================
//
// 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: Font.hxx,v 1.1 2005-06-08 18:45:08 stephena Exp $
//
// Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project
//============================================================================
#ifndef FONT_HXX
#define FONT_HXX
#include "bspf.hxx"
#include "GuiUtils.hxx"
/* builtin C-based proportional/fixed font structure */
/* based on The Microwindows Project http://microwindows.org */
typedef struct
{
const char* name; /* font name */
int maxwidth; /* max width in pixels */
int height; /* height in pixels */
int ascent; /* ascent (baseline) height */
int firstchar; /* first character in bitmap */
int size; /* font size in glyphs */
const uInt16* bits; /* 16-bit right-padded bitmap data */
const int* offset; /* offsets into bitmap data */
const uInt8* width; /* character widths or NULL if fixed */
int defaultchar; /* default char (not glyph index) */
long bits_size; /* # words of bitmap_t bits */
} FontDesc;
namespace GUI {
class Font
{
public:
Font(FontDesc desc);
const FontDesc& desc() { return myFontDesc; }
int getFontHeight() const { return myFontDesc.height; }
int getMaxCharWidth() const { return myFontDesc.maxwidth; }
int getCharWidth(uInt8 chr) const;
int getStringWidth(const string& str) const;
private:
FontDesc myFontDesc;
};
} // namespace GUI
#endif

File diff suppressed because it is too large Load Diff

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: LauncherDialog.cxx,v 1.19 2005-06-07 01:14:39 stephena Exp $ // $Id: LauncherDialog.cxx,v 1.20 2005-06-08 18:45:09 stephena Exp $
// //
// Based on code from ScummVM - Scumm Interpreter // Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project // Copyright (C) 2002-2004 The ScummVM project
@ -220,7 +220,7 @@ void LauncherDialog::loadListFromDisk()
// Create a progress dialog box to show the progress of processing // Create a progress dialog box to show the progress of processing
// the ROMs, since this is usually a time-consuming operation // the ROMs, since this is usually a time-consuming operation
string message = "Loading ROM's from disk ..."; string message = "Loading ROM's from disk ...";
int w = instance()->frameBuffer().font().getStringWidth(message) + 20, int w = instance()->font().getStringWidth(message) + 20,
h = kLineHeight * 4; h = kLineHeight * 4;
int x = (_w - w) / 2, int x = (_w - w) / 2,
y = (_h - h) / 2; y = (_h - h) / 2;

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: ListWidget.cxx,v 1.11 2005-06-07 21:22:39 stephena Exp $ // $Id: ListWidget.cxx,v 1.12 2005-06-08 18:45:09 stephena Exp $
// //
// Based on code from ScummVM - Scumm Interpreter // Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project // Copyright (C) 2002-2004 The ScummVM project
@ -398,8 +398,8 @@ void ListWidget::drawWidget(bool hilite)
else else
fb.frameRect(_x + 1, _y + 1 + kLineHeight * i, _w - 1, kLineHeight, kTextColorHi); fb.frameRect(_x + 1, _y + 1 + kLineHeight * i, _w - 1, kLineHeight, kTextColorHi);
} }
fb.font().drawString(buffer, _x + 2, _y + 2 + kLineHeight * i, _w - 4, fb.drawString(_font, buffer, _x + 2, _y + 2 + kLineHeight * i, _w - 4,
(_selectedItem == pos && _hasFocus) ? kBGColor : kTextColor); (_selectedItem == pos && _hasFocus) ? kBGColor : kTextColor);
} }
} }
@ -407,16 +407,15 @@ void ListWidget::drawWidget(bool hilite)
int ListWidget::getCaretPos() const int ListWidget::getCaretPos() const
{ {
int caretpos = 0; int caretpos = 0;
FrameBuffer& fb = _boss->instance()->frameBuffer();
if (_numberingMode == kListNumberingZero || _numberingMode == kListNumberingOne) if (_numberingMode == kListNumberingZero || _numberingMode == kListNumberingOne)
{ {
char temp[10]; char temp[10];
sprintf(temp, "%2d. ", (_selectedItem + _numberingMode)); sprintf(temp, "%2d. ", (_selectedItem + _numberingMode));
caretpos += fb.font().getStringWidth(temp); caretpos += _font.getStringWidth(temp);
} }
caretpos += fb.font().getStringWidth(_list[_selectedItem]); caretpos += _font.getStringWidth(_list[_selectedItem]);
return caretpos; return caretpos;
} }

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: PopUpWidget.cxx,v 1.9 2005-05-14 03:26:29 stephena Exp $ // $Id: PopUpWidget.cxx,v 1.10 2005-06-08 18:45:09 stephena Exp $
// //
// Based on code from ScummVM - Scumm Interpreter // Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project // Copyright (C) 2002-2004 The ScummVM project
@ -258,7 +258,8 @@ void PopUpDialog::drawMenuEntry(int entry, bool hilite)
fb.hLine(x, y + 1 + kLineHeight / 2, x + w, kColor); fb.hLine(x, y + 1 + kLineHeight / 2, x + w, kColor);
} }
else else
fb.font().drawString(name, x + 1, y + 2, w - 2, hilite ? kBGColor : kTextColor); fb.drawString(_popUpBoss->font(), name, x + 1, y + 2, w - 2,
hilite ? kBGColor : kTextColor);
} }
// //
@ -279,7 +280,7 @@ PopUpWidget::PopUpWidget(GuiObject* boss, int x, int y, int w, int h,
_selectedItem = -1; _selectedItem = -1;
if(!_label.empty() && _labelWidth == 0) if(!_label.empty() && _labelWidth == 0)
_labelWidth = instance()->frameBuffer().font().getStringWidth(_label); _labelWidth = _font.getStringWidth(_label);
myPopUpDialog = new PopUpDialog(this, x + getAbsX(), y + getAbsY()); myPopUpDialog = new PopUpDialog(this, x + getAbsX(), y + getAbsY());
} }
@ -355,8 +356,8 @@ void PopUpWidget::drawWidget(bool hilite)
// Draw the label, if any // Draw the label, if any
if (_labelWidth > 0) if (_labelWidth > 0)
fb.font().drawString(_label, _x, _y + 3, _labelWidth, fb.drawString(_font, _label, _x, _y + 3, _labelWidth,
isEnabled() ? kTextColor : kColor, kTextAlignRight); isEnabled() ? kTextColor : kColor, kTextAlignRight);
// Draw a thin frame around us. // Draw a thin frame around us.
fb.hLine(x, _y, x + w - 1, kColor); fb.hLine(x, _y, x + w - 1, kColor);
@ -371,9 +372,9 @@ void PopUpWidget::drawWidget(bool hilite)
// Draw the selected entry, if any // Draw the selected entry, if any
if(_selectedItem >= 0) if(_selectedItem >= 0)
{ {
TextAlignment align = (fb.font().getStringWidth(_entries[_selectedItem].name) > w-6) ? TextAlignment align = (_font.getStringWidth(_entries[_selectedItem].name) > w-6) ?
kTextAlignRight : kTextAlignLeft; kTextAlignRight : kTextAlignLeft;
fb.font().drawString(_entries[_selectedItem].name, x+2, _y+3, w-6, fb.drawString(_font, _entries[_selectedItem].name, x+2, _y+3, w-6,
!isEnabled() ? kColor : kTextColor, align); !isEnabled() ? kColor : kTextColor, align);
} }
} }

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: PromptDialog.cxx,v 1.3 2005-06-07 21:22:39 stephena Exp $ // $Id: PromptDialog.cxx,v 1.4 2005-06-08 18:45:09 stephena Exp $
// //
// Based on code from ScummVM - Scumm Interpreter // Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project // Copyright (C) 2002-2004 The ScummVM project
@ -26,12 +26,6 @@
#include "PromptDialog.hxx" #include "PromptDialog.hxx"
//#define kConsoleCharWidth (g_consolefont.getMaxCharWidth())
//#define kConsoleLineHeight (g_consolefont.getFontHeight() + 2)
#define kConsoleCharWidth (8)
#define kConsoleLineHeight (10 + 2)
#define PROMPT "> " #define PROMPT "> "
/* TODO: /* TODO:
@ -47,9 +41,12 @@ PromptDialog::PromptDialog(OSystem* osystem, DialogContainer* parent,
int x, int y, int w, int h) int x, int y, int w, int h)
: Dialog(osystem, parent, x, y, w, h) : Dialog(osystem, parent, x, y, w, h)
{ {
_kConsoleCharWidth = instance()->consoleFont().getMaxCharWidth();
_kConsoleLineHeight = instance()->consoleFont().getFontHeight() + 2;
// Calculate depending values // Calculate depending values
_lineWidth = (_w - kScrollBarWidth - 2) / kConsoleCharWidth; _lineWidth = (_w - kScrollBarWidth - 2) / _kConsoleCharWidth;
_linesPerPage = (_h - 2) / kConsoleLineHeight; _linesPerPage = (_h - 2) / _kConsoleLineHeight;
memset(_buffer, ' ', kBufferSize); memset(_buffer, ' ', kBufferSize);
_linesInBuffer = kBufferSize / _lineWidth; _linesInBuffer = kBufferSize / _lineWidth;
@ -121,10 +118,10 @@ void PromptDialog::drawDialog()
#else #else
char c = buffer((start + line) * _lineWidth + column); char c = buffer((start + line) * _lineWidth + column);
#endif #endif
fb.drawChar(c, x, y, kTextColor); fb.drawChar(instance()->consoleFont(), c, x, y, kTextColor);
x += kConsoleCharWidth; x += _kConsoleCharWidth;
} }
y += kConsoleLineHeight; y += _kConsoleLineHeight;
} }
// Draw the caret // Draw the caret
@ -174,7 +171,7 @@ void PromptDialog::handleKeyDown(int ascii, int keycode, int modifiers)
if (_callbackProc) if (_callbackProc)
keepRunning = (*_callbackProc)(this, str, _callbackRefCon); keepRunning = (*_callbackProc)(this, str, _callbackRefCon);
cerr << "Command entered: \'" << str << "\'\n"; cerr << "Command entered: \'" << str << "\'\n"; // FIXME - tie this into DebuggerParser
// Get rid of the string buffer // Get rid of the string buffer
delete [] str; delete [] str;
} }
@ -196,6 +193,7 @@ cerr << "Command entered: \'" << str << "\'\n";
instance()->frameBuffer().refresh(); instance()->frameBuffer().refresh();
break; break;
#if 0 // FIXME - this may not be included in the 2.0 release
case 9: // tab case 9: // tab
{ {
if (_completionCallbackProc) if (_completionCallbackProc)
@ -222,15 +220,15 @@ cerr << "Command entered: \'" << str << "\'\n";
} }
break; break;
} }
#endif
case 127: case 127:
killChar(1); killChar(+1);
draw(); draw();
instance()->frameBuffer().refresh(); instance()->frameBuffer().refresh();
break; break;
case 256 + 24: // pageup case 256 + 24: // pageup
if (1) // FIXME - shift modifiers == OSystem::KBD_SHIFT) if (instance()->eventHandler().kbdShift(modifiers))
{ {
_scrollLine -= _linesPerPage - 1; _scrollLine -= _linesPerPage - 1;
if (_scrollLine < _firstLineInBuffer + _linesPerPage - 1) if (_scrollLine < _firstLineInBuffer + _linesPerPage - 1)
@ -242,7 +240,7 @@ cerr << "Command entered: \'" << str << "\'\n";
break; break;
case 256 + 25: // pagedown case 256 + 25: // pagedown
if (1) // FIXME - shift modifiers == OSystem::KBD_SHIFT) if (instance()->eventHandler().kbdShift(modifiers))
{ {
_scrollLine += _linesPerPage - 1; _scrollLine += _linesPerPage - 1;
if (_scrollLine > _promptEndPos / _lineWidth) if (_scrollLine > _promptEndPos / _lineWidth)
@ -254,7 +252,7 @@ cerr << "Command entered: \'" << str << "\'\n";
break; break;
case 256 + 22: // home case 256 + 22: // home
if (0) // FIXME - shift modifiers == OSystem::KBD_SHIFT) if (instance()->eventHandler().kbdShift(modifiers))
{ {
_scrollLine = _firstLineInBuffer + _linesPerPage - 1; _scrollLine = _firstLineInBuffer + _linesPerPage - 1;
updateScrollBuffer(); updateScrollBuffer();
@ -267,7 +265,7 @@ cerr << "Command entered: \'" << str << "\'\n";
break; break;
case 256 + 23: // end case 256 + 23: // end
if (0) // FIXME - shift modifiers == OSystem::KBD_SHIFT) if (instance()->eventHandler().kbdShift(modifiers))
{ {
_scrollLine = _promptEndPos / _lineWidth; _scrollLine = _promptEndPos / _lineWidth;
if (_scrollLine < _linesPerPage - 1) if (_scrollLine < _linesPerPage - 1)
@ -308,11 +306,9 @@ cerr << "Command entered: \'" << str << "\'\n";
{ {
specialKeys(keycode); specialKeys(keycode);
} }
/*
else if (instance()->eventHandler().kbdAlt(modifiers)) else if (instance()->eventHandler().kbdAlt(modifiers))
{ {
} }
*/
else if (isprint(ascii)) else if (isprint(ascii))
{ {
for (i = _promptEndPos - 1; i >= _currentPos; i--) for (i = _promptEndPos - 1; i >= _currentPos; i--)
@ -370,7 +366,7 @@ void PromptDialog::specialKeys(int keycode)
break; break;
case 'd': case 'd':
killChar(1); killChar(+1);
handled = true; handled = true;
break; break;
@ -380,7 +376,7 @@ void PromptDialog::specialKeys(int keycode)
break; break;
case 'k': case 'k':
killLine(1); killLine(+1);
handled = true; handled = true;
break; break;
@ -643,12 +639,12 @@ void PromptDialog::drawCaret()
int line = _currentPos / _lineWidth; int line = _currentPos / _lineWidth;
int displayLine = line - _scrollLine + _linesPerPage - 1; int displayLine = line - _scrollLine + _linesPerPage - 1;
int x = _x + 1 + (_currentPos % _lineWidth) * kConsoleCharWidth; int x = _x + 1 + (_currentPos % _lineWidth) * _kConsoleCharWidth;
int y = _y + displayLine * kConsoleLineHeight; int y = _y + displayLine * _kConsoleLineHeight;
char c = buffer(_currentPos); char c = buffer(_currentPos);
fb.fillRect(x, y, kConsoleCharWidth, kConsoleLineHeight, kTextColor); fb.fillRect(x, y, _kConsoleCharWidth, _kConsoleLineHeight, kTextColor);
fb.drawChar(c, x, y + 2, kBGColor); fb.drawChar(instance()->consoleFont(), c, x, y + 2, kBGColor);
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: PromptDialog.hxx,v 1.2 2005-06-07 19:01:53 stephena Exp $ // $Id: PromptDialog.hxx,v 1.3 2005-06-08 18:45:09 stephena Exp $
// //
// Based on code from ScummVM - Scumm Interpreter // Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project // Copyright (C) 2002-2004 The ScummVM project
@ -118,6 +118,8 @@ class PromptDialog : public Dialog
int _historySize; int _historySize;
int _historyIndex; int _historyIndex;
int _historyLine; int _historyLine;
int _kConsoleCharWidth, _kConsoleLineHeight;
}; };
#endif #endif

View File

@ -1,150 +0,0 @@
//============================================================================
//
// 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.3 2005-05-13 18:28:06 stephena Exp $
//
// Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project
//============================================================================
#include "FrameBuffer.hxx"
#include "GuiUtils.hxx"
#include "FontData.hxx"
#include "StellaFont.hxx"
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
StellaFont::StellaFont(FrameBuffer* buffer)
: myFrameBuffer(buffer)
{
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)
};
myFontDesc = desc;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
int 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];
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
int StellaFont::getStringWidth(const string& str) const
{
int space = 0;
for(unsigned int i = 0; i < str.size(); ++i)
space += getCharWidth(str[i]);
return space;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void StellaFont::drawString(const string& s, int x, int y, int w,
OverlayColor color, TextAlignment align,
int deltax, bool useEllipsis) const
{
const int leftX = x, rightX = x + w;
unsigned int i;
int 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;
}
}

File diff suppressed because it is too large Load Diff

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: TabWidget.cxx,v 1.2 2005-05-13 18:28:06 stephena Exp $ // $Id: TabWidget.cxx,v 1.3 2005-06-08 18:45:09 stephena Exp $
// //
// Based on code from ScummVM - Scumm Interpreter // Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project // Copyright (C) 2002-2004 The ScummVM project
@ -67,8 +67,6 @@ int TabWidget::getChildY() const
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
int TabWidget::addTab(const string& title) int TabWidget::addTab(const string& title)
{ {
FrameBuffer& fb = instance()->frameBuffer();
// Add a new tab page // Add a new tab page
Tab newTab; Tab newTab;
newTab.title = title; newTab.title = title;
@ -79,7 +77,7 @@ int TabWidget::addTab(const string& title)
int numTabs = _tabs.size(); int numTabs = _tabs.size();
// Determine the new tab width // Determine the new tab width
int newWidth = fb.font().getStringWidth(title) + 2 * kTabPadding; int newWidth = _font.getStringWidth(title) + 2 * kTabPadding;
if (_tabWidth < newWidth) if (_tabWidth < newWidth)
_tabWidth = newWidth; _tabWidth = newWidth;
@ -181,7 +179,9 @@ void TabWidget::drawWidget(bool hilite)
OverlayColor color = (i == _activeTab) ? kColor : kShadowColor; OverlayColor color = (i == _activeTab) ? kColor : kShadowColor;
int yOffset = (i == _activeTab) ? 0 : 2; int yOffset = (i == _activeTab) ? 0 : 2;
box(x, _y + yOffset, _tabWidth, kTabHeight - yOffset, color, color, (i == _activeTab)); box(x, _y + yOffset, _tabWidth, kTabHeight - yOffset, color, color, (i == _activeTab));
fb.font().drawString(_tabs[i].title, x + kTabPadding, _y + yOffset / 2 + (kTabHeight - kLineHeight - 1), _tabWidth - 2 * kTabPadding, kTextColor, kTextAlignCenter); fb.drawString(_font, _tabs[i].title, x + kTabPadding,
_y + yOffset / 2 + (kTabHeight - kLineHeight - 1),
_tabWidth - 2 * kTabPadding, kTextColor, kTextAlignCenter);
x += _tabWidth + kTabSpacing; x += _tabWidth + kTabSpacing;
} }

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: Widget.cxx,v 1.11 2005-05-26 18:56:58 stephena Exp $ // $Id: Widget.cxx,v 1.12 2005-06-08 18:45:09 stephena Exp $
// //
// Based on code from ScummVM - Scumm Interpreter // Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project // Copyright (C) 2002-2004 The ScummVM project
@ -21,7 +21,7 @@
#include "OSystem.hxx" #include "OSystem.hxx"
#include "FrameBuffer.hxx" #include "FrameBuffer.hxx"
#include "StellaFont.hxx" #include "Font.hxx"
#include "Dialog.hxx" #include "Dialog.hxx"
#include "Command.hxx" #include "Command.hxx"
#include "GuiObject.hxx" #include "GuiObject.hxx"
@ -36,7 +36,9 @@ Widget::Widget(GuiObject* boss, int x, int y, int w, int h)
_boss(boss), _boss(boss),
_id(0), _id(0),
_flags(0), _flags(0),
_hasFocus(false) _hasFocus(false),
_color(kTextColor),
_font((GUI::Font&)boss->instance()->font())
{ {
// Insert into the widget list of the boss // Insert into the widget list of the boss
_next = _boss->_firstWidget; _next = _boss->_firstWidget;
@ -125,8 +127,7 @@ Widget* Widget::findWidgetInChain(Widget *w, int x, int y)
StaticTextWidget::StaticTextWidget(GuiObject *boss, int x, int y, int w, int h, StaticTextWidget::StaticTextWidget(GuiObject *boss, int x, int y, int w, int h,
const string& text, TextAlignment align) const string& text, TextAlignment align)
: Widget(boss, x, y, w, h), : Widget(boss, x, y, w, h),
_align(align), _align(align)
_color(kTextColor)
{ {
_flags = WIDGET_ENABLED; _flags = WIDGET_ENABLED;
_type = kStaticTextWidget; _type = kStaticTextWidget;
@ -149,8 +150,8 @@ void StaticTextWidget::setValue(int value)
void StaticTextWidget::drawWidget(bool hilite) void StaticTextWidget::drawWidget(bool hilite)
{ {
FrameBuffer& fb = _boss->instance()->frameBuffer(); FrameBuffer& fb = _boss->instance()->frameBuffer();
fb.font().drawString(_label, _x, _y, _w, fb.drawString(_font, _label, _x, _y, _w,
isEnabled() ? _color : kColor, _align); isEnabled() ? _color : kColor, _align);
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -176,9 +177,8 @@ void ButtonWidget::handleMouseUp(int x, int y, int button, int clickCount)
void ButtonWidget::drawWidget(bool hilite) void ButtonWidget::drawWidget(bool hilite)
{ {
FrameBuffer& fb = _boss->instance()->frameBuffer(); FrameBuffer& fb = _boss->instance()->frameBuffer();
fb.font().drawString(_label, _x, _y + (_h - kLineHeight)/2 + 1, _w, fb.drawString(_font, _label, _x, _y + (_h - kLineHeight)/2 + 1, _w,
!isEnabled() ? kColor : !isEnabled() ? kColor : hilite ? kTextColorHi : _color, _align);
hilite ? kTextColorHi : _color, _align);
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -244,8 +244,7 @@ void CheckboxWidget::drawWidget(bool hilite)
fb.fillRect(_x + 2, _y + 2, 10, 10, kBGColor); fb.fillRect(_x + 2, _y + 2, 10, 10, kBGColor);
// Finally draw the label // Finally draw the label
fb.font().drawString(_label, _x + 20, _y + 3, _w, fb.drawString(_font, _label, _x + 20, _y + 3, _w, isEnabled() ? _color : kColor);
isEnabled() ? _color : kColor);
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -315,8 +314,8 @@ void SliderWidget::drawWidget(bool hilite)
// Draw the label, if any // Draw the label, if any
if(_labelWidth > 0) if(_labelWidth > 0)
fb.font().drawString(_label, _x, _y + 2, _labelWidth, fb.drawString(_font, _label, _x, _y + 2, _labelWidth,
isEnabled() ? _color : kColor, kTextAlignRight); isEnabled() ? _color : kColor, kTextAlignRight);
// Draw the box // Draw the box
fb.box(_x + _labelWidth, _y, _w - _labelWidth, _h, kColor, kShadowColor); fb.box(_x + _labelWidth, _y, _w - _labelWidth, _h, kColor, kShadowColor);

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: Widget.hxx,v 1.13 2005-05-26 15:43:44 stephena Exp $ // $Id: Widget.hxx,v 1.14 2005-06-08 18:45:09 stephena Exp $
// //
// Based on code from ScummVM - Scumm Interpreter // Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project // Copyright (C) 2002-2004 The ScummVM project
@ -27,7 +27,6 @@ class Dialog;
#include <assert.h> #include <assert.h>
#include "OSystem.hxx" #include "OSystem.hxx"
#include "StellaFont.hxx"
#include "FrameBuffer.hxx" #include "FrameBuffer.hxx"
#include "GuiObject.hxx" #include "GuiObject.hxx"
#include "bspf.hxx" #include "bspf.hxx"
@ -65,7 +64,7 @@ enum {
This is the base class for all widgets. This is the base class for all widgets.
@author Stephen Anthony @author Stephen Anthony
@version $Id: Widget.hxx,v 1.13 2005-05-26 15:43:44 stephena Exp $ @version $Id: Widget.hxx,v 1.14 2005-06-08 18:45:09 stephena Exp $
*/ */
class Widget : public GuiObject class Widget : public GuiObject
{ {
@ -107,6 +106,10 @@ class Widget : public GuiObject
bool isEnabled() const { return _flags & WIDGET_ENABLED; } bool isEnabled() const { return _flags & WIDGET_ENABLED; }
bool isVisible() const { return !(_flags & WIDGET_INVISIBLE); } bool isVisible() const { return !(_flags & WIDGET_INVISIBLE); }
void setColor(OverlayColor color) { _color = color; }
void setFont(const GUI::Font& font) { _font = font; }
const GUI::Font& font() { return _font; }
protected: protected:
virtual void drawWidget(bool hilite) {} virtual void drawWidget(bool hilite) {}
@ -122,12 +125,14 @@ class Widget : public GuiObject
{ assert(_boss); _boss->handleCommand(sender, cmd, data); } { assert(_boss); _boss->handleCommand(sender, cmd, data); }
protected: protected:
int _type; int _type;
GuiObject* _boss; GuiObject* _boss;
Widget* _next; Widget* _next;
int _id; int _id;
int _flags; int _flags;
bool _hasFocus; bool _hasFocus;
OverlayColor _color;
GUI::Font& _font;
public: public:
static Widget* findWidgetInChain(Widget* start, int x, int y); static Widget* findWidgetInChain(Widget* start, int x, int y);
@ -142,7 +147,6 @@ class StaticTextWidget : public Widget
int x, int y, int w, int h, int x, int y, int w, int h,
const string& text, TextAlignment align); const string& text, TextAlignment align);
void setValue(int value); void setValue(int value);
void setColor(OverlayColor color) { _color = color; }
void setAlign(TextAlignment align) { _align = align; } void setAlign(TextAlignment align) { _align = align; }
void setLabel(const string& label) { _label = label; void setLabel(const string& label) { _label = label;
_boss->instance()->frameBuffer().refresh(); _boss->instance()->frameBuffer().refresh();
@ -155,7 +159,6 @@ class StaticTextWidget : public Widget
protected: protected:
string _label; string _label;
TextAlignment _align; TextAlignment _align;
OverlayColor _color;
}; };