forked from aburch/simutrans
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmessage_stats_t.cc
91 lines (78 loc) · 1.96 KB
/
message_stats_t.cc
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
/*
* Copyright (c) 1997 - 2003 Hansjörg Malthaner
*
* This file is part of the Simutrans project and may not be used
* in other projects without written permission of the author.
*/
#include "message_stats_t.h"
#include "../simgraph.h"
#include "../simcolor.h"
#include "../simcity.h"
#include "../simwin.h"
#include "../simworld.h"
#include "../simmesg.h"
#include "../gui/stadt_info.h"
message_stats_t::message_stats_t(karte_t *w)
{
welt = w;
msg = message_t::get_instance();
last_count = 0;
setze_groesse(koord(600,msg->gib_count()*14 + 30));
}
/**
* Click on message => go to position
* @author Hj. Malthaner
*/
void message_stats_t::infowin_event(const event_t * ev)
{
if(IS_LEFTRELEASE(ev)) {
const unsigned int line = (ev->cy - 15) / 14;
message_t::node *n=msg->get_node(line);
if(ev->cy>14 && n!=NULL && welt->ist_in_kartengrenzen(n->pos)) {
welt->setze_ij_off(koord3d(n->pos,welt->min_hgt(n->pos)));
}
}
unsigned count = msg->gib_count();
if(last_count!=count) {
last_count = count;
setze_groesse(koord(600,last_count*14 + 30));
}
}
/**
* Now draw the list
* @author prissi
*/
void message_stats_t::zeichnen(koord offset)
{
struct clip_dimension cd = display_gib_clip_wh();
const int offsets = (cd.y-offset.y+13)/14;
int max_message = (cd.yy-offset.y-13)/14;
if(max_message>msg->gib_count()) {
max_message = msg->gib_count();
}
for( int i=offsets; i<max_message; i++ ) {
if(offset.y+i*14<cd.y) {
// reached the top
continue;
}
if(offset.y+i*14+15>cd.yy) {
// reached the bottom
break;
}
message_t::node *n=msg->get_node(i);
if(n==NULL || n->msg==NULL) {
DBG_MESSAGE("message_stats_t::zeichnen()","invalid message %i",i);
// paranoia
break;
}
char buf[256];
for( int j=0; j<256; j++ ) {
buf[j] = (n->msg[j]=='\n')?' ':n->msg[j];
if(buf[j]==0) {
break;
}
}
// display text with clipping
display_proportional_clip(offset.x+10, 15+offset.y+i*14, buf, ALIGN_LEFT, n->color,true);
}
}