1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 #include "ultima/shared/std/string.h"
24 #include "ultima/nuvie/core/nuvie_defs.h"
25 #include "ultima/nuvie/misc/u6_misc.h"
26 #include "ultima/nuvie/gui/gui.h"
27 #include "ultima/nuvie/gui/widgets/gui_widget.h"
28 #include "ultima/nuvie/gui/gui_console.h"
29 
30 namespace Ultima {
31 namespace Nuvie {
32 
GUI_Console(uint16 x,uint16 y,uint16 w,uint16 h)33 GUI_Console::GUI_Console(uint16 x, uint16 y, uint16 w, uint16 h)
34 	: GUI_Widget(NULL, x, y, w, h) {
35 	bg_color = new GUI_Color(0, 0, 0);
36 	font = new GUI_Font(1);
37 	font->setColoring(0xff, 0xff, 0xff, 0, 0, 0);
38 	num_rows = (uint16)(h / font->charHeight());
39 	num_cols = (uint16)(w / font->charWidth());
40 }
41 
~GUI_Console()42 GUI_Console::~GUI_Console() {
43 	delete bg_color;
44 	delete font;
45 }
46 
47 /* Map the color to the display */
SetDisplay(Screen * s)48 void GUI_Console::SetDisplay(Screen *s) {
49 	GUI_Widget::SetDisplay(s);
50 	bg_color->map_color(surface);
51 }
52 
53 /* Show the widget  */
Display(bool full_redraw)54 void GUI_Console:: Display(bool full_redraw) {
55 	Common::Rect framerect;
56 
57 	framerect = area;
58 
59 	SDL_FillRect(surface, &framerect, bg_color->sdl_color);
60 
61 	uint16 i = 0;
62 	for (Std::list<Std::string>::iterator it = data.begin(); it != data.end(); it++) {
63 		font->textOut(surface, area.left, area.top + i * font->charHeight(), (*it).c_str(), false);
64 		i++;
65 	}
66 	screen->update(area.left, area.top, area.width(), area.height());
67 
68 	return;
69 }
70 
AddLine(Std::string line)71 void GUI_Console::AddLine(Std::string line) {
72 	uint16 len = line.length();
73 	uint16 i;
74 
75 	if (len > num_cols) {
76 		for (i = 0; i + num_cols < len; i += num_cols)
77 			data.push_back(Std::string(line.substr(i, num_cols)));
78 
79 		if (i < len)
80 			data.push_back(Std::string(line.substr(i, len - i)));
81 	} else
82 		data.push_back(line);
83 
84 
85 	for (i = data.size(); i > num_rows; i--)
86 		data.pop_front();
87 }
88 
MouseDown(int x,int y,Shared::MouseButton button)89 GUI_status GUI_Console::MouseDown(int x, int y, Shared::MouseButton button) {
90 
91 
92 //grab_focus();
93 
94 	return GUI_YUM;
95 }
96 
MouseUp(int x,int y,Shared::MouseButton button)97 GUI_status GUI_Console::MouseUp(int x, int y, Shared::MouseButton button) {
98 
99 // release_focus();
100 
101 	return GUI_YUM;
102 }
103 
MouseMotion(int x,int y,uint8 state)104 GUI_status GUI_Console::MouseMotion(int x, int y, uint8 state) {
105 
106 
107 //GUI::get_gui()->moveWidget(this,dx,dy);
108 // Redraw();
109 
110 	return (GUI_YUM);
111 }
112 
113 } // End of namespace Nuvie
114 } // End of namespace Ultima
115