put stuff in util.h into namespace ScummVM; fixed stupid bug in String class; took painelf's patch which implements save/load dialog in new GUI and fixed it slightly; various other minor changes

svn-id: r4591
This commit is contained in:
Max Horn 2002-07-18 20:26:35 +00:00
parent d66c9ea2b2
commit 6e6c3c3c96
9 changed files with 98 additions and 48 deletions

View File

@ -27,8 +27,13 @@
/*
* TODO:
* - Allow escape to abort changes
* - Add key repeat (for backspace, etc)
* - Abort changes when ESC is pressed or the selection changes
* - When the editing of a string is ended by return, we might consider sending
* a message. Return means that the edit was confirmed. Hence the SaveDialog
* could immediatly do the save in a trivial fashion.
* - Handle double clicks: either start editing of the selected item, or
* send a cmd to our target (i.e. as specified via setCmd or setDoubleCmd)
* This will allow a double click in the load dialog to immediatly load the game
*/
@ -37,13 +42,13 @@
ListWidget::ListWidget(Dialog *boss, int x, int y, int w, int h)
: Widget(boss, x, y, w - kScrollBarWidth, h)
: Widget(boss, x, y, w - kScrollBarWidth, h), CommandSender(boss)
{
_flags = WIDGET_ENABLED | WIDGET_CLEARBG | WIDGET_RETAIN_FOCUS | WIDGET_WANT_TICKLE;
_type = kListWidget;
_numberingMode = kListNumberingOne;
_entriesPerPage = (_h - 4) / LINE_HEIGHT;
_currentPos = 3;
_currentPos = 0;
_selectedItem = -1;
_scrollBar = new ScrollBarWidget(boss, _x + _w, _y, kScrollBarWidth, _h);
_scrollBar->setTarget(this);
@ -53,38 +58,20 @@ ListWidget::ListWidget(Dialog *boss, int x, int y, int w, int h)
_editable = true;
_editMode = false;
// FIXME - fill in dummy data for now
_list.push_back("A simple game?");
_list.push_back("This space for rent!");
_list.push_back("To be or not to be...");
_list.push_back("It's not easy come up with dummy text :-)");
_list.push_back("Foo bar baz");
_list.push_back("Empty slots follow:");
_list.push_back("");
_list.push_back("");
_list.push_back("Now again a filled slot");
_list.push_back("We need some more text!");
_list.push_back("Because only this way...");
_list.push_back("...can you see the scrollbar...");
_list.push_back("...and verify that it works!");
_list.push_back("One");
_list.push_back("Two");
_list.push_back("Three");
_list.push_back("Four");
_list.push_back("The End");
_scrollBar->_numEntries = _list.size();
_scrollBar->_entriesPerPage = _entriesPerPage;
_scrollBar->_currentPos = _currentPos;
_scrollBar->recalc();
}
ListWidget::~ListWidget()
{
}
void ListWidget::scrollBarRecalc()
{
_scrollBar->_numEntries = _list.size();
_scrollBar->_entriesPerPage = _entriesPerPage;
_scrollBar->_currentPos = _currentPos;
_scrollBar->recalc();
}
void ListWidget::handleMouseDown(int x, int y, int button)
{
int oldSelectedItem = _selectedItem;
@ -220,19 +207,19 @@ void ListWidget::handleCommand(CommandSender *sender, uint32 cmd, uint32 data)
void ListWidget::drawWidget(bool hilite)
{
NewGui *gui = _boss->getGui();
int i, pos;
String buffer;
NewGui *gui = _boss->getGui();
int i, pos, len = _list.size();
ScummVM::String buffer;
// Draw the list items
// FIXME - this is just a temporary demo hack
for (i = 0, pos = _currentPos; i < _entriesPerPage; i++, pos++) {
for (i = 0, pos = _currentPos; i < _entriesPerPage && pos < len; i++, pos++) {
if (_numberingMode == kListNumberingZero || _numberingMode == kListNumberingOne) {
char temp[10];
sprintf(temp, "%2d. ", (pos + _numberingMode));
buffer = temp;
} else
buffer = "";
buffer += _list[pos];
gui->drawString(buffer, _x+5, _y+2 + LINE_HEIGHT * i, _w - 10,

View File

@ -33,7 +33,8 @@ enum {
};
/* ListWidget */
class ListWidget : public Widget, public CommandReceiver {
class ListWidget : public Widget, public CommandReceiver, public CommandSender {
typedef ScummVM::StringList StringList;
protected:
StringList _list;
bool _editable;
@ -48,9 +49,10 @@ public:
ListWidget(Dialog *boss, int x, int y, int w, int h);
virtual ~ListWidget();
void setList(const StringList& list) { _list = list; }
void setList(const StringList& list) { _list = list; scrollBarRecalc(); }
const StringList& getList() const { return _list; }
int getSelected() const { return _selectedItem; }
const ScummVM::String& getSelectedString() const { return _list[_selectedItem]; }
void setNumberingMode(int numberingMode) { _numberingMode = numberingMode; }
virtual void handleMouseDown(int x, int y, int button);
@ -58,6 +60,8 @@ public:
virtual void handleKeyUp(char key, int modifiers);
virtual void handleCommand(CommandSender *sender, uint32 cmd, uint32 data);
void scrollBarRecalc();
protected:
void drawWidget(bool hilite);
void lostFocusWidget();

View File

@ -29,6 +29,8 @@
* - Auto-repeat: if one clicks & holds on one of the arrows, then after a
* brief delay, it should start to contiously scroll
* - Allow for a horizontal scrollbar, too?
* - If there are less items than fit on one pages, no scrolling can be done
* and we thus should not highlight the arrows/slider.
*/
#define UP_DOWN_BOX_HEIGHT 10
@ -172,8 +174,8 @@ void ScrollBarWidget::checkBounds(int old_pos)
void ScrollBarWidget::recalc()
{
_sliderHeight = (_h - 2 * UP_DOWN_BOX_HEIGHT) * _entriesPerPage / _numEntries;
if (_sliderHeight < 4)
_sliderHeight = 4;
if (_sliderHeight < UP_DOWN_BOX_HEIGHT)
_sliderHeight = UP_DOWN_BOX_HEIGHT;
_sliderPos =
UP_DOWN_BOX_HEIGHT + (_h - 2 * UP_DOWN_BOX_HEIGHT - _sliderHeight + 1) * _currentPos / (_numEntries -

View File

@ -24,6 +24,7 @@
#include "newgui.h"
#include "dialog.h"
#include "widget.h"
#include "scumm.h"
#include "ListWidget.h"
Dialog::~Dialog()
@ -248,6 +249,15 @@ enum {
kQuitCmd = 'QUIT'
};
/*
* TODO
* - Maybe go back to the old way of differentiating between the save and the load mode?
* This would include that in the load mode the list is not editable.
* - Currently the savegame list is only loaded once when the dialog is created. Instead,
* it should be loaded whenever the dialog is opened. Might want to add an open()
* method to Dialog for that.
*/
SaveLoadDialog::SaveLoadDialog(NewGui *gui)
: Dialog (gui, 30, 20, 260, 124)
{
@ -269,16 +279,41 @@ SaveLoadDialog::SaveLoadDialog(NewGui *gui)
// FIXME - test
_savegameList = new ListWidget(this, 10, 40, 180, 74);
// Get savegame names
ScummVM::StringList l;
char name[32];
Scumm *s = _gui->getScumm();
for (int i = 0; i <= 80; i++) { // 80 I got from old gui
s->getSavegameName(i, name);
l.push_back(name);
}
((ListWidget *)_savegameList)->setList(l);
}
void SaveLoadDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data)
{
switch (cmd) {
case kSaveCmd:
//printf("Saving game in slot %d\n", _savegameList->getSelected());
if (_savegameList->getSelectedString()[0] != 0) {
Scumm *s = _gui->getScumm();
s->_saveLoadSlot = _savegameList->getSelected();
s->_saveLoadCompatible = false;
s->_saveLoadFlag = 1; // 1 for save, I assume (Painelf)
strcpy(s->_saveLoadName, _savegameList->getSelectedString());
close();
}
break;
case kLoadCmd:
//printf("Loading game in slot %d\n", _savegameList->getSelected());
if (_savegameList->getSelectedString()[0] != 0) {
Scumm *s = _gui->getScumm();
s->_saveLoadSlot = _savegameList->getSelected();
s->_saveLoadCompatible = false;
s->_saveLoadFlag = 2; // 2 for load. Magic number anyone?
close();
}
break;
case kPlayCmd:
close();

View File

@ -23,6 +23,7 @@
#include "scummsys.h"
#include "widget.h"
#include "ListWidget.h"
class NewGui;
@ -83,7 +84,7 @@ public:
virtual void handleCommand(CommandSender *sender, uint32 cmd, uint32 data);
protected:
Widget* _savegameList;
ListWidget* _savegameList;
};

View File

@ -45,7 +45,7 @@ public:
void pop() { if (_size > 0) _stack[--_size] = 0; }
};
typedef List<OSystem::Event> EventList;
typedef ScummVM::List<OSystem::Event> EventList;
// This class hopefully will replace the old Gui class completly one day
class NewGui {
@ -69,6 +69,8 @@ public:
NewGui(Scumm *s);
void handleEvent(const OSystem::Event &event) { _eventList.push_back(event); }
Scumm *getScumm() { return _s; }
protected:
Scumm *_s;

View File

@ -1264,8 +1264,18 @@ void Scumm::waitForTimer(int msec_delay) {
// if newgui is running, copy event to EventList, and let the GUI handle it itself
// we might consider this approach for ScummLoop as well, and clean up the current mess
if (_newgui->isActive())
if (_newgui->isActive()) {
if (event.event_code == OSystem::EVENT_MOUSEMOVE) {
mouse.x = event.mouse.x;
mouse.y = event.mouse.y;
_system->set_mouse_pos(event.mouse.x, event.mouse.y);
#if !defined(__MORPHOS__)
_system->update_screen();
#endif
}
_newgui->handleEvent(event);
continue;
}
switch(event.event_code) {
case OSystem::EVENT_KEYDOWN:
@ -1285,7 +1295,7 @@ void Scumm::waitForTimer(int msec_delay) {
g_debugger.attach(this);
else if (event.kbd.keycode=='s')
resourceStats();
} else if (!_newgui->isActive())
} else
_keyPressed = event.kbd.ascii; // Normal key press, pass on to the game.
break;

View File

@ -82,6 +82,8 @@ void ClearBlendCache(byte *palette, int weight)
#pragma mark -
namespace ScummVM {
String::String(const char *str)
{
_refCount = new int(1);
@ -123,7 +125,7 @@ String& String::operator =(const char* str)
_len = len;
memcpy(_str, str, _len + 1);
} if (_len > 0) {
} else if (_len > 0) {
decRefCount();
_refCount = new int(1);
@ -223,3 +225,4 @@ void String::ensureCapacity(int new_len, bool keep_old)
_str = newStr;
}
}; // End of namespace ScummVM

10
util.h
View File

@ -23,12 +23,13 @@
#include "scummsys.h"
int RGBMatch(byte *palette, int r, int g, int b);
int Blend(int src, int dst, byte *palette);
void ClearBlendCache(byte *palette, int weight);
namespace ScummVM {
template <class T>
class List {
protected:
@ -117,6 +118,7 @@ protected:
}
};
class String {
protected:
int *_refCount;
@ -148,13 +150,17 @@ protected:
void decRefCount();
};
class StringList : public List<String> {
public:
void push_back(const char* str)
{
ensureCapacity(_size + 1);
_data[_size++] = str;
_data[_size] = str;
_size++;
}
};
}; // End of namespace ScummVM
#endif