| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506 |
- /*
- * Copyright (C) 2022 The V-Gears Team
- *
- * This file is part of V-Gears
- *
- * V-Gears is free software: you can redistribute it and/or modify it under
- * terms of the GNU General Public License as published by the Free Software
- * Foundation, version 3.0 (GPLv3) of the License.
- *
- * V-Gears 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.
- */
- #pragma once
- #include <OgreHardwareVertexBuffer.h>
- #include <OgreRenderQueueListener.h>
- #include <OgreRoot.h>
- #include <Overlay/OgreUTFString.h>
- #include <tinyxml.h>
- #include "UiFont.h"
- #include "UiWidget.h"
- class UiSprite;
- /**
- * The textarea state.
- */
- enum TextState{
- /**
- * The text is displayed.
- */
- TS_SHOW_TEXT,
- /**
- * The text is scrolling.
- */
- TS_SCROLL_TEXT,
- /**
- * The text is paused waiting for input.
- */
- TS_PAUSE_OK,
- /**
- * The text is paused waiting for time to pass.
- */
- TS_PAUSE_TIME,
- /**
- * The textarea is done with.
- */
- TS_DONE,
- /**
- * The text is overflowing.
- */
- TS_OVERFLOW,
- /**
- * The text is changing pages.
- */
- TS_NEXT_PAGE,
- };
- struct TextChar{
- TextChar():
- char_code(0),
- colour(Ogre::ColourValue::White),
- skip(false),
- variable(""),
- variable_len(0),
- pause_ok(false),
- pause_time(0.0f),
- next_page(false),
- sprite(NULL),
- sprite_y(0)
- {}
- int char_code;
- Ogre::ColourValue colour;
- bool skip;
- Ogre::String variable;
- unsigned int variable_len;
- bool pause_ok;
- float pause_time;
- bool next_page;
- UiSprite* sprite;
- float sprite_y;
- };
- struct TextVariable
- {
- Ogre::String name;
- Ogre::UTFString value;
- };
- /**
- * An ingame textarea.
- *
- * It may be any window used to represent text: a diaog window, a menu panel,
- * a choice selection...
- */
- class UiTextArea : public UiWidget{
- public:
- /**
- * Creates a UiTextArea.
- *
- * @param name[in] Name for the textarea.
- */
- UiTextArea(const Ogre::String& name);
- /**
- * Creates a UiTextArea.
- *
- * @param name[in] Name for the textarea.
- * @param path_name[in] Path for the widget.
- * @param parent[in] Pointer to the widget that will parent the
- * UiTextArea.
- */
- UiTextArea(
- const Ogre::String& name, const Ogre::String& path_name,
- UiWidget* parent
- );
- /**
- * Destroys the UiTextArea.
- */
- virtual ~UiTextArea();
- /**
- * Sets default values for the UiTextArea.
- *
- * It's automatically called when the UiTextArea is created.
- */
- void Initialise();
- /**
- * Updates the UiTextArea.
- */
- virtual void Update();
- /**
- * Renders the UiTextArea on the screen.
- */
- virtual void Render();
- /**
- * Updates the UiTextArea.
- */
- virtual void UpdateTransformation();
- /**
- * Updates the UiTextArea geometry.
- */
- void UpdateGeometry();
- /**
- * Handles a keypress.
- */
- void InputPressed();
- /**
- * Handles a key being hold.
- */
- void InputRepeated();
- /**
- * Text alignment in the text area.
- */
- enum TextAlign{
- /**
- * Left aligned text.
- */
- LEFT,
- /**
- * Right aligned text.
- */
- RIGHT,
- /**
- * Horizontally centered text.
- */
- CENTER
- };
- /**
- * Sets the text alignment in the text area.
- *
- * @param align[in] The text alignment.
- */
- void SetTextAlign(const TextAlign align);
- /**
- * Sets the paddings in the text area.
- *
- * @param top[in] Padding from the top, in pixels.
- * @param right[in] Padding from the right, in pixels.
- * @param bottom[in] Padding from the bottom, in pixels.
- * @param left[in] Padding from the left, in pixels.
- */
- void SetPadding(
- const float top, const float right,
- const float bottom, const float left
- );
- /**
- * Sets the text from a string.
- *
- * @param text[in] Text to set.
- */
- void SetText(const Ogre::UTFString& text);
- /**
- * Sets the text from an XML node.
- *
- * @param text[in] XML node with the text to set.
- */
- void SetText(TiXmlNode* text);
- /**
- * Removes the text from the text area.
- */
- void TextClear();
- /**
- * @todo Understand and document.
- *
- * @param end[in] @todo Understand and document.
- */
- void RemoveSpritesFromText(const unsigned int end);
- /**
- * Set the font for the text.
- *
- * @param font[in] The font to set.
- */
- void SetFont(const Ogre::String& font);
- /**
- * Retrieves the font.
- *
- * @return The font used for the text in the textarea.
- */
- const UiFont* GetFont() const;
- /**
- * Sets the printing speed.
- *
- * @param speed[in] The text speed. -1 for instant text.
- * @todo Explain units or references.
- */
- void SetTextPrintSpeed(const float speed);
- /**
- * Sets the scroll duration.
- *
- * @param time[in] Time to scroll a line.
- * @todo Units or references.
- */
- void SetTextScrollTime(const float time);
- /**
- * Sets a variable in the text.
- *
- * @param name[in] Variable name.
- * @param value[in] Variable value.
- */
- void SetVariable(
- const Ogre::String& name, const Ogre::UTFString& value
- );
- /**
- * Gets the value of a variable in the text.
- *
- * @param name[in] The variable name.
- * @return The variable value, in string format, or an empty string if
- * there is no such variable.
- */
- Ogre::UTFString GetVariable(const Ogre::String& name) const;
- /**
- * Checks the text state.
- *
- * @return The text state.
- */
- TextState GetTextState() const;
- /**
- * Gets the text limit.
- *
- * @return The text limit.
- * @todo The limit is the max number of letters per text area? Does it
- * include multiple pages?
- */
- float GetTextLimit() const;
- /**
- * Gets the text size.
- *
- * @return The number of characters in the text.
- */
- unsigned int GetTextSize() const;
- /**
- * Retrieves the pause time of the text.
- *
- * @return The time the text must still remain paused, in second.
- */
- float GetPauseTime() const;
- private:
- /**
- * Retrieves the text width.
- *
- * @return The text width, in pixels.
- */
- float GetTextWidth() const;
- /**
- * Prepares text from a XML node.
- *
- * @param node[in] The XML node to get the text from.
- * @param colour[in] The text colour.
- * @todo Does this call setText?
- */
- void PrepareTextFromNode(
- TiXmlNode* node, const Ogre::ColourValue& colour
- );
- /**
- * Prepares text from a string.
- *
- * @param text[in] The text to prepare.
- * @param colour[in] The text colour.
- * @todo Does this call setText?
- */
- void PrepareTextFromText(
- const Ogre::UTFString& text, const Ogre::ColourValue& colour
- );
- /**
- * Constructor.
- */
- UiTextArea();
- /**
- * Creates a vertex buffer for the textarea.
- */
- void CreateVertexBuffer();
- /**
- * Destroys a vertex buffer for the textarea.
- */
- void DestroyVertexBuffer();
- /**
- * Material for the text area.
- */
- Ogre::MaterialPtr material_;
- /**
- * The scene manager.
- */
- Ogre::SceneManager* scene_manager_;
- /**
- * The render system.
- */
- Ogre::RenderSystem* render_system_;
- /**
- * Max letter per textarea.
- */
- unsigned int max_letters_;
- /**
- * The render operation.
- */
- Ogre::RenderOperation render_operation_;
- /**
- * The text area vertext buffer.
- */
- Ogre::HardwareVertexBufferSharedPtr vertex_buffer_;
- /**
- * The font for the text.
- */
- UiFont* font_;
- /**
- * The text alignment.
- */
- TextAlign text_align_;
- /**
- * The text.
- */
- std::vector<TextChar> text_;
- /**
- * The text limit.
- */
- float text_limit_;
- /**
- * The text printing speed.
- */
- float text_print_speed_;
- /**
- * @todo Understand and document.
- */
- float text_print_speed_mod_;
- /**
- * The state of the text.
- */
- TextState text_state_;
- /**
- * Variables in the text.
- */
- std::vector<TextVariable> text_variable_;
- /**
- * Time to scroll the text.
- */
- float text_scroll_time_;
- /**
- * @todo Understand and document.
- */
- float text_y_offset_;
- /**
- * @todo Understand and document.
- */
- float text_y_offset_target_;
- /**
- * The time to pause the text.
- */
- float pause_time_;
- /**
- * @todo Understand and document.
- */
- unsigned int next_page_start_;
- /**
- * Indicates if the 'next' button has been pressed.
- */
- bool next_pressed_;
- /**
- * Indicates if the 'next' button is being held down.
- */
- bool next_repeated_;
- /**
- * The top padding.
- */
- float padding_top_;
- /**
- * The right padding.
- */
- float padding_right_;
- /**
- * The bottom padding.
- */
- float padding_bottom_;
- /**
- * The left padding.
- */
- float padding_left_;
- /**
- * @todo Understand and document.
- */
- bool timer_;
- /**
- * @todo Understand and document.
- */
- int timer_time_;
- };
|