Parser skeleton

Expanded drawing interface

svn-id: r32678
This commit is contained in:
Vicent Marti 2008-06-12 19:06:37 +00:00
parent 5dd77ea820
commit 7a9a74691f
6 changed files with 226 additions and 6 deletions

View file

@ -1204,6 +1204,14 @@
RelativePath="..\..\gui\ThemeModern.cpp"
>
</File>
<File
RelativePath="..\..\gui\ThemeParser.cpp"
>
</File>
<File
RelativePath="..\..\gui\ThemeParser.h"
>
</File>
<File
RelativePath="..\..\gui\widget.cpp"
>

View file

@ -123,6 +123,40 @@ void InterfaceManager::drawLineSeparator(const Common::Rect &r, WidgetStateInfo
addDirtyRect(r);
}
void InterfaceManager::drawCheckbox(const Common::Rect &r, const Common::String &str, bool checked, WidgetStateInfo state) {
if (!_initOk)
return;
drawDD(checked ? kDDCheckboxEnabled : kDDCheckboxDisabled, r);
Common::Rect r2 = r;
r2.left += 16; // TODO: add variable for checkbox text offset.
// TODO: text drawing
// getFont()->drawString(&_screen, str, r2.left, r2.top, r2.width(), getColor(state), Graphics::kTextAlignLeft, 0, false);
addDirtyRect(r);
}
void InterfaceManager::drawSlider(const Common::Rect &r, int width, WidgetStateInfo state) {
if (!_initOk)
return;
drawDD(kDDSliderEmpty, r);
Common::Rect r2 = r;
r2.setWidth(MIN((int16)width, r.width()));
drawDD(kDDSliderFull, r2);
addDirtyRect(r);
}
void InterfaceManager::drawScrollbar(const Common::Rect &r, int sliderY, int sliderHeight, ScrollbarState sb_state, WidgetStateInfo state) {
if (!_initOk)
return;
}
int InterfaceManager::runGUI() {
Common::EventManager *eventMan = _system->getEventManager();
_system->showOverlay();

View file

@ -73,8 +73,10 @@ public:
kDDTab,
kDDScrollBarBase,
kDDScrollBarHandle,
kDDScrollbarBase,
kDDScrollbarButtonTop,
kDDScrollbarButtonBottom,
kDDScrollbarHandle,
kDDPopUp,
kDDCaret,
@ -155,12 +157,12 @@ public:
/** Widget drawing */
void drawWidgetBackground(const Common::Rect &r, uint16 hints, WidgetBackground background = kWidgetBackgroundPlain, WidgetStateInfo state = kStateEnabled) {}
void drawButton(const Common::Rect &r, const Common::String &str, WidgetStateInfo state = kStateEnabled, uint16 hints = 0); // {}
void drawButton(const Common::Rect &r, const Common::String &str, WidgetStateInfo state = kStateEnabled, uint16 hints = 0);
void drawSurface(const Common::Rect &r, const Graphics::Surface &surface, WidgetStateInfo state = kStateEnabled, int alpha = 256, bool themeTrans = false) {}
void drawSlider(const Common::Rect &r, int width, WidgetStateInfo state = kStateEnabled) {}
void drawCheckbox(const Common::Rect &r, const Common::String &str, bool checked, WidgetStateInfo state = kStateEnabled) {}
void drawSlider(const Common::Rect &r, int width, WidgetStateInfo state = kStateEnabled);
void drawCheckbox(const Common::Rect &r, const Common::String &str, bool checked, WidgetStateInfo state = kStateEnabled);
void drawTab(const Common::Rect &r, int tabHeight, int tabWidth, const Common::Array<Common::String> &tabs, int active, uint16 hints, int titleVPad, WidgetStateInfo state = kStateEnabled) {}
void drawScrollbar(const Common::Rect &r, int sliderY, int sliderHeight, ScrollbarState, WidgetStateInfo state = kStateEnabled) {}
void drawScrollbar(const Common::Rect &r, int sliderY, int sliderHeight, ScrollbarState, WidgetStateInfo state = kStateEnabled);
void drawPopUpWidget(const Common::Rect &r, const Common::String &sel, int deltax, WidgetStateInfo state = kStateEnabled, TextAlign align = kTextAlignLeft) {}
void drawCaret(const Common::Rect &r, bool erase, WidgetStateInfo state = kStateEnabled) {}
void drawLineSeparator(const Common::Rect &r, WidgetStateInfo state = kStateEnabled);

111
gui/ThemeParser.cpp Normal file
View file

@ -0,0 +1,111 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* $URL$
* $Id$
*
*/
#include "common/util.h"
#include "common/system.h"
#include "common/events.h"
#include "gui/ThemeParser.h"
/**
<drawdata = "background_default" cache = true>
<draw func = "roundedsq" fill = "gradient" gradient_start = "255, 255, 128" gradient_end = "128, 128, 128" size = "auto">
<draw func = "roundedsq" fill = "none" color = "0, 0, 0" size = "auto">
</drawdata>
*/
namespace GUI {
inline bool isValidNameChar(char c) {
return !isspace(c) && c != '/' && c != '*' && c != '\\' &&
c != '|' && c != '"' && c != '\'' && c != ',' &&
c != '<' && c != '>' && c != '=';
}
void ThemeParser::parserError(const char *error_string) {
_state = kParserError;
}
bool ThemeParser::parseDrawData() {
_state = kParserNeedKey;
while (_text[_pos++]) {
while (isspace(_text[_pos]))
_pos++;
// comment handling: skip everything between /* and */
if (_text[_pos] == '/') {
if (_text[++_pos] != '*') {
parserError("Malformed comment string.");
return false;
}
_pos++;
while (_text[_pos] != '*' && _text[_pos + 1] != '/')
_pos++;
}
switch (_state) {
case kParserNeedKey:
if (_text[_pos] != '<') {
parserError("Expecting key start.");
return false;
}
_state = kParserKeyNeedName;
break;
case kParserKeyNeedName:
_token.clear();
while (isValidNameChar(_text[_pos]))
_token += _text[_pos++];
if (!isspace(_text[_pos])) {
parserError("Invalid character in token name.");
return false;
}
_state = kParserKeyNeedToken;
break;
case kParserKeyNeedToken:
_token.clear();
break;
default:
return false;
}
}
return true;
}
}

64
gui/ThemeParser.h Normal file
View file

@ -0,0 +1,64 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* $URL$
* $Id$
*
*/
#ifndef THEME_PARSER_H
#define THEME_PARSER_H
#include "common/scummsys.h"
#include "graphics/surface.h"
#include "common/system.h"
namespace GUI {
class ThemeParser {
ThemeParser() {}
~ThemeParser() {}
enum ParserState {
kParserKeyNeedName,
kParserKeyNeedToken,
kParserKeyNeedSubkey,
kParserNeedKey,
kParserInComment,
kParserError
};
bool parseDrawData();
void parserError(const char *error_string);
protected:
int _pos;
char *_text;
ParserState _state;
Common::String _error;
Common::String _token;
};
}
#endif

View file

@ -26,6 +26,7 @@ MODULE_OBJS := \
theme.o \
ThemeClassic.o \
ThemeModern.o \
ThemeParser.o \
theme-config.o
# Include common rules