factored out ChooserDialog into it's own header/source file, and made the title adjustable; added a dummy file for EditFieldWidget (not implemented yet); some other cleanup

svn-id: r5658
This commit is contained in:
Max Horn 2002-11-21 12:48:50 +00:00
parent cb160cfbf3
commit dec234c6a5
10 changed files with 205 additions and 67 deletions

24
gui/EditTextWidget.cpp Normal file
View File

@ -0,0 +1,24 @@
/* ScummVM - Scumm Interpreter
* Copyright (C) 2002 The ScummVM project
*
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Header$
*/
#include "stdafx.h"
#include "EditTextWidget.h"
#include "dialog.h"
#include "newgui.h"

56
gui/EditTextWidget.h Normal file
View File

@ -0,0 +1,56 @@
/* ScummVM - Scumm Interpreter
* Copyright (C) 2002 The ScummVM project
*
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Header$
*/
#ifndef EDITTEXTWIDGET_H
#define EDITTEXTWIDGET_H
#include "widget.h"
#include "common/str.h"
#include "common/list.h"
/* EditTextWidget */
class EditTextWidget : public StaticTextWidget {
typedef ScummVM::StringList StringList;
typedef ScummVM::String String;
protected:
int _currentKeyDown;
String _backupString;
bool _caretVisible;
uint32 _caretTime;
public:
EditTextWidget(Dialog *boss, int x, int y, int w, int h);
virtual ~EditTextWidget();
virtual void handleTickle();
virtual void handleMouseDown(int x, int y, int button, int clickCount);
virtual void handleMouseUp(int x, int y, int button, int clickCount);
virtual bool handleKeyDown(char key, int modifiers);
virtual bool handleKeyUp(char key, int modifiers);
virtual void handleCommand(CommandSender *sender, uint32 cmd, uint32 data);
virtual bool wantsFocus() { return true; };
protected:
void drawWidget(bool hilite);
void drawCaret(bool erase);
void lostFocusWidget();
};
#endif

View File

@ -23,7 +23,6 @@
#include "ScrollBarWidget.h"
#include "dialog.h"
#include "newgui.h"
#include "common/engine.h"
ListWidget::ListWidget(Dialog *boss, int x, int y, int w, int h)
@ -91,7 +90,7 @@ void ListWidget::scrollBarRecalc()
void ListWidget::handleTickle()
{
uint32 time = g_system->get_msecs();
uint32 time = _boss->getGui()->get_time();
if (_editMode && _caretTime < time) {
_caretTime = time + 300;
if (_caretVisible) {

View File

@ -22,7 +22,8 @@
#define LISTWIDGET_H
#include "widget.h"
#include "util.h"
#include "common/str.h"
#include "common/list.h"
class ScrollBarWidget;

65
gui/chooser.cpp Normal file
View File

@ -0,0 +1,65 @@
/* ScummVM - Scumm Interpreter
* Copyright (C) 2002 The ScummVM project
*
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Header$
*/
#include "chooser.h"
#include "newgui.h"
#include "ListWidget.h"
enum {
kChooseCmd = 'Chos'
};
ChooserDialog::ChooserDialog(NewGui *gui, const String title, const StringList& list)
: Dialog(gui, 40, 24, 320-2*40, 141)
{
// Headline
new StaticTextWidget(this, 10, 8, _w-2*10, kLineHeight, title, kTextAlignCenter);
// Add choice list
_list = new ListWidget(this, 10, 22, _w-2*10, _h-22-24-10);
_list->setNumberingMode(kListNumberingOff);
_list->setList(list);
// Buttons
addButton(_w-2*(kButtonWidth+10), _h-24, "Cancel", kCloseCmd, 0);
_chooseButton = addButton(_w-(kButtonWidth+10), _h-24, "Choose", kChooseCmd, 0);
_chooseButton->setEnabled(false);
// Result = -1 -> no choice was made
setResult(-1);
}
void ChooserDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data)
{
int item = _list->getSelected();
switch (cmd) {
case kChooseCmd:
case kListItemDoubleClickedCmd:
setResult(item);
close();
break;
case kListSelectionChangedCmd:
_chooseButton->setEnabled(item >= 0);
_chooseButton->draw();
break;
default:
Dialog::handleCommand(sender, cmd, data);
}
}

48
gui/chooser.h Normal file
View File

@ -0,0 +1,48 @@
/* ScummVM - Scumm Interpreter
* Copyright (C) 2002 The ScummVM project
*
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Header$
*/
#ifndef CHOOSER_DIALOG_H
#define CHOOSER_DIALOG_H
#include "dialog.h"
#include "common/str.h"
#include "common/list.h"
class ButtonWidget;
class ListWidget;
/*
* A dialog that allows the user to choose between a selection of items
*/
class ChooserDialog : public Dialog {
typedef ScummVM::String String;
typedef ScummVM::StringList StringList;
public:
ChooserDialog(NewGui *gui, const String title, const StringList& list);
virtual void handleCommand(CommandSender *sender, uint32 cmd, uint32 data);
protected:
ListWidget *_list;
ButtonWidget *_chooseButton;
};
#endif

View File

@ -21,6 +21,7 @@
#include "stdafx.h"
#include "launcher.h"
#include "browser.h"
#include "chooser.h"
#include "newgui.h"
#include "ListWidget.h"
@ -29,67 +30,6 @@
#include "common/engine.h"
#include "common/gameDetector.h"
enum {
kChooseCmd = 'Chos'
};
/*
* A dialog that allows the user to choose between a selection of items
*/
class ChooserDialog : public Dialog {
typedef ScummVM::String String;
typedef ScummVM::StringList StringList;
public:
ChooserDialog(NewGui *gui, const StringList& list);
virtual void handleCommand(CommandSender *sender, uint32 cmd, uint32 data);
protected:
ListWidget *_list;
ButtonWidget *_chooseButton;
};
ChooserDialog::ChooserDialog(NewGui *gui, const StringList& list)
: Dialog(gui, 40, 30, 320-2*40, 200-2*30)
{
// Headline
new StaticTextWidget(this, 10, 8, _w-2*10, kLineHeight,
"Pick the game:", kTextAlignCenter);
// Add choice list
_list = new ListWidget(this, 10, 22, _w-2*10, _h-22-24-10);
_list->setNumberingMode(kListNumberingOff);
_list->setList(list);
// Buttons
addButton(_w-2*(kButtonWidth+10), _h-24, "Cancel", kCloseCmd, 0);
_chooseButton = addButton(_w-(kButtonWidth+10), _h-24, "Choose", kChooseCmd, 0);
_chooseButton->setEnabled(false);
// Result = -1 -> no choice was made
setResult(-1);
}
void ChooserDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data)
{
int item = _list->getSelected();
switch (cmd) {
case kChooseCmd:
case kListItemDoubleClickedCmd:
setResult(item);
close();
break;
case kListSelectionChangedCmd:
_chooseButton->setEnabled(item >= 0);
_chooseButton->draw();
break;
default:
Dialog::handleCommand(sender, cmd, data);
}
}
enum {
kStartCmd = 'STRT',
kOptionsCmd = 'OPTN',
@ -279,7 +219,7 @@ void LauncherDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 dat
for (i = 0; i < candidates.size(); i++)
list.push_back(candidates[i]->gamename);
ChooserDialog dialog(_gui, list);
ChooserDialog dialog(_gui, "Pick the game:", list);
i = dialog.runModal();
if (0 <= i && i < candidates.size())
v = candidates[i];

View File

@ -2,7 +2,9 @@ MODULE := gui
MODULE_OBJS = \
gui/browser.o \
gui/chooser.o \
gui/dialog.o \
gui/EditTextWidget.o \
gui/launcher.o \
gui/ListWidget.o \
gui/message.o \

View File

@ -127,7 +127,7 @@ void NewGui::runLoop()
_system->update_screen();
OSystem::Event event;
uint32 time = _system->get_msecs();
uint32 time = get_time();
while (_system->poll_event(&event)) {
switch(event.event_code) {
@ -475,7 +475,7 @@ void NewGui::drawBitmap(uint32 bitmap[8], int x, int y, int16 color)
//
void NewGui::animateCursor()
{
int time = _system->get_msecs();
int time = get_time();
if (time > _cursorAnimateTimer + kCursorAnimateDelay) {
const byte colors[4] = { 15, 15, 7, 8 };
const byte color = colors[_cursorAnimateCounter];

View File

@ -117,6 +117,9 @@ public:
int16 _textcolor;
int16 _textcolorhi;
// Misc util
uint32 get_time() const { return _system->get_msecs(); }
// Drawing primitives
int16 *getBasePtr(int x, int y);
void box(int x, int y, int width, int height, bool inverted = false);