Move CUITimer and CStatusLine in there own files.
This commit is contained in:
parent
c01bef9426
commit
c0f82a019a
7 changed files with 255 additions and 82 deletions
|
@ -284,7 +284,9 @@ set(ui_SRCS
|
|||
src/ui/menu_proc.cpp
|
||||
src/ui/mouse.cpp
|
||||
src/ui/script_ui.cpp
|
||||
src/ui/statusline.cpp
|
||||
src/ui/ui.cpp
|
||||
src/ui/uitimer.cpp
|
||||
src/ui/widgets.cpp
|
||||
)
|
||||
source_group(ui FILES ${ui_SRCS})
|
||||
|
@ -525,6 +527,8 @@ set(stratagus_generic_HDRS
|
|||
src/include/translate.h
|
||||
src/include/trigger.h
|
||||
src/include/ui/contenttype.h
|
||||
src/include/ui/statusline.h
|
||||
src/include/ui/uitimer.h
|
||||
src/include/ui.h
|
||||
src/include/unit.h
|
||||
src/include/unit_cache.h
|
||||
|
|
|
@ -54,7 +54,8 @@
|
|||
|
||||
#include "color.h"
|
||||
#include "viewport.h"
|
||||
|
||||
#include "ui/statusline.h"
|
||||
#include "ui/uitimer.h"
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
@ -530,36 +531,6 @@ public:
|
|||
int Y;
|
||||
};
|
||||
|
||||
class CStatusLine
|
||||
{
|
||||
public:
|
||||
CStatusLine() : Width(0), TextX(0), TextY(0), Font(0) {}
|
||||
|
||||
void Draw();
|
||||
void Set(const std::string &status);
|
||||
inline const std::string &Get() { return this->StatusLine; }
|
||||
void Clear();
|
||||
|
||||
int Width;
|
||||
int TextX;
|
||||
int TextY;
|
||||
CFont *Font;
|
||||
|
||||
private:
|
||||
std::string StatusLine;
|
||||
};
|
||||
|
||||
class CUITimer
|
||||
{
|
||||
public:
|
||||
CUITimer() : X(0), Y(0), Font(NULL) {}
|
||||
|
||||
int X;
|
||||
int Y;
|
||||
CFont *Font;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
** Defines the user interface.
|
||||
*/
|
||||
|
|
61
src/include/ui/statusline.h
Normal file
61
src/include/ui/statusline.h
Normal file
|
@ -0,0 +1,61 @@
|
|||
// _________ __ __
|
||||
// / _____// |_____________ _/ |______ ____ __ __ ______
|
||||
// \_____ \\ __\_ __ \__ \\ __\__ \ / ___\| | \/ ___/
|
||||
// / \| | | | \// __ \| | / __ \_/ /_/ > | /\___ |
|
||||
// /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ >
|
||||
// \/ \/ \//_____/ \/
|
||||
// ______________________ ______________________
|
||||
// T H E W A R B E G I N S
|
||||
// Stratagus - A free fantasy real time strategy game engine
|
||||
//
|
||||
/**@name statusline.h - The status line header file. */
|
||||
//
|
||||
// (c) Copyright 2012 by Joris Dauphin
|
||||
//
|
||||
// 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; only version 2 of the License.
|
||||
//
|
||||
// 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., 59 Temple Place - Suite 330, Boston, MA
|
||||
// 02111-1307, USA.
|
||||
//
|
||||
|
||||
#ifndef __STATUS_LINE_H__
|
||||
#define __STATUS_LINE_H__
|
||||
|
||||
//@{
|
||||
|
||||
#include <string>
|
||||
|
||||
class CFont;
|
||||
|
||||
class CStatusLine
|
||||
{
|
||||
public:
|
||||
CStatusLine() : Width(0), TextX(0), TextY(0), Font(0) {}
|
||||
|
||||
void Draw();
|
||||
void Set(const std::string &status);
|
||||
const std::string &Get() const { return this->StatusLine; }
|
||||
void Clear();
|
||||
|
||||
public:
|
||||
int Width;
|
||||
int TextX;
|
||||
int TextY;
|
||||
CFont *Font;
|
||||
|
||||
private:
|
||||
std::string StatusLine;
|
||||
};
|
||||
|
||||
//@}
|
||||
|
||||
#endif // __STATUS_LINE_H__
|
52
src/include/ui/uitimer.h
Normal file
52
src/include/ui/uitimer.h
Normal file
|
@ -0,0 +1,52 @@
|
|||
// _________ __ __
|
||||
// / _____// |_____________ _/ |______ ____ __ __ ______
|
||||
// \_____ \\ __\_ __ \__ \\ __\__ \ / ___\| | \/ ___/
|
||||
// / \| | | | \// __ \| | / __ \_/ /_/ > | /\___ |
|
||||
// /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ >
|
||||
// \/ \/ \//_____/ \/
|
||||
// ______________________ ______________________
|
||||
// T H E W A R B E G I N S
|
||||
// Stratagus - A free fantasy real time strategy game engine
|
||||
//
|
||||
/**@name uitimer.h - The ui timer header file. */
|
||||
//
|
||||
// (c) Copyright 2012 by Joris Dauphin
|
||||
//
|
||||
// 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; only version 2 of the License.
|
||||
//
|
||||
// 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., 59 Temple Place - Suite 330, Boston, MA
|
||||
// 02111-1307, USA.
|
||||
//
|
||||
|
||||
#ifndef __UITIMER_H__
|
||||
#define __UITIMER_H__
|
||||
|
||||
//@{
|
||||
|
||||
class CFont;
|
||||
|
||||
class CUITimer
|
||||
{
|
||||
public:
|
||||
CUITimer() : X(0), Y(0), Font(NULL) {}
|
||||
|
||||
void Draw(int second) const;
|
||||
|
||||
public:
|
||||
int X;
|
||||
int Y;
|
||||
CFont *Font;
|
||||
};
|
||||
|
||||
//@}
|
||||
|
||||
#endif // __UITIMER_H__
|
|
@ -960,46 +960,6 @@ void ToggleShowBuilListMessages()
|
|||
}
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
-- STATUS LINE
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
** Draw status line.
|
||||
*/
|
||||
void CStatusLine::Draw()
|
||||
{
|
||||
if (!this->StatusLine.empty()) {
|
||||
PushClipping();
|
||||
SetClipping(this->TextX, this->TextY,
|
||||
this->TextX + this->Width - 1, Video.Height - 1);
|
||||
CLabel(*this->Font).DrawClip(this->TextX, this->TextY, this->StatusLine);
|
||||
PopClipping();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
** Change status line to new text.
|
||||
**
|
||||
** @param status New status line information.
|
||||
*/
|
||||
void CStatusLine::Set(const std::string &status)
|
||||
{
|
||||
if (KeyState != KeyStateInput) {
|
||||
this->StatusLine = status;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
** Clear status line.
|
||||
*/
|
||||
void CStatusLine::Clear()
|
||||
{
|
||||
if (KeyState != KeyStateInput) {
|
||||
this->StatusLine.clear();
|
||||
}
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
-- COSTS
|
||||
----------------------------------------------------------------------------*/
|
||||
|
@ -1319,17 +1279,8 @@ void DrawTimer()
|
|||
return;
|
||||
}
|
||||
|
||||
int sec = GameTimer.Cycles / CYCLES_PER_SECOND % 60;
|
||||
int min = (GameTimer.Cycles / CYCLES_PER_SECOND / 60) % 60;
|
||||
int hour = (GameTimer.Cycles / CYCLES_PER_SECOND / 3600);
|
||||
char buf[30];
|
||||
|
||||
if (hour) {
|
||||
snprintf(buf, sizeof(buf), "%d:%02d:%02d", hour, min, sec);
|
||||
} else {
|
||||
snprintf(buf, sizeof(buf), "%d:%02d", min, sec);
|
||||
}
|
||||
CLabel(*UI.Timer.Font).Draw(UI.Timer.X, UI.Timer.Y, buf);
|
||||
int sec = GameTimer.Cycles / CYCLES_PER_SECOND;
|
||||
UI.Timer.Draw(sec);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
80
src/ui/statusline.cpp
Normal file
80
src/ui/statusline.cpp
Normal file
|
@ -0,0 +1,80 @@
|
|||
// _________ __ __
|
||||
// / _____// |_____________ _/ |______ ____ __ __ ______
|
||||
// \_____ \\ __\_ __ \__ \\ __\__ \ / ___\| | \/ ___/
|
||||
// / \| | | | \// __ \| | / __ \_/ /_/ > | /\___ |
|
||||
// /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ >
|
||||
// \/ \/ \//_____/ \/
|
||||
// ______________________ ______________________
|
||||
// T H E W A R B E G I N S
|
||||
// Stratagus - A free fantasy real time strategy game engine
|
||||
//
|
||||
/**@name statusline.cpp - The statusline. */
|
||||
//
|
||||
// (c) Copyright 2012 by Joris Dauphin
|
||||
//
|
||||
// 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; only version 2 of the License.
|
||||
//
|
||||
// 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., 59 Temple Place - Suite 330, Boston, MA
|
||||
// 02111-1307, USA.
|
||||
//
|
||||
|
||||
//@{
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
-- Includes
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#include "stratagus.h"
|
||||
|
||||
#include "ui/statusline.h"
|
||||
|
||||
#include "font.h"
|
||||
#include "interface.h"
|
||||
#include "video.h"
|
||||
|
||||
/**
|
||||
** Draw status line.
|
||||
*/
|
||||
void CStatusLine::Draw()
|
||||
{
|
||||
if (!this->StatusLine.empty()) {
|
||||
PushClipping();
|
||||
SetClipping(this->TextX, this->TextY,
|
||||
this->TextX + this->Width - 1, Video.Height - 1);
|
||||
CLabel(*this->Font).DrawClip(this->TextX, this->TextY, this->StatusLine);
|
||||
PopClipping();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
** Change status line to new text.
|
||||
**
|
||||
** @param status New status line information.
|
||||
*/
|
||||
void CStatusLine::Set(const std::string &status)
|
||||
{
|
||||
if (KeyState != KeyStateInput) {
|
||||
this->StatusLine = status;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
** Clear status line.
|
||||
*/
|
||||
void CStatusLine::Clear()
|
||||
{
|
||||
if (KeyState != KeyStateInput) {
|
||||
this->StatusLine.clear();
|
||||
}
|
||||
}
|
||||
|
||||
//@}
|
54
src/ui/uitimer.cpp
Normal file
54
src/ui/uitimer.cpp
Normal file
|
@ -0,0 +1,54 @@
|
|||
// _________ __ __
|
||||
// / _____// |_____________ _/ |______ ____ __ __ ______
|
||||
// \_____ \\ __\_ __ \__ \\ __\__ \ / ___\| | \/ ___/
|
||||
// / \| | | | \// __ \| | / __ \_/ /_/ > | /\___ |
|
||||
// /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ >
|
||||
// \/ \/ \//_____/ \/
|
||||
// ______________________ ______________________
|
||||
// T H E W A R B E G I N S
|
||||
// Stratagus - A free fantasy real time strategy game engine
|
||||
//
|
||||
/**@name uitimer.cpp - The ui timer. */
|
||||
//
|
||||
// (c) Copyright 2012 by Joris Dauphin
|
||||
//
|
||||
// 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; only version 2 of the License.
|
||||
//
|
||||
// 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., 59 Temple Place - Suite 330, Boston, MA
|
||||
// 02111-1307, USA.
|
||||
//
|
||||
|
||||
//@{
|
||||
|
||||
#include "stratagus.h"
|
||||
|
||||
#include "ui/uitimer.h"
|
||||
#include "font.h"
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
void CUITimer::Draw(int second) const
|
||||
{
|
||||
const int sec = second % 60;
|
||||
const int min = (second / 60) % 60;
|
||||
const int hour = second / 3600;
|
||||
char buf[30];
|
||||
|
||||
if (hour) {
|
||||
snprintf(buf, sizeof(buf), "%d:%02d:%02d", hour, min, sec);
|
||||
} else {
|
||||
snprintf(buf, sizeof(buf), "%d:%02d", min, sec);
|
||||
}
|
||||
CLabel(*this->Font).Draw(this->X, this->Y, buf);
|
||||
}
|
||||
|
||||
//@}
|
Loading…
Add table
Reference in a new issue