aboutsummaryrefslogtreecommitdiff
path: root/engines/cge/gettext.cpp
blob: e3c60b6e217d0f565786881c81f3a0a41ed6bf5e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/* ScummVM - Graphic Adventure Engine
 *
 * ScummVM is the legal property of its developers, whose names
 * are too numerous to list here. Please refer to the COPYRIGHT
 * file distributed with this source distribution.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.

 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 */

/*
 * This code is based on original Soltys source code
 * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon
 */

#include "cge/gettext.h"
#include "cge/keybd.h"
#include "cge/mouse.h"
#include "cge/cge_main.h"
#include <string.h>

namespace CGE {

GET_TEXT *GET_TEXT::Ptr = NULL;


GET_TEXT::GET_TEXT(CGEEngine *vm, const char *info, char *text, int size, void (*click)(void))
	: TALK(vm), Text(text), Size(min<int>(size, GTMAX)), Len(min<int>(Size, strlen(text))),
	  Cntr(GTBLINK), Click(click), OldKeybClient(KEYBOARD::SetClient(this)), _vm(vm) {
	int i = 2 * TEXT_HM + _Font->Width(info);
	Ptr = this;
	Mode = RECT;
	TS[0] = Box((i + 3) & ~3, 2 * TEXT_VM + 2 * FONT_HIG + TEXT_LS);
	SetShapeList(TS);
	_flags._bDel = true;
	_flags._kill = true;
	memcpy(Buff, text, Len);
	Buff[Len] = ' ';
	Buff[Len + 1] = '\0';
	PutLine(0, info);
	Tick();
}


GET_TEXT::~GET_TEXT(void) {
	KEYBOARD::SetClient(OldKeybClient);
	Ptr = NULL;
}


void GET_TEXT::Tick(void) {
	if (++ Cntr >= GTBLINK) {
		Buff[Len] ^= (' ' ^ '_');
		Cntr = 0;
	}
	PutLine(1, Buff);
	_time = GTTIME;
}


void GET_TEXT::Touch(uint16 mask, int x, int y) {
	static char ogon[] = "���������";
	static char bezo[] = "ACELNOSXZ";
	char *p;

	if (mask & KEYB) {
		if (Click)
			Click();
		switch (x) {
		case Enter :
			Buff[Len] = '\0';
			strcpy(Text, Buff);
			for (p = Text; *p; p++) {
				char *q = strchr(ogon, *p);
				if (q)
					*p = bezo[q - ogon];
			}
		case Esc   :
			SNPOST_(SNKILL, -1, 0, this);
			break;
		case BSp   :
			if (Len) {
				--Len;
				Buff[Len] = Buff[Len + 1];
				Buff[Len + 1] = Buff[Len + 2];
			}
			break;
		default    :
			if (x < 'A' || x > 'Z') {
				if (OldKeybClient)
					OldKeybClient->Touch(mask, x, y);
			} else {
				if (KEYBOARD::Key[ALT]) {
					p = strchr(bezo, x);
					if (p)
						x = ogon[p - bezo];
				}
				if (Len < Size && 2 * TEXT_HM + _Font->Width(Buff) + _Font->Wid[x] <= _w) {
					Buff[Len + 2] = Buff[Len + 1];
					Buff[Len + 1] = Buff[Len];
					Buff[Len++] = x;
				}
			}
			break;
		}
	} else
		Sprite::Touch(mask, x, y);
}

} // End of namespace CGE