[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); |
---|
| 50 | this->_text.setColor(foregroundColor()); |
---|
| 51 | this->_text.setVisibility(false); |
---|
| 52 | this->resize(); |
---|
[7779] | 53 | } |
---|
[5360] | 54 | |
---|
[7779] | 55 | /** |
---|
[8973] | 56 | * @brief sets the Text of the Text |
---|
| 57 | * @param text The new Text. |
---|
| 58 | */ |
---|
| 59 | void GLGuiText::setText(const std::string& text) |
---|
| 60 | { |
---|
| 61 | this->_text.setText(text); |
---|
| 62 | this->changedText(); |
---|
| 63 | } |
---|
| 64 | |
---|
| 65 | /** |
---|
| 66 | * @brief appends text to the Text |
---|
| 67 | * @param appendText the Text to append |
---|
| 68 | */ |
---|
| 69 | void GLGuiText::append(const std::string& appendText) |
---|
| 70 | { |
---|
| 71 | this->_text.append(appendText); |
---|
| 72 | this->changedText(); |
---|
| 73 | } |
---|
| 74 | |
---|
| 75 | |
---|
| 76 | /** |
---|
| 77 | * @brief appends a Character to the Text |
---|
| 78 | * @param character the Character to append. |
---|
| 79 | */ |
---|
| 80 | void GLGuiText::appendCharacter(char character) |
---|
| 81 | { |
---|
| 82 | this->_text.appendCharacter(character); |
---|
| 83 | this->changedText(); |
---|
| 84 | } |
---|
| 85 | |
---|
| 86 | |
---|
| 87 | /** |
---|
| 88 | * @brief Removes Characters from the Text |
---|
| 89 | * @param chars The count of characters to remove |
---|
| 90 | */ |
---|
| 91 | void GLGuiText::removeCharacters(unsigned int chars) |
---|
| 92 | { |
---|
| 93 | this->_text.removeCharacters(chars); |
---|
| 94 | this->changedText(); |
---|
| 95 | } |
---|
| 96 | |
---|
| 97 | void GLGuiText::clear() |
---|
| 98 | { |
---|
| 99 | this->_text.clear(); |
---|
| 100 | this->changedText(); |
---|
| 101 | } |
---|
| 102 | |
---|
| 103 | /** |
---|
| 104 | * @brief If the Text has been changed this function is called. |
---|
| 105 | * |
---|
| 106 | * This Function also emits the Signal textChanged. |
---|
| 107 | */ |
---|
| 108 | void GLGuiText::changedText() |
---|
| 109 | { |
---|
| 110 | this->resize(); |
---|
| 111 | this->setFrontColor(Color(1,1,1,1), true); |
---|
| 112 | emit(this->textChanged(this->_text.text())); |
---|
| 113 | } |
---|
| 114 | |
---|
| 115 | |
---|
| 116 | |
---|
| 117 | /** |
---|
| 118 | * @brief Resizes the Widget to the new Size-constraints. |
---|
| 119 | */ |
---|
| 120 | void GLGuiText::resize() |
---|
| 121 | { |
---|
| 122 | this->_text.setRelCoor2D(borderLeft(), borderTop()); |
---|
| 123 | this->setSize2D( this->_text.getSize2D() + Vector2D(borderLeft() + borderRight(), borderTop() + borderBottom())); |
---|
| 124 | GLGuiWidget::resize(); |
---|
| 125 | /* this->frontRect().setTopLeft(borderLeft(), borderTop()); |
---|
| 126 | this->frontRect().setSize(this->getSize2D() - Vector2D(borderLeft() + borderRight(), borderTop() + borderBottom()));*/ |
---|
| 127 | } |
---|
| 128 | |
---|
| 129 | void GLGuiText::updateFrontColor() |
---|
| 130 | { |
---|
| 131 | this->_text.setColor(foregroundColor()); |
---|
| 132 | } |
---|
| 133 | |
---|
| 134 | void GLGuiText::hiding() |
---|
| 135 | { |
---|
| 136 | this->_text.setVisibility(false); |
---|
| 137 | } |
---|
| 138 | |
---|
| 139 | void GLGuiText::showing() |
---|
| 140 | { |
---|
| 141 | this->_text.setVisibility(true); |
---|
| 142 | } |
---|
| 143 | |
---|
| 144 | |
---|
| 145 | |
---|
| 146 | /** |
---|
[7779] | 147 | * draws the GLGuiText |
---|
| 148 | */ |
---|
[8973] | 149 | void GLGuiText::draw() const |
---|
[7779] | 150 | { |
---|
[8973] | 151 | this->beginDraw(); |
---|
| 152 | GLGuiWidget::draw(); |
---|
| 153 | |
---|
| 154 | // this->frontMaterial().select(); |
---|
| 155 | // GLGuiWidget::drawRect(this->frontRect()); |
---|
| 156 | |
---|
| 157 | this->endDraw(); |
---|
[7779] | 158 | } |
---|
[5360] | 159 | } |
---|