1 //////////////////////////////////////////////////////////////////////////////// 2 // Scorched3D (c) 2000-2011 3 // 4 // This file is part of Scorched3D. 5 // 6 // Scorched3D 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 of the License, or 9 // (at your option) any later version. 10 // 11 // Scorched3D is distributed in the hope that it will be useful, 12 // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 // GNU General Public License for more details. 15 // 16 // You should have received a copy of the GNU General Public License along 17 // with this program; if not, write to the Free Software Foundation, Inc., 18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 //////////////////////////////////////////////////////////////////////////////// 20 21 #if !defined(__INCLUDE_GLWChatViewh_INCLUDE__) 22 #define __INCLUDE_GLWChatViewh_INCLUDE__ 23 24 #include <GLW/GLWidget.h> 25 #include <GLW/GLWIconButton.h> 26 #include <GLEXT/GLFont2d.h> 27 #include <GLEXT/GLTextureReference.h> 28 #include <common/KeyboardKey.h> 29 #include <common/Vector.h> 30 #include <lang/LangString.h> 31 #include <list> 32 33 class GLWChatView : 34 public GLWidget, 35 public GLWButtonI 36 { 37 public: 38 GLWChatView(float x = 0.0f, float y = 0.0f, float w = 0.0f, float h = 0.0f); 39 virtual ~GLWChatView(); 40 41 void addLargeChat(const Vector &color, const LangString &text, GLFont2dI *render = 0); 42 void addChat(const Vector &color, const LangString &text, GLFont2dI *render = 0); 43 void clearChat(); 44 45 virtual bool initFromXMLInternal(XMLNode *node); 46 setAllowScroll(bool allowScroll)47 void setAllowScroll(bool allowScroll) { allowScroll_ = allowScroll; } setDisplayTime(float displayTime)48 void setDisplayTime(float displayTime) { displayTime_ = displayTime; } setSplitLargeLines(bool splitLargeLines)49 void setSplitLargeLines(bool splitLargeLines) { splitLargeLines_ = splitLargeLines; } setVisibleLines(int visibleLines)50 void setVisibleLines(int visibleLines) { visibleLines_ = visibleLines; } 51 getParentSized()52 bool getParentSized() { return parentSized_; } setParentSized(bool parentSized)53 void setParentSized(bool parentSized) { parentSized_ = parentSized; } 54 55 // GLWidget 56 virtual void draw(); 57 virtual void simulate(float frameTime); 58 virtual bool initFromXML(XMLNode *node); 59 virtual void mouseDown(int button, float x, float y, bool &skipRest); 60 virtual void mouseUp(int button, float x, float y, bool &skipRest); 61 virtual void mouseDrag(int button, float mx, float my, float x, float y, bool &skipRest); 62 virtual void keyDown(char *buffer, unsigned int keyState, 63 KeyboardHistory::HistoryElement *history, int hisCount, 64 bool &skipRest); 65 virtual void setX(float x); 66 virtual void setY(float y); 67 68 // ButtonI 69 virtual void buttonDown(unsigned int id); 70 71 REGISTER_CLASS_HEADER(GLWChatView); 72 73 protected: 74 bool init_; 75 76 int splitLine(const LangString &message); 77 private: 78 class GLWChatViewEntry 79 { 80 public: GLWChatViewEntry(const Vector & color,const LangString & text,float timeRemaining,GLFont2dI * renderer)81 GLWChatViewEntry(const Vector &color, const LangString &text, 82 float timeRemaining, GLFont2dI *renderer) 83 { 84 this->color = color; 85 this->text = text; 86 this->timeRemaining = timeRemaining; 87 this->renderer = renderer; 88 } ~GLWChatViewEntry()89 virtual ~GLWChatViewEntry() 90 { 91 delete renderer; 92 } 93 94 Vector color; 95 LangString text; 96 float timeRemaining; 97 GLFont2dI *renderer; 98 }; 99 100 GLWIconButton upButton_; 101 GLWIconButton downButton_; 102 GLWIconButton resetButton_; 103 104 bool alignTop_, parentSized_; 105 bool splitLargeLines_, allowScroll_; 106 int lineDepth_; 107 int scrollPosition_; 108 float displayTime_; 109 float fontSize_, outlineFontSize_; 110 int visibleLines_, totalLines_; 111 int currentVisible_; 112 std::list<GLWChatViewEntry *> textLines_; 113 KeyboardKey *scrollUpKey_; 114 KeyboardKey *scrollDownKey_; 115 KeyboardKey *scrollResetKey_; 116 }; 117 118 #endif // __INCLUDE_GLWChatViewh_INCLUDE__ 119