1 //       _________ __                 __
2 //      /   _____//  |_____________ _/  |______     ____  __ __  ______
3 //      \_____  \\   __\_  __ \__  \\   __\__  \   / ___\|  |  \/  ___/
4 //      /        \|  |  |  | \// __ \|  |  / __ \_/ /_/  >  |  /\___ |
5 //     /_______  /|__|  |__|  (____  /__| (____  /\___  /|____//____  >
6 //             \/                  \/          \//_____/            \/
7 //  ______________________                           ______________________
8 //                        T H E   W A R   B E G I N S
9 //         Stratagus - A free fantasy real time strategy game engine
10 //
11 /**@name uitimer.cpp - The ui timer. */
12 //
13 //      (c) Copyright 2012 by Joris Dauphin
14 //
15 //      This program is free software; you can redistribute it and/or modify
16 //      it under the terms of the GNU General Public License as published by
17 //      the Free Software Foundation; only version 2 of the License.
18 //
19 //      This program is distributed in the hope that it will be useful,
20 //      but WITHOUT ANY WARRANTY; without even the implied warranty of
21 //      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22 //      GNU General Public License for more details.
23 //
24 //      You should have received a copy of the GNU General Public License
25 //      along with this program; if not, write to the Free Software
26 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
27 //      02111-1307, USA.
28 //
29 
30 //@{
31 
32 #include "stratagus.h"
33 
34 #include "ui/uitimer.h"
35 #include "font.h"
36 
37 #include <cstdio>
38 
Draw(int second) const39 void CUITimer::Draw(int second) const
40 {
41 	const int sec = second % 60;
42 	const int min = (second / 60) % 60;
43 	const int hour = second / 3600;
44 	char buf[30];
45 
46 	if (hour) {
47 		snprintf(buf, sizeof(buf), "%d:%02d:%02d", hour, min, sec);
48 	} else {
49 		snprintf(buf, sizeof(buf), "%d:%02d", min, sec);
50 	}
51 	CLabel(*this->Font).Draw(this->X, this->Y, buf);
52 }
53 
54 //@}
55