|
From: <ufo...@li...> - 2011-12-15 21:14:56
|
Revision: 1169
http://ufo2000.svn.sourceforge.net/ufo2000/?rev=1169&view=rev
Author: ssvb
Date: 2011-12-15 21:14:50 +0000 (Thu, 15 Dec 2011)
Log Message:
-----------
Added "set_status_message" helper function
It can be used to set status message text which is shown
at the top part of the screen and disappears automatically
after the specified timeout elapses.
From: Siarhei Siamashka <sia...@gm...>
Modified Paths:
--------------
trunk/src/global.h
trunk/src/main.cpp
Modified: trunk/src/global.h
===================================================================
--- trunk/src/global.h 2011-12-15 21:09:10 UTC (rev 1168)
+++ trunk/src/global.h 2011-12-15 21:14:50 UTC (rev 1169)
@@ -400,6 +400,9 @@
std::string indent(const std::string &);
bool check_filename_case_consistency(const char *filename);
+void set_status_message(
+ int color, const std::string &msg, unsigned int timeout_sec = 2);
+
/**
* @defgroup battlescape Battlescape Map
* Tile dimensions
Modified: trunk/src/main.cpp
===================================================================
--- trunk/src/main.cpp 2011-12-15 21:09:10 UTC (rev 1168)
+++ trunk/src/main.cpp 2011-12-15 21:14:50 UTC (rev 1169)
@@ -137,6 +137,7 @@
Explosive *elist;
Random *cur_random;
+volatile unsigned int g_1s_timer_ticks = 0;
volatile unsigned int ANIMATION = 0;
volatile int CHANGE = 1;
volatile int MOVEIT = 0;
@@ -174,6 +175,7 @@
g_fps = g_fps_counter;
g_fps_counter = 0;
NOTICE++;
+ g_1s_timer_ticks++;
}
END_OF_FUNCTION(timer_1s);
@@ -1444,11 +1446,39 @@
#endif
}
+static std::string status_message_text;
+static unsigned int status_message_timestamp = 0;
+static unsigned int status_message_timeout = 0;
+static int status_message_color;
+
/**
+ * Set status message text, which will automatically disappear
+ * approximately after 'timeout_sec' seconds (precision is very rough).
+ *
+ * @param color message color
+ * @param msg message text
+ * @param timeout_sec timeout before the message disappears (in seconds)
+ */
+void set_status_message(int color, const std::string &msg, unsigned int timeout_sec)
+{
+ status_message_text = msg;
+ status_message_timestamp = g_1s_timer_ticks;
+ status_message_timeout = timeout_sec;
+ status_message_color = color;
+}
+
+/**
* Show a line informational text at the top of screen.
*/
static void show_status_message_text()
{
+ if (g_1s_timer_ticks - status_message_timestamp < status_message_timeout)
+ {
+ textprintf(screen2, font, 0, 0,
+ status_message_color, "%s", status_message_text.c_str());
+ return;
+ }
+
if (MODE == WATCH)
textprintf(screen2, font, 0, 0, COLOR_WHITE, _("WATCH"));
else
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|