Linux multi-monitor fullscreen support
[ryzomcore.git] / ryzom / client / src / interfaces_manager / chat_input.cpp
blob6d4ae4119f5608f4b0663023d4b3f9789397868d
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #include "stdpch.h"
21 //////////////
22 // Includes //
23 //////////////
24 // 3D Interface.
25 #include "nel/3d/u_driver.h"
26 #include "nel/3d/u_text_context.h"
27 // Client
28 #include "client_cfg.h"
29 #include "chat_input.h"
30 #include "chat_control.h"
31 #include "interfaces_manager.h"
32 // Misc.
33 #include "nel/misc/command.h"
35 ////////////////
36 // Namespaces //
37 ////////////////
38 using namespace NLMISC;
39 using namespace NL3D;
40 using namespace std;
43 /////////////
44 // Externs //
45 /////////////
46 extern UDriver *Driver;
49 //-----------------------------------------------
50 // CChatInput :
51 // Constructor.
52 //-----------------------------------------------
53 CChatInput::CChatInput(uint id)
54 : CCapture(id)
56 init();
57 }// CChatInput //
59 //-----------------------------------------------
60 // CChatInput :
61 // Constructor.
62 //-----------------------------------------------
63 CChatInput::CChatInput(uint id, float x, float y, float x_pixel, float y_pixel, float w, float h, float w_pixel, float h_pixel, uint numFunc, const CPen &pen)
64 : CCapture(id, x, y, x_pixel, y_pixel, w, h, w_pixel, h_pixel, numFunc, pen)
66 init();
67 }// CChatInput //
69 //-----------------------------------------------
70 // CChatInput :
71 // Constructor.
72 //-----------------------------------------------
73 CChatInput::CChatInput(uint id, float x, float y, float x_pixel, float y_pixel, float w, float h, float w_pixel, float h_pixel, uint numFunc, uint32 fontSize, CRGBA color, bool shadow)
74 : CCapture(id, x, y, x_pixel, y_pixel, w, h, w_pixel, h_pixel, numFunc, fontSize, color, shadow)
76 init();
77 }// CChatInput //
79 //-----------------------------------------------
80 // ~CChatInput :
81 // Destructor.
82 //-----------------------------------------------
83 CChatInput::~CChatInput()
85 // Remove the listener.
86 Driver->EventServer.removeListener(EventCharId, this);
87 }// ~CChatInput //
89 //-----------------------------------------------
90 // init :
91 // Initialize the button (1 function called for all constructors -> easier).
92 //-----------------------------------------------
93 void CChatInput::init()
95 _Prompt = "Say : ";
96 }// init //
99 //---------------------------------------------------
100 // operator() :
101 // Function that receives events.
102 //---------------------------------------------------
103 void CChatInput::operator()(const CEvent& event)
105 CEventChar &ec = (CEventChar&)event;
106 switch(ec.Char)
108 // RETURN : Send the chat message
109 case KeyRETURN:
110 if(insert())
111 execute();
112 else
113 insert(true);
114 break;
116 // BACKSPACE
117 case KeyBACK:
118 if(insert())
120 if(_Str.size()!= 0)
122 _Str.erase( _Str.end()-1 );
125 break;
127 // TAB
128 case KeyTAB:
129 if(insert())
131 if(!_Str.empty() && _Str[0] == '/')
133 string command = _Str.toString().substr(1);
134 ICommand::expand(command);
135 _Str = '/' + command;
138 break;
140 // ESCAPE
141 case KeyESCAPE:
142 if(insert())
144 _Str.clear();
145 insert(false);
147 break;
149 // OTHER
150 default:
151 if(insert())
152 if(_Str.size() < _MaxChar)
153 _Str += ec.Char;
154 break;
156 }// operator() //
159 //---------------------------------------------------
160 // execute:
161 //---------------------------------------------------
162 void CChatInput::execute()
165 CInterfMngr::runFuncCtrl(_NumFunc, id());
166 _Str.clear();
167 _Insert = false;
168 }// execute //