src/console_gui.cpp
author rubidium
Tue, 16 Dec 2008 17:58:27 +0000
changeset 10426 4a77f7049b5e
parent 10276 b60b7e17db62
permissions -rw-r--r--
(svn r14679) -Fix [FS#2431]: opening the OSK on the chatbox did disable map scrolling (with keyboard) until another window with editbox was opened and closed. Just "refcount" the open edit boxes instead of setting/clearing a bit when opening/closing a window.
9339
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
     1
/* $Id$ */
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
     2
10238
5076964d81a1 (svn r14466) -Doc: remove some obsolete parameters, fix a few parameter names in comments and add a little more doxygen documentation.
rubidium
parents: 10207
diff changeset
     3
/** @file console_gui.cpp Handling the GUI of the in-game console. */
9339
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
     4
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
     5
#include "stdafx.h"
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
     6
#include "openttd.h"
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
     7
#include "textbuf_gui.h"
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
     8
#include "window_gui.h"
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
     9
#include "console_gui.h"
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
    10
#include <stdarg.h>
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
    11
#include <string.h>
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
    12
#include "console_internal.h"
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
    13
#include "window_func.h"
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
    14
#include "string_func.h"
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
    15
#include "gfx_func.h"
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
    16
#include "core/math_func.hpp"
9906
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
    17
#include "settings_type.h"
9339
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
    18
#include "rev.h"
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
    19
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
    20
#include "table/strings.h"
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
    21
9906
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
    22
enum {
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
    23
	ICON_HISTORY_SIZE       = 20,
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
    24
	ICON_LINE_HEIGHT        = 12,
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
    25
	ICON_RIGHT_BORDERWIDTH  = 10,
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
    26
	ICON_BOTTOM_BORDERWIDTH = 12,
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
    27
};
9339
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
    28
9906
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
    29
/**
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
    30
 * Container for a single line of console output
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
    31
 */
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
    32
struct IConsoleLine {
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
    33
	static IConsoleLine *front; ///< The front of the console backlog buffer
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
    34
	static int size;            ///< The amount of items in the backlog
9339
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
    35
9906
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
    36
	IConsoleLine *previous; ///< The previous console message.
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
    37
	char *buffer;          ///< The data to store.
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
    38
	uint16 colour;         ///< The colour of the line.
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
    39
	uint16 time;           ///< The amount of time the line is in the backlog.
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
    40
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
    41
	/**
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
    42
	 * Initialize the console line.
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
    43
	 * @param buffer the data to print.
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
    44
	 * @param colour the colour of the line.
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
    45
	 */
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
    46
	IConsoleLine(char *buffer, uint16 colour) :
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
    47
			previous(IConsoleLine::front),
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
    48
			buffer(buffer),
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
    49
			colour(colour),
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
    50
			time(0)
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
    51
	{
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
    52
		IConsoleLine::front = this;
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
    53
		IConsoleLine::size++;
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
    54
	}
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
    55
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
    56
	/**
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
    57
	 * Clear this console line and any further ones.
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
    58
	 */
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
    59
	~IConsoleLine()
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
    60
	{
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
    61
		IConsoleLine::size--;
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
    62
		free(buffer);
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
    63
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
    64
		delete previous;
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
    65
	}
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
    66
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
    67
	/**
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
    68
	 * Get the index-ed item in the list.
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
    69
	 */
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
    70
	static const IConsoleLine *Get(uint index)
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
    71
	{
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
    72
		const IConsoleLine *item = IConsoleLine::front;
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
    73
		while (index != 0 && item != NULL) {
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
    74
			index--;
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
    75
			item = item->previous;
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
    76
		}
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
    77
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
    78
		return item;
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
    79
	}
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
    80
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
    81
	/**
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
    82
	 * Truncate the list removing everything older than/more than the amount
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
    83
	 * as specified in the config file.
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
    84
	 * As a side effect also increase the time the other lines have been in
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
    85
	 * the list.
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
    86
	 * @return true if and only if items got removed.
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
    87
	 */
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
    88
	static bool Truncate()
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
    89
	{
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
    90
		IConsoleLine *cur = IConsoleLine::front;
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
    91
		if (cur == NULL) return false;
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
    92
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
    93
		int count = 1;
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
    94
		for (IConsoleLine *item = cur->previous; item != NULL; count++, cur = item, item = item->previous) {
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
    95
			if (item->time > _settings_client.gui.console_backlog_timeout &&
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
    96
					count > _settings_client.gui.console_backlog_length) {
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
    97
				delete item;
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
    98
				cur->previous = NULL;
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
    99
				return true;
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
   100
			}
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
   101
9915
9c9960c44822 (svn r14068) -Fix (r14056): MSVC doesn't support typeof.
rubidium
parents: 9906
diff changeset
   102
			if (item->time != MAX_UVALUE(uint16)) item->time++;
9906
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
   103
		}
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
   104
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
   105
		return false;
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
   106
	}
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
   107
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
   108
	/**
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
   109
	 * Reset the complete console line backlog.
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
   110
	 */
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
   111
	static void Reset()
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
   112
	{
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
   113
		delete IConsoleLine::front;
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
   114
		IConsoleLine::front = NULL;
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
   115
		IConsoleLine::size = 0;
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
   116
	}
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
   117
};
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
   118
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
   119
/* static */ IConsoleLine *IConsoleLine::front = NULL;
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
   120
/* static */ int IConsoleLine::size  = 0;
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
   121
9339
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   122
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   123
/* ** main console cmd buffer ** */
9906
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
   124
static Textbuf _iconsole_cmdline;
9339
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   125
static char *_iconsole_history[ICON_HISTORY_SIZE];
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   126
static byte _iconsole_historypos;
9906
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
   127
IConsoleModes _iconsole_mode;
9339
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   128
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   129
/* *************** *
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   130
 *  end of header  *
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   131
 * *************** */
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   132
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   133
static void IConsoleClearCommand()
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   134
{
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   135
	memset(_iconsole_cmdline.buf, 0, ICON_CMDLN_SIZE);
10276
b60b7e17db62 (svn r14514) -Codechange: use 'size' instead of 'length' for querystring and textbuf, explicitly say it includes the terminating zero
smatz
parents: 10238
diff changeset
   136
	_iconsole_cmdline.size = 1; // only terminating zero
9339
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   137
	_iconsole_cmdline.width = 0;
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   138
	_iconsole_cmdline.caretpos = 0;
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   139
	_iconsole_cmdline.caretxoffs = 0;
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   140
	SetWindowDirty(FindWindowById(WC_CONSOLE, 0));
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   141
}
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   142
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   143
static inline void IConsoleResetHistoryPos() {_iconsole_historypos = ICON_HISTORY_SIZE - 1;}
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   144
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   145
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   146
static void IConsoleHistoryAdd(const char *cmd);
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   147
static void IConsoleHistoryNavigate(int direction);
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   148
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   149
struct IConsoleWindow : Window
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   150
{
9906
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
   151
	static int scroll;
9339
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   152
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   153
	IConsoleWindow(const WindowDesc *desc) : Window(desc)
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   154
	{
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   155
		_iconsole_mode = ICONSOLE_OPENED;
10426
4a77f7049b5e (svn r14679) -Fix [FS#2431]: opening the OSK on the chatbox did disable map scrolling (with keyboard) until another window with editbox was opened and closed. Just "refcount" the open edit boxes instead of setting/clearing a bit when opening/closing a window.
rubidium
parents: 10276
diff changeset
   156
		_no_scroll++; // override cursor arrows; the gamefield will not scroll
9339
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   157
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   158
		this->height = _screen.height / 3;
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   159
		this->width  = _screen.width;
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   160
	}
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   161
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   162
	~IConsoleWindow()
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   163
	{
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   164
		_iconsole_mode = ICONSOLE_CLOSED;
10426
4a77f7049b5e (svn r14679) -Fix [FS#2431]: opening the OSK on the chatbox did disable map scrolling (with keyboard) until another window with editbox was opened and closed. Just "refcount" the open edit boxes instead of setting/clearing a bit when opening/closing a window.
rubidium
parents: 10276
diff changeset
   165
		_no_scroll--;
9339
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   166
	}
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   167
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   168
	virtual void OnPaint()
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   169
	{
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   170
		int max = (this->height / ICON_LINE_HEIGHT) - 1;
9906
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
   171
		const IConsoleLine *print = IConsoleLine::Get(IConsoleWindow::scroll);
9339
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   172
		GfxFillRect(this->left, this->top, this->width, this->height - 1, 0);
9906
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
   173
		for (int i = 0; i < max && print != NULL; i++, print = print->previous) {
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
   174
			DoDrawString(print->buffer, 5,
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
   175
				this->height - (2 + i) * ICON_LINE_HEIGHT, print->colour);
9339
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   176
		}
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   177
		/* If the text is longer than the window, don't show the starting ']' */
9906
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
   178
		int delta = this->width - 10 - _iconsole_cmdline.width - ICON_RIGHT_BORDERWIDTH;
9339
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   179
		if (delta > 0) {
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   180
			DoDrawString("]", 5, this->height - ICON_LINE_HEIGHT, CC_COMMAND);
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   181
			delta = 0;
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   182
		}
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   183
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   184
		DoDrawString(_iconsole_cmdline.buf, 10 + delta, this->height - ICON_LINE_HEIGHT, CC_COMMAND);
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   185
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   186
		if (_iconsole_cmdline.caret) {
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   187
			DoDrawString("_", 10 + delta + _iconsole_cmdline.caretxoffs, this->height - ICON_LINE_HEIGHT, TC_WHITE);
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   188
		}
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   189
	}
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   190
9906
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
   191
	virtual void OnHundredthTick()
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
   192
	{
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
   193
		if (IConsoleLine::Truncate() &&
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
   194
				(IConsoleWindow::scroll > IConsoleLine::size)) {
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
   195
			IConsoleWindow::scroll = max(0, IConsoleLine::size - (this->height / ICON_LINE_HEIGHT) + 1);
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
   196
			this->SetDirty();
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
   197
		}
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
   198
	}
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
   199
9339
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   200
	virtual void OnMouseLoop()
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   201
	{
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   202
		if (HandleCaret(&_iconsole_cmdline)) this->SetDirty();
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   203
	}
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   204
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   205
	virtual EventState OnKeyPress(uint16 key, uint16 keycode)
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   206
	{
9906
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
   207
		const int scroll_height = (this->height / ICON_LINE_HEIGHT) - 1;
9339
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   208
		switch (keycode) {
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   209
			case WKC_UP:
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   210
				IConsoleHistoryNavigate(+1);
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   211
				this->SetDirty();
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   212
				break;
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   213
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   214
			case WKC_DOWN:
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   215
				IConsoleHistoryNavigate(-1);
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   216
				this->SetDirty();
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   217
				break;
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   218
9906
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
   219
			case WKC_SHIFT | WKC_PAGEDOWN:
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
   220
				if (IConsoleWindow::scroll - scroll_height < 0) {
9339
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   221
					IConsoleWindow::scroll = 0;
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   222
				} else {
9906
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
   223
					IConsoleWindow::scroll -= scroll_height;
9339
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   224
				}
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   225
				this->SetDirty();
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   226
				break;
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   227
9906
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
   228
			case WKC_SHIFT | WKC_PAGEUP:
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
   229
				if (IConsoleWindow::scroll + scroll_height > IConsoleLine::size - scroll_height) {
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
   230
					IConsoleWindow::scroll = IConsoleLine::size - scroll_height;
9339
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   231
				} else {
9906
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
   232
					IConsoleWindow::scroll += scroll_height;
9339
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   233
				}
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   234
				this->SetDirty();
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   235
				break;
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   236
9906
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
   237
			case WKC_SHIFT | WKC_DOWN:
9339
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   238
				if (IConsoleWindow::scroll <= 0) {
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   239
					IConsoleWindow::scroll = 0;
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   240
				} else {
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   241
					--IConsoleWindow::scroll;
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   242
				}
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   243
				this->SetDirty();
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   244
				break;
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   245
9906
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
   246
			case WKC_SHIFT | WKC_UP:
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
   247
				if (IConsoleWindow::scroll >= IConsoleLine::size) {
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
   248
					IConsoleWindow::scroll = IConsoleLine::size;
9339
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   249
				} else {
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   250
					++IConsoleWindow::scroll;
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   251
				}
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   252
				this->SetDirty();
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   253
				break;
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   254
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   255
			case WKC_BACKQUOTE:
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   256
				IConsoleSwitch();
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   257
				break;
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   258
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   259
			case WKC_RETURN: case WKC_NUM_ENTER:
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   260
				IConsolePrintF(CC_COMMAND, "] %s", _iconsole_cmdline.buf);
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   261
				IConsoleHistoryAdd(_iconsole_cmdline.buf);
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   262
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   263
				IConsoleCmdExec(_iconsole_cmdline.buf);
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   264
				IConsoleClearCommand();
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   265
				break;
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   266
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   267
			case WKC_CTRL | WKC_RETURN:
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   268
				_iconsole_mode = (_iconsole_mode == ICONSOLE_FULL) ? ICONSOLE_OPENED : ICONSOLE_FULL;
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   269
				IConsoleResize(this);
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   270
				MarkWholeScreenDirty();
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   271
				break;
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   272
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   273
			case (WKC_CTRL | 'V'):
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   274
				if (InsertTextBufferClipboard(&_iconsole_cmdline)) {
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   275
					IConsoleResetHistoryPos();
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   276
					this->SetDirty();
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   277
				}
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   278
				break;
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   279
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   280
			case (WKC_CTRL | 'L'):
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   281
				IConsoleCmdExec("clear");
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   282
				break;
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   283
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   284
			case (WKC_CTRL | 'U'):
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   285
				DeleteTextBufferAll(&_iconsole_cmdline);
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   286
				this->SetDirty();
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   287
				break;
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   288
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   289
			case WKC_BACKSPACE: case WKC_DELETE:
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   290
				if (DeleteTextBufferChar(&_iconsole_cmdline, keycode)) {
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   291
					IConsoleResetHistoryPos();
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   292
					this->SetDirty();
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   293
				}
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   294
				break;
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   295
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   296
			case WKC_LEFT: case WKC_RIGHT: case WKC_END: case WKC_HOME:
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   297
				if (MoveTextBufferPos(&_iconsole_cmdline, keycode)) {
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   298
					IConsoleResetHistoryPos();
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   299
					this->SetDirty();
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   300
				}
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   301
				break;
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   302
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   303
			default:
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   304
				if (IsValidChar(key, CS_ALPHANUMERAL)) {
9906
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
   305
					IConsoleWindow::scroll = 0;
9339
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   306
					InsertTextBufferChar(&_iconsole_cmdline, key);
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   307
					IConsoleResetHistoryPos();
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   308
					this->SetDirty();
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   309
				} else {
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   310
					return ES_NOT_HANDLED;
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   311
				}
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   312
		}
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   313
		return ES_HANDLED;
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   314
	}
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   315
};
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   316
9906
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
   317
int IConsoleWindow::scroll = 0;
9339
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   318
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   319
static const Widget _iconsole_window_widgets[] = {
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   320
	{WIDGETS_END}
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   321
};
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   322
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   323
static const WindowDesc _iconsole_window_desc = {
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   324
	0, 0, 2, 2, 2, 2,
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   325
	WC_CONSOLE, WC_NONE,
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   326
	WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   327
	_iconsole_window_widgets,
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   328
};
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   329
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   330
void IConsoleGUIInit()
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   331
{
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   332
	_iconsole_historypos = ICON_HISTORY_SIZE - 1;
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   333
	_iconsole_mode = ICONSOLE_CLOSED;
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   334
9906
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
   335
	IConsoleLine::Reset();
9339
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   336
	memset(_iconsole_history, 0, sizeof(_iconsole_history));
9906
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
   337
9339
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   338
	_iconsole_cmdline.buf = CallocT<char>(ICON_CMDLN_SIZE); // create buffer and zero it
10276
b60b7e17db62 (svn r14514) -Codechange: use 'size' instead of 'length' for querystring and textbuf, explicitly say it includes the terminating zero
smatz
parents: 10238
diff changeset
   339
	_iconsole_cmdline.maxsize = ICON_CMDLN_SIZE;
9339
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   340
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   341
	IConsolePrintF(CC_WARNING, "OpenTTD Game Console Revision 7 - %s", _openttd_revision);
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   342
	IConsolePrint(CC_WHITE,  "------------------------------------");
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   343
	IConsolePrint(CC_WHITE,  "use \"help\" for more information");
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   344
	IConsolePrint(CC_WHITE,  "");
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   345
	IConsoleClearCommand();
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   346
	IConsoleHistoryAdd("");
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   347
}
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   348
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   349
void IConsoleClearBuffer()
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   350
{
9906
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
   351
	IConsoleLine::Reset();
9339
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   352
}
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   353
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   354
void IConsoleGUIFree()
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   355
{
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   356
	free(_iconsole_cmdline.buf);
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   357
	IConsoleClearBuffer();
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   358
}
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   359
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   360
void IConsoleResize(Window *w)
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   361
{
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   362
	switch (_iconsole_mode) {
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   363
		case ICONSOLE_OPENED:
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   364
			w->height = _screen.height / 3;
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   365
			w->width = _screen.width;
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   366
			break;
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   367
		case ICONSOLE_FULL:
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   368
			w->height = _screen.height - ICON_BOTTOM_BORDERWIDTH;
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   369
			w->width = _screen.width;
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   370
			break;
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   371
		default: return;
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   372
	}
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   373
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   374
	MarkWholeScreenDirty();
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   375
}
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   376
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   377
void IConsoleSwitch()
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   378
{
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   379
	switch (_iconsole_mode) {
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   380
		case ICONSOLE_CLOSED:
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   381
			new IConsoleWindow(&_iconsole_window_desc);
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   382
			break;
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   383
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   384
		case ICONSOLE_OPENED: case ICONSOLE_FULL:
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   385
			DeleteWindowById(WC_CONSOLE, 0);
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   386
			break;
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   387
	}
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   388
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   389
	MarkWholeScreenDirty();
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   390
}
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   391
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   392
void IConsoleClose() {if (_iconsole_mode == ICONSOLE_OPENED) IConsoleSwitch();}
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   393
void IConsoleOpen()  {if (_iconsole_mode == ICONSOLE_CLOSED) IConsoleSwitch();}
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   394
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   395
/**
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   396
 * Add the entered line into the history so you can look it back
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   397
 * scroll, etc. Put it to the beginning as it is the latest text
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   398
 * @param cmd Text to be entered into the 'history'
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   399
 */
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   400
static void IConsoleHistoryAdd(const char *cmd)
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   401
{
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   402
	free(_iconsole_history[ICON_HISTORY_SIZE - 1]);
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   403
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   404
	memmove(&_iconsole_history[1], &_iconsole_history[0], sizeof(_iconsole_history[0]) * (ICON_HISTORY_SIZE - 1));
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   405
	_iconsole_history[0] = strdup(cmd);
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   406
	IConsoleResetHistoryPos();
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   407
}
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   408
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   409
/**
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   410
 * Navigate Up/Down in the history of typed commands
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   411
 * @param direction Go further back in history (+1), go to recently typed commands (-1)
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   412
 */
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   413
static void IConsoleHistoryNavigate(int direction)
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   414
{
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   415
	int i = _iconsole_historypos + direction;
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   416
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   417
	/* watch out for overflows, just wrap around */
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   418
	if (i < 0) i = ICON_HISTORY_SIZE - 1;
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   419
	if (i >= ICON_HISTORY_SIZE) i = 0;
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   420
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   421
	if (direction > 0) {
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   422
		if (_iconsole_history[i] == NULL) i = 0;
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   423
	}
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   424
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   425
	if (direction < 0) {
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   426
		while (i > 0 && _iconsole_history[i] == NULL) i--;
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   427
	}
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   428
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   429
	_iconsole_historypos = i;
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   430
	IConsoleClearCommand();
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   431
	/* copy history to 'command prompt / bash' */
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   432
	assert(_iconsole_history[i] != NULL && IsInsideMM(i, 0, ICON_HISTORY_SIZE));
10276
b60b7e17db62 (svn r14514) -Codechange: use 'size' instead of 'length' for querystring and textbuf, explicitly say it includes the terminating zero
smatz
parents: 10238
diff changeset
   433
	ttd_strlcpy(_iconsole_cmdline.buf, _iconsole_history[i], _iconsole_cmdline.maxsize);
9339
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   434
	UpdateTextBufferSize(&_iconsole_cmdline);
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   435
}
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   436
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   437
/**
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   438
 * Handle the printing of text entered into the console or redirected there
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 9915
diff changeset
   439
 * by any other means. Text can be redirected to other clients in a network game
9339
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   440
 * as well as to a logfile. If the network server is a dedicated server, all activities
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   441
 * are also logged. All lines to print are added to a temporary buffer which can be
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   442
 * used as a history to print them onscreen
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   443
 * @param color_code the colour of the command. Red in case of errors, etc.
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   444
 * @param string the message entered or output on the console (notice, error, etc.)
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   445
 */
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   446
void IConsoleGUIPrint(ConsoleColour color_code, char *str)
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   447
{
9906
9c0a829bf58e (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium
parents: 9339
diff changeset
   448
	new IConsoleLine(str, color_code);
9339
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   449
	SetWindowDirty(FindWindowById(WC_CONSOLE, 0));
189117c9c937 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium
parents:
diff changeset
   450
}