sources/interface.h

Tue, 26 May 2015 11:41:58 +0300

author
Teemu Piippo <crimsondusk64@gmail.com>
date
Tue, 26 May 2015 11:41:58 +0300
changeset 81
a18aaf460648
parent 73
07dda51a7a8e
child 78
c1d43ade656e
child 83
08bfc3d9d2ae
permissions
-rw-r--r--

Allow compilation on Windows/MinGW

/*
	Copyright 2014, 2015 Teemu Piippo
	All rights reserved.

	Redistribution and use in source and binary forms, with or without
	modification, are permitted provided that the following conditions
	are met:

	1. Redistributions of source code must retain the above copyright
	   notice, this list of conditions and the following disclaimer.
	2. Redistributions in binary form must reproduce the above copyright
	   notice, this list of conditions and the following disclaimer in the
	   documentation and/or other materials provided with the distribution.
	3. Neither the name of the copyright holder nor the names of its
	   contributors may be used to endorse or promote products derived from
	   this software without specific prior written permission.

	THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
	"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
	TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
	PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER
	OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
	EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
	PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
	PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
	LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
	NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
	SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#pragma once
#include "main.h"
#include "network/ipaddress.h"
#include "coloredline.h"
#include "network/rconsession.h"

class Interface
{
public:
	enum InputState
	{
		INPUTSTATE_NORMAL,
		INPUTSTATE_ADDRESS,
		INPUTSTATE_PASSWORD,
		INPUTSTATE_CONFIRM_DISCONNECTION,
	};

	Interface();
	void handle_input();
	void render();
	void render_full();
	void set_title (const String& message);
	void update_statusbar();
	void connect (String address, String password);
	void set_player_names (const StringList& names);
	void need_refresh();
	void tab_complete (const String& part, String complete);
	RCONSession* get_session() { return &Session; }

	template<typename... argtypes>
	void print (const String& fmtstr, const argtypes&... args)
	{
		print_to_console (format (fmtstr, args...));
	}

	template<typename... argtypes>
	void print_warning (const String& fmtstr, const argtypes&... args)
	{
		print_to_console (TEXTCOLOR_BrightYellow "-!- " + format (fmtstr, args...) + TEXTCOLOR_Reset);
	}

	template<typename... argtypes>
	void print_error (const String& fmtstr, const argtypes&... args)
	{
		print_to_console (TEXTCOLOR_BrightRed "!!! " + format (fmtstr, args...) + TEXTCOLOR_Reset);
	}

private:
	StringList InputHistory;
	int InputCursor = 0;
	int CursorPosition = 0;
	int InputPanning = 0;
	bool NeedRefresh = false;
	bool NeedStatusBarRender = false;
	bool NeedInputRender = false;
	bool NeedOutputRender = false;
	bool NeedNicklistRender = false;
	struct { char ch; int x; } CursorCharacter;
	Vector<ColoredLine> OutputLines;
	int OutputScroll = 0;
	String Title;
	InputState CurrentInputState = INPUTSTATE_NORMAL;
	Function<void (void)> DisconnectConfirmFunction = nullptr;
	IPAddress CurrentAddress;
	String StatusBarText;
	StringList PlayerNames;
	String PasteBuffer;
	RCONSession Session;

	void render_titlebar();
	void safe_disconnect (Function<void()> afterwards);
	int render_colorline (int y, int x0, int width, const ColoredLine& line, bool allowWrap);
	int nicklist_width();
	void render_output();
	void render_nicklist();
	void render_input();
	void render_statusbar();
	void position_cursor();
	int color_pair (Color fg, Color bg);
	const String& current_input();
	void detach_input();
	String& mutable_current_input();
	void move_input_cursor (int delta);
	String prompt_string();
	void set_input_state (InputState newstate);
	void print_to_console (String a);
	void yank (int a, int b);
	int find_previous_word();
	int find_next_word();
};

mercurial