mirror of
https://github.com/libretro/scummvm.git
synced 2024-12-14 21:59:17 +00:00
GUI: Display scummvm.log path and add viewer
This commit is contained in:
parent
ba1567f7d6
commit
42c68234bb
@ -22,6 +22,7 @@ MODULE_OBJS := \
|
||||
saveload.o \
|
||||
saveload-dialog.o \
|
||||
shaderbrowser-dialog.o \
|
||||
textviewer.o \
|
||||
themebrowser.o \
|
||||
ThemeEngine.o \
|
||||
ThemeEval.o \
|
||||
|
@ -29,6 +29,7 @@
|
||||
#include "gui/widgets/tab.h"
|
||||
#include "gui/ThemeEval.h"
|
||||
#include "gui/launcher.h"
|
||||
#include "gui/textviewer.h"
|
||||
|
||||
#include "backends/keymapper/keymapper.h"
|
||||
#include "backends/keymapper/remap-widget.h"
|
||||
@ -106,6 +107,7 @@ enum {
|
||||
kScalerPopUpCmd = 'scPU',
|
||||
kFullscreenToggled = 'oful',
|
||||
kRandomSeedClearCmd = 'rndc',
|
||||
kViewLogCmd = 'vwlg',
|
||||
};
|
||||
|
||||
enum {
|
||||
@ -2484,10 +2486,13 @@ void GlobalOptionsDialog::addPathsControls(GuiObject *boss, const Common::String
|
||||
Common::U32String confPath = ConfMan.getCustomConfigFileName();
|
||||
if (confPath.empty())
|
||||
confPath = g_system->getDefaultConfigFileName();
|
||||
StaticTextWidget* configPathWidget = new StaticTextWidget(boss, prefix + "ConfigPath", _("ScummVM config path: ") + confPath, confPath);
|
||||
StaticTextWidget *configPathWidget = new StaticTextWidget(boss, prefix + "ConfigPath", _("ScummVM config path: ") + confPath, confPath);
|
||||
if (ConfMan.isKeyTemporary("config"))
|
||||
configPathWidget->setFontColor(ThemeEngine::FontColor::kFontColorOverride);
|
||||
|
||||
Common::U32String logPath = g_system->getDefaultLogFileName();
|
||||
new StaticTextWidget(boss, prefix + "LogPath", _("ScummVM log path: ") + logPath, logPath);
|
||||
new ButtonWidget(boss, prefix + "ViewButton", _("View"), Common::U32String(), kViewLogCmd);
|
||||
|
||||
Common::U32String browserPath = _("<default>");
|
||||
if (ConfMan.hasKey("browser_lastpath"))
|
||||
@ -3220,6 +3225,12 @@ void GlobalOptionsDialog::handleCommand(CommandSender *sender, uint32 cmd, uint3
|
||||
_browserPath->setLabel(_("Last browser path: ") + _("<default>"));
|
||||
|
||||
break;
|
||||
case kViewLogCmd: {
|
||||
TextViewerDialog viewer(g_system->getDefaultLogFileName());
|
||||
viewer.runModal();
|
||||
g_gui.scheduleTopDialogRedraw();
|
||||
break;
|
||||
}
|
||||
#ifdef USE_CLOUD
|
||||
#ifdef USE_SDL_NET
|
||||
case kRootPathClearCmd:
|
||||
|
209
gui/textviewer.cpp
Normal file
209
gui/textviewer.cpp
Normal file
@ -0,0 +1,209 @@
|
||||
/* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "common/file.h"
|
||||
#include "common/tokenizer.h"
|
||||
|
||||
#include "graphics/font.h"
|
||||
#include "graphics/fontman.h"
|
||||
|
||||
#include "gui/gui-manager.h"
|
||||
#include "gui/ThemeEval.h"
|
||||
#include "gui/textviewer.h"
|
||||
#include "gui/widgets/scrollbar.h"
|
||||
|
||||
namespace GUI {
|
||||
|
||||
#define kDialogWidthPercent 0.8f
|
||||
#define kDialogHeightPercent 0.8f
|
||||
|
||||
#define kPadX 0.05
|
||||
#define kPadY 0.05
|
||||
|
||||
TextViewerDialog::TextViewerDialog(Common::String fname)
|
||||
: Dialog(0, 0, 1, 1), _fname(fname) {
|
||||
_font = &g_gui.getFont(ThemeEngine::kFontStyleConsole);
|
||||
_charWidth = _font->getMaxCharWidth();
|
||||
_lineHeight = _font->getFontHeight() + 2;
|
||||
|
||||
// Add scrollbar
|
||||
_scrollbarWidth = g_gui.xmlEval()->getVar("Globals.Scrollbar.Width", 0);
|
||||
_scrollBar = new ScrollBarWidget(this, _w - _scrollbarWidth - 1, 0, _scrollbarWidth, _h);
|
||||
_scrollBar->setTarget(this);
|
||||
|
||||
_currentPos = 0;
|
||||
_scrollLine = _linesPerPage - 1;
|
||||
|
||||
reflowLayout();
|
||||
|
||||
loadFile(fname);
|
||||
}
|
||||
|
||||
TextViewerDialog::~TextViewerDialog() {
|
||||
destroy();
|
||||
}
|
||||
|
||||
bool TextViewerDialog::loadFile(Common::String &fname) {
|
||||
Common::FSNode file(fname);
|
||||
|
||||
if (!file.exists()) {
|
||||
warning("TextViewerDialog::loadFile(): Cannot open file %s", fname.c_str());
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
Common::SeekableReadStream *stream = file.createReadStream();
|
||||
|
||||
warning("TextViewerDialog::loadFile(): File size is: %ld", stream->size());
|
||||
|
||||
_linesArray.clear();
|
||||
|
||||
while (!stream->eos()) {
|
||||
Common::String line = stream->readString('\n');
|
||||
|
||||
line.wordWrap(_lineWidth);
|
||||
|
||||
Common::StringTokenizer lines(line, "\n");
|
||||
while (!lines.empty())
|
||||
_linesArray.push_back(lines.nextToken());
|
||||
}
|
||||
|
||||
delete stream;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void TextViewerDialog::destroy() {
|
||||
_linesArray.clear();
|
||||
}
|
||||
|
||||
void TextViewerDialog::reflowLayout() {
|
||||
// Calculate the real width/height (rounded to char/line multiples)
|
||||
_w = (uint16)(kDialogWidthPercent * g_system->getOverlayWidth());
|
||||
_h = (uint16)((kDialogHeightPercent * g_system->getOverlayHeight() - 2) / _lineHeight);
|
||||
_h = _h * _lineHeight + 2;
|
||||
|
||||
_x = (g_system->getOverlayWidth() - _w) / 2;
|
||||
_y = (g_system->getOverlayHeight() - _h) / 2;
|
||||
|
||||
_padX = _w * kPadX;
|
||||
_padY = _h * kPadY;
|
||||
|
||||
// Calculate depending values
|
||||
_lineWidth = (_w - _scrollbarWidth - _padX * 2) / _charWidth;
|
||||
_linesPerPage = (_h - _padY * 2) / _lineHeight;
|
||||
|
||||
_scrollBar->setPos(_w - _scrollbarWidth - 1, 0);
|
||||
_scrollBar->setSize(_scrollbarWidth, _h);
|
||||
}
|
||||
|
||||
void TextViewerDialog::open() {
|
||||
Dialog::open();
|
||||
}
|
||||
|
||||
void TextViewerDialog::drawDialog(DrawLayer layerToDraw) {
|
||||
Dialog::drawDialog(layerToDraw);
|
||||
|
||||
setTextDrawableArea(Common::Rect(_x, _y, _x + _w, _y + _h));
|
||||
|
||||
// Draw a border
|
||||
//g_gui.hLine(_x, _y + _h - 1, _x + _w - 1, g_gui._color);
|
||||
|
||||
// Draw text
|
||||
int y = _y + _padY;
|
||||
|
||||
for (int line = 0; (line < _linesPerPage) && ((_currentPos + line) < (int)_linesArray.size()); line++) {
|
||||
int x = _x + _padX;
|
||||
const char *text = _linesArray[line + _currentPos].c_str();
|
||||
int w = MIN<int>(_lineWidth, _linesArray[line + _currentPos].size());
|
||||
|
||||
for (int column = 0; column < w; column++) {
|
||||
byte c = text[column];
|
||||
g_gui.theme()->drawChar(Common::Rect(x, y, x + _charWidth, y + _lineHeight), c, _font);
|
||||
x += _charWidth;
|
||||
}
|
||||
|
||||
y += _lineHeight;
|
||||
}
|
||||
|
||||
// Draw the scrollbar
|
||||
_scrollBar->_numEntries = _linesArray.size();
|
||||
_scrollBar->_currentPos = _currentPos;
|
||||
_scrollBar->_entriesPerPage = _linesPerPage;
|
||||
_scrollBar->recalc();
|
||||
_scrollBar->draw();
|
||||
}
|
||||
|
||||
|
||||
void TextViewerDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) {
|
||||
switch (cmd) {
|
||||
case kSetPositionCmd:
|
||||
_currentPos = _scrollBar->_currentPos;
|
||||
drawDialog(kDrawLayerForeground);
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void TextViewerDialog::handleMouseWheel(int x, int y, int direction) {
|
||||
_scrollBar->handleMouseWheel(x, y, direction);
|
||||
}
|
||||
|
||||
void TextViewerDialog::handleKeyDown(Common::KeyState state) {
|
||||
switch (state.keycode) {
|
||||
case Common::KEYCODE_ESCAPE:
|
||||
close();
|
||||
break;
|
||||
case Common::KEYCODE_UP:
|
||||
_currentPos--;
|
||||
break;
|
||||
case Common::KEYCODE_DOWN:
|
||||
_currentPos++;
|
||||
break;
|
||||
case Common::KEYCODE_HOME:
|
||||
_currentPos = 0;
|
||||
break;
|
||||
case Common::KEYCODE_END:
|
||||
_currentPos = _linesArray.size() - _linesPerPage;
|
||||
break;
|
||||
case Common::KEYCODE_PAGEUP:
|
||||
_currentPos -= _linesPerPage;
|
||||
break;
|
||||
case Common::KEYCODE_PAGEDOWN:
|
||||
_currentPos += _linesPerPage;
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
if (_currentPos < 0) {
|
||||
_currentPos = 0;
|
||||
}
|
||||
if ((_currentPos + _linesPerPage) >= (int)_linesArray.size()) {
|
||||
_currentPos = _linesArray.size() - _linesPerPage;
|
||||
}
|
||||
|
||||
drawDialog(kDrawLayerForeground);
|
||||
}
|
||||
|
||||
|
||||
} // End of namespace GUI
|
75
gui/textviewer.h
Normal file
75
gui/textviewer.h
Normal file
@ -0,0 +1,75 @@
|
||||
/* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef TEXTVIEWER_DIALOG_H
|
||||
#define TEXTVIEWER_DIALOG_H
|
||||
|
||||
#include "common/array.h"
|
||||
#include "common/str.h"
|
||||
|
||||
#include "gui/dialog.h"
|
||||
|
||||
namespace Graphics {
|
||||
class Font;
|
||||
}
|
||||
|
||||
namespace GUI {
|
||||
|
||||
class ScrollBarWidget;
|
||||
|
||||
class TextViewerDialog : public Dialog {
|
||||
private:
|
||||
int _lineWidth;
|
||||
int _linesPerPage;
|
||||
int _currentPos;
|
||||
int _scrollLine;
|
||||
|
||||
int _scrollbarWidth;
|
||||
int _charWidth;
|
||||
int _lineHeight;
|
||||
int _padX, _padY;
|
||||
|
||||
Common::StringArray _linesArray;
|
||||
|
||||
ScrollBarWidget *_scrollBar;
|
||||
|
||||
Common::String _fname;
|
||||
const Graphics::Font *_font = nullptr;
|
||||
|
||||
bool loadFile(Common::String &fname);
|
||||
void reflowLayout();
|
||||
|
||||
public:
|
||||
TextViewerDialog(Common::String fname);
|
||||
~TextViewerDialog();
|
||||
|
||||
void destroy();
|
||||
void open();
|
||||
void drawDialog(DrawLayer layerToDraw);
|
||||
|
||||
void handleMouseWheel(int x, int y, int direction);
|
||||
void handleKeyDown(Common::KeyState state);
|
||||
void handleCommand(CommandSender *sender, uint32 cmd, uint32 data);
|
||||
};
|
||||
|
||||
} // End of namespace GUI
|
||||
|
||||
#endif
|
@ -893,6 +893,12 @@
|
||||
/>
|
||||
</layout>
|
||||
<widget name = 'ConfigPath' height = 'Globals.Line.Height' />
|
||||
<layout type = 'horizontal' padding = '0, 0, 0, 0' spacing = '10' align = 'center'>
|
||||
<widget name = 'LogPath' height = 'Globals.Line.Height' />
|
||||
<widget name = 'ViewButton'
|
||||
type = 'Button'
|
||||
/>
|
||||
</layout>
|
||||
<layout type = 'horizontal' padding = '0, 0, 0, 0' spacing = '10' align = 'center'>
|
||||
<widget name = 'BrowserPath'
|
||||
height = 'Globals.Line.Height'
|
||||
|
@ -746,6 +746,12 @@
|
||||
/>
|
||||
</layout>
|
||||
<widget name = 'ConfigPath' height = 'Globals.Line.Height' />
|
||||
<layout type = 'horizontal' padding = '0, 0, 0, 0' spacing = '16' align = 'center'>
|
||||
<widget name = 'LogPath' height = 'Globals.Line.Height' />
|
||||
<widget name = 'ViewButton'
|
||||
type = 'Button'
|
||||
/>
|
||||
</layout>
|
||||
<layout type = 'horizontal' padding = '0, 0, 0, 0' spacing = '16' align = 'center'>
|
||||
<widget name = 'BrowserPath'
|
||||
height = 'Globals.Line.Height'
|
||||
|
@ -661,6 +661,12 @@
|
||||
/>
|
||||
</layout>
|
||||
<widget name = 'ConfigPath' height = 'Globals.Line.Height' />
|
||||
<layout type = 'horizontal' padding = '0, 0, 0, 0' spacing = '10' align = 'center'>
|
||||
<widget name = 'LogPath' height = 'Globals.Line.Height' />
|
||||
<widget name = 'ViewButton'
|
||||
type = 'Button'
|
||||
/>
|
||||
</layout>
|
||||
<layout type = 'horizontal' padding = '0, 0, 0, 0' spacing = '10' align = 'center'>
|
||||
<widget name = 'BrowserPath'
|
||||
height = 'Globals.Line.Height'
|
||||
|
@ -668,6 +668,12 @@
|
||||
/>
|
||||
</layout>
|
||||
<widget name = 'ConfigPath' height = 'Globals.Line.Height' />
|
||||
<layout type = 'horizontal' padding = '0, 0, 0, 0' spacing = '16'>
|
||||
<widget name = 'LogPath' height = 'Globals.Line.Height' />
|
||||
<widget name = 'ViewButton'
|
||||
type = 'Button'
|
||||
/>
|
||||
</layout>
|
||||
<layout type = 'horizontal' padding = '0, 0, 0, 0' spacing = '16'>
|
||||
<widget name = 'BrowserPath'
|
||||
height = 'Globals.Line.Height'
|
||||
|
Loading…
Reference in New Issue
Block a user