Ticket #8388: scaleableGui-v2.patch

File scaleableGui-v2.patch, 9.3 KB (added by lordhoto, 19 years ago)

patch on top of 'scaleableGui-v1.patch'

  • graphics/font.cpp

    diff -u --rec -N --exclude=CVS --exclude=.deps --exclude=*.o scummvm.old/graphics/font.cpp scummvm/graphics/font.cpp
    old new  
    3737        return desc.width[chr - desc.firstchar];
    3838}
    3939
    40 void NewFont::drawChar(const Surface *dst, byte chr, int tx, int ty, uint32 color) const {
     40void NewFont::drawChar(const Surface *dst, byte chr, int tx, int ty, uint32 color, bool scale) const {
    4141        assert(dst != 0);
    42         const int scaleFactorWidth = g_gui.getScaleFactorWidth(), scaleFactorHeight = g_gui.getScaleFactorHeight();
     42        const int scaleFactorWidth = scale ? g_gui.getScaleFactorWidth() : 1, scaleFactorHeight = scale ? g_gui.getScaleFactorHeight() : 1;
    4343        tx *= scaleFactorWidth; ty *= scaleFactorHeight;
    4444
    4545        byte *ptr = (byte *)dst->getBasePtr(tx, ty);
     
    102102        return space;
    103103}
    104104
    105 void Font::drawString(const Surface *dst, const Common::String &s, int x, int y, int w, uint32 color, TextAlignment align, int deltax, bool useEllipsis) const {
     105void Font::drawString(const Surface *dst, const Common::String &s, int x, int y, int w, uint32 color, TextAlignment align, int deltax, bool useEllipsis, bool scale) const {
    106106        assert(dst != 0);
    107107        const int leftX = x, rightX = x + w;
    108108        uint i;
     
    167167                if (x+w > rightX)
    168168                        break;
    169169                if (x >= leftX)
    170                         drawChar(dst, str[i], x, y, color);
     170                        drawChar(dst, str[i], x, y, color, scale);
    171171                x += w;
    172172        }
    173173}
  • graphics/font.h

    diff -u --rec -N --exclude=CVS --exclude=.deps --exclude=*.o scummvm.old/graphics/font.h scummvm/graphics/font.h
    old new  
    3535
    3636/**
    3737 * Instances of this class represent a distinct font, with a built-in renderer.
    38  * @todo Maybe move the high-level methods (drawString etc.) to a separate 
     38 * @todo Maybe move the high-level methods (drawString etc.) to a separate
    3939 *       FontRenderer class? That way, we could have different variants... ?
    4040 * @todo Add more parameters to drawString, or additional similar methods,
    4141 *       featuring abilities like
     
    5252        virtual int getMaxCharWidth() const = 0;
    5353
    5454        virtual int getCharWidth(byte chr) const = 0;
    55         virtual void drawChar(const Surface *dst, byte chr, int x, int y, uint32 color) const = 0;
     55        virtual void drawChar(const Surface *dst, byte chr, int x, int y, uint32 color, bool scale = false) const = 0;
    5656
    57         void drawString(const Surface *dst, const Common::String &str, int x, int y, int w, uint32 color, TextAlignment align = kTextAlignLeft, int deltax = 0, bool useEllipsis = true) const;
     57        void drawString(const Surface *dst, const Common::String &str, int x, int y, int w, uint32 color, TextAlignment align = kTextAlignLeft, int deltax = 0, bool useEllipsis = true, bool scale = false) const;
    5858        int getStringWidth(const Common::String &str) const;
    5959};
    6060
     
    6565        virtual int getMaxCharWidth() const { return 8; };
    6666
    6767        virtual int getCharWidth(byte chr) const;
    68         virtual void drawChar(const Surface *dst, byte chr, int x, int y, uint32 color) const;
     68        virtual void drawChar(const Surface *dst, byte chr, int x, int y, uint32 color, bool scale) const;
    6969};
    7070
    7171extern const ScummFont g_scummfont;
     
    9696
    9797public:
    9898        NewFont(const FontDesc &d) : desc(d) {}
    99        
     99
    100100        virtual int getFontHeight() const { return desc.height; }
    101101        virtual int getMaxCharWidth() const { return desc.maxwidth; };
    102102
    103103        virtual int getCharWidth(byte chr) const;
    104         virtual void drawChar(const Surface *dst, byte chr, int x, int y, uint32 color) const;
     104        virtual void drawChar(const Surface *dst, byte chr, int x, int y, uint32 color, bool scale) const;
    105105};
    106106
    107107extern const NewFont g_sysfont;
  • graphics/scummfont.cpp

    Binary files scummvm.old/graphics/libgraphics.a and scummvm/graphics/libgraphics.a differ
    diff -u --rec -N --exclude=CVS --exclude=.deps --exclude=*.o scummvm.old/graphics/scummfont.cpp scummvm/graphics/scummfont.cpp
    old new  
    6363}
    6464
    6565//void ScummFont::drawChar(byte chr, int xx, int yy, OverlayColor color) {
    66 void ScummFont::drawChar(const Surface *dst, byte chr, int tx, int ty, uint32 color) const {
     66void ScummFont::drawChar(const Surface *dst, byte chr, int tx, int ty, uint32 color, bool scale) const {
    6767        assert(dst != 0);
    68         const int scaleFactorWidth = g_gui.getScaleFactorWidth(), scaleFactorHeight = g_gui.getScaleFactorHeight();
     68        const int scaleFactorWidth = scale ? g_gui.getScaleFactorWidth() : 1, scaleFactorHeight = scale ? g_gui.getScaleFactorHeight() : 1;
    6969        tx *= scaleFactorWidth; ty *= scaleFactorHeight;
    7070
    7171        byte *ptr = (byte *)dst->getBasePtr(tx, ty);
  • gui/console.cpp

    diff -u --rec -N --exclude=CVS --exclude=.deps --exclude=*.o scummvm.old/gui/console.cpp scummvm/gui/console.cpp
    old new  
    4949 * - a *lot* of others things, this code is in no way complete and heavily under progress
    5050 */
    5151ConsoleDialog::ConsoleDialog(float widthPercent, float heightPercent)
    52         : Dialog(0, 0, 1, 1), 
     52        : Dialog(0, 0, 1, 1),
    5353        _widthPercent(widthPercent), _heightPercent(heightPercent) {
    54        
     54
    5555        // Setup basic layout/dialog size
    5656        reflowLayout();
    5757
     
    111111}
    112112
    113113void ConsoleDialog::open() {
     114        g_gui.enableScaling(false);
     115
    114116        // Initiate sliding the console down. We do a very simple trick to achieve
    115117        // this effect: we simply move the console dialog just above (outside) the
    116118        // visible screen area, then shift it down in handleTickle() over a
    117         // certain period of time. 
     119        // certain period of time.
    118120        _y = -_h;
    119121        _slideTime = g_system->getMillis();
    120122        _slideMode = kDownSlideMode;
     
    165167                _caretTime = time + kCaretBlinkTime;
    166168                drawCaret(_caretVisible);
    167169        }
    168        
     170
    169171        // Perform the "slide animation".
    170172        if (_slideMode != kNoSlideMode) {
    171173                const float tmp = (float)(g_system->getMillis() - _slideTime) / kConsoleSlideDownDuration;
     
    174176                } else {
    175177                        _y = (int)(_h * (tmp - 1.0));
    176178                }
    177                
     179
    178180                if (_slideMode == kDownSlideMode && _y > 0) {
    179181                        // End the slide
    180182                        _slideMode = kNoSlideMode;
     
    195197
    196198void ConsoleDialog::handleKeyDown(uint16 ascii, int keycode, int modifiers) {
    197199        int i;
    198        
     200
    199201        if (_slideMode != kNoSlideMode)
    200202                return;
    201203
     
    204206        case '\r': {
    205207                if (_caretVisible)
    206208                        drawCaret(true);
    207                        
     209
    208210                nextLine();
    209211
    210212                assert(_promptEndPos >= _promptStartPos);
     
    217219                        // We have to allocate the string buffer with new, since VC++ sadly does not
    218220                        // comply to the C++ standard, so we can't use a dynamic sized stack array.
    219221                        char *str = new char[len + 1];
    220        
     222
    221223                        // Copy the user input to str
    222224                        for (i = 0; i < len; i++)
    223225                                str[i] = buffer(_promptStartPos + i);
  • gui/newgui.cpp

    Binary files scummvm.old/gui/libgui.a and scummvm/gui/libgui.a differ
    diff -u --rec -N --exclude=CVS --exclude=.deps --exclude=*.o scummvm.old/gui/newgui.cpp scummvm/gui/newgui.cpp
    old new  
    5454
    5555
    5656// Constructor
    57 NewGui::NewGui() : _needRedraw(false),
     57NewGui::NewGui() : _scaleEnable(true), _needRedraw(false),
    5858        _stateIsSaved(false), _cursorAnimateCounter(0), _cursorAnimateTimer(0) {
    5959
    6060        _system = OSystem::instance();
     
    7979}
    8080
    8181void NewGui::updateScaleFactor() {
     82        if(!_scaleEnable) {
     83                _scaleFactorWidth = _scaleFactorHeight = 1;
     84                return;
     85        }
     86
    8287        const int16 stdGuiWidth = 320;
    8388        const int16 stdGuiHeight = 200;
    8489
     
    225230        _lastClick.count = 0;
    226231
    227232        _stateIsSaved = true;
     233        _scaleEnable = true;
    228234}
    229235
    230236void NewGui::restoreState() {
     
    348354void NewGui::drawChar(byte chr, int xx, int yy, OverlayColor color, const Graphics::Font *font) {
    349355        if (font == 0)
    350356                font = &getFont();
    351         font->drawChar(&_screen, chr, xx, yy, color);
     357        font->drawChar(&_screen, chr, xx, yy, color, _scaleEnable);
    352358}
    353359
    354360int NewGui::getStringWidth(const String &str) {
    355         return getFont().getStringWidth(str) * _scaleFactorWidth;
     361        int width = 0;
     362        for (uint p = 0; p < str.size(); p++)
     363                width += getCharWidth(str[p]);
     364        return width;
    356365}
    357366
    358367int NewGui::getCharWidth(byte c) {
    359         return getFont().getCharWidth(c) * _scaleFactorWidth;
     368        return getFont().getCharWidth(c) * c != ' ' ? _scaleFactorWidth : 1;
    360369}
    361370
    362371void NewGui::drawString(const String &s, int x, int y, int w, OverlayColor color, TextAlignment align, int deltax, bool useEllipsis) {
    363         getFont().drawString(&_screen, s, x, y, w, color, align, deltax, useEllipsis);
     372        getFont().drawString(&_screen, s, x, y, w, color, align, deltax, useEllipsis, _scaleEnable);
    364373}
    365374
    366375//
  • gui/newgui.h

    diff -u --rec -N --exclude=CVS --exclude=.deps --exclude=*.o scummvm.old/gui/newgui.h scummvm/gui/newgui.h
    old new  
    6868
    6969        int getScaleFactorWidth() { return _scaleFactorWidth; }
    7070        int getScaleFactorHeight() { return _scaleFactorHeight; }
     71        void enableScaling(bool enable) { _scaleEnable = enable; updateScaleFactor(); }
    7172
    7273protected:
    7374        OSystem                 *_system;
     
    7677
    7778        int                     _scaleFactorWidth;
    7879        int                     _scaleFactorHeight;
     80        bool                    _scaleEnable;
    7981
    8082        bool            _needRedraw;
    8183        DialogStack     _dialogStack;