2021-02-07 02:50:45 +02:00
|
|
|
/* 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2021-02-19 02:17:41 +02:00
|
|
|
#ifndef NANCY_UI_TEXTBOX_H
|
|
|
|
#define NANCY_UI_TEXTBOX_H
|
2021-02-07 02:50:45 +02:00
|
|
|
|
2021-02-19 02:17:41 +02:00
|
|
|
#include "engines/nancy/renderobject.h"
|
|
|
|
|
|
|
|
#include "engines/nancy/ui/scrollbar.h"
|
2021-02-07 02:50:45 +02:00
|
|
|
|
|
|
|
#include "common/str.h"
|
|
|
|
#include "common/array.h"
|
|
|
|
|
|
|
|
#include "graphics/managed_surface.h"
|
|
|
|
|
|
|
|
namespace Nancy {
|
|
|
|
|
|
|
|
class NancyEngine;
|
2021-02-19 02:17:41 +02:00
|
|
|
class Scene;
|
|
|
|
struct NancyInput;
|
2021-02-07 02:50:45 +02:00
|
|
|
|
2021-02-19 02:17:41 +02:00
|
|
|
namespace UI {
|
2021-02-07 02:50:45 +02:00
|
|
|
|
2021-02-19 02:17:41 +02:00
|
|
|
class Textbox : public Nancy::RenderObject {
|
2021-02-07 02:50:45 +02:00
|
|
|
public:
|
2021-02-19 02:17:41 +02:00
|
|
|
Textbox(RenderObject &redrawFrom) :
|
|
|
|
RenderObject(redrawFrom),
|
2021-02-07 02:50:45 +02:00
|
|
|
_firstLineOffset(0),
|
|
|
|
_lineHeight(0),
|
2021-02-19 02:17:41 +02:00
|
|
|
_borderWidth(0),
|
|
|
|
_needsTextRedraw(false),
|
|
|
|
_scrollbar(redrawFrom, this),
|
|
|
|
_scrollbarPos(0) {}
|
|
|
|
|
|
|
|
virtual ~Textbox() { _fullSurface.free(); }
|
2021-02-07 02:50:45 +02:00
|
|
|
|
2021-02-19 02:17:41 +02:00
|
|
|
virtual void init() override;
|
|
|
|
virtual void registerGraphics() override;
|
|
|
|
virtual void updateGraphics() override;
|
|
|
|
void handleInput(NancyInput &input);
|
|
|
|
|
|
|
|
void drawTextbox();
|
2021-02-07 02:50:45 +02:00
|
|
|
void clear();
|
|
|
|
|
2021-02-19 02:17:41 +02:00
|
|
|
void addTextLine(const Common::String &text);
|
|
|
|
void onScrollbarPositionChanged(float data);
|
2021-02-07 02:50:45 +02:00
|
|
|
|
2021-02-19 02:17:41 +02:00
|
|
|
static void assembleTextLine(char *rawCaption, Common::String &output, uint size);
|
2021-02-07 02:50:45 +02:00
|
|
|
|
2021-02-19 02:17:41 +02:00
|
|
|
protected:
|
|
|
|
virtual uint16 getZOrder() const override { return 6; }
|
2021-02-07 02:50:45 +02:00
|
|
|
|
|
|
|
private:
|
2021-03-13 23:23:50 +02:00
|
|
|
uint16 getInnerHeight() const;
|
2021-02-19 02:17:41 +02:00
|
|
|
void onScrollbarMove();
|
|
|
|
|
2021-02-07 02:50:45 +02:00
|
|
|
struct Response {
|
2021-02-19 02:17:41 +02:00
|
|
|
Common::String text;
|
2021-02-07 02:50:45 +02:00
|
|
|
Common::Rect hotspot;
|
|
|
|
};
|
2021-02-19 02:17:41 +02:00
|
|
|
|
|
|
|
class TextboxScrollbar : public Scrollbar {
|
|
|
|
public:
|
|
|
|
TextboxScrollbar(RenderObject &redrawFrom, Textbox *parent) :
|
|
|
|
Scrollbar(redrawFrom),
|
|
|
|
_parent(parent) {}
|
|
|
|
~TextboxScrollbar() =default;
|
|
|
|
|
|
|
|
virtual void init() override;
|
|
|
|
Textbox *_parent;
|
|
|
|
};
|
|
|
|
|
|
|
|
Graphics::ManagedSurface _fullSurface;
|
|
|
|
|
|
|
|
TextboxScrollbar _scrollbar;
|
|
|
|
|
2021-02-26 19:36:55 +02:00
|
|
|
Common::Array<Common::String> _textLines;
|
|
|
|
Common::Array<Common::Rect> _hotspots;
|
2021-02-19 02:17:41 +02:00
|
|
|
|
|
|
|
Common::Rect _scrollbarSourceBounds;
|
|
|
|
Common::Point _scrollbarDefaultDest;
|
2021-02-07 02:50:45 +02:00
|
|
|
uint16 _firstLineOffset;
|
|
|
|
uint16 _lineHeight;
|
|
|
|
uint16 _borderWidth;
|
2021-02-19 02:17:41 +02:00
|
|
|
uint16 _numLines;
|
2021-02-26 19:36:55 +02:00
|
|
|
uint16 _fontID;
|
2021-02-19 02:17:41 +02:00
|
|
|
|
|
|
|
bool _needsTextRedraw;
|
|
|
|
float _scrollbarPos;
|
2021-02-07 02:50:45 +02:00
|
|
|
|
2021-03-14 12:33:56 +02:00
|
|
|
static const char _CCBeginToken[];
|
|
|
|
static const char _CCEndToken[];
|
|
|
|
static const char _colorBeginToken[];
|
|
|
|
static const char _colorEndToken[];
|
|
|
|
static const char _hotspotToken[];
|
|
|
|
static const char _newLineToken[];
|
|
|
|
static const char _tabToken[];
|
|
|
|
static const char _telephoneEndToken[];
|
2021-02-07 02:50:45 +02:00
|
|
|
};
|
|
|
|
|
2021-02-19 02:17:41 +02:00
|
|
|
} // End of namespace UI
|
2021-02-07 02:50:45 +02:00
|
|
|
} // End of namespace Nancy
|
|
|
|
|
2021-02-19 02:17:41 +02:00
|
|
|
#endif // NANCY_UI_TEXTBOX_H
|