| [4744] | 1 | /* |
|---|
| [1853] | 2 | orxonox - the future of 3D-vertical-scrollers |
|---|
| 3 | |
|---|
| 4 | Copyright (C) 2004 orx |
|---|
| 5 | |
|---|
| 6 | This program is free software; you can redistribute it and/or modify |
|---|
| 7 | it under the terms of the GNU General Public License as published by |
|---|
| 8 | the Free Software Foundation; either version 2, or (at your option) |
|---|
| 9 | any later version. |
|---|
| [1855] | 10 | |
|---|
| 11 | ### File Specific: |
|---|
| [5360] | 12 | main-programmer: Benjamin Grauer |
|---|
| [1855] | 13 | co-programmer: ... |
|---|
| [1853] | 14 | */ |
|---|
| 15 | |
|---|
| [5360] | 16 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_GUI |
|---|
| [1853] | 17 | |
|---|
| [5365] | 18 | #include "glgui_text.h" |
|---|
| [1853] | 19 | |
|---|
| [5365] | 20 | #include "text.h" |
|---|
| 21 | |
|---|
| [7779] | 22 | namespace OrxGui |
|---|
| [3365] | 23 | { |
|---|
| [7779] | 24 | /** |
|---|
| 25 | * standard constructor |
|---|
| 26 | */ |
|---|
| 27 | GLGuiText::GLGuiText () |
|---|
| 28 | { |
|---|
| 29 | this->init(); |
|---|
| [4320] | 30 | |
|---|
| [7779] | 31 | } |
|---|
| [1853] | 32 | |
|---|
| 33 | |
|---|
| [7779] | 34 | /** |
|---|
| 35 | * standard deconstructor |
|---|
| 36 | */ |
|---|
| 37 | GLGuiText::~GLGuiText() |
|---|
| [8973] | 38 | {} |
|---|
| [5360] | 39 | |
|---|
| [7779] | 40 | /** |
|---|
| 41 | * initializes the GUI-element |
|---|
| 42 | */ |
|---|
| 43 | void GLGuiText::init() |
|---|
| 44 | { |
|---|
| [8973] | 45 | this->setClassID(CL_GLGUI_TEXT, "GLGuiText"); |
|---|
| [5360] | 46 | |
|---|
| [8973] | 47 | this->_text.setParent2D(this); |
|---|
| 48 | this->_text.setRelCoor2D(4,4); |
|---|
| 49 | this->_text.setFont("fonts/final_frontier.ttf", 20); |
|---|
| [8980] | 50 | this->_text.setLineWidth(400); |
|---|
| 51 | this->_text.setDotsPosition(LimitedWidthText::Begin); |
|---|
| [8973] | 52 | this->_text.setColor(foregroundColor()); |
|---|
| 53 | this->_text.setVisibility(false); |
|---|
| [8991] | 54 | this->_changedTextColor = Color::white; |
|---|
| [8973] | 55 | this->resize(); |
|---|
| [7779] | 56 | } |
|---|
| [5360] | 57 | |
|---|
| [7779] | 58 | /** |
|---|
| [8973] | 59 | * @brief sets the Text of the Text |
|---|
| 60 | * @param text The new Text. |
|---|
| 61 | */ |
|---|
| 62 | void GLGuiText::setText(const std::string& text) |
|---|
| 63 | { |
|---|
| 64 | this->_text.setText(text); |
|---|
| 65 | this->changedText(); |
|---|
| 66 | } |
|---|
| 67 | |
|---|
| 68 | /** |
|---|
| 69 | * @brief appends text to the Text |
|---|
| 70 | * @param appendText the Text to append |
|---|
| 71 | */ |
|---|
| 72 | void GLGuiText::append(const std::string& appendText) |
|---|
| 73 | { |
|---|
| 74 | this->_text.append(appendText); |
|---|
| 75 | this->changedText(); |
|---|
| 76 | } |
|---|
| 77 | |
|---|
| 78 | |
|---|
| 79 | /** |
|---|
| 80 | * @brief appends a Character to the Text |
|---|
| 81 | * @param character the Character to append. |
|---|
| 82 | */ |
|---|
| 83 | void GLGuiText::appendCharacter(char character) |
|---|
| 84 | { |
|---|
| 85 | this->_text.appendCharacter(character); |
|---|
| 86 | this->changedText(); |
|---|
| 87 | } |
|---|
| 88 | |
|---|
| 89 | |
|---|
| 90 | /** |
|---|
| 91 | * @brief Removes Characters from the Text |
|---|
| 92 | * @param chars The count of characters to remove |
|---|
| 93 | */ |
|---|
| 94 | void GLGuiText::removeCharacters(unsigned int chars) |
|---|
| 95 | { |
|---|
| 96 | this->_text.removeCharacters(chars); |
|---|
| 97 | this->changedText(); |
|---|
| 98 | } |
|---|
| 99 | |
|---|
| 100 | void GLGuiText::clear() |
|---|
| 101 | { |
|---|
| 102 | this->_text.clear(); |
|---|
| [9656] | 103 | this->resize(); |
|---|
| [8973] | 104 | } |
|---|
| 105 | |
|---|
| [9656] | 106 | |
|---|
| [8973] | 107 | /** |
|---|
| 108 | * @brief If the Text has been changed this function is called. |
|---|
| 109 | * |
|---|
| 110 | * This Function also emits the Signal textChanged. |
|---|
| 111 | */ |
|---|
| 112 | void GLGuiText::changedText() |
|---|
| 113 | { |
|---|
| 114 | this->resize(); |
|---|
| [8991] | 115 | this->setFrontColor(_changedTextColor, true); |
|---|
| [9406] | 116 | this->textChanged.emit(this->_text.text()); |
|---|
| [8973] | 117 | } |
|---|
| 118 | |
|---|
| [9656] | 119 | void GLGuiText::setTextSize(float size) |
|---|
| 120 | { |
|---|
| 121 | this->_text.setSize(size); |
|---|
| 122 | this->changedText(); |
|---|
| 123 | } |
|---|
| 124 | |
|---|
| 125 | void GLGuiText::setFont(const Font& font) |
|---|
| 126 | { |
|---|
| 127 | GLGuiWidget::setFont(font); |
|---|
| 128 | this->_text.setFont(font); |
|---|
| 129 | } |
|---|
| 130 | |
|---|
| [8991] | 131 | void GLGuiText::setChangedTextColor(const Color& color) |
|---|
| 132 | { |
|---|
| 133 | this->_changedTextColor = color; |
|---|
| 134 | } |
|---|
| [8973] | 135 | |
|---|
| 136 | /** |
|---|
| 137 | * @brief Resizes the Widget to the new Size-constraints. |
|---|
| 138 | */ |
|---|
| 139 | void GLGuiText::resize() |
|---|
| 140 | { |
|---|
| 141 | this->_text.setRelCoor2D(borderLeft(), borderTop()); |
|---|
| 142 | this->setSize2D( this->_text.getSize2D() + Vector2D(borderLeft() + borderRight(), borderTop() + borderBottom())); |
|---|
| [8980] | 143 | //this->_text.setLineWidth(this->size2D); |
|---|
| [8973] | 144 | GLGuiWidget::resize(); |
|---|
| 145 | /* this->frontRect().setTopLeft(borderLeft(), borderTop()); |
|---|
| 146 | this->frontRect().setSize(this->getSize2D() - Vector2D(borderLeft() + borderRight(), borderTop() + borderBottom()));*/ |
|---|
| 147 | } |
|---|
| 148 | |
|---|
| 149 | void GLGuiText::updateFrontColor() |
|---|
| 150 | { |
|---|
| 151 | this->_text.setColor(foregroundColor()); |
|---|
| 152 | } |
|---|
| 153 | |
|---|
| 154 | void GLGuiText::hiding() |
|---|
| 155 | { |
|---|
| 156 | this->_text.setVisibility(false); |
|---|
| 157 | } |
|---|
| 158 | |
|---|
| 159 | void GLGuiText::showing() |
|---|
| 160 | { |
|---|
| 161 | this->_text.setVisibility(true); |
|---|
| 162 | } |
|---|
| 163 | |
|---|
| 164 | |
|---|
| 165 | |
|---|
| 166 | /** |
|---|
| [7779] | 167 | * draws the GLGuiText |
|---|
| 168 | */ |
|---|
| [8973] | 169 | void GLGuiText::draw() const |
|---|
| [7779] | 170 | { |
|---|
| [8973] | 171 | this->beginDraw(); |
|---|
| 172 | GLGuiWidget::draw(); |
|---|
| 173 | |
|---|
| 174 | // this->frontMaterial().select(); |
|---|
| 175 | // GLGuiWidget::drawRect(this->frontRect()); |
|---|
| 176 | |
|---|
| 177 | this->endDraw(); |
|---|
| [7779] | 178 | } |
|---|
| [5360] | 179 | } |
|---|