Example #1
0
/***********************************************************
handle world selected event
***********************************************************/
bool ChooseWorldGUI::HandleWorldSelected (const CEGUI::EventArgs& e)
{
	try
	{
		CEGUI::Listbox * lb = static_cast<CEGUI::Listbox *> (
				CEGUI::WindowManager::getSingleton().getWindow("ChooseWorldList"));
		if(lb)
		{
			size_t idx = lb->getItemIndex(lb->getFirstSelectedItem());
			if(idx < _wlist.size())
			{
				CEGUI::MultiLineEditbox * eb = static_cast<CEGUI::MultiLineEditbox *> (
					CEGUI::WindowManager::getSingleton().getWindow("ChooseWorldDescription"));
				if(eb)
				{
					eb->setText(_wlist[idx].Description);
				}

				_selectedworld = _wlist[idx].WorldName;
			}
		}
	}
	catch(CEGUI::Exception &ex)
	{
		LogHandler::getInstance()->LogToFile(std::string("Exception init the world list: ") + ex.getMessage().c_str());
		_root = NULL;
	}

	return true;
}
	void ControllerUI::CopyToClipboard(::CEGUI::Window* EditBox, bool Cut)
	{
		if (!EditBox)
			return;

		// get possibly typed instances we process
		CEGUI::Editbox* box				= dynamic_cast<CEGUI::Editbox*>(EditBox);
		CEGUI::MultiLineEditbox* mlbox	= dynamic_cast<CEGUI::MultiLineEditbox*>(EditBox);
		
		// type of Editbox
		if (box)
		{						
			// get text from cegui textbox
			::CEGUI::String boxStr = box->getText();

			size_t start = box->getSelectionStartIndex();
			size_t len = box->getSelectionLength();

			// get substring which is selected
			boxStr = boxStr.substr(start, len);
			
			// copy to clipboard
			if (boxStr.length() > 0)
			{
				::System::Windows::Forms::Clipboard::SetText(StringConvert::CEGUIToCLR(boxStr));
			
				if (Cut)			
					box->eraseSelectedText();
			}
		}

		// type of MultiLineEditbox
		else if (mlbox)
		{
			// get text from cegui textbox
			::CEGUI::String boxStr = mlbox->getText();

			size_t start = mlbox->getSelectionStartIndex();
			size_t len = mlbox->getSelectionLength();

			// get substring which is selected
			boxStr = boxStr.substr(start, len);
			
			// copy to clipboard
			if (boxStr.length() > 0)
			{
				::System::Windows::Forms::Clipboard::SetText(StringConvert::CEGUIToCLR(boxStr));
			
				if (Cut)			
					mlbox->eraseSelectedText();
			}
		}	
	};
	void ControllerUI::PasteFromClipboard(::CEGUI::Window* EditBox)
	{
		if (!EditBox || !::System::Windows::Forms::Clipboard::ContainsText())
			return;

		// get text from clipboard
		::System::String^ clipText = ::System::Windows::Forms::Clipboard::GetText(
			::System::Windows::Forms::TextDataFormat::Text);
		
		// no text
		if (!clipText || clipText->Length == 0)
			return;
		
		// get possibly typed instances we process
		CEGUI::Editbox* box				= dynamic_cast<CEGUI::Editbox*>(EditBox);
		CEGUI::MultiLineEditbox* mlbox	= dynamic_cast<CEGUI::MultiLineEditbox*>(EditBox);
		
		// type of Editbox
		if (box && !box->isReadOnly())
		{					
			// replace newline characters
			clipText = clipText->Replace(
				::System::Environment::NewLine, ::System::String::Empty);

			// get caretindex
			size_t caretindex = box->getCaretIndex();

			// insert new text
			box->insertText(StringConvert::CLRToCEGUI(clipText), caretindex);

			// set caret at the end of inserted text
			box->setCaretIndex(caretindex + clipText->Length);
		}

		// type of MultiLineEditbox
		else if (mlbox && !mlbox->isReadOnly())
		{
			// get caretindex
			size_t caretindex = mlbox->getCaretIndex();

			// insert new text
			mlbox->insertText(StringConvert::CLRToCEGUI(clipText), caretindex);

			// set caret at the end of inserted text
			mlbox->setCaretIndex(caretindex + clipText->Length);
		}
	};
Example #4
0
void cText_Box :: Editor_Activate( void )
{
	// BaseBox Settings first
	cBaseBox::Editor_Activate();

	// get window manager
	CEGUI::WindowManager &wmgr = CEGUI::WindowManager::getSingleton();

	// text
	CEGUI::MultiLineEditbox *editbox = static_cast<CEGUI::MultiLineEditbox *>(wmgr.createWindow( "TaharezLook/MultiLineEditbox", "text_box_text" ));
	Editor_Add( UTF8_("Text"), UTF8_("Text to display when activated"), editbox, static_cast<float>(text_box_window_width), static_cast<float>(text_box_window_height) );

	editbox->setText( reinterpret_cast<const CEGUI::utf8*>(text.c_str()) );
	editbox->subscribeEvent( CEGUI::MultiLineEditbox::EventTextChanged, CEGUI::Event::Subscriber( &cText_Box::Editor_Text_Text_Changed, this ) );

	// init
	Editor_Init();
}
Example #5
0
void GuiChat::writeMessage(Event* event)
{
	if (event->hasProperty("Perso") && event->hasProperty("Message"))
	{
		std::string message = event->getProperty("Perso") + " > " + event->getProperty("Message");
		// add this entry to the command history buffer
		d_history.push_back(message);
		// reset history position
		d_historyPos = d_history.size();
		// append newline to this entry
		message += '\n';
		// get history window
		CEGUI::MultiLineEditbox* history = static_cast<CEGUI::MultiLineEditbox*>(chatWindow->getChild("ListOfMessage"));
		// append new text to history output
		history->setText(history->getText() + message);
		// scroll to bottom of history output
		history->setCaretIndex(static_cast<size_t>(-1));
	}

}
Example #6
0
/***********************************************************
inform the user the login failed
***********************************************************/
void LoginGUI::InformNotLoggedIn(int problem, const std::string & reason)
{
	try
	{
		CEGUI::MultiLineEditbox * txs =
		static_cast<CEGUI::MultiLineEditbox *> (CEGUI::WindowManager::getSingleton().getWindow("DisplayLoginErrorFrame/text"));


		if(problem == 0)	// can not connect to the server
		{
			txs->setText("");
			txs->appendText("Error trying to log on the server:");
			txs->appendText("Server is not reacheable.");
		}

		if(problem == -1)	// wrong login / password
		{
			txs->setText("");
			txs->appendText("Error trying to log on the server:");
			txs->appendText("Permission denied:");
			txs->appendText(reason);
		}

		if(problem == -2)	// got disconnected
		{
			txs->setText("");
			txs->appendText("You got disconnected from the server.");
		}

		CEGUI::WindowManager::getSingleton().getWindow("DisplayLoginErrorFrame")->show();
	}
	catch(CEGUI::Exception &ex)
	{
		LogHandler::getInstance()->LogToFile(std::string("Exception showing login error window: ") + ex.getMessage().c_str());
		_root = NULL;
	}
}
Example #7
0
/***********************************************************
handle world selected event
***********************************************************/
bool ChooseWorldGUI::HandleWorldSelected (const CEGUI::EventArgs& e)
{
	try
	{
		CEGUI::Listbox * lb = static_cast<CEGUI::Listbox *> (
				CEGUI::WindowManager::getSingleton().getWindow("ChooseWorldList"));
		if(lb)
		{
			size_t idx = lb->getItemIndex(lb->getFirstSelectedItem());
			if(idx < _wlist.size())
			{
				CEGUI::MultiLineEditbox * eb = static_cast<CEGUI::MultiLineEditbox *> (
					CEGUI::WindowManager::getSingleton().getWindow("ChooseWorldDescription"));
				if(eb)
				{
					std::string str = _wlist[idx].Description;
					int idxs = 0;
					bool firsttime=true;
					while((idxs = str.find(" @ ")) != std::string::npos)
					{
						std::string tmp = str.substr(0, idxs);
						if(tmp == "")
							tmp = "\n";

						if(firsttime)
						{
							firsttime = false;
							eb->setText((const unsigned char *)tmp.c_str());
						}
						else
							eb->appendText((const unsigned char *)tmp.c_str());

						while(((idxs+4) < (int)str.size()) && (str[idxs+3] == '@') && (str[idxs+4] == ' '))
						{
							eb->appendText("\n");
							idxs+= 2;
						}

						str = str.substr(idxs+3);
					}

					if(firsttime)
					{
						firsttime = false;
						eb->setText((const unsigned char *)str.c_str());
					}
					else
						eb->appendText((const unsigned char *)str.c_str());
				}

				 eb = static_cast<CEGUI::MultiLineEditbox *> (
					CEGUI::WindowManager::getSingleton().getWindow("ChooseWorldNews"));
				if(eb)
				{
					std::string str = _wlist[idx].News;
					int idxs = 0;
					bool firsttime=true;
					while((idxs = str.find(" @ ")) != std::string::npos)
					{
						std::string tmp = str.substr(0, idxs);
						if(tmp == "")
							tmp = "\n";

						if(firsttime)
						{
							firsttime = false;
							eb->setText((const unsigned char *)tmp.c_str());
						}
						else
							eb->appendText((const unsigned char *)tmp.c_str());

						while(((idxs+4) < (int)str.size()) && (str[idxs+3] == '@') && (str[idxs+4] == ' '))
						{
							eb->appendText("\n");
							idxs+= 2;
						}

						str = str.substr(idxs+3);
					}

					if(firsttime)
					{
						firsttime = false;
						eb->setText((const unsigned char *)str.c_str());
					}
					else
						eb->appendText((const unsigned char *)str.c_str());
				}

				_selectedworld = idx;
				ConfigurationManager::GetInstance()->SetValue("Options.General.SelectedWorld", _selectedworld);
			}
		}
	}
	catch(CEGUI::Exception &ex)
	{
		LogHandler::getInstance()->LogToFile(std::string("Exception init the world list: ") + ex.getMessage().c_str());
		_root = NULL;
	}

	return true;
}
Example #8
0
void CGUIMemo_Impl::EnsureCaratIsVisible ( void )
{
    CEGUI::MultiLineEditbox* wndMemo = reinterpret_cast < CEGUI::MultiLineEditbox* > ( m_pWindow );
    wndMemo->setCaratIndex ( ( wndMemo->getText ( ) ).length ( ) );
}
Example #9
0
void cText_Box :: Activate( void )
{
	CEGUI::WindowManager &wmgr = CEGUI::WindowManager::getSingleton();
	CEGUI::MultiLineEditbox *editbox = static_cast<CEGUI::MultiLineEditbox *>(wmgr.createWindow( "TaharezLook/MultiLineEditbox", "text_box_text" ));

	// add to main window
	pGuiSystem->getGUISheet()->addChildWindow( editbox );


	// set on top
	editbox->setAlwaysOnTop( 1 );
	// set position
	float text_pos_x = m_pos_x - ( text_box_window_width * 0.5f ) + ( m_rect.m_w * 0.5f );
	float text_pos_y = m_pos_y - 5 - text_box_window_height;

	// if not on screen on the left side
	if( text_pos_x < 0 )
	{
		// put it on screen
		text_pos_x = 0;
	}
	// if not on screen on the right side
	if( text_pos_x > pActive_Camera->limit_rect.m_x + pActive_Camera->limit_rect.m_w - text_box_window_width )
	{
		// put it on screen
		text_pos_x = pActive_Camera->limit_rect.m_x + pActive_Camera->limit_rect.m_w - text_box_window_width;
	}

	editbox->setXPosition( CEGUI::UDim( 0, ( text_pos_x - pActive_Camera->x ) * global_upscalex ) );
	editbox->setYPosition( CEGUI::UDim( 0, ( text_pos_y - pActive_Camera->y ) * global_upscaley ) );
	// set size
	editbox->setWidth( CEGUI::UDim( 0, text_box_window_width * global_upscalex ) );
	editbox->setHeight( CEGUI::UDim( 0, text_box_window_height * global_upscaley ) );

	// set text
	editbox->setText( reinterpret_cast<const CEGUI::utf8*>(text.c_str()) );
	// always hide horizontal scrollbar
	editbox->getHorzScrollbar()->hide();

	bool display = 1;

	while( display )
	{
		while( SDL_PollEvent( &input_event ) )
		{
			if( input_event.type == SDL_KEYDOWN )
			{
				pKeyboard->keys[input_event.key.keysym.sym] = 1;

				// exit keys
				if( input_event.key.keysym.sym == pPreferences->m_key_action || input_event.key.keysym.sym == SDLK_ESCAPE || input_event.key.keysym.sym == SDLK_RETURN || input_event.key.keysym.sym == SDLK_SPACE )
				{
					display = 0;
					break;
				}
				// handled keys
				else if( input_event.key.keysym.sym == pPreferences->m_key_right || input_event.key.keysym.sym == pPreferences->m_key_left )
				{
					pKeyboard->Key_Down( input_event.key.keysym.sym );
				}
			}
			else if( input_event.type == SDL_KEYUP )
			{
				pKeyboard->keys[input_event.key.keysym.sym] = 0;

				// handled keys
				if( input_event.key.keysym.sym == pPreferences->m_key_right || input_event.key.keysym.sym == pPreferences->m_key_left )
				{
					pKeyboard->Key_Up( input_event.key.keysym.sym );
				}
			}
			else if( input_event.type == SDL_JOYBUTTONDOWN )
			{
				pJoystick->Set_Button( input_event.jbutton.button, 1 );

				if( input_event.jbutton.button == pPreferences->m_joy_button_action || input_event.jbutton.button == pPreferences->m_joy_button_exit )
				{
					display = 0;
					break;
				}
			}
			else if( input_event.type == SDL_JOYBUTTONUP )
			{
				pJoystick->Set_Button( input_event.jbutton.button, 0 );
			}
			else if( input_event.type == SDL_JOYHATMOTION )
			{
				pJoystick->Handle_Hat( &input_event );
				break;
			}
			else if( input_event.type == SDL_JOYAXISMOTION )
			{
				pJoystick->Handle_Motion( &input_event );
				break;
			}
		}

		Uint8 *keys = SDL_GetKeyState( NULL );
		Sint16 joy_ver_axis = 0;

		// if joystick enabled
		if( pPreferences->m_joy_enabled )
		{
			joy_ver_axis = SDL_JoystickGetAxis( pJoystick->joystick, pPreferences->m_joy_axis_ver );
		}

		// down
		if( keys[pPreferences->m_key_down] || joy_ver_axis > pPreferences->m_joy_axis_threshold )
		{
			editbox->getVertScrollbar()->setScrollPosition( editbox->getVertScrollbar()->getScrollPosition() + ( editbox->getVertScrollbar()->getStepSize() * 0.25f * pFramerate->m_speed_factor ) );
		}
		// up
		if( keys[pPreferences->m_key_up] || joy_ver_axis < -pPreferences->m_joy_axis_threshold )
		{
			editbox->getVertScrollbar()->setScrollPosition( editbox->getVertScrollbar()->getScrollPosition() - ( editbox->getVertScrollbar()->getStepSize() * 0.25f * pFramerate->m_speed_factor ) );
		}

		// move camera because text could not be completely visible
		if( pActive_Camera->y_offset > 0 )
		{
			pActive_Camera->y_offset -= 2;
			// set position
			pActive_Camera->Center();

			// set position
			editbox->setXPosition( CEGUI::UDim( 0, ( text_pos_x - pActive_Camera->x ) * global_upscalex ) );
			editbox->setYPosition( CEGUI::UDim( 0, ( text_pos_y - pActive_Camera->y ) * global_upscaley ) );
		}

		// update animation
		Update();
		
		// update audio
		pAudio->Update();
		// draw
		Draw_Game();
		// render
		pVideo->Render();
		pFramerate->Update();
	}

	wmgr.destroyWindow( editbox );
}
Example #10
0
/***********************************************************
handle send button event
***********************************************************/
bool ChatBox::HandleEnterKey (const CEGUI::EventArgs& e)
{
	const CEGUI::KeyEventArgs& we =
    static_cast<const CEGUI::KeyEventArgs&>(e);

	const CEGUI::WindowEventArgs& wine =
    static_cast<const CEGUI::WindowEventArgs&>(e);


	if(we.scancode == CEGUI::Key::LeftControl || we.scancode == CEGUI::Key::RightControl)
	{
		_control_key_on = true;
		return true;
	}

	if(we.scancode == CEGUI::Key::LeftShift || we.scancode == CEGUI::Key::RightShift)
	{
		_shift_key_on = true;
		return true;
	}

	if(we.scancode == CEGUI::Key::LeftAlt || we.scancode == CEGUI::Key::RightAlt)
	{
		return true;
	}

	if(wine.window->getName() == "Chat/edit")
	{
		if(we.scancode == CEGUI::Key::Return)
		{
			HandleSend (e);

			CEGUI::Editbox * bed = static_cast<CEGUI::Editbox *>
			(CEGUI::WindowManager::getSingleton().getWindow("Chat/edit"));
			bed->deactivate();
			return true;
		}

		if(we.scancode == CEGUI::Key::ArrowUp)
		{
			if(_itltext == _lasttexts.end())
				_itltext = _lasttexts.begin();
			else
			{
				std::list<std::string>::iterator ittmp = _itltext;
				++ittmp;
				if(ittmp != _lasttexts.end())
					++_itltext;
			}

			try
			{
				CEGUI::Window *windowchat = CEGUI::WindowManager::getSingleton().getWindow("Chat/edit");
				std::string text = "";
				if(_itltext != _lasttexts.end())
					text = *_itltext;

				if(windowchat)
					windowchat->setText((const unsigned char *)text.c_str());
			}
			catch(...){}

			//++_currSelectedch;
			//if(_currSelectedch >= (int)_channels.size())
			//	--_currSelectedch;
			//else
			//{
			//	std::list<std::string>::const_iterator it = _channels.begin();
			//	std::list<std::string>::const_iterator end = _channels.end();
			//	for(int cc=0; cc<_currSelectedch && it != end; ++it, ++cc);

			//	CEGUI::PushButton * bch = static_cast<CEGUI::PushButton *>
			//		(CEGUI::WindowManager::getSingleton().getWindow("Chat/bChannel"));
			//	bch->setProperty("Text", *it);
			//}



			return true;
		}
		if(we.scancode == CEGUI::Key::ArrowDown)
		{
			if(_itltext != _lasttexts.end())
			{
				if(_itltext != _lasttexts.begin())
					--_itltext;
				else
					_itltext = _lasttexts.end();
			}

			CEGUI::Window *windowchat = CEGUI::WindowManager::getSingleton().getWindow("Chat/edit");
			std::string text = "";
			if(_itltext != _lasttexts.end())
				text = *_itltext;

			if(windowchat)
				windowchat->setText((const unsigned char *)text.c_str());


			//--_currSelectedch;
			//if(_currSelectedch < 0)
			//	++_currSelectedch;
			//else
			//{
			//	std::list<std::string>::const_iterator it = _channels.begin();
			//	std::list<std::string>::const_iterator end = _channels.end();
			//	for(int cc=0; cc<_currSelectedch && it != end; ++it, ++cc);

			//	CEGUI::PushButton * bch = static_cast<CEGUI::PushButton *>
			//		(CEGUI::WindowManager::getSingleton().getWindow("Chat/bChannel"));
			//	bch->setProperty("Text", *it);
			//}

			return true;
		}


		if(we.scancode == CEGUI::Key::ArrowUp || we.scancode == CEGUI::Key::ArrowDown)
			return true;



		// paste text
		if(we.scancode == CEGUI::Key::V && _control_key_on)
		{
			CEGUI::Editbox * bed = static_cast<CEGUI::Editbox *>
				(CEGUI::WindowManager::getSingleton().getWindow("Chat/edit"));
			if(bed && bed->isActive())
			{
				if(_text_copyed != "")
				{
					size_t selB = bed->getSelectionStartIndex();
					size_t selE = bed->getSelectionLength();
					CEGUI::String str = bed->getText();
					if(selE > 0)
					{
						str = str.erase(selB, selE);
					}

					if(str.size() + _text_copyed.size() < bed->getMaxTextLength())
					{
						size_t idx = bed->getCaratIndex();
						str = str.insert(idx, (unsigned char *)_text_copyed.c_str());
						bed->setText(str);
						bed->setCaratIndex(idx + _text_copyed.size());
					}
				}

				return true;
			}
		}
	}



	// copy text
	if(we.scancode == CEGUI::Key::C && _control_key_on)
	{
		CEGUI::Window * actw = _myChat->getActiveChild();
		if(actw != NULL)
		{
			if(actw->getName() == "Chat/edit")
			{
				CEGUI::Editbox * bed = static_cast<CEGUI::Editbox *> (actw);
				size_t selB = bed->getSelectionStartIndex();
				size_t selE = bed->getSelectionLength();
				if(selE > 0)
				{
					CEGUI::String str = bed->getText().substr(selB, selE);
					_text_copyed = str.c_str();
				}

				return true;
			}
			else
			{
				CEGUI::MultiLineEditbox* txt = static_cast<CEGUI::MultiLineEditbox *>(actw);
				size_t selB = txt->getSelectionStartIndex();
				size_t selE = txt->getSelectionLength();
				if(selE > 0)
				{
					CEGUI::String str = txt->getText().substr(selB, selE);
					_text_copyed = str.c_str();
				}

				return true;
			}
		}

	}

    return false;
}
Example #11
0
/***********************************************************
handle send button event
***********************************************************/
bool ChatBox::HandleEnterKey (const CEGUI::EventArgs& e)
{
	const CEGUI::KeyEventArgs& we =
    static_cast<const CEGUI::KeyEventArgs&>(e);

	const CEGUI::WindowEventArgs& wine =
    static_cast<const CEGUI::WindowEventArgs&>(e);


	if(we.scancode == CEGUI::Key::LeftControl || we.scancode == CEGUI::Key::RightControl)
	{
		_control_key_on = true;
		return true;
	}

	if(we.scancode == CEGUI::Key::LeftShift || we.scancode == CEGUI::Key::RightShift)
	{
		_shift_key_on = true;
		return true;
	}


	if(wine.window->getName() == "Chat/edit")
	{
		if(we.scancode == CEGUI::Key::Return)
		{
			HandleSend (e);

			CEGUI::Editbox * bed = static_cast<CEGUI::Editbox *>
			(CEGUI::WindowManager::getSingleton().getWindow("Chat/edit"));
			bed->deactivate();
			return true;
		}

		if(we.scancode == CEGUI::Key::ArrowUp)
		{
			if(_itltext == _lasttexts.end())
				_itltext = _lasttexts.begin();
			else
			{
				std::list<std::string>::iterator ittmp = _itltext;
				++ittmp;
				if(ittmp != _lasttexts.end())
					++_itltext;
			}

			try
			{
				if(_itltext != _lasttexts.end())
				{
					CEGUI::WindowManager::getSingleton().getWindow("Chat/edit")->setText(
														(const unsigned char *)_itltext->c_str());
				}
				else
				{
					CEGUI::WindowManager::getSingleton().getWindow("Chat/edit")->setText("");
				}
			}
			catch(...){}

			return true;
		}
		if(we.scancode == CEGUI::Key::ArrowDown)
		{
			if(_itltext != _lasttexts.end())
			{
				if(_itltext != _lasttexts.begin())
					--_itltext;
				else
					_itltext = _lasttexts.end();
			}

			if(_itltext != _lasttexts.end())
			{
				CEGUI::WindowManager::getSingleton().getWindow("Chat/edit")->setText(
													(const unsigned char *)_itltext->c_str());
			}
			else
			{
				CEGUI::WindowManager::getSingleton().getWindow("Chat/edit")->setText("");
			}

			return true;
		}


		if(we.scancode == CEGUI::Key::ArrowUp || we.scancode == CEGUI::Key::ArrowDown)
			return true;



		// paste text
		if(we.scancode == CEGUI::Key::V && _control_key_on)
		{
			CEGUI::Editbox * bed = static_cast<CEGUI::Editbox *>
				(CEGUI::WindowManager::getSingleton().getWindow("Chat/edit"));
			if(bed->isActive())
			{
				if(_text_copyed != "")
				{
					size_t selB = bed->getSelectionStartIndex();
					size_t selE = bed->getSelectionLength();
					CEGUI::String str = bed->getText();
					if(selE > 0)
					{
						str = str.erase(selB, selE);
					}

					if(str.size() + _text_copyed.size() < bed->getMaxTextLength())
					{
						size_t idx = bed->getCaratIndex();
						str = str.insert(idx, (unsigned char *)_text_copyed.c_str());
						bed->setText(str);
						bed->setCaratIndex(idx + _text_copyed.size());
					}
				}

				return true;
			}
		}
	}



	// copy text
	if(we.scancode == CEGUI::Key::C && _control_key_on)
	{
		CEGUI::Window * actw = _myChat->getActiveChild();
		if(actw != NULL)
		{
			if(actw->getName() == "Chat/edit")
			{
				CEGUI::Editbox * bed = static_cast<CEGUI::Editbox *> (actw);
				size_t selB = bed->getSelectionStartIndex();
				size_t selE = bed->getSelectionLength();
				if(selE > 0)
				{
					CEGUI::String str = bed->getText().substr(selB, selE);
					_text_copyed = str.c_str();
				}

				return true;
			}
			else
			{
				CEGUI::MultiLineEditbox* txt = static_cast<CEGUI::MultiLineEditbox *>(actw);
				size_t selB = txt->getSelectionStartIndex();
				size_t selE = txt->getSelectionLength();
				if(selE > 0)
				{
					CEGUI::String str = txt->getText().substr(selB, selE);
					_text_copyed = str.c_str();
				}

				return true;
			}
		}

	}

    return false;
}
Example #12
0
bool GUI_Paste_From_Clipboard( void )
{
	CEGUI::Window *sheet = CEGUI::System::getSingleton().getGUISheet();

	// no sheet
	if( !sheet )
	{
		return 0;
	}

	CEGUI::Window *window_active = sheet->getActiveChild();

	// no active window
	if( !window_active )
	{
		return 0;
	}

	const CEGUI::String &type = window_active->getType();

	// MultiLineEditbox
	if( type.find( "/MultiLineEditbox" ) != CEGUI::String::npos )
	{
		CEGUI::MultiLineEditbox *editbox = static_cast<CEGUI::MultiLineEditbox*>(window_active);

		if( editbox->isReadOnly() )
		{
			return 0;
		}

		CEGUI::String::size_type beg = editbox->getSelectionStartIndex();
		CEGUI::String::size_type len = editbox->getSelectionLength();

		CEGUI::String new_text = editbox->getText();
		// erase selected text
		new_text.erase( beg, len );

		// get clipboard text
		CEGUI::String clipboard_text = reinterpret_cast<const CEGUI::utf8*>(Get_Clipboard_Content().c_str());
		// set new text
		editbox->setText( new_text.insert( beg, clipboard_text ) );
		// set new carat index
		editbox->setCaratIndex( editbox->getCaratIndex() + clipboard_text.length() );
	}
	// Editbox
	else if( type.find( "/Editbox" ) != CEGUI::String::npos )
	{
		CEGUI::Editbox *editbox = static_cast<CEGUI::Editbox*>(window_active);

		if( editbox->isReadOnly() )
		{
			return 0;
		}

		CEGUI::String::size_type beg = editbox->getSelectionStartIndex();
		CEGUI::String::size_type len = editbox->getSelectionLength();

		CEGUI::String new_text = editbox->getText();
		// erase selected text
		new_text.erase( beg, len );

		// get clipboard text
		CEGUI::String clipboard_text = reinterpret_cast<const CEGUI::utf8*>(Get_Clipboard_Content().c_str());
		// set new text
		editbox->setText( new_text.insert( beg, clipboard_text ) );
		// set new carat index
		editbox->setCaratIndex( editbox->getCaratIndex() + clipboard_text.length() );
	}
	else
	{
		return 0;
	}

	return 1;
}
Example #13
0
bool GUI_Copy_To_Clipboard( bool cut )
{
	CEGUI::Window *sheet = CEGUI::System::getSingleton().getGUISheet();

	// no sheet
	if( !sheet )
	{
		return 0;
	}

	CEGUI::Window *window_active = sheet->getActiveChild();

	// no active window
	if( !window_active )
	{
		return 0;
	}

	CEGUI::String sel_text;
	const CEGUI::String &type = window_active->getType();

	// MultiLineEditbox
	if( type.find( "/MultiLineEditbox" ) != CEGUI::String::npos )
	{
		CEGUI::MultiLineEditbox *editbox = static_cast<CEGUI::MultiLineEditbox*>(window_active);
		CEGUI::String::size_type beg = editbox->getSelectionStartIndex();
		CEGUI::String::size_type len = editbox->getSelectionLength();
		sel_text = editbox->getText().substr( beg, len ).c_str();

		// if cutting
		if( cut )
		{
			if( editbox->isReadOnly() )
			{
				return 0;
			}

			CEGUI::String new_text = editbox->getText();
			editbox->setText( new_text.erase( beg, len ) );
		}
	}
	// Editbox
	else if( type.find( "/Editbox" ) != CEGUI::String::npos )
	{
		CEGUI::Editbox *editbox = static_cast<CEGUI::Editbox*>(window_active);
		CEGUI::String::size_type beg = editbox->getSelectionStartIndex();
		CEGUI::String::size_type len = editbox->getSelectionLength();
		sel_text = editbox->getText().substr( beg, len ).c_str();

		// if cutting
		if( cut )
		{
			if( editbox->isReadOnly() )
			{
				return 0;
			}

			CEGUI::String new_text = editbox->getText();
			editbox->setText( new_text.erase( beg, len ) );
		}
	}
	else
	{
		return 0;
	}

	Set_Clipboard_Content( sel_text.c_str() );
	return 1;
}