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 * aint32 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 * Based on the original sources
23 * Faery Tale II -- The Halls of the Dead
24 * (c) 1993-1996 The Wyrmkeep Entertainment Co.
25 */
26
27 #include "saga2/saga2.h"
28 #include "saga2/messager.h"
29 #include "saga2/vdraw.h"
30
31 namespace Saga2 {
32
va(const char * format,va_list argptr)33 size_t Messager::va(const char *format, va_list argptr) {
34 if (enabled) {
35 char tempBuf[256];
36 size_t size;
37
38 size = vsprintf((char *) tempBuf, format, argptr);
39
40 if (size) {
41 if (tempBuf[size - 1] != '\n') {
42 tempBuf[size++] = '\n';
43 tempBuf[size] = '\0';
44 }
45 return dumpit(tempBuf, size);
46 }
47 }
48 return 0;
49 }
50
operator ()(const char * format,...)51 size_t Messager::operator()(const char *format, ...) {
52 if (enabled) {
53 size_t size;
54 va_list argptr;
55
56 va_start(argptr, format);
57 size = va(format, argptr);
58 va_end(argptr);
59 return size;
60 }
61 return 0;
62 }
63
64
65 uint16 defaultStatusFX = 468;
66 uint16 defaultStatusFY = 354;
67 uint16 blackStatusF = 24;
68 uint16 heightStatusF = 11;
69
dumpit(char * s,size_t size)70 int StatusLineMessager::dumpit(char *s, size_t size) {
71 Rect16 r;
72
73 r.x = atX;
74 r.y = atY;
75 r.width = atW;
76 r.height = heightStatusF;
77
78 textPort->setColor(blackStatusF);
79 textPort->fillRect(r);
80 textPort->setColor(atColor);
81 textPort->setStyle(0);
82 textPort->drawTextInBox(s, size, r, textPosLeft, Point16(2, 1));
83
84 return 0;
85 }
86
StatusLineMessager(const char * entry,int lineno,gDisplayPort * mp,int32 x,int32 y,int32 w,int16 color)87 StatusLineMessager::StatusLineMessager(const char *entry, int lineno, gDisplayPort *mp, int32 x, int32 y, int32 w, int16 color)
88 : Messager(entry) {
89 line = lineno;
90 textPort = mp;
91 atX = (x >= 0 ? x : defaultStatusFX);
92 atY = (y >= 0 ? y : defaultStatusFY + line * heightStatusF);
93 atW = (w >= 0 ? w : 640 - (defaultStatusFX - 16) - 20);
94 atColor = (color >= 0 ? color : line * 16 + 12);
95 operator()("Status Line %d", line);
96 }
97
StatusLineMessager(int lineno,gDisplayPort * mp,int32 x,int32 y,int32 w,int16 color)98 StatusLineMessager::StatusLineMessager(int lineno, gDisplayPort *mp, int32 x, int32 y, int32 w, int16 color) {
99 line = lineno;
100 textPort = mp;
101 atX = (x >= 0 ? x : defaultStatusFX);
102 atY = (y >= 0 ? y : defaultStatusFY + line * heightStatusF);
103 atW = (w >= 0 ? w : 640 - (defaultStatusFX - 16) - 20);
104 atColor = (color >= 0 ? color : line * 16 + 12);
105 operator()("Status Line %d", line);
106 }
107
~StatusLineMessager()108 StatusLineMessager::~StatusLineMessager() {
109 operator()("");
110 }
111
112 } // end of namespace Saga2
113