[Add] Pimped out Event History box to Sara's request.

This commit is contained in:
Tamir Atias 2012-02-02 01:12:13 +02:00
parent 444abf9f59
commit 9c06cdaa34
4 changed files with 59 additions and 32 deletions

View File

@ -1,10 +1,6 @@
############################################################################# #############################################################################
# Makefile for building: Unuk-QT # Makefile for building: Unuk-QT
<<<<<<< HEAD # Generated by qmake (2.01a) (Qt 4.7.4) on: Wed Feb 1 22:50:50 2012
# Generated by qmake (2.01a) (Qt 4.7.4) on: Wed Feb 1 19:11:29 2012
=======
# Generated by qmake (2.01a) (Qt 4.7.4) on: Wed Feb 1 21:18:56 2012
>>>>>>> 7a6a20dc0c0e4be1afba7b092f663f8be21feb53
# Project: Unuk-QT.pro # Project: Unuk-QT.pro
# Template: app # Template: app
# Command: /home/kono/QtSDK/Desktop/Qt/474/gcc/bin/qmake -spec ../../../QtSDK/Desktop/Qt/474/gcc/mkspecs/linux-g++ CONFIG+=debug -o Makefile Unuk-QT.pro # Command: /home/kono/QtSDK/Desktop/Qt/474/gcc/bin/qmake -spec ../../../QtSDK/Desktop/Qt/474/gcc/mkspecs/linux-g++ CONFIG+=debug -o Makefile Unuk-QT.pro
@ -627,7 +623,8 @@ Bar.o: ../src/libUnuk/UI/Bar.cpp ../src/libUnuk/UI/Bar.h \
../src/libUnuk/System/Debug.h ../src/libUnuk/System/Debug.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o Bar.o ../src/libUnuk/UI/Bar.cpp $(CXX) -c $(CXXFLAGS) $(INCPATH) -o Bar.o ../src/libUnuk/UI/Bar.cpp
Vec2.o: ../src/libUnuk/System/Vec2.cpp ../src/libUnuk/System/Vec2.h Vec2.o: ../src/libUnuk/System/Vec2.cpp ../src/libUnuk/System/Vec2.h \
../src/libUnuk/System/MathBox.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o Vec2.o ../src/libUnuk/System/Vec2.cpp $(CXX) -c $(CXXFLAGS) $(INCPATH) -o Vec2.o ../src/libUnuk/System/Vec2.cpp
####### Install ####### Install

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject> <!DOCTYPE QtCreatorProject>
<!-- Written by Qt Creator 2.4.0, 2012-02-01T21:33:05. --> <!-- Written by Qt Creator 2.4.1, 2012-02-02T01:00:55. -->
<qtcreator> <qtcreator>
<data> <data>
<variable>ProjectExplorer.Project.ActiveTarget</variable> <variable>ProjectExplorer.Project.ActiveTarget</variable>

View File

@ -6,13 +6,17 @@
#include "../../Unuk/Globals.h" #include "../../Unuk/Globals.h"
const int EventHistory::BOX_WIDTH = 350; const int EventHistory::BOX_WIDTH = 350;
const int EventHistory::BOX_HEIGHT = 130; const int EventHistory::BOX_HEIGHT = 140;
EventHistory::EventHistory(void) { EventHistory::EventHistory(void) {
_bgx = SCREEN_WIDTH / 2 - BOX_WIDTH / 2; _bgx = SCREEN_WIDTH / 2 - BOX_WIDTH / 2;
_bgy = 10; _bgy = 10;
_text.SetXY(_bgx + 5, _bgy + 5); _titleText.SetXY(_bgx + BOX_WIDTH/2, _bgy + 5);
_titleText.SetTextBlended("Unuk Log", small, 0, 255, 255);
_titleText.SetXY(_titleText.GetX() - _titleText.GetWidth()/2, _titleText.GetY());
_text.SetXY(_bgx + 5, _bgy + 30);
_visible = false; _visible = false;
} }
@ -23,36 +27,59 @@ EventHistory::~EventHistory(void) {
void EventHistory::LogEvent(const std::string& evtText) { void EventHistory::LogEvent(const std::string& evtText) {
_events.push_back(evtText); _events.push_back(evtText);
if(_events.size() > 5) { if(_events.size() > 4) {
_events.erase(_events.begin()); _events.erase(_events.begin());
} }
BakeText();
if(!_visible) {
_timeToVanish.Start();
_visible = true;
}
}
void EventHistory::Render(void) {
if(_visible && (_timeToVanish.GetTicks() >= 5000)) {
_timeToVanish.Stop();
_events.erase(_events.begin());
if(_events.empty()) {
_visible = false;
} else {
BakeText();
_timeToVanish.Start();
}
}
if(!_visible) {
return;
}
roundedBoxRGBA(screen,
_bgx, _bgy,
_bgx + BOX_WIDTH, _bgy + BOX_HEIGHT,
8,
0, 0, 0, 200);
roundedRectangleRGBA(screen,
_bgx, _bgy,
_bgx + BOX_WIDTH, _bgy + BOX_HEIGHT,
8,
0, 255, 255, 255);
_titleText.RenderLiteral();
_text.RenderLiteral();
}
void EventHistory::BakeText(void) {
std::string textStr; std::string textStr;
for(std::list<std::string>::iterator evIt = _events.begin(); evIt != _events.end(); ++evIt) { for(std::list<std::string>::iterator evIt = _events.begin(); evIt != _events.end(); ++evIt) {
textStr.append(*evIt); textStr.append(*evIt);
textStr.append("\n"); textStr.append("\n");
} }
_text.SetTextBlended(textStr, small, 255, 255, 255); _text.SetTextBlended(textStr, small, 255, 255, 255);
_timeToVanish.Start();
_visible = true;
} }
void EventHistory::Render(void) {
if(_visible && (_timeToVanish.GetTicks() >= 2500)) {
_timeToVanish.Stop();
_visible = false;
}
if(!_visible) {
return;
}
boxRGBA(screen,
_bgx, _bgy,
_bgx + BOX_WIDTH, _bgy + BOX_HEIGHT,
0, 0, 0, 128);
_text.RenderLiteral();
}

View File

@ -16,7 +16,10 @@ public:
void Render(void); void Render(void);
private: private:
void BakeText(void);
std::list<std::string> _events; std::list<std::string> _events;
Text _titleText;
Text _text; Text _text;
Rect _background; Rect _background;
@ -28,4 +31,4 @@ private:
static const int BOX_WIDTH; static const int BOX_WIDTH;
static const int BOX_HEIGHT; static const int BOX_HEIGHT;
}; };